Professional Documents
Culture Documents
Application Layer: Computer Networking: A Top Down Approach
Application Layer: Computer Networking: A Top Down Approach
Application
Layer
run on (different)
end systems
communicate over
network
e.g., web server
software
communicates with application
client/server
clients:
communicate with
server
may be
intermittently
connected
may have dynamic IP
addresses Application Layer 2-7
P2P architecture
no always-on server peer-peer
arbitrary end
systems directly
communicate
peers request
service from other
peers, provide
service in return
to other peers
self scalability
– new peers bring
new service
capacity, as well
as new service
demands
peers are Application Layer 2-8
Processes
communicating
process: programclients, servers
running within a client process:
host process that
within same host, initiates
two processes communication
communicate using server process:
inter-process process that
communication waits to be
(defined by OS) aside:
contacted
processes in applications with
different hosts P2P architectures
communicate by have client
exchanging
messages processes & server
processes
Application Layer 2-9
Sockets
process sends/receives messages to/from
its socket
socket analogous to door
sending process shoves message out door
sending process relies on transport
infrastructure on other side of door to
deliver message to socket at receiving
process application
application socket controlled by
process process app developer
transport transport
network network controlled
link
by OS
link Internet
physical physical
non-persistent persistent
HTTP issues: HTTP:
requires 2 RTTs server leaves
per object connection open
OS overhead for after sending
each TCP response
connection subsequent HTTP
browsers often messages between
open parallel TCP same
connections to client/server
fetch referenced sent over open
objects connection
client sends
requests as soon
as it encounters
a referencedApplication Layer 2-26
HTTP request message
two types of HTTP messages: request,
response
HTTP request message:
ASCII (human-readable format) carriage return character
line-feed character
request line
(GET, POST, GET /index.html HTTP/1.1\r\n
HEAD commands) Host: www-net.cs.umass.edu\r\n
User-Agent: Firefox/3.6.10\r\n
Accept: text/html,application/xhtml+xml\r\n
headerAccept-Language: en-us,en;q=0.5\r\n
linesAccept-Encoding: gzip,deflate\r\n
Accept-Charset: ISO-8859-1,utf-8;q=0.7\r\n
carriage return, Keep-Alive: 115\r\n
line feed at start Connection: keep-alive\r\n
\r\n
of line indicates
end of header lines
Application Layer 2-27
HTTP request message:
general format
method sp URL sp version cr lf request
line
header field name value cr lf
header
~
~ ~
~ lines
~
~ entity body ~
~ body
ebay 8734
usual http request msg Amazon server
cookie file creates ID
usual http response
1678 for user create backend
ebay 8734
set-cookie: 1678 entry database
amazon 1678
usual http request msg
cookie: 1678 cookie- access
specific
usual http response msg action
… …
example 2
host at 3
TLD DNS server
cis.poly.edu 4
wants IP address
for 5
gaia.cs.umass.ed local DNS server
iterated
u query: dns.poly.edu
contacted server 7 6
1 8
replies with
name of server
authoritative DNS server
to contact dns.cs.umass.edu
“ I don’ t know requesting host
cis.poly.edu
this name, but
ask this server
gaia.cs.umass.edu
”
Application Layer 2-67
DNS name
resolution root DNS server
example 2 3
7
recursive query: 6
puts burden of TLD DNS
server
name
resolution on local DNS server
contacted name dns.poly.edu 5 4
server 1 8
heavy load at
authoritative DNS server
upper levels dns.cs.umass.edu
of hierarchy? requesting host
cis.poly.edu
gaia.cs.umass.edu
type=A type=CNAME
name is hostname name is alias name for
value is IP address some “ canonical” (the
real) name
type=NS
name is domain
www.ibm.com is really
(e.g., foo.com) servereast.backup2.ibm.com
value is value is canonical name
hostname of type=MX
authoritative value is name of
name server for
this domain mailserver associated
with name
Application Layer 2-70
DNS protocol, messages
query and reply messages, both
with same message 2 bytes
format 2 bytes
msg header identification flags
2 bytes 2 bytes
identification flags
examples:
file distribution
(BitTorrent)
Streaming
(KanKan)
VoIP (Skype)
Application Layer 2-76
File distribution: client-
server vs P2P
Question: how much time to distribute
file (size F) from one server to N
peers?
peer upload/download capacity is limited
resource
us: server upload
capacity
copies: network
ui
time to send one
client: each client
copy: F/us
must download file
time to send N
copy
copies: NF/us
dmin = min client
download rate
time to download
min client distribute F
time: F/dto N
min
clients using
Dc-s > max{NF/us,,F/dmin}
client-server approach
increases linearly in N
Application Layer 2-78
File distribution time: P2P
server
transmission: must F
u
upload at least one s
copy
di
client: each client network
timedownload
must to send one
file ui
copy: F/us
copy
min client
clients: as download
aggregate must
time: F/d
download NF
min bits
timerate) is us F+ ui
to distribute
DP2P > max{F/us,,F/dmin,,NF/(us +
to N clients using ui)}
P2P approach
increases linearly in N …
… but so does this, as each peer brings service capacity
Application Layer 2-79
Client-server vs. P2P:
example
client upload rate = u, F/u = 1 hour, us = 10u, dmin ≥ us
3.5
P2P
Minimum Distribution Time
3
Client-Server
2.5
1.5
0.5
0
0 5 10 15 20 25 30 35
N
Application Layer 2-80
P2P file distribution:
BitTorrent
file divided into 256Kb chunks
peers in torrent send/receive file chunks
Alice arrives …
… obtains list
of peers from tracker
… and begins exchanging
file chunks with peers in torrent
DHT paradigm
Peer churn
Simple Database
Simple database with(key, value)
pairs:
• key: human name; value: social
Key Value
security #
John Washington 132-54-3570
Diana Louise Jones 761-55-3791
Xiaoming Liu 385-41-0902
Rakesh Gopal 441-89-1956
Linda Cohen 217-66-5609
……. ………
Lisa Kobayashi 177-23-0199
12
60
13
48
25
40
32 “overlay network”
Resolving a query
13
48
(N) messages 25
n avgerage to resolve
uery, when there 40
32
re N peers
Circular DHT with
shortcuts 1 What is the value for
value
key 53
12
60
13
48
25
40
32
• each peer keeps track of IP addresses of
predecessor, successor, short cuts.
• reduced from 6 to 3 messages.
• possible to design shortcuts with O(log N)
neighbors, O(log N) messages in query
Peer churn handling peer
1
churn:
peers may come and go
15 3 (churn)
each peer knows
4 address of its two
successors
12
5 each peer
periodically pings its
10 two successors to check
8
aliveness
example: peer 5 abruptly leaves
if immediate
successor leaves,
choose next successor
as new immediate
successor
Peer churn handling peer
1
churn:
peers may come and go
15 3 (churn)
each peer knows
4 address of its two
successors
12
each peer
periodically pings its
10 two successors to check
8
aliveness
example: peer 5 abruptly leaves
if immediate
peer 4 detects peer 5’ s departure;
successor leaves,
makes 8 its immediatechoose
successor
next successor
4 asks 8 who its immediate successor
as new immediate
is; makes 8’ s immediate successor its
successor
second successor.
Chapter 2: outline
2.1 principles 2.6 P2P
of network applications
applications 2.7 socket
app programming
architectures with UDP and
app TCP
requirements
2.2 Web and HTTP
2.3 FTP
2.4 electronic
mail
SMTP, POP3,
IMAP
Application Layer 2-95
Socket programming
goal: learn how to build
client/server applications that
communicate using sockets
socket: door between application
process and end-end-transport
protocol
application socket application
controlled by
process process app developer
transport transport
network network controlled
link
by OS
link Internet
physical physical
write reply to
serverSocket read datagram from
specifying clientSocket
client address,
port number close
clientSocket
Application 2-99
Example app: UDP client
Python UDPClient
include Python’s socket
library from socket import *
serverName = ‘hostname’
serverPort = 12000
create UDP socket for
server
clientSocket = socket(socket.AF_INET,
get user keyboard socket.SOCK_DGRAM)
input
message = raw_input(’Input lowercase sentence:’)
Attach server name, port to
message; send into socket clientSocket.sendto(message,(serverName, serverPort))
read reply characters from modifiedMessage, serverAddress =
socket into string
clientSocket.recvfrom(2048)
print out received string print modifiedMessage
and close socket
clientSocket.close()
Application Layer 2-100
Example app: UDP server
Python UDPServer
from socket import *
serverPort = 12000
create UDP socket serverSocket = socket(AF_INET, SOCK_DGRAM)
bind socket to local port
number 12000 serverSocket.bind(('', serverPort))
print “The server is ready to receive”
loop forever while 1:
Read from UDP socket into
message, getting client’s
message, clientAddress = serverSocket.recvfrom(2048)
address (client IP and port) modifiedMessage = message.upper()
send upper case string serverSocket.sendto(modifiedMessage, clientAddress)
back to this client
write reply to
connectionSocket read reply from
clientSocket
close
connectionSocket close
clientSocket
Introduction 1-108
application
packet (www browser,
OS
packet Transport (TCP/UDP)
copy of all Network (IP)
capture Ethernet
frames Link (Ethernet)
(pcap) sent/receive
d Physical