Professional Documents
Culture Documents
Application
Layer
A note on the use of these ppt slides:
Were making these slides freely available to all (faculty, students, readers).
Theyre in PowerPoint form so you see the animations; and can add, modify,
and delete slides (including this one) and slide content to suit your needs.
They obviously represent a lot of work on our part. In return for use, we only
ask the following:
If you use these slides (e.g., in a class) that you mention their source
(after all, wed like people to use our book!)
If you post any slides on a www site, that you note that they are adapted
from (or perhaps identical to) our slides, and note our copyright of this
material.
Thanks and enjoy! JFK/KWR
All material copyright 1996-2012
J.F Kurose and K.W. Ross, All Rights Reserved
Computer
Networking:
A Top Down
Approach
6th edition
Jim Kurose, Keith
Ross
Addison-Wesley
March 2012
Application Layer 2-1
Chapter 2: outline
2.1 principles of
network
applications
2.2 Web and HTTP
2.3 FTP
2.4 electronic
mail
2.6 P2P
applications
2.7 socket
programming
with UDP and
TCP
SMTP, POP3,
IMAP
2.5 DNS
Application Layer 2-2
Chapter 2: application
layer
our goals:
conceptual,
implementation
aspects of
network
application
protocols
transport-layer
service models
client-server
paradigm
peer-to-peer
paradigm
learn about
protocols by
examining popular
application-level
protocols
HTTP
FTP
SMTP / POP3 /
IMAP
DNS
creating network
applications
socket API
Application Layer 2-3
e-mail
web
text messaging
remote login
P2P file sharing
multi-user
network games
streaming stored
video (YouTube,
Hulu, Netflix)
voice over IP
(e.g., Skype)
real-time video
conferencing
social networking
search
application
transport
network
data link
physical
application
transport
network
data link
physical
application
transport
network
data link
physical
Application
architectures
possible structure of applications:
client-server
peer-to-peer (P2P)
Client-server
architecture
server:
always-on host
permanent IP address
data centers for
scaling
clients:
client/server
P2P architecture
no always-on server
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
intermittently
connected and change
IP addresses
complex management
peer-peer
Processes
communicating
process: program
running within a
host
clients, servers
client process:
server process:
aside:
applications with
P2P architectures
have client
processes & server
processes
Application Layer 2-9
Sockets
socket
applicatio
n
process
transport
transport
network
network
link
physical
Internet
link
controlled by
app developer
controlled
by OS
physical
Addressing processes
to receive
messages, process
must have
identifier
host device has
unique 32-bit IP
address
Q: does IP address
A:
of
host
which
no,onmany
process
runs can be
processes
suffice
foron same
running
identifying
the
host
process?
identifier includes
both IP address and
port numbers
associated with
process on host.
example port
numbers:
HTTP server: 80
mail server: 25
more shortly
Application Layer 2-11
App-layer protocol
defines
types of messages
open protocols:
exchanged,
e.g., request,
response
message syntax:
what fields in
messages & how fields
are delineated
message semantics
meaning of
information in fields
rules for when and how
processes send &
respond to messages
defined in RFCs
allows for
interoperability
e.g., HTTP, SMTP
proprietary
protocols:
e.g., Skype
timing
some apps (e.g.,
Internet telephony,
interactive games)
require low delay
to be effective
throughput
some apps (e.g.,
multimedia)
require minimum
amount of
throughput to be
effective
other apps
(elastic apps)
make use of
whatever
security
throughput
encryption,they
data
get
integrity,
Application Layer 2-13
data loss
throughput
file transfer
e-mail
Web documents
real-time audio/video
no loss
no loss
no loss
loss-tolerant
stored audio/video
interactive games
text messaging
loss-tolerant
loss-tolerant
no loss
elastic
no
elastic
no
elastic
no
audio: 5kbps-1Mbps yes, 100s msec
video:10kbps-5Mbps
same as above
yes, few secs
few kbps up
yes, 100s msec
elastic
yes and no
time sensitive
Internet transport
protocols services
TCP service:
UDP service:
reliable transport
between sending and
receiving process
flow control: sender
wont overwhelm
receiver
congestion control:
throttle sender when
network overloaded
does not provide:
timing, minimum
throughput guarantee,
security
connection-oriented:
setup required between
client and server
processes
unreliable data
transfer between
sending and
receiving process
does not provide:
reliability, flow
control, congestion
control, timing,
throughput
guarantee, security,
orconnection setup,
application
layer protocol
underlying
transport protocol
TCP
TCP
TCP
TCP
TCP or UDP
TCP or UDP
Securing TCP
TCP & UDP
no encryption
cleartext passwds
sent into socket
traverse Internet
in cleartext
SSL
provides encrypted
TCP connection
data integrity
end-point
authentication
SSL is at app
layer
Apps use SSL
libraries, which
talk to TCP
SSL socket API
cleartext passwds
sent into socket
traverse Internet
encrypted
See Chapter 7
Chapter 2: outline
2.1 principles of
network
applications
app
architectures
app requirements
2.6 P2P
applications
2.7 socket
programming
with UDP and
TCP
2.5 DNS
Application Layer 2-18
path name
HTTP overview
HTTP: hypertext
transfer protocol
Webs application
layer protocol
client/server model
client: browser
that requests,
receives, (using
HTTP protocol) and
displays Web
objects
server: Web server
sends (using HTTP
protocol) objects
in response to
requests
HT
TP
PC running
Firefox browser
req
ues
t
HT
TP
res
p
ons
e
t
es
u
req
server
se
n
running
po
s
e
r
Apache Web
TP
T
server
H
TP
T
H
iphone running
Safari browser
HTTP overview
(continued)
uses TCP:
HTTP is stateless
server maintains no
information about
past client requests
aside
protocols that
maintain state
are complex!
must be maintained
if server/client
crashes, their views
of state may be
inconsistent, must
be reconciled
HTTP connections
non-persistent
HTTP
at most one
object sent over
TCP connection
connection
then closed
downloading
multiple objects
required
multiple
connections
persistent HTTP
multiple
objects can be
sent over
single TCP
connection
between client,
server
Non-persistent HTTP
suppose user enters URL:
www.someSchool.edu/someDepartment/home.index
(contains text,
references to 10
jpeg images)
Non-persistent HTTP
(cont.)
5. HTTP client receives
time
response message
containing html file,
displays html. Parsing
html file, finds 10
referenced jpeg objects
time to
transmit
file
time
Persistent HTTP
non-persistent
HTTP issues:
requires 2 RTTs
per object
OS overhead for
each TCP
connection
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
sent over open
connection
client sends requests
as soon as it
encounters a
referenced object
as little as one RTT
for all the
referenced objects
Application Layer 2-26
header
lines
carriage return,
line feed at start
of line indicates
end of header lines
User-Agent: Firefox/3.6.10\r\n
Accept: text/html,application/xhtml+xml\r\n
Accept-Language: en-us,en;q=0.5\r\n
Accept-Encoding: gzip,deflate\r\n
Accept-Charset: ISO-8859-1,utf-8;q=0.7\r\n
Keep-Alive: 115\r\n
Connection: keep-alive\r\n
\r\n
Application Layer 2-27
sp
URL
sp
value
version
cr
lf
value
cr
lf
request
line
header
lines
~
~
~
~
~
~
cr
lf
lf
entity body
~
~
body
Method
types
HTTP/1.0:
GET
POST
HEAD
asks server to
leave requested
object out of
response
HTTP/1.1:
header
lines
data, e.g.,
requested
HTML file
User-server state:
cookies
example:
many Web sites use
cookies
four components:
1) cookie header
line of HTTP
response message
2) cookie header
line in next HTTP
request message
3) cookie file kept
on users host,
managed by users
browser
4) back-end database
at Web site
ebay 8734
server
usual http request msg
cookie file
ebay 8734
amazon 1678
set-cookie: 1678
cookie: 1678
Amazon server
creates ID
1678 for user create backend
entry database
cookiespecific
action
access
access
usual http request msg
cookie: 1678
cookiespecific
action
Application Layer 2-35
Cookies (continued)
what cookies can
be used for:
aside
cookies and
privacy:
authorization
cookies permit
shopping carts
sites to learn a
recommendations
lot about you
user session state
you may supply
(Web e-mail)
name and e-mail
to sites
how to keep state:
protocol endpoints: maintain
state at sender/receiver
over multiple transactions
cookies: http messages carry
state
HT
TP
r
proxy
server
equ
est
res
pon
se
t
es
u
req
e
P
ns
T
o
T
p
H
es
r
TP
T
H
H
client TTP
client
st
e
u
req
P
T
se
n
o
HT
p
origin
res
P
T
server
HT
origin
server
cache acts as
both client and
server
server for original
requesting client
client to origin
server
typically cache
is installed by
ISP (university,
company,
residential ISP)
Caching example:
assumptions:
avg object size: 100K
bits
avg request rate from
browsers to origin
servers:15/sec
avg data rate to
browsers: 1.50 Mbps
RTT from institutional
router to any origin
problem!
server: 2 sec
access link rate: 1.54
Mbps
origin
servers
public
Internet
1.54 Mbps
access link
institutional
network
1 Gbps LAN
consequences:
LAN utilization: 15%
access link utilization
= 99%
assumptions:
bits
avg request rate from
browsers to origin
servers:15/sec
avg data rate to
browsers: 1.50 Mbps
154
RTT from institutional
router to any origin Mbps
server: 2 sec
9.9%
access link rate: 1.54
Mbps
public
Internet
origin
servers
1.54 Mbps
154 Mbps
access link
institutional
network
1 Gbps LAN
consequences:
LAN utilization:
msecs
15%
access link utilization =
Cost:
99% increased access link speed (not cheap!)
total delay
= Internet
assumptions:
bits
avg request rate from
browsers to origin
servers:15/sec
avg data rate to
browsers: 1.50 Mbps
RTT from institutional
router to any origin
server: 2 sec
? 1.54
access link rate:
?
Mbps
origin
servers
public
Internet
1.54 Mbps
access link
institutional
network
1 Gbps LAN
local web
cache
Cost:
100% web cache (cheap!)
total delay
= Internet
suppose
origin
servers
public
Internet
access link
utilization:
1.54 Mbps
access link
link
link = 0.6*1.50
access
total
delay
Mbps = .9
Mbps
institutional
network
1 Gbps LAN
local web
cache
Conditional GET
server
client
server: response
contains no object
if cached copy is
up-to-date:
HTTP/1.0 304 Not
Modified
HTTP response
HTTP/1.0
304 Not Modified
HTTP response
HTTP/1.0 200 OK
object
not
modified
before
<date>
object
modified
after
<date>
<data>
Application Layer 2-43
Chapter 2: outline
2.1 principles of
network
applications
app
architectures
app requirements
2.6 P2P
applications
2.7 socket
programming
with UDP and
TCP
2.5 DNS
Application Layer 2-44
user
at host
FTP
client
local file
system
FTP
server
remote file
system
sample return
codes
Chapter 2: outline
2.1 principles of
network
applications
app
architectures
app requirements
2.6 P2P
applications
2.7 socket
programming
with UDP and
TCP
2.5 DNS
Application Layer 2-48
Electronic mail
outgoing
message queue
Three major
components:
user agents
mail servers
simple mail transfer
protocol: SMTP
User Agent
user mailbox
user
agent
mail
server
user
agent
SMTP
mail
server
user
agent
SMTP
SMTP
mail
server
user
agent
user
agent
user
agent
mailbox contains
incoming messages for
user
message queue of
outgoing (to be sent)
mail messages
SMTP protocol between
mail servers to send
email messages
client: sending
mail server
server:
receiving mail
server
user
agent
mail
server
user
agent
SMTP
mail
server
user
agent
SMTP
SMTP
mail
server
user
agent
user
agent
user
agent
1 user
agent
2
mail
server
3
Alices mail server
mail
server
6
4
5
Bobs mail server
220 hamburger.edu
HELO crepes.fr
250 Hello crepes.fr, pleased to meet you
MAIL FROM: <alice@crepes.fr>
250 alice@crepes.fr... Sender ok
RCPT TO: <bob@hamburger.edu>
250 bob@hamburger.edu ... Recipient ok
DATA
354 Enter mail, end with "." on a line by itself
Do you like ketchup?
How about pickles?
.
250 Message accepted for delivery
QUIT
221 hamburger.edu closing connection
Application Layer 2-53
telnet servername 25
see 220 reply from server
enter HELO, MAIL FROM, RCPT TO, DATA,
QUIT commands
SMTP uses
persistent
connections
SMTP requires
message (header &
body) to be in 7bit ASCII
SMTP server uses
CRLF.CRLF to
determine end of
message
comparison with
HTTP:
HTTP: pull
SMTP: push
header
blank
line
body
commands!
Body: the message
SMTP
SMTP
mail access
protocol
user
agent
(e.g., POP,
IMAP)
senders mail
server
receivers mail
server
POP3 protocol
authorization phase
client commands:
user: declare username
pass: password
server responses
+OK
-ERR
transaction phase,
client:
S:
C:
S:
C:
S:
C:
S:
S:
S:
C:
S:
S:
C:
C:
S:
S:
C:
C:
S:
list
1 498
2 912
.
retr 1
<message 1 contents>
.
dele 1
retr 2
<message 1 contents>
.
dele 2
quit
+OK POP3 server signing off
on
previous example
uses POP3 download
and delete mode
Bob cannot reread e-mail if
he changes
client
POP3 download-andkeep: copies of
messages on
different clients
POP3 is stateless
across sessions
IMAP
Chapter 2: outline
2.1 principles of
network
applications
app
architectures
app requirements
2.6 P2P
applications
2.7 socket
programming
with UDP and
TCP
2.5 DNS
Application Layer 2-60
distributed database
implemented in
hierarchy of many name
servers
application-layer
protocol: hosts, name
servers communicate to
resolve names
(address/name
translation)
note: core Internet
function, implemented
as application-layer
protocol
complexity at networks
edge
Application Layer 2-61
hostname to IP
address translation
host aliasing
canonical, alias
names
mail server
aliasing
load distribution
replicated Web
servers: many IP
addresses
correspond to
one name
A: doesnt scale!
DNS: a distributed,
hierarchical database
Root DNS Servers
e. NASA Mt View, CA
f. Internet Software C.
Palo Alto, CA (and 48 other
sites)
a. Verisign, Los Angeles CA
(5 other sites)
b. USC-ISI Marina del Rey, CA
l. ICANN Los Angeles, CA
(41 other sites)
g. US DoD Columbus,
OH (5 other sites)
13 root name
servers
worldwide
Application Layer 2-64
TLD, authoritative
servers
top-level domain (TLD) servers:
responsible for com, org, net, edu, aero,
jobs, museums, and all top-level country
domains, e.g.: uk, fr, ca, jp
Network Solutions maintains servers
for .com TLD
Educause for .edu TLD
DNS name
resolution
example
host at
cis.poly.edu
wants IP address
for
gaia.cs.umass.ed
iterated
query:
u
contacted server
replies with
name of server
to contact
I dont know
this name, but
ask this server
3
4
5
local DNS server
dns.poly.edu
requesting host
cis.poly.edu
gaia.cs.umass.edu
Application Layer 2-67
DNS name
resolution
example
recursive query:
3
7
puts burden of
name
resolution on
contacted name
server
heavy load at
upper levels
of hierarchy?
TLD DNS
server
local DNS server
dns.poly.edu
requesting host
cis.poly.edu
gaia.cs.umass.edu
Application Layer 2-68
DNS records
DNS: distributed db storing resource records (RR)
RR format:
type=A
name is hostname
type=CNAME
name is alias name for
value is IP address
type=NS
name is domain
(e.g., foo.com)
value is hostname of
authoritative name
server for this
domain
servereast.backup2.ibm.com
value is canonical name
type=MX
value is name of
mailserver associated
with name
Application Layer 2-70
2 bytes
msg header
identification
flags
identification: 16
# questions
# answer RRs
# authority RRs
# additional RRs
additional helpful
nfo that may be used
2 bytes
2 bytes
identification
flags
# questions
# answer RRs
# authority RRs
# additional RRs
Attacking DNS
DDoS attacks
Bombard root
servers with
traffic
Not successful to
date
Traffic Filtering
Local DNS servers
cache IPs of TLD
servers, allowing
root server bypass
Bombard TLD
servers
Potentially more
dangerous
Redirect attacks
Man-in-middle
Intercept queries
DNS poisoning
Send bogus relies
to DNS server,
which caches
Chapter 2: outline
2.1 principles of
network
applications
app
architectures
app requirements
2.6 P2P
applications
2.7 socket
programming
with UDP and
TCP
2.5 DNS
Application Layer 2-75
no always-on server
arbitrary end
systems directly
communicate
peers are
intermittently
connected and change
IP addresses
examples:
file distribution
(BitTorrent)
Streaming (KanKan)
VoIP (Skype)
Application Layer 2-76
server
uN
dN
us
u1
d1
u2
d2
di
ui
ui: peer i upload
capacity
Application Layer 2-77
server transmission:
must sequentially send
(upload) N file copies:
us
NF/us
di
network
ui
download rate
to distribute
F
min time
client
download
time:toF/d
N clients
using Dc-s
min
client-server approach
> max{NF/us,,F/dmin}
increases linearly in N
Application Layer 2-78
server transmission:
must upload at least
one copy
us
copy:
F/us
must
download
file
di
network
ui
copy
min client download
clients:
as aggregate must
time: F/dmin
download
NF bits
max upload rate (limting max download
rate) is u + ui
time to distribute F s
to N clients using DP2P >
P2P approach
max{F/us,,F/dmin,,NF/(us + ui)}
increases linearly in N
but so does this, as each peer brings service capacity
Application Layer 2-79
torrent: group of
peers exchanging
chunks of a file
Alice arrives
obtains list
of peers from tracker
and begins exchanging
file chunks with peers in torrent
Application Layer 2-81
other peers
peer may change peers with whom it
exchanges chunks
churn: peers may come and go
once peer has entire file, it may
(selfishly) leave or (altruistically)
Application Layer 2-82
BitTorrent: requesting,
sending file chunks
requesting chunks:
every 30 secs:
randomly select
another peer,
starts
Application Layer 2-83
BitTorrent: tit-fortat
Hash table
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
address
Hash Table
More convenient to store and
search on numerical
representation of key
key
Original
Key
Value
= Keyhash(original
key)
John Washington
8962458
132-54-3570
761-55-3791
Xiaoming Liu
1567109
385-41-0902
Rakesh Gopal
2360012
441-89-1956
Linda Cohen
5430938
217-66-5609
.
Lisa Kobayashi
9290124
177-23-0199
Circular DHT
60
13
48
25
40
32
overlay network
Resolving a query
1
value
12
60
13
48
O(N) messages
on avgerage to resolve
query, when there 40
are N peers
25
32
e
60
value for
key 53
13
48
25
40
32
Peer churn
1
3
handling peer
churn:
peers may come and go
(churn)
each peer knows
4
address of its two
successors
12
each peer
5
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
15
Peer churn
1
3
handling peer
churn:
peers may come and go
(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
immediate
peer 4 detects peer 5sif
departure;
makes 8
its immediate successor successor leaves,
choose
next successor
4 asks 8 who its immediate
successor
is;
as new its
immediate
makes 8s immediate successor
second
successor
successor.
15
Chapter 2: outline
2.1 principles of
network
applications
app
architectures
app requirements
2.6 P2P
applications
2.7 socket
programming
with UDP and
TCP
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
applicatio
n
process
socket
applicatio
n
process
transport
transport
network
network
link
physical
Internet
link
controlled by
app developer
controlled
by OS
physical
Socket programming
Two socket types for two transport
services:
UDP: unreliable datagram
TCP: reliable, byte stream-oriented
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
Client/server socket
interaction: UDP
server (running
on serverIP)
client
create socket:
clientSocket =
socket(AF_INET,SOCK_DGRAM)
Create datagram with server IP and
port=x; send datagram via
clientSocket
clientSocket = socket(socket.AF_INET,
socket.SOCK_DGRAM)
message = raw_input(Input lowercase sentence:)
clientSocket.sendto(message,(serverName, serverPort))
modifiedMessage, serverAddress =
print modifiedMessage
clientSocket.recvfrom(2048)
clientSocket.close()
Application Layer 2-100
serverSocket.bind(('', serverPort))
print The server is ready to receive
loop forever
Read from UDP socket into
message, getting clients
address (client IP and port)
send upper case string
back to this client
while 1:
message, clientAddress = serverSocket.recvfrom(2048)
modifiedMessage = message.upper()
serverSocket.sendto(modifiedMessage, clientAddress)
Client/server socket
interaction: TCP
server (running
on hostid)
client
create socket,
port=x, for incoming
request:
serverSocket = socket()
wait for incoming
TCP
connection request
connectionSocket = connection
serverSocket.accept()
read request from
connectionSocket
write reply to
connectionSocket
close
connectionSocket
setup
create socket,
connect to hostid, port=x
clientSocket = socket()
send request using
clientSocket
Example
serverPort = 12000
clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket.connect((serverName,serverPort))
sentence = raw_input(Input lowercase sentence:)
clientSocket.send(sentence)
modifiedSentence = clientSocket.recv(1024)
print From Server:, modifiedSentence
clientSocket.close()
Chapter 2:
summary
our study of network
application architectures
client-server
P2P
application service
requirements:
reliability, bandwidth,
delay
Internet transport service
model
connection-oriented,
reliable: TCP
unreliable, datagrams:
UDP
specific
protocols:
HTTP
FTP
SMTP, POP, IMAP
DNS
P2P: BitTorrent,
DHT
socket
programming: TCP,
UDP sockets
Application Layer 2-106
Chapter 2:
summary
most importantly:
protocols!
typical request/reply
message exchange:
client requests info
or service
server responds with
data, status code
message formats:
headers: fields
giving info about
data
data: info being
communicated
learned about
important themes:
control vs. data
msgs
in-band, out-ofband
centralized vs.
decentralized
stateless vs.
stateful
reliable vs.
unreliable msg
transfer Application Layer 2-107
Chapter 1
Additional
Slides
Introduction 1-108
application
(www browser,
packet
analyzer
email client)
application
OS
packet
capture
(pcap)
Transport (TCP/UDP)
copy of all
Ethernet
frames
sent/receive
d
Network (IP)
Link (Ethernet)
Physical