【大学课件】A TopDown Approach Featuring the Internet

上传人:枫** 文档编号:569505092 上传时间:2024-07-30 格式:PPT 页数:127 大小:3.78MB
返回 下载 相关 举报
【大学课件】A TopDown Approach Featuring the Internet_第1页
第1页 / 共127页
【大学课件】A TopDown Approach Featuring the Internet_第2页
第2页 / 共127页
【大学课件】A TopDown Approach Featuring the Internet_第3页
第3页 / 共127页
【大学课件】A TopDown Approach Featuring the Internet_第4页
第4页 / 共127页
【大学课件】A TopDown Approach Featuring the Internet_第5页
第5页 / 共127页
点击查看更多>>
资源描述

《【大学课件】A TopDown Approach Featuring the Internet》由会员分享,可在线阅读,更多相关《【大学课件】A TopDown Approach Featuring the Internet(127页珍藏版)》请在金锄头文库上搜索。

1、 Computer Networking A Top-Down Approach Featuring the Internet计算机网络-自顶向下方法与Internet特色Chapter 2 Application Layerhttp:/ of Computer Science & Technology2 2Chapter goalsrprinciples of network applicationsqtransport-layer service modelspClient/server pP2PqProcesses Communicationrapplication-level prot

2、ocolsqHTTP/FTP/SMTP / POP3 / IMAP/DNSrprogramming network applicationsqsocket APIqSocket Programming in JavaSchool of Computer Science & Technology3 3Chapter 2: roadmap2.1 Principles of Network Applications2.2 The Web and HTTP2.3 File Transfer ProtocolFTP2.4 Electronic Mail in the Internet2.5 DNS- T

3、he Internet Directory Service2.6 P2P File sharing2.7 Socket Programming with TCP2.8 Socket Programming with UDP2.9 Building a Simple Web Server2.10 SummarySchool of Computer Science & Technology4 4Creating a network applicationWrite programs thatqrun on differentdifferent end systems qcommunicate ov

4、er a networknetwork.qe.g., Web server / browserNo software written for devices in network coreapplicationtransportnetworkdata linkphysicalapplicationtransportnetworkdata linkphysicalapplicationtransportnetworkdata linkphysical2 2. .1 1P Pr ri in nc ci ip pl le es s o of f N Ne et tw wo or rk k A Ap

5、pp pl li ic ca at ti io on ns sSchool of Computer Science & Technology5 51. Application architecturesrApplication architecture is distinctly different from the network architectureqnetwork architecture: fixed qApp architecture : how application is organized over various end systemsrTypical applicati

6、on architectureqClient-Server (C/S)qPeer-to-Peer (P2P)qHybrid of client-server and P2P2 2. .1 1P Pr ri in nc ci ip pl le es s o of f N Ne et tw wo or rk k A Ap pp pl li ic ca at ti io on ns sSchool of Computer Science & Technology6 6Client-Server architectureserver: qqalways-onalways-on hostqqperman

7、entpermanent, well-knownwell-known IP addressqqserver farmsserver farms for scalingclients:qcommunicate with serverqmay be intermittently connectedqmay have dynamic IP addressesC/S apps: Web, FTP, Telnet, e-maileasy managementserver is bottleneck2 2. .1 1P Pr ri in nc ci ip pl le es s o of f N Ne et

8、 tw wo or rk k A Ap pp pl li ic ca at ti io on ns sSchool of Computer Science & Technology7 7Pure P2P architecturerno always onalways on server at the center of appsrarbitrary end systems directly communicaterpeers intermittently connected and can changechange IP addresses rexample: qGnutellaHighly

9、scalableBut difficult to manage2 2. .1 1P Pr ri in nc ci ip pl le es s o of f N Ne et tw wo or rk k A Ap pp pl li ic ca at ti io on ns sSchool of Computer Science & Technology8 8Hybrid of client-server and P2PNapsterqFile transfer P2PqFile search centralized: Instant messagingqChatting between two u

10、sers is P2PqPresence detection/location centralized:2 2. .1 1P Pr ri in nc ci ip pl le es s o of f N Ne et tw wo or rk k A Ap pp pl li ic ca at ti io on ns sSchool of Computer Science & Technology9 92. Processes communicatingProcess:Process: program running within a host.rwithin same hostwithin same

11、 host, two processes communicate using inter-process communicationinter-process communication (IPC, defined by OS).rprocesses in different hostsprocesses in different hosts communicate by exchanging exchanging messagesmessages through the network2 2. .1 1P Pr ri in nc ci ip pl le es s o of f N Ne et

12、 tw wo or rk k A Ap pp pl li ic ca at ti io on ns sSchool of Computer Science & Technology10102. 1 Client and Server ProcessClient process:Client process: process that initiates initiates communicationServer process:Server process: process that waitswaits to be contactedrNote: applications with P2P

13、architectures have both client client processesprocesses & server processesserver processes2 2. .1 1P Pr ri in nc ci ip pl le es s o of f N Ne et tw wo or rk k A Ap pp pl li ic ca at ti io on ns sSchool of Computer Science & Technology11112.2 SocketsrAny message sent from one process to another must

14、 go through the underlying network.underlying network.rA process sends message into ,and receives messages from, the network through its socketsocketprocessTCP withbuffers,variablessockethost orserverprocessTCP withbuffers,variablessockethost orserverInternetcontrolledby OScontrolled byapp developer

15、rDevelopers canq choice of transport protocol; q ability to fix a few parameters2 2. .1 1P Pr ri in nc ci ip pl le es s o of f N Ne et tw wo or rk k A Ap pp pl li ic ca at ti io on ns sSchool of Computer Science & Technology12122.3 Addressing processesrfor a process to receive messages, it must have

16、 an identifier.ridentifier must include both the IP addressIP address and portport numbersnumbers.qport numbers:pHTTP server: 80pMail server: 25Q:Q: does the IP addressIP address of the destination host suffice for identifyingidentifying the destination process?2 2. .1 1P Pr ri in nc ci ip pl le es

17、s o of f N Ne et tw wo or rk k A Ap pp pl li ic ca at ti io on ns sA: A: No, many processes can be running on same hostSchool of Computer Science & Technology13133. App-layer protocolrAn Application-layer protocol defines:qTypesTypes of messages exchangedp e.g., request request & responseresponse me

18、ssagesqSyntaxSyntax of message typespwhat fields in messages & how fields are delineatedqSemanticsSemantics of the fieldspie, meaning of information in fieldsqRulesRules for when and how processes send & respond to messages2 2. .1 1P Pr ri in nc ci ip pl le es s o of f N Ne et tw wo or rk k A Ap pp

19、pl li ic ca at ti io on ns sSchool of Computer Science & Technology1414rPublic-domain protocols:qdefined in RFCs, allows for interoperabilitype.g., HTTP, SMTPrProprietary protocols:qe.g., KaZaArapplication vs. app-layer protocolqprotocol is a piece of a app.3. App-layer protocol2 2. .1 1P Pr ri in n

20、c ci ip pl le es s o of f N Ne et tw wo or rk k A Ap pp pl li ic ca at ti io on ns sSchool of Computer Science & Technology15154. What transport service does an app need?reliable data transferrsome apps (e.g., audio) can tolerate some lossrother apps (e.g., file transfer, telnet) require 100% reliab

21、le data transfer Timingrsome apps (Internet telephonyInternet telephony, interactive gamesinteractive games) require low delay to be “effective”bandwidthrbandwidth sensitive app (e.g., multimedia) relastic bandwidth apps (mail, FTP)2 2. .1 1P Pr ri in nc ci ip pl le es s o of f N Ne et tw wo or rk k

22、 A Ap pp pl li ic ca at ti io on ns sSchool of Computer Science & Technology16162.1.4 requirements of common appsApplicationfile transfere-mailWeb documentsreal-time audio/videostored audio/videointeractive gamesinstant messagingData lossno lossno lossno lossloss-tolerantloss-tolerantloss-tolerantno

23、 lossBandwidthelasticelasticelasticaudio: 5kbps-1Mbpsvideo:10kbps-5Mbpssame as above few kbps upelasticTime Sensitivenononoyes, 100s msecyes, few secsyes, 100s msecyes and noSchool of Computer Science & Technology17175. Internet services TCP service:qconnection-oriented qreliable transportqflow cont

24、rol:qcongestion control: does not provide: timing, minimum bandwidth guaranteesUDP service:qqunreliableunreliable data transferqdoes not provide: pconnection setuppReliabilitypflow controlpcongestion controlptiming, or bandwidth guarantee Q: Why is there a UDP?congestion control is harmful to apps t

25、hat have minimum bandwidth constraint ; some apps are loss-tolerant2 2. .1 1P Pr ri in nc ci ip pl le es s o of f N Ne et tw wo or rk k A Ap pp pl li ic ca at ti io on ns sSchool of Computer Science & Technology1818Internet apps: application, transport protocolsApplicatione-mailremote terminal acces

26、sWeb file transferstreaming multimediaInternet telephonyApplicationlayer protocolSMTP RFC 2821Telnet RFC 854HTTP RFC 2616FTP RFC 959proprietary(e.g. RealNetworks)proprietary(e.g., Dialpad)Underlyingtransport protocolTCPTCPTCPTCPTCP or UDPtypically UDPSchool of Computer Science & Technology1919Chapte

27、r 2: roadmap2.1 Principles of Network Applications2.2 The Web and HTTP2.3 File Transfer ProtocolFTP2.4 Electronic Mail in the Internet2.5 DNS- The Internet Directory Service2.6 P2P File sharing2.7 Socket Programming with TCP2.8 Socket Programming with UDP2.9 Building a Simple Web Server2.10 SummaryS

28、chool of Computer Science & Technology2020The Web and HTTPsome jargonqWeb page consists of basebase HTML-file which includes several referenced objectsobjectsqqObjectObject can be HTML file, image, Java applet, audio file,pif a web page contains a HTML file and 5 5 jpeg images, then the web page has

29、 6 6 objects: the base HTML file and 5 images.qEach object is addressable by a URLpUniform Resource Locator www.someschool.edu/someDept/pic.gifhost namepath name Object2.2 The Web and HTTPSchool of Computer Science & Technology2121Contentsr1.Overview of HTTP r2.HTTP connectionsqNon-persistent HTTP c

30、onnectionqPersistent HTTP connectionr3.HTTP message type and message formatqRequest messageqResponse messager4.Cookiesr6.Web cachingr7.Conditional GET2.2 The Web and HTTTPSchool of Computer Science & Technology22221. Overview of HTTPHTTP: hypertext transfer protocolPC runningExplorerServer runningAp

31、ache WebserverMac runningNavigatorHTTP requestHTTP requestHTTP responseHTTP response2.2 The Web and HTTPqWebs application layer protocolqclient/server modelqdefinespHow client requestsrequests web pages ( written in HTML/XMLHTML/XML) from server & how server transfers transfers web pages to clientqV

32、ersions:pHTTP 1.0(RFC 1945)pHTTP 1.1( RFC 2616)School of Computer Science & Technology23231. Overview of HTTPHTTP Uses TCP as underlying transport protocol :qclient initiates initiates TCP connection with the server at port 80qHTTP messages exchanged between browser and Web server through their sock

33、etsocketsHTTP is “stateless”qserver maintains no information about past client requestsqProtocols that maintain “state” are complex!2.2 The Web and HTTPSchool of Computer Science & Technology24242. HTTP connectionsNonpersistent Connectionqat most one object is sent over a TCP connection.qHTTP/1.0 us

34、es nonpersistent HTTP as defaultdefaultPersistent ConnectionqMultiple objects can be sent over single TCP connection between client and server.qHTTP/1.1 uses persistent connections in default mode2.2 The Web and HTTPSchool of Computer Science & Technology25252.1 nonpersistent HTTP connectionSuppose

35、user enters URLURL in the address of browser www.someSchool.edu/someDepartment/home.index1a. client initiates initiates TCP connection to HTTP server2. client sendssends HTTP request messagerequest message1b. server “acceptsaccepts” connection, notifying client3. server receives request message, for

36、ms/Creates response messageresponse messagetime4. server closes the TCP connection. 5. client receives response messageresponse message6. Steps 1-5 repeated for each of 10 jpeg objectsSchool of Computer Science & Technology26262.1 nonpersistent HTTP connectionrQuestion:q How many connectionsHow many

37、 connections?pEach TCP connection transports exactly one one request msg and one response msgrequest msg and one response msgp11 TCP connectionsqThese connections are parallel or serial?These connections are parallel or serial?pUser can configures modern browsers to control the degree of parallelism

38、parallelismpMost browsers open 5 to 10 parallel parallel TCP connections, and each connection handles one one request-responserequest-response transaction2.2 The Web and HTTPSchool of Computer Science & Technology27272.1 Response time modelingRTT: time to send a small a small packetpacket to travel

39、from client to server and back.Response time:rone RTT to initiateinitiate TCP connectionrone RTT for HTTP request and first few bytes of HTTP response to returnrfile transmission timetotal = 2RTT+transmit timetime to transmit fileinitiate TCPconnectionRTTRequest fileRTTFile receivedtimetime2.2 The W

40、eb and HTTPSchool of Computer Science & Technology28282.2 Persistent HTTP connectionrNonpersistent HTTP issues:qrequires 2 RTTs per objectqOS must work and allocate host resources for each TCP connectionpbrowsers often open parallel parallel TCP connections to fetch the referenced objectsrPersistent

41、 HTTPqserver leaves leaves connection openopen after sending responseqqsubsequentsubsequent HTTP messages between same client/server are sent over the connection established previously2.2 The Web and HTTPSchool of Computer Science & Technology29292.2 Persistent HTTP connectionrPersistent connection

42、without pipelining:pipelining:qclient issues new request only when previous response has been receivedqone RTT for each referenced objectrPersistent connection with pipeliningpipelining:qclient sends requests as soon as it encounters a referenced objectqas little as one RTT for all the referenced ob

43、jectsqdefault in HTTP/1.12.2 The Web and HTTPSchool of Computer Science & Technology30303. HTTP Message format : requestrTwo types of HTTP message (RFC2616) qqrequestrequest message and responseresponse messagerRequest Message formatqASCII (human-readable format)GET /somedir/page.html HTTP/1.1Host:

44、www.someschool.edu User-agent: Mozilla/4.0Connection: close Accept-language: fr (extra carriage return, line feed) request line(GET, POST, HEAD commands)header linesCarriage return + Line feed(0x0D0A)indicates end of message headMozilla= Mosaic +GodzillaSchool of Computer Science & Technology3131rGe

45、neral format of a request messagerMethodqGETpEntity body of the request message is emptyqPOSTpEntity body includes some parameters sent to serverpThe server can create response message according to the create response message according to the parametersparameters receivedqHEADpSimilar to GET, but th

46、e response message has no objectpUsed for debug3.1 HTTP Request Message2.2 The Web and HTTPSchool of Computer Science & Technology33333.1 Uploading form inputPost method:rWeb page often includes formforms rinput is uploaded to server in entity bodyentity bodyGET+URL method:rUses GETGET methodrInput

47、is uploaded in the URLURL field of request request lineline:http:/ The Web and HTTPEntity bodySchool of Computer Science & Technology34343.1 Method types supportedrHTTP/1.0qOnly three methods: GET/POST/HEADrHTTP/1.1qGET/POST/HEADqPUTpuploads file in entity body to path specified in URL fieldqDELETEp

48、deletes file specified in the URL field2.2 The Web and HTTPSchool of Computer Science & Technology35353.2 HTTP Response Message2.2 The Web and HTTPSchool of Computer Science & Technology3636HTTP/1.1 200 OK Connection: closeDate: Thu, 06 Aug 1998 12:00:15 GMT Server: Apache/1.3.0 (Unix) Last-Modified

49、: Mon, 22 Jun 1998 . Content-Length: 6821 Content-Type: text/html data data data data data . status line(protocolstatus codestatus phrase)header linesdata, e.g., requestedHTML file3.2 HTTP Response Message2.2 The Web and HTTPSchool of Computer Science & Technology3737200 OKqrequest succeeded, reques

50、ted object is returned in the response message301 Moved Permanentlyqrequested object moved, new location specified later in this message (Location:)400 Bad Requestqrequest message not understood by server404 Not Foundqrequested document not found on this server505 HTTP Version Not SupportedrStatus C

51、ode and phrase3.2 HTTP Response Message2.2 The Web and HTTPSchool of Computer Science & Technology39394. User-server Interaction: cookiesMany major Web sites use cookiescookiesFour components:1) Set-cookieSet-cookie header line in the HTTP response messageresponse message2) cookie cookie header line

52、 in HTTP requestrequest messagemessage3) cookiecookie filefile kept on users host and managedmanaged by users browserbrowser4) back-endback-end database at WebWeb sitesiteExample:qqSusan Susan access Internet always from same PCqShe visits a specific e-commerce site for first timeqWhen initial HTTP

53、requests arrives at site, site creates a unique ID and creates an entry in backend database for ID2.2 The Web and HTTPSchool of Computer Science & Technology4040Cookies: keeping “state” (cont.)clientserverusual http request msgusual http response +Set-cookieSet-cookie: 1678 usual http request msgcoo

54、kiecookie: 1678usual http response msgusual http request msgcookiecookie: 1678usual http response msgcookie-specificactioncookie-spectificactionservercreates ID1678 for userentry in backend databaseaccessaccessCookie fileamazon: 1678ebay: 8734Cookie fileebay: 8734Cookie fileamazon: 1678ebay: 8734one

55、 week later:School of Computer Science & Technology41414. Cookies (continued)What cookies can bring:rauthorizationrshopping cartsrrecommendationsruser session state (Web e-mail)Cookies and privacy:rcookies permit sites to learn a lot about youryou may supply name and e-mail to sitesrsearch engines u

56、se redirection & cookies to learn yet moreradvertising companies obtain info across sitesaside2.2 The Web and HTTPSchool of Computer Science & Technology42426. Web Cachingruser sets browserqWeb accesses via proxyrbrowser sends all HTTP requests to the cacherCache acts as both client and serverqTypic

57、ally cache is installed by ISPGoal: satisfy client request without involving origin server2.2 The Web and HTTPSchool of Computer Science & Technology43436. More about Web cachingWhy Web caching?qreduce response timeresponse time.qreduce traffic on the access linkaccess link.rInternet dense with cach

58、es enables “ “poorpoor” ” content providers to effectively deliver content qso does P2P file sharing2.2 The Web and HTTPSchool of Computer Science & Technology44446. Caching example rraverage object sizeaverage object size = 100,000 bitsravg. request rate from institutions browsers to origin servers

59、 = 15/secrdelay from institutional router to any origin server and back to router = 2 secrrtotal delaytotal delay = Internet delayInternet delay + accessaccess delaydelay + LANLAN delaydelay = 2 sec + minutes + millisecondsoriginserverspublic Internetinstitutionalnetwork10 Mbps LAN1.5 Mbps access li

60、nkinstitutionalcache2.2 The Web and HTTPUtilizationLAN = (15 requests/sec)*(100kbits/Request)/10Mbps=0.15 UtilizationAccess = (15 Requests/sec)*(100kbits/Request)/1.5Mbps=1School of Computer Science & Technology4545Possible solutionqincrease bandwidthbandwidth of access link to 10 MbpsConsequencesqu

61、tilization on LAN = 15%qutilization on access link = 15%qTotal delay = Internet delay + access delay + LAN delay = 2 sec + msecs + msecsqoften a costly upgrade6. Caching example 2.2 The Web and HTTPSchool of Computer Science & Technology4646Install a cacheqhit ratehit rate is 0.4qq40%40% requests wi

62、ll be satisfied almost immediately(10ms)qq60%60% requests satisfied by origin serverorigin serverqqutilizationutilization of access link reduced to 60%, resulting in negligible negligible delays qqtotal total avg delayavg delay = Internet delay + access delay + LAN delay = 0.6*(2.01) s +0.4*(0.01) m

63、soriginserverspublic Internetinstitutionalnetwork10 Mbps LAN1.5 Mbps access linkinstitutionalcache6. Caching example 2.2 The Web and HTTPSchool of Computer Science & Technology47477. Conditional GETrAn HTTP request Message is so called conditional GETconditional GET message if:qUse GET GET method, a

64、ndqIncludes an If-Modified-Since:If-Modified-Since: header linerGoal: dont send object if cache has up-to-date up-to-date cached versionqcache: specify date of cached copy in HTTP requestIf-modified-since: qserver: response contains no object if cached copy is up-to-date:up-to-date: HTTP/1.0 304 Not

65、 Modified2.2 The Web and HTTPSchool of Computer Science & Technology4848cacheserverHTTP request msgIf-modified-since: HTTP responseHTTP/1.0 304 Not Modifiedobject not modifiedHTTP request msgIf-modified-since: HTTP responseHTTP/1.0 200 OKobject modified7. Conditional GET: example2.2 The Web and HTTP

66、School of Computer Science & Technology4949Chapter 2: roadmap2.1 Principles of Network Applications2.2 The Web and HTTP2.3 File Transfer ProtocolFTP2.4 Electronic Mail in the Internet2.5 DNS- The Internet Directory Service2.6 P2PFile sharing2.7 Socket Programming with TCP2.8 Socket Programming with

67、UDP2.9 Building a Simple Web Server2.10 SummarySchool of Computer Science & Technology5555Introduction rE-mail is an asynchronous asynchronous communication systemrThree major components: qquser agentsuser agents qqmailmail serversservers qqSMTPSMTP: : simple mail transfer protocolrUser Agentq“mail

68、reader/composer”qcomposing, editing, reading mail messagesqe.g., Eudora, Outlook, Netscape Messengerqoutgoing, incoming messages stored on server2 2. .4 4 E El le ec ct tr ro on ni ic c MMa ai il l i in n t th he e I In nt te er rn ne et tSchool of Computer Science & Technology5656rMail Servers qthe

69、 core of the e-mail infrastructureqqmailboxmailbox contains incoming mails for userqqmessagemessage queuequeue buffering the outgoing (to be sent) mail messagesrSMTPqprincipal application-layerapplication-layer protocol of e-mailqtransfers mail from sendersender s s mail server to the recipientrecip

70、ient s s mail serverpclient sidepserver sideqruns over TCP, port 25Introduction 2 2. .4 4 E El le ec ct tr ro on ni ic c MMa ai il l i in n t th he e I In nt te er rn ne et tSchool of Computer Science & Technology5757user mailboxoutgoing message queuemailserveruseragentuseragentuseragentmailserverus

71、eragentmailserveruseragentSMTPSMTPSMTPuseragentIntroduction 2 2. .4 4 E El le ec ct tr ro on ni ic c MMa ai il l i in n t th he e I In nt te er rn ne et tSchool of Computer Science & Technology58581. SMTP RFC 2821rSMTP transfers messages from senders mail server to the recipients mail serverqpersist

72、ent TCP connectionrMessages (header and body) must be in 7-bit ASCIIASCIIqsave the scare transmission capacityqoutdated.rSMTP server uses CRLF.CRLFCRLF.CRLF to determine end of message2 2. .4 4 E El le ec ct tr ro on ni ic c MMa ai il l i in n t th he e I In nt te er rn ne et tSchool of Computer Sci

73、ence & Technology59591) Alice uses UAUA to compose message and “to” bobsomeschool.edu2) Alices UA sends message to her mail servermail server; message placed in message queuemessage queue3) Client side of SMTP opens TCP connection with Bobs mail server4) SMTP client sends Alices message over the TCP

74、 connection5) Bobs mail server places the message in Bobs mailbox6) Bob invokes his UAUA to read messageuseragentmailservermailserveruseragent1234562 2. .4 4 E El le ec ct tr ro on ni ic c MMa ai il l i in n t th he e I In nt te er rn ne et t1. SMTP operationSchool of Computer Science & Technology61

75、612. Comparison with HTTPrCommon:qboth used to transfer files from one host to anotherqboth can use persistentpersistent TCPrDifferences:qHTTP is a pullpull protocol and SMTP is a pushpush protocolqSMTP requires each msg to be in 7-bit ASCII ASCII formatqHow a document consisting the text and image

76、is handles?pHTTP: each object encapsulated in its own response msgpSMTP: multiple objects sent in a multipart msg2 2. .4 4 E El le ec ct tr ro on ni ic c MMa ai il l i in n t th he e I In nt te er rn ne et tSchool of Computer Science & Technology6262SMTP(RFC 822: standard for text message format)rhe

77、ader linesqTo:qFrom:qSubject:differentdifferent from SMTP commands!rbodyqthe “message”, ASCII characters onlyheaderbodyBlank line3.1 Mail message format2 2. .4 4 E El le ec ct tr ro on ni ic c MMa ai il l i in n t th he e I In nt te er rn ne et tSchool of Computer Science & Technology63633.2 multime

78、dia extensions for non ASCII datarMIME: MMultipurpose I Internet MMail E ExtensionqRFC 2045, 2056rTwo key MIME headersqContent-TypeqContent-Transfer-EncodingFrom: alicecrepes.fr To: bobhamburger.edu Subject: Picture of yummy crepe. MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Type: im

79、age/jpeg base64 encoded data . . .base64 encoded data multimedia datatype, subtype, parameter declarationmethod usedto encode dataMIME versionencoded data2 2. .4 4 E El le ec ct tr ro on ni ic c MMa ai il l i in n t th he e I In nt te er rn ne et tSchool of Computer Science & Technology6464rReceivin

80、g server appends a Received:Received: header line to the top of the received message3.3 The Received Message2 2. .4 4 E El le ec ct tr ro on ni ic c MMa ai il l i in n t th he e I In nt te er rn ne et tReceived: from hambufer.edu by sushi.jp 12 Oct 98 15:27:51 GMTReceived: from crepes.fr by hamburge

81、r.edu; 12 Oct 98 15:27:39 GMTFrom: alicecrepes.frTo: bobhamburger.eduSubject: Picture of yummy crepe.MIME-Version: 1.0Content-Transfer-Encoding: base64Content-Type: image/jpeg base64 encoded data . base64 encoded data rMultiple Received:Received:header lines in a msg.qbob configures his mail server

82、to forward forward all of his mails to sushi.jpSchool of Computer Science & Technology65654. Mail access protocolsrSMTP: delivery/storage to receivers serverrMail access protocol: retrieval from serverqqPOP: POP: Post Office Protocol RFC 1939pauthorization (agent server) and download qqIMAP:IMAP: In

83、ternet Mail Access Protocol RFC 1730pmore features (more complex)pmanipulation of stored msgs on serverqqHTTP:HTTP: Hotmail , Yahoo! Mail, etc.useragentsenders mail serveruseragentSMTPSMTPaccessprotocolreceivers mail server2 2. .4 4 E El le ec ct tr ro on ni ic c MMa ai il l i in n t th he e I In nt

84、 te er rn ne et tSchool of Computer Science & Technology6969Chapter 2: roadmap2.1 Principles of Network Applications2.2 The Web and HTTP2.3 File Transfer ProtocolFTP2.4 Electronic Mail in the Internet2.5 DNS- The Internet Directory Service2.6 P2P File sharing2.7 Socket Programming with TCP2.8 Socket

85、 Programming with UDP2.9 Building a Simple Web Server2.10 SummarySchool of Computer Science & Technology7070IntroductionPeople: many identifiers:qI.D.card#, name, passport #Internet hosts, routers:qIP address (32 bit) - used for addressing datagramsq“name”, e.g., - used by humansQ: How to map betwe

86、en IP addresses and domain name ?qDNS 2 2. .5 5 D DN NS ST Th he e I In nt te er rn ne et t s s D Di ir re ec ct to or ry y S Se er rv vi ic ce eSchool of Computer Science & Technology7171Domain Name System:rA distributed databaseqimplemented in hierarchyhierarchy of many name serversname serversrAn

87、 application-layer protocolqhost, routers, name servers to communicate to resolveresolve names (address/name translation)Introduction2 2. .5 5 D DN NS ST Th he e I In nt te er rn ne et t s s D Di ir re ec ct to or ry y S Se er rv vi ic ce eSchool of Computer Science & Technology7272rHostname to IP a

88、ddress translationtranslationrHost aliasingqCanonical and alias (Canonical) (alias)rMail server aliasingrLoad distribution (load balancing)qreplicated Web servers: set of IP addresses for one canonical name2 2. .5 5 D DN NS ST Th he e I In nt te er rn ne et t s s D Di ir re ec ct to or ry y S Se er

89、 rv vi ic ce e1. DNS ServicesSchool of Computer Science & Technology7373rWhy not centralize DNS?qsingle point of failuresingle point of failureqtraffic volumetraffic volumeqdistant centralized databasedistant centralized databaseqmaintenancemaintenance doesnt scale!rClasses of DNS serverqRoot DNS se

90、rversqTop-Level DNS serversqAuthoritative DNS servers2 2. .5 5 D DN NS ST Th he e I In nt te er rn ne et t s s D Di ir re ec ct to or ry y S Se er rv vi ic ce e2. Overview of How DNS Works?School of Computer Science & Technology7474Root DNS ServersRoot DNS Serverscomcom DNS servers DNS serversorgorg

91、 DNS servers DNS serverseduedu DNS servers DNS serverspoly.eduDNS serversumass.eduDNS DNS DNS serverspbs.orgDNS servers2 2. .5 5 D DN NS ST Th he e I In nt te er rn ne et t s s D Di ir re ec ct to or ry y S Se er rv vi ic ce e2.1 Distributed, Hierarchical DatabaseTLD TLD ServersSchool of Computer Sc

92、ience & Technology7575rClasses of DNS serverqRoot DNS serversp13 root servers labeledlabeled A A through MMqTop-Level serversqAuthoritative DNS servers2 2. .5 5 D DN NS ST Th he e I In nt te er rn ne et t s s D Di ir re ec ct to or ry y S Se er rv vi ic ce e2.1 Distributed, Hierarchical DatabaseScho

93、ol of Computer Science & Technology7676b USC-ISI Marina del Rey, CAl ICANN Los Angeles, CAe NASA Mt View, CAf Internet Software C. Palo Alto, CA (and 17 other locations) i Autonomica, Stockholm (plus 3 other locations)k RIPE London (also Amsterdam, Frankfurt)m WIDE Tokyoa Verisign, Dulles, VAc Cogen

94、t, Herndon, VA (also Los Angeles)d U Maryland College Park, MDg US DoD Vienna, VAh ARL Aberdeen, MDj Verisign, ( 11 locations)2 2. .5 5 D DN NS ST Th he e I In nt te er rn ne et t s s D Di ir re ec ct to or ry y S Se er rv vi ic ce e2.1 Root DNS ServersSchool of Computer Science & Technology7777rCla

95、sses of DNS serverqRoot DNS serversqTop-Level serverspresponsible for comcom, orgorg, netnet, eduedu, etcetc, and all top-level countrycountry domainsdomains: cn uk, fr, ca, jp.qAuthoritative DNS servers2 2. .5 5 D DN NS ST Th he e I In nt te er rn ne et t s s D Di ir re ec ct to or ry y S Se er rv

96、vi ic ce e2.1 Distributed, Hierarchical DatabaseSchool of Computer Science & Technology7878rClasses of DNS serverqRoot DNS serversqTop-Level serversqAuthoritative DNS serverspporganizationorganization s s DNS serverspproviding authoritative authoritative hostname to IP mappings for organizations hos

97、ts (e.g., Web and mail).oCan be maintained by organization or service provider2 2. .5 5 D DN NS ST Th he e I In nt te er rn ne et t s s D Di ir re ec ct to or ry y S Se er rv vi ic ce e2.1 Distributed, Hierarchical DatabaseSchool of Computer Science & Technology7979rDoes not strictly belong to the h

98、ierarchyrEach ISP (residential ISP, company, university) has one.qAlso called “default name serverdefault name server”rWhen a host makes a DNS query, query is sent to its local DNS serverqacts as a proxy,proxy, forwardsforwards the query into the hierarchy.2 2. .5 5 D DN NS ST Th he e I In nt te er

99、rn ne et t s s D Di ir re ec ct to or ry y S Se er rv vi ic ce e2.1 Local Name ServerSchool of Computer Science & Technology8080recursive query:recursive query:qputs burden of name resolution on contacted name serverrequesting hostcis.poly.edulocal DNS serverdns.poly.edugaia.cs.umass.eduroot DNS ser

100、ver12authoritative DNS serverdns.cs.umass.edu8TLD DNS server456372.1 Query : Iterative and Recursive 2 2. .5 5 D DN NS ST Th he e I In nt te er rn ne et t s s D Di ir re ec ct to or ry y S Se er rv vi ic ce eiterated query:iterated query:qcontacted server replies with name of server to contactq“I do

101、nt know this name, but ask this server”School of Computer Science & Technology8181requesting hostcis.poly.edugaia.cs.umass.eduroot DNS serverlocal DNS serverdns.poly.edu12345authoritative DNS serverdns.cs.umass.edu867TLD DNS server2.1 Query ExamplerHost at cis.poly.educis.poly.edu wants the IP addre

102、ss of gaia.cs.umass.edugaia.cs.umass.edu2 2. .5 5 D DN NS ST Th he e I In nt te er rn ne et t s s D Di ir re ec ct to or ry y S Se er rv vi ic ce eSchool of Computer Science & Technology8383ronce (any) server learns a mapping, it cachescaches the mappingmappingqcache entries timeout after some timeq

103、local name servers often caches the TLD serversproot name servers not often visitedrupdate/notify mechanisms under design by IETFqDynamic Updates in the Domain Name System (DNS UPDATE) RFC 2136 2.2 DNS: caching2 2. .5 5 D DN NS ST Th he e I In nt te er rn ne et t s s D Di ir re ec ct to or ry y S Se

104、 er rv vi ic ce eSchool of Computer Science & Technology84843. DNS recordsDNS: distributed db storing resource records (RR)rType=NSNSqname is a domainqvalue is hostname of authoritative name server for this domain(name, value, type, ttl)rType=A Aqname is hostnameqvalue is IP addressrType=CNAMECNAMEq

105、name is alias name for “canonical” (the real) namepName = pValue= qvalue is canonical namerType=MXMXqvalue is canonical qName=alias name of mail server2 2. .5 5 D DN NS ST Th he e I In nt te er rn ne et t s s D Di ir re ec ct to or ry y S Se er rv vi ic ce eSchool of Computer Science & Technology929

106、2Chapter 2: roadmap2.1 Principles of Network Applications2.2 The Web and HTTP2.3 File Transfer ProtocolFTP2.4 Electronic Mail in the Internet2.5 DNS- The Internet Directory Service2.6 P2P File sharing2.7 Socket Programming with TCP2.8 Socket Programming with UDP2.9 Building a Simple Web Server2.10 S

107、ummarySchool of Computer Science & Technology94941. Architectures for Locating ContentsrCentralized DirectoryrQuery FloodingrExploiting Heterogeneity2.6 P2P File SharingSchool of Computer Science & Technology9595original “ “NapsterNapster” ” design1) When app starts, it informs informs a central ser

108、ver:pIP addresspShared contents2) Server checks the peers s state (on or off) periodicallyperiodicallypremove the entryExample: qAlice queries for “Hey Jude”qAlice requests file from Bobcentralizeddirectory serverpeersAliceBob111123inform and update Query for contentfile transfer1. Centralized Direc

109、tory-Napster2.6 P2P File SharingSchool of Computer Science & Technology9696rProblems of Centralized DirectoryqSingle point of failureqPerformance bottleneckqCopyright infringement file transfer is decentralized file transfer is decentralized , but but locating content is highly centralizedlocating c

110、ontent is highly centralized1. Centralized Directory-Napster2.6 P2P File SharingSchool of Computer Science & Technology9797rPeers form an overlayoverlay networkqedge between peer X and Y if theres a TCP connectionqall active peers and edges form the overlayoverlay netqedge is not a physical linkqa p

111、eer will typically be connected with 10 overlay neighborsrfully distributeddistributedqno central serverrpublic domain protocol2. Query Flooding - Gnutella2.6 P2P File SharingSchool of Computer Science & Technology9898QueryQueryHitQueryQueryQueryHitQueryQueryQueryHitFile transfer:HTTPr Query message

112、sent over existing TCPconnectionsr peers forwardQuery messager QueryHit sent over reversepathScalability:limited scopeflooding2. Query Flooding - Gnutella2.6 P2P File SharingSchool of Computer Science & Technology9999rJoining peer X must find some other peer in Gnutella networkruse list of candidate

113、 peersrX sequentially attempts to make TCP with peers on list until one connection setup with some peer YrX sends PingPing message to Y; Y forwards Ping message. (Ping also includes peer-count field)rAll peers receiving Ping message respond with PongPong messagerX receives many PongPong messages. It

114、 can then setup additional TCP connections2. Query Flooding - Gnutella2.6 P2P File SharingSchool of Computer Science & Technology100100rEach peer is either a group group leaderleader or assigned to a group leader.qTCP connection between peer and its group leader.qTCP connections between some pairs o

115、f group leaders.rrGroup leaderGroup leader tracks the content in all its children.ordinary peergroup-leader peerneighoring relationshipsin overlay network3. Exploiting Heterogeneity: KaZaA2.6 P2P File SharingSchool of Computer Science & Technology101101rEach file has a hash hash and a descriptor;rCl

116、ient sends keyword query to its group leader;rIf (match founded) Group leader responds with matches; else group leader forwards query to other group leaders, they respond with matches;rClient then selects files for downloading;3. Exploiting Heterogeneity: KaZaA2.6 P2P File SharingSchool of Computer

117、Science & Technology1021023. Exploiting Heterogeneity: KaZaAHow to improve the performance?qRequest queuingqIncentive prioritiesqParallel downloading2.6 P2P File SharingSchool of Computer Science & Technology103103Chapter 2: roadmap2.1 Principles of Network Applications2.2 The Web and HTTP2.3 File T

118、ransfer ProtocolFTP2.4 Electronic Mail in the Internet2.5 DNS- The Internet Directory Service2.6 P2P File sharing2.7 Socket Programming with TCP2.8 Socket Programming with UDP2.9 Building a Simple Web Server2.10 SummarySchool of Computer Science & Technology104104IntroductionSocket APIrintroduced in

119、 BSD4.1 UNIXBSD4.1 UNIX, 1981rrexplicitlyexplicitly created, used, and released by appsr client/serverclient/server paradigm rtwo types of transport service via socket API: qunreliable datagram qreliable a host-local, application-created, OS-controlled interface (a “door”) into whichapplication proc

120、ess can both send and receive messages to/from another application processsocketGoal: learn how to build client/serverclient/server application that communicate using socketssockets2.7 Socket Programming with TCPSchool of Computer Science & Technology1051051. Socket-programming with TCPSocket: a doo

121、r door between application process and end-end-transport protocol (UCP or TCP)TCP service: reliable transferreliable transfer of bytesbytes from one process to anotherprocessTCP withbuffers,variablessocketcontrolled byapplicationdevelopercontrolled byoperatingsystemhost orserverprocessTCP withbuffer

122、s,variablessocketcontrolled byapplicationdevelopercontrolled byoperatingsystemhost orserverinternet2.7 Socket Programming with TCPSchool of Computer Science & Technology1061061. Socket-programming with TCPClient/Server modelqclient initiating initiating the contact with the serverpserver process mus

123、t first befirst be runningrunningpserver must have created created socketsocket (door) that welcomes clients contact2.7 Socket Programming with TCPSchool of Computer Science & Technology1071071. Socket-programming with TCPrA client contacts the server by:qcreating client-local client-local TCP socke

124、tqspecifies ( IP addressIP address, port numberport number) of server processqclient TCPTCP establishes connection to server TCPTCPrServer sideqWhen contacted by a client, server TCP createscreates new new socketsocket to communicate with the clientpallows server to talk with multiple clientspsource

125、 socket used to distinguish clients ( more in Chap 3)2.7 Socket Programming with TCPSchool of Computer Science & Technology1081081. Socket-programming with TCPrWhats a streamstream?qa sequence of characterssequence of characters that flow into into or outout of a process.qqinputinput streamstream is

126、 attached to some input source for the process( keyboard or a socket) .qqoutputoutput streamstream is attached to an output source, (monitor or a socket).2.7 Socket Programming with TCPTCP provides reliablereliable, in-order in-order transfer of bytesbytes streamstream (“pipepipe”) between the sende

127、r and the receiver. application viewpointSchool of Computer Science & Technology1091092. An Example in Java1)client reads lineline from keyboardkeyboard (inFromUserinFromUser stream), and sends to server via socketsocket (outToServeroutToServer stream)2) server reads line from socket socket , conver

128、ts the line to uppercaseuppercase, and sends back to the client3) client reads and prints prints the modified line received from the socketsocket (inFromServerinFromServer stream)client TCP socket2.7 Socket Programming with TCPSchool of Computer Science & Technology1101102.1 Client/Server socket int

129、eractionwait for 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

130、 hostid)Clientsend request usingclientSocketread request fromconnectionSocketwrite reply toconnectionSocketTCP connection setup2.7 Socket Programming with TCPSchool of Computer Science & Technology111111Example: Java server (TCP)import java.io.*; import .*; class TCPServer public static void main(St

131、ring argv) throws Exception String clientSentence; String capitalizedSentence; ServerSocket welcomeSocket = new ServerSocket(65123); while(true) Socket connectionSocket = welcomeSocket.accept(); BufferedReader inFromClient = new BufferedReader( new InputStreamReader( connectionSocket.getInputStream(

132、); Createwelcoming socketat port 6789Wait, on welcomingsocket for contactby clientCreate inputstream, attached to socketSchool of Computer Science & Technology112112Example: Java server (TCP), cont DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream(); clientSentence

133、 = inFromClient.readLine(); capitalizedSentence = clientSentence.toUpperCase() + n; outToClient.writeBytes(capitalizedSentence); Read in linefrom socketCreate outputstream, attached to socketWrite out lineto socketEnd of while loop,loop back and wait foranother client connectionSchool of Computer Sc

134、ience & Technology113113Example: Java client (TCP)import java.io.*; import .*; public class TCPClient public static void main(String argv) throws Exception String sentence; String modifiedSentence; BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in); Socket clientSocket =

135、 new Socket(“localhostlocalhost, 6512365123); DataOutputStream outToServer = new DataOutputStream (clientSocket.getOutputStream(); Createinput streamCreate client socket, connect to serverCreateoutput streamattached to socketTCPClient.javaSchool of Computer Science & Technology114114Example: Java cl

136、ient (TCP), cont. BufferedReader inFromServer = new BufferedReader ( new InputStreamReader (clientSocket.getInputStream(); /input a line from keyboard sentence = inFromUser.readLine(); outToServer.writeBytes(sentence + n); modifiedSentence = inFromServer.readLine(); System.out.println(FROM SERVER: +

137、 modifiedSentence); clientSocket.close(); /close socket and TCP connection Send lineto serverRead linefrom serverCreateinput streamattached to socketSchool of Computer Science & Technology115115Chapter 2: roadmap2.1 Principles of Network Applications2.2 The Web and HTTP2.3 File Transfer ProtocolFTP2

138、.4 Electronic Mail in the Internet2.5 DNS - The Internet Directory Service2.6 P2P File sharing2.7 Socket Programming with TCP2.8 Socket Programming with UDP2.9 Building a Simple Web Server2.10 SummarySchool of Computer Science & Technology116116IntroductionUDP: no “connection” between client and ser

139、verqno handshakinghandshakingqsender explicitly attaches IP addressIP address and portport of destination to each packeteach packetqserver must extract IP addressIP address, portport of sender from received packetqtransmitted data received may be out of orderout of order, or lostlostapplication view

140、pointUDP provides unreliableunreliable transfer of groups of bytes (“datagrams”) between client and server2.8 Socket Programming with UDPSchool of Computer Science & Technology1171171. Client/server socket interaction: UDPcloseclientSocketServer (running on hostid)read reply fromclientSocketcreate s

141、ocket,clientSocket = DatagramSocket()ClientCreate, address (hostid, port=x,send datagram request using clientSocketcreate socket,port=x, forincoming request:serverSocket = DatagramSocket()read request fromserverSocketwrite reply toserverSocketspecifying clienthost address,port number2.8 Socket Progr

142、amming with UDPSchool of Computer Science & Technology1181182. Example: Java client (UDP)Output: sends packet packet (TCP sent “byte stream”)Input: receives packetpacket (TCP received “byte stream”)Clientprocessclient UDP socket2.8 Socket Programming with UDPSchool of Computer Science & Technology11

143、9119Example: Java server (UDP)import java.io.*; import .*; class UDPServer public static void main(String args) throws Exception DatagramSocket serverSocket = new DatagramSocket(65123); byte receiveData = new byte1024; byte sendData = new byte1024; while(true) DatagramPacket receivePacket = new Data

144、gramPacket(receiveData, receiveData.length); serverSocket.receive(receivePacket); Createdatagram socketat port 65132Create space forreceived datagramReceivedatagramSchool of Computer Science & Technology120120Example: Java server (UDP), cont String sentence = new String(receivePacket.getData(); Inet

145、Address IPAddress = receivePacket.getAddress(); int port = receivePacket.getPort(); String capitalizedSentence = sentence.toUpperCase(); sendData = capitalizedSentence.getBytes(); DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, port); serverSocket.send(sendPacket

146、); Get IP addrport #, ofsenderWrite out datagramto socketEnd of while loop,loop back and wait foranother datagramCreate datagramto send to clientSchool of Computer Science & Technology121121Example: Java client (UDP)import java.io.*; import .*; public class UDPClient public static void main(String a

147、rgs) throws Exception BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in); DatagramSocket clientSocket = new DatagramSocket(); InetAddress IPAddress = InetAddress.getByName(“localhost); byte sendData = new byte1024; byte receiveData = new byte1024; String sentence = inFro

148、mUser.readLine(); sendData = sentence.getBytes(); Createinput streamCreate client socketTranslate hostname to IP address using DNStype conversionstring to bytes arraySchool of Computer Science & Technology122122Example: Java client (UDP), cont. DatagramPacket sendPacket = new DatagramPacket (sendDat

149、a, sendData.length, IPAddress, 65123); clientSocket.send(sendPacket); DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); clientSocket.receive(receivePacket); String modifiedSentence = new String (receivePacket.getData(); System.out.println(FROM SERVER: + modifiedSent

150、ence); clientSocket.close(); Create datagram with data-to-send,length, IP addr, portSend datagramto serverRead datagramfrom serverSchool of Computer Science & Technology123123Chapter 2: roadmap2.1 Principles of Network Applications2.2 The Web and HTTP2.3 File Transfer ProtocolFTP2.4 Electronic Mail

151、in the Internet2.5 DNS- The Internet Directory Service2.6 P2P File sharing2.7 Socket Programming with TCP2.8 Socket Programming with UDP2.9 Building a Simple Web Server2.10 SummarySchool of Computer Science & Technology124124Introductionrhandles only oneonly one HTTP requestrequestraccepts the reque

152、st and parsesparses the headerrobtains requested filerequested file from servers file systemrcreates HTTP response message:qheader lines + filersends response message to clientrafter creating the server, you can request file using a browserrsee text and references for details2.9 Building a Simple We

153、b ServerSchool of Computer Science & Technology125125Chapter 2: SummaryrApplication architecturesqclient-server/P2P/Hybridrapplication service requirements:q reliability, bandwidth, delayrInternet transport service modelqreliable: TCPqunreliable, datagrams: UDPOur study of network apps now complete!

154、rspecific protocols:qHTTPqFTPqSMTP, POP, IMAPqDNSrsocket programming with TCP and UDPSchool of Computer Science & Technology126126Chapter 2: Summaryrtypical request/reply request/reply message exchange:qclient requests info or serviceqserver responds with data, status codermessage formats:qheaders:

155、fields giving info about dataqdata: info being communicatedMost importantly: learned about protocolsrcontrol vs. data msgsqin-band, out-of-bandrcentralized vs. decentralized rstateless vs. statefulrreliable vs. unreliable msg transfer r“complexity at network edge”School of Computer Science & Technology127127Homework and Program Assignmentrhomework:qP171: 1qP172: 4,6,8qP173: 9,qP175: 15qdue date: 2 weeksrProgramming Assignment (P.178):qassignment 1: multithreaded web servermultithreaded web serverqdue date : 4 weeks

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

最新文档


当前位置:首页 > 办公文档 > 工作计划

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