Chapter2_5th_Aug2009 - Network

119
2: Application Layer 1 Chapter 2 Application Layer Computer Networking: A Top Down Approach , 5 th  edition. Jim uro!e, eith "o!! Addi!on#$e!ley, April 2%%&.  A note on the use of th ese ppt slides: We’re making these slides f reely available to all (faculty, students, readers). They’re in o!eroint form so you can add, modify, and delete slides (including this one) and slide content to suit your needs. They obviously represent a lot  of !ork on our part. "n return for use, !e only ask the follo!ing:  "f you use these slides (e.g., in a class) in substantially unaltered form, that you mention their source (after all, !e’d like people to use our book#)  "f you p ost any slides in substantially unaltered form on a !!! site, that you note that they are adapted from (or perhaps identical to) our slides, and note our copyright of this material. Thanks and en$oy# %&''W  All material copyright *++-//+ %.& 'urose and ' .W. oss, All ights eserv ed

Transcript of Chapter2_5th_Aug2009 - Network

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 1/119

2: Application Layer 1

Chapter 2

Application Layer

Computer Networking:A Top Down Approach ,5th edition.Jim uro!e, eith "o!!Addi!on#$e!ley, April2%%&.

 A note on the use of these ppt slides:We’re making these slides freely available to all (faculty, students, readers).

They’re in o!eroint form so you can add, modify, and delete slides

(including this one) and slide content to suit your needs. They obviously

represent a lot  of !ork on our part. "n return for use, !e only ask the

follo!ing:

 "f you use these slides (e.g., in a class) in substantially unaltered form,that you mention their source (after all, !e’d like people to use our book#)  "f you post any slides in substantially unaltered form on a !!! site, that

you note that they are adapted from (or perhaps identical to) our slides,

and note our copyright of this material.

Thanks and en$oy# %&''W

 All material copyright *++-//+

%.& 'urose and '.W. oss, All ights eserved

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 2/119

2: Application Layer 2

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 3/119

2: Application Layer 3

Chapter 2: Application layer

2.' (rinciple! o)network application!

2.2 $e* and +TT(

2. -T( 2. /lectronic 0ail

10T(, ((, 30A(

2.5 DN1

2.6 P2P applications

2.7 Socket programming with

UDP

2.8 Socket programming with

TCP

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 4/119

2: Application Layer 4

Chapter 2: Application Layer

ur goal!:  conceptual,

implementationa!pect! o) network

application protocol! tran!port#layer

!er4ice model! client#!er4er

paradigm peer#to#peer

paradigm

learn ao!t protocols "e#amining pop!lar

application$le%el

 protocols

+TT( -T( 10T( (( 30A( DN1

 programming network

applications

!ocket A(3

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 5/119

2: Application Layer &

1ome network app!

e#mail we* in!tant me!!aging

remote login (2( )ile !haring multi#u!er network

game!

!treaming !tored 4ideoclip!

social networks

%oice o%er 'P

real$time %i(eo con)erencing

gri( comp!ting

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 6/119

2: Application Layer 6

Creating a network app

write program! that run on 6di))erent7 end

!y!tem!  communicate o4er network e.g., we* !er4er !o)tware

communicate! with*row!er !o)tware

No need to write !o)tware)or network#core de4ice!

Network#core de4ice! donot run u!er application!

application! on end !y!tem!allow! )or rapid app

de4elopment, propagation

applicationtran!portnetworkdata link

phy!ical

applicationtran!portnetwork

data linkphy!ical

applicationtran!portnetworkdata linkphy!ical

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 7/119

2: Application Layer 7

Chapter 2: Application layer

2.' (rinciple! o)network application!

2.2 $e* and +TT(

2. -T( 2. /lectronic 0ail 10T(, ((, 30A(

2.5 DN1

2.6 P2P applications

2.7 Socket programming with

UDP

2.8 Socket programming with

TCP

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 8/119

2: Application Layer 8

Application architecture!

Client#!er4er 3ncluding data center! cloud computing

(eer#to#peer 6(2(7

+y*rid o) client#!er4er and (2(

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 9/119

2: Application Layer *

Client#!er4er architecture

ser%er+  alway!#on ho!t permanent 3( addre!! !er4er )arm! )or

!calingclients+

communicate with !er4er may *e intermittently

connected may ha4e dynamic 3(

addre!!e! do not communicate

directly with each other

client!er4er

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 10/119

8oogle Data Center!

/!timated co!t o) data center: 9%%0 8oogle !pent 92.; in 2%%< on new data

center!

/ach data center u!e! 5%#'%% megawatt!o) power

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 11/119

2: Application Layer 11

(ure (2( architecture

no  alway!#on !er4er ar*itrary end !y!tem!

directly communicate

peer! are intermittentlyconnected and change 3(addre!!e!

+ighly !cala*le *utdi))icult to manage

peer#peer

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 12/119

2: Application Layer 12

+y*rid o) client#!er4er and (2(

1kype 4oice#o4er#3( (2( application centrali=ed !er4er: )inding addre!! o) remote

party: client#client connection: direct 6not through

!er4er73n!tant me!!aging

chatting *etween two u!er! i! (2( centrali=ed !er4ice: client pre!ence

detectionlocation• u!er regi!ter! it! 3( addre!! with central

!er4er when it come! online• u!er contact! central !er4er to )ind 3(

addre!!e! o) *uddie!

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 13/119

2: Application Layer 13

(roce!!e! communicating

(roce!!: program runningwithin a ho!t.

within !ame ho!t, twoproce!!e! communicate

u!ing inter#proce!!communication 6de)ined*y 17.

proce!!e! in di))erent

ho!t! communicate *ye>changing me!!age!

Client process+ process that

initiates comm!nication

Ser%er process+ process that

waits to e contacte(

Note: application! with

(2( architecture! ha4eclient proce!!e! ?!er4er proce!!e!

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 14/119

2: Application Layer 14

1ocket!

proce!! !end!recei4e!me!!age! to)rom it!!ocket

!ocket analogou! to door !ending proce!! !ho4e!

me!!age out door !ending proce!! relie! on

tran!port in)ra!tructureon other !ide o) door which*ring! me!!age to !ocketat recei4ing proce!!

 process

TCP with

 !))ers,

%ariales

socket

host or ser%er 

 process

TCP with

 !))ers,

%ariales

socket

host or ser%er 

'nternet

controlle( " -S

controlle( "

app (e%eloper 

A(3: 6'7 choice o) tran!port protocol@ 627 a*ility to )i>a )ew parameter! 6lot! more on thi! later7

 

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 15/119

2: Application Layer 1&

Addre!!ing proce!!e!

to recei%e messages, process

m!st ha%e identifier 

host (e%ice has !ni!e 32$it 'P

a((ress

/#ercise+ !se ipconfig )rom

comman( prompt to get "o!r'P a((ress 0in(ows

:  doe! 3( addre!! o)

ho!t on which proce!!run! !u))ice )oridenti)ying the proce!!B A:  No, many  proce!!e!

can *e running on!ame 3denti)ier  include! *oth

3( addre!! and portnum*er! a!!ociated withproce!! on ho!t.

/>ample port num*er!: +TT( !er4er: % 0ail !er4er: 25

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 16/119

2: Application Layer 16

App#layer protocol de)ine!

Type! o) me!!age!e>changed, e.g., reue!t, re!pon!e

0e!!age !ynta>: what )ield! in me!!age! ?

how )ield! are delineated

0e!!age !emantic! meaning o) in)ormation in

)ield! "ule! )or when and how

proce!!e! !end ?re!pond to me!!age!

P!lic$(omain protocols+

(e)ine( in Cs

allows )or interoperailit"

e.g., 5TTP, STP,

itTorrentProprietar" protocols+

e.g., Sk"pe, ppstream

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 17/119

2: Application Layer 17

$hat tran!port !er4ice doe! an app needB

Data lo!! !ome app! 6e.g., audio7 can

tolerate !ome lo!! other app! 6e.g., )ile

tran!)er, telnet7 reuire

'%%E relia*le datatran!)er Timingsome apps 0e.g., 'nternet

telephon", interacti%egames re!ire low (ela"to e e))ecti%e9

Throughput !ome app! 6e.g.,

multimedia7 reuireminimum amount o)throughput to *e

Fe))ecti4eG other app! 6Fela!tic app!G7

make u!e o) whate4erthroughput they get

1ecurity /ncryption, data integrity,

H

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 18/119

2: Application Layer 18

Tran!port !er4ice reuirement! o) common app!

Application

file transfer 

e-mail

Web documentsreal-time audiovideo

stored audiovideo

interactive games

instant messaging

Data loss

no loss

no loss

no lossloss-tolerant

loss-tolerant

loss-tolerant

no loss

Throughput

elastic

elastic

elasticaudio: 0kbps-*1bps

video:*/kbps-01bps

same as above

fe! kbps up

elastic

Time Sensitive

no

no

noyes, *//’s msec

yes, fe! secs

yes, *//’s msec

yes and no

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 19/119

2: Application Layer 1*

3nternet tran!port protocol! !er4ice!

TC( !er4ice: connection#oriented:  !etup

reuired *etween client and!er4er proce!!e!

relia*le tran!port *etween!ending and recei4ing proce!! )low control:  !ender wonIt

o4erwhelm recei4er conge!tion control:  throttle

!ender when networko4erloaded

doe! not pro4ide:  timing,minimum throughputguarantee!, !ecurity

UDP ser%ice+!nreliale (ata trans)er etween

sen(ing an( recei%ing process

(oes not pro%i(e+ connection

set!p, reliailit", )low control,

congestion control, timing,

thro!ghp!t g!arantee, or

sec!rit"

:+ wh" other; h" is there a

UDP;

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 20/119

2: Application Layer 2<

3nternet app!: application, tran!port protocol!

Application

e-mail

remote terminal access

Webfile transfer 

streaming multimedia

"nternet telephony

Applicationlayer protocol

21T 3&4 5*6

Telnet 3&4 5076

8TT 3&4 *6&T 3&4 +0+6

8TT (eg 9outube),

T 3&4 *55+6

2", T, proprietary

(e.g., 2kype)

Underlyingtransport protocol

T4

T4

T4T4

T4 or ;

typically ;

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 21/119

2: Application Layer 21

Chapter 2: Application layer

2.' (rinciple! o)network application!

2.2 $e* and +TT(

2. -T( 2. /lectronic 0ail 10T(, ((, 30A(

2.5 DN1

2.6 P2P applications

2.7 Socket programming with

UDP

2.8 Socket programming with

TCP

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 22/119

2: Application Layer 22

$e* and +TT(

-ir!t !ome argon $e* page con!i!t! o) o*ect! *ect can *e +T0L )ile, J(/8 image, Ja4a

applet, audio )ile,H $e* page con!i!t! o) *a!e +T0L#)ile whichinclude! !e4eral re)erenced o*ect!

/ach o*ect i! addre!!a*le *y a K"L

/>ample K"L:www.someschool.edu/someDept/pic.gif

ho!t name path name

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 23/119

2: Application Layer 23

+TT( o4er4iew

+TT(: hyperte>ttran!)er protocol

$e*I! application layerprotocol

client!er4er model client:  *row!er that

reue!t!, recei4e!,Fdi!play!G $e* o*ect!

!er4er:  $e* !er4er

!end! o*ect! inre!pon!e to reue!t!

(C running/>plorer

1er4errunning

Apache $e*

!er4er

0ac runningNa4igator

+ T  T  (  r e D u e ! t 

 +  T  T  ( 

 r e D  u e !

 t

+ T  T  (  r e !  p o n ! e 

 +  T  T  ( 

 r e ! p o n

 ! e

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 24/119

2: Application Layer 24

+TT( o4er4iew 6continued7

K!e! TC(: client initiate! TC(

connection 6create! !ocket7to !er4er, port %

!er4er accept! TC(connection )rom client +TT( me!!age! 6application#

layer protocol me!!age!7e>changed *etween *row!er

6+TT( client7 and $e*!er4er 6+TT( !er4er7 TC( connection clo!ed

5TTP is stateless9ser%er maintains no

in)ormation ao!t past

client re!ests

(rotocol! that maintainF!tateG are comple>

pa!t hi!tory 6!tate7 mu!t*e maintained

i) !er4erclient cra!he!,their 4iew! o) F!tateG may*e incon!i!tent, mu!t *ereconciled

a!ide

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 25/119

2: Application Layer 2&

+TT( connection!

Nonper!i!tent +TT( At mo!t one o*ect i!

!ent o4er a TC(connection.

Persistent 5TTP

!ltiple o=ects can e sent

o%er single TCP

connection etween client

an( ser%er.

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 26/119

2: Application Layer 26

Nonper!i!tent +TT(1uppo!e u!er enter! K"L

www.someSchool.edu/someDepartment/home.index

1a. 5TTP client initiates TCP

connection to 5TTP ser%er 0process

at !!!.some2chool.edu on port

8<

2. +TT( client !end! +TT(reue!t me!!age  6containingK"L7 into TC( connection

!ocket. 0e!!age indicate!that client want! o*ectsome;epartmenthome.inde<

'*. +TT( !er4er at ho!t!!!.some2chool.edu waiting

)or TC( connection at port %.Faccept!G connection,

noti)ying client

. +TT( !er4er recei4e! reue!t

me!!age, )orm! re!pon!eme!!age  containing reue!tedo*ect, and !end! me!!ageinto it! !ocket

time

(contains te<t,

references to */

 $peg images)

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 27/119

2: Application Layer 27

Nonper!i!tent +TT( 6cont.7

&. 5TTP client recei%es response

message containing html )ile,

(ispla"s html. Parsing html )ile,

)in(s 1< re)erence( =peg o=ects

. 1tep! '#5 repeated )or eacho) '% peg o*ect!

. +TT( !er4er clo!e! TC(connection.

time

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 28/119

2: Application Layer 28

Non#(er!i!tent +TT(: "e!pon!e time

De)inition o) "TT: time )ora !mall packet to tra4el)rom client to !er4erand *ack.

"e!pon!e time: one "TT to initiate TC(

connection one "TT )or +TT(

reue!t and )ir!t )ew*yte! o) +TT( re!pon!eto return

)ile tran!mi!!ion timetotal M 2"TTtran!mit time

time totran!mit)ile

initiate TC(connection

"TT reue!t)ile

"TT 

)ile

recei4ed

time time

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 29/119

2: Application Layer 2*

(er!i!tent +TT(

Nonper!i!tent +TT( i!!ue!: reuire! 2 "TT! per o*ect 1 o4erhead )or each  TC(

connection *row!er! o)ten open parallel

TC( connection! to )etchre)erenced o*ect!

Persistent 5TTPser%er lea%es connection open a)ter

sen(ing response

s!se!ent 5TTP messages

 etween same client>ser%er sent

o%er open connectionclient sen(s re!ests as soon as it

enco!nters a re)erence( o=ect

as little as one TT )or all the

re)erence( o=ects

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 30/119

2: Application Layer 3<

+TT( reue!t me!!age

two type! o) +TT( me!!age!: reue!t , re!pon!e  +TT( reue!t me!!age:

A1C33 6human#reada*le )ormat7

GET /somedir/page.html HTTP/1.1

Host: www.someschool.edu

User-agent: Mozilla/.!

"onnection: close

 #ccept-language:$r

(e<tra carriage return, line feed) 

reue!t line68/T, (1T,

+/AD command!7

header

 line!

Carriage return,line )eed

indicate! end

o) me!!age

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 31/119

2: Application Layer 31

+TT( reue!t me!!age: general )ormat

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 32/119

2: Application Layer 32

Kploading )orm input

(o!t method: $e* page o)ten

include! )orm input 3nput i! uploaded to

!er4er in entity *ody

U? metho(+

Uses @/T metho(

'np!t is !ploa(e( in U?

)iel( o) re!est line+

www.somesite.com/animalsearch?monkeys&banana

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 33/119

2: Application Layer 33

0ethod type!

+TT('.% 8/T  (1T 

+/AD a!k! !er4er to lea4ereue!ted o*ect out o)re!pon!e

5TTP>1.1

@/T, P-ST, 5/AD

PUT upload! )ile in entity

*ody to path !peci)iedin K"L )ield

D/?/T/ delete! )ile !peci)ied in

the K"L )ield

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 34/119

2: Application Layer 34

+TT( re!pon!e me!!age

HTTP/1.1 %!! &'

"onnection close

(ate: Thu) !* #ug 1++, 1%:!!:1 GMT

erer: #pache/1.0.! Uni23

4ast-Modi$ied: Mon) %% 5un 1++, 6...

"ontent-4ength: *,%1

"ontent-T7pe: te2t/html

 

data data data data data ...

!tatu! line6protocol!tatu! code

!tatu! phra!e7

header line!

data, e.g.,

reue!ted+T0L )ile

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 35/119

2: Application Layer 3&

+TT( re!pon!e !tatu! code!

%!! &'  reue!t !ucceeded, reue!ted o*ect later in thi! me!!age

0!1 Moed Permanentl7 reue!ted o*ect mo4ed, new location !peci)ied later in

thi! me!!age 6Location:7

!! 8ad 9euest

reue!t me!!age not under!tood *y !er4er! ;ot <ound 

reue!ted document not )ound on thi! !er4er

! HTTP =ersion ;ot upported 

3n )ir!t line in !er4er#Oclient re!pon!e me!!age.A )ew !ample code!:

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 36/119

2: Application Layer 36

Trying out +TT( 6client !ide7 )or your!el)

'. Telnet to your )a4orite $e* !er4er:

pen! TC( connection to port %6de)ault +TT( !er4er port7 at ci!.poly.edu.Anything typed in !ent

to port % at ci!.poly.edu

telnet cis.pol7.edu ,!

2. Type in a 8/T +TT( reue!t:

GET />ross/ HTTP/1.1

Host: cis.pol7.edu

;y typing thi! in 6hit carriagereturn twice7, you !end

thi! minimal 6*ut complete78/T reue!t to +TT( !er4er

. Look at re!pon!e me!!age !ent *y +TT( !er4er

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 37/119

2: Application Layer 37

K!er#!er4er !tate: cookie!

0any maor $e* !ite!u!e cookie!

-our component!:'7 cookie header line o)

+TT( re!pon!e  me!!age27 cookie header line in

+TT( reue!t  me!!age7 cookie )ile kept on

u!erI! ho!t, managed *y

u!erI! *row!er7 *ack#end data*a!e at

$e* !ite

/#ample+S!san alwa"s access 'nternet

alwa"s )rom PC

%isits speci)ic e$commerce site

)or )irst time

when initial 5TTP re!ests

arri%es at site, site creates+

uniue 3D entry in *ackend

data*a!e )or 3D

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 38/119

2: Application Layer 38

Cookie!: keeping F!tateG 6cont.7

client

!er4er

u!ual http re!pon!e m!g

u!ual http re!pon!e m!g

cookie )ile

one week later:

u!ual http reue!t m!gcoo?ie: 1*@, cookie#

!peci)icaction

acce!!

ebay 8734u!ual http reue!t m!g Ama=on !er4er

create! 3D'< )or u!er create

  entry

u!ual http re!pon!eet-coo?ie: 1*@,

ebay 8734amazon 178

u!ual http reue!t m!gcoo?ie: 1*@, cookie#

!pecti)icaction

acce!!ebay 8734

amazon 178

*ackenddata*a!e

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 39/119

2: Application Layer 3*

Cookie! 6continued7

$hat cookie! can *ring: authori=ation !hopping cart! recommendation! u!er !e!!ion !tate

6$e* e#mail7

Cookie! and pri4acy: cookie! permit !ite! to

learn a lot a*out you  you may !upply name

and e#mail to !ite!

a!ide

+ow to keep F!tateG:

protocol endpoint!: maintain !tateat !enderrecei4er o4er multipletran!action!

cookie!: http me!!age! carry !tate

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 40/119

2: Application Layer 4<

$e* cache! 6pro>y !er4er7

u!er !et! *row!er:$e* acce!!e! 4iacache

*row!er !end! all+TT( reue!t! tocache o*ect in cache: cache

return! o*ect el!e cache reue!t!

o*ect )rom origin!er4er, then return!o*ect to client

8oal: !ati!)y client reue!t without in4ol4ing origin !er4er

client

(ro>y

!er4er

client

 +  T  T  ( 

 r e D  u e !

 t

 +  T  T  (  r e ! p o

 n ! e

+ T  T  (  r e D u e ! t   + T T

 (  r e D u e ! t

origin!er4er

origin!er4er

+ T  T  (  r e !  p o n ! e   + T T (  r e

 ! p o n ! e

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 41/119

2: Application Layer 41

0ore a*out $e* caching

cache act! a! *othclient and !er4er

typically cache i!in!talled *y 31(

6uni4er!ity, company,re!idential 31(7

h" e caching;

re(!ce response time )or

client re!est

re(!ce tra))ic on an

instit!tionBs access link.'nternet (ense with caches+

enales poor9 content

 pro%i(ers to e))ecti%el"

(eli%er content 0!t so(oes P2P )ile sharing

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 42/119

2: Application Layer 42

Caching e>ample

A!!umption! a4erage o*ect !i=e M

',%%%,%%% *it! a4g. reue!t rate )rom

in!titutionI! *row!er! to

origin !er4er! M '5!ec delay )rom in!titutional router

to any origin !er4er and *ackto router M 2 !ec

Con!euence! utili=ation on LAN M '5E utili=ation on acce!! link M '%%E total delay M 3nternet delay

acce!! delay LAN delay  M 2 !ec minute! milli!econd!

origin

!er4er!pu*lic

 3nternet

in!titutionalnetwork '%% 0*p! LAN

'5 0*p!acce!! link

in!titutionalcache

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 43/119

2: Application Layer 43

Caching e>ample 6cont7

po!!i*le !olution increa!e *andwidth o) acce!!

link to, !ay, '%% 0*p!

con!euence utili=ation on LAN M '5E utili=ation on acce!! link M '5E Total delay M 3nternet delay

acce!! delay LAN delay  M 2 !ec m!ec! m!ec! o)ten a co!tly upgrade

origin

!er4er!pu*lic

 3nternet

in!titutionalnetwork '%% 0*p! LAN

'%% 0*p!acce!! link

in!titutionalcache

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 44/119

2: Application Layer 44

Caching e>ample 6cont7

po!!i*le !olution: in!tallcache

!uppo!e hit rate i! %.con!euence %E reue!t! will *e

!ati!)ied almo!t immediately %E reue!t! !ati!)ied *y

origin !er4er utili=ation o) acce!! link

reduced to %E, re!ulting innegligi*le delay! 6!ay '%m!ec7

total a4g delay M 3nternetdelay acce!! delay LANdelay M .P62.%'7 !ec! .Pmilli!econd! Q '. !ec!

origin

!er4er!pu*lic

 3nternet

in!titutionalnetwork '%% 0*p! LAN

'5 0*p!acce!! link

in!titutionalcache

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 45/119

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 46/119

2: Application Layer 46

Chapter 2: Application layer

2.' (rinciple! o)network application!

2.2 $e* and +TT( 2. -T( 2. /lectronic 0ail

10T(, ((, 30A(

2.5 DN1

2.6 P2P applications

2.7 Socket programming with

UDP

2.8 Socket programming with

TCP

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 47/119

2: Application Layer 47

-T(: the )ile tran!)er protocol

tran!)er )ile to)rom remote ho!t client!er4er model

client:  !ide that initiate! tran!)er 6either to)rom

remote7 !er4er:  remote ho!t

)tp: "-C &5& )tp !er4er: port 2'

)ile tran!)er -T(!er4er

-T(u!er

inter)ace

-T(client

local )ile!y!tem

remote )ile

!y!tem

u!erat ho!t

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 48/119

2: Application Layer 48

-T(: !eparate control, data connection!

-T( client contact! -T( !er4erat port 2', TC( i! tran!portprotocol

client authori=ed o4er controlconnection

client *row!e! remotedirectory *y !ending command!o4er control connection.

when !er4er recei4e! )iletran!)er command, !er4eropen! 2 nd  TC( connection 6)or)ile7 to client

a)ter tran!)erring one )ile,!er4er clo!e! data connection.

-T(client

-T(!er4er

TC( control connectionport 2'

TC( data connectionport 2%

!er4er open! another TC(data connection to tran!)eranother )ile.

control connection: Fout o)

*andG -T( !er4er maintain! F!tateG:

current directory, earlierauthentication

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 49/119

2: Application Layer 4*

-T( command!, re!pon!e!

1ample command!: !ent a! A1C33 te>t o4er

control channel UE9 username

P#  password 

4AT return li!t o) )ile incurrent directory

9ET9 $ilename retrie4e!6get!7 )ile

T&9 $ilename !tore!6put!7 )ile onto remoteho!t

Sample ret!rn co(esstat!s co(e an( phrase 0as in

5TTP

001 Username &')

 password reuired 

1% data connection

alread7 openD

trans$er starting

% "ant open data

connection

% Error writing $ile

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 50/119

2: Application Layer &<

Chapter 2: Application layer

2.' (rinciple! o)network application!

2.2 $e* and +TT( 2. -T( 2. /lectronic 0ail

10T(, ((, 30A(

2.5 DN1

2.6 P2P applications

2.7 Socket programming with

UDP

2.8 Socket programming with

TCP

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 51/119

2: Application Layer &1

/lectronic 0ail

Three maor component!:  u!er agent! mail !er4er! !imple mail tran!)er

protocol: 10T(K!er Agent a.k.a. Fmail readerG compo!ing, editing, reading

mail me!!age! e.g., /udora, utlook, elm,0o=illa Thunder*ird

outgoing, incoming me!!age!!tored on !er4er

u!er mail*o>

outgoingme!!age ueue

mail

!er4er

u!eragent

u!eragent

u!eragent

mail!er4er

u!eragent

u!eragent

mail!er4er

u!eragent

10T(

10T(

10T(

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 52/119

2: Application Layer &2

/lectronic 0ail: mail !er4er!

0ail 1er4er!  mail*o> contain! incoming

me!!age! )or u!er me!!age ueue o) outgoing

6to *e !ent7 mail me!!age! 10T( protocol *etween mail

!er4er! to !end emailme!!age! client: !ending mail

!er4er F!er4erG: recei4ing mail

!er4er

mail!er4er

u!eragent

u!eragent

u!eragent

mail

!er4er

u!eragent

u!eragent

mail!er4er

u!eragent

10T(

10T(

10T(

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 53/119

2: Application Layer &3

/lectronic 0ail: 10T( R"-C 22'S

u!e! TC( to relia*ly tran!)er email me!!age )rom clientto !er4er, port 25

direct tran!)er: !ending !er4er to recei4ing !er4er three pha!e! o) tran!)er

hand!haking 6greeting7 tran!)er o) me!!age! clo!ure

commandre!pon!e interaction command!: A1C33 te>t

re!pon!e: !tatu! code and phra!e me!!age! mu!t *e in <#*it A1C33

1 i Ali d t ; *

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 54/119

2: Application Layer &4

1cenario: Alice !end! me!!age to ;o*

'7 Alice u!e! KA to compo!e

me!!age and [email protected]

27 AliceI! KA !end! me!!ageto her mail !er4er@ me!!ageplaced in me!!age ueue

7 Client !ide o) 10T( open!TC( connection with ;o*I!mail !er4er

4 STP client sen(s AliceBs

message o%er the TCPconnection

& oBs mail ser%er places the

message in oBs mailo#

6 o in%okes his !ser agent to

rea( message

u!eragent

mail!er4er

mail!er4er u!er

agent

'

2 5

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 55/119

2: Application Layer &&

1ample 10T( interaction  : %%! hamFurger.edu

": HE4& crepes.$r: %! Hello crepes.$r) pleased to meet 7ou

": M#A4 <9&M: Balicecrepes.$rC

: %! alicecrepes.$r... ender o?

": 9"PT T&: BFoFhamFurger.eduC

: %! FoFhamFurger.edu ... 9ecipient o?": (#T#

: 0 Enter mail) end with . on a line F7 itsel$

": (o 7ou li?e ?etchupI

": How aFout pic?lesI

": .: %! Message accepted $or delier7

": JUAT

: %%1 hamFurger.edu closing connection

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 56/119

2: Application Layer &6

Try 10T( interaction )or your!el):

telnet serername %

!ee 22% reply )rom !er4er enter +/L, 0A3L -"0, "C(T T, DATA, K3T

command! a*o4e let! you !end email without u!ing email client6reader7

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 57/119

2: Application Layer &7

10T(: )inal word!

10T( u!e! per!i!tentconnection!

10T( reuire! me!!age6header ? *ody7 to *e in <#*it A1C33

10T( !er4er u!e!CR!.CR! to determineend o) me!!age

Comparison with 5TTP+

5TTP+ p!ll

STP+ p!sh

 oth ha%e ASC''

comman(>response interaction,stat!s co(es

5TTP+ each o=ect encaps!late( in

its own response msg

STP+ m!ltiple o=ects sent in

m!ltipart msg

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 58/119

2: Application Layer &8

0ail me!!age )ormat

10T(: protocol )ore>changing email m!g!

"-C 22: !tandard )or te>tme!!age )ormat:

header line!, e.g., To: -rom: 1u*ect:di))erent  )rom 10T(

command! 

*ody the Fme!!ageG, A1C33

character! only

header

*ody

*lankline

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 59/119

2: Application Layer &*

0ail acce!! protocol!

10T(: deli4ery!torage to recei4erI! !er4er 0ail acce!! protocol: retrie4al )rom !er4er

((: (o!t ))ice (rotocol R"-C '&&S• authori=ation 6agent Q##O!er4er7 and download

30A(: 3nternet 0ail Acce!! (rotocol R"-C '<%S• more )eature! 6more comple>7• manipulation o) !tored m!g! on !er4er

+TT(: gmail, +otmail, ahoo 0ail, etc.

u!eragent

!enderI! mail!er4er

u!eragent

10T( 10T( acce!!protocol

recei4erI! mail!er4er

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 60/119

2: Application Layer 6<

(( protocol

authori=ation pha!e client command!:

user: declare u!ername pass: pa!!word

!er4er re!pon!e! K&' 

-E99 

tran!action pha!e, client: list: li!t me!!age num*er!

retr: retrie4e me!!age *ynum*er

dele: delete uit

  ": list

: 1 +,

: % +1%

: .

": retr 1

: Bmessage 1 contentsC 

  : .

": dele 1

": retr %

: Bmessage 1 contentsC 

  : .

": dele %

": uit

: K&' P&P0 serer signing o$$

: K&' P&P0 serer read7

": user FoF

: K&'": pass hungr7

: K&'  user success$ull7 logged on

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 61/119

2: Application Layer 61

(( 6more7 and 30A(

0ore a*out (( (re4iou! e>ample u!e!

Fdownload and deleteGmode.

;o* cannot re#read e#mail i) he change!client

FDownload#and#keepG:copie! o) me!!age! ondi))erent client!

(( i! !tatele!!acro!! !e!!ion!

'APeep all messages in one

 place+ the ser%er 

Allows !ser to organie

messages in )ol(ers

'AP keeps !ser state across

sessions+ name! o) )older! and

mapping! *etween

me!!age 3D! and )oldername

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 62/119

2: Application Layer 62

Chapter 2: Application layer

2.' (rinciple! o)network application!

2.2 $e* and +TT( 2. -T( 2. /lectronic 0ail

10T(, ((, 30A(

2.5 DN1

2.6 P2P applications

2.7 Socket programming with

UDP

2.8 Socket programming with

TCP

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 63/119

2: Application Layer 63

DN1: Domain Name 1y!tem

(eople: many identi)ier!: 11N, name, pa!!port U

3nternet ho!t!, router!: 3( addre!! 62 *it7 #

u!ed )or addre!!ingdatagram!

FnameG, e.g.,ww.yahoo.com # u!ed *yhuman!

: map *etween 3(addre!!e! and name B

Domain Eame S"stem+distributed database implemente( in

hierarch" o) man" name servers

application-layer protocol  host,

ro!ters, name ser%ers to

comm!nicate to resolve names0a((ress>name translation

note: core 3nternet)unction, implemented a!application#layer protocol

comple>ity at networkI!FedgeG

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 64/119

2: Application Layer 64

DN1

h" not centralie DES;single point o) )ail!re

tra))ic %ol!me

(istant centralie( (ataase

maintenance

(oesnBt scale!

DN1 !er4ice! ho!tname to 3(

addre!! tran!lation ho!t alia!ing

Canonical, alia! name! mail !er4er alia!ing load di!tri*ution

replicated $e* !er4er!:

!et o) 3( addre!!e! )orone canonical name

Di!tri*uted +ierarchical Data*a!e

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 65/119

2: Application Layer 6&

oot ;=2 2ervers

com ;=2 servers org ;=2 servers edu ;=2 servers

poly.edu

;=2 servers

umass.edu

;=2 serversyahoo.com

;=2 servers

ama>on.com

;=2 servers

pbs.org

;=2 servers

Di!tri*uted, +ierarchical Data*a!e

Client wants 'P )or www.amaon.comF 1st appro#+

client !eries a root ser%er to )in( com DES ser%er 

client !eries com DES ser%er to get amaon.com DES ser%er 

client !eries amaon.com DES ser%er to get 'P a((ress )or

www.amaon.com

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 66/119

2: Application Layer 66

DN1: "oot name !er4er!

contacted *y local name !er4er that can not re!ol4e name root name !er4er: contact! authoritati4e name !er4er i) name mapping not known get! mapping return! mapping to local name !er4er

  ' root name!er4er! worldwide

b 24-"2" 1arina del ey, 4A

l "4A== ?os Angeles, 4A

e =A2A 1t @ie!, 4A

f "nternet 2oft!are 4. alo Alto,

4A (and other locations)

i Autonomica, 2tockholm (plus

5 other locations)

k "B ?ondon (also * other locations)

m W";B Tokyo (also 2eoul,

aris, 2&)

a @erisign, ;ulles, @A

c 4ogent, 8erndon, @A (also ?A)

d 1aryland 4ollege ark, 1;

g 2 ;o; @ienna, @A

h A? Aberdeen, 1; $ @erisign, ( * locations)

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 67/119

2: Application Layer 67

TLD and Authoritati4e 1er4er!

Top#le4el domain 6TLD7 !er4er!:  re!pon!i*le )or com, org, net, edu, etc, and all

top#le4el country domain! uk, )r, ca, p. Network 1olution! maintain! !er4er! )or com TLD /ducau!e )or edu TLD

Authoritati4e DN1 !er4er!:  organi=ationI! DN1 !er4er!, pro4iding

authoritati4e ho!tname to 3( mapping! )or

organi=ationI! !er4er! 6e.g., $e*, mail7. can *e maintained *y organi=ation or !er4ice

pro4ider

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 68/119

2: Application Layer 68

Local Name 1er4er

doe! not !trictly *elong to hierarchy each 31( 6re!idential 31(, company,

uni4er!ity7 ha! one.

al!o called Fde)ault name !er4erG when ho!t make! DN1 uery, uery i! !ent

to it! local DN1 !er4er act! a! pro>y, )orward! uery into hierarchy

DN1 name

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 69/119

2: Application Layer 6*

reue!ting ho!tcis!poly!edu

gaia!cs!umass!edu

root DN1 !er4er

local DN1 !er4erdns!poly!edu

*

7

0

authoritati4e DN1 !er4er

dns!cs!umass!edu

C5

TLD DN1 !er4er

DN1 namere!olution e>ample

+o!t at ci!.poly.eduwant! 3( addre!! )orgaia.c!.uma!!.edu

iterated uery: contacted !er4er

replie! with name o)!er4er to contact

F3 donIt know thi!

name, *ut a!k thi!!er4erG

DN1 name

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 70/119

2: Application Layer 7<

reue!ting ho!tcis!poly!edu

gaia!cs!umass!edu

root DN1 !er4er

local DN1 !er4erdns!poly!edu

*

70

authoritati4e DN1 !er4erdns!cs!umass!edu

C

5

TLD DN1 !er4er

recur!i4e uery: put! *urden o) name

re!olution oncontacted name

!er4er hea4y loadB

DN1 namere!olution e>ample

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 71/119

2: Application Layer 71

DN1: caching and updating record!

once 6any7 name !er4er learn! mapping, it cache!  mapping cache entrie! timeout 6di!appear7 a)ter !ome

time

TLD !er4er! typically cached in local name!er4er!• Thu! root name !er4er! not o)ten 4i!ited

updatenoti)y mechani!m! under de!ign *y 3/T-

"-C 2' http:www.iet).orghtml.charter!dn!ind#charter.html

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 72/119

2: Application Layer 72

DN1 record!

DN1: di!tri*uted d* !toring re!ource record! 6""7

T"peGES name i! domain 6e.g.

)oo.com7 alue i! ho!tname o)authoritati4e name!er4er )or thi! domain

"" )ormat: name) alue) t7pe) ttl3

TypeMA

name i! ho!tname alue i! 3( addre!!

TypeMCNA0/

name i! alia! name )or !omeFcanonicalG 6the real7 name

  www.ibm.com i! really  ser#ereast.backup$.ibm.com

alue i! canonical name

TypeM0V alue i! name o) mail!er4er

a!!ociated with name

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 73/119

2: Application Layer 73

DN1 protocol, me!!age!

DN1 protocol : uery  and reply  me!!age!, *oth with!ame me!!age )ormat 

m!g header identi)ication: ' *it U

)or uery, reply to ueryu!e! !ame U )lag!:

uery or reply recur!ion de!ired recur!ion a4aila*le reply i! authoritati4e

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 74/119

2: Application Layer 74

DN1 protocol, me!!age!

Name, type )ield! )or a uery

""! in re!pon!e

to uery

record! )orauthoritati4e !er4er!

additional Fhelp)ulGin)o that may *e u!ed

d DN

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 75/119

2: Application Layer 7&

3n!erting record! into DN1

e>ample: new !tartup FNetwork KtopiaG regi!ter name networkuptopia.com at DN1 regi!trar  

6e.g., Network 1olution!7 pro4ide name!, 3( addre!!e! o) authoritati4e name !er4er

6primary and !econdary7 regi!trar in!ert! two ""! into com TLD !er4er:

%networkutopia.com dns'.networkutopia.com (S)

%dns'.networkutopia.com $'$.$'$.$'$.' *)

create authoritati4e !er4er Type A record )orwww.networkuptopia.com@ Type 0V record )ornetworkutopia.com

+ow do people get 3( addre!! o) your $e* !iteB

Ch 2 li i l

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 76/119

2: Application Layer 76

Chapter 2: Application layer

2.' (rinciple! o)network application!

2.2 $e* and +TT( 2. -T( 2. /lectronic 0ail

10T(, ((, 30A(

2.5 DN1

2.6 P2P applications

2.7 Socket programming with

UDP

2.8 Socket programming with

TCP

( (2( hi

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 77/119

2: Application Layer 77

(ure (2( architecture

no  alway!#on !er4er ar*itrary end !y!tem!

directly communicate peer! are intermittently

connected and change 3(addre!!e!

Three topic!: -ile di!tri*ution 1earching )or in)ormation Ca!e 1tudy: 1kype

peer#peer

-il Di i* i Cli (2(

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 78/119

2: Application Layer 78

-ile Di!tri*ution: 1er4er#Client 4! (2(ue!tion  : +ow much time to di!tri*ute )ile

)rom one !er4er to N peer! B

us

u2 d 

1d 

u1

uN 

d N 

1er4er

Network 6witha*undant *andwidth7

-ile, !i=e - 

us: server upload

band!idth

ui 

: peer i uploadband!idth

d i : peer i do!nload

band!idth

- l d * l

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 79/119

2: Application Layer 7*

-ile di!tri*ution time: !er4er#client

us

u2 d 

1 d 2 

u1

uN 

d N 

1er4er

Network 6witha*undant *andwidth7

-  !er4er !euentially

!end! N copie!: N-5u !  time

client i take! -di

time to download

increa!e! linearly in N

6)or large N7

M dc! M ma> W N-5u ! , -5min6d i 7  Xi 

Time to di!tri*ute -  to N  client! u!ingclient!er4er approach

-il di i* i i (2(

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 80/119

2: Application Layer 8<

-ile di!tri*ution time: (2(

us

u2 d 

1 d 2 

u1

uN 

d N 

1er4er

Network 6witha*undant *andwidth7

-  !er4er mu!t !end one

copy: -5u !  time

client i take! -di timeto download

N- *it! mu!t *edownloaded 6aggregate7 )a!te!t po!!i*le upload rate: u!  Σui

d(2( M ma> W -5u ! , -5min6d i 7  , N-6u!  Σui7 Xi 

1 li (2( l

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 81/119

2: Application Layer 81

1er4er#client 4!. (2(: e>ample

Client upload rate M u, -u M ' hour, u!

 M '%u, dmin

 Y u!

-il di t i* ti ;itT t

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 82/119

2: Application Layer 82

-ile di!tri*ution: ;itTorrent

tracker:  track! peer!participating in torrent

torrent:  group o)peer! e>changingchunk! o) a )ile

o*tain li!to) peer! 

trading

chunk!

peer

(2( )ile di!tri*ution

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 83/119

2: Application Layer 83

;itTorrent 6'7 )ile di4ided into 25; chunk! . peer oining torrent:

ha! no chunk!, *ut will accumulate them o4er time regi!ter! with tracker to get li!t o) peer!,connect! to !u*!et o) peer! 6Fneigh*or!G7

while downloading, peer upload! chunk! to other

peer!. peer! may come and go once peer ha! entire )ile, it may 6!el)i!hly7 lea4e or

6altrui!tically7 remain

;itT t 627

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 84/119

2: Application Layer 84

;itTorrent 627

P!lling Ch!nksat an" gi%en time, (i))erent

 peers ha%e (i))erent s!sets

o) )ile ch!nks

 perio(icall", a peer 0Alice

asks each neighor )or list

o) ch!nks that the" ha%e.

Alice sen(s re!ests )or her

missing ch!nks

rare!t )ir!t

1ending Chunk!: tit#)or#tat Alice !end! chunk! to )our

neigh*or! currently!ending her chunk! at thehighe!t rate   re#e4aluate top e4ery

'% !ec! e4ery % !ec!: randomly

!elect another peer,!tart! !ending chunk!

newly cho!en peer may oin top

Foptimi!tically unchokeG

;itT t Tit ) t t

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 85/119

2: Application Layer 8&

;itTorrent: Tit#)or#tat6'7 Alice Foptimi!tically unchoke!G ;o*

627 Alice *ecome! one o) ;o*I! top#)our pro4ider!@ ;o* reciprocate!67 ;o* *ecome! one o) AliceI! top#)our pro4ider!

$ith higher upload rate,can )ind *etter tradingpartner! ? get )ile )a!ter

Di!t i* t d + !h T *l 6D+T7

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 86/119

Di!tri*uted +a!h Ta*le 6D+T7

D+T M di!tri*uted (2( data*a!e Data*a!e ha! 6key, 4alue7 pair!@

 key: !! num*er@ 4alue: human name

key: content type@ 4alue: 3( addre!! (eer! uery D; with key

D; return! 4alue! that match the key

(eer! can al!o in!ert 6key, 4alue7 peer!

D+T 3d ti)i !

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 87/119

D+T 3denti)ier!

A!!ign integer identi)ier to each peer in rangeR%,2n#'S. /ach identi)ier can *e repre!ented *y n *it!.

"euire each key to *e an integer in !ame range. To get integer key!, ha!h original key.

eg, key M h6FLed Zeppelin 3[G7 Thi! i! why they call it a di!tri*uted Fha!hG ta*le

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 88/119

Circular D+T 6'7

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 89/119

'

5

'%

'2

'5

Circular D+T 6'7

/ach peer only  aware o) immediate !ucce!!orand predece!!or.

F4erlay networkG

Circle D+T 627

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 90/119

Circle D+T 627

%%%'

%%''

%'%%

%'%'

'%%%'%'%

''%%

''''

$hoI! re!p

)or key '''% B3 am

6N7 me!!age!on a4g to re!ol4euery, when thereare N peer!

***/

***/

***/

***/

***/

***/

De)ine clo!e!ta! clo!e!t!ucce!!or

Circular D+T with 1hortcut!

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 91/119

Circular D+T with 1hortcut!

/ach peer keep! track o) 3( addre!!e! o) predece!!or, !ucce!!or,!hort cut!.

"educed )rom to 2 me!!age!. (o!!i*le to de!ign !hortcut! !o 6log N7 neigh*or!, 6log N7

me!!age! in uery

'

5

'%

'2

'5

$hoI! re!p)or key '''%B

(eer Churn

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 92/119

(eer Churn

(eer 5 a*ruptly lea4e!

(eer detect!@ make! it! immediate !ucce!!or@a!k! who it! immediate !ucce!!or i!@ make! I!immediate !ucce!!or it! !econd !ucce!!or.

$hat i) peer ' want! to oinB

'

5

'%

'2

'5

D To handle peer churn, reuire

each peer to know the 3( addre!!o) it! two !ucce!!or!.D  /ach peer periodically ping! it!

two !ucce!!or! to !ee i) they

are !till ali4e.

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 93/119

(eer! a! relay!

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 94/119

2: Application Layer *4

(eer! a! relay!

(ro*lem when *othAlice and ;o* are*ehind FNAT!G. NAT pre4ent! an out!ide

peer )rom initiating a call

to in!ider peer 1olution:

K!ing AliceI! and ;o*I!1N!, "elay i! cho!en

/ach peer initiate!

!e!!ion with relay. (eer! can now

communicate throughNAT! 4ia relay

Chapter 2: Application layer

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 95/119

2: Application Layer *&

Chapter 2: Application layer

2.' (rinciple! o)network application!

2.2 $e* and +TT( 2. -T( 2. /lectronic 0ail

10T(, ((, 30A(

2.5 DN1

2.6 P2P applications2.7 Socket programming with

UDP

2.8 Socket programming with

TCP

1ocket programming

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 96/119

2: Application Layer *6

1ocket programming

1ocket A(3 introduced in ;1D.' KN3V,

'&' e>plicitly created, u!ed,

relea!ed *y app! client!er4er paradigm two type! o) tran!port

!er4ice 4ia !ocket A(3: KD( TC(

A application#created ,1#controlled  inter)ace

6a FdoorG7 into whichapplication proce!! can

*oth !end andrecei4e me!!age! to)rom

another applicationproce!!

!ocket

8oal: learn how to *uild client!er4er application thatcommunicate u!ing !ocket!

1ocket programming *a!ic!

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 97/119

1ocket programming *a!ic!

1er4er mu!t *erunning *e)oreclient can !endanything to it.

1er4er mu!t ha4e a!ocket 6door7through which it

recei4e! and !end!!egment! 1imilarly client

need! a !ocket

Socket is locall" i(enti)ie(with a port n!mer  Analogou! to the apt U

in a *uildingClient nee(s to know ser%er

'P a((ress an( socket port

n!mer.

2: Application Layer *7

1ocket programming with KD(

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 98/119

2: Application Layer *8

1ocket programming with KD( 

KD(: no FconnectionG *etweenclient and !er4er

no hand!haking !ender e>plicitly attache!

3( addre!! and port o)

de!tination to each !egment 1 attache! 3( addre!! and

port o) !ending !ocket toeach !egment

1er4er can e>tract 3(

addre!!, port o) !ender)rom recei4ed !egment

application 4iewpoint

KD( pro4ide! unrelia*le tran!)er  o) group! o) *yte! 6Fdatagram!G7 

 *etween client and !er4er 

Note: the o))icial terminology)or a KD( packet i! FdatagramG.3n thi! cla!!, we in!tead u!e FKD(!egmentG.

"unning e>ample

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 99/119

"unning e>ample

Client:  K!er type! line o) te>t Client program !end! line to !er4er

1er4er: 1er4er recei4e! line o) te>t Capitali=e! all the letter! 1end! modi)ied line to client

Client: "ecei4e! line o) te>t Di!play!

2: Application Layer **

Client!er4er !ocket interaction: KD(

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 100/119

2: Application Layer 1<<

Client!er4er !ocket interaction: KD(

1er4er 6running on hostid 7

close

client2ocket

read datagram fromclient2ocket

create socket,

client2ocket E

;atagram2ocket()

Client

4reate datagram !ith server " andportE<F send datagram via

 client2ocket

create socket,

portE <.

server2ocket E

;atagram2ocket()

read datagram from

server2ocket

!rite reply to

server2ocket

specifyingclient address,

port number 

/>ample: Ja4a client 6KD(7

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 101/119

2: Application Layer 1<1

/>ample: Ja4a client 6KD(7

    s    e    n      d          a    c      k    e     t

to net!ork from net!ork

    r    e    c    e      i    v    e          a    c      k    e     t

      i    n      &    r    o    m      :    s    e    r

keyboard monitor  

rocess

client2ocket

:;

packet

input

stream

:;

packet

:;

socket

utput: !end!packet 6recallthat TC( !entF*yte !treamG7

3nput: recei4e!packet 6recallthatTC( recei4edF*yte !treamG7

Clientproce!!

client KD(!ocket

/>ample: Ja4a client 6KD(7

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 102/119

2: Application Layer 1<2

/>ample: Ja4a client 6KD(7

import $ava.io.GFimport $ava.net.GF

class ;4lient H

public static void main(2tring args36) thro!s B<ception

H

Iufferedeader in&romser Ene! Iufferedeader(ne! "nput2treameader(2ystem.in))F

;atagram2ocket client2ocket E ne! ;atagram2ocket()F

"netAddress "Address E "netAddress.getIy=ame(JhostnameJ)F

byte36 send;ata E ne! byte3*/76F

byte36 receive;ata E ne! byte3*/76F

2tring sentence E in&romser.read?ine()F

send;ata E sentence.getIytes()F 

Create

input !treamCreate

client !ocket

Tran!late ho!tname to 3(

addre!! u!ing DN1

/>ample: Ja4a client 6KD(7 cont

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 103/119

2: Application Layer 1<3

/>ample: Ja4a client 6KD(7, cont.

  ;atagramacket sendacket E

ne! ;atagramacket(send;ata, send;ata.length, "Address, +5C)F

client2ocket.send(sendacket)F

;atagramacket receiveacket E

ne! ;atagramacket(receive;ata, receive;ata.length)F

client2ocket.receive(receiveacket)F

2tring modified2entence E

ne! 2tring(receiveacket.get;ata())F

2ystem.out.println(J&K1 2B@B:J L modified2entence)F

client2ocket.close()F

M

Create datagramwith data#to#!end,

length, 3( addr, port

1end datagramto !er4er

"ead datagram)rom !er4er

/>ample: Ja4a !er4er 6KD(7

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 104/119

2: Application Layer 1<4

/>ample: Ja4a !er4er 6KD(7

import $ava.io.GFimport $ava.net.GF

class ;2erver H

public static void main(2tring args36) thro!s B<ception

H

;atagram2ocket server2ocket E ne! ;atagram2ocket(+5C)F

byte36 receive;ata E ne! byte3*/76F

byte36 send;ata E ne! byte3*/76F

!hile(true)

H

;atagramacket receiveacket E

ne! ;atagramacket(receive;ata, receive;ata.length)F

server2ocket.receive(receiveacket)F  

Create

datagram !ocketat port &<

Create !pace )orrecei4ed datagram

"ecei4edatagram

/>ample: Ja4a !er4er 6KD(7 cont

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 105/119

2: Application Layer 1<&

/>ample: Ja4a !er4er 6KD(7, cont

  2tring sentence E ne! 2tring(receiveacket.get;ata())F

"netAddress "Address E receiveacket.getAddress()F

int port E receiveacket.getort()F

2tring capitali>ed2entence E sentence.topper4ase()F

send;ata E capitali>ed2entence.getIytes()F

;atagramacket sendacket E

ne! ;atagramacket(send;ata, send;ata.length, "Address,

port)F

server2ocket.send(sendacket)FM

M

8et 3( addrport U, o)

!ender

$rite out

datagramto !ocket

/nd o) while loop,loop *ack and wait )oranother datagram

Create datagramto !end to client

KD( o*!er4ation! ? ue!tion!

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 106/119

KD( o*!er4ation! ? ue!tion!

;oth client !er4er u!e Datagram1ocket De!t 3( and port are e>plicitly attached to

!egment. $hat would happen i) change *oth client1ocket

and !er4er1ocket to Fmy1ocketGB Can the client !end a !egment to !er4er without

knowing the !er4erI! 3( addre!! andor port

num*erB Can multiple client! u!e the !er4erB

2: Application Layer 1<6

Chapter 2: Application layer

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 107/119

2: Application Layer 1<7

Chapter 2: Application layer

2.' (rinciple! o)network application!

2.2 $e* and +TT( 2. -T( 2. /lectronic 0ail

10T(, ((, 30A(

2.5 DN1

2.6 P2P applications2.7 Socket programming with

UDP

2.8 Socket programming with

TCP

1ocket#programming u!ing TC(

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 108/119

2: Application Layer 1<8

1ocket programming u!ing TC(

TC( !er4ice: relia*le tran!)er o) bytes )rom oneproce!! to another

proce!!

TC( with

*u))er!,4aria*le!

!ocket

controlled *yapplicationde4eloper

controlled *y

operating!y!tem

ho!t or!er4er

proce!!

TC( with*u))er!,4aria*le!

!ocket

controlled *yapplicationde4eloper

controlled *yoperating!y!tem

ho!t or!er4er

internet

1ocket programming with TC(

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 109/119

2: Application Layer 1<*

1ocket programming with TC( 

Client mu!t contact !er4er !er4er proce!! mu!t )ir!t

*e running !er4er mu!t ha4e created

!ocket 6door7 thatwelcome! clientI! contact

Client contact! !er4er *y: creating client#local TC(

!ocket !peci)ying 3( addre!!, port

num*er o) !er4er proce!! $hen client create!

!ocket: client TC(e!ta*li!he! connection to!er4er TC(

hen contacte( " client, ser%er

TCP creates new socket )or

ser%er process to comm!nicate

with client

allow! !er4er to talk withmultiple client!

!ource port num*er!u!ed to di!tingui!hclient! 6more in Chap 7

TC( pro4ide! relia*le, in#order  tran!)er o) *yte! 6FpipeG7*etween client and !er4er 

application 4iewpoint

Client!er4er !ocket interaction: TC(

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 110/119

2: Application Layer 11<

Client!er4er !ocket interaction: TC(

!ait for incomingconnection reNuestconnection2ocket E

!elcome2ocket.accept()

create socket,

portE2, for 

incoming reNuest:!elcome2ocket E

2erver2ocket()

create socket,

connect to hostid , portE2client2ocket E

2ocket()

close

connection2ocket

read reply from

client2ocket

close

client2ocket

1er4er 6running on hostid 7 Client

send reNuest using

client2ocketread reNuest from

connection2ocket

!rite reply to

connection2ocket

TC(connection !etup

1tream argon

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 111/119

2: Application Layer 111

    o   u     t     T    o     2    e    r   v    e    r

to net!o rk fro m net!o rk

     i    n     &    r    o    m     2    e    r   v    e    r

     i    n     &    r    o    m     :    s    e    r

keyboard monitor  

rocess

client2ocket

input

stream

input

stream

output

stream

T4

socket

Clientproce!!

client TC(!ocket

1tream argon

A !tream i! a !euence o)character! that )low intoor out o) a proce!!.

An input !tream i!attached to !ome input

!ource )or the proce!!,e.g., key*oard or !ocket. An output !tream i!

attached to an output!ource, e.g., monitor or

!ocket.

1ocket programming with TC(

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 112/119

2: Application Layer 112

1ocket programming with TC(

/>ample client#!er4er app:'7 client read! line )rom!tandard input 6in<romUser !tream7 , !end! to !er4er 4ia!ocket 6outToerer 

!tream727 !er4er read! line )rom !ocket7 !er4er con4ert! line to

upperca!e, !end! *ack toclient

7 client read!, print! modi)iedline )rom !ocket6in<romerer !tream7

/>ample: Ja4a client 6TC(7

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 113/119

2: Application Layer 113

/>ample: Ja4a client 6TC(7

import $ava.io.GFimport $ava.net.GF

class T44lient H

public static void main(2tring argv36) thro!s B<ception

H

2tring sentenceF2tring modified2entenceF

Iufferedeader in&romser E

ne! Iufferedeader(ne! "nput2treameader(2ystem.in))F

2ocket client2ocket E ne! 2ocket(JhostnameJ, C5+)F

;ataKutput2tream outTo2erver E

ne! ;ataKutput2tream(client2ocket.getKutput2tream())F 

Createinput !tream

Create

client !ocket,connect to !er4er

Createoutput !tream

attached to !ocket

/>ample: Ja4a client 6TC(7, cont.

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 114/119

2: Application Layer 114

/>ample Ja4a client 6TC(7, cont.

  Iufferedeader in&rom2erver E

ne! Iufferedeader(ne!

  "nput2treameader(client2ocket.get"nput2tream()))F

sentence E in&romser.read?ine()F

outTo2erver.!riteIytes(sentence L OPnO)F

modified2entence E in&rom2erver.read?ine()F

2ystem.out.println(J&K1 2B@B: J L modified2entence)F

client2ocket.close()F

M

Createinput !tream

attached to !ocket

1end lineto !er4er

"ead line)rom !er4er

/>ample: Ja4a !er4er 6TC(7

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 115/119

2: Application Layer 11&

/>ample Ja4a !er4er 6TC(7import $ava.io.GF

import $ava.net.GF

class T42erver H

public static void main(2tring argv36) thro!s B<ception

H

2tring client2entenceF

2tring capitali>ed2entenceF

2erver2ocket !elcome2ocket E ne! 2erver2ocket(C5+)F

!hile(true) H

2ocket connection2ocket E !elcome2ocket.accept()F

Iufferedeader in&rom4lient E

ne! Iufferedeader(ne!

  "nput2treameader(connection2ocket.get"nput2tream()))F

Createwelcoming !ocket

at port <&

$ait, on welcoming!ocket )or contact

*y clientCreate input

!tream, attachedto !ocket

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 116/119

TC( o*!er4ation! ? ue!tion!

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 117/119

1er4er ha! two type! o) !ocket!: 1er4er1ocket and 1ocket

$hen client knock! on !er4er1ocketI! Fdoor,G!er4er create! connection1ocket and complete!

TC( con>. De!t 3( and port are not e>plicitly attached to

!egment. Can multiple client! u!e the !er4erB

2: Application Layer 117

Chapter 2: 1ummary

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 118/119

2: Application Layer 118

application architecture! client#!er4er (2( hy*rid

application !er4icereuirement!:  relia*ility, *andwidth,

delay

3nternet tran!port!er4ice model connection#oriented,

relia*le: TC( unrelia*le, datagram!: KD(

o!r st!(" o) network apps now completeH

!peci)ic protocol!: +TT( -T( 10T(, ((, 30A( DN1 (2(: ;itTorrent, 1kype

!ocket programming

Chapter 2: 1ummary

8/18/2019 Chapter2_5th_Aug2009 - Network

http://slidepdf.com/reader/full/chapter25thaug2009-network 119/119

Chapter 1ummary

typical reue!treplyme!!age e>change: client reue!t! in)o or

!er4ice !er4er re!pond! with

data, !tatu! code

me!!age )ormat!:

header!: )ield! gi4ingin)o a*out data data: in)o *eing

communicated

ost importantl"+ learne( ao!t protocols

3mportant theme!: control 4!. data m!g!

in#*and, out#o)#*and centrali=ed 4!.decentrali=ed

!tatele!! 4!. !tate)ul

relia*le 4!. unrelia*lem!g tran!)er Fcomple>ity at network