Presentation is loading. Please wait.

Presentation is loading. Please wait.

2: Application Layer1 Chapter 2 Application Layer Computer Networking: A Top Down Approach Featuring the Internet, 3 rd edition. Jim Kurose, Keith Ross.

Similar presentations


Presentation on theme: "2: Application Layer1 Chapter 2 Application Layer Computer Networking: A Top Down Approach Featuring the Internet, 3 rd edition. Jim Kurose, Keith Ross."— Presentation transcript:

1 2: Application Layer1 Chapter 2 Application Layer Computer Networking: A Top Down Approach Featuring the Internet, 3 rd edition. Jim Kurose, Keith Ross Addison-Wesley, July 2004. A note on the use of these ppt slides: We’re making these slides freely available to all (faculty, students, readers). They’re in PowerPoint form so you can add, modify, and delete slides (including this one) and slide content to suit your needs. They obviously represent a lot of work on our part. In return for use, we only ask the following:  If you use these slides (e.g., in a class) in substantially unaltered form, that you mention their source (after all, we’d like people to use our book!)  If you post any slides in substantially unaltered form on a www site, that you note that they are adapted from (or perhaps identical to) our slides, and note our copyright of this material. Thanks and enjoy! JFK/KWR All material copyright 1996-2005 J.F Kurose and K.W. Ross, All Rights Reserved

2 2: Application Layer2 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP, POP3, IMAP r 2.5 DNS r 2.6 P2P file sharing r 2.7 Socket programming with TCP r 2.8 Socket programming with UDP r 2.9 Building a Web server

3 2: Application Layer3 Chapter 2: Application Layer Our goals: r conceptual, implementation aspects of network application protocols  transport-layer service models  client-server paradigm  peer-to-peer paradigm r learn about protocols by examining popular application-level protocols  HTTP  FTP  SMTP / POP3 / IMAP  DNS r programming network applications  socket API

4 2: Application Layer4 Some network apps r E-mail r Web r Instant messaging r Remote login r P2P file sharing r Multi-user network games r Streaming stored video clips r Internet telephone r Real-time video conference r Massive parallel computing

5 2: Application Layer5 Creating a network app Write programs that  run on different end systems and  communicate over a network.  e.g., Web: Web server software communicates with browser software little software written for devices in network core  network core devices do not run user application code  application on end systems allows for rapid app development, propagation application transport network data link physical application transport network data link physical application transport network data link physical

6 2: Application Layer6 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP, POP3, IMAP r 2.5 DNS r 2.6 P2P file sharing r 2.7 Socket programming with TCP r 2.8 Socket programming with UDP r 2.9 Building a Web server

7 2: Application Layer7 Application layer functions r Applications  Implement desired functionality within application protocols when no underlying network service provides support Mail, Web, News, P2P, etc….  Other functions Security (S/MIME, PGP, S-HTTP) Delivery semantics (multicast overlays, anycast) Reliable data transfer (reliable multicast, reliable UDP) Quality of service (QoS overlays, scheduling) Congestion control (Non-TCP applications) Flow control (Non-TCP applications) Naming (DNS, URLs) Routing (overlays) r Functionality that is common rolled into libraries and “middleware”

8 2: Application Layer8 Application architectures r Client-server r Peer-to-peer (P2P) r Hybrid of client-server and P2P

9 2: Application Layer9 Client-server architecture server:  always-on host  permanent IP address  server farms for scaling clients:  communicate with server  may be intermittently connected  may have dynamic IP addresses  do not communicate directly with each other

10 2: Application Layer10 Pure P2P architecture r every participant is both a client and a server to other clients  arbitrary end systems directly communicate  Resource costs shared r peers are intermittently connected, change IP addresses r example: Gnutella Highly scalable But difficult to manage

11 2: Application Layer11 Hybrid of client-server and P2P Napster  File transfer P2P  File search centralized: Peers register content at central server Peers query same central server to locate content Instant messaging  Chatting between two users is P2P  Presence detection/location centralized: User registers its IP address with central server when it comes online User contacts central server to find IP addresses of buddies

12 2: Application Layer12 Processes communicating Process: program running within a host. r within same host, two processes communicate using inter-process communication (defined by OS). r processes in different hosts communicate by exchanging messages Client process: process that initiates communication Server process: process that waits to be contacted r Note: applications with P2P architectures have client processes & server processes

13 2: Application Layer13 Sockets r process sends/receives messages to/from its socket r socket analogous to door  sending process shoves message out door  sending process relies on transport infrastructure on other side of door which brings message to socket at receiving process process TCP with buffers, variables socket host or server process TCP with buffers, variables socket host or server Internet controlled by OS controlled by app developer r API: (1) choice of transport protocol; (2) ability to fix a few parameters (lots more on this later)

14 2: Application Layer14 Addressing processes r For a process to receive messages, it must have an identifier r A host has a unique32- bit IP address r Q: does the IP address of the host on which the process runs suffice for identifying the process? r Answer: No, many processes can be running on same host r Identifier includes both the IP address and port numbers associated with the process on the host. r Example port numbers:  HTTP server: 80  Mail server: 25 r More on this later

15 2: Application Layer15 App-layer protocol defines r Types of messages exchanged, e.g., request & response messages r Syntax of message types: what fields in messages & how fields are delineated r Semantics of the fields, i.e., meaning of information in fields r Rules for when and how processes send & respond to messages Public-domain protocols: r defined in RFCs r allows for interoperability r e.g., HTTP, SMTP Proprietary protocols: r e.g., KaZaA

16 2: Application Layer16 What transport service does an app need? Data loss r some apps (e.g., audio) can tolerate some loss r other apps (e.g., file transfer, telnet) require 100% reliable data transfer Timing r some apps (e.g., Internet telephony, interactive games) require low delay to be “effective” Bandwidth r some apps (e.g., multimedia) require minimum amount of bandwidth to be “effective” r other apps (“elastic apps”) make use of whatever bandwidth they get

17 2: Application Layer17 Transport service requirements of common apps Application file transfer e-mail Web documents real-time audio/video stored audio/video interactive games instant messaging Data loss no loss loss-tolerant no loss Bandwidth elastic audio: 5kbps-1Mbps video:10kbps-5Mbps same as above few kbps up elastic Time Sensitive no yes, 100’s msec yes, few secs yes, 100’s msec yes and no

18 2: Application Layer18 Internet transport protocols services TCP service: r connection-oriented: setup required between client and server processes r reliable transport between sending and receiving process r flow control: sender won’t overwhelm receiver r congestion control: throttle sender when network overloaded r does not provide: timing, minimum bandwidth guarantees UDP service: r unreliable data transfer between sending and receiving process r does not provide: connection setup, reliability, flow control, congestion control, timing, or bandwidth guarantee Q: why bother? Why is there a UDP?

19 2: Application Layer19 Internet apps: application, transport protocols Application e-mail remote terminal access Web file transfer streaming multimedia Internet telephony Application layer protocol SMTP [RFC 2821] Telnet [RFC 854] HTTP [RFC 2616] FTP [RFC 959] proprietary (e.g. RealNetworks) proprietary (e.g., Vonage,Dialpad) Underlying transport protocol TCP TCP or UDP typically UDP

20 2: Application Layer20 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP, POP3, IMAP r 2.5 DNS r 2.6 P2P file sharing r 2.7 Socket programming with TCP r 2.8 Socket programming with UDP r 2.9 Building a Web server

21 2: Application Layer21 Programming application protocols Goal: learn how to build client/server application that communicate using sockets without understanding underlying functions of TCP/IP  Many possible programming interfaces Socket APIs (most common) –BSD C Socket API (most common) –Java socket API –Python socket API Other APIs –Client-side Java URLconnections –Server-side Java servlets –Python urllib –Python HTTPServer –RPC, CORBA, Java RMI (not covered)

22 2: Application Layer22 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm r two types of transport service via socket API:  unreliable datagram  reliable, byte stream- oriented a host-local, application-created, OS-controlled interface (a “door”) into which application process can both send and receive messages to/from another application process socket

23 2: Application Layer23 Socket-programming using TCP Socket: a door between application process and end- end-transport protocol (UCP or TCP) TCP service: reliable transfer of bytes from one process to another process TCP with buffers, variables socket controlled by application developer controlled by operating system host or server process TCP with buffers, variables socket controlled by application developer controlled by operating system host or server internet

24 2: Application Layer24 Socket programming with TCP Client must contact server r server process must first be running r server must have created socket (door) that welcomes client’s contact Client contacts server by: r creating client-local TCP socket r specifying IP address, port number of server process r When client creates socket: client TCP establishes connection to server TCP r 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) TCP provides reliable, in-order transfer of bytes (“pipe”) between client and server application viewpoint

25 2: Application Layer25 Sockets in action *,SIP:80 CIP:1099,SIP:80 *,SIP:80 CIP:1099,SIP:80 CIP:1100,SIP:80 *,SIP:80 CIP:1099,SIP:80 CIP:1100,SIP:80

26 2: Application Layer26 BSD sockets in C/Unix r Socket API (socket.h) socket(): create unnamed socket (data structure) –UDP (SOCK_DGRAM), TCP (SOCK_STREAM) –IP (SOCK_RAW) bind(): name socket (bind local address to socket) listen(): enable socket to accept connections accept(): get connect() request from listen queue, allocate file descriptor for new socket connect(): initiate connection on a socket (TCP handshake) send(), sendto(), sendmsg(), writev(), write(): send data recv(), recvfrom(), recvmsg(), readv(), read(): receive data setsockopt(), getsockopt(): set socket options (such as buffer sizes, flag fields) close(), shutdown(): teardown connection

27 2: Application Layer27 BSD sockets in action server client bind() socket() recvfrom() sendto() bind() recvfrom() UDP example TCP example sendto() connect() socket() bind() server client listen() accept() write() read() write() read()

28 2: Application Layer28 BSD example r http://www.thefengs.com/wuchang/work/cou rses/cs594/socket_example http://www.thefengs.com/wuchang/work/cou rses/cs594/socket_example r TCP socket code  Client tcpcli.c  Server tcpserv.c r UDP socket code  Client udpcli.c  Server udpserv.c

29 2: Application Layer29 Java network programming Java network applications java.net package System-dependent implementations

30 2: Application Layer30 Java installation on linuxlab r J2SE  javac java compiler  java java interpreter http://www.ibiblio.org/javafaq/javatut orial.html http://www.ibiblio.org/javafaq/javatut orial.html

31 2: Application Layer31 java.net classes r Low-level networking classes (Sockets and Packets) r High-level URL networking classes r http://java.sun.com/j2se/1.5.0/docs/api/ http://java.sun.com/j2se/1.5.0/docs/api/ r java.lang.Object  java.net.Socket  java.net.ServerSocket  java.net.DatagramSocket  java.net.DatagramPacket  java.net.URL  java.net.URLConnection java.net.HttpURLConnection  java.net.URLencoder  java.net.InetAddress

32 2: Application Layer32 java.net.Socket r Constructors  Socket(InetAddress, int)  Socket(String, int)  Socket(InetAddress, int, InetAddress, int) r Some methods  getInputStream()  getOutputStream  getInetAddress()  getPort()  getLocalAddress()  getLocalPort()  get/set individual socket options

33 2: Application Layer33 java.net.ServerSocket r Constructors  ServerSocket(int)  ServerSocket(int, int) // backlog specified  ServerSocket(int, int, InetAddress) // local address and backlog specified r Some methods  accept()  getInetAddress()  getLocalPort()

34 2: Application Layer34 Stream jargon for Java network programming r A stream is a sequence of characters that flow into or out of a process. r An input stream is attached to some input source for the process, e.g., keyboard or socket. r An output stream is attached to an output source, e.g., monitor or socket.

35 2: Application Layer35 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) Client process client TCP socket

36 2: Application Layer36 Client/server socket interaction: TCP wait for incoming connection request connectionSocket = welcomeSocket.accept() create socket, port= x, for incoming request: welcomeSocket = ServerSocket() create socket, connect to hostid, port= x clientSocket = Socket() close connectionSocket read reply from clientSocket close clientSocket Server (running on hostid ) Client send request using clientSocket read request from connectionSocket write reply to connectionSocket TCP connection setup

37 2: Application Layer37 Example: Java client (TCP) import java.io.*; import java.net.*; class TCPClient { public static void main(String argv[]) throws Exception { String sentence; String modifiedSentence; BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); Socket clientSocket = new Socket("hostname", 6789); DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream()); Create input stream Create client socket, connect to server Create output stream attached to socket

38 2: Application Layer38 Example: Java client (TCP), cont. BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); sentence = inFromUser.readLine(); outToServer.writeBytes(sentence + '\n'); modifiedSentence = inFromServer.readLine(); System.out.println ("FROM SERVER: " + modifiedSentence ); clientSocket.close(); } Create input stream attached to socket Send line to server Read line from server

39 2: Application Layer39 Example: Java server (TCP) import java.io.*; import java.net.*; class TCPServer { 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())); Create welcoming socket at port 6789 Wait, on welcoming socket for contact by client Create input stream, attached to socket

40 2: Application Layer40 Example: Java server (TCP), cont DataOutputStream outToClient = new DataOutputStream (connectionSocket.getOutputStream()); clientSentence = inFromClient.readLine(); capitalizedSentence = clientSentence.toUpperCase() + '\n'; outToClient.writeBytes(capitalizedSentence); } Read in line from socket Create output stream, attached to socket Write out line to socket End of while loop, loop back and wait for another client connection

41 2: Application Layer41 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP, POP3, IMAP r 2.5 DNS r 2.6 P2P file sharing r 2.7 Socket programming with TCP r 2.8 Socket programming with UDP r 2.9 Building a Web server

42 2: Application Layer42 Socket programming with UDP UDP: no “connection” between client and server r no handshaking r sender explicitly attaches IP address and port of destination to each packet r server must extract IP address, port of sender from received packet UDP: transmitted data may be received out of order, or lost application viewpoint UDP provides unreliable transfer of groups of bytes (“datagrams”) between client and server

43 2: Application Layer43 java.net.DatagramSocket r Constructors  DatagramSocket()  DatagramSocket(int) // bind to specific port  DatagramSocket(int, InetAddress) // specify local address r Some methods  getLocalAddress()  getLocalPort()  receive(DatagramPacket)  send(DatagramPacket)  get/set individual socket options

44 2: Application Layer44 java.net.DatagramPacket r Constructors  DatagramPacket(byte[], int) // receiving packets  DatagramPacket(byte[], int, InetAddress, int) // sending packets r Some methods  getAddress() // remote address  getPort() // remote port  getLength() // get packet length  getData() // return data received or to be sent  setAddress(InetAddress) // set remote address  setData(byte[]) // set packet data  setLength(int) // set packet length  setPort(int) // set remote port

45 2: Application Layer45 Client/server socket interaction: UDP close clientSocket Server (running on hostid ) read reply from clientSocket create socket, clientSocket = DatagramSocket() Client Create, address ( hostid, port=x, send datagram request using clientSocket create socket, port= x, for incoming request: serverSocket = DatagramSocket() read request from serverSocket write reply to serverSocket specifying client host address, port number

46 2: Application Layer46 Example: Java client (UDP) Output: sends packet (recall that TCP sent “byte stream”) Input: receives packet (recall thatTCP received “byte stream”) Client process client UDP socket

47 2: Application Layer47 Example: Java client (UDP) import java.io.*; import java.net.*; class UDPClient { public static void main(String args[]) throws Exception { 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(); Create input stream Create client socket Translate hostname to IP address using DNS

48 2: Application Layer48 Example: Java client (UDP), cont. DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876); clientSocket.send(sendPacket); DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); clientSocket.receive(receivePacket); String modifiedSentence = new String(receivePacket.getData()); System.out.println("FROM SERVER:" + modifiedSentence); clientSocket.close(); } Create datagram with data-to-send, length, IP addr, port Send datagram to server Read datagram from server

49 2: Application Layer49 Example: Java server (UDP) import java.io.*; import java.net.*; 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) { DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); serverSocket.receive(receivePacket); Create datagram socket at port 9876 Create space for received datagram Receive datagram

50 2: Application Layer50 Example: Java server (UDP), cont String sentence = new String(receivePacket.getData()); InetAddress IPAddress = receivePacket.getAddress(); int port = receivePacket.getPort(); String capitalizedSentence = sentence.toUpperCase(); sendData = capitalizedSentence.getBytes(); DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, port); serverSocket.send(sendPacket); } Get IP addr port #, of sender Write out datagram to socket End of while loop, loop back and wait for another datagram Create datagram to send to client

51 2: Application Layer51 High-level Java networking classes r Socket/Packet  Low level building blocks  Must implement all application-level logic r Many protocols based on URLs and/or tunneled in HTTP  Program at a higher-level to hide underlying protocol details  Do not re-implement HTTP, URL parsing, MIME handling for each application

52 2: Application Layer52 High-level client-side Java networking classes r java.net.URL  Represent a URL object r java.net.URLConnection  Represent a connection to a URL which can be read and written from r java.net.HttpURLConnection  Subclass of URLConnection for http:// URLs r Example

53 2: Application Layer53 Java high-level client-side networking classes example r http://www.thefengs.com/wuchang/work/c ourses/cs594/java_example import java.net.*; import java.io.*; public class Test { public static void main(String argv[]) { try { URL u=new URL(http://www.google.com/);http://www.google.com/ URLConnection uc=u.openConnection(); Object o = (Object) uc.getContent(); } catch (Exception e) { }

54 2: Application Layer54 High-level server-side Java networking classes r Servlets  Dynamically generate content  Implement common protocol header logic Example http servlets –Cookies –Content-type –Content-length r Servlet classes  javax.servlet.Servlet javax.servlet.HttpServlet init() service() destroy()  javax.servlet.ServletRequest javax.servlet.ServletResponse  javax.servlet.HttpServletRequest javax.servlet.HttpServletResponse

55 2: Application Layer55 Python network programming Python network applications System-dependent implementations Python network packages (socket, URLlib, HTTPServer)

56 2: Application Layer56 Python network programming r Python  Scripting language  No compilation required  Language reference: http://www.python.orghttp://www.python.org  Provides APIs similar to Java socket –Low-level socket interface urllib –HTTP client SimpleHTTPServer –HTTP server

57 2: Application Layer57 Python sockets r Similar to C and Java  Client import socket host = “localhost” port = 7 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((host,port)) s.send(“some data to echo”) print s.recv(20) s.close

58 2: Application Layer58 Python sockets r Similar to C and Java  Server import socket host = “” port = 7 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((host,port)) s.listen(1) while (1): conn, addr = s.accept() data = conn.recv(20) conn.send(data) conn.close()

59 2: Application Layer59 Python urllib/urllib2 r Client-side HTTP code similar to Java’s java.net.URLConnection  Hides socket creation, HTTP request formatting, HTTP response parsing url = sys.argv[1] sock = urllib.urlopen(url) htmlSource = sock.read() sock.close() print htmlSource url = sys.argv[1] txdata = None txheaders = { ‘Accept-Language’: ‘en-us’ } req = urllib2.Request(url, txdata, txheaders) u = urlib2.urlopen(req) headers = u.info() print u.read() Python urllib Python urllib2

60 2: Application Layer60 Python BasicHTTPServer r Server-side HTTP processing libraries javax.servlet.HTTPServlet  Hides socket creation, HTTP request parsing, HTTP response formatting  SocketServer.TCPServer.BaseHTTPServer

61 2: Application Layer61 Python network programming URLs r http://docs.python.org/lib/internet.html r http://docs.python.org/lib/module-socket.html r http://docs.python.org/lib/module-urllib.html r http://docs.python.org/lib/module-urllib2.html r http://docs.python.org/lib/module- SimpleHTTPServer.html r http://docs.python.org/lib/module- BaseHTTPServer.html r http://www.w3journal.com/6/s3.vanrossum.html

62 2: Application Layer62 Chapter 2: Application layer r 2.1 Principles of network applications  app architectures  app requirements r 2.2 Web and HTTP r 2.4 Electronic Mail  SMTP, POP3, IMAP r 2.5 DNS r 2.6 P2P file sharing r 2.7 Socket programming with TCP r 2.8 Socket programming with UDP r 2.9 Building a Web server

63 2: Application Layer63 Web and HTTP First some jargon r Web page consists of objects r Object can be HTML file, JPEG image, Java applet, audio file,… r Each object is addressable by a URL r Web page consists of base HTML-file which includes several referenced objects r Example URL: www.someschool.edu/someDept/pic.gif host name path name

64 2: Application Layer64 HTTP overview r HTTP: hypertext transfer protocol r Web’s application layer protocol r client/server model  client: browser that requests, receives, “displays” Web objects  server: Web server sends objects in response to requests r HTTP 1.0: RFC 1945  http://www.rfc-editor.org/rfc/rfc1945.txt http://www.rfc-editor.org/rfc/rfc1945.txt r HTTP 1.1: RFC 2068  http://www.rfc-editor.org/rfc/rfc2068.txt http://www.rfc-editor.org/rfc/rfc2068.txt r HTTP state management (cookies): RFC 2109  http://www.rfc-editor.org/rfc/rfc2109.txt http://www.rfc-editor.org/rfc/rfc2109.txt PC running Explorer Server running Apache Web server Mac running Navigator HTTP request HTTP response

65 2: Application Layer65 HTTP overview (continued) Uses TCP: r client initiates bi-directional TCP connection (via socket) to server, port 80 r server accepts TCP connection from client r HTTP messages (application- layer protocol messages) exchanged between browser (HTTP client) and Web server (HTTP server)  Messages encoded in text r TCP connection closed HTTP is “stateless” r server maintains no information about past client requests Protocols that maintain “state” are complex! r past history (state) must be maintained r if server/client crashes, their views of “state” may be inconsistent, must be reconciled aside

66 2: Application Layer66 Non-persistent HTTP connections r HTTP/0.9 & HTTP/1.0 r One request/response per connection  simple to implement  server parses request, responds, and closes connection r Disadvantages  Short transfers hard on TCP Each connection stuck in slow start Loss recovery poor when windows small  Connection setup latency (three-way handshake) Several extra round trips added to transfer  Server and network overhead Connection handling, extra packets TIME_WAIT –Much larger than # active connections

67 2: Application Layer67 Nonpersistent HTTP Suppose user enters URL www.someSchool.edu/someDepartment/home.index 1a. HTTP client initiates TCP connection to HTTP server (process) at www.someSchool.edu on port 80 2. HTTP client sends HTTP request message (containing URL) into TCP connection socket. Message indicates that client wants object someDepartment/home.index 1b. HTTP server at host www.someSchool.edu waiting for TCP connection at port 80. “accepts” connection, notifying client 3. HTTP server receives request message, forms response message containing requested object, and sends message into its socket time (contains text, references to 10 jpeg images)

68 2: Application Layer68 Nonpersistent HTTP (cont.) 5. HTTP client receives response message containing html file, displays html. Parsing html file, finds 10 referenced jpeg objects 6. Steps 1-5 repeated for each of 10 jpeg objects 4. HTTP server closes TCP connection. time

69 2: Application Layer69 Response time modeling Definition of RTT: time to send a small packet to travel from client to server and back. Response time: r one RTT to initiate TCP connection r one RTT for HTTP request and first few bytes of HTTP response to return r file transmission time total = 2RTT+transmit time time to transmit file initiate TCP connection RTT request file RTT file received time

70 2: Application Layer70 Single non-persistent example Client Server SYN ACK DAT FIN ACK 0 RTT 1 RTT 2 RTT 3 RTT 4 RTT Server reads from disk FIN Server reads from disk Client opens TCP connection Client sends HTTP request for HTML Client parses HTML Client opens TCP connection Client sends HTTP request for image Image begins to arrive

71 2: Application Layer71 Parallel non-persistent connections (Netscape) r Improve non-persistent latency by using multiple concurrent connections  Different parts of Web page arrive independently on separate connections (object demux via connections)  Can grab more of the network bandwidth than other users r Doesn’t necessarily improve response time  TCP loss recovery ends up being timeout dominated because windows are small

72 2: Application Layer72 Persistent HTTP connections r Default in HTTP/1.1 r Several requests/responses on one TCP connection  On same TCP connection: server, parses request, responds, parses new request,.. r Benefits greatest for small objects  Up to 2x improvement in response time (avoid handshake) r Server resource utilization reduced due to fewer connection establishments and fewer active connections r TCP behavior improved  Longer connections help adaptation to available bandwidth  Larger congestion window improves loss recovery r HTTP/1.1 vs. HTTP/1.0 example  Multiple requests to www.cs.pdx.eduwww.cs.pdx.edu r Problem: serial delivery of objects (head-of-line object blocking)

73 2: Application Layer73 Persistent HTTP connection example Client Server ACK DAT ACK 0 RTT 1 RTT 2 RTT Server reads from disk Client sends HTTP request for HTML Client parses HTML Client sends HTTP request for image Image begins to arrive DAT Server reads from disk DAT

74 2: Application Layer74 Persistent HTTP connections r Pipelining requests  Examples Getall – request HTML document and all embeds –Requires server to parse HTML files –Embeds returned serially –Doesn’t consider client cached documents Getlist – request a set of documents –Implemented as a simple set of GETs  Problems with pipelined serialized requests Stall in one object prevents delivery of others Most useful information in first few bytes (layout info) –Multiple connections allow incremental rendering of images Need application-level demux to emulate multiple connections

75 2: Application Layer75 HTTP-NG? r HTTP-NG, HTTP/2.0, HTTP range requests  Support pipelining, but avoid HOL blocking via application-layer demux of objects  Demux within application stream Data “labeled” with object it is for  Application specific solution to transport protocol problems! r Better approach?  SCTP: Stream Control Transmission Protocol Support above across all applications

76 2: Application Layer76 Persistent HTTP Nonpersistent HTTP issues: r requires 2 RTTs per object r OS overhead to allocate resources for each TCP connection r browsers often open parallel TCP connections to fetch referenced objects r Solves demux issue on multiple objects Persistent HTTP r server leaves connection open after sending response r subsequent HTTP messages between same client/server sent over open connection Persistent without pipelining: r client issues new request only when previous response has been received r one RTT for each referenced object Persistent with pipelining: r default in HTTP/1.1 r client sends requests as soon as it encounters a referenced object r as little as one RTT for all the referenced objects r Objects still returned one at a time (HOL blocking versus parallel non- persistent HTTP)

77 2: Application Layer77 HTTP request message r two types of HTTP messages: request, response r 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) header lines Carriage return, line feed indicates end of message

78 2: Application Layer78 HTTP request message: general format

79 2: Application Layer79 HTTP request line (methods) HTTP/1.0 r GET  Return object specified by URI r POST  Send data to server (forms) r HEAD  asks server to leave requested object out of response  Return headers only of GET response HTTP/1.1 r GET, POST, HEAD r PUT  uploads file in entity body to path specified in URL field r DELETE  deletes file specified in the URL field r OPTIONS, TRACE, CONNECT

80 2: Application Layer80 HTTP request line (cont.) r URI  Object to retrieve E.g. http://www.cs.pdx.edu/index.html with a proxyhttp://www.cs.pdx.edu/index.html E.g. /index.html if no proxy r HTTP version  Version being used  HTTP 1.1 Host: header required Connection: header supported

81 2: Application Layer81 Common HTTP request headers r Accept  Acceptable document types, encodings, languages, character sets r If-Modified-Since  For use with caching r Referer  URL which caused this page to be requested r User-Agent r Host  For multiple web sites hosted on same server r Connection  Keep connection alive for subsequent request or close connection

82 2: Application Layer82 Other HTTP request headers r Authorization  Authentication info for HTTP authentication r From  User email (when privacy is disabled) Rest of HTTP request r Blank-line  Separate request headers from POST information  End of request r Body  If POST, send POST information

83 2: Application Layer83 Handling user input (forms) POST method: r Input is uploaded to server in entity body GET method: r Input is uploaded in URL field of request line GET search?name=george&animal=monkey HTTP/1.1 Host: www.somesite.comwww.somesite.com POST search HTTP/1.1 Host: www.somesite.comwww.somesite.com Content-type: application/x-www-form-urlencoded name=george&animal=monkey

84 2: Application Layer84 HTTP response message HTTP/1.1 200 OK Connection close Date: Thu, 06 Aug 1998 12:00:15 GMT Server: Apache/1.3.0 (Unix) Last-Modified: Mon, 22 Jun 1998 …... Content-Length: 6821 Content-Type: text/html data data data data data... status line (protocol status code status phrase) header lines data, e.g., requested HTML file

85 2: Application Layer85 HTTP response message: general format

86 2: Application Layer86 HTTP response format r Status-line  HTTP version  3 digit response code 1XX – informational 2XX – success 3XX – redirection 4XX – client error 5XX – server error  Reason phrase

87 2: Application Layer87 HTTP response status codes 200 OK  request succeeded, requested object later in this message 301 Moved Permanently  requested object moved, new location specified later in this 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 A few sample codes:

88 2: Application Layer88 Common HTTP response headers r Server  server software r Content-Encoding  x-gzip r Content-Length r Content-Type r Expires r Last-Modified r ETag

89 2: Application Layer89 Other HTTP response headers r Location  redirection r WWW-Authenticate  request for authentication r Allow  list of methods supported (GET, HEAD, etc) Rest of HTTP response r Blank-line  Separate headers from data r Body  Data being returned to client

90 2: Application Layer90 HTTP headers by function r Authentication  Client Authorization, Proxy- Authorization  Server WWW-authenticate, Proxy-Authenticate r User, server tracking  Client Cookie, Referer, From, User-agent  Server Set-cookie, Server r Caching  General Cache-control, Pragma  Client If-Modified-Since, If- Unmodified-Since, If- Match  Server Last-Modified, Expires, ETag, Age

91 2: Application Layer91 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 sent to port 80 at cis.poly.edu telnet cis.poly.edu 80 2. Type in a GET HTTP request: GET /~ross/ HTTP/1.1 Host: cis.poly.edu By typing this in (hit carriage return twice), you send this minimal (but complete) GET request to HTTP server 3. Look at response message sent by HTTP server!

92 2: Application Layer92 Let’s look at HTTP in action r telnet example r Ethereal example r Other examples  http://www.thefengs.com/courses/cs594/http.txt http://www.thefengs.com/courses/cs594/http.txt  http://www.thefengs.com/courses/cs594/http_po st.txt http://www.thefengs.com/courses/cs594/http_po st.txt

93 2: Application Layer93 User-server state: cookies Many major Web sites use cookies Four components: 1) cookie header line of HTTP response message Set-cookie: 2) cookie header line in HTTP request message Cookie: 3) cookie file kept on user’s host, managed by user’s browser 4) back-end database at Web site Example:  Susan access Internet always from same PC  She visits a specific e- commerce site for first time  When initial HTTP requests arrives at site, site creates a unique ID and creates an entry in backend database for ID

94 2: Application Layer94 Cookies: keeping “state” (cont.) client server usual http request msg usual http response + Set-cookie: 1678 usual http request msg cookie: 1678 usual http response msg usual http request msg cookie: 1678 usual http response msg cookie- specific action cookie- spectific action server creates ID 1678 for user entry in backend database access Cookie file amazon: 1678 ebay: 8734 Cookie file ebay: 8734 Cookie file amazon: 1678 ebay: 8734 one week later:

95 2: Application Layer95 Cookies (continued) What cookies can bring: r authorization r shopping carts r Site preferences r recommendations r user session state (Web e-mail) Cookies and privacy: r cookies permit sites to learn a lot about you r you may supply name and e-mail to sites r search engines use redirection & cookies to learn yet more r advertising companies obtain info across sites aside

96 2: Application Layer96 Web caches (proxy server) Why Web caching? r Reduce response time for client request. r Reduce traffic on an institution’s access link. r Reduce load on servers. r Enables “poor” content providers to effectively deliver content (but so does P2P file sharing) Goal: satisfy client request without involving origin server (i.e. do not send content that has not changed) Info on web caching r http://www.ircache.net/ http://www.ircache.net/ r http://www.squid.org http://www.squid.org r ICP r http://www.rfc- editor.org/rfc/rfc2186.txt http://www.rfc- editor.org/rfc/rfc2186.txt r http://www.rfc- editor.org/rfc/rfc2187.txt http://www.rfc- editor.org/rfc/rfc2187.txt

97 2: Application Layer97 More about Web caching r Browser sends all HTTP requests to cache  object in cache: cache returns object  else cache requests object from origin server, then returns object to client r Done directly at client  Via browser web cache r Along path from client to origin server  Via proxy web cache  Proxy acts as both client and server  Typically cache is installed by ISP (university, company, residential ISP) client Proxy server client HTTP request HTTP response HTTP request HTTP response origin server origin server

98 2: Application Layer98 Caching example Assumptions r average object size = 100,000 bits r avg. request rate from institution’s browsers to origin servers = 15/sec r delay from institutional router to any origin server and back to router = 2 sec Consequences r utilization on LAN = 15% r utilization on access link = 100% r total delay = Internet delay + access delay + LAN delay = 2 sec + minutes + milliseconds origin servers public Internet institutional network 10 Mbps LAN 1.5 Mbps access link institutional cache

99 2: Application Layer99 Caching example (cont) Possible solution r increase bandwidth of access link to, say, 10 Mbps Consequences r utilization on LAN = 15% r utilization on access link = 15% r Total delay = Internet delay + access delay + LAN delay = 2 sec + msecs + msecs r often a costly upgrade origin servers public Internet institutional network 10 Mbps LAN 10 Mbps access link institutional cache

100 2: Application Layer100 Caching example (cont) Install cache r suppose hit rate is.4 Consequence r 40% requests will be satisfied almost immediately r 60% requests satisfied by origin server r utilization of access link reduced to 60%, resulting in negligible delays (say 10 msec) r total avg delay = Internet delay + access delay + LAN delay =.6*(2.01) secs +.4*milliseconds < 1.4 secs origin servers public Internet institutional network 10 Mbps LAN 1.5 Mbps access link institutional cache

101 2: Application Layer101 Conditional GET r Goal: don’t send object if cache has up-to-date cached version r cache: specify date of cached copy in HTTP request If-modified-since: r server: response contains no object if cached copy is up- to-date: HTTP/1.0 304 Not Modified cache server HTTP request msg If-modified-since: HTTP response HTTP/1.0 304 Not Modified object not modified HTTP request msg If-modified-since: HTTP response HTTP/1.0 200 OK object modified

102 2: Application Layer102 HTTP caching r Additional caching methods  ETag and If-Match HTTP 1.1 has file signature as well r When/how often should the original be checked for changes?  Check every time?  Check each session? Day? Etc?  Use Expires header If no Expires, often use Last-Modified as estimate

103 2: Application Layer103 Example Cache Check Request GET / HTTP/1.1 Accept: */* Accept-Language: en-us Accept-Encoding: gzip, deflate If-Modified-Since: Mon, 29 Jan 2001 17:54:18 GMT If-None-Match: "7a11f-10ed-3a75ae4a" User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0) Host: www.cs.pdx.edu Connection: Keep-Alive

104 2: Application Layer104 Example Cache Check Response HTTP/1.1 304 Not Modified Date: Tue, 27 Mar 2001 03:50:51 GMT Server: Apache/1.3.14 (Unix) (Red- Hat/Linux) mod_ssl/2.7.1 OpenSSL/0.9.5a DAV/1.0.2 PHP/4.0.1pl2 mod_perl/1.24 Connection: Keep-Alive Keep-Alive: timeout=15, max=100 ETag: "7a11f-10ed-3a75ae4a"

105 2: Application Layer105 Content distribution networks (CDNs) “Active caching” (Akamai) Push content close to client a priori Versus pulling content through cache CDN company puts content servers throughout Internet – in lower-tier ISPs, close to users CDN replicates customers’ content in CDN servers. When provider updates content, CDN updates servers origin server in North America CDN distribution node CDN server in S. America CDN server in Europe CDN server in Asia

106 2: Application Layer106 CDN example r origin server  www.foo.com  distributes HTML  Replaces: http://www.foo.com/sports.ruth.gif with http://www.cdn.com/www.foo.com/ sports/ruth.gif http://www.foo.com/sports.ruth.gif http://www.cdn.com/www.foo.com/ sports/ruth.gif r CDN (cdn.com)  distributes gif files to content servers  uses its authoritative DNS server to route redirect requests HTTP request for www.foo.com/sports/sports.html DNS query for www.cdn.com HTTP request for www.cdn.com/www.foo.com/sports/ruth.gif 1 2 3 Origin server CDNs authoritative DNS server Nearby CDN server

107 2: Application Layer107 More about CDNs routing requests CDN creates a “map”, indicating distances from leaf ISPs and CDN nodes when query arrives at authoritative DNS server: – server determines ISP from which query originates – uses “map” to determine best CDN server not just Web pages streaming stored audio/video streaming real- time audio/video – CDN nodes create application-layer multicast overlay network

108 2: Application Layer108 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP, POP3, IMAP r 2.5 DNS r 2.6 P2P file sharing r 2.7 Socket programming with TCP r 2.8 Socket programming with UDP r 2.9 Building a Web server

109 2: Application Layer109 FTP: the file transfer protocol r transfer file to/from remote host r client/server model  client: side that initiates transfer (either to/from remote)  server: remote host r ftp: RFC 959 r ftp server: port 21 file transfer FTP server FTP user interface FTP client local file system remote file system user at host

110 2: Application Layer110 FTP: separate control, data connections r FTP client contacts FTP server at port 21 using TCP  Control connection for exchanging commands  Out-of-band signaling between end-points r Server maintains “state”  Authorization status  Current directory  Contrast to HTTP r For file transfer  Request via control connection  New TCP connection for data xfer is negotiated and created Can be server or client initiated Includes IP address and port information sent in application layer message – Why? – Protocol allows client to initiate transfer between 2 ftp servers Data connection closed after transfer FTP client FTP server TCP control connection port 21 TCP data connection port 20

111 2: Application Layer111 FTP commands, responses Sample commands: r sent as ASCII text over control channel  USER username  PASS password  LIST return list of file in current directory  RETR filename retrieves (gets) file  STOR filename stores (puts) file onto remote host Sample return codes r status code and phrase (as in HTTP) r 331 Username OK, password required r 125 data connection already open; transfer starting r 425 Can’t open data connection r 452 Error writing file

112 2: Application Layer112 ftp and NAT (network address translation) r NAT  Dynamically assign source address to a pool of available addresses “Statistically multiplex” address usage due to IP address shortage Replaces source IP address of packets Each machine gets unique, external IP address out of pool What to do if the “pool” runs out? –NAT with port translation

113 2: Application Layer113 ftp and NAT (network address translation) r NAPT (NAT with port translation)  Use the source port field (of TCP or UDP) along with pool of IP addresses Example: single, globally routable external IP address 192.168.0.1 192.168.0.2 Packet #2 SrcIP=192.168.0.2 SrcPort=1312 DstIP=131.252.220.66 DstPort=21 Packet #1 SrcIP=192.168.0.1 SrcPort=1312 DstIP=131.252.220.66 DstPort=21 NAPT translator ExternalIP=129.95.50.3

114 2: Application Layer114 ftp and NAT (network address translation) r NAPT (NAT with port translation)  Use the source port field (of TCP or UDP) along with pool of IP addresses Example: single, globally routable external IP address 192.168.0.1 192.168.0.2 Packet #2 SrcIP=192.168.0.2 SrcPort=1312 DstIP=131.252.220.66 DstPort=21 Packet #1 SrcIP=192.168.0.1 SrcPort=1312 DstIP=131.252.220.66 DstPort=21 NAPT translator ExternalIP=129.95.50.3 Packet #1 after NAPT SrcIP=129.95.50.3 SrcPort=2000 DstIP=131.252.220.66 DstPort=21 Packet #2 after NAPT SrcIP=129.95.50.3 SrcPort=2001 DstIP=131.252.220.66 DstPort=21

115 2: Application Layer115 ftp and NAT (network address translation) r NAPT (NAT with port translation)  Use the source port field (of TCP or UDP) along with pool of IP addresses Example: single, globally routable external IP address 192.168.0.1 192.168.0.2 NAPT translator ExternalIP=129.95.50.3 Reply #1 SrcIP=131.252.220.66 SrcPort=21 DstIP=129.95.50.3 DstPort=2000 Reply #2 SrcIP=131.252.220.66 SrcPort=21 DstIP=129.95.50.3 DstPort=2001

116 2: Application Layer116 ftp and NAT (network address translation) r NAPT (NAT with port translation)  Use the source port field (of TCP or UDP) along with pool of IP addresses Example: single, globally routable external IP address 192.168.0.1 192.168.0.2 Reply #2 after NAPT SrcIP=131.252.220.66 SrcPort=21 DstIP=192.168.0.2 DstPort=1312 Reply #1 after NAPT SrcIP=131.252.220.66 SrcPort=21 DstIP=192.168.0.1 DstPort=1312 NAPT translator ExternalIP=129.95.50.3 Reply #1 SrcIP=131.252.220.66 SrcPort=21 DstIP=129.95.50.3 DstPort=2000 Reply #2 SrcIP=131.252.220.66 SrcPort=21 DstIP=129.95.50.3 DstPort=2001

117 2: Application Layer117 ftp, NAT and PORT command r Normal FTP mode  Server has port 20, 21 reserved  Client initiates control connection to port 21 on server  Client allocates port X for data connection  Client passes the data connection port (X) and its IP address in a PORT command to server  Server parses PORT command and initiates connection from its own port 20 to the client on port X  What if client is behind a NAT device? NAT must capture outgoing connections destined for port 21 and look to translate X within payload –What if NAT doesn’t parse PORT command correctly? –What if ftp server is running on a different port than 21?  http://www.practicallynetworked.com/support/linksys_ft p_port.htm

118 2: Application Layer118 ftp, NAT, and PORT command r Passive (PASV) mode  Client initiates control connection by connecting to port 21 on server  Client enables “Passive” mode  Server responds with PORT command giving client the IP address and port to use for subsequent data connection (usually port 20, but can be bypassed)  Client initiates data connection by connecting to specified port on server  Most web browsers do PASV-mode ftp  What if server is behind a NAT device? See client issues  What if both client and server are behind NAT devices? Problem Similar to P2P xfers

119 2: Application Layer119 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP, POP3, IMAP r 2.5 DNS r 2.6 P2P file sharing r 2.7 Socket programming with TCP r 2.8 Socket programming with UDP r 2.9 Building a Web server

120 2: Application Layer120 Electronic Mail Three major components: r user agents r mail servers r simple mail transfer protocol: SMTP User Agent r a.k.a. “mail reader” r composing, editing, reading mail messages r e.g., Eudora, Outlook, elm, Netscape Messenger r outgoing, incoming messages stored on server user mailbox outgoing message queue mail server user agent user agent user agent mail server user agent user agent mail server user agent SMTP

121 2: Application Layer121 Electronic Mail: mail servers Mail Servers r mailbox contains incoming messages for user r message queue of outgoing (to be sent) mail messages r SMTP protocol between mail servers to send email messages  Mail servers are both clients and servers client: sending mail server server: receiving mail server Peer-to-peer? r SMTP protocol also between user agents and mail servers to send email messages mail server user agent user agent user agent mail server user agent user agent mail server user agent SMTP

122 2: Application Layer122 Electronic Mail: SMTP [RFC 821] r uses TCP to reliably transfer email message from client to server, port 25 r direct transfer  User agent to sending server If one runs SMTP locally (postfix, sendmail) or uses SMTP built-in to client software  Sending server to receiving server r three phases of transfer  handshaking (greeting)  transfer of messages  closure r command/response interaction  commands: ASCII text  response: status code and phrase r messages must be in 7-bit ASCII

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

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

125 2: Application Layer125 Try SMTP interaction for yourself:  telnet servername 25 r see 220 reply from server r enter HELO, MAIL FROM, RCPT TO, DATA, QUIT commands above lets you send email without using email client (reader)

126 2: Application Layer126 SMTP: final words r SMTP uses persistent connections r SMTP requires message (header & body) to be in 7- bit ASCII  SMTP server uses CRLF.CRLF to determine end of message Comparison with HTTP: r HTTP: pull r SMTP: push r both have ASCII command/response interaction, status codes r HTTP: each object encapsulated in its own response msg r SMTP: multiple objects sent in multipart msg

127 2: Application Layer127 Mail message format SMTP: protocol for exchanging email msgs RFC 822: standard for text message format: r header lines, e.g.,  To:  From:  Subject: different from SMTP commands! r body  the “message”, ASCII characters only header body blank line

128 2: Application Layer128 Message format: multimedia extensions r MIME: multimedia mail extension, RFC 2045, 2056 r additional lines in msg header declare MIME content type From: alice@crepes.fr To: bob@hamburger.edu Subject: Picture of yummy crepe. MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Type: image/jpeg base64 encoded data....................................base64 encoded data multimedia data type, subtype, parameter declaration method used to encode data MIME version encoded data

129 2: Application Layer129 MIME types Text example subtypes: plain, html Image example subtypes: jpeg, gif Audio exampe subtypes: basic (8-bit mu-law encoded), 32kadpcm (32 kbps coding) Video example subtypes: mpeg, quicktime Application other data that must be processed by reader before “viewable” example subtypes: msword, octet- stream Content-Type: type/subtype

130 2: Application Layer130 Multipart Types From: alice@crepes.fr To: bob@hamburger.edu Subject: Picture of yummy crepe. MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=98766789 --98766789 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain Dear Bob, Please find a picture of a crepe. --98766789 Content-Transfer-Encoding: base64 Content-Type: image/jpeg base64 encoded data....................................base64 encoded data --98766789--

131 2: Application Layer131 Mail access protocols r SMTP: delivery/storage to receiver’s server r Mail access protocol: retrieval from server  Direct (telnet or ssh followed by “mail”)  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: Hotmail, Yahoo! Mail, Horde/IMP, etc. user agent sender’s mail server user agent SMTP access protocol receiver’s mail server

132 2: Application Layer132 POP3 protocol authorization phase r client commands:  user: declare username  pass: password r server responses  +OK  -ERR transaction phase, client:  list: list message numbers  retr: retrieve message by number  dele: delete r quit C: list S: 1 498 S: 2 912 S:. C: retr 1 S: S:. C: dele 1 C: retr 2 S: S:. C: dele 2 C: quit S: +OK POP3 server signing off S: +OK POP3 server ready C: user bob S: +OK C: pass hungry S: +OK user successfully logged on

133 2: Application Layer133 POP3 (more) and IMAP More about POP3 r Previous example uses “download and delete” mode. r Bob cannot re-read e- mail if he changes client r “Download-and-keep”: copies of messages on different clients r POP3 is stateless across sessions IMAP r Keep all messages in one place: the server r Allows user to organize messages in folders r IMAP keeps user state across sessions:  names of folders and mappings between message IDs and folder name

134 2: Application Layer134 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP, POP3, IMAP r 2.5 DNS r 2.6 P2P file sharing r 2.7 Socket programming with TCP r 2.8 Socket programming with UDP r 2.9 Building a Web server

135 2: Application Layer135 Domain Name System (DNS) r Internet hosts, routers like to use fixed- length addresses (numbers)  IP address (32 bit) - used for addressing datagrams r Humans like to use variable-length names  www.cs.pdx.edu www.  keywords r DNS, keywords, naming protocols  Map between IP addresses and names

136 2: Application Layer136 Original Name to Address Mapping r Flat namespace  /etc/hosts.txt  SRI kept main copy  Downloaded regularly r Problems  Count of hosts was increasing From machine per domain to machine per user Many more downloads of hosts.txt Many more updates of hosts.txt

137 2: Application Layer137 DNS: Domain Name System (1984) r application-layer protocol used by hosts and name servers  communicate to resolve names (address/name translation)  core Internet function, implemented as application-layer protocol complexity at network’s “edge” Compare to phone network –Naming (none supported) –Addressing (complex mechanism within network)

138 2: Application Layer138 DNS: Domain Name System (1984) r distributed database implemented in hierarchy of many name servers  Goals Scalability Decentralized maintenance Robustness, fault-tolerance Global scope –Names mean the same thing everywhere Don’t need –Atomicity –Strong consistency  Why not centralize DNS? Not scalable, hard to maintain, single point of failure  http://www.rfc-editor.org/rfc/rfc1034.txt  http://www.rfc-editor.org/rfc/rfc1035.txt

139 2: Application Layer139 Other DNS issues r Host aliasing  Canonical and alias names r Mail server aliasing  MX record r Load distribution  Replicated Web servers: set of IP addresses for one canonical name

140 2: Application Layer140 DNS records DNS: distributed db storing resource records (RR) r Type=NS  name is domain (e.g. foo.com)  value is hostname of authoritative name server for this domain RR format: (name, value, type, ttl) r Type=A  name is hostname  value is IP address r Type=CNAME  name is alias name for some “canonical” (the real) name www.ibm.com is really servereast.backup2.ibm.com  value is canonical name r Type=MX  value is name of mailserver associated with name

141 2: Application Layer141 DNS MX record type r Initially only “A” records r MX records created for mail  Point to mail exchanger for a name  E.g. mail.acm.org is MX for acm.org r Addition of MX record type proved to be a challenge  How to get mail programs to lookup MX record for mail delivery rather than A record?  Needed critical mass of such mailers

142 2: Application Layer142 DNS hierarchical canonical name space r www.cs.pdx.edu root edu net org uk com ca gwu ucb pdx bu mit cs ece www

143 2: Application Layer143 Root DNS Servers com DNS servers org DNS serversedu DNS servers poly.edu DNS servers umass.edu DNS servers yahoo.com DNS servers amazon.com DNS servers pbs.org DNS servers Maps closely to hierarchy r Administrative hierarchy  Organized into regions known as “zones” with “.” as separator  zone = contiguous section of name space r Zones created by convincing owner node to delegate subzone  umass.edu zone delegates cs.umass.edu to a different set of authoritative name servers  Each zone contains multiple redundant servers (fault tolerance) Primary (master) name server updated manually Secondary (redundant) servers updated by zone transfer of name space

144 2: Application Layer144 DNS: Root name servers r contacted by local name server that can not resolve name r root name servers  contacts authoritative name server or intermediate name server if name mapping not known  gets mapping and returns it to local name server  13 root name servers worldwide for fault-tolerance All that fit in a 512 octet SOA record b USC-ISI Marina del Rey, CA l ICANN Los Angeles, CA e NASA Mt View, CA f Internet Software C. Palo Alto, CA (and 17 other locations) i Autonomica, Stockholm (plus 3 other locations) k RIPE London (also Amsterdam, Frankfurt) m WIDE Tokyo a Verisign, Dulles, VA c Cogent, Herndon, VA (also Los Angeles) d U Maryland College Park, MD g US DoD Vienna, VA h ARL Aberdeen, MD j Verisign, ( 11 locations)

145 2: Application Layer145 TLD Servers r Top-level domain (TLD) servers: responsible for com, org, net, edu, etc, and all top-level country domains uk, fr, ca, jp.  Network Solutions maintains servers for com TLD  Educause for edu TLD

146 2: Application Layer146 Authoritative Servers r Provides authoritative hostname to IP mappings  Typically, one per organization  Hand mappings out for organization’s servers (Web & mail). r Store parts of the database  Each name assigned to authoritative server  Server responds to all queries for name it is the authority  Can be maintained by organization or service provider r Root name servers are authorities for TLD names  Root servers deliver authority for “.edu” TLD r TLD name servers are authorities for their domains  “.edu” TLD server delivers authority for “pdx.edu” name r Each local DNS server has pointers to root servers  Hard-coded into name server distributions

147 2: Application Layer147 Local Name Server r Does not strictly belong to hierarchy r Each ISP (residential ISP, company, university) has one.  Also called “default name server” r When a host makes a DNS query, query is sent to its local DNS server  Acts as a proxy, forwards query into hierarchy.  Typically answer queries about local zone directly  Do a lookup of distant host names for local hosts Configured with well-known root servers Currently {a-m}.root-servers.net

148 2: Application Layer148 Client resolver r Common code on client to query DNS hierarchy  Typically a library that applications can link to obtain gethostbyname() function  Resolver configuration /etc/nsswitch.conf  Local name servers hand-configured (e.g. /etc/resolv.conf) or automatically configured (DHCP) Can specify a file /etc/hosts Can specify a name server by its IP address (i.e. 129.95.50.2)  Host queries local name server for unknown names

149 2: Application Layer149 Inserting records into DNS r Example: just created startup “Network Utopia” r Register name networkuptopia.com at a registrar (e.g., Network Solutions)  Need to provide registrar with names and IP addresses of your authoritative name server (primary and secondary)  Registrar inserts two RRs into the com TLD server: (networkutopia.com, dns1.networkutopia.com, NS) (dns1.networkutopia.com, 212.212.212.1, A) r Put in authoritative server  Type A record for www.networkuptopia.comwww.networkuptopia.com  Type MX record for networkutopia.com r How do people get the IP address of your Web site?

150 2: Application Layer150 Query types recursive query: r puts burden of name resolution on contacted name server r Only returns answer or “not found” r Heavy load?  Root servers currently disable recursive querying through them  RFC 2010 iterated query: r contacted server replies with name of server to contact r “I don’t know this name, but ask this server” r Client iteratively queries

151 2: Application Layer151 requesting host cis.poly.edu gaia.cs.umass.edu root DNS server local DNS server dns.poly.edu 1 2 4 5 6 authoritative DNS server dns.cs.umass.edu 7 8 TLD DNS server 3 Recursive query example r Host at cis.poly.edu wants IP address for gaia.cs.umass.edu

152 2: Application Layer152 requesting host cis.poly.edu gaia.cs.umass.edu root DNS server local DNS server dns.poly.edu 1 2 3 4 5 6 authoritative DNS server dns.cs.umass.edu 7 8 TLD DNS server Iterated query example r Host at cis.poly.edu wants IP address for gaia.cs.umass.edu iterated query

153 2: Application Layer153 Typical Resolution r Client does recursive request to local name server r Local name server does iterative requests to find name r Local name server has knowledge of root servers r Steps for resolving www.pdx.edu  Application calls gethostbyname()  Resolver contacts local name server (S 1 )  S 1 queries root server (S 2 ) for (www.pdx.edu)www..edu  S 2 returns NS record for pdx.edu (S 3 )  S 1 queries S 3 for www.pdx.eduwww..edu  S 3 returns A record for www.pdx.eduwww..edu r Can return multiple addresses -> what does this mean?

154 2: Application Layer154 DNS: caching and updating records r DNS responsescached throughout hierarchy  Quick response for repeated translations Other queries may reuse some parts of lookup –NS records for domains reused often (xxx.yahoo.com) Entries timeout after some time (soft state) –TTL field controlled by authority –Affects DNS-based load balancing  TLD servers often cached in local name servers Thus root name servers not often visited  Negative responses also cached Don’t repeat past mistakes (misspellings) r update/notify mechanisms under design by IETF  RFC 2136  http://www.ietf.org/html.charters/dnsind-charter.html

155 2: Application Layer155 DNS Lookup Caching Example Client Local DNS server root & edu DNS server pdx.edu DNS server www.cs.pdx.edu? NS pdx.edu www.cs.pdx.edu NS pdx.edu www=IPaddr cs.pdx.edu DNS server

156 2: Application Layer156 Subsequent Lookup Example Client Local DNS server root & edu DNS server pdx.edu DNS server cs.pdx.edu DNS server ftp.cs.pdx.edu ftp=IPaddr ftp.cs.pdx.edu cs.pdx.edu entry cached

157 2: Application Layer157 Iterated queries and caching r Recall  Recursive query to local DNS server  Iterative query from local DNS server on r Why not do iterative queries from host?  Win2k client Does iterative queries from host  Caching implications?

158 2: Application Layer158 DNS dig example r Real example using dig and named  Shows iterative queries, recursive queries, and caching r dig cat /etc/resolv.conf # local DNS server dig +norecurse www.thefengs.com. # do an iterative query to local DNS serverwww.thefengs.com dig @192.41.162.30 +norecurse www.thefengs.com. # do an iterative query to IP addr of L TLDwww.thefengs.com dig @216.21.226.71 +norecurse www.thefengs.com. # do an iterative query to IP addr of NS at register.comwww.thefengs.com dig +norecurse www.thefengs.com. # do an iterative query again to local DNS serverwww.thefengs.com # NOTHING was cached at local DNS server! dig +recurse www.thefengs.com. # now do a recursive query through local DNS serverwww.thefengs.com dig +norecurse www.thefengs.com. # now you get a cached resultwww.thefengs.com # Negative results also cached dig +norecurse www.jjkkllmmnnoopp.com. # returns pointer to root name serverswww.jjkkllmmnnoopp.com dig +recurse www.jjkkllmmnnoopp.com. # returns status: NXDOMAINwww.jjkkllmmnnoopp.com dig +norecurse www.jjkkllmmnnoopp.com. # returns status: NXDOMAINwww.jjkkllmmnnoopp.com

159 2: Application Layer159 DNS protocol, messages DNS protocol : query and reply messages, both with same message format msg header r identification: 16 bit # for query, reply to query uses same # r flags:  query or reply  recursion desired  recursion available  reply is authoritative

160 2: Application Layer160 DNS protocol, messages Name, type fields for a query RRs in response to query records for authoritative servers additional “helpful” info that may be used

161 2: Application Layer161 DNS issues r Poor static configuration (root server list) r Lack of exponential backoff r No centralized caching per site  Each machine runs one caching local server r UDP used for queries  Need reliability -> Why not TCP? r Vulnerability of 13 TLD servers  Jon Postel and his mobility “experiment”  Attacks on TLD have occurred

162 2: Application Layer162 Chapter 2: Application layer r 2.1 Principles of network applications  app architectures  app requirements r 2.2 Web and HTTP r 2.4 Electronic Mail  SMTP, POP3, IMAP r 2.5 DNS r 2.6 P2P file sharing r 2.7 Socket programming with TCP r 2.8 Socket programming with UDP r 2.9 Building a Web server

163 2: Application Layer163 Building a simple Web server r handles one HTTP request r accepts the request r parses header r obtains requested file from server’s file system r creates HTTP response message:  header lines + file r sends response to client r after creating server, you can request file using a browser (e.g., IE explorer) r see text for details

164 2: Application Layer164 Chapter 2: Summary r Application architectures  client-server  P2P  hybrid r application service requirements:  reliability, bandwidth, delay r Internet transport service model  connection-oriented, reliable: TCP  unreliable, datagrams: UDP Our study of network apps now complete! r specific protocols:  HTTP  FTP  SMTP, POP, IMAP  DNS r socket programming

165 2: Application Layer165 Chapter 2: Summary r typical request/reply message exchange:  client requests info or service  server responds with data, status code r message formats:  headers: fields giving info about data  data: info being communicated Most importantly: learned about protocols r control vs. data msgs  in-band, out-of-band r centralized vs. decentralized r stateless vs. stateful r reliable vs. unreliable msg transfer r “complexity at network edge”

166 2: Application Layer166 Extra slides

167 2: Application Layer167 HTTP Authentication Authentication goal: control access to server documents r stateless: client must present authorization in each request r authorization: typically name, password  authorization: header line in request  if no authorization presented, server refuses access, sends WWW authenticate: header line in response r http://www.sandbox.com/clip board/pub-doc/home.jsp http://www.sandbox.com/clip board/pub-doc/home.jsp client server usual http request msg 401: authorization req. WWW authenticate: usual http request msg + Authorization:cred usual http response msg usual http request msg + Authorization:cred usual http response msg time Browser caches name & password so that user does not have to repeatedly enter it.

168 2: Application Layer168 HTTP Authentication example r http://www.thefengs.com/wuchang/work/c ourses/cs594/http_ba.txt http://www.thefengs.com/wuchang/work/c ourses/cs594/http_ba.txt

169 2: Application Layer169 Chapter 2: Application layer r 2.1 Principles of network applications  app architectures  app requirements r 2.2 Web and HTTP r 2.4 Electronic Mail  SMTP, POP3, IMAP r 2.5 DNS r 2.6 P2P file sharing r 2.7 Socket programming with TCP r 2.8 Socket programming with UDP r 2.9 Building a Web server

170 2: Application Layer170 P2P file sharing Example r Alice runs P2P client application on her notebook computer r Intermittently connects to Internet; gets new IP address for each connection r Asks for “Hey Jude” r Application displays other peers that have copy of Hey Jude. r Alice chooses one of the peers, Bob. r File is copied from Bob’s PC to Alice’s notebook: HTTP r While Alice downloads, other users uploading from Alice. r Alice’s peer is both a Web client and a transient Web server. All peers are servers = highly scalable!

171 2: Application Layer171 P2P: centralized directory original “Napster” design 1) when peer connects, it informs central server:  IP address  content 2) Alice queries for “Hey Jude” 3) Alice requests file from Bob centralized directory server peers Alice Bob 1 1 1 1 2 3

172 2: Application Layer172 P2P: problems with centralized directory r Single point of failure r Performance bottleneck r Copyright infringement file transfer is decentralized, but locating content is highly centralized

173 2: Application Layer173 P2P: decentralized directory r Gnutella  fully distributed no central server –Location service distributed over peers –More difficult to shut down query flooding to search  Issues “Bootstrap” node needed Excessive query traffic Limited scoping –Query radius may not have content Maintenance overhead  public domain protocol many Gnutella clients implementing protocol

174 2: Application Layer174 Gnutella: protocol Query QueryHit Query QueryHit Query QueryHit File transfer: HTTP r Query message sent over existing TCP connections r peers forward Query message r QueryHit sent over reverse path Scalability: limited scope flooding

175 2: Application Layer175 Gnutella: Peer joining 1. Joining peer X must find some other peer in Gnutella network: use list of candidate peers 2. X sequentially attempts to make TCP with peers on list until connection setup with Y 3. X sends Ping message to Y; Y forwards Ping message. 4. All peers receiving Ping message respond with Pong message 5. X receives many Pong messages. It can then setup additional TCP connections Peer leaving: see homework problem!

176 2: Application Layer176 Exploiting heterogeneity: KaZaA r Each peer is either a group leader or assigned to a group leader.  TCP connection between peer and its group leader.  TCP connections between some pairs of group leaders. r Group leader tracks the content in all its children.  Forwards query to other group leaders if content not present r Overlay network  Edges are TCP connections not links

177 2: Application Layer177 KaZaA: Querying r Each file has a hash and a descriptor r Client sends keyword query to its group leader r Group leader responds with matches:  For each match: metadata, hash, IP address r If group leader forwards query to other group leaders, they respond with matches r Client then selects files for downloading  HTTP requests using hash as identifier sent to peers holding desired file

178 2: Application Layer178 KaZaA tricks r Limitations on simultaneous uploads r Request queuing r Incentive priorities r Parallel downloading For more info: r J. Liang, R. Kumar, K. Ross, “Understanding KaZaA,” (available via cis.poly.edu/~ross)

179 2: Application Layer179 P2P: BitTorrent r Previous systems  Sources/servers Have entire copy of content Keep content available for others to download  Clients Connect to sources/servers with full copy  Problems Must force clients to become sources/servers for P2P application to work Can’t redistribute data blocks of a file until it is received in its entirety (large files problematic) No control of content (must rely on naming and popularity to infer integrity) –“URL-based P2P?” Slides courtesy of Karthik Tamilmani

180 2: Application Layer180 Philosophy r Author: Bram Cohen r Based on Tit-for-tat  Incentive - Uploading while downloading  Get preference in downloading if you supply good upload r Pieces of files r Components  Ordinary web server to serve up metainfo file (.torrent)  Client web browser  BitTorrent tracker (location of which is specified as a URL in.torrent)  Original downloader (the first “seed”)  Client downloader

181 2: Application Layer181 Overall Architecture Web page with link to.torrent A B C Peer [Leech] Downloader “US” Peer [Leech] Tracker Web Server.torrent Origin Downloader [Seed] Peer [Seed]

182 2: Application Layer182 Overall Architecture Web page with link to.torrent A B C Peer [Leech] Downloader “US” Peer [Seed] Peer [Leech] Tracker Get- announce Web Server Origin Downloader [Seed]

183 2: Application Layer183 Overall Architecture Web page with link to.torrent A B C Peer [Leech] Downloader “US” Peer [Seed] Peer [Leech] Tracker Response-peer list Web Server Origin Downloader [Seed]

184 2: Application Layer184 Overall Architecture Web page with link to.torrent A B C Peer [Leech] Downloader “US” Peer [Seed] Peer [Leech] Tracker Shake-hand Web Server Shake-hand Origin Downloader [Seed] Shake-hand

185 2: Application Layer185 Overall Architecture Web page with link to.torrent A B C Peer [Leech] Downloader “US” Peer [Seed] Peer [Leech] Tracker pieces Web Server Origin Downloader [Seed] pieces

186 2: Application Layer186 Overall Architecture Web page with link to.torrent A B C Peer [Leech] Downloader “US” Peer [Seed] Peer [Leech] Tracker pieces Web Server Origin Downloader [Seed] pieces

187 2: Application Layer187 Overall Architecture Web page with link to.torrent A B C Peer [Leech] Downloader “US” Peer [Leech] Tracker Get-announce Response-peer list pieces Web Server Origin Downloader [Seed] pieces Peer [Seed]

188 2: Application Layer188 Messages r Peer – Peer messages  TCP Sockets r Peer – Tracker messages  HTTP Request/Response r B-encoding r http://bitconjurer.org/BitTorrent/protocol.html

189 2: Application Layer189.torrent r URL of the tracker r Dictionary keys for B-encoding scheme r Pieces r Piece length r Name r Length r Files  Path  length

190 2: Application Layer190 Tracker r Peer cache  IP, port, peer id r State information  Completed  Downloading r Returns random list

191 2: Application Layer191

192 2: Application Layer192 Peer Operation r File space allocated r Connect to peers r Bitfield  have(1) and not have(0) r Have  Advertise pieces r Interest /Not_interested  Expressing interest in the pieces published by the peer r Requesting for a chunk  Request

193 2: Application Layer193 Peer Operation r Choking algorithm  Choke/Unchoke Avoid large numbers of TCP connections Optimistic unchoke for a peer, rotates every 30 sec. Preferred peers do not get choked  Snubbing behavior Prevented by Anti-snubbing. r Upload to interested peers who are not choking.

194 2: Application Layer194 Peer Operation r Verify on receiving complete piece r Endgame Behavior  Cancel  To fix the “waiting” on the last slow peer

195 2: Application Layer195 Experimental client

196 2: Application Layer196

197 2: Application Layer197 Strengths r Better bandwidth utilization  Never before speeds. Up to 7 MB/s from the Internet. r Limit free riding – tit-for-tat r Limit leech attack – coupling upload & download r Ability to resume a download

198 2: Application Layer198 Drawbacks r Small files – latency, overhead r Random list of peers - naive r Scalability  Millions of peers – Tracker behavior (uses 1/1000 of bandwidth)  Single point of failure r Robustness  System progress dependent on altruistic nature of seeds (and peers)  Malicious attacks and leeches.

199 2: Application Layer199 Interesting links r Official site: http://bitconjurer.org/BitTorrent http://bitconjurer.org/BitTorrent r BitTorrent FAQ: http://btfaq.comhttp://btfaq.com r Torrent sites  http://f.scarywater.net http://f.scarywater.net  http://www.suprnova.org http://www.suprnova.org  http://tvtorrents.com http://tvtorrents.com Remember  leave your download windows open  Big brother is watching!


Download ppt "2: Application Layer1 Chapter 2 Application Layer Computer Networking: A Top Down Approach Featuring the Internet, 3 rd edition. Jim Kurose, Keith Ross."

Similar presentations


Ads by Google