Application Layer
Application Layer
Application Layer
Computer
Networking: A
Top Down
Approach
6th edition
Jim Kurose, Keith Ross
Addison-Wesley
March 2012
clients:
communicate with server
client/server may be intermittently
connected
may have dynamic IP
addresses
do not communicate directly
with each other
Application Layer 2-6
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 can come and join
or leave the network.
peers are intermittently
connected and change IP
addresses
complex management
application application
socket controlled by
process process app developer
transport transport
network network controlled
link
by OS
link Internet
physical physical
Throughput
the rate at which the sending process can deliver bits to the receiving
process.
some apps (“bandwidth-sensitive applications”) require minimum
amount of throughput to be “ effective”
other apps (“ elastic apps” ) make use of whatever throughput they get
timing
some apps (e.g., Internet telephony, interactive games) require low delay to
be “ effective”
security
encryption, data integrity, …
application underlying
application layer protocol transport protocol
www.someschool.edu/someDept/
pic.gif
host name path name
time
6. Steps 1-5 repeated for each of 10
jpeg objects
~
~ entity body ~
~ body
data, e.g.,
requested
HTML file
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
HTTP/1.1 200 OK
Date: Sat, 8 oct 2011 15:39:29
Server: Apache/1.3.0 (unix)
Last-Modified: Wed, 7 Sep 2011 09:23:25
Content-Type: image/gif
… …
gaia.cs.umass.edu
type=A type=CNAME
name is hostname name is alias name for some
value is IP address “ canonical” (the real) name
type=NS www.ibm.com is really
name is domain (e.g., servereast.backup2.ibm.com
foo.com) value is canonical name
value is hostname of
authoritative name
server for this domain
2 bytes 2 bytes
identification flags
examples:
file distribution
(BitTorrent)
Streaming (KanKan)
VoIP (Skype)
time to distribute F
to N clients using
Dc-s > max{NF/us,,F/dmin}
client-server approach
increases linearly in N
Application Layer 2-66
File distribution time: P2P
server transmission: must
upload at least one copy F
us
time to send one copy: F/us
di
client: each client must
network
download file copy ui
min client download time: F/dmin
clients: as aggregate must download NF bits
max upload rate (limting max download rate) is u + u
s i
time to distribute F
DP2P
to N clients using > max{F/us,,F/dmin,,NF/(us + ui)}
P2P approach
increases linearly in N …
… but so does this, as each peer brings service capacity
Application Layer 2-67
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
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 security #
Key Value
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
O(N) messages 25
on avgerage to resolve
query, when there 40
32
are 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 churn:
1
peers may come and go (churn)
each peer knows address of its
3 two successors
15
each peer periodically pings its
4 two successors to check aliveness
if immediate successor leaves,
12
5 choose next successor as new
immediate successor
10
8
example: peer 5 abruptly leaves
Peer churn handling peer churn:
1
peers may come and go (churn)
each peer knows address of its
15 3 two successors
each peer periodically pings its
4 two successors to check aliveness
if immediate successor leaves,
12
choose next successor as new
immediate successor
10
8
example: peer 5 abruptly leaves
peer 4 detects peer 5’s departure; makes 8 its immediate
successor
4 asks 8 who its immediate successor is; makes 8’s
immediate successor its second successor.
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 data and displays
the line on its screen.
Application Layer 2-84
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-86
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-87
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