Chapter 8 Application Layer based on A note
Chapter 8 Application Layer based on: A note on the use of these ppt slides: We’re making these slides freely available to all (faculty, students, readers). They’re in Power. Point 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: v 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!) v If you post any slides in substantially unaltered form on a www site, that you note that they are adapted from (or perhaps identical to) our slides, and note our copyright of this material. Computer Networking: A Top Down Approach, 5 th edition. Jim Kurose, Keith Ross Addison-Wesley, April 2009. Thanks and enjoy! JFK/KWR All material copyright 1996 -2010 J. F Kurose and K. W. Ross, All Rights Reserved Application 2 -1
Chapter 8: 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 application-layer protocols by looking at examples: m m HTTP DNS (web) (web addressing) r interface to transport layer Application Layer 8 -2
Creating network applications 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 app. software written for devices in network core m m Network core devices do not function at application layer This design allows for rapid app development application transport network data link physical Application Layer 8 -3
App-layer protocol defines r Types of messages 2 TYPES OF PROTOCOLS: exchanged, e. g. request Public-domain protocols: & response messages r defined in RFCs r Syntax of message r enable interoperability types: what fields in r eg: HTTP, SMTP, SIP messages & where fields are located Proprietary protocols: r Semantics of the fields, r owned by a company i. e. meaning of r eg: Skype, Messenger information in fields r Rules for when and how processes send & respond to messages Application Layer 8 -4
Client / Server concepts r Hardware view r Process / interaction view r Client-Server architecture r Peer-to-Peer architecture Application Layer 8 -5
Client Hosts /Server Hosts server host : m m m always-on host permanent IP address server farms for scaling client host (=workstation): m m m located next to user may be intermittently connected may have dynamic IP address Note: r Both client and server are called hosts Application Layer 8 -6
Client Process/Server Process: program running within a host. r processes in different hosts communicate by exchanging messages r when processes cooperate for a common purpose, there must be one of them that initiates the common work m Client process: process that initiates communication Server process: process that waits to be contacted by client Sends the first message Note: r Client process may run on a client host or on a server host r Server process may run on a client host (see Peer to Peer architecture) Application Layer 8 -7
Process Interaction Scenario Client process 1 server process: m m waits all the time for work its IP address must be known to the client process before interaction starts client process: m Server proc. 1 m Server proc. 2 m Client process 2 Note: m 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 r Server host usually runs several server processes in parallel Application Layer 8 -8
Client-Server architecture server process: m m runs on server host only the server host’s IP address is publicly known client process: m runs on client host ( usually) or on a server host m example: in e-mail appl. the sender mail server runs a client process, while the receiving MS runs a server process Application Layer 8 -9
Pure P 2 P architecture r no always-on server r arbitrary end systems directly communicate peer-peer r peers are intermittently connected and change IP addresses highly scalable but difficult to manage Application 2 -10
Hybrid of client-server and P 2 P Skype voice-over-IP P 2 P application m centralized server: finding address of remote party: m client-client connection: direct (not through server) m P 2 P Instant messaging chatting btw. two users is P 2 P m 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 C-S m P 2 P C-S data initializatio n Application 2 -11
What transport service does an app need? Data loss r some apps (e. g. , file transfer, telnet) require 100% reliable data transfer r other apps (e. g. , audio) can tolerate some loss Timing r some apps (e. g. , Internet telephony, interactive games) require low delay to be “effective” Throughput v some apps (e. g. , multimedia) require ≥ minimum amount of throughput to be “effective” v other apps (“elastic apps”) make use of whatever throughput they get Security v encryption, data integrity, … Application 2 -12
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, a few secs yes, 100’s msec yes and no Application Layer 8 -13
Web and HTTP First a review 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 Application Layer 8 -14
HTTP overview HTTP: hypertext transfer protocol r Web’s application layer protocol r client/server model m client : browser that requests, receives and “displays” Web objects m server : Web server that sends objects in response to requests r HTTP 1. 0 : RFC 1945 r HTTP 1. 1 : RFC 2616 HT TP req ues PC running HT t TP res Explorer pon se st e u q re se Server P n T o p running HT es r TP Apache Web T H server Mac running Navigator Note: r Different H/W and S/W r use the same protocol Application Layer 8 -15
HTTP overview (continued) HTTP uses TCP: r client initiates TCP connection (creates socket) to server port 80 (WKP) 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 HTTP keeps no information about past client requests m BUT, cookies allow Web server to run stateful applications note 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 Application Layer 8 -16
HTTP connections Nonpersistent HTTP r At most one object sent over a TCP connection. r is default in HTTP/1. 0 m use Keep Alive header to force Persistent mode r Disadvantages: 1. wastes RTT per message 2. adds overhead packets 3. stays most of the time in Slow Start Cong. Ctrl r Partial help: m use parallel connections Persistent HTTP r Multiple objects sent over single TCP connection between client and server. m Last request contains the Close Connection header r is default in HTTP/1. 1 Persistent w. Pipelining r Send requests for referenced objects one after the other, without waiting for response to previous requests r saves another RTT per object Application Layer 8 -17
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) header lines carriage return, line feed at start of line indicates end of header lines carriage return character line-feed character GET /index. html HTTP/1. 1rn Host: www-net. cs. umass. edurn User-Agent: Firefox/3. 6. 10rn Accept: text/html, application/xhtml+xmlrn Accept-Language: en-us, en; q=0. 5rn Accept-Encoding: gzip, deflatern Accept-Charset: ISO-8859 -1, utf-8; q=0. 7rn Keep-Alive: 115rn Connection: keep-alivern Connection: Close rn Application 2 -18
HTTP request message: general format request line header lines body Application 2 -19
Uploading form input POST method: m web page often includes form input r input is uploaded to server in entity body GET method with URL parameters: r uses GET method r input is uploaded in URL field of request line: www. somesite. com/animalsearch? monkeys&banana Application 2 -20
Methods HTTP/1. 0 r GET r POST r HEAD m m asks server to leave requested object out of response Used for: • debugging • troubleshooting HTTP/1. 1 r GET, POST, HEAD r PUT m uploads file in the entity body to the path specified in URL field r DELETE m deletes file specified in the URL field Application Layer 8 -21
HTTP response message status line (protocol status code status phrase) header lines HTTP/1. 1 200 OKrn Date: Sun, 26 Sep 2010 20: 09: 20 GMTrn Server: Apache/2. 0. 52 (Cent. OS)rn Last-Modified: Tue, 30 Oct 2007 17: 00: 02 GMTrn ETag: "17 dc 6 -a 5 c-bf 716880"rn Accept-Ranges: bytesrn Content-Length: 2652rn Connection: Closern Content-Type: text/html; charset=ISO-8859 -1rn data data. . . data, e. g. , requested HTML file Application 2 -22
HTTP response status codes In first line of the response message. A few examples of status 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 Application Layer 8 -23
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/ 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! (or use wireshark!) Application 2 -24
User-server “state”: cookies Many major Web sites use Example: cookies m Susan accesses 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 m m m 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 Application Layer 8 -25
Cookies: keeping “state” (cont. ) client ebay 8734 cookie file ebay 8734 amazon 1678 server usual http request msg usual http response Set-cookie: 1678 usual http request msg cookie: 1678 one week later: usual http response msg Amazon server creates ID 1678 for user create entry cookiespecific action access ebay 8734 amazon 1678 usual http request msg cookie: 1678 usual http response msg backend database cookiespecific action Application 2 -26
Cookies (continued) What cookies can bring: r user session state (e. g. in Web e-mail) r user identification m on given workstation r shopping carts r recommendations aside Cookies and privacy: r cookies permit sites to learn a lot about you r you may supply name and email to sites r advertising companies obtain info across sites from inserted banner adds o info collected by the advertizing server o there are regulatory restrictions on releasing it Application Layer 8 -27
Web cache (proxy server) Goal: satisfy client request without involving origin server r user sets up browser to access Web via proxy r browser sends all HTTP requests to proxy m m IF object in the proxy’s cache: proxy returns object ELSE proxy requests object from origin server, then returns object to client v and keeps file in its cache Proxy Server HT TP (web cache) est u q re client. HTTP res ues pon se est t u eq r P nse T o p HT es r TP T H origin server se TP n o HT p res P T HT client origin server v Note: user’s browser has a private cache on its host. Application Layer 8 -28
More about Web caching r proxy acts as HTTP client and server r Typically proxy is installed by ISP or a user organization. Caching advantages r Reduce response time for client request. r Reduce traffic on an institution’s access link. r Internet dense with proxies enables “poor” content providers to effectively deliver content Qn : what is the main problem with caching as described? Caching rules r Origin server may : m m forbid caching allow caching by private cache only (privacy) r Origin server sends: m m m Last Modified date/time Expiration time or Max. Age r Proxy should respect age and other restrictions Application Layer 8 -29
Caching example (1) origin servers 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 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 link delay + LAN delay = 2 sec + minutes + milliseconds institutional cache Application 2 -30
Caching example (2) possible solution r increase bandwidth of access link to, say, 10 Mbps consequence 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 origin servers public Internet 10 Mbps access link institutional network 10 Mbps LAN institutional cache Application 2 -31
Caching example (3) origin servers possible solution: r install cache consequence r suppose hit rate is 0. 4 m 40% requests will be satisfied almost immediately m 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 +. 4*milliseconds < 1. 4 secs public Internet 1. 5 Mbps access link institutional network 10 Mbps LAN institutional cache Application 2 -32
Conditional GET r Goal: don’t send object if proxy has up-to-date cached version m used if cacheability conditions or data are missing r proxy specifies date of cached copy in HTTP request header: If-modified-since: <date> r server sends short response if cached copy is up-to-date: HTTP/1. 0 304 Not Modified (contains no object) (see Case 1 on this slide) proxy Case 1 server HTTP request msg If-modified-since: <date> HTTP response object not modified HTTP/1. 0 304 Not Modified proxy Case 2 server HTTP request msg If-modified-since: <date> HTTP response object modified HTTP/1. 0 200 OK <data> Application Layer 8 -33
Legacy Internet Applications Telnet r Remote terminal r Enables user to enter line commands to remote host r Remote host returns display to user. r characters sent one by one and echoed on display r sets char, encoding rules FTP r File transfer and remote control of a file server r Uses Telnet encoding rules Client-Server Email r Mail client on user’s host m e. g. Outlook r User mailbox on his Server r Msg prepared on client, sent to user’s Mail Server (MS) r MS sends to dest. MS using SMTP (a PUSH protocol) r dest. MS stores msg in mailbox r User collects msg using PULL protocol (POP 3 or IMAP) Webmail r Client functionality on Server r User has an HTTP GUI terminal Application Layer 8 -34
DNS: Domain Name System People: many identifiers: m SSN, name, passport # Internet hosts, routers: m IP address (32 bit) used for addressing datagrams (packets) – good for routers m “name”, e. g. , www. yahoo. com – good for human use Q: map between name and IP addresses ? Domain Name System: 1. 2. 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) m Note: Internet infrastructure ( )תשתית function, implemented as application-layer protocol m all the work at network’s “edge”, not in the core Application Layer 8 -35
DNS services r Hostname to IP address Why not centralize DNS? r single point of failure translation r traffic volume r Host aliasing m canonical name = main r distant centralized name of computer database m alias = additional name r maintenance difficult r Finding server names r doesn’t scale! m e. g hostname of mail server for domain r Load distribution m Replicated Web servers: set of IP addresses for one canonical name Application Layer 8 -36
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 NS wants IP address for www. amazon. com : r Client NS queries a root server to find com DNS server r It then queries com DNS server to get amazon. com DNS (name- ) server (by sending message to UDP port 53) r 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 Application Layer 8 -37
TLD, Authoritative Servers, Zones r Top-level domain (TLD) servers: responsible for com, org, net, edu, etc, and all top-level country domains uk, fr, ca, jp, il m Network Solutions maintains servers for com TLD m Educause does the same for edu TLD r Authoritative DNS server: organization’s DNS server, providing authoritative hostname to IP mappings for organization’s servers m It is responsible for a “zone” (or several zones) m Zone = Domain υ { subdomains that have their own zones } r Example: m 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 ) Application Layer 8 -38
Resolver and Local Name Server r Each host has a Resolver = a function resident in the host r r r which can communicate with the DNS system Each ISP (residential ISP, company, university) has a “Local name server” (it was called “Client NS” above) m 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 supplies answer to the application Application Layer 8 -39
DNS name resolution example root DNS server 2 r host at cis. poly. edu wants IP address for gaia. cs. umass. edu iterated query: v v v 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 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 Application 2 -40
DNS name resolution example recursive query: root DNS server 2 puts burden of name 7 resolution on contacted name server local DNS server v heavy load? dns. poly. edu Note: 1 8 r scenario may involve a mix of the two modes. r root name servers are usually iterative requesting host v 3 6 TLD DNS server 5 4 authoritative DNS server dns. cs. umass. edu cis. poly. edu gaia. cs. umass. edu Application 2 -41
DNS: caching and mirroring r once (any) name server learns mapping, it caches mapping m cache entries timeout (disappear) after some time (each response includes a TTL) m TLD servers typically cached in all local name servers • Thus root name servers less often visited r Usually zone database is duplicated on several authoritative name servers (mirroring) m m m 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 Application Layer 8 -42
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) r Type=CNAME m name is alias name for some “canonical” (the real) name www. ibm. com is really servereast. backup 2. ibm. com m value is canonical name r Type=MX m value is IP address of m name is domain, e. g. gmail. com authoritative name server m value is hostname of mail server for this domain Application Layer 8 -43
DNS protocol, messages DNS protocol : query and reply messages, both with same message format msg header v v identification: 16 bit # for query, reply to query uses same # flags: § query or reply § recursion desired § recursion available § reply is authoritative Application 2 -44
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
Inserting records into DNS r example: new startup “Network Utopia” r register name networkuptopia. com at DNS registrar (e. g. , Network Solutions) m m provide names, IP addresses of authoritative name server (primary and secondary) registrar inserts two RRs into com TLD server: (networkutopia. com, dns 1. networkutopia. com, NS) (dns 1. networkutopia. com, 212. 1, A) (networkutopia. com, nili. networkutopia. com, MX) (www. networkutopia. com, a 1. networkutopia. com, CNAME) r What does each of these RRs define? What RRs are missing? r How do people get IP address of your Web site? Application 2 -46
Pure P 2 P architecture r no always-on server r arbitrary end systems directly communicate r peers are intermittently peer-peer connected and change IP addresses r Most common applications have a background server that initializes the system we discuss three topics: m m m file distribution searching for information case Study: Skype Application 2 -47
File Distribution: Server-Client vs P 2 P Question : How much time to distribute file from one server to N peers? us: server upload bandwidth Server us File, size F d. N u 1 d 1 u 2 ui: peer i upload bandwidth d 2 di: peer i download bandwidth Network (with abundant bandwidth) upload : sending to Network download : receiving from Network Application 2 -48
File distribution time: server-client r server sequentially sends N copies: m NF/us time r client i takes F/di time to download Server F us d. N u 1 d 1 u 2 d 2 Network (with abundant bandwidth) Time to distribute F to = dcs ≥ max {NF/us, F/min(di) } i N clients by client/ server approach equal under best server scheduling arrangement increases linearly in N (for large N) Application 2 -49
File distribution time: P 2 P Server r server must send one F u 1 d 1 u 2 d 2 copy: F/us time us r client i takes F/di time Network (with d. N to download abundant bandwidth) u. N r NF bits must be downloaded (aggregate) § fastest possible upload rate: us + Sui d. P 2 P ≥ max { F/us, F/min(di) , NF/(us + i N S ui ) } i=1 equal under best independent of N if the u are i data distribution all of same order of magnitude arrangement Application 2 -50
Server-client vs. P 2 P: example Client upload rate = u, F/u = 1 hour, us = 10 u, dmin ≥ us Application 2 -51
File distribution: Bit. Torrent P 2 P file distribution tracker: tracks peers participating in torrent: group of peers exchanging chunks of a file obtain list of peers trading chunks peer Application 2 -52
Bit. Torrent (1) r file divided into 256 KB chunks. r peer joining torrent: m has no chunks, but will accumulate them over time m registers with tracker to get list of peers, connects to a chosen subset of peers (“neighbors”) r while downloading, peer uploads chunks to other peers may come and go r once peer has entire file, it may (selfishly) leave (“leech”) or (cooperatively) remain (“seed”) Application 2 -53
Bit. Torrent (2) Sending Chunks: tit-for-tat v Alice sends chunks to four neighbors currently sending to her chunks at the highest rate Pulling Chunks r at any given time, different peers have different subsets of file chunks r periodically, a peer (Alice) asks each v neighbor for list of chunks that they have. r Alice sends requests for her missing chunks m rarest first § 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
Bit. Torrent: 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
Distributed Hash Table (DHT) r DHT: distributed P 2 P database r database has (key, value) pairs; m key: Soc. Security number; value: human name m key: content title; value: IP address r peers query DB with key m DB returns values that match the key r peers can also insert (key, value) pairs Application 2 -56
DHT Identifiers r assign to each peer an integer identifier in range [0, 2 n-1]. m Each identifier can be represented by n bits. r require each key to also be an integer in [0, 2 n-1]. r since original key may be a string, we build an integer key applying an n-bit hash function to the original key. m e. g. , key = h(“Led Zeppelin IV”) m this is why they call it a distributed “hash” table Application 2 -57
How to assign keys to peers? r central issue: m assigning (key, value) pairs to peers that will store them. r rule: assign key to the peer that has the closest ID. r convention in lecture: closest is the immediate successor of the key, i. e. closest from above or equal. r e. g. , : n=4; peers: 1, 3, 4, 5, 8, 10, 12, 14; m key = 13, then successor peer = 14 m key = 15, then successor peer = 1 o the numbers are arranged in a ring (cyclic order) Application 2 -58
Circular DHT (1) 1 3 15 4 12 5 10 8 r each peer only aware of immediate successor and predecessor and communicates only with them. r this forms the “overlay network” Application 2 -59
Circular DHT (2) O(N) messages on avg required to resolve query in overlay network, when there are 1111 N peers 0001 I am Who’s resp 0011 ? 1110 0100 1110 1100 1110 Define closest as closest successor for key 1110 1010 1110 0101 1110 1000 Application 2 -60
Circular DHT with Shortcuts 1 3 15 Who’s resp for key 1110? 4 12 5 10 8 r each peer keeps track of IP addresses of predecessor, successor and short cuts. r reduced from 6 to 2 messages. r possible to design shortcuts so O(log N) neighbors and O(log N) messages per query Application 2 -61
Peer Churn To handle peer churn, require each peer to know the IP address of its two successors. v Each peer periodically pings its two successors to see if they are still alive. v 1 3 15 4 12 5 10 8 r Example: peer 5 abruptly leaves r Peer 4 detects; makes 8 its immediate successor; asks 8 who its immediate successor is; makes 8’s immediate successor its second successor. r Who else needs to update its neighbor list? r What happens with the database info held by peer 5? r What if peer 13 wants to join? Application 2 -62
P 2 P Case study: Skype r inherently P 2 P: pairs of Skype clients (SC) users communicate. r proprietary application. Skype layer protocol login server (inferred via reverse engineering) r hierarchical overlay with Supernodes (SNs) r Index maps usernames to IP addresses; distributed over SNs Supernode (SN) r Note: SNs are hosts with non-NAT addresses, so any host can contact them Application 2 -63
Peers as relays r problem when both Alice and Bob are behind “NATs”. m NAT prevents an outside peer from initiating a call to insider peer r solution: m using Alice’s and Bob’s SNs, relay host is chosen m each peer initiates a TCP session with relay. m peers can now transfer their realtime data through NATs via relay m Note: relay is another Skype user Application 2 -64
EXTRA SLIDES Ch. 1: Introduction 65
Nonpersistent HTTP (page contains text and Suppose user enters URL of a page : references to www. some. School. edu/some. Department/home. index 10 jpeg images) Client Server 1 a. HTTP client initiates TCP connection to HTTP server (process) at www. some. School. edu on port 80 2. HTTP client sends HTTP time 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 Application Layer 8 -66
Nonpersistent HTTP (cont. ) 4. after sending the object, HTTP server closes TCP connection. 5. HTTP client receives response time 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 Application Layer 8 -67
Response time modeling Definition of RTT: time to send a small packet to travel from client to server and back. initiate TCP connection Response time: RTT r one RTT to initiate TCP request connection file RTT r one RTT for HTTP request and first few file received bytes of HTTP response to return time r file transmission time to transmit file time total = 2 RTT + transmit time Application Layer 8 -68
Persistent HTTP Nonpersistent HTTP issues: r 2 RTT overhead per object Extra Delay r OS must work and allocate host resources for each TCP connection r 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 same connection Persistent without pipelining: r client issues new request only when previous response has been received r one RTT overhead for each referenced object r Qn: What time is saved? Persistent with pipelining: r default in HTTP/1. 1 r client sends requests as soon as it encounters a referenced object r only one RTT for all the referenced objects r Qn: Can you see an advantage of Non. Persistent? Application Layer 8 -69
FTP: the file transfer protocol user at host FTP user client interface file transfer (RFC 959) FTP server remote file system local file system r transfer file to/from remote host m remote management of a file system r client/server model m m client (user’s workstation) initiates the connection server (file server) responds to client’s commands • mainly files transfers to or from client r ftp Well Known Port for control traffic : 21 r ftp Well Known Port for data traffic : 20 Application Layer 8 -70
FTP: separate control, data connections r FTP client contacts FTP server r r 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 dataconnection 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 TCP control connection, server port 21 FTP client TCP data connection, server 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” throughout the session: current directory, authentication state Application Layer 8 -71
FTP commands, responses Sample commands: (sent as ASCII text over control channel) r USER username r PASS password r LIST - list the files in current directory – change working dir. PORT N – set up data connect. r CWD r to my port N r RETR <filename> - download a file from server to client r STOR <filename> - upload a file from client to server Sample return codes (status code and phrase: same as in HTTP) r 331 Username OK, password required r 125 data connection already open; transfer starting r 425 Can’t open data connection r 452 Error writing file r 226 File transfer OK, closing connection Note: in Windows FTP user writes r GET for RETR r PUT for STOR Application Layer 8 -72
Electronic Mail outgoing message queue Four major components: user mailbox r user agents user agent r mail servers r SMTP protocol btw servers r POP 3/ IMAP protocols to mail server retrieve mail by user agent User Agent r a. k. a. “mail reader” r composing, editing, reading mail messages r e. g. , Outlook, Eudora, elm, Netscape Messenger r sends outgoing messages to server r collects incoming messages from server SMTP mail server user agent SMTP user agent mail server user agent אפקה תשע"א ס"א Applic 2 -73 ation
Electronic Mail: mail servers Mail Servers r mailbox contains incoming messages for user r message queue of outgoing (to be sent) mail messages r SMTP protocol used between mail servers to send email messages m SMTP client: the sending mail server m SMTP server: the receiving mail server user agent mail server SMTP mail server Note: Some user agents use SMTP to send mail to their mail server user agent mail server SMTP user agent אפקה תשע"א ס"א Applic 2 -74 ation
Electronic Mail: SMTP [RFC 821, 2821] r uses TCP to reliably transfer email messages from client to server m SMTP server port 25 (WKP) r direct transfer: sending-server to receiving-server r three phases of transfer handshaking (greeting) m transfer of messages m closing connection r command/response interaction m commands: ASCII text m response: status code (number) and phrase m r messages must be in 7 -bit US-ASCII m both the SMTP handshake and the message itself אפקה תשע"א ס"א Applic 2 -75 ation
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 1 user agent 2 mail server 3 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) mail server 4 5 6 user agent אפקה תשע"א ס"א Applic 2 -76 ation
Sample SMTP interaction <client sets up a TCP connection to server port 25> 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? Mail headers skipped here How about pickles? (see a full mail example. on slide 73) 250 Message accepted for delivery QUIT 221 hamburger. edu closing connection אפקה תשע"א ס"א Application Layer 2 -77
SMTP: final words Comparison with HTTP: r SMTP uses persistent connections r SMTP requires message (header & body) to be in 7 -bit ASCII r SMTP server uses CRLF (single dot in a line) to signal end of message r HTTP: (mainly) PULL r SMTP: always PUSH r both have ASCII command/response interaction, status codes r HTTP: a page may contain pictures and other objects m each object in own message r SMTP: m m m originally only ASCII text with MIME format, can include any type of objects sent inside msg. אפקה תשע"א ס"א Applic 2 -78 ation
Original Email msg format SMTP: protocol for transferring email msgs Original email msg FORMAT: RFC 822: standard for text message format: r header lines, e. g. , To: m From: m Subject: different from SMTP commands ! m [RFC 822] header blank line body r body m the “message” text, ASCII characters only אפקה תשע"א ס"א Applic 2 -79 ation
MIME format: multimedia extensions r MIME: Multimedia Mail Extension, RFC 2045, 2056 r additional lines in msg header declare MIME content type and encoding method, m this enables multimedia content MIME version method used to encode data (*) multimedia data type, subtype, parameters 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 (*) data always encoded into 7 -bit ASCII אפקה תשע"א ס"א Applic 2 -80 ation
Mail access protocols user agent SMTP sender’s mail server access protocol user agent receiver’s mail server r SMTP: mail delivery to receiver’s server – PUSH r Mail access protocols: retrieval from server to agent – PULL they require authentication of agent by server m POP: Post Office Protocol [RFC 1939] • download all messages and keep at your workstation m IMAP: Internet Mail Access Protocol [RFC 1730] • enables organizing mail folders on server • you can read mail conveniently from any workstation r HTTP: (e. g. gmail) - display tool for agent located at the server m אפקה תשע"א ס"א Applic 2 -81 ation
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 אפקה תשע"א ס"א Applic 2 -82 ation on
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”: can get 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 אפקה תשע"א ס"א Applic 2 -83 ation
- Slides: 83