920 likes | 931 Views
CMPT 371 Data Communications and Networking. Chapter 2 Application Layer. Our goals: conceptual, implementation aspects of network application protocols transport-layer service models client-server paradigm peer-to-peer paradigm.
E N D
CMPT 371Data Communications and Networking Chapter 2Application Layer 2: 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-level protocols HTTP FTP SMTP / POP3 / IMAP DNS programming network applications socket API Chapter 2: Application Layer 2: Application Layer
2.1 Principles of app layer protocols 2.2 Web and HTTP 2.3 FTP 2.4 Electronic Mail SMTP, POP3, IMAP 2.5 DNS 2.6 Content distribution Network Web caching Content distribution networks P2P file sharing 2.7 Cloud Chapter 2 outline 2: Application Layer
e-mail web text messaging remote login P2P file sharing multi-user network games streaming stored video (YouTube, Hulu, Netflix) voice over IP (e.g., Skype) real-time video conferencing social networking search … … Some network apps Application Layer
Applications -> Software Network applications • What exactly running in a computer ? 2: Application Layer
Process: program running within a host. implements user interface & application-level protocol Web: browser E-mail: mail reader streaming audio/video: media player Network applications: some jargon • within same host, two processes communicate using interprocess communication (defined by OS). • processes running in different hosts communicate with an application-layer protocol 2: Application Layer
Creating a network app write programs that: 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 (user) applications 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 Application Layer
Application: communicating, distributed processes e.g., e-mail, Web, P2P file sharing, instant messaging running in end systems (hosts) exchange messages to implement application Application-layer protocols one “piece” of an app define messages exchanged by apps and actions taken use communication services provided by lower layer protocols (TCP, UDP) application transport network data link physical application transport network data link physical application transport network data link physical Applications and application-layer protocols 2: Application Layer
Types of messages exchanged, e.g., request & response messages Syntax of message types: what fields in messages & how fields are delineated Semantics of the fields, i.e., meaning of information in fields Rules for when and how processes send & respond to messages Public-domain protocols: defined in RFCs allows for interoperability eg, HTTP, SMTP Proprietary protocols: eg, Skype BitTorrent (?) WhatsApp/Line/Wechat PokemonGo! App-layer protocol defines 2: Application Layer
Typical network app has two pieces: client and server request reply application transport network data link physical application transport network data link physical Client-server paradigm Client: • initiates contact with server (“speaks first”) • typically requests service from server, • Web: client implemented in browser; e-mail: in mail reader Server: • provides requested service to client • e.g., Web server sends requested Web page, mail server delivers e-mail 2: Application Layer
Programming - Socket clients, servers client process:process that initiates communication server process:process that waits to be contacted • process sends/receives messages to/from its socket application application socket controlled by app developer process process transport transport controlled by OS network network link Internet link physical physical 2: Application Layer
host or server host or server process process socket socket TCP/UDP with buffers, variables TCP/UDP with buffers, variables Programming - Socket • socket analogous to door • sending process shoves message out door • sending process assumes transport infrastructure on other side of door which brings message to socket at receiving process controlled by app developer Internet controlled by OS • API: Application Programmer’s Interface (1) choose transport protocol; (2) set parameters 2: Application Layer
create socket: clientSocket = socket(AF_INET,SOCK_DGRAM) Create datagram with server IP and port=x; send datagram viaclientSocket read datagram from serverSocket write reply to serverSocket specifying client address, port number read datagram from clientSocket close clientSocket Socket Example: UDP client server (running on serverIP) create socket, port= x: serverSocket = socket(AF_INET,SOCK_DGRAM) Application 2-13
Socket Example: UDP include Python’s socket library from socket import * serverName = ‘hostname’ serverPort = 12000 clientSocket = socket(socket.AF_INET, socket.SOCK_DGRAM) message = raw_input(’Input lowercase sentence:’) clientSocket.sendto(message,(serverName, serverPort)) modifiedMessage, serverAddress = clientSocket.recvfrom(2048) print modifiedMessage clientSocket.close() create UDP socket for server get user keyboard input Attach server name, port to message; send into socket read reply characters from socket into string print out received string and close socket Application Layer
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” Outside of the door – Transport Layer Service Bandwidth • some apps (e.g., multimedia) require minimum amount of bandwidth to be “effective” • other apps (“elastic apps”) make use of whatever bandwidth they get 2: Application Layer
Transport service requirements of common apps Time Sensitive no no no yes, 100’s msec yes, few secs yes, 100’s msec yes and no Application file transfer e-mail Web documents real-time audio/video stored audio/video interactive games instant messaging Bandwidth elastic elastic elastic audio: 5kbps-1Mbps video:10kbps-5Mbps same as above few kbps up elastic Data loss no loss no loss no loss loss-tolerant loss-tolerant loss-tolerant no loss 2: Application Layer
Internet apps: application, transport protocols Application layer protocol SMTP [RFC 2821] Telnet [RFC 854] HTTP [RFC 2616] FTP [RFC 959] proprietary (e.g. YouTube) proprietary (e.g., Skype) Underlying transport protocol Application e-mail remote terminal access Web file transfer streaming multimedia Internet telephony TCP TCP TCP TCP TCP or UDP TCP or UDP 2: Application Layer
2.1 Principles of app layer protocols 2.2 Web and HTTP 2.3 FTP 2.4 Electronic Mail SMTP, POP3, IMAP 2.5 DNS 2.6 Content distribution Network Web caching Content distribution networks P2P file sharing 2.7 Cloud Chapter 2 outline 2: Application Layer
http://www.cs.sfu.ca/~jcliu/cmpt371/index.htm path name host name Web and HTTP First some jargon • Web page consists of objects • Object can be HTML file, JPEG image, Java applet, audio file,… • Most Web sites have a base HTML-file which includes several referenced objects • Each object is addressable by a URL • Example URL: 2: Application Layer
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 HTTP 1.0: RFC 1945 HTTP 1.1: RFC 2068 HTTP response HTTP response HTTP request HTTP request HTTP overview PC running Firefox browser server running Apache Web server iphone running Safari browser 2: Application Layer
Is it difficult to write a Browser ? MS Internet Explorer/Edge Safari FireFox Chrome … 2: Application Layer
1. Telnet to your favorite Web server: Trying out HTTP (client side) for yourself telnet www.cs.sfu.ca 80 Opens TCP connection to port 80 (default HTTP server port) at www.cs.sfu.ca Anything typed in sent to port 80 2: Application Layer
1. Telnet to your favorite Web server: Trying out HTTP (client side) for yourself telnet www.cs.sfu.ca 80 Opens TCP connection to port 80 (default HTTP server port) at www.cs.sfu.ca Anything typed in sent to port 80 2. Type in a GET HTTP request: GET or GET /~jcliu/index.htm You have sent this minimal (but complete) GET request to HTTP server And you have received HTML objects ! 2: Application Layer
Implement HTTP - network Implement a GUI - local Anymore ? Is it difficult to write a Browser ? Internet Explorer Chrome FireFox … • Efficiency, fault-tolerant, compatibility, security, Java-support, multi-language … 2: Application Layer
Uses TCP: client initiates TCP connection (creates socket) to server, port 80 server accepts TCP connection from client HTTP messages (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 HTTP overview (continued) aside 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 reconciled 2: Application Layer
HTTP request message • two types of HTTP messages: request, response • HTTP request message: • ASCII (human-readable format) request line (GET, POST, HEAD commands) 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) header lines Carriage return, line feed indicates end of message 2: Application Layer
~ ~ ~ ~ ~ ~ ~ ~ value value header field name header field name cr cr lf lf cr lf HTTP request message: general format request line sp sp version cr method URL lf header lines entity body body 2: Application Layer
Post method: Web page often includes form input Input is uploaded to server in entity body URL method: Uses GET method Input is uploaded in URL field of request line: Uploading form input www.somesite.com/animalsearch?monkeys&banana 2: Application Layer
HTTP/1.0 GET POST HEAD asks server to leave requested object out of response debugging HTTP/1.1 GET, POST, HEAD PUT uploads file in entity body to path specified in URL field DELETE deletes file specified in the URL field Method types 2: Application Layer
HTTP response message status line (protocol status code status phrase) 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 ... header lines data, e.g., requested HTML file 2: Application Layer
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 HTTP response status codes In first line in server->client response message. A few sample codes: 2: Application Layer
Nonpersistent HTTP At most one object is sent over a TCP connection. HTTP/1.0 uses nonpersistent HTTP Persistent HTTP Multiple objects can be sent over single TCP connection between client and server. HTTP/1.1 uses persistent connections in default mode HTTP connections 2: Application Layer
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 Nonpersistent HTTP (contains text, references to 10 jpeg images) 1b. HTTP server at host www.someSchool.edu 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 someDepartment/home.index 3. HTTP server receives request message, forms response message containing requested object, and sends message into its socket time 2: Application Layer
5. HTTP client receives response message containing html file, displays html. Parsing html file, finds 10 referenced jpeg objects Nonpersistent HTTP (cont.) 4. HTTP server closes TCP connection. time 6.Steps 1-5 repeated for each of 10 jpeg objects 2: Application Layer
None-Persistent HTTP: Response time RTT (definition): time for a small packet to travel from client to server and back HTTP 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 • non-persistent HTTP response time = 2RTT+ file transmission time initiate TCP connection RTT request file RTT file received time time 2: Application Layer
Persistent HTTP non-persistent HTTP issues: • requires 2 RTTs per object • OS overhead for each TCP connection • browsers often open parallel TCP connections to fetch referenced objects persistent HTTP: • server leaves connection open after sending response • subsequent HTTP messages between same client/server sent over open connection 2: Application Layer
server leaves connection open after sending response subsequent HTTP messages between same client/server are sent over connection Persistent without pipelining: client issues new request only when previous response has been received one RTT for each referenced object Persistent with pipelining: default in HTTP/1.1 client sends requests as soon as it encounters a referenced object as little as one RTT for all the referenced objects Persistent HTTP 2: Application Layer
HTTP Request Format: Update • HTTP request message: • ASCII (human-readable format) carriage return character line-feed character request line (GET, POST, HEAD commands) 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 header lines carriage return, line feed at start of line indicates end of header lines
Authorization : control access to server content authorization credentials: typically name, password stateless: client must present authorization in each request authorization: header line in each request if no authorization: header, server refuses access, sends WWW authenticate: header line in response usual http request msg + Authorization: <cred> usual http request msg + Authorization: <cred> usual http response msg usual http response msg time User-server interaction: authorization server client usual http request msg 401: authorization req. WWW authenticate: 2: Application Layer
Many Web sites use cookies Example: You access Internet always from same PC You visit 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 Cookies: keeping “state” 2: Application Layer
Many major Web sites use cookies Four components: 1) cookie header line in the HTTP response message 2) cookie header line in HTTP request message 3) cookie file kept on user’s host and managed by user’s browser 4) back-end database at Web site Cookies: keeping “state” 2: Application Layer
client server usual http request msg usual http response + Set-cookie: 1678 Cookie file Cookie file Cookie file amazon: 1678 ebay: 8734 amazon: 1678 ebay: 8734 ebay: 8734 cookie- specific action usual http request msg cookie: 1678 usual http request msg cookie: 1678 usual http response msg usual http response msg cookie- spectific action Cookies: keeping “state” (cont.) server creates ID 1678 for user entry in backend database access access one week later: 2: Application Layer
What cookies can bring: authorization shopping carts recommendations user session state (Web e-mail) Cookies (continued) aside Cookies and privacy: • cookies permit sites to learn a lot about you • you may supply name and e-mail to sites • search engines use redirection & cookies to learn yet more • advertising companies obtain info across sites 2: Application Layer
Cookies: Enable/Disable 2: Application Layer
Cookies: Delelte 2: Application Layer
2.1 Principles of app layer protocols 2.2 Web and HTTP 2.3 FTP 2.4 Electronic Mail SMTP, POP3, IMAP 2.5 DNS 2.6 Content distribution Network Web caching Content distribution networks P2P file sharing 2.7 Cloud Chapter 2 outline 2: Application Layer
transfer file to/from remote host client/server model client: side that initiates transfer (either to/from remote) server: remote host ftp: RFC 959 ftp server: port 21 FTP user interface FTP client FTP server local file system FTP: the file transfer protocol file transfer user at host remote file system 2: Application Layer
FTP client contacts FTP server at port 21, specifying TCP as transport protocol Client obtains authorization over control connection Client browses remote directory by sending commands over control connection. When server receives a command for a file transfer, the server opens a TCP data connection to client After transferring one file, server closes connection. TCP control connection port 21 TCP data connection port 20 FTP client FTP server FTP: separate control, data connections • Server opens a second TCP data connection to transfer another file. • Control connection: “out of band” • FTP server maintains “state”: current directory, earlier authentication 2: Application Layer
Sample commands: sent as ASCII text over control channel USER username PASS password LISTreturn list of file in current directory RETR filenameretrieves (gets) file STOR filenamestores (puts) file onto remote host Sample return codes status code and phrase (as in HTTP) 331 Username OK, password required 125 data connection already open; transfer starting 425 Can’t open data connection 452 Error writing file FTP commands, responses 2: Application Layer
FTP Client Software 2: Application Layer