Apache Web. server ... Server: Apache/2.0.52 (CentOS)\r\n ..... e.g., key = h(“Led Zeppelin IV”); this is why they call it a distributed “hash” table.




1.Chapter 8 Application Layer based on: Computer Networking: A Top Down Approach , 5 th edition. Jim Kurose, Keith Ross Addison-Wesley, April 2009. 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. Thanks and enjoy! JFK/KWR All material copyright 1996-2010 J.F Kurose and K.W. Ross, All Rights Reserved Application 2- 1

2.Application Layer 8- 2 Chapter 8: Application Layer Our goals: conceptual / implementation aspects of network application protocols transport-layer service models client-server paradigm peer-to-peer paradigm learn about application-layer protocols by looking at examples: HTTP (web) DNS (web addressing) interface to transport layer

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

4.Application Layer 8- 4 App-layer protocol defines Types of messages exchanged, e.g. request & response messages Syntax of message types: what fields in messages & where fields are located Semantics of the fields, i.e. meaning of information in fields Rules for when and how processes send & respond to messages 2TYPES OF PROTOCOLS: Public-domain protocols: defined in RFCs enable interoperability eg: HTTP, SMTP, SIP Proprietary protocols: owned by a company eg: Skype, Messenger

5.Application Layer 8- 5 Client / Server concepts Hardware view Process / interaction view Client-Server architecture Peer-to-Peer architecture

6.Application Layer 8- 6 Client Hosts /Server Hosts server host : always-on host permanent IP address server farms for scaling client host (=workstation): located next to user may be intermittently connected may have dynamic IP address Note : Both client and server are called hosts

7.Application Layer 8- 7 Process: program running within a host. processes in different hosts communicate by exchanging messages when processes cooperate for a common purpose, there must be one of them that initiates the common work Sends the first message Client process : process that initiates communication Server process : process that waits to be contacted by client Note : Client process may run on a client host or on a server host Server process may run on a client host (see Peer to Peer architecture) Client Process/Server Process

8.Application Layer 8- 8 Process Interaction Scenario server process : waits all the time for work its IP address must be known to the client process before interaction starts client process: initiates interaction with server process when needs its help if server process agrees : the two processes exchange messages the messages enable them to cooperate to get the work done Note : Server host usually runs several server processes in parallel Client process 1 Client process 2 Server proc. 1 Server proc. 2

9.Application Layer 8- 9 Client-Server architecture server process : runs on server host only the server host’s IP address is publicly known client process: runs on client host ( usually) or on a server host example: in e-mail appl. the sender mail server runs a client process , while the receiving MS runs a server process

10.Pure P2P architecture no always-on server arbitrary end systems directly communicate peers are intermittently connected and change IP addresses highly scalable but difficult to manage peer-peer Application 2- 10

11.Hybrid of client-server and P2P Skype voice-over-IP P2P application centralized server: finding address of remote party: client-client connection: direct (not through server) Instant messaging chatting btw. two users is P2P centralized service: client presence detection/location user registers its IP address with central server when it comes online user contacts central server to find IP addresses of buddies Application 2- 11 data initialization C-S C-S P2P P2P

12.What transport service does an app need? Data loss some apps (e.g., file transfer, telnet) require 100% reliable data transfer other apps (e.g., audio) can tolerate some loss Timing some apps (e.g., Internet telephony, interactive games) require low delay to be “effective” Throughput some apps (e.g., multimedia) require ≥ minimum amount of throughput to be “effective” other apps (“elastic apps”) make use of whatever throughput they get Security encryption, data integrity, … Application 2- 12

13.Application Layer 8- 13 Transport service requirements of common apps Application file transfer e-mail Web documents real-time audio/video stored audio/video interactive games instant messaging Data loss no loss no loss no loss loss-tolerant loss-tolerant loss-tolerant no loss Bandwidth elastic elastic elastic audio: 5kbps-1Mbps video:10kbps-5Mbps same as above few kbps up elastic Time Sensitive no no no yes, 100’s msec yes, a few secs yes, 100’s msec yes and no

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

15.Application Layer 8- 15 HTTP overview HTTP: hypertext transfer protocol Web’s application layer protocol client/server model client : browser that requests, receives and “displays” Web objects server : Web server that sends objects in response to requests HTTP 1.0 : RFC 1945 HTTP 1.1 : RFC 2616 PC running Explorer Server running Apache Web server Mac running Navigator HTTP request HTTP request HTTP response HTTP response Note : Different H/W and S/W use the same protocol

16.Application Layer 8- 16 HTTP overview (continued) HTTP uses TCP: client initiates TCP connection (creates socket) to server port 80 (WKP) server accepts TCP connection from client HTTP messages (application-layer protocol messages) exchanged between browser (HTTP client) and Web server (HTTP server) TCP connection closed HTTP is “stateless” HTTP keeps no information about past client requests BUT, cookies allow Web server to run stateful applications Protocols that maintain “state” are complex! past history (state) must be maintained if server/client crashes, their views of “state” may be inconsistent, must be reconciled note

17.Application Layer 8- 17 HTTP connections Nonpersistent HTTP At most one object sent over a TCP connection. is default in HTTP/1.0 use Keep Alive header to force Persistent mode Disadvantages : wastes RTT per message adds overhead packets stays most of the time in Slow Start Cong.Ctrl Partial help: use parallel connections Persistent HTTP Multiple objects sent over single TCP connection between client and server. Last request contains the Close Connection header is default in HTTP/1.1 Persistent w. Pipelining Send requests for referenced objects one after the other, without waiting for response to previous requests saves another RTT per object

18.GET /index.html HTTP/1.1 Host: www-net.cs.umass.edu User-Agent: Firefox/3.6.10 Accept: text/ html,application / xhtml+xml Accept-Language: en- us,en;q =0.5 Accept-Encoding: gzip,deflate Accept- Charset : ISO-8859-1,utf-8;q=0.7 Keep-Alive: 115 Connection: keep-alive Connection: Close carriage return, line feed at start of line indicates end of header lines HTTP request message two types of HTTP messages: request , response HTTP request message: ASCII (human-readable format) request line (GET, POST, HEAD commands) header lines Application 2- 18 carriage return character line-feed character

19.HTTP request message: general format Application 2- 19 request line header lines body

20.Uploading form input POST method: web page often includes form input input is uploaded to server in entity body GET method with URL parameters: uses GET method input is uploaded in URL field of request line: www.somesite.com/animalsearch?monkeys&banana Application 2- 20

21.Application Layer 8- 21 Methods HTTP/1.0 GET POST HEAD asks server to leave requested object out of response Used for: debugging troubleshooting HTTP/1.1 GET, POST, HEAD PUT uploads file in the entity body to the path specified in URL field DELETE deletes file specified in the URL field

22.HTTP response message status line (protocol status code status phrase) header lines data, e.g., requested HTML file Application 2- 22 HTTP/1.1 200 OK Date: Sun, 26 Sep 2010 20:09:20 GMT Server: Apache/2.0.52 ( CentOS ) Last-Modified: Tue, 30 Oct 2007 17:00:02 GMT ETag : "17dc6-a5c-bf716880" Accept-Ranges: bytes Content-Length: 2652 Connection: Close Content-Type : text/ html;charset =ISO-8859-1 data data data data data ...

23.Application Layer 8- 23 HTTP response status codes 200 OK request succeeded, requested object later in this message 301 Moved Permanently requested object moved, new location specified later in this message (Location:) 400 Bad Request request message not understood by server 404 Not Found requested document not found on this server 505 HTTP Version Not Supported In first line of the response message. A few examples of status codes:

24.Trying out HTTP (client side) for yourself 1. Telnet to your favorite Web server: 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 telnet cis.poly.edu 80 2. type in a GET HTTP request: GET /~ross/ HTTP/1.1 Host: cis.poly.edu 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! Application 2- 24 (or use wireshark!)

25.Application Layer 8- 25 User-server “state”: cookies Many major Web sites use cookies Four components: 1) the HTTP server sends response message with a ‘ Set-Cookie:’ header 2) user’s browser puts the cookie header content in cookie file on user’s host, labeled with server name 3) next request message to this server will contain Cookie: header with the same value 4) cookie points to database record at server site Example: Susan accesses Internet always from same PC She visits a specific e-commerce site for first time When initial HTTP requests arrives at site, site creates a unique ID and an entry in backend database for that ID The ID is the cookie between them

26.Cookies: keeping “state” (cont.) client server usual http response msg usual http response msg cookie file one week later: usual http request msg cookie: 1678 cookie- specific action access ebay 8734 usual http request msg Amazon server creates ID 1678 for user create entry usual http response Set-cookie: 1678 ebay 8734 amazon 1678 usual http request msg cookie: 1678 cookie- specific action access ebay 8734 amazon 1678 backend database Application 2- 26

27.Application Layer 8- 27 Cookies (continued) What cookies can bring: user session state (e.g. in Web e-mail) user identification on given workstation shopping carts recommendations Cookies and privacy: cookies permit sites to learn a lot about you you may supply name and e-mail to sites advertising companies obtain info across sites from inserted banner adds info collected by the advertizing server there are regulatory restrictions on releasing it aside

28.Application Layer 8- 28 Web cache (proxy server) user sets up browser to access Web via proxy browser sends all HTTP requests to proxy IF object in the proxy’s cache: proxy returns object ELSE proxy requests object from origin server, then returns object to client and keeps file in its cache Note : user’s browser has a private cache on its host. Goal: satisfy client request without involving origin server client Proxy Server (web cache) client HTTP request HTTP request HTTP response HTTP response HTTP request HTTP response origin server origin server

29.Application Layer 8- 29 More about Web caching proxy acts as HTTP client and server Typically proxy is installed by ISP or a user organization. Caching advantages Reduce response time for client request. Reduce traffic on an institution’s access link. Internet dense with proxies enables “poor” content providers to effectively deliver content Qn :what is the main problem with caching as described? Caching rules Origin server may : forbid caching allow caching by private cache only (privacy) Origin server sends: Last Modified date/time Expiration time or Max. Age Proxy should respect age and other restrictions

30.Caching example (1) assumptions average object size = 100,000 bits avg. request rate from institution’s browsers to origin servers = 15/sec delay from institutional router to any origin server and back to router = 2 sec consequences utilization on LAN = 15% utilization on access link = 100% total delay = Internet delay + access link delay + LAN delay = 2 sec + minutes + milliseconds origin servers public Internet institutional network 10 Mbps LAN 1.5 Mbps access link institutional cache Application 2- 30

31.Caching example (2) possible solution increase bandwidth of access link to, say, 10 Mbps consequence utilization on LAN = 15% utilization on access link = 15% Total delay = Internet delay + access delay + LAN delay = 2 sec + msecs + msecs often a costly upgrade origin servers public Internet institutional network 10 Mbps LAN 10 Mbps access link institutional cache Application 2- 31

32.Caching example (3) possible solution: install cache consequence suppose hit rate is 0.4 40% requests will be satisfied almost immediately 60% requests satisfied by origin server utilization of access link reduced to 60%, resulting in negligible delays (say 10 msec) total avg delay = Internet delay + access delay + LAN delay = .6*(2.01) secs + .4*milliseconds < 1.4 secs origin servers public Internet institutional network 10 Mbps LAN 1.5 Mbps access link institutional cache Application 2- 32

33.Application Layer 8- 33 Conditional GET Goal: don’t send object if proxy has up-to-date cached version used if cacheability conditions or data are missing proxy specifies date of cached copy in HTTP request header: server sends short response if cached copy is up-to-date: (see Case 1 on this slide) HTTP/1.0 304 Not Modified (contains no object) If-modified-since: <date> proxy server HTTP request msg If-modified-since: <date> HTTP response HTTP/1.0 304 Not Modified object not modified Case 1 HTTP request msg If-modified-since: <date> HTTP response HTTP/1.0 200 OK <data> object modified proxy server Case 2

34.Application Layer 8- 34 Legacy Internet Applications Telnet Remote terminal Enables user to enter line commands to remote host Remote host returns display to user. characters sent one by one and echoed on display sets char, encoding rules Client-Server Email Mail client on user’s host e.g. Outlook User mailbox on his Server Msg prepared on client, sent to user’s Mail Server (MS) MS sends to dest. MS using SMTP (a PUSH protocol) dest. MS stores msg in mailbox User collects msg using PULL protocol (POP3 or IMAP) Webmail Client functionality on Server User has an HTTP GUI terminal FTP File transfer and remote control of a file server Uses Telnet encoding rules

35.Application Layer 8- 35 DNS: Domain Name System People: many identifiers: SSN, name, passport # Internet hosts, routers: IP address (32 bit) - used for addressing datagrams (packets) – good for routers “name”, e.g., www.yahoo.com – good for human use Q: map between name and IP addresses ? Domain Name System: Distributed database implemented in hierarchy of many name servers application-layer protocol host, routers, name servers communicate to resolve names (name-to-address translation) (WKP: UDP 53) Note: Internet infrastructure (תשתית) function, implemented as application-layer protocol all the work at network’s “edge”, not in the core

36.Application Layer 8- 36 DNS Why not centralize DNS? single point of failure traffic volume distant centralized database maintenance difficult doesn’t scale! DNS services Hostname to IP address translation Host aliasing canonical name = main name of computer alias = additional name Finding server names e.g hostname of mail server for domain Load distribution Replicated Web servers: set of IP addresses for one canonical name

37.Application Layer 8- 37 Root DNS Servers (*) com DNS servers org DNS servers edu DNS servers poly.edu DNS servers umass.edu DNS servers yahoo.com DNS servers amazon.com DNS servers pbs.org DNS servers Distributed, Hierarchical Database Client NS wants IP address for www.amazon.com : Client NS queries a root server to find com DNS server It then queries com DNS server to get amazon.com DNS (name-) server (by sending message to UDP port 53) It then queries amazon.com DNS server to get IP address for www.amazon.com (*) There are 13 root servers world-wide; their addresses are known to all name servers

38.Application Layer 8- 38 TLD, Authoritative Servers, Zones Top-level domain (TLD) servers: responsible for com, org, net, edu , etc, and all top-level country domains uk , fr , ca, jp , il Network Solutions maintains servers for com TLD Educause does the same for edu TLD Authoritative DNS server: organization’s DNS server, providing authoritative hostname to IP mappings for organization’s servers It is responsible for a “ zone ” (or several zones) Zone = Domain \ υ { subdomains that have their own zones } Example: ns.tau.ac.il zone includes all natural science faculty except dep”ts that have their own zones (e.g. cs.ns.tau.ac.il & math.ns.tau.ac.il )

39.Application Layer 8- 39 Resolver and Local Name Server Each host has a Resolver = a function resident in the host which can communicate with the DNS system Each ISP (residential ISP, company, university) has a “Local name server” (it was called “Client NS” above) Also called “default name server” When application needs to translate a DNS name, it calls the resolver on its computer Resolver sends a DNS query to its local name server (LNS) LNS finds the answer in its cache or by querying other name servers and sends answer to Resolver Resolver supplies answer to the application

40.requesting host cis.poly.edu gaia.cs.umass.edu root DNS server local DNS server dns.poly.edu 1 2 3 4 5 6 authoritative DNS server dns.cs.umass.edu 7 8 TLD DNS server DNS name resolution example host at cis.poly.edu wants IP address for gaia.cs.umass.edu iterated query: contacted server replies with name of server to contact “I don’t know this name, please ask this server ” There are 2 iterated queries in the example Application 2- 40

41.requesting host cis.poly.edu gaia.cs.umass.edu root DNS server local DNS server dns.poly.edu 1 2 4 5 6 authoritative DNS server dns.cs.umass.edu 7 8 TLD DNS server 3 recursive query: puts burden of name resolution on contacted name server heavy load ? Note: scenario may involve a mix of the two modes. root name servers are usually iterative DNS name resolution example Application 2- 41

42.Application Layer 8- 42 DNS: caching and mirroring once (any) name server learns mapping, it caches mapping cache entries timeout (disappear) after some time (each response includes a TTL) TLD servers typically cached in all local name servers Thus root name servers less often visited Usually zone database is duplicated on several authoritative name servers (mirroring) the main one is updated by the administrator by a file the others copy the zone from the main one main NS notifies the others when update available

43.Application Layer 8- 43 DNS records DNS: distributed db storing resource records (RR) Type=NS name is domain (e.g. foo.com) value is IP address of authoritative name server for this domain RR format: ( name, value, type, ttl ) Type=A name is hostname value is IP address Type=CNAME name is alias name for some “canonical” (the real) name www.ibm.com is really servereast.backup2.ibm.com value is canonical name Type=MX name is domain, e.g. gmail.com value is hostname of mail server

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- 44

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- 45

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,, A) (networkutopia.com, nili.networkutopia.com, MX) (www.networkutopia.com, a1.networkutopia.com, CNAME) What does each of these RRs define? What RRs are missing? How do people get IP address of your Web site? Application 2- 46

47.Pure P2P architecture no always-on server arbitrary end systems directly communicate peers are intermittently connected and change IP addresses Most common applications have a background server that initializes the system we discuss three topics: file distribution searching for information case Study: Skype peer-peer Application 2- 47

48.File Distribution: Server-Client vs P2P Question : How much time to distribute file from one server to N peers ? u s u 2 d 1 d 2 u 1 u N d N Server Network (with abundant bandwidth) File, size F u s : server upload bandwidth u i : peer i upload bandwidth d i : peer i download bandwidth Application 2- 48 upload : sending to Network download : receiving from Network

49.= d cs ≥ max { NF/u s , F/min( d i ) } Time to distribute F to N clients by client / server approach i File distribution time: server-client u s u 2 d 1 d 2 u 1 u N d N Server Network (with abundant bandwidth) F server sequentially sends N copies: NF/u s time client i takes F/ d i time to download increases linearly in N (for large N) Application 2- 49 equal under best server scheduling arrangement

50.File distribution time: P2P u s u 2 d 1 d 2 u 1 u N d N Server Network (with abundant bandwidth) F server must send one copy: F /u s time client i takes F/d i time to download NF bits must be downloaded (aggregate) fastest possible upload rate: u s + S u i d P2P ≥ max { F/u s , F/min( d i ) , NF/(u s + S u i ) } i i=1 Application 2- 50 N independent of N if the u i are all of same order of magnitude equal under best data distribution arrangement

51.Server-client vs. P2P: example Client upload rate = u, F/u = 1 hour, u s = 10u, d min ≥ u s Application 2- 51

52.File distribution: BitTorrent tracker: tracks peers participating in torrent torrent: group of peers exchanging chunks of a file obtain list of peers trading chunks peer P2P file distribution Application 2- 52

53.BitTorrent (1) file divided into 256KB chunks . peer joining torrent: has no chunks, but will accumulate them over time registers with tracker to get list of peers, connects to a chosen subset of peers (“neighbors”) while downloading, peer uploads chunks to other peers. peers may come and go once peer has entire file, it may (selfishly) leave (“leech”) or (cooperatively) remain (“seed”) Application 2- 53

54.BitTorrent (2) Pulling Chunks at any given time, different peers have different subsets of file chunks periodically, a peer (Alice) asks each neighbor for list of chunks that they have. Alice sends requests for her missing chunks rarest first Sending Chunks: tit-for-tat Alice sends chunks to four neighbors currently sending to her chunks at the highest rate re-evaluate top 4 every 10 secs every 30 secs : randomly select another peer, starts sending chunks newly chosen peer may join top 4, if sends fast to her “optimistically unchoke ” Application 2- 54

55.BitTorrent: Tit-for-tat (1) Alice “optimistically unchokes” Bob (2) Alice becomes one of Bob’s top-four providers; Bob reciprocates (3) Bob becomes one of Alice’s top-four providers “optimistic unchoke ” procedure helps find better trading partners & get file faster! Application 2- 55

56.Distributed Hash Table (DHT) DHT: distributed P2P database database has (key, value) pairs; key: Soc.Security number; value: human name key: content title; value: IP address peers query DB with key DB returns values that match the key peers can also insert (key, value) pairs Application 2- 56

57.DHT Identifiers assign to each peer an integer identifier in range [0,2 n -1]. Each identifier can be represented by n bits. require each key to also be an integer in [0,2 n -1]. since original key may be a string, we build an integer key applying an n-bit hash function to the original key. e.g., key = h(“Led Zeppelin IV”) this is why they call it a distributed “hash” table Application 2- 57

58.How to assign keys to peers? central issue: assigning (key, value) pairs to peers that will store them. rule: assign key to the peer that has the closest ID. convention in lecture: closest is the immediate successor of the key, i.e. closest from above or equal. e.g.,: n=4; peers: 1,3,4,5,8,10,12,14; key = 13, then successor peer = 14 key = 15, then successor peer = 1 the numbers are arranged in a ring (cyclic order) Application 2- 58

59.1 3 4 5 8 10 12 15 Circular DHT (1) each peer only aware of immediate successor and predecessor and communicates only with them. this forms the “overlay network” Application 2- 59

60.Circular DHT (2) 0001 0011 0100 0101 1000 1010 1100 1111 Who’s resp for key 1110 ? I am O(N) messages on avg required to resolve query in overlay network, when there are N peers 1110 1110 1110 1110 1110 1110 Define closest as closest successor Application 2- 60

61.Circular DHT with Shortcuts each peer keeps track of IP addresses of predecessor, successor and short cuts. reduced from 6 to 2 messages. possible to design shortcuts so O(log N) neighbors and O(log N) messages per query 1 3 4 5 8 10 12 15 Who’s resp for key 1110? Application 2- 61

62.Peer Churn Example: peer 5 abruptly leaves Peer 4 detects; makes 8 its immediate successor; asks 8 who its immediate successor is; makes 8’s immediate successor its second successor. Who else needs to update its neighbor list? What happens with the database info held by peer 5? What if peer 13 wants to join? 1 3 4 5 8 10 12 15 To handle peer churn, require each peer to know the IP address of its two successors. Each peer periodically pings its two successors to see if they are still alive . Application 2- 62

63.P2P Case study: Skype inherently P2P: pairs of users communicate. proprietary application-layer protocol (inferred via reverse engineering) hierarchical overlay with Supernodes (SNs) Index maps usernames to IP addresses; distributed over SNs Skype clients (SC) Supernode (SN) Skype login server Application 2- 63 Note: SNs are hosts with non-NAT addresses, so any host can contact them

64.Peers as relays problem when both Alice and Bob are behind “NATs”. NAT prevents an outside peer from initiating a call to insider peer solution: using Alice’s and Bob’s SNs, relay host is chosen each peer initiates a TCP session with relay. peers can now transfer their realtime data through NATs via relay Note : relay is another Skype user Application 2- 64

65.Ch.1: Introduction EXTRA SLIDES 65

66.Application Layer 8- 66 Nonpersistent HTTP Suppose user enters URL of a page : 1a . HTTP client initiates TCP connection to HTTP server (process) at www.someSchool.edu on port 80 2. HTTP client sends HTTP request message (containing URL) into TCP connection socket. Message indicates that client wants object someDepartment/home.index 1b. HTTP server at host www.someSchool.edu waiting for TCP connection at port 80. “accepts” connection, notifying client 3. HTTP server receives request message, forms response message containing requested object, and sends message into its socket (page contains text and references to 10 jpeg images) Client Server www.someSchool.edu/someDepartment/home.index time

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

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

69.Application Layer 8- 69 Persistent HTTP Nonpersistent HTTP issues: 2 RTT overhead per object Extra Delay OS must work and allocate host resources for each TCP connection browsers often open parallel TCP connections to fetch referenced objects Persistent HTTP server leaves connection open after sending response subsequent HTTP messages between same client/server are sent over same connection Persistent without pipelining: client issues new request only when previous response has been received one RTT overhead for each referenced object Qn: What time is saved? Persistent with pipelining: default in HTTP/1.1 client sends requests as soon as it encounters a referenced object only one RTT for all the referenced objects Qn: Can you see an advantage of NonPersistent?

70.Application Layer 8- 70 FTP: the file transfer protocol (RFC 959) transfer file to/from remote host remote management of a file system client/server model client (user’s workstation) initiates the connection server (file server) responds to client’s commands mainly files transfers to or from client ftp Well Known Port for control traffic : 21 ftp Well Known Port for data traffic : 20 file transfer FTP server FTP user interface FTP client local file system remote file system user at host

71.Application Layer 8- 71 FTP: separate control, data connections FTP client contacts FTP server by TCP at port 21, sets up control connection client obtains authorization over control connection client browses remote directory by sending commands over control connection. before a file transfer, client asks server to open a data-connection to a client port N (from server port 20) client sends command: RETR or STOR (see next slide) After sending/receiving one file, data connection is closed FTP client FTP server TCP control connection, server port 21 TCP data connection, server port 20 Server opens a second TCP data connection to transfer another file. Control connection: “out of band” FTP server maintains “state” throughout the session: current directory, authentication state

72.Application Layer 8- 72 FTP commands, responses Sample commands: (sent as ASCII text over control channel) USER username PASS password LIST - list the files in current directory CWD – change working dir. PORT N – set up data connect. to my port N RETR <filename> - download a file from server to client STOR <filename> - upload a file from client to server Sample return codes (status code and phrase: same 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 226 File transfer OK, closing connection Note: in Windows FTP user writes GET for RETR PUT for STOR

73.אפקה תשע"א ס"א Application Layer 2- 73 Electronic Mail Four major components: user agents mail servers SMTP protocol btw servers POP3/ IMAP protocols to retrieve mail by user agent User Agent a.k.a. “mail reader” composing, editing, reading mail messages e.g., Outlook, Eudora, elm, Netscape Messenger sends outgoing messages to server collects incoming messages from server user mailbox outgoing message queue mail server user agent user agent user agent mail server user agent user agent mail server user agent SMTP SMTP SMTP

74.אפקה תשע"א ס"א Application Layer 2- 74 Electronic Mail: mail servers Mail Servers mailbox contains incoming messages for user message queue of outgoing (to be sent) mail messages SMTP protocol used between mail servers to send email messages SMTP client : the sending mail server SMTP server : the receiving mail server mail server user agent user agent user agent mail server user agent user agent mail server user agent SMTP SMTP SMTP Note: Some user agents use SMTP to send mail to their mail server

75.אפקה תשע"א ס"א Application Layer 2- 75 Electronic Mail: SMTP [RFC 821, 2821] uses TCP to reliably transfer email messages from client to server SMTP server port 25 (WKP) direct transfer: sending-server to receiving-server three phases of transfer handshaking (greeting) transfer of messages closing connection command/response interaction commands: ASCII text response: status code (number) and phrase messages must be in 7-bit US-ASCII both the SMTP handshake and the message itself

76.אפקה תשע"א ס"א Application Layer 2- 76 Scenario: Alice sends message to Bob 1) Alice uses UA (*) to compose message with “to” field: bob@someschool.edu 2) Alice’s UA sends message to her mail server; message placed in message queue 3) Alice’s mail server (=SMTP client) opens TCP connection to Bob’s mail server 4) SMTP client sends Alice’s message over the TCP connection 5) Bob’s mail server places the message in Bob’s mailbox 6) Bob uses his user agent to retrieve message from mailbox and reads it * UA=User agent (e.g. Outlook) user agent mail server mail server user agent 1 2 3 4 5 6

77.אפקה תשע"א ס"א Application Layer 2- 77 Sample SMTP interaction < client sets up a TCP connection to server port 25 > S: 220 hamburger.edu C: HELO crepes.fr S: 250 Hello crepes.fr, pleased to meet you C: MAIL FROM: <alice@crepes.fr> S: 250 alice@crepes.fr... Sender ok C: RCPT TO: <bob@hamburger.edu> S: 250 bob@hamburger.edu ... Recipient ok C: DATA S: 354 Enter mail, end with "." on a line by itself C: Do you like ketchup? Mail headers skipped here C: How about pickles? ( see a full mail example C: . on slide 73 ) S: 250 Message accepted for delivery C: QUIT S: 221 hamburger.edu closing connection

78.אפקה תשע"א ס"א Application Layer 2- 78 SMTP: final words SMTP uses persistent connections SMTP requires message (header & body) to be in 7-bit ASCII SMTP server uses CRLF.CRLF (single dot in a line) to signal end of message Comparison with HTTP: HTTP: (mainly) PULL SMTP: always PUSH both have ASCII command/response interaction, status codes HTTP: a page may contain pictures and other objects each object in own message SMTP: originally only ASCII text with MIME format, can include any type of objects objects sent inside msg.

79.אפקה תשע"א ס"א Application Layer 2- 79 Original Email msg format [RFC 822] SMTP: protocol for transferring email msgs Original email msg FORMAT: RFC 822: standard for text message format : header lines, e.g., To: From: Subject: different from SMTP commands ! body the “message” text, ASCII characters only header body blank line

80.אפקה תשע"א ס"א Application Layer 2- 80 MIME format: multimedia extensions MIME: Multimedia Mail Extension, RFC 2045, 2056 additional lines in msg header declare MIME content type and encoding method, this enables multimedia content 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 multimedia data type, subtype, parameters method used to encode data (*) MIME version encoded data (*) data always encoded into 7-bit ASCII

81.אפקה תשע"א ס"א Application Layer 2- 81 Mail access protocols SMTP: mail delivery to receiver’s server – PUSH Mail access protocols: retrieval from server to agent – PULL they require authentication of agent by server POP: Post Office Protocol [RFC 1939] download all messages and keep at your workstation IMAP: Internet Mail Access Protocol [RFC 1730] enables organizing mail folders on server you can read mail conveniently from any workstation HTTP: (e.g. gmail) - display tool for agent located at the server user agent sender’s mail server user agent SMTP SMTP access protocol receiver’s mail server

82.אפקה תשע"א ס"א Application Layer 2- 82 POP3 protocol authorization phase client commands: user: declare username pass: password server responses +OK -ERR transaction phase, client: list: list message numbers retr: retrieve message by number dele: delete quit C: list S: 1 498 S: 2 912 S: . C: retr 1 S: <message 1 contents> S: . C: dele 1 C: retr 2 S: <message 1 contents> S: . C: dele 2 C: quit S: +OK POP3 server signing off S: +OK POP3 server ready C: user bob S: +OK C: pass hungry S: +OK user successfully logged on

83.אפקה תשע"א ס"א Application Layer 2- 83 POP3 (more) and IMAP More about POP3 Previous example uses “download and delete” mode. Bob cannot re-read e-mail if he changes client “Download-and-keep”: can get messages on different clients POP3 is stateless across sessions IMAP Keep all messages in one place: the server Allows user to organize messages in folders IMAP keeps user state across sessions: names of folders and mappings between message IDs and folder name