Documente Academic
Documente Profesional
Documente Cultură
Application Layer
al
4th edition.
Jim Kurose, Keith Ross
Addison-Wesley, July
2007.
itn
ep
Computer Networking:
A Top Down Approach,
cs
Were making these slides freely available to all (faculty, students, readers).
Theyre in PowerPoint form so you 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) in substantially unaltered form,
that you mention their source (after all, wed like people to use our book!)
If you post any slides in substantially unaltered form 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.
2: Application Layer
itn
ep
al
2.5 DNS
cs
2: Application Layer
HTTP
FTP
SMTP / POP3 / IMAP
DNS
programming network
applications
socket API
al
itn
ep
cs
Our goals:
conceptual,
implementation
aspects of network
application protocols
transport-layer
service models
client-server
paradigm
peer-to-peer
paradigm
2: Application Layer
al
voice over IP
real-time video
conferencing
grid computing
itn
ep
e-mail
web
instant messaging
remote login
P2P file sharing
multi-user network
games
streaming stored video
clips
cs
2: Application Layer
Network-core devices do
not run user applications
applications on end systems
allows for rapid app
development, propagation
application
transport
network
data link
physical
application
transport
network
data link
physical
al
systems
itn
ep
cs
application
transport
network
data link
physical
2: Application Layer
2.5 DNS
al
itn
ep
cs
2.1 Principles of
network applications
2.2 Web and HTTP
2.3 FTP
2.4 Electronic Mail
2: Application Layer
Application architectures
Client-server
Peer-to-peer (P2P)
cs
itn
ep
al
2: Application Layer
Client-server architecture
server:
always-on host
permanent IP address
server farms for
scaling
clients:
al
itn
ep
cs
client/server
2: Application Layer
no always-on server
itn
ep
cs
al
2: Application Layer
cs
itn
ep
Skype
voice-over-IP P2P application
centralized server: finding address of remote
party:
client-client connection: direct (not through
server)
Instant messaging
chatting between two users is P2P
centralized service: client presence
detection/location
user registers its IP address with central
server when it comes online
user contacts central server to find IP
addresses of buddies
al
2: Application Layer
10
Processes communicating
Client process: process
that initiates
communication
Server process: process
that waits to be
contacted
al
itn
ep
cs
2: Application Layer
11
Sockets
socket
socket
TCP with
buffers,
variables
TCP with
buffers,
variables
Internet
controlled
by OS
cs
process
al
process
controlled by
app developer
itn
ep
process sends/receives
messages to/from its
socket
socket analogous to door
host or
server
host or
server
2: Application Layer
12
Addressing processes
to receive messages,
process must have
identifier
cs
itn
ep
al
2: Application Layer
13
Addressing processes
HTTP server: 80
Mail server: 25
IP address: 128.119.245.12
Port number: 80
al
identifier
more shortly
itn
ep
to receive messages,
process must have
cs
2: Application Layer
14
Message syntax:
Message semantics
meaning of information in
fields
al
Public-domain protocols:
defined in RFCs
allows for
interoperability
e.g., HTTP, SMTP
Proprietary protocols:
e.g., Skype
itn
ep
Types of messages
exchanged,
cs
2: Application Layer
15
itn
ep
al
Throughput
some apps (e.g.,
multimedia) require
minimum amount of
throughput to be
effective
other apps (elastic apps)
make use of whatever
throughput they get
Security
Encryption, data
integrity,
cs
Data loss
some apps (e.g., audio) can
tolerate some loss
other apps (e.g., file
transfer, telnet) require
100% reliable data
transfer
Timing
some apps (e.g.,
Internet telephony,
interactive games)
require low delay to be
effective
2: Application Layer
16
Throughput
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
itn
ep
al
cs
Application
2: Application Layer
17
al
connection-oriented: setup
itn
ep
UDP service:
cs
TCP service:
2: Application Layer
18
TCP
TCP
TCP
TCP
TCP or UDP
typically UDP
al
Internet telephony
itn
ep
e-mail
remote terminal access
Web
file transfer
streaming multimedia
Underlying
transport protocol
cs
Application
Application
layer protocol
2: Application Layer
19
app architectures
app requirements
al
2.5 DNS
itn
ep
cs
2: Application Layer
20
path name
cs
host name
itn
ep
www.someschool.edu/someDept/pic.gif
al
2: Application Layer
21
HTTP overview
st
e
u
q
re
se Server
P
n
T
o
running
HT
esp
r
TP
Apache Web
T
H
server
Mac running
Navigator
al
protocol
client/server model
client: browser that
requests, receives,
displays Web objects
server: Web server
sends objects in
response to requests
equ
est
PC running HT
TP
res
Explorer
pon
se
itn
ep
HT
TP
r
cs
HTTP: hypertext
transfer protocol
2: Application Layer
22
aside
al
server maintains no
itn
ep
HTTP is stateless
cs
Uses TCP:
2: Application Layer
23
HTTP connections
itn
ep
al
Persistent HTTP
Multiple objects can
be sent over single
TCP connection
between client and
server.
cs
Nonpersistent HTTP
At most one object is
sent over a TCP
connection.
2: Application Layer
24
Nonpersistent HTTP
(contains text,
Suppose user enters URL
references to 10
www.someSchool.edu/someDepartment/home.index
jpeg images)
time
al
www.someSchool.edu waiting
for TCP connection at port 80.
accepts connection, notifying
client
itn
ep
cs
2: Application Layer
25
connection.
cs
itn
ep
al
of 10 jpeg objects
2: Application Layer
26
initiate TCP
connection
RTT
request
file
file
received
time
itn
ep
time
al
time to
transmit
file
RTT
cs
2: Application Layer
27
itn
ep
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
cs
al
Persistent HTTP
2: Application Layer
28
request line
(GET, POST,
HEAD commands)
itn
ep
cs
Carriage return,
line feed
indicates end
of message
al
2: Application Layer
29
cs
itn
ep
al
2: Application Layer
30
URL method:
Uses GET method
Input is uploaded in
URL field of request
line:
cs
itn
ep
al
www.somesite.com/animalsearch?monkeys&banana
2: Application Layer
31
Method types
DELETE
al
itn
ep
HTTP/1.1
GET, POST, HEAD
PUT
cs
HTTP/1.0
GET
POST
HEAD
2: Application Layer
32
al
data, e.g.,
requested
HTML file
itn
ep
header
lines
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
cs
status line
(protocol
status code
status phrase)
2: Application Layer
33
itn
ep
cs
al
2: Application Layer
34
cs
itn
ep
al
2: Application Layer
35
cs
itn
ep
al
Example:
Many major Web sites
Susan always access
use cookies
Internet always from PC
Four components:
visits specific e1) cookie header line of
HTTP response message
commerce site for first
2) cookie header line in
time
HTTP request message
when initial HTTP
3) cookie file kept on
users host, managed by
requests arrives at site,
users browser
site creates:
4) back-end database at
unique ID
Web site
entry in backend
database for ID
2: Application Layer
36
cookie file
ebay 8734
amazon 1678
server
usual http request msg
usual http response
Set-cookie: 1678
usual http request msg
cookie: 1678
Amazon server
creates ID
1678 for user create
entry
cookiespecific
action
access
cookie: 1678
cookiespectific
action
itn
ep
cs
ebay 8734
amazon 1678
al
access
backend
database
2: Application Layer
37
Cookies (continued)
itn
ep
al
cs
aside
2: Application Layer
38
origin
server
al
client
origin
server
itn
ep
cs
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
2: Application Layer
39
itn
ep
cs
al
2: Application Layer
40
Caching example
origin
servers
Assumptions
average object size = 100,000
public
Internet
bits
avg. request rate from
institutions browsers to origin
servers = 15/sec
delay from institutional router
to any origin server and back
institutional
to router = 2 sec
network
Consequences
1.5 Mbps
access link
10 Mbps LAN
cs
itn
ep
institutional
cache
al
2: Application Layer
41
possible solution
10 Mbps
access link
institutional
network
10 Mbps LAN
institutional
cache
al
consequence
itn
ep
public
Internet
cs
2: Application Layer
42
consequence
origin
servers
public
Internet
1.5 Mbps
access link
institutional
cache
al
10 Mbps LAN
itn
ep
institutional
network
cs
2: Application Layer
43
Conditional GET
If-modified-since:
<date>
HTTP response
object
not
modified
HTTP/1.0
304 Not Modified
HTTP response
HTTP/1.0 200 OK
<data>
object
modified
al
If-modified-since:
<date>
itn
ep
server
cache
cs
2: Application Layer
44
2.5 DNS
al
itn
ep
cs
2.1 Principles of
network applications
2.2 Web and HTTP
2.3 FTP
2.4 Electronic Mail
2: Application Layer
45
user
at host
FTP
FTP
user
client
interface
file transfer
local file
system
FTP
server
remote file
system
itn
ep
remote)
server: remote host
ftp: RFC 959
ftp server: port 21
al
cs
2: Application Layer
46
cs
itn
ep
al
2: Application Layer
47
Sample commands:
current directory
(gets) file
itn
ep
in HTTP)
331 Username OK,
password required
125 data connection
already open;
transfer starting
425 Cant open data
connection
452 Error writing
file
cs
control channel
USER username
PASS password
al
2: Application Layer
48
itn
ep
al
2.5 DNS
cs
2: Application Layer
49
Electronic Mail
outgoing
message queue
user mailbox
user
agent
SMTP
protocol: SMTP
mail
server
user
agent
SMTP
user
agent
mail
server
user
agent
user
agent
al
User Agent
a.k.a. mail reader
composing, editing, reading
mail messages
e.g., Eudora, Outlook, elm,
Mozilla Thunderbird
outgoing, incoming messages
stored on server
SMTP
user
agent
itn
ep
mail servers
mail
server
cs
user agents
2: Application Layer
50
Mail Servers
user
agent
SMTP
mail
server
SMTP
user
agent
user
agent
user
agent
al
mail
server
SMTP
user
agent
itn
ep
mail
server
cs
2: Application Layer
51
itn
ep
cs
al
to server, port 25
direct transfer: sending server to receiving server
three phases of transfer
handshaking (greeting)
transfer of messages
closure
command/response interaction
commands: ASCII text
response: status code and phrase
2: Application Layer
52
user
agent
mail
server
3
mail
server
4
user
agent
al
itn
ep
cs
2: Application Layer
53
itn
ep
al
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
cs
S:
C:
S:
C:
S:
C:
S:
C:
S:
C:
C:
C:
S:
C:
S:
2: Application Layer
54
cs
itn
ep
al
2: Application Layer
55
command/response
interaction, status codes
al
itn
ep
connections
SMTP requires message
(header & body) to be in 7bit ASCII
SMTP server uses
CRLF.CRLF to determine
end of message
cs
2: Application Layer
56
To:
From:
Subject:
header
blank
line
body
itn
ep
cs
al
body
2: Application Layer
57
type
encoded data
al
multimedia data
type, subtype,
parameter declaration
itn
ep
method used
to encode data
cs
MIME version
From: alice@crepes.fr
To: bob@hamburger.edu
Subject: Picture of yummy crepe.
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Type: image/jpeg
2: Application Layer
58
SMTP
SMTP
senders mail
server
access
protocol
user
agent
receivers mail
server
itn
ep
cs
al
2: Application Layer
59
-ERR
number
dele: delete
quit
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
al
client commands:
itn
ep
authorization phase
S:
C:
S:
C:
S:
cs
POP3 protocol
2: Application Layer
60
itn
ep
al
IMAP
Keep all messages in
one place: the server
Allows user to
organize messages in
folders
IMAP keeps user state
across sessions:
cs
2: Application Layer
61
2.5 DNS
al
itn
ep
cs
2.1 Principles of
network applications
2.2 Web and HTTP
2.3 FTP
2.4 Electronic Mail
2: Application Layer
62
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)
note: core Internet
function, implemented as
application-layer protocol
complexity at networks
edge
al
itn
ep
cs
2: Application Layer
63
DNS
replicated Web
servers: set of IP
addresses for one
canonical name
doesnt scale!
al
itn
ep
cs
DNS services
hostname to IP
address translation
host aliasing
2: Application Layer
64
yahoo.com
amazon.com
DNS servers DNS servers
cs
itn
ep
al
2: Application Layer
65
e NASA Mt View, CA
f Internet Software C. Palo Alto,
cs
itn
ep
al
13 root name
servers worldwide
2: Application Layer
66
cs
itn
ep
al
2: Application Layer
67
itn
ep
al
cs
2: Application Layer
68
DNS name
resolution example
2
Host at cis.poly.edu
wants IP address for
gaia.cs.umass.edu
5
local DNS server
dns.poly.edu
requesting host
al
contacted server
cis.poly.edu
itn
ep
iterated query:
gaia.cs.umass.edu
cs
2: Application Layer
69
DNS name
resolution example
recursive query:
6
TLD DNS server
requesting host
cis.poly.edu
al
itn
ep
gaia.cs.umass.edu
cs
resolution on
contacted name
server
heavy load?
2: Application Layer
70
http://www.ietf.org/html.charters/dnsind-charter.html
itn
ep
al
cs
2: Application Layer
71
DNS records
DNS: distributed db storing resource records (RR)
RR format: (name,
name is hostname
value is IP address
Type=CNAME
Type=NS
Type=MX
al
itn
ep
Type=A
cs
2: Application Layer
72
itn
ep
cs
al
identification: 16 bit #
2: Application Layer
73
cs
itn
ep
al
additional helpful
info that may be used
2: Application Layer
74
cs
itn
ep
al
2: Application Layer
75
app architectures
app requirements
al
2.5 DNS
itn
ep
cs
2: Application Layer
76
no always-on server
File distribution
Searching for information
Case Study: Skype
itn
ep
al
Three topics:
cs
2: Application Layer
77
Server
uN
d2
Network (with
abundant bandwidth)
al
dN
u2
itn
ep
File, size F
d1
cs
us
u1
2: Application Layer
78
sends N copies:
NF/us time
time to download
Server
us
dN
uN
u1 d1 u2
d2
Network (with
abundant bandwidth)
itn
ep
al
Time to distribute F
to N clients using = dcs = max { NF/us, F/min(di) }
i
client/server approach
cs
increases linearly in N
(for large N) 2: Application Layer
79
itn
ep
al
cs
2: Application Layer
80
3
2.5
2
1.5
1
0
0
10
15
20
25
30
itn
ep
al
0.5
35
cs
3.5
2: Application Layer
81
participating in torrent
torrent: group of
peers exchanging
chunks of a file
obtain list
of peers
peer
itn
ep
al
trading
chunks
cs
2: Application Layer
82
itn
ep
cs
al
BitTorrent (1)
2: Application Layer
83
highest rate
al
itn
ep
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
rarest first
cs
BitTorrent (2)
2: Application Layer
84
BitTorrent: Tit-for-tat
cs
itn
ep
al
2: Application Layer
85
cs
itn
ep
al
2: Application Layer
86
IP address
content
1
3
1
2
al
centralized
directory server
Alice
itn
ep
Bob
cs
2: Application Layer
87
itn
ep
al
file transfer is
decentralized, but
locating content is
highly centralized
cs
2: Application Layer
88
no central server
used by Gnutella
Each peer indexes the
files it makes available
for sharing (and no
other files)
itn
ep
fully distributed
cs
al
Query flooding
2: Application Layer
89
Query flooding
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
itn
ep
Qu
er
cs
Scalability:
limited scope
flooding
al
QueryHit
2: Application Layer
90
cs
itn
ep
al
1.
2: Application Layer
91
Hierarchical Overlay
between centralized
index, query flooding
approaches
each peer is either a
super node or assigned to
a super node
group-leader peer
neighoring relationships
in overlay network
al
ordinary peer
itn
ep
cs
2: Application Layer
92
cs
itn
ep
al
Supernode
(SN)
2: Application Layer
93
Peers as relays
Problem when both
Alice and Bob are
behind NATs.
al
Solution:
itn
ep
cs
2: Application Layer
94
itn
ep
al
2.5 DNS
cs
2: Application Layer
95
Socket programming
Goal: learn how to build client/server application that
communicate using sockets
application-created,
OS-controlled interface
al
1981
explicitly created, used,
released by apps
client/server paradigm
two types of transport
service via socket API:
unreliable datagram
reliable, byte streamoriented
a host-local,
itn
ep
socket
cs
Socket API
2: Application Layer
96
host or
server
internet
socket
TCP with
buffers,
variables
host or
server
controlled by
operating
system
al
socket
TCP with
buffers,
variables
itn
ep
controlled by
operating
system
process
process
cs
controlled by
application
developer
controlled by
application
developer
2: Application Layer
97
application viewpoint
al
itn
ep
cs
2: Application Layer
98
Client
create socket,
port=x, for
incoming request:
welcomeSocket =
ServerSocket()
close
connectionSocket
al
write reply to
connectionSocket
itn
ep
setup
create socket,
connect to hostid, port=x
clientSocket =
Socket()
cs
TCP
2: Application Layer
99
Stream jargon
keyboard
monitor
input
stream
to network
itn
ep
client
TCP
clientSocket
socket
al
inFromServer
output
stream
TCP
socket
from network
cs
Client
Process
process
input
stream
outToServer
inFromUser
A stream is a sequence of
2: Application Layer
100
itn
ep
cs
al
2: Application Layer
101
al
Create
output stream
attached to socket
itn
ep
Create
client socket,
connect to server
BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in));
cs
Create
input stream
2: Application Layer
102
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();
al
cs
itn
ep
clientSocket.close();
2: Application Layer
103
al
Create input
stream, attached
to socket
while(true) {
BufferedReader inFromClient =
new BufferedReader(new
InputStreamReader(connectionSocket.getInputStream()));
itn
ep
Wait, on welcoming
socket for contact
by client
cs
Create
welcoming socket
at port 6789
2: Application Layer
104
DataOutputStream outToClient =
new DataOutputStream(connectionSocket.getOutputStream());
Read in line
from socket
clientSentence = inFromClient.readLine();
capitalizedSentence = clientSentence.toUpperCase() + '\n';
outToClient.writeBytes(capitalizedSentence);
}
itn
ep
cs
al
2: Application Layer
105
itn
ep
al
2.5 DNS
cs
2: Application Layer
106
al
itn
ep
application viewpoint
cs
2: Application Layer
107
write reply to
serverSocket
specifying
client address,
port number
al
create socket,
clientSocket =
DatagramSocket()
itn
ep
create socket,
port= x.
serverSocket =
DatagramSocket()
Client
cs
2: Application Layer
108
Client
process
monitor
inFromUser
keyboard
Process
Input: receives
packet (recall
thatTCP received
byte stream)
to network
from network
al
UDP
socket
itn
ep
client
UDP
clientSocket
socket
UDP
packet
cs
UDP
packet
receivePacket
packet (recall
that TCP sent
byte stream)
sendPacket
Output: sends
2: Application Layer
109
al
Translate
hostname to IP
address using DNS
itn
ep
Create
client socket
BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in));
cs
Create
input stream
class UDPClient {
public static void main(String args[]) throws Exception
{
2: Application Layer
110
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);
cs
itn
ep
al
String modifiedSentence =
new String(receivePacket.getData());
2: Application Layer
111
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];
serverSocket.receive(receivePacket);
itn
ep
Receive
datagram
DatagramPacket receivePacket =
new DatagramPacket(receiveData, receiveData.length);
cs
al
while(true)
{
2: Application Layer
112
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);
cs
itn
ep
al
2: Application Layer
113
Chapter 2: Summary
our study of network apps now complete!
application architectures
application service
requirements:
reliability, bandwidth,
delay
HTTP
FTP
SMTP, POP, IMAP
DNS
P2P: BitTorrent, Skype
socket programming
Internet transport
service model
connection-oriented,
reliable: TCP
unreliable, datagrams: UDP
al
client-server
P2P
hybrid
specific protocols:
itn
ep
cs
2: Application Layer
114
Chapter 2: Summary
Most importantly: learned about protocols
message formats:
al
Important themes:
itn
ep
typical request/reply
message exchange:
cs
2: Application Layer
115