Chapter 2 Application Layer Chapter goals r conceptual

  • Slides: 94
Download presentation
Chapter 2: Application Layer Chapter goals: r conceptual + last updated 22/09/03 More chapter

Chapter 2: Application Layer Chapter goals: r conceptual + last updated 22/09/03 More chapter goals r specific protocols: implementation m http aspects of network m ftp application protocols m smtp m client server m pop paradigm m dns m service models r programming network r learn about protocols applications by examining popular m socket programming application-level protocols Comp 361 Fall 2003 Chapter 2: Application Layer 1

Chapter 2 outline r 2. 1 Principles of app layer r r protocols 2.

Chapter 2 outline r 2. 1 Principles of app layer r r protocols 2. 2 Web and HTTP 2. 3 FTP 2. 4 Electronic Mail m SMTP, POP 3, IMAP 2. 5 DNS Comp 361 Fall 2003 r 2. 6 Socket programming with TCP r 2. 7 Socket programming with UDP r 2. 8 Building a Web server r 2. 9 Content distribution m Content distribution networks vs. Web Caching Chapter 2: Application Layer 2

Applications and application-layer protocols Applications: communicating, distributed processes m running the “user space” of

Applications and application-layer protocols Applications: communicating, distributed processes m running the “user space” of network hosts m which exchange messages among themselves m Network Applications are applications which involves interactions of processes implemented in multiple hosts connected by a network. Examples: the web, email, file transfer m Within the same host, processes communicate with interprocess communication defined by the OS (Operating System). m Processes running in different hosts communicate with an application-layer protocol Application-layer protocols m a “piece” of Application (apps) m define messages exchanged by apps and actions taken m uses services provided by lower layer protocols Comp 361 Fall 2003 Chapter 2: Application Layer 3

Client-server paradigm Typical network app has two pieces: client and server Client application transport

Client-server paradigm Typical network app has two pieces: client and server Client application transport network data link physical Client: request r initiates contact with server (“speaks first”) r typically requests service from server r for Web, client is implemented in browser; for e-mail, in mail reader Server: r provides requested service to client r e. g. , Web server sends requested Web page, mail server delivers e-mail Comp 361 Fall 2003 reply application transport network data link physical Server Chapter 2: Application Layer 4

Application-layer protocols (cont). Q: how does a process API: application “identify” the other programming

Application-layer protocols (cont). Q: how does a process API: application “identify” the other programming interface process with which it wants to communicate? r defines interface between application m IP address of host and transport layer running other process r socket: Internet API m “port number” - allows m two processes communicate by sending data into socket, reading data out of socket Comp 361 Fall 2003 receiving host to determine to which local process the message should be delivered … lots more on this later. Chapter 2: Application Layer 5

What transport service does an app need? Data loss r some apps (e. g.

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 Bandwidth telephony, interactive games) require low delay to be “effective” r some apps (e. g. , multimedia) require minimum amount of bandwidth to be “effective” r other apps (“elastic apps”) make use of whatever bandwidth they get Comp 361 Fall 2003 Chapter 2: Application Layer 6

Transport service requirements of common apps Data loss Bandwidth Time Sensitive file transfer e-mail

Transport service requirements of common apps Data loss Bandwidth Time Sensitive file transfer e-mail Web documents real-time audio/video no loss-tolerant no no no yes, 100’s msec stored audio/video interactive games financial apps loss-tolerant no loss elastic audio: 5 Kb-1 Mb video: 10 Kb-5 Mb same as above few Kbps up elastic Application Comp 361 Fall 2003 yes, few secs yes, 100’s msec yes and no Chapter 2: Application Layer 7

Services provided by Internet transport protocols TCP service: r connection-oriented: setup r r UDP

Services provided by Internet transport protocols TCP service: r connection-oriented: setup r r UDP service: r unreliable data transfer required between client, server between sending and reliable transport between receiving process sending and receiving process r does not provide: flow control: sender won’t connection setup, reliable overwhelm receiver transport, flow control, congestion control, timing, congestion control: throttle or bandwidth guarantee sender when network overloaded does not providing: timing, minimum bandwidth guarantees Comp 361 Fall 2003 Chapter 2: Application Layer 8

Internet apps: their protocols and transport protocols Application e-mail remote terminal access Web file

Internet apps: their protocols and transport protocols Application e-mail remote terminal access Web file transfer streaming multimedia remote file server Internet telephony Application layer protocol Underlying transport protocol smtp [RFC 821] telnet [RFC 854] http [RFC 2068] ftp [RFC 959] proprietary (e. g. Real. Networks) NFS proprietary (e. g. , Vocaltec) TCP TCP TCP or UDP Comp 361 Fall 2003 TCP or UDP typically UDP Chapter 2: Application Layer 9

Chapter 2 outline r 2. 1 Principles of app layer r r protocols 2.

Chapter 2 outline r 2. 1 Principles of app layer r r protocols 2. 2 Web and HTTP 2. 3 FTP 2. 4 Electronic Mail m SMTP, POP 3, IMAP 2. 5 DNS Comp 361 Fall 2003 r 2. 6 Socket programming with TCP r 2. 7 Socket programming with UDP r 2. 8 Building a Web server r 2. 9 Content distribution m Content distribution networks vs. Web Caching Chapter 2: Application Layer 10

The Web: some jargon r Web page: m consists of “objects” m addressed by

The Web: some jargon r Web page: m consists of “objects” m addressed by a URL r Most Web pages consist of: m m base HTML page, and several referenced objects. r URL has two components: host name and path name: r User agent for Web is called a browser: m m MS Internet Explorer Netscape Communicator r Server for Web is called Web server: m m Apache (public domain) MS Internet Information Server www. some. School. edu/some. Dept/pic. gif Comp 361 Fall 2003 Chapter 2: Application Layer 11

The Web: the http protocol http: hypertext transfer protocol r Web’s application layer protocol

The Web: the http protocol http: hypertext transfer protocol r Web’s application layer protocol r client/server model m client: browser that requests, receives, “displays” Web objects m server: Web server sends objects in response to requests r http 1. 0: RFC 1945 r http 1. 1: RFC 2068 Comp 361 Fall 2003 htt PC running Explorer htt pr equ pr esp est ons e t es u q re tp ht se n po s re Server running NCSA Web server Mac running Navigator Chapter 2: Application Layer 12

The http protocol: more http: TCP transport service: r client initiates TCP connection (creates

The http protocol: more http: TCP transport service: r client initiates TCP connection (creates socket) to server, port 80 r server accepts TCP connection from client r http messages (application -layer protocol messages) exchanged between browser (http client) and Web server (http server) r TCP connection closed Comp 361 Fall 2003 http is “stateless” r server maintains no information about past client requests aside Protocols that maintain “state” are complex! r past history (state) must be maintained r if server/client crashes, their views of “state” may be inconsistent, must be reconciled Chapter 2: Application Layer 13

http example Suppose user enters URL www. some. School. edu/some. Department/home. index 1 a.

http example Suppose user enters URL www. some. School. edu/some. Department/home. index 1 a. http client initiates TCP connection to http server (process) at www. some. School. edu. Port 80 is default for http server. 2. http client sends http request message (containing URL) into TCP connection socket time Comp 361 Fall 2003 (contains text, references to 10 jpeg images) 1 b. http server at host www. some. School. edu waiting for TCP connection at port 80. “accepts” connection, notifying client 3. http server receives request message, forms response message containing requested object (some. Department/home. index), sends message into socket Chapter 2: Application Layer 14

http example (cont. ) 5. http client receives response message containing html file, displays

http example (cont. ) 5. http client receives response message containing html file, displays html. Parsing html file, finds 10 referenced jpeg objects 4. http server closes TCP connection. 6. Steps 1 -5 repeated for time each of 10 jpeg objects Comp 361 Fall 2003 Chapter 2: Application Layer 15

Non-persistent and persistent connections Non-persistent r HTTP/1. 0 r server parses request, responds, and

Non-persistent and persistent connections Non-persistent r HTTP/1. 0 r server parses request, responds, and closes TCP connection r At least 2 RTTs (Round Trip Time) to fetch each object r Repeated 10 times for 10 objects. Each object transfer suffers from slow start But most 1. 0 browsers use parallel TCP connections. Comp 361 Fall 2003 Persistent r default for HTTP/1. 1 r on same TCP connection: server, parses request, responds, parses new request, . . r Client sends requests for all referenced objects as soon as it receives base HTML. r Fewer RTTs and less slow start. Chapter 2: Application Layer 16

http message format: request r two types of http messages: request, response r http

http message format: request r two types of http messages: request, response r http request message: m ASCII (human-readable format) request line (GET, POST, HEAD commands) GET /somedir/page. html HTTP/1. 0 User-agent: Mozilla/4. 0 Accept: text/html, image/gif, image/jpeg header Accept-language: fr lines Carriage return, line feed indicates end of message (extra carriage return, line feed) Comp 361 Fall 2003 Chapter 2: Application Layer 17

http request message: general format Comp 361 Fall 2003 Chapter 2: Application Layer 18

http request message: general format Comp 361 Fall 2003 Chapter 2: Application Layer 18

http request message: more info r http/1. 0 has only three request methods m

http request message: more info r http/1. 0 has only three request methods m GET: m POST: forms. Uses Entity Body to transfer form info m HEAD: Like GET but response does not actually return any info. This is used for debugging/test purposes r http/1. 1 has two additional request methods m PUT: Allows uploading object to web server m DELETE: Allows deleting object from web server Comp 361 Fall 2003 Chapter 2: Application Layer 19

http message format: respone status line (protocol status code status phrase) header lines data,

http message format: respone status line (protocol status code status phrase) header lines data, e. g. , requested html file status code 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. . . Comp 361 Fall 2003 Chapter 2: Application Layer 20

http response status codes In first line in server->client response message. A few sample

http response status codes In first line in server->client response message. A few sample codes: 200 OK m request succeeded, requested object later in this message 301 Moved Permanently m requested object moved, new location specified later in this message (Location: ) 400 Bad Request m request message not understood by server 404 Not Found m requested document not found on this server 505 HTTP Version Not Supported Comp 361 Fall 2003 Chapter 2: Application Layer 21

Trying out http (client side) for yourself 1. Telnet to your favorite Web server:

Trying out http (client side) for yourself 1. Telnet to your favorite Web server: telnet cis. poly. edu 80 Opens TCP connection to port 80 (default http server port) at cis. poly. edu. Anything typed in sent to port 80 at cis. poly. edu. 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! Try telnet www. cs. ust. hk 80 Comp 361 Fall 2003 Chapter 2: Application Layer 22

User-server interaction: authentication Authentication goal: control access to server documents r stateless: client must

User-server interaction: authentication Authentication goal: control access to server documents r stateless: client must present authorization in each request r authorization: typically name, password m authorization: header line in request m if no authorization presented, server refuses access, sends WWW authenticate: header line in response client server usual http request msg 401: authorization req. WWW authenticate: usual http request msg + Authorization: line usual http response msg time Browser caches name & password so that user does not have to repeatedly enter it. Chapter 2: Application Layer Comp 361 Fall 2003 23

User-server interaction: cookies r server sends “cookie” to client in response msg Set-cookie: 1678453

User-server interaction: cookies r server sends “cookie” to client in response msg Set-cookie: 1678453 r client stores & presents cookie in later requests server client usual http request msg usual http response + Set-cookie: # cookie: 1678453 r server matches presented-cookie with server-stored info m authentication m remembering user preferences, previous choices usual http request msg cookie: # usual http response msg Comp 361 Fall 2003 cookiespectific action Chapter 2: Application Layer 24

Cookie example telnet www. google. com 80 Trying 216. 239. 33. 99. . .

Cookie example telnet www. google. com 80 Trying 216. 239. 33. 99. . . Connected to www. google. com. Escape character is '^]'. GET /index. html HTTP/1. 0 200 OK Date: Wed, 10 Sep 2003 08: 55 GMT Set-Cookie: PREF=ID=43 bd 8 b 0 f 34818 b 58: TM=1063184203: LM=1063184203: S =DDq. Pg. Tb 56 Za 88 O 2 y; expires=Sun, 17 -Jan-2038 19: 14: 07 GMT; path=/; domain=. google. com. . Comp 361 Fall 2003 Chapter 2: Application Layer 25

User-server interaction: conditional GET r Goal: don’t send object if server client has up-to-date

User-server interaction: conditional GET r Goal: don’t send object if server client has up-to-date stored (cached) version r client: specify date of cached copy in http request If-modified-since: <date> http request msg If-modified-since: <date> http response HTTP/1. 0 304 Not Modified object not modified r server: response contains no object if cached copy up-todate: HTTP/1. 0 304 Not Modified http request msg If-modified-since: <date> http response object modified HTTP/1. 1 200 OK … <data> Comp 361 Fall 2003 Chapter 2: Application Layer 26

Web Caches (proxy server) Goal: satisfy client request without involving origin server r user

Web Caches (proxy server) Goal: satisfy client request without involving origin server r user sets browser: Web accesses via web cache r client sends all http requests to web cache m m if object at web cache, web cache immediately returns object in http response else requests object from origin server, then returns http response to client Comp 361 Fall 2003 origin server htt client htt pr equ pr esp est Proxy server ons e t es u eq r nse tp o t p h es r tp ht client t es u eq r se p n t o p ht es r tp ht htt pr equ htt est pr esp ons e origin server Chapter 2: Application Layer 27

More about Web caching r Cache acts as both client and server r Cache

More about Web caching r Cache acts as both client and server r Cache can do up-to-date check using If-modified-since HTTP header m m Issue: should cache take risk and deliver cached object without checking? Heuristics are used. r Typically cache is installed by ISP (university, company, residential ISP) Comp 361 Fall 2003 Why Web caching? r Reduce response time for client request. r Reduce traffic on an institution’s access link. r Internet dense with caches enables “poor” content providers to effectively deliver content Chapter 2: Application Layer 28

Caching example (1) Assumptions r average object size = 100, 000 bits r avg.

Caching example (1) Assumptions r average object size = 100, 000 bits r avg. request rate from institution’s browser to origin serves = 15/sec r delay from institutional router to any origin server and back to router = 2 sec Consequences r utilization on LAN = 15% r utilization on access link = 100% r total delay = Internet delay + access delay + LAN delay = 2 sec + minutes + milliseconds Comp 361 Fall 2003 origin servers public Internet 1. 5 Mbps access link institutional network 10 Mbps LAN institutional cache Chapter 2: Application Layer 29

Caching example (2) Possible solution r increase bandwidth of access link to, say, 10

Caching example (2) Possible solution r increase bandwidth of access link to, say, 10 Mbps Consequences origin servers public Internet 10 Mbps access link r utilization on LAN = 15% r utilization on access link = 15% r Total delay = Internet delay + access delay + LAN delay = 2 sec + msecs r often a costly upgrade Comp 361 Fall 2003 institutional network 10 Mbps LAN institutional cache Chapter 2: Application Layer 30

Caching example (3) origin servers Install cache r suppose hit rate is. 4 Consequence

Caching example (3) origin servers Install cache r suppose hit rate is. 4 Consequence public Internet r 40% requests will be satisfied almost immediately r 60% requests satisfied by origin server r utilization of access link reduced to 60%, resulting in negligible delays (say 10 msec) r total delay = Internet delay + access delay + LAN delay =. 6*2 sec +. 6*. 01 secs + milliseconds < 1. 3 secs Comp 361 Fall 2003 1. 5 Mbps access link institutional network 10 Mbps LAN institutional cache Chapter 2: Application Layer 31

Chapter 2 outline r 2. 1 Principles of app layer r r protocols 2.

Chapter 2 outline r 2. 1 Principles of app layer r r protocols 2. 2 Web and HTTP 2. 3 FTP 2. 4 Electronic Mail m SMTP, POP 3, IMAP 2. 5 DNS Comp 361 Fall 2003 r 2. 6 Socket programming with TCP r 2. 7 Socket programming with UDP r 2. 8 Building a Web server r 2. 9 Content distribution m Content distribution networks vs. Web Caching Chapter 2: Application Layer 32

ftp: the file transfer protocol user at host FTP user client interface file transfer

ftp: the file transfer protocol user at host FTP user client interface file transfer local file system FTP server remote file system r transfer file to/from remote host r client/server model client: side that initiates transfer (either to/from remote) m server: remote host r ftp: RFC 959 r ftp server: port 21 m Comp 361 Fall 2003 Chapter 2: Application Layer 33

ftp: separate control, data connections r ftp client contacts ftp server at port 21,

ftp: separate control, data connections r ftp client contacts ftp server at port 21, specifying TCP as transport protocol r two parallel TCP connections opened: m control: exchange commands, responses between client, FTP server. client “out of band control” m data: file data to/from server r ftp server maintains “state”: current directory, earlier authentication Comp 361 Fall 2003 TCP control connection port 21 TCP data connection port 20 FTP server Chapter 2: Application Layer 34

ftp: separate control, data connections r When server receives request for file transfer it

ftp: separate control, data connections r When server receives request for file transfer it opens a TCP data connection to client on port 20. r After transferring one FTP file, server closes client connection r When next request for file transfer arrives server opens new TCP data connection on port 20 Comp 361 Fall 2003 TCP control connection port 21 TCP data connection port 20 FTP server Chapter 2: Application Layer 35

ftp commands, responses Sample commands: r sent as ASCII text over control channel r

ftp commands, responses Sample commands: r sent as ASCII text over control channel r USER username r PASS password r LIST return list of file in current directory r RETR filename retrieves (gets) file r STOR filename stores (puts) file onto remote host Comp 361 Fall 2003 Sample return codes r status code and phrase r r (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 Chapter 2: Application Layer 36

Chapter 2 outline r 2. 1 Principles of app layer r r protocols 2.

Chapter 2 outline r 2. 1 Principles of app layer r r protocols 2. 2 Web and HTTP 2. 3 FTP 2. 4 Electronic Mail m SMTP, POP 3, IMAP 2. 5 DNS Comp 361 Fall 2003 r 2. 6 Socket programming with TCP r 2. 7 Socket programming with UDP r 2. 8 Building a Web server r 2. 9 Content distribution m Content distribution networks vs. Web Caching Chapter 2: Application Layer 37

Electronic Mail outgoing message queue user mailbox Three major components: r user agents r

Electronic Mail outgoing message queue user mailbox Three major components: r user agents r mail servers r simple mail transfer protocol: user agent mail server smtp User Agent SMTP r a. k. a. “mail reader” r composing, editing, reading mail messages server r e. g. , Eudora, Outlook, elm, Netscape Messenger r outgoing, incoming messages user agent stored on server Comp 361 Fall 2003 SMTP user agent mail server user agent Chapter 2: Application Layer 38

Electronic Mail: mail servers Mail “Servers” r mailbox contains incoming user agent mail messages

Electronic Mail: mail servers Mail “Servers” r mailbox contains incoming user agent mail messages (yet to be read) server for user SMTP r message queue of outgoing (to be sent) mail messages SMTP r smtp protocol between mail servers to send email SMTP messages mail server m client: sending mail server user agent m “server”: receiving mail user server agent Comp 361 Fall 2003 user agent mail server user agent Chapter 2: Application Layer 39

Electronic Mail: smtp [RFC 821] r uses tcp to reliably transfer email msg from

Electronic Mail: smtp [RFC 821] r uses tcp to reliably transfer email msg from client to server, port 25 r direct transfer: sending server to receiving server r three phases of transfer m handshaking (greeting) m transfer of messages m closure r command/response interaction m commands: ASCII text m response: status code and phrase r messages must be in 7 -bit ASCII Comp 361 Fall 2003 Chapter 2: Application Layer 40

Scenario: Alice sends message to Bob 1) Alice uses UA to compose 4) SMTP

Scenario: Alice sends message to Bob 1) Alice uses UA to compose 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 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 Comp 361 Fall 2003 mail server 4 5 6 user agent Chapter 2: Application Layer 41

Sample smtp interaction S: C: S: C: C: C: S: 220 hamburger. edu HELO

Sample smtp interaction S: C: S: C: C: 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 Comp 361 Fall 2003 Chapter 2: Application Layer 42

Try SMTP interaction for yourself: r telnet servername 25 r see 220 reply from

Try SMTP interaction for yourself: r telnet servername 25 r see 220 reply from server r enter HELO, MAIL FROM, RCPT TO, DATA, QUIT commands above lets you send email without using email client (reader) Comp 361 Fall 2003 Chapter 2: Application Layer 43

smtp: final words r smtp uses persistent connections r smtp requires that message (header

smtp: final words r smtp uses persistent connections r smtp requires that message (header & body) be in 7 -bit ascii r certain character strings are not permitted in message (e. g. , CRLF). Thus message has to be encoded (usually into either base-64 or quoted printable) r smtp server uses CRLF to determine end of message Comp 361 Fall 2003 Comparison with http r http: pull r email: push r both have ASCII command/response interaction, status codes r http: each object is encapsulated in its own response message r smtp: multiple objects message sent in a multipart message Chapter 2: Application Layer 44

q. Mail message format smtp: protocol for exchanging email msgs RFC 822: standard for

q. Mail message format smtp: protocol for exchanging email msgs RFC 822: standard for text message format: r header lines, e. g. , To: m From: m Subject: different from smtp commands! header m blank line body r body m the “message”, ASCII characters only Comp 361 Fall 2003 Chapter 2: Application Layer 45

Message format: multimedia extensions r MIME: (Multipurpose Internet Mail Extensions) multimedia mail extension, RFC

Message format: multimedia extensions r MIME: (Multipurpose Internet Mail Extensions) multimedia mail extension, RFC 2045, 2056 r additional lines in msg header declare MIME content type MIME version method used to encode data multimedia data type, subtype, parameter declaration encoded data Comp 361 Fall 2003 From: alice@crepes. fr To: bob@hamburger. edu Subject: Picture of yummy crepe. MIME-Version: 1. 0 Content-Transfer-Encoding: base 64 Content-Type: image/jpeg base 64 encoded data. . . . . base 64 encoded data Chapter 2: Application Layer 46

MIME types Content-Type: type/subtype; parameters Text r example subtypes: plain, html Video r example

MIME types Content-Type: type/subtype; parameters Text r example subtypes: plain, html Video r example subtypes: mpeg, quicktime Image r example subtypes: jpeg, gif Audio r exampe subtypes: basic (8 - bit mu-law encoded), 32 kadpcm (32 kbps coding) Comp 361 Fall 2003 Application r other data that must be processed by reader before “viewable” r example subtypes: msword, octet-stream Chapter 2: Application Layer 47

Multipart Type From: alice@crepes. fr To: bob@hamburger. edu Subject: Picture of yummy crepe. MIME-Version:

Multipart Type From: alice@crepes. fr To: bob@hamburger. edu Subject: Picture of yummy crepe. MIME-Version: 1. 0 Content-Type: multipart/mixed; boundary=Start. Of. Next. Part --Start. Of. Next. Part Dear Bob, Please find a picture of a crepe. --Start. Of. Next. Part Content-Transfer-Encoding: base 64 Content-Type: image/jpeg base 64 encoded data. . . . . base 64 encoded data --Start. Of. Next. Part Do you want the recipe? Comp 361 Fall 2003 Chapter 2: Application Layer 48

Mail access protocols user agent SMTP sender’s mail server POP 3 or IMAP user

Mail access protocols user agent SMTP sender’s mail server POP 3 or IMAP user agent receiver’s mail server r SMTP: delivery/storage to receiver’s server r Mail access protocol: retrieval from server m m m 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. Comp 361 Fall 2003 Chapter 2: Application Layer 49

POP 3 protocol authorization phase r client commands: user: declare username m pass: password

POP 3 protocol authorization phase r client commands: user: declare username m pass: password r server responses m +OK m -ERR m transaction phase, client: r list: list message numbers r retr: retrieve message by number r dele: delete r quit Comp 361 Fall 2003 S: C: S: +OK POP 3 server ready user alice +OK pass hungry +OK user successfully logged C: S: 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 POP 3 server signing off Chapter 2: Application Layer 50 on

POP 3 (more) and IMAP More about POP 3 r Previous example uses “download

POP 3 (more) and IMAP More about POP 3 r Previous example uses “download and delete” mode. r Bob cannot re-read email if he changes client r “Download-and-keep”: copies of messages on different clients r POP 3 is stateless across sessions Comp 361 Fall 2003 IMAP r Keep all messages in one place: the server r Allows user to organize messages in folders r IMAP keeps user state across sessions: m names of folders and mappings between message IDs and folder name Chapter 2: Application Layer 51

Chapter 2 outline r 2. 1 Principles of app layer r r protocols 2.

Chapter 2 outline r 2. 1 Principles of app layer r r protocols 2. 2 Web and HTTP 2. 3 FTP 2. 4 Electronic Mail m SMTP, POP 3, IMAP 2. 5 DNS Comp 361 Fall 2003 r 2. 6 Socket programming with TCP r 2. 7 Socket programming with UDP r 2. 8 Building a Web server r 2. 9 Content distribution m Content distribution networks vs. Web Caching Chapter 2: Application Layer 52

DNS: Domain Name System People: many identifiers: m SSN, name, Passport # Domain Name

DNS: Domain Name System People: many identifiers: m SSN, name, Passport # Domain Name System: r distributed database implemented in hierarchy of Internet hosts, routers: many name servers m IP address (32 bit) - used r application-layer protocol for addressing datagrams host, routers, name servers to communicate to resolve names m “name”, e. g. , (address/name translation) gaia. cs. umass. edu - used by humans m note: core Internet function implemented as Q: map between IP application-layer protocol addresses and name ? m complexity at network’s “edge” Comp 361 Fall 2003 Chapter 2: Application Layer 53

DNS name servers r no server has all name-to. Why not centralize IP address

DNS name servers r no server has all name-to. Why not centralize IP address mappings DNS? local name servers: r single point of failure m each ISP, company has local (default) name server r traffic volume m host DNS query first goes to local name server r distant centralized authoritative name server: database m for a host: stores that host’s IP address, name r maintenance m doesn’t scale! Comp 361 Fall 2003 can perform name/address translation for that host’s name Chapter 2: Application Layer 54

DNS: Root name servers r contacted by local name server that can not resolve

DNS: Root name servers r contacted by local name server that can not resolve name r root name server: m contacts authoritative name server if name mapping not known m gets mapping m returns mapping to local name server r ~ dozen root name servers worldwide Comp 361 Fall 2003 Chapter 2: Application Layer 55

2. DNS m Defined in RFCs 1034 and 1035. m Hierarchical, domain-based naming scheme,

2. DNS m Defined in RFCs 1034 and 1035. m Hierarchical, domain-based naming scheme, and uses distributed database system. Illustration from Tanenbaum Comp 361 Fall 2003 Computer Networks - The Application Layer 56

Simple DNS example host surf. eurecom. fr wants IP address of gaia. cs. umass.

Simple DNS example host surf. eurecom. fr wants IP address of gaia. cs. umass. edu 1. Contacts its local DNS server, dns. eurecom. fr 2. dns. eurecom. fr contacts root name server, if necessary 3. root name server contacts authoritative name server, dns. umass. edu, if necessary Comp 361 Fall 2003 root name servers 2 5 local name server dns. eurecom. fr 1 3 4 authorititive name server dns. umass. edu 6 requesting host surf. eurecom. fr gaia. cs. umass. edu Chapter 2: Application Layer 57

DNS example root name server Root name server: r may not know authoritative name

DNS example root name server Root name server: r may not know authoritative name server r may know intermediate name server: who to contact to find authoritative name server 6 2 7 local name server dns. eurecom. fr 1 8 requesting host 3 intermediate name server dns. umass. edu 4 5 authoritative name server dns. cs. umass. edu surf. eurecom. fr gaia. cs. umass. edu Comp 361 Fall 2003 Chapter 2: Application Layer 58

DNS: iterated queries root name server recursive query: r puts burden of name resolution

DNS: iterated queries root name server recursive query: r puts burden of name resolution on contacted name server r heavy load? iterated query: r contacted server replies with name of server to contact r “I don’t know this name, but ask this server” Comp 361 Fall 2003 iterated query 2 3 4 7 local name server dns. eurecom. fr 1 8 requesting host intermediate name server dns. umass. edu 5 6 authoritative name server dns. cs. umass. edu surf. eurecom. fr gaia. cs. umass. edu Chapter 2: Application Layer 59

DNS: caching and updating records r once (any) name server learns mapping, it caches

DNS: caching and updating records r once (any) name server learns mapping, it caches mapping m cache entries timeout (disappear) after some time r update/notify mechanisms under design by IETF m RFC m 2136 http: //www. ietf. org/html. charters/dnsind-charter. html Comp 361 Fall 2003 Chapter 2: Application Layer 60

DNS records DNS: distributed db storing resource records (RR) RR format: (name, value, type,

DNS records DNS: distributed db storing resource records (RR) RR format: (name, value, type, ttl) r Type=A m name is hostname m value is IP address r Type=NS m name is domain (e. g. foo. com) m value is IP address of authoritative name server for this domain Comp 361 Fall 2003 r Type=CNAME m name is an alias name for some “cannonical” (the real) name m value is cannonical name r Type=MX m value is hostname of mailserver associated with name Chapter 2: Application Layer 61

2. Resource Record From Tanenbaum Comp 361 Fall 2003 Computer Networks - The Application

2. Resource Record From Tanenbaum Comp 361 Fall 2003 Computer Networks - The Application Layer 62

DNS protocol, messages DNS protocol : query and reply messages, both with same message

DNS protocol, messages DNS protocol : query and reply messages, both with same message format msg header r identification: 16 bit # for query, reply to query uses same # r flags: m query or reply m recursion desired m recursion available m reply is authoritative Comp 361 Fall 2003 Chapter 2: Application Layer 63

DNS protocol, messages Name, type fields for a query RRs in reponse to query

DNS protocol, messages Name, type fields for a query RRs in reponse to query records for authoritative servers additional “helpful” info that may be used Comp 361 Fall 2003 Chapter 2: Application Layer 64

Chapter 2 outline r 2. 1 Principles of app layer r r protocols 2.

Chapter 2 outline r 2. 1 Principles of app layer r r protocols 2. 2 Web and HTTP 2. 3 FTP 2. 4 Electronic Mail m SMTP, POP 3, IMAP 2. 5 DNS Comp 361 Fall 2003 r 2. 6 Socket programming with TCP r 2. 7 Socket programming with UDP r 2. 8 Building a Web server r 2. 9 Content distribution m Content distribution networks vs. Web Caching Chapter 2: Application Layer 65

Socket programming Goal: learn how to build client/server application that communicate using sockets Socket

Socket programming Goal: learn how to build client/server application that communicate using sockets Socket API r introduced in BSD 4. 1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm r two types of transport service via socket API: m unreliable datagram m reliable, byte streamoriented Comp 361 Fall 2003 socket 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 Chapter 2: Application Layer 66

Socket-programming using TCP Socket: a door between application process and end-transport protocol (UCP or

Socket-programming using TCP Socket: a door between application process and end-transport protocol (UCP or TCP) TCP service: reliable transfer of bytes from one process to another controlled by application developer controlled by operating system process socket TCP with buffers, variables host or server Comp 361 Fall 2003 internet socket TCP with buffers, variables controlled by application developer controlled by operating system host or server Chapter 2: Application Layer 67

Socket programming with TCP Client must contact server r server process must first be

Socket programming with TCP Client must contact server r server process must first be running r server must have created socket (door) that welcomes client’s contact Client contacts server by: r creating client-local TCP socket r specifying IP address, port number of server process r When client creates socket: client TCP establishes connection to server TCP Comp 361 Fall 2003 r When contacted by client, server TCP creates new socket for server process to communicate with client m allows server to talk with multiple clients m source port numbers used to distinguish clients (more in Chap 3) application viewpoint TCP provides reliable, in-order transfer of bytes (“pipe”) between client and server Chapter 2: Application Layer 68

Stream jargon r A stream is a sequence of characters that flow into or

Stream jargon r A stream is a sequence of characters that flow into or out of a process. r An input stream is attached to some input source for the process, eg, keyboard or socket. r An output stream is attached to an output source, eg, monitor or socket. Comp 361 Fall 2003 Chapter 2: Application Layer 69

Socket programming with TCP Example client-server app: 1) client reads line from standard input

Socket programming with TCP Example client-server app: 1) client reads line from standard input (in. From. User stream) , sends to server via socket (out. To. Server stream) 2) server reads line from socket 3) server converts line to uppercase, sends back to client 4) client reads, prints modified line from socket (in. From. Server stream) Comp 361 Fall 2003 Client process client TCP socket Chapter 2: Application Layer 70

Client/server socket interaction: TCP Server Client (running on hostid) create socket, port=x, for incoming

Client/server socket interaction: TCP Server Client (running on hostid) create socket, port=x, for incoming request: welcome. Socket = Server. Socket() TCP wait for incoming connection request connection. Socket = welcome. Socket. accept() read request from connection. Socket write reply to connection. Socket close connection. Socket Comp 361 Fall 2003 setup create socket, connect to hostid, port=x client. Socket = Socket() send request using client. Socket read reply from client. Socket close client. Socket Chapter 2: Application Layer 71

Example: Java client (TCP) import java. io. *; import java. net. *; class TCPClient

Example: Java client (TCP) import java. io. *; import java. net. *; class TCPClient { public static void main(String argv[]) throws Exception { String sentence; String modified. Sentence; Create input stream Create client socket, connect to server Create output stream attached to socket Buffered. Reader in. From. User = new Buffered. Reader(new Input. Stream. Reader(System. in)); Socket client. Socket = new Socket("hostname", 6789); Data. Output. Stream out. To. Server = new Data. Output. Stream(client. Socket. get. Output. Stream()); Comp 361 Fall 2003 Chapter 2: Application Layer 72

Example: Java client (TCP), cont. Create input stream attached to socket Buffered. Reader in.

Example: Java client (TCP), cont. Create input stream attached to socket Buffered. Reader in. From. Server = new Buffered. Reader(new Input. Stream. Reader(client. Socket. get. Input. Stream())); sentence = in. From. User. read. Line(); Send line to server out. To. Server. write. Bytes(sentence + 'n'); Read line from server modified. Sentence = in. From. Server. read. Line(); System. out. println("FROM SERVER: " + modified. Sentence); client. Socket. close(); } } Comp 361 Fall 2003 Chapter 2: Application Layer 73

Example: Java server (TCP) import java. io. *; import java. net. *; class TCPServer

Example: Java server (TCP) import java. io. *; import java. net. *; class TCPServer { Create welcoming socket at port 6789 Wait, on welcoming socket for contact by client Create input stream, attached to socket public static void main(String argv[]) throws Exception { String client. Sentence; String capitalized. Sentence; Server. Socket welcome. Socket = new Server. Socket(6789); while(true) { Socket connection. Socket = welcome. Socket. accept(); Buffered. Reader in. From. Client = new Buffered. Reader(new Input. Stream. Reader(connection. Socket. get. Input. Stream())); Comp 361 Fall 2003 Chapter 2: Application Layer 74

Example: Java server (TCP), cont Create output stream, attached to socket Data. Output. Stream

Example: Java server (TCP), cont Create output stream, attached to socket Data. Output. Stream out. To. Client = new Data. Output. Stream(connection. Socket. get. Output. Stream()); Read in line from socket client. Sentence = in. From. Client. read. Line(); capitalized. Sentence = client. Sentence. to. Upper. Case() + 'n'; Write out line to socket out. To. Client. write. Bytes(capitalized. Sentence); } } } End of while loop, loop back and wait for another client connection Comp 361 Fall 2003 Chapter 2: Application Layer 75

Chapter 2 outline r 2. 1 Principles of app layer r r protocols 2.

Chapter 2 outline r 2. 1 Principles of app layer r r protocols 2. 2 Web and HTTP 2. 3 FTP 2. 4 Electronic Mail m SMTP, POP 3, IMAP 2. 5 DNS Comp 361 Fall 2003 r 2. 6 Socket programming with TCP r 2. 7 Socket programming with UDP r 2. 8 Building a Web server r 2. 9 Content distribution m Content distribution networks vs. Web Caching Chapter 2: Application Layer 76

Socket programming with UDP: no “connection” between client and server r no handshaking r

Socket programming with UDP: no “connection” between client and server r no handshaking r sender explicitly attaches IP address and port of destination to each packet r server must extract IP address, port of sender from received packet application viewpoint UDP provides unreliable transfer of groups of bytes (“datagrams”) between client and server UDP: transmitted data may be received out of order, or lost Comp 361 Fall 2003 Chapter 2: Application Layer 77

Client/server socket interaction: UDP Server (running on hostid) create socket, port=x, for incoming request:

Client/server socket interaction: UDP Server (running on hostid) create socket, port=x, for incoming request: server. Socket = Datagram. Socket() read request from server. Socket write reply to server. Socket specifying client host address, port number Comp 361 Fall 2003 Client create socket, client. Socket = Datagram. Socket() Create, address (hostid, port=x, send datagram request using client. Socket read reply from client. Socket close client. Socket Chapter 2: Application Layer 78

TCP vs. UDP TCP UDP 1. Socket() r Connection steam established: Data goes in

TCP vs. UDP TCP UDP 1. Socket() r Connection steam established: Data goes in one end of pipe and out the other. Pipe stays open until it is closed. 1. Datagram. Socket() r Data sent as individual packets of bytes. Each packet contains all addressing info. No concept of open “pipe”. 2. Server. Socket() r A special type of socket that sits waiting for a knock from a client to open connection. Leads to handshaking. 2. Comp 361 Fall 2003 No handshaking! r A Datagram. Socket waits to receive each packet Chapter 2: Application Layer 79

Example: Java client (UDP) Client process Input: receives packet (TCP received “byte stream”) Output:

Example: Java client (UDP) Client process Input: receives packet (TCP received “byte stream”) Output: sends packet (TCP sent “byte stream”) client UDP socket Comp 361 Fall 2003 Chapter 2: Application Layer 80

Example: Java client (UDP) import java. io. *; import java. net. *; Create input

Example: Java client (UDP) import java. io. *; import java. net. *; Create input stream Create client socket Translate hostname to IP address using DNS class UDPClient { public static void main(String args[]) throws Exception { Buffered. Reader in. From. User = new Buffered. Reader(new Input. Stream. Reader(System. in)); Datagram. Socket client. Socket = new Datagram. Socket(); Inet. Address IPAddress = Inet. Address. get. By. Name("hostname"); byte[] send. Data = new byte[1024]; byte[] receive. Data = new byte[1024]; String sentence = in. From. User. read. Line(); send. Data = sentence. get. Bytes(); Comp 361 Fall 2003 Chapter 2: Application Layer 81

Example: Java client (UDP), cont. Create datagram with data-to-send, length, IP addr, port Send

Example: Java client (UDP), cont. Create datagram with data-to-send, length, IP addr, port Send datagram to server Datagram. Packet send. Packet = new Datagram. Packet(send. Data, send. Data. length, IPAddress, 9876); client. Socket. send(send. Packet); Datagram. Packet receive. Packet = new Datagram. Packet(receive. Data, receive. Data. length); Read datagram from server client. Socket. receive(receive. Packet); String modified. Sentence = new String(receive. Packet. get. Data()); System. out. println("FROM SERVER: " + modified. Sentence); client. Socket. close(); } } Comp 361 Fall 2003 Chapter 2: Application Layer 82

Example: Java server (UDP) import java. io. *; import java. net. *; Create datagram

Example: Java server (UDP) import java. io. *; import java. net. *; Create datagram socket at port 9876 class UDPServer { public static void main(String args[]) throws Exception { Datagram. Socket server. Socket = new Datagram. Socket(9876); byte[] receive. Data = new byte[1024]; byte[] send. Data = new byte[1024]; while(true) { Create space for received datagram Receive datagram Datagram. Packet receive. Packet = new Datagram. Packet(receive. Data, receive. Data. length); server. Socket. receive(receive. Packet); Comp 361 Fall 2003 Chapter 2: Application Layer 83

Example: Java server (UDP), cont String sentence = new String(receive. Packet. get. Data()); Get

Example: Java server (UDP), cont String sentence = new String(receive. Packet. get. Data()); Get IP addr port #, of sender Inet. Address IPAddress = receive. Packet. get. Address(); int port = receive. Packet. get. Port(); String capitalized. Sentence = sentence. to. Upper. Case(); send. Data = capitalized. Sentence. get. Bytes(); Create datagram to send to client Write out datagram to socket } Datagram. Packet send. Packet = new Datagram. Packet(send. Data, send. Data. length, IPAddress, port); server. Socket. send(send. Packet); } } End of while loop, loop back and wait for another datagram Comp 361 Fall 2003 Chapter 2: Application Layer 84

Chapter 2 outline r 2. 1 Principles of app layer r r protocols 2.

Chapter 2 outline r 2. 1 Principles of app layer r r protocols 2. 2 Web and HTTP 2. 3 FTP 2. 4 Electronic Mail m SMTP, POP 3, IMAP 2. 5 DNS Comp 361 Fall 2003 r 2. 6 Socket programming with TCP r 2. 7 Socket programming with UDP r 2. 8 Building a Web server r 2. 9 Content distribution m Content distribution networks vs. Web Caching Chapter 2: Application Layer 85

Building a simple Web server r handles one HTTP request r accepts the request

Building a simple Web server r handles one HTTP request r accepts the request r parses header r obtains requested file from server’s file system r creates HTTP response message: m header r after creating server, you can request file using a browser (e. g. IE explorer) r see text for details lines + file r sends response to client Comp 361 Fall 2003 Chapter 2: Application Layer 86

Chapter 2 outline r 2. 1 Principles of app layer r r protocols 2.

Chapter 2 outline r 2. 1 Principles of app layer r r protocols 2. 2 Web and HTTP 2. 3 FTP 2. 4 Electronic Mail m SMTP, POP 3, IMAP 2. 5 DNS Comp 361 Fall 2003 r 2. 6 Socket programming with TCP r 2. 7 Socket programming with UDP r 2. 8 Building a Web server r 2. 9 Content distribution m Content distribution networks vs. Web Caching Chapter 2: Application Layer 87

Content distribution networks (CDNs) r The content providers are the origin server in North

Content distribution networks (CDNs) r The content providers are the origin server in North America Content replication r CDN company installs hundreds of CDN servers throughout Internet m in lower-tier ISPs, close to users CDN distribution node CDN customers r CDN replicates its customers’ content in CDN servers. When provider updates content, CDN updates servers Comp 361 Fall 2003 CDN server in S. America CDN server in Europe CDN server in Asia Chapter 2: Application Layer 88

CDN example HTTP request for www. foo. com/sports. html Origin server 1 2 3

CDN example HTTP request for www. foo. com/sports. html Origin server 1 2 3 DNS query for www. cdn. com CDNs authoritative DNS server HTTP request for www. cdn. com/www. foo. com/sports/ruth. gif Nearby CDN server origin server r www. foo. com r distributes HTML r Replaces: http: //www. foo. com/sports. ruth. gif with CDN company r cdn. com r distributes gif files r uses its authoritative DNS server to route redirect requests http: //www. cdn. com/www. foo. com/sports/ruth. gif Comp 361 Fall 2003 Chapter 2: Application Layer 89

More about CDNs routing requests r CDN creates a “map”, indicating distances from leaf

More about CDNs routing requests r CDN creates a “map”, indicating distances from leaf ISPs and CDN nodes r when query arrives at authoritative DNS server: m server determines ISP from which query originates m uses “map” to determine best CDN server Comp 361 Fall 2003 not just Web pages r streaming stored audio/video r streaming real-time audio/video Chapter 2: Application Layer 90

Web Caching vs. CDN Both Web Caching and CDN replicate content r Web Caching:

Web Caching vs. CDN Both Web Caching and CDN replicate content r Web Caching: Content replicated on demand as function of user requests r CDN: Content replicated by content provider Comp 361 Fall 2003 Chapter 2: Application Layer 91

P 2 P As well as retrieving objects from content providers/proxy caches/CDNs it is

P 2 P 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 (P 2 P). For more on P 2 P see textbook. Comp 361 Fall 2003 Chapter 2: Application Layer 92

Chapter 2: Summary Our study of network apps now complete! r application service requirements:

Chapter 2: Summary Our study of network apps now complete! r application service requirements: m reliability, bandwidth, delay r client-server paradigm r Internet transport service model m connection-oriented, reliable: TCP m unreliable, datagrams: UDP Comp 361 Fall 2003 r specific protocols: HTTP m FTP m SMTP, POP, IMAP m DNS r socket programming r content distribution m caches, CDNs m P 2 P m Chapter 2: Application Layer 93

Chapter 2: Summary Most importantly: learned about protocols r typical request/reply message exchange: m

Chapter 2: Summary Most importantly: learned about protocols r typical request/reply message exchange: m m client requests info or service server responds with data, status code r message formats: m m headers: fields giving info about data: info being communicated r control vs. data msgs r r r Comp 361 Fall 2003 in-based, out-of-band centralized vs. decentralized stateless vs. stateful reliable vs. unreliable msg transfer “complexity at network edge” security: authentication m Chapter 2: Application Layer 94