计算机网络教学课件:Chapter 2 Application layer

上传人:壹****1 文档编号:569945433 上传时间:2024-07-31 格式:PPT 页数:113 大小:2.84MB
返回 下载 相关 举报
计算机网络教学课件:Chapter 2 Application layer_第1页
第1页 / 共113页
计算机网络教学课件:Chapter 2 Application layer_第2页
第2页 / 共113页
计算机网络教学课件:Chapter 2 Application layer_第3页
第3页 / 共113页
计算机网络教学课件:Chapter 2 Application layer_第4页
第4页 / 共113页
计算机网络教学课件:Chapter 2 Application layer_第5页
第5页 / 共113页
点击查看更多>>
资源描述

《计算机网络教学课件:Chapter 2 Application layer》由会员分享,可在线阅读,更多相关《计算机网络教学课件:Chapter 2 Application layer(113页珍藏版)》请在金锄头文库上搜索。

1、Chapter 2 Application layer2.1 Principles of network applications2.2 Web and HTTP2.3 FTP 2.4 Electronic MailSMTP, POP3, IMAP2.5 DNS2.6 P2P applications2.7 Socket programming with TCP2.8 Socket programming with UDPApplication 2-1Chapter 2: Application LayerOur goals: vconceptual, implementation aspec

2、ts of network application protocolstransport-layer service modelsclient-server paradigmpeer-to-peer paradigmvlearn about protocols by examining popular application-level protocolsHTTPFTPSMTP / POP3 / IMAPDNSvprogramming network applicationssocket APIApplication 2-2Some network appsve-mailvwebvinstan

3、t messagingvremote loginvP2P file sharingvmulti-user network gamesvstreaming stored video (YouTube)vvoice over IPvreal-time video conferencingvcloud computingvRemote desktop communicationv Application 2-3Creating a network appwrite programs thatrun on (different) end systemscommunicate over networke

4、.g., web server software communicates with browser softwareNo need to write software for network-core devicesnetwork-core devices do not run user applications applications on end systems allows for rapid app development, propagationapplicationtransportnetworkdata linkphysicalapplicationtransportnetw

5、orkdata linkphysicalapplicationtransportnetworkdata linkphysicalApplication 2-4Chapter 2: Application layer2.1 Principles of network applications2.2 Web and HTTP2.3 FTP 2.4 Electronic MailSMTP, POP3, IMAP2.5 DNS2.6 P2P applications2.7 Socket programming with TCP2.8 Socket programming with UDPApplica

6、tion 2-5Application architecturesvclient-servervpeer-to-peer (P2P)vhybrid of client-server and P2PApplication 2-6Client-server architectureserver: always-on hostpermanent IP addressserver farms for scalingclients:communicate with servermay be intermittently (间歇地) connectedmay have dynamic IP address

7、esdo not communicate directly with each otherclient/serverApplication 2-7Pure P2P architecturevno always-on servervArbitrary (任意的) end systems directly communicatevpeers are intermittently connected and change IP addresseshighly scalable (伸缩性) but difficult to managepeer-peerApplication 2-8Hybrid of

8、 client-server and P2PSkypevoice-over-IP P2P applicationcentralized server: finding address of remote party: client-client connection: direct (not through server) Instant messagingchatting between two users is P2Pcentralized service: client presence detection/locationuser registers its IP address wi

9、th central server when it comes onlineuser contacts central server to find IP addresses of buddiesApplication 2-9Processes communicatingprocess: program running within a host.vwithin same host, two processes communicate using inter-process communication (进程间通信 vdefined by OS).vprocesses in different

10、 hosts communicate by exchanging messagesclient process: process that initiates 初始化communicationserver process: process that waits to be contacted 被被联系vaside: applications with P2P architectures have client processes & server processesApplication 2-10Socketsvprocess sends/receives messages to/from i

11、ts socketvsocket analogous to doorsending process shoves 推 message out doorsending process relies on transport infrastructure on other side of door which brings message to socket at receiving processprocessTCP withbuffers,variablessockethost orserverprocessTCP withbuffers,variablessockethost orserve

12、rInternetcontrolledby OScontrolled byapp developervAPI: (1) choice of transport protocol; (2) ability to fix a few parameters (lots more on this later) Application 2-11Addressing processesvto receive messages, process must have identifiervhost device has unique 32-bit IP addressvQ: does IP address o

13、f host on which process runs suffice for identifying the process?Application 2-12Addressing processesvto receive messages, process must have identifiervhost device has unique 32-bit IP addressvQ: does IP address of host on which process runs suffice for identifying the process?A: No, many processes

14、can be running on same hostvidentifier includes both IP address and port numbers associated with process on host.vexample port numbers:HTTP server: 80Mail server: 25vto send HTTP message to gaia.cs.umass.edu web server:IP address: 128.119.245.12Port number: 80vmore shortlyApplication 2-13App-layer p

15、rotocol definesvtypes of messages exchanged, e.g., request, response vmessage syntax:what fields in messages & how fields are delineatedvmessage semantics meaning of information in fieldsvrules for when and how processes send & respond to messagespublic-domain protocols:vdefined in RFCsvallows for i

16、nteroperabilityve.g., HTTP, SMTPproprietary protocols:ve.g., SkypeApplication 2-14What transport service does an app need?Data lossvsome apps (e.g., audio) can tolerate some lossvother apps (e.g., file transfer, telnet) require 100% reliable data transfer Timingvsome apps (e.g., Internet telephony,

17、interactive games) require low delay to be “effective”Throughputvsome apps (e.g., multimedia) require minimum amount of throughput to be “effective”vother apps (“elastic弹性 apps”) make use of whatever throughput they get SecurityvEncryption加密, data integrity完整, Application 2-15Transport service requi

18、rements of common appsApplicationfile transfere-mailWeb documentsreal-time audio/videostored audio/videointeractive gamesinstant messagingData lossno lossno lossno lossloss-tolerant可容忍丢失loss-tolerantloss-tolerantno lossThroughputelasticelasticelasticaudio: 5kbps-1Mbpsvideo:10kbps-5Mbpssame as above

19、few kbps upelasticTime Sensitivenononoyes, 100s msecyes, few secsyes, 100s msecyes and noApplication 2-16Internet transport protocols servicesTCP service:vconnection-oriented: setup required between client and server processesvreliable transport between sending and receiving processvflow control: se

20、nder wont overwhelm 塞满 receiver vcongestion control: throttle 节流 sender when network overloadedvdoes not provide: timing, minimum throughput guarantees, securityUDP service:vunreliable data transfer between sending and receiving processvdoes not provide: connection setup, reliability, flow control,

21、congestion control, timing, throughput guarantee, or security Q: why bother? Why is there a UDP?Application 2-17Internet apps: application, transport protocolsApplicatione-mailremote terminal accessWeb file transferstreaming multimediaInternet telephonyApplicationlayer protocolSMTP RFC 2821Telnet RF

22、C 854HTTP RFC 2616FTP RFC 959HTTP (e.g., YouTube), RTP RFC 1889SIP, RTP, proprietary(e.g., Skype)Underlyingtransport protocolTCPTCPTCPTCPTCP or UDPtypically UDPApplication 2-18Chapter 2: Application layer2.1 Principles of network applications app architecturesapp requirements2.2 Web and HTTP2.3 FTP2

23、.4 Electronic MailSMTP, POP3, IMAP2.5 DNS2.6 P2P applications2.7 Socket programming with TCP2.8 Socket programming with UDPApplication 2-19Web and HTTPFirst, a reviewvweb page consists of objectsvobject can be HTML file, JPEG image, Java applet, audio file,vweb page consists of base HTML-file which

24、includes several referenced objectsveach object is addressable by a URLvexample URL:www.someschool.edu/someDept/pic.gifhost namepath nameApplication 2-20HTTP overviewHTTP: hypertext transfer protocolvWebs application layer protocolvclient/server modelclient: browser that requests, receives, “display

25、s” Web objectsserver: Web server sends objects in response to requestsPC runningExplorerServer runningApache WebserverMac runningNavigatorHTTP requestHTTP requestHTTP responseHTTP responseApplication 2-21HTTP overview (continued)Uses TCP:vclient initiates TCP connection (creates socket) to server, p

26、ort 80vserver accepts TCP connection from clientvHTTP messages (application-layer protocol messages) exchanged between browser (HTTP client) and Web server (HTTP server)vTCP connection closedHTTP is “stateless” 无状态vserver maintains no information about past client requestsprotocols that maintain “st

27、ate” are complex!vpast history (state) must be maintainedvif server/client crashes, their views of “state” may be inconsistent, must be reconciledasideApplication 2-22HTTP connectionsnon-persistent HTTP非持续的vat most one object sent over TCP connection.persistent HTTPvmultiple objects can be sent over

28、 single TCP connection between client, server.Application 2-23Nonpersistent HTTPsuppose user enters URL:1a. HTTP client initiates TCP connection to HTTP server (process) at www.someSchool.edu on port 802. HTTP client sends HTTP request message (containing URL) into TCP connection socket. Message ind

29、icates that client wants object someDepartment/home.index1b. HTTP server at host www.someSchool.edu waiting for TCP connection at port 80. “accepts” connection, notifying client3. HTTP server receives request message, forms response message containing requested object, and sends message into its soc

30、kettime(contains text, references to 10 jpeg images)Application 2-24www.someSchool.edu/someDepartment/home.indexNonpersistent HTTP (cont.)5. HTTP client receives response message containing html file, displays html. Parsing html file, finds 10 referenced jpeg objects6. Steps 1-5 repeated for each of

31、 10 jpeg objects4. HTTP server closes TCP connection. timeApplication 2-25Non-Persistent HTTP: Response timedefinition of RTT: time for a small packet to travel from client to server and back.response time:vone RTT to initiate TCP connectionvone RTT for HTTP request and first few bytes of HTTP respo

32、nse to returnvfile transmission timetotal = 2RTT+transmit timetime to transmit fileinitiate TCPconnectionRTTrequestfileRTTfilereceivedtimetimeApplication 2-26Persistent HTTPnon-persistent HTTP issues:vrequires 2 RTTs per objectvOS overhead for each TCP connectionvbrowsers often open parallel TCP con

33、nections to fetch referenced objectspersistent HTTPvserver leaves connection open after sending responsevsubsequent HTTP messages between same client/server sent over open connectionvclient sends requests as soon as it encounters a referenced objectvas little as one RTT for all the referenced object

34、sApplication 2-27HTTP request messagevtwo types of HTTP messages: request, responsevHTTP request message:ASCII (human-readable format)request line(GET, POST, HEAD commands)header linescarriage return, line feed at startof line indicatesend of header linesApplication 2-28GET /index.html HTTP/1.1rnHos

35、t: www-net.cs.umass.edurnUser-Agent: Firefox/3.6.10rnAccept: text/html,application/xhtml+xmlrnAccept-Language: en-us,en;q=0.5rnAccept-Encoding: gzip,deflaternAccept-Charset: ISO-8859-1,utf-8;q=0.7rnKeep-Alive: 115rnConnection: keep-alivernrncarriage return characterline-feed characterHTTP request me

36、ssage: general formatApplication 2-29requestlineheaderlinesbodyUploading form inputPOST method:web page often includes form inputvinput is uploaded to server in entity bodyURL method:vuses GET methodvinput is uploaded in URL field of request line: 2-30Method typesHTTP/1.0vGETvPOSTvHEADasks server to

37、 leave requested object out of responseHTTP/1.1vGET, POST, HEADvPUTuploads file in entity body to path specified in URL fieldvDELETEdeletes file specified in the URL fieldApplication 2-31HTTP response messagestatus line(protocolstatus codestatus phrase)header linesdata, e.g., requestedHTML fileAppli

38、cation 2-32HTTP/1.1 200 OKrnDate: Sun, 26 Sep 2010 20:09:20 GMTrnServer: Apache/2.0.52 (CentOS)rnLast-Modified: Tue, 30 Oct 2007 17:00:02 GMTrnETag: 17dc6-a5c-bf716880rnAccept-Ranges: bytesrnContent-Length: 2652rnKeep-Alive: timeout=10, max=100rnConnection: Keep-AlivernContent-Type: text/html; chars

39、et=ISO-8859-1rnrndata data data data data . HTTP response status codes200 OKrequest succeeded, requested object later in this msg301 Moved Permanentlyrequested object moved, new location specified later in this msg (Location:)400 Bad Requestrequest msg not understood by server404 Not Foundrequested

40、document not found on this server505 HTTP Version Not Supportedvstatus code appears in 1st line in server-client response message.vsome sample codes:Application 2-33Trying out HTTP (client side) for yourself1. Telnet to your favorite Web server:opens TCP connection to port 80(default HTTP server por

41、t) at cis.poly.edu.anything typed in sent to port 80 at cis.poly.edutelnet cis.poly.edu 802. type in a GET HTTP request:GET /ross/ HTTP/1.1Host: cis.poly.eduby typing this in (hit carriagereturn twice), you sendthis minimal (but complete) GET request to HTTP server3. look at response message sent by

42、 HTTP server!Application 2-34(or use Wireshark!)User-server state: cookiesmany Web sites use cookiesfour components:1) cookie header line of HTTP response message2) cookie header line in HTTP request message3) cookie file kept on users host, managed by users browser4) back-end database at Web siteex

43、ample:vSusan always access Internet from PCvvisits specific e-commerce site for first timevwhen initial HTTP requests arrives at site, site creates: unique IDentry in backend database for IDApplication 2-35Cookies: keeping “state” (cont.)clientserverusual http response msgusual http response msgcook

44、ie fileone week later:usual http request msgcookie: 1678cookie-specificactionaccessebay 8734usual http request msgAmazon servercreates ID1678 for usercreate entryusual http response Set-cookie: 1678 ebay 8734amazon 1678usual http request msgcookie: 1678cookie-specificactionaccessebay 8734amazon 1678

45、backenddatabaseApplication 2-36Cookies (continued)what cookies can bring:vAuthorization授权vshopping cartsvrecommendationsvuser session state (Web e-mail)cookies and privacy:vcookies permit sites to learn a lot about youvyou may supply name and e-mail to sitesasidehow to keep “state”:vprotocol endpoin

46、ts: maintain state at sender/receiver over multiple transactionsvcookies: http messages carry stateApplication 2-37Web caches (proxy server)vuser sets browser: Web accesses via cachevbrowser sends all HTTP requests to cacheobject in cache: cache returns object else cache requests object from origin

47、server, then returns object to clientGoal: satisfy client request without involving origin serverclientProxyserverclientHTTP requestHTTP responseHTTP requestHTTP requestorigin serverorigin serverHTTP responseHTTP responseApplication 2-38More about Web cachingvcache acts as both client and servervtyp

48、ically cache is installed by ISP (university, company, residential ISP)why Web caching?vreduce response time for client requestvreduce traffic on an institutions access link.vInternet dense with caches: enables “poor” content providers to effectively deliver content (but so does P2P file sharing)App

49、lication 2-39Caching example assumptionsvaverage object size = 100,000 bitsvavg. request rate from institutions browsers to origin servers = 15/secvdelay from institutional router to any origin server and back to router = 2 secconsequencesvutilization on LAN = 15%vutilization on access link = 100%vt

50、otal delay = Internet delay + access delay + LAN delay = 2 sec + minutes + millisecondsoriginserverspublic Internetinstitutionalnetwork10 Mbps LAN1.5 Mbps access linkinstitutionalcacheApplication 2-40Caching example (cont)possible solutionvincrease bandwidth of access link to, say, 10 Mbpsconsequenc

51、evutilization on LAN = 15%vutilization on access link = 15%vTotal delay = Internet delay + access delay + LAN delay = 2 sec + msecs + msecsvoften a costly upgradeoriginserverspublic Internetinstitutionalnetwork10 Mbps LAN10 Mbps access linkinstitutionalcacheApplication 2-41Caching example (cont)poss

52、ible solution: vinstall cacheconsequencevsuppose hit rate is 0.440% requests will be satisfied almost immediately60% requests satisfied by origin servervutilization of access link reduced to 60%, resulting in negligible 可忽略的 delays (say 10 msec)vtotal avg delay = Internet delay + access delay + LAN

53、delay = .6*(2.01) secs + .4*milliseconds 1.4 secsoriginserverspublic Internetinstitutionalnetwork10 Mbps LAN1.5 Mbps access linkinstitutionalcacheApplication 2-42Conditional GETvGoal: dont send object if cache has up-to-date cached versionvcache: specify date of cached copy in HTTP requestIf-modifie

54、d-since: vserver: response contains no object if cached copy is up-to-date: HTTP/1.0 304 Not ModifiedcacheserverHTTP request msgIf-modified-since: HTTP responseHTTP/1.0 304 Not Modifiedobject not modifiedbeforeHTTP request msgIf-modified-since: HTTP responseHTTP/1.0 200 OKobject modifiedafter Applic

55、ation 2-43Chapter 2: Application layer2.1 Principles of network applications2.2 Web and HTTP2.3 FTP 2.4 Electronic mailSMTP, POP3, IMAP2.5 DNS2.6 P2P applications2.7 Socket programming with TCP2.8 Socket programming with UDPApplication 2-44FTP: the file transfer protocolvtransfer file to/from remote

56、 hostvclient/server modelclient: side that initiates transfer (either to/from remote)server: remote hostvftp: RFC 959vftp server: port 21file transferFTPserverFTPuserinterfaceFTPclientlocal filesystemremote filesystemuser at hostApplication 2-45FTP: separate control, data connectionsvFTP client cont

57、acts FTP server at port 21, TCP is transport protocolvclient authorized over control connectionvclient browses remote directory by sending commands over control connection.vwhen server receives file transfer command, server opens 2nd TCP connection (for file) to clientvafter transferring one file, s

58、erver closes data connection.FTPclientFTPserverTCP control connection,server port 21TCP data connection,server port 20vserver opens another TCP data connection to transfer another file.vcontrol connection: “out of band”vFTP server maintains “state”: current directory, earlier authenticationApplicati

59、on 2-46FTP commands, responsessample commands:vsent as ASCII text over control channelvUSER usernamevPASS passwordvLIST return list of file in current directoryvRETR filename retrieves (gets) filevSTOR filename stores (puts) file onto remote hostsample return codesvstatus code and phrase (as in HTTP

60、)v331 Username OK, password requiredv125 data connection already open; transfer startingv425 Cant open data connectionv452 Error writing fileApplication 2-47Chapter 2: Application layer2.1 Principles of network applications2.2 Web and HTTP2.3 FTP 2.4 Electronic MailSMTP, POP3, IMAP2.5 DNS2.6 P2P app

61、lications2.7 Socket programming with TCP2.8 Socket programming with UDPApplication 2-48Electronic MailThree major components: vuser agents vmail servers vsimple mail transfer protocol: SMTPUser Agentva.k.a. “mail reader”vcomposing, editing, reading mail messagesve.g., Outlook, elm, Mozilla Thunderbi

62、rd, iPhone mail clientvoutgoing, incoming messages stored on serveruser mailboxoutgoing message queuemailserveruseragentuseragentuseragentmailserveruseragentuseragentmailserveruseragentSMTPSMTPSMTPApplication 2-49Electronic Mail: mail serversMail Servers vmailbox contains incoming messages for userv

63、message queue of outgoing (to be sent) mail messagesvSMTP protocol between mail servers to send email messagesclient: sending mail server“server”: receiving mail servermailserveruseragentuseragentuseragentmailserveruseragentuseragentmailserveruseragentSMTPSMTPSMTPApplication 2-50Electronic Mail: SMT

64、P RFC 2821vuses TCP to reliably transfer email message from client to server, port 25vdirect transfer: sending server to receiving servervthree phases of transferhandshaking (greeting)transfer of messagesclosurevcommand/response interactioncommands: ASCII textresponse: status code and phrasevmessage

65、s must be in 7-bit ASCIIApplication 2-51Scenario: Alice sends message to Bob1) Alice uses UA to compose message and “to” bobsomeschool.edu2) Alices UA sends message to her mail server; message placed in message queue3) Client side of SMTP opens TCP connection with Bobs mail server4) SMTP client send

66、s Alices message over the TCP connection5) Bobs mail server places the message in Bobs mailbox6) Bob invokes his user agent to read messageuseragentmailservermailserveruseragent123456Application 2-52Sample SMTP interaction S: 220 hamburger.edu C: HELO crepes.fr S: 250 Hello crepes.fr, pleased to mee

67、t you C: MAIL FROM: S: 250 alicecrepes.fr. Sender ok C: RCPT TO: S: 250 bobhamburger.edu . Recipient ok C: DATA S: 354 Enter mail, end with . on a line by itself C: Do you like ketchup? C: How about pickles? C: . S: 250 Message accepted for delivery C: QUIT S: 221 hamburger.edu closing connectionApp

68、lication 2-53Try SMTP interaction for yourself:vtelnet servername 25vsee 220 reply from serverventer HELO, MAIL FROM, RCPT TO, DATA, QUIT commands above lets you send email without using email client (reader)Application 2-54SMTP: final wordsvSMTP uses persistent connectionsvSMTP requires message (he

69、ader & body) to be in 7-bit ASCIIvSMTP server uses CRLF.CRLF to determine end of messagecomparison with HTTP:vHTTP: pullvSMTP: pushvboth have ASCII command/response interaction, status codesvHTTP: each object encapsulated in its own response msgvSMTP: multiple objects sent in multipart msgApplicatio

70、n 2-55Mail message formatSMTP: protocol for exchanging email msgsRFC 822: standard for text message format:vheader lines, e.g.,To:From:Subject:different from SMTP commands!vbodythe “message”, ASCII characters onlyheaderbodyblanklineApplication 2-56Mail access protocolsvSMTP: delivery/storage to rece

71、ivers servervmail access protocol: retrieval from serverPOP: Post Office Protocol RFC 1939authorization (agent server) and download IMAP: Internet Mail Access Protocol RFC 1730more features (more complex)manipulation of stored msgs on serverHTTP: gmail, Hotmail, Yahoo! Mail, etc.useragentsenders mai

72、l serveruseragentSMTPSMTPaccessprotocolreceivers mail serverApplication 2-57POP3 protocolauthorization phasevclient commands: user: declare usernamepass: passwordvserver responses+OK-ERRtransaction phase, client:vlist: list message numbersvretr: retrieve message by numbervdele: deletevquit C: list S

73、: 1 498 S: 2 912 S: . C: retr 1 S: S: . C: dele 1 C: retr 2 S: S: . C: dele 2 C: quit S: +OK POP3 server signing offS: +OK POP3 server ready C: user bob S: +OK C: pass hungry S: +OK user successfully logged onApplication 2-58POP3 (more) and IMAPmore about POP3vprevious example uses “download and del

74、ete” mode.vBob cannot re-read e-mail if he changes clientv“download-and-keep”: copies of messages on different clientsvPOP3 is stateless across sessionsIMAPvkeeps all messages in one place: at servervallows user to organize messages in foldersvkeeps user state across sessions:names of folders and ma

75、ppings between message IDs and folder nameApplication 2-59Chapter 2: Application layerv2.1 Principles of network applicationsv2.2 Web and HTTPv2.3 FTP v2.4 Electronic MailSMTP, POP3, IMAPv2.5 DNSv2.6 P2P applicationsv2.7 Socket programming with TCPv2.8 Socket programming with UDPApplication 2-60DNS:

76、 Domain Name Systempeople: many identifiers:SSN, name, passport #Internet hosts, routers:IP address (32 bit) - used for addressing datagrams“name”, e.g., - used by humansQ: map between IP address and name, and vice versa ?Domain Name System:vdistributed database implemented in hierarchy of many nam

77、e serversvapplication-layer protocol host, routers, name servers to communicate to resolve names (address/name translation)note: core Internet function, implemented as application-layer protocolcomplexity at networks “edge”Application 2-61DNS Why not centralize DNS?vsingle point of failurevtraffic v

78、olumevdistant centralized databasevmaintenancedoesnt scale!DNS servicesvhostname to IP address translationvhost aliasingCanonical, alias namesvmail server aliasingvload distributionreplicated Web servers: set of IP addresses for one canonical nameApplication 2-62Root DNS Serverscom DNS serversorg DN

79、S serversedu DNS serverspoly.eduDNS serversumass.eduDNS DNS DNS serverspbs.orgDNS serversDistributed, Hierarchical Databaseclient wants IP for ; 1st approx:vclient queries a root server to find com DNS servervclient queries com DNS server to get DNS servervclient queries DNS server to get IP addre

80、ss for Application 2-63DNS: Root name serversvcontacted by local name server that can not resolve namevroot name server:contacts authoritative name server if name mapping not knowngets mappingreturns mapping to local name server 13 root name servers worldwideb USC-ISI Marina del Rey, CAl ICANN Los A

81、ngeles, CAe NASA Mt View, CAf Internet Software C. Palo Alto, CA (and 36 other locations)i Autonomica, Stockholm (plus 28 other locations)k RIPE London (also 16 other locations)m WIDE Tokyo (also Seoul, Paris, SF)a Verisign, Dulles, VAc Cogent, Herndon, VA (also LA)d U Maryland College Park, MDg US

82、DoD Vienna, VAh ARL Aberdeen, MDj Verisign, ( 21 locations)Application 2-64TLD and Authoritative ServersTop-level domain (TLD) servers:responsible for com, org, net, edu, aero, jobs, museums, and all top-level country domains, e.g.: uk, fr, ca, jpNetwork Solutions maintains servers for com TLDEducau

83、se for edu TLDAuthoritative DNS servers: organizations DNS servers, providing authoritative hostname to IP mappings for organizations servers (e.g., Web, mail).can be maintained by organization or service providerApplication 2-65Local Name Servervdoes not strictly belong to hierarchyveach ISP (resid

84、ential ISP, company, university) has onealso called “default name server”vwhen host makes DNS query, query is sent to its local DNS serveracts as proxy, forwards query into hierarchyApplication 2-66requesting hostcis.poly.edugaia.cs.umass.eduroot DNS serverlocal DNS serverdns.poly.edu123456authorita

85、tive DNS serverdns.cs.umass.edu78TLD DNS serverDNS name resolution examplevhost at cis.poly.edu wants IP address for gaia.cs.umass.eduiterated query:vcontacted server replies with name of server to contactv“I dont know this name, but ask this server”Application 2-67requesting hostcis.poly.edugaia.cs

86、.umass.eduroot DNS serverlocal DNS serverdns.poly.edu12456authoritative DNS serverdns.cs.umass.edu78TLD DNS server3recursive query:vputs burden of name resolution on contacted name servervheavy load?DNS name resolution exampleApplication 2-68DNS: caching and updating recordsvonce (any) name server l

87、earns mapping, it caches mappingcache entries timeout (disappear) after some timeTLD servers typically cached in local name serversThus root name servers not often visitedvupdate/notify mechanisms proposed IETF standardRFC 2136Application 2-69DNS recordsDNS: distributed db storing resource records (

88、RR)Type=NSname is domain (e.g., )value is hostname of authoritative name server for this domainRR format: (name, value, type, ttl)Type=Aname is hostnamevalue is IP addressType=CNAMEname is alias name for some “canonical” (the real) is really value is canonical nameType=MXvalue is name of mailserver

89、 associated with nameApplication 2-70DNS protocol, messagesDNS protocol : query and reply messages, both with same message formatmsg headervidentification: 16 bit # for query, reply to query uses same #vflags:query or replyrecursion desired recursion availablereply is authoritativeApplication 2-71DN

90、S protocol, messagesName, type fields for a queryRRs in responseto queryrecords forauthoritative serversadditional “helpful”info that may be usedApplication 2-72Inserting records into DNSvexample: new startup “Network Utopia”vregister name at DNS registrar (e.g., Network Solutions)provide names, IP

91、 addresses of authoritative name server (primary and secondary)registrar inserts two RRs into com TLD server:(, , NS)(, 212.212.212.1, A)vcreate authoritative server Type A record for ; Type MX record for vHow do people get IP address of your Web site?Application 2-73Chapter 2: Application layer2.1

92、Principles of network applications 2.2 Web and HTTP2.3 FTP2.4 Electronic MailSMTP, POP3, IMAP2.5 DNS2.6 P2P applications2.7 Socket programming with TCP2.8 Socket programming with UDPApplication 2-74Pure P2P architecturevno always-on servervarbitrary end systems directly communicatevpeers are intermi

93、ttently connected and change IP addressesThree topics:file distributionsearching for informationcase Study: Skypepeer-peerApplication 2-75File Distribution: Server-Client vs P2PQuestion : How much time to distribute file from one server to N peers?usu2d1d2u1uNdNServerNetwork (with abundant bandwidth

94、)File, size Fus: server upload bandwidthui: peer i upload bandwidthdi: peer i download bandwidthApplication 2-76File distribution time: server-clientusu2d1d2u1uNdNServerNetwork (with abundant bandwidth)Fvserver sequentially sends N copies:NF/us time vclient i takes F/di time to downloadincreases lin

95、early in N(for large N)= dcs = max NF/us, F/min(di) iTime to distribute F to N clients using client/server approach Application 2-77File distribution time: P2Pusu2d1d2u1uNdNServerNetwork (with abundant bandwidth)Fvserver must send one copy: F/us time vclient i takes F/di time to downloadvNF bits mus

96、t be downloaded (aggregate)fastest possible upload rate: us + SuidP2P = max F/us, F/min(di) , NF/(us + Sui) iApplication 2-78Server-client vs. P2P: exampleClient upload rate = u, F/u = 1 hour, us = 10u, dmin usApplication 2-79File distribution: BitTorrent tracker: tracks peers participating in torre

97、nttorrent: group of peers exchanging chunks of a fileobtain listof peers trading chunkspeerP2P file distributionApplication 2-80BitTorrent (1)vfile divided into 256KB chunks.vpeer joining torrent: has no chunks, but will accumulate them over timeregisters with tracker to get list of peers, connects

98、to subset of peers (“neighbors”)vwhile downloading, peer uploads chunks to other peers. vpeers may come and govonce peer has entire file, it may (selfishly自私) leave or (altruistically 利他) remainApplication 2-81BitTorrent (2)Pulling Chunksvat any given time, different peers have different subsets of

99、file chunksvperiodically, a peer (Alice) asks each neighbor for list of chunks that they have.vAlice sends requests for her missing chunksrarest firstSending Chunks: tit-for-tat一报还一报vAlice sends chunks to four neighbors currently sending her chunks at the highest rate re-evaluate top 4 every 10 secs

100、vevery 30 secs: randomly select another peer, starts sending chunksnewly chosen peer may join top 4“optimistically unchoke疏通”Application 2-82BitTorrent: Tit-for-tat(1) Alice “optimistically unchokes” Bob(2) Alice becomes one of Bobs top-four providers; Bob reciprocates报答(3) Bob becomes one of Alices

101、 top-four providersWith higher upload rate, can find better trading partners & get file faster!Application 2-83Distributed Hash Table (DHT)vDHT: distributed P2P databasevdatabase has (key, value) pairs; key: ss number; value: human namekey: content type; value: IP addressvpeers query DB with keyDB r

102、eturns values that match the keyvpeers can also insert (key, value) peersApplication 2-84DHT Identifiersvassign integer identifier to each peer in range 0,2n-1.Each identifier can be represented by n bits.vrequire each key to be an integer in same range.vto get integer keys, hash original key.e.g.,

103、key = h(“Led Zeppelin IV”)this is why they call it a distributed “hash” tableApplication 2-85How to assign keys to peers?vcentral issue:assigning (key, value) pairs to peers.vrule: assign key to the peer that has the closest ID.vconvention in lecture: closest is the immediate successor 最近后继 of the k

104、ey.ve.g.,: n=4; peers: 1,3,4,5,8,10,12,14; key = 13, then successor peer = 14key = 15, then successor peer = 1Application 2-8613458101215Circular DHT (1)veach peer only aware of immediate successor and predecessor.v“overlay network”Application 2-87Circular DHT (2)00010011010001011000101011001111Whos

105、 resp for key 1110 ?I amO(N) messageson avg to resolvequery, when thereare N peers111011101110111011101110Define closestas closestsuccessorApplication 2-88Circular DHT with Shortcutsveach peer keeps track of IP addresses of predecessor, successor, short cuts.vreduced from 6 to 2 messages.vpossible t

106、o design shortcuts so O(log N) neighbors, O(log N) messages in query13458101215Whos resp for key 1110? Application 2-89Peer Churn扰动vpeer 5 abruptly leavesvPeer 4 detects; makes 8 its immediate successor; asks 8 who its immediate successor is; makes 8s immediate successor its second successor.vWhat i

107、f peer 13 wants to join?13458101215vTo 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. Application 2-90P2P Case study: Skypevinherently P2P: pairs of users communicate.vProprietary私有的

108、 application-layer protocol (inferred 推断 via reverse engineering) vhierarchical overlay with SNsvIndex maps usernames to IP addresses; distributed over SNsSkype clients (SC)Supernode (SN)Skype login serverApplication 2-91Peers as relays中继(防火墙穿透)vproblem when both Alice and Bob are behind “NATs”. NAT

109、 prevents an outside peer from initiating a call to insider peervsolution:using Alices and Bobs SNs, relay is choseneach peer initiates session with relay. peers can now communicate through NATs via relayApplication 2-92Chapter 2: Application layer2.1 Principles of network applications2.2 Web and HT

110、TP2.3 FTP 2.4 Electronic MailSMTP, POP3, IMAP2.5 DNS2.6 P2P applications2.7 Socket programming with TCP2.8 Socket programming with UDPApplication 2-93Socket programmingSocket APIvintroduced in BSD4.1 UNIX, 1981vexplicitly created, used, released by apps vclient/server paradigm vtwo types of transpor

111、t service via socket API: unreliable datagram reliable, byte stream-oriented a host-local, application-created, OS-controlled interface (a “door”) into whichapplication process can both send and receive messages to/from another application processsocketGoal: learn how to build client/server applicat

112、ion that communicate using socketsApplication 2-94Socket-programming using TCPSocket: a door between application process and end-end-transport protocol (UCP or TCP)TCP service: reliable transfer of bytes from one process to anotherprocessTCP withbuffers,variablessocketcontrolled byapplicationdevelop

113、ercontrolled byoperatingsystemhost orserverprocessTCP withbuffers,variablessocketcontrolled byapplicationdevelopercontrolled byoperatingsystemhost orserverinternetApplication 2-95Socket programming with TCPClient must contact servervserver process must first be runningvserver must have created socke

114、t (door) that welcomes clients contactClient contacts server by:vcreating client-local TCP socketvspecifying IP address, port number of server processvwhen client creates socket: client TCP establishes connection to server TCPvwhen contacted by client, server TCP creates new socket for server proces

115、s to communicate with clientallows server to talk with multiple clientssource port numbers used to distinguish clients (more in Chap 3)TCP provides reliable, in-order transfer of bytes (“pipe”) between client and serverapplication viewpointApplication 2-96Client/server socket interaction: TCPwait fo

116、r incomingconnection requestconnectionSocket =welcomeSocket.accept()create socket,port=x, forincoming request:welcomeSocket = ServerSocket()create socket,connect to hostid, port=xclientSocket = Socket()closeconnectionSocketread reply fromclientSocketcloseclientSocketServer (running on hostid)Clients

117、end request usingclientSocketread request fromconnectionSocketwrite reply toconnectionSocketTCP connection setupApplication 2-97Clientprocessclient TCP socketStream jargonvstream is a sequence of characters that flow into or out of a process.vinput stream is attached to some input source for the pro

118、cess, e.g., keyboard or socket.voutput stream is attached to an output source, e.g., monitor or socket.Application 2-98Socket programming with TCPExample client-server app:1) client reads line from standard input (inFromUser stream) , sends to server via socket (outToServer stream)2) server reads li

119、ne from socket3) server converts line to uppercase, sends back to client4) client reads, prints modified line from socket (inFromServer stream)Application 2-99Example: Java client (TCP)import java.io.*; import .*; class TCPClient public static void main(String argv) throws Exception String sentence;

120、 String modifiedSentence; BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in); Socket clientSocket = new Socket(hostname, 6789); DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream(); createinput streamcreate clientSocket object of type Socket

121、, connect to servercreateoutput streamattached to socketApplication 2-100This package defines Socket() and ServerSocket() classesserver port #server name,e.g., www.umass.eduExample: Java client (TCP), cont. BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputS

122、tream(); sentence = inFromUser.readLine(); outToServer.writeBytes(sentence + n); modifiedSentence = inFromServer.readLine(); System.out.println(FROM SERVER: + modifiedSentence); clientSocket.close(); createinput streamattached to socketsend lineto serverread linefrom serverApplication 2-101close soc

123、ket(clean up behind yourself!)Example: Java server (TCP)import java.io.*; import .*; class TCPServer public static void main(String argv) throws Exception String clientSentence; String capitalizedSentence; ServerSocket welcomeSocket = new ServerSocket(6789); while(true) Socket connectionSocket = wel

124、comeSocket.accept(); BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream(); wait, on welcomingsocket accept() method for client contact create, new socket on return Application 2-102createwelcoming socketat port 6789create inputstream, attached to s

125、ocketExample: Java server (TCP), cont DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream(); clientSentence = inFromClient.readLine(); capitalizedSentence = clientSentence.toUpperCase() + n; outToClient.writeBytes(capitalizedSentence); read in linefrom socketcreate o

126、utputstream, attached to socketwrite out lineto socketend of while loop,loop back and wait foranother client connectionApplication 2-103Chapter 2: Application layer2.1 Principles of network applications2.2 Web and HTTP2.3 FTP 2.4 Electronic MailSMTP, POP3, IMAP2.5 DNS2.6 P2P applications2.7 Socket p

127、rogramming with TCP2.8 Socket programming with UDPApplication 2-104Socket programming with UDPUDP: no “connection” between client and servervno handshakingvsender explicitly attaches IP address and port of destination to each packetvserver must extract IP address, port of sender from received packet

128、UDP: transmitted data may be received out of order, or lostapplication viewpoint:UDP provides unreliable transfer of groups of bytes (“datagrams”) between client and serverApplication 2-105Client/server socket interaction: UDPServer (running on hostid)closeclientSocketread datagram fromclientSocketc

129、reate socket,clientSocket = DatagramSocket()ClientCreate datagram with server IP andport=x; send datagram via clientSocketcreate socket,port= x.serverSocket = DatagramSocket()read datagram fromserverSocketwrite reply toserverSocketspecifying client address,port numberApplication 2-106Example: Java c

130、lient (UDP)Output: sends packet (recallthat TCP sent “byte stream”)Input: receives packet (recall thatTCP received “byte stream”)Clientprocessclient UDP socketApplication 2-107Example: Java client (UDP)import java.io.*; import .*; class UDPClient public static void main(String args) throws Exception

131、 BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in); DatagramSocket clientSocket = new DatagramSocket(); InetAddress IPAddress = InetAddress.getByName(hostname); byte sendData = new byte1024; byte receiveData = new byte1024; String sentence = inFromUser.readLine(); sendD

132、ata = sentence.getBytes(); createinput streamcreate client sockettranslate hostname to IP address using DNSApplication 2-108Example: Java client (UDP), cont. DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876); clientSocket.send(sendPacket); DatagramPacket rece

133、ivePacket = new DatagramPacket(receiveData, receiveData.length); clientSocket.receive(receivePacket); String modifiedSentence = new String(receivePacket.getData(); System.out.println(FROM SERVER: + modifiedSentence); clientSocket.close(); create datagram with data-to-send,length, IP addr, portsend d

134、atagramto serverread datagramfrom serverApplication 2-109Example: Java server (UDP)import java.io.*; import .*; class UDPServer public static void main(String args) throws Exception DatagramSocket serverSocket = new DatagramSocket(9876); byte receiveData = new byte1024; byte sendData = new byte1024;

135、 while(true) DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); serverSocket.receive(receivePacket); createdatagram socketat port 9876create space forreceived datagramreceivedatagramApplication 2-110Example: Java server (UDP), cont String sentence = new String(receiv

136、ePacket.getData(); InetAddress IPAddress = receivePacket.getAddress(); int port = receivePacket.getPort(); String capitalizedSentence = sentence.toUpperCase(); sendData = capitalizedSentence.getBytes(); DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, port); serve

137、rSocket.send(sendPacket); get IP addrport #, ofsenderwrite out datagramto socketend of while loop,loop back and wait foranother datagramcreate datagramto send to clientApplication 2-111Chapter 2: Summaryvapplication architecturesclient-serverP2Phybridvapplication service requirements: reliability, b

138、andwidth, delayvInternet transport service modelconnection-oriented, reliable: TCPunreliable, datagrams: UDPour study of network apps now complete!vspecific protocols:HTTPFTPSMTP, POP, IMAPDNSP2P: BitTorrent, Skypevsocket programmingApplication 2-112Chapter 2: Summaryvtypical request/reply message e

139、xchange:client requests info or serviceserver responds with data, status codevmessage formats:headers: fields giving info about datadata: info being communicatedmost importantly: learned about protocolsImportant themes: vcontrol vs. data msgsvin-band, out-of-bandvcentralized vs. decentralized vstateless vs. statefulvreliable vs. unreliable msg transfer v“complexity at network edge”Application 2-113

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 高等教育 > 研究生课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号