Скачать презентацию Chapter 2 Application Layer A note on the Скачать презентацию Chapter 2 Application Layer A note on the

a76334e98e908506f3191234af182f17.ppt

  • Количество слайдов: 131

Chapter 2 Application Layer A note on the use of these ppt slides: We’re Chapter 2 Application Layer A note on the use of these ppt slides: We’re making these slides freely available to all (faculty, students, readers). They’re in 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: q 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!) q 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 -2009 J. F Kurose and K. W. Ross, All Rights Reserved 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 v r 2. 6 P 2 P applications r 2. 7 Socket programming with TCP r 2. 8 Socket programming with UDP SMTP, POP 3, IMAP r 2. 5 DNS 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 v transport-layer service models v client-server paradigm v peer-to-peer paradigm r learn about protocols by examining popular application-level protocols v v HTTP FTP SMTP / POP 3 / IMAP DNS r programming network applications v socket API 2: Application Layer 3

Some network apps r e-mail r voice over IP r web r real-time video Some network apps r e-mail r voice over IP r web r real-time video r remote login conferencing r grid computing r P 2 P file sharing r r multi-user network r r instant messaging games r streaming stored video clips r 2: Application Layer 4

Creating a network app write programs that v v v run on (different) end Creating a network app write programs that v v v run on (different) end systems communicate over network e. g. , web server software communicates with browser software No need to write software for network-core devices v v Network-core devices do not run user applications on end systems allows for rapid app development, propagation 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 v r 2. 6 P 2 P applications r 2. 7 Socket programming with TCP r 2. 8 Socket programming with UDP SMTP, POP 3, IMAP r 2. 5 DNS 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: v always-on host v permanent IP address v server farms for Client-server architecture server: v always-on host v permanent IP address v server farms for scaling clients: client/server v v communicate with server may be intermittently connected may have dynamic IP addresses do not communicate directly with each other 2: Application Layer 8

Google Data Centers r Estimated cost of data center: $600 M r Google spent Google Data Centers r Estimated cost of data center: $600 M r Google spent $2. 4 B in 2007 on new data centers r Each data center uses 50 -100 megawatts of power 2: Application Layer 9

Pure P 2 P architecture r no always-on server r arbitrary end systems directly 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 2: Application Layer 10

Hybrid of client-server and P 2 P Skype v voice-over-IP P 2 P application Hybrid of client-server and P 2 P Skype v voice-over-IP P 2 P application v centralized server: finding address of remote party: v client-client connection: direct (not through server) Instant messaging v chatting between two users is P 2 P v 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 2: Application Layer 11

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 Q: do applications with P 2 P architectures have client processes & server processes ? 2: Application Layer 12

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 13

Sockets r process sends/receives messages to/from its socket r socket analogous to door v Sockets r process sends/receives messages to/from its socket r socket analogous to door v v 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 14

Addressing processes r to receive messages, process must have identifier r host device has Addressing processes r to receive messages, process must have identifier r host device has unique 32 -bit IP address r Q: does IP address of host suffice for identifying the process? 2: Application Layer 15

Addressing processes r to receive messages, process must have identifier r host device has Addressing processes r to receive messages, process must have identifier r host device has unique 32 -bit IP address r Q: does IP address of host on which process runs suffice for identifying the process? v A: No, many processes can be running on same host r identifier includes both IP address and port numbers associated with process on host. r Example port numbers: v v HTTP server: 80 Mail server: 25 r to send HTTP message to gaia. cs. umass. edu web server: v v IP address: 128. 119. 245. 12 Port number: 80 r more shortly… 2: Application Layer 16

App-layer protocol defines r Types of messages exchanged, v e. g. , request, response App-layer protocol defines r Types of messages exchanged, v e. g. , request, response r Message syntax: v what fields in messages & how fields are delineated r Message semantics v meaning of information in fields r Rules for when and how Public-domain protocols: r defined in RFCs r allows for interoperability r e. g. , HTTP, SMTP Proprietary protocols: r e. g. , Skype processes send & respond to messages 2: Application Layer 17

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” Throughput r some apps (e. g. , multimedia) require minimum amount of throughput to be “effective” r other apps (“elastic apps”) make use of whatever throughput they get Security r Encryption, data integrity, … 2: Application Layer 18

Transport service requirements of common apps Data loss Throughput Time Sensitive file transfer e-mail Transport service requirements of common apps Data loss Throughput 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 19

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 throughput guarantees, security UDP service: r unreliable data transfer between sending and receiving process r does not provide: connection setup, reliability, flow control, congestion control, timing, throughput guarantee, or security Q: why bother? Why is there a UDP? 2: Application Layer 20

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] HTTP (eg Youtube), RTP [RFC 1889] SIP, RTP, proprietary (e. g. , Skype) TCP TCP TCP or UDP typically UDP 2: Application Layer 21

Chapter 2: Application layer r 2. 1 Principles of network applications v v app Chapter 2: Application layer r 2. 1 Principles of network applications v v app architectures app requirements r 2. 2 Web and HTTP r 2. 4 Electronic Mail v SMTP, POP 3, IMAP r 2. 6 P 2 P applications r 2. 7 Socket programming with TCP r 2. 8 Socket programming with UDP r 2. 5 DNS 2: Application Layer 22

Web r What are the major components of the Web? HTTP v Browsers v Web r What are the major components of the Web? HTTP v Browsers v Servers v 2: Application Layer 23

Web applications r Thin client vs. “thick” client r Also referred to as Rich Web applications r Thin client vs. “thick” client r Also referred to as Rich Internet Applications r Benefits: v Little disk space, automatic upgrade, integrate with other web procedures, cross-platform compatibility, mobility friendly, business reasons r Limits v Internet connectivity, inconsistency in browser implementations, (currently) limited functionalities 2: Application Layer 24

Examples r Google Documents r Gears (original Google Gears), a software platform for Ajax Examples r Google Documents r Gears (original Google Gears), a software platform for Ajax web applications development. v v v open-source, BSD-license, incremental Offline capability (e. g. , Google Reader, Google Docs) Three components • Local. Server: to access the application offline • Database: to store large amounts of structured data • Worker. Pool: to perform long sync when you reconnect (w. o. blocking the browser). r Google browser: Chrome 2: Application Layer 25

r Ajax, Adobe Flash r ASP (Application service provider) v Provide web access to r Ajax, Adobe Flash r ASP (Application service provider) v Provide web access to software (for monthly or yearly fees) r Software as a service r Computing as a service 2: Application Layer 26

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 27

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 v client: browser that requests, receives, “displays” Web objects v server: Web server sends objects in response to requests v Popular servers HT TP req ues PC running HT t TP res Explorer pon se st ue eq r se Server TP on p running HT res P T Apache Web HT server Mac running Navigator 2: Application Layer 28

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 29

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. Persistent HTTP r Multiple objects can be sent over single TCP connection between client and server. 2: Application Layer 30

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: v 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 35

HTTP request message: general format 2: Application Layer 36 HTTP request message: general format 2: Application Layer 36

Uploading form input Post method: r Web page often includes form input r Input Uploading form input Post method: r Web page often includes form input r Input is uploaded to server in entity body URL method: r Uses GET method r Input is uploaded in URL field of request line: www. somesite. com/animalsearch? monkeys&banana 2: Application Layer 37

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

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 39

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 v request succeeded, requested object later in this message 301 Moved Permanently v requested object moved, new location specified later in this message (Location: ) 400 Bad Request v request message not understood by server 404 Not Found v requested document not found on this server 505 HTTP Version Not Supported 2: Application Layer 40

Trying out HTTP (client side) for yourself 1. Telnet to your favorite Web server: Trying out HTTP (client side) for yourself 1. Telnet to your favorite Web server: telnet cis. poly. edu 80 Opens TCP connection to port 80 (default HTTP server port) at cis. poly. edu. Anything typed in sent to port 80 at cis. poly. edu 2. Type in a GET HTTP request: GET /~ross/ 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! 2: Application Layer 41

User-server state: cookies Example: r Susan always access Internet always from PC r visits User-server state: cookies Example: r Susan always access Internet always from PC r visits specific e 1) cookie header line of HTTP response message commerce site for first 2) cookie header line in time HTTP request message r when initial HTTP 3) cookie file kept on user’s host, managed by requests arrives at site, user’s browser site creates: 4) back-end database at v unique ID Web site v entry in backend database for ID Many major Web sites use cookies Four components: 2: Application Layer 42

Cookies: keeping “state” (cont. ) client ebay 8734 cookie file ebay 8734 amazon 1678 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 cookiespectific action 2: Application Layer 43

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 How to keep “state”: r protocol endpoints: maintain state at sender/receiver over multiple transactions r cookies: http messages carry state 2: Application Layer 44

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 v v 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 ues Proxy server t res pon se t es qu e se Pr on T p HT res P TT H client st que re se TP pon HT es Pr T HT origin server 2: Application Layer 45

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 46

Caching example origin servers Assumptions r average object size = 100, 000 bits r Caching example 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 delay + LAN delay = 2 sec + minutes + milliseconds institutional cache 2: Application Layer 47

Caching example (cont) origin servers possible solution r increase bandwidth of access link to, Caching example (cont) origin servers possible solution r increase bandwidth of access link to, say, 10 Mbps consequence 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 48

Caching example (cont) possible solution: install cache r suppose hit rate is 0. 4 Caching example (cont) possible solution: install cache r suppose hit rate is 0. 4 consequence origin servers 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 +. 4*milliseconds < 1. 4 secs 1. 5 Mbps access link institutional network 10 Mbps LAN institutional cache 2: Application Layer 49

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: 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: HTTP response object not modified HTTP/1. 0 304 Not Modified HTTP request msg If-modified-since: HTTP response object modified HTTP/1. 0 200 OK 2: Application Layer 50

Content Distribution Networks r Strategically deploy servers for performance, scalability, cost effectiveness. r Top Content Distribution Networks r Strategically deploy servers for performance, scalability, cost effectiveness. r Top 3: Akamai, Limelight, and CDNetworks r Mirror content, DNS redirect, r P 2 P CDNs 2: Application Layer 51

Content distribution networks (CDNs) r The content providers are the CDN customers. Content replication Content distribution networks (CDNs) r The content providers are the CDN customers. Content replication r CDN company installs hundreds of CDN servers throughout Internet v close to users r CDN replicates its customers’ content in CDN servers. When provider updates content, CDN updates servers origin server in North America CDN distribution node CDN server in S. America CDN server in Europe CDN server in Asia 2: Application Layer 52

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

More about CDNs routing requests r CDN creates a “map”, indicating distances from leaf More about CDNs routing requests r CDN creates a “map”, indicating distances from leaf ISPs and CDN nodes r when query arrives at authoritative DNS server: v v server determines ISP from which query originates uses “map” to determine best CDN server not just Web pages r streaming stored audio/video r streaming real-time audio/video v CDN nodes create application-layer overlay network Companies: 2: Application Layer 54

Content distribution r Web caching r Content distribution networks (CDNs) r Peer-to-peer file sharing Content distribution r Web caching r Content distribution networks (CDNs) r Peer-to-peer file sharing r Web caching helps user-side bottleneck r CDN helps server-side bottleneck 2: Application Layer 55

Web applications r Thin client vs. “thick” client r Also referred to as Rich Web applications r Thin client vs. “thick” client r Also referred to as Rich Internet Applications r Benefits: v Little disk space, automatic upgrade, integrate with other web procedures, cross-platform compatibility, mobility friendly, business reasons r Limits v Internet connectivity, inconsistency in browser implementations, (currently) limited functionalities 2: Application Layer 56

Examples r Google Documents r Gears (original Google Gears), a software platform for Ajax Examples r Google Documents r Gears (original Google Gears), a software platform for Ajax web applications development. v v v open-source, BSD-license, incremental Offline capability (e. g. , Google Reader, Google Docs) Three components • Local. Server: to access the application offline • Database: to store large amounts of structured data • Worker. Pool: to perform long sync when you reconnect (w. o. blocking the browser). r Google browser: Chrome 2: Application Layer 57

r ASP (Application service provider) v Provide web access to software (for monthly or r ASP (Application service provider) v Provide web access to software (for monthly or yearly fees) r Software as a service r Computing as a service 2: Application Layer 58

Amazon EC 2 r Amazon Elastic Computing Cloud v Allow users to rent machines Amazon EC 2 r Amazon Elastic Computing Cloud v Allow users to rent machines managed by Amazon; v Ex: web sites to host files and execute code on Amazon’s servers r Examples of instance v Small Instance (Default) 1. 7 GB of memory, 1 EC 2 Compute Unit (1 virtual core with 1 EC 2 Compute Unit), 160 GB of instance storage, 32 -bit platform v High-CPU Extra Large Instance 7 GB of memory, 20 EC 2 Compute Units (8 virtual cores with 2. 5 EC 2 Compute Units each), 1690 GB of instance storage, 64 -bit platform r On-Demand / Reserved services r Elastic, flexibility r Automated scaling 2: Application Layer 59

Cloud Computing r Amazon web service r IBM Blue Cloud r Google App Engine Cloud Computing r Amazon web service r IBM Blue Cloud r Google App Engine r Microsoft Azure r Rack. Space cloud computing r Go. Grid r Cellular phone cloud (Intel) 2: Application Layer 60

Web 2. 0 r Origin: Web 2. 0 Conference in 2004 r “embrace the Web 2. 0 r Origin: Web 2. 0 Conference in 2004 r “embrace the strength of the web and use it as a platform”, -- Tim O’Reilly r Enabling technologies: Ajax, Flex, etc. r Rich user experience, user participation, dynamic r r content, meta data, web standards and scalability. Interactive, more cooperation, distributed Craigslist, Flickr, del. icio. us, Wikipedia, Adsense, Ebay, Twitter, You. Tube Blog, podcast, tagging, etc. Critics 2: Application Layer 61

Long Tail r In statistics, refers to distributions that are probability distributions whose tails Long Tail r In statistics, refers to distributions that are probability distributions whose tails are not exponentially bounded r the niche strategy of businesses, such as Amazon. com or Netflix, that sell a large number of unique items, each in relatively small quantities. r Large stores vs. small businesses r An example of “embracing the Internet”, instead of fighting it. 2: Application Layer 62

Acknowledgement: Wikipedia 2: Application Layer 63 Acknowledgement: Wikipedia 2: Application Layer 63

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 v SMTP, POP 3, IMAP r 2. 5 DNS r 2. 6 P 2 P applications r 2. 7 Socket programming with TCP r 2. 8 Socket programming with UDP r 2. 9 Building a Web server 2: Application Layer 64

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) v server: remote host r ftp: RFC 959 r ftp server: port 21 v 2: Application Layer 65

FTP: separate control, data connections r FTP client contacts FTP server r r TCP FTP: separate control, data connections r FTP client contacts FTP server r r TCP control connection port 21 at port 21, TCP is transport protocol TCP data connection FTP port 20 client authorized over control client server connection client browses remote r server opens another TCP directory by sending commands data connection to transfer over control connection. another file. when server receives file r control connection: “out of transfer command, server band” opens 2 nd TCP connection (for r FTP server maintains “state”: file) to client current directory, earlier after transferring one file, authentication server closes data connection. 2: Application Layer 66

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 67

[liu@shannon ~]$ ftp -v ftp. uu. net Connected to ftp. uu. net. 220 FTP [liu@shannon ~]$ ftp -v ftp. uu. net Connected to ftp. uu. net. 220 FTP server ready. 530 Please login with USER and PASS. KERBEROS_V 4 rejected as an authentication type Name (ftp. uu. net: liu): anonymous 331 Guest login ok, send your complete e-mail address as password. Password: 230230 Welcome to the UUNET archive. 230 - A service of UUNET Technologies Inc, Falls Church, Virginia 230 - For information about UUNET, call +1 703 206 5600, or see the files 230 - in /uunet-info …. 230 Guest login ok, access restrictions apply. Remote system type is UNIX. Using binary mode to transfer files. 2: Application Layer 68

ftp> ls 227 Entering Passive Mode (192, 48, 96, 9, 118, 43) 150 Opening ftp> ls 227 Entering Passive Mode (192, 48, 96, 9, 118, 43) 150 Opening ASCII mode data connection for /bin/ls. total 20088 drwxr-sr-x 2 1 512 Jun 29 2001. forward -rw-r--r-- 1 11 0 Jun 29 2001. hushlogin -rw-r--r-- 1 100 59 Jun 29 2001. kermrc 226 Transfer complete. ftp> ls 227 Entering Passive Mode (192, 48, 96, 9, 125, 39) 150 Opening ASCII mode data connection for /bin/ls. total 20088 drwxr-sr-x 2 1 512 Jun 29 2001. forward -rw-r--r-- 1 11 0 Jun 29 2001. hushlogin -rw-r--r-- 1 100 59 Jun 29 2001. kermrc -rw-r--r-- 1 100 0 Jun 29 2001. notar 226 Transfer complete. ftp> bi 200 Type set to I. ftp> quit 221 -You have transferred 0 bytes in 0 files. 221 -Total traffic for this session was 7739 bytes in 2 transfers. 221 -Thank you for using the FTP service on neo-ftp. uu. net. 221 Goodbye. Note: server does the active open/close of the data connection. 2: Application Layer Connection close=file complete 69

SFTP r SFTP: SSH file transfer protocol or Secure File transfer protocol r Main SFTP r SFTP: SSH file transfer protocol or Secure File transfer protocol r Main motivation: encrypts both commands and data. r Graphical and command line SFTP client. 2: Application Layer 70

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 v r 2. 6 P 2 P applications r 2. 7 Socket programming with TCP r 2. 8 Socket programming with UDP SMTP, POP 3, IMAP r 2. 5 DNS 2: Application Layer 71

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, Mozilla Thunderbird r outgoing, incoming messages stored on server SMTP mail server user agent SMTP user agent mail server user agent 2: Application Layer 72

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 v client: sending mail server v “server”: receiving mail server SMTP mail server user agent SMTP user agent mail server user agent 2: Application Layer 73

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 v handshaking (greeting) v transfer of messages v closure r command/response interaction v commands: ASCII text v response: status code and phrase r messages must be in 7 -bit ASCII 2: Application Layer 74

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 75

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: 250 alice@crepes. fr. . . Sender ok RCPT TO: 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 76

Invoke user’s agent jadzia: ~ % mail -v xinliu@shay. ecn. purdue. edu Subject: hello Invoke user’s agent jadzia: ~ % mail -v xinliu@shay. ecn. purdue. edu Subject: hello test. EOT xinliu@shay. ecn. purdue. edu. . . Connecting to shay. ecn. purdue. edu. via esmtp. . . 220 shay. ecn. purdue. edu ESMTP Sendmail 8. 12. 10/8. 12. 10; Wed, 19 Nov 2003 15: 35: 00 -0500 (EST) Greeting >>> EHLO jadzia. ifp. uiuc. edu 250 -shay. ecn. purdue. edu Hello jadzia. ifp. uiuc. edu [130. 126. 122. 22], pleased to meet you Identify itself 250 -ENHANCEDSTATUSCODES 250 -PIPELINING 250 -8 BITMIME 250 -SIZE 250 -DSN 250 -ETRN 250 -STARTTLS 250 -DELIVERBY 250 HELP >>> MAIL From: SIZE=70 Identify originator 250 2. 1. 0 . . . Sender ok >>> RCPT To: Identify receiver >>> DATA 250 2. 1. 5 . . . Recipient ok 354 Enter mail, end with ". " on a line by itself >>>. 250 2. 0. 0 h. AJKZ 06 i 019357 Message accepted for delivery xinliu@shay. ecn. purdue. edu. . . Sent (h. AJKZ 06 i 019357 Message accepted for delivery) Closing connection to shay. ecn. purdue. edu. >>> QUIT 221 2. 0. 0 shay. ecn. purdue. edu closing connection 2: Application Layer 77

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 HTTP: persistent and non-p r SMTP: persistent 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 78

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. , To: v From: v Subject: different from SMTP commands! v header blank line body r body v the “message”, ASCII characters only 2: Application Layer 79

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 80

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

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 From srikant@ifp. uiuc. edu Fri Oct 18 14: 59: 04 2002 Received: from dosai. csl. uiuc. edu (dosai. csl. uiuc. edu [130. 126. 137. 172]) by jadzia. ifp. uiuc. edu (8. 10. 1/8. 10. 1) with ESMTP id g 9 IJwv. M 27934 for ; Fri, 18 Oct 2002 14: 58: 57 -0500 (CDT) Received: from localhost (srikant@localhost) by dosai. csl. uiuc. edu (8. 10. 0/8. 10. 0) with ESMTP id g 9 IJx 2923097 for ; Fri, 18 Oct 2002 14: 59: 02 -0500 (CDT) Date: Fri, 18 Oct 2002 14: 59: 01 -0500 (CDT) From: Rayadurgam Srikant To: Xin Liu Subject: CV Message-ID: MIME-Version: 1. 0 Content-Type: TEXT/PLAIN; charset=US-ASCII Content-Length: 274 Status: RO X-Status: X-Keywords: X-UID: 3 2: Application Layer 82

From: Rayadurgam Srikant <srikant@ifp. uiuc. edu> To: Xin Liu <xinliu@ifp. uiuc. edu> Subject: CV From: Rayadurgam Srikant To: Xin Liu Subject: CV Message-ID: MIME-Version: 1. 0 Content-Type: MULTIPART/MIXED; BOUNDARY="-559023410 -851401618 -1034971141=: 23095" Content-Length: 150065 Status: RO X-Status: X-Keywords: X-UID: 16 This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. Send mail to mime@docserver. cac. washington. edu for more info. ---559023410 -851401618 -1034971141=: 23095 Content-Type: TEXT/PLAIN; charset=US-ASCII ------R. Srikant 1308 W. Main Street Associate Professor Urbana, IL 61801 Coordinated Science Lab. and (217) 333 -2457 (Phone) Department of General Engineering (217) 244 -1642 (Fax) University of Illinois rsrikant@uiuc. edu http: //comm. csl. uiuc. edu/~srikant ---559023410 -851401618 -1034971141=: 23095 Content-Type: APPLICATION/Post. Script; name="my_bio. ps" Content-Transfer-Encoding: BASE 64 Content-Description: Content-Disposition: attachment; filename="my_bio. ps" 2: Application Layer 83

RFC 821 r 4. 5. 2. TRANSPARENCY The mail data may contain any of RFC 821 r 4. 5. 2. TRANSPARENCY The mail data may contain any of the 128 ASCII characters. All characters are to be delivered to the recipient's mailbox including format effectors and other control characters. If the transmission channel provides an 8 -bit byte (octets) data stream, the 7 -bit ASCII codes are transmitted right justified in the octets with the high order bits cleared to zero. In some systems it may be necessary to transform the data as it is received and stored. This may be necessary for hosts that use a different character set than ASCII as their local character set, or that store data in records rather than strings. If such transforms are necessary, they must be reversible -- especially if such transforms are applied to mail being relayed. 2: Application Layer 84

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 v v v POP: Post Office Protocol [RFC 1939] • authorization (agent <-->server) and download IMAP: Internet Mail Access Protocol [RFC 1730] • more features (more complex) • manipulation of stored msgs on server HTTP: gmail, Hotmail, Yahoo! Mail, etc. 2: Application Layer 85

POP 3 protocol authorization phase r client commands: v v user: declare username pass: POP 3 protocol authorization phase r client commands: v v user: declare username pass: password r server responses v v +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 . dele 1 retr 2 . dele 2 quit +OK POP 3 server signing off 2: Application Layer 86 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: v names of folders and mappings between message IDs and folder name 2: Application Layer 87

Social and Economic Impacts r Social impact r Economic impact r Managing emails r Social and Economic Impacts r Social impact r Economic impact r Managing emails r Etiquette r Spam 2: Application Layer 88

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 v SMTP, POP 3, IMAP r 2. 5 DNS r 2. 6 P 2 P applications r 2. 7 Socket programming with TCP r 2. 8 Socket programming with UDP r 2. 9 Building a Web server 2: Application Layer 89

DNS r What does it do? r Is it a user-application or a functionality DNS r What does it do? r Is it a user-application or a functionality of Internet core? 2: Application Layer 90

DNS: Domain Name System People: many identifiers: v SSN, name, passport # Internet hosts, DNS: Domain Name System People: many identifiers: v SSN, name, passport # Internet hosts, routers: v v IP address (32 bit) used for addressing datagrams “name”, e. g. , ww. 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) v note: core Internet function, implemented as application-layer protocol v complexity at network’s “edge” 2: Application Layer 91

DNS services r hostname to IP address translation r host aliasing v Canonical, alias DNS services r hostname to IP address translation r host aliasing v Canonical, alias names r mail server aliasing r load distribution v 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 92

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 ucdavis. 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 93

DNS: Root name servers r contacted by local name server that can not resolve DNS: Root name servers r contacted by local name server that can not resolve name r root name server: v v v contacts authoritative name server if name mapping not known gets mapping returns mapping to local name server a Verisign, Dulles, VA c Cogent, Herndon, VA (also LA) d U Maryland College Park, MD g US Do. D Vienna, VA h ARL Aberdeen, MD j Verisign, ( 21 locations) e NASA Mt View, CA f Internet Software C. Palo Alto, k RIPE London (also 16 other locations) i Autonomica, Stockholm (plus 28 other locations) m WIDE Tokyo (also Seoul, Paris, SF) CA (and 36 other locations) 13 root name servers worldwide b USC-ISI Marina del Rey, CA l ICANN Los Angeles, CA 2: Application Layer 94

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

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. v also called “default name server” r when host makes DNS query, query is sent to its local DNS server v acts as proxy, forwards query into hierarchy 2: Application Layer 96

DNS name resolution example root DNS server 2 r Host at cis. poly. edu DNS name resolution example root DNS server 2 r Host at cis. poly. edu wants IP address for gaia. cs. umass. edu iterated query: r contacted server replies with name of server to contact r “I don’t know this name, but ask this server” 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 97

DNS name resolution example recursive query: root DNS server 2 r puts burden of DNS name resolution example recursive query: root DNS server 2 r puts burden of name resolution on contacted name server r heavy load? 3 7 local DNS server dns. poly. edu 1 6 TLD DNS server 5 4 8 requesting host authoritative DNS server dns. cs. umass. edu cis. poly. edu gaia. cs. umass. edu 2: Application Layer 98

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 v cache entries timeout (disappear) after some time v TLD servers typically cached in local name servers • Thus root name servers not often visited r update/notify mechanisms under design by IETF v RFC 2136 v http: //www. ietf. org/html. charters/dnsind-charter. html 2: Application Layer 99

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

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: v query or reply v recursion desired v recursion available v reply is authoritative 2: Application Layer 101

DNS protocol, messages Name, type fields for a query RRs in response to query 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 2: Application Layer 102

Inserting records into DNS r example: new startup “Network Utopia” r register name networkuptopia. Inserting records into DNS r example: new startup “Network Utopia” r register name networkuptopia. com at DNS registrar (e. g. , Network Solutions) v v 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) r create authoritative server Type A record for www. networkuptopia. com; Type MX record for networkutopia. com r How do people get IP address of your Web site? r Domain name value 2: Application Layer 103

Transport Layer r UDP or TCP r “Queries are messages which may be sent Transport Layer r UDP or TCP r “Queries are messages which may be sent to a name server to provoke a response. In the Internet, queries are carried in UDP datagrams or over TCP connections. ” RFC 1034 r “An update transaction may be carried in a UDP datagram, if the request fits, or in a TCP connection (at the discretion of the requestor). When TCP is used, the message is in the format described in [RFC 1035 4. 2. 2]. ” RFC 2136, DNS update 2: Application Layer 104

DNS related RFCs r Over 100 DNS-related RFC, about 20 obsolete ones. r http: DNS related RFCs r Over 100 DNS-related RFC, about 20 obsolete ones. r http: //www. dns. net/dnsrd/rfc/ 2: Application Layer 105

DNS attacks r Large-scale root DNS server DDo. S attacks, 2002, 2007 r DNS DNS attacks r Large-scale root DNS server DDo. S attacks, 2002, 2007 r DNS cache poisoning attacks r. . . 2: Application Layer 106

Chapter 2: Application layer r 2. 1 Principles of network applications v v app Chapter 2: Application layer r 2. 1 Principles of network applications v v app architectures app requirements r 2. 2 Web and HTTP r 2. 4 Electronic Mail v SMTP, POP 3, IMAP r 2. 6 P 2 P applications r 2. 7 Socket programming with TCP r 2. 8 Socket programming with UDP r 2. 5 DNS 2: Application Layer 107

Pure P 2 P architecture r no always-on server r arbitrary end systems directly 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 r Three topics: v File distribution v Searching for information v Case Study: Skype 2: Application Layer 108

File Distribution: Server-Client vs P 2 P Question : How much time to distribute 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) 2: Application Layer 109

File distribution time: server-client r server sequentially sends N copies: v NF/us time r File distribution time: server-client r server sequentially sends N copies: v 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 N clients using = dcs = max { NF/us, F/min(di) } i client/server approach increases linearly in N (for large N) 2: Application Layer 110

File distribution time: P 2 P r server must send one Server F u File distribution time: P 2 P r server must send one Server 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) r fastest possible upload rate: us + Sui d. P 2 P = max { F/us, F/min(di) , NF/(us + i S ui ) } 2: Application Layer 111

Server-client vs. P 2 P: example Client upload rate = u, F/u = 1 Server-client vs. P 2 P: example Client upload rate = u, F/u = 1 hour, us = 10 u, dmin ≥ us 2: Application Layer 112

File distribution: Bit. Torrent r P 2 P file distribution tracker: tracks peers participating File distribution: Bit. Torrent r 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 2: Application Layer 113

Bit. Torrent (1) r file divided into 256 KB chunks. r peer joining torrent: Bit. Torrent (1) r file divided into 256 KB chunks. r peer joining torrent: has no chunks, but will accumulate them over time v registers with tracker to get list of peers, connects to 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 or (altruistically) remain v 2: Application Layer 114

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

Bit. Torrent: Tit-for-tat (1) Alice “optimistically unchokes” Bob (2) Alice becomes one of Bob’s 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 With higher upload rate, can find better trading partners & get file faster! 2: Application Layer 116

P 2 P: searching for information Index in P 2 P system: maps information P 2 P: searching for information Index in P 2 P system: maps information to peer location (location = IP address & port number). Instant messaging File sharing (eg e-mule) r Index maps user names r Index dynamically to locations. tracks the locations of files that peers share. r When user starts IM application, it needs to r Peers need to tell inform index of its index what they have. location r Peers search index to determine where files determine IP address can be found of user. 2: Application Layer 117

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

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: “target” of lawsuit is obvious file transfer is decentralized, but locating content is highly centralized 2: Application Layer 119

Query flooding r fully distributed v no central server r used by Gnutella r Query flooding r fully distributed v no central server r used by Gnutella r Each peer indexes the files it makes available for sharing (and no other files) 2: Application Layer 121

Distributed Hash Table (DHT) r DHT = distributed P 2 P database r Database Distributed Hash Table (DHT) r DHT = distributed P 2 P database r Database has (key, value) pairs; v key: ss number; value: human name v key: content type; value: IP address r Peers query DB with key v DB returns values that match the key r Peers can also insert (key, value) peers 2: Application Layer 122

DHT Identifiers r Assign integer identifier to each peer in range [0, 2 n-1]. DHT Identifiers r Assign integer identifier to each peer in range [0, 2 n-1]. v Each identifier can be represented by n bits. r Require each key to be an integer in same range. r To get integer keys, hash original key. v eg, key = h(“Led Zeppelin IV”) v This is why they call it a distributed “hash” table 2: Application Layer 123

How to assign keys to peers? r Central issue: v Assigning (key, value) pairs How to assign keys to peers? r Central issue: v Assigning (key, value) pairs to peers. r Rule: assign key to the peer that has the closest ID. r Convention in lecture: closest is the immediate successor of the key. r Ex: n=4; peers: 1, 3, 4, 5, 8, 10, 12, 14; key = 13, then successor peer = 14 v key = 15, then successor peer = 1 v Q: how to insert a (key, value) pair? How to decide which peer? 2: Application Layer 124

Circular DHT (1) 1 3 15 4 12 5 10 8 r Each peer Circular DHT (1) 1 3 15 4 12 5 10 8 r Each peer only aware of immediate successor and predecessor. r “Overlay network” 2: Application Layer 125

Overlay r overlay network: graph r edge between peer X and Y if there’s Overlay r overlay network: graph r edge between peer X and Y if there’s a TCP connection r all active peers and edges form overlay net r edge: virtual (not physical) link r given peer typically connected with < 10 overlay neighbors 2: Application Layer 126

Circle DHT (2) O(N) messages on avg to resolve query, when there are N Circle DHT (2) O(N) messages on avg to resolve query, when there are N peers 0001 I am Who’s resp 0011 for key 1110 ? 1111 1110 0100 1110 1100 1110 Define closest as closest successor 1010 1110 0101 1110 1000 2: Application Layer 127

Circular DHT with Shortcuts 1 3 15 Who’s resp for key 1110? 4 12 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, short cuts. r Reduced from 6 to 2 messages. r Possible to design shortcuts so O(log N) neighbors, O(log N) messages in query Q; how many shortcuts? 2: Application Layer 128

Peer Churn 1 • To handle peer churn, require 3 15 4 12 5 Peer Churn 1 • To handle peer churn, require 3 15 4 12 5 10 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. 8 r 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 What if peer 13 wants to join? 2: Application Layer 129

P 2 P Case study: Skype clients (SC) r inherently P 2 P: pairs P 2 P Case study: Skype clients (SC) r inherently P 2 P: pairs of users communicate. r proprietary application Skype login server -layer protocol (inferred via reverse engineering) r hierarchical overlay with SNs r Index maps usernames to IP addresses; distributed over SNs Supernode (SN) 2: Application Layer 133

Peers as relays r Problem when both Alice and Bob are behind “NATs”. v Peers as relays r Problem when both Alice and Bob are behind “NATs”. v NAT prevents an outside peer from initiating a call to insider peer r Solution: v Using Alice’s and Bob’s SNs, Relay is chosen v Each peer initiates session with relay. v Peers can now communicate through NATs via relay 2: Application Layer 134

P 2 PTV r Joost r PPLive r PPstream 2: Application Layer 135 P 2 PTV r Joost r PPLive r PPstream 2: Application Layer 135

P 2 P r Legality issue r Network operator p 2 p filtering/throttling r P 2 P r Legality issue r Network operator p 2 p filtering/throttling r Network neutrality 2: Application Layer 136

Chapter 2: Summary our study of network apps now complete! r application architectures v Chapter 2: Summary our study of network apps now complete! r application architectures v client-server v P 2 P v hybrid r application service requirements: v reliability, bandwidth, delay r specific protocols: v HTTP v FTP v SMTP, POP, IMAP v DNS v P 2 P: Bit. Torrent, Skype r socket programming r Internet transport service model v v connection-oriented, reliable: TCP unreliable, datagrams: UDP 2: Application Layer 137

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

Now this is not the end. It is not even the beginning of the Now this is not the end. It is not even the beginning of the end. But it is, perhaps, the end of the beginning. - Winston Churchill 2: Application Layer 139