Professional Documents
Culture Documents
Our goals:
conceptual,
implementation
aspects of network
application protocols
o transport-layer
service models
o client-server
paradigm
o peer-to-peer
paradigm
HTTP
FTP
SMTP / POP3 / IMAP
DNS
programming network
applications
o
socket API
2: Application Layer
E-mail
Web
Instant messaging
Remote login
P2P file sharing
Multi-user network
games
Streaming stored
video clips
Internet telephone
Real-time video
conference
Massive parallel
computing
2: Application Layer
application
transport
network
data link
physical
application
transport
network
data link
physical
application
transport
network
data link
physical
2: Application Layer
Application architectures
Client-server
Peer-to-peer (P2P)
Hybrid of client-server and P2P
2: Application Layer
Client-server archicture
server:
o
o
o
always-on host
permanent IP address
server farms for scaling
clients:
o
o
o
o
communicate with
server
may be intermittently
connected
may have dynamic IP
addresses
do not communicate
directly with each other
2: Application Layer
no always on server
arbitrary end systems
directly communicate
peers are intermittently
connected and change IP
addresses
example: Gnutella
Highly scalable
But difficult to manage
2: Application Layer
Instant messaging
o
o
2: Application Layer
application
transport
network
data link
physical
Application-layer protocols
o
o
application
transport
network
data link
physical
application
transport
network
data link
physical
2: Application Layer
Types of messages
exchanged, eg, request
& response messages
Syntax of message
types: what fields in
messages & how fields
are delineated
Semantics of the
fields, ie, 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, KaZaA, Skype
2: Application Layer
10
process sends/receives
messages to/from its
socket
socket analogous to door
o
o
host or
server
host or
server
process
controlled by
app developer
process
socket
socket
TCP with
buffers,
variables
Internet
TCP with
buffers,
variables
controlled
by OS
2: Application Layer
11
Addressing processes:
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:
o
o
HTTP server: 80
Mail server: 25
2: Application Layer
12
Bandwidth
some apps (e.g.,
multimedia) require
minimum amount of
bandwidth to be
effective
other apps (elastic
apps) make use of
whatever bandwidth
they get
2: Application Layer
13
Bandwidth
Time Sensitive
file transfer
e-mail
Web documents
real-time audio/video
no loss
no loss
no loss
loss-tolerant
no
no
no
yes, 100s msec
stored audio/video
interactive games
instant messaging
loss-tolerant
loss-tolerant
no loss
elastic
elastic
elastic
audio: 5kbps-1Mbps
video:10kbps-5Mbps
same as above
few kbps up
elastic
Application
2: Application Layer
14
UDP service:
connection-oriented: setup
2: Application Layer
15
Application
layer protocol
Underlying
transport protocol
TCP
TCP
TCP
TCP
TCP or UDP
typically UDP
2: Application Layer
16
host name
path name
2: Application Layer
17
HTTP overview
HTTP: hypertext
transfer protocol
HT
TP
r
equ
est
PC running HT
TP
res
Explorer
pon
se
st
e
u
q
re
se Server
P
n
T
o
running
HT
esp
r
TP
Apache Web
T
H
server
Mac running
Navigator
2: Application Layer
18
HTTP is stateless
server maintains no
information about
past client requests
2: Application Layer
19
HTTP connections
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
2: Application Layer
20
Nonpersistent HTTP
Suppose user enters URL
www.bilkent.edu.tr/someDepartment/
(contains text,
references to 10
jpeg images)
time
2: Application Layer
21
connection.
2: Application Layer
22
initiate TCP
connection
RTT
request
file
time to
transmit
file
RTT
file
received
time
time
2: Application Layer
23
Persistent HTTP
Nonpersistent HTTP issues:
requires 2 RTTs per object
OS must work and allocate
host resources for each TCP
connection
but browsers often open
parallel TCP connections to
fetch referenced objects
Persistent HTTP
server leaves connection
open after sending response
subsequent HTTP messages
between same client/server
are sent over connection
2: Application Layer
24
request line
(GET, POST,
HEAD commands)
Carriage return,
line feed
indicates end
of message
2: Application Layer
25
2: Application Layer
26
Method types
HTTP/1.0
GET
POST
HEAD
o
HTTP/1.1
GET, POST, HEAD
PUT
o
DELETE
o
2: Application Layer
27
2: Application Layer
28
data, e.g.,
requested
HTML file
HTTP/1.1 200 OK
Connection close
Date: Thu, 06 Aug 1998 12:00:15 GMT
Server: Apache/1.3.0 (Unix)
Last-Modified: Mon, 22 Jun 1998 ...
Content-Length: 6821
Content-Type: text/html
data data data data data ...
2: Application Layer
29
30
telnet www.ee.bilkent.edu.tr 80
31
time
2: Application Layer
32
Example:
o
o
2: Application Layer
33
Set-cookie: 1678
usual http request msg
cookie: 1678
usual http response msg
Cookie file
amazon: 1678
ebay: 8734
cookiespecific
action
ss
acce
ac
ce
n
server
da try i
creates ID tabasen bac
ke
nd
1678 for user
ss
Cookie file
server
cookie: 1678
usual http response msg
cookiespectific
action
2: Application Layer
34
Cookies (continued)
What cookies can bring:
authorization
shopping carts
recommendations
user session state
(Web e-mail)
35
path=PATH
2: Application Layer
36
Cookies File
.netscape.com TRUE /
FALSE 1128258721
sampler 1097500321
.edge.ru4.com TRUE /
FALSE 2074142135
ru4.uid 2|3|0#12740302632086421#1917818738
.edge.ru4.com TRUE /
FALSE 1133246135
ru4.1188.gts :2
.netscape.com TRUE /
FALSE 1128065747
RWHAT set|1128065747300
.nytimes.com TRUE /
FALSE 1159598159
RMID 833ff0b33a03433cdccf603e
.netscape.com TRUE /
FALSE 1128148560
adsNetPopup0 1128062159725
servedby.advertising.com
TRUE /
FALSE 1130654161
1812261973
_433cdcd1,,695214^76559_
.advertising.com
TRUE /
FALSE 1285742161
ACID bb640011280621610000!
.bluestreak.com TRUE /
FALSE 1443407766
id
33167285258566120 bb=141A11twQw_"4totrKoAA| adv=
.mediaplex.com TRUE /
FALSE 1245628800
svid 80016269101
.nytdigital.com TRUE /
FALSE 1625726176
TID
0e0pcsb11jpn70
.nytdigital.com TRUE /
FALSE 1625726176
TData
.nytimes.com TRUE /
FALSE 1625726176
TID
0e0pcsb11jpn70
.nytimes.com TRUE /
FALSE 1625726176
TData
.doubleclick.net
TRUE /
FALSE 1222670215
id
8000006195fbc8b
servedby.advertising.com
TRUE /
FALSE 1130654216
5907528 _433cdd08,,707769^243007_
www.yahoo.com TRUE /
FALSE 1149188401
FPB
fc1hmqbqc11jpnci
2: Application Layer
37
edge.ru4.com
TRUE
FALSE
2074142135 ru4.uid
2|3|0#1274
nytimes.com
TRUE
FALSE
1625726176 TID
0e0pcsb11jpn70
Name
Value
2: Application Layer
38
server
client
HTTP request msg
If-modified-since:
<date>
HTTP response
object
not
modified
HTTP/1.0
304 Not Modified
HTTP response
object
modified
HTTP/1.0 200 OK
<data>
2: Application Layer
39
user
at host
FTP
FTP
user
client
interface
local file
system
file transfer
FTP
server
remote file
system
40
FTP
client
FTP
server
41
2: Application Layer
42
Electronic Mail
outgoing
message queue
user mailbox
user
agent
user agents
mail servers
simple mail transfer
protocol: SMTP
User Agent
a.k.a. mail reader
composing, editing, reading
mail messages
e.g., Eudora, Outlook, elm,
Netscape Messenger
outgoing, incoming messages
stored on server
mail
server
SMTP
SMTP
mail
server
user
agent
SMTP
user
agent
mail
server
user
agent
user
agent
user
agent
2: Application Layer
43
Mail Servers
mail
server
SMTP
SMTP
mail
server
user
agent
SMTP
user
agent
mail
server
user
agent
user
agent
user
agent
2: Application Layer
44
2: Application Layer
45
Aye
Ali
1
user
agent
mail
server
3
mail
server
4
user
agent
2: Application Layer
46
HELO cs.bilkent.edu.tr
250 gordion.cs.bilkent.edu.tr Hello nemrut.ee.bilkent.edu.
tr [139.179.12.28], pleased to meet you
DATA
354 Enter mail, end with "." on a line by itself
hello
.
250 2.0.0 Message accepted for delivery
QUIT
221 2.0.0 gordion.cs.bilkent.edu.tr closing connection
2: Application Layer
47
HTTP: pull
SMTP: push
both have ASCII
command/response
interaction, status codes
HTTP: each object
encapsulated in its own
response msg
SMTP: multiple objects
sent in multipart msg
2: Application Layer
48
SMTP
SMTP
senders mail
server
access
protocol
user
agent
receivers mail
server
49
distributed database
application-layer protocol
Q: map between IP
addresses and name ?
implemented in hierarchy of
many name servers
host, routers, name servers to
communicate to resolve names
(address/name translation)
o note: core Internet
function, implemented as
application-layer protocol
o complexity at networks
edge
2: Application Layer
50
DNS
DNS services
Hostname to IP
address translation
Host aliasing
o
Replicated Web
servers: set of IP
addresses for one
canonical name
2: Application Layer
51
52
e NASA Mt View, CA
f Internet Software C. Palo Alto,
CA (and 17 other locations)
13 root name
servers worldwide
b USC-ISI Marina del Rey, CA
l ICANN Los Angeles, CA
2: Application Layer
53
2: Application Layer
54
2: Application Layer
55
Example
Host at
firat.bilkent.edu.tr
wants IP address for
gaia.cs.umass.edu
2
3
requesting host
Firat.bilkent.edu.tr
gaia.cs.umass.edu
2: Application Layer
56
Recursive queries
recursive query:
iterated query:
3
7
6
TLD DNS serve
contacted server
1
8
replies with name of
server to contact
authoritative DNS server
dns.cs.umass.edu
I dont know this
requesting host
name, but ask this Firat.bilkent.edu.tr
server
gaia.cs.umass.edu
2: Application Layer
57
RFC 2136
http://www.ietf.org/html.charters/dnsind-charter.html
2: Application Layer
58
DNS records
DNS: distributed db storing resource records (RR)
RR format: (name,
Type=A
o
o
name is hostname
value is IP address
Type=CNAME
o
Type=NS
o
o
Type=MX
o
59
message format
msg header
identification: 16 bit #
for query, reply to query
uses same #
flags:
o query or reply
o recursion desired
o recursion available
o reply is authoritative
2: Application Layer
60
2: Application Layer
61
2: Application Layer
62
2
local DNS server
dns.bilkent.edu.tr
5: reply contains IP
address for Web
server for
Network Utopia
(212.212.212.178)
requesting host
firat.bilkent.edu.tr
7: TCP connection
authoritative name
server for Network
Utopia
IP: 212.212.212.1
63
Socket programming
Goal: learn how to build client/server application that
communicate using sockets
Socket API
socket
a host-local,
application-created,
OS-controlled interface
2: Application Layer
64
process
process
socket
TCP with
buffers,
variables
host or
server
internet
socket
TCP with
buffers,
variables
controlled by
application
developer
controlled by
operating
system
host or
server
2: Application Layer
65
66
Stream jargon
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.
2: Application Layer
67
Client
Process
process
input
stream
output
stream
inFromServer
outToServer
monitor
inFromUser
keyboard
input
stream
client
TCP
clientSocket
socket
to network
TCP
socket
from network
2: Application Layer
68
Client
create socket,
port=x, for
incoming request:
welcomeSocket =
ServerSocket()
TCP
setup
create socket,
connect to hostid, port=x
clientSocket =
Socket()
send request using
clientSocket
69
BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in));
Socket clientSocket = new Socket("hostname", 6789);
DataOutputStream outToServer =
new DataOutputStream(clientSocket.getOutputStream());
2: Application Layer
70
BufferedReader inFromServer =
new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));
sentence = inFromUser.readLine();
Send line
to server
outToServer.writeBytes(sentence + '\n');
Read line
from server
modifiedSentence = inFromServer.readLine();
System.out.println("FROM SERVER: " + modifiedSentence);
clientSocket.close();
}
}
2: Application Layer
71
Create
welcoming socket
at port 6789
Wait, on welcoming
socket for contact
by client
Create input
stream, attached
to socket
72
DataOutputStream outToClient =
new DataOutputStream(connectionSocket.getOutputStream());
Read in line
from socket
clientSentence = inFromClient.readLine();
capitalizedSentence = clientSentence.toUpperCase() + '\n';
outToClient.writeBytes(capitalizedSentence);
}
}
2: Application Layer
73
application viewpoint
2: Application Layer
74
Client
create socket,
clientSocket =
DatagramSocket()
Create, address (hostid, port=x,
send datagram request
using clientSocket
2: Application Layer
75
Client
process
monitor
inFromUser
keyboard
Process
Input: receives
packet (TCP
received byte
stream)
UDP
packet
receivePacket
sendPacket
Output: sends
client
UDP
clientSocket
socket
to network
UDP
packet
UDP
socket
from network
2: Application Layer
76
Create
input stream
Create
client socket
Translate
hostname to IP
address using DNS
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();
2: Application Layer
77
DatagramPacket sendPacket =
new DatagramPacket(sendData, sendData.length, IPAddress, 9876);
clientSocket.send(sendPacket);
DatagramPacket receivePacket =
new DatagramPacket(receiveData, receiveData.length);
Read datagram
from server
clientSocket.receive(receivePacket);
String modifiedSentence =
new String(receivePacket.getData());
System.out.println("FROM SERVER:" + modifiedSentence);
clientSocket.close();
}
}
2: Application Layer
78
Create
datagram socket
at port 9876
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);
2: Application Layer
79
Get IP addr
port #, of
sender
Create datagram
to send to client
DatagramPacket sendPacket =
new DatagramPacket(sendData, sendData.length, IPAddress,
port);
Write out
datagram
to socket
serverSocket.send(sendPacket);
}
}
2: Application Layer
80
2: Application Layer
81
origin
server
Proxy
HT
st
TP
e
u
req server
req
H
u
P
e
st
client TTP
nse
TT
o
H
p
res
res
pon
P
se
TT
H
st
e
u
eq
r
P
nse
T
o
HT
esp
r
TP
T
H
client
origin
server
2: Application Layer
82
2: Application Layer
83
institutional
cache
2: Application Layer
84
origin
servers
public
Internet
10 Mbps
access link
institutional
network
10 Mbps LAN
institutional
cache
2: Application Layer
85
Consequence
origin
servers
public
Internet
1.5 Mbps
access link
institutional
network
10 Mbps LAN
institutional
cache
2: Application Layer
86
2: Application Layer
87
CDN example
Origin server
1
2
3
CDNs authoritative
DNS server
HTTP request for
www.cdn.com/www.foo.com/sports/ruth.gif
origin server
www.foo.com
distributes HTML
Nearby
CDN server
Replaces:
http://www.foo.com/sports.ruth.gif
with
http://www.cdn.com/www.foo.com/sports/ruth.gif
CDN company
cdn.com
distributes gif files
uses its authoritative
DNS server to route
redirect requests
2: Application Layer
88
89
no always-on server
arbitrary end systems
directly communicate peer-peer
peers are intermittently
connected and change IP
addresses
2: Application Layer
90
Server
us
File, size F
dN
uN
u1
d1
u2
Network (with
abundant bandwidth)
2: Application Layer
91
server sequentially
sends N copies:
o
NF/us time
Server
F
us
dN
u1 d1 u2
d2
Network (with
abundant bandwidth)
uN
Time to distribute F
to N clients using = dcs = max { NF/us, F/min(di) }
i
client/server approach
increases linearly in N
(for large N) 2: Application Layer
92
93
3.5
P2P
Client-Server
3
2.5
2
1.5
1
0.5
0
0
10
15
20
25
30
35
N
2: Application Layer
94
fully distributed
o
no central server
95
Gnutella: protocol
Query message
sent over existing TCP
connections
peers forward
Query message
ry
e
QueryHit
it
Qu
H
ry
sent over
e
Qu
reverse
Query
path
File transfer:
HTTP
Query
QueryHit
Qu
e
ry
QueryHit
Scalability:
limited scope
flooding
Qu
er
2: Application Layer
96
2: Application Layer
97
ordinary peer
group-leader peer
neighoring relationships
in overlay network
2: Application Layer
98
KaZaA: Querying
99
Kazaa tricks
2: Application Layer
100
participating in torrent
torrent: group of
peers exchanging
chunks of a file
obtain list
of peers
trading
chunks
peer
2: Application Layer
101
BitTorrent (1)
102
BitTorrent (2)
Pulling Chunks
at any given time,
different peers have
different subsets of
file chunks
periodically, a peer
(Alice) asks each
neighbor for list of
chunks that they have.
Alice sends requests
for her missing chunks
o rarest first
highest rate
2: Application Layer
103
Supernode
(SN)
2: Application Layer
104
SC registers with SN
o
SC logs in
(authenticate)
Skype
login server
105
Peers as relays
Solution:
o
o
o
106