首页计算机计算机系统结构计算机网络 01-2 Chapter1 Introduction.pptx

01-2 Chapter1 Introduction.pptx

页数:81页文件大小:3.00 MB来源: 计算机网络ppt课件

本课件进入协议栈最上层,先讲应用层协议原理与进程通信、套接字与传输服务需求,再依次分析Web与HTTP、FTP、电子邮件与SMTP、DNS域名系统、P2P文件分发与套接字编程,并给出Java示例。

第2章应用层封面,标示教材名称、作者与出版信息
第2章:应用层,涵盖2.1 Principles ofnetwork、2.2 Web and HTTP、2.3 FTP
第2章:应用层,涵盖conceptual,implementatio、learn about protocolsby、programming network
查看本课件的文字版(共 81 页,供检索与复制)

第1页:第2章应用层 封面

第2章应用层 封面

Chapter 2 Application Layer Computer Networking:A Top Down Approach,4 thedition. Jim Kurose, Keith Ross Addison-Wesley, July 2007.

第2页:第2章:应用层

第2章:应用层

  • 2.1 Principles ofnetwork applications
  • 2.2 Web and HTTP
  • 2.3 FTP
  • 2.4 Electronic Mail
    • SMTP, POP3, IMAP
  • 2.5 DNS
  • 2.6 P2P Applications
  • 2.7 Socket programmingwith TCP
  • 2.8 Socket programmingwith UDP

第3页:第2章:应用层

第2章:应用层

  • conceptual,implementation aspects of network application protocols
    • transport-layer service models
    • client-server paradigm
    • peer-to-peerparadigm
  • learn about protocolsby examining popular application-level protocols
    • HTTP
    • FTP
    • SMTP / POP3 / IMAP
    • DNS
  • programming network applications
    • socket API

第4页:Some network apps

Some network apps

  • e-mail
  • web
  • instant messaging
  • remote login
  • P2P file sharing
  • multi-user networkgames
  • streaming stored videoclips
  • voice over IP
  • real-time videoconferencing
  • grid computing

第5页:应用层协议原理(示意图)

应用层协议原理(示意图)

  • run on (different)endsystems
  • communicate over network
  • e.g., web server software communicates with browser software little software written fordevices in network core
  • network core devices donot run user applications
  • applications on end system sallows for rapid appdevelopment, propagation application transport networkdata link physical application transport networkdata link physical application transport networkdata linkphysical

第6页:第2章:应用层

第2章:应用层

  • 2.1 Principles ofnetwork applications
  • 2.2 Web and HTTP
  • 2.3 FTP
  • 2.4 Electronic Mail
    • SMTP, POP3, IMAP
  • 2.5 DNS
  • 2.6 P2P file sharing
  • 2.7 Socket programmingwith TCP
  • 2.8 Socket programmingwith UDP
  • 2.9 Building a Webserver

第7页:应用体系结构

应用体系结构

  • Client-server
  • Peer-to-peer (P2P)
  • Hybrid of client-server and P2P

第8页:Client-server architecture server

Client-server architecture server

  • always-on host
  • permanent IP address
  • server farms forscalingclients:
  • communicate with server
  • may be intermittently connected
  • may have dynamic IPaddresses
  • do not communicate directly with each other client/server

第9页:Pure P2P architecture

Pure P2P architecture

  • noalways-on server
  • arbitrary end systems directly communicate
  • peers are intermittently connected and change IPaddresses
  • example: Gnutella Highly scalable butdifficult to managepeer-peer

第10页:Hybrid client-server and P2PSkype

Hybrid client-server and P2PSkype

  • voice-over-IP P2P application
  • centralized server: finding address of remote party:
  • client-client connection: direct (not through server)Instant messaging
  • chatting between two users is P2P
  • centralized service: client presence detection/location
  • user registers its IP address with central server when it comes online
  • user contacts central server to find IPaddresses of buddies

第11页:Processes comm

Processes comm

  • within same host, twoprocesses communicateusing inter-process communication(definedby OS).
  • processes in differenthosts communicate byex changing messages Client process:processthat initiates communication Server process:processthat waits to becontacted
  • Note: applications with P2P architectures haveclient processes &server processes

第12页:Sockets

Sockets

  • process sends/receives messages to/from itssocket
  • socket analogous to door
    • sending process shoves message out door
    • sending process relies ontransport infrastructureon other side of door which brings message to socketat receiving process process TCP withbuffers,varia blessock ethost orserver process TCP withbuffers,varia blessock ethost orserver Internet controlledby OScontrolled byapp developer
  • API: (1) choice of transport protocol; (2) ability to fixa few parameters(lots more on this later)

第13页:编址进程

编址进程

  • to receive messages,process must haveidentifier
  • host device has unique 32-bit IP address
  • Q:does IP address ofhost on which processruns suffice foridentifying the process?

第14页:编址进程

编址进程

  • to receive messages,process must haveidentifier
  • host device has unique 32-bit IP address
  • Q:does IP address ofhost on which processruns suffice foridentifying theprocess?
    • A:No,manyprocesses can berunning on same host
  • identifierincludes both IP addressandport numbers associated withprocess on host.
  • Example port numbers:
    • HTTP server: 80
    • Mail server: 25
  • to send HTTP messageto gaia.cs.umass.edu webserver:
    • IP address:128.119.245.12
    • Port number:80
  • more shortly…

第15页:App-layer protocol defines

App-layer protocol defines

  • Types of messages exchanged,
    • e.g., request, response
  • Message syntax:
    • what fields in messages &how fields are delineated
  • Message semantics
    • meaning of information infields
  • Rules for when and howprocesses send &respond to messages Public-domain protocols:
  • defined in RFCs
  • allows forinte roper ability
  • e.g., HTTP, SMTP Proprietary protocols:
  • e.g., Skype

第16页:什么运输服务 app

什么运输服务 app

  • some apps (e.g., audio) cantolerate some loss
  • other apps (e.g., filetransfer, telnet) require 100% reliable datatransfer Timing
  • some apps (e.g., Internet telephony,interactive games)require low delay to be“effective”Bandwidth
  • some apps (e.g.,multimedia) require minimum amount ofbandwidth to be“effective”
  • other apps (“elasticapps”) make use ofwhatever bandwidththey get

第17页:运输服务需求的常见 apps

运输服务需求的常见 apps

Transport service requirements of common apps Applicationfile transfere-mail Web documentsreal-time audio/video stored audio/video interactive gamesinstant messaging Data lossno lossno lossno lossloss-tolerantloss-tolerantloss-tolerantno loss Bandwidth elastic elastic elastic audio: 5 kbps-1 Mbpsvideo:10 kbps-5 Mbpssame as abovefew kbps upelastic Time Sensitivenono noyes, 100’s msecyes, few secsyes, 100’s msecyes and no

第18页:因特网运输协议服务 TCP

因特网运输协议服务 TCP

  • connection-oriented:setup required between client andserver processes
  • reliable transport betweens ending and receiving process
  • flow control:sender won’toverwhelm receiver
  • congestion control:throttle sender when network overloaded
  • does not provide:timing,minimum bandwidth guarantees UDP service:
  • unreliable data transfer between sending andreceiving process
  • does not provide:connection setup,reliability, flow control,congestion control, timing,or bandwidth guarantee Q:why bother? Why isthere a UDP?

第19页:因特网 apps:应用运输协议

因特网 apps:应用运输协议

Internet apps: application, transport protocols Applicatione-mailremote terminal access Webfile transfer streaming multimedia Internet telephony Application layer protocol SMTP [RFC 2821]Telnet [RFC 854]HTTP [RFC 2616]FTP [RFC 959]proprietary(e.g. Real Networks)proprietary(e.g., Vonage, Dialpad)Underlying transport protocol TCPTCPTCPTCPTCP or UDPtypically UDP

第20页:第2章:应用层

第2章:应用层

  • 2.1 Principles ofnetwork applications
    • app architectures
    • app requirements
  • 2.2 Web and HTTP
  • 2.4 Electronic Mail
    • SMTP, POP3, IMAP
  • 2.5 DNS
  • 2.6 P2P file sharing
  • 2.7 Socket programmingwith TCP
  • 2.8 Socket programmingwith UDP

第21页:Web and HTTP

Web and HTTP

  • Web pageconsists ofobjects
  • Object can be HTML file, JPEG image, Javaapplet, audio file,…
  • Web page consists ofbase HTML-filewhichincludes several referenced objects
  • Each object is addressable by a URL
  • Example URL:www.someschool.edu/some Dept/pic.gifhost namepath name

第22页:HTTP overview HTTP: hypertext

HTTP overview HTTP: hypertext

  • Web’s application layer protocol
  • client/server model
    • client:browser thatrequests, receives,“displays” Web objects
    • server:Web serversends objects inresponse to requests
  • HTTP 1.0: RFC 1945
  • HTTP 1.1: RFC 2068PC running Explorer Server running Apache Webserver Mac running Navigator HTTP request HTTP request HTTP response HTTP response

第23页:HTTP overview (continued

HTTP overview (continued

  • client initiates TCPconnection (creates socket)to server, port 80
  • server accepts TCPconnection from client
  • HTTP messages (application-layer protocol messages)exchanged between browser(HTTP client) and Webserver (HTTP server)
  • TCP connection closed HTTP is “stateless”
  • server maintains noinformation aboutpast client requests Protocols that maintain“state” are complex!
  • past history (state) mustbe maintained
  • if server/client crashes,their views of “state” maybe inconsistent, must bereconciled aside

第24页:HTTP connections Nonpersistent HTTP

HTTP connections Nonpersistent HTTP

  • At most one object issent over a TCPconnection.
  • HTTP/1.0 uses nonpersistent HTTPPersistent HTTP
  • Multiple objects canbe sent over single TCP connection between client andserver.
  • HTTP/1.1 usespersistent connectionsin default mode

第25页:Nonpersistent HTTP

Nonpersistent HTTP

Nonpersistent HTTPSuppose user enters URLwww.some School.edu/some Department/home.index 1 a. HTTP client initiates TCPconnection to HTTP server(process) atwww.some School.edu on port 802. HTTPclient sends HTTPrequest message(containing URL) into TCP connection socket. Message indicatesthat client wants objectsome Department/home.index 1 b. HTTPserver at hostwww.some School.eduwaitingfor TCP connection at port 80.“accepts” connection, notifying client 3. HTTPserver receives request message, forms response message containing requested object, and sends messageinto its sockettime(contains text,references to 10 jpeg images)

第26页:Nonpersistent HTTP (cont.)5. HTTP client

Nonpersistent HTTP (cont.)5. HTTP client

Nonpersistent HTTP (cont.)5. HTTP client receives response message containing html file,displays html. Parsing htmlfile, finds 10 referenced jpegobjects 6. Steps 1-5 repeated for eachof 10 jpeg objects 4. HTTPserver closes TCPconnection.time

第27页:非持续 HTTP 响应时间定义

非持续 HTTP 响应时间定义

  • one RTT to initiate TCPconnection
  • one RTT for HTTPrequest and first fewbytes of HTTP responseto return
  • file transmission timetotal = 2RTT+transmit timetime totransmitfile initiate TCPconnection RTTrequestfile RTTfilereceivedtimetime

第28页:持续 HTTP 非持续 HTTP 问题

持续 HTTP 非持续 HTTP 问题

  • requires 2 RTTs per object
  • OS overhead foreach TCPconnection
  • browsers often open parallel TCP connections to fetch referenced objects Persistent HTTP
  • server leaves connectionopen after sending response
  • subsequent HTTP messages between same client/serversent over open connection Persistent withoutpipe lining:
  • client issues new requestonly when previous response has been received
  • one RTT for eachreferenced object Persistentwithpipelining:
  • default in HTTP/1.1
  • client sends requests assoon as it encounters areferenced object
  • as little as one RTT for allthe referenced objects

第29页:HTTP 请求报文

HTTP 请求报文

  • two types of HTTP messages:request,response
  • HTTP request message:
    • ASCII (human-readable format)GET /somedir/page.html HTTP/1.1 Host: www.someschool.edu User-agent: Mozilla/4.0 Connection: close Accept-language:fr(extra carriage return, line feed)request line(GET, POST, HEAD commands)headerlines Carriage return,line feedindicates endof message

第30页:HTTP 请求报文通用格式

HTTP 请求报文通用格式

HTTP request message: general format

第31页:Uploading form input Post method

Uploading form input Post method

  • Web page often includes form input
  • Input is uploaded toserver in entity body URL method:
  • Uses GET method
  • Input is uploaded in URL field of requestline:www.somesite.com/animal search?monkeys&banana

第32页:Method types HTTP/1.0

Method types HTTP/1.0

  • GET
  • POST
  • HEAD
    • asks server to leavere quested object out ofresponse HTTP/1.1
  • GET, POST, HEAD
  • PUT
    • uploads file in entitybody to path specifiedin URL field
  • DELETE
    • deletes file specified inthe URL field

第33页:HTTP response message HTTP/1.1 200

HTTP response message HTTP/1.1 200

HTTP response message HTTP/1.1 200 OKConnection close Date: Thu, 06 Aug 1998 12:00:15 GMTServer: Apache/1.3.0 (Unix)Last-Modified: Mon, 22 Jun 1998 …... Content-Length: 6821 Content-Type: text/htmldata data data data data ...status line(protocol status codestatus phrase)headerlinesdata, e.g.,requested HTML file

第34页:HTTP response status codes 200 OK

HTTP response status codes 200 OK

  • request succeeded, requested object later in this message 301 Moved Permanently
  • requested object moved, new location specified later inthis message (Location:)400 Bad Request
  • request message not understood by server 404 Not Found
  • requested document not found on this server 505 HTTP Version Not Supported In first line in server->client response message. A few sample codes:

第35页:Trying out HTTP (client side)

Trying out HTTP (client side)

Trying out HTTP (client side) for yourself 1. Telnet to your favorite Web server:Opens TCP connection to port 80(default HTTP server port) at cis.poly.edu. Anything typed in sentto port 80 at cis.poly.edutelnet cis.poly.edu 802. Type in a GET HTTP request:GET /~ross/ HTTP/1.1 Host: cis.poly.edu By typing this in (hit carriagereturn twice), you sendthis minimal (but complete)GET request to HTTP server 3. Look at response message sent by HTTP server!

第36页:Let’s look HTTP action

Let’s look HTTP action

  • telnet example
  • Ethereal example

第37页:User-server

User-server

  • Susan always access Internet always from PC
  • visits specific e-commerce site for firsttime
  • when initial HTTPrequests arrives at site,site creates:
    • unique ID
    • entry in backenddatabase for ID

第38页:Cookies: keeping “state” (cont.)

Cookies: keeping “state” (cont.)

Cookies: keeping “state” (cont.)client server usual http response msgusual http response msgcookie fileone week later:usual http request msgcookie: 1678 cookie-specific action accessebay 8734 usual http request msg Amazon server creates ID1678 for user create entry usual http response Set-cookie: 1678 ebay 8734 amazon 1678 usual http request msgcookie: 1678 cookie-spectificactionaccessebay 8734 amazon 1678 backenddatabase

第39页:Cookies (continued

Cookies (continued

  • authorization
  • shopping carts
  • recommendations
  • user session state(Web e-mail)Cookies and privacy:
  • cookies permit sites tolearn a lot about you
  • you may supply nameand e-mail to sitesaside How to keep “state”:
  • protocol endpoints: maintain stateat sender/receiver over multiple transactions
  • cookies: http messages carry state

第40页:Web caches (proxy server)

Web caches (proxy server)

  • user sets browser:Web accesses viacache
  • browser sends all HTTP requests tocache
    • object in cache: cachereturns object
    • else cache requests object from origin server, then returnsobject to client Goal:satisfy client request without involving origin server client Proxy server client HTTP request HTTP response HTTP request HTTP request origin server origin server HTTP response HTTP response

第41页:More about Web caching

More about Web caching

  • cache acts as bothclient and server
  • typically cache isinstalled by ISP(university, company,residential ISP)Why Web caching?
  • reduce response timefor client request
  • reduce traffic on aninstitution’s accesslink.
  • Internet dense withcaches: enables “poor”content providers toeffectively deliver content (but so does P2P file sharing)

第42页:Caching example Assumptions

Caching example Assumptions

  • average object size = 100,000 bits
  • avg. request rate from institution’s browsers to origin servers = 15/sec
  • delay from institutional routerto any origin server and backto router = 2 sec Consequences
  • utilization on LAN = 15%
  • utilization on access link = 100%
  • total delay = Internet delay +access delay + LAN delay= 2 sec + minutes + milliseconds origin servers public Internet institutional network 10 Mbps LAN1.5 Mbpsaccess link institutional cache

第43页:缓存示例续

缓存示例续

  • increase bandwidth of accesslink to, say, 10 Mbps consequence
  • utilization on LAN = 15%
  • utilization on access link = 15%
  • Total delay = Internet delay +access delay + LAN delay= 2 sec + msecs + msecs
  • often a costly upgrade origin servers public Internet institutional network 10 Mbps LAN10 Mbpsaccess link institutional cache

第44页:缓存示例续

缓存示例续

  • suppose hit rate is 0.4 consequence
  • 40% requests will besatisfied almost immediately
  • 60% requests satisfied byorigin server
  • utilization of access linkreduced to 60%, resulting innegligible delays (say 10 msec)
  • total avg delay = Internet delay + access delay + LANdelay = .6*(2.01) secs +.4*milliseconds < 1.4 secs origin servers public Internet institutional network 10 Mbps LAN1.5 Mbpsaccess link institutional cache

第45页:Conditional GET

Conditional GET

  • Goal:don’t send object ifcache has up-to-date cached version
  • cache: specify date ofcached copy in HTTP request If-modified-since:<date>
  • server: response contains noobject if cached copy is up-to-date:HTTP/1.0 304 Not Modified cache server HTTP request msg If-modified-since:<date>HTTP response HTTP/1.0304 Not Modified objectnot modified HTTP request msg If-modified-since:<date>HTTP response HTTP/1.0 200 OK<data>object modified

第46页:第2章:应用层

第2章:应用层

  • 2.1 Principles ofnetwork applications
  • 2.2 Web and HTTP
  • 2.3 FTP
  • 2.4 Electronic Mail
    • SMTP, POP3, IMAP
  • 2.5 DNS
  • 2.6 P2P file sharing
  • 2.7 Socket programmingwith TCP
  • 2.8 Socket programmingwith UDP
  • 2.9 Building a Webserver

第47页:FTP: file transfer protocol

FTP: file transfer protocol

  • transfer file to/from remote host
  • client/server model
    • client:side that initiates transfer (either to/fromremote)
    • server:remote host
  • ftp: RFC 959
  • ftp server: port 21 file transfer FTPserver FTPuserinterface FTPclient local file system remote filesystemuserat host

第48页:FTP: separate control, data connections

FTP: separate control, data connections

  • FTP client contacts FTP serverat port 21, TCP is transport protocol
  • client authorized over control connection
  • client browses remote directory by sending commandsover control connection.
  • when server receives filetransfer command, serveropens 2 nd TCP connection (forfile) to client
  • after transferring one file,server closes data connection. FTPclient FTPserver TCP control connectionport 21TCP data connectionport 20
  • server opens another TCPdata connection to transfer another file.
  • control connection:“out ofband”
  • FTP server maintains “state”:current directory, earlierauthentication

第49页:FTP commands, responses Sample commands

FTP commands, responses Sample commands

  • sent as ASCII text overcontrol channel
  • USERusername
  • PASSpassword
  • LISTreturn list of file incurrent directory
  • RETR filename retrieves(gets) file
  • STOR filename stores(puts) file onto remotehost Sample return codes
  • status code and phrase (asin HTTP)
  • 331 Username OK,password required
  • 125 data connection already open;transfer starting
  • 425 Can’t open dataconnection
  • 452 Error writingfile

第50页:第2章:应用层

第2章:应用层

  • 2.1 Principles ofnetwork applications
  • 2.2 Web and HTTP
  • 2.3 FTP
  • 2.4 Electronic Mail
    • SMTP, POP3, IMAP
  • 2.5 DNS
  • 2.6 P2P file sharing
  • 2.7 Socket programmingwith TCP
  • 2.8 Socket programmingwith UDP
  • 2.9 Building a Webserver

第51页:Electronic Mail Three major components

Electronic Mail Three major components

  • user agents
  • mail servers
  • simple mail transfer protocol: SMTPUser Agent
  • a.k.a. “mail reader”
  • composing, editing, readingmail messages
  • e.g., Eudora, Outlook, elm, Mozilla Thunderbird
  • outgoing, incoming messages stored on serveruser mailbox outgoing message queuemailserveruseragentuseragentuseragentmailserveruseragentuseragentmailserveruseragent SMTPSMTPSMTP

第52页:Electronic Mail: mail servers Mail

Electronic Mail: mail servers Mail

  • mailbox contains incoming messages for user
  • message queueof outgoing(to be sent) mail messages
  • SMTP protocol between mailservers to send email messages
    • client: sending mailserver
    • “server”: receiving mailservermailserveruseragentuseragentuseragentmailserveruseragentuseragentmailserveruseragent SMTPSMTPSMTP

第53页:Electronic Mail: SMTP[RFC 2821]

Electronic Mail: SMTP[RFC 2821]

  • uses TCP to reliably transfer email message from clientto server, port 25
  • direct transfer: sending server to receiving server
  • three phases of transfer
    • handshaking (greeting)
    • transfer of messages
    • closure
  • command/response interaction
    • commands:ASCII text
    • response:status code and phrase
  • messages must be in 7-bit ASCII

第54页:Scenario: Alice sends message Bob

Scenario: Alice sends message Bob

Scenario: Alice sends message to Bob 1) Alice uses UA to compose message and “to”bob@someschool.edu 2) Alice’s UA sends messageto her mail server; message placed in message queue 3) Client side of SMTP opens TCP connection with Bob’smail server 4) SMTP client sends Alice’smessage over the TCPconnection 5) Bob’s mail server places themessage in Bob’s mailbox 6) Bob invokes his user agentto read messageuseragentmailservermailserveruseragent 123456

第55页:Sample SMTP interaction S: 220

Sample SMTP interaction S: 220

Sample SMTP interaction S: 220 hamburger.edu C: HELO crepes.fr S: 250 Hello crepes.fr, pleased to meet you C: MAIL FROM: <alice@crepes.fr>S: 250 alice@crepes.fr... Sender ok C: RCPT TO: <bob@hamburger.edu>S: 250 bob@hamburger.edu ... Recipient ok C: DATAS: 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: QUITS: 221 hamburger.edu closing connection

第56页:Try SMTP interaction yourself

Try SMTP interaction yourself

  • telnet servername 25
  • see 220 reply from server
  • enter HELO, MAIL FROM, RCPT TO, DATA, QUITcommandsabove lets you send email without using email client(reader)

第57页:SMTP: final words

SMTP: final words

  • SMTP uses persistent connections
  • SMTP requires message(header & body) to be in 7-bit ASCII
  • SMTP server uses CRLF. CRLFto determineend of message Comparison with HTTP:
  • HTTP: pull
  • SMTP: push
  • both have ASCII command/response interaction, status codes
  • HTTP: each object encapsulated in its ownresponse msg
  • SMTP: multiple objectssent in multipart msg

第58页:Mail message format SMTP: protocol fore

Mail message format SMTP: protocol fore

  • header lines, e.g.,
    • To:
    • From:
    • Subject:differentfrom SMTPcommands!
  • body
    • the “message”, ASCII characters onlyheaderbodyblankline

第59页:Message format: multimedia extensions

Message format: multimedia extensions

  • MIME: multimedia mail extension, RFC 2045, 2056
  • additional lines in msg header declare MIME contenttype From: alice@crepes.fr To: bob@hamburger.edu Subject: Picture of yummy crepe. MIME-Version: 1.0 Content-Transfer-Encoding: base 64 Content-Type: image/jpegbase 64 encoded data ....................................base 64 encoded datamultimedia datatype, subtype,parameter declaration method usedto encode data MIME version encoded data

第60页:Mail access protocols

Mail access protocols

  • SMTP: delivery/storage to receiver’s server
  • Mail access protocol: retrieval from server
    • POP: Post Office Protocol [RFC 1939]
  • authorization (agent <-->server) and download
    • IMAP: Internet Mail Access Protocol [RFC 1730]
  • more features (more complex)
  • manipulation of stored msgs on server
    • HTTP: gmail, Hotmail, Yahoo! Mail, etc.user agent sender’s mailserveruseragent SMTPSMTP access protocol receiver’s mailserver

第61页:POP3协议授权阶段

POP3协议授权阶段

  • client commands:
    • user:declare username
    • pass:password
  • server responses
    • +OK
    • -ERRtransaction phase,client:
  • list:list message numbers
  • retr:retrieve message bynumber
  • dele:delete
  • quit C: list S: 1 498S: 2 912S: . C: retr 1S: <message 1 contents>S: . C: dele 1C: retr 2S: <message 1 contents>S: . C: dele 2C: quit S: +OKPOP3 server signing off S: +OK POP3 server ready C: user bob S: +OKC: pass hungry S: +OKuser success fully logged on

第62页:POP3 (more) and IMA

POP3 (more) and IMA

  • Previous example uses“download and delete”mode.
  • Bob cannot re-read e-mail if he changes client
  • “Download-and-keep”:copies of messages ondifferent clients
  • POP3 is stateless across sessions IMAP
  • Keep all messages inone place: the server
  • Allows user toorganize messages infolders
  • IMAP keeps user state across sessions:
    • names of folders andmappings between message IDs and foldername

第63页:第2章:应用层

第2章:应用层

  • 2.1 Principles ofnetwork applications
  • 2.2 Web and HTTP
  • 2.3 FTP
  • 2.4 Electronic Mail
    • SMTP, POP3, IMAP
  • 2.5 DNS
  • 2.6 P2P file sharing
  • 2.7 Socket programmingwith TCP
  • 2.8 Socket programmingwith UDP
  • 2.9 Building a Webserver

第64页:DNS: Domain Name System People

DNS: Domain Name System People

  • SSN, name, passport #Internet hosts, routers:
  • IP address (32 bit)-used for addressing datagrams
  • “name”, e.g.,ww.yahoo.com-used byhumans Q:map between IPaddresses and name ?Domain Name System:
  • distributed database implemented in hierarchy ofmanyname servers
  • application-layer protocolhost, routers, name servers tocommunicate toresolvenames(address/name translation)
    • note: core Internet function, implemented asapplication-layer protocol
    • complexity at network’s“edge”

第65页:DNSWhy not centralize DNS?

DNSWhy not centralize DNS?

  • single point of failure
  • traffic volume
  • distant centralized database
  • maintenancedoesn’tscale!DNS services
  • hostname to IPaddress translation
  • host aliasing
    • Canonical, alias names
  • mail server aliasing
  • load distribution
    • replicated Webservers: set of IPaddresses for onecanonical name

第66页:Root DNS Server

Root DNS Server

  • client queries a root server to find com DNS server
  • client queries com DNS server to get amazon.com DNS server
  • client queries amazon.com DNS server to get IPaddress for www.amazon.com

第67页:DNS: Root name servers

DNS: Root name servers

  • contacted by local name server that can not resolve name
  • root name server:
    • contacts authoritative name server if name mapping not known
    • gets mapping
    • returns mapping to local name server 13 root nameservers worldwideb USC-ISI Marina del Rey, CAl ICANN Los Angeles, 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 Do D Vienna, VAh ARL Aberdeen, MDj Verisign, ( 21 locations)

第68页:顶级域和权威 Servers

顶级域和权威 Servers

  • Top-level domain (TLD) servers:
    • responsible for com, org, net, edu, etc, and alltop-level country domains uk, fr, ca, jp.
    • Network Solutions maintains servers for com TLD
    • Educause for edu TLD
  • Authoritative DNS servers:
    • organization’s DNS servers, providingauthoritative hostname to IP mappings fororganization’s servers (e.g., Web, mail).
    • can be maintained by organization or service provider

第69页:本地名字服务器

本地名字服务器

  • does not strictly belong to hierarchy
  • each ISP (residential ISP, company,university) has one.
    • also called “default name server”
  • when host makes DNS query, query is sentto its local DNS server
    • acts as proxy, forwards query into hierarchy

第70页:requesting hostcis.p

requesting hostcis.p

  • Host at cis.poly.eduwants IP address forgaia.cs.umass.eduiterated query:
  • contacted serverreplies with name ofserver to contact
  • “I don’t know thisname, but ask thisserver”

第71页:requesting hostcis.p

requesting hostcis.p

  • puts burden of nameresolution oncontacted nameserver
  • heavy load?DNS nameresolution example

第72页:DNS: caching and

DNS: caching and

  • once (any) name server learns mapping, itcaches mapping
    • cache entries timeout (disappear) after sometime
    • TLD servers typically cached in local nameservers
  • Thus root name servers not often visited
  • update/notify mechanisms under design by IETF
    • RFC 2136

第73页:DNS records DNS:distributed db

DNS records DNS:distributed db

  • Type=NS
    • nameis domain (e.g.foo.com)
    • valueis hostname ofauthoritative nameserver for this domain RR format:(name, value, type, ttl)
  • Type=A
    • nameis hostname
    • valueis IP address
  • Type=CNAME
    • nameis alias name for some“canonical” (the real) namewww.ibm.comis reallyservereast.backup 2.ibm.com
    • valueis canonical name
  • Type=MX
    • valueis name of mail server associated withname

第74页:DNS protocol, messages DNS protocol

DNS protocol, messages DNS protocol

  • identification:16 bit #for query, reply to queryuses same #
  • flags:
    • query or reply
    • recursion desired
    • recursion available
    • reply is authoritative

第75页:DNS 协议报文名字类型字段

DNS 协议报文名字类型字段

DNS protocol, messages Name, type fieldsfor a query RRs in responseto query records forauthoritative servers additional “helpful”info that may be used

第76页:插入

插入

  • example: new startup “Network Utopia”
  • register name networkuptopia.com at DNSregistrar(e.g., Network Solutions)
    • provide names, IP addresses of authoritative name server(primary and secondary)
    • registrar inserts two RRs into com TLD server:(network utopia.com, dns 1.network utopia.com, NS)(dns 1.network utopia.com, 212.212.212.1, A)
  • create authoritative server Type A record forwww.networkuptopia.com; Type MX record fornetwork utopia.com
  • How do people get IP address of your Web site?

第77页:第2章:应用层

第2章:应用层

  • 2.1 Principles ofnetwork applications
    • app architectures
    • app requirements
  • 2.2 Web and HTTP
  • 2.4 Electronic Mail
    • SMTP, POP3, IMAP
  • 2.5 DNS
  • 2.6 P2P file sharing
  • 2.7 Socket programmingwith TCP
  • 2.8 Socket programmingwith UDP
  • 2.9 Building a Webserver

第78页:P2P 文件共享示例

P2P 文件共享示例

  • Alice runs P2P client application on hernotebook computer
  • intermittently connects to Internet;gets new IP addressfor each connection
  • asks for “Hey Jude”
  • application displays other peers that havecopy of Hey Jude.
  • Alice chooses one ofthe peers, Bob.
  • file is copied from Bob’s PC to Alice’snotebook: HTTP
  • while Alice downloads,other users uploadingfrom Alice.
  • Alice’s peer is both a Web client and atransient Web server. All peers are servers =highly scalable!

第79页:P2P: centralized directory original

P2P: centralized directory original

  • IP address
  • content 2) Alice queries for “Hey Jude”3) Alice requests file from Bobcentralized directory serverpeers Alice Bob 111123

第80页:P2P: problems with centralized directory

P2P: problems with centralized directory

  • single point of failure
  • performance bottleneck
  • copyright infringement:“target” of lawsuit isobviousfile transfer isdecentralized, butlocating content ishighly centralized

第81页:Query floodi

Query floodi

  • fully distributed
    • no central server
  • public domain protocol
  • many Gnutella clients implementing protocol overlay network: graph
  • edge between peer Xand Y if there’s a TCPconnection
  • all active peers andedges form overlay net
  • edge: virtual (notphysical) link
  • given peer typically connected with < 10 overlay neighbors

第82页:P2P对等应用(示意图)

P2P对等应用(示意图)

  • Query messagesent over existing TCPconnections
  • peers forward Query message
  • Query Hitsent overreversepath Scalability:limited scope flooding

第83页:P2P对等应用(示意图)

P2P对等应用(示意图)

  • peers receiving Ping message respond to Alicewith Pong message 4. Alice receives many Pong messages, and can thensetup additional TCP connections Peer leaving: see homework problem!

第84页:层次覆盖网络

层次覆盖网络

  • between centralized index, query flooding approaches
  • each peer is either agroup leaderor assignedto a group leader.
    • TCP connection betweenpeer and its group leader.
    • TCP connections betweensome pairs of group leaders.
  • group leader tracks content in its children

第85页:客户-服务器与P2P分发时间对比

客户-服务器与P2P分发时间对比

Comparing Client-server, P2P architectures Question: How much time distribute fileinitially at one server to Nother computers?usu 2 d 1 d 2 u 1 u Nd NServer Network (withabundant bandwidth)File, size Fus:server upload bandwidthui:client/peer iupload bandwidthdi:client/peer idownload bandwidth

第86页:Client-server: file distribution

Client-server: file distribution

  • server sequentiallysends N copies:
    • NF/ustime
  • client i takes F/ditime to downloadin creases linearly in N(for large N)= dcs= max{NF/us, F/min(di)}i Time to distribute Fto Nclients usingclient/server approach

第87页:P2P: file distribution timeusu 2 d

P2P: file distribution timeusu 2 d

  • server must send onecopy: F/ustime
  • client i takes F/ditimeto download
  • NF bits must bedownloaded (aggregate)
  • fastest possible upload rate (assumingall nodes sending file chunks to samepeer): us+ uii=1, Nd P2P= max{F/us, F/min(di), NF/(us+ ui)}ii=1, N

第88页:客户-服务器与P2P架构对比

客户-服务器与P2P架构对比

Comparing Client-server, P2P architectures

第89页:P2P Case Study: Bit Torrent tracker

P2P Case Study: Bit Torrent tracker

  • P2P file distribution

第90页:Bit Torrent (1)

Bit Torrent (1)

  • file divided into 256KBchunks.
  • peer joining torrent:
    • has no chunks, but will accumulate them over time
    • registers with tracker to get list of peers,connects to subset of peers (“neighbors”)
  • while downloading, peer uploads chunks to otherpeers.
  • peers may come and go
  • once peer has entire file, it may (selfishly) leave or(altruistically) remain

第91页:Bit Torrent (2)Pulling Chunks

Bit Torrent (2)Pulling Chunks

  • at any given time,different peers havedifferent subsets offile chunks
  • periodically, a peer(Alice) asks eachneighbor for list ofchunks that they have.
  • Alice issues requestsfor her missing chunks
    • rarest first Sending Chunks: tit-for-tat
  • Alice sends chunks tofour neighbors currentlys ending her chunksat thehighest rate
    • re-evaluate top 4 every 10 secs
  • every 30 secs: randomly select another peer,starts sending chunks
    • newly chosen peer mayjoin top 4

第92页:P2P Case study: Skype

P2P Case study: Skype

  • P2P (pc-to-pc, pc-to-phone, phone-to-pc)Voice-Over-IP (Vo IP)application
    • also IM
  • proprietary application-layer protocol (inferred viareverse engineering)
  • hierarchical overlay Skype clients (SC)Supernode(SN)Skype login server

第93页:Skype: making call

Skype: making call

  • User starts Skype Skype login server
  • SC registers with SN
    • list of bootstrap SNs
  • SC logs in(authenticate)
  • Call: SC contacts SN willcallee ID
    • SN contacts other SNs(unknown protocol, maybe flooding) to find addr ofcallee; returns addr to SC
  • SC directly contacts callee, over TCP

第94页:第2章:应用层

第2章:应用层

  • 2.1 Principles ofnetwork applications
  • 2.2 Web and HTTP
  • 2.3 FTP
  • 2.4 Electronic Mail
    • SMTP, POP3, IMAP
  • 2.5 DNS
  • 2.6 P2P file sharing
  • 2.7 Socket programmingwith TCP
  • 2.8 Socket programmingwith UDP

第95页:套接字编程套接字 API

套接字编程套接字 API

  • introduced in BSD4.1 UNIX,1981
  • explicitly created, used,released by apps
  • client/server paradigm
  • two types of transport service via socket API:
    • unreliable datagram
    • reliable, byte stream-orientedahost-local,application-created, OS-controlled interface(a “door”) into which application process canboth send andreceive messages to/froman other application process socket Goal:learn how to build client/server application that communicate using sockets

第96页:Socket-programming using TCP

Socket-programming using TCP

Socket-programming using TCPSocket:a door between application process and end-end-transport protocol (UCP or TCP)TCP service:reliable transfer ofbytesfrom oneprocess to another process TCP withbuffers,variables socket controlled byapplication developer controlled byoperatingsystemhost orserver process TCP withbuffers,variables socket controlled byapplication developer controlled byoperatingsystemhost orserver internet

第97页:Socket programmingwith TCP

Socket programmingwith TCP

  • server process must firstbe running
  • server must have created socket (door) thatwelcomes client’s contact Client contacts server by:
  • creating client-local TCPsocket
  • specifying IP address, portnumber of server process
  • Whenclient creates socket: client TCPestablishes connection toserver TCP
  • When contacted by client,server TCP creates newsocketfor server process tocommunicate with client
    • allows server to talk withmultiple clients
    • source port numbersused to distinguish clients(more in Chap 3)TCP provides reliable, in-order transfer of bytes (“pipe”)between client and server application viewpoint

第98页:Client/server socket interaction

Client/server socket interaction

Client/server socket interaction: TCPwait for incoming connection request connection Socket =welcome Socket.accept()create socket,port=x, forincoming request:welcome Socket =Server Socket()create socket,connect tohostid, port=xclient Socket =Socket()close connection Socketread reply fromclient Socket close client Socket Server(running onhostid)Clientsend request usingclient Socketread request fromconnection Socket write reply toconnection Socket TCPconnection setup

第99页:Client process client TCP

Client process client TCP

  • Astreamis a sequence ofcharacters that flow intoor out of a process.
  • Aninput streamis attached to some inputsource for the process,e.g., keyboard or socket.
  • Anoutput streamis attached to an output source, e.g., monitor orsocket.

第100页:套接字编程与 TCP

套接字编程与 TCP

Socket programming with TCPExample client-server app:1) client reads line fromstandard input (in From Userstream) , sends to server viasocket (out To Server stream)2) server reads line from socket 3) server converts line touppercase, sends back toclient 4) client reads, prints modifiedline from socket(in From Server stream)

第101页:Example: Java client

Example: Java client

Example: Java client (TCP)import java.io.*;import java.net.*;class TCPClient {public static void main(String argv[]) throws Exception{String sentence;String modified Sentence;Buffered Reader in From User =new Buffered Reader(new Input Stream Reader(System.in));Socket client Socket = new Socket("hostname", 6789);Data Output Stream out To Server =new Data Output Stream(client Socket.get Output Stream());Createinput stream Create client socket,connect to server Create output stream attached to socket

第102页:Example: Java client (TCP), cont

Example: Java client (TCP), cont

Example: Java client (TCP), cont. Buffered Reader in From Server =new Buffered Reader(new Input Stream Reader(client Socket.get Input Stream()));sentence = in From User.read Line();out To Server.write Bytes(sentence + '\n');modified Sentence = in From Server.read Line();System.out.println("FROM SERVER: " + modified Sentence);client Socket.close();}}Createinput stream attached to socket Send lineto server Read linefrom server

第103页:Example: Java server

Example: Java server

Example: Java server (TCP)import java.io.*;import java.net.*;class TCPServer {public static void main(String argv[]) throws Exception{String client Sentence;String capitalized Sentence;Server Socket welcome Socket = new Server Socket(6789);while(true) {Socket connection Socket = welcome Socket.accept();Buffered Reader in From Client =new Buffered Reader(new Input Stream Reader(connection Socket.get Input Stream()));Createwel coming socketat port 6789 Wait, on welcoming socket for contactby client Create inputstream, attachedto socket

第104页:Example: Java server (TCP), cont Data

Example: Java server (TCP), cont Data

Example: Java server (TCP), cont Data Output Stream out To Client =new Data Output Stream(connection Socket.get Output Stream());client Sentence = in From Client.read Line();capitalized Sentence = client Sentence.to Upper Case() + '\n';out To Client.write Bytes(capitalized Sentence);}}}Read in linefrom socket Create output stream, attachedto socket Write out lineto socket End of while loop,loop back and wait foranother client connection

第105页:第2章:应用层

第2章:应用层

  • 2.1 Principles ofnetwork applications
  • 2.2 Web and HTTP
  • 2.3 FTP
  • 2.4 Electronic Mail
    • SMTP, POP3, IMAP
  • 2.5 DNS
  • 2.6 P2P file sharing
  • 2.7 Socket programmingwith TCP
  • 2.8 Socket programmingwith UDP
  • 2.9 Building a Webserver

第106页:Socket programmingwith UDPUDP: no

Socket programmingwith UDPUDP: no

  • no handshaking
  • sender explicitly attaches IP address and port ofdestination to each packet
  • server must extract IPaddress, port of senderfrom received packet UDP: transmitted data may bereceived out of order, orlostapplication viewpoint UDP provides unreliable transferof groups of bytes (“datagrams”)between client and server

第107页:Client/server socket interaction: UDP

Client/server socket interaction: UDP

Client/server socket interaction: UDPclose client Socket Server(running onhostid)read reply fromclient Socket create socket,client Socket =Datagram Socket()Client Create, address (hostid, port=x,send datagram requestusingclient Socket create socket,port=x, forincoming request:server Socket =Datagram Socket()read request fromserver Socket write reply toserver Socket specifying clienthost address,port number

第108页:Example: Java client

Example: Java client

Example: Java client (UDP)Output:sendspacket (recallthat TCP sent“byte stream”)Input:receives packet (recallthat TCP received“byte stream”)Client process client UDPsocket

第109页:Example: Java client

Example: Java client

Example: Java client (UDP)import java.io.*;import java.net.*;class UDPClient {public static void main(String args[]) throws Exception{Buffered Reader in From User =new Buffered Reader(new Input Stream Reader(System.in));Datagram Socket client Socket = new Datagram Socket();Inet Address IPAddress = Inet Address.get By Name("hostname");byte[] send Data = new byte[1024];byte[] receive Data = new byte[1024];String sentence = in From User.read Line();send Data = sentence.get Bytes();Createinput stream Create client socket Translatehostname to IPaddressusing DNS

第110页:Example: Java client (UDP), cont

Example: Java client (UDP), cont

Example: Java client (UDP), cont. Datagram Packet send Packet =new Datagram Packet(send Data, send Data.length, IPAddress, 9876);client Socket.send(send Packet);Datagram Packet receive Packet =new Datagram Packet(receive Data, receive Data.length);client Socket.receive(receive Packet);String modified Sentence =new String(receive Packet.get Data());System.out.println("FROM SERVER:" + modified Sentence);client Socket.close();}}Create datagramwith data-to-send,length, IP addr, port Send datagramto server Read datagramfrom server

第111页:Example: Java server

Example: Java server

Example: Java server (UDP)import java.io.*;import java.net.*;class UDPServer {public static void main(String args[]) throws Exception{Datagram Socket server Socket = new Datagram Socket(9876);byte[] receive Data = new byte[1024];byte[] send Data = new byte[1024];while(true){Datagram Packet receive Packet =new Datagram Packet(receive Data, receive Data.length);server Socket.receive(receive Packet);Create datagram socketat port 9876 Create space forreceived datagram Receive datagram

第112页:Example: Java server (UDP), cont String

Example: Java server (UDP), cont String

Example: Java server (UDP), cont String sentence = new String(receive Packet.get Data());Inet Address IPAddress = receive Packet.get Address();int port = receive Packet.get Port();String capitalized Sentence = sentence.to Upper Case();send Data = capitalized Sentence.get Bytes();Datagram Packet send Packet =new Datagram Packet(send Data, send Data.length, IPAddress,port);server Socket.send(send Packet);}}}Get IP addrport #, ofsender Write outdatagramto socket End of while loop,loop back and wait foranother datagram Create datagramto send to client

第113页:第2章小结

第2章小结

  • application architectures
    • client-server
    • P2P
    • hybrid
  • application service requirements:
    • reliability, bandwidth,delay
  • Internet transport service model
    • connection-oriented,reliable: TCP
    • unreliable, datagrams: UDPour study of network apps now complete!
  • specific protocols:
    • HTTP
    • FTP
    • SMTP, POP, IMAP
    • DNS
    • P2P: Bit Torrent, Skype
  • socket programming

第114页:第2章小结

第2章小结

  • typical request/replymessage exchange:
    • client requests info orservice
    • server responds withdata, status code
  • message formats:
    • headers: fields givinginfo about data
    • data: info being communicated Most importantly:learned about protocols Important themes:
  • control vs. data msgs
    • in-band, out-of-band
  • centralized vs.decentralized
  • stateless vs. stateful
  • reliable vs. unreliablemsg transfer
  • “complexity at networkedge”
顶部目录