Chapter 2: Application Layer 1
/ (application layer protocols) http ftp smtp pop dns 2
),, (TCP,UDP) application transport network data link physical application transport network data link physical application transport network data link physical 3
( process): Interprocess communication : : : () () E-: : 4
- : : : ) application transport network data link physical application transport network data link physical 5
API: application programming interface - (socket): API Q:? IP address port number lots more on this later. 6
? (reliability) /, E- (Bandwidth) (elastic) (Delay) 7
file transfer e-mail Web documents real-time audio/video stored audio/video interactive games financial apps no loss no loss loss-tolerant loss-tolerant loss-tolerant loss-tolerant no loss elastic elastic elastic audio: 5Kb-1Mb video:10kb-5mb same as above few Kbps up elastic no no no yes, 100 s msec yes, few secs yes, 100 s msec yes and no 8
TCP : (connectionoriented) (reliable transport) (flow control) (congestion control) :, UDP: Q: UDP? ( ) 9
: e-mail remote terminal access Web file transfer streaming multimedia remote file server Internet telephony smtp [RFC 821] telnet [RFC 854] http [RFC 2068] ftp [RFC 959] proprietary (e.g. RealNetworks) NSF proprietary (e.g., Vocaltec) TCP TCP TCP TCP TCP or UDP TCP or UDP typically UDP 10
(Web page): HTML + URL (object) URL: / ( ): MS Internet Explorer Netscape Communicator : MS Internet Information Server www.someschool.edu/somedept/pic.gif 11
: http http: hypertext transfer protocol client/server model http1.0: RFC 1945 http1.1: RFC 2068 PC running Explorer http request http response http request http response Server running NCSA Web server Mac running Navigator 12
http http: TCP TCP (80 ) ( ) http TCP http stateless Cf. (cookies) 13
time http URL www.someschool.edu/somedepartment/home.index 1a. http client initiates TCP connection to http server (process) at www.someschool.edu. Port 80 is default for http server. 2. http client sends http request message (containing URL) into TCP connection socket (contains text, references to 10 jpeg images) 1b. http server at host www.someschool.edu waiting for TCP connection at port 80. accepts connection, notifying client 3. http server receives request message, forms response message containing requested object (somedepartment/home.index), sends message into socket 14
http () time 5. http client receives response message containing html file, displays html. Parsing html file, finds 10 referenced jpeg objects 6. Steps 1-5 repeated for each of 10 jpeg objects 4. http server closes TCP connection. 15
HTTP/1.0 HTTP/1.1 HTTP/1.0 server parses request, responds, and closes TCP connection 2 RTT slow start O/H HTTP/1.1 TCP HTML (pipelining). RTT slow start O/H ( ) But most 1.0 browsers use parallel TCP connections. 16
http : request two types of http messages: request, response http request message: ASCII request line (GET, POST, HEAD commands) header lines GET /somedir/page.html HTTP/1.0 User-agent: Mozilla/4.0 Accept: text/html, image/gif,image/jpeg Accept-language:fr Carriage return, line feed indicates end of message (extra carriage return, line feed) 17
http request : general format 18
http message format: respone status line (protocol status code status phrase) data, e.g., requested html file header lines HTTP/1.0 200 OK 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... 19
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 301 Moved Permanently requested object moved, new location specified later in this message (Location:) 400 Bad Request request message not understood by server 404 Not Found requested document not found on this server 505 HTTP Version Not Supported 20
Trying out http (client side) for yourself 1. Telnet to your favorite Web server: telnet www.eurecom.fr 80 Opens TCP connection to port 80 (default http server port) at www.eurecom.fr. Anything typed in sent to port 80 at www.eurecom.fr 2. Type in a GET http request: GET /~ross/index.html HTTP/1.0 By typing this in (hit carriage return twice), you send this minimal (but complete) GET request to http server 3. Look at response message sent by http server! 21
-: (authentication) client server stateless: request ( ) usual http request msg 401: authorization req. WWW authenticate: authorization: name, password authorization: header line in request authorization, WWW authenticate:. usual http request msg + Authorization:line usual http response msg usual http request msg + Authorization:line usual http response msg time 22
-: (cookies) Set-cookie: 1678453 request cookie: 1678453, client usual http request msg usual http response + Set-cookie: # usual http request msg cookie: # usual http response msg usual http request msg cookie: # usual http response msg server 23
-: conditional GET : If-modified-since: <date> : : HTTP/1.0 304 Not Modified http request msg If-modified-since: <date> http response HTTP/1.0 304 Not Modified http request msg If-modified-since: <date> http response HTTP/1.1 200 OK <data> 24
( ) : all http request Hit Miss http request http response http request http request http response http response http request http response 25
? : 1.5 Mbps 10 Mbps LAN 26
ftp: FTP FTP FTP / ftp: RFC 959 ftp server: port 21 27
ftp:, TCP 21 TCP : : out of band control FTP TCP port 21 TCP port 20 FTP : ftp state :, 28
ftp ( ): ASCII USER username PASS password LIST return list of file in current directory RETR filename retrieves (gets) file STOR filename stores (puts) file onto remote host ( ) status code and phrase (as in http) 331 Username OK, password required 125 data connection already open; transfer starting 425 Can t open data connection 452 Error writing file 29
E- : user agent user agents mail servers mail server user agent simple mail transfer protocol: smtp SMTP SMTP mail server user agent,,, ) Eudora, Outlook, elm, Netscape Messenger mail server user agent SMTP user agent user agent 30
Electronic Mail: mail servers Mail Servers mailbox contains incoming messages (yet to be read) 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 mail server SMTP mail server user agent user agent SMTP SMTP user agent mail server user agent user agent user agent 31
Electronic Mail: smtp [RFC 821] uses tcp to reliably transfer email msg 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 messages must be in 7-bit ASCII 32
Sample smtp interaction S: 220 hamburger.edu C: HELO crepes.fr S: 250 Hello crepes.fr, pleased to meet you C: MAIL FROM: <alice@crepes.fr> S: 250 alice@crepes.fr... Sender ok C: RCPT TO: <bob@hamburger.edu> S: 250 bob@hamburger.edu... Recipient ok C: DATA S: 354 Enter mail, end with "." on a line by itself C: Do you like ketchup? C: How about pickles? C:. S: 250 Message accepted for delivery C: QUIT S: 221 hamburger.edu closing connection 33
try smtp interaction for yourself: telnet servername 25 see 220 reply from server enter HELO, MAIL FROM, RCPT TO, DATA, QUIT commands above lets you send email without using email client (reader) 34
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.CRLF to 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 35
Mail message format smtp: protocol for exchanging email msgs RFC 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 blank line 36
Message format: multimedia extensions MIME: multimedia mail extension, RFC 2045, 2056 additional lines in msg header declare MIME content type MIME version method used to encode data multimedia data type, subtype, parameter declaration encoded data From: alice@crepes.fr To: bob@hamburger.edu Subject: Picture of yummy crepe. MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Type: image/jpeg base64 encoded data.........base64 encoded data 37
MIME types Content-Type: type/subtype; parameters Text example subtypes: plain, html Video example subtypes: mpeg, quicktime Image example subtypes: jpeg, gif Audio exampe subtypes: basic (8-bit mu-law encoded), 32kadpcm (32 kbps coding) Application other data that must be processed by reader before viewable example subtypes: msword, octet-stream 38
Multipart Type From: alice@crepes.fr To: bob@hamburger.edu Subject: Picture of yummy crepe. MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=98766789 --98766789 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain Dear Bob, Please find a picture of a crepe. --98766789 Content-Transfer-Encoding: base64 Content-Type: image/jpeg base64 encoded data.........base64 encoded data --98766789-- 39
Mail access protocols user agent SMTP SMTP POP3 or IMAP user agent sender s mail server receiver s mail server 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. 40
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 S: +OK POP3 server ready C: user alice S: +OK C: pass hungry S: +OK user successfully logged on 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 41