Академический Документы
Профессиональный Документы
Культура Документы
Application Layer
Computer Networking:
A Top Down Approach,
5th edition.
Jim Kurose, Keith Ross
Addison-Wesley, April
2009.
2.5 DNS
Application 2-2
HTTP
FTP
SMTP / POP3 / IMAP
DNS
programming network
applications
socket API
Application 2-3
e-mail
web
instant messaging
remote login
P2P file sharing
multi-user network
games
streaming stored video
(YouTube)
voice over IP
real-time video
conferencing
cloud computing
Application 2-4
application
transport
network
data link
physical
application
transport
network
data link
physical
application
transport
network
data link
physical
Application 2-5
2.5 DNS
Application 2-6
Application architectures
client-server
peer-to-peer (P2P)
hybrid of client-server and P2P
Application 2-7
Client-server architecture
server:
always-on host
permanent IP address
server farms for scaling
clients:
client/server
Application 2-8
no always-on server
arbitrary end systems
directly communicate peer-peer
peers are intermittently
connected and change IP
addresses
Application 2-9
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
Application 2-11
Sockets
process sends/receives
messages to/from its
socket
socket analogous to door
sending process shoves
message out door
sending process relies on
transport infrastructure
on other side of door which
brings message to socket
at receiving process
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)
Application 2-12
Addressing processes
to receive messages,
process must have
identifier
host device has unique
32-bit IP address
Q: does IP address of
host on which process
runs suffice for
identifying the process?
Application 2-13
Addressing processes
to receive messages,
process must have
identifier
host device has unique
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
more shortly
Application 2-14
types of messages
exchanged,
e.g., request, response
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
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,
Application 2-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
Application
Application 2-17
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:
Application 2-18
Application
layer protocol
Underlying
transport protocol
TCP
TCP
TCP
TCP
TCP or UDP
typically UDP
Application 2-19
2.5 DNS
Application 2-20
path name
Application 2-21
HTTP overview
HTTP: hypertext
transfer protocol
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
Application 2-22
HTTP is stateless
server maintains no
information about
past client requests
aside
HTTP connections
non-persistent HTTP
at most one object
sent over TCP
connection.
persistent HTTP
multiple objects can
be sent over single
TCP connection
between client, server.
Application 2-24
Nonpersistent HTTP
suppose user enters URL:
(contains text,
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
Application 2-25
connection.
Application 2-26
initiate TCP
connection
RTT
request
file
RTT
file
received
time
time to
transmit
file
time
Application 2-27
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 2-28
request line
(GET, POST,
HEAD commands)
header
lines
carriage return,
line feed at start
of line indicates
end of header lines
Application 2-29
body
Application 2-30
input is uploaded to
server in entity body
URL method:
uses GET method
input is uploaded in
URL field of request
line: www.somesite.com/animalsearch?monkeys&banana
Application 2-31
Method types
HTTP/1.0
GET
POST
HEAD
asks server to leave
requested object out of
response
HTTP/1.1
GET, POST, HEAD
PUT
uploads file in entity
body to path specified
in URL field
DELETE
deletes file specified in
the URL field
Application 2-32
header
lines
data, e.g.,
requested
HTML file
Application 2-33
200 OK
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
cookiespecific
action
Application 2-37
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
Application 2-39
Caching example
origin
servers
assumptions
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
Application 2-41
origin
servers
public
Internet
10 Mbps
access link
institutional
network
10 Mbps LAN
institutional
cache
Application 2-42
possible solution:
install cache
consequence
public
Internet
1.5 Mbps
access link
institutional
network
10 Mbps LAN
institutional
cache
Application 2-43
Conditional GET
server
cache
HTTP request msg
If-modified-since: <date>
HTTP response
HTTP/1.0
304 Not Modified
object
not
modified
before
<date>
HTTP response
HTTP/1.0 200 OK
<data>
object
modified
after
<date>
Application 2-44
2.5 DNS
Application 2-45
user
at host
FTP
FTP
user
client
interface
local file
system
file transfer
FTP
server
remote file
system
FTP
client
FTP
server
Application 2-48
2.5 DNS
Application 2-49
Electronic Mail
outgoing
message queue
user mailbox
user agents
mail servers
simple mail transfer protocol:
SMTP
User Agent
a.k.a. mail reader
composing, editing, reading
mail messages
e.g., Outlook, elm, Mozilla
Thunderbird, iPhone mail client
outgoing, incoming messages
stored on server
user
agent
mail
server
SMTP
SMTP
mail
server
user
agent
SMTP
user
agent
mail
server
user
agent
user
agent
user
agent
Application 2-50
Mail Servers
mail
server
SMTP
SMTP
mail
server
user
agent
SMTP
user
agent
mail
server
user
agent
user
agent
user
agent
Application 2-51
Application 2-52
1
user
agent
mail
server
3
mail
server
4
user
agent
Application 2-53
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 2-54
Application 2-55
HTTP: pull
SMTP: push
Application 2-56
header
blank
line
body
body
the message, ASCII
characters only
Application 2-57
SMTP
SMTP
senders mail
server
access
protocol
user
agent
receivers mail
server
Application 2-58
POP3 protocol
authorization phase
client commands:
user: declare username
pass: password
server responses
+OK
-ERR
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
Application 2-59
IMAP
keeps all messages in
one place: at server
allows user to organize
messages in folders
keeps user state
across sessions:
names of folders and
mappings between
message IDs and folder
name
Application 2-60
2.1 Principles of
network applications
2.2 Web and HTTP
2.3 FTP
2.4 Electronic Mail
2.5 DNS
Application 2-61
Q: map between IP
address and name, and
vice versa ?
distributed database
implemented in hierarchy of
many name servers
application-layer protocol
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
Application 2-62
2: Application Layer
63
DNS
DNS services
hostname to IP
address translation
host aliasing
Canonical, alias names
Application 2-64
Application 2-65
2: Application Layer
66
2: Application Layer
67
2: Application Layer
68
2: Application Layer
69
e NASA Mt View, CA
f Internet Software C. Palo Alto, CA (and 36
28 other locations)
other locations)
13 root name
servers worldwide
Application 2-70
Application 2-73
2: Application Layer
74
DNS name
resolution example
host at cis.poly.edu
wants IP address for
gaia.cs.umass.edu
iterated query:
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 2-75
DNS name
resolution example
recursive query:
3
6
TLD DNS server
requesting host
cis.poly.edu
gaia.cs.umass.edu
Application 2-76
Application 2-77
DNS records
DNS: distributed db storing resource records (RR)
RR format:
Type=A
name is hostname
value is IP address
Type=NS
Type=CNAME
name is alias name for some
canonical (the real) name
www.ibm.com is really
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
Application 2-78
msg header
identification: 16 bit #
for query, reply to query
uses same #
flags:
query or reply
recursion desired
recursion available
reply is authoritative
Application 2-79
Application 2-80
2.5 DNS
Application 2-82
no always-on server
arbitrary end systems
directly communicate
peers are intermittently peer-peer
connected and change IP
addresses
Three topics:
file distribution
searching for information
case Study: Skype
Application 2-83
us
File, size F
dN
uN
u1
d1
u2
d2
Network (with
abundant bandwidth)
Application 2-84
server sequentially
sends N copies:
NF/us time
client i takes F/di 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)
Application 2-85
Server
us
u1 d1 u2
Network (with
abundant bandwidth)
ui
d2
ui) }
Application 2-86
Application 2-87
torrent: group of
peers exchanging
chunks of a file
obtain list
of peers
trading
chunks
peer
Application 2-88
BitTorrent (1)
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
Application 2-90
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
Application 2-92
DHT Identifiers
Application 2-93
central issue:
assigning (key, value) pairs to peers.
Application 2-94
15
4
12
5
10
Application 2-95
0001
I am
Whos resp
0011
1111
1110
0100
1110
1110
1100
1110
Define closest
as closest
successor
1010
1110
0101
1110
1000
Application 2-96
15
Whos resp
for key 1110?
4
12
5
10
Peer Churn
1
15
4
12
5
10
Supernode
(SN)
Application 2-99
Peers as relays
solution:
Application 2-100
2.5 DNS
Application 2-101
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
(a door) into which
application process can
both send and
receive messages to/from
another application
process
Application 2-102
controlled by
application
developer
controlled by
operating
system
process
process
socket
TCP with
buffers,
variables
socket
TCP with
buffers,
variables
host or
server
internet
controlled by
application
developer
controlled by
operating
system
host or
server
Application 2-103
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
input
stream
Client
Process
process
output
stream
monitor
inFromUser
stream is a sequence of
characters that flow into
or out of a process.
input stream is attached to
some input source for the
process, e.g., keyboard or
socket.
output stream is attached
to an output source, e.g.,
monitor or socket.
outToServer
keyboard
inFromServer
Stream jargon
input
stream
client
TCP
clientSocket
socket
to network
TCP
socket
from network
Application 2-106
Application 2-107
create
input stream
create
clientSocket object
of type Socket,
connect to server
create
output stream
attached to socket
Application 2-108
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);
close socket
clientSocket.close();
}
}
Application 2-109
create
welcoming socket
at port 6789
wait, on welcoming
socket accept() method
for client contact create,
new socket on return
create input
stream, attached
to socket
Application 2-110
DataOutputStream outToClient =
new DataOutputStream(connectionSocket.getOutputStream());
read in line
from socket
clientSentence = inFromClient.readLine();
capitalizedSentence = clientSentence.toUpperCase() + '\n';
outToClient.writeBytes(capitalizedSentence);
}
}
Application 2-111
2.5 DNS
Application 2-112
application viewpoint:
Application 2-113
(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
Application 2-114
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
Application 2-115
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();
Application 2-116
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();
}
}
Application 2-117
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);
Application 2-118
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);
}
}
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
Application 2-120
Chapter 2: Summary
most importantly: learned about 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
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
Application 2-121