Professional Documents
Culture Documents
Chapter2 Redes de Computadoras
Chapter2 Redes de Computadoras
Chapter2 Redes de Computadoras
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
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
Addressing processes
to receive messages,
process must have
identifier
host device has unique 32bit 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
req
ues
PC running HT
t
TP
r
Explorer
esp
ons
e
t
es
u
req
e Server
P
ns
T
o
T
p
H
running
es
r
P
Apache Web
T
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)
tim
e
Application 2-25
tim
e
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,
GET /index.html HTTP/1.1\r\n
HEAD commands) Host: www-net.cs.umass.edu\r\n
User-Agent: Firefox/3.6.10\r\n
Accept: text/html,application/xhtml+xml\r\n
headerAccept-Language: en-us,en;q=0.5\r\n
linesAccept-Encoding: gzip,deflate\r\n
Accept-Charset: ISO-8859-1,utf-8;q=0.7\r\n
Keep-Alive: 115\r\n
carriage return,
Connection: keep-alive\r\n
line feed at start
\r\n
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
response message.
some sample codes:
200 OK
request succeeded, requested object later in this msg
example:
Susan always access
Internet from PC
visits specific ecommerce site for first
time
when initial HTTP
requests arrives at site,
site creates:
unique ID
entry in backend
database for ID
Application 2-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
access
ebay 8734
amazon 1678
cookie: 1678
backend
database
cookiespecific
action
Application 2-37
Cookies (continued)
aside
origin
server
Proxy
HT
TP
est
u
server
q
req
re
H
u
P
e
T
se
T
st
client TP
n
T
o
H
res
esp
r
pon
se
TTP
H
t
es
u
req
e
P
ns
T
o
T
p
H
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
FTP
client
local file
system
file transfer
FTP
server
remote file
system
Application 2-46
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
user
agent
SMT
P
SMT
P
mail
server
SMT
P
mail
server
user
agent
user
agent
user
agent
user
agent
Application 2-50
Mail Servers
mail
server
user
agent
SMT
P
SMT
P
mail
server
SMT
P
mail
server
user
agent
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
SMT
P
senders mail
server
SMT
P
access
protocol
user
agent
receivers mail
server
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 applicationlayer protocol
complexity at networks
edge
Application 2-62
DNS
DNS services
hostname to IP address
translation
host aliasing
Canonical, alias names
Application 2-63
Application 2-64
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
Application 2-65
Application 2-67
DNS name
resolution example
host at cis.poly.edu
wants IP address for
gaia.cs.umass.edu
iterated query:
contacted server
3
4
5
local DNS server
dns.poly.edu
requesting host
cis.poly.edu
gaia.cs.umass.edu
Application 2-68
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
Application 2-69
Application 2-70
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
Application 2-71
Application 2-72
Application 2-73
2.5 DNS
Application 2-75
no always-on server
arbitrary end systems
directly communicate
peers are intermittently
connected and change IP
addresses
peer-peer
Three topics:
file distribution
searching for information
case Study: Skype
Application 2-76
us
u1
d1
u2
d2
File, size F
dN
uN
Network (with
abundant bandwidth)
Application 2-77
server sequentially
sends N copies:
NF/us time
client i takes F/di time to
download
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)
Application 2-78
us
u1 d1 u2
d2
Application 2-79
3.5
P2P
Client-Server
3
2.5
2
1.5
1
0.5
0
0
10
15
20
25
30
35
N
Application 2-80
torrent: group of
peers exchanging
chunks of a file
obtain list
of peers
trading
chunks
peer
Application 2-81
BitTorrent (1)
Application 2-82
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-83
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-85
DHT Identifiers
Application 2-86
central issue:
assigning (key, value) pairs to peers.
Application 2-87
15
4
12
5
10
Application 2-88
0001
Whos resp
for key 1110 ?
I am
0011
1111
1110
0100
1110
1110
1100
1110
Define closest
as closest
successor
1110
0101
1110
1010
1000
Application 2-89
Whos resp
for key 1110?
15
4
12
5
10
Peer Churn
1
To handle peer churn, require
15
4
12
5
10
Supernode
(SN)
Application 2-92
Peers as relays
solution:
using Alices and Bobs
SNs, relay is chosen
each peer initiates session
with relay.
peers can now
communicate through
NATs via relay
Application 2-93
2.5 DNS
Application 2-94
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-95
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-96
Application 2-97
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
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-99
Application 2-100
create
input stream
create
clientSocket object
of type Socket,
connect to server
create
output stream
attached to socket
Application 2-101
create
input stream
attached to socket
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-102
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-103
DataOutputStream outToClient =
new DataOutputStream(connectionSocket.getOutputStream());
read in line
from socket
clientSentence = inFromClient.readLine();
capitalizedSentence = clientSentence.toUpperCase() + '\n';
outToClient.writeBytes(capitalizedSentence);
}
}
Application 2-104
2.5 DNS
Application 2-105
application viewpoint:
UDP provides unreliable transfer
of groups of bytes (datagrams)
between client and server
Application 2-106
Client
create socket,
clientSocket =
DatagramSocket()
Create datagram with server IP and
port=x; send datagram via
clientSocket
Application 2-107
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
clientSocket UDP
socket
to network
UDP
packet
UDP
socket
from network
Application 2-108
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-109
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-110
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-111
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);
}
}
}
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
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-114