Data Communication and Networks Lecture 3 Application Protocols

Download Report

Transcript Data Communication and Networks Lecture 3 Application Protocols

Data Communication and
Networks
Lecture 3
Application Protocols
(HTTP, SMTP,FTP)
September 23, 2004
2: Application Layer
1
Some network apps
 E-mail
 Internet telephone
 Web
 Real-time video
 Instant messaging
 Remote login
 P2P file sharing
conference
 Massive parallel
computing
 Multi-user network
games
 Streaming stored
video clips
2: Application Layer
2
Application architectures
 Client-server
 Peer-to-peer (P2P)
 Hybrid of client-server and P2P
2: Application Layer
3
Client-server archicture
server:



always-on host
permanent IP address
server farms for scaling
clients:




communicate with
server
may be intermittently
connected
may have dynamic IP
addresses
do not communicate
directly with each other
2: Application Layer
4
Pure P2P architecture
 no always on server
 arbitrary end systems
directly communicate
 peers are intermittently
connected and change IP
addresses
 example: Gnutella
Highly scalable
But difficult to manage
2: Application Layer
5
Hybrid of client-server and P2P
Napster
File transfer P2P
 File search centralized:

• Peers register content at central server
• Peers query same central server to locate content
Instant messaging
Chatting between two users is P2P
 Presence detection/location centralized:

• User registers its IP address with central server
when it comes online
• User contacts central server to find IP addresses of
buddies
2: Application Layer
6
Addressing processes
 For a process to
receive messages, it
must have an identifier
 A host has a unique32bit IP address
 Q: does the IP address
of the host on which
the process runs
suffice for identifying
the process?
 Answer: No, many
processes can be
running on same host
 Identifier includes
both the IP address
and port numbers
associated with the
process on the host.
 Example port numbers:


HTTP server: 80
Mail server: 25
 More on this later
2: Application Layer
7
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
2: Application Layer
8
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
100% reliable data
transfer
Timing
 some apps (e.g.,
Internet telephony,
interactive games)
require low delay to be
“effective”
Bandwidth
 some apps (e.g.,
multimedia) require
minimum amount of
bandwidth to be
“effective”
 other apps (“elastic
apps”) make use of
whatever bandwidth
they get
2: Application Layer
9
Transport service requirements of common apps
Data loss
Bandwidth
Time Sensitive
file transfer
e-mail
Web documents
real-time audio/video
no loss
no loss
no loss
loss-tolerant
no
no
no
yes, 100’s msec
stored audio/video
interactive games
instant messaging
loss-tolerant
loss-tolerant
no loss
elastic
elastic
elastic
audio: 5kbps-1Mbps
video:10kbps-5Mbps
same as above
few kbps up
elastic
Application
yes, few secs
yes, 100’s msec
yes and no
2: Application Layer
10
Web and HTTP
First some jargon
 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
 Example URL:
www.someschool.edu/someDept/pic.gif
host name
path name
2: Application Layer
11
HTTP overview
HTTP: hypertext
transfer protocol
 Web’s application layer
protocol
 client/server model
 client: browser that
requests, receives,
“displays” Web objects
 server: Web server
sends objects in
response to requests
 HTTP 1.0: RFC 1945
 HTTP 1.1: RFC 2068
PC running
Explorer
Server
running
Apache Web
server
Mac running
Navigator
2: Application Layer
12
HTTP overview (continued)
Uses TCP:
 client initiates TCP
connection (creates socket)
to server, port 80
 server accepts TCP
connection from client
 HTTP messages (applicationlayer protocol messages)
exchanged between browser
(HTTP client) and Web
server (HTTP server)
 TCP connection closed
HTTP is “stateless”
 server maintains no
information about
past client requests
aside
Protocols that maintain
“state” are complex!
 past history (state) must
be maintained
 if server/client crashes,
their views of “state” may
be inconsistent, must be
reconciled
2: Application Layer
13
Stateless vs. Stateful Servers
 Stateful
server remembers something about client
transactions (control block)
 improves efficiency by reducing transport
message size

 Stateless
 server remembers nothing about client
transactions
 useful when transport protocols may unreliable
 servers recover fast from crashes
2: Application Layer
14
Precise description of stateful
server challenge
• Idempotent
– An operation which can be applied multiple times and still
produce the same result
– Formally, operation O is idempotent iff
» O( a ) = O( O( a ) )
• Example
– Idempotent: x = z
– Not idempotent: x = x +z
• In a stateful server
– Request operations must be idempotent, or
– The server must recover from failures
2: Application Layer
15
Comer advice
 If the network is unreliable or machines
can crash then the server should be
stateless
 Do you agree?
2: Application Layer
16
HTTP connections
Nonpersistent HTTP
 At most one object is
sent over a TCP
connection.
 HTTP/1.0 uses
nonpersistent HTTP
Persistent HTTP
 Multiple objects can
be sent over single
TCP connection
between client and
server.
 HTTP/1.1 uses
persistent connections
in default mode
2: Application Layer
17
Nonpersistent 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
(process) at
www.someSchool.edu on port 80
2. HTTP client sends HTTP
request message (containing
URL) into TCP connection
socket. Message indicates
that client wants object
someDepartment/home.index
1b. HTTP server at host
www.someSchool.edu waiting
for TCP connection at port 80.
“accepts” connection, notifying
client
3. HTTP server receives request
message, forms response
message containing requested
object, and sends message
into its socket
time
2: Application Layer
18
Nonpersistent HTTP (cont.)
4. HTTP server closes TCP
5. HTTP client receives response
connection.
message containing html file,
displays html. Parsing html
file, finds 10 referenced jpeg
objects
time 6. Steps 1-5 repeated for each
of 10 jpeg objects
2: Application Layer
19
HTTP 1.1 Persistent Connections
 In previous example, a connection is made
for each request. This is bad. Why?


TCP 3-way hand-shake
TCP slow start
 In http 1.1, persistent connections were
added as default behavior.
 Connection stays open unless client or
server specify close when request
satisfied:

Header = Connection: close
2: Application Layer
20
HTTP 1.1 Pipelining
 Persistent connection improves
performance some, but connection half
session is still under-utilized.
Client sends request, then waits for response
 Server sends response, the waits for new
request

 Pipelining - send next request before
previous response is received.
 Studies show that persistent connections
alone perform poorly. Pipelining improves
performance considerably.
2: Application Layer
21
HTTP request message
 two types of HTTP messages: request, response
 HTTP request message:
 ASCII (human-readable format)
request line
(GET, POST,
HEAD commands)
GET /somedir/page.html HTTP/1.1
Host: www.someschool.edu
User-agent: Mozilla/4.0
header Connection: close
lines Accept-language:fr
Carriage return,
line feed
indicates end
of message
(extra carriage return, line feed)
2: Application Layer
22
HTTP request message: general format
2: Application Layer
23
HTTP Request Methods
 First word in HTTP request is method
 HTTP 1.1 methods are:
 GET
(retrieve a resource)
 HEAD (retrieve info about resource)
 POST (submit an html form)
 PUT
(create/modify resources)
 DELETE (delete a resource)
 TRACE (trace requests in proxy chains)
 OPTIONS (request for settings from proxy or
server)
2: Application Layer
24
HTTP response message
status line
(protocol
status code
status phrase)
header
lines
data, e.g.,
requested
HTML file
HTTP/1.1 200 OK
Connection close
Date: Thu, 06 Aug 1998 12:00:15 GMT
Server: Apache/1.3.0 (Unix)
Last-Modified: Mon, 22 Jun 1998 …...
Content-Length: 6821
Content-Type: text/html
data data data data data ...
2: Application Layer
25
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
26
Trying out HTTP (client side) for yourself
1. Telnet to your favorite Web server:
telnet cis.poly.edu 80
Opens TCP connection to port 80
(default HTTP server port) at cis.poly.edu.
Anything typed in sent
to port 80 at cis.poly.edu
2. Type in a GET HTTP request:
GET /~ross/ HTTP/1.1
Host: cis.poly.edu
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
27
HTTP State Management: Cookies
 We said earlier that HTTP is a stateless protocol
 We also said that stateful protocols can provide
improved performance. This feature is usually
established by the idea of a “session” between
client and server.
 So, how can we get sessions in HTTP?
 COOKIES!
2: Application Layer
28
COOKIES (briefly)
 Cookie protocol - RFC 2109
 A cookie is a token given to a client by a
server.
Server sends Set-cookie: header in response
 Client associates cookie with issuing server
(directory)

 The token is just a file with a simple
format (name/value pairs)
 Each cookie has a unique name
2: Application Layer
29
Client-server interaction: cookies
 server sends “cookie” to
client in response mst
Set-cookie: 1678453
 client presents cookie in
later requests
cookie: 1678453
 server matches
presented-cookie with
server-stored info
 authentication
 remembering user
preferences, previous
choices
server
client
usual http request msg
usual http response +
Set-cookie: #
usual http request msg
cookie: #
usual http response msg
usual http request msg
cookie: #
usual http response msg
cookiespectific
action
cookiespectific
action
2: Application Layer
30
Cookie example
1. User Agent -> Server
POST /acme/login HTTP/1.1
[form data]
User identifies self via a form.
2. Server -> User Agent
HTTP/1.1 200 OK
Set-Cookie: Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"
Cookie reflects user's identity.
3. User Agent -> Server
POST /acme/pickitem HTTP/1.1
Cookie: $Version="1"; Customer="WILE_E_COYOTE"; $Path="/acme"
[form data]
User selects an item for "shopping basket."
2: Application Layer
31
Cookie example (continued)
4. Server -> User Agent
HTTP/1.1 200 OK
Set-Cookie: Part_Number="Rocket_Launcher_0001"; Version="1";
Path="/acme"
Shopping basket contains an item.
5. User Agent -> Server
POST /acme/shipping HTTP/1.1
Cookie: $Version="1";
Customer="WILE_E_COYOTE"; $Path="/acme";
Part_Number="Rocket_Launcher_0001"; $Path="/acme"
[form data]
User selects shipping method from form.
2: Application Layer
32
Cookie example (continued)
6. Server -> User Agent
HTTP/1.1 200 OK
Set-Cookie: Shipping="FedEx"; Version="1"; Path="/acme"
New cookie reflects shipping method.
7. User Agent -> Server
POST /acme/process HTTP/1.1
Cookie: $Version="1";
Customer="WILE_E_COYOTE"; $Path="/acme";
Part_Number="Rocket_Launcher_0001"; $Path="/acme";
Shipping="FedEx"; $Path="/acme"
[form data]
User chooses to process order.
8. Server -> User Agent
HTTP/1.1 200 OK
Transaction is complete.
2: Application Layer
33
FTP: the file transfer protocol
user
at host
FTP
FTP
user
client
interface
file transfer
local file
system
FTP
server
remote file
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
34
FTP: Issues
 Allow transfer of arbitrary files
 Accommodate different file types
 Convert between heterogeneous systems



Data types
Word lengths
Rules for file names
 Provide some security (user login)
 Permit Interactive or Batch Operation
2: Application Layer
35
FTP: separate control, data connections
 ftp client contacts ftp server
at port 21
 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”
TCP control connection
port 21
FTP
client
TCP data connection
port 20
FTP
server
2: Application Layer
36
FTP: Using separate data connections
 Separates commands from data
 Client can send commands during data
transfer
 Closed connection indicates end of file
 Control connection persists, data
connections come and go
2: Application Layer
37
FTP commands
 Sent as ASCII text over control channel





USER username
PASS password
LIST return list of file in current directory
RETR filename retrieves (gets) file
STOR filename stores (puts) file onto remote host
2: Application Layer
38
FTP return codes
 Status code and phrase (as in smtp,
http) returned in ASCII over control
connection
 331
Username OK, password required
 125 data connection already open;
transfer starting
 425 Can’t open data connection
 452 Error writing file
2: Application Layer
39
Example Protocol Interaction
LOCAL COMMANDS BY USER
ftp (host) multics<CR>
username Doe <CR>
password mumble <CR>
retrieve (local type) ASCII<CR>
(local pathname) test 1 <CR>
(for. pathname) test.pl1<CR>
type Image<CR>
store (local type) image<CR>
(local pathname) file dump<CR>
for.pathname) >udd>cn>fd<CR>
terminate
ACTION INVOLVED
Connect to host S, port L,
establishing control connections.
<---- 220 Service ready <CRLF>.
USER Doe<CRLF>---->
<---- 331 User name ok,
need password<CRLF>.
PASS mumble<CRLF>---->
<---- 230 User logged in<CRLF>.
User-FTP opens local file in ASCII.
RETR test.pl1<CRLF> ---->
<---- 150 File status okay;
about to open data
connection<CRLF>.
Server makes data connection
to port U.
<---- 226 Closing data connection,
file transfer successful<CRLF>.
TYPE I<CRLF> ---->
<---- 200 Command OK<CRLF>
User-FTP opens local file in Image.
STOR >udd>cn>fd<CRLF> ---->
<---- 550 Access denied<CRLF>
QUIT <CRLF> ---->
Server closes all
connections.
2: Application Layer
40
Electronic Mail
outgoing
message queue
user mailbox
user
agent
Three major components:
 user agents
 mail servers
mail
server
SMTP
 simple mail transfer
protocol: SMTP
User Agent
 a.k.a. “mail reader”
 composing, editing, reading
mail messages
 e.g., Eudora, Outlook, elm,
Netscape Messenger
 outgoing, incoming messages
stored on server
SMTP
mail
server
user
agent
SMTP
user
agent
mail
server
user
agent
user
agent
user
agent
2: Application Layer
41
Electronic Mail: mail servers
user
agent
Mail Servers
 mailbox contains incoming
messages for user
 message queue of outgoing
(to be sent) mail messages
 SMTP protocol between mail
servers to send email
messages
 client: sending mail
server
 “server”: receiving mail
server
mail
server
SMTP
SMTP
mail
server
user
agent
SMTP
user
agent
mail
server
user
agent
user
agent
user
agent
2: Application Layer
42
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
 commands: ASCII text
 response: status code and phrase
 messages must be in 7-bit ASCII
2: Application Layer
43
Scenario: Alice sends message to Bob
1) Alice uses UA to compose
message and “to”
[email protected]
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
1
user
agent
2
mail
server
3
4) SMTP client sends Alice’s
message over the TCP
connection
5) Bob’s mail server places the
message in Bob’s mailbox
6) Bob invokes his user agent
to read message
mail
server
4
5
6
user
agent
2: Application Layer
44
Sample SMTP interaction
S:
C:
S:
C:
S:
C:
S:
C:
S:
C:
C:
C:
S:
C:
S:
220 hamburger.edu
HELO crepes.fr
250 Hello crepes.fr, pleased to meet you
MAIL FROM: <[email protected]>
250 [email protected]... Sender ok
RCPT TO: <[email protected]>
250 [email protected] ... Recipient ok
DATA
354 Enter mail, end with "." on a line by itself
Do you like ketchup?
How about pickles?
.
250 Message accepted for delivery
QUIT
221 hamburger.edu closing connection
2: Application Layer
45
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
46
SMTP: final words
 SMTP uses persistent
connections
 SMTP requires message
(header & body) to be in 7bit ASCII
 SMTP server uses
CRLF.CRLF to determine
end of message
Comparison with HTTP:
 HTTP: pull
 SMTP: push
 both have ASCII
command/response
interaction, status codes
 HTTP: each object
encapsulated in its own
response msg
 SMTP: multiple objects
sent in multipart msg
2: Application Layer
47
Mail message format
SMTP: protocol for
exchanging email msgs
RFC 822: standard for text
message format:
 header lines, e.g.,
To:
 From:
 Subject:
different from SMTP
commands!

header
blank
line
body
 body

the “message”, ASCII
characters only
2: Application Layer
48
Message format: multimedia extensions
 MIME: multipart Internet mail extension, RFC 2045, 2056
 additional lines in msg header declare MIME content type
MIME version
method used
to encode data
multimedia data
type, subtype,
parameter declaration
encoded data
From: [email protected]
To: [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
2: Application Layer
49
MIME types
Text : plain, html
Image: jpeg, gif
Audio: basic, 32kadpcm
Video: mpeg, quicktime
Application: other data that must be processed by
reader before “viewable”. Example subtypes:
msword, octet-stream.
Multipart: used when sending objects of different
types
2: Application Layer
50
Multipart Type
 Multipart separation
 boundary="------------C725BD4EC548463C“
 Potentially recursive
 Each part described by a MIME type
2: Application Layer
51
Multipart Example
From: [email protected]
To: [email protected]
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
52
What is base64 you ask?
 Problem: how to send binary data?
 Base64 is hashing method to map 8 bit to 6 bit
codes that define a subset of the ASCII
Character space.
 Convert each 24 bits to four 6 bit codes, pad
trailing bits with 0’s.
 Use 6 bit code to index table for mapped ASCII
character
 Note: base64 map table does not include CRLF or
other RFC822 special characters (or =, which is a
base64 pad character.
2: Application Layer
53
Mail access protocols
user
agent
SMTP
SMTP
sender’s mail
server
access
protocol
user
agent
receiver’s mail
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
54
POP3 protocol
authorization phase
 client commands:
user: declare username
 pass: password
 server responses
 +OK
 -ERR

transaction phase, client:
 list: list message numbers
 retr: retrieve message by
number
 dele: delete
 quit
S:
C:
S:
C:
S:
+OK POP3 server ready
user bob
+OK
pass hungry
+OK user successfully logged
C:
S:
S:
S:
C:
S:
S:
C:
C:
S:
S:
C:
C:
S:
list
1 498
2 912
.
retr 1
<message 1 contents>
.
dele 1
retr 2
<message 1 contents>
.
dele 2
quit
+OK POP3 server signing off
2: Application Layer
on
55
POP3 (more) and IMAP
More about POP3
 Previous example uses
“download and delete”
mode.
 Bob cannot re-read email if he changes
client
 “Download-and-keep”:
copies of messages on
different clients
 POP3 is stateless
across sessions
IMAP
 Keep all messages in
one place: the server
 Allows user to
organize messages in
folders
 IMAP keeps user state
across sessions:

names of folders and
mappings between
message IDs and folder
name
2: Application Layer
56