Chapter 2 Application Layer Computer Networking A Top

  • Slides: 81
Download presentation
Chapter 2 Application Layer Computer Networking: A Top Down Approach Featuring the Internet, 3

Chapter 2 Application Layer Computer Networking: A Top Down Approach Featuring the Internet, 3 rd edition. Jim Kurose, Keith Ross Addison-Wesley, July 2004. 2: Application Layer 1

Chapter 2: Application layer r 2. 1 Principles of network applications r 2. 2

Chapter 2: Application layer r 2. 1 Principles of network applications r 2. 2 Web and HTTP r 2. 3 FTP r 2. 4 Electronic Mail m SMTP, POP 3, IMAP r 2. 5 DNS r 2. 6 P 2 P file sharing r 2. 7 Socket programming with TCP r 2. 8 Socket programming with UDP r 2. 9 Building a Web server 2: Application Layer 2

Chapter 2: Application Layer Our goals: r conceptual, implementation aspects of network application protocols

Chapter 2: Application Layer Our goals: r conceptual, implementation aspects of network application protocols m transport-layer service models m client-server paradigm m peer-to-peer paradigm r learn about protocols by examining popular application-level protocols m m HTTP FTP SMTP / POP 3 / IMAP DNS r programming network applications m socket API 2: Application Layer 3

Some network apps r E-mail r Internet telephone r Web r Real-time video r

Some network apps r E-mail r Internet telephone r Web r Real-time video r Instant messaging r Remote login r P 2 P file sharing conference r Massive parallel computing r Multi-user network games r Streaming stored video clips 2: Application Layer 4

Creating a network app Write programs that m m m run on different end

Creating a network app Write programs that m m m run on different end systems and communicate over a network. e. g. , Web: Web server software communicates with browser software No software written for devices in network core m m Network core devices do not function at app layer This design allows for rapid app development application transport network data link physical 2: Application Layer 5

Chapter 2: Application layer r 2. 1 Principles of network applications r 2. 2

Chapter 2: Application layer r 2. 1 Principles of network applications r 2. 2 Web and HTTP r 2. 3 FTP r 2. 4 Electronic Mail m SMTP, POP 3, IMAP r 2. 5 DNS r 2. 6 P 2 P file sharing r 2. 7 Socket programming with TCP r 2. 8 Socket programming with UDP r 2. 9 Building a Web server 2: Application Layer 6

Application architectures r Client-server r Peer-to-peer (P 2 P) r Hybrid of client-server and

Application architectures r Client-server r Peer-to-peer (P 2 P) r Hybrid of client-server and P 2 P 2: Application Layer 7

Client-server architecture server: m m m always-on host permanent IP address server farms for

Client-server architecture server: m m m always-on host permanent IP address server farms for scaling clients: m m communicate with server may be intermittently connected may have dynamic IP addresses do not communicate directly with each other 2: Application Layer 8

Pure P 2 P architecture r no always on server r arbitrary end systems

Pure P 2 P architecture r no always on server r arbitrary end systems directly communicate r peers are intermittently connected and change IP addresses r example: Gnutella Highly scalable But difficult to manage 2: Application Layer 9

Hybrid of client-server and P 2 P Napster m File transfer P 2 P

Hybrid of client-server and P 2 P Napster m File transfer P 2 P m File search centralized: • Peers register content at central server • Peers query same central server to locate content Instant messaging m Chatting between two users is P 2 P m Presence detection/location centralized: • User registers its IP address with central server when it comes online • User contacts central server to find IP addresses of buddies 2: Application Layer 10

Processes communicating Process: program running within a host. r within same host, two processes

Processes communicating Process: program running within a host. r within same host, two processes communicate using inter-process communication (defined by OS). r processes in different hosts communicate by exchanging messages Client process: process that initiates communication Server process: process that waits to be contacted r Note: applications with P 2 P architectures have client processes & server processes 2: Application Layer 11

Sockets r process sends/receives messages to/from its socket r socket analogous to door m

Sockets r process sends/receives messages to/from its socket r socket analogous to door m m sending process shoves message out door sending process relies on transport infrastructure on other side of door which brings message to socket at receiving process host or server process controlled by app developer process socket TCP with buffers, variables Internet TCP with buffers, variables controlled by OS r API: (1) choice of transport protocol; (2) ability to fix a few parameters (lots more on this later) 2: Application Layer 12

Addressing processes r For a process to receive messages, it must have an identifier

Addressing processes r For a process to receive messages, it must have an identifier r A host has a unique 32 bit IP address r Q: does the IP address of the host on which the process runs suffice for identifying the process? r Answer: No, many processes can be running on same host r Identifier includes both the IP address and port numbers associated with the process on the host. r Example port numbers: m m HTTP server: 80 Mail server: 25 r More on this later 2: Application Layer 13

App-layer protocol defines r Types of messages exchanged, e. g. , request & response

App-layer protocol defines r Types of messages exchanged, e. g. , request & response messages r Syntax of message types: what fields in messages & how fields are delineated r Semantics of the fields, ie, meaning of information in fields r Rules for when and how processes send & respond to messages Public-domain protocols: r defined in RFCs r allows for interoperability r eg, HTTP, SMTP Proprietary protocols: r eg, Ka. Za. A 2: Application Layer 14

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 telephony, interactive games) require low delay to be “effective” Bandwidth 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 2: Application Layer 15

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 instant messaging loss-tolerant no loss elastic audio: 5 kbps-1 Mbps video: 10 kbps-5 Mbps same as above few kbps up elastic Application yes, few secs yes, 100’s msec yes and no 2: Application Layer 16

Internet transport protocols services TCP service: r connection-oriented: setup r r required between client

Internet transport protocols services TCP service: r connection-oriented: setup r r required between client and server processes reliable transport between sending and receiving process flow control: sender won’t overwhelm receiver congestion control: throttle sender when network overloaded does not provide: timing, minimum bandwidth guarantees UDP service: r unreliable data transfer between sending and receiving process r does not provide: connection setup, reliability, flow control, congestion control, timing, or bandwidth guarantee Q: why bother? Why is there a UDP? 2: Application Layer 17

Internet apps: application, transport protocols Application e-mail remote terminal access Web file transfer streaming

Internet apps: application, transport protocols Application e-mail remote terminal access Web file transfer streaming multimedia Internet telephony Application layer protocol Underlying transport protocol SMTP [RFC 2821] Telnet [RFC 854] HTTP [RFC 2616] FTP [RFC 959] proprietary (e. g. Real. Networks) proprietary (e. g. , Dialpad) TCP TCP TCP or UDP typically UDP 2: Application Layer 18

Chapter 2: Application layer r 2. 1 Principles of network applications m m app

Chapter 2: Application layer r 2. 1 Principles of network applications m m app architectures app requirements r 2. 2 Web and HTTP r 2. 4 Electronic Mail m SMTP, POP 3, IMAP r 2. 5 DNS r 2. 6 P 2 P file sharing r 2. 7 Socket programming with TCP r 2. 8 Socket programming with UDP r 2. 9 Building a Web server 2: Application Layer 19

Web and HTTP First some jargon r Web page consists of objects r Object

Web and HTTP First some jargon r Web page consists of objects r Object can be HTML file, JPEG image, Java applet, audio file, … r Web page consists of base HTML-file which includes several referenced objects r Each object is addressable by a URL r Example URL: www. someschool. edu/some. Dept/pic. gif host name path name 2: Application Layer 20

HTTP overview HTTP: hypertext transfer protocol r Web’s application layer protocol r client/server model

HTTP overview 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 HT TP req ues PC running HT t TP res Explorer pon se st ue q e r P nse Server T o p running HT es r P T Apache Web HT server Mac running Navigator 2: Application Layer 21

HTTP overview (continued) Uses TCP: r client initiates TCP connection (creates socket) to server,

HTTP overview (continued) Uses TCP: r client initiates TCP connection (creates socket) to server, port 80 r server accepts TCP connection from client r HTTP messages (applicationlayer protocol messages) exchanged between browser (HTTP client) and Web server (HTTP server) r TCP connection closed 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 2: Application Layer 22

HTTP connections Nonpersistent HTTP r At most one object is sent over a TCP

HTTP connections Nonpersistent HTTP r At most one object is sent over a TCP connection. r HTTP/1. 0 uses nonpersistent HTTP Persistent HTTP r Multiple objects can be sent over single TCP connection between client and server. r HTTP/1. 1 uses persistent connections in default mode 2: Application Layer 23

Nonpersistent HTTP (contains text, Suppose user enters URL references to 10 www. some. School.

Nonpersistent HTTP (contains text, Suppose user enters URL references to 10 www. some. School. edu/some. Department/home. index jpeg images) 1 a. HTTP client initiates TCP connection to HTTP server (process) at www. some. School. edu on port 80 2. HTTP client sends HTTP request message (containing URL) into TCP connection socket. Message indicates that client wants object some. Department/home. index 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, and sends message into its socket time 2: Application Layer 24

Nonpersistent HTTP (cont. ) 4. HTTP server closes TCP 5. HTTP client receives response

Nonpersistent HTTP (cont. ) 4. HTTP server closes TCP 5. HTTP client receives response connection. message containing html file, displays html. Parsing html file, finds 10 referenced jpeg objects time 6. Steps 1 -5 repeated for each of 10 jpeg objects 2: Application Layer 25

Response time modeling Definition of RRT: time to send a small packet to travel

Response time modeling Definition of RRT: time to send a small packet to travel from client to server and back. Response time: r one RTT to initiate TCP connection r one RTT for HTTP request and first few bytes of HTTP response to return r file transmission time total = 2 RTT+transmit time initiate TCP connection RTT request file RTT file received time to transmit file time 2: Application Layer 26

Persistent HTTP Nonpersistent HTTP issues: r requires 2 RTTs per object r OS must

Persistent HTTP Nonpersistent HTTP issues: r requires 2 RTTs per object r OS must work and allocate host resources for each TCP connection r but browsers often open parallel TCP connections to fetch referenced objects Persistent HTTP r server leaves connection open after sending response r subsequent HTTP messages between same client/server are sent over connection Persistent without pipelining: r client issues new request only when previous response has been received r one RTT for each referenced object Persistent with pipelining: r default in HTTP/1. 1 r client sends requests as soon as it encounters a referenced object r as little as one RTT for all the referenced objects 2: Application Layer 27

HTTP request message r two types of HTTP messages: request, response r HTTP request

HTTP request message 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. 1 Host: www. someschool. edu User-agent: Mozilla/4. 0 header Connection: close lines Accept-language: fr Carriage return, line feed indicates end of message (extra carriage return, line feed) 2: Application Layer 28

HTTP request message: general format 2: Application Layer 29

HTTP request message: general format 2: Application Layer 29

Method types HTTP/1. 0 r GET r POST r HEAD m asks server to

Method types HTTP/1. 0 r GET r POST r HEAD m asks server to leave requested object out of response (for debugging) HTTP/1. 1 r GET, POST, HEAD r PUT m uploads file in entity body to path specified in URL field r DELETE m deletes file specified in the URL field 2: Application Layer 30

HTTP response message status line (protocol status code status phrase) header lines data, e.

HTTP response message status line (protocol status code status phrase) header lines data, e. g. , requested HTML file HTTP/1. 1 200 OK Connection close Date: Thu, 06 Aug 1998 12: 00: 15 GMT Server: Apache/1. 3. 0 (Unix) Last-Modified: Mon, 22 Jun 1998 …. . . Content-Length: 6821 Content-Type: text/html data data. . . 2: Application Layer 31

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 2: Application Layer 32

User-server state: cookies Many major Web sites use cookies Four components: 1) cookie header

User-server state: cookies Many major Web sites use cookies Four components: 1) cookie header line in the HTTP response message 2) cookie header line in HTTP request message 3) cookie file kept on user’s host and managed by user’s browser 4) back-end database at Web site Example: m m m Susan access Internet always from same PC She visits a specific ecommerce site for first time When initial HTTP requests arrives at site, site creates a unique ID and creates an entry in backend database for ID 2: Application Layer 33

Cookies: keeping “state” (cont. ) client ebay: 8734 Cookie file amazon: 1678 ebay: 8734

Cookies: keeping “state” (cont. ) client ebay: 8734 Cookie file amazon: 1678 ebay: 8734 usual http request msg usual http response + Set-cookie: 1678 usual http request msg cookie: 1678 usual http response msg Cookie file amazon: 1678 ebay: 8734 cookiespecific action ss acce ac ce one week later: e n server da try i tab n b creates ID as ac e ke nd 1678 for user ss Cookie file server usual http request msg cookie: 1678 usual http response msg cookiespectific action 2: Application Layer 34

Cookies (continued) What cookies can bring: r authorization r shopping carts r recommendations r

Cookies (continued) What cookies can bring: r authorization r shopping carts r recommendations r user session state (Web e-mail) aside Cookies and privacy: r cookies permit sites to learn a lot about you r you may supply name and e-mail to sites r search engines use redirection & cookies to learn yet more r advertising companies obtain info across sites 2: Application Layer 35

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 cache r browser sends all HTTP requests to cache m m object in cache: cache returns object else cache requests object from origin server, then returns object to client origin server HT client. HTTP TP req Proxy server ues t res pon se t s ue q re P nse o T p HT es r TP T H client est u q e Pr T nse o p HT res P T HT origin server 2: Application Layer 36

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

More about Web caching r Cache acts as both client and server r Typically cache is installed by ISP (university, company, residential ISP) Why Web caching? r Reduce response time for client request. r Reduce traffic on an institution’s access link. r Internet dense with caches enables “poor” content providers to effectively deliver content (but so does P 2 P file sharing) 2: Application Layer 37

Caching example Assumptions r average object size = 100, 000 bits r avg. request

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

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

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

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

Caching example (cont) 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 avg delay = Internet delay + access delay + LAN delay =. 6*(2. 01) secs + milliseconds < 1. 4 secs 1. 5 Mbps access link institutional network 10 Mbps LAN institutional cache 2: Application Layer 40

Conditional GET r Goal: don’t send object if cache has up-to-date cached version r

Conditional GET r Goal: don’t send object if cache has up-to-date cached version r cache: specify date of cached copy in HTTP request If-modified-since: <date> r server: response contains no object if cached copy is up-to -date: HTTP/1. 0 304 Not Modified server cache HTTP request msg If-modified-since: <date> HTTP response object not modified HTTP/1. 0 304 Not Modified HTTP request msg If-modified-since: <date> HTTP response object modified HTTP/1. 0 200 OK <data> 2: Application Layer 41

Chapter 2: Application layer r 2. 1 Principles of network applications r 2. 2

Chapter 2: Application layer r 2. 1 Principles of network applications r 2. 2 Web and HTTP r 2. 3 FTP r 2. 4 Electronic Mail m SMTP, POP 3, IMAP r 2. 5 DNS r 2. 6 P 2 P file sharing r 2. 7 Socket programming with TCP r 2. 8 Socket programming with UDP r 2. 9 Building a Web server 2: Application Layer 42

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 2: Application Layer 43

FTP: separate control, data connections TCP control connection port 21 r FTP client contacts

FTP: separate control, data connections TCP control connection port 21 r FTP client contacts FTP r r server at port 21, specifying TCP as transport protocol Server obtains authorization over control connection Client browses remote directory by sending commands over control connection. When server receives a command for a file transfer, the server opens a TCP data connection to client After transferring one file, server closes connection. FTP client TCP data connection port 20 FTP server r Server opens a second TCP data connection to transfer another file. r Control connection: “out of band” r FTP server maintains “state”: current directory, earlier authentication 2: Application Layer 44

FTP commands, responses Sample commands: Sample return codes r sent as ASCII text over

FTP commands, responses Sample commands: Sample return codes r sent as ASCII text over r status code and phrase (as control channel r USER username r PASS password r LIST return list of file in r r current directory r RETR filename retrieves r r STOR filename stores r (gets) file (puts) file onto remote host in HTTP) 331 Username OK, password required 125 data connection already open; transfer starting 425 Can’t open data connection 452 Error writing file 2: Application Layer 45

Chapter 2: Application layer r 2. 1 Principles of network applications r 2. 2

Chapter 2: Application layer r 2. 1 Principles of network applications r 2. 2 Web and HTTP r 2. 3 FTP r 2. 4 Electronic Mail m SMTP, POP 3, IMAP r 2. 5 DNS r 2. 6 P 2 P file sharing r 2. 7 Socket programming with TCP r 2. 8 Socket programming with UDP r 2. 9 Building a Web server 2: Application Layer 46

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

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

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

Electronic Mail: mail servers user agent Mail Servers r mailbox contains incoming messages for user r message queue of outgoing (to be sent) mail messages r SMTP protocol between mail servers to send email messages m client: sending mail server m “server”: receiving mail server SMTP mail server user agent SMTP user agent mail server user agent 2: Application Layer 48

Electronic Mail: SMTP [RFC 2821] r uses TCP to reliably transfer email message from

Electronic Mail: SMTP [RFC 2821] r uses TCP to reliably transfer email message 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 2: Application Layer 49

Scenario: Alice sends message to Bob 4) SMTP client sends Alice’s message over the

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 2: Application Layer 50

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 2: Application Layer 51

SMTP: final words r SMTP uses persistent connections r SMTP requires message (header &

SMTP: final words r SMTP uses persistent connections r SMTP requires message (header & body) to be in 7 bit ASCII r SMTP server uses CRLF to determine end of message Comparison with HTTP: r HTTP: pull r SMTP: push r both have ASCII command/response interaction, status codes r HTTP: each object encapsulated in its own response msg r SMTP: multiple objects sent in multipart msg 2: Application Layer 52

Mail message format SMTP: protocol for exchanging email msgs RFC 822: standard for text

Mail message format SMTP: protocol for exchanging email msgs RFC 822: standard for text message format: r header lines, e. g. , m m m To: From: Subject: header blank line body r body m the “message”, ASCII characters only 2: Application Layer 53

Message format: multimedia extensions r MIME: multimedia mail extension, RFC 2045, 2056 r additional

Message format: multimedia extensions r MIME: 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 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 2: Application Layer 54

Mail access protocols user agent SMTP sender’s mail server access protocol user agent receiver’s

Mail access protocols user agent SMTP sender’s mail server access protocol 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 3: Post Office Protocol – Version 3 [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. 2: Application Layer 55

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

POP 3 protocol authorization phase r client commands: m m user: declare username pass: password r server responses m m +OK -ERR transaction phase, client: r list: list message numbers r retr: retrieve message by number r dele: delete r quit S: C: S: +OK POP 3 server ready user bob +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 2: Application Layer 56 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 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 2: Application Layer 57

Chapter 2: Application layer r 2. 1 Principles of network applications r 2. 2

Chapter 2: Application layer r 2. 1 Principles of network applications r 2. 2 Web and HTTP r 2. 3 FTP r 2. 4 Electronic Mail m SMTP, POP 3, IMAP r 2. 5 DNS r 2. 6 P 2 P file sharing r 2. 7 Socket programming with TCP r 2. 8 Socket programming with UDP r 2. 9 Building a Web server 2: Application Layer 58

DNS: Domain Name System People: many identifiers: m SSN, name, passport # Internet hosts,

DNS: Domain Name System People: many identifiers: m SSN, name, passport # Internet hosts, routers: m m IP address (32 bit) used for addressing datagrams “name”, e. g. , www. yahoo. com - used by humans Q: map between IP addresses and name ? Domain Name System: r distributed database implemented in hierarchy of many name servers r application-layer protocol host, routers, name servers to communicate to resolve names (address/name translation) m core Internet function, implemented as application -layer protocol 2: Application Layer 59

DNS services r Hostname to IP address translation r Host aliasing m Canonical and

DNS services r Hostname to IP address translation r Host aliasing m Canonical and alias names r Mail server aliasing r Load distribution m Replicated Web servers: set of IP addresses for one canonical name Why not centralize DNS? r single point of failure r traffic volume r distant centralized database r maintenance doesn’t scale! 2: Application Layer 60

Distributed, Hierarchical Database Root DNS Servers com DNS servers yahoo. com amazon. com DNS

Distributed, Hierarchical Database Root DNS Servers com DNS servers yahoo. com amazon. com DNS servers org DNS servers pbs. org DNS servers edu DNS servers poly. edu umass. edu DNS servers Client wants IP for www. amazon. com; 1 st approx: r Client queries a root server to find com DNS server r Client queries com DNS server to get amazon. com DNS server r Client queries amazon. com DNS server to get IP address for www. amazon. com 2: Application Layer 61

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 a Verisign, Dulles, VA c Cogent, Herndon, VA (also Los Angeles) d U Maryland College Park, MD k RIPE London (also Amsterdam, g US Do. D Vienna, VA Frankfurt) Stockholm (plus 3 i Autonomica, h ARL Aberdeen, MD other locations) j Verisign, ( 11 locations) m WIDE Tokyo e NASA Mt View, CA f Internet Software C. Palo Alto, CA (and 17 other locations) b USC-ISI Marina del Rey, CA l ICANN Los Angeles, CA 13 root name servers worldwide 2: Application Layer 62

TLD and Authoritative Servers r Top-level domain (TLD) servers: responsible for com, org, net,

TLD and Authoritative Servers r Top-level domain (TLD) servers: responsible for com, org, net, edu, etc, and all top-level country domains uk, fr, ca, jp. m Network solutions maintains servers for com TLD m Educause for edu TLD r Authoritative DNS servers: organization’s DNS servers, providing authoritative hostname to IP mappings for organization’s servers (e. g. , Web and mail). m Can be maintained by organization or service provider 2: Application Layer 63

Local Name Server r Does not strictly belong to hierarchy r Each ISP (residential

Local Name Server r Does not strictly belong to hierarchy r Each ISP (residential ISP, company, university) has one. m Also called “default name server” r When a host makes a DNS query, query is sent to its local DNS server m Acts as a proxy, forwards query into hierarchy. 2: Application Layer 64

Example root DNS server 2 r Host at cis. poly. edu wants IP address

Example root DNS server 2 r Host at cis. poly. edu wants IP address for gaia. cs. umass. edu 3 4 TLD DNS server 5 local DNS server dns. poly. edu 1 8 requesting host 7 6 authoritative DNS server dns. cs. umass. edu cis. poly. edu gaia. cs. umass. edu 2: Application Layer 65

Recursive queries recursive query: 2 r puts burden of name resolution on contacted name

Recursive queries recursive query: 2 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” root DNS server 3 7 local DNS server dns. poly. edu 1 6 TLD DNS serve 5 4 8 requesting host authoritative DNS server dns. cs. umass. edu cis. poly. edu gaia. cs. umass. edu 2: Application Layer 66

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 m TLD servers typically cached in local name servers • Thus root name servers not often visited r update/notify mechanisms under design by IETF m RFC 2136 m http: //www. ietf. org/html. charters/dnsind-charter. html 2: Application Layer 67

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=CNAME m name is alias name for some “canonical” (the real) name www. ibm. com is really r Type=NS servereast. backup 2. ibm. com m name is domain (e. g. m value is canonical name foo. com) m value is IP address of r Type=MX authoritative name server m value is name of mailserver for this domain associated with name 2: Application Layer 68

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 2: Application Layer 69

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 2: Application Layer 70

Inserting records into DNS r Example: just created startup “Network Utopia” r Register name

Inserting records into DNS r Example: just created startup “Network Utopia” r Register name networkuptopia. com at a registrar (e. g. , Network Solutions) m m Need to provide registrar with names and IP addresses of your authoritative name server (primary and secondary) Registrar inserts two RRs into the com TLD server: (networkutopia. com, dns 1. networkutopia. com, NS) (dns 1. networkutopia. com, 212. 1, A) r Put in authoritative server Type A record for www. networkuptopia. com and Type MX record for mail. networkutopia. com r How do people get the IP address of your Web site? 2: Application Layer 71

Chapter 2: Application layer r 2. 1 Principles of network applications m m app

Chapter 2: Application layer r 2. 1 Principles of network applications m m app architectures app requirements r 2. 2 Web and HTTP r 2. 4 Electronic Mail m SMTP, POP 3, IMAP r 2. 5 DNS r 2. 6 P 2 P file sharing r 2. 7 Socket programming with TCP r 2. 8 Socket programming with UDP r 2. 9 Building a Web server 2: Application Layer 72

P 2 P file sharing Example r Alice runs P 2 P client application

P 2 P file sharing Example r Alice runs P 2 P client application on her notebook computer r Intermittently connects to Internet; gets new IP address for each connection r Asks for “Hey Jude” r Application displays other peers that have copy of Hey Jude. r Alice chooses one of the peers, Bob. r File is copied from Bob’s PC to Alice’s notebook: HTTP r While Alice downloads, other users uploading from Alice. r Alice’s peer is both a Web client and a transient Web server. All peers are servers = highly scalable! 2: Application Layer 73

P 2 P: centralized directory original “Napster” design 1) when peer connects, it informs

P 2 P: centralized directory original “Napster” design 1) when peer connects, it informs central server: m m Bob centralized directory server 1 peers IP addresbs content 2) Alice queries for “Hey Jude” 3) Alice requests file from Bob 1 3 1 2 1 Alice 2: Application Layer 74

P 2 P: problems with centralized directory r Single point of failure r Performance

P 2 P: problems with centralized directory r Single point of failure r Performance bottleneck r Copyright infringement file transfer is decentralized, but locating content is highly decentralized 2: Application Layer 75

Query flooding: Gnutella r fully distributed m no central server r public domain protocol

Query flooding: Gnutella r fully distributed m no central server r public domain protocol r many Gnutella clients implementing protocol overlay network: graph r edge between peer X and Y if there’s a TCP connection r all active peers and edges is overlay net r Edge is not a physical link r Given peer will typically be connected with < 10 overlay neighbors 2: Application Layer 76

Gnutella: protocol r Query message sent over existing TCP connections r peers forward Query

Gnutella: protocol r Query message sent over existing TCP connections r peers forward Query message ry e r Query. Hit it Qu H ry sent over e Qu reverse Query path File transfer: HTTP Query. Hit Qu ery Query. Hit Scalability: limited scope flooding Qu er y 2: Application Layer 77

Gnutella: Peer joining Joining peer X must find some other peer in Gnutella network:

Gnutella: Peer joining Joining peer X must find some other peer in Gnutella network: use list of candidate peers 2. X sequentially attempts to make TCP with peers on list until connection setup with Y 3. X sends Ping message to Y; Y forwards Ping message. 4. All peers receiving Ping message respond with Pong message 5. X receives many Pong messages. It can then setup additional TCP connections Peer leaving: see homework problem! 1. 2: Application Layer 78

Exploiting heterogeneity: Ka. Za. A r Each peer is either a group leader or

Exploiting heterogeneity: Ka. Za. A r Each peer is either a group leader or assigned to a group leader. m m TCP connection between peer and its group leader. TCP connections between some pairs of group leaders. r Group leader tracks the content in all its children. 2: Application Layer 79

Ka. Za. A: Querying r Each file has a hash and a descriptor r

Ka. Za. A: Querying r Each file has a hash and a descriptor r Client sends keyword query to its group leader r Group leader responds with matches: m For each match: metadata, hash, IP address r If group leader forwards query to other group leaders, they respond with matches r Client then selects files for downloading m HTTP requests using hash as identifier sent to peers holding desired file 2: Application Layer 80

Kazaa tricks r Limitations on simultaneous uploads r Request queuing r Incentive priorities r

Kazaa tricks r Limitations on simultaneous uploads r Request queuing r Incentive priorities r Parallel downloading 2: Application Layer 81