Application Layer Networking Concepts
Application Layer Networking Concepts
Application Layer
Computer
Networking: A Top
Down Approach
7th edition
Jim Kurose, Keith Ross
The Powerpoint slides are from Kurose and Ross’s Pearson/Addison Wesley
book’s website. April 2016
Application Layer 1
Chapter 2: outline
2.1 principles of network 2.7 socket programming
applications with UDP and TCP
2.2 Web and HTTP
2.3 electronic mail
• SMTP, POP3, IMAP
2.4 DNS
Application Layer 2
Chapter 2: application layer
our goals: ▪ learn about protocols by
▪ conceptual, examining popular
implementation aspects application-level
of Internet application protocols
protocols • HTTP
• client-server • SMTP / POP3 / IMAP
paradigm • DNS
• transport-layer ▪ programming network
service models applications
• socket API
Application Layer 3
Some Internet apps
▪ e-mail ▪ voice over IP (e.g.,
▪ web Skype)
▪ text messaging ▪ real-time video
▪ remote login conferencing
▪ P2P file sharing ▪ social networking
▪ multi-user network ▪ search
games ▪ …
▪ streaming stored ▪ …
video (YouTube,
Netflix)
Application Layer 4
Creating an Internet app application
transport
network
data link
physical
need to write programs that:
▪ run on (different) end systems
▪ communicate over network
▪ e.g., browser software
communicates with web server
software
Application Layer 5
Application architectures
possible application structures:
▪ client-server
▪ peer-to-peer (P2P)
Application Layer 6
Client-server architecture
server:
▪ always-on host
▪ permanent IP address
clients:
▪ communicate with server
▪ may be intermittently
client/server connected
▪ may have dynamic IP
addresses
▪ do not communicate directly
with each other
Application Layer 7
P2P architecture
▪ no permanent always-on server peer-peer
▪ arbitrary end systems directly
communicate
▪ peers request service from
other peers, provide service in
return to other peers
• self scalability – new peers
bring new service capacity,
as well as new service
demands
▪ peers are intermittently
connected
• need complex management
Application Layer 8
Inter-process communication
Application Layer 9
Sockets
▪ process sends/receives messages to/from its socket
▪ socket analogous to door
• sending process pushes message out door
• sending process relies on transport service out of the
door to deliver message to door at receiving process
application application
socket controlled by
process process app developer
transport transport
network network controlled
link by OS
link Internet
physical physical
Application Layer 10
Addressing processes
Application Layer 11
What transport service does an app need?
data loss bandwidth
▪ some apps (e.g., file transfer, ▪ some apps (e.g., video)
stock transaction) require require minimum
100% reliable data transfer bandwidth to be usable
▪ some other apps (e.g., audio) ▪ some other apps (e.g., web)
can tolerate some loss make use of whatever
bandwidth they get
delay sensitive
▪ some apps (e.g., Internet
telephony, interactive
games) require low delay
to be usable
▪ some other apps (e.g., e-
mail) don’t care
Application Layer 12
Transport service requirements: common apps
Application Layer 13
Internet transport layer services
TCP service: UDP service:
▪ connection-oriented: setup is ▪ unreliable data transfer
required between client and between sending and
server processes receiving processes
▪ reliable data transfer between ▪ does not provide:
sending and receiving ▪ reliability,
processes ▪ flow control,
▪ flow control: sender won’t ▪ congestion control,
overwhelm receiver ▪ timing,
▪ congestion control: throttle ▪ bandwidth guarantee,
sender when network ▪ or connection setup
overloaded
▪ does not provide: timing, Q: why bother? Why is
minimum bandwidth there a UDP?
guarantee
Application Layer 14
Internet apps: application / transport layer protocols
Application Layer 15
Chapter 2: outline
2.1 principles of network 2.7 socket programming
applications with UDP and TCP
2.2 Web and HTTP
2.3 electronic mail
• SMTP, POP3, IMAP
2.4 DNS
Application Layer 16
Web and HTTP
First, some terms…
▪ web page consists of objects
▪ object can be HTML file, JPEG image, Java applet,
audio file,…
▪ web page consists of base HTML-file which
includes several referenced objects
▪ each object is addressable by a URL (Uniform
Resource Locator), e.g.,
[Link]/someDept/[Link]
Application Layer 17
HTTP overview
HTTP: hypertext
transfer protocol
▪ Web’s application layer
protocol
▪ client/server model PC running
Firefox browser
• client: browser that
requests / receives
(using HTTP protocol),
and displays Web server
objects running
• server: Web server Apache Web
sends objects (using server
HTTP protocol) in
response to client’s iPhone running
requests Safari browser
▪ two types of messages:
request, response
Application Layer 18
HTTP overview
uses TCP: HTTP is “stateless”
▪ client initiates TCP ▪ server maintains no
connection (creates socket) information about
to server, port 80 past client requests
▪ server accepts TCP
connection from client aside
▪ HTTP messages protocols that maintain
(application-layer protocol “state” are complex!
messages) exchanged ▪ past history (state) must be
between browser (HTTP maintained
client) and Web server ▪ if server/client crashes, their
(HTTP server) views of “state” may be
▪ TCP connection closed inconsistent, must be
reconciled
Application Layer 19
HTTP connections
Application Layer 20
Non-persistent HTTP
suppose user enters URL: (contains text,
[Link]/someDepartment/[Link] references to 10
jpeg images)
1a. HTTP client initiates TCP
connection to HTTP server
(process) at 1b. HTTP server at host
[Link] on port 80 [Link] waiting
for TCP connection at port 80.
“accepts” connection, notifies
2. HTTP client sends HTTP request client
message (containing URL) into
TCP connection socket. 3. HTTP server receives request
Message indicates that client message, forms response
wants object message containing requested
someDepartment/[Link] object, and sends message into
its socket
time
Application Layer 21
Non-persistent HTTP (cont’d)
Application Layer 22
Non-persistent HTTP: response time
RTT (round-trip time): time for
a small packet to travel from
client to server and back initiate TCP
HTTP response time: connection
time time
Application Layer 23
Persistent HTTP
non-persistent HTTP issues: persistent HTTP:
▪ requires 2 RTTs per object ▪ server leaves connection
▪ overhead for each TCP open after sending
connection response
▪ browsers often open ▪ subsequent HTTP
parallel TCP connections to messages between same
fetch referenced objects 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
Application Layer 24
HTTP request message
▪ HTTP request message:
• ASCII (human-readable format)
~
~ entity body ~
~ body
Application Layer 25
HTTP request message (example)
carriage return character
line-feed character
request line
(GET, POST, GET /[Link] HTTP/1.1\r\n
HEAD commands) Host: [Link]\r\n
User-Agent: Firefox/3.6.10\r\n
Accept: text/html,application/xhtml+xml\r\n
header Accept-Language: en-us,en;q=0.5\r\n
lines Accept-Encoding: gzip,deflate\r\n
carriage return, Accept-Charset: ISO-8859-1,utf-8;q=0.7\r\n
line feed at start Keep-Alive: 115\r\n
Connection: keep-alive\r\n
of line indicates \r\n
end of header lines
Application Layer 26
Uploading form input
POST method:
▪ web page can include form input
▪ input is uploaded to server in entity body
URL method:
▪ uses GET method
▪ input is uploaded in URL field of request line:
[Link]/animalsearch?monkeys&banana
Application Layer 27
Method types
HTTP/1.0: HTTP/1.1:
▪ GET ▪ GET, POST, HEAD
▪ POST ▪ PUT
▪ HEAD • uploads file in entity
• asks server to leave body to path specified
requested object out in URL field
of response ▪ DELETE
• deletes file specified in
the URL field
Application Layer 28
HTTP response message
status line
(protocol
status code HTTP/1.1 200 OK\r\n
status phrase) Date: Sun, 26 Sep 2010 [Link] GMT\r\n
Server: Apache/2.0.52 (CentOS)\r\n
Last-Modified: Tue, 30 Oct 2007 [Link]
GMT\r\n
header ETag: "17dc6-a5c-bf716880"\r\n
Accept-Ranges: bytes\r\n
lines 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, e.g., data data data data data ...
requested
HTML file
Application Layer 29
HTTP response status codes
▪ status code appears in 1st line in server-to-client
response message.
▪ some sample codes:
200 OK
• request succeeded, requested object later in this msg
301 Moved Permanently
• requested object moved, new location specified later in this msg
(Location:)
400 Bad Request
• request msg not understood by server
404 Not Found
• requested document not found on this server
505 HTTP Version Not Supported
Application Layer 30
User-server state: cookies
many Web sites use cookies
four components: example:
1) cookie header line of ▪ Susan always access Internet
HTTP response from PC
message ▪ visits specific e-commerce
2) cookie header line in site for first time
next HTTP request ▪ when initial HTTP request
message arrives at site, site creates:
3) cookie file kept on • unique ID
user’s host, managed • entry in back-end
by user’s browser database for ID
4) back-end database at
Web site
Application Layer 31
Cookies: keeping “state”
client server
ebay 8734
usual http request msg Amazon server
cookie file creates ID
usual http response
1678 for user create backend
ebay 8734
set-cookie: 1678 entry database
amazon 1678
usual http request msg
cookie: 1678 cookie- access
specific
usual http response msg action
Application Layer 33
Web caches (proxy server)
goal: satisfy client request without involving origin server
▪ user sets browser: Web
accesses via cache
▪ browser sends all HTTP proxy
requests to cache server
• object found in cache: client
origin
cache returns object server
• else (object not found
in cache): cache
requests object from
origin server, then
returns object to client client origin
server
Application Layer 34
More about Web caching
Application Layer 35
Caching example:
assumptions: origin
▪ avg object size: 1M bits servers
public
▪ avg request rate from browsers to origin Internet
servers:15/sec
▪ avg data rate to browsers: 15 Mbps
▪ RTT from institutional router to any origin
server: 2 sec 15 Mbps
▪ access link rate: 15 Mbps access link
institutional
consequences: network
▪ LAN utilization: 15% problem! 100Mbps LAN
Application Layer 36
Caching example: wider access link
assumptions:
▪ avg object size: 1M bits origin
▪ avg request rate from browsers to servers
origin servers:15/sec public
▪ avg data rate to browsers: 15 Mbps Internet
▪ RTT from institutional router to any
origin server: 2 sec
▪ access link rate: 15 Mbps
150 Mbps 15 Mbps
150 Mbps
consequences: access link
Application Layer 41
Electronic mail outgoing
message queue
user mailbox
Three major components: user
agent
▪ user agents
▪ mail servers mail user
server agent
▪ simple mail transfer
protocol: SMTP SMTP mail user
server agent
Application Layer 43
Electronic Mail: SMTP [RFC 2821]
▪ uses TCP to reliably transfer email message from
client to server, port 25
▪ direct transfer: sending server to receiving
server
▪ three phases of transfer
• handshaking (greeting)
• transfer of messages
• closure
▪ command/response interaction (like HTTP)
• commands: ASCII text
• response: status code and phrase
▪ messages must be in 7-bit ASCII
Application Layer 44
Scenario: Alice sends message to Bob
1) Alice uses UA to compose 4) SMTP client sends Alice’s
message “to” message over the TCP
bob@[Link] connection
2) Alice’s UA sends message 5) Bob’s mail server places the
to her mail server; message message in Bob’s mailbox
placed in message queue 6) Bob invokes his user agent
3) client side of SMTP opens to read message
TCP connection with Bob’s
mail server
Application Layer 46
SMTP: final words
▪ SMTP uses persistent comparison with HTTP:
connections
▪ HTTP: pull
▪ SMTP requires message
(header & body) to be in ▪ SMTP: push
7-bit ASCII ▪ both have ASCII
▪ SMTP server uses command/response
[Link] to interaction, status codes
determine end of message
▪ HTTP: each object
encapsulated in its own
response message
▪ SMTP: multiple objects
sent in multipart message
Application Layer 47
Mail message format
Application Layer 48
Mail access protocols
user
mail access user
SMTP SMTP protocol
agent agent
(e.g., POP,
IMAP)
Application Layer 49
POP3 protocol
S: +OK POP3 server ready
C: user bob
authorization phase S:
C:
+OK
pass hungry
▪ client commands: S: +OK user successfully logged on
• user: declare username
• pass: password C: list
S: 1 498
▪ server responses
S: 2 912
• +OK S: .
• -ERR C: retr 1
transaction phase, client: S:
S:
<message 1 contents>
.
▪ list: list message numbers C: dele 1
▪ retr: retrieve message by C: retr 2
number S: <message 2 contents>
▪ dele: delete S: .
▪ quit C: dele 2
C: quit
S: +OK POP3 server signing off
Application Layer 50
POP3 (more) and IMAP
more about POP3 IMAP
▪ previous example uses ▪ keeps all messages in one
POP3 “download and place: at server
delete” mode ▪ allows user to organize
• Bob cannot re-read e- messages in folders
mail if he changes ▪ keeps user state across
client sessions:
▪ POP3 “download-and- • names of folders and
keep”: copies of messages mappings between
on different clients message IDs and folder
▪ POP3 is stateless across name
sessions
Application Layer 51
Chapter 2: outline
2.1 principles of network 2.7 socket programming
applications with UDP and TCP
2.2 Web and HTTP
2.3 electronic mail
• SMTP, POP3, IMAP
2.4 DNS
Application Layer 52
DNS: domain name system
people: many identifiers: Domain Name System:
• SSN, name, passport # ▪ distributed database
Internet hosts, routers: implemented in hierarchy of
• IP address (32 bit) - many name servers
used for addressing ▪ application-layer protocol: hosts,
datagrams name servers communicate to
• “name”, e.g., resolve names (address/name
[Link] - translation)
used by humans • note: core Internet function,
Q: how to map between IP implemented as application-
layer protocol
address and name, and
vice versa ? • complexity at network’s
“edge”
Application Layer 53
DNS: services, structure
DNS services why not centralize DNS?
▪ hostname to IP address ▪ single point of failure
translation ▪ traffic volume
▪ host aliasing ▪ distant centralized database
• canonical, alias names ▪ maintenance
▪ mail server aliasing
▪ load distribution A: doesn‘t scale!
• replicated Web
servers: many IP
addresses correspond
to one name
Application Layer 54
DNS: a distributed, hierarchical database
Root DNS Servers
… …
Application Layer 55
DNS: root name servers
▪ contacted by local name server that can not resolve name
▪ root name server:
• contacts authoritative name server if name mapping not known
• gets mapping
• returns mapping to local name server
Application Layer 56
TLD, authoritative servers
Application Layer 57
Local DNS name server
Application Layer 58
DNS name root DNS server
resolution example
2
▪ host at [Link] 3
TLD DNS server
wants IP address for 4
[Link]
5
[Link]
Application Layer 59
DNS name root DNS server
resolution example
2 3
recursive query: 7
6
▪ puts burden of name TLD DNS
server
resolution on
contacted name local DNS server
server [Link] 5 4
[Link]
Application Layer 60
DNS: caching, updating records
▪ once (any) name server learns mapping, it caches
mapping
• cache entries timeout (disappear) after some time (TTL)
• TLD servers typically cached in local name servers
• thus root name servers not often visited
▪ cached entries may be out-of-date (best effort
name-to-address translation!)
• if name host changes IP address, may not be known
Internet-wide until all TTLs expire
▪ update/notify mechanisms proposed IETF standard
• RFC 2136
Application Layer 61
DNS records
DNS: distributed database storing resource records (RR)
RR format: (name, value, type, ttl)
type=A type=CNAME
▪ name is hostname ▪ name is alias name for some
▪ value is IP address “canonical” (the real) name
type=NS ▪ [Link] is really
• name is domain (e.g., [Link]
[Link]) ▪ value is canonical name
• value is hostname of
authoritative name type=MX
server for this domain ▪ value is name of mailserver
associated with name
Application Layer 62
DNS protocol, messages
▪ query and reply messages, both with same message
format 2 bytes 2 bytes
Application Layer 63
DNS protocol, messages
2 bytes 2 bytes
identification flags
Application Layer 65
Chapter 2: outline
2.1 principles of network 2.7 socket programming
applications with UDP and TCP
2.2 Web and HTTP
2.3 electronic mail
• SMTP, POP3, IMAP
2.4 DNS
Application Layer 66
Socket programming
goal: learn how to build client/server applications that
communicate using sockets
Socket API socket
▪ introduced in BSD4.1 UNIX,
1981 a host-local,
▪ explicitly created, used, released application-created,
by apps OS-controlled interface
▪ client/server paradigm into which
▪ two types of transport service application process can
via socket API: both send and
• unreliable datagram receive messages to/from
• reliable, byte stream- another application
oriented process
Application Layer 67
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 68
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 69
Client/server socket interaction: UDP
write reply to
serverSocket read datagram from
specifying clientSocket
client address,
port number close
clientSocket
Application Layer 70
Example app: UDP client
Python UDPClient
include Python’s socket
library
from socket import *
serverName = ‘hostname’
serverPort = 12000
create UDP socket for clientSocket = socket(AF_INET,
server
SOCK_DGRAM)
get user keyboard
input message = input(’Input lowercase sentence:’)
Attach server name, port to [Link]([Link](),
message; send into socket
(serverName, serverPort))
read reply characters from modifiedMessage, serverAddress =
socket into string
[Link](2048)
print out received string print ([Link]())
and close socket
[Link]()
Application Layer 71
Example app: UDP server
Python UDPServer
from socket import *
serverPort = 12000
create UDP socket serverSocket = socket(AF_INET, SOCK_DGRAM)
bind socket to local port
number 12000
[Link](('', serverPort))
print (‘The server is ready to receive’)
loop forever while True:
Read from UDP socket into message, clientAddress = [Link](2048)
message, getting client’s
address (client IP and port) modifiedMessage = [Link]().upper()
send upper case string [Link]([Link](),
back to this client
clientAddress)
Application Layer 72
Socket programming with TCP
client must contact server ▪ when contacted by client,
▪ server process must first be server TCP creates new socket
running for server process to
▪ server must have created communicate with that
socket (door) that particular client
welcomes client’s contact • allows server to talk with
multiple clients
client contacts server by: • source port numbers used
▪ creating TCP socket, to distinguish clients
specifying IP address, port (more in Chap 3)
number of server process
▪ when client creates socket: application viewpoint:
client TCP establishes TCP provides reliable, in-order
connection to server TCP byte-stream transfer (“pipe”)
between client and server
Application Layer 73
Client/server socket interaction: TCP
server (running on hostid) client
create socket,
port=x, for incoming
request:
serverSocket = socket()
write reply to
connectionSocket read reply from
clientSocket
close
connectionSocket close
clientSocket
Application Layer 74
Example app: TCP client
Python TCPClient
from socket import *
serverName = ’servername’
create TCP socket for
serverPort = 12000
server, remote port 12000
clientSocket = socket(AF_INET, SOCK_STREAM)
[Link]((serverName,serverPort))
sentence = input(‘Input lowercase sentence:’)
No need to attach server [Link]([Link]())
name, port
modifiedSentence = [Link](1024)
print (‘From Server:’, [Link]())
[Link]()
Application Layer 75
Example app: TCP server
Python TCPServer
from socket import *
create TCP welcoming serverPort = 12000
socket serverSocket = socket(AF_INET,SOCK_STREAM)
[Link]((‘’,serverPort))
server begins listening for
incoming TCP requests [Link](1)
print (‘The server is ready to receive’)
loop forever
while True:
server waits on accept()
for incoming requests, new
connectionSocket, addr = [Link]()
socket created on return
sentence = [Link](1024).decode()
read bytes from socket (but
not address as in UDP) capitalizedSentence = [Link]()
close connection to this [Link](capitalizedSentence.
client (but not welcoming
socket) encode())
[Link]()
Application Layer 76
Chapter 2: summary
our study of network apps now complete!
▪ application architectures ▪ specific protocols:
• client-server • HTTP
• P2P • SMTP, POP, IMAP
▪ application service
• DNS
requirements:
• reliability, bandwidth, delay ▪ socket programming:
▪ Internet transport service TCP, UDP sockets
model
• connection-oriented,
reliable: TCP
• unreliable, datagrams: UDP
Application Layer 77
Chapter 2: summary
most importantly: learned about protocols!
▪ typical request/reply
message exchange: important themes:
• client requests info or ▪ control vs. data messages
service ▪ stateless vs. stateful
• server responds with ▪ reliable vs. unreliable message
data, status code
transfer
▪ message formats:
• headers: fields giving ▪ “complexity at network
info about data edge”
• data: info(payload)
being communicated
Application Layer 78