Chapter 2: Application Layer - UH

Transcription

COSC 4377, Spring 2001 - Chapter 2, Part A9/18/01chapter 2: Application LayerChapter goals:conceptual implementation aspectsof network applicationprotocolsm client serverparadigmm service modelsr learn about protocols byexamining popularapplication-levelprotocolsrMore chapter goalsr specific protocols:mmmmmhttpftpsmtppopdnsr programming networkapplicationsmsocket programming2: Application Layer1Applications and application-layer protocolsApplication: communicating,distributed processesm running in network hostsand in “user space”m exchange messages toimplement appm e.g., email, file transfer,the WebApplication-layer protocolsm one (big) “piece” of anetwork applicationm define messages exchangedby apps and actions takenm use services provided bylower layer protocols , e.g.,TCP, UDPapplicationtransportnetworkdata linkphysicalapplicationtransportnetworkdata linkphysicalapplicationtransportnetworkdata linkphysical2: Application Layer21

COSC 4377, Spring 2001 - Chapter 2, Part A9/18/01Network applications: some jargonA process is a programthat is running within ahost.r Within the same host, twoprocesses communicatewith interprocesscommunication defined bythe OS.r Processes running indifferent hostscommunicate with anapplication-layer protocolrr A user agent is aninterface between theuser and the networkapplication.mmmWeb:browserE-mail: mail readerstreaming audio/video:media player2: Application Layer3Client-server paradigmTypical network app has twopieces: client and serverClient:r initiates contact with server(“speaks first”)r typically requests servicefrom server,r for Web, client is implementedin browser; for e-mail, in mailreaderServer:r active in listening moder responds and providesrequested service to clientr e.g., Web server sendsrequested Web pageapplicationtransportnetworkdata kdata linkphysical2: Application Layer42

COSC 4377, Spring 2001 - Chapter 2, Part A9/18/01Application-layer protocols (cont).API: applicationprogramming interfacer defines interfacebetween applicationand transport layerr socket: Internet APImQ: how does a process“identify” the otherprocess with which itwants to communicate?mmtwo processescommunicate by sendingdata into socket,reading data out ofsocketIP address of hostrunning other process“port number” - allowsreceiving host todetermine to whichlocal process themessage should bedelivered lots more on this later.2: Application Layer5What transport service does an app need?Data losssome apps (e.g., audio) cantolerate some lossr other apps (e.g., filetransfer, telnet) require100% reliable data transferrBandwidthsome apps (e.g., multimedia)require minimum amount ofbandwidth to be “effective”r other apps (“elastic apps”)make use of whateverbandwidth they getrTimingrsome apps (e.g., Internettelephony, interactivegames) require low delay tobe “effective”2: Application Layer63

COSC 4377, Spring 2001 - Chapter 2, Part A9/18/01Transport service requirements of common appsData lossBandwidthTime Sensitivefile transfere-mailWeb documentsreal-time audio/videono lossno lossloss-tolerantloss-tolerantnononoyes, 100’s msecstored audio/videointeractive gamesfinancial appsloss-tolerantloss-tolerantno losselasticelasticelasticaudio: 5Kb-1Mbvideo:10Kb-5Mbsame as abovefew Kbps upelasticApplicationyes, few secsyes, 100’s msecyes and no2: Application Layer7Services provided by Internettransport protocolsTCP service:rrrrrconnection-oriented: setuprequired between client,serverreliable transport betweensending and receiving processflow control: sender won’toverwhelm receivercongestion control: throttlesender when networkoverloadeddoes not provide: timing,minimum bandwidthguaranteesUDP service:unreliable data transferbetween sending andreceiving processr does not provide:connection setup,reliability, flow control,congestion control, timing,or bandwidth guaranteerQ: why bother? Why isthere a UDP?2: Application Layer84

COSC 4377, Spring 2001 - Chapter 2, Part A9/18/01Internet apps: their protocols and transportprotocolsApplicatione-mailremote terminal accessWebfile transferstreaming multimediaremote file serverInternet telephonyApplicationlayer protocolUnderlyingtransport protocolsmtp [RFC 821]telnet [RFC 854]http [RFC 2068]ftp [RFC 959]proprietary(e.g. RealNetworks)NFSproprietary(e.g., Vocaltec)TCPTCPTCPTCPTCP or UDPTCP or UDPtypically UDP2: Application Layer9The Web: some jargonr Web page:m consists of “objects”m addressed by a URLr Most Web pages consistof:mmbase HTML file, andseveral referencedobjects.r URL (Uniform ResourceLocator) has three parts:r User agent for Web iscalled a browser:mmMS Internet ExplorerNetscape Communicatorr Server for Web iscalled Web server:mmApache (public domain)MS InternetInformation Serverprotocol, host name(w/port), and path if2: Application Layer105

COSC 4377, Spring 2001 - Chapter 2, Part A9/18/01The Web: the http protocolhttp: hypertext transferprotocolWeb’s application layerprotocolr client/server modelm client: browser thatrequests, receives,“displays” Web objectsm server: Web serversends objects inresponse to requestsr http1.0: RFC 1945, May 1996r http1.1: RFC 2068, Jan. 1997rPC runningExplorerhttp nningNCSA WebserverMac runningNavigator2: Application Layer11The http protocol: morehttp: TCP transportservice:client initiates TCPconnection (creates socket)to server, port 80r server accepts TCPconnection from clientr http messages (applicationlayer protocol messages)exchanged between browser(http client) and Web server(http server)r TCP connection closedrhttp is “stateless”rserver maintains noinformation aboutpast client requestsasideProtocols that maintain“state” are complex!r past history (state) mustbe maintainedr if server/client crashes,their views of “state” maybe inconsistent, must bereconciled2: Application Layer126

COSC 4377, Spring 2001 - Chapter 2, Part A9/18/01http exampleSuppose user enters ndex1a. http client initiates TCPconnection to http server(process) atwww.someSchool.edu. Port 80is default for http server.1b. http server at hostwww.someSchool.edu waitingfor TCP connection at port 80.“accepts” connection, notifyingclient2. http client sends http requestmessage (containing URL) intoTCP connection socket(contains text,references to10 jpeg images)3. http server receives requesttimemessage, forms responsemessage containing requestedobject(someDepartment/home.index),sends message into socket2: Application Layer13http example (cont.)4. http server closes TCPconnection.5. http client receives responsetimemessage containing html file,displays html. Parsing htmlfile, finds 10 referenced jpegobjects6. Steps 1-5 repeated for eachof 10 jpeg objects2: Application Layer147

COSC 4377, Spring 2001 - Chapter 2, Part A9/18/01Non-persistent and persistent connectionsNon-persistentr HTTP/1.0r server parses request,responds, and closesTCP connectionr 2 RTTs (round-trip time)to fetch each objectr Each object transfersuffers from slowstartBut most 1.0 browsers useparallel TCP connections.Persistentr default for HTTP/1.1r on same TCPconnection: server,parses request,responds, parses newrequest,.r Client sends requestsfor all referencedobjects as soon as itreceives base HTML.(pipelined)r Fewer RTTs and lessslow start.2: Application Layer15http message format: requestr two types of http messages: request, responser http request message:m ASCII (human-readable format)request line(GET, POST,HEAD commands)GET /somedir/page.html HTTP/1.0User-agent: Mozilla/4.0Accept: text/html, image/ gif,image/jpegheader Accept-language:frlinesCarriage return,line feedindicates endof message(extra carriage return, line feed)2: Application Layer168

COSC 4377, Spring 2001 - Chapter 2, Part A9/18/01http request message: general format2: Application Layer17http message format: responestatus line(protocolstatus codestatus phrase)headerlinesdata, e.g.,requestedhtml fileHTTP/1.0 200 OKDate: Thu, 06 Aug 1998 12:00:15 GMTServer: Apache/1.3.0 (Unix)Last-Modified: Mon, 22 Jun 1998 .Content-Length: 6821Content-Type: text/htmldata data data data data .2: Application Layer189

COSC 4377, Spring 2001 - Chapter 2, Part A9/18/01http response status codesIn first line in server- client response message.A few sample codes:200 OKmrequest succeeded, requested object later in this message301 Moved Permanentlymrequested object moved, new location specified later inthis message (Location:)400 Bad Requestmrequest message not understood by server404 Not Foundmrequested document not found on this server505 HTTP Version Not Supported2: Application Layer19Trying out http (client side) for yourself1. Telnet to your favorite Web server:telnet www.eurecom.fr 80 Opens TCP connection to port 80(default http server port) at www.eurecom.fr.Anything typed in sentto port 80 at www.eurecom.fr2. Type in a GET http request:GET / ross/index.html HTTP/1.0By typing this in (hit carriagereturn twice), you sendthis minimal (but complete)GET request to http server3. Look at response message sent by http server!2: Application Layer2010

COSC 4377, Spring 2001 - Chapter 2, Part A9/18/01User-server interaction: authenticationserverclientAuthentication goal: controlaccess to server documentsusual http request msgr stateless: client must present401: authorization req.authorization in each requestWWW authenticate:r authorization: typically name,passwordusual http request msgm authorization: header Authorization:lineline in requestusual http response msgm if no authorizationpresented, server refusesusual http request msgaccess, sends Authorization:lineWWW authenticate:header line in responseusual http response msgBrowser caches name & password sothat user does not have to repeatedly enter it.time2: Application Layer21User-server interaction: cookiesrserver sends “cookie” toclient in response mstSet-cookie: 1678453rclient presents cookie inlater requestscookie: 1678453rserver matchespresented-cookie withserver-stored infom authenticationm remembering userpreferences, previouschoicesserverclientusual http request msgusual http response Set-cookie: #usual http request msgcookie: #usual http response msgusual http request msgcookie: #usual http response msgcookiespecificactioncookiespecificaction2: Application Layer2211

COSC 4377, Spring 2001 - Chapter 2, Part A9/18/01User-server interaction: conditional GETGoal: don’t send object if clientclient has up-to-date storedhttp request msg(cached) versionIf-modified-since: date r client: specify date ofcached copy in http requesthttp responserIf-modified-since: date robjectnotmodifiedHTTP/1.0304 Not Modifiedserver: response containsno object if cached copy upto-date:HTTP/1.0 304 NotModifiedserverhttp request msgIf-modified-since: date http responseobjectmodifiedHTTP/1.1 200 OK data 2: Application Layer23Web Caches (proxy server)Goal: satisfy client request without involving origin serveruser sets browser:Web accesses via webcacher client sends all httprequests to web cachermmif object at webcache, web cacheimmediately returnsobject in httpresponseelse requests objectfrom origin server,then returns httpresponse to clientoriginserverProxyhttp reestque server requestpclient ohtttppserrespptotnsehclientoriginserver2: Application Layer2412

COSC 4377, Spring 2001 - Chapter 2, Part A9/18/01Why Web Caching?Assume: cache is “close”to client (e.g., in samenetwork)r smaller response time:cache “closer” toclientr decrease traffic todistant serversmoriginserverspublicInternet1.5 Mbpsaccess linkinstitutionalnetworklink out ofinstitutional/local ISPnetwork oftenbottleneck10 Mbps LANinstitutionalcache2: Application Layer25ftp: the file transfer protocoluserat hostFTPFTPuserclientinterfacelocal filesystemfile transferFTPserverremote filesystemtransfer file to/from remote hostr client/server modelm client: side that initiates transfer (either to/fromremote)m server: remote hostr ftp: RFC 959r ftp server: port 21r2: Application Layer2613

COSC 4377, Spring 2001 - Chapter 2, Part A9/18/01ftp: separate control, data connectionsftp client contacts ftp serverat port 21, specifying TCP astransport protocolr two parallel TCP connectionsopened:m control: exchangecommands, responsesbetween client, server.“out of band control”m data: file data to/fromserverr ftp server maintains “state”:current directory, earlierauthenticationrTCP control connectionport 21FTPclientTCP data connectionport 20FTPserver2: Application Layer27ftp commands, responsesSample commands:Sample return codessent as ASCII text overcontrol channelr USER usernamer PASS passwordrrrLIST return list of file incurrent directoryrRETR filename retrieves(gets) filerSTOR filename stores(puts) file onto remotehostrrrrstatus code and phrase (asin http)331 Username OK,password required125 data connectionalready open;transfer starting425 Can’t open dataconnection452 Error writingfile2: Application Layer2814

COSC 4377, Spring 2001 - Chapter 2, Part A9/18/01Electronic MailMajor Components:typessending callsMUAsendingmailservermail user agents (MUA) andAlicemailer process (e.g. sendmail)on the sending networkr mail serversr simple mail transfer protocol:InternetSMTP / ESMTPon the receiving networkr mail access protocols (e.g.receivingdelivers toPOP, IMAP)mailUser Agentserverr a.k.a. “mail reader”Bob’sr composing, editing, readingMUABob’smail messagesmailboxBob’sr e.g., Eudora, Outlook, elm,notifierBobpine, Netscape Messengerr2: Application LayerElectronic Mail: mail serversmailbox contains incomingmessages (yet to be read)for userr message queue of outgoing(to be sent) mail messagesr smtp protocol used betweenmail servers to send emailmessages (routing messages)m client: sending mail serverm “server”: receiving mailserveroutgoingmessage queueuser mailboxMail ragent2: Application Layer3015

COSC 4377, Spring 2001 - Chapter 2, Part A9/18/01Electronic Mail: smtp [RFC 821]rrrrrruses tcp to reliably transfer email msg from client to server,port 25direct transfer: sending server to receiving serverthree phases of transferm handshaking (greeting)m transfer of messagesm closurecommand/response interactionm commands: ASCII textm response: status code and phrasemessages must be in 7-bit ASCIIESMTP [RFC 1869] - SMTP Service Extension: 8-bit datatransfer2: Application Layer31Sample smtp interactionS:C:S:C:S:C:S:C:S:C:C:C:S:C:S:220 hamburger.eduHELO crepes.fr250 Hello crepes.fr, pleased to meet youMAIL FROM: alice@crepes.fr 250 alice@crepes.fr. Sender okRCPT TO: bob@hamburger.edu 250 bob@hamburger.edu . Recipient okDATA354 Enter mail, end with "." on a line by itselfDo you like ketchup?How about pickles?.250 Message accepted for deliveryQUIT221 hamburger.edu closing connection2: Application Layer3216

COSC 4377, Spring 2001 - Chapter 2, Part A9/18/01try smtp interaction for yourself:r telnet servername 25r see 220 reply from serverr enter HELO, MAIL FROM, RCPT TO, DATA, QUITcommandsabove lets you send email without using email client(reader)2: Application Layer33smtp: final wordsrrrrrsmtp uses persistentconnectionssmtp requires that message(header & body) be in 7-bitasciicertain character strings arenot permitted in message (e.g.,CRLF.CRLF). Thus message hasto be encoded (usually intoeither base-64 or quotedprintable)smtp server uses CRLF.CRLFto determine end of messageesmtp can take 8-bit dataComparison with httprrrhttp: pullemail: pushboth have ASCIIcommand/responseinteraction, status codeshttp: each object isencapsulated in its ownresponse messager smtp: multiple objectsmessage sent in a multipartmessager2: Application Layer3417

COSC 4377, Spring 2001 - Chapter 2, Part A9/18/01Mail message formatsmtp: protocol for exchangingemail msgsRFC 822: standard for textmessage format:r header lines(keyword: values), e.g.,To:m From:m Subject:different from smtpcommands!mrheaderblanklinebodybodymthe “message”, ASCIIcharacters only2: Application Layer35Message format: multimedia extensionsMIME: Multipurpose Internet Mail Extension, RFCs 2045-2049,especially RFC 2045 and 2046r additional lines in msg header declare MIME content typerMIME versionmethod usedto encode datamultimedia datatype, subtype,parameter declarationencoded dataFrom: alice@crepes.frTo: bob@hamburger.eduSubject: Picture of yummy crepe.MIME-Version: 1.0Content-Transfer-Encoding: base64Content-Type: image/ jpegbase64 encoded data .base64 encoded data2: Application Layer3618

COSC 4377, Spring 2001 - Chapter 2, Part A9/18/01MIME typesContent-Type: type/subtype; parametersTextrexample subtypes: plain,htmlImagerexample subtypes: jpeg,gifAudiorexample subtypes: basic(8-bit mu-law encoded),32kadpcm (32 kbpscoding)Videorexample subtypes: mpeg,quicktimeApplicationother data that must beprocessed by readerbefore “viewable”r example subtypes:msword, octet-streamr2: Application Layer37Multipart TypeFrom: alice@crepes.frTo: bob@hamburger.eduSubject: Picture of yummy crepe.MIME-Version: 1.0Content-Type: multipart/mixed; boundary 98766789--98766789Content-Transfer-Encoding: quoted-printableContent-Type: text/plainDear Bob,Please find a picture of a crepe.--98766789Content-Transfer-Encoding: base64Content-Type: image/jpegbase64 encoded data .base64 encoded data--98766789--2: Application Layer3819

COSC 4377, Spring 2001 - Chapter 2, Part A9/18/01Mail access protocolsuseragentSMTPSMTPsender’s mailserverPOP3 orIMAPuseragentreceiver’s mailserverSMTP: delivery/storage to receiver’s serverr Mail access protocol: retrieval from serverm POP: Post Office Protocol [RFC 1939] authorization (agent -- server) download mailm IMAP: Internet Mail Access Protocol [RFC 1730]m HTTP or Webmailr2: Application LayerPOP3 protocolauthorization phaseclient commands:m user: declare usernamem pass: passwordr server responsesm OKm -ERRrtransaction phase, client:list: list message numbersr retr: retrieve message bynumberr dele: deleter quitr39S:C:S:C:S: OK POP3 server readyuser alice OKpass hungry OK user successfully loggedC:S:S:S:C:S:S:C:C:S:S:C:C:S:list1 4982 912.retr 1 message 1 contents .dele 1retr 2 message 1 contents .dele 2quit OK POP3 server signing off2: Application Layeron4020

COSC 4377, Spring 2001 - Chapter 2, Part A9/18/01Mail access protocolsr Problems with POPm viewed mail resides on a specific user machine and cannotbe accessed from other machines.r IMAP maintains folder hierarchy on the server can receive/download only components of a message,e.g., header or certain attachmentsr HTTPm Hotmail , Yahoo! Mail, Novell MyRealBox.com, etc.m Similar in concept to IMAP but with a web interface2: Application Layer4121

response to requests rhttp1.0: RFC 1945, May 1996 rhttp1.1: RFC 2068, Jan. 1997 PC running Explorer Server running NCSA Web server Mac running Navigator http request http request http response http response 2: Application Layer 12 The http protocol: more http: TCP transport service: rclient initiates TCP connection (creates socket) to server .