Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

302
Application Layer ( Application Layer ( 2-89-90) 2-89-90) 2- 2-1 . Application Layer Computer Networks Computer Networks

Transcript of Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Page 1: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-11

.

Application Layer

Computer NetworksComputer Networks

Page 2: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-22

2.1 Principles of app layer protocols clients and servers app requirements

2.2 Web and HTTP 2.3 FTP 2.4 Electronic Mail

SMTP, POP3, IMAP 2.5 DNS

2.6 Socket programming with TCP

2.7 Socket programming with UDP

2.8 Building a Web server

2.9 Content distribution Network Web caching Content distribution

networks P2P file sharing

Chapter 2 OutlineChapter 2 Outline

Page 3: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-33

within same host, two processes communicate using inter-process communication (defined by OS).

processes running in different hosts communicate with an application-layer protocol

implements user interface & application-level protocol Web: browser E-mail: mail reader streaming

audio/video: media player

Process: program running within a host.

user agent: interfaces with user “above” and network “below”.

Network ApplicationsNetwork Applications

Page 4: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-44

Network Application ArchitecturesNetwork Application Architectures

Client-Server Architecture P2P Architecture Hybrid of the Client-Server and P2P

Architecture.

Page 5: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-55

Typical network app has two pieces: client and server

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

Client-Server ParadigmClient-Server Paradigm

Server process

application

transportnetworkdata linkphysical

reply

request

client process

application

transportnetworkdata linkphysical

Page 6: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-66

Pure P2P architecturePure P2P architecture

Arbitrary end systems directly communicate

Peers are intermittently connected and change IP addresses

Example: Gnutella

Highly scalable But difficult to manage

Page 7: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-77

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.

Applications and Application-Layer ProtocolsApplications and Application-Layer Protocols

Server process

application

transportnetworkdata linkphysical

Server process

application

transportnetworkdata linkphysical

Server process

application

transportnetworkdata linkphysical

Page 8: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-88

Types of messages exchanged: request & response messages

Syntax of message types: what fields in messages & how fields are delineated

Semantics of the fields: meaning of information in fields

Rules for when and how processes send & respond to messages

Types of messages exchanged: request & response messages

Syntax of message types: what fields in messages & how fields are delineated

Semantics of the fields: 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, Napster, KaZaA,

Public-domain protocols:

defined in RFCs allows for

interoperability eg, HTTP, SMTP

Proprietary protocols: eg, Napster, KaZaA,

Application-Layer ProtocolsApplication-Layer Protocols

Page 9: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-99

For a process to receive messages, it must have an identifier

Every host has a unique 32-bit IP address

Q: does the IP address of the host on which the process runs suffice for identifying the process?

Answer: No, many processes can be running on same host

For a process to receive messages, it must have an identifier

Every host has a unique 32-bit IP address

Q: does the IP address of the host on which the process runs suffice for identifying the process?

Answer: No, many processes can be running on same host

Identifier includes both the IP address and port numbers associated with the process on the host.

Example port numbers: HTTP server: 80 Mail server: 25

Example IP address: 113.45.12.201

Example Identifier: (80; 113.45.12.201)

Process IdentifierProcess Identifier

Page 10: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-1010

2.1 Principles of app layer protocols clients and servers app requirements

2.2 Web and HTTP 2.3 FTP 2.4 Electronic Mail

SMTP, POP3, IMAP 2.5 DNS

2.6 Socket programming with TCP

2.7 Socket programming with UDP

2.8 Building a Web server

2.9 Content distribution Network Web caching Content distribution

networks P2P file sharing

Chapter 2 OutlineChapter 2 Outline

Page 11: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-1111

What is a Web BrowserWhat is a Web Browser

It is a software application that enables a user to display

and interact with html, text, images, audio, and other

information typically located on a web page at a web server.

Text and images on a web page can contain hyperlinks to

other web pages at the same or different websites.

Web browsers allow a user to quickly and easily access

information provided on many web pages at many websites

by traversing these links.

Web browser hides http underneath a nice GUI.

Browser must handle server error messages in some

elegant way.

Page 12: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-1212

Web BrowsersWeb Browsers

Mozilla Firefox

Microsoft Internet Explorer

Google Chrome

AOL Netscape

Opera

Apple Safari

Flock

Page 13: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-1313

What is a Web Server?What is a Web Server?

The term Web server can mean one of two things:

A computer or A program that is: responsible for accepting HTTP requests from

clients, which are known as Web browsers, and serving them HTTP responses along with optional data contents, which usually are Web pages such as HTML documents and linked objects (images, etc.).

The term Web server can mean one of two things:

A computer or A program that is: responsible for accepting HTTP requests from

clients, which are known as Web browsers, and serving them HTTP responses along with optional data contents, which usually are Web pages such as HTML documents and linked objects (images, etc.).

Page 14: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-1414

Modern Web ServersModern Web Servers

On client side, higher-end client capabilities: Java applets DHTML (css, xml, javascript, etc). Increased form support in http multimedia (flash, etc.)

On client side, higher-end client capabilities: Java applets DHTML (css, xml, javascript, etc). Increased form support in http multimedia (flash, etc.)

On server side, this led to: dynamic web pages – asp, jsp, servlets, Cold Fusion,

PHP, etc. improvements in cgi

On server side, this led to: dynamic web pages – asp, jsp, servlets, Cold Fusion,

PHP, etc. improvements in cgi

Page 15: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-1515

Market Share for Top Servers Across All Domains Market Share for Top Servers Across All Domains

Source: http://news.netcraft.com/

Page 16: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-1616

Total Sites Across All DomainTotal Sites Across All Domain

, ,

Page 17: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-1717

URIs, URLs and URNsURIs, URLs and URNs

Uniform Resource Identifier (URI = URL or URN) Generic term for all textual names/addresses

Uniform Resource Locator (URL) The set of URI schemes that have explicit instructions

on how to access the resource over the Internet, e.g. http, ftp, gopher

Uniform Resource Name (URN) is location-independent resource identifier urn: ietf: rfc:3187 urn: isbn: 0451450523

Page 18: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-1818

Web page consists of objects Object can be HTML file, JPEG image, Java

applet, audio file,… Web page consists of base HTML-file which

includes several referenced objects Each object is addressable by a URL Example URL:

Web page consists of objects Object can be HTML file, JPEG image, Java

applet, audio file,… Web page consists of base HTML-file which

includes several referenced objects Each object is addressable by a URL Example URL:

http://www.iust.ac.ir/computer/home.html

host name path name

WebWeb

Page 19: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-1919

HTTP: hypertext transfer protocol

Web’s app 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

PC runningExplorer

Server running

Apache Webserver

Mac runningNavigator

HTTP request

HTTP request

HTTP response

HTTP response

Storagecontents:base files, objects

HTTP OverviewHTTP Overview

Page 20: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-2020

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

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

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

aside

HTTP Overview (cont.)HTTP Overview (cont.)

Page 21: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-2121

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 ConnectionsHTTP Connections

Page 22: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-2222

Suppose user enters URL www.iust.ac.ir/computer/home.html

Suppose user enters URL www.iust.ac.ir/computer/home.html

1. HTTP client initiates TCP connection to HTTP server (process) at www.iust.ac.ir on port 80

3. HTTP client sends HTTP request message (containing URL) into TCP connection socket. Message indicates that client wants object Computer//home.html

2. HTTP server at host www.iust.ac.ir waiting for TCP connection at port 80. “accepts” connection, notifying client

4. 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)

(contains text, references to 10

jpeg images)

Non-persistent HTTPNon-persistent HTTP

Next slide

Page 23: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-2323

5. HTTP client receives response message containing html file, displays html. Parsing html file, finds 10 referenced jpeg objects

7. Steps 1-6 repeated for each of 10 jpeg objects

6. HTTP server closes TCP connection.

time

4. …

Non-persistent HTTP (cont.)Non-persistent HTTP (cont.)

Page 24: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-2424

Non-Persistent &Parallel ConnectionsNon-Persistent &Parallel Connections

1. Clients creates first TCP connection and then ask for the base file.

2. Client creates several TCP connections with the server(s) simultaneously.

3. Client requests one object on each connection.

4. Each TCP connection is terminated when the requested object is retrieved.

Page 25: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-2525

Persistent HTTP Without Pipeline1Persistent HTTP Without Pipeline1

time to transmit base file

initiate TCP connection

RTT

Request base (html) file

RTT

Base file received

time

Request first object

time to transmit first object

First object received

Second object received

Request second object

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

Page 26: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-2626

Response Time: one RTT to initiate TCP

connection one RTT for HTTP

request and first few bytes of HTTP response to return

Time ≈ (N+2)RTT + (N+1) file transmit time

N = number of objects in the web page.

time to transmit base file

initiate TCPconnection

RTT

requestbase file

RTT

base filereceived

time

Response Time Model (Per.-no pip.)Response Time Model (Per.-no pip.)

Page 27: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-2727

Persistent HTTP With Pipeline Persistent HTTP With Pipeline default in HTTP/1.1

time to transmit base file

initiate TCP connection

RTT

Request base (html) file

RTT

Base file received

time

1- Request first object2- Request second object…10- Tenth second object

time to transmit first object

First object received

Tenth object received

Response Time ≈ 3RTT+ (N+1) file transmit timeResponse Time ≈ 3RTT+ (N+1) file transmit time

1210

Page 28: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-2828

method

SP URL SP versionCR

LFheader field name : valu

eCR LF

--- - --- --- ---

header field name : value

CR LFCR

LF

request line

header lines

HTTP HTTP RequestRequest Message: General Message: General FormatFormat

http

Head

er

Entity Body(Application Message, Object, …)

Page 29: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-2929

version SPstatus code

SP phrase CR LFheader field name : valu

eCR LF

--- - --- --- ---

header field name : value

CR LFCR

LF

status line

header lines

Entity Body(Application Message, Object, …)

HTTP HTTP ResponseResponse Message: General Format Message: General Formath

ttp H

ead

er

Page 30: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-3030

HTTP request message: ASCII (human-readable format)

GET /somedir/page.html HTTP/1.1Host: www.someschool.edu User-agent: Mozilla/5.0Connection: close Accept-language:frIf-modified-since:Sun,27 Sep 2009 13:45:12 (carriage return, line feed)

request line(GET, POST,

HEAD commands)

header lines

Carriage return, line feed

indicates end of message

HTTP HTTP RequestRequest Message Message

Page 31: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-3131

HTTP/1.1 200 OK Connection: closeDate: Thu,15 Oct 2009 12:00:15 GMT Server: Apache/1.3.0 (Unix) Last-Modified: Mon, 12 Oct 2009 …... Content-Length: 6821 Content-Type: text/html data data data data data ...

status line(protocol

status codestatus phrase)

header lines

data, e.g., requestedHTML file

MIME lines

HTTP HTTP ResponseResponse Message Message

Page 32: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-3232

GETGETThe GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI.

The semantics of the GET method changes to a "conditional GET" if the request message includes an If-Modified-Since header field.

HEADHEADThe HEAD method is identical to GET except that the server must not return any Entity-Body in the response.

There is no"conditional HEAD"request analogous to the conditional GET.

GET and HEAD CommandsGET and HEAD Commands

Page 33: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-3333

Goal: don’t send object if client has up-to-date

cached version client: 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

client 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

Conditional GET: Client-Side CachingConditional GET: Client-Side Caching

Page 34: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-3434

POSTPOST

The POST method is used to request that the destination server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URL in the Request-Line. POST is designed to allow a uniform method to cover the following functions:

Annotation of existing resources;

Posting a message to a bulletin board, newsgroup, mailing list,or similar group of articles;

Providing a block of data, such as the result of submitting a form, to a data-handling process;

Extending a database through an append operation.

POST CommandPOST Command

Page 35: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-3535

Get method: Web page often

includes form input Input is uploaded to

server in URL field of request line:

Post method: Web page often

includes form input Input is uploaded to

server in entity body

www.somesite.com/cgi.bin/form.cgi?firstname=morteza&lastnme=analoui

URL Encoded data

URL encodingA-Z A-Za-z a-z0-9 0-9

*-_ *-_Space +Others %HEX

Uploading Form InputUploading Form Input

Page 36: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-3636

HTTP/1.0 GET POST HEAD

asks server to leave requested object out of response

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

Other Methods

OPTIONS, PATCH, COPY, MOVE, DELETE, LINK, UNLINK, TRACE, WRAPPED, extension method.

Other Methods

OPTIONS, PATCH, COPY, MOVE, DELETE, LINK, UNLINK, TRACE, WRAPPED, extension method.

Method TypesMethod Types

Page 37: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-3737

1. General Header Fields

2. Request Header Fields

3. Response Header Fields

4. Entity Body Hearer Fields

1. General Header Fields

2. Request Header Fields

3. Response Header Fields

4. Entity Body Hearer Fields

Header FieldsHeader Fields

Page 38: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-3838

1. General Header Fields

Keep-Alive

Upgrade

Connection

Forwarded

Cache-Control

Data

Pragma

1. General Header Fields

Keep-Alive

Upgrade

Connection

Forwarded

Cache-Control

Data

Pragma

Header Fields - 1Header Fields - 1

Page 39: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-3939

2. Request Header Fields Accept: Accept-Language: Authorization: From: Host: If-Modified-Since: Proxy-Authorization:

Range: Refer: Unless: User-Agent: Accept-Encoding: Cookie:

Header Fields - 2Header Fields - 2

Page 40: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-4040

3. Response Header Fields

Location:

Proxy-Authentication:

Public:

Retry-After:

Server:

WWW-Authenticate:

Set-Cookie:

3. Response Header Fields

Location:

Proxy-Authentication:

Public:

Retry-After:

Server:

WWW-Authenticate:

Set-Cookie:

Header Fields - 3Header Fields - 3

Page 41: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-4141

4. Entity Body Header Fields Allow Content-EncodingContent-Language Content-Length Content-RangeContent-TypeContent-Version Content-MD5

Derived-From Expires Last-Modified Link Title Transfer-Encoding URL-Header extension-header

Header Fields - 4Header Fields - 4

Page 42: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-4242

TypeApplication

TextImageAudioMultipartVideo

Subtypes Postscript, msword, Msexel,… Html, plain(ASCII),… Jpeg, gif, ief,… Basic, x-pn-realaudio,… mixed mpeg, quicktime

Multipurpose Internet Mail Extensions(rfcs822obs, 2045, 2046, 2077)

Multipurpose Internet Mail Extensions(rfcs822obs, 2045, 2046, 2077)

Header Fields – 4 (Content-Type)Header Fields – 4 (Content-Type)

Page 43: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-4343

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

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

In first line in server -> client response message.

A few sample codes:

In first line in server -> client response message.

A few sample codes:

HTTP Response Status CodesHTTP Response Status Codes

Page 44: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-4444

Status Codes CategoriesStatus Codes Categories

Response Categories Informational :100 Successful :200 Redirection :300 Client Error :400 (eg. 404 Not found) Server Error :500

Page 45: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-4545

Status-Codes "201" ; Created "202" ; Accepted "204" ; No Content "301" ; Moved Permanently "200" ; OK "302" ; Moved Temporarily "304" ; Not Modified "400" ; Bad Request "401" ; Unauthorized "403" ; Forbidden "404" ; Not Found "500" ; Internal Server Error "501" ; Not Implemented "502" ; Bad Gateway "503" ; Service Unavailable “505” ; HTTP Version Not Supported

Status-Codes "201" ; Created "202" ; Accepted "204" ; No Content "301" ; Moved Permanently "200" ; OK "302" ; Moved Temporarily "304" ; Not Modified "400" ; Bad Request "401" ; Unauthorized "403" ; Forbidden "404" ; Not Found "500" ; Internal Server Error "501" ; Not Implemented "502" ; Bad Gateway "503" ; Service Unavailable “505” ; HTTP Version Not Supported

Status CodesStatus Codes

Page 46: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-4747

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, sendsWWW authenticate:

header line in response

client server

usual http request msg401: 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

User-Server Interaction: AuthorizationUser-Server Interaction: Authorization

Page 47: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-4848

Observing HTTP in actionObserving HTTP in action WireShark (Ethereal) packet-sniffer

http://www.wireshark.org/ captures, records link-layer frames being

sent/received recall: HTTP encapsulated inside TCP inside IP inside

Ethernet (see chapter 6)

operating system

application

packet capture (pcap)

copy of all Ethernet frames sent/received

application (e.g., www browser, ftp client)

Transport (TCP/UDP)

Network (IP)

Link (Ethernet)

Physical

packet analyzer

packet sniffer

to/from network to/from network

Page 48: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-4949

Ethereal Screen ShotEthereal Screen Shot

listing of captured packets

details of selected

packet header

packet content in hexadecimal

and ASCII

display filter specification

command menus

Page 49: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-5050

Cookies: Keeping “State”-RFC2109Cookies: Keeping “State”-RFC2109

Some Web sites store information in a small text file on your computer. This file is called a cookie.

There are several types of cookies,

you can choose whether to allow some, none, or all of them to be saved on your computer.

If you do not allow cookies at all, you may not be able to

view some Web sites or take advantage of customization features (such as

local news and weather, or stock quotes).

Page 50: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-5252

Anatomy of a (Simple) CookieAnatomy of a (Simple) Cookie

String of text with these 6 attributes: Name of the cookie Value (content) of the cookie Site (host) for which the cookie is valid Path for which the cookie is valid Whether a secure connection needed

to use the cookie. An expiration date

A Cookie may not exceed 4 KB in size.

Page 51: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-5353

How cookies are usedHow cookies are used

Created by an Internet site to store information on your computer.

Example, you visit a Web site, it saves a record of the pages you looked at, to help the site customize the view for you the next time you visit.

The file is a text file, usually stored in directory named Cookies and having username@WebServerName[1].txt name.

Cookies can also store personally identifiable information, that can be used to identify or contact you, such as

your name, e-mail address, or telephone number. A Web site only has access to the information you provide.

Once a cookie is saved on your computer, only the Web site that created the cookie can read it.

Page 52: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-5454

There are four components:

1) cookie header line in the HTTP response message

SET-COOKIE: (name, value, expires, path, domain, secure)

2) cookie header line in HTTP request message

COOKIE: name

3) cookie file kept on user’s host and managed by user’s browser

4) back-end database at Web site

There are four components:

1) cookie header line in the HTTP response message

SET-COOKIE: (name, value, expires, path, domain, secure)

2) cookie header line in HTTP request message

COOKIE: name

3) cookie file kept on user’s host and managed by user’s browser

4) back-end database at Web site

Many major Web sites use cookiesMany major Web sites use cookies

HTTP and CookiesHTTP and Cookies

Page 53: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-5555

client server

usual http request msgusual http response

+Set-cookie: 1678

usual http request msg

cookie: 1678usual http response

msg

usual http request msg

cookie: 1678usual http response msg

cookie-specificaction

cookie-specificaction

servercreates ID

1678 for user

entry in backend

database

access

acce

ss

Cookie file

amazon: 1678ebay: 8734

Cookie file

ebay: 8734

Cookie file

amazon: 1678ebay: 8734

one week later:

A Simple ExampleA Simple Example

Page 54: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-5656

Cookie Example - 1Cookie Example - 1

Name: Lang Content: en Host: webmail.iust.ac.ir Path: / Send For: Any type of connection (secure and no-

secure) Expires: Monday, July 16, 2007 12:00:55 AM

[email protected]/15362988154882988652277920158429813096*Langenwebmail.iust.ac.ir/153634615495682987529279016025629801864*Themefarsiwebmail.iust.ac.ir/153634615495682987529279016025629801864*

Page 55: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-5757

Cookie Example - 2Cookie Example - 2

SRCHUIDV=1&GUID=2A674B205B514D43BF918B49294F41B5search.msn.com/10247911939843045869690096649629869799*AFORMMSNHsearch.msn.com/102479119398430458696154618190429869801*SRCHUSRAUTOREDIR=0&GEOVAR=1&DOB=20070715search.msn.com/102440699493123060405390127649629869799*

vid213.160.98.227.1198190542941908shockwave.com/1536226640563230048508249129052829901657*

Apache3f07293ece0600007fe0fc4688290400016a0000www.toyota.com/1536324757811230245003340226955229884863*

Arr

ay C

ookie

Sim

ple

Cookie

s

Page 56: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-5858

Client-specific locations No standard

IE stores in a folder called “Temporary Internet Files”

Each cookie stored in a separate file. Firefox stores them in a user-specific profile

file that ends in “.default” Safari stores them in

~/Library/Cookies/Cookies.plist

Where are cookies stored on client?Where are cookies stored on client?

Page 57: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-5959

Cookie Types and TaxonomyCookie Types and Taxonomy

By Origination First Party Cookies Third Party Cookies

By Lifespan Session (temporary) Cookies (RAM) Persistent Cookies (Disk)

By Read-Write Mechanism (see next slide) Server-Side Cookies (HTTP Header) Client-Side Cookies (JavaScript)

By Structure Simple Cookies Array Cookies

Page 58: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-6060

Cookie CodeCookie Code

Cookies may be read/written by server-side code, or client-side code.

Server-side Cookies are executed by the web server and instructions included in HTTP header for the page.

Server-side Cookie languages: Perl/CGI, ASP/VBScript.

Client-side scripts: JavaScript embedded in page HTML. function setCookie (name, value, expires, path, domain,

secure) function getCookie (name) function deleteCookie (name, path, domain)

Page 59: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-6161

First-Party vs. Third-Party cookiesFirst-Party vs. Third-Party cookies

A first-party cookie either originates on or is sent to the Web site you are currently viewing.

A third-party cookie either originates on or is sent to a Web site different from the one you are currently viewing.

Third-party Web sites usually provide some content on the Web site you are viewing. For example, many sites use advertising from third-party Web sites and those third-party Web sites may use cookies.

A common use for this type of cookie is to track your Web page use for advertising or other marketing purposes.

Third-party cookies can either be persistent or temporary.

Page 60: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-6262

Cookie Code: JavaScriptCookie Code: JavaScript

JavaScript code uses 3 standard functions that are defined in the HTML <head> tag:

getCookie(cookieName)

setCookie(cookieName, value, expDate)

delCookie(cookieName)

All Cookie manipulation is performed using these 3 functions and regular algorithmic constructs

All functions are automatically performed on the cookie object of that domain/path

Page 61: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-6363

HTTP

TCP

IP

Routers

Files

packetspacketspacketspacketspacketspackets

Routers

HTTP over TCPHTTP over TCP

Page 62: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-6464

2.1 Principles of app layer protocols clients and servers app requirements

2.2 Web and HTTP

2.3 FTP 2.4 Electronic Mail

SMTP, POP3, IMAP 2.5 DNS

2.6 Socket programming with TCP

2.7 Socket programming with UDP

2.8 Building a Web server

2.9 Content distribution Network Web caching Content distribution

networks P2P file sharing

Chapter 2 OutlineChapter 2 Outline

Page 63: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-6565

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

file transfer FTPserver

FTPuser

interface

FTPclient

local filesystem

remote filesystem

user at host

FTP: the File Transfer ProtocolFTP: the File Transfer Protocol

Page 64: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-6666

FTP client contacts FTP server at port 21, specifying TCP as transport protocol.

Client obtains authorization over control connection.

Client browses remote directoryremote directory by sending commands over control connection.

When server receives a command for a file transfer, server opens a TCP data conn. to client at port 20.

FTP clientFTP server

TCP control connectionport 21 (persistent)

TCP data connectionport 20(nonpersistent)

FTP: Separate Control, Data ConnectionsFTP: Separate Control, Data Connections

Page 65: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-6767

USERUSERUSERUSER

FILE SYSTEM

FILE SYSTEM

USERINTERFACE

USERINTERFACE

USERPI

USERPI

USERDTP

USERDTP

SERVERDTP

SERVERDTP

FILESYSTEM

FILESYSTEM

SERVERPI

SERVERPIFTP REPLIESFTP REPLIES

FTP COMMANDSFTP COMMANDS

DATACONNECTION

PI: Protocol InterpreterDTP: Data Transfer Process

FTP MODEL - 1FTP MODEL - 1

Page 66: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-6868

In the model, the user-protocol interpreter (PI) initiates the control connection.

The control connection follows the Telnet protocol.

FTP commands are generated by the user-PI and transmitted to the server process via the control connection.

Standard replies are sent from the server-PI to the user-PI over the control connection in response to the commands.

Control Connection InitiationControl Connection Initiation

Page 67: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-6969

The FTP commands specify the parameters for the data connection (data port, transfer mode, representation type, and

structure) and the nature of file system operation (store, retrieve,

append, delete, etc.). The user-DTP should "listen" on the specified

data port, and the server initiate the data connection and data transfer in accordance with the specified parameters.

Note that the data connection may be used for simultaneous sending and receiving.

Data Connection InitiationData Connection Initiation

Page 68: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-7070

After transferring a file, server closes port 20.

Server opens a second TCP data connection to transfer the next file.

Control connection: “out of band” (http is also a file transfer protocol. It is

stateless, in-band and a push/pull protocol. FTP is also a push/pull one)

FTP server maintains “state”: current directory, earlier authentication

FTP: Separate Control, Data ConnectionsFTP: Separate Control, Data Connections

Page 69: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-7171

Sample commands: sent as ASCII text over

control channel (4 uppercase ASCII characters)

USER username PASS password LIST return list of file in

current directory PORT ip and port

addr. for datat connection

RETR filename retrieves (gets) file

STOR filename stores (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://ftpserver.iust.ac.ir/dir1/filename.extensionftp://ftpserver.iust.ac.ir/dir1/filename.extension

FTP Commands, ResponsesFTP Commands, Responses

Page 70: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-7272

72

ExampleExample

FTP client tells FTP server how to open the data connection: supplies IP address and port

Page 71: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-7373

FTP Reply Status Code - 1FTP Reply Status Code - 1

First digit of status code indicates type of reply: ‘1’: Positive Preliminary Reply (got it, but wait). ‘2’: Positive Completion Reply (success). ‘3’: Positive Intermediate Reply (waiting for more

information). ‘4’: Transient Negative Completion (error - try

again). ‘5’: Permanent Negative Reply (error - can’t do).

Page 72: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-7474

FTP Reply Status Code - 2FTP Reply Status Code - 2

2nd digit indicates function groupings. ‘0’: Syntax (problem with command syntax). ‘1’: Information (reply to help or status cmds). ‘2’: Connections (problem with a connection). ‘3’: Authentication (problem with login). ‘4’: Unspecified. ‘5’: File system (related to file system).

3rd digit indicates specific problem within function group.

Page 73: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-7575

2.1 Principles of app layer protocols clients and servers app requirements

2.2 Web and HTTP 2.3 FTP 2.4 Electronic Mail

SMTP, POP3, IMAP, HTTP

2.5 DNS

2.6 Socket programming with TCP

2.7 Socket programming with UDP

2.8 Building a Web server

2.9 Content distribution Network Web caching Content distribution

networks P2P file sharing

Chapter 2 OutlineChapter 2 Outline

Page 74: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-7676

Three major components: user agents mail servers simple mail transfer

protocol: SMTP

User Agent Sometimes is called:

“mail reader” composing, editing, reading

mail messages e.g., Eudora, Outlook, elm,

Netscape Messenger outgoing, incoming

messages stored on server

user mailbox

outgoing message queue

mailserver

useragent

useragent

useragent

mailserver

useragent

useragent

mailserver

useragent

SMTP

SMTP

SM

TP

Electronic MailElectronic Mail

Page 75: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-7777

Microsoft Outlook

Microsoft Live Mail

Qualcomm Eroda

Microsoft Outlook

Microsoft Live Mail

Qualcomm Eroda

Mail ClientsMail Clients

Mozila Thunderbird

Mailreader (pop3)

Netscape Messenger

Mozila Thunderbird

Mailreader (pop3)

Netscape Messenger

Page 76: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-7878

Mail Servers mailbox contains incoming

messages for user message queue of

outgoing (to be sent) mail messages

SMTP SMTP protocol between

mail servers to send email messages “client”: sending mail

server (sending agent) “server”: receiving mail

server (receiving agent)

mailserver

useragent

useragent

useragent

mailserver

useragent

useragent

mailserver

useragent

SMTP

SMTP

SM

TP

Electronic Mail: Mail ServersElectronic Mail: Mail Servers

Page 77: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-7979

SMTP Mail FlowSMTP Mail FlowMail

Queue

InternetInternet

Page 78: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-8080

uses TCP to reliably transfer email message from client to server, port 25

direct transfer: sending server to receiving server three phases of transfer

handshaking (greeting) transfer of messages closure

command/response interaction commands: ASCII text response: status code and phrase

messages must be in 7-bit ASCII

Electronic Mail: SMTP [RFC 2821]Electronic Mail: SMTP [RFC 2821]

Page 79: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-8181

1) User1 (sender) uses UA to compose message to [email protected] .

2) User1’s UA sends message to his mail server; message placed in message queue.

3) Client side of SMTP opens TCP connection with User2’s mail server.

4) SMTP client sends User1’s message over the TCP connection.

5) User2’s mail server places the message in User2’s mailbox.

6) User2 invokes his/her user agent to read message.

UA

: U

ser

Agent

Scenario: User1 sends message to User2Scenario: User1 sends message to User2

useragent

mailserver

mailserver user

agent

1

23 4 5

6User1

User2

[email protected]

[email protected]

webmail.iust.ac.ir

yahoo.com

Page 80: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-8282

SMTP uses persistent connections.

SMTP requires message (header & body) to be in 7-bit ASCII

SMTP server uses CRLF.CRLF to determine end of message

Comparison with HTTP: HTTP: pull SMTP: push

both have ASCII command/response interaction, status codes.

HTTP: each object encapsulated in its own response message.

SMTP: multiple objects sent in multipart message.

SMTP: Final WordsSMTP: Final Words

Page 81: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-8383

SMTP: protocol for exchanging email msgs

RFC 822: standard for text message format:

header lines, e.g., To: From: Subject:different from SMTP

commands! body

the “message”, ASCII characters only

header

bodybody

blankline

Mail Message FormatMail Message Format

..

Page 82: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-8484

Mail

Massage

sms rms: TCP connection establishment on port 25sms rms: SMTP handshake (HELO, MAIL, FROM, RCPT TO, DATA,

commands, and 220, 250, 354, 221 status codes)sms header

<CRLF>body<CRLF>.<CRLF>

sms QUITrms 221 yahoo.com closing connection

SMTP Message Transfer Between Mail ServersSMTP Message Transfer Between Mail Servers

sms = sending mail server (client side)rms = receiving mail server (server side)

Page 83: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-8585

ExampleExample

useragent

mailserver

mailserver user

agent12 3 4 5

6

User1

User2

[email protected]

[email protected]

webmail.iust.ac.ir

yahoo.com

Page 84: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-8686

Mail Massage

from user1user1 to

user2user2

sms: TCP connection request on port 25rms: 220 yahoo.com accepts connectionsms: HELO webmail.iust.ac.ir is readyrms: 250 Hello webmail.iust.ac.ir sms: MAIL FROM: <[email protected]> rms: 250 [email protected]... Sender ok sms: RCPT TO: <[email protected]> rms: 250 [email protected] ... Recipient ok sms: DATA rms: 354 Enter mail, end with "." on a line by itself sms: From: [email protected] sms: To: [email protected] .

sms: . rms: 250 Message accepted for delivery sms: QUIT rms: 221 yahoo.com closing connection

Example: SMTP InteractionExample: SMTP Interaction

Page 85: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-8787

MIME: multimedia mail extension, RFC 2045, 2056 additional lines in message header declare MIME

content type

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

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

.

MIME versionMIME version

method usedto encode data

method usedto encode data

multimedia datatype, subtype,

parameter declaration

multimedia datatype, subtype,

parameter declaration

encoded dataencoded data

Message Format: Multimedia ExtensionsMessage Format: Multimedia Extensions

Page 86: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-8888

Text example subtypes:

plain, html

Image example subtypes: jpeg,

gif

Audio example 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

MIME MIME (RFCs(RFCs2045, , 2046, , 2077)) Types TypesContent-Type: type/subtype; parametersContent-Type: type/subtype; parameters

Page 87: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-8989

From: [email protected] To: [email protected] Subject: photo of iust. MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=StartOfNextPart --StartOfNextPartDear User1, Hear is a photo of iust in 1383 winter.--StartOfNextPartContent-Transfer-Encoding: base64Content-Type: image/jpegbase64 encoded data ..... ......................... ......base64 encoded data --StartOfNextPartDo you like to receive more pictures?.

Multipart TypeMultipart Type

Page 88: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-9090

sms: TCP connection request on port 25rms: 220 yahoo.com accepts connectionsms: HELO webmail.iust.ac.ir is readyrms: 250 Hello webmail.iust.ac.ir sms: MAIL FROM: <[email protected]> rms: 250 [email protected]... Sender ok sms: RCPT TO: <[email protected]> rms: 250 [email protected] ... Recipient ok sms: DATA rms: 354 Enter mail, end with "." on a line by itself sms: From: [email protected] sms: To: [email protected] .

sms: . rms: 250 Message accepted for delivery sms: QUIT rms: 221 yahoo.com closing connection

Example: SMTP Response TimeExample: SMTP Response Time1RTT1RTT

1RTT1RTT

1RTT1RTT

1RTT1RTT

1RTT1RTT

1RTT1RTT

1RTT1RTT

Mail Sending

Time (MST)

Mail Sending

Time (MST)

Next mail1RTT1RTT

4RTT4RTT

Page 89: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-9191

SMTP Response Time - 1SMTP Response Time - 1

TCP

220Helo

250Mail From

250Rcp To

250Data

354

250Quit

221

time

1RTT

6RTT

8RTT+M/B

7RTT+M/B

4RTT

Page 90: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-9292

SMTP Response Time - 2SMTP Response Time - 2

1 Message from sms to rms SRT = 8RTT + M/B

N messages from sms to rms N

SRT = 4(N+1)RTT +∑ Mi /Bi

B is the throughput of sms-rms connection (Byte/sec)

M is the email message size (Byte)

Page 91: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-9393

sms: TCP connection request on port 25rms: 220 yahoo.com accepts connectionsms: HELO webmail.iust.ac.ir is readyrms: 250 Hello webmail.iust.ac.ir sms: MAIL FROM: <[email protected]> rms: 250 [email protected]... Sender ok sms: RCPT TO: <[email protected]> rms: 250 [email protected] ... Recipient ok sms: RCPT TO: <[email protected]> rms: 250 [email protected] ... Recipient ok sms: DATA rms: 354 Enter mail, end with "." on a line by itself sms: From: [email protected] sms: To: [email protected]; [email protected] .

sms: . rms: 250 Message accepted for delivery sms: QUIT rms: 221 yahoo.com closing connection

Example: 1 mail for 2 RCPTsExample: 1 mail for 2 RCPTs

Page 92: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-9494

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

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

download IMAP: Internet Mail Access Protocol [RFC 1730]

more features (more complex) manipulation of stored messages on server

HTTP (webmail) : Hotmail , Yahoo Mail, Gmail, etc.

useragent

sender’s mail server

useragent

SMTP SMTP accessprotocol

receiver’s mail server

Sender Receiver

Mail Access ProtocolsMail Access Protocols

Page 93: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-9595

RFC 1939 / Std 53 To retrieve emails from server (POP3

server) Server port number: 110

Three states Authorization State Transaction State Update State

POP3-Post Office Protocol - Version 3POP3-Post Office Protocol - Version 3

Page 94: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-9696

POP3 CommandsPOP3 Commands

Authorization State USER username PASS password APOP name digest

Transaction State STAT LIST [msgNo] RETR msgNo DELE msgNo NOOP RSET TOP msgNo line UIDL [msgNo]

Authorization State USER username PASS password APOP name digest

Transaction State STAT LIST [msgNo] RETR msgNo DELE msgNo NOOP RSET TOP msgNo line UIDL [msgNo]

Update State QUIT

Update State QUIT

Page 95: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-9797

authorization phase client commands:

user: declare username pass: password

server responses +OK -ERR

transaction phase, client: list: list message

numbers retr: retrieve message by

number dele: delete quit

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 USER1S: +OK C: pass zxcdvf S: +OK user successfully logged on

POP3 ProtocolPOP3 Protocol

Page 96: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-9898

More about POP3 Previous example uses

“download and delete” mode.

“Download” brings the mail into client computer.

“Delete” removes the mail from the mail server. User1 cannot re-read e-mail if he/she changes client computer.

“Download-and-keep”: leaves the message on the mail server.

POP3 is stateless across sessions.

IMAP Keep all messages in

one place: the server Allows user to

organize messages in folders

IMAP keeps user state across sessions: names of folders and

mappings between message IDs and folder name

POP3 (more) and IMAPPOP3 (more) and IMAP

Page 97: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-9999

WebmailWebmail

Web-based e-mail programs called webmail. Webmail has several advantages:

ability to send and receive e-mail from anywhere using a single application: a web browser.

This eliminates the need to configure an e-mail client.

Examples of e-mail services which also provide the user a webmail interface are Hotmail, Gmail, AOL and Yahoo.

Page 98: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-100100

Webmail (more)Webmail (more)

The main drawbacks of webmail are: User interactions are subject to network response

and There is no offline capability.

Webmail generally provides the best experience over broadband,

A mail-reader can provide a satisfactory experience over dialup, and messages can be searched and viewed without an internet connection.

Page 99: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-101101

2.1 Principles of app layer protocols clients and servers app requirements

2.2 Web and HTTP 2.3 FTP 2.4 Electronic Mail

SMTP, POP3, IMAP, HTTP

2.5 DNS (Internet directory service)

2.6 Socket programming with TCP

2.7 Socket programming with UDP

2.8 Building a Web server

2.9 Content distribution Network Web caching Content distribution

networks P2P file sharing

Chapter 2 OutlineChapter 2 Outline

Page 100: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-102102

Paul V. Mockapetris is the inventor of the Domain Name System.

In 1983, he proposed a Domain Name System (DNS) architecture in RFCs 882 and 883.

He had recognized the problem in the early Internet (then ARPAnet) of holding name to address translations in a single table on a single host, and instead proposed a distributed and dynamic DNS database: essentially DNS as we have it today.

Together with Jon Postel, he is acknowledged as the inventor of DNS.

Domain Name System (DNS)Domain Name System (DNS)

Page 101: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-103103

www.internic.netwww.internic.net

. Public Information Regarding Internet Domain

Name Registration Services

www.whois.net domain name lookup, available domain names, domain keyword search, deleted domains

Page 102: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-104104

Name, Address, RouteName, Address, Route

The name of a resource indicates what we seek human recognizable Universal Resource Names (URNs)

An address indicates where it is IP address, port

A route tells how to get there Internet routing

Page 103: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-105105

People: has name(s)/identifier(s):

given and family names, national number, passport #

addressInternet hosts, routers:

Host: may have “name(s)”, e.g., www.iust.ac.ir

Router: has no name Hosts and Routers: have

address (IP address)

Domain Name System: map between name(s) and

IP addresses:

Name translation Address

distributed database implemented in hierarchy of many name servers

application-layer protocol host and name servers communicate to resolve names (address/name translation)

DNS: Domain Name SystemDNS: Domain Name SystemRFC1034RFC1034

Page 104: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-106106

Why DNSWhy DNS

Although DNS is most commonly associated with the Internet, private networks also use DNS because of the following benefits:

Convenience: User-friendly names are easier for

people to remember than numerical IP addresses.

Consistency: IP addresses may change, but the server names can remain constant.

Simplicity: Users need to learn only one naming convention to find resources on either the Internet or on an intranet.

Page 105: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-107107

DNS: Domain Name SystemDNS: Domain Name System

The Domain Name System is a distributed database system that can serve as the foundation for name resolution in a TCP/IP network.

DNS is used by most internetworking software, such as web browsers and electronic mail programs, to locate servers and to resolve, or map, a user-friendly name of a computer to its IP address.

Page 106: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-108108

DNS ComponentsDNS Components

To understand how DNS maps names to IP addresses, you will need to understand the following five components: 1. Domain Name Space

Name Structure, 2. Zone

Zone data base file, 3. Name Server (DNS Server)

DNS Root Servers, 4. DNS Resolver, 5. Protocol

Forward Lookup Query Caching.

Page 107: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-109109

1. Domain Name Space1. Domain Name Space

The domain name space has a hierarchical structure.

The root domain is at the top, and it is represented by a period.

Below the root domain, the top-level, or 1st-level domains can be an organizational type, such as com or edu., or a geographic location, such as ir. for IRAN.

Second-level domains are registered to individuals or organizations, such as microsoft.com, the Microsoft Corporation domain.

Second-level domains can have many sub domains. …and any domain can have hosts.

Page 108: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-110110

1. Domain Name Space1. Domain Name Space

“ .”Root Domain

Top Level or First Level Domain

org. edu. com. ir.

Second Level Domain (Registered to Individuals or Organizations)ac.ir.

iust.ac.ir.

ce.iust.ac.ir.

Any domain can have hosts. A host is a specific computer within a domain. Iran University of Science & Technology ‘s Domain: iust.ac.ir.

Any domain can have hosts. A host is a specific computer within a domain. Iran University of Science & Technology ‘s Domain: iust.ac.ir.

host

subdomain 2nd-leveldomain

top-leveldomain

webmail . iust . ac . ir .root

fully

qualifi

ed d

om

ain

nam

e, or

FQD

N

Page 109: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-111111

1. Domain Name Space: Name Structure1. Domain Name Space: Name Structure

Host name . … . Subdomain-name . 2nd-level –name. 1st-level-name .

Max: 255 Characters

Max: 63 Characters

ICANN: Internet Corporation For Assigned Names and Numbers) http://icann.org

Levelm -name authority appoints levelm-1 -names.

Example: ir is controlled by iranic.com iust.ir is controlled by Iran University of science and

Technology.

Root

Page 110: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-112112

Names are ValuableNames are Valuable

newnew

Page 111: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-113113

Top Level DomainsTop Level Domains

Three types of top-level domains: Organizational: 3-character code indicates the function

of the organization Used primarily within the US Examples: gov, mil, edu, org, com, net

Geographical: 2-character country or region code Examples: ir, uk, jp, de

Reverse domains: A special domain (in-addr.arpa) used for IP address-to-name mapping and gateway locating.

Infrastructure Domain (Address and Routing Parameter Area domain) .arpa

There are more than 200 top-level domains.

Page 112: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-114114

Examples: Top Level DomainsExamples: Top Level Domains com: commercial edu: educational institute ac: Academic, research

institute int: international organization gov: US federal goverment org: US armed forces net: network providers biz: business name: people’s name pro: professions tv: TV stations and networks …

ir: Iran nl: Netherlands jp: Japan uk: England …

ir: Iran nl: Netherlands jp: Japan uk: England …

For the most up-to-date For the most up-to-date information about new top information about new top level domains, consult: level domains, consult: http://www.icann.org/tldshttp://www.icann.org/tlds

For the most up-to-date For the most up-to-date information about new top information about new top level domains, consult: level domains, consult: http://www.icann.org/tldshttp://www.icann.org/tlds

Page 113: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-115115

RegistrarRegistrar

A few words about a Registrar: Organization where you register a domain

name

Verifies uniqueness of name

Enters domain name into various databases: whois & DNS

Page 114: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-116116

List of registrars from internic.net:List of registrars from internic.net:

Page 115: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-117117

Whois databasesWhois databases

Input: domain name or company name Output: registrar, whois server, dns

serverSome useful whois sites: www.internic.net

For com, net and org top-level domains www.allwhois.com

For country-code top-level domains, e.g., jp, fr

Two steps First find target’s registrar Then whois target at registrar

Page 116: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-118118

Internic Whois: Target “kazaa”Internic Whois: Target “kazaa”

Page 117: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-119119

Whois: next stepWhois: next step

Do whois at registrar, eg, register.com Input: domain name, IP address, net

administrator name Output:

Names of people (administrator, billing contact)

Telephone numbers E-mail addresses Name servers and IP addresses

Page 118: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-120120

Whois at kazaa’s registrarWhois at kazaa’s registrar

Page 119: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-121121

Reconnaissance: IP RangesReconnaissance: IP Ranges

ARIN: American Registry for Internet Numbers Maintains whois database that includes IP

address ranges in US RIPE: Europe, Middle East, Central Asia APNIC: Asia, Pasific

Page 120: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-122122

RIPE NCCRIPE NCC

Page 121: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-123123

Local Internet Registrar for IranLocal Internet Registrar for Iran

Page 122: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-127127

For administrative purposes, domains can be organized into zones.

As you can see in this example, a zone is a discrete and contiguous area of the domain name space.

One reason to divide a name space into zones is to delegate authority for different portions of it.

One very large domain could be difficult to administer. The name-to-IP address data for computers located in a

zone, is stored in a zone database file on a DNS name server.

The zone DNS server is an authoritative server.

For administrative purposes, domains can be organized into zones.

As you can see in this example, a zone is a discrete and contiguous area of the domain name space.

One reason to divide a name space into zones is to delegate authority for different portions of it.

One very large domain could be difficult to administer. The name-to-IP address data for computers located in a

zone, is stored in a zone database file on a DNS name server.

The zone DNS server is an authoritative server.

2. Zones & Authoritative DNS Server2. Zones & Authoritative DNS Serverir.

ac.ir.NameServer

NameServer

NameServer

Zone Database File

Zone Database File

Zone Database File

Page 123: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-128128

2. Zone Owner’s Responsibilities2. Zone Owner’s Responsibilities

Authoritatively maintain the zone’s data. Arrange for replicated name servers for the

zone Typically, zone data is maintained in a primary file and

loaded into a primary server Replicated servers use TCP-based zone transfers

specified in DNS protocol to refresh their data. Therefore, either servers can answer name resolution

queries for that zone. A name server authoritative for a zone does not

have to be in that zone. A name server can handle any number of zones,

which don’t have to be contiguous.

Page 124: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-129129

A zone database storing resource records (RR) of the zone for which a server is authoritative.

Type=NS name is domain (e.g. iust.ac.ir) value is IP address of

authoritative name server for this domain

Type=A name is hostname value is IP address

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

Type=MX value is name of mail-

server associated with name

2. Zone Database File2. Zone Database File

RR format: (Name, TTL, Class, Type, Value)

Page 125: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-130130

2. Zone Database File: Type Description2. Zone Database File: Type Description

Number

Type Description Example Resource Record Format

1 A Network address www 1D IN A 10.1.1.1

2 NS Authoritative name server

@ 1D IN NS na.av.com

3 MD Mail destination; now replaced by MX

4 MF Mail forwarder; now replaced by MX

5 CNAME Canonical alias name

6 SOA Start of zone authority

7 MB Mailbox domain name

8 MG Mailbox member

9 MR Mail rename domain

10 NULL Null resource record

11 WKS Well-Known service

RR format: (Name, TTL, Class, Type, Value)

Page 126: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-131131

2. Zone Database File: Type Description2. Zone Database File: Type Description

Number

Type Description Example Record Format

12 PTR Pointer to a domain name

13 HINFO Host information www 1D IN HINFO Solaris

14 MINFO Mailbox information

15 MX Mail exchange

16 TXT Text strings System 1 IN TXT “This is a new system”

17 RP Responsible person

18 AFSDB AFS-type services

19 X.25 X.25 address

20 ISDN ISDN address

21 RT Route through

RR format: (Name, TTL, Class, Type, Value)

Page 127: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-132132

2. Zone Database File: 2. Zone Database File: ExampleExample

mail.iust.ac.ir 1 D IN HINFO Sun Unix

mail.iust.ac.ir 1 D IN A 130.37.16.112

mail.iust.ac.ir 1 D IN A 192.31.231.165

mail.iust.ac.ir 1 D IN MX 1 mail.iust.ac.ir

mail.iust.ac.ir 1 D IN MX 2 ms.iust.ac.ir

post.iust.ac.ir. 1 D IN CNAME mail.iust.ac.ir

ftp.iust.ac.ir. 1 D IN CNAME file.iust.ac.ir

mail.iust.ac.ir 1 D IN HINFO Sun Unix

mail.iust.ac.ir 1 D IN A 130.37.16.112

mail.iust.ac.ir 1 D IN A 192.31.231.165

mail.iust.ac.ir 1 D IN MX 1 mail.iust.ac.ir

mail.iust.ac.ir 1 D IN MX 2 ms.iust.ac.ir

post.iust.ac.ir. 1 D IN CNAME mail.iust.ac.ir

ftp.iust.ac.ir. 1 D IN CNAME file.iust.ac.ir

NameName TTLTTL ClassClass TypeType ValueValue

Canonical Names Canonical Names Real namesReal names

Primary mail server

Primary mail server

Secondary mail serverSecondary mail server

Host InformationHost Information

Page 128: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-133133

An ExampleAn Example

db.mylab.com $TTL 86400 mylab.com. IN SOA PC4.mylab.com. hostmaster.mylab.com. ( 1 ; serial 28800 ; refresh 7200 ; retry 604800 ; expire 86400 ; ttl ) ; mylab.com. IN NS PC4.mylab.com. ; localhost A 127.0.0.1 PC4.mylab.com. A 10.0.1.41 PC3.mylab.com. A 10.0.1.31 PC2.mylab.com. A 10.0.1.21 PC1.mylab.com. A 10.0.1.11

Max. age of cached data in seconds

* Start of authority (SOA) record. Means: “This name server is authoritative for the zone Mylab.com” * PC4.mylab.com is the name server* [email protected] is the email address of the person in charge

Name server (NS) record. One entry for each authoritative name server

Address (A) records. One entry for each hostaddress

Page 129: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-134134

A DNS server is a computer that runs a DNS server program, such as Berkeley Internet NAME Domain (BIND).

DNS Servers contain DNS database files.

They resolve name resolution queries issued by DNS clients.

Why not centralize DNS? single point of failure traffic volume distant centralized

database maintenance

doesn’t scale!

no server has all name-to-IP address mappings.does scale!

3. DNS Name Servers3. DNS Name Servers

Page 130: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-135135

BIND Software – Last VersionBIND Software – Last Version

About the BIND 10 The architecture of BIND 10

concentrates on these technical aspects: modularity, customizability, clusterization, integration, resilience, and runtime control.

Source: Internet System Consortium, http://www.isc.org

Page 131: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-136136

3. DNS Name Servers3. DNS Name Servers

One name server holds the primary zone database file for a zone.

That name server is said to"have authority" for making changes to the zone file.

A copy of the zone file maybe stored on other servers to balance network load.

These copies are referred to as secondary zone database files.

The secondary zone database files are updated regularly from the primary zone database file by a process called zone transfer.

One name server holds the primary zone database file for a zone.

That name server is said to"have authority" for making changes to the zone file.

A copy of the zone file maybe stored on other servers to balance network load.

These copies are referred to as secondary zone database files.

The secondary zone database files are updated regularly from the primary zone database file by a process called zone transfer.

ir.

ac.ir.

NameServer

Secondary Zone Database File

NameServer

Primary Zone Database File

Page 132: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-137137

(b)(b) USC-ISI Marina del Rey, CA

(l)(l) ICANN Marina del Rey, CA

(e) (e) NASA Mt View, CA(f)(f) Internet Software C. Palo Alto,

CA

(i)(i) NORDUnet Stockholm, Sweden

(k)(k) RIPE London, UK

(m)(m) WIDE Tokyo, Japan

(a)(a) NSI Herndon, VA(c)(c) PSInet Herndon, VA

(d)(d) U Maryland College Park, MD(g)(g) DISA Vienna, VA

(h)(h) ARL Aberdeen, MD(j)(j) NSI (TBD) Herndon, VA

13 root name servers worldwide

3. DNS Root Name Servers3. DNS Root Name Servers

Page 133: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-138138

3. Root Name Server in Action3. Root Name Server in Action

Contacted by local name server that can not resolve name

Root name server: Either,

contacts authoritative name server gets mapping returns mapping to local name server

Or, introduces authoritative/top level name server to local name server.

Page 134: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-139139

13 Root Name Servers13 Root Name Servers

F gets 270,000,000+ hits per day. Other root servers are comparable.

Top Level Domain servers answer 5,000,000,000 per day.

F gets 270,000,000+ hits per day. Other root servers are comparable.

Top Level Domain servers answer 5,000,000,000 per day.

Page 135: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-140140

3. DNS Root Name Servers3. DNS Root Name Servers

Root Servers

Server Operator Locations IP Addr HomeASN

A VeriSign Global Registry Services

Dulles VA 198.41.0.4 19836

B Information Sciences Institute

Marina Del Rey CA IPv4: 192.228.79.201

IPv6: 2001:478:65::53

tba

C Cogent Communications Herndon VA; Los Angeles;

New York City; Chicago 192.33.4.12 2149

D University of Maryland College Park MD 128.8.10.90 27

E NASA Ames Research Center

Mountain View CA 192.203.230.10 297

F Internet Systems Consortium, Inc.

Ottawa; Palo Alto; San Jose CA;New York City; San Francisco;Madrid; Hong Kong; Los Angeles;Rome; Auckland; Sao Paulo; Beijing; Seoul; Moscow; Taipei;Dubai; Paris; Singapore; Brisbane;Toronto; Monterrey; Lisbon; Johannesburg;Tel Aviv;Jakarta; Munich;

IPv4: 192.5.5.241IPv6: 2001:500::1035

3557

G U.S. DOD NetworkInformation Center

Vienna VA 192.112.36.4 568

Page 136: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-141141

3. DNS Root Name Servers3. DNS Root Name Servers

Root Servers

Server Operator Locations IP Addr Hom

eASN

H U.S. Army Research Lab Aberdeen MD IPv4: 128.63.2.53IPv6:2001:500:1::803f:235

13

I Autonomica/NORDUnet

Stockholm; Helsinki; Milan;London; Geneva; Amsterdam;Oslo; Bangkok; Hong Kong;Brussels; Frankfurt;Bucharest; Ankara;Chicago; Washington DC;Tokyo; Kuala Lumpur

192.36.148.17 29216

J VeriSign Global Registry Services

Dulles VA (2 locations); Mountain View CA;Seattle WA; Amsterdam;Atlanta GA; Los Angeles CA;Miami; Stockholm; London;Tokyo; Seoul; Singapore;Sterling VA (2 locations, standby)

192.58.128.30 26415

K Reseaux IP Europeens -

Network Coordination Centre

London (UK); Amsterdam (NL);Frankfurt (DE); Athens (GR);Doha (QA); Milan (IT)

IPv4: 193.0.14.129IPv6: 2001:7fd::1

25152

L Internet Corporation for

Assigned Names and Numbers

Los Angeles 198.32.64.12 20144

M WIDE Project Tokyo; Seoul (KR); Paris (FR) 202.12.27.33

IPv6: 2001:dc3::35 7500

Page 137: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-143143

TLD and Authoritative ServersTLD and Authoritative Servers

Top-level domain (TLD) servers: responsible for com, org, net, edu, etc, and all

top-level country domains ir, uk, fr, ca. Network Solutions maintains servers for com

TLD Educause for edu TLD

Authoritative DNS servers: organization’s DNS servers, providing

authoritative hostname to IP mappings for organization’s servers (e.g., Web, mail).

can be maintained by organization or service provider

Page 138: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-144144

Distributed Hierarchical DNS ServersDistributed Hierarchical DNS Servers

Portion of Hierarchy of DNS Servers

Root DNS Servers

ir DNS Servers(Top-Level Domain)

org DNS Servers(Top-Level-

Domain)

com DNS Servers(Top-Level-Domain)

Yahoo.comDNS Servers

amazon.com

DNS Servers

dns.orgDNS Servers

ac.irDNS Servers

iust.ac.irDNS Server(s)

Page 139: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-145145

Local Name ServerLocal Name Server

Does not strictly belong to hierarchy Each ISP (residential ISP, company,

university) has one. also called “default name server”

When host makes DNS query, query is sent to its local DNS server acts as proxy, forwards query into hierarchy

Page 140: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-146146

4. Resolver4. Resolver

A DNS resolver is a service that uses the DNS protocol to query for information from DNS servers.

Function of DNS resolver is performed by the DNS client service.

DNS service uses UDP in transport layer on port 53.

Page 141: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-147147

Root name server: may not know

authoritative name server

may know intermediate name server: who to contact to find authoritative name server

requesting host

www.icann.org

root name server

local name serverdns.iust.ac.ir

1

23

4 5

6

authoritative name serverdns.icann.org

intermediate name server(TDL) dns.org

7

8

5. DNS Protocol: Forward Lookup Query 5. DNS Protocol: Forward Lookup Query (recursive)(recursive)

a:answerr:referral q:query q

q

q

a

a

a

a

q

Page 142: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-148148

recursive query: puts burden of

name resolution on contacted name server

heavy load?

iterated query: contacted server

replies with name of server to contact

“I don’t know this name, but ask this server”

requesting host

www.icann.org

root name server

local name serverdns.iust.ac.ir

1

23

4

5 6

authoritative name serverdns.icann.org

intermediate name server(TDL) dns.org

7

8

iterated query

5. DNS Protocol: Forward Lookup Query (iterative)5. DNS Protocol: Forward Lookup Query (iterative)

a:answerr:referral q:query

aq

q

q

qa

r

a

Page 143: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-149149

5. DNS Protocol: Forward Lookup Query5. DNS Protocol: Forward Lookup Query

requesting host

www.icann.org

root name server

local name serverdns.iust.ac.ir

1

23

4

5

6

authoritative name serverdns.icann.org

intermediate name server(TDL) dns.org

7

8

iterated query

a:answerr:referral q:query

aq

r

q

q

qr

a

Page 144: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-150150

5. DNS Protocol: Forward Lookup Query15. DNS Protocol: Forward Lookup Query1

The query contains the FQDN of the requested computer. A forward lookup query is a request

to map a name to an IP address.

“ .”

org. edu. com. ir.

ac.ir.

iust.ac.ir.Local

Name Server

RootName Server

Client

www.icann.org.

org top level DNS server

Forward Lookup Query:What is IP Address of www.icann.org

IP Address of www.icann.org is 142.12.01.23

Page 145: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-151151

5. DNS Protocol: Forward Lookup Query25. DNS Protocol: Forward Lookup Query2

Application

DNS resolver

Local DNSserver

1 10

DNS cache

DNS query2

DNS response9

Root server

3

4

Top-leveldomain server

5

6

Second-leveldomain server(authoritative)

7

8

Caching based on a time-to-live (TTL) assigned by the DNS server responsible for the host name to reduce latency in DNS translation.

Page 146: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-153153

DNS protocol : query and reply messages, both with same message format

msg header identification: 16 bit #

for query, reply to query uses same #

flags: query or reply recursion desired recursion available reply is authoritative

5. DNS Protocol Messages5. DNS Protocol Messages

identification flags

number of questions number of answer RRs

number of authority RRs number of additional RRs

questions(variable number of questions)

answers(variable number of resource records)

authority(variable number of resource records)

additional information(variable number of resource records)

12

byte

s

Page 147: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-154154

identification flags

number of questions number of answer RRs

number of authority RRs number of additional RRs

questions(variable number of questions)

answers(variable number of resource records)

authority(variable number of resource records)

additional information(variable number of resource records)

Name, Type fields for a query

RRs in responseto query

records forauthoritative servers

additional “helpful”info that may be used

5. DNS Protocol Messages5. DNS Protocol Messages12

byte

s

Query and reply messages sent over UDP on port 53.

Page 148: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-155155

Inserting records into DNSInserting records into DNS

Example: new startup “iust company” Register name iustcompany.com at DNS

registrar (e.g., Network Solutions) Provides names, IP addresses of authoritative name

server (primary and secondary) Registrar inserts two RRs into com TLD server:

(iustcompany.com, dns1.iustcompany.com, NS)(dns1.iustcompany.com, 212.212.212.1, A)

Create authoritative server Type A record for www.iustcompany.com; Type MX record for networkutopia.com

Page 149: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-156156

DNS Other Important ServicesDNS Other Important Services

Host Aliasing Complicated hostname (computer.enginerring-

student.1990.iust.ac.ir) can have one or more nickname (alias names) such as student90.iust.ir and computer90.ir

computer.enginerring-student.1990.iust.ac.ir is said to be canonical hostname

Mail Server Aliasing Mail server can also have aliased hostnames. MX records permits the mail server and web server of a

company have identical aliased hostname. Load Distribution

DNS is used to perform load distribution among replicated servers.

For replicated web servers, a set of IP addresses is associated with one canonical hostname. Name server rotates IP add. within each reply to dns query.

Page 150: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-157157

Domain names may not be the best way to name other resources, e.g. files

Relatively static resource types make it hard to introduce new services or handle mobility

Although theoretically you can update the values of the records, it is rarely enabled

Simple query model make it hard to implement advanced query

Early binding (separation of DNS query from application query) does not work well in mobile, dynamic environments

e.g., load balancing, locate the nearest printer

Problems of DNSProblems of DNS

Page 151: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-158158

2.1 Principles of app layer protocols clients and servers app requirements

2.2 Web and HTTP 2.3 FTP 2.4 Electronic Mail

SMTP, POP3, IMAP 2.5 DNS

2.6 Socket programming with TCP

2.7 Socket programming with UDP

2.8 Building a Web server

2.9 Content distribution Network Web caching Content distribution

networks P2P file sharing

Chapter 2 OutlineChapter 2 Outline

Page 152: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-159159

Server TypesServer Types

Iterative server it can handle only one request at a time other requests have to wait

Concurrent server handles several requests concurrently

ServersServers

ConnectionlessIterative

ConnectionlessIterative

ConnectionlessConcurrent

ConnectionlessConcurrent

Connection-OrientedIterative

Connection-OrientedIterative

Connection-OrientedConcurrent

Connection-OrientedConcurrent

Page 153: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-160160

Iterative ServerIterative Server

Page 154: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-161161

Concurrent ServerConcurrent Server

Page 155: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-162162

Using Ports to Identify ServicesUsing Ports to Identify Services

Web server(port 80)

Client host

Server host 128.2.194.242

Echo server(port 7)

Service request for128.2.194.242:80

(i.e., the Web server)

Web server(port 80)

Echo server(port 7)

Service request for128.2.194.242:7

(i.e., the echo server)

OS

OS

Client

Client

Client host

Page 156: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-163163

Network Application-CommunicationNetwork Application-Communication

Network Applications (process) communicates through a network.

API is a programming means, either a library or part of OS. API provides the communication functionality for the

Network Applications (Processes).

Application Program Interface (API)

Communication Software & HardwarePlatform (OS + Hardware)

Application Software(Network Application)Application Software(Network Application)

OSOS

API comes as a library

Page 157: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-164164

Application Program Interface (API)

Communication Software & HardwarePlatform (OS + Hardware)

Application SoftwareApplication Software

(API)(API)

App. SoftwareApp. Software

transportnetwork

linkphysical

application

Controlledby OS

Controlledby App. Soft.

Application-layer protocols:One “piece” of the application.Define messages exchanged by apps and actions taken.

Application-layer protocols:One “piece” of the application.Define messages exchanged by apps and actions taken.

the application

API and Networking LayersAPI and Networking Layers

Page 158: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-165165

process sends/receives messages to/from its socket

socket analogous to door sending process pushes

message out door sending process

assumes transport infrastructure on other side of door which brings message to socket at receiving process

socketsocket

transportnetwork

linkphysical

process

host or server

process

host or server

Internet

Socket APISocket API

Sockets: doors between process and hostSockets: doors between process and host

socketsocket

transportnetwork

linkphysical

Page 159: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-166166

API TechnologiesAPI Technologies-Sockets-Sockets

Sockets (earliest technology) Low level functions for the

communication Socket, ServerSocket, ConnectionSocket, ClientSocket, DatagramSocket, Send, Read, Write, Close, Accept

Page 160: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-167167

API TechnologiesAPI Technologies-RPC-RPC Remote Procedure Call (RPC)

Client code invokes a procedure on a remote server.

RPCs support a wire format common to all platforms.

Client and server translate from their binary format into the wire format.

Each RPC involves four translation: Client to wire format, Wire to server format, Server back to wire (for the return value), Wire format back to client format.

Page 161: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-168168

API TechnologiesAPI Technologies-Components-Components

Components: Components Look and act like objects, CORBA (common object request Broker

Architecture) COM, COM+ , DCOM (Distributed Component Object

Model)

Page 162: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-169169

Socket API introduced in BSD4.1

UNIX, 1981 explicitly created, used,

released by applications client/server paradigm

two types of transport service via socket API: unreliable datagram reliable, byte stream-

oriented

Socket API introduced in BSD4.1

UNIX, 1981 explicitly created, used,

released by applications client/server paradigm

two types of transport service via socket API: unreliable datagram reliable, byte stream-

oriented

Goal:Goal: learn how to build client/server application learn how to build client/server application that communicate using socketsthat communicate using sockets

Socket ProgrammingSocket Programming

Socket 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 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

Page 163: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-170170

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

socketsocket

controlled byapplicationdeveloper

controlled byoperating

system

client or server

process

socketsocket

controlled byapplicationdeveloper

controlled byoperatingsystem

client or server

NetworkTCP withTCP withbuffers,buffers,

variablesvariables

TCP withTCP withbuffers,buffers,

variablesvariables

Socket Programming Using TCPSocket Programming Using TCP

Page 164: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-171171

Client must contact server server process must first

be running server must have created

socket (door) that welcomes client’s contact

Client contacts server by: creating client-local TCP

socket specifying IP address, port

number of server process When client creates

socket: client TCP establishes connection to server TCP

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

with multiple clients source port numbers

used to distinguish clients (more in Chap 3)

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

application viewpoint

Socket Programming Socket Programming with TCPwith TCP

Page 165: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-172172

SocketsSockets

ClientsocketClient

socketConnectionsocketConnectionsocket

WelcomingsocketWelcomingsocket

Three-way handshake

Client processClient process Server processServer process

Client IP Address&

Port Number

Server IP Address&

Port Number2

Server IP Address&

Port Number1

bytes

send read read write

Page 166: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-173173

1) Example client-server app. in Java:2) Client

1) reads line from standard input (keyboard) (inFromUser stream)

2) sends to server via socket (outToServer stream)

3) Server 1) reads line from socket2) converts line to uppercase, 3) sends back to client

4) Client 1) reads (inFromServer stream), 2) prints modified line from socket on its standard output

(monitor)

1) Example client-server app. in Java:2) Client

1) reads line from standard input (keyboard) (inFromUser stream)

2) sends to server via socket (outToServer stream)

3) Server 1) reads line from socket2) converts line to uppercase, 3) sends back to client

4) Client 1) reads (inFromServer stream), 2) prints modified line from socket on its standard output

(monitor)

Example: Socket Programming with TCPExample: Socket Programming with TCP

Page 167: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-174174

Example: 3 streams and 1 socketExample: 3 streams and 1 socket

ClientProcess

ClientProcess

ClientSocketClientSocket

ou

tTO

Serv

ero

utT

OS

erv

er

inFo

rmU

serin

Form

Use

r

inFo

rmServ

erin

Form

Serv

er

InputStream

OutputStream

InputStream

TCP socket

To transport layerFrom transport layer

Page 168: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-175175

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, eg, keyboard or socket.

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

StreamsStreams

Page 169: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-176176

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

Server (running on hostid) Client

send request usingclientSocketread request from

connectionSocket

write reply toconnectionSocket

TCP connection setup

Client/Server Socket Interaction: TCPClient/Server Socket Interaction: TCP

Page 170: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-177177

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

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

Createsinput stream

Creates client socket,

TCP connection to server

Example: TCPClient.javaExample: TCPClient.java

server name

server port no.

importStatements

make Java classes available

networking class

class: is a collection of data and methods that operate on that data

Page 171: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-178178

DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());

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

DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());

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

Createsinput stream

attached to socket

Sends line

to serverReads line

from server

Example: TCPClient.java (cont.)Example: TCPClient.java (cont.)Creates

output streamattached to socket

Page 172: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-187187

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

Createwelcoming socket

at port 6789

Wait, on welcomingsocket for contact

by client

Create inputstream, attached

to socket

Example: TCPServer.javaExample: TCPServer.java

Page 173: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-188188

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

Example: TCPServer.java (cont.)Example: TCPServer.java (cont.)

Page 174: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-195195

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

Client/Server Socket Interaction: UDPClient/Server Socket Interaction: UDP

Page 175: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-196196

Example: Java Client (UDPExample: Java Client (UDP))

Output: sends packet (TCP sent

“byte stream”)

Input: receives packet (TCP received “byte stream”)

ProcessProcess

ClientSocketClientSocketre

cievepack

etse

ndpack

et

inFr

om

Use

r

InputStream

UDPdatagram

packet

UDPdatagrampacket

UDP socket

To transport layer

Fromtransport layer

Page 176: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-197197

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

Translate hostname to IP

address using DNS

Example: UDPClient.javaExample: UDPClient.java

Page 177: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-198198

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

Example: Example: UDPClient.java (cont.)Example: Example: UDPClient.java (cont.)

Page 178: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-207207

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

Receivedatagra

m

Example: UDPServer.javaExample: UDPServer.java

Page 179: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-208208

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

Example: Example: UDPServer.java (cont.)Example: Example: UDPServer.java (cont.)

Page 180: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-209209

handles one HTTP request

accepts the request parses header obtains requested file

from server’s file system

creates HTTP response message: header lines + file

sends response to client

after creating server, you can request file using a browser (eg IE explorer)

see the following slides for details.

Building a Simple Web ServerBuilding a Simple Web Server

Page 181: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-210210

Example: WebServer.javaExample: WebServer.java

import java.io.*;

import java.net.*;

import java.util.*;

class WebServer {

public static void main(String argv[ ]) throws Exception

{

String requestMessageLine;

String fileName;

ServerSocket listenSocket = new ServerSocket(6789);

Socket connectionSocket = listenSocket.accept();

BufferedReader inFromClient = new BufferedReader(

new InputStreamReader(connectionSocket.getInputStream()));

DataOutputStream outToClient =

new DataOutputStream(connectionSocket.getOutputStream());

import java.io.*;

import java.net.*;

import java.util.*;

class WebServer {

public static void main(String argv[ ]) throws Exception

{

String requestMessageLine;

String fileName;

ServerSocket listenSocket = new ServerSocket(6789);

Socket connectionSocket = listenSocket.accept();

BufferedReader inFromClient = new BufferedReader(

new InputStreamReader(connectionSocket.getInputStream()));

DataOutputStream outToClient =

new DataOutputStream(connectionSocket.getOutputStream());

contain the first line in the HTTP request messagecontain the file name of the requested file

contain the first line in the HTTP request messagecontain the file name of the requested file

When a request for a connection arrives, the accept( ) method of listenSocket creates a new object, connectionSocket, of type Socket.

When a request for a connection arrives, the accept( ) method of listenSocket creates a new object, connectionSocket, of type Socket.

two s

tream

s are

cr

eate

dtw

o s

tream

s are

cr

eate

d

Page 182: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-211211

Example: WebServer.java (cont.)Example: WebServer.java (cont.)

requestMessageLine = inFromClient.readLine();

StringTokenizer tokenizedLine =

new StringTokenizer(requestMessageLine);

If(tokenizedLine.nextToken().equals("GET")) {

fileName = tokenizedLine.nextToken();

if (fileName.startsWith("/") == true )

fileName = fileName.substring(1);

File file = new File(fileName);

int numOfBytes = (int) file.length();

FileInputStream inFile =

new FileInputStream (fileName);

byte[ ] fileInBytes = new byte[ ];

inFile.read(fileInBytes);

requestMessageLine = inFromClient.readLine();

StringTokenizer tokenizedLine =

new StringTokenizer(requestMessageLine);

If(tokenizedLine.nextToken().equals("GET")) {

fileName = tokenizedLine.nextToken();

if (fileName.startsWith("/") == true )

fileName = fileName.substring(1);

File file = new File(fileName);

int numOfBytes = (int) file.length();

FileInputStream inFile =

new FileInputStream (fileName);

byte[ ] fileInBytes = new byte[ ];

inFile.read(fileInBytes);

reads the first line of the HTTP request message.reads the first line of the HTTP request message.

tokenizedLine holds the request line with each of the "words" GET, file_name, and HTTP/1.1 placed in a separate placeholder called a token.

tokenizedLine holds the request line with each of the "words" GET, file_name, and HTTP/1.1 placed in a separate placeholder called a token.

removes the backslash that may precede the filename.

removes the backslash that may precede the filename.

These commands determine the size of the file and construct an array of bytes of that size. The name of the array is fileInBytes.

These commands determine the size of the file and construct an array of bytes of that size. The name of the array is fileInBytes.

reads from the stream inFile to the byte array fileInBytes

reads from the stream inFile to the byte array fileInBytes

Page 183: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-212212

Example: WebServer.java (cont.)Example: WebServer.java (cont.)

outToClient.writeBytes(

"HTTP/1.0 200 Document Follows\r\n");

if (fileName.endsWith(".jpg"))

outToClient.writeBytes("Content-Type:image/jpeg\r\n");

if (fileName.endsWith(".gif"))

outToClient.writeBytes("Content-Type:image/gif\r\n");

outToClient.writeBytes("Content-Length: " +numOfBytes + "\r\n");

outToClient.writeBytes("\r\n");

outToClient.write(fileInBytes, 0, numOfBytes);

connectionSocket.close();

}

else System.out.println("Bad Request Message");

} }

outToClient.writeBytes(

"HTTP/1.0 200 Document Follows\r\n");

if (fileName.endsWith(".jpg"))

outToClient.writeBytes("Content-Type:image/jpeg\r\n");

if (fileName.endsWith(".gif"))

outToClient.writeBytes("Content-Type:image/gif\r\n");

outToClient.writeBytes("Content-Length: " +numOfBytes + "\r\n");

outToClient.writeBytes("\r\n");

outToClient.write(fileInBytes, 0, numOfBytes);

connectionSocket.close();

}

else System.out.println("Bad Request Message");

} }

sends the mandatory status line: HTTP/1.1 200 Document Follows, followed by a carriage return and a line feed.

sends the mandatory status line: HTTP/1.1 200 Document Follows, followed by a carriage return and a line feed.

◊ to transfer a GIF image, server prepares the header line Content-Type: image/gif. ◊ to transfer a JPEG image, server prepares the header line Content-Type: image/jpeg.

◊ to transfer a GIF image, server prepares the header line Content-Type: image/gif. ◊ to transfer a JPEG image, server prepares the header line Content-Type: image/jpeg.sends a

content-length

header line and a

mandatory blank line

sends a content-

length header line

and a mandatory blank line

sends the requested file, fileInBytes, to the TCP send buffer

sends the requested file, fileInBytes, to the TCP send buffer

closing the socket connectionSocketclosing the socket connectionSocket

Page 184: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-226226

C-language tutorial (audio/slides): “Unix Network Programming” (J. Kurose),http://manic.cs.umass.edu/~amldemo/courseware/intro.

Java-tutorials: “All About Sockets” (Sun tutorial),

http://www.javaworld.com/javaworld/jw-12-1996/jw-12-sockets.html

“Socket Programming in Java: a tutorial,” http://www.javaworld.com/javaworld/jw-12-1996/jw-12-sockets.html

Socket Programming: ReferencesSocket Programming: References

Page 185: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-227227

2.1 Principles of app layer protocols clients and servers app requirements

2.2 Web and HTTP 2.3 FTP 2.4 Electronic Mail

SMTP, POP3, IMAP 2.5 DNS

2.6 Socket programming with TCP

2.7 Socket programming with UDP

2.8 Building a Web server 2.9 Overlay Networks

P2P Networks Unstructured Structured

Content Networks Network Caches Content Distribution

Networks (CDNs) Server Farms

Chapter 2 OutlineChapter 2 Outline

Page 186: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-228228

Overlay networksOverlay networks

A network built on top of one or more existing networks.

Generally defined as “a routing (relay) system among

involved nodes”

Relay nodes may become bottlenecks.

Independent from the underlying (physical) network.

Applications neglect the network topology

Adds additional layers of indirection/virtualization.

Page 187: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-229229

Overlay networks over TCP/IP NetworkOverlay networks over TCP/IP Network

TCP/IP (Underlying Network)

Overlay Network

X

YY

Edge between peer X and Y if there is a TCP connection. All active nodes and edges is overlay network. An edge is not a physical link. A given node (peer) will typically be connected with <10 overlay neighbors.

Edge between peer X and Y if there is a TCP connection. All active nodes and edges is overlay network. An edge is not a physical link. A given node (peer) will typically be connected with <10 overlay neighbors.

X

YY

Page 188: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-230230

Overlay NetworksOverlay Networks

TCP/IP – Underlying (Physical Network)

Overlay Network

X

YY

X

YY

A node is a destination/source peer and a router (relay).

A node is a destination/source peer and a router (relay).

Page 189: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-231231

Abstract of an Overlay Network Abstract of an Overlay Network ArchitectureArchitecture

Page 190: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-232232

Overlay Networks ExamplesOverlay Networks Examples

P2P Structured

CAN, Chord, Pastry Unstructured

Napster, Gnutella, BitTorrent, KaZaA

Content Networks Network Caches Content Distribution Networks (CDNs) Server Farms

Page 191: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-233233

Examples of p2p ApplicationsExamples of p2p Applications

File-sharing applications Napster, KazaA,

Gnutella, BitTorrent, … E-Commerce Systems

eBay, … Parallel Processing

Distributed computing (grid?), SETI (Internet-connected computers used for Search for Extraterrestrial Intelligence), …

Collaboration Distributed

(Internet) games, Instant messaging, Shared Application, …

Distributed databases Mariposa, Litwin,

Yokota, Plaxton, … Mobile Ad hoc

networks (Unstructured networks)

Application-level multicast

Page 192: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-234234

2.1 Principles of app layer protocols clients and servers app requirements

2.2 Web and HTTP 2.3 FTP 2.4 Electronic Mail

SMTP, POP3, IMAP 2.5 DNS

2.6 Socket programming with TCP

2.7 Socket programming with UDP

2.8 Building a Web server 2.9 Overlay Networks

P2P Networks Content Networks

Network Caches Content Distribution

Networks (CDNs) Server Farms

Chapter 2 OutlineChapter 2 Outline

Page 193: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-235235

Example User1 runs P2P client runs P2P client

application on his application on his notebook computer.notebook computer.

Intermittently connects to Internet; gets new IP address for each connection.

Asks for “network e-book” Application displays other

peers that have copy of network e-book.

Example User1 runs P2P client runs P2P client

application on his application on his notebook computer.notebook computer.

Intermittently connects to Internet; gets new IP address for each connection.

Asks for “network e-book” Application displays other

peers that have copy of network e-book.

User1 chooses one of the peers, User2.

File is copied from User2’s PC to User1’s notebook: HTTP

While User1 downloads, other users uploading from User1.

User1’s peer is both a Web client and a transient Web server.

User1 chooses one of the peers, User2.

File is copied from User2’s PC to User1’s notebook: HTTP

While User1 downloads, other users uploading from User1.

User1’s peer is both a Web client and a transient Web server.

All peers are servers = highly scalable!All peers are servers = highly scalable!All peers are servers = highly scalable!All peers are servers = highly scalable!

P2P File SharingP2P File Sharing

Page 194: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-236236

Example: University of Washington (2002)Example: University of Washington (2002)

UW is an HTTP content provider Exported 16.65 TB - Imported 3.44 TB

Bandwidth consumption (in + out) 0.2% Akamai (overnet. eDonkey) [content delivery

networks] 6.04% Gnutella (p2p system) 14.3% WWW 36.9% Kazaa (p2p system) 43% other TCP protocols, e.g. mail, streaming video

Page 195: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-237237

Question : How much time to distribute file from one server to N peers?

uS

u2

d1d2u1

uN

dN

Server

Network (with abundant bandwidth)

File, size F

uS: server upload bandwidth

ui: peer i upload bandwidth

di: peer i download bandwidth

File Distribution: Server-Client vs P2PFile Distribution: Server-Client vs P2P

Page 196: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-238238

Throughput: Internet scenarioThroughput: Internet scenario

10 connections (fairly) share backbone bottleneck link R

bits/sec

us

us

us

dc

dc

dc

R

End-to-end throughput constrained by bottleneck link

Per-connection end-end Throughput:

min(dc, us, R/10)

In practice: dc or us is often bottleneck:

R/10 >> dc

R/10 >> uc

Page 197: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-239239

Server sequentially sends N copies: NF/us time

Server sends 1 copy for N clients in parallel: F/(us/N)=NF/us time

Client i takes F/di time to download

increases linearly in N (for large N)

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

Time to distribute F to N clients using client/server approach =

File distribution time: server-clientFile distribution time: server-client

Page 198: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-240240

server must send one copy: F/uS time

client i takes F/di time to download NF bits must be downloaded (aggregate)

fastest possible upload rate: uS + ui

TP2P = max { F/uS , F/min(di) , NF/(uS + ui) }i

File distribution time: P2PFile distribution time: P2P

Page 199: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-241241

0

0.5

1

1.5

2

2.5

3

3.5

0 5 10 15 20 25 30 35

N

Min

imum

Dis

trib

utio

n T

ime P2P

Client-Server

Client upload rate = ui , F/ui = 1 hour, uS = 10ui , dmin ≥ uS

Server-client vs. P2P: exampleServer-client vs. P2P: example

NF/us =1 hTP2P = max { F/uS , F/min(di) , NF/(uS + ui) } =10F/20ui = 0.5 h

Page 200: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-242242

Properties of P2P SystemsProperties of P2P Systems

No central control, no central database No hierarchy

Every node is both a client and a server The communication between peers is symmetric

No global view of the system Scalability

Availability for any peer Peers are autonomous System globally unreliable

Robustness and security issues

Page 201: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-243243

Key Issues for P2P SystemsKey Issues for P2P Systems

Join/leave How do nodes join/leave? Who is allowed?

Publish How to advertise a file?

Search and retrieval How to find content? How are metadata indexes built, stored,

distributed? Content Distribution

Where is content stored? How is it downloaded and retrieved?

Page 202: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-244244

Types Publish and SearchTypes Publish and Search

Basic Strategies: Hybrid or Centralized (BitTorrent, Napster) Pure or Decentralized (Gnutella, Freenet)

Flood the query Super Peers or Hierarchical (KaZaA, DNS) Redundant Super Peers (DNS)

Rout the query

Page 203: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-245245

How Much P2P is Involved?How Much P2P is Involved?

P2P User Interaction

P2P Applicatio

n

P2P Information Manageme

nt

eBay yes no no

Napster yes yes no

Gnutella,

Freenet

yes yes yes

Page 204: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-246246

Hybrid or Centralized P2PHybrid or Centralized P2P

In a hybrid P2P system, some operations are performed at a central server.

For other operations, the peers have equal status.

Example: Napster file download Central server contains an index of the files located at

all the peers currently available. Peer 1 asks server where a file is located. Server returns address of Peer 2 who has the file. Peer 1 asks Peer 2 (directly) for the file.

Page 205: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-247247

Hybrid SystemHybrid System

2

3

4

5

1

1 5

2 5

3 4

4

5

Who has 1 5

Give me

Page 206: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-248248

Original “Napster” design1) Peers to notify server when

they join and leave:(IP Add, Port Num)

Peers to notify server if their available files change:

ContentsPeers to run a “server” program that listens on a port for download requests.

2) User1 queries for “network e-book”,

3) User1 requests file from User2.

peers

User1

User2

1

1

1

12

3

Napster as a Centralized SystemNapster as a Centralized System

1

2

3

°

°

°

locationserver

Page 207: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-249249

Centralized model (Napster)Centralized model (Napster)

INTERNET

locationserver

register

Document x?OK: Peer ZIP = a.b.c.d

Document x!

x

Peer ZIP: a.b.c.d

Page 208: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-250250

Centralized Model (BitTorrent)Centralized Model (BitTorrent)

Released in the summer of 2001

Uses basic ideas from game theory to largely eliminate the free-rider problem "free riders" are those who consume more than their

fair share. All previous systems could not deal with this problem

well.

Page 209: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-251251

Basic IdeaBasic Idea

Chop file into many pieces (chunks). Replicate DIFFERENT pieces on different peers

as soon as possible. As soon as a peer has a complete piece, it can

trade it with other peers. Hopefully, we will be able to assemble the

entire file at the end.

Page 210: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-252252

Basic ComponentsBasic Components

Seed Peer that has the entire file

Leacher Peer that has an incomplete copy of the file

A Torrent file Passive component Files are typically fragmented into 256KB pieces (chunks) The torrent file lists SHA1 hashes of all the pieces to allow

peers to verify integrity Typically hosted on a web server

A Tracker Active component Allows peers to find each other Returns a random list of peers

Page 211: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-253253

P2P File distribution: BitTorrent P2P File distribution: BitTorrent

tracker: tracks peers participating in torrent

torrent: group of peers exchanging chunks of a file

The peer obtain listof peers

trading chunksThe peer

Page 212: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-254254

File divided into 256KB chunks. Peer joining torrent:

has no chunks, but will accumulate them over time

registers with tracker to get list of peers, connects to subset of peers (“neighbors”).

While downloading, peer uploads chunks to other peers.

Peers may come and go. Once peer has entire file, it may (selfishly) leave

or (altruistically) remain.

BitTorrent - 1BitTorrent - 1

Page 213: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-255255

BitTorrent - 2BitTorrent - 2

Pulling Chunks At any given time,

different peers have different subsets of file chunks.

Periodically, a peer asks each neighbor for list of chunks that they have.

The peer sends requests for its missing chunks. The rarest first!

Sending Chunks: tit-for-tat A peer sends chunks to four

neighbors currently sending it 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 “optimistically unchoke”

Page 214: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-256256

ChokingChoking

One of BitTorrent’s most powerful idea is the choking mechanism.

It ensures that nodes cooperate and eliminates the free-rider problem.

Cooperation involves uploaded pieces that you have to your peer.

Choking is a temporary refusal to upload; downloading occurs as normal.

Connection is kept open so that setup costs are not borne again and again

Based on game-theoretic concepts Tit-for-tat strategy in Repeated Games

Page 215: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-257257

(1) A “optimistically unchokes” B.(2) A becomes one of B’s top-four providers; B reciprocates.(3) B becomes one of A’s top-four providers.

With higher upload rate, can find better trading partners & get file faster!

BitTorrent: Tit-for-tatBitTorrent: Tit-for-tat

A

B

Page 216: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-258258

Hybrid: Ads and DisAdsHybrid: Ads and DisAds

Advantages: Search is generally efficient

Disadvantages High cost on centralized index Performance & scalability bottleneck Vulnerable! Highly visible target

Page 217: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-259259

Pure P2P-1Pure P2P-1

All peers have equal roles in all responsibilities Example: Gnutella

In order to find an item, Peer 1 asks his neighbors if they have it.

They ask their neighbors, and so on

A message has a “time to live” which determines how long it will be sent along. Why is this needed?

Different search strategies will be discussed later

Page 218: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-260260

Pure P2P-2Pure P2P-2

What happens when a peer (say, Peer 34) is identified, who has the file that Peer 1 wants?

2 Different options are in use in different systems Peer 34 directly sends file to Peer 1 Peer 34 sends the file back in the same route that it

was requested Advantages/disadvantages of each option?

Page 219: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-261261

Pure P2PPure P2P

??

??

??

?

?

?

Page 220: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-262262

Pure P2P: Option 1Pure P2P: Option 1

Page 221: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-263263

Pure P2P: Option 2Pure P2P: Option 2

Page 222: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-264264

Gnutella: protocolGnutella: protocol

Query message HTTP sent over existing TCP connections

Gnutella on ports 6346 and 6347

peers forward Query message

QueryHit sent over reverse path

Scalability: limited scopeflooding

Query QueryHit

Query

QueryHit

QueryHit Query

Query

Query

File

Tran

sfer:

http

Page 223: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-265265

Gnutella Protocol MessagesGnutella Protocol Messages

Broadcast Messages Ping: initiating message (“I’m here”) Query: search pattern and TTL (time-to-live)

Back-Propagated Messages Pong: reply to a ping, contains information about the

peer Query response: contains information about the

computer that has the needed file Node-to-Node Messages

GET: return the requested file PUSH: push the file to me

Page 224: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-266266

Peer Joining in GnutellaPeer Joining in Gnutella

Joining peer X must find some other peer in Gnutella network; use list of candidate peers.

X sequentially attempts to make TCP connection with peers on list until connection setup with Y.

X sends Ping message to Y; Y forwarded Ping message. All peers receiving Ping message respond with Pong

message. X receives many Pong messages. It can then setup

additional TCP connections.

Peer living!

Page 225: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-267267

Topology of GnutellaTopology of Gnutella

Backbone Backbone + Outskirts

Page 226: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-268268

Pure: Ads and DisAdsPure: Ads and DisAds

Advantages: Easy to start No maintenance needed Hard to shut down privacy

Disadvantages: Inefficient search Lot of network traffic Bottlenecks (limited peers)

Page 227: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-269269

Super PeersSuper Peers

Make use of heterogeneity Powerful peers serve as super peers Weaker peers act as clients Example: KaZaA

Super-peers index clients’ files Requires updates on join/leave/update

Queries handled at super-peer level. Query evaluation between super-peers similar to

query evaluation between peers in a pure system.

Page 228: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-270270

Super PeersSuper Peers

Page 229: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-271271

Each peer is either a group leader or assigned to a group

leader. Group leader tracks

the content in all its children.

Each peer queries its group leader.

Group leader may query other group leaders.

KazaA on port 1214

ordinary peer (ordinary node)

group-leader peer (super node)

neighboring relationshipsin overlay network

Decentralized Directory (KaZaA)Decentralized Directory (KaZaA)

Page 230: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-272272

KazaA QueryKazaA Query

Each file has a hash and a descriptor. Client sends keyword query to its group

leader. Group leader responds with matches;

For each match: metadata, hash, IP address

If group leader forwards query to other group leaders, they respond with matches.

Client then selects files for downloading; HTTP requests using hash as identifier sent to peers

holding desired file.

Page 231: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-273273

Super Peers: Ads and DisAdsSuper Peers: Ads and DisAds

Advantages: All the advantages of pure Takes advantage of different peer capabilities

Disadvantages: Super nodes might become bottlenecks for clients Clients are disconnected when super peer leaves Inefficient search (but better than Pure P2P) Maintenance costs for super peers

Page 232: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-274274

Redundant Super Peers Redundant Super Peers

Like super peers, but each super-peer is k-redundant, i.e., there are k nodes sharing the super peer load all k nodes have the same indexes of all the clients clients ask super-peer queries in a round robin fashion

Page 233: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-275275

Super PeersSuper Peers

Page 234: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-276276

Redundant Super PeersRedundant Super Peers

Page 235: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-277277

Redundant Super Peers: Ads and DisAdsRedundant Super Peers: Ads and DisAds

Advantages All advantages of super-peers load of queries is shared among peers less points of fail

Disadvantages additional maintenance: nodes must notify all

redundant super-peers upon joining, leaving, updating files

Additional connections between super-peers required

Page 236: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-278278

Non-structured systemNon-structured system

Two phases (like Napster) Localization + exchange

No server Open source

gnutella.wego.com Distributed search

The query is flooded Loop avoidance Limited TTL (not all nodes are visited)

Page 237: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-279279

Structured systems (DHTs)Structured systems (DHTs)

Based on Distributed Hash Tables (DHTs) No flooding

Exact matches Overhead

Gnutella-like O(n) DHT O(log n)

Examples CAN, Pastry, Chord, Kademlia, Tapestry, P-Grid, ...

Page 238: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-294294

JXTA (Sun)JXTA (Sun)

Open platform for p2p cooperation

Interoperability Any system/peer/application

Platform independency Languages (C, Java, etc) Systems platforms (Unix, Windows, etc) Networking platforms (802.11, Bluetooth, TCP/IP, etc)

Ubiquity Sensors, PDAs, routers, desktops, laptops, storage

systems

Page 239: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-295295

JXTA (Sun)JXTA (Sun)

Objectives Find peers and resources Share files with anyone across the network Create a particular group of peers across different

networks Communicate securely with peers across public networks

Projects Applications (24 projects) Core (13 projects) Demos (3 projects) Forge (15 projects) Other (12 projects) Services (24 projects)

Page 240: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-296296

JXTA (Sun)JXTA (Sun)

Peer (Desktop, cell phone, PDA, etc.)

Security

Peer Groups Peer Pipes Peer Monitoring

JXTA Community ServicesSun JXTAServices

JXTAShell

PeerCommands

JXTA Community ApplicationsJXTA

applications

JXTA services

JXTA core

Page 241: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-297297

JXTA ProtocolsJXTA Protocols

Transport

Peer MembershipProtocol

Peer EndpointRouting Protocol

Peer ResolverProtocol

Peer DiscoveryProtocol

Peer BindingProtocol

Peer InformationProtocol

Peer

PeerGroup

Resolver

Endpoint

Transport

Peer MembershipProtocol

Peer EndpointRouting Protocol

Peer ResolverProtocol

Peer DiscoveryProtocol

Peer BindingProtocol

Peer InformationProtocol

Peer

PeerGroup

Resolver

Endpoint

Page 242: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-298298

JXTA ApplicationsJXTA Applications

JXTA Content Manager Service (CMS) Allows sharing and retrieving of content

InstantP2P Peer-to-peer messenger service Group chat File sharing

Net Services Standards such as WSDL (Web Service Description

Language ), ebXML (Electronic Business XML),

SOAP(Simple Object Access Protocol), UPnP (UPnP is a

protocol for data transmission), etc.

Page 243: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-299299

Final remarksFinal remarks

P2P implies a very large spectrum of areas High interest in both academicals/industrials Much has already been done, but no

conclusions are definitive IPv6 and P2P

NAT, firewalls, IPv6 as an overlay Many open issues

Trust, security, scalability, QoS, etc.

Page 244: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-300300

2.1 Principles of app layer protocols clients and servers app requirements

2.2 Web and HTTP 2.3 FTP 2.4 Electronic Mail

SMTP, POP3, IMAP 2.5 DNS

2.6 Socket programming with TCP

2.7 Socket programming with UDP

2.8 Building a Web server 2.9 Overlay Networks

P2P Networks Content Networks

Network Caches Content Distribution

Networks (CDNs) Server Farms

Chapter 2 OutlineChapter 2 Outline

Page 245: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-301301

browsers

serverserver

networks

Content in NetworkContent in Network

browsers

browsers

Page 246: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-302302

routers

The ProblemsThe Problems

browsersnetworks

serverserver

serverserver

browsers

browsersProblems: Congestio

n in routers

Overloading servers

High latency for users

Page 247: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-303303

browsers

server

Replicated Content(mirror)

router

content source

content sink(cache)

Content Network: IdeasContent Network: Ideas

Ideas: Network

Caches Content

Distribution Networks (mirror)

Server Farms.

Page 248: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-304304

The conventional Technologies are: Proxy cache server, and Mirror server

They are cost effective technologies which enhance the performance, namely: Reducing the latency of access. Reducing the network bandwidth required for

document transfers. Reducing the demand on servers with very popular

documents. Improving the security of electronic file transfer.

Servers: Caching, and MirrorServers: Caching, and Mirror(content distribution strategies)(content distribution strategies)

Page 249: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-305305

Caching: ideaCaching: idea(information distribution strategies)(information distribution strategies)

Basic idea in caching: Store the frequently retrieved documents

into local files or proxies for future use.

Caching on client disk: Browsers maintain small caches of previously-

viewed pages on the user’s local disk. ( example: Documents and Settings\WELCOME\Local Settings\Temporary Internet Files )

Network caching: Caching system is located on machine in

the path from multiple clients to multiple servers.

Page 250: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-306306

AAadvantages of web cachingadvantages of web caching

It improves access speed and cuts down on network traffic. increase availability in the web by replicating

documents among many servers (cache). Also:

It reduces the server load. Data can be accessed when remote server is down

(enhanced robustness). It allows analysis of organization usage patterns.

Page 251: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-307307

Disadvantages of web cachingDisadvantages of web caching

Data not updated automatically. Cache miss can cause increase in latency

(extra proxy processing). Bottleneck effect: limited number of clients per

proxy. A single proxy is a single point of failure. Information providers can not monitor number

of visits per site.

Page 252: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-308308

More about Web CachingMore about Web Caching

Cache acts as both client and server. Cache can do up-to-date check using If-modified-since HTTP header Issue: should cache take risk and deliver cached

object without checking? Heuristics are used.

Typically cache is installed by ISP (university, company, residential ISP)

Page 253: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-309309

Caching: proxyCaching: proxy(information distribution strategies)(information distribution strategies)

Caching proxy servers can be located near a large community of users such as:

on a campus network, at an intranet server, or at an ISP server.

Caching proxy servers can be located near a large community of users such as:

on a campus network, at an intranet server, or at an ISP server.

HTML, FTP, Search, Database

origin servers

Proxy Architecture

originservers

institutionalnetwork

institutionalCache(Proxy

server)

Internet

LAN router Internetrouter

Page 254: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-310310

user sets browser: Web accesses via cache (proxy)

browser sends all HTTP requests to cache (proxy)

object in cache: cache returns object

else cache requests object from origin server, then returns object to client

Goal: satisfy client request without involving origin server.

Goal: satisfy client request without involving origin server.

client

Proxyserver

client

HTTP request

HTTP request

HTTP response

HTTP response

HTTP request

HTTP response

origin server

origin server

Web Caches (Proxy web-Server)Web Caches (Proxy web-Server)

Page 255: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-311311

Service ProvidingEntity

λ :Arrival (request) Departure (response)

Content Distribution ModelContent Distribution Model

Service Providing Entity examples: Server LAN Access Link …

Service Providing Entity examples: Server LAN Access Link …

λ :Arrival rate (request) Departure rate (response)

Service ProvidingEntity

in servicewaiting

SOffered load Throughput

Page 256: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-312312

Model ParametersModel Parameters

λ : Average Arrival rate [requests/sec]

S: Average Service time [sec/response];

Example1: Server λ : Average Arrival rate [file request/sec]

S: Average Service time [sec/file response];

Example2: Link, LAN λ : Average Arrival rate [bit/sec]

S: Average Service time [sec/file] = L/R;

L: file length, R: Link Bandwidth

λ :Arrival rate (request) Departure rate (response)

Service ProvidingEntity

in servicewaiting

SOffered load Throughput

Page 257: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-313313

Model Equations (M/M/1)Model Equations (M/M/1)

Utilization of Service Providing Entity = U = λ x S

;

( λ ≤ 1/S )

delay (Response Time)=Service Time + Waiting

Time;

delay = S / (1-U) ;

Waiting Time (Queuing Delay) = delay – S

Page 258: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-314314

Equations for Link, LANEquations for Link, LAN

λ = a [files/sec]; rate of files entering into the

link, LAN

S = L/R [sec/file]; the time needed to pass a

file through the Link, LAN

U = λxS = La/R [ ]; Link, LAN Utilization

I = U [ ]; Link, LAN Traffic Intensity

delay = S/(1-U) = L/[R(1-U)] [secs/file]

Page 259: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-315315

Link Response TimeLink Response Time

Ruplink

LAN router

Internet router

Files from origin servers

Rdownlink

Request from clientsλ

λ’ Uup

link = Lreq λ /Ruplink = Iup

link

delayup = Sup/(1-Uuplink) [sec/req]

Udownlink = Lres λ’ /Rdown

link = Idownlink

delaydown = Sdown/(1-Udownlink) [sec/res]

delay = delayup + delaydown ≈ delaydown

It is because: Lres >> Lreq

Page 260: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-316316

Caching Example1 (1)Caching Example1 (1)

Assumptions

Average request rate from institution’s browser to origin

serves: λ = 15reqs/sec

Average request massage size ≈ 0 bit

Average object size = L= 100,000 bits

Internet delay ≈ 2 sec (average)

Time spent in the Internet

originservers

public Internet

LAN

Rlink =1.6 Mbps (up and down)

Rlan =10 Mbps

Page 261: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-317317

Caching Example1 (2)Caching Example1 (2)delay is calculated for down stream

only:

LAN Service time= Slan = L/Rlan = 10

msec

LAN Utilization = La/Rlan = 0.15 =

15% LAN delay =S/(1-U) = 10/0.85 =11.8

msec

Link Service time Slink = L/Rlink = 62.5

msec Link Utilization (Traffic Intensity) =

La/Rlink = 93.75%

Link delay = 62.5/0.0625 = 1000 msec

delay = Internet delay + access-link delay + LAN delay =

2000 + 1000 + 11.8 =3011.8 msecs

qrouter = 1000 – 62.5 = 937.5 msec

originservers

public Internet

LAN

Rlink =1.6 Mbps access-link

Rlan =10 Mbps

937.5 msecs

62.5 msecs

11.8 msecs

Page 262: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-318318

Caching Example2Caching Example2Upgrade the link:

LAN Service time= Slan = L/Rlan = 10

msec

LAN Utilization = La/Rlan = 0.15 = 15%

LAN delay = S/(1-U) = 10/0.85 = 11.8 msec

Link Service time Slink = L/Rlink = 10

msec Link Utilization (Traffic Intensity) =

La/Rlink = 15%

Link delay = 11.8 msec

delay = Internet delay + access-link delay + LAN delay =

2000 + 11.8 + 11.8 =2023.6 msecs

qrouter = 11.8 – 10 = 1.8 msec

originservers

public Internet

LAN

Rlink =10 Mbps access-link

Rlan =10 Mbps

1.8 msecs

10 msecs

11.8 msecs

Often a costly upgrade

Page 263: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-319319

Install cache suppose hit rate is 0.4

Consequence 40% requests will be satisfied

almost immediately 60% requests satisfied by origin

server utilization of access link (reduced

to 60%) = 0.6 *93.75= 56.25% Link delay = 62.5/0.4375 = 143

msec delay = 0.4* 11.8 + 0.6 x (2000

+ 143 + 11.8) = 1297.6 msec

Caching Example3Caching Example3origin

servers

public Internet

LAN

Rlink =1.6 Mbps access-link

Rlan =10 Mbps

80.5 msecs

62.5 msecs

11.8 msecs

Network cache

Page 264: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-320320

Content Distribution MetricContent Distribution Metric

Cost × Performance analysis is the key metric to the effectiveness of an information (content) distributed system.

Page 265: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-321321

Note: Cache miss FlowsNote: Cache miss Flowsorigin

servers

public Internet

LAN

Rlan =10 Mbps Network cache

Cache miss flows and utilization: There to sequential flows:

Flow of missed files from origin servers to cache server

Flow of the missed files from cache server to the clients.

Both above mentioned flows do not appear into LAN at the same time. At any given time there is one of them in the LAN.

So, LAN utilization = La/Rlan =

0.15 = 15%

Page 266: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-322322

When are DNS Queries Unnecessary?When are DNS Queries Unnecessary?

Client is configured to use a proxy Client sends all HTTP requests through a proxy. Then, the proxy takes care of issuing the DNS request.

Requested Web resource is locally cached Client has locally cached

http://www.irib.ir/1387/leadstory.html No need to request the resource, so no need to query.

Client recently queried (DNS) for a host name User recently visited http://www.irib.ir/ So, the client may be locally caching the resulting IP

address.

Page 267: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-323323

The content (information) providers are the CDN customers.

Content replication (mirror) CDN company installs

hundreds of CDN servers throughout Internet. in lower-tier ISPs, close

to users. CDN replicates its

customers’ content in CDN servers. When provider updates content, CDN updates servers.

Content Distribution Network: ideaContent Distribution Network: idea

origin server in North America

CDN distribution node

CDN serverin S. America CDN server

in Europe

CDN serverin Asia

Page 268: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-324324

1. Origin server informs RR of Content Availability.

2. Content Pushed to Distribution System.

3. Client Requests Content, Origin server redirects client to RR.

4. Client sends query to RR.

5. RR finds the most suitable Mirror Server.

6. Mirror server receives client request and provides services.

1. Origin server informs RR of Content Availability.

2. Content Pushed to Distribution System.

3. Client Requests Content, Origin server redirects client to RR.

4. Client sends query to RR.

5. RR finds the most suitable Mirror Server.

6. Mirror server receives client request and provides services.

CDN: Architectural LayoutCDN: Architectural LayoutRequestRequest

Routing(RR)Routing(RR)RequestRequest

Routing(RR)Routing(RR)

Distribution Distribution NodeNode

Distribution Distribution NodeNode

OriginOriginServerServerOriginOriginServerServer

1

2a

ClientClientClientClient

MirrorMirrorServerServerMirrorMirrorServerServer

2b

6

4

Clie

nt

request

s

OS re

dire

cts client

3

Clie

nt

sen

ds

request

5

RR

sends clie

nt’s

request

Page 269: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-325325

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

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 overlay network

not just Web pages streaming stored

audio/video streaming real-time

audio/video CDN nodes create

application-layer overlay network

More about CDNsMore about CDNs

Page 270: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-326326

Arbitrate client requests to servers using an “intelligent” L4-L7 switch

Widely used today

Arbitrate client requests to servers using an “intelligent” L4-L7 switch

Widely used today

Content networks: Server Farms Content networks: Server Farms Simple solution to the content distribution problem:

deploy a large group of servers

Simple solution to the content distribution problem: deploy a large group of servers

L4-L7 Switch(Load balancer)

Request fromgrad.ut.edu

Request from iust.ac.ir

Request fromiust.ac.ir

Request fromgrad.ut.edu

www.x.com (Copy n)

www.x.com (Copy 1)

Virtual IP addr.

Virtual IP addr.

Virtual IP addr.

Page 271: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-327327

application service requirements:

reliability, bandwidth, delay.

client-server paradigm.

Internet transport service model.

connection-oriented, reliable: TCP

unreliable, datagrams: UDP

application service requirements:

reliability, bandwidth, delay.

client-server paradigm.

Internet transport service model.

connection-oriented, reliable: TCP

unreliable, datagrams: UDP

Our study of network apps now complete!Our study of network apps now complete!

specific protocols: HTTP FTP SMTP, POP, IMAP DNS

socket programming

content distribution P2P caches, CDNs,

Server Farms.

specific protocols: HTTP FTP SMTP, POP, IMAP DNS

socket programming

content distribution P2P caches, CDNs,

Server Farms.

Chapter 2: Summary1Chapter 2: Summary1

Page 272: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-328328

typical request/reply message exchange: client requests info or

service server responds with

data, status code message formats:

headers: fields giving information about data

data: information being communicated

typical request/reply message exchange: client requests info or

service server responds with

data, status code message formats:

headers: fields giving information about data

data: information being communicated

Most importantly: learned about protocolsMost importantly: learned about protocols

control vs data messages in-band, out-of-band

centralized vs. decentralized

stateless vs. stateful reliable vs. unreliable msg

transfer “complexity at network edge” security: authentication

control vs data messages in-band, out-of-band

centralized vs. decentralized

stateless vs. stateful reliable vs. unreliable msg

transfer “complexity at network edge” security: authentication

Chapter 2: Summary2Chapter 2: Summary2

Page 273: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-329329

Complimentary Hyperlinks This part provides hyperlinks to interesting

(and hopefully useful) computer-networking resources.

Most of these resources provide complimentary information to the material in chapter 2.

If you're asked to write a paper pertaining to a specialized topic in computer networking, these resources should serve as a good starting point for your research.

Complimentary Hyperlinks This part provides hyperlinks to interesting

(and hopefully useful) computer-networking resources.

Most of these resources provide complimentary information to the material in chapter 2.

If you're asked to write a paper pertaining to a specialized topic in computer networking, these resources should serve as a good starting point for your research.

References & LinksReferences & Links

References and Hyperlinks

Page 274: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-330330

Unix Network Programming http://www-aml.cs.umass.edu/~jsmanic/unetpgm

Online tutorial on Unix socket programming, using slides and audio, from author James Kurose.

Tutorial on Java sockets http://www.javaworld.com/javaworld/jw-12-1996/jw-12-sockets.html

This tutorial presents an introduction to sockets programming and shows how to write client/server applications in Java.

ComplimentaryComplimentary Hyperlinks Hyperlinks11

Page 275: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-331331

The World Wide Web Consortium (W3C) http://www.w3.org/ The W3C was founded in 1994 to develop common protocols for the

evolution of the World Wide Web. This is an outstanding site with fascinating information on emerging Web technologies, protocols, and standards.

Web Protocols and Practice http://www.aw.com/catalog/academic/product/1,4096,0201710889,00.html

Web Protocols and Practice: HTTP/1.1, Networking Protocols, Caching, and Traffic Measurement, a comprehensive and readable book by Balachander Krishnamurthy and Jennifer Rexford on Web protocols and related topics.

Cookie Central http://www.cookiecentral.com/ Everything you ever wanted to know about cookies, including how they

infringe on users' privacy.

The IMAP Connection http://www.imap.org/ Everything you always wanted to know about IMAP, including history, direct

access to relevant RFCs, and product information.

ComplimentaryComplimentary Hyperlinks Hyperlinks22

Page 276: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-332332

ISC BIND http://www.isc.org/products/BIND DNS name servers use the Berkeley Internet Name Domain

(BIND) software. You can learn about it (and download it) here.

Exploring Name Servers http://www.unhooked.net/cgi-bin/host

nslookup, host, and dig are client programs available for exploring the contents of name servers in the Internet. Several sites, including the one listed above, allow you to access these programs through a Web browser. All of these programs mimic DNS clients. They send a DNS query message to a name server (which can often be supplied by the user), and they receive a corresponding DNS response. They then extract information (e.g., IP addresses, whether the response is authoritative, etc.) and present the information to the user.

ComplimentaryComplimentary Hyperlinks Hyperlinks33

Page 277: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-333333

Online Java Tutorial http://java.sun.com/docs/books/tutorial Do you what to learn Java before doing the programming

exercises? This is an excellent place to start.

Akamai Homepage http://www.akamai.com/ Homepage for leading Content Distribution Network (CDN)

company.

Developers Site for Gnutella http://www.gnutelladev.com/ Includes links to source code as well as links to documentation of

the protocol.

ComplimentaryComplimentary Hyperlinks Hyperlinks 4 4

Page 278: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-334334

A note on Internet Request for Comments (RFCs): Copies of Internet RFCs are maintained at multiple sites. The RFC URLs below all point into the RFC archive at the Information Sciences Institute (ISI), maintained the the RFC Editor of the Internet Society (the body that oversees the RFCs). Other RFC sites include http://www.faqs.org/rfc, http://www.pasteur.fr/other/computer/RFC (located in France), and http://www.csl.sony.co.jp/rfc/ (located in Japan). 

Internet RFCs can be updated or obsoleted by later RFCs. We encourage you to check the sites listed above for the most up-to-date information. The RFC search facility at ISI, http://www.rfc-editor.org/rfcsearch.html, will allow you to search for an RFC and show updates to that RFC. 

[Abitz 1993] P. Albitz and C. Liu, DNS and BIND, O'Reilly & Associates, Petaluma, CA, 1993. 

[Akamai 2000] Akamai homepage, http://www.akamai.com

References and HyperlinksReferences and Hyperlinks11

Page 279: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-335335

[Berners-Lee 1994] T. Berners-Lee, R. Cailliau, A. Luotonen, H. Frystyk Nielsen, and A. Secret, "The World-Wide Web," Commun. ACM 37, 8 (Aug. 1994), Pages 76-82 

[BIND 2000] Internet Software Consortium page on BIND, http://www.isc.org/bind.html

[Claffy 1998] K. Claffy, G. Miller, and K. Thompson, "The Nature of the Beast: Recent Traffic Measurements from an Internet Backbone," Proceedings of Inet '98 , (Geneva, Switzerland, July 1998), http://www.caida.org/outreach/resources/papers/Inet98/

[Cookie Central 2000] Cookie Central homepage, http://www.cookiecentral.com

[Cusumano 1998] M.A. Cusumano and D.B. Toffle, Competing on Internet Time: Lessons from Netscape and its Battle with Microsoft, Free Press, 1998 

[DNSNet] DNSNet page on DNS resources, http://www.dns.net/dnsrd/docs/

References and HyperlinksReferences and Hyperlinks22

Page 280: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-336336

[Frost 1994] J. Frost, "BSD Sockets: A Quick and Dirty Primer," http://world.std.com/~jimf/papers/sockets/sockets.html

[Gauthier 1999] L. Gauthier, C. Diot, and J. Kurose, "End-to-end Transmission Control Mechanisms for Multiparty Interactive Applications on the Internet," Proceedings of IEEE Infocom '99, (New York, NY, Apr. 1999). ftp://ftp.sprintlabs.com/diot/infocom99-mimiaze.zip

[Gay 1997] V. Gay and B. Dervella, "MHEGAM--A Multimedia Messaging System," IEEE Multimedia Magazine, Oct.-Dec. 1997, pp. 22-29. 

References and HyperlinksReferences and Hyperlinks33

Page 281: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-337337

[Heidemann 1997] J. Heidemann, K. Obraczka, and J. Touch, "Modeling the Performance of HTTP over Several Transport Protocols," IEEE/ACM Transactions on Networking, Vol. 5, No. 5 (Oct. 1997), pp. 616-630. 

[Hess 1998] C. Hess, D. Lin and K. Nahrstedt, "VistaMail: An Integrated Multimedia Mailing System," IEEE Multimedia Magazine, Oct.-Dec. 1998, pp. 13-23. 

[Huffaker 1998] B. Huffaker, J. Jung, D. Wessels, and K. Claffy, "Visualization of the Growth and Topology of the NLANR Caching Hierarchy," The 3rd Web Caching Workshop, June 1998, England. http://www.caida.org/tools/visualization/plankton/Paper/plankton.xml

References and HyperlinksReferences and Hyperlinks44

Page 282: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-338338

[IMAP 1999] The IMAP Connection, http://www.imap.org/ [ITU 1997] International Telecommunications Union,

"Recommendation E.164/ I.331--The international public telecommunication numbering plan," May 1997. http://www.itu.int/itudoc/itu-t/rec/e/s_e164.html

[Kurose 1996] J. F. Kurose, Unix Network Programming. http://manic.cs.umass.edu/~amldemo/courseware/intro.html

[Luotonen 1998] A. Luotonen, Web Proxy Servers, Prentice Hall, Englewood Cliffs, New Jersey, 1998. 

[McKusik 1996] Marshall Kirk McKusick, Keith Bostic, Michael Karels, and John Quarterman, The Design and Implementation of the 4.4BSD Operating System, Addison-Wesley, Reading, MA, 1996. 

[Netcraft 2000] The Netcraft Web Server Survey, Netcraft Web Site, http://www.netcraft.com/survey/

References and HyperlinksReferences and Hyperlinks55

Page 283: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-339339

[Netscape Cookie 1999] Netscape, "Persistent Client State http Cookies. http://home.netscape.com/newsref/std/cookie_spec.html

[Nielsen 1997] H. F. Nielsen, J. Gettys, A. Baird-Smith, E. Prud'hommeaux, H. W. Lie, and C. Lilley, "Network Performance Effects of HTTP/1.1, CSS1, and PNG," W3C Document, 1997 (also appears in Proceedings of ACM SIGCOMM '97, Cannes, France, pp. 155-166 ). http://www.acm.org/sigcomm/sigcomm97/papers/p102.html

[NLANR 1999] A Distributed Testbed for National Information Provisioning, http://ircache.nlanr.net/

[Padhye 1999] J. Padhye and J. Kurose, "An Empirical Study of Client Interactions with a Continuous-Media Courseware Server," IEEE Internet Computing, Apr. 1999. ftp://gaia.cs.umass.edu/pub/Padh97:Empirical.ps.gz

[Ramjee 1994] R. Ramjee, J. Kurose, D. Towsley, and H. Schulzrinne, "Adaptive Playout Mechanisms for Packetized Audio Applications in Wide-Area Networks," Proceeding IEEE Infocom 94. ftp://gaia.cs.umass.edu/pib/Ramj94:Adaptive.ps.Z

[RFC 821] J. Postel, "Simple Mail Transfer Protocol," RFC 821, Aug. 1982. http://www.rfc-editor.org/rfc/rfc821.txt

References and HyperlinksReferences and Hyperlinks66

Page 284: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-340340

[RFC 854] J. Postel and J. Reynolds, "TELNET Protocol Specification," RFC 854. May 1993. http://www.rfc-editor.org/rfc/rfc854.txt

[RFC 959] J. Postel and J. Reynolds, "File Transfer Protocol (FTP)," RFC 959, Oct. 1985. http://www.rfc-editor.org/rfc/rfc959.txt

[RFC 1034] P. V. Mockapetris, "Domain Names--Concepts and Facilities," RFC 1034, Nov. 1987. http://www.rfc-editor.org/rfc/rfc1034.txt

[RFC 1035] P. Mockapetris, "Domain Names--Implementation and Specification," RFC 1035, Nov. 1987. http://www.rfc-editor.org/rfc/rfc1035.txt

[RFC 1945] T. Berners-Lee, R. Fielding, H. Frystyk, "Hypertext Transfer Protocol--HTTP/1.0," RFC 1945, May 1996 http://www.rfc-editor.org/rfc/rfc1945.txt

[RFC 2045] N. Freed, N. Borenstein, "Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies," RFC 2045, Nov. 1996. http://www.rfc-editor.org/rfc/rfc2045.txt

References and HyperlinksReferences and Hyperlinks77

Page 285: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-341341

[RFC 2046] N. Freed, N. Borenstein,, "Multipurpose Internet Mail Extensions (MIME) Part Two: Media Types," RFC 2046, Nov. 1996. http://www.rfc-editor.org/rfc/rfc2046.txt

[RFC 2068] R. Fielding, J. Gettys, J. Mogul, H. Frystyk, and T. Berners-Lee, "Hypertext Transfer Protocol--HTTP/1.1," RFC 2068, Jan. 1997. http://www.rfc-editor.org/rfc/rfc2068.txt. Obsoleted by RFC 2616. 

[RFC 2186] K. Claffy and D. Wessels, "Internet Caching Protocol (ICP), version 2," RFC 2186, Sept. 1997. http://www.rfc-editor.org/rfc/rfc2186.txt

[RFC 2616] R. Fielding, J. Gettys, J. Mogul, H. Frystyk, L. Masinter, P. Leach, T. Berners-Lee, R. Feilding, "Hypertext Transfer Protocol--HTTP/1.1," RFC 2616, June 1999. http://www.rfc-editor.org/rfc/rfc2616.txt

[Ross 1997] K. W. Ross, "Hash-Routing for Collections of Shared Web Caches," IEEE Network Magazine, Vol. 11 (Nov.-Dec. 1997), pp. 37-45. 

[Ross 1998] K. W. Ross, Distribution of Stored Information in the Web, An Online Tutorial, http://www.eurecom.fr/~ross/CacheTutorial/DistTutorial.html, 1998. 

References and HyperlinksReferences and Hyperlinks88

Page 286: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-342342

[Schurmann 1996] G. Schurmann, "Multimedia Mail," ACM Multimedia Systems, Oct. 1996, pp. 281-295. 

[Squid 2000] Squid Web Proxy Cache, http://www.squid-cache.org/ [Stevens 1997] W.R. Stevens, Unix Network Programming, Volume 1:

Networking APIs-Sockets and XTI, 2nd edition, Prentice-Hall, Englewood Cliffs, NJ, 1997. 

[Turner 1999] D. A. Turner and K. W. Ross, "Continuous-Media Internet E-Mail: Infrastructure Inadequacies and Solutions," http://www.eurecom.fr/~turner/cmail1.html

[Valloppillil 1997] V. Valloppillil and K. W. Ross, "Cache Array Routing Protocol," Internet Draft, <draft-vinod-carp-v1-03.txt>, June 1997. 

[Yeager 1996] N. J. Yeager and R. E. McGrath, Web Server Technology, Morgan Kaufmann Publishers, San Francisco, 1996. © 2000-2001 by Addison Wesley LongmanA division of Pearson Education

References and HyperlinksReferences and Hyperlinks99

Page 287: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-343343

P2P-Working groups et al.P2P-Working groups et al.

A generic site on p2p from O'Reilly www.openp2p.com

P2P working group www.peer-to-peerwg.org/

Internet2 p2p working group p2p.internet2.edu

Peer-to-peer development (p2p-hackers) zgp.org/mailman/listinfo/p2p-hackers

Interesting meeting www.codecon.org

Page 288: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-344344

P2P-References-1P2P-References-1

Distributed Computing Distributed (www.distributed.net) SETI@home (www.seti.org) Genome@home (gah.stanford.edu) Folding@home (www.stanford.edu/group/pandegroup/folding) Global Grid Forum (www.globalgridforum.org) Globus Project (www.globus.org)

File sharing Napster (www.napster.com) Gnutella (gnutella.wego.co) Kazaa (www.kazaa.com)

Page 289: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-345345

P2P-References-2P2P-References-2

Distributed hash tables CAN (www.acm.org/sigs/sigcomm/sigcomm2001/p13-

ratnasamy.pdf) Pastry (research.microsoft.com/~antr/Pastry) Chord (www.pdos.lcs.mit.edu/chord) Tapestry (www.cs.berkeley.edu/~ravenben/tapestry) Freenet (freenet.sourceforge.net) Kademlia (kademlia.scs.cs.nyu.edu)

Ad hoc networking AODV (www.ietf.org/internet-drafts/draft-ietf-manet-aodv-

13.txt) OLSR (www.ietf.org/internet-drafts/draft-ietf-manet-olsr-10.txt) Tribe (rp.lip6.fr/site_rp/_publications/350-79Viana.ps.gz)

Page 290: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-346346

P2P-References-3P2P-References-3

Platforms JXTA (www.jxta.org) .NET (www.microsoft.com/net)

Collaboration Groove (www.groove.net) Endeavors (www.endeavors.com)

IPv6 as a p2p overlay Working Groups

p2p.internet2.edu www.openp2p.com

Page 291: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-347347

Socket Programming in C

AppendixAppendix

Page 292: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-348348

Client must contact server• server process must first be running• server must have created socket

(door) that welcomes client’s contact

Client contacts server by:• creating client-local TCP

socket• specifying IP address, port

number of server process• When client creates socket:

client TCP establishes connection to server TCP

• When contacted by client, server TCP creates new socket for server process to communicate with client– allows server to talk

with multiple clients– source port numbers

used to distinguish clients (more in Chap 3)

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

application viewpoint

Socket programming Socket programming with TCPwith TCP

Page 293: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-349349

/* client.c */void main(int argc, char *argv[]){ struct sockaddr_in sad; /* structure to hold an IP address */ int clientSocket; /* socket descriptor */ struct hostent *ptrh; /* pointer to a host table entry */

char Sentence[128]; char modifiedSentence[128];

host = argv[1]; port = atoi(argv[2]);

clientSocket = socket(PF_INET, SOCK_STREAM, 0); memset((char *)&sad,0,sizeof(sad)); /* clear sockaddr structure

*/ sad.sin_family = AF_INET; /* set family to Internet */ sad.sin_port = htons((u_short)port); ptrh = gethostbyname(host); /* Convert host name to IP address

*/memcpy(&sad.sin_addr, ptrh->h_addr, ptrh->h_length);

connect(clientSocket, (struct sockaddr *)&sad, sizeof(sad));

Create client socket, connect to server

Example: C client (TCP)Example: C client (TCP)

Page 294: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-350350

gets(Sentence);

n=write(clientSocket, Sentence, strlen(Sentence)+1);

n=read(clientSocket, modifiedSentence, sizeof(modifiedSentence)); printf("FROM SERVER: %s\n”,modifiedSentence);

close(clientSocket); }

Get input stream

from user

Send lineto server

Read linefrom server

Close connection

Example: C client (TCP), cont.Example: C client (TCP), cont.

Page 295: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-351351

/* server.c */void main(int argc, char *argv[]){ struct sockaddr_in sad; /* structure to hold an IP address */ struct sockaddr_in cad;int welcomeSocket, connectionSocket; /* socket descriptor */ struct hostent *ptrh; /* pointer to a host table entry */

char clientSentence[128]; char capitalizedSentence[128];

port = atoi(argv[1]);

welcomeSocket = socket(PF_INET, SOCK_STREAM, 0); memset((char *)&sad,0,sizeof(sad)); /* clear sockaddr structure */ sad.sin_family = AF_INET; /* set family to Internet */ sad.sin_addr.s_addr = INADDR_ANY; /* set the local IP address */ sad.sin_port = htons((u_short)port);/* set the port number */

bind(welcomeSocket, (struct sockaddr *)&sad, sizeof(sad));

Create welcoming socket at port &

Bind a local address

Example: C server (TCP)Example: C server (TCP)

Page 296: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-352352

/* Specify the maximum number of clients that can be queued */listen(welcomeSocket, 10)

while(1) {

connectionSocket=accept(welcomeSocket, (struct sockaddr *)&cad, &alen); n=read(connectionSocket, clientSentence, sizeof(clientSentence)); /* capitalize Sentence and store the result in capitalizedSentence*/

n=write(connectionSocket, capitalizedSentence, strlen(capitalizedSentence)+1);

close(connectionSocket); } }

Write out the result to socket

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

Wait, on welcoming socket for contact by a client

Example: C server (TCP), contExample: C server (TCP), cont

Page 297: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-353353

UDP: no “connection” between client and server

• no handshaking• sender explicitly attaches

IP address and port of destination to each packet

• 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

Socket programming Socket programming with UDPwith UDP

Page 298: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-354354

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

Client/server socket interaction: UDPClient/server socket interaction: UDP

Page 299: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-355355

/* client.c */void main(int argc, char *argv[]){ struct sockaddr_in sad; /* structure to hold an IP address */ int clientSocket; /* socket descriptor */ struct hostent *ptrh; /* pointer to a host table entry */

char Sentence[128]; char modifiedSentence[128];

host = argv[1]; port = atoi(argv[2]);

clientSocket = socket(PF_INET, SOCK_DGRAM, 0);

/* determine the server's address */memset((char *)&sad,0,sizeof(sad)); /* clear sockaddr structure

*/ sad.sin_family = AF_INET; /* set family to Internet */ sad.sin_port = htons((u_short)port); ptrh = gethostbyname(host); /* Convert host name to IP address

*/memcpy(&sad.sin_addr, ptrh->h_addr, ptrh->h_length);

Create client socket, NO connection to server

Example: C client (UDP)Example: C client (UDP)

Page 300: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-356356

gets(Sentence);

addr_len =sizeof(struct sockaddr); n=sendto(clientSocket, Sentence, strlen(Sentence)+1, (struct sockaddr *) &sad, addr_len);

n=recvfrom(clientSocket, modifiedSentence, sizeof(modifiedSentence). (struct sockaddr *) &sad, &addr_len); printf("FROM SERVER: %s\n”,modifiedSentence);

close(clientSocket); }

Get input stream

from user

Send lineto server

Read linefrom server

Close connection

Example: C client (UDP), cont.Example: C client (UDP), cont.

Page 301: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-357357

/* server.c */void main(int argc, char *argv[]){ struct sockaddr_in sad; /* structure to hold an IP address */ struct sockaddr_in cad;int serverSocket; /* socket descriptor */ struct hostent *ptrh; /* pointer to a host table entry */

char clientSentence[128]; char capitalizedSentence[128];

port = atoi(argv[1]);

serverSocket = socket(PF_INET, SOCK_DGRAM, 0); memset((char *)&sad,0,sizeof(sad)); /* clear sockaddr structure */ sad.sin_family = AF_INET; /* set family to Internet */ sad.sin_addr.s_addr = INADDR_ANY; /* set the local IP address */ sad.sin_port = htons((u_short)port);/* set the port number */

bind(serverSocket, (struct sockaddr *)&sad, sizeof(sad));

Create welcoming socket at port &

Bind a local address

Example: C server (UDP)Example: C server (UDP)

Page 302: Application Layer ( 2-89-90) 2-1. Application Layer Computer Networks.

Application Layer (Application Layer (2-89-90)2-89-90) 2-2-358358

while(1) {

n=recvfrom(serverSocket, clientSentence, sizeof(clientSentence), 0 (struct sockaddr *) &cad, &addr_len ); /* capitalize Sentence and store the result in capitalizedSentence*/

n=sendto(connectionSocket, capitalizedSentence, strlen(capitalizedSentence)+1,0 (struct sockaddr *) &cad, &addr_len);

close(connectionSocket); } }

Write out the result to socket

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

Receive messages from clients

Example: C server (UDP), contExample: C server (UDP), cont