Download as pdf or txt
Download as pdf or txt
You are on page 1of 48

Chapter 2

Application Layer

Dr/ Hala Hassan


User-server state: cookies
example:
many Web sites use
cookies  Susan always access Internet
four components: from PC
1) cookie header line of HTTP  visits specific e-commerce
response message
site for first time
2) cookie header line in next
HTTP request message  when initial HTTP requests
3) cookie file kept on user’s host, arrives at site, site creates:
managed by user’s browser
• unique ID
4) back-end database at Web site
• entry in backend database for ID

Application Layer 2-2


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
Application Layer 2-3
usual http response msg action
Cookies (continued)
what cookies can be used for: aside
cookies and privacy:
 authorization
 cookies permit sites to
 shopping carts learn a lot about you
 recommendations  you may supply name and
 user session state (Web e-mail to sites
e-mail)

how to keep “state”:


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

Application Layer 2-4


Web caches (proxy server)
goal: satisfy client request without involving origin server
 user
sets browser: Web
accesses via cache
 browsersends all HTTP proxy
server
requests to cache client
origin
 object in cache: cache returns server
object
 else cache requests object
from origin server, then returns
object to client

client origin
server
Application Layer 2-5
More about Web caching

 cache acts as both client and why Web caching?


server
 reduce response time for client
 server for original request
requesting client  reduce traffic on an institution’s
 client to origin server access link

 typically cache is installed by  Internet dense with caches:


ISP (university, company, enables “poor” content providers to
residential ISP) effectively deliver content (so too
does P2P file sharing)

Application Layer 2-6


Caching example:
assumptions:
 avg object size: 100K bits
 avg request rate from origin
browsers to origin servers
servers:15/sec public
 avg data rate to browsers: 1.50 Internet

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

Mbps
 RTT from institutional router
to any origin server: 2 sec 1.54 Mbps
154 Mbps
 access link rate: 1.54 Mbps access link
154 Mbps institutional
consequences: network
 LAN utilization: 15% 9.9% 1 Gbps LAN
 access link utilization = 99%
 total delay = Internet delay + access
delay + LAN delay
= 2 sec + minutes + usecs
msecs 2-8

Cost: increased access link speed (not cheap!)


Caching example: install local cache
assumptions:
 avg object size: 100K bits
 avg request rate from browsers to origin
origin servers:15/sec servers
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
consequences: 1.54 Mbps
 LAN utilization: 15% access link
 access link utilization = 100% institutional
 total delay = Internet delay + access network
delay + LAN delay ? 1 Gbps LAN
= 2 sec + minutes? + usecs
local web
How to compute link cache
utilization, delay?
Application Layer 2-9
Cost: web cache (cheap!)
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, servers
60% requests satisfied at origin public
Internet

 access link utilization:


 60% of requests use access link
 data rate to browsers over access 1.54 Mbps
link access link
= 0.6*1.50 Mbps = .9 Mbps institutional
 utilization = 0.9/1.54 = .58 network
1 Gbps LAN
 total delay
 = 0.6 * (delay from origin servers) +0.4 local web
* (delay when satisfied at cache) cache
 = 0.6 (2.01) + 0.4 (~msecs) = ~ 1.2 secs
 less than with 154 Mbps link (and
cheaper too!) 2-10
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 If-modified-since: <date> object
no object if cached copy modified
is up-to-date: HTTP response after
HTTP/1.0 304 Not HTTP/1.0 200 OK <date>
Modified
Application Layer <data>2-11
Chapter 2: outline

2.1 principles of network applications 2.5 P2P applications


2.2 Web and HTTP 2.6 video streaming and content
distribution networks
2.3 electronic mail
• SMTP, POP3, IMAP
2.7 socket programming with UDP
and TCP
2.4 DNS

Application Layer 2-12


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 mail
agent

 e.g., Outlook, Thunderbird, server


iPhone mail client user
agent
 outgoing, incoming messages
stored on server user
agent
Application Layer 2-13
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 SMTP user
mail servers to send mail
agent

email messages server


user
 client: sending mail server agent
 “server”: receiving mail server user
agent
Application Layer 2-14
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)


 commands: ASCII text
 response: status code and phrase
 messages must be in 7-bit ASCI

Application Layer 2-15


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
her mail server; message the message in Bob’s
placed in message queue
mailbox
3) client side of SMTP opens
TCP connection with Bob’s
6) Bob invokes his user
mail server agent to read message

1 user mail user


mail agent
agent server server
2 3 6
4
5
Application Layer Alice’s mail server 2-16
Bob’s mail server
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
Application Layer 2-17
SMTP: final words

comparison with HTTP:


 SMTP uses persistent
connections  HTTP: pull

 SMTP requires message  SMTP: push


(header & body) to be  both have ASCII
in 7-bit 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-18
Mail message format

SMTP: protocol for


exchanging email header
messages 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
Application Layer 2-19
Mail access protocols

user
mail access user
SMTP SMTP protocol
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 messages on server
 HTTP: gmail, Hotmail, Yahoo! Mail, etc.

Application Layer 2-20


POP3 protocol
S: +OK POP3 server ready
C: user bob
authorization phase S: +OK
 client commands: C: pass hungry
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: .
C: dele 2
 quit C: quit
Application Layer S: +OK POP3 2-21
server signing off
POP3 (more) and IMAP
more about POP3 IMAP
 previous example uses  keeps all messages in
POP3 “download and one place: at server
delete” mode
 Bob cannot re-read e-mail if he  allows user to organize
changes client messages in folders
 POP3 “download-and-  keeps user state across
keep”: copies of
sessions:
messages on different
clients  names of folders and mappings
between message IDs and
 POP3 is stateless across folder name
sessions

Application Layer 2-22


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

Application Layer 2-23


DNS: domain name system
Domain Name System:
people: many identifiers:
 SSN, name, passport #  distributed database
implemented in hierarchy
Internet hosts, routers: of many name servers
 IP address (32 bit) - used for
addressing datagrams  application-layer protocol:
 “name”, e.g., www.yahoo.com
hosts, name servers
- used by humans communicate to resolve
names (address/name
Q: how to map between
translation)
IP address and name,
 note: core Internet
and vice versa ? function, implemented as
application-layer protocol
 complexity at network’s
Application Layer
“edge” 2-24
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 A: doesn‘t scale!
 load distribution
 replicated Web servers: many
IP addresses correspond to one
name

Application Layer 2-25


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 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-26
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


(5 other sites)
b. USC-ISI Marina del Rey, CA
13 logical root name
l. ICANN Los Angeles, CA “servers” worldwide
(41 other sites)
g. US DoD Columbus, •each “server” replicated
OH (5 other sites)
many times
2-27
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

Application Layer 2-28


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-29


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

iterated query: local DNS server


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

server” cis.poly.edu

gaia.cs.umass.edu
Application Layer 2-30
DNS name root DNS server
resolution example
2 3
recursive query: 7
6
 puts burden of name TLD DNS
resolution on server
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
Application Layer 2-31
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

Application Layer 2-32


DNS records
DNS: distributed database storing resource records (RR)

RR format: (name, value, type, ttl)

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

2 bytes 2 bytes

message header identification flags

 identification: 16 bit # for # questions # answer RRs


query, reply to query # authority RRs # additional RRs
uses same #
 flags: questions (variable # of questions)

 query or reply
 recursion desired answers (variable # of RRs)

 recursion available
authority (variable # of RRs)
 reply is authoritative
additional info (variable # of RRs)
Application Layer 2-34
DNS protocol, messages

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
Application may be used
Layer 2-35
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

Application Layer 2-36


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

Application Layer 2-37


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)

Application Layer 2-38


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
Application Layer 2-39
File distribution time: client-server

 server transmission: must


sequentially send (upload) N F
us
file copies: di
 time to send one copy: F/us network
ui
 time to send N copies: NF/us
 client: each client must
download file copy
• dmin = min client download rate
• min client download time: F/dmin

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

increases linearly in N
Application Layer
2-40
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 file network
copy ui
• min client download time: F/dmin
 clients: as aggregate must download NF bits
• max upload rate (limiting max download rate) is us + Sui

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

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

3.5
P2P
Minimum Distribution Time

3
Client-Server
2.5

1.5

0.5

0
0 5 10 15 20 25 30 35

Application Layer N 2-42


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
Application Layer 2-43
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-44
BitTorrent: requesting, sending file chunks

requesting chunks: sending chunks: tit-for-tat


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

Application Layer 2-45


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 !
Application Layer 2-46
Quiz

1. At point 2 in the diagram, what protocol is being used?


2. At point 4 in the diagram, what protocol is being used?
3. At point 6 in the diagram, what protocol is being used?
4. Does SMTP use TCP or UDP?
5. Is SMTP a 'push' or 'pull' protocol?
6. Is IMAP a 'push' or 'pull' protocol?
7. What port does SMTP use?

You might also like