Chapter 2 - Application
Chapter 2 - Application
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
remote login
conferencing
grid computing
multi-user network
instant messaging
games
streaming stored video
clips
2: Application Layer
systems
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
no always-on server
2: Application Layer
10
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
11
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
2: Application Layer
12
Addressing processes
to receive messages,
identifier
32-bit IP address
Q: does IP address of
host on which process
runs suffice for
identifying the process?
2: Application Layer
13
Addressing processes
to receive messages,
identifier
32-bit IP address
Q: does IP address of
host on which process
runs suffice for
identifying the
process?
A: No, many
processes can be
running on same host
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
14
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
15
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
Throughput
2: Application Layer
16
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
17
connection-oriented: setup
UDP service:
unreliable data transfer
2: Application Layer
18
Internet telephony
Application
layer protocol
Underlying
transport protocol
TCP
TCP
TCP
TCP
TCP or UDP
typically UDP
2: Application Layer
19
network applications
app architectures
app requirements
with TCP
2.8 Socket programming
with UDP
2.5 DNS
2: Application Layer
20
path name
2: Application Layer
21
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
HTTP 1.0: RFC 1945
HTTP 1.1: RFC 2068
PC running
Explorer
Server
running
Apache Web
server
Mac running
Navigator
2: Application Layer
22
HTTP is stateless
server maintains no
information about
past client requests
aside
23
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
24
Nonpersistent HTTP
(contains text,
Suppose user enters URL
references to 10
www.someSchool.edu/someDepartment/home.index
jpeg images)
www.someSchool.edu waiting
for TCP connection at port 80.
accepts connection, notifying
client
time
2: Application Layer
25
connection.
2: Application Layer
26
initiate TCP
connection
RTT
request
file
RTT
file
received
time
time to
transmit
file
time
2: Application Layer
27
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
2: Application Layer
28
request, response
Carriage return,
line feed
indicates end
of message
2: Application Layer
29
2: Application Layer
30
URL method:
Uses GET method
Input is uploaded in
URL field of request
line:
www.somesite.com/animalsearch?monkeys&banana
2: Application Layer
31
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
32
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
33
34
35
Ethereal example
2: Application Layer
36
2: Application Layer
37
cookie file
ebay 8734
amazon 1678
server
usual http request msg
Set-cookie: 1678
usual http request msg
cookie: 1678
cookie: 1678
Amazon server
creates ID
1678 for user create
entry
cookiespecific
action
access
access
backend
database
cookiespectific
action
2: Application Layer
38
origin
server
client
client
Proxy
server
origin
server
2: Application Layer
39
40
Caching example
origin
servers
Assumptions
average object size = 1 M bits
Consequences
utilization on LAN = 15%
public
Internet
1.5 Mbps
access link
institutional
network
10 Mbps LAN
total delay
= Internet delay +
access delay + LAN delay
= 2 sec + minutes + milliseconds
institutional
cache
2: Application Layer
41
crude calculation
Traffic intensity on the LAN=
(15 requests/sec) (1 Mbits/request)/(100 Mbps) = 0.15
Traffic on the access link ( between two routers =
(15 requests/sec) (1 Mbits/request)/(15 Mbps) = 1
A traffic intensity of 0.15 on a LAN typically results in a delay
of almost tens of milliseconds and
a delay on becomes very large and grows without bound since
traffic intensity is 1
One possible solution is to replace access link 100 Mbps to reduce
intensity to 0.15 and it will bring delay to tens of milliseconds
but is costly
Another possible solution is discussed on next transparency
2: Application Layer
42
possible solution
increase bandwidth of access
consequence
public
Internet
= Internet delay +
access delay + LAN delay
= 2 sec + msecs + msecs
often a costly upgrade
10 Mbps
access link
Total delay
institutional
network
10 Mbps LAN
institutional
cache
2: Application Layer
43
consequence
origin
servers
public
Internet
1.5 Mbps
access link
institutional
network
10 Mbps LAN
institutional
cache
2: Application Layer
44
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
45
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
46
user
at host
FTP
FTP
user
client
interface
file transfer
local file
system
FTP
server
remote file
system
remote)
server: remote host
ftp: RFC 959
ftp server: port 21
2: Application Layer
47
48
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
49
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
50
Electronic Mail
outgoing
message queue
user mailbox
user
agent
mail
server
SMTP
protocol: SMTP
User Agent
Sometimes called as mail
reader
composing, editing, reading
mail messages
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
51
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
52
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
53
1
user
agent
mail
server
3
mail
server
4
user
agent
2: Application Layer
54
220 hamburger.edu
HELO crepes.fr
250 Hello crepes.fr, pleased to meet you
MAIL FROM: <[email protected]>
250 [email protected]... Sender ok
RCPT TO: <[email protected]>
250 [email protected] ... 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
55
commands
above lets you send email without using email client
(reader)
2: Application Layer
56
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
57
To:
From:
Subject:
header
blank
line
body
58
type
MIME version
method used
to encode data
multimedia data
type, subtype,
parameter declaration
encoded data
From: [email protected]
To: [email protected]
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
59
SMTP
SMTP
senders mail
server
access
protocol
user
agent
receivers mail
server
60
POP3
IMAP
2: Application Layer
61
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
on
62
IMAP
Keep all messages in
one place: the server
Allows user to
organize messages in
folders
IMAP keeps user state
across sessions:
63
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
64
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
2: Application Layer
65
DNS
DNS services
hostname to IP
address translation
host aliasing
load distribution
replicated Web
servers: set of IP
addresses for one
canonical name
2: Application Layer
66
pbs.org
DNS servers
67
e NASA Mt View, CA
f Internet Software C. Palo Alto,
13 root name
servers worldwide
b USC-ISI Marina del Rey, CA
l ICANN Los Angeles, CA
2: Application Layer
68
2: Application Layer
69
2: Application Layer
70
DNS name
resolution example
Host at cis.poly.edu
iterated query:
contacted server
5
local DNS server
dns.poly.edu
requesting host
cis.poly.edu
gaia.cs.umass.edu
2: Application Layer
71
DNS name
resolution example
recursive query:
resolution on
contacted name
server
heavy load?
3
7
requesting host
cis.poly.edu
gaia.cs.umass.edu
2: Application Layer
72
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
73
DNS records
DNS: distributed db storing resource records (RR)
RR format: (name,
Type=A
name is hostname
value is IP address
Type=NS
name is domain (e.g.
foo.com)
value is hostname of
authoritative name
server for this domain
Type=CNAME
name is alias name for some
canonical (the real) name
www.ibm.com is really
servereast.backup2.ibm.com
Type=MX
value is name of mailserver
associated with name
2: Application Layer
74
msg header
identification: 16 bit #
2: Application Layer
75
2: Application Layer
76
registrar
77
network applications
app architectures
app requirements
with TCP
2.8 Socket programming
with UDP
2.9 Building a Web
server
2: Application Layer
78
79
Bob
centralized
directory server
peers
IP address
content
1
3
1
2
Alice
2: Application Layer
80
target of lawsuit is
obvious
file transfer is
decentralized, but
locating content is
highly centralized
2: Application Layer
81
implementing protocol
82
Gnutella: protocol
Query message
File transfer:
HTTP
Query
QueryHit
QueryHit
Scalability:
limited scope
flooding
2: Application Layer
83
2: Application Layer
84
Hierarchical Overlay
between centralized
ordinary peer
group-leader peer
neighoring relationships
in overlay network
2: Application Layer
85
Server
us
File, size F
dN
uN
u1
d1
u2
ui: client/peer i
upload bandwidth
d2
di: client/peer i
download bandwidth
Network (with
abundant bandwidth)
2: Application Layer
86
sends N copies:
NF/us time
time to download
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
87
Server
u1 d1 u2
d2
copy: F/us time
us
client i takes F/di time
Network (with
dN
to download
abundant bandwidth)
uN
NF bits must be
downloaded (aggregate)
fastest possible upload rate (assuming
all nodes sending file chunks to same
peer): us + Sui
i=1,N
i=1,N
2: Application Layer
88
3.5
P2P
Client-Server
3
2.5
2
1.5
1
0.5
0
0
10
15
20
25
30
35
2: Application Layer
89
participating in torrent
torrent: group of
peers exchanging
chunks of a file
obtain list
of peers
trading
chunks
peer
2: Application Layer
90
BitTorrent (1)
file divided into 256KB
chunks.
2: Application Layer
91
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 issues requests
for her missing chunks
rarest first
highest rate
re-evaluate top 4
every 10 secs
every 30 secs: randomly
select another peer,
starts sending chunks
newly chosen peer may
join top 4
2: Application Layer
92
phone, phone-to-pc)
Voice-Over-IP (VoIP)
Skype
application
login server
also IM
proprietary
application-layer
protocol (inferred via
reverse engineering)
hierarchical overlay
Supernode
(SN)
2: Application Layer
93
SC registers with SN
list of bootstrap SNs
SC logs in
Skype
login server
(authenticate)
callee ID
94
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
95
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
2: Application Layer
96
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
97
application viewpoint
98
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
99
Stream jargon
keyboard
monitor
output
stream
inFromServer
Client
Process
process
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
100
101
BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in));
Socket clientSocket = new Socket("hostname", 6789);
DataOutputStream outToServer =
new DataOutputStream(clientSocket.getOutputStream());
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();
System.out.println("FROM SERVER: " + modifiedSentence);
clientSocket.close();
}
}
2: Application Layer
103
Create
welcoming socket
at port 6789
Wait, on welcoming
socket for contact
by client
Create input
stream, attached
to socket
104
DataOutputStream outToClient =
new DataOutputStream(connectionSocket.getOutputStream());
Read in line
from socket
clientSentence = inFromClient.readLine();
outToClient.writeBytes(capitalizedSentence);
}
}
2: Application Layer
105
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
106
application viewpoint
2: Application Layer
107
Client
create socket,
clientSocket =
DatagramSocket()
Create, address (hostid, port=x,
send datagram request
using clientSocket
2: Application Layer
108
Client
process
monitor
inFromUser
keyboard
Process
Input: receives
packet (recall
thatTCP received
byte stream)
UDP
packet
receivePacket
packet (recall
that TCP sent
byte stream)
sendPacket
Output: sends
UDP
packet
client
UDP
clientSocket
socket
to network
UDP
socket
from network
2: Application Layer
109
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
110
DatagramPacket sendPacket =
new DatagramPacket(sendData, sendData.length, IPAddress, 9876);
Send datagram
to server
clientSocket.send(sendPacket);
Read datagram
from server
clientSocket.receive(receivePacket);
DatagramPacket receivePacket =
new DatagramPacket(receiveData, receiveData.length);
String modifiedSentence =
new String(receivePacket.getData());
System.out.println("FROM SERVER:" + modifiedSentence);
clientSocket.close();
}
}
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);
Receive
datagram
DatagramPacket receivePacket =
new DatagramPacket(receiveData, receiveData.length);
serverSocket.receive(receivePacket);
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);
}
}
2: Application Layer
113
Chapter 2: Summary
our study of network apps now complete!
application architectures
client-server
P2P
hybrid
application service
requirements:
reliability, bandwidth,
delay
specific protocols:
HTTP
FTP
SMTP, POP, IMAP
DNS
P2P: BitTorrent, Skype
socket programming
Internet transport
service model
connection-oriented,
reliable: TCP
unreliable, datagrams: UDP
2: Application Layer
114
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
115