CHAPTER 2
APPLICATION LAYER
FACULTY OF INFORMATION TECHNOLOGY
MSc. NGUYEN CONG DANH
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
OUTLINE
1. Application Architectures
2. Web & HTTP
3. DNS (Domain Name System)
4. FTP service
5. P2P applications
6. Electronic mail
2
1. APPLICATION
ARCHITECTURES
Faculty of Information Technology
MSc. Nguyen Cong Danh
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
SOME NETWORK APPS
• e-mail
• web
• text messaging
• remote login
• P2P file sharing
• multi-user network games
• streaming stored video (YouTube, Hulu, Netflix)
• voice over IP (e.g., Skype)
• real-time video conferencing
• social networking
• search
• …
4
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
APPLICATION PROTOCOL DEFINES…
• Types of messages exchanged • Open protocols:
- e.g., request, response o Defined in RFCs
• Message syntax: o Allows for interoperability
- what fields in messages & how fields are o e.g., HTTP, SMTP
delineated • Proprietary protocols:
• Message semantics o e.g., Skype
- meaning of information in fields
• Rules for when and how processes send &
respond to messages
5
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
CLIENT-SERVER ARCHITECTURE
Server:
• always-on host
• permanent IP address
• data centers for scaling
Clients:
• communicate with server
• may be intermittently connected
• may have dynamic IP addresses
• do not communicate directly with each other
6
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
P2P ARCHITECTURE
• No always-on server
• Arbitrary end systems directly communicate
• Peers request service from other peers, provide
service in return to other peers
o Self scalability – new peers bring new
service capacity, as well as new service
demands
• Peers are intermittently connected and change
IP addresses
o Complex management
7
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
PROCESSES COMMUNICATING
How the programs, running in multiple end systems, communicate with each other?
clients, servers
Process: program running within a host Client process: process that
• Within same host, two processes initiates communication
communicate using inter-process Server process: process that waits
communication (defined by OS) to be contacted
• Processes in different hosts
communicate by exchanging
messages • Aside: applications with P2P architectures
have client processes & server processes
8
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
SOCKETS
• Process sends/receives messages
to/from its socket
• Socket analogous to door
o Sending process shoves message
out door
o Sending process relies on
transport infrastructure on other
side of door to deliver message to
socket at receiving process
Application processes, sockets, and underlying transport protocol
9
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
ADDRESSING PROCESSES
• To receive messages, process must • Identifier includes both IP address and port numbers
have identifier associated with process on host.
• Host device has unique 32-bit IP • Example port numbers:
address o HTTP server: 80
• Question: does IP address of host on o Mail server: 25
which process runs suffice for
• To send HTTP message to mangmaytinh.com web
identifying the process?
server:
- Answer: no, many processes can o IP address: 128.119.245.12
be running on same host
o Port number: 80
• More shortly…
10
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
TRANSPORT SERVICES AVAILABLE TO
APPLICATION
Reliable Data Transfer Throughput
• some apps (e.g., file transfer, web some apps (e.g., multimedia) require
transactions) require 100% reliable data minimum amount of throughput to be
transfer “effective” bandwidth-sensitive
applications.
• other apps (multimedia apps: e.g.,
other apps (“elastic apps”) make use of
audio) can tolerate some loss
whatever throughput they get
Timing Security
• some apps (e.g., Internet telephony, encryption, data integrity, …
interactive games) require low delay to
be “effective”
11
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
SUPPLEMENT 1 - Transport service requirements: common apps
12
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
SUPPLEMENT 2 - Internet transport protocols services
TCP service: UDP service:
• reliable transport between sending
and receiving process • unreliable data transfer between
• flow control: sender won’t sending and receiving process
overwhelm receiver • does not provide: reliability, flow
• congestion control: throttle sender
control, congestion control,
when network overloaded
• does not provide: timing, minimum timing, throughput guarantee,
throughput guarantee, security security, or connection setup,
• connection-oriented: setup required
between client and server
processes
13
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
SUPPLEMENT 3 - Internet apps: application, transport protocols
14
2. WEB & HTTP
Faculty of Information Technology
MSc. Nguyen Cong Danh
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
WEB
First, a review…
• 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, e.g.,
www.someschool.edu/someDept/pic.gif
host name path name
16
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
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
17
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
HTTP OVERVIEW
Uses TCP: HTTP is “stateless”
• server maintains no information
• Client initiates TCP connection (creates about past client requests
socket) to server, port 80
aside
• Server accepts TCP connection from client
Protocols that maintain “state”
• HTTP messages (application-layer protocol are complex!
messages) exchanged between browser past history (state) must be
(HTTP client) and Web server (HTTP server) maintained
if server/client crashes, their
• TCP connection closed
views of “state” may be
inconsistent, must be reconciled
18
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
HTTP OVERVIEW
Persistent HTTP
Non-persistent HTTP • Multiple objects can be sent
• At most one object sent over single TCP connection
over TCP connection between client, server
o Connection then closed • Server leaves connection
• Downloading multiple open after sending response
objects required multiple • Subsequent HTTP messages
connections between same client/server
• Requires 2 RTTs per object sent over open connection
• OS overhead for each TCP • Slient sends requests as
connection soon as it encounters a
referenced object
• Browsers often open
parallel TCP connections to • As little as one RTT for all
fetch referenced objects the referenced objects
19
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
NON-PERSISTENT HTTP
(contains text,
suppose user enters URL: references to 10
www.someSchool.edu/someDepartment/home.index jpeg images)
1a. HTTP client initiates TCP
connection to HTTP server
1b. HTTP server at host
(process) at www.someSchool.edu
www.someSchool.edu on port 80 waiting for TCP connection
at port 80. “accepts”
2. HTTP client sends HTTP connection, notifying client
request message (containing
URL) into TCP connection 3. HTTP server receives
socket. Message indicates request message, forms
that client wants object response message
someDepartment/home.inde containing requested object,
x and sends message into its
time socket
20
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
NON-PERSISTENT HTTP 4. HTTP server closes TCP
connection.
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
time
21
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
HTTP REQUEST MESSAGE
• Two types of HTTP messages: request, response
• HTTP request message:
- ASCII (human-readable format) carriage return character
request line line-feed character
(GET, POST, GET /index.html HTTP/1.1\r\n
HEAD commands) Host: www-net.cs.umass.edu\r\n
User-Agent: Firefox/3.6.10\r\n
headerAccept: text/html,application/xhtml+xml\r\n
Accept-Language: en-us,en;q=0.5\r\n
linesAccept-Encoding: gzip,deflate\r\n
carriage return, \r\n
line feed at start
of line indicates
end of header lines
22
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
EXAMPLE
Suppose the client-to-server HTTP GET message
is the following:
GET
/kurose_ross_sandbox/interactive/quotation8.htm
HTTP/1.0
Host: gaia.cs.umass.edu
QUESTION LIST
If-Modified-Since: Mon, 27 Jul 2020 16:21:57 -0700
1. What is the name of the file that is being retrieved in this GET
message?
2. What version of HTTP is the client running?
3. True or False: The client already has a cached copy of the file
23
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
HTTP RESPONSE MESSAGE
status code status phrase
status line
(protocol)
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
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
data, e.g., \r\n
requested data data data data data ...
HTML file
24
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
HTTP RESPONSE STATUS CODES
• Status code appears in 1st line in server-to-client
response message.
• Some sample codes:
o 200 OK
- Rrequest succeeded, requested object later in
this msg
o 301 Moved Permanently
- Requested object moved, new location specified
later in this msg (Location:)
o 400 Bad Request
- Request msg not understood by server
o 404 Not Found
- Requested document not found on this server
o 505 HTTP Version Not Supported
25
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
EXAMPLE
Suppose the server-to-client HTTP RESPONSE message
is the following:
HTTP/1.1 200 OK
Date: Mon, 27 Jul 2020 23:12:22 +0000
Server: Apache/2.2.3 (CentOS)
Last-Modified: Mon, 27 Jul 2020 23:15:22 +0000 QUESTION LIST
ETag:17dc6-a5c-bf716880.
Content-Length: 51389 1. Is the response message using HTTP 1.0 or HTTP 1.1?
Keep-Alive: timeout=33, max=79 2. Was the server able to send the document successfully? Yes
Connection: Keep-alive or No
Content-type: image/html 3. How big is the document in bytes?
4. Is the connection persistent or nonpersistent?
5. What is the type of file being sent by the server in response?
6. What is the name of the server and its version? Write your
answer as server/x.y.z
7. Will the ETag change if the resource content at this particular
resource location changes? Yes or No
26
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
ASSIGNMENT 1
1. What are the cookies (user-server state)?
2. Web caches (Proxy server)?
27
3. DNS (DOMAIN
NAME SYSTEM)
Faculty of Information Technology
MSc. Nguyen Cong Danh
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
DNS: DOMAIN NAME SYSTEM
DNS services
• People: many identifiers: • Hostname to IP address translation
- SSN, name, passport # • Host aliasing
• Internet hosts, routers: - canonical, alias names
- IP address (32 bit) - used for addressing • Mail server aliasing
datagrams
• Load distribution
- “name”, e.g., www.yahoo.com - used by
- replicated Web servers: many IP
humans
addresses correspond to one name
Question: how to map between IP address
• DNS generally uses UDP, in some cases
and name, and vice versa ?
such as, zone transfer it uses TCP
• Port: 53
Domain Name System (= Distributer
Database) with many name servers.
29
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
DNS: A DISTRIBUTED, HIERARCHICAL
DATABASE
30
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
TOP-LEVEL DOMAIN (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.: uk, fr, ca, jp
- Network Solutions maintains servers for .com TLD
- Educause for .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
• Local DNS server
o Does not strictly belong to hierarchy
o Each ISP (residential ISP, company, university) has one, also called “default name server”
o 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
31
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
EXAMPLE
• Host at cse.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”
32
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
EXAMPLE
• Host at cse.nyu.edu wants IP address for
gaia.cs.umass.edu
Recursive query:
• Puts burden of name resolution on
contacted name server
• Heavy load at upper levels of hierarchy?
33
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
DNS RECORDS
• A resource record, commonly referred to as an RR, is the unit of information entry in DNS
database
• RRs are used to resolve all DNS queries
• Including:
o Start of Authority (SOA)
o Name Server (NS)
o Host (A)
o Host (AAAA)
o Canonical Name (CNAME)
o Mail Exchanger (MX)
o Pointer (PTR)
o Service Record (SRV)
34
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
DNS MESSAGE FORMAT
35
4. FTP SERVICE
Faculty of Information Technology
MSc. Nguyen Cong Danh
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
FILE TRANSFER PROTOCOL (FTP)
• FTP is used for the transfer of computer files
between a client and server on a computer
network
• FTP is built on a client-server model
architecture using separate control (port 21)
and data (port 20) connections between the
client and the server.
• FTP provides the sharing of files.
• It uses TCP protocol.
• It transfers the data more reliably and
efficiently.
37
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
ACTIVE FTP MODE
38
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
PASSIVE FTP MODE
39
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
FTP COMMANDS, RESPONSES
Sample commands: Sample return codes
• sent as ASCII text over control channel • status code and phrase (as in HTTP)
• USER username • 331 Username OK, password required
• PASS password • 125 data connection already open; transfer starting
• LIST return list of file in current directory • 425 Can’t open data connection
• RETR filename retrieves (gets) file • 452 Error writing file
• STOR filename stores (puts) file onto
remote host
40
5. P2P APPLICATIONS
Faculty of Information Technology
MSc. Nguyen Cong Danh
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
PEER-2-PEER (P2P) ARCHITECTURE
• No always-on server, all nodes are both clients
and servers
o Provide and consume data
o Any node can initiate a connection
• No centralized data source
o The information is not located in a central
location but is distributed among all peers
• Arbitrary end systems directly communicate
• Peers are intermittently connected and change
IP addresses
• Network is dynamic: nodes enter and leave the
network “frequently”
Examples:
- File distribution (BitTorrent)
- Streaming (KanKan)
- VoIP (Skype) 42
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
P2P FILE DISTRIBUTION: BIT TORRENT
• File divided into 256KB chunks
• Peers in torrent send/receive file chunks
tracker: tracks peers torrent: group of peers
participating in torrent exchanging chunks of a file
Alice arrives …
… obtains list
of peers from tracker
… and begins exchanging
file chunks with peers in torrent
43
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
P2P FILE DISTRIBUTION: BIT TORRENT
• Peer joining torrent:
o Has no chunks, but will accumulate them over time
from other peers
o 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
44
6. ELECTRONIC MAIL
Faculty of Information Technology
MSc. Nguyen Cong Danh
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
ELECTRONIC MAIL
Three major components:
• User agents
• Mail servers
• Simple mail transfer protocol: SMTP
A. User Agent
• a.k.a. “mail reader”
• composing, editing, reading mail messages
• e.g., Outlook, Thunderbird, iPhone mail client
• outgoing, incoming messages stored on server
46
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
ELECTRONIC MAIL
B. Mail Server
• Mailbox contains incoming messages for user
• Message queue of outgoing (to be sent) mail
messages
• SMTP protocol between mail servers to send
email messages
o client: sending mail server
o “server”: receiving mail server
47
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
ELECTRONIC MAIL
C. SMTP Protocol
• Uses TCP to reliably transfer email message from
client to server, port 25
• Direct transfer: sending server to receiving server
• Three phases of transfer
o handshaking (greeting)
o transfer of messages
o closure
48
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
SCENARIO: ALICE SENDS MESSAGE TO BOB
1) Alice uses UA to compose message “to” 4) SMTP client sends Alice’s message over the TCP
[email protected] connection
2) Alice’s UA sends message to her mail server; 5) Bob’s mail server places the message in Bob’s mailbox
message placed in message queue 6) Bob invokes his user agent to read message
3) client side of SMTP opens TCP connection
with Bob’s mail server
49
FACULTY OF INFORMATION TECHNOLOGY
MSc. Nguyen Cong Danh
MAIL ACCESS PROTOCOLS
• SMTP: delivery/storage to receiver’s server
• Mail access protocol: retrieval from server
- POP3: Post Office Protocol – Version 3 [RFC 1939]: authorization, download (Port: 110).
- IMAP: Internet Mail Access Protocol [RFC 3501]: more features, including manipulation of stored
messages on server
- HTTP: gmail, Hotmail, Yahoo! Mail, etc.
50