application layer.pdf
TRANSCRIPT
Application Layer
CC&N-CE-402 1
Application Layer
Computer Communication & Networking— CE - 402
Department of Computer Engineering, SSUET
1Instructor: M. Rehan RasheedCE - 402
Instructor: M. Rehan Rasheed 2
Network applications:
Process: program running within a host.
within same host, two processes communicate using interprocess communication (defined by OS).
processes running in different hosts communicate with an application-layer protocol
User agent: interfaces with user “above” and network “below”.
implements user interface & application-level protocol
Web: browser
E-mail: mail reader
streaming audio/video: media player
CE - 402
Application Layer
CC&N-CE-402 2
3
Applications and application-layer protocols
Application: communicating, distributed processes
e.g., e-mail, Web, P2P file sharing, instant messaging
running in end systems (hosts)
exchange messages to implement application
Application-layer protocols
one “piece” of an app
define messages exchanged by apps and actions taken
use communication services provided by lower layer protocols (TCP, UDP)
applicationtransportnetworkdata linkphysical
applicationtransportnetworkdata linkphysical
applicationtransportnetworkdata linkphysical
CE - 402 Instructor: M. Rehan Rasheed
4
App-layer protocol defines
Types of messages exchanged, eg, request & response messages
Syntax of message types: what fields in messages & how fields are delineated
Semantics of the fields, ie, meaning of information in fields
Rules for when and how processes send & respond to messages
Public-domain protocols:
defined in RFCs
allows for interoperability
eg, HTTP, SMTP
Proprietary protocols:
eg, KaZaA
THREE PARADIGMS
• Client server
• Peer-to-Peer
• Hybrid
CE - 402 Instructor: M. Rehan Rasheed
Application Layer
CC&N-CE-402 3
5
Client-server paradigm
Client:
initiates contact with server
(“speaks first”)
typically requests service from
server,
Web: client implemented in
browser; e-mail: in mail reader
Typical network app has two pieces: client and server
Server:
provides requested service to client
e.g., Web server sends requested Web
page, mail server delivers e-mail
applicationtransportnetworkdata linkphysical
applicationtransportnetworkdata linkphysical
applicationtransportnetworkdata linkphysical
applicationtransportnetworkdata linkphysical
request
reply
CE - 402 Instructor: M. Rehan Rasheed
Instructor: M. Rehan Rasheed 6
Peer-to-Peer paradigm
Peers communicate with each other
Peers are desktop/laptops controlled by users
Communication is without passing through a dedicatedserver
Examples: File distribution application (Bit Torrent,Lime wire, eMule), Internet Telephony (Skype), IPTV(PPLive)
Hybrid Applications are instant messaging services(MSN, Yahoo)
Servers are used to track peer IP address andmessages are exchanged between users withoutpassing through intermediate servers
CE - 402
Application Layer
CC&N-CE-402 4
Instructor: M. Rehan Rasheed 7
Internet apps: their protocols and transport
protocols
Application
remote terminal access
Web
file transfer
streaming multimedia
remote file server
Internet telephony
Application
layer protocol
smtp
telnet
http
ftp
proprietary
(e.g. RealNetworks)
NSF
proprietary
(e.g., Vocaltec)
Underlying
transport protocol
TCP
TCP
TCP
TCP
TCP or UDP
TCP or UDP
typically UDP
CE - 402
8
WWW: the http protocol
http: hypertext transfer
protocol
WWW’s application layer
protocol
client/server model
client: browser that
requests, receives,
“displays” WWW objects
server: WWW server
sends objects in response
to requests
PC runningExplorer
Server runningNCSA Webserver
Mac runningNavigator
CE - 402 Instructor: M. Rehan Rasheed
Application Layer
CC&N-CE-402 5
The WWW today is a distributed client/server service, inwhich a client using a browser can access a service using aserver.
However, the service provided is distributed over manylocations called sites.
Each site holds one or more documents, referred to asWeb pages.
The request, among other information, includes theaddress of the site and the Web page, called the URL
WWW: the http protocol
CE - 402 Instructor: M. Rehan Rasheed 9
Architecture of WWW
CE - 402 Instructor: M. Rehan Rasheed 10
Application Layer
CC&N-CE-402 6
Client (Browser)
Each browser usually consists of three parts: a controller, client protocol, and
interpreters.
The controller receives input from the keyboard or the mouse and uses the
client programs to access the document.
After the document has been accessed, the controller uses one of the
interpreters to display the document on the screen.
The client protocol can be one of the protocols described previously such as
FTP or HTTP.
The interpreter can be HTML, Java, or JavaScript, depending on the type of
document.
CE - 402 Instructor: M. Rehan Rasheed 11
URL
To facilitate the access of documents distributedthroughout the world, HTTP uses locators.
The uniform resource locator (URL) is a standard forspecifying any kind of information on the Internet.
The URL defines four things: protocol, host computer,port, and path
CE - 402 Instructor: M. Rehan Rasheed 12
Application Layer
CC&N-CE-402 7
Cookies
A cookie, also known as an HTTP cookie, web cookie, or
browser cookie, is a small piece of data sent from a website and
stored in a user's web browser while the user is browsing that
website.
Every time the user loads the website, the browser sends the
cookie back to the server to notify the website of the user's
previous activity.
Cookies were designed to be a reliable mechanism for websites
to remember stateful information (such as items in a shopping
cart) or to record the user's browsing activity (including clicking
particular buttons, logging in, or recording which pages were
visited by the user as far back as months or years ago).
CE - 402 Instructor: M. Rehan Rasheed 13
Cookies
The World Wide Web was originally designed as a stateless
entity. A client sends a request; a server responds. Their
relationship is over.
The original design of WWW, retrieving publicly available
documents, exactly fits this purpose.
Today the Web has other functions; some are listed here.
1. Some websites need to allow access to registered clients only.
2. Websites are being used as electronic stores that allow users to browse
through the store, select wanted items, put them in an electronic cart,
and pay at the end with a credit card.
3. Some websites are used as portals: the user selects the Web pages he
wants to see.
4. Some websites are just advertising.
For these purposes, the cookie mechanism was devised
CE - 402 Instructor: M. Rehan Rasheed 14
Application Layer
CC&N-CE-402 8
WEB DOCUMENTS
The documents in the WWW can be grouped into three
broad categories: static, dynamic, and active.
The category is based on the time at which the contents of
the document are determined.
CE - 402 Instructor: M. Rehan Rasheed 15
Static document
When a client accesses the document, a copy of the document is
sent. The user can then use a browsing program to display the
document
CE - 402 Instructor: M. Rehan Rasheed 16
Application Layer
CC&N-CE-402 9
Dynamic document using CGI
A dynamic document is created by a Web server whenever a
browser requests the document.
When a request arrives, the Web server runs an application
program or a script that creates the dynamic document. The
server returns the output of the program or script as a response
to the browser that requested the document.
CE - 402 Instructor: M. Rehan Rasheed 17
Dynamic document using server-site script
Dynamic documents are sometimes referred to as server-site
dynamic documents.
CE - 402 Instructor: M. Rehan Rasheed 18
Application Layer
CC&N-CE-402 10
Active document using Java applet
Active document using client-site script
Active documents are
sometimes referred to as
client-site dynamic
documents.
CE - 402 Instructor: M. Rehan Rasheed 19
HTTP
The Hypertext Transfer Protocol (HTTP) is a protocol used
mainly to access data on the World Wide Web. HTTP functions
as a combination of FTP and SMTP.
It is similar to FTP because it transfers files and uses the
services of TCP.
However, it is much simpler than FTP because it uses only one
TCP connection. There is no separate control connection; only
data are transferred between the client and the server.
HTTP uses the services of TCP on well-known port 80.
CE - 402 Instructor: M. Rehan Rasheed 20
Application Layer
CC&N-CE-402 11
Request and response messages
CE - 402 Instructor: M. Rehan Rasheed 21
22
The http protocol: more
http: TCP transport service:
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
WWW server (http server)
TCP connection closed
http is “stateless”
server maintains no
information about past client
requests
so that the communication
consists of independent pairs
of request and response
Protocols that maintain “state”
are complex!
CE - 402 Instructor: M. Rehan Rasheed
Application Layer
CC&N-CE-402 12
Instructor: M. Rehan Rasheed 23
http example
Suppose user enters URL
www.SSUET.edu/CEDt/home.index
1a. http client initiates TCP
connection to http server
(process) at www.SSUET.edu.
Port 80 is default for http server.
2. http client sends http request message (containing URL) into TCP connection socket
1b. http server at host www.SSUET.edu waiting for TCP connection at port 80. “accepts” connection, notifying client
3. http server receives request message, forms response message containing requested object (CED/home.index), sends message into sockettime
(contains text, references
to 10 jpeg images)
CE - 402
Instructor: M. Rehan Rasheed 24
http example (cont.)
5. http client receives response
message containing html file,
displays html. Parsing html file,
finds 10 referenced jpeg
objects
6. Steps 1-5 repeated for each of 10 jpeg objects
4. http server closes TCP connection.
time
CE - 402
Application Layer
CC&N-CE-402 13
HTTP persistent connection
HTTP persistent connection, also called HTTP keep-alive, or
HTTP connection reuse, is the idea of using a single TCP
connection to send and receive multiple HTTP
requests/responses, as opposed to opening a new connection
for every single request/response pair
HTTP 1.1
In HTTP 1.1, all connections are considered persistent unless
declared otherwise. The HTTP persistent connections do not use
separate keepalive messages, they just allow multiple requests
to use a single connection.
CE - 402 Instructor: M. Rehan Rasheed 25
Advantages Persistent connection
Lower CPU and memory usage (because fewer connections are
open simultaneously).
Enables HTTP pipelining of requests and responses.
Reduced network congestion (fewer TCP connections).
Reduced latency in subsequent requests (no handshaking).
Errors can be reported without the penalty of closing the TCP
connection.
CE - 402 Instructor: M. Rehan Rasheed 26
Application Layer
CC&N-CE-402 14
Persistent V/s Non persistent
non-persistent
connection: one object
in each TCP
connection
some browsers
create multiple
TCP connections
simultaneously -
one per object
persistent connection:
multiple objects
transferred within one
TCP connection
CE - 402 Instructor: M. Rehan Rasheed 27
28
http message format: request
two types of http messages: request, response
http request message:
ASCII (human-readable format)
GET /somedir/page.html HTTP/1.1
Connection: close
User-agent: Mozilla/4.0
Accept: text/html, image/gif,image/jpeg
Accept-language:fr
(extra carriage return, line feed)
request line(GET, POST, HEAD commands)
headerlines
Carriage return, line feed indicates end of message
CE - 402 Instructor: M. Rehan Rasheed
Application Layer
CC&N-CE-402 15
Instructor: M. Rehan Rasheed 29
http request message: general format
CE - 402
Instructor: M. Rehan Rasheed 30
http message format: reply
HTTP/1.1 200 OK
Connection: close
Date: Thu, 06 Aug 2011 12:00:15 GMT
Server: Apache/1.3.0 (Unix)
Last-Modified: Mon, 22 Jun 2011 …...
Content-Length: 6821
Content-Type: text/html
data data data data data ...
status line(protocolstatus codestatus phrase)
headerlines
data, e.g., requestedhtml file
CE - 402
Application Layer
CC&N-CE-402 16
Instructor: M. Rehan Rasheed 31
http reply status codes
200 OK
request succeeded, requested object later in this message
301 Moved Permanently
requested object moved, new location specified later in this
message (Location:)
400 Bad Request
request message not understood by server
404 Not Found
requested document not found on this server
505 HTTP Version Not Supported
In first line in server->client response message.
A few sample codes:
CE - 402
Instructor: M. Rehan Rasheed 32
User-server interaction: authentication
Authentication goal: control
access to server documents
stateless: client must present
authorization in each request
authorization: typically name,
password
authorization: header line in
request
if no authorization presented,
server refuses access, sends
WWW authenticate:
header line in response
client server
usual http request msg
401: authorization req.
WWW authenticate:
usual http request msg+ Authorization:line
usual http response msg
usual http request msg+ Authorization:line
usual http response msgtime
CE - 402
Application Layer
CC&N-CE-402 17
33
User-server interaction: conditional GET
Goal: don’t send object if
client has up-to-date stored
(cached) version
client: specify date of cached
copy in http request
If-modified-since:
<date>
server: response contains no
object if cached copy up-to-
date:
HTTP/1.0 304 Not
Modified
client server
http request msgIf-modified-since:
<date>
http responseHTTP/1.0
304 Not Modified
object not modified
http request msgIf-modified-since:
<date>
http responseHTTP/1.1 200 OK
…
<data>
object modified
CE - 402 Instructor: M. Rehan Rasheed
34
Web Caches (proxy server)
user sets browser:
WWW accesses via
web cache
client sends all http
requests to web cache
if object at web cache,
web cache immediately
returns object in http
response
else requests object
from origin server, then
returns http response to
client
Goal: satisfy client request without involving origin server
client
Proxyserver
clientorigin server
origin server
CE - 402 Instructor: M. Rehan Rasheed
Application Layer
CC&N-CE-402 18
35
Why WWW Caching?
Assume: cache is “close” to
client (e.g., in same
network)
smaller response time:
cache “closer” to client
decrease traffic to distant
servers
link out of institutional/local
ISP network often
bottleneck
originservers
publicInternet
institutionalnetwork 10 Mbps LAN
1.5 Mbps access link
institutional
cache
CE - 402 Instructor: M. Rehan Rasheed
Instructor: M. Rehan Rasheed 36
ftp: the file transfer protocol
transfer file to/from remote host
client/server model
client: side that initiates transfer (either to/from remote)
server: remote host
ftp server: port 21
file transferFTPserver
FTPuserinterface
FTPclient
local filesystem
remote filesystem
user at host
CE - 402
Application Layer
CC&N-CE-402 19
Instructor: M. Rehan Rasheed 37
ftp: separate control, data connections
ftp client contacts ftp server at
port 21, specifying TCP as
transport protocol
two parallel TCP connections
opened:
control: exchange
commands, responses
between client, server.
“out of band control”
data: file data to/from server
ftp server maintains “state”:
current directory, earlier
authentication
FTPclient
FTPserver
TCP control connectionport 21
TCP data connectionport 20
CE - 402
Instructor: M. Rehan Rasheed 38
ftp commands, responses
Sample commands:
sent as ASCII text over control
channel
USER username
PASS password
LIST return list of files in
current directory
RETR filename retrieves
(gets) file
STOR filename stores (puts)
file onto remote host
Sample return codes
status code and phrase (as in
http)
331 Username OK,
password required
125 data connection
already open; transfer
starting
425 Can’t open data
connection
452 Error writing file
CE - 402
Application Layer
CC&N-CE-402 20
Instructor: M. Rehan Rasheed 39
Electronic Mail
Three major components:
user agents
mail servers
simple mail transfer protocol:
smtp
User Agent
a.k.a. “mail reader”
composing, editing, reading
mail messages
e.g., Microsoft Outlook,
Pegasus Mail,Gmail, Yahoo
outgoing, incoming messages
stored on server
user mailbox
outgoing message queue
mailserver
useragent
useragent
useragent
mailserver
useragent
useragent
mailserver
useragent
SMTP
SMTP
SMTP
CE - 402
Instructor: M. Rehan Rasheed 40
Electronic Mail: mail servers
Mail Servers
mailbox contains incoming
messages (yet to be read) for user
message queue of outgoing (to be
sent) mail messages
smtp protocol between mail server
to send email messages
client: “sending mail server”
server: “receiving mail server”
mailserver
useragent
useragent
useragent
mailserver
useragent
useragent
mailserver
useragent
SMTP
SMTP
SMTP
CE - 402
Application Layer
CC&N-CE-402 21
Instructor: M. Rehan Rasheed 41
Electronic Mail: Smtp
uses tcp to reliably transfer email msg from client
to server, port 25
direct transfer: sending server to receiving server
three phases of transfer
handshaking (greeting)
transfer
closure
command/response interaction
commands: ASCI text
response: status code and phrase
CE - 402
Instructor: M. Rehan Rasheed 42
Sample smtp interaction
S: 220 SSUET.edu
C: HELO yahoo.com
S: 250 Hello yahoo.com, pleased to meet you
C: MAIL FROM: <[email protected] >
S: 250 [email protected] ... Sender ok
C: RCPT TO: <[email protected]>
S: 250 [email protected] ... Recipient ok
C: DATA
S: 354 Enter mail, end with "." on a line by itself
C: Do you like ketchup?
C: How about pickles?
C: .
S: 250 Message accepted for delivery
C: QUIT
S: 221 SSUET.edu closing connection
CE - 402
Application Layer
CC&N-CE-402 22
Instructor: M. Rehan Rasheed 43
Smtp: http
Comparison with http
http: pull
email: push
both have ASCII command/response interaction, status codes
http: each object encapsulated in its own response (if v.1.0 or so
specified in 1.1)
smtp: multiple message parts sent in one connection (multipart
mess)
CE - 402
Instructor: M. Rehan Rasheed 44
Message format: multimedia extensions
MIME: multimedia mail extension,
additional lines in msg header declare MIME content type
From: [email protected]
Subject: Picture of yummy crepe.
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Type: image/jpeg
base64 encoded data .....
.........................
......base64 encoded data
.
multimedia datatype, subtype,
parameter declaration
method usedto encode data
MIME version
encoded data
CE - 402
Application Layer
CC&N-CE-402 23
45
Mail access protocols
SMTP: delivery/storage to receiver’s server
Mail access protocol: retrieval from server
POP: Post Office Protocol
authorization (agent <-->server) and
download
IMAP: Internet Mail Access Protocol
more features (more complex)
manipulation of stored msgs on
server
receiver’s mail server
useragent
sender’s mail server
useragent
SMTP SMTP POP3 orIMAP
POP IMAP
Relatively straightforward
Slower but more redundant
Faster (sends your e-mails and gets e-mails from you)
Keeps a copy of everything you do on the server
The downside is that if you lose e-mails on your computer you have lost them forever (unless you have saved a copy on the server)
The downside is that it takes up more space
CE - 402 Instructor: M. Rehan Rasheed
Instructor: M. Rehan Rasheed 46
P2P file sharing
Example
Alice runs P2P client application
on her notebook computer
Intermittently connects to
Internet; gets new IP address for
each connection
Asks for “XYZ”
Application displays other peers
that have copy of XYZ.
Alice chooses one of the peers,
Bob.
File is copied from Bob’s PC to
Alice’s notebook: HTTP
While Alice downloads, other
users uploading from Alice.
Alice’s peer is both a Web client
and a transient Web server.
All peers are servers = highly
scalable!
CE - 402
Application Layer
CC&N-CE-402 24
Instructor: M. Rehan Rasheed 47
P2P: centralized directory
original “Napster” design
1) when peer connects, it
informs central server:
IP address
content
2) Alice queries for “XYZ”
3) Alice requests file from
Bob
centralizeddirectory server
peers
Alice
Bob
1
1
1
12
3
CE - 402
Instructor: M. Rehan Rasheed 48
P2P: problems with centralized directory
Single point of failure
Performance bottleneck
Copyright violation file transfer is decentralized, but locating content is highly decentralized
CE - 402
Application Layer
CC&N-CE-402 25
Instructor: M. Rehan Rasheed 49
P2P: decentralized directory
Each peer is either a group
leader or assigned to a
group leader.
Group leader tracks the
content in all its children.
Peer queries group leader;
group leader may query
other group leaders.
ordinary peer
group-leader peer
neighoring relationships
in overlay network
CE - 402
Instructor: M. Rehan Rasheed 50
More about decentralized directory
overlay network
peers are nodes
edges between peers and their
group leaders
edges between some pairs of
group leaders
virtual neighbors
bootstrap node
connecting peer is either
assigned to a group leader or
designated as leader
advantages of approach
no centralized directory server
location service distributed
over peers
more difficult to shut down
disadvantages of approach
bootstrap node needed
group leaders can get
overloaded
CE - 402
Application Layer
CC&N-CE-402 26
Instructor: M. Rehan Rasheed 51
P2P: Query flooding
Gnutella
no hierarchy
use bootstrap node to learn
about others
join message
Send query to neighbors
Neighbors forward query
If queried peer has object,
it sends message back to
querying peer
join
CE - 402
Skype
Instructor: M. Rehan Rasheed 52
Skype is a peer-to-peer VoIP client
developed in 2003 by the
organization that created Kazaa
Skype uses an overlay peer-to-peer
network
An ordinary host must connect to a
super node and must authenticate
itself with the Skype login server
User names, passwords and “buddy
list” are stored at the login server
It uses TCP for signaling and both
UDP and TCP for transporting
media traffic
CE - 402