You are on page 1of 85

Chapter 2: Outline

2.1 principles of network 2.6 P2P applications


applications 2.7 socket programming
2.2 Web and HTTP with UDP and TCP
2.3 FTP
2.4 electronic mail
 SMTP, POP3, IMAP
2.5 DNS

Kurose & Ross 2-1


Chapter 2: Application Layer

our goals:  popular application-level


 conceptual, protocols
implementation aspects  HTTP
of network application  FTP
protocols  SMTP / POP3 / IMAP
 transport-layer  DNS
service models
 client-server
paradigm
 peer-to-peer
paradigm

Kurose & Ross 2-2


Some network apps
 e-mail  voice over IP (e.g., Skype)
 web  real-time video
 text messaging conferencing
 remote login  social networking
 P2P file sharing  search
 multi-user network games  …
 streaming stored video  …
(YouTube, Hulu, Netflix)

Kurose & Ross 2-3


Creating a network app
application
write programs that: transport
network
 run on (different) end systems data link
physical
 communicate over network

 e.g., web server software


communicates with browser
software

no need to write software for


network-core devices
 network-core devices do not run
user applications application
transport
 applications on end systems allows network
data link application
for rapid app development, physical transport
network
propagation data link
physical

Kurose & Ross 2-4


Application architectures
possible structure of applications:

 Client-server

 Peer-to-Peer (P2P)

Kurose & Ross 2-5


Client-server architecture
server:
 always-on host
 permanent IP address
 data centers for scaling

clients:
 communicate with server
client/server  may be intermittently
connected
 may have dynamic IP addresses
 do not communicate directly
with each other

Kurose & Ross 2-6


P2P architecture
 no always-on server peer-peer
 arbitrary end systems directly
communicate
 peers request service from
other peers, provide service in
return to other peers
 self scalability – new peers
bring new service capacity, as
well as new service demands
 peers are intermittently
connected and change IP
addresses
 complex management

Kurose & Ross 2-7


Processes communicating
process: program running clients, servers
within a host client process: process that
 within same host, two initiates communication
processes communicate server process: process that
using inter-process waits to be contacted
communication (defined by
OS)
 processes in different hosts
communicate by exchanging  aside: applications with P2P
messages architectures have client
processes & server
processes

Kurose & Ross 2-8


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 to deliver message to socket at receiving
process

application application
socket controlled by
process process app developer

transport transport

network network controlled


link by OS
link Internet
physical physical

Kurose & Ross 2-9


Addressing processes
 to receive messages, process  identifier includes both IP address
must have identifier and port numbers associated with
 host device has unique 32-bit IP process on host.
address  example port numbers:
 Q: does IP address of host on which  HTTP server: 80
process runs suffice for identifying  mail server: 25
the process?  to send HTTP message to
gaia.cs.umass.edu web server:
 IP address: 128.119.245.12
 A: no, many processes can be  port number: 80
running on same host
 more shortly…

Kurose & Ross 2-10


App-layer protocol defines
 types of messages exchanged, open protocols:
 e.g., request, response  defined in RFCs
 message syntax:  allows for interoperability
 what fields in messages &  e.g., HTTP, SMTP
how fields are delineated proprietary protocols:
 message semantics  e.g., Skype
 meaning of information in
fields
 rules for when and how
processes send & respond to
messages

Kurose & Ross 2-11


What transport service does an app need?

data integrity throughput


 some apps (e.g., file transfer, web  some apps (e.g., multimedia)
transactions) require 100% reliable require minimum amount of
data transfer throughput to be “effective”
 other apps (e.g., audio/video) can  other apps (“elastic apps”) make
tolerate some loss use of whatever throughput they
get
timing
 some apps (e.g., Internet
telephony, interactive games)
require low delay to be
“effective”
security
 some can tolerate longer delays  encryption, data integrity, …
but must have bounded “delay
jitter”

Kurose & Ross 2-12


Transport service requirements: common apps

application data loss throughput time sensitive

file transfer no loss elastic no


e-mail no loss elastic no
Web documents no loss elastic no
real-time audio/video loss-tolerant audio: 5kbps-1Mbps yes, 100’s msec
video:10kbps-5Mbps
stored audio/video loss-tolerant same as above yes, few secs
interactive games loss-tolerant few kbps up yes, 100’s msec
text messaging no loss elastic yes and no

Kurose & Ross 2-13


Internet transport protocols services

TCP service: UDP service:


 reliable transport between  unreliable data transfer
sending and receiving process between sending and
 flow control: sender won’t receiving process
overwhelm receiver  does not provide: reliability,
 congestion control: throttle flow control, congestion
sender when network control, timing, throughput
overloaded
guarantee, security,
 does not provide: timing, orconnection setup,
minimum throughput
guarantee, security
 connection-oriented: setup Q: why bother? Why is there a
required between client and UDP?
server processes

Kurose & Ross 2-14


Internet apps: application, transport protocols

application underlying
application layer protocol transport protocol

e-mail SMTP [RFC 2821] TCP


remote terminal access Telnet [RFC 854] TCP
Web HTTP [RFC 2616] TCP
file transfer FTP [RFC 959] TCP
streaming multimedia HTTP (e.g., YouTube), TCP or UDP
RTP [RFC 1889]
Internet telephony SIP, RTP, proprietary
(e.g., Skype) TCP or UDP

Kurose & Ross 2-15


Securing TCP

TCP & UDP SSL is at app layer


 no encryption  Apps use SSL libraries,
 cleartext passwds sent which “talk” to TCP
into socket traverse SSL socket API
Internet in cleartext  cleartext passwds sent
SSL into socket traverse
 provides encrypted TCP Internet encrypted
connection  More later ……
 data integrity
 end-point authentication

Kurose & Ross 2-16


Chapter 2: outline
2.1 principles of network 2.6 P2P applications
applications 2.7 socket programming
 app architectures with UDP and TCP
 app requirements
2.2 Web and HTTP
2.3 FTP
2.4 electronic mail
 SMTP, POP3, IMAP
2.5 DNS

Kurose & Ross 2-17


Web and HTTP
First, a review…
 web page consists of objects
 object can be HTML file, JPEG image, Java applet, audio
file,…
 web page consists of base HTML-file which includes several
referenced objects
 each object is addressable by a URL, e.g.,

www.someschool.edu/someDept/pic.gif

host name path name

Kurose & Ross 2-18


HTTP overview
HTTP: hypertext
transfer protocol
 Web’s application layer
protocol PC running
Firefox browser
 client/server model
 client: browser that
requests, receives, (using
HTTP protocol) and
server
“displays” Web objects running
 server: Web server sends Apache Web
(using HTTP protocol) server
objects in response to
requests
iphone running
Safari browser

Kurose & Ross 2-19


HTTP overview (continued)
uses TCP: HTTP is “stateless”
 client initiates TCP connection  server maintains no
(creates socket) to server, information about past
port 80 client requests
 server accepts TCP
connection from client
 HTTP messages (application- aside
layer protocol messages) protocols that maintain “state” are
exchanged between browser complex!
(HTTP client) and Web server  past history (state) must be
(HTTP server) maintained
 TCP connection closed  if server/client crashes, their
views of “state” may be
inconsistent, must be
reconciled
Kurose & Ross 2-20
HTTP connections
non-persistent HTTP persistent HTTP
 at most one object  multiple objects can
sent over TCP be sent over single
connection TCP connection
 connection then between client, server
closed
 downloading multiple
objects required
multiple connections

Kurose & Ross 2-21


Non-persistent HTTP
suppose user enters URL: (contains text,
www.someSchool.edu/someDepartment/home.index references to 10
jpeg images)
1a. HTTP client initiates TCP
connection to HTTP server
(process) at 1b. HTTP server at host
www.someSchool.edu on port www.someSchool.edu waiting
80 for TCP connection at port 80.
“accepts” connection, notifying
2. HTTP client sends HTTP client
request message (containing
URL) into TCP connection 3. HTTP server receives request
socket. Message indicates that message, forms response
client wants object message containing requested
someDepartment/home.index object, and sends message into
its socket
time
Kurose & Ross 2-22
Non-persistent HTTP (cont.)
4. HTTP server closes TCP
connection.
5. HTTP client receives response
message containing html file,
displays html. Parsing html file,
finds 10 referenced jpeg objects

time
6. Steps 1-5 repeated for each of
10 jpeg objects

Kurose & Ross 2-23


Non-persistent HTTP: response time

RTT (definition): time for a small


packet to travel from client to
server and back
HTTP response time: initiate TCP
 one RTT to initiate TCP connection
connection RTT
 one RTT for HTTP request and request
first few bytes of HTTP file
time to
response to return RTT transmit
 file transmission time file
file
 non-persistent HTTP response received
time =
2RTT+ file transmission time time
time

Kurose & Ross 2-24


Persistent HTTP

non-persistent HTTP issues: persistent HTTP:


 requires 2 RTTs per object  server leaves connection
 OS overhead for each TCP open after sending response
connection  subsequent HTTP messages
 browsers often open parallel between same client/server
TCP connections to fetch sent over open connection
referenced objects  client sends requests as
soon as it encounters a
referenced object
 as little as one RTT for all
the referenced objects

Kurose & Ross 2-25


HTTP request message

 two types of HTTP messages: request, response


 HTTP request message:
 ASCII (human-readable format)
carriage return character
line-feed character
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
header Accept-Language: en-us,en;q=0.5\r\n
lines Accept-Encoding: gzip,deflate\r\n
Accept-Charset: ISO-8859-1,utf-8;q=0.7\r\n
carriage return, Keep-Alive: 115\r\n
line feed at start Connection: keep-alive\r\n
\r\n
of line indicates
end of header lines
Kurose & Ross 2-26
HTTP response message
status line
(protocol
status code HTTP/1.1 200 OK\r\n
status phrase) Date: Sun, 26 Sep 2010 20:09:20 GMT\r\n
Server: Apache/2.0.52 (CentOS)\r\n
Last-Modified: Tue, 30 Oct 2007 17:00:02
GMT\r\n
header ETag: "17dc6-a5c-bf716880"\r\n
Accept-Ranges: bytes\r\n
lines Content-Length: 2652\r\n
Keep-Alive: timeout=10, max=100\r\n
Connection: Keep-Alive\r\n
Content-Type: text/html; charset=ISO-8859-
1\r\n
\r\n
data, e.g., data data data data data ...
requested
HTML file
Kurose & Ross 2-27
HTTP response status codes
 status code appears in 1st line in server-to-
client response message.
 some sample codes:
200 OK
 request succeeded, requested object later in this msg
301 Moved Permanently
 requested object moved, new location specified later in this msg
(Location:)
400 Bad Request
 request msg not understood by server
404 Not Found
 requested document not found on this server
505 HTTP Version Not Supported
Kurose & Ross 2-28
User-server state: cookies
many Web sites use cookies example:
four components:  Susan always access Internet from
her PC
1) cookie header line of HTTP  visits specific e-commerce site for
response message first time
2) cookie header line in next  when initial HTTP requests
HTTP request message arrives at site, site creates:
3) cookie file kept on user’s  unique ID
host, managed by user’s  entry in backend database for
browser ID
4) back-end database at Web
site

Kurose & Ross 2-29


Cookies: keeping “state” (cont.)
client server

ebay 8734
usual http request msg Amazon server
cookie file creates ID
usual http response
1678 for user create backend
ebay 8734
set-cookie: 1678 entry database
amazon 1678
usual http request msg
cookie: 1678 cookie- access
specific
usual http response msg action

one week later:


access
ebay 8734 usual http request msg
amazon 1678 cookie: 1678 cookie-
specific
usual http response msg action
Kurose & Ross 2-30
Cookies (continued)
aside
what cookies can be used cookies and privacy:
for:  cookies permit sites to learn a
 authorization lot about you
 shopping carts  you may supply name and e-
 recommendations mail to sites
 user session state (Web e-mail)

how to keep “state”:


 protocol endpoints: maintain state at
sender/receiver over multiple transactions
 cookies: http messages carry state

Kurose & Ross 2-31


Web caches (proxy server)
goal: satisfy client request without involving origin server

 user sets browser: Web


accesses via cache
 browser sends all HTTP proxy
requests to cache server
client
 object in cache: cache origin
server
returns object
 else cache requests
object from origin
server, then returns
object to client
client origin
server

Kurose & Ross 2-32


More about Web caching
 cache acts as both client why Web caching?
and server
 reduce response time for
 server for original
requesting client client request
 client to origin server  reduce traffic on an
 typically cache is installed institution’s access link
by ISP (university,  Internet dense with caches:
company, residential ISP) enables “poor” content
providers to effectively
deliver content (so too
does P2P file sharing)

Kurose & Ross 2-33


Caching example:
assumptions:
 avg object size: 100K bits origin
 avg request rate from browsers to servers
origin servers:15/sec public
 avg data rate to browsers: 1.50 Mbps Internet
 RTT from institutional router to any
origin server: 2 sec
 access link rate: 1.54 Mbps 1.54 Mbps
access link
consequences:
institutional
 LAN utilization: 15%
network
 access link utilization = 99% 1 Gbps LAN
problem!
 total delay = Internet delay + access
delay + LAN delay
= 2 sec + minutes + usecs

Kurose & Ross 2-34


Caching example: fatter access link
assumptions:
 avg object size: 100K bits
 avg request rate from browsers to
origin servers:15/sec origin
servers
 avg data rate to browsers: 1.50 Mbps public
 RTT from institutional router to any Internet
origin server: 2 sec
 access link rate: 1.54 Mbps

consequences: 1.54 Mbps


154 Mbps
 LAN utilization: 15% access link
154 Mbps
 access link utilization = 99% institutional
 total delay = Internet delay + access network
1 Gbps LAN
delay + LAN delay
9.9%
= 2 sec + minutes + usecs

msecs
Cost: increased access link speed (not cheap!)
Kurose & Ross 2-35
Caching example: install local cache
assumptions:
 avg object size: 100K bits
 avg request rate from browsers to
origin servers:15/sec origin
servers
 avg data rate to browsers: 1.50 Mbps public
 RTT from institutional router to any Internet
origin server: 2 sec
 access link rate: 1.54 Mbps

consequences: 1.54 Mbps


 LAN utilization: 15% access link

 access link utilization = institutional


network
 total delay = 1 Gbps LAN
?
? local web
cache
How to compute link utilization, delay?

Cost: web cache (cheap!)


Kurose & Ross 2-36
Caching example: install local cache
Calculating access link utilization, delay
with cache:
 suppose cache hit rate is 0.4
origin
 40% requests satisfied at cache, 60%
servers
requests satisfied at origin public
Internet
 access link utilization:
 60% of requests use access link
 data rate to browsers over access link =
0.6*1.50 Mbps = .9 Mbps 1.54 Mbps
access link
 utilization = 0.9/1.54 = .58
institutional
 total delay
network
 = 0.6 * (delay from origin servers) +0.4 1 Gbps LAN
* (delay when satisfied at cache)
 = 0.6 (2.01) + 0.4 (~msecs) local web
 = ~ 1.2 secs cache
 less than with 154 Mbps link (and
cheaper too!)
Kurose & Ross 2-37
Conditional GET
client server
 Goal: don’t send object if
cache has up-to-date cached
version HTTP request msg
object
 no object transmission If-modified-since: <date>
delay not
modified
 lower link utilization HTTP response
before
HTTP/1.0
 cache: specify date of 304 Not Modified <date>
cached copy in HTTP
request
If-modified-since:
<date>
HTTP request msg
 server: response contains no If-modified-since: <date> object
object if cached copy is up-to- modified
date: HTTP response after
HTTP/1.0 304 Not HTTP/1.0 200 OK <date>
Modified <data>
Kurose & Ross 2-38
Chapter 2: outline
2.1 principles of network 2.6 P2P applications
applications 2.7 socket programming
 app architectures with UDP and TCP
 app requirements
2.2 Web and HTTP
2.3 FTP
2.4 electronic mail
 SMTP, POP3, IMAP
2.5 DNS

Kurose & Ross 2-39


FTP: the file transfer protocol
file transfer
FTP FTP FTP
user client server
interface
user
at host remote file
local file system
system

 transfer file to/from remote host


 client/server model
 client: side that initiates transfer (either to/from remote)
 server: remote host
 ftp: RFC 959
 ftp server: port 21

Kurose & Ross 2-40


FTP: separate control, data connections

 FTP client contacts FTP server at TCP control connection,


server port 21
port 21, using TCP
 client authorized over control
connection TCP data connection,
FTP server port 20 FTP
 client browses remote directory, client server
sends commands over control
connection
 server opens another TCP data
 when server receives file transfer
command, server opens 2nd TCP data connection to transfer another file
connection (for file) to client  control connection: “out of band”
 after transferring one file, server  FTP server maintains “state”:
closes data connection current directory, earlier
authentication

Kurose & Ross 2-41


FTP commands, responses
sample commands: sample return codes
 sent as ASCII text over  status code and phrase (as
control channel in HTTP)
 USER username  331 Username OK,
 PASS password password required
 DIR return list of file in  125 data
current directory connection already
open; transfer
 GET filename starting
retrieves (gets) file
 425 Can’t open
 PUT filename stores data connection
(puts) file onto remote  452 Error writing
host file

Kurose & Ross 2-42


Chapter 2: outline
2.1 principles of network 2.6 P2P applications
applications 2.7 socket programming
 app architectures with UDP and TCP
 app requirements
2.2 Web and HTTP
2.3 FTP
2.4 electronic mail
 SMTP, POP3, IMAP
2.5 DNS

Kurose & Ross 2-43


Electronic mail outgoing
message queue

Three major components: user mailbox


user
 user agents agent
 mail servers
mail user
 simple mail transfer protocol: server
SMTP agent
SMTP mail user
User Agent server agent
 a.k.a. “mail reader” SMTP
 composing, editing, reading mail user
messages SMTP
agent
mail
 e.g., Outlook, Thunderbird, server
iPhone mail client user
 outgoing, incoming messages agent
stored on server user
agent

Kurose & Ross 2-44


Electronic mail: mail servers
mail servers: user
agent
 mailbox contains incoming
messages for user mail user
server
 message queue of outgoing (to agent
be sent) mail messages SMTP mail user
 SMTP protocol between mail server agent
servers to send email messages
SMTP
 client: sending mail server
 “server”: receiving mail SMTP user
server agent
mail
server
user
agent
user
agent

Kurose & Ross 2-45


Electronic Mail: SMTP [RFC 2821]

 uses TCP to reliably transfer email message from client to


server, port 25
 direct transfer: sending server to receiving server
 three phases of transfer
 handshaking (greeting)
 transfer of messages
 closure
 command/response interaction (like HTTP, FTP)
 commands:ASCII text
 response: status code and phrase
 messages must be in 7-bit ASCI

Kurose & Ross 2-46


Scenario: Alice sends message to Bob

1) Alice uses UA to compose 4) SMTP client sends Alice’s


message “to” message over the TCP
bob@someschool.edu connection
2) Alice’s UA sends message to 5) Bob’s mail server places the
her mail server; message message in Bob’s mailbox
placed in message queue 6) Bob invokes his user agent
3) client side of SMTP opens to read message
TCP connection with Bob’s
mail server

1 user mail user


mail agent
agent server server
2 3 6
4
5
Alice’s mail server Bob’s mail server
Kurose & Ross 2-47
Sample SMTP interaction
S: 220 hamburger.edu
C: HELO crepes.fr
S: 250 Hello crepes.fr, pleased to meet you
C: MAIL FROM: <alice@crepes.fr>
S: 250 alice@crepes.fr... Sender ok
C: RCPT TO: <bob@hamburger.edu>
S: 250 bob@hamburger.edu ... Recipient ok
C: DATA
S: 354 Enter mail, end with "." on a line by itself
C: Do you like ketchup?
C: How about pickles?
C: .
S: 250 Message accepted for delivery
C: QUIT
S: 221 hamburger.edu closing connection

Kurose & Ross 2-48


SMTP: final words
 SMTP uses persistent comparison with HTTP:
connections
 SMTP requires message  HTTP: pull
(header & body) to be in 7-  SMTP: push
bit ASCII
 both have ASCII
 SMTP server uses command/response
CRLF.CRLF to determine interaction, status codes
end of message
 HTTP: each object
encapsulated in its own
response msg
 SMTP: multiple objects sent
in multipart msg

Kurose & Ross 2-49


Mail message format

SMTP: protocol for


exchanging email msgs header
blank
RFC 822: standard for text line
message format:
 header lines, e.g.,
 To: body
 From:
 Subject:
different from SMTP MAIL
FROM, RCPT TO:
commands!
 Body: the “message”
 ASCII characters only

Kurose & Ross 2-50


Mail access protocols
mail access
protocol
user SMTP user
SMTP
agent agent
(e.g., POP,
IMAP)

sender’s mail receiver’s mail


server server

 SMTP: delivery/storage to receiver’s server


 mail access protocol: retrieval from server
 POP: Post Office Protocol [RFC 1939]: authorization, download
 IMAP: Internet Mail Access Protocol [RFC 1730]: more features,
including manipulation of stored msgs on server
 HTTP: gmail, Hotmail,Yahoo! Mail, etc.

Kurose & Ross 2-51


POP3 protocol
S: +OK POP3 server ready
C: user bob
authorization phase S:
C:
+OK
pass hungry
 client commands: S: +OK user successfully logged on
 user: declare username
 pass: password C: list
S: 1 498
 server responses S: 2 912
 +OK S: .
 -ERR C: retr 1
S: <message 1 contents>
transaction phase, client: S: .
 list: list message numbers C: dele 1
 retr: retrieve message by C: retr 2
number S: <message 1 contents>
 dele: delete S: .
 quit C: dele 2
C: quit
S: +OK POP3 server signing off
Kurose & Ross 2-52
POP3 (more) and IMAP
more about POP3 IMAP
 previous example uses POP3  keeps all messages in one
“download and delete” place: at server
mode  allows user to organize
 Bob cannot re-read e- messages in folders
mail if he changes client  keeps user state across
 POP3 “download-and-keep”: sessions:
copies of messages on  names of folders and
different clients mappings between
 POP3 is stateless across message IDs and folder
sessions name

Kurose & Ross 2-53


Chapter 2: outline
2.1 principles of network 2.6 P2P applications
applications 2.7 socket programming
 app architectures with UDP and TCP
 app requirements
2.2 Web and HTTP
2.3 FTP
2.4 electronic mail
 SMTP, POP3, IMAP
2.5 DNS

Kurose & Ross 2-54


DNS: domain name system
people: many identifiers: Domain Name System:
 SSN, name, passport #  distributed database
Internet hosts, routers: implemented in hierarchy of
 IP address (32 bit) - used many name servers
for addressing datagrams  application-layer protocol: hosts,
 “name”, e.g., name servers communicate to
www.yahoo.com - used by resolve names (address/name
humans translation)
Q: how to map between IP
address and name, and vice
versa ?

Kurose & Ross 2-55


DNS: domain name system
 Specified either directly by the user or obtained through
DHCP (IP Address)
 Specify both a “Primary DNS” and a “Secondary DNS”

 Would usually be a machine in the host's own network,

or “close by”
 Also possible to specify a Public DNS

Google 8.8.8.8 (Primary) 8.8.4.4 (Secondary)


 Security and Privacy Issues –
 taking down your DNS will prevent you from accessing
the network
 you cannot keep any secrets from your DNS
DNS: services, structure
DNS services why not centralize DNS?
 hostname to IP address  single point of failure
translation  traffic volume
 host aliasing  distant centralized database
 canonical, alias names  maintenance
 mail server aliasing
 load distribution
 replicated Web servers:
many IP addresses A: doesn’t scale!
correspond to one name

Kurose & Ross 2-57


DNS: a distributed, hierarchical database

Root DNS Servers


… …

com DNS servers org DNS servers edu DNS servers

pbs.org poly.edu umass.edu


yahoo.com amazon.com
DNS servers DNS serversDNS servers
DNS servers DNS servers

client wants IP for www.amazon.com; 1st approx:


 client queries root server to find com DNS server
 client queries .com DNS server to get amazon.com DNS server
 client queries amazon.com DNS server to get IP address for
www.amazon.com

Kurose & Ross 2-58


DNS: root name servers
 contacted by local name server that can not resolve name
 root name server:
 contacts authoritative name server if name mapping not known
 gets mapping
 returns mapping to local name server

c. Cogent, Herndon, VA (5 other sites)


d. U Maryland College Park, MD k. RIPE London (17 other sites)
h. ARL Aberdeen, MD
j. Verisign, Dulles VA (69 other sites ) i. Netnod, Stockholm (37 other sites)

e. NASA Mt View, CA m. WIDE Tokyo


f. Internet Software C. (5 other sites)
Palo Alto, CA (and 48 other
sites)

a. Verisign, Los Angeles CA 13 root name


(5 other sites)
b. USC-ISI Marina del Rey, CA
“servers”
l. ICANN Los Angeles, CA worldwide
(41 other sites)
g. US DoD Columbus,
OH (5 other sites)

Kurose & Ross 2-59


TLD, authoritative servers
top-level domain (TLD) servers:
 responsible for com, org, net, edu, aero, jobs, museums, and
all top-level country domains, e.g.: uk, fr, ca, jp
 Network Solutions maintains servers for .com TLD
 Educause for .edu TLD
authoritative DNS servers:
 organization’s own DNS server(s), providing authoritative
hostname to IP mappings for organization’s named hosts
 can be maintained by organization or service provider

Kurose & Ross 2-60


Local DNS name server
 does not strictly belong to hierarchy
 each ISP (residential ISP, company, university) has
one
 also called “default name server”
 when host makes DNS query, query is sent to its
local DNS server
 has local cache of recent name-to-address translation
pairs (but may be out of date!)
 acts as proxy, forwards query into hierarchy

Kurose & Ross 2-61


DNS name root DNS server
resolution example
2
 host at cis.poly.edu 3
TLD DNS server
wants IP address for 4
gaia.cs.umass.edu
5

local DNS server


iterated query: dns.poly.edu
 contacted server 7 6
1 8
replies with name of
server to contact
authoritative DNS server
 “I don’t know this dns.cs.umass.edu
name, but ask this requesting host
cis.poly.edu
server”
gaia.cs.umass.edu

Kurose & Ross 2-62


DNS name root DNS server
resolution example
2 3
recursive query: 7
6
 puts burden of name TLD DNS
server
resolution on
contacted name local DNS server
server dns.poly.edu 5 4

 heavy load at upper 1 8


levels of hierarchy?
authoritative DNS server
dns.cs.umass.edu
requesting host
cis.poly.edu

gaia.cs.umass.edu

Kurose & Ross 2-63


DNS: caching, updating records

 once (any) name server learns mapping, it caches mapping


 cache entries timeout (disappear) after some time (TTL)
 TLD servers typically cached in local name servers
• thus root name servers not often visited
 cached entries may be out-of-date (best effort name-to-address
translation!)
 if name host changes IP address, may not be known Internet-
wide until all TTLs expire
 update/notify mechanisms proposed IETF standard
 RFC 2136

Kurose & Ross 2-64


Inserting records into DNS
 example: new startup “Network Utopia”
 register name networkuptopia.com at DNS registrar
(e.g., Network Solutions)
 provide names, IP addresses of authoritative name server
(primary and secondary)
 registrar inserts two RRs into .com TLD server:
(networkutopia.com, dns1.networkutopia.com, NS)
(dns1.networkutopia.com, 212.212.212.1, A)
 create authoritative server type A record for
www.networkuptopia.com; type MX record for
networkutopia.com

Kurose & Ross 2-65


Attacking DNS
DDoS attacks Redirect attacks
 Bombard root servers  Man-in-middle
with traffic  Intercept queries
 Not successful to date  DNS poisoning
 Traffic Filtering  Send bogus replies to DNS
 Local DNS servers cache server, which caches
IPs of TLD servers, allowing
root server bypass Exploit DNS for DDoS
 Send queries with spoofed
 Bombard TLD servers source address: target IP
 Potentially more dangerous  Requires amplification

Kurose & Ross 2-66


Chapter 2: outline
2.1 principles of network 2.6 P2P applications
applications 2.7 socket programming
 app architectures with UDP and TCP
 app requirements
2.2 Web and HTTP
2.3 FTP
2.4 electronic mail
 SMTP, POP3, IMAP
2.5 DNS

Kurose & Ross 2-67


Pure P2P architecture
 no always-on server
 arbitrary end systems
directly communicate
 peers are intermittently
connected and change IP
addresses

examples:
 file distribution
(BitTorrent)
 Streaming (KanKan)
 VoIP (Skype)

Kurose & Ross 2-68


File distribution: client-server vs P2P
Question: how much time to distribute file (size F) from
one server to N peers?
 peer upload/download capacity is limited resource

us: server upload


capacity

di: peer i download


file, size F u1 d1 capacity
us u2 d2
server
di
uN network (with abundant
bandwidth) ui
dN
ui: peer i upload
capacity

Kurose & Ross 2-69


File distribution time: client-server
 server transmission: must
sequentially send (upload) N F
us
file copies:
 time to send one copy: F/us di

 time to send N copies: NF/us network


ui

 client: each client must download


file copy
 dmin = min client download rate
 min client download time: F/dmin increases linearly in N

time to distribute F
to N clients using Dc-s > max{NF/us,,F/dmin}
client-server approach

Kurose & Ross 2-70


File distribution time: P2P
 server transmission: must upload
at least one copy F
us
 time to send one copy: F/us
di
 client: each client must download network
file copy ui

 min client download time: F/dmin

 clients: as aggregate must download NF bits


 max upload rate (limting max download rate) is us + ui

time to distribute F
to N clients using DP2P > max{F/us,,F/dmin,,NF/(us + ui)}
P2P approach

increases linearly in N …
… but so does this, as each peer brings service capacity
Kurose & Ross 2-71
Client-server vs. P2P: example
client upload rate = u, F/u = 1 hour, us = 10u, dmin ≥ us

3.5
P2P
3
Minimum Distribution Time

Client-Server
2.5

1.5

0.5

0
0 5 10 15 20 25 30 35
N

Kurose & Ross 2-72


P2P file distribution: BitTorrent
 file divided into 256Kb chunks
 peers in torrent send/receive file chunks

tracker: tracks peers torrent: group of peers


participating in torrent exchanging chunks of a file

Alice arrives …
… obtains list
of peers from tracker
… and begins exchanging
file chunks with peers in torrent

Kurose & Ross 2-73


P2P file distribution: BitTorrent

 peer joining torrent:


 has no chunks, but will accumulate
them over time from other peers
 registers with tracker to get list of
peers, connects to subset of peers
(“neighbors”)

 while downloading, peer uploads chunks to other peers


 peer may change peers with whom it exchanges chunks
 churn: peers may come and go
 once peer has entire file, it may (selfishly) leave or (altruistically) remain in
torrent

Kurose & Ross 2-74


BitTorrent: requesting, sending file chunks

requesting chunks: sending chunks: tit-for-tat


 at any given time, different peers  Alice sends chunks to those four
have different subsets of file peers currently sending her chunks at
chunks highest rate
 periodically, Alice asks each peer  other peers are choked by Alice (do
for list of chunks that they have not receive chunks from her)
 Alice requests missing chunks  re-evaluate top 4 every10 secs
from peers, rarest first  every 30 secs: randomly select another
peer, starts sending chunks
 “optimistically unchoke” this peer
 newly chosen peer may join top 4

Kurose & Ross 2-75


BitTorrent: tit-for-tat
(1) Alice “optimistically unchokes” Bob
(2) Alice becomes one of Bob’s top-four providers; Bob reciprocates
(3) Bob becomes one of Alice’s top-four providers

higher upload rate: find better


trading partners, get file faster !

Kurose & Ross 2-76


Chapter 2: outline
2.1 principles of network 2.6 P2P applications
applications 2.7 socket programming
 app architectures with UDP and TCP
 app requirements
2.2 Web and HTTP
2.3 FTP
2.4 electronic mail
 SMTP, POP3, IMAP
2.5 DNS

Kurose & Ross 2-77


Socket programming
goal: learn how to build client/server applications that
communicate using sockets
socket: door between application process and end-
end-transport protocol

application application
socket controlled by
process process app developer

transport transport
network network controlled
link by OS
link Internet
physical physical

Kurose & Ross 2-78


Socket programming

Two socket types for two transport services:

 UDP: unreliable datagram

 TCP: reliable, byte stream-oriented

Kurose & Ross 2-79


Socket programming with UDP
UDP: no “connection” between client & server
 no handshaking before sending data
 sender explicitly attaches IP destination address and port #
to each packet
 rcvr extracts sender IP address and port# from received
packet

UDP: transmitted data may be lost or received


out-of-order
Application viewpoint:
 UDP provides unreliable transfer of groups of bytes
(“datagrams”) between client and server

Kurose & Ross 2-80


Client/server socket interaction: UDP

server (running on serverIP) client


create socket:
create socket, port= x: clientSocket =
serverSocket = socket(AF_INET,SOCK_DGRAM)
socket(AF_INET,SOCK_DGRAM)
Create datagram with server IP and
port=x; send datagram via
read datagram from clientSocket
serverSocket

write reply to
serverSocket read datagram from
specifying clientSocket
client address,
port number close
clientSocket

& Ross 2-812-81


KuroseApplication
Socket programming with TCP
client must contact server  when contacted by client,
 server process must first be server TCP creates new socket
running for server process to
 server must have created communicate with that
socket (door) that welcomes particular client
client’s contact
 allows server to talk with
client contacts server by: multiple clients
 Creating TCP socket,  source port numbers used to
distinguish clients
specifying IP address, port
number of server process
 when client creates socket:
client TCP establishes application viewpoint:
connection to server TCP TCP provides reliable, in-order
byte-stream transfer (“pipe”)
between client and server

Kurose & Ross 2-82


Client/server socket interaction: TCP

server (running on hostid) client


create socket,
port=x, for incoming
request:
serverSocket = socket()

wait for incoming create socket,


connection request
TCP connect to hostid, port=x
connectionSocket = connection setup clientSocket = socket()
serverSocket.accept()

send request using


read request from clientSocket
connectionSocket

write reply to
connectionSocket read reply from
clientSocket
close
connectionSocket close
clientSocket

Kurose & Ross 2-83


Chapter 2: summary
our study of network apps now complete!

 application architectures  specific protocols:


 client-server  HTTP
 P2P  FTP
 application service requirements:
 SMTP, POP, IMAP
 reliability, bandwidth, delay
 DNS
 Internet transport service model
 connection-oriented, reliable:  P2P: BitTorrent, DHT
TCP  socket programming: TCP, UDP
 unreliable, datagrams: UDP sockets

Kurose & Ross 2-84


Chapter 2: summary
most importantly: learned about protocols!

 typical request/reply message important themes:


exchange:
 control vs. data msgs
 client requests info or
service  in-band, out-of-band
 server responds with data,  centralized vs. decentralized
status code
 stateless vs. stateful
 message formats:
 reliable vs. unreliable msg transfer
 headers: fields giving info
about data  “complexity at network edge”
 data: info being
communicated

Kurose & Ross 2-85

You might also like