Professional Documents
Culture Documents
Application
Layer
clients:
communicate with server
may be intermittently
client/server connected
may have dynamic IP
addresses
do not communicate
directly with each
other
application application
socket controlled by
process process app developer
transport transport
network network controlled
link
by OS
link Internet
physical physical
~
~ 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
client origin
server
access link
utilization:
60% of requests use access 1.54 Mbps
link access link
data rate to browsers over institutional
access
total link = 0.6*1.50
delay network
1 Gbps LAN
Mbps = .9 Mbps
= 0.6 * (delay from origin
utilization = 0.9/1.54 = .
servers) +0.4 * (delay when
58 local web
satisfied at cache) cache
= 0.6 (2.01) + 0.4 (~msecs)
= ~ 1.2 secs
less than with 154 Mbps
link (and cheaper too!) Application Layer 2-42
Conditional GET
client server
Goal: don’ t send
object if cache has
up-to-date cached HTTP request msg
version If-modified-since: <date> object
no object transmission not
delay modified
HTTP response
lower link utilization before
HTTP/1.0
cache: specify date 304 Not Modified <date>
of cached copy in
HTTP request
If-modified-since:
<date>
server: response HTTP request msg
If-modified-since: <date> object
contains no object
modified
if cached copy is
up-to-date: HTTP response after
HTTP/1.0 200 OK <date>
HTTP/1.0 304 Not
Modified <data>
Application Layer 2-43
Chapter 2: outline
2.1 principles of 2.6 P2P
network applications
applications 2.7 socket
app programming
architectures
app requirements
with UDP and
TCP
2.2 Web and HTTP
2.3 FTP
2.4 electronic
mail
SMTP, POP3, IMAP
2.5 DNS
Application Layer 2-44
FTP: the file transfer
protocol
file transfer
FTP FTP FTP
user client server
interface
user
at host remote file
local file system
system
… …
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
recursive query: 7
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
type=NS real) name
name is domain www.ibm.com is really
(e.g., foo.com) servereast.backup2.ibm.com
value is hostname
of authoritative value is canonical name
name server for type=MX
this domain value is name of
mailserver associated
with name
Application Layer 2-70
DNS protocol, messages
query and reply messages, both with same message format
2 bytes 2 bytes
2 bytes 2 bytes
identification flags
examples:
file distribution
(BitTorrent)
Streaming (KanKan)
VoIP (Skype)
increases linearly in N
Application Layer 2-78
File distribution time: P2P
server
transmission: must F
u
upload at least one s
di
copy
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:
Key
human name;
Value
value: social
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
example: peer 5 abruptlyaliveness
leaves
peer 4 detects peer 5’
sif immediatemakes 8
departure;
its immediate successor successor leaves,
choosesuccessor
4 asks 8 who its immediate next successor
is;
as new immediate
makes 8’ s immediate successor its second
successor. successor
Chapter 2: outline
2.1 principles of 2.6 P2P
network applications
applications
2.7 socket
app
architectures programming
app requirements with UDP and
TCP
2.2 Web and HTTP
2.3 FTP
2.4 electronic
mail
SMTP, POP3, IMAP
2.5 DNS
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 application
socket controlled by
process process app developer
transport transport
network network controlled
link
by OS
link Internet
physical physical
Application Example:
1. Client reads a line of characters
(data) from its keyboard and sends
the data to the server.
2. The server receives the data and
converts characters to uppercase.
3. The server sends the modified data
to the client.
4. The client receives the modified
Application Layer 2-97
Socket programming with
UDP
UDP: no “ connection” between client
& server
no handshaking before sending data
sender explicitly attaches IP destination
address and port # to each packet
rcvr extracts sender IP address and port#
from received packet
UDP: transmitted data may be lost or
received out-of-order
Application viewpoint:
UDP provides unreliable transfer of
groups of bytes (“ datagrams” ) between
client and server
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