Chapter 2 Application Layer A note on the use of these ppt slides: We’re making these slides freely available to all (faculty, students, readers). They’re in PowerPoint form so you can add, modify, and delete slides (including this one) and slide content to suit your needs. They obviously represent a lot of work on our part. In return for use, we only ask the following: If you use these slides (e.g., in a class) in substantially unaltered form, that you mention their source (after all, we’d like people to use our book!) If you post any slides in substantially unaltered form on a www site, that you note that they are adapted from (or perhaps identical to) our slides, and note our copyright of this material. Computer Networking: A Top Down Approach, 5th edition. Jim Kurose, Keith Ross Addison-Wesley, April 2009. Thanks and enjoy! JFK/KWR All material copyright 1996-2010 J.F Kurose and K.W. Ross, All Rights Reserved Application 2-1 Chapter 2: Application layer 2.1 Principles of network applications 2.2 Web and HTTP 2.3 FTP 2.4 Electronic mail 2.6 Socket programming with TCP 2.7Socket programming with UDP SMTP, POP3, IMAP 2.5 DNS Application 2-2 FTP: the file transfer protocol FTP FTP user client interface user at host local file system file transfer FTP server remote file system 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 Application 2-3 FTP: separate control, data connections TCP control connection, server port 21 FTP client contacts FTP server at port 21, TCP is transport protocol client authorized over control TCP data connection, FTP FTP server port 20 connection client server client browses remote directory by sending commands over server opens another TCP control connection. data connection to transfer when server receives file another file. transfer command, server opens control connection: “out of 2nd TCP connection (for file) to band” client FTP server maintains “state”: after transferring exactly one current directory, earlier file, server closes data authentication connection. Application 2-4 FTP commands, responses sample commands: sent as ASCII text over control channel 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 sample return codes 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 Application 2-5 Chapter 2: Application layer 2.1 Principles of network applications 2.2 Web and HTTP 2.3 FTP 2.4 Electronic Mail 2.6 P2P applications 2.7 Socket programming with TCP 2.8 Socket programming with UDP SMTP, POP3, IMAP 2.5 DNS Application 2-6 outgoing message queue Electronic Mail user mailbox Three major components: user agents mail servers simple mail transfer protocol: SMTP user agent mail server User Agent SMTP a.k.a. “mail reader” composing, editing, reading mail mail messages server e.g., Outlook, elm, Mozilla Thunderbird, iPhone mail client user outgoing, incoming messages agent stored on server SMTP SMTP user agent mail server user agent user agent user agent Application 2-7 Electronic Mail: SMTP [RFC 5321] 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 messages must be in 7-bit ASCII Application 2-9 Scenario: Alice sends message to Bob 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 1) Alice uses UA to compose message and “to” bob@someschool.edu 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 1 user agent 2 mail server 3 mail server 4 5 6 user agent Application 2-10 Sample SMTP interaction S: C: S: C: S: C: S: C: S: C: C: C: S: C: S: 220 hamburger.edu HELO crepes.fr 250 Hello crepes.fr, pleased to meet you MAIL FROM: <alice@crepes.fr> 250 alice@crepes.fr... Sender ok RCPT TO: <bob@hamburger.edu> 250 bob@hamburger.edu ... Recipient ok DATA 354 Enter mail, end with "." on a line by itself Do you like ketchup? How about pickles? . 250 Message accepted for delivery QUIT 221 hamburger.edu closing connection Application 2-11 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) Application 2-12 Sample Session 2: Application Layer 13 SMTP: final words SMTP uses persistent connections SMTP requires message (header & body) to be in 7bit ASCII SMTP server uses CRLF.CRLF to determine end of message Comparison with HTTP: HTTP: pull SMTP: push both have ASCII command/response interaction, status codes HTTP: each object encapsulated in its own response msg SMTP: multiple objects sent in multipart msg Application 2-15 Mail message format SMTP: protocol for exchanging email msgs RFC 822, 5322: standard for text message format: header lines, e.g., From: To: Subject: header blank line body different from SMTP commands! body the “message”, ASCII characters only Application 2-16 Message format: multimedia extensions MIME: Multipurpose Internet Mail Extensions (RFC 2045, 2056) additional lines in msg header declare MIME content type MIME version method used to encode data multimedia dataType (RFC 1521), 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 MIME types Content-Type: type/subtype; parameters Text example subtypes: plain, html Image example subtypes: jpeg, gif Audio exampe subtypes: basic (8bit mu-law encoded), 32kadpcm (32 kbps coding) Video example subtypes: mpeg, quicktime Application other data that must be processed by reader before “viewable” example subtypes: msword, octetstream 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-- Mail access protocols user agent SMTP SMTP sender’s mail server access protocol user agent receiver’s mail server SMTP: delivery/storage to receiver’s server mail access protocol: retrieval from server POP3: Post Office Protocol [RFC 1939] • authorization (agent <-->server) and download IMAP: Internet Mail Access Protocol [RFC 1730] • more features (more complex) • manipulation of stored messages on server HTTP: Gmail, Hotmail, Yahoo! Mail, etc. Application 2-20 POP3 protocol (port 110) 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 update phase – occurs after the quit command quit S: C: S: C: S: +OK POP3 server ready user bob +OK pass hungry +OK user successfully logged C: S: S: S: C: S: S: C: C: S: S: C: C: S: list 1 498 2 912 . retr 1 <message 1 contents> . dele 1 retr 2 <message 1 contents> . dele 2 quit +OK POP3 server signing off on Application 2-21 POP3 (more) and IMAP more about POP3 previous example uses “download and delete” mode. Bob cannot re-read email if he changes client “download-and-keep”: copies of messages on different clients POP3 is stateless across sessions IMAP keeps all messages in one place: at server allows user to organize messages in folders Selected components of messages can be obtained keeps user state across sessions: names of folders and mappings between message IDs and folder name Application 2-22 Chapter 2: Application layer 2.1 Principles of network applications 2.2 Web and HTTP 2.3 FTP 2.4 Electronic Mail 2.6 Socket programming with TCP 2.7 Socket programming with UDP SMTP, POP3, IMAP 2.5 DNS Application 2-23 DNS: Domain Name System people: many identifiers: SSN, name, passport # Domain Name System: Internet hosts, routers: IP address (32 bit) - used for addressing datagrams “hostname”, e.g., www.yahoo.com - used by humans Q: map between IP address and name, and vice versa ? distributed database implemented in hierarchy of many name servers application-layer protocol host, routers, name servers to communicate to resolve names (address/name translation) note: core Internet function, implemented as applicationlayer protocol complexity at network’s “edge” Application 2-24 DNS RFC 1034, 1035 DNS services 1. hostname to IP address translation 2. host aliasing Canonical, alias names Example: • www.ibm.com.cs186.net • ibm.com Why not centralize DNS? single point of failure traffic volume distant centralized database maintenance 3. 4. mail server aliasing load distribution Therefore, a centralised database approach doesn’t scale! replicated Web servers: set of IP addresses for one canonical name Application 2-25 Distributed, Hierarchical Database Root DNS Servers Top-level domain servers org DNS servers com DNS servers edu DNS servers Intermediate DNS servers Authoritative DNS servers yahoo.com amazon.com DNS servers DNS servers pbs.org DNS servers poly.edu umass.edu DNS servers DNS servers Each ISP also has a Local DNS server (default name server) client wants IP for www.amazon.com; 1st approx: client queries a root server to find com DNS server client queries com DNS server to get amazon.com DNS server client queries amazon.com DNS server to get IP address for www.amazon.com DNS query and reply messages are sent within UDP datagrams to port 53. Application 2-26 DNS: Root name servers contacted by local name server that cannot resolve name root name server: 1. contacts authoritative name server if name mapping is not known 2. gets mapping 3. 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) e NASA Mt View, CA f Internet Software C. Palo Alto, k RIPE London (also 16 other locations) i Autonomica, Stockholm (plus 28 other locations) m WIDE Tokyo (also Seoul, Paris, SF) CA (and 36 other locations) 13 root name servers worldwide b USC-ISI Marina del Rey, CA l ICANN Los Angeles, CA Application 2-27 DNS: Root name servers Copy a very small database, the content of which is currently decided by IANA (Internet Assigned Numbers Authority) and US Dept. of Commerce. Put that database in the servers. Make the data available to all Internet users. http://www.root-servers.org/ 2: Application Layer 28 TLD and Authoritative Servers Top-level domain (TLD) servers: responsible for com, org, net, edu, aero, jobs, museums, and all top-level country domains, e.g.: uk, fr, ch, jp, nz Network Solutions maintains servers for com TLD Educause for edu TLD Authoritative DNS servers: organization’s DNS servers, providing authoritative hostname to IP mappings for organization’s servers (e.g., Web, mail). can be maintained by organization or service provider Application 2-29 Local Name Server does not strictly belong to hierarchy each ISP (residential ISP, company, university) has one also called “default name server” when host makes DNS query, query is sent to its local DNS server acts as proxy, forwards query into hierarchy of DNS servers Application 2-30 DNS in action What happens when a user wants to view a website (e.g. www.networkutopia.com)? Let’s trace the sequence of DNS server interaction. 2: Application Layer 31 DNS Root DNS Server Local DNS Server i.e. Name Server responsible for COM Top-Level Domain (TLD) DNS Server Dns1.networkutopia.com IP: 212.212.212.1 Authoritative DNS Server (primary) 1 Dns2.networkutopia.com Authoritative DNS Server (secondary) Requesting host Destination Host 2: Application Layer 32 DNS Root DNS Server i.e. Name Server responsible for COM Top-Level Domain (TLD) DNS Server 2 Local DNS Server Dns1.networkutopia.com IP: 212.212.212.1 Authoritative DNS Server (primary) 1 Dns2.networkutopia.com Authoritative DNS Server (secondary) Requesting host Destination Host 2: Application Layer 33 DNS Root DNS Server 2 i.e. Name Server responsible for COM Top-Level Domain (TLD) DNS Server 3 Local DNS Server Dns1.networkutopia.com IP: 212.212.212.1 Authoritative DNS Server (primary) 1 Dns2.networkutopia.com Authoritative DNS Server (secondary) Requesting host Destination Host 2: Application Layer 34 DNS i.e. Name Server responsible for COM Root DNS Server 2 3 Local DNS Server Top-Level Domain (TLD) DNS Server 4 Dns1.networkutopia.com IP: 212.212.212.1 Authoritative DNS Server (primary) 1 Dns2.networkutopia.com Authoritative DNS Server (secondary) Requesting host Destination Host 2: Application Layer 35 DNS i.e. Name Server responsible for COM Root DNS Server 2 Top-Level Domain (TLD) DNS Server 4 3 5 Local DNS Server Dns1.networkutopia.com IP: 212.212.212.1 Authoritative DNS Server (primary) 1 Requesting host Dns2.networkutopia.com 5. Resource Records Authoritative DNS Server (secondary) (networkutopia.com, Dns1.networkutopia.com, NS) (Dns1.networkutopia.com, 212.212.212.1, A) Destination ...etc. Host 2: Application Layer 36 DNS i.e. Name Server responsible for COM Root DNS Server 2 4 3 5 Local DNS Server 1 Requesting host Top-Level Domain (TLD) DNS Server 6 Dns1.networkutopia.com IP: 212.212.212.1 Authoritative DNS Server (primary) Dns2.networkutopia.com DNS Server (secondary) 6. What is the IP address Authoritative of www.networkutopia.com? - give me a Type A Resource Destination Record Host 2: Application Layer 37 DNS i.e. Name Server responsible for COM Root DNS Server 2 3 Top-Level Domain (TLD) DNS Server 4 5 Local DNS Server 6 7 1 Dns1.networkutopia.com IP: 212.212.212.1 Authoritative DNS Server (primary) Dns2.networkutopia.com Authoritative DNS Server (secondary) Requesting host Destination Host 7. Type A Resource Record: (www.networkutopia.com, 212.212.71.4, A) 2: Application Layer 38 DNS i.e. Name Server responsible for COM Root DNS Server 2 Top-Level Domain (TLD) DNS Server 4 3 5 Local DNS Server 6 7 1 8 Dns1.networkutopia.com IP: 212.212.212.1 Authoritative DNS Server (primary) Dns2.networkutopia.com Authoritative DNS Server (secondary) Requesting host 8. IP address of www.networkutopia.com is 212.212.71.4 Destination Host 2: Application Layer 39 DNS i.e. Name Server responsible for COM Root DNS Server 2 3 Top-Level Domain (TLD) DNS Server 4 5 Local DNS Server 6 7 1 8 Dns1.networkutopia.com IP: 212.212.212.1 Authoritative DNS Server (primary) Dns2.networkutopia.com Authoritative DNS Server (secondary) 9 Requesting host Destination Host networkutopia.com IP: 212.212.71.4 9. TCP connection with www.networkutopia.com (212.212.71.4), HTTP request 2: Application Layer 40 DNS name resolution example root DNS server 2 iterative query: 3 host at cis.poly.edu wants IP address for gaia.cs.umass.edu contacted server replies with name of server to contact “I don’t know this name, but ask this server” TLD DNS server 4 5 local DNS server dns.poly.edu 1 8 7 6 authoritative DNS server dns.cs.umass.edu requesting host cis.poly.edu gaia.cs.umass.edu Application 2-41 DNS name resolution example recursive query: root DNS server 2 puts burden of name resolution on contacted name server heavy load? 3 7 6 TLD DNS server local DNS server dns.poly.edu 1 5 4 8 authoritative DNS server dns.cs.umass.edu requesting host cis.poly.edu gaia.cs.umass.edu Application 2-42 DNS: caching and updating records once (any) name server learns a mapping, it caches that mapping cache entries timeout (disappear) after some time (often set to 2 days) TLD servers typically cached in local name servers • Thus root name servers not often visited update/notify mechanisms proposed IETF standard RFC 2136 Application 2-43 DNS records DNS: distributed db storing Resource Records (RR) RR format: (name, Type=A name is hostname value is IP address Type=NS name is domain (e.g., foo.com) value is hostname of authoritative name server for this domain value, type, ttl) Type=CNAME name is alias name for some “canonical” (the real) name www.ibm.com is really www.ibm.com.cs186.net value is canonical name Type=MX value is canonical name of mail server associated with name Application 2-44 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 Application 2-45 DNS protocol, messages Name, type fields for a query RRs in response to query records for authoritative servers additional “helpful” info that may be used Application 2-46 Inserting records into DNS example: new startup “Network Utopia” register name networkuptopia.com at DNS registrar (e.g., Network Solutions) 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) Enter into authoritative server a Type A record for www.networkuptopia.com, and Type MX record for mail.networkutopia.com How do people get IP address of your Web site? Public Information Regarding Internet Domain Name Registration Services: http://www.internic.net/ Application 2-47 The End 2: Application Layer 48