Understanding Application Layer Protocols
Understanding Application Layer Protocols
2
Creating a network app application
transport
network
data link
write programs that: physical
3
Application architectures
4
Client-server architecture
server:
always-on
permanent IP address
data centers for scaling
clients:
communicate with server
may be intermittently connected
may have dynamic IP addresses
client/server do not communicate directly with
each other
5
P2P architecture
no always-on server peer-peer
arbitrary end systems
directly communicate
peers request service from
other peers, provide service
in return to other peers
peers are intermittently
connected and change IP
addresses
complex management
example:
file distribution
(BitTorrent)
6
Processes communicating
process: program running within a clients, servers
host
client process: process that initiates
within same host, two processes
communication
communicate using inter-
process communication (defined server process: process that waits
by OS) to be contacted
processes in different hosts
communicate by exchanging
messages
7
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
application application
socket controlled by
process process app developer
transport transport
network network controlled
link by OS
link Internet
physical physical
8
Addressing processes
To receive messages, process must have identifier
host device has unique 32-bit IP address
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 [Link] web server:
IP address: [Link]
port number: 80
9
App-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
10
How the application messages are transported
Using TCP and UDP protocols over the transport layer.
data integrity ( vs. data loss)
some apps (e.g., file transfer, web transactions) require 100% reliable data
transfer
other apps (e.g., audio) can tolerate some loss
Timing (delay)
some apps (e.g., Internet telephony, interactive games) require low delay to
be “effective”
Throughput (bandwidth)
some apps (e.g., multimedia) require minimum amount of throughput to be
“effective”
other apps (“elastic apps”) make use of whatever throughput they get
11
Internet transport protocols services
12
Web and HTTP
web page consists of objects : object can be HTML file,
JPEG image, Java applet, audio file,…
[Link]/someDept/[Link]
13
HTTP overview
HTTP: hypertext transfer protocol
Web’s application layer protocol
iphone running
Safari browser
14
HTTP overview
uses TCP: HTTP is “stateless”
client initiates TCP connection server maintains no
(creates socket) to server, port information about past
80 client requests
15
HTTP connections
non-persistent HTTP ( http/1.0)
16
Non-persistent HTTP
(contains,
suppose user enters URL: references to 10
[Link]/someDepartment/[Link] jpeg images)
18
Persistent HTTP: response time
server leaves connection open after sending response
subsequent HTTP messages between same client/server sent over
open connection
19
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, 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
Accept-Charset: ISO-8859-1,utf-8;q=0.7\r\n
carriage return, Keep-Alive: 115\r\n
line feed at start Connection: keep-alive\r\n
of line indicates \r\n
end of header lines HTTP keep-alive, a.k.a., HTTP persistent connection, is an instruction
that allows a single TCP connection to remain open for multiple HTTP
requests/responses. By default, HTTP connections close after each
20
request.
HTTP request message: general format
~
~ entity body ~
~ body
21
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 of in URL field
response and give meta
information in headers DELETE
about it deletes file specified in
the URL field
22
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
23
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
24
Trying out HTTP (client side) for yourself
1. Telnet to your favorite Web server:
25
User-server state: cookies
many Web sites use cookies to keep track of users (stateless http)
four components:
1) cookie header line of HTTP response message
2) cookie header line in 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 always access Internet from PC
visits specific e-commerce site for first time
when initial HTTP requests arrives at site, site creates:
unique ID
entry in backend database for ID
26
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
28
Web caches (proxy server)
goal: satisfy client request without involving origin server
user sets browser: Web
accesses via cache
client origin
server
29
More about Web caching
cache acts as both client and server
server for original requesting client
client to origin server
Up-to-date objects?
30
Conditional GET
client server
32
FTP: separate control, data connections
33
FTP commands, responses
sample commands: sample return codes
sent as ASCII text over control status code and phrase (as in
channel HTTP)
331 Username OK,
USER username password required
PASS password
125 data connection
LIST return list of file in already open; transfer
starting
current directory
34
Electronic mail outgoing
message queue
Three major components: user mailbox
user agents
user
agent
mail servers
simple mail transfer protocol: SMTP
mail user
server agent
User Agent
“mail reader”: composing, editing, reading mail SMTP mail user
messages (e.g., outlook, iPhone mail client…)
server agent
outgoing, incoming messages stored on server
SMTP
mail servers:
mailbox contains incoming messages for user
SMTP user
agent
mail
message queue of outgoing (to be sent) mail
server
messages user
agent
SMTP protocol between mail servers to send
email messages user
agent
client: sending mail server
“server”: receiving mail server
35
Electronic Mail: SMTP
uses TCP port 25 to reliably transfer email message from client to
server
36
Scenario: Alice sends message to Bob
1) Alice uses UA to compose message “to” bob@[Link]
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
above lets you send email without using email client (reader)
38
Mail message format
SMTP: protocol for exchanging
email msgs
header
2-blank
RFC 822: standard for text message line
format:
1-header lines, e.g.,
To:
From: body
Subject:
39
Mail access protocols
user
mail access user
SMTP SMTP protocol
agent agent
(e.g., POP,
IMAP)
IMAP: Internet Mail Access Protocol [RFC 1730]: more features, including
manipulation of stored msgs on server (TCP port 143)
40
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
41
DNS: domain name system
people: many identifiers:
SSN, name, passport #
42
DNS: services, structure
DNS services why not centralize
hostname to IP address translation DNS?
single point of failure
host aliasing traffic volume
canonical, alias names distant centralized database
maintenance
mail server aliasing
43
DNS: a distributed, hierarchical database
Root DNS Servers
… …
44
DNS: a distributed, hierarchical database
root name servers
contacted by local name server that can not resolve name
root name server:
contacts authoritative name server if name mapping not known
gets mapping
returns mapping to local name server
c. Cogent, Herndon, VA (5 other sites)
d. U Maryland College Park, MD k. RIPE London (17 other sites)
h. ARL Aberdeen, MD
j. Verisign, Dulles VA (69 other sites ) i. Netnod, Stockholm (37 other sites)
45
DNS: a distributed, hierarchical database
top-level domain (TLD) servers:
responsible for com, org, net, edu, aero, jobs, museums, and all top-
level country domains, e.g.: uk, fr, ca, jp
when host makes DNS query, query is sent to its local DNS server
has local cache of recent name-to-address translation pairs
acts as proxy, forwards query into hierarchy
46
DNS name root DNS server
resolution example
2
host at [Link] 3
TLD DNS server
wants IP address for 4
[Link]
5
47
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]
48
DNS: caching, updating records
once (any) name server learns mapping, it caches
mapping
49
DNS records
DNS: distributed db 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
50
DNS protocol, messages
query and reply messages, both with same message
format 2 bytes 2 bytes
51
DNS protocol, messages
2 bytes 2 bytes
identification flags
53