Chapter 2 Application Layer
2: Application Layer
Chapter 2: Application layer
r 2.1 Principles of
network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail
r 2.6 P2P application
SMTP, POP3, IMAP
r 2.5 DNS
2: Application Layer
Chapter 2: Application Layer
Our goals: r conceptual, implementation aspects of network application protocols transport-layer service models client-server paradigm peer-to-peer paradigm
r learn about protocols
by examining popular application-level protocols
HTTP FTP SMTP / POP3 / IMAP DNS
r programming network
applications socket API
2: Application Layer
Some network apps
r e-mail r web r instant messaging r remote login r P2P file sharing r multi-user network r voice over IP r real-time video
conferencing
games r streaming stored video clips
2: Application Layer
Chapter 2: Application layer
r 2.1 Principles of
network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail
r 2.6 P2P applications
SMTP, POP3, IMAP
r 2.5 DNS
2: Application Layer
Application architectures
r Client-server r Peer-to-peer (P2P) r Hybrid of client-server and P2P
2: Application Layer
Client-server architecture
server: always-on host permanent IP address server farms for scaling clients:
client/server
communicate with server may be intermittently connected may have dynamic IP addresses do not communicate directly with each other
2: Application Layer 7
Pure P2P architecture
r
no always-on server
r arbitrary end systems
directly communicate peer-peer r peers are intermittently connected and change IP addresses
Highly scalable but difficult to manage
2: Application Layer
Hybrid of client-server and P2P
Instant messaging chatting between two users is P2P centralized service: client presence detection/location user registers its IP address with central server when it comes online user contacts central server to find IP addresses of buddies
2: Application Layer
Processes communicating
Process: program running within a host. r within same host, two processes communicate using inter-process communication (defined by OS). r processes in different hosts communicate by exchanging messages Client process: process that initiates communication Server process: process that waits to be contacted
2: Application Layer
10
Sockets
r process sends/receives
messages to/from its socket r API: (1) choice of transport protocol; (2) ability to fix a few parameters (lots more on this later)
host or server controlled by app developer
host or server
process socket TCP with buffers, variables
process socket
Internet
TCP with buffers, variables
controlled by OS
2: Application Layer
11
Addressing processes
r to receive messages,
process must have
identifier
r host device has unique
32-bit IP address r Q: does IP address of host suffice for identifying the process?
2: Application Layer
12
Addressing processes
r to receive messages,
process must have
identifier
r host device has unique
32-bit IP address r Q: does IP address of host on which process runs suffice for identifying the process? A: No, many processes can be running on same host
IP address and port numbers associated with process on host. r Example port numbers:
identifier includes both
HTTP server: 80 Mail server: 25
r to send HTTP message
to gaia.cs.umass.edu web server:
IP address: 128.119.245.12 Port number: 80
2: Application Layer
r more shortly
13
App-layer protocol defines
r Types of messages
exchanged,
e.g., request, response
r Message syntax: what fields in messages & how fields are delineated r Message semantics meaning of information in fields r Rules for when and how
Public-domain protocols: r defined in RFCs r allows for interoperability r e.g., HTTP, SMTP Proprietary protocols: r e.g., Skype
processes send & respond to messages
2: Application Layer
14
What transport service does an app need?
Data loss r some apps (e.g., audio) can tolerate some loss r other apps (e.g., file transfer, telnet) require 100% reliable data transfer Timing r some apps (e.g., Internet telephony, interactive games) require low delay to be effective Throughput r some apps (e.g., multimedia) require minimum amount of throughput to be effective r other apps (elastic apps) make use of whatever throughput they get Security r Encryption, data integrity,
2: Application Layer 15
Transport service requirements of common apps
Application file transfer e-mail Web documents real-time audio/video stored audio/video interactive games instant messaging Data loss Throughput elastic elastic elastic audio: 5kbps-1Mbps video:10kbps-5Mbps same as above few kbps up elastic Time Sensitive
2: Application Layer
16
Transport service requirements of common apps
Application file transfer e-mail Web documents real-time audio/video stored audio/video interactive games instant messaging Data loss no loss no loss no loss loss-tolerant loss-tolerant loss-tolerant no loss Throughput elastic elastic elastic audio: 5kbps-1Mbps video:10kbps-5Mbps same as above few kbps up elastic Time Sensitive no no no yes, 100s msec yes, few secs yes, 100s msec yes and no
2: Application Layer
17
Internet transport protocols services
TCP service:
r
UDP service:
r
r r r
required between client and server processes reliable transport between sending and receiving process flow control: sender wont overwhelm receiver congestion control: throttle sender when network overloaded does not provide: timing, minimum throughput guarantees, security
connection-oriented: setup
unreliable data transfer between sending and receiving process does not provide: connection setup, reliability, flow control, congestion control, timing, throughput guarantee, or security
Q: why bother? Why is there a UDP?
2: Application Layer 18
Internet apps: application, transport protocols
Application e-mail remote terminal access Web file transfer streaming multimedia Internet telephony Application layer protocol Underlying transport protocol
2: Application Layer
19
Internet apps: application, transport protocols
Application e-mail remote terminal access Web file transfer streaming multimedia Internet telephony Application layer protocol SMTP [RFC 2821] Telnet [RFC 854] HTTP [RFC 2616] FTP [RFC 959] HTTP (eg Youtube), RTP [RFC 1889] SIP, RTP, proprietary (e.g., Skype) Underlying transport protocol TCP TCP TCP TCP TCP or UDP
typically UDP
2: Application Layer
20
Chapter 2: Application layer
r 2.1 Principles of
network applications
app architectures app requirements
r 2.6 P2P applications r 2.7 Socket programming
r 2.2 Web and HTTP r 2.4 Electronic Mail SMTP, POP3, IMAP r 2.5 DNS
with TCP r 2.8 Socket programming with UDP
2: Application Layer
21
Web and HTTP
First some jargon r Web page consists of objects r Object can be HTML file, JPEG image, Java applet, audio file, r Web page consists of base HTML-file which includes several referenced objects r Each object is addressable by a URL r Example URL: www.someschool.edu/someDept/pic.gif host name path name
2: Application Layer 22
HTTP overview
HTTP: hypertext transfer protocol
r r
Webs application layer protocol client/server model client: browser that requests, receives, displays Web objects server: Web server sends objects in response to requests
PC running Explorer
Server running Apache Web server Mac running Navigator
2: Application Layer
23
HTTP overview (continued)
Uses TCP:
r
HTTP is stateless
r
r r
client initiates TCP connection (creates socket) to server, port 80 server accepts TCP connection from client HTTP messages (applicationlayer protocol messages) exchanged between browser (HTTP client) and Web server (HTTP server) TCP connection closed
server maintains no information about past client requests
2: Application Layer
24
Uploading form input
Post method: r Web page often includes form input r Input is uploaded to server in entity body URL method: r Uses GET method r Input is uploaded in URL field of request line:
www.somesite.com/animalsearch?monkeys&banana
2: Application Layer
25
HTTP response message
status line (protocol status code status phrase) header lines HTTP/1.1 200 OK Connection close Date: Thu, 06 Aug 1998 12:00:15 GMT Server: Apache/1.3.0 (Unix) Last-Modified: Mon, 22 Jun 1998 ... Content-Length: 6821 Content-Type: text/html data data data data data ...
data, e.g., requested HTML file
2: Application Layer
26
HTTP response status codes
In first line in server->client response message. A few sample codes: 200 OK
request succeeded, requested object later in this message requested object moved, new location specified later in this message (Location:) request message not understood by server requested document not found on this server
2: Application Layer
301 Moved Permanently
400 Bad Request
404 Not Found
505 HTTP Version Not Supported
27
User-server state: cookies
Many major Web sites use cookies Four components: Example: r Susan always access Internet always from PC r visits specific e1) cookie header line of HTTP response message commerce site for first 2) cookie header line in time HTTP request message r when initial HTTP 3) cookie file kept on users host, managed requests arrives at site, by users browser site creates: 4) back-end database at unique ID Web site entry in backend database for ID
2: Application Layer 28
Cookies: keeping state (cont.)
client
ebay 8734
server
usual http request msg usual http response
cookie file
ebay 8734 amazon 1678
Set-cookie: 1678
usual http request msg
Amazon server creates ID 1678 for user create cookiespecific action cookiespectific action
access
entry
cookie: 1678
one week later:
ebay 8734 amazon 1678
usual http response msg usual http request msg
access
backend database
cookie: 1678
usual http response msg
2: Application Layer
29
Cookies (continued)
What cookies can bring: r authorization r shopping carts r recommendations r user session state (Web e-mail) Cookies and privacy: r cookies permit sites to learn a lot about you r you may supply name and e-mail to sites
aside
How to keep state: r protocol endpoints: maintain state at sender/receiver over multiple transactions r cookies: http messages carry state
2: Application Layer 30
Web caches (proxy server)
Goal: satisfy client request without involving origin server
r user sets browser:
origin server
Web accesses via cache r browser sends all HTTP requests to cache
client
Proxy server
object in cache: cache returns object else cache requests object from origin server, then returns object to client
client
origin server
2: Application Layer 31
More about Web caching
r cache acts as both
client and server r typically cache is installed by ISP (university, company, residential ISP)
Why Web caching? r reduce response time for client request r reduce traffic on an institutions access link. r Internet dense with caches: enables poor content providers to effectively deliver content (but so does P2P file sharing)
2: Application Layer 32
Chapter 2: Application layer
r 2.1 Principles of
network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail
r 2.6 P2P applications
SMTP, POP3, IMAP
r 2.5 DNS
2: Application Layer
33
FTP: the file transfer protocol
FTP FTP user client interface local file system file transfer FTP server remote file system
user at host
r r
r r
transfer file to/from remote host client/server model client: side that initiates transfer (either to/from remote) server: remote host ftp: RFC 959 ftp server: port 21
2: Application Layer 34
FTP: separate control, data connections
r
r r
FTP client contacts FTP server at port 21, TCP is transport protocol TCP data connection FTP FTP port 20 client authorized over control client server connection client browses remote r server opens another TCP directory by sending commands data connection to transfer over control connection. another file. when server receives file r control connection: out of transfer command, server band opens 2nd TCP connection (for r FTP server maintains state: file) to client current directory, earlier after transferring one file, authentication server closes data connection.
2: Application Layer 35
TCP control connection port 21
Chapter 2: Application layer
r 2.1 Principles of
network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail
r 2.6 P2P applications
SMTP, POP3, IMAP
r 2.5 DNS
2: Application Layer
36
Electronic Mail
Three major components:
r r r
outgoing message queue user mailbox user agent mail server user agent mail server user agent
user agents mail servers simple mail transfer protocol: SMTP
SMTP SMTP
mail server
User Agent r a.k.a. mail reader r composing, editing, reading mail messages r e.g., Eudora, Outlook, elm, Mozilla Thunderbird r outgoing, incoming messages stored on server
SMTP
user agent
user agent
user agent
2: Application Layer
37
Electronic Mail: mail servers
Mail Servers
r r r
mailbox contains incoming messages for user message queue of outgoing (to be sent) mail messages SMTP protocol between mail servers to send email messages client: sending mail server server: receiving mail server
user agent mail server user agent mail server user agent
SMTP SMTP
mail server
SMTP
user agent
user agent
user agent
2: Application Layer
38
Electronic Mail: SMTP [RFC 2821]
r r r
uses TCP to reliably transfer email message from client to server, port 25 direct transfer: sending server to receiving server three phases of transfer handshaking (greeting) transfer of messages closure command/response interaction commands: ASCII text response: status code and phrase
r messages must be in 7-bit ASCII
2: Application Layer
39
Scenario: Alice sends message to Bob
1) Alice uses UA to compose message and to
[email protected] 2) Alices UA sends message to her mail server; message placed in message queue 3) Client side of SMTP opens TCP connection with Bobs mail server 4) SMTP client sends Alices message over the TCP connection 5) Bobs mail server places the message in Bobs mailbox 6) Bob invokes his user agent to read message
1 user agent 2
mail server 3
mail server 4 5 6
user agent
2: Application Layer
40
Mail message format
SMTP: protocol for exchanging email msgs RFC 822: standard for text message format: r header lines, e.g.,
header
blank line
different from SMTP commands!
r
To: From: Subject:
body
body
the message, ASCII characters only
2: Application Layer
41
Mail access protocols
user agent
SMTP
SMTP
access protocol
user agent
senders mail server
receivers mail server
r r
SMTP: delivery/storage to receivers server Mail access protocol: retrieval from server POP: Post Office Protocol [RFC 1939] authorization (agent <-->server) and download IMAP: Internet Mail Access Protocol [RFC 1730] more features (more complex) manipulation of stored msgs on server HTTP: gmail, Hotmail, Yahoo! Mail, etc.
2: Application Layer 42
Chapter 2: Application layer
r 2.1 Principles of
network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail
r 2.6 P2P applications
SMTP, POP3, IMAP
r 2.5 DNS
2: Application Layer
43
DNS: Domain Name System
People: many identifiers:
Domain Name System:
r
SSN, name, passport # IP address (32 bit) used for addressing datagrams name, e.g., ww.yahoo.com - used by humans
distributed database
Internet hosts, routers:
Q: map between IP addresses and name ?
host, routers, name servers to communicate to resolve names (address/name translation) note: core Internet function, implemented as application-layer protocol complexity at networks edge
2: Application Layer 44
application-layer protocol
implemented in hierarchy of many name servers
DNS
DNS services r hostname to IP address translation r host aliasing
Canonical, alias names
r mail server aliasing r load distribution replicated Web servers: set of IP addresses for one canonical name
Why not centralize DNS? r single point of failure r traffic volume r distant centralized database r maintenance doesnt scale!
2: Application Layer
45
Distributed, Hierarchical Database
Root DNS Servers
com DNS servers yahoo.com amazon.com DNS servers DNS servers
org DNS servers pbs.org DNS servers
edu DNS servers poly.edu umass.edu DNS serversDNS servers
Client wants IP for www.amazon.com; 1st approx: r client queries a root server to find com DNS server r client queries com DNS server to get amazon.com DNS server r client queries amazon.com DNS server to get IP address for www.amazon.com
2: Application Layer 46
DNS: Root name servers
r r
contacted by local name server that can not resolve name root name server: contacts authoritative name server if name mapping not known gets mapping returns mapping to local name server
a Verisign, Dulles, VA c Cogent, Herndon, VA (also LA) d U Maryland College Park, MD g US DoD Vienna, VA h ARL Aberdeen, MD
j Verisign, ( 21 locations)
k RIPE London (also 16 other locations) i Autonomica, Stockholm (plus 28 other locations) m WIDE Tokyo (also Seoul, Paris, SF)
e NASA Mt View, CA f Internet Software C. Palo Alto,
CA (and 36 other locations)
13 root name servers worldwide
b USC-ISI Marina del Rey, CA l ICANN Los Angeles, CA
2: Application Layer
47
TLD and Authoritative Servers
r Top-level domain (TLD) servers: responsible for com, org, net, edu, etc, and all top-level country domains uk, fr, ca, jp. Network Solutions maintains servers for com TLD Educause for edu TLD r Authoritative DNS servers: organizations DNS servers, providing authoritative hostname to IP mappings for organizations servers (e.g., Web, mail). can be maintained by organization or service provider
2: Application Layer
48
Local Name Server
r does not strictly belong to hierarchy r each ISP (residential ISP, company,
university) has one.
also called default name server
r when host makes DNS query, query is sent
to its local DNS server
acts as proxy, forwards query into hierarchy
2: Application Layer
49
DNS name resolution example
r Host at cis.poly.edu
2
root DNS server
3 4 5 local DNS server
dns.poly.edu
wants IP address for gaia.cs.umass.edu
contacted server replies with name of server to contact I dont know this name, but ask this server
TLD DNS server
iterated query:
r
requesting host
cis.poly.edu
authoritative DNS server dns.cs.umass.edu
gaia.cs.umass.edu
2: Application Layer
50
DNS name resolution example
recursive query:
r
root DNS server
2 6
3 TLD DNS server
puts burden of name 7 resolution on contacted name server local DNS server heavy load?
dns.poly.edu
8
authoritative DNS server dns.cs.umass.edu
requesting host
cis.poly.edu
gaia.cs.umass.edu
2: Application Layer 51
DNS: caching and updating records
r once (any) name server learns mapping, it
mapping cache entries timeout (disappear) after some time TLD servers typically cached in local name servers
Thus root name servers not often visited
caches
r update/notify mechanisms under design by IETF RFC 2136
http://www.ietf.org/html.charters/dnsind-charter.html
2: Application Layer
52
Inserting records into DNS
r example: new startup Network Utopia r register name networkuptopia.com at DNS
(e.g., Network Solutions)
registrar
provide names, IP addresses of authoritative name server (primary and secondary) registrar inserts two RRs into com TLD server:
(networkutopia.com, dns1.networkutopia.com, NS) (dns1.networkutopia.com, 212.212.212.1, A)
r create authoritative server Type A record for
www.networkuptopia.com; Type MX record for networkutopia.com r How do people get IP address of your Web site?
2: Application Layer 53
Chapter 2: Application layer
r 2.1 Principles of
network applications
app architectures app requirements
r 2.6 P2P applications
r 2.2 Web and HTTP r 2.4 Electronic Mail SMTP, POP3, IMAP r 2.5 DNS
2: Application Layer
54
Pure P2P architecture
r
no always-on server
r arbitrary end systems
directly communicate peer-peer r peers are intermittently connected and change IP addresses
r Three topics: File distribution Searching for information Case Study: Skype
2: Application Layer 55
File Distribution: Server-Client vs P2P
Question : How much time to distribute file from one server to N peers?
Server u1 d1 u2
us: server upload bandwidth ui: peer i upload bandwidth
d2
File, size F dN uN
us
di: peer i download bandwidth
Network (with abundant bandwidth)
2: Application Layer
56
File distribution time: server-client
r server sequentially
Server
sends N copies:
F
us dN uN
u1 d1 u2
d2
r client i takes F/di
NF/us time
Network (with abundant bandwidth)
time to download
Time to distribute F to N clients using = dcs = max { NF/us, F/min(di) } i client/server approach increases linearly in N (for large N) 2: Application Layer
57
File distribution time: P2P
r server must send one
Server d2 copy: F/us time us r client i takes F/di time Network (with dN to download abundant bandwidth) uN r NF bits must be downloaded (aggregate) r fastest possible upload rate: us + ui
u1 d1 u2
dP2P = max { F/us, F/min(di) , NF/(us + ui) }
i
2: Application Layer 58
Server-client vs. P2P: example
Client upload rate = u, F/u = 1 hour, us = 10u, dmin us
3.5
Minimum Distribution Time
3 2.5 2 1.5 1 0.5 0 0
P2P Client-Server
10
15
20
25
30
35
N
2: Application Layer 59
File distribution: BitTorrent
r P2P file distribution
tracker: tracks peers
participating in torrent
torrent: group of
peers exchanging chunks of a file
obtain list of peers trading chunks
peer
2: Application Layer 60
BitTorrent
r file divided into 256KB r peer joining torrent:
chunks.
has no chunks, but will accumulate them over time registers with tracker to get list of peers, connects to subset of peers (neighbors) r while downloading, peer uploads chunks to other peers. r peers may come and go r once peer has entire file, it may (selfishly) leave or (altruistically) remain
2: Application Layer 61
P2P: searching for information
Index in P2P system: maps information to peer location (location = IP address & port number) File sharing (eg e-mule) r Index dynamically tracks the locations of files that peers share. r Peers need to tell index what they have. r Peers search index to determine where files can be found Instant messaging r Index maps user names to locations. r When user starts IM application, it needs to inform index of its location r Peers search index to determine IP address of user.
2: Application Layer 62
P2P: centralized index
original Napster design 1) when peer connects, it informs central server:
Bob centralized directory server 1 peers 1 1 2 1 3
IP address content
2) Alice queries for Hey Jude 3) Alice requests file from Bob
Alice
2: Application Layer
63
P2P: problems with centralized directory
r single point of failure r performance bottleneck r copyright infringement:
target of lawsuit is obvious
file transfer is decentralized, but locating content is highly centralized
2: Application Layer
64
Query flooding
r fully distributed no central server r used by Gnutella r Each peer indexes the
files it makes available for sharing (and no other files)
overlay network: graph r edge between peer X and Y if theres a TCP connection r all active peers and edges form overlay net r edge: virtual (not physical) link r given peer typically connected with < 10 overlay neighbors
2: Application Layer 65
Query flooding
sent over existing TCP connections r peers forward Query message r QueryHit sent over reverse Query path Scalability: limited scope flooding
r Query message
File transfer: HTTP
Query QueryHit
QueryHit
2: Application Layer
66
Hierarchical Overlay
r between centralized
index, query flooding approaches r each peer is either a super node or assigned to a super node
TCP connection between peer and its super node. TCP connections between some pairs of super nodes.
ordinary peer group-leader peer neighoring relationships in overlay network
r Super node tracks content
in its children
2: Application Layer
67
P2P Case study: Skype
r inherently P2P: pairs
Skype clients (SC)
of users communicate. r proprietary Skype login server application-layer protocol (inferred via reverse engineering) r hierarchical overlay with SNs r Index maps usernames to IP addresses; distributed over SNs
Supernode (SN)
2: Application Layer
68
Chapter 2: Summary
our study of network apps now complete!
r application architectures client-server P2P hybrid r application service r specific protocols: HTTP FTP SMTP, POP, IMAP DNS P2P: BitTorrent, Skype
requirements:
reliability, bandwidth, delay
r Internet transport
service model
connection-oriented, reliable: TCP unreliable, datagrams: UDP
2: Application Layer
69