Sei sulla pagina 1di 107

Chapter 2

Application
Layer
A note on the use of these Powerpoint slides:
Were making these slides freely available to all (faculty, students, readers).
Theyre in PowerPoint form so you see the animations; and can add, modify,
and delete slides (including this one) and slide content to suit your needs.
They obviously represent a lot of work on our part. In return for use, we only
ask the following: Computer
If you use these slides (e.g., in a class) that you mention their source
(after all, wed like people to use our book!) Networking: A Top-
Down Approach
If you post any slides on a www site, that you note that they are adapted
from (or perhaps identical to) our slides, and note our copyright of this
material.
7th Edition, Global Edition
Thanks and enjoy! JFK/KWR Jim Kurose, Keith Ross
Pearson
All material copyright 1996-2016
April 2016
J.F Kurose and K.W. Ross, All Rights Reserved
Application Layer 2-1
Chapter 2: outline
2.1 principles of 2.5 P2P applications
network 2.6 video streaming
applications and content
2.2 Web and HTTP distribution
2.3 electronic mail networks
SMTP, POP3, IMAP 2.7 socket
2.4 DNS programming
with UDP and TCP

Application Layer 2-2


Chapter 2: application
layer
our goals: learn about
conceptual, protocols by
implementation examining popular
aspects of network application-level
application protocols protocols
transport-layer HTTP
service models SMTP / POP3 / IMAP
client-server DNS
paradigm P2P: BitTorrent
peer-to-peer creating network
paradigm applications
content socket API
distribution
networks

Application Layer 2-3


Some network apps
e-mail voice over IP
web (e.g., Skype,
Facetime and
text messaging
Google Hangouts)
remote login real-time video
P2P file sharing conferencing
multi-user social networking
network games search
streaming stored
...
video (YouTube,
Hulu, Netflix) ...
Remote login, ex. Telnet and SSH (Secure Shell)
Application Layer 2-4
Creating a network app application
transport
network
data link
physical

write programs that:


run on (different) end
systems
communicate over network
e.g., web server software
communicates with browser
software

no need to write software


application
transport

for network-core devices


network
data link application
physical transport
network-core devices do not network
data link
run user applications physical

applications on end systems


allows for rapid app
development, propagation

Application Layer 2-5


Application architectures
possible structure of applications:
client-server
peer-to-peer (P2P)

network architecture e.g., five-layer Internet architecture

application architecture how the application is structured over the


various end systems

Application Layer 2-6


Client-server architecture
ex. Web, FTP, Telnet, e-mail

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

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

data center housing a large number of hosts, is often used to create a powerful
Application Layer 2-7
virtual server
P2P architecture
no always-on server peer-to-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
Application Layer 2-8
Processes communicating
process: program clients, servers
running within a client process: process
host that initiates
within same host, two communication
processes server process:
communicate using process that waits to
inter-process be contacted
communication
(defined by OS) aside: applications
processes in different with P2P architectures
hosts communicate have client processes
by exchanging & server processes
messages

Application Layer 2-9


Sockets process: house
socket: door

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 process
controlled by
process app developer

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

Application Layer 2-10


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

Application Layer 2-11


What transport service does an
app need?
Reliable Data Transfer Throughput
some apps (e.g., file some apps (e.g.,
transfer, web transactions)
multimedia) require
require 100% reliable data
transfer minimum amount of
other apps (e.g., audio) can throughput to be
tolerate some loss (loss- effective
tolerant applications) (bandwidth-sensitive
applications)
Timing
other apps (elastic
some apps (e.g.,
Internet telephony, apps) make use of
interactive games) whatever throughput
Security
require low delay to be they get
encryption, data
effective
integrity, ...
how to select the available transport-layer protocol?
ex. select either train or airplane transport for travel between two cities
Application Layer 2-12
Transport service requirements:
common apps

Application Data Loss Throughput Time-Sensitive

File transfer / download no loss elastic no


E-mail no loss elastic no
Web documents no loss elastic (few kbps) no
Internet telephony / loss-tolerant audio: few kbps-1Mbps yes, 100s of msec
Video conferencing video:10kbps-5Mbps
Streaming stored loss-tolerant same as above yes, few secs
audio / video
interactive games loss-tolerant few kbps-10kbps yes, 100s of msec
Smartphone messaging no loss elastic yes and no

Application Layer 2-13


Internet transport protocols
services
TCP service: UDP service:
connection-oriented: connectionless
setup required between
client and server unreliable data transfer
processes between sending and
receiving process
reliable transport between
does not provide:
sending and receiving
process reliability, flow control,
congestion control,
flow control: sender wont timing, throughput
overwhelm receiver guarantee, security, or
congestion control: connection setup
throttle sender when
network overloaded
does not provide: timing, Q: why bother? Why is
there a UDP?
minimum throughput
guarantee, security
real-time applications
Application Layer 2-14
Internet apps: application, transport
protocols
Application- Underlying
Application Layer Protocol Transport Protocol

E-mail SMTP [RFC 5321] 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
Internet telephony SIP [RFC 3261],
RTP [RFC 3550],
or proprietary (e.g., Skype) UDP or TCP

Application Layer 2-15


Securing TCP

TCP & UDP SSL is at app layer


no encryption apps use SSL
cleartext passwds sent libraries, that talk
into socket traverse to TCP
Internet in cleartext SSL socket API
SSL cleartext passwords
provides encrypted
sent into socket
TCP connection
traverse Internet
data integrity encrypted
end-point see Chapter 8
authentication

Application Layer 2-16


App-layer protocol defines
types of messages open protocols:
exchanged, defined in RFCs
e.g., request,
response
allows for
message syntax: interoperability
what fields in
e.g., HTTP, SMTP
messages & how proprietary protocols:
fields are delineated e.g., Skype
message semantics
meaning of
information in fields define how an applications processes,
rules for when and how running on different end systems, pass
processes send & messages to each other
respond to messages

Application Layer 2-17


Chapter 2: outline
2.1 principles of 2.5 P2P applications
network 2.6 video streaming
applications and content
2.2 Web and HTTP distribution
2.3 electronic mail networks
SMTP, POP3, IMAP 2.7 socket
2.4 DNS programming
electronic communication
with UDP and TCP
technologies: telephone (1870s),
broadcast radio/television (1920s),
Internet
Web operates on demand, unlike
broadcast radio/television Application Layer 2-18
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,
http://www.someschool.edu/someDept/pic.gif
e.g.,
host name path name

URL (Uniform / Universal Resource Locator)


Application Layer 2-19
HTTP overview
HTTP: HyperText
Transfer Protocol HT
Webs application TP
req
ues
layer protocol PC running HT t
Firefox browser TP
client/server model res
p ons
client: browser that e
requests, receives, t
(using HTTP u es
protocol) and req server
TP nse
T po running
displays Web H
res
Apache Web
objects HT TP
server
server: Web server
sends (using HTTP
protocol) objects in iPhone running
response to requests Safari browser

Application Layer 2-20


HTTP overview (continued)
uses TCP: HTTP is stateless
client initiates TCP server maintains no
connection (creates information about
socket) to server, port 80 past client requests
server accepts TCP
connection from client aside
HTTP messages
(application-layer protocols that maintain
protocol messages) state are complex!
exchanged between past history (state) must
browser (HTTP client) be maintained
and Web server (HTTP if server/client crashes,
server) their views of state
TCP connection closed may be inconsistent,
must be reconciled

Application Layer 2-21


HTTP connections
non-persistent HTTP persistent HTTP
at most one multiple objects
object sent over can be sent over
TCP connection single TCP
connection then connection
closed between client,
downloading server
multiple objects
required multiple
connections

Application Layer 2-22


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 www.someSchool.edu
port 80 waiting for TCP
connection at port 80.
2. HTTP client sends HTTP accepts connection,
request message notifying client
(containing URL) into TCP 3. HTTP server receives
connection socket. request message, forms
Message indicates that response message
client wants object containing requested
someDepartment/home.i object, and sends
time ndex message into its socket
Application Layer 2-23
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

a base HTML file and 10 JPEG images require 11 TCP connections

the 11 TCP connections are serial or parallel?


the degree of parallelism can be configured in the browser
most browsers open 5 to 10 parallel TCP connections
Application Layer 2-24
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
request
and first few bytes of HTTP file
response to return time to
RTT
file transmission time transmit
file
non-persistent HTTP file
response time = received
2RTT+ file transmission
time time time

Application Layer 2-25


the server closes a connection when it isnt
Persistent HTTP used for a certain time

non-persistent HTTP persistent HTTP:


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

Application Layer 2-26


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
header Accept: text/html,application/xhtml+xml\r\n
Accept-Language: en-us,en;q=0.5\r\n
lines Accept-Encoding: gzip,deflate\r\n
carriage return, Accept-Charset: ISO-8859-1,utf-8;q=0.7\r\n
line feed at start Keep-Alive: 115\r\n
Connection: keep-alive\r\n
of line indicates \r\n
end of header lines
* Check out the online interactive exercises for more
examples: http://gaia.cs.umass.edu/kurose_ross/interactive/ Application Layer 2-27
HTTP request message: general
format
method sp URL sp version cr lf Request line
header field name: sp value cr lf

~
~ ~
~ Header lines

header field name: sp value cr lf


cr lf Blank line

~
~ entity body ~
~ Entity body

why need Entity Body ?

Application Layer 2-28


Uploading form input
POST method:
web page often
includes form input
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 Layer 2-29


Method
types
HTTP/1.0: HTTP/1.1:
GET GET, POST, HEAD
POST PUT
HEAD uploads file in
asks server to entity body to
leave requested path specified in
object out of URL field
response DELETE
deletes file
specified in the
URL field

Application Layer 2-30


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
lines Accept-Ranges: bytes\r\n
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
blank line \r\n
data, e.g., data data data data data ...
requested
HTML file
* Check out the online interactive exercises for more
examples: http://gaia.cs.umass.edu/kurose_ross/interactive/ Application Layer 2-31
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
Application Layer 2-32
Trying out HTTP (client side) for
yourself
1. Telnet to your favorite Web server:
telnet www.cgu.edu.tw 80 opens TCP connection to port 80
(default HTTP server port)
at www.cgu.edu.tw
anything typed in will be sent
to port 80 at www.cgu.edu.tw

2. type in a GET HTTP request:


GET / HTTP/1.1 by typing this in (hit carriage
return twice), you send
Host: www.cgu.edu.tw
this minimal (but complete)
GET /bin/home.php HTTP/1.1 GET request to HTTP server
Host: www.cgu.edu.tw
3. look at response message sent by HTTP server!
(or use Wireshark to look at captured HTTP request/response)
Application Layer 2-33
User-server state: cookies
many Web sites use example:
cookies Susan always access
four components: Internet from PC
1) cookie header line of visits specific e-commerce
HTTP response site for first time
message when initial HTTP
2) cookie header line in requests arrives at site,
next HTTP request site creates:
message
unique ID
3) cookie file kept on
users host, managed entry in backend
by users browser HTTP isdatabase for ID
a stateless protocol
4) back-end database Cookies, defined in the RFC 6265, allow
at Web site sites to keep track of users
Cookies can be used to create a user session
layer on top of stateless HTTP
Application Layer 2-34
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-


cookie: 1678 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
Application Layer 2-35
Cookies (continued)
aside
what cookies can cookies and privacy:
be used for: cookies permit sites
authorization to learn a lot about
shopping carts you
recommendations you may supply
user session state name and e-mail to
(Web e-mail) sites
how to keep state:
protocol endpoints: maintain
state at sender/receiver over
multiple transactions
cookies: http messages carry
state
Application Layer 2-36
Web caches (proxy server)
goal: satisfy client request without involving
origin server
user sets browser: Web
accesses via cache
browser sends all HTTP
requests to cache HT proxy
TP u est
object in cache: requ server req
H est T P se
client TTP HT o n
cache returns object res
pon P res
p origin
se T server
else cache requests HT
t
ues
object from origin req e
server, then returns TT P o ns
p
H r es
object to client T TP
H

client origin
server

Application Layer 2-37


More about Web caching
cache acts as why Web caching?
both client and reduce response time
server for client request
server for original reduce traffic on an
requesting client institutions access
client to origin server link
typically cache is Internet dense with
installed by ISP caches: enables
(university, poor content
company, providers to
residential
Proxy ISP) effectively deliver
content (so too does
proxy.cgu.edu.tw P2P file sharing)
3128 Application Layer 2-38
Caching example:
assumptions:
avg object size: 1 Mbits origin
avg request rate from servers
browsers to origin servers: 15 public
requests/sec Internet
avg data rate to browsers: 15 Internet delay
Mbps
RTT from institutional router
15 Mbps access delay
to any origin server: 2 sec
(15*1M)/100M = 0.15 access link
access link rate: 15 Mbps
problem! institutional
network LAN delay
consequences: 100 Mbps LAN
LAN utilization: 15%
access link utilization = 100%
total delay = Internet delay +
access delay + LAN delay
(15*1M)/15M = 1
= 2 sec + minutes + usecs
Application Layer 2-39
Caching example: fatter
access link
assumptions:
avg object size: 1 Mbits origin
avg request rate from servers
browsers to origin servers: 15 public
requests/sec Internet
avg data rate to browsers: 15
Mbps
RTT from institutional router 15 Mbps
to any origin server: 2100
sec access link
100 Mbps
Mbps = 0.15
(15*1M)/100M
access link rate: 15 Mbps institutional
network
consequences: 15% 100 Mbps LAN
LAN utilization: 15%
access link utilization = 100%
total delay = Internet delay +
access delay + LANmsecs
delay (15*1M)/100M = 0.15
= 2 sec + minutes + usecs
Cost: increased access link speed (not cheap!)
Application Layer 2-40
Caching example: install local
cache
assumptions:
avg object size: 1 Mbits origin
avg request rate from servers
browsers to origin servers: 15 public
requests/sec Internet
avg data rate to browsers: 15
Mbps
RTT from institutional router 15 Mbps
to any origin server: 2 sec access link
access link rate: 15 Mbps
institutional
network
consequences: ? 100 Mbps LAN
? 15%
LAN utilization:
access link utilization = 100% local web

How to compute link


total delay = Internet delay + cache
utilization,
access delay + LANdelay?
delay
= 2 sec + minutes + usecs
Cost: web cache (cheap!)
Application Layer 2-41
Caching example: install local
hit rate, typically range from 0.2 to 0.7
cache
Calculating access link
utilization, delay with
cache: origin
suppose cache hit rate is 0.4 servers
40% requests satisfied at cache, public
60% requests satisfied at origin Internet
access link utilization:
60% of requests use access link
data rate to browsers over 15 Mbps
access link access link
= 0.6*15 Mbps = 9 Mbps institutional
utilization = 9/15 = 0.6
total delay network
100 Mbps LAN
= 0.6 * (delay from origin
servers) + 0.4 * (delay when local web
satisfied at cache) cache
= 0.6 (2.01) + 0.4 (~msecs) =
~ 1.2 secs 40%: 0.01 sec
less than
traffic intensity with
on the 100link
access Mbps
1.0 link
0.6
(and cheaper too!)
60%: 2+0.01=2.01 sec
traffic intensity<0.8 a small delay Application Layer 2-42
Avg: 0.4*0.01+0.6*2.01=1.21
Cache stores Last -Modified date
Conditional GET along with an object, then uses this last-
modified date to check
client server
Goal: dont send
object if cache has up-
to-date cached version HTTP request msg
object
no object transmission If-modified-since: <date>
not
delay
modified
lower link utilization HTTP response
since
cache: specify date of HTTP/1.0
304 Not Modified <date>
cached copy in HTTP
request
If-modified-since:
<date>
server: response HTTP request msg
If-modified-since: <date> object
contains no object if
modified
cached copy is up-to- after
date: HTTP response
HTTP/1.0 200 OK <date>
HTTP/1.0 304 Not
Modified <data>
HTTP has a mechanism that allows a cache to verify that its objectsApplication
are up toLayer
date2-43
Chapter 2: outline
2.1 principles of 2.5 P2P applications
network 2.6 video streaming
applications and content
2.2 Web and HTTP distribution
2.3 electronic mail networks
SMTP, POP3, IMAP 2.7 socket
2.4 DNS programming
with UDP and TCP

Application Layer 2-44


Electronic mail outgoing
message queue
user mailbox
Three major components: user
user agents agent

mail servers mail user


Simple Mail Transfer server agent
Protocol: SMTP
SMTP mail user
User Agent server agent
a.k.a. mail reader SMTP
composing, editing, reading
SMTP user
mail messages agent
e.g., Outlook, Thunderbird, mail
server
iPhone mail client user
outgoing, incoming agent
messages stored on server
user
agent

Application Layer 2-45


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

Application Layer 2-46


Electronic Mail: SMTP [RFC
5321]
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)
commands: ASCII text
response: status code and phrase
messages must be in 7-bit ASCII

binary multimedia data must be encoded to ASCII before beingLayer


Application sent2-47
over
Scenario: Alice sends message
to Bob
1) Alice uses UA to 4) SMTP client sends
compose message to Alices message over
bob@someschool.edu the TCP connection
2) Alices UA sends 5) Bobs mail server
message to her mail places the message in
server; message placed Bobs mailbox
in message queue 6) Bob invokes his user
3) client side of SMTP agent to read message
opens TCP connection
with Bobs mail server

1 user mail user


mail agent
agent server server
2 3 6
4
5
Alices mail server Bobs mail server
Application Layer 2-48
S: SMTP Server

Sample SMTP interaction C: SMTP Client


the following transcript begins after the TCP connection is established
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

SMTP uses persistent connections Application Layer 2-49


Try SMTP interaction for yourself:
telnet servername 25
see 220 reply from server
enter HELO, MAIL FROM, RCPT TO, DATA, QUIT
commands

above lets you send email without using email


client (reader)

Application Layer 2-50


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

Application Layer 2-51


Mail message format
SMTP: protocol for
exchanging email
messages header
blank
RFC 5322 (RFC 822): line
standard for text
message format:
header lines, e.g.,
To:
body
From:
Subject:
different from SMTP
MAIL FROM, RCPT TO:
commands!
Body: the message
ASCII characters only
SMTP commands are part of the SMTP handshaking protocol
herein header lines are part of the mail message itself Application Layer 2-52
Mail access protocols
user mail access user
SMTP SMTP protocol
agent agent
(e.g., POP3,
IMAP, or HTTP)
senders mail receivers mail
server server Why need senders mail server?
SMTP: delivery/storage to receivers server
mail access protocol: retrieval from server
POP: Post Office Protocol [RFC 1939]: authorization,
download (port: 110)
IMAP: Internet Mail Access Protocol [RFC 3501]: more
features, including manipulation of stored messages on
server
HTTP: gmail, Hotmail, Yahoo! Mail, etc.

POP3 (Post Office Protocol Version 3)


Application Layer 2-53
POP3 protocol
S: +OK POP3 server ready
C: user bob
authorization phase S: +OK
client commands: C: pass hungry
user: declare username S: +OK user successfully logged on

pass: password C: list


server responses S: 1 498
+OK S: 2 912
-ERR S: .
transaction phase, client: C: retr 1
list: list message numbers S: <message 1 contents>
retr: retrieve message by S: .
number C: dele 1
dele: delete C: retr 2
quit S: <message 2 contents>
update phase S: .
Remove messages 1 and 2 C: dele 2
C: quit
S: +OK POP3 server signing off
Application Layer 2-54
POP3 (more) and IMAP
more about POP3 IMAP
previous example keeps all messages in
uses POP3 download one place: at server
and delete mode allows user to organize
messages in folders
Bob cannot re-read keeps user state across
e-mail if he sessions:
changes client names of folders and
POP3 download-and- mappings between
keep: copies of message IDs and folder
messages on name
Permit a user agent to obtain
different clients components of messages
POP3 is stateless ex. download just the message
header of a message with a
across sessions low-bandwidth connection

Application Layer 2-55


Web-Based E-Mail
HTTP SMTP
(Web-based e-mail)
browser

mail other mail


server servers

Many implementations of web-based e-mail


use an IMAP server to provide the folder
functionality
Running scripts in an HTTP server to use IMAP
protocol to communicate with an IMAP server
Chapter 2: outline
2.1 principles of 2.5 P2P applications
network 2.6 video streaming
applications and content
2.2 Web and HTTP distribution
2.3 electronic mail networks
SMTP, POP3, IMAP 2.7 socket
2.4 DNS programming
with UDP and TCP

Application Layer 2-57


UDP/TCP, port 53
DNS: domain name system RFC 1034, 1035

people: many identifiers: Domain Name System:


SSN, name, passport distributed database
# implemented in hierarchy
Internet hosts, routers: of many name servers
IP address (32-bit) - application-layer protocol:
used for addressing hosts, name servers
datagrams (routers communicate to resolve
prefer) names (address/name
name, e.g., translation)
www.yahoo.com - note: core Internet
used by humans function, implemented as
Q: how to map between IP application-layer protocol
address and name, and complexity at networks
vice versa? edge
birth certificate, SSN (Social Security Number), drivers license number
Hi. My name is 132-67-9875. Please meet husband, 178-87-1146.
Application Layer 2-58
IP, like a postal address, can be scanned from left to right, and get more info.
DNS: services, structure
DNS services why not centralize DNS?
hostname to IP single point of failure
address translation traffic volume
host aliasing distant centralized
canonical, alias database
names maintenance
mail server aliasing A: doesnt scale!
load distribution
replicated Web
servers: many IP
addresses DNS will rotate the ordering of the
correspond to onewithin each reply
address
name
a hostname may have one or more alias names, ex. www.udn.com,
www.udn.com.tw; www.yahoo.com.tw, yahoo.com.tw
Application Layer 2-59
mail server, ex. bob@hotmail.com relay1.west-coast.hotmail.com
DNS: a distributed, hierarchical
database
Root DNS Servers

Top-Level Domain ... ...

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
Authoritative DNS Server
client wants IP for www.amazon.com; 1 st approximation:
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

Application Layer 2-60


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
c. Cogent, Herndon, VA (5 other sites)
d. U Maryland College Park, MD
name server
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 logical root name


(5 other sites)
b. USC-ISI Marina del Rey, CA
servers worldwide
l. ICANN Los Angeles, CA
(41 other sites)
Each server is a network
g. US DoD Columbus, of replicated servers
OH (5 other sites)

Application Layer 2-61


TLD, authoritative servers
top-level domain (TLD) servers:
responsible for com, org, net, edu, gov, aero,
jobs, museums, and all top-level country
domains, e.g.: uk, fr, ca, jp, tw
The company Verisign Global Registry Services
maintains servers for .com TLD
The company Educause for .edu TLD
authoritative DNS servers:
organizations own DNS server(s), providing
authoritative hostname to IP mappings for
organizations named hosts
can be maintained by organization or service
provider
Application Layer 2-62
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

Application Layer 2-63


iterative queries
DNS name root DNS server

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

local DNS server


iterative query: dns.poly.edu
contacted server 7 6
1 8
replies with name
of server to
authoritative DNS server
contact dns.cs.umass.edu
I dont know this requesting host
cis.poly.edu
name, but ask this
server recursive queries
gaia.cs.umass.edu

Application Layer 2-64


DNS name root DNS server

resolution
example 2 3
recursive query: 7
6
puts burden of TLD DNS
name resolution server

on contacted local DNS server


name server dns.poly.edu 5 4

heavy load at 1 8
upper levels of
authoritative DNS server
hierarchy? dns.cs.umass.edu
requesting host
cis.poly.edu

gaia.cs.umass.edu

Application Layer 2-65


DNS: caching, updating
records
In order to improve the delay performance and
to reduce the number of DNS messages
once (any) name server learns mapping, it
caches mapping
cache entries timeout (disappear) after some time
(TTL) (often set to two days)
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

Application Layer 2-66


DNS records
DNS: distributed database storing resource records (RR)
RR format: (name, value, type, ttl)
ttl: time to live

type=A type=CNAME
name is hostname name is alias name for some
value is IP address canonical (the real) name
(relay1.bar.foo.com, 145.37.93.126, A) www.ibm.com is really
servereast.backup2.ibm.com
type=NS value is canonical name
name is domain (e.g., (foo.com, relay1.bar.foo.com, CNAME)
foo.com)
value is hostname of type=MX
authoritative name value is name of
server for this domain
mailserver associated with
(foo.com, dns.foo.com, NS) name mail.bar.foo.com,
(foo.com, Application Layer 2-67
MX)
DNS protocol, messages
query and reply messages, both with same message format

2 bytes 2 bytes

message header identification flags

identification: 16-bit # # questions # answer RRs


for query, reply to
# authority RRs # additional RRs
query uses same #
flags: questions (variable # of questions)
query or reply
recursion desired answers (variable # of RRs)
recursion available
reply is authoritative authority (variable # of RRs)

additional info (variable # of RRs)

Application Layer 2-68


DNS protocol, messages
nslookup program

ex. the answer field a mail server and its canonical hostname
the additional information IP address for the canonical hostname
2 bytes 2 bytes

identification flags

# questions # answer RRs

# authority RRs # additional RRs

name, type fields questions (variable # of questions)


for a query
RRs in
response answers (variable # of RRs)
to query
records for authority (variable # of RRs)
authoritative servers
additional helpful additional info (variable # of RRs)
info that may be used
Application Layer 2-69
Inserting records into DNS
example: new startup Network Utopia
register name networkutopia.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.networkutopia.com; type MX record for
networkutopia.com
How do people get IP address of your Web site?

a complete list of accredited registrars http://www.internic.net


http://www.twnic.net Application Layer 2-70
Attacking DNS
DDoS attacks redirect attacks
bombard root servers Man-in-the-Middle
with traffic (DDoS Intercept queries
attack took place on DNS poisoning
October 21, 2002) Send bogus relies to
not successful to date DNS server, which
traffic filtering caches
local DNS servers cache exploit DNS for DDoS
IPs of TLD servers,
allowing root server send queries with
bypass spoofed source
bombard TLD servers address: target IP
potentially more requires
dangerous amplification

Application Layer 2-71


Chapter 2: outline
2.1 principles of 2.5 P2P applications
network 2.6 video streaming
applications and content
2.2 Web and HTTP distribution
2.3 electronic mail networks
SMTP, POP3, IMAP 2.7 socket
2.4 DNS programming
with UDP and TCP

Application Layer 2-72


Pure P2P architecture
no always-on server
arbitrary end systems
directly communicate
peer-to-peer
peers are
intermittently
connected and change
IP addresses
examples:
file distribution
(BitTorrent)
Streaming (KanKan,
PPLive, ppstream)
VoIP (Skype)

Application Layer 2-73


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

u1 di: peer i download


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

Application Layer 2-74


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

client: each client must


download file copy
dmin = min. client
download rate
min. client download
time: F/dtomindistribute F
time
to N clients using Dcs > max{NF/us,,F/dmin}
client-server approach

increases linearly in N
Application Layer 2-75
File distribution time: P2P
server transmission:
must upload at least F
us
one copy
di
time to
client: sendclient
each one copy:
must network
F/us
download file copy ui
min. client download time:
F/dmin
clients: as aggregate must download NF
bits
max. upload rate (limiting 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
Application Layer 2-76
Client-server vs. P2P: example
client upload rate = u, F/u = 1 hour, us = 10u, dmin us

Application Layer 2-77


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

tracker: tracks peers torrent: group of


participating in torrent peers exchanging
chunks of a file

Alice arrives ...


... obtains list
of peers from tracker
... and begins exchanging
file chunks with peers in torrent

Application Layer 2-78


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 Application Layer 2-79
BitTorrent: requesting, sending file
chunks
requesting chunks: sending chunks: tit-for-
at any given time, tat
different peers have Alice sends chunks to
different subsets of file those four peers currently
chunks sending her chunks at
periodically, Alice asks highest rate
each peer for list of other peers are choked by
chunks that they have Alice (do not receive chunks
Alice requests missing from her)
chunks from peers, re-evaluate top 4 every10
rarest first secs
every 30 secs: randomly
select another peer,
starts sending chunks
optimistically unchoke this
peer Application Layer 2-80
BitTorrent: tit-for-tat
(1) Alice optimistically unchokes Bob
(2) Alice becomes one of Bobs top-four providers; Bob reciprocat
(3) Bob becomes one of Alices top-four providers

higher upload rate: find


better trading partners,
get file faster !
Application Layer 2-81
Chapter 2: outline
2.1 principles of 2.5 P2P applications
network 2.6 video streaming
applications and content
2.2 Web and HTTP distribution
2.3 electronic mail networks (CDNs)
SMTP, POP3, IMAP 2.7 socket
2.4 DNS programming
with UDP and TCP

Application Layer 2-82


Video Streaming and CDNs:
context
video traffic: major consumer of Internet bandwidth
Netflix, YouTube: 37%, 16% of downstream
residential ISP traffic
~1B YouTube users, ~75M Netflix users
challenge: scale - how to reach ~1B
users?
single mega-video server wont work (why?)
challenge: heterogeneity
different users have different capabilities (e.g.,
wired versus mobile; bandwidth rich versus
bandwidth poor)
solution: distributed, application-level
infrastructure

Application Layer 2-83


Multimedia: spatial coding example: instead
of sending N values of same
color (all purple), send only two

video
video: sequence of
values: color value (purple) and
number of repeated values (N)

images displayed at ..
..
constant rate
e.g., 24 images/sec
digital image: array of
pixels
each pixel represented
by bits
frame i
coding: use redundancy
within and between
images to decrease #
bits used to encode
temporal coding example:
image instead of sending
spatial (within image) complete frame at i+1,
send only differences from
temporal (from one frame i frame i+1
image to next)

Application Layer 2-84


Multimedia: spatial coding example: instead
of sending N values of same
color (all purple), send only two

video
CBR: (constant bit
values: color value (purple) and
number of repeated values (N)

rate): video encoding ..


..
rate fixed
VBR: (variable bit
rate): video encoding
rate changes as
amount of spatial,
temporal coding frame i
changes
examples:
MPEG 1 (CD-ROM) temporal coding example:
1.5 Mbps instead of sending
complete frame at i+1,
MPEG2 (DVD) 3-6 send only differences from
frame i+1
frame i
Mbps
MPEG4 (often used Application Layer 2-85
Streaming stored video:
simple scenario:

Internet

video server client


(stored video)

Application Layer 2-86


Streaming multimedia:
DASH
DASH: Dynamic, Adaptive Streaming over
HTTP
server:
divides video file into multiple chunks
each chunk stored, encoded at different rates
manifest file: provides URLs for different chunks
client:
periodically measures server-to-client bandwidth
consulting manifest, requests one chunk at a time
chooses maximum coding rate sustainable
given current bandwidth
can choose different coding rates at different
points in time (depending on available
bandwidth at time)
Application Layer 2-87
Streaming multimedia:
DASH
DASH: Dynamic, Adaptive Streaming
over HTTP
intelligence at client: client
determines
when to request chunk (so that buffer
starvation, or overflow does not occur)
what encoding rate to request (higher
quality when more bandwidth available)
where to request chunk (can request from
URL server that is close to client or has
high available bandwidth)

Application Layer 2-88


Content distribution
networks
challenge: how to stream content
(selected from millions of videos) to
hundreds of thousands of simultaneous
users?

option 1: single, large mega-server


single point of failure
point of network congestion
long path to distant clients
multiple copies of video sent over outgoing link

....quite simply: this solution doesnt scale


Application Layer 2-89
Content distribution
networks
challenge: how to stream content (selected
from millions of videos) to hundreds of
thousands of simultaneous users?

option 2: store/serve multiple copies of


videos at multiple geographically distributed
sites (CDN)
enter deep: push CDN servers deep into many
access networks
close to users
used by Akamai, 1700 locations
bring home: smaller number (10s) of larger
clusters in POPs near (but not within) access
networks
used by Limelight
Application Layer 2-90
Content Distribution Networks
(CDNs)
CDN: stores copies of content at CDN
nodes
e.g. Netflixrequests
subscriber content
stores copies from CDN
of MadMen
directed to nearby copy, retrieves content
may choose different copy if network path
congested

manifest file


wheres Madmen?


Application Layer 2-91
Content Distribution Networks
(CDNs)

over the top


Internet host-to-host communication as a service


OTT challenges: coping with a congested
Internet
from which CDN node to retrieve content?

viewer behavior in presence of congestion?

what content to place in which CDN node?
more .. in chapter 9
CDN content access: a closer
look
Bob (client) requests video http://netcinema.com/6Y
video stored in CDN at http://KingCDN.com/NetC6y&B23V

1. Bob gets URL for video


http://netcinema.com/6Y7B23V
from netcinema.com web page 2. resolve http://netcinema.com/6Y7B23V
2 via Bobs local DNS
1 6. request video
from KINGCDN 5 Bobs
server, streamed local DNS
via HTTP server
4&5. Resolve
netcinema.com 3. netcinemas DNS returns URL
4 http://KingCDN.com/NetC6y&B23
http://KingCDN.com/NetC6y&B23V
via KingCDNs authoritative DNS,
3 which returns IP address of KingCDN
server with video
netcinemas
authoratative DNS KingCDN.com KingCDN
authoritative DNS Application Layer 2-93
Case study: Netflix
Amazon cloud upload copies of
multiple versions of
video to CDN servers
CDN
server
Netflix registration,
accounting servers
3. Manifest file
2. Bob browses returned for
requested video CDN
Netflix video 2 server
3
1

1. Bob manages
Netflix account CDN
server

4. DASH streaming

Application Layer 2-94


Chapter 2: outline
2.1 principles of 2.5 P2P applications
network 2.6 video streaming
applications and content
2.2 Web and HTTP distribution
2.3 electronic mail networks
SMTP, POP3, IMAP 2.7 socket
2.4 DNS programming
with UDP and TCP

Application Layer 2-95


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

application application
socket process
controlled by
process app developer

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

Application Layer 2-96


Socket programming
Two socket types for two transport services:
UDP: connectionless, unreliable datagram
TCP: connection-oriented, reliable, byte-stream
channel

Application Example:
1. client reads a line of characters (data)
from its keyboard and sends data to
server
2. server receives the data and converts
characters to uppercase
3. server sends modified data to client
4. client receives modified data and Application Layer 2-97
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
receiver 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

Application Layer 2-98


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 serverIP and
port=x; send datagram via
Read UDP datagram from clientSocket
serverSocket

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

Application 2-99
Example app: UDP client
Python UDPClient
include Pythons socket
library from socket import *
serverName = hostname
serverPort = 12000
create UDP socket for clientSocket = socket(AF_INET,
client
SOCK_DGRAM)
get user keyboard
input message = raw_input(Input lowercase sentence:)
Attach server name, port to
message; send into socket
clientSocket.sendto(message.encode(),
(serverName, serverPort))
read reply characters from
modifiedMessage, serverAddress =
socket into string
clientSocket.recvfrom(2048)
print out received string
and close socket
print(modifiedMessage.decode())
clientSocket.close()
Application Layer 2-100
Example app: UDP server
Python UDPServer
from socket import *
serverPort = 12000
create UDP socket serverSocket = socket(AF_INET, SOCK_DGRAM)
bind socket to local port
number 12000 serverSocket.bind(('', serverPort))
print(The server is ready to receive)
loop forever
while True:
Read from UDP socket into
message, getting clients
message, clientAddress = serverSocket.recvfrom(2048)
address (client IP and port) modifiedMessage = message.decode().upper()
send upper case string serverSocket.sendto(modifiedMessage.encode(),
back to this client
clientAddress)

Application Layer 2-101


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

Application Layer 2-102


Client/server socket interaction:
TCP
server (running on serverIP) client
create socket,
port=x, for incoming
request:
serverSocket = socket()

wait for incoming create socket,


connection request TCP connect to serverIP, 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

Application Layer 2-103


Example app: TCP client
Python TCPClient
from socket import *
serverName = servername
create TCP socket for serverPort = 12000
client, remote port 12000
clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket.connect((serverName, serverPort))
sentence = raw_input(Input lowercase sentence:)
No need to attach server
name, port clientSocket.send(sentence.encode())
modifiedSentence = clientSocket.recv(1024)
print(From Server:, modifiedSentence.decode())
clientSocket.close()

Application Layer 2-104


Example app: TCP server
Python TCPServer
from socket import *
create TCP welcoming serverPort = 12000
socket serverSocket = socket(AF_INET, SOCK_STREAM)
serverSocket.bind((, serverPort))
server begins listening for
incoming TCP requests serverSocket.listen(1)
print(The server is ready to receive)
loop forever
while True:
server waits on accept()
for incoming requests, new
connectionSocket, addr = serverSocket.accept()
socket created on return

read bytes from socket (but


sentence = connectionSocket.recv(1024).decode()
not address as in UDP) capitalizedSentence = sentence.upper()
close connection to this connectionSocket.send(capitalizedSentence.
client (but not welcoming
socket) encode())
connectionSocket.close()
Application Layer 2-105
Chapter 2:
summary
our study of network apps now complete!
application architectures specific protocols:
client-server
HTTP
P2P
application service SMTP, POP, IMAP
requirements:
DNS
reliability, bandwidth, delay
Internet transport service P2P: BitTorrent
model video streaming,
connection-oriented,
reliable: TCP CDNs
unreliable, datagrams: UDP socket programming:
TCP, UDP sockets

Application Layer 2-106


Chapter 2:
summary
most importantly: learned about
protocols!
typical request/reply important themes:
message exchange:
client requests info control vs. data
or service messages
server responds with in-band, out-of-band
data, status code
message formats:
centralized vs.
headers: fields giving decentralized
info about data stateless vs. stateful
data: info (payload) reliable vs. unreliable
being communicated
message transfer
complexity at network
edge
Application Layer 2-107

Potrebbero piacerti anche