You are on page 1of 99

Lecture_05

Application
Layer
Application layer: overview
 P2P applications
 Principles of network  video streaming and content
applications distribution networks
 Web and HTTP  socket programming with
 E-mail, SMTP, IMAP UDP and TCP
 The Domain Name System
DNS

Application Layer: 2-2


Maintaining user/server state: cookies
a stateful protocol: client makes
Recall: HTTP GET/response two changes to X, or none at all
interaction is stateless
X
 no notion of multi-step exchanges of
HTTP messages to complete a Web lock data
record X
X
“transaction” OK
update X
• no need for client/server to track X’
X’
“state” of multi-step exchange OK
t’ update X
• all HTTP requests are independent of X’’
X’’
each other unlock X
OK

• no need for client/server to “recover”


OK X’’
from a partially-completed-but-never-
time time
completely-completed transaction
Q: what happens if network connection or
client crashes at t’ ?
Application Layer: 2-3
Maintaining user/server state: cookies
Web sites and client browser use Example:
cookies to maintain some state  Susan uses browser on laptop,
visits specific e-commerce site
between transactions for first time
four components:  when initial HTTP requests
1) cookie header line of HTTP response arrives at site, site creates:
message • unique ID (aka “cookie”)
• entry in backend database
2) cookie header line in next HTTP for ID
request message
• subsequent HTTP requests
3) cookie file kept on user’s host, from Susan to this site will
managed by user’s browser contain cookie ID value,
4) back-end database at Web site allowing site to “identify”
Susan
Application Layer: 2-4
Maintaining user/server state: cookies
client
Amazon server
ebay 8734
usual HTTP request msg Amazon server
cookie file creates ID
usual HTTP response 1678 for user backend
create
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
time time Application Layer: 2-6
HTTP cookies: comments
aside
What cookies can be used for: cookies and privacy:
 authorization  cookies permit sites to
 shopping carts learn a lot about you on
their site.
 recommendations  third party persistent
 user session state (Web e-mail) cookies (tracking cookies)
allow common identity
(cookie value) to be
Challenge: How to keep state? tracked across multiple
 at protocol endpoints: maintain state at web sites
sender/receiver over multiple
transactions
 in messages: cookies in HTTP messages
carry state
Application Layer: 2-7
Example: displaying a NY Times web page
1 GET base html file
2
from nytimes.com

4 fetch ad from nytimes.com


5
AdX.com
HTTP 1
GET 2 HTTP
7 display composed reply
page

3 4
6 5

NY times page with


embedded ad displayed AdX.com
Cookies: tracking a user’s browsing behavior

1634: sports, 2/15/22

nytimes.com (sports) “first party” cookie –


from website you chose
to visit (provides base
HTTP HTTP
GET reply html file)
Set cookie: 1634

HTTP GET
Referrer: NY Times Sports
4
7493: NY Times sports, 2/15/22
5
“third party” cookie – HTTP reply
from website you did not NY Times: 1634 Set cookie: 7493
choose to visit AdX: 7493
AdX.com
Cookies: tracking a user’s browsing behavior

1634: sports, 2/15/22

nytimes.com AdX:
HTTP  tracks my web browsing
socks.com reply
over sites with AdX ads
2
HTTP 1  can return targeted ads
GET based on browsing history
HTTP GET
Referrer: socks.com, cookie: 7493
4
7493: NY Times sports, 2/15/22
5 7493: socks.com, 2/16/22
HTTP reply
NY Times: 1634 Set cookie: 7493
AdX: 7493
AdX.com
Cookies: tracking a user’s browsing behavior (one day later)

1634: sports, 2/15/22


1634: arts, 2/17/22

nytimes.com (arts)
socks.com HTTP HTTP
GET reply
cookie: 1634 Set cookie: 1634

HTTP GET
Referrer: nytimes.com, cookie: 7493
4
7493: NY Times sports, 2/15/22
5 7493: socks.com, 2/16/22
HTTP reply 7493: NY Times arts, 2/15/22
NY Times: 1634 Set cookie: 7493
AdX: 7493 Returned ad for socks!
AdX.com
Cookies: tracking a user’s browsing behavior
Cookies can be used to:
 track user behavior on a given website (first party cookies)
 track user behavior across multiple websites (third party cookies)
without user ever choosing to visit tracker site (!)
 tracking may be invisible to user:
• rather than displayed ad triggering HTTP GET to tracker, could be an invisible
link

third party tracking via cookies:


 disabled by default in Firefox, Safari browsers
 to be disabled in Chrome browser in 2023
GDPR (EU General Data Protection Regulation) and cookies
“Natural persons may be associated with online
identifiers […] such as internet protocol addresses,
cookie identifiers or other identifiers […].
This may leave traces which, in particular when
combined with unique identifiers and other
information received by the servers, may be used to
create profiles of the natural persons and identify
them.”
GDPR, recital 30 (May 2018)

User has explicit control over


when cookies can identify an individual, cookies whether or not cookies are
are considered personal data, subject to GDPR allowed
personal data regulations
Web caches (Proxy Server)
Goal: satisfy client requests without involving origin server
 user configures browser to
point to a (local) Web cache HT T
P re
Web
uest
que cache P re
q
H s T nse
 browser sends all HTTP client T TP r
esp
ons
t H T
P resp o origin
T server
requests to cache est
e HT
u
• if object in cache: cache P req se
T T o n
H esp
returns object to client HT
TP
r

• else cache requests object


client
from origin server, caches
received object, then Typically a Web cache is purchased and installed by an ISP.
returns object to client For example, a university might install a cache on its campus network
and configure all of the campus browsers to point to the cache
Application Layer: 2-14
Web caches ( proxy servers)
 Web cache acts as both Why Web caching?
client and server
 reduce response time for client
• server for original
requesting client request
• client to origin server • cache is closer to client
 reduce traffic on an institution’s
 server tells cache about
object’s allowable caching in access link
response header:  Internet is dense with caches
• enables “poor” content providers
to more effectively deliver content

Application Layer: 2-15


Caching example
Scenario:
 access link rate: 15 Mbps origin
 RTT from institutional router to server: 2 sec servers
public
 Avg web object size: 1 Mbps Internet
 average request rate from browsers to origin
servers: 15 requests /sec
15 Mbps
access link
Performance:
institutional
LAN Traffic: (15 requests/sec)⋅(1 Mbits/request)/(100 Mbps)=0.15 network
100 Mbps LAN
Access Link Traffic: (15 requests/sec)⋅(1 Mbits/request)/(15 Mbps)=1
A traffic intensity of 0.15 on a LAN typically results in, at most, tens of
milliseconds of delay; hence, we can neglect the LAN delay.
However, as the traffic intensity approaches 1 (as is the case of the access link
the delay on a link becomes very large and grows without bound. Thus, the
average response time to satisfy requests is going to be on the order of minutes
Solution 1: buy a faster access link

origin
servers
public
Internet

Cost: faster access link (expensive!)


100Mbps
access link
institutional
network
100 Mbps LAN

Application Layer: 2-17


Option 2: install a web cache
Cost: web cache (cheap!)
• Hit rates—the fraction of requests that are satisfied by a cache— typically range
from 0.2 to 0.7 in practice. For illustrative purposes, let’s suppose that the cache
provides a hit rate of 0.4 for this institution.
origin
• Because the clients and the cache are connected to the same high-speed LAN, servers
public
40 percent of the requests will be satisfied almost immediately, say, within Internet
10 milliseconds, by the cache.

• Nevertheless, the remaining 60 percent of the requests still need to be satisfied by


the origin servers. But with only 60 percent of the requested objects passing through 15 Mbps
the access link, the traffic intensity on the access link is reduced from 1.0 to 0.6. access link
institutional
• Typically, a traffic intensity less than 0.8 corresponds to a small delay, say, network 100 Mbps LAN
tens of milliseconds, on a 15 Mbps link.

• This delay is negligible compared with the two-second Internet delay.

local web cache

Application Layer: 2-18


Calculating access link utilization, end-end delay with cache:

suppose cache hit rate is 0.4:


 40% requests served by cache, with low origin
servers
(msec) delay public
 60% requests satisfied at origin Internet

• rate to browsers over access link


= 0.6 * 15 Mbps = 9 Mbps
1.54 Mbps
• access link utilization = 9/15 = 0.6 ms low access link
queueing delay at access link institutional
 average end-end delay: network
1 Gbps LAN
= 0.6 * (delay from origin servers)
+ 0.4 * (delay when satisfied at cache)
= 0.6 (2.01 sec) + 0.4 (0.01 sec) = ~ 1.2 secs local web cache

lower average end-end delay than with 15 Mbps link (and cheaper too!)
Application Layer: 2-19
Browser caching: Conditional GET
client server
Goal: don’t send object if browser
HTTP request msg
has up-to-date cached version If-modified-since: <date> object
• no object transmission delay (or use not
modified
of network resources) HTTP response
before
HTTP/1.0
 client: specify date of browser- 304 Not Modified <date>

cached copy in HTTP request


If-modified-since: <date>
 server: response contains no HTTP request msg
If-modified-since: <date> object
object if browser-cached copy is modified
up-to-date: HTTP response after
HTTP/1.0 200 OK <date>
HTTP/1.0 304 Not Modified <data>

Application Layer: 2-20


HTTP/2
Key goal: decreased delay in multi-object HTTP requests
HTTP1.1: introduced multiple, pipelined GETs over single TCP
connection
 server responds in-order (FCFS: first-come-first-served scheduling) to
GET requests
 with FCFS, small object may have to wait for transmission (head-of-
line (HOL) blocking) behind large object(s)
 loss recovery (retransmitting lost TCP segments) stalls object
transmission

Application Layer: 2-21


HTTP/2
Key goal: decreased delay in multi-object HTTP requests
HTTP/2: [RFC 7540, 2015] increased flexibility at server in sending
objects to client:
 methods, status codes, most header fields unchanged from HTTP 1.1
 transmission order of requested objects based on client-specified
object priority (not necessarily FCFS)
 push unrequested objects to client
 divide objects into frames, schedule frames to mitigate HOL blocking

Application Layer: 2-22


HTTP/2: mitigating HOL blocking
HTTP 1.1: client requests 1 large object (e.g., video file) and 3 smaller
objects
server

GET O4 GET O3 GET O2 GET O1 object data requested


client

O1

O2
O1
O2 O3
O3
O4
O4

objects delivered in order requested: O2, O3, O4 wait behind O1 Application Layer: 2-23
HTTP/2: mitigating HOL blocking
HTTP/2: objects divided into frames, frame transmission interleaved
server

GET O4 GET O3 GET O2 GET O1 object data requested


client
O2
O4
O3 O1

O2
O3
O1 O4

O2, O3, O4 delivered quickly, O1 slightly delayed Application Layer: 2-24


HTTP/2 to HTTP/3
 HTTP/3: adds security, per object error- and congestion-
control (more pipelining) over UDP
• more on HTTP/3 in transport layer

Application Layer: 2-25


Application layer: overview
 P2P applications
 Principles of network  video streaming and content
applications distribution networks
 Web and HTTP  socket programming with
 E-mail, SMTP, IMAP UDP and TCP
 The Domain Name System
DNS

Application Layer: 2-26


E-mail user
agent
Three major components: mail user
 user agents server agent

 mail servers SMTP mail user


server agent
 simple mail transfer protocol: SMTP SMTP

User Agent SMTP user


agent
mail
 a.k.a. “mail reader” server
user
 composing, editing, reading mail messages agent

 e.g., Outlook, iPhone mail client user


agent
 outgoing, incoming messages stored on outgoing
message queue
server user mailbox

Application Layer: 2-27


E-mail: mail servers user
agent
mail servers: mail user
server agent
 mailbox contains incoming
messages for user SMTP mail user
server agent
 message queue of outgoing (to be SMTP
sent) mail messages
SMTP user
SMTP protocol between mail mail
server
agent

servers to send email messages user


agent
 client: sending mail server user
 “server”: receiving mail server agent
outgoing
message queue
user mailbox

Application Layer: 2-28


SMTP RFC (5321) “client”
SMTP server
“server”
SMTP server

 uses TCP to reliably transfer email message


initiate TCP
from client (mail server initiating connection
connection) to server, port 25 RTT
 direct transfer: sending server (acting like client) TCP connection
initiated
to receiving server
 three phases of transfer 220
• SMTP handshaking (greeting) SMTP HELO
handshaking
• SMTP transfer of messages 250 Hello
• SMTP closure
SMTP
transfers
time
Application Layer: 2-29
Scenario: Alice sends e-mail to Bob
1) Alice uses UA to compose e-mail 4) SMTP client sends Alice’s message
message “to” bob@someschool.edu over the TCP connection
2) Alice’s UA sends message to her 5) Bob’s mail server places
mail server using SMTP; message the message in Bob’s
placed in message queue mailbox
3) client side of SMTP at mail server 6) Bob invokes his user
opens TCP connection with Bob’s mail agent to read message
server

1 user mail user


mail agent
agent server server
2 3 6
4
5
Alice’s mail server Bob’s mail server
Application Layer: 2-30
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-31
SMTP: observations
comparison with HTTP:  SMTP: multiple objects
 HTTP: client pull (someone loads sent in multipart
information on a Web server and users message
use HTTP to pull the information from  SMTP uses persistent
the server at their convenience) connections
 SMTP: client push (the ending mail  SMTP requires message
server pushes the file to the receiving (header & body) to be in
mail server) 7-bit ASCII
 both have ASCII command/response  SMTP server uses
interaction, status codes CRLF.CRLF to determine
end of message
 HTTP: each object encapsulated in its
own response message Application Layer: 2-32
Mail message format
SMTP: protocol for exchanging e-mail messages, defined in RFC 5321
(like RFC 7231 defines HTTP)
RFC 2822 defines syntax for e-mail message itself (like HTML defines
syntax for web documents)
 header lines, e.g., header
blank
• To:
line
• From:
• Subject:
these lines, within the body of the email body
message area different from SMTP MAIL FROM:,
RCPT TO: commands!
 Body: the “message” , ASCII characters only
Application Layer: 2-33
Retrieving email: mail access protocols
user
e-mail access user
SMTP SMTP protocol
agent agent
(e.g., IMAP,
HTTP)

sender’s e-mail receiver’s e-mail


server server

 SMTP: delivery/storage of e-mail messages to receiver’s server


 mail access protocol: retrieval from server
• IMAP: Internet Mail Access Protocol [RFC 3501]: messages stored on server, IMAP
provides retrieval, deletion, folders of stored messages on server
 HTTP: gmail, Hotmail, Yahoo!Mail, etc. provides web-based interface on
top of STMP (to send), IMAP (or POP) to retrieve e-mail messages
Application Layer: 2-34
Application Layer: Overview
 P2P applications
 Principles of network  video streaming and content
applications distribution networks
 Web and HTTP  socket programming with
 E-mail, SMTP, IMAP UDP and TCP
 The Domain Name System
DNS

Application Layer: 2-35


DNS: Domain Name System
people: many identifiers: Domain Name System (DNS):
• SSN, name, passport #  distributed database implemented in
Internet hosts, routers: hierarchy of many name servers
• IP address (32 bit) - used for  application-layer protocol: hosts, DNS
addressing datagrams servers communicate to resolve
• “name”, e.g., cs.umass.edu - names (address/name translation)
used by humans
• note: core Internet function,
Q: how to map between IP implemented as application-layer
address and name, and vice protocol
versa ?
• complexity at network’s “edge”

Application Layer: 2-36


DNS: Services
 Host aliasing. A host with a Domain Name System (DNS):
complicated hostname can have  distributed database implemented in
one or more alias names. For hierarchy of many name servers
example, a hostname such as
 application-layer protocol: hosts, DNS
relay1.westcoast.enterprise.com servers communicate to resolve
could have, say, two aliases such names (address/name translation)
as enterprise.com and
www.enterprise.com . • note: core Internet function,
implemented as application-layer
protocol
In this case, the hostname • complexity at network’s “edge”
relay1.westcoast.enterprise.com is
said to be a canonical hostname.
Application Layer: 2-37
DNS: services, structure
DNS services: Q: Why not centralize DNS?
 hostname-to-IP-address translation  single point of failure
 traffic volume
 host aliasing
 distant centralized database
• canonical, alias names
 maintenance
 mail server aliasing
 load distribution A: doesn‘t scale!
• replicated Web servers: many IP  Comcast DNS servers alone:
addresses correspond to one 600B DNS queries/day
name  Akamai DNS servers alone:
2.2T DNS queries/day

Application Layer: 2-38


Thinking about the DNS
humongous distributed database:
 ~ billion records, each simple
handles many trillions of queries/day:
 many more reads than writes
 performance matters: almost every
Internet transaction interacts with
DNS - msecs count!
organizationally, physically decentralized:
 millions of different organizations
responsible for their records
“bulletproof”: reliability, security
Application Layer: 2-39
DNS: a distributed, hierarchical database
Root DNS Servers Root
… …
.com DNS servers .org DNS servers .edu DNS servers Top Level Domain
… … … …
yahoo.com amazon.com pbs.org nyu.edu umass.edu
DNS servers DNS servers DNS servers DNS servers DNS servers Authoritative

Client wants IP address 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-40
DNS: root name servers
 official, contact-of-last-resort by
name servers that can not
resolve name

Application Layer: 2-41


DNS: root name servers
 official, contact-of-last-resort by
name servers that can not 13 logical root name “servers”
worldwide each “server” replicated
resolve name many times (~200 servers in US)
 incredibly important Internet
function
• Internet couldn’t function without it!
• DNSSEC – provides security
(authentication, message integrity)
 ICANN (Internet Corporation for
Assigned Names and Numbers)
manages root DNS domain

Application Layer: 2-42


Application Layer: 2-43
Top-Level Domain, and authoritative servers
Top-Level Domain (TLD) servers:
 responsible for .com, .org, .net, .edu, .aero, .jobs, .museums, and all top-level
country domains, e.g.: .cn, .uk, .fr, .ca, .jp
 Network Solutions: authoritative registry for .com, .net TLD
 Educause: .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-44


DNS name resolution: iterated query
root DNS server
Example: host at engineering.nyu.edu
wants IP address for gaia.cs.umass.edu 2
3
TLD DNS server
Iterated query: 1 4

 contacted server replies 8 5


with name of server to requesting host at local DNS server
contact engineering.nyu.edu dns.nyu.edu
gaia.cs.umass.edu
 “I don’t know this name, 7 6
but ask this server”
authoritative DNS server
dns.cs.umass.edu

Application Layer: 2-45


DNS name resolution: recursive query
root DNS server
Example: host at engineering.nyu.edu
wants IP address for gaia.cs.umass.edu 2 3

7 6
Recursive query: 1 TLD DNS server
 puts burden of name 8
resolution on requesting host at local DNS server
5 4
engineering.nyu.edu dns.nyu.edu
contacted name gaia.cs.umass.edu

server
 heavy load at upper authoritative DNS server
levels of hierarchy? dns.cs.umass.edu

Application Layer: 2-46


Caching DNS Information
 once (any) name server learns mapping, it caches mapping,
and immediately returns a cached mapping in response to a
query
• caching improves response time
• cache entries timeout (disappear) after some time (TTL)
• TLD servers typically cached in local name servers
 cached entries may be out-of-date
• if named host changes IP address, may not be known Internet-
wide until all TTLs expire!
• best-effort name-to-address translation!

Application Layer: 2-47


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 “canonical” (the
 value is IP address real) name
 www.ibm.com is really servereast.backup2.ibm.com
type=NS  value is canonical name
 name is domain (e.g., foo.com)
 value is hostname of
type=MX
authoritative name server for  value is name of SMTP mail server
this domain associated with name
Application Layer: 2-48
DNS protocol messages
DNS query and reply messages, both have same format:
2 bytes 2 bytes

message header: identification flags

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

reply to query uses same # # authority RRs # additional RRs


 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-49


DNS protocol messages
DNS query and reply messages, both have same format:
2 bytes 2 bytes

identification flags

# questions # answer RRs

# authority RRs # additional RRs

name, type fields for a query questions (variable # of questions)

RRs in response to query answers (variable # of RRs)

records for authoritative servers authority (variable # of RRs)

additional “ helpful” info that may additional info (variable # of RRs)


be used
Application Layer: 2-50
The first 12 bytes is the header section, which has a number of fields.
The first field is a 16-bit number that identifies the query. This identifier is copied into the reply
message to a query, allowing the client to match received replies with sent queries.

There are a number of flags in the flag field.


1-bit query/reply flag indicates whether the message is a query (0) or a reply (1).
1-bit authoritative flag is set in a reply message when a DNS server is an authoritative server
for a queried name.
1-bit recursion-desired flag is set when a client (host or DNS server) desires that the DNS
server perform recursion when it doesn’t have the record.
1-bit recursion-available field is set in a reply if the DNS server supports recursion.

In the header, there are also four number-of fields. These fields indicate the number of
occurrences of the four types of data sections that follow the header.

Application Layer: 2-51


The question section contains information about the query that is being made. This section
includes
(1) a name field that contains the name that is being queried, and
(2) a type field that indicates the type of question being asked about the name—for example,
a host address associated with a name (Type A) or the mail server for a name (Type MX).

In a reply from a DNS server, the answer section contains the resource records for the name
that was originally queried. Recall that in each resource record there is the Type (for example,
A, NS, CNAME, and MX), the Value , and the TTL . A reply can return multiple RRs in the
answer, since a hostname can have multiple IP addresses (for example, for replicated Web
servers, as discussed earlier in this section).

The authority section contains records of other authoritative servers.

The additional section contains other helpful records. For example, the answer field in a reply
to an MX query contains a resource record providing the canonical hostname of a mail server.
The additional section contains a Type A record providing the IP address for the canonical
hostname of the mail server. Application Layer: 2-52
Getting your info into the 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 NS, A RRs into .com TLD server:
(networkutopia.com, dns1.networkutopia.com, NS)
(dns1.networkutopia.com, 212.212.212.1, A)
 create authoritative server locally with IP address 212.212.212.1
• type A record for www.networkuptopia.com
• type MX record for networkutopia.com

Application Layer: 2-53


Application Layer: Overview
 P2P applications
 Principles of network  video streaming and content
applications distribution networks
 Web and HTTP  socket programming with
 E-mail, SMTP, IMAP UDP and TCP
 The Domain Name System
DNS

Application Layer: 2-54


Peer-to-peer (P2P) architecture
 no always-on server mobile network
 arbitrary end systems directly national or global ISP

communicate
 peers request service from other
peers, provide service in return to
other peers local or
regional ISP
• self scalability – new peers bring new
service capacity, and new service demands home network content
provider
 peers are intermittently connected network datacenter
network
and change IP addresses
• complex management
 examples: P2P file sharing (BitTorrent), enterprise
network
streaming (KanKan), VoIP (Skype)
Application Layer: 2-55
File distribution: client-server vs P2P
Q: 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 u2 capacity
us d2
server
di
uN network (with abundant
bandwidth) ui
dN
ui: peer i upload
capacity
Introduction: 1-56
File distribution time: client-server
 server transmission: must sequentially
send (upload) N file copies:
F
• time to send one copy: F/us us

• time to send N copies: NF/us di


network
ui
 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
Dc-s > max{NF/us,,F/dmin}
client-server approach

increases linearly in N Introduction: 1-57


File distribution time: P2P
 server transmission: must upload at
least one copy:
F
• time to send one copy: F/us us

 client: each client must download di


network
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 + Sui

time to distribute F
to N clients using
P2P approach
DP2P > max{F/us,,F/dmin,,NF/(us + Sui)}
increases linearly in N …
… but so does this, as each peer brings service capacity Application Layer: 2-58
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

N
Application Layer: 2-59
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-60


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


BitTorrent: requesting, sending file chunks
Requesting chunks: Sending chunks: tit-for-tat
 at any given time, different  Alice sends chunks to those four
peers have different subsets peers currently sending her chunks
of file chunks at highest rate
• other peers are choked by Alice (do
 periodically, Alice asks each not receive chunks from her)
peer for list of chunks that • re-evaluate top 4 every10 secs
they have
 every 30 secs: randomly select
 Alice requests missing another peer, starts sending
chunks from peers, rarest chunks
first • “optimistically unchoke” this peer
• newly chosen peer may join top 4
Application Layer: 2-62
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-63


Application layer: overview
 P2P applications
 Principles of network  video streaming and content
applications distribution networks
 Web and HTTP  socket programming with
 E-mail, SMTP, IMAP UDP and TCP
 The Domain Name System
DNS

Application Layer: 2-64


Video Streaming and CDNs: context
 stream video traffic: major
consumer of Internet bandwidth
• Netflix, YouTube, Amazon Prime: 80% of
residential ISP traffic (2020)
 challenge: scale - how to reach
~1B users?
 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-65
Multimedia: video spatial coding example: instead
of sending N values of same
color (all purple), send only two
values: color value (purple) and

 video: sequence of images number of repeated values (N)

displayed at constant rate ……………………..


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

next) send only differences from


frame i frame i+1

Application Layer: 2-66


Multimedia: video spatial coding example: instead
of sending N values of same
color (all purple), send only two
values: color value (purple) and
 CBR: (constant bit rate): video number of repeated values (N)

encoding rate fixed ……………………..


……………….…….
 VBR: (variable bit rate): video
encoding rate changes as
amount of spatial, temporal
coding changes
 examples: frame i
• MPEG 1 (CD-ROM) 1.5 Mbps
• MPEG2 (DVD) 3-6 Mbps
temporal coding example:
• MPEG4 (often used in instead of sending
complete frame at i+1,
Internet, 64Kbps – 12 Mbps) send only differences from
frame i frame i+1

Application Layer: 2-67


Streaming stored video
simple scenario:

Internet
video server
client
(stored video)

Main challenges:
 server-to-client bandwidth will vary over time, with changing network
congestion levels (in house, access network, network core, video server)
 packet loss, delay due to congestion will delay playout, or result in poor
video quality
Application Layer: 2-68
Streaming stored video
Cumulative data

2. video
sent
1. video 3. video received, played out at client
recorded (30 frames/sec)
(e.g., 30 time
network delay
frames/sec) (fixed in this
example)
streaming: at this time, client playing out
early part of video, while server still sending
later part of video
Application Layer: 2-69
Streaming stored video: challenges
 continuous playout constraint: during client
video playout, playout timing must match
original timing
• … but network delays are variable (jitter), so will
need client-side buffer to match continuous playout
constraint
 other challenges:
• client interactivity: pause, fast-forward, rewind,
jump through video
• video packets may be lost, retransmitted
Application Layer: 2-70
Streaming stored video: playout buffering
constant bit
Cumulative data rate video client video constant bit
transmission reception rate video
playout at client
variable
network

buffered
video
delay

client playout time


delay

 client-side buffering and playout delay: compensate for


network-added delay, delay jitter
Application Layer: 2-71
Dynamic, Adaptive
Streaming multimedia: DASHStreaming over HTTP
server:
 divides video file into multiple chunks ...
 each chunk encoded at multiple different rates ...
 different rate encodings stored in different files ?
 files replicated in various CDN nodes
...
 manifest file: provides URLs for different chunks client

client:
 periodically estimates 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), and from different servers
Application Layer: 2-72
Streaming multimedia: DASH
 “intelligence” at client: client
determines ...
• when to request chunk (so that buffer ...

starvation, or overflow does not occur) ?


• what encoding rate to request (higher ...
client
quality when more bandwidth
available)
• where to request chunk (can request
from URL server that is “close” to
client or has high available
bandwidth)
Streaming video = encoding + DASH + playout buffering
Application Layer: 2-73
Content distribution networks (CDNs)
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 (and possibly congested) path
to distant clients

….quite simply: this solution doesn’t scale


Application Layer: 2-74
Content distribution networks (CDNs)
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
• Akamai: 240,000 servers deployed
in > 120 countries (2015)
• bring home: smaller number (10’s) of
larger clusters in POPs near access nets
• used by Limelight
Application Layer: 2-75
Akamai today:

Source: https://networkingchannel.eu/living-on-the-edge-for-a-quarter-century-an-akamai-retrospective-downloads/

Transport Layer: 3-76


How does Netflix work?
 Netflix: stores copies of content (e.g., MADMEN) at its
(worldwide) OpenConnect CDN nodes
 subscriber requests content, service provider returns manifest
• using manifest, client retrieves content at highest supportable rate
• may choose different rate or copy if network path congested

… …


manifest file

where’s Madmen?

… …
Application Layer: 2-77
Content distribution networks (CDNs)

OTT: “over the top”

… …
Internet host-host communication as a service


OTT challenges: coping with a congested Internet from the “edge”


 what content to place in which CDN node?
 from which CDN node to retrieve content? At which rate?
… …
Application Layer: 2-78
Application Layer: Overview
 P2P applications
 Principles of network  video streaming and content
applications distribution networks
 Web and HTTP  socket programming with
 E-mail, SMTP, IMAP UDP and TCP
 The Domain Name System
DNS

Application Layer: 2-79


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

Application Layer: 2-80


Socket programming
Two socket types for two transport services:
 UDP: unreliable datagram
 TCP: reliable, byte stream-oriented
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 displays line on its screen

Application Layer: 2-81


Socket programming with UDP
UDP: no “connection” between
client and 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 processes
Application Layer: 2-82
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 address
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
Application Layer: 2-83
Example app: UDP client
Python UDPClient
include Python’s socket library from socket import *
serverName = 'hostname'
serverPort = 12000
create UDP socket clientSocket = socket(AF_INET,
SOCK_DGRAM)
get user keyboard input message = input('Input lowercase sentence:')
attach server name, port to message; send into socket clientSocket.sendto(message.encode(),
(serverName, serverPort))
read reply data (bytes) from socket modifiedMessage, serverAddress =
clientSocket.recvfrom(2048)
print out received string and close socket print(modifiedMessage.decode())
clientSocket.close()

Note: this code update (2023) to Python 3 Application Layer: 2-84


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 message, clientAddress = serverSocket.recvfrom(2048)
client’s address (client IP and port)
modifiedMessage = message.decode().upper()
send upper case string back to this client serverSocket.sendto(modifiedMessage.encode(),
clientAddress)

Note: this code update (2023) to Python 3 Application Layer: 2-85


Socket programming with TCP
Client must contact server  when contacted by client, server
 server process must first be TCP creates new socket for server
running process to communicate with that
 server must have created socket particular client
(door) that welcomes client’s • allows server to talk with multiple
contact clients
• client source port # and IP address used
Client contacts server by: to distinguish clients (more in Chap 3)
 Creating TCP socket, specifying IP
address, port number of server Application viewpoint
process TCP provides reliable, in-order
 when client creates socket: client byte-stream transfer (“pipe”)
between client and server
TCP establishes connection to processes
server TCP
Application Layer: 2-86
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
Application Layer: 2-87
Example app: TCP client
Python TCPClient
from socket import *
serverName = 'servername'
serverPort = 12000
create TCP socket for server, clientSocket = socket(AF_INET, SOCK_STREAM)
remote port 12000
clientSocket.connect((serverName,serverPort))
sentence = input('Input lowercase sentence:')
clientSocket.send(sentence.encode())
No need to attach server name, port modifiedSentence = clientSocket.recv(1024)
print ('From Server:', modifiedSentence.decode())
clientSocket.close()

Note: this code update (2023) to Python 3 Application Layer: 2-88


Example app: TCP server
Python TCPServer
from socket import *
serverPort = 12000
create TCP welcoming 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 connectionSocket, addr = serverSocket.accept()
requests, new socket created on return

read bytes from socket (but sentence = connectionSocket.recv(1024).decode()


not address as in UDP) capitalizedSentence = sentence.upper()
connectionSocket.send(capitalizedSentence.
encode())
close connection to this client (but not connectionSocket.close()
welcoming socket)
Note: this code update (2023) to Python 3 Application Layer: 2-89
Chapter 2: Summary
our study of network application layer is now complete!
 application architectures  specific protocols:
• client-server • HTTP
• P2P • SMTP, IMAP
• DNS
 application service requirements:
• P2P: BitTorrent
• reliability, bandwidth, delay
 video streaming, CDNs
 Internet transport service model  socket programming:
• connection-oriented, reliable: TCP
TCP, UDP sockets
• unreliable, datagrams: UDP

Application Layer: 2-90


Chapter 2: Summary
Most importantly: learned about protocols!
 typical request/reply message important themes:
exchange:  centralized vs. decentralized
• client requests info or service  stateless vs. stateful
• server responds with data, status code  scalability
 message formats:  reliable vs. unreliable
• headers: fields giving info about data message transfer
• data: info(payload) being  “complexity at network
communicated
edge”

Application Layer: 2-91


Additional Chapter 2 slides
JFK note: the timeout slides are important IMHO if one is doing a programming assignment (especially
an RDT programming assignment in Chapter 3), since students will need to use timers in their code,
and the TRY/EXCEPT is really the easiest way to do this. I introduce this here in Chapter 2 with the
socket programming assignment since it teaches something (how to handle exceptions/timeouts), and
lets students learn/practice that before doing the RDT programming assignment, which is harder

Application Layer: 2-92


Socket programming: waiting for multiple events

 sometimes a program must wait for one of several events to happen, e.g.,:
 wait for either (i) a reply from another end of the socket, or (ii) timeout: timer
 wait for replies from several different open sockets: select(), multithreading
 timeouts are used extensively in networking
 using timeouts with Python socket:
receive a message
socket() connect() send() settimeout() recv() …
timeout
handle
timeout


Application Layer: 2-93
How Python socket.settimeout() works?
timer starts! no packet arrives in 30 secs timeout

s.settimeout(30) s.recv() interrupt s.recv() &


raise timeout exception

receive a message no packet arrives in 10 secs


timer starts! & timer stop! timer starts! timeout

s.settimeout(10) s.recv() s.recv() interrupt s.recv() &


raise timeout exception

Set a timeout on all future socket operations of that specific socket!


Application Layer: 2-94
Python try-except block
Execute a block of code, and handle “exceptions” that may occur when
executing that block of code
try:
Executing this try code block may cause exception(s) to catch. If an exception
<do something> is raised, execution jumps from jumps directly into except code block
except <exception>:
this except code block is only executed if an <exception> occurred in the try
<handle the exception> code block (note: except block is required with a try block)
Socket programming: socket timeouts
Toy Example:
- A shepherd boy tends his master’s sheep. Python TCPServer (Villagers)
- If he sees a wolf, he can send a message to
villagers for help using a TCP socket. from socket import *
- The boy found it fun to connect to the server serverPort = 12000
without sending any messages. But the villagers serverSocket = socket(AF_INET,SOCK_STREAM)
don’t think so.
- And they decided that if the boy connects to serverSocket.bind(('',serverPort))
the server and doesn’t send the wolf location serverSocket.listen(1)
within 10 seconds for three times, they will stop counter = 0
listening to him forever and ever.
while counter < 3:
set a 10-seconds timeout on connectionSocket, addr = serverSocket.accept()
all future socket operations connectionSocket.settimeout(10)
try:
timer starts when recv() is called and will wolf_location = connectionSocket.recv(1024).decode()
send_hunter(wolf_location) # a villager function
raise timeout exception if there is no connectionSocket.send('hunter sent')
message within 10 seconds.
except timeout:
catch socket timeout exception counter += 1
connectionSocket.close()

Application Layer: 2-96


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-97
CDN content access: a closer look
Bob (client) requests video http://netcinema.com/6Y7B23V
 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 Bob’s local DNS
1
6. request video from 5 Bob’s
KINGCDN server, local DNS
streamed via HTTP server
3. netcinema’s DNS returns CNAME for
netcinema.com 4
http://KingCDN.com/NetC6y&B23V

netcinema’s
authoratative DNS KingCDN.com KingCDN
authoritative DNS
Application Layer: 2-98
Case study: Netflix
Amazon cloud upload copies of
multiple versions of
video to CDN servers
CDN
server
Netflix registration,
accounting servers
Bob browses
Netflix video CDN
2 Manifest file, server
requested
1 3 returned for
Bob manages specific video
Netflix account
CDN
4 server

DASH server
selected, contacted,
streaming begins
Application Layer: 2-99

You might also like