Академический Документы
Профессиональный Документы
Культура Документы
Application Layer
Computer Networking:
A Top Down Approach,
4th edition.
Jim Kurose, Keith Ross
Addison-Wesley, July
2007.
2: Application Layer
network applications
2.2 Web and HTTP
2.3 FTP
2.4 Electronic Mail
with TCP
2.8 Socket programming
with UDP
2.5 DNS
2: Application Layer
by examining popular
application-level
protocols
HTTP
FTP
SMTP / POP3 / IMAP
DNS
programming network
applications
socket API
2: Application Layer
voice over IP
web
real-time video
instant messaging
remote login
conferencing
grid computing
multi-user network
games
streaming stored video
clips
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
application
transport
network
data link
physical
2: Application Layer
network applications
2.2 Web and HTTP
2.3 FTP
2.4 Electronic Mail
2.5 DNS
with TCP
2.8 Socket programming
with UDP
2.9 Building a Web
server
2: Application Layer
Application architectures
Client-server
Peer-to-peer (P2P)
Hybrid of client-server and P2P
2: Application Layer
Client-server architecture
server:
always-on host
permanent IP address
server farms for scaling
clients:
client/server
2: Application Layer
Processes communicating
Process: program running
within a host.
within same host, two
processes communicate
using inter-process
communication (defined
by OS).
processes in different
hosts communicate by
exchanging messages
Sockets
process sends/receives
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
API: (1) choice of transport protocol; (2) ability to fix a few parameters (lots more on this
later)
2: Application Layer 1
Addressing processes
to receive messages,
2: Application Layer 1
Addressing processes
to receive messages,
HTTP server: 80
Mail server: 25
to gaia.cs.umass.edu web
server:
IP address: 128.119.245.12
Port number: 80
more shortly
2: Application Layer 1
exchanged,
Message syntax:
what fields in messages &
how fields are delineated
Message semantics
meaning of information in
fields
Public-domain protocols:
defined in RFCs
allows for
interoperability
e.g., HTTP, SMTP
Proprietary protocols:
e.g., Skype
2: Application Layer 1
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,
2: Application Layer 1
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
Application
2: Application Layer 1
connection-oriented: setup
required between client and
server processes
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
guarantees, security
UDP service:
unreliable data transfer
2: Application Layer 1
Application
layer protocol
Underlying
transport protocol
TCP
TCP
TCP
TCP
TCP or UDP
typically UDP
2: Application Layer 1
network applications
app architectures
app requirements
with TCP
2.8 Socket programming
with UDP
2.5 DNS
2: Application Layer 2
path name
2: Application Layer 2
HTTP overview
HTTP: hypertext
transfer protocol
Webs application layer
protocol
client/server model
client: browser that
requests, receives,
displays Web objects
server: Web server
sends objects in
response to requests
HT
TP
r
equ
est
PC running HT
TP
res
Explorer
pon
se
st
e
u
req
se Server
P
n
T
o
p
running
HT
es
r
P
T
Apache Web
HT
server
Mac running
Navigator
2: Application Layer 2
HTTP is stateless
server maintains no
information about
past client requests
aside
2: Application Layer 2
HTTP connections
Nonpersistent HTTP
At most one object is
sent over a TCP
connection.
Persistent HTTP
Multiple objects can
be sent over single
TCP connection
between client and
server.
2: Application Layer 2
Nonpersistent HTTP
(contains text,
Suppose user enters URL www.someSchool.edu/someDepartment/home.index
references to 10
jpeg images)
www.someSchool.edu waiting
for TCP connection at port 80.
accepts connection,
notifying client
time
2: Application Layer 2
connection.
2: Application Layer 2
initiate TCP
connection
RTT
request
file
RTT
file
received
time
time to
transmit
file
time
2: Application Layer 2
Persistent HTTP
Nonpersistent 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
2: Application Layer 2
request, response
Carriage return,
line feed
indicates end
of message
2: Application Layer 2
2: Application Layer 3
URL method:
Uses GET method
Input is uploaded in
URL field of request
line:
www.somesite.com/animalsearch?monkeys&banana
2: Application Layer 3
Method types
HTTP/1.0
GET
POST
HEAD
HTTP/1.1
GET, POST, HEAD
PUT
DELETE
deletes file specified in
the URL field
2: Application Layer 3
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 3
200 OK
2: Application Layer 3
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
access
usual http request msg
cookie: 1678
backend
database
cookiespectific
action
2: Application Layer 3
Cookies (continued)
What cookies can bring:
authorization
shopping carts
recommendations
user session state
(Web e-mail)
aside
origin
server
Proxy
HT
TP
est
u
q
req server
re
H
u
P
e
T
se
T
st
client TP
n
T
o
H
p
res
res
pon
P
se
TT
H
st
e
u
req
P
nse
T
o
p
HT
es
r
TP
T
H
client
origin
server
2: Application Layer 3
2: Application Layer 4
Caching example
origin
servers
Assumptions
average object size = 100,000
bits
avg. request rate from
institutions browsers to origin
servers = 15/sec
delay from institutional router to
any origin server and back to
router = 2 sec
Consequences
utilization on LAN = 15%
utilization on access link = 100%
total delay = Internet delay + access
delay + LAN delay
= 2 sec + minutes + milliseconds
public
Internet
1.5 Mbps
access link
institutional
network
10 Mbps LAN
institutional
cache
2: Application Layer 4
possible solution
increase bandwidth of access
consequence
public
Internet
10 Mbps
access link
institutional
network
10 Mbps LAN
institutional
cache
2: Application Layer 4
origin
servers
public
Internet
consequence
1.5 Mbps
access link
institutional
network
10 Mbps LAN
institutional
cache
2: Application Layer 4
Conditional GET
Goal: dont send object if
server
cache
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 4
network applications
2.2 Web and HTTP
2.3 FTP
2.4 Electronic Mail
2.5 DNS
with TCP
2.8 Socket programming
with UDP
2.9 Building a Web
server
2: Application Layer 4
user
at host
FTP
FTP
user
client
interface
file transfer
local file
system
FTP
server
remote file
system
2: Application Layer 4
2: Application Layer 4
control channel
USER username
PASS password
current directory
(gets) file
in HTTP)
331 Username OK,
password required
125 data connection
already open;
transfer starting
425 Cant open data
connection
452 Error writing
file
2: Application Layer 4
network applications
2.2 Web and HTTP
2.3 FTP
2.4 Electronic Mail
with TCP
2.8 Socket programming
with UDP
2.5 DNS
2: Application Layer 4
Electronic Mail
outgoing
message queue
user mailbox
user
agent
mail
server
SMTP
SMTP
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
mail
server
user
agent
SMTP
user
agent
mail
server
user
agent
user
agent
user
agent
2: Application Layer 5
Mail Servers
mailbox contains incoming
mail
server
SMTP
SMTP
mail
server
user
agent
SMTP
user
agent
mail
server
user
agent
user
agent
user
agent
2: Application Layer 5
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 5
1
user
agent
mail
server
3
mail
server
4
user
agent
2: Application Layer 5
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
2: Application Layer 5
commands
above lets you send email without using email client
(reader)
2: Application Layer 5
connections
SMTP requires message
(header & body) to be in 7bit ASCII
SMTP server uses
CRLF.CRLF to determine
end of message
command/response
interaction, status codes
2: Application Layer 5
header
blank
line
body
body
2: Application Layer 5
type
MIME version
method used
to encode data
multimedia data
type, subtype,
parameter declaration
encoded data
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
base64 encoded data .....
.........................
......base64 encoded data
2: Application Layer 5
SMTP
SMTP
senders mail
server
access
protocol
user
agent
receivers mail
server
2: Application Layer 5
POP3 protocol
authorization phase
client commands:
number
dele: delete
quit
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
2: Application Layer 6
on
IMAP
Keep all messages in
one place: the server
Allows user to
organize messages in
folders
IMAP keeps user state
across sessions:
2: Application Layer 6
network applications
2.2 Web and HTTP
2.3 FTP
2.4 Electronic Mail
2.5 DNS
with TCP
2.8 Socket programming
with UDP
2.9 Building a Web
server
2: Application Layer 6
Q: map between IP
addresses and name ?
2: Application Layer 6
DNS
DNS services
hostname to IP
address translation
host aliasing
2: Application Layer 6
e NASA Mt View, CA
f Internet Software C. Palo Alto,
13 root name
servers worldwide
2: Application Layer 6
2: Application Layer 6
2: Application Layer 6
DNS name
resolution example
Host at cis.poly.edu
iterated query:
contacted server
3
4
5
local DNS server
dns.poly.edu
requesting host
cis.poly.edu
gaia.cs.umass.edu
2: Application Layer 6
DNS name
resolution example
recursive query:
resolution on
contacted name
server
heavy load?
3
7
6
TLD DNS server
requesting host
cis.poly.edu
gaia.cs.umass.edu
2: Application Layer 7
caches
mapping
cache entries timeout (disappear) after some
time
TLD servers typically cached in local name
servers
Thus root name servers not often visited
http://www.ietf.org/html.charters/dnsind-charter.html
2: Application Layer 7
DNS records
DNS: distributed db storing resource records (RR)
RR format:
Type=A
name is hostname
value is IP address
Type=CNAME
name is alias name for some
canonical (the real) name
www.ibm.com is really
Type=NS
servereast.backup2.ibm.com
name is domain (e.g. foo.com)
value is canonical name
value is hostname of
authoritative name server
Type=MX
for this domain
2: Application Layer 7
msg header
identification: 16 bit #
2: Application Layer 7
2: Application Layer 7
registrar
network applications
app architectures
app requirements
with TCP
2.8 Socket programming
with UDP
2.5 DNS
2: Application Layer 7
Three topics:
File distribution
Searching for information
Case Study: Skype
2: Application Layer 7
us
File, size F
dN
uN
u1
d1
u2
d2
Network (with
abundant bandwidth)
2: Application Layer 7
sends N copies:
NF/us time
time to download
Server
us
dN
uN
u1 d1 u2
d2
Network (with
abundant bandwidth)
Time to distribute F
to N clients using = dcs = max { NF/us, F/min(d
i) }
i
client/server approach
increases linearly in N
(for large
N)
2: Application
Layer 7
Server
us
dN
to download
uN
NF bits must be
downloaded (aggregate)
fastest possible upload rate: us +
u1 d1 u2
Network (with
abundant bandwidth)
ui
d2
ui) }
2: Application Layer 8
2: Application Layer 8
torrent: group of
peers exchanging
chunks of a file
obtain list
of peers
trading
chunks
peer
2: Application Layer 8
BitTorrent (1)
file divided into 256KB
chunks.
2: Application Layer 8
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
rarest first
2: Application Layer 8
BitTorrent: Tit-for-tat
(1) Alice optimistically unchokes Bob
(2) Alice becomes one of Bobs top-four providers; Bob reciprocates
(3) Bob becomes one of Alices top-four providers
2: Application Layer 8
Bob
centralized
directory server
1
peers
1
IP address
content
1
2
Alice
2: Application Layer 8
target of lawsuit is
obvious
file transfer is
decentralized, but
locating content is
highly centralized
2: Application Layer 8
Query flooding
fully distributed
no central server
used by Gnutella
Query flooding
Query message
File transfer:
HTTP
Query
QueryHit
Qu
ery
QueryHit
Scalability:
limited scope
flooding
Qu
er
y
2: Application Layer 9
2: Application Layer 9
Hierarchical Overlay
between centralized
in its children
o rd in a ry p e e r
g r o u p - le a d e r p e e r
n e ig h o r in g r e la tio n s h ip s
in o v e r la y n e tw o r k
2: Application Layer 9
of users communicate.
proprietary
Skype
application-layer
login server
protocol (inferred via
reverse engineering)
hierarchical overlay
with SNs
Index maps usernames
to IP addresses;
distributed over SNs
Supernode
(SN)
2: Application Layer 9
Peers as relays
Problem when both
Solution:
Using Alices and Bobs
SNs, Relay is chosen
Each peer initiates
session with relay.
Peers can now
communicate through
NATs via relay
2: Application Layer 9
network applications
2.2 Web and HTTP
2.3 FTP
2.4 Electronic Mail
with TCP
2.8 Socket programming
with UDP
2.5 DNS
2: Application Layer 9
Socket programming
Goal: learn how to build client/server application that
communicate using sockets
Socket API
introduced in BSD4.1 UNIX,
1981
explicitly created, used,
released by apps
client/server paradigm
two types of transport service
via socket API:
unreliable datagram
reliable, byte streamoriented
socket
a host-local,
application-created,
OS-controlled interface
(a door) into which
application process can
both send and
receive messages to/from
another application
process
2: Application Layer 9
controlled by
application
developer
controlled by
operating
system
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 9
application viewpoint
2: Application Layer 9
Client
(running on hostid)
create socket,
port=x, for
incoming request:
welcomeSocket =
ServerSocket()
TCP
setup
create socket,
connect to hostid, port=x
clientSocket =
Socket()
send request using
clientSocket
2: Application Layer 9
Stream jargon
keyboard
monitor
Client
Process
process
output
stream
inFromServer
input
stream
outToServer
inFromUser
A stream is a sequence of
input
stream
client
TCP
clientSocket
socket
to network
TCP
socket
from network
2: Application Layer 1
2: Application Layer 1
BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in));
Socket clientSocket = new Socket("hostname", 6789);
DataOutputStream outToServer =
new DataOutputStream(clientSocket.getOutputStream());
2: Application Layer 1
BufferedReader inFromServer =
new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));
sentence = inFromUser.readLine();
Send line
to server
outToServer.writeBytes(sentence + '\n');
modifiedSentence = inFromServer.readLine();
Read line
from server
2: Application Layer 1
Create
welcoming socket
at port 6789
Wait, on welcoming
socket for contact
by client
Create input
stream, attached
to socket
2: Application Layer 1
DataOutputStream outToClient =
new DataOutputStream(connectionSocket.getOutputStream());
Read in line
from socket
clientSentence = inFromClient.readLine();
capitalizedSentence = clientSentence.toUpperCase() + '\n';
outToClient.writeBytes(capitalizedSentence);
}
}
2: Application Layer 1
network applications
2.2 Web and HTTP
2.3 FTP
2.4 Electronic Mail
with TCP
2.8 Socket programming
with UDP
2.5 DNS
2: Application Layer 1
application viewpoint
2: Application Layer 1
(running on hostid)
create socket,
port= x.
serverSocket =
DatagramSocket()
Client
create socket,
clientSocket =
DatagramSocket()
Create datagram with server IP and
port=x; send datagram via
clientSocket
2: Application Layer 1
Client
Process
monitor
inFromUser
keyboard
Input: receives
process
packet (recall
thatTCP received
byte stream)
UDP
packet
receivePacket
packet (recall
that TCP sent
byte stream)
sendPacket
Output: sends
client
UDP
clientSocket
socket
to network
UDP
packet
UDP
socket
from network
2: Application Layer 1
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 1
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 1
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 1
Get IP addr
port #, of
sender
Create datagram
to send to client
Write out
datagram
to socket
}
DatagramPacket sendPacket =
new DatagramPacket(sendData, sendData.length, IPAddress,
port);
serverSocket.send(sendPacket);
}
}
2: Application Layer 1
Chapter 2: Summary
our study of network apps now complete!
application architectures
client-server
P2P
hybrid
application service
requirements:
model
specific protocols:
HTTP
FTP
SMTP, POP, IMAP
DNS
P2P: BitTorrent, Skype
socket programming
2: Application Layer 1
Chapter 2: Summary
Most importantly: learned about protocols
typical request/reply
message exchange:
message formats:
headers: fields giving info
about data
data: info being
communicated
Important themes:
control vs. data msgs
in-band, out-of-band
centralized vs.
decentralized
stateless vs. stateful
reliable vs. unreliable msg
transfer
complexity at network
edge
2: Application Layer 1