程序代写代做代考 case study dns Java flex html graph game database cache go FTP Chapter 2 Application Layer

Chapter 2 Application Layer
Computer Networking: A Top-Down Approach
8th edition
Jim Kurose, Keith Ross Pearson, 2020
Application Layer: 2-1

Application layer: overview
§ 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
Application Layer: 2-2

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
• HTTP
• SMTP, IMAP • DNS
§ programming network applications
• socket API
Application Layer: 2-3

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 § Internet search
§ remote login
§…
Q: your favorites?
Application Layer: 2-4

Creating a network app
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
§applicationsonendsystems allows for rapid app development, propagation
mobile network
application
transport
network
data link
physical
national or global ISP
local or regional ISP
home network
enterprise network
content
provider
network
datacenter
application
transport
network
data link
physical
application
transport
network data link
network
physical
Application Layer: 2-5

Client-server paradigm
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
mobile network
national or global ISP
local or regional ISP
home network
enterprise network
content provider network
datacenter network
Application Layer: 2-6

Peer-peer architecture
§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
mobile network
national or global ISP
local or regional ISP
home network
enterprise network
content provider network
datacenter network
Application Layer: 2-7

Processes communicating
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
clients, servers
client process: process that initiates communication
server process: process that waits to be contacted
§ note: applications with P2P architectures have client processes & server processes
Application Layer: 2-8

Sockets
§ process sends/receives messages to/from its socket § socket analogous to door
• sending process shoves message out door
• sending process relies on transport infrastructure on other side of
door to deliver message to socket at receiving process • two sockets involved: one on each side
application
process
socket
Internet
controlled by app developer
controlled by OS
application
process
transport
transport
network
network
link
link
physical
physical
Application Layer: 2-9

Addressing processes
§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
• SMTP 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…
Application Layer: 2-10

An application-layer protocol defines:
§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
Application Layer: 2-11

What transport service does an app need?
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, …
Application Layer: 2-12

Transport service requirements: common apps
application
file transfer/download e-mail Web documents real-time audio/video
streaming audio/video interactive games text messaging
data loss
no loss
no loss
no loss loss-tolerant
loss-tolerant loss-tolerant no loss
throughput
elastic
elastic
elastic
audio: 5Kbps-1Mbps video:10Kbps-5Mbps same as above Kbps+
elastic
time sensitive?
no
no
no
yes, 10’s msec
yes, few secs yes, 10’s msec yes and no
Application Layer: 2-13

Internet transport protocols services
TCP service:
§reliable transport between sending and receiving process
§flow control: sender won’t overwhelm receiver
§congestion control: throttle sender when network overloaded
§does not provide: timing, minimum throughput guarantee, security
§connection-oriented: setup required between client and server processes
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?
Application Layer: 2-14

Internet transport protocols services
application
file transfer/download e-mail Web documents Internet telephony
streaming audio/video interactive games
application layer protocol
FTP [RFC 959]
SMTP [RFC 5321]
HTTP 1.1 [RFC 7320]
SIP [RFC 3261], RTP [RFC 3550], or proprietary HTTP [RFC 7320], DASH WOW, FPS (proprietary)
transport protocol
TCP TCP TCP
TCP or UDP
TCP UDP or TCP
Application Layer: 2-15

Securing TCP
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 TSL libraries, that use TCP in turn
TLS socket API
§cleartext sent into socket traverse Internet encrypted
§see Chapter 8
Application Layer: 2-16

Application layer: overview
§ 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
Application Layer: 2-17

Web and HTTP
First, a quick review…
§ 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
Application Layer: 2-18

HTTP overview
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
PC running Firefox browser
iPhone running Safari browser
server running Apache Web server
Application Layer: 2-19
HTTP request
HTTP response
HTTP request
HTTP response

HTTP overview (continued)
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
aside
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
Application Layer: 2-20

HTTP connections: two types
Non-persistent HTTP
1. TCPconnectionopened 2. atmostoneobjectsent
over TCP connection 3. TCPconnectionclosed
downloading multiple objects required multiple connections
Persistent HTTP
§TCPconnectionopenedto a server
§multiple objects can be sent over single TCP connection between client, and that server
§TCP connection closed
Application Layer: 2-21

Non-persistent HTTP: example
User enters URL:
www.someSchool.edu/someDepartment/home.index
(containing text, references to 10 jpeg images)
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
Application Layer: 2-22

Non-persistent HTTP: example (cont.)
User enters URL:
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
(containing text, references to 10 jpeg images)
4. HTTP server closes TCP connection.
time
Application Layer: 2-23

Non-persistent HTTP: response time
RTT (definition): time for a small packet to travel from client to server and back
HTTP response time (per object):
§one RTT to initiate TCP connection §one RTT for HTTP request and first few
bytes of HTTP response to return §obect/file transmission time
initiate TCP connection
RTT
request file
RTT
file received
time
time to transmit file
time
Non-persistent HTTP response time = 2RTT+ file transmission time
Application Layer: 2-24

Persistent HTTP (HTTP 1.1)
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)
Application Layer: 2-25

HTTP request message
§two types of HTTP messages: request, response §HTTP request message:
• ASCII (human-readable format)
carriage return character line-feed character
request line (GET, POST, HEAD commands)
header lines
carriage return, line feed at start of line indicates end of header lines
GET /index.html HTTP/1.1\r\n
Host: www-net.cs.umass.edu\r\n
User-Agent: Firefox/3.6.10\r\n
Accept: text/html,application/xhtml+xml\r\n Accept-Language: en-us,en;q=0.5\r\n Accept-Encoding: gzip,deflate\r\n Accept-Charset: ISO-8859-1,utf-8;q=0.7\r\n Keep-Alive: 115\r\n
Connection: keep-alive\r\n
\r\n
* Check out the online interactive exercises for more examples: http://gaia.cs.umass.edu/kurose_ross/interactive/
Application Layer: 2-26

HTTP request message: general format
method
sp
URL
sp
version
cr
lf
header field name
value
cr
lf
~
~
request line
header lines
header field name
value
cr
lf
cr
lf
~
entity body
~ body
Application Layer: 2-27

Uploading form input
POST method:
§ web page often includes form input
§ user input sent from client to server in entity body of HTTP POST request message
GET/URL 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
Application Layer: 2-28

Other HTTP request messages
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 request message
DELETE method:
§ allows a user or application to delete an object on a web server
§ use carefully!
§ generally, this request is often disabled or restricted (for what should be obvious reasons)
Application Layer: 2-29

HTTP response message
status line (protocol status code status phrase)
header lines
HTTP/1.1 200 OK\r\n
Date: Sun, 26 Sep 2010 20:09:20 GMT\r\n Server: Apache/2.0.52 (CentOS)\r\n Last-Modified: Tue, 30 Oct 2007 17:00:02
GMT\r\n
ETag: “17dc6-a5c-bf716880″\r\n Accept-Ranges: bytes\r\n
Content-Length: 2652\r\n
Keep-Alive: timeout=10, max=100\r\n Connection: Keep-Alive\r\n
Content-Type: text/html; charset=ISO-8859-
1\r\n \r\n
data data data data data …
data, e.g., requested HTML file
* Check out the online interactive exercises for more examples: http://gaia.cs.umass.edu/kurose_ross/interactive/
Application Layer: 2-30

HTTP response status codes
§ status code appears in 1st line in server-to-client response message. § some sample codes:
200 OK
• request succeeded, requested object later in this message 301 Moved Permanently
• requested object moved, new location specified later in this message (in Location: field)
400 Bad Request
• request msg not understood by server 404 Not Found
• requested document not found on this server 505 HTTP Version Not Supported
Application Layer: 2-31

Trying out HTTP (client side) for yourself
1. Telnet to your favorite Web server:
telnet gaia.cs.umass.edu 80
2. type in a GET HTTP request:
§ opens TCP connection to port 80 (default HTTP server port) at gaia.cs.umass. edu.
§ anything typed in will be sent to port 80 at gaia.cs.umass.edu
GET /kurose_ross/interactive/index.php HTTP/1.1
Host: gaia.cs.umass.edu
§ by typing this in (hit carriage return twice), you send this minimal (but complete) GET request to HTTP server
3. look at response message sent by HTTP server!
(or use Wireshark to look at captured HTTP request/response)
Application Layer: 2-32

Maintaining user/server state: cookies
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
X X
X’
X’’
X’’
Q: what happens if network connection or client crashes at t’ ?
t’
time time
Application Layer: 2-33
OK OK
OK
OK
lock data record X update X X’
update X X’’ unlock X

Maintaining user/server state: cookies
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
Application Layer: 2-34

Maintaining user/server state: cookies
client
ebay 8734
cookie file
ebay 8734 amazon 1678
server
Amazon server creates ID 1678 for user
cookie- specific action
access
backend database
usual HTTP request msg
usual HTTP response
set-cookie: 1678
create entry
access
usual HTTP request msg
cookie: 1678
usual HTTP response msg
one week later:
ebay 8734 amazon 1678
cookie- specific action
usual HTTP request msg
cookie: 1678
usual HTTP response msg
time time
Application Layer: 2-35

HTTP cookies: comments
What cookies can be used for:
§ authorization
§shopping carts
§ recommendations
§user session state (Web e-mail)
Challenge: How to keep state:
§ protocol endpoints: maintain state at sender/receiver over multiple transactions
§ cookies: HTTP messages carry state
aside
§ 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
cookies and privacy:
Application Layer: 2-36

Web caches (proxy servers)
Goal: satisfy client request without involving origin server § user configures browser to
point to a 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
proxy server
client
origin server
client
origin server
Application Layer: 2-37
HTTP request
HTTP request
HTTP response
HTTP response
HTTP request
HTTP response

Web caches (proxy servers)
§Web cache acts as both client and server
• server for original requesting client
• client to origin server
§typically cache is installed by ISP (university, company, residential ISP)
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
Application Layer: 2-38

Caching example
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
§ average data rate to browsers: 1.50 Mbps
origin servers
public Internet
Performance:
§ LAN utilization: .0015
§ access link utilization = .97
problem: large delays at high utilization!
1.54 Mbps access link
institutional network
1 Gbps LAN
§ end-end delay = Internet delay +
access link delay + LAN delay
= 2 sec + minutes + usecs
Application Layer: 2-39

Caching example: buy a faster access link
§ RTT from institutional router to server: 2 sec
§ Web object size: 100K bits
§ Avg request rate from browsers to origin servers: 15/sec
§ avg data rate to browsers: 1.50 Mbps
Performance:
§ LAN utilization: .0015
§ access link utilization = .97 .0097
§ end-end delay = Internet delay +
access link delay + LAN delay
= 2 sec + minutes + usecs msecs Cost: faster access link (expensive!)
Scenario:
154 Mbps § access link rate: 1.54 Mbps
origin servers
public Internet
institutional network
154 Mbps
1.54 Mbps access link
1 Gbps LAN
Application Layer: 2-40

Caching example: install a web cache
Scenario:
§ access link rate: 1.54 Mbps
§ RTT from institutional router to server: 2 sec
§ Web object size: 100K bits
§ Avg request rate from browsers to origin servers: 15/sec
§ avg data rate to browsers: 1.50 Mbps
Performance:
origin servers
public Internet
§ LAN utilization: .?
§ access link utilization = ?
§ average end-end delay = ?
Cost: web cache (cheap!)
institutional network
1.54 Mbps access link
1 Gbps LAN
local web cache
How to compute link utilization, delay?
Application Layer: 2-41

Caching example: install a web cache
Calculating access link utilization, end- end delay with cache:
§ suppose cache hit rate is 0.4: 40% requests satisfied at cache, 60% requests satisfied at origin
§ access link: 60% of requests use access link
§ data rate to browsers over access link
=0.6*1.50Mbps = .9Mbps
§ utilization = 0.9/1.54 = .58
§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
origin servers
public Internet
institutional network
1 Gbps LAN
local web cache
1.54 Mbps access link
lower average end-end delay than with 154 Mbps link (and cheaper too!)
Application Layer: 2-42

Conditional GET
Goal: don’t send object if cache has up-to-date cached version
• no object transmission delay • lower link utilization
§cache: specify date of cached copy in HTTP request
If-modified-since:
§server: response contains no object if cached copy is up-to-date:
HTTP/1.0 304 Not Modified
client
server
object not
modified before
HTTP request msg
If-modified-since:
HTTP response
HTTP/1.0 304 Not Modified
HTTP request msg
If-modified-since:
object modified
after
HTTP response
HTTP/1.0 200 OK
Application Layer: 2-43

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

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

HTTP/2: mitigating HOL blocking
HTTP 1.1: client requests 1 large object (e.g., video file, and 3 smaller
objects)
server
GET O4
client
GET O3
GET O2
GET O1
object data requested
O1
O2
O3 O4
O1 O2 O3O4
objects delivered in order requested: O2, O3, O4 wait behind O1
Application Layer: 2-46

HTTP/2: mitigating HOL blocking
HTTP/2: objects divided into frames, frame transmission interleaved
server
GET O4
client
O2 O4
O3
GET O3
GET O2
GET O1
object data requested
O1
O2
O3 O4
O1
O2, O3, O4 delivered quickly, O1 slightly delayed
Application Layer: 2-47

HTTP/2 to HTTP/3
Key goal: decreased delay in multi-object HTTP requests 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
Application Layer: 2-48

Application layer: overview
§ 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
Application Layer: 2-49

E-mail
Three major components:
§user agents
§mail servers
§simple mail transfer protocol: SMTP
User Agent
SMTP
SMTP
SMTP
mail server
mail server
§a.k.a. “mail reader”
§composing, editing, reading mail messages §e.g., Outlook, iPhone mail client
§outgoing, incoming messages stored on server
mail server
user agent
outgoing message queue
user mailbox
user agent
user agent
user agent
user agent
user agent
Application Layer: 2-50

E-mail: mail servers
mail servers:
§mailbox contains incoming messages for user
§message queue of outgoing (to be sent) mail messages
§SMTP protocol used to send email messages
• client: sending user agent or mail server
• “server”: receiving mail server
SMTP
SMTP
SMTP
mail server
mail server
mail server
user agent
outgoing message queue
user mailbox
user agent
user agent
user agent
user agent
user agent
Application Layer: 2-51

E-mail: the RFC (5321)
§uses TCP to reliably transfer email message from client (user agent or
mail server initiating connection) to server, port 25
§three phases of transfer • handshaking (greeting)
• transfer of messages
• closure
§command/response interaction (like HTTP) • commands: ASCII text
• response: status code and phrase
§messages must be in 7-bit ASCII
Application Layer: 2-52

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

Sample SMTP interaction
S: 220 hamburger.edu
C: HELO crepes.fr
S: 250 Hello crepes.fr, pleased to meet you
C: MAIL FROM:
S: 250 alice@crepes.fr… Sender ok
C: RCPT TO:
S: 250 bob@hamburger.edu … Recipient ok
C: DATA
S: 354 Enter mail, end with “.” on a line by itself
C: Do you like ketchup?
C: How about pickles?
C: .
S: 250 Message accepted for delivery
C: QUIT
S: 221 hamburger.edu closing connection
Application Layer: 2-54

Try SMTP interaction for yourself:
telnet 25
§ see 220 reply from server
§ enter HELO, MAIL FROM:, RCPT TO:, DATA, QUIT commands above lets you send email without using e-mail client (reader)
Note: this will only work if allows telnet connections to port 25 (this is becoming increasingly rare because of security concerns)
Application Layer: 2-55

SMTP: closing observations
comparison with HTTP:
§ HTTP: pull
§ SMTP: 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
§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
Application Layer: 2-56

Mail message format
SMTP: protocol for exchanging e-mail messages, defined in RFC 531 (like HTTP)
RFC 822 defines syntax for e-mail message itself (like HTML)
§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
blank line
header
body
Application Layer: 2-57

Mail access protocols
SMTP SMTP
e-mail access protocol
(e.g., IMAP, HTTP)
user agent
user agent
sender’s e-mail receiver’s e-mail server server
§SMTP: delivery/storage of e-mail messages to receiver’s server
§mail access protocol: retrieval from server
• POP: Post Office Protocol [RFC 1939]: authorization, download
• IMAP: Internet Mail Access Protocol [RFC 3501]: more features, with messages stored on server, providing retrieval, deletion, folders of stored messages on server
• HTTP:Gmail,Hotmail,etc.provideaweb-basedinterfaceontopof SMTP (to send), IMAP (or POP) to retrieve e-mail messages
Application Layer: 2-58

More about POP and IMAP
POP IMAP
§ originally, POP only supported a “download and delete” mode
• Bob cannot re-read e-mail if he changes client, as the message is no longer on the server
§ POP3 “download-and-keep”: copies of messages on different clients
§ POP3 is stateless across sessions
• no server-side organization or manipulation of messages
§ keeps all messages in one place: at server
§ allows user to organize messages in folders
§ keeps user state across sessions:
• names of folders and mappings between message IDs and folder name
Application Layer: 2-59

Application Layer: Overview
§ 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
Application Layer: 2-60

DNS: Domain Name System
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:
§distributed database implemented in hierarchy of many name servers
§application-layer protocol: hosts, name servers communicate to resolve names (address/name translation)
• note: core Internet function, implemented as application-layer protocol
• complexity at network’s “edge”
Application Layer: 2-61

DNS: services, structure
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
Q: Why not centralize DNS?
§single point of failure §traffic volume
§distant centralized database § maintenance
A: doesn‘t scale!
§ Comcast DNS servers alone: 600B DNS queries per day
Application Layer: 2-62

DNS: a distributed, hierarchical database
Root DNS Servers
……
.com DNS servers .org DNS servers .edu DNS servers
yahoo.com DNS servers
………… amazon.com pbs.org nyu.edu
DNS servers DNS servers DNS servers
umass.edu DNS servers
Root
Top Level Domain Authoritative
Client wants IP address for www.amazon.com; 1st approximation:
§client queries root server to find .com DNS server
§client queries .com DNS server to get amazon.com DNS server
§client queries amazon.com DNS server to get IP address for www.amazon.com Application Layer: 2-63

DNS: root name servers
§ official, contact-of-last-resort by name servers that can not resolve name
§ incredibly important Internet function
• Internet couldn’t function without it!
• DNSSEC – provides security (authentication and 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)
Application Layer: 2-64

TLD: authoritative servers
Top-Level Domain (TLD) servers:
§ responsible for .com, .org, .net, .edu, .aero, .jobs, .museums, and all top-level country domains, e.g.: .cn, .uk, .fr, .ca, .jp
§ Network Solutions: authoritative registry for .com, .net TLD
§ Educause: .edu TLD
Authoritative DNS servers:
§ organization’s own DNS server(s), providing authoritative hostname to IP mappings for organization’s named hosts
§ can be maintained by organization or service provider
Application Layer: 2-65

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

DNS name resolution: iterated query
Example: host at engineering.nyu.edu wants IP address for gaia.cs.umass.edu
root DNS server
2
3 TLD DNS server 14
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
8 5
local DNS server
dns.nyu.edu
gaia.cs.umass.edu
6
authoritative DNS server
dns.cs.umass.edu
7
Application Layer: 2-67

DNS name resolution: recursive query
Example: host at engineering.nyu.edu wants IP address for gaia.cs.umass.edu
root DNS server
3 7
4
Recursive query:
§ puts burden of name resolution on contacted name server
§ heavy load at upper levels of hierarchy?
2
6
1 8
local DNS server
dns.nyu.edu
TLD DNS server
requesting host at
engineering.nyu.edu
5
gaia.cs.umass.edu
authoritative DNS server
dns.cs.umass.edu
Application Layer: 2-68

Caching, Updating DNS Records
§once (any) name server learns mapping, it caches mapping
• cache entries timeout (disappear) after some time (TTL)
• TLD servers typically cached in local name servers • thus root name servers not often visited
§ cached entries may be out-of-date (best-effort name-to- address translation!)
• if name host changes IP address, may not be known Internet-wide until all TTLs expire!
§update/notify mechanisms proposed IETF standard • RFC 2136
Application Layer: 2-69

DNS records
DNS: distributed database storing resource records (RR) RR format: (name, value, type, ttl)
type=A
§ name is hostname § value is IP address
type=NS
§ name is domain (e.g., foo.com)
§ value is hostname of authoritative name server for this domain
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 mailserver associated with name
Application Layer: 2-70

DNS protocol messages
DNS query and reply messages, both have same format:
2 bytes
2 bytes
identification
# questions
# authority RRs
questions (variable # of questions)
answers (variable # of RRs)
authority (variable # of RRs)
additional info (variable # of RRs)
flags
# answer RRs
# additional RRs
message header:
§ identification: 16 bit # for query,
reply to query uses same #
§ flags:
• query or reply
• recursion desired
• recursion available
• reply is authoritative
Application Layer: 2-71

DNS protocol messages
DNS query and reply messages, both have same format:
2 bytes
2 bytes
identification
# questions
# authority RRs
questions (variable # of questions)
answers (variable # of RRs)
authority (variable # of RRs)
additional info (variable # of RRs)
flags
# answer RRs
# additional RRs
name, type fields for a query
RRs in response to query
records for authoritative servers
additional “ helpful” info that may be used
Application Layer: 2-72

Inserting records into DNS
Example: new startup “Network Utopia”
§ register name networkuptopia.com at DNS registrar (e.g., Network Solutions)
• provide names, IP addresses of authoritative name server (primary and secondary)
• registrar inserts NS, A RRs into .com TLD server: (networkutopia.com, dns1.networkutopia.com, NS) (dns1.networkutopia.com, 212.212.212.1, A)
§ create authoritative server locally with IP address 212.212.212.1 • typeArecordforwww.networkuptopia.com
• typeMXrecordfornetworkutopia.com
Application Layer: 2-73

DNS security
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
Redirect attacks
§ man-in-middle
• intercept DNS queries
§ DNS poisoning
• send bogus replies to DNS
server, which caches
Exploit DNS for DDoS
DNSSEC [RFC 4033]
§ send queries with spoofed source address: target IP
§ requires amplification
Application Layer: 2-74

Application Layer: Overview
§ 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
Application Layer: 2-75

Peer-to-peer (P2P) architecture §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)
mobile network
national or global ISP
local or regional ISP
home network
enterprise network
content provider network
datacenter network
Application Layer: 2-76

File distribution: client-server vs P2P
Q: how much time to distribute file (size F) from one server to N peers?
• peer upload/download capacity is limited resource us: server upload
capacity
u
us 1 d1
di bandwidth) ui
ui: peer i upload capacity
file, size F
server
uN dN
u2 d2
di: peer i download capacity
network (with abundant
Introduction: 1-77

File distribution time: client-server
§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
F us
network
di ui
time to distribute F to N clients using
client-server approach
Dc-s > max{NF/us,,F/dmin}
increases linearly in N
Introduction: 1-78

File distribution time: P2P
§server transmission: must upload at least one copy:
• time to send one copy: F/us
§ client: each client must download file copy
F
us
network
di ui
• min client download time: F/dmin
§ clients: as aggregate must download NF bits
• max upload rate (limiting max download rate) is us + Sui
time to distribute F to N clients using
P2P approach
DP2P > max{F/us,,F/dmin,,NF/(us + Sui)}
increases linearly in N …
… but so does this, as each peer brings service capacity
Application Layer: 2-79

Client-server vs. P2P: example
client upload rate = u, F/u = 1 hour, us = 10u, dmin ≥ us
3.5 3 2.5 2 1.5 1 0.5 0
P2P
Client-Server
0 5 10 15 20 25 30 35 N
Application Layer: 2-80
Minimum Distribution Time

P2P file distribution: BitTorrent
§ file divided into 256Kb chunks
§ peers in torrent send/receive file chunks
tracker: tracks peers participating in torrent
Alice arrives …
… obtains list
of peers from tracker
… and begins exchanging
file chunks with peers in torrent
torrent: group of peers exchanging chunks of a file
Application Layer: 2-81

P2P file distribution: BitTorrent
§ peer joining torrent:
• has no chunks, but will accumulate them
over time from other peers
• registers with tracker to get list of peers, connects to subset of peers (“neighbors”)
§ while downloading, peer uploads chunks to other peers
§ peer may change peers with whom it exchanges chunks
§ churn: peers may come and go
§ once peer has entire file, it may (selfishly) leave or (altruistically) remain in torrent
Application Layer: 2-82

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

BitTorrent: tit-for-tat
(1) Alice “optimistically unchokes” Bob
(2) Alice becomes one of Bob’s top-four providers; Bob reciprocates (3) Bob becomes one of Alice’s top-four providers
higher upload rate: find better trading partners, get file faster !
Application Layer: 2-84

Application layer: overview
§ 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
Application Layer: 2-85

Video Streaming and CDNs: context
§ streaming video traffic: major consumer of Internet
bandwidth
• Netflix, YouTube, Amazon Prime: 80% of residential ISP
traffic (2020)
§ challenge: scale – how to reach ~1B users?
• single mega-video server won’t work (why?)
§ challenge: heterogeneity
§different users have different capabilities (e.g., wired
versus mobile; bandwidth rich versus bandwidth poor)
§ solution: distributed, application-level infrastructure
Application Layer: 2-86

Multimedia: video
§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
temporal coding example:
instead of sending complete frame at i+1, send only differences from frame i
frame i+1
Application Layer: 2-87

Multimedia: video
§ CBR: (constant bit rate): video encoding rate fixed
§ VBR: (variable bit rate): video encoding rate changes as amount of spatial, temporal coding changes
§ examples:
• MPEG 1 (CD-ROM) 1.5 Mbps
• MPEG2 (DVD) 3-6 Mbps
• MPEG4 (often used in Internet, 64Kbps – 12 Mbps)
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
temporal coding example:
instead of sending complete frame at i+1, send only differences from frame i
frame i+1
Application Layer: 2-88

Streaming stored video
simple scenario:
video server (stored video)
Main challenges:
Internet
§ server-to-client bandwidth will vary over time, with changing network congestion levels (in house, in access network, in network core, at video server)
§ packet loss and delay due to congestion will delay playout, or result in poor video quality
client
Application Layer: 2-89

Streaming stored video
1. video recorded
(e.g., 30 frames/sec)
2. video sent
3. video received, played out at client (30 frames/sec)
time
network delay (fixed in this example)
streaming: at this time, client playing out early part of video, while server still sending later part of video
Application Layer: 2-90
Cumulative data

Streaming stored video: challenges
§continuous playout constraint: once client playout begins, playback must match original timing
• … but network delays are variable (jitter), so will need client-side buffer to match playout requirements
§other challenges:
• client interactivity: pause, fast-forward, rewind,
jump through video
• video packets may be lost, retransmitted
Application Layer: 2-91

Streaming stored video: playout buffering
constant bit rate video
transmission
variable network delay
client playout delay
client video reception
constant bit rate video
playout at client
§client-side buffering and playout delay: compensate for network-added delay, delay jitter
time
Application Layer: 2-92
Cumulative data
buffered video

Streaming multimedia: DASH
§DASH: Dynamic, Adaptive Streaming over HTTP
§ server:
• divides video file into multiple chunks
• each chunk stored, encoded at different rates
• manifest file: provides URLs for different chunks
§ client:
• periodically measures server-to-client bandwidth • consulting manifest, requests one chunk at a time
Internet
• chooses maximum coding rate sustainable given current bandwidth
• can choose different coding rates at different points in time (depending on available bandwidth at time)
client
Application Layer: 2-93

Streaming multimedia: DASH
§“intelligence” at client: client determines
• when to request chunk (so that buffer starvation, or overflow does not occur)
• what encoding rate to request (higher quality when more bandwidth available)
Internet
• where to request chunk (can request from URL server that is “close” to client or has high available bandwidth)
Streaming video = encoding + DASH + playout buffering
Application Layer: 2-94
client

Content distribution networks (CDNs)
§challenge: how to stream content (selected from millions of videos) to hundreds of thousands of simultaneous users?
§option 1: single, large “mega-server” • single point of failure
• point of network congestion
• long path to distant clients
• multiple copies of video sent over outgoing link ….quite simply: this solution doesn’t scale
Application Layer: 2-95

Content distribution networks (CDNs)
§challenge: how to stream content (selected from millions of videos) to hundreds of thousands of simultaneous users?
§option 2: store/serve multiple copies of videos at multiple geographically distributed sites (CDN)
• enter deep: push CDN servers deep into many access networks and ISPs
• close to users
• Akamai: 240,000 servers deployed in more than 120
countries (2015)
• bring home: smaller number (10’s) of larger clusters in IXPs near (but not within) access networks
• used by Limelight
Application Layer: 2-96

Content distribution networks (CDNs)
§ CDN: stores copies of content at CDN nodes • e.g. Netflix stores copies of MadMen
§subscriber requests content from CDN • directed to nearby copy, retrieves content
• may choose different copy if network path congested
manifest file
where’s Madmen?
Application Layer: 2-97





Content distribution networks (CDNs)
OTT: “over the top”
Internet host-host communication as a service
OTT challenges: coping with a congested Internet § from which CDN node to retrieve content?
§ viewer behavior in presence of congestion? § what content to place in which CDN node?






Application Layer: 2-98

CDN content access: a closer look
Bob (client) requests video http://netcinema.com/6Y7B23V § video stored in CDN at http://KingCDN.com/NetC6y&B23V
1. Bob gets URL for video http://netcinema.com/6Y7B23V
from www.netcinema.com web page
1
2
2. resolve http://netcinema.com/6Y7B23V via Bob’s local DNS
Bob’s local DNS server
4
6. request video from 5 KINGCDN server, streamed via HTTP
www.netcinema.com
3
netcinema’s authoratative DNS
KingCDN.com
KingCDN authoritative DNS
3. netcinema’s DNS returns CNAME for http://KingCDN.com/NetC6y&B23V
Application Layer: 2-99

Case study: Netflix
Amazon cloud
upload copies of multiple versions of video to CDN servers
Netflix registration, accounting servers
1
Bob manages Netflix account
CDN server
Bob browses Netflix video
2
Manifest file, CDN
requested server 3 returned for
specific video
4
CDN server
DASH server selected, contacted, streaming begins
Application Layer: 2-100

Application Layer: Overview
§ 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
Application Layer: 2-101

Socket programming
goal: learn how to build client/server applications that communicate using sockets
socket: door between application process and end-end-transport protocol
application
process
socket
Internet
controlled by app developer
controlled by OS
application
process
transport
transport
network
network
link
link
physical
physical
Application Layer: 2-102

Socket programming
Two socket types for two transport services:
§ UDP: unreliable datagram
§ TCP: reliable, byte stream-oriented
Application Example:
1. client reads a line of characters (data) from its keyboard and sends data to server
2. server receives the data and converts characters to uppercase 3. server sends modified data to client
4. client receives modified data and displays line on its screen
Application Layer: 2-103

Socket programming with UDP
UDP: no “connection” between client & server
§ no handshaking before sending data
§ sender explicitly attaches IP destination address and port # to each packet
§ receiver extracts sender IP address and port# from received packet
UDP: transmitted data may be lost or received out-of-order
Application viewpoint:
§ UDP provides unreliable transfer of groups of bytes (“datagrams”) between client and server
Application Layer: 2-104

Client/server socket interaction: UDP
server (running on serverIP)
create socket, port= x:
serverSocket = socket(AF_INET,SOCK_DGRAM)
read datagram from
serverSocket
write reply to
serverSocket
specifying client address, port number
client
create socket:
clientSocket = socket(AF_INET,SOCK_DGRAM)
Create datagram with server IP and port=x; send datagram via clientSocket
read datagram from
clientSocket
close
clientSocket
Application Layer: 2-105

Example app: UDP client
include Python’s socket library
create UDP socket for server
get user keyboard input attach server name, port to message; send into socket
read reply characters from socket into string
Python UDPClient
from socket import *
serverName = ’localhost’
serverPort = 12000
clientSocket = socket(AF_INET, SOCK_DGRAM)
message = input(’Input lowercase sentence:’)
clientSocket.sendto(message.encode(),
(serverName, serverPort))
modifiedMessage, serverAddress =
clientSocket.recvfrom(2048) print out received string and close socket print(modifiedMessage.decode())
clientSocket.close()
Application Layer: 2-106

Example app: UDP server
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
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)
Application Layer: 2-107

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
§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)
Application viewpoint
TCP provides reliable, in-order byte-stream transfer (“pipe”) between client and server
Application Layer: 2-108

Client/server socket interaction: TCP
server (running on hostid)
create socket, port=x, for incoming
request:
serverSocket = socket()
wait for incoming connection request connectionSocket = serverSocket.accept()
read request from
connectionSocket write reply to
connectionSocket
close
connectionSocket
client
TCP connection setup
create socket,
connect to hostid, port=x
clientSocket = socket()
send request using
clientSocket
read reply from
clientSocket
close
clientSocket
Application Layer: 2-109

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

Example app: TCP server
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)
Python TCPServer
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()
capsSentence = sentence.upper()
connectionSocket.send(capsSentence.encode())
connectionSocket.close()
Application Layer: 2-111

Chapter 2: Summary
our study of network application layer is now complete!
§ application architectures • client-server
• P2P
§ application service requirements:
• reliability, bandwidth, delay
§ Internet transport service model • connection-oriented, reliable: TCP • unreliable, datagrams: UDP
§ specific protocols: • HTTP
• SMTP, IMAP
• DNS
• P2P: BitTorrent
§ video streaming, CDNs § socket programming:
TCP, UDP sockets
Application Layer: 2-112

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

Additional Chapter 2 slides
Application Layer: 2-114