* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download 3rd Edition: Chapter 2 - Universidad de Sevilla
Survey
Document related concepts
TCP congestion control wikipedia , lookup
SIP extensions for the IP Multimedia Subsystem wikipedia , lookup
Server Message Block wikipedia , lookup
Cracking of wireless networks wikipedia , lookup
Dynamic Host Configuration Protocol wikipedia , lookup
Recursive InterNetwork Architecture (RINA) wikipedia , lookup
Internet protocol suite wikipedia , lookup
Cross-site scripting wikipedia , lookup
Zero-configuration networking wikipedia , lookup
Remote Desktop Services wikipedia , lookup
Transcript
Departamento de Tecnología Electrónica Computer Networking Chapter 2 The Application layer Some of these slides are given as copyrighted material from: Computer Networking: A Top Down Approach , 5th edition. Jim Kurose, Keith Ross Addison-Wesley, April 2009. Chapter 2: The Application Layer Our goals: conceptual, implementation aspects of network application protocols transport-layer service models client-server paradigm peer-to-peer paradigm learn about protocols by examining popular application-layer protocols HTTP DNS programming network applications socket API Application 2-2 Some network apps e-mail web instant messaging remote login P2P file sharing multi-user network games streaming stored video (e.g. YouTube) voice over IP (VoIP) real-time video conferencing cloud computing … … Application 2-3 Creating a network app write programs that application transport network data link physical run on (different) end systems communicate over network e.g., web server software communicates with browser software No need to write software for network-core devices network-core devices do not run user applications applications on end systems allows for rapid app development, propagation application transport network data link physical application transport network data link physical Application 2-4 Chapter 2: Application layer 2.1 Principles of network applications 2.2 DNS 2.3 Web and HTTP 2.4 Socket programming with TCP 2.5 Socket programming with UDP Application 2-5 Application architectures client-server peer-to-peer (P2P) hybrid of client-server and P2P Note: IP address: it uniquely identifies the devices (end systems, routers, etc...) connected to a TCP/IP network. The ISP assigns a static (fixed) or dynamic (variable) IP addr. More soon ... Application 2-6 Client-server architecture server: always-on host permanent IP address server farms for scaling clients: client/server communicate with server may be intermittently connected may have dynamic IP addresses do not communicate directly with each other Application 2-7 Pure P2P architecture no always-on server arbitrary end systems directly communicate peer-peer peers are intermittently connected and change IP addresses highly scalable but difficult to manage Application 2-8 Hybrid of client-server and P2P Skype 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 IP addresses of buddies Application 2-9 How is app layer implemented? Web browsers, e.g.: Mozilla firefox, Chrome, Internet Explore, Safari,… User interface User interface Application Application Protocol Application A_PDU SAP SAP Transport Transport Internet Application 2-10 App-layer protocol defines types of exchanged messages, e.g., request, response message syntax: what fields are in messages & how fields are distinguished public-domain protocols: defined in RFCs allows for interoperability e.g., HTTP, SMTP proprietary protocols: e.g., Skype message semantics meaning of information in fields rules for when and how processes send & respond to messages Application 2-11 Process communication process: program running within a host. within the same host, communication is held using inter-process communication (defined by OS). In different hosts, communication is done by exchanging messages (PDUs). Communication services (generally defined by OS) are used. client process: process that initiates communication server process: process that waits to be contacted Note: applications with P2P architectures have both client processes & server processes Application 2-12 Sockets (SAP) process sends/receives messages to/from its socket socket analogous to door sending process sends message out door sending process relies on transport infrastructure on the other side of the door, bringing message to socket at receiving process server client process controlled by app developer process socket socket TCP with buffers, variables Internet TCP with buffers, variables controlled by OS API: (1) choice of transport protocol; (2) ability to fix a few parameters (more on this later) Application 2-13 How is a socket identified? If you want to send a friend a mail you need to know his address to reach his home mailbox Each end system has unique 32-bit IP address (IPv4) Note For every IP address you have an associated name (hostname) which are used to identify the network devices by humans and applications. For example, www.dte.us.es = 150.214.141.196 More on Names and IPs on next section… Q: Is your friend’s address enough to make the letters reach him? A: No. Several people may be living at the same home. Several app protocols can be running on one end system Web browser, email client, Skype… Application 2-14 How is a socket identified? Each app protocol is identified by a port number Client port number and server port number may not be the same example port numbers: HTTP server: 80 DNS server: 53 Mail server: 25 ICANN (Internet Corporation for Assigned Names and Numbers) is responsible for public app protocols port registering http://www.iana.org/assignments/port-numbers Socket is identified by the pair: IP address Port number Application 2-15 Example DTE web server Interfaz Usuario Interfaz Usuario Aplicación Aplicación 150.214.141.196, 80 Client IP address, port Transport Transport Internet Application 2-16 Localhost: Connecting 2 process on the same host localhost: is a “reserved name” related to a particular IP address which always identify our own end system. It’s useful to connect network applications on a single host (without any other physical network connection). In general, it allows interprocess comunications in the end system using the same Internet protocol stack. Note process1 process2 socket1 socket2 OS Internet Communication Service Localhost is usually asociated to IP address 127.0.0.1, but other IPs may be used…. More on Chapter 4… Q: How can the communication service on the host able to distinguish each process? Application 2-17 What transport service does an app need? Data loss some apps (e.g., audio) can tolerate some loss other apps (e.g., file transfer, telnet) require 100% reliable data transfer Timing some apps (e.g., Internet telephony, interactive games) require low delay to be “effective” Throughput some apps (e.g., multimedia) require minimum amount of throughput to be “effective” other apps (“elastic apps”) make use of whatever throughput they get Security encryption, data integrity, … Application 2-18 Transport service requirements of common apps Data loss Throughput Time Sensitive file transfer e-mail Web documents real-time audio/video no loss no loss no loss loss-tolerant no no no yes, 100’s msec stored audio/video interactive games instant messaging loss-tolerant loss-tolerant no loss elastic elastic elastic audio: 5kbps-1Mbps video:10kbps-5Mbps same as above few kbps up elastic Application yes, few secs yes, 100’s msec yes and no Application 2-19 Internet transport protocols services TCP service: connection-oriented: setup required between client and server processes reliable transport between sending and receiving process flow control: sender won’t overwhelm receiver congestion control: throttle sender when network overloaded does not provide: timing, minimum throughput guarantees, security UDP service: unreliable data transfer between sending and receiving process does not provide: connection setup, reliability, flow control, congestion control, timing, throughput guarantee, or security Q: Why UDP? Application 2-20 Internet apps: application, transport protocols Application e-mail remote terminal access Web file transfer streaming multimedia Internet telephony Application layer protocol Underlying transport protocol SMTP [RFC 2821] Telnet [RFC 854] HTTP [RFC 2616] FTP [RFC 959] HTTP (e.g., YouTube), RTP [RFC 1889] SIP, RTP, propietary (e.g., Skype) TCP TCP TCP TCP TCP or UDP typically UDP Application 2-21 Chapter 2: Application layer 2.1 Principles of network applications 2.2 DNS 2.3 Web and HTTP 2.4 Socket programming with TCP 2.5 Socket programming with UDP Application 2-22 DNS: Domain Name System people: many identifiers: SSN, name, passport # Internet hosts, routers: IP address (32 bit) - used for addressing datagrams “name”, e.g., www.yahoo.com - used by humans Q: map between IP address and name, and viceversa? Domain Name System: distributed database implemented in hierarchy of many name servers application-layer protocol host, routers, name servers to communicate to resolve names (address/name translation) note: core Internet function, implemented as applicationlayer protocol Application 2-23 http://www.dte.us.es/index.html HTTP client DNS server DNS client DNS adds an additional delay HTTP server Internet Application 2-24 DNS DNS services hostname to IP address translation (direct) IP address to hostname translation (inverse) host aliasing Canonical, alias names mail server aliasing Which transport service does it use? load distribution Not reliable replicated Web servers: set of IP UDP, port 53 addresses for one canonical Why not centralize DNS? single point of failure traffic volume distant centralized database maintenance … doesn’t scale! @domain name Application 2-25 DNS: caching and updating records once (any) name server learns mapping, it caches mapping cache entries timeout (disappear) after some time TLD servers typically cached in local name servers • Thus root name servers not often visited update/notify mechanisms among DNS servers proposed IETF standard RFC 2136 Application 2-26 DNS: how does it work? (simplified!) If an application have a hostname and not the associated IP address it requests the resolution to the DNS service in the same host (reverse resolution is also available). El DNS service check if there’s an entry in the DNS cache for the hostname or IP address and then… … if there’s an entry in the cache: It returns the requested resolution to the application. … if there’s no entry in the cache: The DNS service sends a DNS REQUEST (DNS_PDU) to the DNS Server IP address configured on the host (at least one is usually configured) and wait for the DNS REPLY (another type of DNS_PDU) from the DNS Server it was requested. The reply is then added to the cache to accelerate future requests and it’s also returned to the application. If it’s not possible to resolve the hostname or IP address, it notifies the application. Note When a DNS Server receives a DNS REQUEST, its behaviour is the same as a host, it first tries its own cache and if it’s not available it generates a Request to another DNS Server in a higher hierarchy, and the Reply is then forwarded back to the client. Application 2-27 Chapter 2: Application layer 2.1 Principles of network applications 2.2 DNS 2.3 Web and HTTP 2.4 Socket programming with TCP 2.5 Socket programming with UDP Application 2-28 Web and HTTP First, a review… web page consists of objects object can be HTML file, JPEG image, Java applet, audio file,… web page consists of base HTML-file which includes several referenced objects each object is addressable by a URL (Uniform Resource Locator) example URL: www.informatica.us.es/DTE/pic.gif host name path name Application 2-29 HTML language format It allows formatting web pages; created in 1991. It includes elements with TAGS in <>. Each element usually have 4 fields: a starting tag (like “<html>”) & an ending tag (like “</html>”), some attributes (in starting tag) and some contents (between the tags). <!DOCTYPE html…> remarks document start (optional) <html>document</html> start/finish of document <head>headers</head> header content (not visible to the end user, like title, styles, metainformation, etc…) <body>webpage</body> it contains the body of the webpage, with: from <h1> to <h6> headings <table>table</table>creates a table with fils/cols <a href=“URL”>link</a> hiperlink: when the user clicks on the link, the URL object is requested. <img src=“URL”> object reference, navigator requests the URL object inmediately to be shown. Aside You can view the HTML code in any webpage with your favourite navigator, right-click -> view source code. Application 2-30 HTTP overview HTTP: hypertext transfer protocol Web’s application layer protocol client/server model client: browser that requests, receives, “displays” Web objects server: Web server sends objects in response to requests PC running IExplorer Server running Apache Web server Linux running Firefox Application 2-31 HTTP overview (continued) Uses TCP: client initiates TCP connection (creates socket) to server, port 80 in server server accepts TCP connection from client HTTP messages (A_PDU’s: Application-layer protocol messages) exchanged between browser (HTTP client) and Web server (HTTP server) TCP connection closed HTTP is “stateless” server maintains no information about past client requests note protocols that maintain “state” are complex! past history (state) must be maintained if server/client crashes, their views of “state” may be inconsistent, must be synchronized Application 2-32 HTTP connections non-persistent HTTP one object sent over TCP connection. persistent HTTP multiple objects can be sent over single TCP connection between client, server. Application 2-33 Non-persistent HTTP suppose user enters URL: (contains text & references to 13 objects) http://www.dte.us.es/personal/smartin/lab3/referencias.html 1a. HTTP client initiates TCP connection to HTTP server (process) at www.dte.us.es on port 80 1b. HTTP server at host www.dte.us.es waiting for TCP connection at port 80. “accepts” connection, notifying client 2. HTTP client sends HTTP request message (containing URL) into TCP connection socket. Message indicates that client wants object with pathname /personal/smartin/lab3/r eferencias.html 3. HTTP server receives request message, forms response message containing requested object, and sends message into its socket time Application 2-34 Nonpersistent HTTP (cont.) 4. HTTP server closes TCP connection. 5. HTTP client receives response time message containing html file, displays html. Parsing html file, finds 13 referenced objects (images, scripts, …) 6. Steps 1-5 repeated for each of 13 objects with different unique URLs Application 2-35 Non-Persistent HTTP: Response time RTT (Round-Trip Time): time for a PDU with a few bytes to travel from client to server and back. Response time: one RTT to initiate TCP connection one RTT for HTTP request and first few bytes of HTTP response to return file transmission time total = 2RTT+transmit time initiate TCP connection RTT request file RTT file received time time to transmit file time Application 2-36 Persistent HTTP non-persistent HTTP issues: requires 2 RTTs per object OS overhead for each TCP connection Note that: Parallel HTTP connections: browsers often open parallel TCP connections to fetch referenced objects faster. They are requested sequentally per each connection (persistent or not). persistent HTTP server leaves connection open after sending response subsequent HTTP messages between same client/server sent over open connection client sends requests as soon as it finds a referenced object Each referenced object takes only 1 RTT Application 2-37 Mensajes HTTP (HTTP_PDU) 2 types of messages: HTTP Request: Sent by the client Takes neccessary information Transporta información (HTTP_PCI) to get an object from the server (HTTP_UD) ASCII chracters (intelligible text) HTTP Response: Sent by the server Takes the object (HTTP_UD) requested by the client and some control information (HTTP_PCI) Aplicación 2-38 HTTP request message Note: <CR>: Carriage-Return : \r <LF>: Line-Feed: \n request line (GET, POST, HEAD commands) header lines \r & \n at start of line indicates end of header lines UD GET /index.html HTTP/1.1\r\n Host: www-net.cs.umass.edu\r\n User-Agent: Firefox/3.6.10\r\n Accept: text/html,application/xhtml+xml\r\n Accept-Language: en-us,en;q=0.5\r\n Accept-Encoding: gzip,deflate\r\n Accept-Charset: ISO-8859-1,utf-8;q=0.7\r\n Keep-Alive: 115\r\n Connection: keep-alive\r\n \r\n Application 2-39 Some HTTP headers CLIENT can send Host: hostname (name of the web site) User-Agent: web_navigator_version Accept-xxx: preferences_list_for_xxx_feature Connection: keep-alive Client if asking the server to stablish persistant connection Keep-Alive: nnn Client if asking the server to keep the persistant connection alive for nnn seconds. Aplicación 2-40 HTTP request message: general format request line header lines PCI PDU body UD Application 2-41 Uploading form input Web page often includes form input (with some parameters that are sended to server). There are two methods to send: POST method: input is uploaded to server in entity body GET method: Inputs are uploaded in URL field of request line (separated by “?” and “&”): GET /animalsearch?monkeys&banana HTTP/1.1\r\n Host: www.somesearchengine.com\r\n … Application 2-42 Method types HTTP/1.0 (RFC-1945) GET POST HEAD Identical to GET but object is not included in response (only corresponding headers) HTTP/1.1 (RFC-2616) GET, POST, HEAD PUT uploads file in entity body to path specified in URL field DELETE deletes file specified in the URL field Application 2-43 HTTP response message status line (protocol status code status phrase) header lines data, e.g., requested HTML file HTTP/1.1 200 OK\r\n Date: Sun, 26 Sep 2010 20:09:20 GMT\r\n Server: Apache/2.0.52 (CentOS)\r\n Last-Modified: Tue, 30 Oct 2007 17:00:02 GMT\r\n ETag: "17dc6-a5c-bf716880"\r\n Accept-Ranges: bytes\r\n Content-Length: 2652\r\n Keep-Alive: timeout=10, max=100\r\n Connection: Keep-Alive\r\n Content-Type: text/html; charset=ISO-88591\r\n \r\n data data data data data ... Application 2-44 Some HTTP headers the SERVER can send Date: date Last-Modified: (last modification of the requested object) Server: web_server_version Content-Type: object_type (HTML, image, text …) Content-Length: body_length (in bytes) Connection: keep-alive Server announces the connection will be persistant. Keep-Alive: timeout=ttt, max=nnn Server will close the connection after ttt seconds of inactivity or otherwise after nnn seconds. Application 2-45 HTTP response status codes status code appears in 1st line in serverclient response message. some sample codes: 200 OK request succeeded, requested object later in this msg 301 Moved Permanently requested object moved, new location specified later in this msg (Location:) 400 Bad Request request msg not understood by server 404 Not Found requested document not found on this server 505 HTTP Version Not Supported Application 2-46 Trying out HTTP (client side) for yourself 1. Telnet to your favourite Web server: telnet www.dte.us.es 80 opens TCP connection to port 80 (default HTTP server port) at www.dte.us.es anything typed in sent to port 80 at www.dte.us.es 2. type in a GET HTTP request: GET /docencia/ HTTP/1.1 Host: www.dte.us.es by typing this, you send this minimal (but complete) GET request to HTTP server 3. look at response message sent by HTTP server! (or use Wireshark!) Q: What happens if you send “hello”? Application 2-47 User-server state: cookies many Web sites use cookies four components: 1) cookie header line of HTTP response message 2) cookie header line in HTTP request message 3) cookie file kept on user’s host, managed by user’s browser 4) back-end database at Web site example: Susan always accesses Internet from her PC visits specific e-commerce site for first time (e.g. Amazon) when initial HTTP requests arrives at site, site creates: unique ID entry in back-end database for ID Application 2-48 Cookies: Example Client visits AMAZON ebay 8734 cookie file AMAZON server usual http request msg usual http response Set-cookie:1678 ebay 8734 amazon 1678 usual http request msg cookie:1678 one week later: usual http response msg Amazon server creates ID 1678 for user create entry cookiespecific action access access ebay 8734 amazon 1678 usual http request msg cookie:1678 usual http response msg backend database cookiespecific action Application 2-49 Cookies (continued) Note what cookies can bring: authorization shopping carts recommendations user session state (Web email) cookies and privacy: cookies allow sites to learn a lot about you you may supply personal information to sites (name, e-mail,…) Application 2-50 Web caches (proxy server) Goal: satisfy client request without involving origin server user sets browser: Web accesses via cache-proxy browser sends all HTTP requests to cache-proxy object in cache: cache returns object Else, cache requests object from origin server, then returns object to client origin server client Proxy server client origin server Application 2-51 More about Web caching - Proxy cache acts as both client (of the original server) and server (of the user client) typically cache is installed by ISP (university, company, residential ISP) why Web caching? reduce response time for client request reduce traffic on an institution’s access link. enables “poor” content providers to effectively deliver content (but so does P2P file sharing) Application 2-52 Conditional GET Goal: don’t send object if cache-proxy cache has up-to-date cached version HTTP request msg If-modified-since: <date> Cache-proxy: specify date of cached copy in HTTP request HTTP response If-modified-since: <date> server: response contains no object if cached copy is up-to-date: Last-modified:<date> object modified before <date> HTTP/1.0 304 Not Modified HTTP request msg If-modified-since: <date> HTTP/1.0 304 Not Modified Or modified object is sended with the lastmodified date: server HTTP response HTTP/1.0 200 OK Last-modified: <date> object modified after <date> <data> Application 2-53 Chapter 2: Application layer 2.1 Principles of network applications 2.2 DNS 2.3 Web and HTTP 2.4 Socket programming with TCP 2.5 Socket programming with UDP Application 2-54 Socket programming Goal: learn how to build client/server application that communicate using sockets Socket 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 streamoriented socket A local-host, application-created, OS-controlled interface (a “door”) where application processes can both send and receive messages to/from another application processes Application 2-55 Application protocol Server Client User interface User interface Application Application Server IP address, port Client IP address, port Transport Transport Internet Application 2-56 Socket-programming using TCP Socket: a door between application process and end-endtransport protocol (UCP or TCP) TCP service: reliable transfer of bytes from one process to another controlled by application developer controlled by operating system process process socket TCP with buffers, variables socket TCP with buffers, variables client or server internet controlled by application developer controlled by operating system client or server Application 2-57 Socket programming with TCP Client must contact server server process must first be running server must open a socket (door) that welcomes client’s contact Client contacts server by: creating client TCP socket specifying IP address, port number of server process when client creates socket: client TCP establishes connection to server TCP when contacted by client, server TCP creates new socket for server process to communicate with client allows server to talk with multiple clients source port numbers used to distinguish clients (more in Chap 3) application viewpoint TCP provides reliable, in-order transfer of bytes (“pipe”) between client and server Application 2-58 Client/server socket interaction: TCP Server (running on hostid) Wait for primitive: Connection.indication Send primitive: Connection.response Client create socket, port=x, for incoming request: welcomeSocket = ServerSocket() TCP connection setup wait for incoming connection request connectionSocket = welcomeSocket.accept() read request from connectionSocket write reply to connectionSocket close connectionSocket hostid = IP or hostname create socket, connect to hostid, port=x clientSocket = Socket() send request using clientSocket Send primitive: Connection.request Wait for primitive: Connection.confirm read reply from clientSocket close clientSocket Application 2-59 Java Stream Client Process inFromUser inFromUser input input stream stream monitor monitor process output output stream stream inFromServer inFromServer stream is a sequence of characters that flow into or out of a process. input stream is attached to some input source for the process, e.g., keyboard or socket. output stream is attached to an output source, e.g., monitor or socket. Ex.: we are going to use 3 streams and 1 socket in the client outToServer outToServer keyboard keyboard client TCP clientSocket socket to network To transport layer input input stream stream TCP socket from network From transport layer Application 2-60 Socket programming with TCP Example client-server app: 1) client reads line from standard input (inFromUser stream) , sends to server via socket (outToServer stream) 2) server reads line from socket 3) server converts line to uppercase, sends back to client 4) client reads, prints modified line from socket (inFromServer stream) Application 2-61 Example: Java client (TCP) import java.io.*; import java.net.*; class TCPClient { create input stream create clientSocket object of type Socket, connect to server create output stream attached to socket This package defines Socket() and ServerSocket() classes public static void main(String argv[]) throws Exception { server name, String sentence; e.g., www.dte.us.es String modifiedSentence; T_ICI BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); Socket clientSocket = new Socket("hostname", 6789); T_ICI DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream()); server port # Application 2-62 Example: Java client (TCP), cont. BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); create input stream attached to socket Send primitive: Data.request sentence = inFromUser.readLine(); send line to server PDU outToServer.writeBytes(sentence + '\n'); read line from server Wait for primitive: Data.indication modifiedSentence = inFromServer.readLine(); System.out.println("FROM SERVER: " + modifiedSentence); close socket clientSocket.close(); (clean up behind yourself!) } } Application 2-63 Example: Java server (TCP) import java.io.*; import java.net.*; class TCPServer { create welcoming socket at port 6789 wait, on welcoming socket accept() method for client contact create, new socket on return create input stream, attached to socket public static void main(String argv[]) throws Exception { String clientSentence; String capitalizedSentence; ServerSocket welcomeSocket = new ServerSocket(6789); while(true) { Socket connectionSocket = welcomeSocket.accept(); BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream())); Application 2-64 Example: Java server (TCP), cont create output stream, attached to socket DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream()); PDU Wait for primitive: clientSentence = inFromClient.readLine(); Data.indication read in line from socket capitalizedSentence = clientSentence.toUpperCase() + '\n'; write out line to socket outToClient.writeBytes(capitalizedSentence); } } } Send primitive: Data.request PDU end of while loop, loop back and wait for another client connection Application 2-65 Chapter 2: Application layer 2.1 Principles of network applications 2.2 DNS 2.3 Web and HTTP 2.4 Socket programming with TCP 2.5 Socket programming with UDP Application 2-66 Socket programming with UDP UDP: no “connection” between client and server no handshaking sender explicitly attaches IP address and port of destination to each message (PDU) that wants to send server must extract IP address, port of sender from received message application viewpoint: UDP provides unreliable transfer of groups of bytes (“datagrams”) between client and server UDP: transmitted data may be received out of order, or some may be lost Application 2-67 Client/server socket interaction: UDP Server (running on hostid) create socket, port= x. serverSocket = DatagramSocket() read datagram from serverSocket write reply to serverSocket specifying client address, port number hostid = IP or hostname Client create socket, clientSocket = DatagramSocket() Wait primitive: Data.indication Create datagram with server IP and port=x; send datagram via clientSocket Send primitive: Data.request read datagram from clientSocket close clientSocket Application 2-68 Example: client (UDP datagrams) input input stream stream Client Process monitor monitor inFromUser inFromUser keyboard keyboard process Input: receives packet receivePacket inFromServer UDP output stream packet outToServer (recall that TCP sent “byte stream”) sendPacket Output: sends packet client UDP clientSocket socket to network To transport layer (recall that TCP received “byte stream”) UDP input stream packet TCP UDP socket from network From transport layer socket Application 2-69 Example: Java client (UDP) import java.io.*; import java.net.*; class UDPClient { public static void main(String args[]) throws Exception { create input stream create client socket translate hostname to IP address using DNS BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); DatagramSocket clientSocket = new DatagramSocket(); InetAddress IPAddress = InetAddress.getByName("hostname"); byte[] sendData = new byte[1024]; byte[] receiveData = new byte[1024]; String sentence = inFromUser.readLine(); sendData = sentence.getBytes(); Application 2-70 Example: Java client (UDP) (cont.) T_ICI create T_IDU with A_PDU, length, IP addr, port A_PDU DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876); clientSocket.send(sendPacket); Send primitive: T_IDU Data.request DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); send T_IDU create new T_IDU clientSocket.receive(receivePacket); receive T_IDU Wait for primitive: Data.indication String modifiedSentence = new String(receivePacket.getData()); System.out.println("FROM SERVER:" + modifiedSentence); clientSocket.close(); } } Application 2-71 Example: Java server (UDP) import java.io.*; import java.net.*; Create UDP socket at port 9876 (known by client) class UDPServer { public static void main(String args[]) throws Exception { DatagramSocket serverSocket = new DatagramSocket(9876); byte[] receiveData = new byte[1024]; byte[] sendData = new byte[1024]; while(true) { create new T_IDU receive T_IDU Wait for primitive: Data.indication DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); serverSocket.receive(receivePacket); Application 2-72 Example: Java server (UDP) (cont.) String sentence = new String(receivePacket.getData()); get sender IP addr and port # from T_ICI InetAddress IPAddress = receivePacket.getAddress(); int port = receivePacket.getPort(); String capitalizedSentence = sentence.toUpperCase(); create T_IDU with A_PDU to send, length, IP addr and port # sendData = capitalizedSentence.getBytes(); DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, port); serverSocket.send(sendPacket); Send T_IDU } } } end of while loop, loop back and wait for another datagram Application 2-73 Departamento de Tecnología Electrónica Computer Networking – Chapter 2: Application layer PROBLEMS AND EXERCISES Application 2-74 Pr1: True or false? a) With non-persistent connections between browser and origin server, it is possible for a single TCP segment to carry two different HTTP request messages. b) A user requests a Web page that consists of some text and two images. For this page, the client sends one request message and receives three response messages. c) These two different Web pages www.mit.edu/index.html and www.dte.us.es/index.html can be sent over the same persistent connection. d) The “Date:” header in the HTTP response message indicates when the object in the response was last modified. e) HTTP response messages never have an empty message body. Application 2-75 Pr2: Application-Transport Consider an HTTP client that wants to retrieve a Web document from a given URL. HTTP server’s IP address is initially unknown. What transport and application-layer protocols besides HTTP are needed in this scenario? Application 2-76 Pr3: HTTP client headers Consider the following string of ASCll characters that were captured by Wireshark when the browser sent an HTTP GET message (i .e., this is the actual content of an HTTPGET message). The characters <cr><l/> are carriage return and line-feed characters (that is, the character string <cr> in the text below represents the single carriage-return character that was contained at that point in the HTTP header). Answer the following questions, indicating where in the HTTP GET message below you found the answer. GET /cs453/index.html HTTP/l.l<cr><lf>Host: gaia.cs.umass.edu<cr><lf>User-Agent: Mozilla/5.0 (WindowsiUi Windows NT 5.1i en-USi rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) <cr><lf>Accept:ext/xml, application/xml, application/xhtml+xml, text/htmliq=0.9, text/plain iq=0.8,image/png,*/*;q=0.5<cr><lf>Accept-Language: enus,enjq=0.5<cr><lf>AcceptEncoding:zip,deflate<cr><lf>AcceptCharset: ISO-8859-1,utf-8;q=0.7,*jq=0.7<cr><lf>Keep-Alive: 300<cr><If>Connection:keep-alive<cr><lf><cr><lf> a) What is the URL of the document requested by the browser? b) What version of HTTP is the browser running? c) Does the browser request a non-persistent or a persistent connection? d) What is the IP address of the host on which the browser is running? e) What type of browser initiates this message? Why is the browser type needed in an HTTP request message? Application 2-77 Pr4: HTTP server headers The text below shows the reply sent from the server in response to the HTTP GET message in the question above. Answer the following questions, pointing out where in the message below you found the answer. HTTP/1.1 200 OK<cr><lf>Date: Tue, 07 Mar 2008 12:39:45GMT<cr><lf>Server: Apache/2.0.52 (Fedora) <cr><lf>LastModified: Sat, 10 Dec2005 18:27:46 GMT<cr><lf>ETag: "526c3-f22a88a4c80"<cr><lf>AcceptRanges: bytes<cr><lf>Content-Length: 3874<cr><lf> Keep-Alive: timeout=max=100<cr><lf>Connection: KeepAlive<cr><lf>Content-Type: text/html; charset= ISO-88591<cr><lf><cr><lf><!doctype html public "// w3c//dtd html 4.0 transitional//en"><lf><html><lf> <head><lf> <meta httpequiv="Content-Type“ content="text/htmlj charset=iso-8859-1"><lf> <meta name="GENERATOR" content="Mozilla/4.79 [en] (Windows NT 5.0j U) Netscape]"><lf> <title>CMPSCI 453 / 591 / NTU-ST550A Spring 2005 homepage</title><lf></head><lf> <much more document text following here (not shown) a) Was the server able to successfully find the document or not? What time was the document reply provided? b) When was the document last modified? c) How many bytes are there in the returned document? d) What are the first 5 bytes of the returned document? e) Did the server agree to a persistent connection? Application 2-78 Pr5: RTT with DNS (I) Suppose you click on a link within your Web browser to obtain a Web page. The IP address for the associated URL is not cached in your local host, so a DNS request is necessary to obtain the IP address. Suppose that RTT for a DNS request is RTTDNS. Besides, suppose that the Web page associated with the link contains exactly one object, consisting of a small amount of HTML text (assume object transmission time = 0). Let RTT0 be the RTT between the local host and the Web server. How long does it take since the client clicks on the link until the client receives the object? Application 2-79 Pr6: RTT with DNS (II) Referring to Problem Pr5, suppose the HTML file references eight very small objects on the same server. Despite of transmission times, how long does it take to get the web page using: a)Non-persistent HTTP with no parallel TCP connections? b)Non-persistent HTTP with the browser configured for 5 parallel connections? c)Persistent HTTP? Application 2-80 Pr7: Proxy (I) This figure shows two networks (institutional and public). The institutional network is a high speed LAN. A router in the institutional network and a router in the Internet are connected by 1.5 Mbps. The origin servers are attached to the Internet but are located all over the globe. Suppose that: The average object size = 100 Kbits The average request rate from institution’s browsers to origin servers = 15 requests/sec HTTP request message are negligibly small Delay from institutional router to any origin server and back to router = 2 sec We can calculate the following: a) utilization on LAN = 15% b) utilization on access link = 100% c) As access link uses is 100%, aL/R ~ 1, queues can grow indefinitely and with them the associated delay. Total delay: increses indefinitely. origin servers public Internet 1.5 Mbps access link 10 Mbps LAN Institutional network Application 2-81 Pr7: Proxy (II) One possible solution: increase bandwidth of access link to, say, 10 Mbps consequences a) utilization on LAN ? b) utilization on access link ? c) average total delay ? d) Comments ? public Internet 10 Mbps access link 10 Mbps LAN Institutional network Application 2-82 Pr7: Proxy (III) Origin servers Another possible solution: Install proxy-cache server Success rate of 0.4: 40% requests replied by the proxy inmediately 60% requests forwared to the origin web servers Consequences: utilization on LAN ? utilization on access link ? average total delay ? Comments ? Public Internet 1.5 Mbps Access link Institutional network 10 Mbps LAN Institutional proxy Aplicación 2-83