1、2:Application Layer1Chapter 2Application LayerComputer Networking:A Top Down Approach,4th edition.Jim Kurose,Keith RossAddison-Wesley,July 2007.2:Application Layer2Chapter 2:Application layerr2.1 Principles of network applicationsr2.2 Web and HTTPr2.3 FTP r2.4 Electronic MailvSMTP,POP3,IMAPr2.5 DNSr
2、2.6 P2P applicationsr2.7 Socket programming with TCPr2.8 Socket programming with UDP2:Application Layer3Chapter 2:Application LayerOur goals:rconceptual,implementation aspects of network application protocolsvtransport-layer service modelsvclient-server paradigmvpeer-to-peer paradigmrlearn about pro
3、tocols by examining popular application-level protocolsvHTTPvFTPvSMTP/POP3/IMAPvDNSrprogramming network applicationsvsocket API2:Application Layer4Some network appsre-mailrwebrinstant messagingrremote loginrP2P file sharingrmulti-user network gamesrstreaming stored video clipsrvoice over IPrreal-tim
4、e video conferencingrgrid computing 2:Application Layer5Creating a network appwrite programs thatvrun on(different)end systemsvcommunicate over networkve.g.,web server software communicates with browser softwareNo need to write software for network-core devicesvNetwork-core devices do not run user a
5、pplications vapplications on end systems allows for rapid app development,propagationapplicationtransportnetworkdata linkphysicalapplicationtransportnetworkdata linkphysicalapplicationtransportnetworkdata linkphysical2:Application Layer6Chapter 2:Application layerr2.1 Principles of network applicati
6、onsr2.2 Web and HTTPr2.3 FTP r2.4 Electronic MailvSMTP,POP3,IMAPr2.5 DNSr2.6 P2P applicationsr2.7 Socket programming with TCPr2.8 Socket programming with UDPr2.9 Building a Web server2:Application Layer7Application architecturesrClient-serverrPeer-to-peer(P2P)rHybrid of client-server and P2P2:Applic
7、ation Layer8Client-server architectureserver:valways-on hostvpermanent IP addressvserver farms for scaling 主机群集clients:vcommunicate with servervmay be intermittently connectedvmay have dynamic IP addressesvdo not communicate directly with each otherclient/server2:Application Layer9Pure P2P architect
8、urerno always-on serverrarbitrary end systems directly communicaterpeers are intermittently connected and change IP addressesHighly scalable but difficult to managepeer-peer2:Application Layer10Hybrid of client-server and P2PSkypevvoice-over-IP P2P applicationvcentralized service:client presence det
9、ection/location user registers its IP address with central server when it comes online user contacts central server to find IP addresses of buddiesvclient-client connection:direct(not through server),chatting between two users is P2PInstant messagingvMSN,QQ,2:Application Layer112:Application Layer12
10、Processes communicatingProcess:program running within a host.rwithin same host,two processes communicate using inter-process communication(defined by OS).rprocesses in different hosts communicate by exchanging messagesClient process:process that initiates communicationServer process:process that wai
11、ts to be contactedrNote:applications with P2P architectures have client processes&server processes2:Application Layer13Socketsrprocess sends/receives messages to/from its socketrsocket analogous to doorrdefinitionvA socket is one endpoint of a two-way communication link between two programs running
12、on the network.A socket is bound to a port number so that the TCP layer can identify the application that data is destined to be sent.processTCP withbuffers,variablessockethost orserverprocessTCP withbuffers,variablessockethost orserverInternetcontrolledby OScontrolled byapp developerrAPI(Applicatio
13、n Programming Interface):(1)choice of transport protocol;(2)ability to fix a few parameters(lots more on this later)2:Application Layer14rAn endpoint is a combination of an IP address and a port number.Every TCP connection can be uniquely identified by its two endpoints.That way you can have multipl
14、e connections between your host and the server.2:Application Layer15rOn the client-side:To make a connection request,the client tries to rendezvous(在指定地点集合)with the server on the servers machine and port.The client also needs to identify itself to the server so it binds to a local port number that i
15、t will use during this connection.This is usually assigned by the system.2:Application Layer16rNormally,a server runs on a specific computer and has a socket that is bound to a specific port number.The server just waits,listening to the socket for a client to make a connection request.rOn the server
16、-side:If everything goes well,the server accepts the connection.Upon acceptance,the server gets a new socket bound to the same local port and also has its remote endpoint set to the address and port of the client.It needs a new socket so that it can continue to listen to the original socket for conn
17、ection requests while tending to the needs of the connected client.2:Application Layer17Addressing processesrto receive messages,process must have identifierrhost device has unique 32-bit IP addressrQ:does IP address of host suffice for identifying the process?2:Application Layer18Addressing process
18、esrto receive messages,process must have identifierrhost device has unique 32-bit IP addressrQ:does IP address of host on which process runs suffice for identifying the process?vA:No,many processes can be running on same hostridentifier includes both IP address and port numbers associated with proce
19、ss on host.rExample port numbers:vHTTP server:80vMail server:25rto send HTTP message to gaia.cs.umass.edu web server:vIP address:128.119.245.12vPort number:802:Application Layer19App-layer protocol definesrTypes of messages exchanged,ve.g.,request,response rMessage syntax:vwhat fields in messages&ho
20、w fields are delineatedrMessage semantics vmeaning of information in fieldsrRules for when and how processes send&respond to messagesPublic-domain protocols:rdefined in RFCsrallows for interoperabilityre.g.,HTTP,SMTPProprietary protocols:re.g.,Skype2:Application Layer20What transport service does an
21、 app need?Data lossrsome apps(e.g.,audio)can tolerate some lossrother apps(e.g.,file transfer,telnet)require 100%reliable data transfer Timingrsome apps(e.g.,Internet telephony,interactive games)require low delay to be“effective”Throughputrsome apps(e.g.,multimedia)require minimum amount of throughp
22、ut to be“effective”rother apps(“elastic apps”)make use of whatever throughput they get SecurityrEncryption,data integrity,2:Application Layer21Transport service requirements of common appsApplicationfile transfere-mailWeb documentsreal-time audio/videostored audio/videointeractive gamesinstant messa
23、gingData lossno lossno lossno lossloss-tolerantloss-tolerantloss-tolerantno lossThroughputelasticelasticelasticaudio:5kbps-1Mbpsvideo:10kbps-5Mbpssame as above few kbps upelasticTime Sensitivenononoyes,100s msecyes,few secsyes,100s msecyes and no2:Application Layer22Internet transport protocols serv
24、icesTCP service:rconnection-oriented:setup required between client and server processesrreliable transport between sending and receiving processrflow control:sender wont overwhelm receiver rcongestion control:throttle sender when network overloadedrdoes not provide:timing,minimum throughput guarante
25、es,securityUDP service:runreliable data transfer between sending and receiving processrdoes not provide:connection setup,reliability,flow control,congestion control,timing,throughput guarantee,or security Q:why bother?Why is there a UDP?2:Application Layer23Internet apps:application,transport protoc
26、olsApplicatione-mailremote terminal accessWeb file transferstreaming multimediaInternet telephonyApplicationlayer protocolSMTP RFC 2821Telnet RFC 854HTTP RFC 2616FTP RFC 959HTTP(eg Youtube),RTP RFC 1889SIP,RTP,proprietary(e.g.,Skype)Underlyingtransport protocolTCPTCPTCPTCPTCP or UDPtypically UDP2:Ap
27、plication Layer24rSIP-Session Initiation Protocol-is a network communications protocol commonly employed for Voice over IP signaling.rRTP-(Realtime Transport Protocol)-An IP protocol that supports real-time transmission of voice and video.It is widely used for IP telephony and audio and video stream
28、ing.An RTP packet rides on top of UDP and includes timestamping and synchronization information in its header for proper reassembly at the receiving end.Secure RTP(SRTP)is a version of RTP that provides confidentiality and message authentication.2:Application Layer25Chapter 2:Application layerr2.1 P
29、rinciples of network applications vapp architecturesvapp requirementsr2.2 Web and HTTPr2.4 Electronic MailvSMTP,POP3,IMAPr2.5 DNSr2.6 P2P applicationsr2.7 Socket programming with TCPr2.8 Socket programming with UDP2:Application Layer26Web and HTTPFirst some jargon(行话)rWeb is a kind of application.rW
30、eb page consists of objectsrObject can be HTML file,JPEG image,Java applet,audio file,rWeb page consists of base HTML-file which includes several referenced objectsrEach object is addressable by a URLwww.someschool.edu/someDept/pic.gifhost namepath name2:Application Layer27HTTP overviewHTTP:hypertex
31、t transfer protocolrWebs application layer protocolrclient/server modelvclient:browser that requests,receives,“displays”Web objectsvserver:Web server sends objects in response to requestsPC runningExplorerServer runningApache WebserverMac runningNavigatorHTTP requestHTTP requestHTTP responseHTTP res
32、ponse2:Application Layer28HTTP overview(continued)Uses TCP:rclient initiates TCP connection(creates socket)to server,port 80rserver accepts TCP connection from clientrHTTP messages(application-layer protocol messages)exchanged between browser(HTTP client)and Web server(HTTP server)rTCP connection cl
33、osedHTTP is“stateless”rserver maintains no information about past client requestsProtocols that maintain“state”are complex!rpast history(state)must be maintainedrif server/client crashes,their views of“state”may be inconsistent,must be reconciledaside2:Application Layer29HTTP connectionsNonpersisten
34、t HTTP非持久rAt most one object is sent over a TCP connection.Persistent HTTPrMultiple objects can be sent over single TCP connection between client and server.2:Application Layer30Nonpersistent HTTPSuppose user enters URL www.someSchool.edu/someDepartment/home.index1a.HTTP client initiates TCP connect
35、ion to HTTP server(process)at www.someSchool.edu on port 802.HTTP client sends HTTP request message(containing URL)into TCP connection socket.Message indicates that client wants object someDepartment/home.index1b.HTTP server at host www.someSchool.edu waiting for TCP connection at port 80.“accepts”c
36、onnection,notifying client3.HTTP server receives request message,forms response message containing requested object,and sends message into its sockettime(contains text,references to 10 jpeg images)2:Application Layer31Nonpersistent HTTP(cont.)5.HTTP client receives response message containing html f
37、ile,displays html.Parsing html file,finds 10 referenced jpeg objects6.Steps 1-5 repeated for each of 10 jpeg objects4.HTTP server closes TCP connection.time2:Application Layer32Non-Persistent HTTP:Response timeDefinition of RTT:time for a small packet to travel from client to server and back.Respons
38、e time:rone RTT to initiate TCP connectionrone RTT for HTTP request and first few bytes of HTTP response to returnrfile transmission timetotal=2RTT+transmit timetime to transmit fileinitiate TCPconnectionRTTrequestfileRTTfilereceivedtimetime2:Application Layer33Persistent HTTPNonpersistent HTTP issu
39、es:rrequires 2 RTTs per objectrOS overhead for each TCP connectionrbrowsers often open parallel TCP connections to fetch referenced objectsPersistent HTTPrserver leaves connection open after sending responsersubsequent HTTP messages between same client/server sent over open connectionrclient sends r
40、equests as soon as it encounters a referenced objectras little as one RTT for all the referenced objects2:Application Layer34HTTP request messagertwo types of HTTP messages:request,responserHTTP request message:vASCII(human-readable format)GET/somedir/page.html HTTP/1.1Host:www.someschool.edu User-a
41、gent:Mozilla/4.0Connection:close Accept-language:fr(extra carriage return,line feed)request line(GET,POST,HEAD commands)header linesCarriage return,line feed indicates end of message2:Application Layer35HTTP request message:general format2:Application Layer36Uploading form inputPost method:rWeb page
42、 often includes form inputrInput is uploaded to server in entity bodyURL method:rUses GET methodrInput is uploaded in URL field of request line: Layer372:Application Layer38rzh-cn:simplified chinese rAccept-Encoding:gzip,deflaterUser-Agent:Mozilla/4.0(compatible;MSIE 6.0;Windows NT 5.1;SV1;InfoPath.
43、1;.NET CLR 2.0.50727)the ie of the user2:Application Layer39Method typesHTTP/1.0rGETrPOSTrHEADvasks server to leave requested object out of responsevUsed to trace faultsHTTP/1.1rGET,POST,HEADrPUTvuploads file in entity body to path specified in URL fieldrDELETEvdeletes file specified in the URL fiel
44、d2:Application Layer40HTTP response messageHTTP/1.1 200 OK Connection closeDate: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 data data data.status line(protocolstatus codestatus phrase)header linesdata,e.g.,r
45、equestedHTML file2:Application Layer412:Application Layer42HTTP response status codes200 OKvrequest succeeded,requested object later in this message301 Moved Permanentlyvrequested object moved,new location specified later in this message(Location:)400 Bad Requestvrequest message not understood by se
46、rver404 Not Foundvrequested document not found on this server505 HTTP Version Not SupportedIn first line in server-client response message.A few sample codes:2:Application Layer43Trying out HTTP(client side)for yourself1.Open ethereal;2.http:/3.Stop capture2:Application Layer44User-server state:cook
47、iesMany major 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 siteExample:rSusan always access Internet always from PCrvisits specific e-c
48、ommerce site for first timerwhen initial HTTP requests arrives at site,site creates:vunique IDventry in backend database for ID2:Application Layer45Cookies:keeping“state”(cont.)clientserverusual http response msgusual http response msgcookie fileone week later:usual http request msgcookie:1678cookie
49、-specificactionaccessebay 8734usual http request msgAmazon servercreates ID1678 for usercreate entryusual http response Set-cookie:1678 ebay 8734amazon 1678usual http request msgcookie:1678cookie-spectificactionaccessebay 8734amazon 1678backenddatabase2:Application Layer46Cookies(continued)What cook
50、ies can bring:rauthorizationrshopping cardsrrecommendationsruser session state(Web e-mail)Cookies and privacy:rcookies permit sites to learn a lot about youryou may supply name and e-mail to sitesasideHow to keep“state”:rprotocol endpoints:maintain state at sender/receiver over multiple transactions