This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Chapter 2: Application Layer 1Comp361 Fall 2003
Chapter 2: Application Layer last updated 22/09/03
Chapter goals:❒ conceptual +
implementation aspects of network application protocols❍ client server
paradigm❍ service models
❒ learn about protocols by examining popular application-level protocols
More chapter goals ❒ specific protocols:
❍ http❍ ftp❍ smtp❍ pop ❍ dns
❒ programming network applications
❍ socket programming
Chapter 2: Application Layer 2Comp361 Fall 2003
Chapter 2 outline
❒ 2.1 Principles of app layer protocols
❒ 2.2 Web and HTTP❒ 2.3 FTP❒ 2.4 Electronic Mail
❍ SMTP, POP3, IMAP❒ 2.5 DNS
❒ 2.6 Socket programming with TCP
❒ 2.7 Socket programming with UDP
❒ 2.8 Building a Web server
❒ 2.9 Content distribution❍ Content distribution
networks vs. Web Caching
Chapter 2: Application Layer 3Comp361 Fall 2003
Applications and application-layer protocols
Applications: communicating, distributed processes❍ running the “user space” of network hosts❍ which exchange messages among themselves❍ Network Applications are applications which involves interactions
of processes implemented in multiple hosts connected by a network. Examples: the web, email, file transfer
❍ Within the same host, processes communicate with interprocesscommunication defined by the OS (Operating System).
❍ Processes running in different hosts communicate with an application-layer protocol
Application-layer protocols❍ a “piece” of Application (apps)❍ define messages exchanged by apps and actions taken❍ uses services provided by lower layer protocols
Chapter 2: Application Layer 4Comp361 Fall 2003
Client-server paradigm
Typical network app has two pieces: client and server
applicationtransportnetworkdata linkphysical
applicationtransportnetworkdata linkphysical
Client:❒ initiates contact with server
(“speaks first”)❒ typically requests service from server ❒ for Web, client is implemented in
browser; for e-mail, in mail readerServer:❒ provides requested service to client❒ e.g., Web server sends requested Web
page, mail server delivers e-mail
request
reply
Server
Client
Chapter 2: Application Layer 5Comp361 Fall 2003
Application-layer protocols (cont).
Q: how does a process “identify” the other process with which it wants to communicate?❍ IP address of host
running other process❍ “port number” - allows
receiving host to determine to which local process the message should be delivered
API: application programming interface
❒ defines interface between application and transport layer
❒ socket: Internet API❍ two processes
communicate by sending data into socket, reading data out of socket
… lots more on this later.
Chapter 2: Application Layer 6Comp361 Fall 2003
What transport service does an app need?Data loss❒ some apps (e.g., audio) can
tolerate some loss❒ other apps (e.g., file
transfer, telnet) require 100% reliable data transfer
Timing❒ some apps (e.g., Internet
telephony, interactive games) require low delay to be “effective”
Bandwidth❒ some apps (e.g., multimedia) require
minimum amount of bandwidth to be “effective”
❒ other apps (“elastic apps”) make use of whatever bandwidth they get
Chapter 2: Application Layer 7Comp361 Fall 2003
Transport service requirements of common apps
Application
file transfere-mail
Web documentsreal-time audio/video
stored audio/videointeractive games
financial apps
Data loss
no lossno lossno lossloss-tolerant
loss-tolerantloss-tolerantno loss
Bandwidth
elasticelasticelasticaudio: 5Kb-1Mbvideo:10Kb-5Mbsame as above few Kbps upelastic
Time Sensitive
nononoyes, 100’s msec
yes, few secsyes, 100’s msecyes and no
Chapter 2: Application Layer 8Comp361 Fall 2003
Services provided by Internet transport protocols
TCP service:❒ connection-oriented: setup
required between client, server❒ reliable transport between
sending and receiving process❒ flow control: sender won’t
overwhelm receiver❒ congestion control: throttle
sender when network overloaded❒ does not providing: timing,
minimum bandwidth guarantees
UDP service:❒ unreliable data transfer
between sending and receiving process
❒ does not provide: connection setup, reliable transport, flow control, congestion control, timing, or bandwidth guarantee
Chapter 2: Application Layer 9Comp361 Fall 2003
Internet apps: their protocols and transport protocols
2) Alice’s UA sends message to her mail server; message placed in message queue
3) Client side of SMTP opens TCP connection with Bob’s mail server
4) SMTP client sends Alice’s message over the TCP connection
5) Bob’s mail server places the message in Bob’s mailbox
6) Bob invokes his user agent to read message
useragent
mailserver
mailserver user
agent
1
3 4 562
Chapter 2: Application Layer 42Comp361 Fall 2003
Sample smtp interaction
S: 220 hamburger.eduC: HELO crepes.frS: 250 Hello crepes.fr, pleased to meet youC: MAIL FROM: <[email protected]> S: 250 [email protected]... Sender okC: RCPT TO: <[email protected]> S: 250 [email protected] ... Recipient okC: DATA S: 354 Enter mail, end with "." on a line by itselfC: Do you like ketchup? C: How about pickles? C: . S: 250 Message accepted for deliveryC: QUIT S: 221 hamburger.edu closing connection
Chapter 2: Application Layer 43Comp361 Fall 2003
Try SMTP interaction for yourself:
❒ telnet servername 25❒ see 220 reply from server❒ enter HELO, MAIL FROM, RCPT TO, DATA,
QUIT commandsabove lets you send email without using email
client (reader)
Chapter 2: Application Layer 44Comp361 Fall 2003
smtp: final words
❒ smtp uses persistent connections
❒ smtp requires that message (header & body) be in 7-bit ascii
❒ certain character strings are not permitted in message (e.g., CRLF.CRLF). Thus message has to be encoded (usually into either base-64 or quoted printable)
❒ smtp server uses CRLF.CRLFto determine end of message
Comparison with http❒ http: pull❒ email: push
❒ both have ASCII command/response interaction, status codes
❒ http: each object is encapsulated in its own response message
❒ smtp: multiple objects message sent in a multipart message
Chapter 2: Application Layer 45Comp361 Fall 2003
Mail message formatsmtp: protocol for exchanging
email msgsRFC 822: standard for text
message format:❒ header lines, e.g.,
❍ To:❍ From:❍ Subject:different from smtp
commands!❒ body
❍ the “message”, ASCII characters only
header
body
blankline
Chapter 2: Application Layer 46Comp361 Fall 2003
Message format: multimedia extensions
❒ MIME: (Multipurpose Internet Mail Extensions) multimedia mail extension, RFC 2045, 2056
❒ additional lines in msg header declare MIME content type
--StartOfNextPartDear Bob, Please find a picture of a crepe.--StartOfNextPartContent-Transfer-Encoding: base64Content-Type: image/jpegbase64 encoded data ..... ......................... ......base64 encoded data --StartOfNextPartDo you want the recipe?
Chapter 2: Application Layer 49Comp361 Fall 2003
Mail access protocols
❒ SMTP: delivery/storage to receiver’s 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: Hotmail , Yahoo! Mail, etc.
useragent
sender’s mail server
useragent
SMTP SMTP POP3 orIMAP
receiver’s mail server
Chapter 2: Application Layer 50Comp361 Fall 2003
POP3 protocol
authorization phase❒ client commands:
❍ user: declare username❍ pass: password
❒ server responses❍ +OK❍ -ERR
transaction phase, client:❒ list: list message numbers❒ retr: retrieve message by
number❒ dele: delete❒ quit
C: list S: 1 498 S: 2 912 S: . C: retr 1 S: <message 1 contents>S: . C: dele 1 C: retr 2 S: <message 1 contents>S: . C: dele 2 C: quit S: +OK POP3 server signing off
S: +OK POP3 server ready C: user aliceS: +OK C: pass hungry S: +OK user successfully logged on
Chapter 2: Application Layer 51Comp361 Fall 2003
POP3 (more) and IMAP
More about POP3❒ Previous example uses
“download and delete” mode.
❒ Bob cannot re-read e-mail if he changes client
❒ “Download-and-keep”: copies of messages on different clients
❒ POP3 is stateless across sessions
IMAP❒ Keep all messages in
one place: the server❒ Allows user to
organize messages in folders
❒ IMAP keeps user state across sessions:
❍ names of folders and mappings between message IDs and folder name
Chapter 2: Application Layer 52Comp361 Fall 2003
Chapter 2 outline
❒ 2.1 Principles of app layer protocols
❒ 2.2 Web and HTTP❒ 2.3 FTP❒ 2.4 Electronic Mail
❍ SMTP, POP3, IMAP❒ 2.5 DNS
❒ 2.6 Socket programming with TCP
❒ 2.7 Socket programming with UDP
❒ 2.8 Building a Web server
❒ 2.9 Content distribution❍ Content distribution
networks vs. Web Caching
Chapter 2: Application Layer 53Comp361 Fall 2003
DNS: Domain Name System
People: many identifiers:❍ SSN, name, Passport #
Internet hosts, routers:❍ IP address (32 bit) - used
for addressing datagrams❍ “name”, e.g.,
gaia.cs.umass.edu - used by humans
Q: map between IP addresses and name ?
Domain Name System:❒ distributed database
implemented in hierarchy of many name servers
❒ application-layer protocolhost, routers, name servers to communicate to resolve names (address/name translation)
❍ note: core Internet function implemented as application-layer protocol
❍ complexity at network’s “edge”
Chapter 2: Application Layer 54Comp361 Fall 2003
DNS name servers
❒ no server has all name-to-IP address mappings
local name servers:❍ each ISP, company has
local (default) name server❍ host DNS query first goes
to local name serverauthoritative name server:
❍ for a host: stores that host’s IP address, name
❍ can perform name/address translation for that host’s name
Why not centralize DNS?
❒ single point of failure❒ traffic volume❒ distant centralized
database❒ maintenance
doesn’t scale!
Chapter 2: Application Layer 55Comp361 Fall 2003
DNS: Root name servers
❒ 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❒ ~ dozen root name
servers worldwide
Chapter 2: Application Layer 56Comp361 Fall 2003
2. DNS ❍ Defined in RFCs 1034 and 1035.❍ Hierarchical, domain-based naming scheme, and
uses distributed database system.Illustration from Tanenbaum
Chapter 2: Application Layer 57Comp361 Fall 2003
Simple DNS exampleroot name servers
host surf.eurecom.frwants IP address of gaia.cs.umass.edu
1. Contacts its local DNS server, dns.eurecom.fr
2. dns.eurecom.frcontacts root name server, if necessary
3. root name server contacts authoritative name server, dns.umass.edu, if necessary
25 3
4
local name serverdns.eurecom.fr
authorititive name serverdns.umass.edu
1 6
requesting hostsurf.eurecom.fr
gaia.cs.umass.edu
Chapter 2: Application Layer 58Comp361 Fall 2003
DNS example root name server
Root name server:
❒ may not know authoritative name server
❒ may know intermediate name server: who to contact to find authoritative name server
27 3
6
4 5
authoritative name serverdns.cs.umass.edu
intermediate name serverdns.umass.edu
local name serverdns.eurecom.fr
1 8
requesting hostsurf.eurecom.fr
gaia.cs.umass.edu
Chapter 2: Application Layer 59Comp361 Fall 2003
DNS: iterated queriesroot name server
23
iterated queryrecursive query:❒ puts burden of
name resolution on contacted name server
❒ heavy load?
iterated query:❒ contacted server
replies with name of server to contact
❒ “I don’t know this name, but ask this server”
4
7
5 6
authoritative name serverdns.cs.umass.edu
intermediate name serverdns.umass.edu
local name serverdns.eurecom.fr
1 8
requesting hostsurf.eurecom.fr
gaia.cs.umass.edu
Chapter 2: Application Layer 60Comp361 Fall 2003
DNS: caching and updating records
❒ once (any) name server learns mapping, it caches mapping❍ cache entries timeout (disappear)
after some time❒ update/notify mechanisms under design
by IETF❍ RFC 2136❍ http://www.ietf.org/html.charters/dnsind-
charter.html
Chapter 2: Application Layer 61Comp361 Fall 2003
DNS records
DNS: distributed db storing resource records (RR)
RR format: (name, value, type,ttl)
❒ Type=CNAME❍ name is an alias name
for some “cannonical” (the real) name
❍ value is cannonicalname
❒ Type=NS❍ name is domain (e.g.
foo.com)❍ value is IP address of
authoritative name server for this domain
❒ Type=A❍ name is hostname❍ value is IP address
❒ Type=MX❍ value is hostname of
mailserver associated with name
Chapter 2: Application Layer 62Comp361 Fall 2003
2. Resource RecordFrom Tanenbaum
Chapter 2: Application Layer 63Comp361 Fall 2003
DNS protocol, messages
DNS protocol : query and reply messages, both with same message format
msg header❒ identification: 16 bit # for
query, reply to query uses same #
❒ flags:❍ query or reply❍ recursion desired ❍ recursion available❍ reply is authoritative
Chapter 2: Application Layer 64Comp361 Fall 2003
DNS protocol, messages
Name, type fieldsfor a query
RRs in reponseto query
records forauthoritative servers
additional “helpful”info that may be used
Chapter 2: Application Layer 65Comp361 Fall 2003
Chapter 2 outline
❒ 2.1 Principles of app layer protocols
❒ 2.2 Web and HTTP❒ 2.3 FTP❒ 2.4 Electronic Mail
❍ SMTP, POP3, IMAP❒ 2.5 DNS
❒ 2.6 Socket programming with TCP
❒ 2.7 Socket programming with UDP
❒ 2.8 Building a Web server
❒ 2.9 Content distribution❍ Content distribution
networks vs. Web Caching
Chapter 2: Application Layer 66Comp361 Fall 2003
Socket programmingGoal: learn how to build client/server
application that communicate using socketsSocket API❒ introduced in BSD4.1
UNIX, 1981❒ explicitly created, used,
released by apps ❒ client/server paradigm ❒ two types of transport
service via socket API: ❍ unreliable datagram ❍ reliable, byte stream-
oriented
a host-local, application-created,
OS-controlled interface (a “door”) into which
application process can both send and
receive messages to/from another application
process
socket
Chapter 2: Application Layer 67Comp361 Fall 2003
Socket-programming using TCPSocket: a door between application process
and end-end-transport protocol (UCP or TCP)
TCP service: reliable transfer of bytes from one process to another
process
TCP withbuffers,variables
socket
controlled byapplicationdeveloperprocess
TCP withbuffers,variables
socket
controlled byapplicationdeveloper
internet
controlled byoperatingsystem
controlled byoperating
system
host orserver
host orserver
Chapter 2: Application Layer 68Comp361 Fall 2003
Socket programming with TCP
Client must contact server❒ server process must first
be running❒ server must have created
socket (door) that welcomes client’s contact
Client contacts server by:❒ creating client-local TCP
socket❒ specifying IP address, port
number of server process❒ When client creates
socket: client TCP establishes connection to server TCP
❒ When contacted by client, server TCP creates new socket for server process to communicate with client
❍ allows server to talk with multiple clients
❍ source port numbers used to distinguish clients (more in Chap 3)
TCP provides reliable, in-ordertransfer of bytes (“pipe”) between client and server
application viewpoint
Chapter 2: Application Layer 69Comp361 Fall 2003
Stream jargon
❒ A stream is a sequence of characters that flow into or out of a process.
❒ An input stream is attached to some input source for the process, eg, keyboard or socket.
❒ An output stream is attached to an output source, eg, monitor or socket.
Chapter 2: Application Layer 70Comp361 Fall 2003
Socket programming with TCP
outT
oSer
ver
to network from network
inFr
omS
erve
r
inFr
omU
ser
keyboard monitor
Process
clientSocket
inputstream
inputstream
outputstream
TCPsocket
Clientprocess
client TCP socket
Example client-server app:1) client reads line from
standard input (inFromUserstream) , sends to server via socket (outToServerstream)
2) server reads line from socket3) server converts line to
uppercase, sends back to client
4) client reads, prints modified line from socket (inFromServer stream)
Chapter 2: Application Layer 71Comp361 Fall 2003
Client/server socket interaction: TCPServer (running on hostid) Client
wait for incomingconnection requestconnectionSocket =welcomeSocket.accept()
HTTP request for www.cdn.com/www.foo.com/sports/ruth.gif
1
2
3
Origin server
CDNs authoritative DNS server
NearbyCDN server
CDN company❒ cdn.com❒ distributes gif files❒ uses its authoritative DNS
server to route redirect requests
Chapter 2: Application Layer 90Comp361 Fall 2003
More about CDNs
routing requests❒ CDN creates a “map”,
indicating distances from leaf ISPs and CDN nodes
❒ when query arrives at authoritative DNS server:
❍ server determines ISP from which query originates
❍ uses “map” to determine best CDN server
not just Web pages❒ streaming stored
audio/video❒ streaming real-time
audio/video
Chapter 2: Application Layer 91Comp361 Fall 2003
Web Caching vs. CDN
Both Web Caching and CDN replicate content
❒ Web Caching: Content replicated on demand as function of user requests
❒ CDN: Content replicated by content provider
Chapter 2: Application Layer 92Comp361 Fall 2003
P2P
As well as retrieving objects from content providers/proxy caches/CDNs it is also possible for edge-machines to retrieve content from other edge-machines. This approach is known as Peer-To-Peer (P2P).
For more on P2P see textbook.
Chapter 2: Application Layer 93Comp361 Fall 2003
Chapter 2: SummaryOur study of network apps now complete!
❒ specific protocols:❍ HTTP❍ FTP❍ SMTP, POP, IMAP❍ DNS
❒ socket programming❒ content distribution
❍ caches, CDNs❍ P2P
❒ application service requirements:
❍ reliability, bandwidth, delay
❒ client-server paradigm❒ Internet transport service
model❍ connection-oriented,
reliable: TCP❍ unreliable, datagrams: UDP
Chapter 2: Application Layer 94Comp361 Fall 2003
Chapter 2: SummaryMost importantly: learned about protocols
❒ typical request/reply message exchange:
❍ client requests info or service❍ server responds with data,
status code❒ message formats:
❍ headers: fields giving info about data
❍ data: info being communicated
❒ control vs. data msgs❍ in-based, out-of-band
❒ centralized vs. decentralized ❒ stateless vs. stateful❒ reliable vs. unreliable msg