Chapter 2:
Application
Layer
Lect ure Slides f rom the Boo k authors
http://gaia.cs.umas s.edu/kuro se_ross /
interactive/
Layers
ZESHAN.KHAN@NU.EDU.PK Application Layer: 2-2
APPLICATION PRESENTATION SESSION TRANSPORT NETWORK LINK
PHYSICAL
Chapter 2:
Application
layer
ZESHAN.KHAN@NU.EDU.PK
Application Layer:
2-3
Principles of network applications
Web and HTTP
E-mail, SMTP, IMAP
The Domain Name System DNS
P2P applications
video streaming and content distribution networks
socket programming with UDP and TCP
ZESHAN.KHAN@NU.EDU.PK
Application layer: overview
Our goals:
 conceptual and implementation aspects of application-layer protocols
• transport-layer service models
• client-server paradigm
• peer-to-peer paradigm
 learn about protocols by examining popular application-layer protocols and infrastructure
• HTTP
• SMTP, IMAP
• DNS
• video streaming systems, CDNs
 programming network applications
• socket API
Application Layer: 2-
4
ZESHAN.KHAN@NU.EDU.PK
Some network apps
 social networking
 Web
 text messaging
 e-mail
 multi-user network games
 streaming stored video
(YouTube, Hulu, Netflix)
 P2P file sharing
 voice over IP (e.g., Skype)
 real-time video conferencing
(e.g., Zoom, meet)
 Internet search
 remote login
 …
Application Layer: 2-
5
ZESHAN.KHAN@NU.EDU.PK
mobile network
home network
enterprise
network
national or global ISP
local or
regional ISP
datacenter
network
content
provider
network
application
transport
network
data link
physical
application
transport
network
data link
physical
application
transport
network
data link
physical
Creating a network app
Application Layer: 2-
6
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 for
network-core devices
 network-core devices do not run user
applications
 applications on end systems allows
for rapid app development,
propagation
ZESHAN.KHAN@NU.EDU.PK
mobile network
home network
enterprise
network
national or global ISP
local or
regional ISP
datacenter
network
content
provider
network
Client-server paradigm
Application Layer: 2-
7
server:
 always-on host
 permanent IP address
 often in data centers, for scaling
clients:
 contact, communicate with server
 may be intermittently connected
 may have dynamic IP addresses
 do not communicate directly with
each other
 examples: HTTP, IMAP, FTP
ZESHAN.KHAN@NU.EDU.PK
mobile network
home network
enterprise
network
national or global ISP
local or
regional ISP
datacenter
network
content
provider
network
Peer-peer architecture
Application Layer: 2-
8
 no always-on server
 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
 example: P2P file sharing
ZESHAN.KHAN@NU.EDU.PK
Processes communicating
Application Layer: 2-
9
process: program running
within a host
within same host, two
processes communicate
using inter-process
communication (defined by
OS)
processes in different hosts
communicate by exchanging
messages
 note: applications with
P2P architectures have
client processes &
server processes
client process: process that
initiates communication
server process: process
that waits to be contacted
clients, servers
ZESHAN.KHAN@NU.EDU.PK
Sockets
Application Layer: 2-
10
 process sends/receives messages to/from its socket
 socket analogous to door
• sending process shoves message outdoor
• sending process relies on transport infrastructure on other side of door to deliver
message to socket at receiving process
• two sockets involved: one on each side
Internet
controlled
by OS
controlled by
app developer
transport
application
physical
link
network
process
transport
application
physical
link
network
process
socket
ZESHAN.KHAN@NU.EDU.PK
Addressing processes
Application Layer: 2-
11
 to receive messages, process
must have identifier
 host device has unique 32-bit
IP address
 Q: does IP address of host on
which process runs suffice for
identifying the process?
 A: no, many processes can be
running on same host
 identifier includes both IP address and
port numbers associated with process
on host.
 example port numbers:
• HTTP server: 80
• mail server: 25
 to send HTTP message to
gaia.cs.umass.edu web server:
• IP address: 128.119.245.12
• port number: 80
 more shortly…
ZESHAN.KHAN@NU.EDU.PK
An application-layer protocol defines:
Application Layer: 2-
12
 types of messages exchanged,
• e.g., request, response
 message syntax:
• what fields in messages & how
fields are delineated
 message semantics
• meaning of information in fields
 rules for when and how processes
send & respond to messages
open protocols:
 defined in RFCs, everyone
has access to protocol
definition
 allows for interoperability
 e.g., HTTP, SMTP
proprietary protocols:
 e.g., Skype, Zoom
ZESHAN.KHAN@NU.EDU.PK
What transport service does an app need?
Application Layer: 2-
13
data integrity
 some apps (e.g., file transfer,
web transactions) require
100% reliable data transfer
 other apps (e.g., audio) can
tolerate some loss
timing
 some apps (e.g., Internet
telephony, interactive games)
require low delay to be “effective”
throughput
 some apps (e.g., multimedia)
require minimum amount of
throughput to be “effective”
 other apps (“elastic apps”)
make use of whatever
throughput they get
security
 encryption, data integrity,
…
Transport
service
requirements:
common apps
ZESHAN.KHAN@NU.EDU.PK
Application Layer:
2-14
application data loss throughput time sensitive?
file transfer/download no loss elastic No
e-mail no loss elastic No
Web documents no loss elastic No
real-time audio/video loss-tolerant audio: 5Kbps-
1Mbps
video:10Kbps-
5Mbps
yes, 10’s msec
streaming audio/video loss-tolerant audio: 5Kbps-
1Mbps
video:10Kbps-
5Mbps
yes, few secs
interactive games loss-tolerant Kbps yes, 10’s msec
text messaging no loss elastic yes and no
ZESHAN.KHAN@NU.EDU.PK
Internet transport protocols services
Application Layer: 2-
15
TCP service:
 reliable transport between sending and
receiving process
 flow control: sender won’t overwhelm
receiver
 congestion control: throttle sender when
network overloaded
 connection-oriented: setup required
between client and server processes
 does not provide: timing, minimum
throughput guarantee, security
UDP service:
 unreliable data transfer
between sending and receiving
process
 does not provide: reliability,
flow control, congestion
control, timing, throughput
guarantee, security, or
connection setup.
Q: why bother? Why
is there a UDP?
Internet
applications,
and transport
protocols
ZESHAN.KHAN@NU.EDU.PK
Application Layer:
2-16
Application application
layer protocol
transport
protocol
file
transfer/download
FTP [RFC 959] TCP
e-mail SMTP [RFC 5321] TCP
Web documents HTTP 1.1 [RFC 7320] TCP
Internet telephony SIP [RFC 3261], RTP
[RFC 3550], or
proprietary
TCP or UDP
streaming
audio/video
HTTP [RFC 7320],
DASH
TCP
interactive games WOW, FPS
(proprietary)
TCP or UDP
ZESHAN.KHAN@NU.EDU.PK
Securing TCP
Application Layer: 2-
17
Vanilla TCP & UDP sockets:
 no encryption
 cleartext passwords sent into socket
traverse Internet in cleartext (!)
Transport Layer Security (TLS)
 provides encrypted TCP connections
 data integrity
 end-point authentication
TLS implemented in
application layer
 apps use TLS libraries, that
use TCP in turn
 cleartext sent into “socket”
traverse Internet encrypted
 more: Chapter 8
Chapter 2:
Application
layer
ZESHAN.KHAN@NU.EDU.PK
Application Layer:
2-18
Principles of network applications
Web and HTTP
E-mail, SMTP, IMAP
The Domain Name System DNS
P2P applications
video streaming and content distribution networks
socket programming with UDP and TCP
Web and HTTP
Transport Layer: 3-
19
 web page consists of objects, each of which can be stored on
different Web servers
 object can be HTML file, JPEG image, Java applet, audio file,…
 web page consists of base HTML-file which includes several
referenced objects, each addressable by a URL, e.g.,
www.someschool.edu/someDept/pic.gif
host name path name
HTTP overview
Transport Layer: 3-
20
HTTP: hypertext transfer protocol
 Web’s application-layer protocol
 client/server model:
• client: browser that requests,
receives, (using HTTP protocol) and
“displays” Web objects
• server: Web server sends (using
HTTP protocol) objects in response
to requests
HTTP request
HTTP response
HTTP request
HTTP response
iPhone running
Safari browser
PC running
Firefox browser
server running
Apache Web
server
HTTP overview (continued)
Transport Layer: 3-
21
HTTP uses TCP:
 client initiates TCP connection
(creates socket) to server, port 80
 server accepts TCP connection
from client
 HTTP messages (application-layer
protocol messages) exchanged
between browser (HTTP client) and
Web server (HTTP server)
 TCP connection closed
HTTP is “stateless”
 server maintains no
information about past client
requests
protocols that maintain “state”
are complex!
 past history (state) must be
maintained
 if server/client crashes, their views
of “state” may be inconsistent, must
be reconciled
aside
HTTP connections: two types
Transport Layer: 3-
22
Non-persistent HTTP
1. TCP connection opened
2. at most one object sent
over TCP connection
3. TCP connection closed
downloading multiple
objects required multiple
connections
Persistent HTTP
TCP connection opened to
a server
multiple objects can be
sent over single TCP
connection between client,
and that server
TCP connection closed
Non-persistent HTTP: example
Transport Layer: 3-
23
User enters URL:
1a. HTTP client initiates TCP
connection to HTTP server
(process) at www.someSchool.edu on
port 80
2. HTTP client sends HTTP
request message (containing
URL) into TCP connection
socket. Message indicates
that client wants object
someDepartment/home.index
1b. HTTP server at host
www.someSchool.edu waiting for TCP
connection at port 80 “accepts”
connection, notifying client
3. HTTP server receives request message,
forms response message containing
requested object, and sends message
into its socket
time
(containing text, references to 10 jpeg images)
www.someSchool.edu/someDepartment/home.index
Non-persistent HTTP: example (cont.)
Transport Layer: 3-
24
User enters URL:
(containing text, references to 10 jpeg images)
www.someSchool.edu/someDepartment/home.index
5. HTTP client receives response
message containing html file,
displays html. Parsing html file,
finds 10 referenced jpeg objects
6. Steps 1-5 repeated for
each of 10 jpeg objects
4. HTTP server closes TCP
connection.
time
Non-persistent HTTP: response time
Transport Layer: 3-
25
RTT (definition): time for a small
packet to travel from client to
server and back
HTTP response time (per object):
 one RTT to initiate TCP connection
 one RTT for HTTP request and first few
bytes of HTTP response to return
 object/file transmission time
time to
transmit
file
initiate TCP
connection
RTT
request file
RTT
file received
time time
Non-persistent HTTP response time = 2RTT+ file transmission time
Persistent HTTP (HTTP 1.1)
Transport Layer: 3-
26
Non-persistent HTTP issues:
 requires 2 RTTs per object
 OS overhead for each TCP
connection
 browsers often open multiple
parallel TCP connections to
fetch referenced objects in
parallel
Persistent HTTP (HTTP1.1):
 server leaves connection open after
sending response
 subsequent HTTP messages between
same client/server sent over open
connection
 client sends requests as soon as it
encounters a referenced object
 as little as one RTT for all the referenced
objects (cutting response time in half)
HTTP request message
Transport Layer: 3-
27
 two types of HTTP messages: request, response
 HTTP request message:
• ASCII (human-readable format)
header
lines
GET /index.html HTTP/1.1rn
Host: www-net.cs.umass.edurn
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X
10.15; rv:80.0) Gecko/20100101 Firefox/80.0 rn
Accept: text/html,application/xhtml+xmlrn
Accept-Language: en-us,en;q=0.5rn
Accept-Encoding: gzip,deflatern
Connection: keep-alivern
rn
carriage return character
line-feed character
request line (GET, POST,
HEAD commands)
carriage return, line feed
at start of line indicates
end of header lines
HTTP request message: general format
Transport Layer: 3-
28
request
line
header
lines
body
method sp sp cr lf
version
URL
cr lf
value
header field name
cr lf
value
header field name
~
~ ~
~
cr lf
entity body
~
~ ~
~
Other HTTP request messages
Transport Layer: 3-
29
POST method:
 web page often includes form
input
 user input sent from client to
server in entity body of HTTP
POST request message
GET method (for sending data to server):
 include user data in URL field of HTTP
GET request message (following a ‘?’):
www.somesite.com/animalsearch?monkeys&banana
HEAD method:
 requests headers (only) that
would be returned if specified URL
were requested with an HTTP
GET method.
PUT method:
 uploads new file (object) to server
 completely replaces file that exists
at specified URL with content in
entity body of POST HTTP request
message
HTTP response message
Transport Layer: 3-
30
status line (protocol status code status phrase)
header
lines
data, e.g., requested
HTML file
Date: Tue, 08 Sep 2020 00:53:20 GMT
Server: Apache/2.4.6 (CentOS)
OpenSSL/1.0.2k-fips PHP/7.4.9
mod_perl/2.0.11 Perl/v5.16.3
Last-Modified: Tue, 01 Mar 2016 18:57:50 GMT
ETag: "a5b-52d015789ee9e"
Accept-Ranges: bytes
Content-Length: 2651
Content-Type: text/html; charset=UTF-8
rn
data data data data data ...
HTTP/1.1 200 OK
HTTP response
status codes
Transport Layer: 3-
31
 status code appears
in 1st line in server-
to-client response
message.
 some sample codes:
• request succeeded, requested object later in this message
200 OK
• requested object moved, new location specified later in this
message (in Location: field)
301 Moved Permanently
• request msg not understood by server
400 Bad Request
• requested document not found on this server
404 Not Found
505 HTTP Version Not Supported
Maintaining user/server state: cookies
Transport Layer: 3-
33
Recall: HTTP GET/response
interaction is stateless
 no notion of multi-step exchanges of
HTTP messages to complete a Web
“transaction”
• no need for client/server to track
“state” of multi-step exchange
• all HTTP requests are independent of
each other
• no need for client/server to “recover”
from a partially-completed-but-never-
completely-completed transaction
a stateful protocol: client makes
two changes to X, or none at all
time time
OK
OK
unlock X
OK
update X X’
update X X’’
lock data record X
OK
X
X
X’
X’’
X’’
t’
Q: what happens if network connection or
client crashes at t’ ?
Maintaining user/server state: cookies
Transport Layer: 3-
34
Web sites and client browser use cookies
to maintain some state between
transactions
four components:
1) cookie header line of HTTP response
message
2) cookie header line in next HTTP request
message
3) cookie file kept on user’s host, managed by
user’s browser
4) back-end database at Web site
Example:
 Susan uses browser on laptop, visits
specific e-commerce site for first time
 when initial HTTP requests arrives at
site, site creates:
• unique ID (aka “cookie”)
• entry in backend database for ID
• subsequent HTTP requests from
Susan to this site will contain cookie
ID value, allowing site to “identify”
Susan
Maintaining user/server state: cookies
Transport Layer: 3-
35
client
server
usual HTTP response msg
usual HTTP response msg
cookie file
one week later:
usual HTTP request msg
cookie: 1678 cookie-
specific
action
access
ebay 8734
usual HTTP request msg Amazon server
creates ID
1678 for user create
entry
usual HTTP response
set-cookie: 1678
ebay 8734
amazon 1678
usual HTTP request msg
cookie: 1678 cookie-
specific
action
access
ebay 8734
amazon 1678
backend
database
time time
HTTP cookies: comments
Transport Layer: 3-
36
What cookies can be used for:
 authorization
 shopping carts
 recommendations
 user session state (Web e-mail)
cookies and privacy:
 cookies permit sites to
learn a lot about you on
their site.
 third party persistent
cookies (tracking cookies)
allow common identity
(cookie value) to be
tracked across multiple
web sites
aside
Challenge: How to keep state?
 at protocol endpoints: maintain state at
sender/receiver over multiple
transactions
 in messages: cookies in HTTP messages
carry state
Web caches
Transport Layer: 3-
37
 user configures browser to
point to a (local) Web cache
 browser sends all HTTP
requests to cache
• if object in cache: cache
returns object to client
• else cache requests object
from origin server, caches
received object, then
returns object to client
Goal: satisfy client requests without involving origin server
client
Web
cache
client
HTTP request
HTTP response
HTTP request HTTP request
origin
server
HTTP response HTTP response
Web caches (proxy servers)
Transport Layer: 3-
38
 Web cache acts as both
client and server
• server for original
requesting client
• client to origin server
Why Web caching?
 reduce response time for client
request
• cache is closer to client
 reduce traffic on an institution’s
access link
 Internet is dense with caches
• enables “poor” content providers
to more effectively deliver content
 server tells cache about
object’s allowable caching in
response header:
Caching example
Transport Layer: 3-
39
origin
servers
public
Internet
institutional
network
1 Gbps LAN
1.54 Mbps
access link
Scenario:
 access link rate: 1.54 Mbps
 RTT from institutional router to server: 2 sec
 web object size: 100K bits
 average request rate from browsers to origin
servers: 15/sec
 avg data rate to browsers: 1.50 Mbps
Performance Access Link
 A=packet arrival rate (requests/second)=15/sec
 R=transmission rate (bits/second)=1.54M/s
 L=Packet size=100K
 Traffic Intensity=LA/R=100K*15/1.54M=0.97
Caching example
Transport Layer: 3-
40
origin
servers
public
Internet
institutional
network
1 Gbps LAN
1.54 Mbps
access link
Scenario:
 access link rate: 1.54 Mbps
 RTT from institutional router to server: 2 sec
 web object size: 100K bits
 average request rate from browsers to origin
servers: 15/sec
 avg data rate to browsers: 1.50 Mbps
Performance Institute LAN
 A=packet arrival rate (requests/second)=15/sec
 R=transmission rate (bits/second)=1G/s
 L=Packet size=100K
 Traffic Intensity=LA/R=100K*15/1G=0.0015
Caching example
Transport Layer: 3-
41
origin
servers
public
Internet
institutional
network
1 Gbps LAN
1.54 Mbps
access link
Performance:
 access link utilization = .97
 LAN utilization: .0015
 end-end delay = Internet delay +
access link delay + LAN delay
= 2 sec + minutes + micro secs
Scenario:
 access link rate: 1.54 Mbps
 RTT from institutional router to server: 2 sec
 web object size: 100K bits
 average request rate from browsers to origin
servers: 15/sec
 avg data rate to browsers: 1.50 Mbps
problem: large
queueing delays at
high utilization!
Performance:
 access link utilization = .97
 LAN utilization: .0015
 end-end delay = Internet delay +
access link delay + LAN delay
= 2 sec + minutes + micro secs
Option 1: buy a faster access link
Transport Layer: 3-
42
origin
servers
public
Internet
institutional
network
1 Gbps LAN
1.54 Mbps
access link
Scenario:
 access link rate: 1.54 Mbps
 RTT from institutional router to server: 2 sec
 web object size: 100K bits
 average request rate from browsers to origin
servers: 15/sec
 avg data rate to browsers: 1.50 Mbps
154 Mbps
154 Mbps
.0097
msecs
Cost: faster access link (expensive!)
Performance:
 LAN utilization: .?
 access link utilization = ?
 average end-end delay = ?
Option 2: install a web cache
Transport Layer: 3-
43
origin
servers
public
Internet
institutional
network
1 Gbps LAN
1.54 Mbps
access link
Scenario:
 access link rate: 1.54 Mbps
 RTT from institutional router to server: 2 sec
 web object size: 100K bits
 average request rate from browsers to origin
servers: 15/sec
 avg data rate to browsers: 1.50 Mbps
How to compute link
utilization, delay?
Cost: web cache (cheap!)
local web cache
Calculating access link utilization, end-end delay with cache:
Transport Layer: 3-
44
origin
servers
public
Internet
institutional
network
1 Gbps LAN
1.54 Mbps
access link
local web cache
suppose cache hit rate is 0.4:
 40% requests served by cache, with low (msec)
delay
 60% requests satisfied at origin
• rate to browsers over access link
= 0.6 * 1.50 Mbps = .9 Mbps
• access link utilization = 0.9/1.54 = .58 means
low (msec) queueing delay at access link
 average end-end delay:
= 0.6 * (delay from origin servers)
+ 0.4 * (delay when satisfied at cache)
= 0.6 (2.01) + 0.4 (~msecs) = ~ 1.2 secs
lower average end-end delay than with 154 Mbps link (and cheaper too!)
Conditional GET
Transport Layer: 3-
45
Goal: don’t send object if cache has
up-to-date cached version
• no object transmission delay (or use
of network resources)
 client: specify date of cached copy
in HTTP request
If-modified-since: <date>
 server: response contains no
object if cached copy is up-to-date:
HTTP/1.0 304 Not Modified
HTTP request msg
If-modified-since: <date>
HTTP response
HTTP/1.0
304 Not Modified
object
not
modified
before
<date>
HTTP request msg
If-modified-since: <date>
HTTP response
HTTP/1.0 200 OK
<data>
object
modified
after
<date>
client server
HTTP/2
Transport Layer: 3-46
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
HTTP/2
Transport Layer: 3-
47
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
Key goal: decreased delay in multi-object HTTP requests
HTTP/2: mitigating HOL blocking
Transport Layer: 3-
48
HTTP 1.1: client requests 1 large object (e.g., video file) and 3 smaller
objects
client
server
GET O1
GET O2
GET O3
GET O4
O1
O2
O3
O4
object data requested
O1
O2
O3
O4
objects delivered in order requested: O2, O3, O4 wait behind O1
HTTP/2: mitigating HOL blocking
Transport Layer: 3-
49
HTTP/2: objects divided into frames, frame transmission interleaved
client
server
GET O1
GET O2
GET O3
GET O4
O2
O4
object data requested
O1
O2
O3
O4
O2, O3, O4 delivered quickly, O1 slightly delayed
O3
O1
HTTP/2 to HTTP/3
Transport Layer: 3-
50
HTTP/2 over single TCP connection means:
 recovery from packet loss still stalls all object transmissions
• as in HTTP 1.1, browsers have incentive to open multiple parallel
TCP connections to reduce stalling, increase overall throughput
 no security over vanilla TCP connection
 HTTP/3: adds security, per object error- and congestion-
control (more pipelining) over UDP
• more on HTTP/3 in transport layer
Chapter 2:
Application
layer
ZESHAN.KHAN@NU.EDU.PK
Application Layer:
2-51
Principles of network applications
Web and HTTP
E-mail, SMTP, IMAP
The Domain Name System DNS
P2P applications
video streaming and content distribution networks
socket programming with UDP and TCP
ZESHAN.KHAN@NU.EDU.PK
E-mail
Application Layer: 2-
52
Three major components:
user agents
mail servers
simple mail transfer protocol: SMTP
User Agent
“mail reader”
composing, editing, reading mail messages
e.g., Outlook, iPhone mail client
outgoing, incoming messages stored on
server user mailbox
outgoing
message queue
mail
server
mail
server
mail
server
SMTP
SMTP
SMTP
user
agent
user
agent
user
agent
user
agent
user
agent
user
agent
ZESHAN.KHAN@NU.EDU.PK
E-mail: mail servers
Application Layer: 2-
53
user mailbox
outgoing
message queue
mail
server
mail
server
mail
server
SMTP
SMTP
SMTP
user
agent
user
agent
user
agent
user
agent
user
agent
user
agent
mail servers:
 mailbox contains incoming
messages for user
 message queue of outgoing (to be
sent) mail messages
SMTP protocol between mail
servers to send email messages
 client: sending mail server
 “server”: receiving mail server
ZESHAN.KHAN@NU.EDU.PK
SMTP RFC (5321)
Application Layer: 2-
54
 uses TCP to reliably transfer email message
from client (mail server initiating
connection) to server, port 25
 direct transfer: sending server (acting like client)
to receiving server
 three phases of transfer
• SMTP handshaking (greeting)
• SMTP transfer of messages
• SMTP closure
 command/response interaction (like HTTP)
• commands: ASCII text
• response: status code and phrase
initiate TCP
connection
RTT
time
220
250 Hello
HELO
SMTP
handshaking
TCP connection
initiated
“client”
SMTP server
“server”
SMTP server
SMTP
transfers
ZESHAN.KHAN@NU.EDU.PK
Scenario: Alice sends e-mail to Bob
Application Layer: 2-
55
1) Alice uses UA to compose e-mail
message “to” bob@someschool.edu
4) SMTP client sends Alice’s message
over the TCP connection
user
agent
mail
server
mail
server
1
2 3 4
5
6
Alice’s mail server Bob’s mail server
user
agent
2) Alice’s UA sends message to her
mail server using SMTP; message
placed in message queue
3) client side of SMTP at mail server
opens TCP connection with Bob’s mail
server
5) Bob’s mail server places
the message in Bob’s
mailbox
6) Bob invokes his user
agent to read message
ZESHAN.KHAN@NU.EDU.PK
SMTP: observations
Application Layer: 2-
56
 SMTP uses persistent
connections
 SMTP requires message
(header & body) to be in
7-bit ASCII
 SMTP server uses
CRLF.CRLF to determine
end of message
comparison with HTTP:
 HTTP: client pull
 SMTP: client push
 both have ASCII command/response
interaction, status codes
 HTTP: each object encapsulated in its
own response message
 SMTP: multiple objects sent in
multipart message
ZESHAN.KHAN@NU.EDU.PK
Mail message format
Application Layer: 2-
57
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
body
blank
line
 header lines, e.g.,
• To:
• From:
• Subject:
these lines, within the body of the email
message area different from SMTP MAIL FROM:,
RCPT TO: commands!
 Body: the “message” , ASCII characters only
ZESHAN.KHAN@NU.EDU.PK
Retrieving email: mail access protocols
Application Layer: 2-
58
sender’s e-mail
server
SMTP SMTP
receiver’s e-mail
server
e-mail access
protocol
(e.g., IMAP,
HTTP)
user
agent
user
agent
 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
ZESHAN.KHAN@NU.EDU.PK
SMTP vs IMAP
SMTP (SIMPLE MAIL TRANSFER
PROTOCOL)
It is primarily used for sending emails from a
client (such as an email application or server)
to an email server or between email servers.
It handles the process of sending outgoing
emails, including routing emails to the
appropriate recipient's email server.
It operates on port 25 (although encrypted
versions like SMTPS or SMTP over TLS may use
different ports) and is responsible for
transferring the email message from the
sender's email client to the recipient's email
server.
IMAP (INTERNET MESSAGE ACCESS
PROTOCOL)
It is used for accessing emails stored on an email server
from a client device (such as an email application
or webmail client).
It allows users to view, manage, and organize their email
messages stored on the server without downloading
them to the client device.
It supports features like folder synchronization, allowing
changes made on one device to be reflected on
other devices accessing the same email account.
It operates on port 143 (or 993 for IMAP over TLS/SSL) and
provides a way for email clients to communicate with the
email server to retrieve and manage emails.
Application Layer: 2-
59
Chapter 2:
Application
layer
ZESHAN.KHAN@NU.EDU.PK
Application Layer:
2-60
Principles of network applications
Web and HTTP
E-mail, SMTP, IMAP
The Domain Name System DNS
P2P applications
video streaming and content distribution networks
socket programming with UDP and TCP
ZESHAN.KHAN@NU.EDU.PK
DNS: Domain Name System
Application Layer: 2-
61
people: many identifiers:
• SSN, name, passport #
Internet hosts, routers:
• IP address (32 bit) - used for
addressing datagrams
• “name”, e.g., cs.umass.edu -
used by humans
Q: how to map between IP
address and name, and vice
versa ?
Domain Name System (DNS):
 distributed database implemented in
hierarchy of many name servers
 application-layer protocol: hosts, DNS
servers communicate to resolve
names (address/name translation)
• note: core Internet function,
implemented as application-layer
protocol
• complexity at network’s “edge”
ZESHAN.KHAN@NU.EDU.PK
DNS: services, structure
Application Layer: 2-
62
Q: Why not centralize DNS?
 single point of failure
 traffic volume
 distant centralized database
 maintenance
DNS services:
hostname-to-IP-address translation
host aliasing
• canonical, alias names
 mail server aliasing
 load distribution
• replicated Web servers: many IP
addresses correspond to one
name
A: doesn‘t scale!
 Comcast DNS servers alone:
600B DNS queries/day
 Akamai DNS servers alone:
2.2T DNS queries/day
ZESHAN.KHAN@NU.EDU.PK
Thinking about the DNS
Application Layer: 2-
63
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
ZESHAN.KHAN@NU.EDU.PK
DNS: a distributed, hierarchical database
Application Layer: 2-
64
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
.com DNS servers .org DNS servers .edu DNS servers
… …
Top Level Domain
Root DNS Servers Root
nyu.edu
DNS servers
umass.edu
DNS servers
yahoo.com
DNS servers
amazon.com
DNS servers
pbs.org
DNS servers Authoritative
…
… … …
ZESHAN.KHAN@NU.EDU.PK
DNS: root name servers
Application Layer: 2-
65
 official, contact-of-last-resort by
name servers that can't resolve
name
ZESHAN.KHAN@NU.EDU.PK
DNS: root name servers
Application Layer: 2-
66
 official, contact-of-last-resort by
name servers that can't resolve
name
 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
13 logical root name “servers”
worldwide each “server” replicated
many times (~200 servers in US)
ZESHAN.KHAN@NU.EDU.PK
Top-Level Domain, and authoritative servers
Application Layer: 2-
67
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
ZESHAN.KHAN@NU.EDU.PK
Local DNS name servers
Application Layer: 2-
68
 when host makes DNS query, it is sent to its local DNS server
• Local DNS server returns reply, answering:
• from its local cache of recent name-to-address translation pairs (possibly out
of date!)
• forwarding request into DNS hierarchy for resolution
• each ISP has local DNS name server; to find yours:
• MacOS: % scutil --dns
• Windows: >ipconfig /all
 local DNS server doesn’t strictly belong to hierarchy
ZESHAN.KHAN@NU.EDU.PK
DNS name resolution: iterated query
Application Layer: 2-
69
Example: host at engineering.nyu.edu
wants IP address for gaia.cs.umass.edu
Iterated query:
 contacted server replies
with name of server to
contact
 “I don’t know this name,
but ask this server”
requesting host at
engineering.nyu.edu
gaia.cs.umass.edu
root DNS server
local DNS server
dns.nyu.edu
1
2
3
4
5
6
authoritative DNS server
dns.cs.umass.edu
7
8
TLD DNS server
ZESHAN.KHAN@NU.EDU.PK
DNS name resolution: recursive query
Application Layer: 2-
70
requesting host at
engineering.nyu.edu
gaia.cs.umass.edu
root DNS server
local DNS server
dns.nyu.edu
1
2 3
4
5
6
authoritative DNS server
dns.cs.umass.edu
7
8
TLD DNS server
Recursive query:
 puts burden of name
resolution on
contacted name
server
 heavy load at upper
levels of hierarchy?
Example: host at engineering.nyu.edu
wants IP address for gaia.cs.umass.edu
ZESHAN.KHAN@NU.EDU.PK
Caching DNS Information
Application Layer: 2-
71
 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!
ZESHAN.KHAN@NU.EDU.PK
DNS records
Application Layer: 2-
72
DNS: distributed database storing resource records (RR)
type=NS
 name is domain
 value is hostname of authoritative
name server for this domain
 (foo.com, dns.foo.com, NS)
RR format: (name, value, type, ttl)
type=A
 name is hostname
 value is IP address
 (relay1.bar.foo.com, 145.37.93.126, A)
type=CNAME
 name is alias name for some “canonical”
(the real) name
 www.ibm.com is really servereast.backup2.ibm.com
 value is canonical name
type=MX
 value is name of SMTP mail
server associated with name
ZESHAN.KHAN@NU.EDU.PK
identification flags
# questions
questions (variable # of questions)
# additional RRs
# authority RRs
# answer RRs
answers (variable # of RRs)
authority (variable # of RRs)
additional info (variable # of RRs)
2 bytes 2 bytes
DNS protocol messages
Application Layer: 2-
73
DNS query and reply messages, both have same format:
message header:
 identification: 16 bit # for query,
reply to query uses same #
 flags:
• query or reply
• recursion desired
• recursion available
• reply is authoritative
ZESHAN.KHAN@NU.EDU.PK
identification flags
# questions
questions (variable # of questions)
# additional RRs
# authority RRs
# answer RRs
answers (variable # of RRs)
authority (variable # of RRs)
additional info (variable # of RRs)
2 bytes 2 bytes
DNS query and reply messages, both have same format:
name, type fields for a query
RRs in response to query
records for authoritative servers
additional “ helpful” info that may
be used
DNS protocol messages
Application Layer: 2-
74
ZESHAN.KHAN@NU.EDU.PK
Getting your info into the DNS
Application Layer: 2-
75
example: new startup “FAST”
 register name fast.com at DNS registrar (e.g., FAST.com)
• provide names, IP addresses of authoritative name server (primary and
secondary)
• registrar inserts NS, A RRs into .com TLD server:
(fast.com, dns1.fast.com, NS)
(dns1.fast.com, 212.212.212.1, A)
 create authoritative server locally with IP address 212.212.212.1
• type A record for www.fast.com
• type MX record for fast.com
ZESHAN.KHAN@NU.EDU.PK
DNS security
Application Layer: 2-
76
DDoS attacks
 bombard root servers with
traffic
• not successful to date
• traffic filtering
• local DNS servers cache IPs of TLD
servers, allowing root server
bypass
 bombard TLD servers
• potentially more dangerous
Spoofing attacks
 intercept DNS queries,
returning bogus replies
 DNS cache poisoning
 RFC 4033: DNSSEC
authentication services
Chapter 2:
Application
layer
ZESHAN.KHAN@NU.EDU.PK
Application Layer:
2-77
Principles of network applications
Web and HTTP
E-mail, SMTP, IMAP
The Domain Name System DNS
P2P applications
video streaming and content distribution networks
socket programming with UDP and TCP
ZESHAN.KHAN@NU.EDU.PK
mobile network
home network
enterprise
network
national or global ISP
local or
regional ISP
datacenter
network
content
provider
network
Peer-to-peer (P2P) architecture
Application Layer: 2-
78
 no always-on server
 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, and new service demands
 peers are intermittently connected
and change IP addresses
• complex management
 examples: P2P file sharing (BitTorrent),
streaming (KanKan), VoIP (Skype)
ZESHAN.KHAN@NU.EDU.PK
File distribution: client-server vs P2P
Application Layer: 2-
79
Q: how much time to distribute file (size F) from one server to N
peers?
• peer upload/download capacity is limited resource
us
uN
dN
server
network (with abundant
bandwidth)
file, size F
us: server upload
capacity
ui: peer i upload
capacity
di: peer i download
capacity
u2 d2
u1 d1
di
ui
ZESHAN.KHAN@NU.EDU.PK
File distribution time: client-server
Application Layer: 2-
80
 server transmission: must sequentially
send (upload) N file copies:
• time to send one copy: F/us
• 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
us
network
di
ui
F
increases linearly in N
time to distribute F
to N clients using
client-server approach
Dc-s > max{NF/us,,F/dmin}
ZESHAN.KHAN@NU.EDU.PK
File distribution time: P2P
Application Layer: 2-
81
 server transmission: must upload at
least one copy:
• time to send one copy: F/us
 client: each client must download
file copy
• min client download time: F/dmin
us
network
di
ui
F
 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)}
… but so does this, as each peer brings service capacity
increases linearly in N …
ZESHAN.KHAN@NU.EDU.PK
Client-server vs. P2P: example
Application Layer: 2-
82
client upload rate = u, F/u = 1 hour, us = 10u, dmin ≥ us
0
0.5
1
1.5
2
2.5
3
3.5
0 5 10 15 20 25 30 35
N
Minimum
Distribution
Time
P2P
Client-Server
ZESHAN.KHAN@NU.EDU.PK
P2P file distribution: BitTorrent
Application Layer: 2-
83
 file divided into 256Kb chunks
 peers in torrent send/receive file chunks
tracker: tracks peers
participating in torrent
torrent: group of peers
exchanging chunks of a file
Alice arrives …
… obtains list
of peers from tracker
… and begins exchanging
file chunks with peers in torrent
ZESHAN.KHAN@NU.EDU.PK
P2P file distribution: BitTorrent
Application Layer: 2-
84
 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
ZESHAN.KHAN@NU.EDU.PK
BitTorrent: requesting, sending file chunks
Application Layer: 2-
85
Requesting chunks:
 at any given time, different
peers have different subsets
of file chunks
 periodically, Alice asks each
peer for list of chunks that
they have
 Alice requests missing
chunks from peers, rarest
first
Sending chunks: tit-for-tat
 Alice sends chunks to those four peers
currently sending her chunks at highest
rate
• other peers are choked by Alice (do not
receive chunks from her)
• re-evaluate top 4 every10 secs
 every 30 secs: randomly select another
peer, starts sending chunks
• “optimistically unchoke” this peer
• newly chosen peer may join top 4
ZESHAN.KHAN@NU.EDU.PK
BitTorrent: tit-for-tat
Application Layer: 2-
86
(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 !
Chapter 2:
Application
layer
ZESHAN.KHAN@NU.EDU.PK
Application Layer:
2-87
Principles of network applications
Web and HTTP
E-mail, SMTP, IMAP
The Domain Name System DNS
P2P applications
video streaming and content distribution networks
socket programming with UDP and TCP
ZESHAN.KHAN@NU.EDU.PK
Video Streaming and CDNs: context
Application Layer: 2-
88
 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
ZESHAN.KHAN@NU.EDU.PK
Multimedia: video
Application Layer: 2-
89
 video: sequence of images displayed
at constant rate
• e.g., 24 images/sec
 digital image: array of pixels
• each pixel represented by bits
 coding: use redundancy within and
between images to decrease # bits
used to encode image
• spatial (within image)
• temporal (from one image to next)
……………………..
spatial coding example: instead
of sending N values of same
color (all purple), send only two
values: color value (purple) and
number of repeated values (N)
……………….…….
frame i
frame i+1
temporal coding example:
instead of sending
complete frame at i+1,
send only differences from
frame i
ZESHAN.KHAN@NU.EDU.PK
Multimedia: video
Application Layer: 2-
90
……………………..
spatial coding example: instead
of sending N values of same
color (all purple), send only two
values: color value (purple) and
number of repeated values (N)
……………….…….
frame i
frame i+1
temporal coding example:
instead of sending
complete frame at i+1,
send only differences from
frame i
 CBR: (constant bit rate): video
encoding rate fixed
 VBR: (variable bit rate): video
encoding rate changes as
amount of spatial, temporal
coding changes
 examples:
• MPEG1 (CD-ROM) 1.5 Mbps
• MPEG2 (DVD) 3-6 Mbps
• MPEG4 (often used in
Internet, 64Kbps – 12 Mbps)
ZESHAN.KHAN@NU.EDU.PK
Streaming 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-
91
simple scenario:
video server
(stored video)
client
Internet
ZESHAN.KHAN@NU.EDU.PK
Streaming stored video
Application Layer: 2-
92
1. video
recorded
(e.g., 30
frames/sec)
2. video
sent
Cumulati
ve
data
streaming: at this time, client playing out
early part of video, while server still sending
later part of video
time
3. video received, played out at client
(30 frames/sec)
network delay
(fixed in this
example)
ZESHAN.KHAN@NU.EDU.PK
Streaming stored video: challenges
Application Layer: 2-
93
 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
ZESHAN.KHAN@NU.EDU.PK
Streaming stored video: playout buffering
Application Layer: 2-
94
constant bit
rate video
transmission
Cumula
tive
data
time
variable
network
delay
client video
reception
constant bit
rate video
playout at client
client playout
delay
buffered
video
client-side buffering and playout delay: compensate for
network-added delay, delay jitter
ZESHAN.KHAN@NU.EDU.PK
Streaming multimedia: DASH
Application Layer: 2-
95
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
...
...
...
Dynamic, Adaptive
Streaming over HTTP
ZESHAN.KHAN@NU.EDU.PK
...
...
...
Streaming multimedia: DASH
Application Layer: 2-
96
“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)
Streaming video = encoding + DASH + playout buffering
client
?
ZESHAN.KHAN@NU.EDU.PK
Content distribution networks (CDNs)
Application Layer: 2-
97
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
ZESHAN.KHAN@NU.EDU.PK
Content distribution networks (CDNs)
Application Layer: 2-
98
challenge: how to stream content (selected from millions of
videos) to hundreds of thousands of simultaneous users?
• enter deep: push CDN servers deep into many access networks
• close to users
• Akamai: 240,000 servers deployed
in > 120 countries (2015)
 option 2: store/serve multiple copies of videos at multiple
geographically distributed sites (CDN)
• bring home: smaller number (10’s) of
larger clusters in POPs near access nets
• used by Limelight
ZESHAN.KHAN@NU.EDU.PK
…
…
…
…
…
…
Content distribution networks (CDNs)
subscriber requests content, service provider returns manifest
Application Layer: 2-
99
 CDN: stores copies of content (e.g. MADMEN) at CDN nodes
where’s Madmen?
manifest file
• using manifest, client retrieves content at highest supportable rate
• may choose different rate or copy if network path congested
ZESHAN.KHAN@NU.EDU.PK
…
…
…
…
…
…
Internet host-host communication as a service
Content distribution networks (CDNs)
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-
100
OTT: “over the top”
Chapter 2:
Application
layer
ZESHAN.KHAN@NU.EDU.PK
Application Layer:
2-101
Principles of network applications
Web and HTTP
E-mail, SMTP, IMAP
The Domain Name System DNS
P2P applications
video streaming and content distribution networks
socket programming with UDP and TCP
ZESHAN.KHAN@NU.EDU.PK
Socket programming
Application Layer: 2-
102
goal: learn how to build client/server applications that
communicate using sockets
socket: door between application process and end-end-transport
protocol
Internet
controlled
by OS
controlled by
app developer
transport
application
physical
link
network
process
transport
application
physical
link
network
process
socket
ZESHAN.KHAN@NU.EDU.PK
Socket programming
Two socket types for two transport services:
 UDP: unreliable datagram
 TCP: reliable, byte stream-oriented
Application Layer: 2-
103
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
ZESHAN.KHAN@NU.EDU.PK
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
Application Layer: 2-
104
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
ZESHAN.KHAN@NU.EDU.PK
Client/server socket interaction: UDP
Application Layer: 2-
105
close
clientSocket
read datagram from
clientSocket
create socket:
clientSocket =
socket(AF_INET,SOCK_DGRAM)
Create datagram with serverIP address
And port=x; send datagram via
clientSocket
create socket, port= x:
serverSocket =
socket(AF_INET,SOCK_DGRAM)
read datagram from
serverSocket
write reply to
serverSocket
specifying
client address,
port number
server (running on serverIP) client
ZESHAN.KHAN@NU.EDU.PK
Example app: UDP client
Application Layer: 2-
106
from socket import *
serverName = ‘hostname’
serverPort = 12000
clientSocket = socket(AF_INET, SOCK_DGRAM)
message = raw_input(’Input lowercase sentence:’)
clientSocket.sendto(message.encode(), (serverName,
serverPort))
modifiedMessage, serverAddress =
clientSocket.recvfrom(2048)
print modifiedMessage.decode()
clientSocket.close()
Python UDPClient
include Python’s socket library
create UDP socket for server
get user keyboard input
attach server name, port to message; send into socket
print out received string and close socket
read reply characters from socket into string
ZESHAN.KHAN@NU.EDU.PK
Example app: UDP server
Application Layer: 2-
107
Python UDPServer
from socket import *
serverPort = 12000
serverSocket = socket(AF_INET, SOCK_DGRAM)
serverSocket.bind(('', serverPort))
print (“The server is ready to receive”)
while True:
message, clientAddress = serverSocket.recvfrom(2048)
modifiedMessage = message.decode().upper()
serverSocket.sendto(modifiedMessage.encode(),
clientAddress)
create UDP socket
bind socket to local port number 12000
loop forever
Read from UDP socket into message, getting
client’s address (client IP and port)
send upper case string back to this client
ZESHAN.KHAN@NU.EDU.PK
Socket programming with TCP
Client must contact server
server process must first be running
server must have created socket
(door) that welcomes client’s contact
Client contacts server by:
Creating TCP socket, specifying IP
address, port number of server
process
when client creates socket: client TCP
establishes connection to server TCP
Application Layer: 2-
108
 when contacted by client, server
TCP creates new socket for server
process to communicate with that
particular client
• allows server to talk with multiple
clients
• source port numbers used to
distinguish clients (more in Chap 3)
TCP provides reliable, in-order
byte-stream transfer (“pipe”)
between client and server
processes
Application viewpoint
ZESHAN.KHAN@NU.EDU.PK
Client/server socket interaction: TCP
Application Layer: 2-
109
server (running on hostid) client
wait for incoming
connection request
connectionSocket =
serverSocket.accept()
create socket,
port=x, for incoming
request:
serverSocket = socket()
create socket,
connect to hostid, port=x
clientSocket = socket()
send request using
clientSocket
read request from
connectionSocket
write reply to
connectionSocket
TCP
connection setup
close
connectionSocket
read reply from
clientSocket
close
clientSocket
ZESHAN.KHAN@NU.EDU.PK
Example app: TCP client
Application Layer: 2-
110
from socket import *
serverName = ’servername’
serverPort = 12000
clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket.connect((serverName,serverPort))
sentence = raw_input(‘Input lowercase sentence:’)
clientSocket.send(sentence.encode())
modifiedSentence = clientSocket.recv(1024)
print (‘From Server:’, modifiedSentence.decode())
clientSocket.close()
Python TCPClient
create TCP socket for server,
remote port 12000
No need to attach server name, port
ZESHAN.KHAN@NU.EDU.PK
Example app: TCP server
Application Layer: 2-
111
from socket import *
serverPort = 12000
serverSocket = socket(AF_INET,SOCK_STREAM)
serverSocket.bind((‘’,serverPort))
serverSocket.listen(1)
print ‘The server is ready to receive’
while True:
connectionSocket, addr = serverSocket.accept()
sentence = connectionSocket.recv(1024).decode()
capitalizedSentence = sentence.upper()
connectionSocket.send(capitalizedSentence.
encode())
connectionSocket.close()
Python TCPServer
create TCP welcoming socket
server begins listening for
incoming TCP requests
loop forever
server waits on accept() for incoming
requests, new socket created on return
read bytes from socket (but
not address as in UDP)
close connection to this client (but not
welcoming socket)
ZESHAN.KHAN@NU.EDU.PK
Chapter 2: Summary
 application architectures
• client-server
• P2P
 application service requirements:
• reliability, bandwidth, delay
 Internet transport service model
• connection-oriented, reliable: TCP
• unreliable, datagrams: UDP
Application Layer: 2-
112
our study of network application layer is now complete!
 specific protocols:
• HTTP
• SMTP, IMAP
• DNS
• P2P: BitTorrent
 video streaming, CDNs
 socket programming:
TCP, UDP sockets
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
ZESHAN.KHAN@NU.EDU.PK
Application Layer:
2-113
ZESHAN.KHAN@NU.EDU.PK
CDN content access: a closer look
Application Layer: 2-
114
netcinema.com
KingCDN.com
1
1. Bob gets URL for video
http://netcinema.com/6Y7B23V
from netcinema.com web page
2
2. resolve http://netcinema.com/6Y7B23V
via Bob’s local DNS
netcinema’s
authoratative DNS
3
3. netcinema’s DNS returns CNAME for
http://KingCDN.com/NetC6y&B23V 4
5
6. request video from
KINGCDN server,
streamed via HTTP
KingCDN
authoritative DNS
Bob’s
local DNS
server
Bob (client) requests video http://netcinema.com/6Y7B23V
 video stored in CDN at http://KingCDN.com/NetC6y&B23V
ZESHAN.KHAN@NU.EDU.PK
Case study: Netflix
Application Layer: 2-
115
1
Bob manages
Netflix account
Netflix registration,
accounting servers
Amazon cloud
CDN
server
2
Bob browses
Netflix video
Manifest file,
requested
returned for
specific video
DASH server
selected, contacted,
streaming begins
upload copies of
multiple versions of
video to CDN servers
CDN
server
CDN
server
3
4

More Related Content

PPTX
CS3001_Computer_Networks_Chapter_2_v8.1(1).pptx
PPTX
kkkkkkkkkkkkkkkkkkkmkm,kll;kl;l;l;l;lll;l;l;;;
PPTX
Computer network network edge and network
PPTX
Chapter_2 Computer Networks Basics....pptx
PPTX
Chapter_2_v8.1.pptx
PPTX
Computer Network presentation chapter two
PDF
20CS2008 Computer Networks
PPTX
Chapter_2_v8.3.pptx
CS3001_Computer_Networks_Chapter_2_v8.1(1).pptx
kkkkkkkkkkkkkkkkkkkmkm,kll;kl;l;l;l;lll;l;l;;;
Computer network network edge and network
Chapter_2 Computer Networks Basics....pptx
Chapter_2_v8.1.pptx
Computer Network presentation chapter two
20CS2008 Computer Networks
Chapter_2_v8.3.pptx

Similar to CS3001_Computer_Networks_Chapter_2_v8.1.pptx (20)

PDF
Application Layer Application Layer Application Layer
PPTX
Chapter_2 jaringan komputer informatika.pptx
PPT
applicationapplicationapplicationapplication.ppt
PPT
Chapter 2 - Computer Networking a top-down Approach 7th
PPT
Chapter_2_V7.01.ppt The client sends one request message for the HTML file, a...
PPT
Chapter 2 Application Layer Computer Networks
PPT
principles of network applications 2.2 Web and HTTP 2.3 electronic mail SMTP,...
PPT
Chapter2_L2.ppt
PPT
Application Layer.pptand documents of co
PPTX
Ci hy Jo is type ki videos edit krei Inbox kro mujhe with similar portfolio ...
PPT
Chapter_2_V6.1._C__hapter_2_V6.1____.ppt
PPT
Chapter 2 v6.3
PPT
Hasanain_Application Layer_Chapter_2_Version 7.1.ppt
PPT
Chapter2 l2 modified_um
PPTX
02_Chapter_2_V6_LV.pptx
PPT
Chapter_2 computer netwprks mod 2 enclosed
PPTX
Transport Layer and Client-Server Socket communications 2022.pptx
PPTX
Net_Chapter_2_ computer network-software.pptx
PPT
Ch2 application layer Network
PPTX
2 - Applications.pptx cccccccccccccccccc
Application Layer Application Layer Application Layer
Chapter_2 jaringan komputer informatika.pptx
applicationapplicationapplicationapplication.ppt
Chapter 2 - Computer Networking a top-down Approach 7th
Chapter_2_V7.01.ppt The client sends one request message for the HTML file, a...
Chapter 2 Application Layer Computer Networks
principles of network applications 2.2 Web and HTTP 2.3 electronic mail SMTP,...
Chapter2_L2.ppt
Application Layer.pptand documents of co
Ci hy Jo is type ki videos edit krei Inbox kro mujhe with similar portfolio ...
Chapter_2_V6.1._C__hapter_2_V6.1____.ppt
Chapter 2 v6.3
Hasanain_Application Layer_Chapter_2_Version 7.1.ppt
Chapter2 l2 modified_um
02_Chapter_2_V6_LV.pptx
Chapter_2 computer netwprks mod 2 enclosed
Transport Layer and Client-Server Socket communications 2022.pptx
Net_Chapter_2_ computer network-software.pptx
Ch2 application layer Network
2 - Applications.pptx cccccccccccccccccc
Ad

More from MujtabaVlogs (19)

PDF
Lecture 2 The Environment and Corporate Culture.pdf
PDF
Lecture 3 Managing Ethics and Social Responsibility.pdf
PDF
Lecture 1 Introduction to Mangement and Management thinking.pdf
PDF
L06-07 Software Design Requirements Basics.pdf
PDF
L08-09-10 Use cases - Use case Diagram- Expanded Use Cases.pdf
PDF
L13 L14 Software System Sequence Diagram.pdf
PPTX
Chapter 6 - Operating System Deadlock.pptx
PPTX
Chapter 5 - Operating Synchronization.pptx
PPTX
Week 12 Operating System Lectures lec 2.pptx
PPTX
Chapter 4 - Operating Systems Threads.pptx
PPTX
Chapter 3 - InterProcess Communication.pptx
PPTX
Chapter 3 - Operating System Scheduling.pptx
PPTX
Chapter 1 - Operating Systems Introduction.pptx
PPTX
Chapter 0 - Operating System Preliminaries.pptx
PPTX
Chapter 2 - Operating System Processes(1).pptx
PPT
Lec-4-2-Recurrence Relation-Iteration Method.ppt
PPTX
Network layer. IP Addressing Part 1.pptx
PDF
CS3001-Computer-Networks-Ch3-Chapter-3.pdf
PPTX
CS3001_Computer_Networks_Chapter_1_v8.1.pptx
Lecture 2 The Environment and Corporate Culture.pdf
Lecture 3 Managing Ethics and Social Responsibility.pdf
Lecture 1 Introduction to Mangement and Management thinking.pdf
L06-07 Software Design Requirements Basics.pdf
L08-09-10 Use cases - Use case Diagram- Expanded Use Cases.pdf
L13 L14 Software System Sequence Diagram.pdf
Chapter 6 - Operating System Deadlock.pptx
Chapter 5 - Operating Synchronization.pptx
Week 12 Operating System Lectures lec 2.pptx
Chapter 4 - Operating Systems Threads.pptx
Chapter 3 - InterProcess Communication.pptx
Chapter 3 - Operating System Scheduling.pptx
Chapter 1 - Operating Systems Introduction.pptx
Chapter 0 - Operating System Preliminaries.pptx
Chapter 2 - Operating System Processes(1).pptx
Lec-4-2-Recurrence Relation-Iteration Method.ppt
Network layer. IP Addressing Part 1.pptx
CS3001-Computer-Networks-Ch3-Chapter-3.pdf
CS3001_Computer_Networks_Chapter_1_v8.1.pptx
Ad

Recently uploaded (20)

PPTX
Wireless sensor networks (WSN) SRM unit 2
PPTX
chapter 1.pptx dotnet technology introduction
PPTX
Quality engineering part 1 for engineering undergraduates
PDF
MACCAFERRY GUIA GAVIONES TERRAPLENES EN ESPAÑOL
PPTX
Real Estate Management PART 1.pptxFFFFFFFFFFFFF
PDF
electrical machines course file-anna university
PDF
LS-6-Digital-Literacy (1) K12 CURRICULUM .pdf
PPTX
Environmental studies, Moudle 3-Environmental Pollution.pptx
PPTX
AI-Reporting for Emerging Technologies(BS Computer Engineering)
PDF
Using Technology to Foster Innovative Teaching Practices (www.kiu.ac.ug)
PPTX
CNS - Unit 1 (Introduction To Computer Networks) - PPT (2).pptx
PDF
[jvmmeetup] next-gen integration with apache camel and quarkus.pdf
PPTX
Design ,Art Across Digital Realities and eXtended Reality
PPT
Programmable Logic Controller PLC and Industrial Automation
PPTX
ARCHITECTURE AND PROGRAMMING OF EMBEDDED SYSTEMS
PPTX
Environmental studies, Moudle 3-Environmental Pollution.pptx
PPTX
Agentic Artificial Intelligence (Agentic AI).pptx
DOCX
An investigation of the use of recycled crumb rubber as a partial replacement...
PDF
Software defined netwoks is useful to learn NFV and virtual Lans
PDF
ASPEN PLUS USER GUIDE - PROCESS SIMULATIONS
Wireless sensor networks (WSN) SRM unit 2
chapter 1.pptx dotnet technology introduction
Quality engineering part 1 for engineering undergraduates
MACCAFERRY GUIA GAVIONES TERRAPLENES EN ESPAÑOL
Real Estate Management PART 1.pptxFFFFFFFFFFFFF
electrical machines course file-anna university
LS-6-Digital-Literacy (1) K12 CURRICULUM .pdf
Environmental studies, Moudle 3-Environmental Pollution.pptx
AI-Reporting for Emerging Technologies(BS Computer Engineering)
Using Technology to Foster Innovative Teaching Practices (www.kiu.ac.ug)
CNS - Unit 1 (Introduction To Computer Networks) - PPT (2).pptx
[jvmmeetup] next-gen integration with apache camel and quarkus.pdf
Design ,Art Across Digital Realities and eXtended Reality
Programmable Logic Controller PLC and Industrial Automation
ARCHITECTURE AND PROGRAMMING OF EMBEDDED SYSTEMS
Environmental studies, Moudle 3-Environmental Pollution.pptx
Agentic Artificial Intelligence (Agentic AI).pptx
An investigation of the use of recycled crumb rubber as a partial replacement...
Software defined netwoks is useful to learn NFV and virtual Lans
ASPEN PLUS USER GUIDE - PROCESS SIMULATIONS

CS3001_Computer_Networks_Chapter_2_v8.1.pptx

  • 1. Chapter 2: Application Layer Lect ure Slides f rom the Boo k authors http://gaia.cs.umas s.edu/kuro se_ross / interactive/
  • 2. Layers [email protected] Application Layer: 2-2 APPLICATION PRESENTATION SESSION TRANSPORT NETWORK LINK PHYSICAL
  • 3. Chapter 2: Application layer [email protected] Application Layer: 2-3 Principles of network applications Web and HTTP E-mail, SMTP, IMAP The Domain Name System DNS P2P applications video streaming and content distribution networks socket programming with UDP and TCP
  • 4. [email protected] Application layer: overview Our goals:  conceptual and implementation aspects of application-layer protocols • transport-layer service models • client-server paradigm • peer-to-peer paradigm  learn about protocols by examining popular application-layer protocols and infrastructure • HTTP • SMTP, IMAP • DNS • video streaming systems, CDNs  programming network applications • socket API Application Layer: 2- 4
  • 5. [email protected] Some network apps  social networking  Web  text messaging  e-mail  multi-user network games  streaming stored video (YouTube, Hulu, Netflix)  P2P file sharing  voice over IP (e.g., Skype)  real-time video conferencing (e.g., Zoom, meet)  Internet search  remote login  … Application Layer: 2- 5
  • 6. [email protected] mobile network home network enterprise network national or global ISP local or regional ISP datacenter network content provider network application transport network data link physical application transport network data link physical application transport network data link physical Creating a network app Application Layer: 2- 6 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 for network-core devices  network-core devices do not run user applications  applications on end systems allows for rapid app development, propagation
  • 7. [email protected] mobile network home network enterprise network national or global ISP local or regional ISP datacenter network content provider network Client-server paradigm Application Layer: 2- 7 server:  always-on host  permanent IP address  often in data centers, for scaling clients:  contact, communicate with server  may be intermittently connected  may have dynamic IP addresses  do not communicate directly with each other  examples: HTTP, IMAP, FTP
  • 8. [email protected] mobile network home network enterprise network national or global ISP local or regional ISP datacenter network content provider network Peer-peer architecture Application Layer: 2- 8  no always-on server  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  example: P2P file sharing
  • 9. [email protected] Processes communicating Application Layer: 2- 9 process: program running within a host within same host, two processes communicate using inter-process communication (defined by OS) processes in different hosts communicate by exchanging messages  note: applications with P2P architectures have client processes & server processes client process: process that initiates communication server process: process that waits to be contacted clients, servers
  • 10. [email protected] Sockets Application Layer: 2- 10  process sends/receives messages to/from its socket  socket analogous to door • sending process shoves message outdoor • sending process relies on transport infrastructure on other side of door to deliver message to socket at receiving process • two sockets involved: one on each side Internet controlled by OS controlled by app developer transport application physical link network process transport application physical link network process socket
  • 11. [email protected] Addressing processes Application Layer: 2- 11  to receive messages, process must have identifier  host device has unique 32-bit IP address  Q: does IP address of host on which process runs suffice for identifying the process?  A: no, many processes can be running on same host  identifier includes both IP address and port numbers associated with process on host.  example port numbers: • HTTP server: 80 • mail server: 25  to send HTTP message to gaia.cs.umass.edu web server: • IP address: 128.119.245.12 • port number: 80  more shortly…
  • 12. [email protected] An application-layer protocol defines: Application Layer: 2- 12  types of messages exchanged, • e.g., request, response  message syntax: • what fields in messages & how fields are delineated  message semantics • meaning of information in fields  rules for when and how processes send & respond to messages open protocols:  defined in RFCs, everyone has access to protocol definition  allows for interoperability  e.g., HTTP, SMTP proprietary protocols:  e.g., Skype, Zoom
  • 13. [email protected] What transport service does an app need? Application Layer: 2- 13 data integrity  some apps (e.g., file transfer, web transactions) require 100% reliable data transfer  other apps (e.g., audio) can tolerate some loss timing  some apps (e.g., Internet telephony, interactive games) require low delay to be “effective” throughput  some apps (e.g., multimedia) require minimum amount of throughput to be “effective”  other apps (“elastic apps”) make use of whatever throughput they get security  encryption, data integrity, …
  • 14. Transport service requirements: common apps [email protected] Application Layer: 2-14 application data loss throughput time sensitive? file transfer/download no loss elastic No e-mail no loss elastic No Web documents no loss elastic No real-time audio/video loss-tolerant audio: 5Kbps- 1Mbps video:10Kbps- 5Mbps yes, 10’s msec streaming audio/video loss-tolerant audio: 5Kbps- 1Mbps video:10Kbps- 5Mbps yes, few secs interactive games loss-tolerant Kbps yes, 10’s msec text messaging no loss elastic yes and no
  • 15. [email protected] Internet transport protocols services Application Layer: 2- 15 TCP service:  reliable transport between sending and receiving process  flow control: sender won’t overwhelm receiver  congestion control: throttle sender when network overloaded  connection-oriented: setup required between client and server processes  does not provide: timing, minimum throughput guarantee, security UDP service:  unreliable data transfer between sending and receiving process  does not provide: reliability, flow control, congestion control, timing, throughput guarantee, security, or connection setup. Q: why bother? Why is there a UDP?
  • 16. Internet applications, and transport protocols [email protected] Application Layer: 2-16 Application application layer protocol transport protocol file transfer/download FTP [RFC 959] TCP e-mail SMTP [RFC 5321] TCP Web documents HTTP 1.1 [RFC 7320] TCP Internet telephony SIP [RFC 3261], RTP [RFC 3550], or proprietary TCP or UDP streaming audio/video HTTP [RFC 7320], DASH TCP interactive games WOW, FPS (proprietary) TCP or UDP
  • 17. [email protected] Securing TCP Application Layer: 2- 17 Vanilla TCP & UDP sockets:  no encryption  cleartext passwords sent into socket traverse Internet in cleartext (!) Transport Layer Security (TLS)  provides encrypted TCP connections  data integrity  end-point authentication TLS implemented in application layer  apps use TLS libraries, that use TCP in turn  cleartext sent into “socket” traverse Internet encrypted  more: Chapter 8
  • 18. Chapter 2: Application layer [email protected] Application Layer: 2-18 Principles of network applications Web and HTTP E-mail, SMTP, IMAP The Domain Name System DNS P2P applications video streaming and content distribution networks socket programming with UDP and TCP
  • 19. Web and HTTP Transport Layer: 3- 19  web page consists of objects, each of which can be stored on different Web servers  object can be HTML file, JPEG image, Java applet, audio file,…  web page consists of base HTML-file which includes several referenced objects, each addressable by a URL, e.g., www.someschool.edu/someDept/pic.gif host name path name
  • 20. HTTP overview Transport Layer: 3- 20 HTTP: hypertext transfer protocol  Web’s application-layer protocol  client/server model: • client: browser that requests, receives, (using HTTP protocol) and “displays” Web objects • server: Web server sends (using HTTP protocol) objects in response to requests HTTP request HTTP response HTTP request HTTP response iPhone running Safari browser PC running Firefox browser server running Apache Web server
  • 21. HTTP overview (continued) Transport Layer: 3- 21 HTTP uses TCP:  client initiates TCP connection (creates socket) to server, port 80  server accepts TCP connection from client  HTTP messages (application-layer protocol messages) exchanged between browser (HTTP client) and Web server (HTTP server)  TCP connection closed HTTP is “stateless”  server maintains no information about past client requests protocols that maintain “state” are complex!  past history (state) must be maintained  if server/client crashes, their views of “state” may be inconsistent, must be reconciled aside
  • 22. HTTP connections: two types Transport Layer: 3- 22 Non-persistent HTTP 1. TCP connection opened 2. at most one object sent over TCP connection 3. TCP connection closed downloading multiple objects required multiple connections Persistent HTTP TCP connection opened to a server multiple objects can be sent over single TCP connection between client, and that server TCP connection closed
  • 23. Non-persistent HTTP: example Transport Layer: 3- 23 User enters URL: 1a. HTTP client initiates TCP connection to HTTP server (process) at www.someSchool.edu on port 80 2. HTTP client sends HTTP request message (containing URL) into TCP connection socket. Message indicates that client wants object someDepartment/home.index 1b. HTTP server at host www.someSchool.edu waiting for TCP connection at port 80 “accepts” connection, notifying client 3. HTTP server receives request message, forms response message containing requested object, and sends message into its socket time (containing text, references to 10 jpeg images) www.someSchool.edu/someDepartment/home.index
  • 24. Non-persistent HTTP: example (cont.) Transport Layer: 3- 24 User enters URL: (containing text, references to 10 jpeg images) www.someSchool.edu/someDepartment/home.index 5. HTTP client receives response message containing html file, displays html. Parsing html file, finds 10 referenced jpeg objects 6. Steps 1-5 repeated for each of 10 jpeg objects 4. HTTP server closes TCP connection. time
  • 25. Non-persistent HTTP: response time Transport Layer: 3- 25 RTT (definition): time for a small packet to travel from client to server and back HTTP response time (per object):  one RTT to initiate TCP connection  one RTT for HTTP request and first few bytes of HTTP response to return  object/file transmission time time to transmit file initiate TCP connection RTT request file RTT file received time time Non-persistent HTTP response time = 2RTT+ file transmission time
  • 26. Persistent HTTP (HTTP 1.1) Transport Layer: 3- 26 Non-persistent HTTP issues:  requires 2 RTTs per object  OS overhead for each TCP connection  browsers often open multiple parallel TCP connections to fetch referenced objects in parallel Persistent HTTP (HTTP1.1):  server leaves connection open after sending response  subsequent HTTP messages between same client/server sent over open connection  client sends requests as soon as it encounters a referenced object  as little as one RTT for all the referenced objects (cutting response time in half)
  • 27. HTTP request message Transport Layer: 3- 27  two types of HTTP messages: request, response  HTTP request message: • ASCII (human-readable format) header lines GET /index.html HTTP/1.1rn Host: www-net.cs.umass.edurn User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:80.0) Gecko/20100101 Firefox/80.0 rn Accept: text/html,application/xhtml+xmlrn Accept-Language: en-us,en;q=0.5rn Accept-Encoding: gzip,deflatern Connection: keep-alivern rn carriage return character line-feed character request line (GET, POST, HEAD commands) carriage return, line feed at start of line indicates end of header lines
  • 28. HTTP request message: general format Transport Layer: 3- 28 request line header lines body method sp sp cr lf version URL cr lf value header field name cr lf value header field name ~ ~ ~ ~ cr lf entity body ~ ~ ~ ~
  • 29. Other HTTP request messages Transport Layer: 3- 29 POST method:  web page often includes form input  user input sent from client to server in entity body of HTTP POST request message GET method (for sending data to server):  include user data in URL field of HTTP GET request message (following a ‘?’): www.somesite.com/animalsearch?monkeys&banana HEAD method:  requests headers (only) that would be returned if specified URL were requested with an HTTP GET method. PUT method:  uploads new file (object) to server  completely replaces file that exists at specified URL with content in entity body of POST HTTP request message
  • 30. HTTP response message Transport Layer: 3- 30 status line (protocol status code status phrase) header lines data, e.g., requested HTML file Date: Tue, 08 Sep 2020 00:53:20 GMT Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.9 mod_perl/2.0.11 Perl/v5.16.3 Last-Modified: Tue, 01 Mar 2016 18:57:50 GMT ETag: "a5b-52d015789ee9e" Accept-Ranges: bytes Content-Length: 2651 Content-Type: text/html; charset=UTF-8 rn data data data data data ... HTTP/1.1 200 OK
  • 31. HTTP response status codes Transport Layer: 3- 31  status code appears in 1st line in server- to-client response message.  some sample codes: • request succeeded, requested object later in this message 200 OK • requested object moved, new location specified later in this message (in Location: field) 301 Moved Permanently • request msg not understood by server 400 Bad Request • requested document not found on this server 404 Not Found 505 HTTP Version Not Supported
  • 32. Maintaining user/server state: cookies Transport Layer: 3- 33 Recall: HTTP GET/response interaction is stateless  no notion of multi-step exchanges of HTTP messages to complete a Web “transaction” • no need for client/server to track “state” of multi-step exchange • all HTTP requests are independent of each other • no need for client/server to “recover” from a partially-completed-but-never- completely-completed transaction a stateful protocol: client makes two changes to X, or none at all time time OK OK unlock X OK update X X’ update X X’’ lock data record X OK X X X’ X’’ X’’ t’ Q: what happens if network connection or client crashes at t’ ?
  • 33. Maintaining user/server state: cookies Transport Layer: 3- 34 Web sites and client browser use cookies to maintain some state between transactions four components: 1) cookie header line of HTTP response message 2) cookie header line in next HTTP request message 3) cookie file kept on user’s host, managed by user’s browser 4) back-end database at Web site Example:  Susan uses browser on laptop, visits specific e-commerce site for first time  when initial HTTP requests arrives at site, site creates: • unique ID (aka “cookie”) • entry in backend database for ID • subsequent HTTP requests from Susan to this site will contain cookie ID value, allowing site to “identify” Susan
  • 34. Maintaining user/server state: cookies Transport Layer: 3- 35 client server usual HTTP response msg usual HTTP response msg cookie file one week later: usual HTTP request msg cookie: 1678 cookie- specific action access ebay 8734 usual HTTP request msg Amazon server creates ID 1678 for user create entry usual HTTP response set-cookie: 1678 ebay 8734 amazon 1678 usual HTTP request msg cookie: 1678 cookie- specific action access ebay 8734 amazon 1678 backend database time time
  • 35. HTTP cookies: comments Transport Layer: 3- 36 What cookies can be used for:  authorization  shopping carts  recommendations  user session state (Web e-mail) cookies and privacy:  cookies permit sites to learn a lot about you on their site.  third party persistent cookies (tracking cookies) allow common identity (cookie value) to be tracked across multiple web sites aside Challenge: How to keep state?  at protocol endpoints: maintain state at sender/receiver over multiple transactions  in messages: cookies in HTTP messages carry state
  • 36. Web caches Transport Layer: 3- 37  user configures browser to point to a (local) Web cache  browser sends all HTTP requests to cache • if object in cache: cache returns object to client • else cache requests object from origin server, caches received object, then returns object to client Goal: satisfy client requests without involving origin server client Web cache client HTTP request HTTP response HTTP request HTTP request origin server HTTP response HTTP response
  • 37. Web caches (proxy servers) Transport Layer: 3- 38  Web cache acts as both client and server • server for original requesting client • client to origin server Why Web caching?  reduce response time for client request • cache is closer to client  reduce traffic on an institution’s access link  Internet is dense with caches • enables “poor” content providers to more effectively deliver content  server tells cache about object’s allowable caching in response header:
  • 38. Caching example Transport Layer: 3- 39 origin servers public Internet institutional network 1 Gbps LAN 1.54 Mbps access link Scenario:  access link rate: 1.54 Mbps  RTT from institutional router to server: 2 sec  web object size: 100K bits  average request rate from browsers to origin servers: 15/sec  avg data rate to browsers: 1.50 Mbps Performance Access Link  A=packet arrival rate (requests/second)=15/sec  R=transmission rate (bits/second)=1.54M/s  L=Packet size=100K  Traffic Intensity=LA/R=100K*15/1.54M=0.97
  • 39. Caching example Transport Layer: 3- 40 origin servers public Internet institutional network 1 Gbps LAN 1.54 Mbps access link Scenario:  access link rate: 1.54 Mbps  RTT from institutional router to server: 2 sec  web object size: 100K bits  average request rate from browsers to origin servers: 15/sec  avg data rate to browsers: 1.50 Mbps Performance Institute LAN  A=packet arrival rate (requests/second)=15/sec  R=transmission rate (bits/second)=1G/s  L=Packet size=100K  Traffic Intensity=LA/R=100K*15/1G=0.0015
  • 40. Caching example Transport Layer: 3- 41 origin servers public Internet institutional network 1 Gbps LAN 1.54 Mbps access link Performance:  access link utilization = .97  LAN utilization: .0015  end-end delay = Internet delay + access link delay + LAN delay = 2 sec + minutes + micro secs Scenario:  access link rate: 1.54 Mbps  RTT from institutional router to server: 2 sec  web object size: 100K bits  average request rate from browsers to origin servers: 15/sec  avg data rate to browsers: 1.50 Mbps problem: large queueing delays at high utilization!
  • 41. Performance:  access link utilization = .97  LAN utilization: .0015  end-end delay = Internet delay + access link delay + LAN delay = 2 sec + minutes + micro secs Option 1: buy a faster access link Transport Layer: 3- 42 origin servers public Internet institutional network 1 Gbps LAN 1.54 Mbps access link Scenario:  access link rate: 1.54 Mbps  RTT from institutional router to server: 2 sec  web object size: 100K bits  average request rate from browsers to origin servers: 15/sec  avg data rate to browsers: 1.50 Mbps 154 Mbps 154 Mbps .0097 msecs Cost: faster access link (expensive!)
  • 42. Performance:  LAN utilization: .?  access link utilization = ?  average end-end delay = ? Option 2: install a web cache Transport Layer: 3- 43 origin servers public Internet institutional network 1 Gbps LAN 1.54 Mbps access link Scenario:  access link rate: 1.54 Mbps  RTT from institutional router to server: 2 sec  web object size: 100K bits  average request rate from browsers to origin servers: 15/sec  avg data rate to browsers: 1.50 Mbps How to compute link utilization, delay? Cost: web cache (cheap!) local web cache
  • 43. Calculating access link utilization, end-end delay with cache: Transport Layer: 3- 44 origin servers public Internet institutional network 1 Gbps LAN 1.54 Mbps access link local web cache suppose cache hit rate is 0.4:  40% requests served by cache, with low (msec) delay  60% requests satisfied at origin • rate to browsers over access link = 0.6 * 1.50 Mbps = .9 Mbps • access link utilization = 0.9/1.54 = .58 means low (msec) queueing delay at access link  average end-end delay: = 0.6 * (delay from origin servers) + 0.4 * (delay when satisfied at cache) = 0.6 (2.01) + 0.4 (~msecs) = ~ 1.2 secs lower average end-end delay than with 154 Mbps link (and cheaper too!)
  • 44. Conditional GET Transport Layer: 3- 45 Goal: don’t send object if cache has up-to-date cached version • no object transmission delay (or use of network resources)  client: specify date of cached copy in HTTP request If-modified-since: <date>  server: response contains no object if cached copy is up-to-date: HTTP/1.0 304 Not Modified HTTP request msg If-modified-since: <date> HTTP response HTTP/1.0 304 Not Modified object not modified before <date> HTTP request msg If-modified-since: <date> HTTP response HTTP/1.0 200 OK <data> object modified after <date> client server
  • 45. HTTP/2 Transport Layer: 3-46 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
  • 46. HTTP/2 Transport Layer: 3- 47 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 Key goal: decreased delay in multi-object HTTP requests
  • 47. HTTP/2: mitigating HOL blocking Transport Layer: 3- 48 HTTP 1.1: client requests 1 large object (e.g., video file) and 3 smaller objects client server GET O1 GET O2 GET O3 GET O4 O1 O2 O3 O4 object data requested O1 O2 O3 O4 objects delivered in order requested: O2, O3, O4 wait behind O1
  • 48. HTTP/2: mitigating HOL blocking Transport Layer: 3- 49 HTTP/2: objects divided into frames, frame transmission interleaved client server GET O1 GET O2 GET O3 GET O4 O2 O4 object data requested O1 O2 O3 O4 O2, O3, O4 delivered quickly, O1 slightly delayed O3 O1
  • 49. HTTP/2 to HTTP/3 Transport Layer: 3- 50 HTTP/2 over single TCP connection means:  recovery from packet loss still stalls all object transmissions • as in HTTP 1.1, browsers have incentive to open multiple parallel TCP connections to reduce stalling, increase overall throughput  no security over vanilla TCP connection  HTTP/3: adds security, per object error- and congestion- control (more pipelining) over UDP • more on HTTP/3 in transport layer
  • 50. Chapter 2: Application layer [email protected] Application Layer: 2-51 Principles of network applications Web and HTTP E-mail, SMTP, IMAP The Domain Name System DNS P2P applications video streaming and content distribution networks socket programming with UDP and TCP
  • 51. [email protected] E-mail Application Layer: 2- 52 Three major components: user agents mail servers simple mail transfer protocol: SMTP User Agent “mail reader” composing, editing, reading mail messages e.g., Outlook, iPhone mail client outgoing, incoming messages stored on server user mailbox outgoing message queue mail server mail server mail server SMTP SMTP SMTP user agent user agent user agent user agent user agent user agent
  • 52. [email protected] E-mail: mail servers Application Layer: 2- 53 user mailbox outgoing message queue mail server mail server mail server SMTP SMTP SMTP user agent user agent user agent user agent user agent user agent mail servers:  mailbox contains incoming messages for user  message queue of outgoing (to be sent) mail messages SMTP protocol between mail servers to send email messages  client: sending mail server  “server”: receiving mail server
  • 53. [email protected] SMTP RFC (5321) Application Layer: 2- 54  uses TCP to reliably transfer email message from client (mail server initiating connection) to server, port 25  direct transfer: sending server (acting like client) to receiving server  three phases of transfer • SMTP handshaking (greeting) • SMTP transfer of messages • SMTP closure  command/response interaction (like HTTP) • commands: ASCII text • response: status code and phrase initiate TCP connection RTT time 220 250 Hello HELO SMTP handshaking TCP connection initiated “client” SMTP server “server” SMTP server SMTP transfers
  • 54. [email protected] Scenario: Alice sends e-mail to Bob Application Layer: 2- 55 1) Alice uses UA to compose e-mail message “to” [email protected] 4) SMTP client sends Alice’s message over the TCP connection user agent mail server mail server 1 2 3 4 5 6 Alice’s mail server Bob’s mail server user agent 2) Alice’s UA sends message to her mail server using SMTP; message placed in message queue 3) client side of SMTP at mail server opens TCP connection with Bob’s mail server 5) Bob’s mail server places the message in Bob’s mailbox 6) Bob invokes his user agent to read message
  • 55. [email protected] SMTP: observations Application Layer: 2- 56  SMTP uses persistent connections  SMTP requires message (header & body) to be in 7-bit ASCII  SMTP server uses CRLF.CRLF to determine end of message comparison with HTTP:  HTTP: client pull  SMTP: client push  both have ASCII command/response interaction, status codes  HTTP: each object encapsulated in its own response message  SMTP: multiple objects sent in multipart message
  • 56. [email protected] Mail message format Application Layer: 2- 57 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 body blank line  header lines, e.g., • To: • From: • Subject: these lines, within the body of the email message area different from SMTP MAIL FROM:, RCPT TO: commands!  Body: the “message” , ASCII characters only
  • 57. [email protected] Retrieving email: mail access protocols Application Layer: 2- 58 sender’s e-mail server SMTP SMTP receiver’s e-mail server e-mail access protocol (e.g., IMAP, HTTP) user agent user agent  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
  • 58. [email protected] SMTP vs IMAP SMTP (SIMPLE MAIL TRANSFER PROTOCOL) It is primarily used for sending emails from a client (such as an email application or server) to an email server or between email servers. It handles the process of sending outgoing emails, including routing emails to the appropriate recipient's email server. It operates on port 25 (although encrypted versions like SMTPS or SMTP over TLS may use different ports) and is responsible for transferring the email message from the sender's email client to the recipient's email server. IMAP (INTERNET MESSAGE ACCESS PROTOCOL) It is used for accessing emails stored on an email server from a client device (such as an email application or webmail client). It allows users to view, manage, and organize their email messages stored on the server without downloading them to the client device. It supports features like folder synchronization, allowing changes made on one device to be reflected on other devices accessing the same email account. It operates on port 143 (or 993 for IMAP over TLS/SSL) and provides a way for email clients to communicate with the email server to retrieve and manage emails. Application Layer: 2- 59
  • 59. Chapter 2: Application layer [email protected] Application Layer: 2-60 Principles of network applications Web and HTTP E-mail, SMTP, IMAP The Domain Name System DNS P2P applications video streaming and content distribution networks socket programming with UDP and TCP
  • 60. [email protected] DNS: Domain Name System Application Layer: 2- 61 people: many identifiers: • SSN, name, passport # Internet hosts, routers: • IP address (32 bit) - used for addressing datagrams • “name”, e.g., cs.umass.edu - used by humans Q: how to map between IP address and name, and vice versa ? Domain Name System (DNS):  distributed database implemented in hierarchy of many name servers  application-layer protocol: hosts, DNS servers communicate to resolve names (address/name translation) • note: core Internet function, implemented as application-layer protocol • complexity at network’s “edge”
  • 61. [email protected] DNS: services, structure Application Layer: 2- 62 Q: Why not centralize DNS?  single point of failure  traffic volume  distant centralized database  maintenance DNS services: hostname-to-IP-address translation host aliasing • canonical, alias names  mail server aliasing  load distribution • replicated Web servers: many IP addresses correspond to one name A: doesn‘t scale!  Comcast DNS servers alone: 600B DNS queries/day  Akamai DNS servers alone: 2.2T DNS queries/day
  • 62. [email protected] Thinking about the DNS Application Layer: 2- 63 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
  • 63. [email protected] DNS: a distributed, hierarchical database Application Layer: 2- 64 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 .com DNS servers .org DNS servers .edu DNS servers … … Top Level Domain Root DNS Servers Root nyu.edu DNS servers umass.edu DNS servers yahoo.com DNS servers amazon.com DNS servers pbs.org DNS servers Authoritative … … … …
  • 64. [email protected] DNS: root name servers Application Layer: 2- 65  official, contact-of-last-resort by name servers that can't resolve name
  • 65. [email protected] DNS: root name servers Application Layer: 2- 66  official, contact-of-last-resort by name servers that can't resolve name  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 13 logical root name “servers” worldwide each “server” replicated many times (~200 servers in US)
  • 66. [email protected] Top-Level Domain, and authoritative servers Application Layer: 2- 67 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
  • 67. [email protected] Local DNS name servers Application Layer: 2- 68  when host makes DNS query, it is sent to its local DNS server • Local DNS server returns reply, answering: • from its local cache of recent name-to-address translation pairs (possibly out of date!) • forwarding request into DNS hierarchy for resolution • each ISP has local DNS name server; to find yours: • MacOS: % scutil --dns • Windows: >ipconfig /all  local DNS server doesn’t strictly belong to hierarchy
  • 68. [email protected] DNS name resolution: iterated query Application Layer: 2- 69 Example: host at engineering.nyu.edu wants IP address for gaia.cs.umass.edu Iterated query:  contacted server replies with name of server to contact  “I don’t know this name, but ask this server” requesting host at engineering.nyu.edu gaia.cs.umass.edu root DNS server local DNS server dns.nyu.edu 1 2 3 4 5 6 authoritative DNS server dns.cs.umass.edu 7 8 TLD DNS server
  • 69. [email protected] DNS name resolution: recursive query Application Layer: 2- 70 requesting host at engineering.nyu.edu gaia.cs.umass.edu root DNS server local DNS server dns.nyu.edu 1 2 3 4 5 6 authoritative DNS server dns.cs.umass.edu 7 8 TLD DNS server Recursive query:  puts burden of name resolution on contacted name server  heavy load at upper levels of hierarchy? Example: host at engineering.nyu.edu wants IP address for gaia.cs.umass.edu
  • 70. [email protected] Caching DNS Information Application Layer: 2- 71  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!
  • 71. [email protected] DNS records Application Layer: 2- 72 DNS: distributed database storing resource records (RR) type=NS  name is domain  value is hostname of authoritative name server for this domain  (foo.com, dns.foo.com, NS) RR format: (name, value, type, ttl) type=A  name is hostname  value is IP address  (relay1.bar.foo.com, 145.37.93.126, A) type=CNAME  name is alias name for some “canonical” (the real) name  www.ibm.com is really servereast.backup2.ibm.com  value is canonical name type=MX  value is name of SMTP mail server associated with name
  • 72. [email protected] identification flags # questions questions (variable # of questions) # additional RRs # authority RRs # answer RRs answers (variable # of RRs) authority (variable # of RRs) additional info (variable # of RRs) 2 bytes 2 bytes DNS protocol messages Application Layer: 2- 73 DNS query and reply messages, both have same format: message header:  identification: 16 bit # for query, reply to query uses same #  flags: • query or reply • recursion desired • recursion available • reply is authoritative
  • 73. [email protected] identification flags # questions questions (variable # of questions) # additional RRs # authority RRs # answer RRs answers (variable # of RRs) authority (variable # of RRs) additional info (variable # of RRs) 2 bytes 2 bytes DNS query and reply messages, both have same format: name, type fields for a query RRs in response to query records for authoritative servers additional “ helpful” info that may be used DNS protocol messages Application Layer: 2- 74
  • 74. [email protected] Getting your info into the DNS Application Layer: 2- 75 example: new startup “FAST”  register name fast.com at DNS registrar (e.g., FAST.com) • provide names, IP addresses of authoritative name server (primary and secondary) • registrar inserts NS, A RRs into .com TLD server: (fast.com, dns1.fast.com, NS) (dns1.fast.com, 212.212.212.1, A)  create authoritative server locally with IP address 212.212.212.1 • type A record for www.fast.com • type MX record for fast.com
  • 75. [email protected] DNS security Application Layer: 2- 76 DDoS attacks  bombard root servers with traffic • not successful to date • traffic filtering • local DNS servers cache IPs of TLD servers, allowing root server bypass  bombard TLD servers • potentially more dangerous Spoofing attacks  intercept DNS queries, returning bogus replies  DNS cache poisoning  RFC 4033: DNSSEC authentication services
  • 76. Chapter 2: Application layer [email protected] Application Layer: 2-77 Principles of network applications Web and HTTP E-mail, SMTP, IMAP The Domain Name System DNS P2P applications video streaming and content distribution networks socket programming with UDP and TCP
  • 77. [email protected] mobile network home network enterprise network national or global ISP local or regional ISP datacenter network content provider network Peer-to-peer (P2P) architecture Application Layer: 2- 78  no always-on server  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, and new service demands  peers are intermittently connected and change IP addresses • complex management  examples: P2P file sharing (BitTorrent), streaming (KanKan), VoIP (Skype)
  • 78. [email protected] File distribution: client-server vs P2P Application Layer: 2- 79 Q: how much time to distribute file (size F) from one server to N peers? • peer upload/download capacity is limited resource us uN dN server network (with abundant bandwidth) file, size F us: server upload capacity ui: peer i upload capacity di: peer i download capacity u2 d2 u1 d1 di ui
  • 79. [email protected] File distribution time: client-server Application Layer: 2- 80  server transmission: must sequentially send (upload) N file copies: • time to send one copy: F/us • 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 us network di ui F increases linearly in N time to distribute F to N clients using client-server approach Dc-s > max{NF/us,,F/dmin}
  • 80. [email protected] File distribution time: P2P Application Layer: 2- 81  server transmission: must upload at least one copy: • time to send one copy: F/us  client: each client must download file copy • min client download time: F/dmin us network di ui F  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)} … but so does this, as each peer brings service capacity increases linearly in N …
  • 81. [email protected] Client-server vs. P2P: example Application Layer: 2- 82 client upload rate = u, F/u = 1 hour, us = 10u, dmin ≥ us 0 0.5 1 1.5 2 2.5 3 3.5 0 5 10 15 20 25 30 35 N Minimum Distribution Time P2P Client-Server
  • 82. [email protected] P2P file distribution: BitTorrent Application Layer: 2- 83  file divided into 256Kb chunks  peers in torrent send/receive file chunks tracker: tracks peers participating in torrent torrent: group of peers exchanging chunks of a file Alice arrives … … obtains list of peers from tracker … and begins exchanging file chunks with peers in torrent
  • 83. [email protected] P2P file distribution: BitTorrent Application Layer: 2- 84  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
  • 84. [email protected] BitTorrent: requesting, sending file chunks Application Layer: 2- 85 Requesting chunks:  at any given time, different peers have different subsets of file chunks  periodically, Alice asks each peer for list of chunks that they have  Alice requests missing chunks from peers, rarest first Sending chunks: tit-for-tat  Alice sends chunks to those four peers currently sending her chunks at highest rate • other peers are choked by Alice (do not receive chunks from her) • re-evaluate top 4 every10 secs  every 30 secs: randomly select another peer, starts sending chunks • “optimistically unchoke” this peer • newly chosen peer may join top 4
  • 85. [email protected] BitTorrent: tit-for-tat Application Layer: 2- 86 (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 !
  • 86. Chapter 2: Application layer [email protected] Application Layer: 2-87 Principles of network applications Web and HTTP E-mail, SMTP, IMAP The Domain Name System DNS P2P applications video streaming and content distribution networks socket programming with UDP and TCP
  • 87. [email protected] Video Streaming and CDNs: context Application Layer: 2- 88  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
  • 88. [email protected] Multimedia: video Application Layer: 2- 89  video: sequence of images displayed at constant rate • e.g., 24 images/sec  digital image: array of pixels • each pixel represented by bits  coding: use redundancy within and between images to decrease # bits used to encode image • spatial (within image) • temporal (from one image to next) …………………….. spatial coding example: instead of sending N values of same color (all purple), send only two values: color value (purple) and number of repeated values (N) ……………….……. frame i frame i+1 temporal coding example: instead of sending complete frame at i+1, send only differences from frame i
  • 89. [email protected] Multimedia: video Application Layer: 2- 90 …………………….. spatial coding example: instead of sending N values of same color (all purple), send only two values: color value (purple) and number of repeated values (N) ……………….……. frame i frame i+1 temporal coding example: instead of sending complete frame at i+1, send only differences from frame i  CBR: (constant bit rate): video encoding rate fixed  VBR: (variable bit rate): video encoding rate changes as amount of spatial, temporal coding changes  examples: • MPEG1 (CD-ROM) 1.5 Mbps • MPEG2 (DVD) 3-6 Mbps • MPEG4 (often used in Internet, 64Kbps – 12 Mbps)
  • 90. [email protected] Streaming 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- 91 simple scenario: video server (stored video) client Internet
  • 91. [email protected] Streaming stored video Application Layer: 2- 92 1. video recorded (e.g., 30 frames/sec) 2. video sent Cumulati ve data streaming: at this time, client playing out early part of video, while server still sending later part of video time 3. video received, played out at client (30 frames/sec) network delay (fixed in this example)
  • 92. [email protected] Streaming stored video: challenges Application Layer: 2- 93  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
  • 93. [email protected] Streaming stored video: playout buffering Application Layer: 2- 94 constant bit rate video transmission Cumula tive data time variable network delay client video reception constant bit rate video playout at client client playout delay buffered video client-side buffering and playout delay: compensate for network-added delay, delay jitter
  • 94. [email protected] Streaming multimedia: DASH Application Layer: 2- 95 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 ... ... ... Dynamic, Adaptive Streaming over HTTP
  • 95. [email protected] ... ... ... Streaming multimedia: DASH Application Layer: 2- 96 “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) Streaming video = encoding + DASH + playout buffering client ?
  • 96. [email protected] Content distribution networks (CDNs) Application Layer: 2- 97 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
  • 97. [email protected] Content distribution networks (CDNs) Application Layer: 2- 98 challenge: how to stream content (selected from millions of videos) to hundreds of thousands of simultaneous users? • enter deep: push CDN servers deep into many access networks • close to users • Akamai: 240,000 servers deployed in > 120 countries (2015)  option 2: store/serve multiple copies of videos at multiple geographically distributed sites (CDN) • bring home: smaller number (10’s) of larger clusters in POPs near access nets • used by Limelight
  • 98. [email protected] … … … … … … Content distribution networks (CDNs) subscriber requests content, service provider returns manifest Application Layer: 2- 99  CDN: stores copies of content (e.g. MADMEN) at CDN nodes where’s Madmen? manifest file • using manifest, client retrieves content at highest supportable rate • may choose different rate or copy if network path congested
  • 99. [email protected] … … … … … … Internet host-host communication as a service Content distribution networks (CDNs) 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- 100 OTT: “over the top”
  • 100. Chapter 2: Application layer [email protected] Application Layer: 2-101 Principles of network applications Web and HTTP E-mail, SMTP, IMAP The Domain Name System DNS P2P applications video streaming and content distribution networks socket programming with UDP and TCP
  • 101. [email protected] Socket programming Application Layer: 2- 102 goal: learn how to build client/server applications that communicate using sockets socket: door between application process and end-end-transport protocol Internet controlled by OS controlled by app developer transport application physical link network process transport application physical link network process socket
  • 102. [email protected] Socket programming Two socket types for two transport services:  UDP: unreliable datagram  TCP: reliable, byte stream-oriented Application Layer: 2- 103 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
  • 103. [email protected] 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 Application Layer: 2- 104 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
  • 104. [email protected] Client/server socket interaction: UDP Application Layer: 2- 105 close clientSocket read datagram from clientSocket create socket: clientSocket = socket(AF_INET,SOCK_DGRAM) Create datagram with serverIP address And port=x; send datagram via clientSocket create socket, port= x: serverSocket = socket(AF_INET,SOCK_DGRAM) read datagram from serverSocket write reply to serverSocket specifying client address, port number server (running on serverIP) client
  • 105. [email protected] Example app: UDP client Application Layer: 2- 106 from socket import * serverName = ‘hostname’ serverPort = 12000 clientSocket = socket(AF_INET, SOCK_DGRAM) message = raw_input(’Input lowercase sentence:’) clientSocket.sendto(message.encode(), (serverName, serverPort)) modifiedMessage, serverAddress = clientSocket.recvfrom(2048) print modifiedMessage.decode() clientSocket.close() Python UDPClient include Python’s socket library create UDP socket for server get user keyboard input attach server name, port to message; send into socket print out received string and close socket read reply characters from socket into string
  • 106. [email protected] Example app: UDP server Application Layer: 2- 107 Python UDPServer from socket import * serverPort = 12000 serverSocket = socket(AF_INET, SOCK_DGRAM) serverSocket.bind(('', serverPort)) print (“The server is ready to receive”) while True: message, clientAddress = serverSocket.recvfrom(2048) modifiedMessage = message.decode().upper() serverSocket.sendto(modifiedMessage.encode(), clientAddress) create UDP socket bind socket to local port number 12000 loop forever Read from UDP socket into message, getting client’s address (client IP and port) send upper case string back to this client
  • 107. [email protected] Socket programming with TCP Client must contact server server process must first be running server must have created socket (door) that welcomes client’s contact Client contacts server by: Creating TCP socket, specifying IP address, port number of server process when client creates socket: client TCP establishes connection to server TCP Application Layer: 2- 108  when contacted by client, server TCP creates new socket for server process to communicate with that particular client • allows server to talk with multiple clients • source port numbers used to distinguish clients (more in Chap 3) TCP provides reliable, in-order byte-stream transfer (“pipe”) between client and server processes Application viewpoint
  • 108. [email protected] Client/server socket interaction: TCP Application Layer: 2- 109 server (running on hostid) client wait for incoming connection request connectionSocket = serverSocket.accept() create socket, port=x, for incoming request: serverSocket = socket() create socket, connect to hostid, port=x clientSocket = socket() send request using clientSocket read request from connectionSocket write reply to connectionSocket TCP connection setup close connectionSocket read reply from clientSocket close clientSocket
  • 109. [email protected] Example app: TCP client Application Layer: 2- 110 from socket import * serverName = ’servername’ serverPort = 12000 clientSocket = socket(AF_INET, SOCK_STREAM) clientSocket.connect((serverName,serverPort)) sentence = raw_input(‘Input lowercase sentence:’) clientSocket.send(sentence.encode()) modifiedSentence = clientSocket.recv(1024) print (‘From Server:’, modifiedSentence.decode()) clientSocket.close() Python TCPClient create TCP socket for server, remote port 12000 No need to attach server name, port
  • 110. [email protected] Example app: TCP server Application Layer: 2- 111 from socket import * serverPort = 12000 serverSocket = socket(AF_INET,SOCK_STREAM) serverSocket.bind((‘’,serverPort)) serverSocket.listen(1) print ‘The server is ready to receive’ while True: connectionSocket, addr = serverSocket.accept() sentence = connectionSocket.recv(1024).decode() capitalizedSentence = sentence.upper() connectionSocket.send(capitalizedSentence. encode()) connectionSocket.close() Python TCPServer create TCP welcoming socket server begins listening for incoming TCP requests loop forever server waits on accept() for incoming requests, new socket created on return read bytes from socket (but not address as in UDP) close connection to this client (but not welcoming socket)
  • 111. [email protected] Chapter 2: Summary  application architectures • client-server • P2P  application service requirements: • reliability, bandwidth, delay  Internet transport service model • connection-oriented, reliable: TCP • unreliable, datagrams: UDP Application Layer: 2- 112 our study of network application layer is now complete!  specific protocols: • HTTP • SMTP, IMAP • DNS • P2P: BitTorrent  video streaming, CDNs  socket programming: TCP, UDP sockets
  • 112. Sample SMTP interaction S: 220 hamburger.edu C: HELO crepes.fr S: 250 Hello crepes.fr, pleased to meet you C: MAIL FROM: <[email protected]> S: 250 [email protected]... Sender ok C: RCPT TO: <[email protected]> S: 250 [email protected] ... 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 [email protected] Application Layer: 2-113
  • 113. [email protected] CDN content access: a closer look Application Layer: 2- 114 netcinema.com KingCDN.com 1 1. Bob gets URL for video http://netcinema.com/6Y7B23V from netcinema.com web page 2 2. resolve http://netcinema.com/6Y7B23V via Bob’s local DNS netcinema’s authoratative DNS 3 3. netcinema’s DNS returns CNAME for http://KingCDN.com/NetC6y&B23V 4 5 6. request video from KINGCDN server, streamed via HTTP KingCDN authoritative DNS Bob’s local DNS server Bob (client) requests video http://netcinema.com/6Y7B23V  video stored in CDN at http://KingCDN.com/NetC6y&B23V
  • 114. [email protected] Case study: Netflix Application Layer: 2- 115 1 Bob manages Netflix account Netflix registration, accounting servers Amazon cloud CDN server 2 Bob browses Netflix video Manifest file, requested returned for specific video DASH server selected, contacted, streaming begins upload copies of multiple versions of video to CDN servers CDN server CDN server 3 4

Editor's Notes

  • #33: t’
  • #34: t’
  • #35: t’
  • #36: t’
  • #37: t’
  • #38: re: poor content providers – like in real-estate, location is everything. servers want to be close to clients.
  • #39: explain why minutes (recall earlier delay versus arrival rate curve from Chapter 1)
  • #40: explain why minutes (recall earlier delay versus arrival rate curve from Chapter 1)
  • #41: explain why minutes (recall earlier delay versus arrival rate curve from Chapter 1)
  • #42: t’
  • #43: t’
  • #44: t’
  • #45: t’
  • #46: t’
  • #47: t’
  • #48: t’
  • #49: shortest job first: decreased average delay!
  • #50: t’
  • #99: Akamai: 100,000+ servers in 1000+ clusters in 1000+ networks in 70+ countries serving trillions of requests a day. How many people use Netflix?
  • #100: peak load: 7million viewers, 2 Tbytes via
  • #113: Retired this slide, since telnet isn’t really used anymore, and few non https: mail servers around anymore....
  • #114: This slide retired, since there’s the Netflix example which is visually better
  • #115: This slide retired, since there’s the new Netflix example which is visually better