Chapter 2 Application Layer - UNSW School of Computer...

120
2: Application Layer 1 Chapter 2 Application Layer Computer Networking: A Top Down Approach, 4 th edition. Jim Kurose, Keith Ross Addison-Wesley, July 2007. A note on the use of these ppt slides: The notes used in this course are substantially based on powerpoint slides developed and copyrighted by J.F. Kurose and K.W. Ross, 2007

Transcript of Chapter 2 Application Layer - UNSW School of Computer...

Page 1: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 1

Chapter 2Application Layer

Computer Networking: A Top Down Approach, 4th edition. Jim Kurose, Keith RossAddison-Wesley, July 2007.

A note on the use of these ppt slides:The notes used in this course are substantially based on powerpoint slides developed and copyrighted by J.F. Kurose and K.W. Ross, 2007

Page 2: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 2

Chapter 2: Application Layer

2.1 Principles of network applications2.2 Web and HTTP2.3 FTP 2.4 Electronic Mail

SMTP, POP3, IMAP2.5 DNS

2.6 P2P Applications2.7 Socket programming with TCP2.8 Socket programming with UDP

Page 3: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 3

Chapter 2: Application LayerOur goals: Learn about protocols

by examining popular application-level protocols

HTTPFTPSMTP / POP3 / IMAPDNS

Programming network applications

Socket API

Conceptual, implementation aspects of network application protocols

Transport-layer service modelsClient-server paradigmPeer-to-peer paradigm

Page 4: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 4

Some Network Apps

e-mailwebinstant messagingremote loginP2P file sharingmulti-user network gamesstreaming stored video clips

voice over IPreal-time video conferencinggrid computing

Page 5: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 5

Creating a Network App applicationtransportnetworkdata linkphysical

applicationtransportnetworkdata linkphysical

applicationtransportnetworkdata linkphysical

Write programs thatRun on (different) end systemsCommunicate over networkE.g., web server software communicates with browser software

Little software written for devices in network core

Network core devices do not run user applications Applications on end systems allows for rapid app development, propagation

Page 6: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 6

Chapter 2: Application Layer

2.1 Principles of network applications2.2 Web and HTTP2.3 FTP 2.4 Electronic Mail

SMTP, POP3, IMAP2.5 DNS

2.6 P2P file sharing2.7 Socket programming with TCP2.8 Socket programming with UDP2.9 Building a Web server

Page 7: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 7

Application Architectures

Client-server

Peer-to-peer (P2P)

Hybrid of client-server and P2P

clientclient

client

Page 8: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 8

Client-Server ArchitectureServer:

Always-on hostPermanent IP addressServer farms for scaling

Clients:Communicate with serverMay be intermittently connectedMay have dynamic IP addressesDo not communicate directly with each other

client/server

Page 9: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 9

Pure P2P Architecture

No always-on serverArbitrary end systems directly communicatePeers are intermittently connected and change IP addressesExample: Gnutella

Highly scalable but difficult to manage

peer-peer

Page 10: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 10

Hybrid of Client-Server and P2PSkype

Voice-over-IP P2P applicationCentralized server: finding address of remote party Client-client connection: direct (not through server)

Instant messagingChatting between two users is P2PCentralized service: client presence detection/location

• User registers its IP address with central server when it comes online

• User contacts central server to find IP addresses of buddies

Page 11: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

Processes Communicating

Process: program running within a host.Within same host, two processes communicate using inter-process communication (defined by OS)Processes in different hosts communicate by exchanging messages

Client process: process that initiates communication

Server process: process that waits to be contacted

Note: applications with P2P architectures have client processes & server processes

2: Application Layer 11

Page 12: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 12

Sockets

Process sends/receives messages to/from its socketSocket analogous to door

Sending process shoves message out doorSending process relies on transport infrastructure on other side of door which brings message to socket at receiving process

controlled byapp developer

Internet

controlledby OS

API: (1) choice of transport protocol; (2) ability to fix a few parameters (lots more on this later)

process

TCP withbuffers,variables

socket

host orserver

process

TCP withbuffers,variables

socket

host orserver

Page 13: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 13

Addressing ProcessesTo receive messages, process must have identifierHost device has unique 32-bit IP addressQ: does IP address of host on which process runs suffice for identifying the process?Answer: NO, many processes can be running on same host

Instant Messenger

Web Browsing

Packet X

Page 14: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 14

Addressing ProcessesTo receive messages, process must have identifierHost device has unique 32-bit IP addressQ: does IP address of host on which process runs suffice for identifying the process?Answer: NO, many processes can be running on same host

Identifier includes both IP address and port numbersassociated with process on hostExample port numbers:

HTTP server: 80Mail server: 25

To send HTTP message to www.cs.ust.hk web server:

IP address: 143.89.40.4Port number: 80

More on this later

Page 15: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 15

App-Layer Protocol Defines

Public-domain protocols:Defined in RFCsAllows for interoperabilitye.g., HTTP, SMTP

Proprietary protocols:e.g., KaZaA

Types of messages exchanged

e.g., request, response Message syntax:

What fields in messages & how fields are delineated

Message semantics Meaning of information in fields

Rules for when and how processes send & respond to messages

Page 16: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 16

What Transport Service does an App Need?

Data lossSome apps (e.g., audio, video) can tolerate some lossOther apps (e.g., file transfer, telnet) require 100% reliable data transfer

TimingSome apps (e.g., Internet telephony, interactive games) require low delay to be “effective”

BandwidthSome apps (e.g., multimedia) require minimum amount of bandwidth to be “effective”Other apps (“elastic apps”) make use of whatever bandwidth they get (Best-Efforts)

Page 17: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 17

Transport Service Requirements of Common Apps

Application

file transfere-mail

Web documentsreal-time audio/video

stored audio/videointeractive gamesinstant messaging

Data loss

no lossno lossno lossloss-tolerant

loss-tolerantloss-tolerantno loss

Bandwidth

elasticelasticelasticaudio: 5kbps-1Mbpsvideo:10kbps-5Mbpssame as above few kbps upelastic

Time Sensitive

nononoyes, 100’s msec

yes, few secsyes, 100’s msecyes and no

Page 18: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 18

Internet Transport Protocols Services

high capacity receiver

congested network

congestion control problem

low capacity receiver

fast network

flow control problem

TCP service:Connection-oriented: setup required between client and server processesReliable transport between sending and receiving processFlow control: sender won’t overwhelm receiver Congestion control: throttle sender when network overloadedDoes not provide: timing, minimum bandwidth guarantees

Page 19: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 19

Internet Transport Protocols Services

TCP service:Connection-oriented: setup required between client and server processesReliable transport between sending and receiving processFlow control: sender won’t overwhelm receiver Congestion control: throttle sender when network overloadedDoes not provide: timing, minimum bandwidth guarantees

UDP service:Unreliable data transfer between sending and receiving processDoes not provide: connection setup, reliability, flow control, congestion control, timing, or bandwidth guarantee

Q: Why bother? Why is there a UDP?

A: Low latency, low overhead, simple

Page 20: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 20

Internet Apps: Application, Transport Protocols

Application

e-mailremote terminal access

Web file transfer

streaming multimedia

Internet telephony

Applicationlayer protocol

SMTP [RFC 2821]Telnet [RFC 854]HTTP [RFC 2616]FTP [RFC 959]proprietary(e.g. RealNetworks)proprietary(e.g., Vonage,Dialpad)

Underlyingtransport protocol

TCPTCPTCPTCPTCP or UDP

typically UDP

Page 21: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 21

Chapter 2: Application Layer

2.1 Principles of network applications

app architecturesapp requirements

2.2 Web and HTTP2.4 Electronic Mail

SMTP, POP3, IMAP2.5 DNS

2.6 P2P file sharing2.7 Socket programming with TCP2.8 Socket programming with UDP

Page 22: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 22

Web and HTTP

First some jargonWeb page consists of objectsObject can be HTML file, JPEG image, Java applet, audio file,…Web page consists of base HTML-file which includes several referenced objectsEach object is addressable by a URLExample URL:www.someschool.edu/someDept/pic.gif

host name path name

Page 23: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 23

Web and HTTP

First some jargon

User agent for Web is called a browser:MS Internet ExplorerNetscape CommunicatorFirefox web browser

Server for Web is called Web server:Apache (public domain)MS Internet Information Server

Page 24: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 24

HTTP Overview

HTTP: hypertext transfer protocolWeb’s application layer protocolClient/server model

Client: browser that requests, receives, “displays” Web objectsServer: web server sends objects in response to requests

HTTP 1.0: RFC 1945HTTP 1.1: RFC 2068

HTTP request

HTTP request

HTTP response

HTTP response

PC runningExplorer

Server running

Apache Webserver

Mac runningNavigator

Page 25: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 25

HTTP Overview (cont.)

HTTP is “stateless”Server maintains no information about past client requests

Uses TCP:Client initiates TCP connection (creates socket) to server, port 80Server accepts TCP connection from clientHTTP messages (application-layer protocol messages) exchanged between browser (HTTP client) and Web server (HTTP server)TCP connection closed

Protocols that maintain “state” are complex!Past history (state) must be maintainedIf server/client crashes, their views of “state” may be inconsistent, must be reconciled

aside

Page 26: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 26

HTTP Connections

Nonpersistent HTTPAt most one object is sent over a TCP connectionEach TCP connection is closed after the server sends the objectHTTP/1.0 uses nonpersistent HTTP

Persistent HTTPMultiple objects can be sent over single TCP connection between client and serverHTTP/1.1 uses persistent connections in default mode

Page 27: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 27

Nonpersistent HTTP(contains text,

references to 10 jpeg images)

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

Page 28: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 28

Nonpersistent HTTP (cont.)

time

4. HTTP server closes TCP connection.

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

Page 29: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 29

Non-Persistent HTTP: Response Time

Definition of RTT: time to send a small packet to travel from client to server and back

Response time:

time to transmit file

initiate TCPconnection

RTT

requestfile

RTT

filereceived

time

One RTT to initiate TCP connectionOne RTT for HTTP request and first few bytes of HTTP response to returnFile transmission time

total = 2RTT+transmit timetime

Page 30: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 30

Persistent HTTP

Nonpersistent HTTP issues:Requires 2 RTTs per objectOS overhead for each TCP connectionBrowsers often open parallel TCP connections to fetch referenced objects

Persistent HTTPServer leaves connection open after sending responseSubsequent HTTP messages between same client/server sent over open connection

Persistent without pipelining:Client issues new request only when previous response has been receivedOne RTT for each referenced object

Persistent with pipelining:Default in HTTP/1.1Client sends requests as soon as it encounters a referenced objectAs little as one RTT for all the referenced objects

Page 31: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 31

HTTP Request Message

Two types of HTTP messages: request, responseHTTP request message:

ASCII (human-readable format)

GET /somedir/page.html HTTP/1.1Host: www.someschool.edu User-agent: Mozilla/4.0Connection: close Accept-language:fr

(extra carriage return, line feed)

request line(GET, POST,

HEAD commands)

headerlines

Carriage return, line feed

indicates end of message

Page 32: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 32

HTTP Request Message: General Format

Empty with GET method

Is used with POST method

cr: carriage returnlf: line feed

Page 33: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 33

Uploading Form Input

Post method:Web page often includes form inputInput is uploaded to server in entity body

URL method:Uses GET methodInput is uploaded in URL field of request line:

www.somesite.com/animalsearch?monkeys&banana

Page 34: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 34

Method Types

HTTP/1.0GETPOSTHEAD

Similar to GET methodAsks server to leave requested object out of responseOften being used for debugging

HTTP/1.1GET, POST, HEADPUT

In conjunction with Web publishing toolUploads file in entity body to path specified in URL field

DELETEDeletes file specified in the URL field

Page 35: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 35

HTTP Response Message

HTTP/1.1 200 OK Connection: closeDate: 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 codestatus phrase)

headerlines

data, e.g., requestedHTML file

Page 36: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 36

HTTP Response Status CodesIn first line in server->client response messageA few sample codes:

200 OKRequest succeeded, requested object later in this message

301 Moved PermanentlyRequested object moved, new location specified later in this message (Location:)

400 Bad RequestRequest message not understood by server

404 Not FoundRequested document not found on this server

505 HTTP Version Not Supported

Page 37: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 37

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:By typing this in (hit carriagereturn twice), you sendthis minimal (but complete) GET request to HTTP server

GET /~ross/ HTTP/1.1Host: cis.poly.edu

3. Look at response message sent by HTTP server!

Page 38: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 38

User-Server State: Cookies

Why need cookies?HTTP server is stateless

• Simplify server design and handle thousands of simultaneous TCP connections

It is often desirable to identify users• Restrict user access• Serve content as a function of the user identity

Cookies [RFC 2109]Allow sites to keep track of users

Page 39: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 39

User-Server State: Cookies

Many major Web sites use cookies

Four components:

Example:Susan access Internet always from same PCShe visits a specific e-commerce site for first timeWhen initial HTTP requests arrives at site, site creates a unique ID and creates an entry in backend database for ID

1) Cookie header line of HTTP response message

2) Cookie header line in HTTP request message

3) Cookie file kept on user’s host, managed by user’s browser

4) Back-end database at Web site

Page 40: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 40

Cookies: Keeping “State” (cont.)

client serverusual http request msg

usual http response +Set-cookie: 1678

usual http request msgcookie: 1678

usual http response msg

usual http request msgcookie: 1678

usual http response msg

servercreates ID

1678 for user

Cookie file

ebay: 8734

entry in backend database

access

access

Cookie file

amazon: 1678ebay: 8734

cookie-specificaction

one week later:

Cookie file

amazon: 1678ebay: 8734

cookie-spectific

action

Page 41: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

Cookies (continued)What cookies can bring:

AuthorizationShopping cartsRecommendationsUser session state (Web e-mail) Cookies and privacy:

Cookies permit sites to learn a lot about youYou may supply name and e-mail to sites

aside

How to keep “state”:Protocol endpoints: maintain state at sender/receiver over multiple transactionsCookies: http messages carry state

2: Application Layer 41

Page 42: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 42

Cookie Exampletelnet www.google.com 80

Trying 216.239.33.99...Connected to www.google.com.Escape character is '^]'.

GET /index.html HTTP/1.0

HTTP/1.0 200 OKDate: Wed, 10 Sep 2004 08:58:55 GMTSet-Cookie:

PREF=ID=43bd8b0f34818b58:TM=1063184203:LM=1063184203:S=DDqPgTb56Za88O2y; expires=Sun, 17-Jan-203819:14:07 GMT; path=/; domain=.google.com

Page 43: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

Web Caches (Proxy Server)

User sets browser: Web accesses via cacheBrowser sends all HTTP requests to cache

Object in cache: cache returns object Else cache requests object from origin server, then returns object to client

Goal: satisfy client request without involving origin server

client

Proxyserver

clientorigin server

origin server

HTTP request

HTTP request

HTTP response

HTTP response

HTTP request

HTTP response

2: Application Layer 43

Page 44: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 44

More about Web Caching

Cache acts as both client and serverTypically cache is installed by ISP (university, company, residential ISP)

Why Web caching?Reduce response time for client request.Reduce traffic on an institution’s access link.Internet dense with caches: enables “poor”content providers to effectively deliver content (but so does P2P file sharing)

Page 45: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 45

Caching Example origin

serversPublic

Internet

institutionalnetwork 10 Mbps LAN

1.5 Mbps access link

Traffic density = La/R

AssumptionsAverage object size = 100,000 bitsAvg. request rate from institution’s browsers to origin servers = 15/secDelay from institutional router to any origin server and back to router = 2 sec

ConsequencesUtilization on LAN = 15%Utilization on access link = 100%Total delay = Internet delay + access delay + LAN delay

= 2 sec + minutes + milliseconds

Page 46: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 46

Caching Example (cont.)origin

serversPublic

Internet

institutionalnetwork 10 Mbps LAN

10 Mbps access link

Possible solutionIncrease bandwidth of access link to, say, 10 Mbps

ConsequencesUtilization on LAN = 15%Utilization on access link = 15%Total delay = Internet delay + access delay + LAN delay

= 2 sec + msecs + msecsOften a costly upgrade

Page 47: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 47

Caching Example (cont.)origin

serversPublic

Internet

institutionalnetwork 10 Mbps LAN

1.5 Mbps access link

institutionalcache

Install cacheSuppose hit rate is 0.4

Consequence40% requests will be satisfied almost immediately60% requests satisfied by origin serverUtilization of access link reduced to 60%, resulting in negligible delays (say 10 msec)Total avg delay = Internet delay + access delay + LAN delay = 0.6*(2.01) secs + 0.4*0.01seconds < 1.4 secs

Page 48: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 48

Conditional GETThe copy of an object residing in the cache may be stale cache server

HTTP request msgIf-modified-since:

<date>

HTTP responseHTTP/1.0

304 Not Modified

object not

modified

HTTP request msgIf-modified-since:

<date>

HTTP responseHTTP/1.0 200 OK

<data>

object modified

Goal: don’t send object if cache has up-to-date cached versionCache: specify date of cached copy in HTTP requestIf-modified-since:

<date>

Server: response contains no object if cached copy is up-to-date: HTTP/1.0 304 Not

Modified

Page 49: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 49

Chapter 2: Application Layer

2.1 Principles of network applications2.2 Web and HTTP2.3 FTP2.4 Electronic Mail

SMTP, POP3, IMAP2.5 DNS

2.6 P2P file sharing2.7 Socket programming with TCP2.8 Socket programming with UDP2.9 Building a Web server

Page 50: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 50

FTP: the File Transfer Protocol

Transfer file to/from remote hostClient/server model

Client: side that initiates transfer (either to/from remote)Server: remote host

Ftp: RFC 959Ftp server: port 21

file transferFTP

serverFTPuser

interface

FTPclient

local filesystem

remote filesystem

user at host

Page 51: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 51

FTP: Separate Control, Data Connections

FTP client contacts FTP server at port 21, specifying TCP as transport protocolClient obtains authorization over control connectionClient browses remote directory by sending commands over control connection.When server receives file transfer command, server opens 2nd TCP connection (for file) to clientAfter transferring one file, server closes data connection.

TCP control connectionport 21

TCP data connectionport 20

Server opens another TCP data connection to transfer another file.Control connection: “out of band”FTP server maintains “state”: current directory, earlier authentication

FTPclient

FTPserver

Page 52: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 52

FTP Commands, Responses

Sample commands:Sent as ASCII text over control channelUSER usernamePASS password

LIST return list of file in current directoryRETR filename retrieves (gets) fileSTOR filename stores (puts) file onto remote host

Sample return codesstatus code and phrase (as in HTTP)331 Username OK, password required125 data connection already open; transfer starting425 Can’t open data connection452 Error writing file

Page 53: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 53

Chapter 2: Application Layer

2.1 Principles of network applications2.2 Web and HTTP2.3 FTP 2.4 Electronic Mail

SMTP, POP3, IMAP2.5 DNS

2.6 P2P file sharing2.7 Socket programming with TCP2.8 Socket programming with UDP2.9 Building a Web server

Page 54: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 54

Electronic Mailuser mailbox

outgoing message queue

useragent

useragent

useragent

useragent

useragent

useragent

mailserver

mailserver

mailserver

SMTP

SMTP

SMTP

Three major components:User agents Mail servers Simple mail transfer protocol: SMTP

User Agenta.k.a. “mail reader”Composing, editing, reading mail messagese.g., Eudora, Outlook, elm, Netscape MessengerOutgoing, incoming messages stored on server

Page 55: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 55

Electronic Mail: Mail Servers

Mail ServersMailbox contains incoming messages for userMessage queue of outgoing (to be sent) mail messagesSMTP protocol between mail servers to send email messages

Client: sending mail serverServer: receiving mail server

useragent

useragent

useragent

useragent

useragent

useragent

mailserver

mailserver

mailserver

SMTP

SMTP

SMTP

user mailbox

outgoing message queue

Page 56: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 56

Electronic Mail: SMTP [RFC 2821]

Uses TCP to reliably transfer email message from client to server, port 25Direct transfer: sending server to receiving serverThree phases of transfer

Handshaking (greeting)Transfer of messagesClosure

Command/response interactionCommands: ASCII textResponse: status code and phrase

Messages must be in 7-bit ASCII

Page 57: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 57

Scenario: Alice sends Message to Bob4) 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

1) Alice uses UA to compose message and “to”[email protected]

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

mailserver

mailserver user

agent

1

2 3 4 56

useragent

Page 58: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 58

Sample SMTP InteractionS: 220 hamburger.edu C: HELO crepes.fr S: 250 Hello crepes.fr, pleased to meet you C: MAIL FROM: <[email protected]> S: 250 [email protected]... Sender ok C: RCPT TO: <[email protected]> S: 250 [email protected] ... 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

Page 59: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 59

Try SMTP Interaction for Yourself:

telnet servername 25See 220 reply from serverEnter HELO, MAIL FROM, RCPT TO, DATA, QUIT commandsabove lets you send email without using email client (reader)

Page 60: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 60

SMTP: Final Words

SMTP uses persistent connectionsSMTP requires message (header & body) to be in 7-bit ASCIISMTP server uses CRLF.CRLF to determine end of message

Comparison with HTTP:HTTP: pullSMTP: push

Both have ASCII command/response interaction, status codes

HTTP: each object encapsulated in its own response msgSMTP: multiple objects sent in multipart msg

Page 61: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 61

Mail Message Format

SMTP: protocol for exchanging email msgs

RFC 822: standard for text message format:Header lines, e.g.,

To:From:Subject:

different from SMTP commands!

BodyThe “message”, ASCII characters only

header

body

blankline

Page 62: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 62

Message Format: Multimedia Extensions

MIME: multimedia mail extension, RFC 2045, 2056Additional lines in msg header declare MIME content type

From: [email protected] To: [email protected] Subject: Picture of yummy crepe. MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Type: image/jpeg

base64 encoded data ..... ......................... ......base64 encoded data

multimedia datatype, subtype,

parameter declaration

encoded data

MIME version

method usedto encode data

Page 63: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 63

MIME TypesContent-Type: type/subtype; parameters

TextExample subtypes: plain, html

ImageExample subtypes: jpeg, gif

AudioExampe subtypes: basic(8-bit mu-law encoded), 32kadpcm (32 kbps coding)

VideoExample subtypes: mpeg, quicktime

ApplicationOther data that must be processed by reader before “viewable”Example subtypes: msword, octet-stream

Page 64: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 64

Multipart TypeFrom: [email protected]: [email protected]: Picture of yummy crepe. MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=StartOfNextPart

--StartOfNextPartDear Bob, Please find a picture of a crepe.--StartOfNextPartContent-Transfer-Encoding: base64Content-Type: image/jpegbase64 encoded data ..... ......................... ......base64 encoded data --StartOfNextPartDo you want the recipe?

Page 65: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 65

Mail Access Protocols

SMTP: delivery/storage to receiver’s serverMail access protocol: retrieval from server

POP: Post Office Protocol [RFC 1939]• Authorization (agent <-->server) and download

IMAP: Internet Mail Access Protocol [RFC 1730]• More features (more complex)• Manipulation of stored msgs on server

HTTP: Hotmail , Yahoo! Mail, etc.

SMTP SMTP accessprotocol

sender’s mail server

useragent

receiver’s mail server

useragent

Page 66: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 66

POP3 Protocol

Authorization phaseClient commands:

user: declare usernamepass: password

Server responses+OK

-ERR

Transaction phase, client:list: list message numbersretr: retrieve message by numberdele: deletequit

C: list S: 1 498 S: 2 912 S: . C: retr 1 S: <message 1 contents>S: . C: dele 1 C: retr 2 S: <message 1 contents>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

Page 67: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 67

POP3 (more) and IMAPMore about POP3

Previous example uses “download and delete”modeBob cannot re-read e-mail if he changes client“Download-and-keep”: copies of messages on different clientsPOP3 is stateless across sessions

IMAPKeep all messages in one place: the serverAllows user to organize messages in foldersIMAP keeps user state across sessions:

names of folders and mappings between message IDs and folder name

Page 68: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 68

Chapter 2: Application Layer

2.1 Principles of network applications2.2 Web and HTTP2.3 FTP 2.4 Electronic Mail

SMTP, POP3, IMAP2.5 DNS

2.6 P2P file sharing2.7 Socket programming with TCP2.8 Socket programming with UDP2.9 Building a Web server

Page 69: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 69

DNS: Domain Name System

People: many identifiers:SSN, name, passport #

Internet hosts, routers:IP address (32 bit) -used for addressing datagrams“Name”, e.g., ww.yahoo.com - used by humans

Q: map between IP addresses and name ?

Domain Name System:Distributed databaseimplemented in hierarchy of many name serversApplication-layer protocolhost, routers, name servers to communicate to resolve names (address/name translation)

Note: core Internet function, implemented as application-layer protocolComplexity at network’s “edge”

Page 70: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 70

DNS Why not centralize DNS?DNS services

Single point of failureTraffic volumeDistant centralized databaseMaintenance

Doesn’t Scale!

Hostname to IP address translationHost aliasing

Canonical and alias names

Mail server aliasingLoad distribution

Replicated Web servers: set of IP addresses for one canonical name

Page 71: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 71

Distributed, Hierarchical DatabaseRoot DNS Servers

com DNS servers org DNS servers edu DNS servers

poly.eduDNS servers

umass.eduDNS serversyahoo.com

DNS serversamazon.comDNS servers

pbs.orgDNS servers

Client wants IP for www.amazon.com; 1st approx:Client queries a root server to find com DNS server (top-level domain)Client queries com DNS server to get amazon.com DNS server (authoritative)Client queries amazon.com DNS server to get IP address for www.amazon.com

Page 72: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 72

DNS: Root Name ServersContacted by local name server that can not resolve nameRoot name server:

Contacts authoritative name server if name mapping not knownGets mappingReturns mapping to local name server

13 root name servers worldwide

b USC-ISI Marina del Rey, CAl ICANN Los Angeles, CA

e NASA Mt View, CAf Internet Software C. Palo Alto, CA (and 36 other locations)

i Autonomica, Stockholm (plus 3 other locations)

k RIPE London (also Amsterdam, Frankfurt)

m WIDE Tokyo

a Verisign, Dulles, VAc Cogent, Herndon, VA (also Los Angeles)d U Maryland College Park, MDg US DoD Vienna, VAh ARL Aberdeen, MDj Verisign, ( 21 locations)

Page 73: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 73

TLD and Authoritative Servers

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 TLDEducause for edu TLD

Authoritative DNS servers: organization’s DNS servers, providing authoritative hostname to IP mappings for organization’s servers (e.g., Web and mail)

Can be maintained by organization or service provider

Page 74: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 74

Local Name Server

Does not strictly belong to hierarchyEach ISP (residential ISP, company, university) has one

Also called “default name server”When a host makes a DNS query, query is sent to its local DNS server

Acts as a proxy, forwards query into hierarchy

Page 75: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 75

requesting hostcis.poly.edu

gaia.cs.umass.edu

root DNS server

local DNS serverdns.poly.edu

23

4

5

6781

authoritative DNS serverdns.cs.umass.edu

TLD DNS server

Example

Host at cis.poly.edu wants IP address for gaia.cs.umass.edu

Recursive query

Iterated query

Page 76: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 76

Recursive QueriesRecursive query:

Puts burden of name resolution on contacted name serverHeavy load?

Iterated query:Contacted server replies with name of server to contact“I don’t know this name, but ask this server”

requesting hostcis.poly.edu

gaia.cs.umass.edu

root DNS server

local DNS serverdns.poly.edu

1

2

45

6

authoritative DNS serverdns.cs.umass.edu

7

8

TLD DNS server

3

Recursive query

Page 77: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 77

DNS: Caching and Updating Records

Once (any) name server learns mapping, it cachesmapping

Cache entries timeout (disappear) after some timeTLD servers typically cached in local name servers

• Thus root name servers not often visitedUpdate/notify mechanisms under design by IETF

RFC 2136 (Dynamic Updates in the Domain Name System (DNS UPDATE))http://www.ietf.org/html.charters/dnsext-charter.html (DNS Extensions)

Page 78: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 78

DNS RecordsDNS: distributed db storing resource records (RR)

RR format: (name, value, type, ttl)

Type=NSname is domainvalue is hostname of authoritative name server for this domainE.g., (ibm.com,dns.ibm.com, NS)

Type=Aname is hostnamevalue is IP addressE.g., (servereast.backup2. ibm.com,129.42.60.212,A)

Type=CNAMEname is alias name for some “canonical” (the real) namevalue is canonical nameE.g., (ibm.com,servereast. backup2.ibm.com,CNAME)

Type=MXvalue is name of mailserver associated with nameE.g., (ibm.com, mail. backup2.ibm.com, MX)

Page 79: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 79

DNS Protocol, MessagesDNS protocol : query and reply messages, both with

same message format

Msg headeridentification: 16 bit # for query, reply to query uses same #flags:

query or reply indicationrecursion desired (client)recursion available (DNS server)reply is authoritative

Page 80: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 80

DNS Protocol, Messages

Name, type fieldsfor a query

RRs in responseto query

records forauthoritative servers

additional “helpful”info that may be used

Try nslookuphttp://network-tools.com/nslook/Default.asp

Page 81: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 81

Inserting Records into DNS

Example: just created startup “Network Utopia”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)

Put in authoritative server Type A record for www.networkuptopia.com and Type MX record for networkutopia.comHow do people get the IP address of your Web site?

Page 82: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 82

Get IP address of your Web Site

www.networkutopia.com

Local DNS server

TLD com server(networkutopia.com, dns1.networkutopia.com, NS)(dns1.networkutopia.com, 212.212.212.1, A)

212.212.212.1212.212.71.4

212.212.71.4

Page 83: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 83

Chapter 2: Application layer

2.1 Principles of network applications

app architecturesapp requirements

2.2 Web and HTTP2.4 Electronic Mail

SMTP, POP3, IMAP2.5 DNS

2.6 P2P file sharing2.7 Socket programming with TCP2.8 Socket programming with UDP2.9 Building a Web server

Page 84: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 84

P2P File Sharing

ExampleAlice runs P2P client application on her notebook computerIntermittently connects to Internet; gets new IP address for each connectionAsks for “Hey Jude”Application displays other peers that have copy of Hey Jude

Alice chooses one of the peers, Bob.File is copied from Bob’s PC to Alice’s notebook: HTTPWhile Alice downloads, other users uploading from AliceAlice’s peer is both a Web client and a transient Web server

All peers are servers = highly scalable!

Page 85: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 85

P2P: Centralized Directory

Original “Napster” design1) When peer connects, it

informs central server:IP addressContent

2) Alice queries for “Hey Jude”

3) Alice requests file from Bob

centralizeddirectory server

peers

Alice

Bob

1

1

1

12

3

Page 86: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 86

P2P: Problems with Centralized Directory

Single point of failurePerformance bottleneckCopyright infringement

File transfer is decentralized, but locating content is highly centralized

Page 87: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 87

Query Flooding: Gnutella

Overlay network: graphEdge between peer X and Y if there’s a TCP connectionAll active peers and edges is overlay netEdge is not a physical linkGiven peer will typically be connected with < 10 overlay neighbors

Fully distributedNo central server

Public domain protocolMany Gnutella clients implementing protocol

Page 88: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 88

Gnutella: Protocol

Query

QueryHit

Query

Query

QueryHit

Query

Query

QueryH

it

File transfer:HTTPQuery message

sent over existing TCPconnections

Peers forwardQuery message

QueryHit sentover reversepath

Scalability:limited scope flooding

Page 89: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 89

Gnutella: Peer Joining

1. Joining peer X must find some other peer in Gnutella network: (bootstrap problem)use list of candidate peers (maintain in X or Gnutella site)

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!

Page 90: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 90

Hierarchical Overlay

ordinary peer

group-leader peer

neighoring relationshipsin overlay network

Between centralized index, query flooding approachesEach 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.

Group leader tracks content in its children

Page 91: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 91

Comparing Client-Server, P2P ArchitecturesQuestion : How much time distribute file

initially at one server to N other computers?us: server upload bandwidth

us

u2d1 d2u1

Serverui: client/peer i upload bandwidth

uN

dN Network (with abundant bandwidth)

di: client/peer i download bandwidthFile, size F

Page 92: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 92

Client-Server: File Distribution Time

us

u2d1 d2u1

uN

dN

Server

Network (with abundant bandwidth)

FServer sequentially sends N copies:

NF/us time Client i takes F/ditime to download

= dcs = max { NF/us, F/min(di) }i

Time to distribute Fto N clients using

client/server approach

increases linearly in N(for large N)

Page 93: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 93

P2P: File Distribution Time

us

u2d1 d2u1

uN

dN

Server

Network (with abundant bandwidth)

FServer must send one copy: F/us time Client i takes F/di time to downloadNF bits must be downloaded (aggregate)

Fastest possible upload rate (assuming all nodes sending file chunks to same peer): us + Σuii=1,N

dP2P = max { F/us, F/min(di) , NF/(us + Σui) }i i=1,N

Page 94: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 94

Comparing Client-Server, P2P Architectures

0

0.5

1

1.5

2

2.5

3

3.5

0 5 10 15 20 25 30 35

N

Min

imum

Dis

tribu

tion

Tim

e P2PClient-Server

Page 95: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 95

P2P Case Study: BitTorrent

tracker: tracks peers participating in torrent

torrent: group of peers exchanging chunks of a file

obtain listof peers

trading chunks

peer

P2P file distribution

Page 96: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 96

BitTorrent (1)

File divided into 256KB chunksPeer joining torrent:

Has no chunks, but will accumulate themover timeRegisters with tracker to get list of peers, connects to subset of peers (“neighbors”)

While downloading, peer uploads chunks to other peersPeers may come and goOnce peer has entire file, it may (selfishly) leave or (altruistically) remain

Page 97: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 97

BitTorrent (2)Pulling Chunks

At any given time, different peers have different subsets of file chunksPeriodically, a peer (Alice) asks each neighbor for list of chunks that they have.Alice issues requests for her missing chunks

rarest first

Sending Chunks: tit-for-tatAlice sends chunks to four neighbors currently sending her chunks at the highest rate

re-evaluate top 4 every 10 secs

every 30 secs: randomly select another peer, starts sending chunks

newly chosen peer may join top 4

Page 98: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 98

P2P Case Study: SkypeSkype clients (SC)

Supernode(SN)

Skype login server

P2P (pc-to-pc, pc-to-phone, phone-to-pc) Voice-Over-IP (VoIP) application

also IMProprietary application-layer protocol (inferred via reverse engineering) Hierarchical overlay

Page 99: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 99

Skype: Making a Call

User starts Skype

Skype login server

SC registers with SNlist of bootstrap SNs

SC logs in (authenticate)Call: SC contacts SN will callee ID

SN contacts other SNs(unknown protocol, maybe flooding) to find addr of callee; returns addr to SC

SC directly contacts callee, overTCP

Page 100: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 100

Chapter 2: Application layer

2.1 Principles of network applications2.2 Web and HTTP2.3 FTP 2.4 Electronic Mail

SMTP, POP3, IMAP2.5 DNS

2.6 P2P file sharing2.7 Socket programming with TCP2.8 Socket programming with UDP

Page 101: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 101

Socket ProgrammingGoal: learn how to build client/server application that

communicate using sockets

Socket APIIntroduced in BSD4.1 UNIX, 1981Explicitly created, used, released by apps Client/server paradigm 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

Page 102: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 102

Socket-Programming using TCPSocket: a door between application process and end-

end-transport protocol (UCP or TCP)TCP service: reliable transfer of bytes from one

process to another

controlled byapplicationdeveloper

controlled byapplicationdeveloper

process

TCP withbuffers,variables

socketprocess

TCP withbuffers,variables

socket

Internetcontrolled byoperatingsystem

controlled byoperating

system

host orserver

host orserver

Page 103: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 103

Socket Programming with TCPClient must contact server

Server process must first be runningServer must have created socket (door) that welcomes client’s contact

Client contacts server by:Creating client-local TCP socketSpecifying IP address, port number of server processWhen client creates socket: client TCP establishes connection to server TCP

When contacted by client, server TCP creates new socket for server process to communicate with client

Allows server to talk with multiple clientsSource port numbers used to distinguish clients (more in Chap 3)

TCP provides reliable, in-ordertransfer of bytes (“pipe”) between client and server

application viewpoint

Page 104: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 104

Stream Jargon

A stream is a sequence of characters that flow into or out of a process

An input stream is attached to some input source for the process, e.g., keyboard or socket

An output stream is attached to an output source, e.g., monitor or socket

Page 105: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 105

Socket Programming with TCP

outT

oSer

ver

to network from network

inFr

omS

erve

r

inFr

omU

ser

keyboard monitor

Process

clientSocket

inputstream

inputstream

outputstream

TCPsocket

Clientprocess

client TCP socket

Example client-server app:1) Client reads line from

standard input (inFromUserstream) , sends to server via socket (outToServerstream)

2) Server reads line from socket3) Server converts line to

uppercase, sends back to client

4) Client reads, prints modified line from socket (inFromServer stream)

Page 106: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 106

Client/Server Socket Interaction: TCPServer (running on hostid) Client

wait for incomingconnection requestconnectionSocket =welcomeSocket.accept()

create socket,port=x, forincoming request:welcomeSocket =

ServerSocket()

create socket,connect to hostid, port=xclientSocket =

Socket()

closeconnectionSocket

read reply fromclientSocket

closeclientSocket

send request usingclientSocketread request from

connectionSocket

write reply toconnectionSocket

TCP connection setup

Page 107: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

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());

Createinput stream

Create client socket,

connect to serverCreate

output streamattached to socket

2: Application Layer 107

Page 108: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

Example: Java Client (TCP), cont.

BufferedReader inFromServer = new BufferedReader(newInputStreamReader(clientSocket.getInputStream()));

sentence = inFromUser.readLine();

outToServer.writeBytes(sentence + '\n');

modifiedSentence = inFromServer.readLine();

System.out.println("FROM SERVER: " + modifiedSentence);

clientSocket.close();

} }

Createinput stream

attached to socket

Send lineto server

Read linefrom server

2: Application Layer 108

Page 109: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 109

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(newInputStreamReader(connectionSocket.getInputStream()));

Createwelcoming socket

at port 6789

Wait, on welcomingsocket for contact

by client

Create inputstream, attached

to socket

Page 110: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

Example: Java Server (TCP), cont

DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());

clientSentence = inFromClient.readLine();

capitalizedSentence = clientSentence.toUpperCase() + '\n';

outToClient.writeBytes(capitalizedSentence); }

} }

Read in linefrom socket

Create outputstream, attached

to socket

Write out lineto socket

End of while loop,loop back and wait foranother client connection

2: Application Layer 110

Page 111: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 111

Chapter 2: Application Layer

2.1 Principles of network applications2.2 Web and HTTP2.3 FTP 2.4 Electronic Mail

SMTP, POP3, IMAP2.5 DNS

2.6 P2P file sharing2.7 Socket programming with TCP2.8 Socket programming with UDP2.9 Building a Web server

Page 112: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 112

Socket Programming with UDP

UDP: no “connection” between client and serverNo handshakingSender explicitly attaches IP address and port of destination to each packetServer 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 unreliabletransfer of groups of bytes (“datagrams”)

between client and server

Page 113: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 113

Client/Server Socket Interaction: UDP

closeclientSocket

Server (running on hostid)

read reply fromclientSocket

create socket,clientSocket = DatagramSocket()

Client

Create, address (hostid, port=x,send datagram request using clientSocket

create socket,port=x, forincoming request:serverSocket = DatagramSocket()

read request fromserverSocket

write reply toserverSocketspecifying clienthost address,port number

Page 114: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 114

Example: Java Client (UDP)

send

Pac

ket

to network from network

rece

iveP

acke

t

inFr

omU

ser

keyboard monitor

Process

clientSocket

UDPpacket

inputstream

UDPpacket

UDPsocket

Output: sends packet (recallthat TCP sent “byte stream”)

Input: receives packet (recall thatTCP received “byte stream”)

Clientprocess

client UDP socket

Page 115: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

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();

Createinput stream

Create client socket

Translatehostname to IP

address using DNS

2: Application Layer 115

Page 116: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

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 datagramto server

Read datagramfrom server

2: Application Layer 116

Page 117: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 117

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);

Createdatagram socket

at port 9876

Create space forreceived datagram

Receivedatagram

Page 118: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

Example: Java Server (UDP), cont

2: Application Layer 118

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 addrport #, of

sender

Write out datagramto socket

End of while loop,loop back and wait foranother datagram

Create datagramto send to client

Page 119: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 119

Chapter 2: Summaryour study of network apps now complete!

Application architecturesClient-serverP2PHybrid

Application service requirements:

Reliability, bandwidth, delayInternet transport service model

Connection-oriented, reliable: TCPUnreliable, datagrams: UDP

Specific protocols:HTTPFTPSMTP, POP, IMAPDNSP2P: BitTorrent, Skype

Socket programming

Page 120: Chapter 2 Application Layer - UNSW School of Computer ...qianzh/COMP561-Fall2008/notes/Chapter2_2008.pdf · Chapter 2: Application Layer 2.1 Principles of network applications app

2: Application Layer 120

Chapter 2: SummaryMost importantly: learned about protocols

Typical request/reply message exchange:

Client requests info or serviceServer responds with data, status code

Message formats:Headers: fields giving info about dataData: info being communicated

Important themes: Control vs. data msgs

In-band, out-of-bandCentralized vs. decentralized Stateless vs. statefulReliable vs. unreliable msg transfer “Complexity at network edge”