Sei sulla pagina 1di 40

Chapter 2: Application Layer

Chapter goals: More chapter goals


 conceptual +  specific protocols:
implementation aspects
 http
of network application
protocols  ftp
 client server
 smtp
paradigm  pop
 service models  dns
 learn about protocols by  programming network
examining popular applications
application-level
 socket programming
protocols

2: Application Layer 1
Applications and application-layer protocols

Application: communicating, application


transport
distributed processes network
data link
 running in network hosts in physical

“user space”
 exchange messages to
implement app
 e.g., email, file transfer,
the Web
Application-layer protocols
application
 one “piece” of an app application
transport
transport
network
network
 define messages
data link
data link physical
physical
exchanged by apps and
actions taken
 user services provided by
lower layer protocols
2: Application Layer 2
Network applications: some jargon

 A process is a program  A user agent is an


that is running within a interface between the
host.
user and the network
 Within the same host, two
processes communicate
application.
with interprocess  Web:browser
communication defined by  E-mail: mail reader
the OS.  streaming audio/video:
 Processes running in media player
different hosts
communicate with an
application-layer protocol

2: Application Layer 3
Client-server paradigm
Typical network app has two application
pieces: client and server transport
network
data link

Client: physical

 initiates contact with server


request
(“speaks first”)
 typically requests service from
server,
 for Web, client is implemented reply
in browser; for e-mail, in mail
application
reader transport
network
Server: data link
physical

 provides requested service to


client
 e.g., Web server sends
requested Web page, mail
2: Application Layer
server delivers e-mail 4
Application-layer protocols (cont).

API: application Q: how does a process


programming interface “identify” the other
 defines interface process with which it
between application wants to communicate?
and transport layer  IP address of host
running other process
 socket: Internet API
 “port number” - allows
 two processes receiving host to
communicate by sending determine to which
data into socket, local process the
reading data out of message should be
socket delivered

… lots more on this later.


2: Application Layer 5
What transport service does an app need?
Data loss
 some apps (e.g., audio) can
tolerate some loss
 other apps (e.g., file
transfer, telnet) require Timing
100% reliable data transfer  some apps (e.g., Internet
telephony, interactive
Bandwidth games) require low delay to
 some apps (e.g., multimedia) be “effective”
require minimum amount of
bandwidth to be “effective”
 other apps (“elastic apps”)
make use of whatever
bandwidth they get

2: Application Layer 6
Transport service requirements of common apps

Application Data loss Bandwidth Time Sensitive

file transfer no loss elastic no


e-mail no loss elastic no
Web documents loss-tolerant elastic no
real-time audio/video loss-tolerant audio: 5Kb-1Mb yes, 100’s msec
video:10Kb-5Mb
stored audio/video loss-tolerant same as above yes, few secs
interactive games loss-tolerant few Kbps up yes, 100’s msec
financial apps no loss elastic yes and no

2: Application Layer 7
Services provided by Internet
transport protocols
TCP service: UDP service:
 connection-oriented: setup  unreliable data transfer
required between client, between sending and
server receiving process
 reliable transport between  does not provide:
sending and receiving process connection setup,
 flow control: sender won’t reliability, flow control,
overwhelm receiver congestion control, timing,
or bandwidth guarantee
 congestion control: throttle
sender when network
overloaded Q: why bother? Why is
 does not providing: timing, there a UDP?
minimum bandwidth
guarantees
2: Application Layer 8
Internet apps: their protocols and transport
protocols
Application Underlying
Application layer protocol transport protocol

e-mail smtp [RFC 821] TCP


remote terminal access telnet [RFC 854] TCP
Web http [RFC 2068] TCP
file transfer ftp [RFC 959] TCP
streaming multimedia proprietary TCP or UDP
(e.g. RealNetworks)
remote file server NSF TCP or UDP
Internet telephony proprietary typically UDP
(e.g., Vocaltec)

2: Application Layer 9
The Web: some jargon
 User agent for Web is
 Web page:
called a browser:
 consists of “objects”
 MS Internet Explorer
 addressed by a URL
 Netscape Communicator
 Most Web pages
 Server for Web is
consist of:
called Web server:
 base HTML page, and
 Apache (public domain)
 several referenced
objects.  MS Internet
Information Server
 URL has two
components: host name
and path name:
www.someSchool.edu/someDept/pic.gif
2: Application Layer 10
The Web: the http protocol

http: hypertext transfer


protocol
 Web’s application layer PC running
protocol Explorer

 client/server model
 client: browser that
requests, receives, Server
“displays” Web objects running
NCSA Web
 server: Web server
server
sends objects in
response to requests
Mac running
 http1.0: RFC 1945 Navigator
 http1.1: RFC 2068

2: Application Layer 11
The http protocol: more
http: TCP transport http is “stateless”
service:  server maintains no
 client initiates TCP information about
connection (creates socket) past client requests
to server, port 80
aside
 server accepts TCP Protocols that maintain
connection from client “state” are complex!
 http messages (application-  past history (state) must
layer protocol messages) be maintained
exchanged between browser  if server/client crashes,
(http client) and Web server their views of “state” may
(http server) be inconsistent, must be
 TCP connection closed reconciled

2: Application Layer 12
http example
Suppose user enters URL (contains text,
www.someSchool.edu/someDepartment/home.index references to 10
jpeg images)
1a. http client initiates TCP
connection to http server
(process) at
1b. http server at host
www.someSchool.edu waiting
www.someSchool.edu. Port 80
for TCP connection at port 80.
is default for http server.
“accepts” connection, notifying
client
2. http client sends http request
message (containing URL) into
TCP connection socket 3. http server receives request
message, forms response
message containing requested
object
(someDepartment/home.index),
sends message into socket
time
2: Application Layer 13
http example (cont.)
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

2: Application Layer 14
Non-persistent and persistent connections

Non-persistent Persistent
 HTTP/1.0  default for HTTP/1.1
 server parses request,  on same TCP
responds, and closes connection: server,
TCP connection parses request,
 2 RTTs to fetch each responds, parses new
object request,..
 Each object transfer  Client sends requests
suffers from slow for all referenced
start objects as soon as it
receives base HTML.
But most 1.0 browsers use  Fewer RTTs and less
parallel TCP connections. slow start.

2: Application Layer 15
http message format: request

 two types of http messages: request, response


 http request message:
 ASCII (human-readable format)

request line
(GET, POST, GET /somedir/page.html HTTP/1.0
HEAD commands) User-agent: Mozilla/4.0
Accept: text/html, image/gif,image/jpeg
header Accept-language:fr
lines

Carriage return, (extra carriage return, line feed)


line feed
indicates end
of message
2: Application Layer 16
http request message: general format

2: Application Layer 17
http message format: respone
status line
(protocol
status code HTTP/1.0 200 OK
status phrase) Date: Thu, 06 Aug 1998 12:00:15 GMT
Server: Apache/1.3.0 (Unix)
Last-Modified: Mon, 22 Jun 1998 …...
header
Content-Length: 6821
lines
Content-Type: text/html

data data data data data ...


data, e.g.,
requested
html file

2: Application Layer 18
http response status codes
In first line in server->client response message.
A few 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 (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
2: Application Layer 19
Trying out http (client side) for yourself

1. Telnet to your favorite Web server:


telnet www.eurecom.fr 80 Opens TCP connection to port 80
(default http server port) at www.eurecom.fr.
Anything typed in sent
to port 80 at www.eurecom.fr

2. Type in a GET http request:


GET /~ross/index.html HTTP/1.0 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!

2: Application Layer 20
User-server interaction: authentication

Authentication goal: control client server


access to server documents usual http request msg
 stateless: client must present 401: authorization req.
authorization in each request WWW authenticate:
 authorization: typically name,
password usual http request msg
 authorization: header + Authorization:line
line in request
usual http response msg
 if no authorization
presented, server refuses
access, sends usual http request msg
WWW authenticate: + Authorization:line
header line in response usual http response msg time
Browser caches name & password so
that user does not have to repeatedly enter it. 2: Application Layer 21
User-server interaction: cookies

 server sends “cookie” to client server


client in response mst usual http request msg
Set-cookie: 1678453 usual http response +
 client presents cookie in Set-cookie: #
later requests
cookie: 1678453
usual http request msg
 server matches cookie: # cookie-
presented-cookie with spectific
usual http response msg action
server-stored info
 authentication
 remembering user usual http request msg
cookie-
preferences, previous cookie: #
spectific
choices usual http response msg action

2: Application Layer 22
User-server interaction: conditional GET

 Goal: don’t send object if client server


client has up-to-date stored
http request msg
(cached) version If-modified-since: object
 client: specify date of <date>
not
cached copy in http request http response modified
If-modified-since: HTTP/1.0
<date> 304 Not Modified

 server: response contains


no object if cached copy up-
to-date: http request msg
If-modified-since:
HTTP/1.0 304 Not
<date> object
Modified modified
http response
HTTP/1.1 200 OK

<data>
2: Application Layer 23
Web Caches (proxy server)
Goal: satisfy client request without involving origin server
 user sets browser: origin
Web accesses via web server
cache
Proxy
 client sends all http server
requests to web cache client
 if object at web
cache, web cache
immediately returns
object in http
response
 else requests object
from origin server, client
origin
then returns http server
response to client
2: Application Layer 24
Why Web Caching?
origin
servers
Assume: cache is “close”
to client (e.g., in same public
Internet
network)
 smaller response time:
cache “closer” to 1.5 Mbps
client access link

 decrease traffic to institutional


network
distant servers 10 Mbps LAN

 link out of
institutional/local ISP
network often institutional
bottleneck cache

2: Application Layer 25
ftp: the file transfer protocol

FTP file transfer


FTP FTP
user client server
interface
user
at host local file remote file
system system

 transfer file to/from remote host


 client/server model
 client: side that initiates transfer (either to/from
remote)
 server: remote host
 ftp: RFC 959
 ftp server: port 21

2: Application Layer 26
ftp: separate control, data connections

 ftp client contacts ftp server


at port 21, specifying TCP as
transport protocol
TCP control connection
 two parallel TCP connections port 21
opened:
 control: exchange
TCP data connection
commands, responses FTP port 20 FTP
between client, server. client server
“out of band control”
 data: file data to/from
server
 ftp server maintains “state”:
current directory, earlier
authentication
2: Application Layer 27
ftp commands, responses

Sample commands: Sample return codes


 sent as ASCII text over  status code and phrase (as
control channel in http)
 USER username  331 Username OK,
 PASS password password required
 125 data connection
 LIST return list of file in
already open;
current directory
transfer starting
 RETR filename retrieves  425 Can’t open data
(gets) file connection
 STOR filename stores  452 Error writing
(puts) file onto remote file
host

2: Application Layer 28
Electronic Mail outgoing
message queue
user mailbox
user
Three major components: agent
 user agents mail
user
server
 mail servers agent
 simple mail transfer SMTP mail
protocol: smtp server user
SMTP agent
User Agent
 a.k.a. “mail reader” SMTP
mail user
 composing, editing, reading agent
server
mail messages
 e.g., Eudora, Outlook, elm, user
Netscape Messenger agent
user
 outgoing, incoming messages agent
stored on server
2: Application Layer 29
Electronic Mail: mail servers
user
Mail Servers agent
 mailbox contains incoming mail
user
messages (yet to be read) server
agent
for user
SMTP
 message queue of outgoing mail
server user
(to be sent) mail messages
 smtp protocol between mail
SMTP agent

servers to send email SMTP


messages mail user
agent
 client: sending mail server
server
user
 “server”: receiving mail agent
server user
agent

2: Application Layer 30
Electronic Mail: smtp [RFC 821]

 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 of messages
 closure
 command/response interaction
 commands: ASCII text
 response: status code and phrase

 messages must be in 7-bit ASCII

2: Application Layer 31
Sample smtp interaction
S: 220 hamburger.edu
C: HELO crepes.fr
S: 250 Hello crepes.fr, pleased to meet you
C: MAIL FROM: <alice@crepes.fr>
S: 250 alice@crepes.fr... Sender ok
C: RCPT TO: <bob@hamburger.edu>
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

2: Application Layer 32
try smtp interaction for yourself:

 telnet servername 25
 see 220 reply from server
 enter HELO, MAIL FROM, RCPT TO, DATA, QUIT
commands
above lets you send email without using email client
(reader)

2: Application Layer 33
smtp: final words
 smtp uses persistent Comparison with http
connections
 http: pull
 smtp requires that
message (header & body)  email: push
be in 7-bit ascii  both have ASCII
 certain character strings command/response
are not permitted in interaction, status codes
message (e.g., CRLF.CRLF).
Thus message has to be  http: each object is
encoded (usually into either encapsulated in its own
base-64 or quoted response message
printable)  smtp: multiple objects
 smtp server uses message sent in a multipart
CRLF.CRLF to determine message
end of message
2: Application Layer 34
Mail message format

smtp: protocol for exchanging


email msgs header
blank
RFC 822: standard for text
line
message format:
 header lines, e.g.,
To:

body
 From:
 Subject:
different from smtp
commands!
 body
 the “message”, ASCII
characters only

2: Application Layer 35
Message format: multimedia extensions
 MIME: multimedia mail extension, RFC 2045, 2056
 additional lines in msg header declare MIME content
type

From: alice@crepes.fr
MIME version To: bob@hamburger.edu
Subject: Picture of yummy crepe.
method used MIME-Version: 1.0
to encode data Content-Transfer-Encoding: base64
Content-Type: image/jpeg
multimedia data
type, subtype, base64 encoded data .....
parameter declaration .........................
......base64 encoded data
encoded data

2: Application Layer 36
MIME types
Content-Type: type/subtype; parameters

Text Video
 example subtypes: plain,  example subtypes: mpeg,
html quicktime

Image Application
 example subtypes: jpeg,  other data that must be
gif processed by reader
before “viewable”
Audio  example subtypes:
 exampe subtypes: basic
msword, octet-stream
(8-bit mu-law encoded),
32kadpcm (32 kbps
coding)
2: Application Layer 37
Multipart Type
From: alice@crepes.fr
To: bob@hamburger.edu
Subject: Picture of yummy crepe.
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=98766789

--98766789
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain

Dear Bob,
Please find a picture of a crepe.
--98766789
Content-Transfer-Encoding: base64
Content-Type: image/jpeg

base64 encoded data .....


.........................
......base64 encoded data
--98766789--

2: Application Layer 38
Mail access protocols
SMTP SMTP POP3 or user
user
agent IMAP agent

sender’s mail receiver’s mail


server server

 SMTP: delivery/storage to receiver’s server


 Mail access protocol: retrieval from server
 POP: Post Office Protocol [RFC 1939]
• authorization (agent <-->server) and download
 IMAP: Internet Mail Access Protocol [RFC 1730]
• more features (more complex)
• manipulation of stored msgs on server
 HTTP: Hotmail , Yahoo! Mail, etc.

2: Application Layer 39
POP3 protocol S: +OK POP3 server ready
C: user alice
authorization phase S: +OK
C: pass hungry
 client commands: S: +OK user successfully logged on
 user: declare username
C: list
 pass: password S: 1 498
 server responses S: 2 912
S: .
 +OK
C: retr 1
 -ERR S: <message 1 contents>
transaction phase, client: S: .
C: dele 1
 list: list message numbers C: retr 2
 retr: retrieve message by S: <message 1 contents>
number S: .
C: dele 2
 dele: delete
C: quit
 quit S: +OK POP3 server signing off
2: Application Layer 40

Potrebbero piacerti anche