2011-03-5 chapter 2 - application layer
TRANSCRIPT
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
1/108
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
2/108
Application LayerOur goals:
conceptual,implementation
aspects of networkapplication protocols
transport-layerservice models
client-serverparadigm
peer-to-peer paradigm
learn about protocols byexamining popularapplication-level
protocols HTTP
FTP
SMTP / POP3 / IMAP
DNS programming network
applications socket API
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
3/108
Chapter 2: outline 2.1 Principles of app layer
protocols clients and servers
app requirements
2.2 Web and HTTP
2.3 FTP
2.4 Electronic Mail SMTP, POP3, IMAP
2.5 DNS
2.6 Socket programmingwith TCP
2.7 Socket programmingwith UDP
2.8 Building a Web server
2.9 Content distribution Network Web caching
Content distributionnetworks
P2P file sharing
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
4/108
Principles of App layer protocolsClients and servers
Protocols support remote access
Software is distributed among two or more systemsApplication software
Electronic mail (sendmail, qmail, )
Web (apache, tomcat, )
File transfer (vsftpd, Serv-U, )Remote access to computer (telnet, ssh, )
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
5/108
Network application: terminologiesProcess: program running
within a host.
within same host, two
processes communicateusing interprocesscommunication (definedby OS).
processes running indifferent hostscommunicate with anapplication-layer protocol
user agent: interfaces withuser above and networkbelow.
implements userinterface & application-level protocol Web: browser
E-mail: mail reader streaming audio/video:
media player
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
6/108
Application and application layer protocolsApplication: communicating,
distributed processes e.g., e-mail, Web, P2P file
sharing, instant messaging
running in end systems(hosts)
exchange messages toimplement application
Application-layer protocols one piece of an app
define messages exchanged byapps and actions taken
use communication servicesprovided by lower layer
protocols (TCP, UDP)
applicationtransportnetworkdata linkphysical
applicationtransportnetworkdata linkphysical
applicationtransportnetworkdata linkphysical
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
7/108
Application layer protocols 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 forinteroperability
eg, HTTP, SMTP
Proprietary protocols:
eg, KaZaA
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
8/108
Clients Servers paradigm
Client:
initiates contact with server(speaks first) typically requests service from
server, Web: client implemented in
browser; e-mail: in mail reader
Server:
provides requested service to client e.g., Web server sends requested Web
page, mail server delivers e-mail
Typically has two parts or sidesClient side and server side
applicationtransportnetworkdata linkphysical
applicationtransportnetworkdata linkphysical
request
reply
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
9/108
Processes Communicating across network
process
TCP with
buffers,
variables
socket
host or
server
process
TCP with
buffers,
variables
socket
host or
server
Internet
controlled
by OS
controlled by
app developer
API: (1) choice of transport protocol; (2) ability to fix a few parameters (lotsmore on this later)
process sends/receivesmessages to/from its socket
socket analogous to door sending process shoves
message out door
sending process asssumestransport infrastructure onother side of door whichbrings message to socket atreceiving process
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
10/108
Addressing processesTo send a message from host A to host B, the sending
prosess must identify the receiving process The name or address of the host machine
The port number for receiving process on destination host Identify both of IP address and port number associated
with the process on the host Every host has a unique 32-bit IP address
Port number serves for the purpose in the InternetEx:HTTP server: 80
Mail Server: 25
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
11/108
User AgentsThe interface between user and network application
Ex: the web application is running on Web server, user
uses browser (Netscape, Internet Explorer, Firefox, )Navigate in the web
view web pages
Web scripts (java scripts, perl script, )
Interact with the web server (input to forms, send email,receive email, )
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
12/108
What services does an Application Need?
Data loss
some apps (e.g., audio) cantolerate some loss
other apps (e.g., file transfer,telnet) require 100% reliabledata transfer
Timing some apps are real-time
apps (e.g., Internettelephony, interactivegames) require low delay
to be effective
Bandwidth
some apps (e.g.,multimedia , Inter nettelephony) requireminimum amount of
bandwidth to beeffective
other apps (elasticapps) make use of
whatever bandwidth theyget
Network applications may need from a transport protocol, services:
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
13/108
Transport service requirements of
common apps
Application
file transfere-mail
Web documents
real-time audio/video
stored audio/video
interactive games
instant messaging
Data loss
no lossno loss
no loss
loss-tolerant
loss-tolerant
loss-tolerant
no loss
Bandwidth
elasticelastic
elastic
audio: 5kbps-1Mbps
video:10kbps-5Mbps
same as above
few kbps up
elastic
Time Sensitive
nono
no
yes, 100s msec
yes, few secs
yes, 100s msecyes and no
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
14/108
Internet Transport Protocol Services
TCP service: connection-oriented: setup
required between client andserver processes
reliable transport betweensending and receiving process,guarantees delivery of all data.
flow control:sender wontoverwhelm receiver
congestion control: throttlesender when network overloaded
does not providing: timing,minimum bandwidth guarantees
UDP service: unreliable data transfer
between sending andreceiving process
does not provide: connectionsetup, reliability, flowcontrol, congestion control,timing, or bandwidthguarantee
Q: why bother? Why is there aUDP? (be faster withoutacknowledgements andretransmissions real-timeapplications)
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
15/108
Internet apps: applications,
transport protocols
Application
e-mailremote terminal access
Web
file transfer
streaming multimedia
Internet telephony
Application
layer protocol
SMTP [RFC 2821]Telnet [RFC 854]
HTTP [RFC 2616]
FTP [RFC 959]
proprietary
(e.g. RealNetworks)proprietary
(e.g., Dialpad)
Underlying
transport protocol
TCPTCP
TCP
TCP
TCP or UDP
typically UDP
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
16/108
Network Apps covered in this
chapterFocus on a number of important and popular
applications:
The Web
File Tranfers
Electronic mail
Directory service (Domain Name System DNS)
Invoke through other application indirectly
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
17/108
Chapter 2: Outline 2.1 Principles of app layer
protocols
clients and servers app requirements
2.2 Web and HTTP
2.3 FTP
2.4 Electronic Mail SMTP, POP3, IMAP
2.5 DNS
2.6 Socket programmingwith TCP
2.7 Socket programmingwith UDP
2.8 Building a Web server
2.9 Content distribution Network Web caching
Content distributionnetworks
P2P file sharing
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
18/108
Introduction In the 1980s, the Internet was used by researchers,
academics and university students (academic and researchcommunities only) Login to remote host Transfer files from local to remote hosts, vice versa Send, and receive news or electronic email.
In the 1990s, the World Wide Web arrived on the scence,the Web an Internet application
Everyone can become a publisherDisplay graphics and animated graphicsAudio and video materials can be access on demand
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
19/108
Web and HTTPSome Terminologies
Web pages consists ofobjects
Objects can be HTML files, JPEG file, Java applet, audiofile, video file,
Web page consists of a base HTML file and severalreference objects
Each object has addressed by a URL (Uniform ResourceLocator)
www.someschool.edu/someDept/pic.gif
host namepath name
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
20/108
Overview of HTTPHTTP: hypertext transferprotocol
Webs application layer
protocol client/server model
client: browser thatrequests, receives,displays Web objects
server: Web server sendsobjects in response torequests
PC runningExplorer
Serverrunning
Apache Webserver
Mac runningNavigator
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
21/108
HTTP Overview (cont.)HTTP definesHow web client (browsers) request web pages from
server (Web servers)
How the server transfer Web pages to clientsHTTP/1.0 [RFC 1945] in 1997
HTTP/1.1 [RFC 2068] in 1998
Both HTTP/1.0 and HTTP/1.1 use TCP as transport
protocolDefine communication protocols between
HTTP client program
HTTP server program
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
22/108
HTTP Overview (Cont.)Uses TCP: 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 Web server(HTTP server)
TCP connection closed
Protocols that maintain stateare complex!
past history (state) must be
maintained if server/client crashes, theirviews of state may beinconsistent, must bereconciled
aside
HTTP is stateless protocols Without storing any state
information about past client
requests
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
23/108
HTTP ConnectionsNon-persistent HTTP
At most one object is
sent over a TCPconnection.
HTTP/1.0 is default modeof non-persistent HTTP
Persistent HTTP
Multiple objects can besent over single TCPconnection betweenclient and server.
HTTP/1.1 uses persistentconnections in default
mode
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
24/108
Non-Persistent HTTPSuppose user enters URL www.someSchool.edu/someDepartment/home.index
(contains text,
references to 10
jpeg images)
1a. HTTP client initiates TCPconnection to HTTP server(process) at www.someSchool.edu
on port 80
2. HTTP client sends HTTP requestmessage (containing URL) intoTCP connection socket. Messageindicates that client wants objectsomeDepartment/home.index
1b. HTTP server at hostwww.someSchool.edu
waitingfor TCP connection at port 80.accepts connection, notifyingclient
3. HTTP server receives requestmessage, retrieves the requestedobjects from its storage, formsresponse message (encapsulate srequested objects in a HTTPresponse message, and sends
message into its socket
time
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
25/108
Non-Persistent HTTP (Cont.)
5. HTTP client receives responsemessage containing html file,extract file from responsemessage , and then displays html.Parsing html file, finds 10referenced jpeg objects
6.Steps 1-5 repeated for each of 10jpeg objects
4. HTTP server closes TCPconnection after flush out
response message to client.
time
In this example, when a user requests theWeb page, there are 1 text , and 10 referenceimages, hence, 11 TCP connections are
generated. 1 text over 1 TCP connection 10 images over ten serial TCP connections
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
26/108
Response Time ModelingRound-Trip Time (RTT):Time to send a small
packet to travel from clientto server and back.
Response time:one RTT to initiate TCP
connectionone RTT for HTTP request
and first few bytes ofHTTP response to return
file transmission timetotal = 2RTT+transmit time
time to
transmit
file
initiate TCP
connection
RTT
request
file
RTT
file
received
time time
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
27/108
Persistent HTTPNonpersistent HTTP issues: requires 2 RTTs per object
OS must work and allocate hostresources for each TCP
connection but browsers often open
parallel TCP connections tofetch referenced objects
Persistent HTTP
server leaves connection openafter sending response
subsequent HTTP messagesbetween same client/server aresent over single connection
Persistent without pipelining:
client issues new request onlywhen previous response hasbeen received
one RTT for each referencedobject
Persistent with pipelining:
default in HTTP/1.1
client sends requests as soonas it encounters a referencedobject
as little as one RTT for all thereferenced objects
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
28/108
HTTP message formats two types of HTTP messages: request, response
HTTP request message:ASCII (human-readable format)
GET /somedir/page.html HTTP/1.1
Host: www.someschool.edu
User-agent: Mozilla/4.0
Connection: close
Accept: text/html, image/gif, image/jpegAccept-language:fr
(extra carriage return, line feed)
request line(GET, POST,HEAD commands)
headerlines
Carriage return,line feed
indicates endof message
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
29/108
HTTP request message: general format
Method: POST
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
30/108
Uploading form inputPost method:Web page often includes
form input
Input is uploaded toserver in entity body
URL method:
Uses GET method
Input is uploaded in URLfield of request line:
www.somesite.com/animalsearch?monkeys&banana
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
31/108
Method TypesHTTP/1.0
GET
POST
HEAD asks server to leave
requested object out of
response
HTTP/1.1
GET, POST, HEAD
PUT uploads file in entity body
to path specified in URLfield
DELETE deletes file specified in the
URL field
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
32/108
HTTP Response Message
HTTP/1.1 200 OK
Connection closeDate: 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 ...
status line(protocol
status code
status phrase)
headerlines
data, e.g.,requestedHTML file
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
33/108
HTTP Response Status Code200 OK
request succeeded, requested object later in this message
301 Moved Permanently
requested object moved, new location specified later in thismessage (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:
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
34/108
HTTP response message: general format
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
35/108
Trying out HTTP request with Telnet1. Telnet to your favorite Web server:
telnet 10.33.6.10 80
2. Type in a GET HTTP request:
GET index.html HTTP/1.0 By typing this in (hit carriage
return twice), you sendthis minimal (but complete)GET request to HTTP server
3. Look at response message sent by HTTP server!
Opens TCP connection to port 80(default HTTP server port) at 10.33.6.10Anything typed in sent
to port 80 at 10.33.6.10
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
36/108
HTTP Response message
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
37/108
User-Server Interaction: AuthorizationAuthorization : control access to
server content
authorization credentials:
typically name, password stateless: client must present
authorization in each request
authorization: header line ineach request
if no authorization: header,server refuses access, sends
WWW authenticate:
header line in response
client server
usual http request msg
401: Authorization required.
WWW-Authenticate: header
Authorization: username &
password
usual http response msg
usual http request msg+ Authorization:
usual http response msg
time
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
38/108
Cookies: keeping stateMany major Web sites use
cookies
Four components:1) cookie header line in the
HTTP response message
2) cookie header line inHTTP request message
3) cookie file kept on usershost and managed byusers browser
4) back-end database at Website
Example: Susan access Internet
always from same PC
She visits a specific e-commerce site for firsttime
When initial HTTPrequests arrives at site, site
creates a unique ID andcreates an entry in backenddatabase for ID
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
39/108
Cookies (cont.)client server
usual http request msg
usual http response +
Set-cookie: 1678
usual http request msgcookie: 1678
usual http response msg
usual http request msgcookie: 1678
usual http response msg
cookie-specificaction
cookie-spectificaction
servercreates ID
1678 for user
Cookie file
amazon: 1678
ebay: 8734
Cookie file
ebay: 8734
Cookie file
amazon: 1678
ebay: 8734
one week later:
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
40/108
Cookies (Cont.)What cookies can bring:
authorization
shopping carts recommendations
user session state (Webe-mail)
Cookies and privacy: cookies permit sites to learn a lot
about you
you may supply name and e-mailto sites search engines use redirection &
cookies to learn yet more advertising companies obtain info
across sites
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
41/108
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
42/108
Web cache: Example
Browser requests an uncached object from Web sever
Web server sends a response message with object to client
GET /fruit/kiwi.gif HTTP/1.0
User-agent: Mozilla/4.0Accept: text/html, image/gif, image/jpeg
HTTP/1.0 200 OKDate: Wed, 12 Aug 1998 15:39:29Server: Apache/1.3.0 (Unix)Last-Modified: Mon, 22 Jun 1998 09:23:24Content-Type: image/gifdata data data data data ...
Last-modified datealong with the object
Client saves object inlocal cache.
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
43/108
Web cache: ExampleOne week later, user requests the same object is still in cacheGET /fruit/kiwi.gif HTTP/1.0User-agent: Mozilla/4.0
Accept: text/html, image/gif, image/jpegIf-modified-since: Mon, 22 Jun 1998 09:23:24
If-modified-since = Last-Modified
Conditional GET is enable, and Web server only send the
objects which has been modified since specified dateHTTP/1.0 304 Not ModifiedDate: Wed, 19 Aug 1998 15:39:29Server: Apache/1.3.0 (Unix)(empty entity body)
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
44/108
Chapter 2: outline2.1 Principles of app layer
protocols clients and servers
app requirements
2.2 Web and HTTP
2.3 FTP
2.4 Electronic Mail SMTP, POP3, IMAP
2.5 DNS
2.6 Socket programmingwith TCP
2.7 Socket programmingwith UDP
2.8 Building a Web server
2.9 Content distribution Network Web caching
Content distributionnetworks
P2P file sharing
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
45/108
FTP: File Transfer Protocolfile transfer
FTPserver
FTPuser
interface
FTPclient
local filesystem
remote filesystem
userat host
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
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
46/108
FTP: separate control, data connections FTP client contacts FTP server at
port 21, specifying TCP astransport protocol
Client obtains authorization over
control connection
Client browses remote directoryby sending commands overcontrol connection.
When server receives acommand for a file transfer, theserver opens a TCP dataconnection to client
After transferring one file, servercloses connection.
Server opens a second TCP dataconnection to transfer anotherfile.
Control connection: out ofband
FTP server maintains state:current directory, earlierauthentication
FTPclient FTPserver
TCP control connectionport 21
TCP data connection
port 20
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
47/108
FTP commands, responsesSample return codes status code and phrase (as in
HTTP)
331 Username OK,password required
125 data connection
already open;
transfer starting
425 Cant open dataconnection
452 Error writing
file
Sample commands: sent as ASCII text over control
channel
USERusername
PASS password
LISTreturn list of file incurrent directory
RETR filenameretrieves(gets) file
STOR filenamestores(puts) file onto remote host
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
48/108
FTP: Example
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
49/108
Electronic MailThree 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., Eudora, Outlook, elm,
Netscape Messenger
outgoing, incoming messagesstored on server
user mailbox
outgoingmessage queue
mailserver
useragent
useragent
user
agentmail
server
useragent
useragent
mailserver
useragent
SMTP
SMTP
SMTP
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
50/108
Mail Server
mailserver
useragent
useragent
useragent
mail
server
useragent
useragent
mailserver
useragent
SMTP
SMTP
SMTP
Mail Servers mailbox contains incoming
messages for user
messagequeue of outgoing (tobe sent) mail messages
SMTP protocol between mailservers to send email messages
client: sending mail server
server: receiving mailserver
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
51/108
SMTP [RFC 5321]Simple Mail Transfer Protocol: Internet standard for
electronic mail (e-mail)
RFC 821 first defined
RFC 2821 updated in 2001
RFC 5321 last updated in 2008
Include extended SMTP (ESMTP)
Transmission across Internet Protocol (IP)Using TCP port 25
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
52/108
RFC 5321 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
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
53/108
ASCII Code
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
54/108
Example1) Alice uses UA to compose messageand to [email protected]
2) Alices UA sends message to hermail server; message placed inmessage queue
3) Client side of SMTP opens TCPconnection with Bobs mail server
4) SMTP client sends Alicesmessage over the TCPconnection
5) Bobs mail server places the
message in Bobs mailbox
6) Bob invokes his user agent toread message
useragent
mailserver
mailserver user
agent
1
2 3 4 56
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
55/108
Example
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
56/108
SMTP: final word SMTP uses persistent
connections
SMTP requires message(header & body) to be in 7-bit
ASCII
SMTP server uses CRLF.CRLFto determine end of message
Comparison with HTTP:
HTTP: pull
SMTP: push
both have ASCIIcommand/responseinteraction, status codes
HTTP: each object
encapsulated in its ownresponse msg
SMTP: multiple objects sent inmultipart msg
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
57/108
Mail Message FormatSMTP: protocol for exchangingemail msgs
RFC 822: standard for textmessage format:
header lines, e.g.,
To:
From:
Subject:
differentfrom SMTP commands! body
the message, ASCIIcharacters only
header
body
blankline
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
58/108
MIME Extension for Non-ASCII Data MIME: multimedia mail extension, RFC 2045, 2056
additional lines in msg header declare MIME content type
From: [email protected]: [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
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
59/108
MIME Types
Content-Type: type/subtype; parametersText example subtypes:plain,html
Image example subtypes: jpeg,gif
Audio exampe subtypes:basic (8-
bit mu-law encoded),32kadpcm(32 kbps coding)
Video example subtypes:mpeg,quicktime
Application other data that must be
processed by reader beforeviewable
example subtypes:msword,octet-stream
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
60/108
Multipart TypeFrom: [email protected]
Subject: Picture of yummy crepe.
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=StartOfNextPart
--StartOfNextPart
Dear Bob, Please find a picture of a crepe.
--StartOfNextPart
Content-Transfer-Encoding: base64
Content-Type: image/jpeg
base64 encoded data ..............................
......base64 encoded data
--StartOfNextPart
Do you want the reciple?
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
61/108
Mail access protocol
useragent
senders mail
server
useragent
SMTP SMTP accessprotocol
receivers mail
server
SMTP: delivery/storage to receivers 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.
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
62/108
POP3 Protocolauthorization phase client commands:
user: declare username
pass: password
server responses +OK
-ERR
transaction phase, client: list: list message numbers
retr: retrieve message bynumber
dele: delete
quit
S: +OK POP3 server ready
C: user bobS: +OK
C: pass hungry
S: +OKuser successfully logged on
C: list
S: 1 498
S: 2 912S: .
C: retr 1
S:
S: .
C: dele 1
C: retr 2
S:
S: .
C: dele 2
C: quit
S: +OKPOP3 server signing off
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
63/108
POP3 more and IMAPMore about POP3Previous example uses
download and delete
mode.Bob cannot re-read e-
mail if he changes client
Download-and-keep:
copies of messages ondifferent clients
POP3 is stateless acrosssessions
IMAP
Keep all messages in oneplace: the server
Allows user to organizemessages in folders
IMAP keeps user stateacross sessions:
names of folders andmappings betweenmessage IDs and foldername
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
64/108
Chapter 2: Outline2.1 Principles of app layer
protocols clients and servers
app requirements
2.2 Web and HTTP
2.3 FTP
2.4 Electronic Mail SMTP, POP3, IMAP
2.5 DNS
2.6 Socket programmingwith TCP
2.7 Socket programming
with UDP 2.8 Building a Web server
2.9 Content distribution Network Web caching
Content distributionnetworks
P2P file sharing
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
65/108
DNS (Domain Name System)People: many identifiers:
SSN, name, passport #
Internet hosts, routers: IP address (32 bit) - used
for addressing datagrams
name, e.g.,gaia.cs.umass.edu - used
by humansQ: map between IP
addresses and name ?
Domain Name System: distributed database
implemented in hierarchy of
manyname servers application-layer protocolhost,
routers, name servers tocommunicate to resolvenames(address/name translation)
note: core Internet function,implemented as application-layer protocol
complexity at networks edge
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
66/108
DNS name serversWhy not centralize DNS? single point of failure
traffic volume
distant centralized database
maintenance
doesnt scale!
no server has all name-to-IPaddress mappings
local name servers:
each ISP, company has local(default) name server
host DNS query first goes tolocal name server
authoritative name server:
for a host: stores that hosts IPaddress, name
can perform name/addresstranslation for that hostsname
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
67/108
DNS: 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
b USC-ISI Marina del Rey, CA
l ICANN Marina del Rey, CA
e NASA Mt View, CA
f Internet Software C. Palo Alto,CA
i NORDUnet Stockholm
k RIPE London
m WIDE Tokyo
a NSI Herndon, VA
c PSInet Herndon, VA
d U Maryland College Park, MD
g DISA Vienna, VA
h ARL Aberdeen, MDj NSI (TBD) Herndon, VA
13 root name serversworldwide
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
68/108
Simple DNS Example
requesting hostsurf.eurecom.fr gaia.cs.umass.edu
root name server
local name serverdns.eurecom.fr
1
23
4
5
6
host surf.eurecom.frwants IP address ofgaia.cs.umass.edu
1. contacts its local DNS server,dns.eurecom.fr
2.dns.eurecom.fr contactsroot name server, if necessary
3. root name server contactsauthoritative name server,dns.umass.edu, ifnecessary
authorititive name serverdns.umass.edu
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
69/108
DNS Example
requesting hostsurf.eurecom.fr
gaia.cs.umass.edu
root name server
local name serverdns.eurecom.fr
1
23
4 5
6
authoritative name serverdns.cs.umass.edu
intermediate name serverdns.umass.edu
7
8
Root name server: may not know
authoritative nameserver
may know intermediatename server: who tocontact to findauthoritative nameserver
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
70/108
DNS: iterated query
requesting hostsurf.eurecom.fr
gaia.cs.umass.edu
root name server
local name serverdns.eurecom.fr
1
23
4
5 6
authoritative name serverdns.cs.umass.edu
intermediate name serverdns.umass.edu
7
8
iterated queryrecursive query: puts burden of name
resolution on contacted
name server heavy load?
iterated query: contacted server replies
with name of server tocontact
I dont know this name,but ask this server
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
71/108
DNS: caching and updating recordsonce (any) name server learns mapping, it caches
mapping
cache entries timeout (disappear) after some time
update/notify mechanisms under design by IETF RFC 2136
http://www.ietf.org/html.charters/dnsind-charter.html
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
72/108
DNS recordsDNS: distributed db storing resource records (RR)
Type=NS name is domain (e.g.
foo.com)
value is IP address ofauthoritative name server forthis domain
RR format: (name, value, type, ttl)
Type=A name is hostname value is IP address
Type=CNAME name is alias name for some
cannonical (the real) namewww.ibm.com is reallyservereast.backup2.ibm.com
value is cannonical name
Type=MX value is name of mailserver
associated with name
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
73/108
DNS protocol, messagesDNS protocol :queryand reply messages, both with same message format
msg header
identification: 16 bit # forquery, reply to query usessame #
flags: query or reply
recursion desired recursion available reply is authoritative
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
74/108
DNS protocol, messagesName, type fields
for a query
RRs in reponseto query
records for
authoritative servers
additional helpfulinfo that may be used
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
75/108
Chapter 2: Outline2.1 Principles of app layerprotocols clients and servers
app requirements
2.2 Web and HTTP
2.3 FTP
2.4 Electronic Mail
SMTP, POP3, IMAP2.5 DNS
2.6 Socket programmingwith TCP
2.7 Socket programming
with UDP 2.8 Building a Web server
2.9 Content distribution Network Web caching
Content distributionnetworks
P2P file sharing
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
76/108
Socket Programming
Socket API
introduced in BSD4.1 UNIX,1981
explicitly created, used,released by apps
client/server paradigm
two types of transport servicevia socket API: unreliable datagram
reliable, byte stream-oriented
a host-local,application-created,
OS-controlledinterface (adoor) into which
application process canboth send and
receive messages to/fromanother application process
socket
Goal: learn how to build client/server application that communicate usingsockets
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
77/108
Socket-programming using TCP
process
TCP with
buffers,variables
socket
controlled byapplication
developer
controlled by
operatingsystem
host orserver
process
TCP with
buffers,variables
socket
controlled byapplicationdeveloper
controlled byoperatingsystem
host orserver
internet
Socket: a door between application process and end-end-transport protocol (UCP or TCP)
TCP service: reliable transfer ofbytesfrom one process toanother
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
78/108
Socket Programming with TCPClient must contact server server process must first be
running
server must have created
socket (door) that welcomesclients contact
Client contacts server by:
creating client-local TCPsocket
specifying IP address, portnumber of server process
When client creates socket:client TCP establishesconnection to server TCP
When contacted by client,server TCP creates new socketfor server process tocommunicate with client
allows server to talk withmultiple clients
source port numbers used todistinguish clients (more inChap 3)
TCP provides reliable, in-ordertransfer of bytes (pipe)between client and server
application viewpoint
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
79/108
Stream typesAstream is a sequence of characters that flow intoor out of a process.
An input stream is attached to some input sourcefor the process, eg, keyboard or socket.
An output stream is attached to an output source,eg, monitor or socket.
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
80/108
Socket programming with TCPExample client-server app:1) client reads line from standard
input (inFromUser stream) ,
sends to server via socket(outToServer stream)
2) server reads line from socket
3) server converts line to uppercase,sends back to client
4) client reads, prints modified linefrom socket (inFromServerstream) o
utToServe
r
to network from network
inFromServer
inFromUser
keyboard monitor
Process
clientSocket
input
stream
input
stream
output
stream
TCP
socket
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
81/108
Client/server socket interaction: TCP
wait for incoming
connection requestconnectionSocket =
welcomeSocket.accept()
create socket,port=x, for
incoming request:welcomeSocket =
ServerSocket()
create socket,connect to hostid, port=xclientSocket =
Socket()
close
connectionSocket
read reply from
clientSocket
close
clientSocket
Server (running on hostid) Client
send request using
clientSocketread request from
connectionSocket
write reply to
connectionSocket
TCPconnection setup
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
82/108
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
83/108
Example: Java ClientBufferedReader inFromServer =new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));
sentence = inFromUser.readLine();
outToServer.writeBytes(sentence + '\n');
modifiedSentence = inFromServer.readLine();
System.out.println("FROM SERVER: " + modifiedSentence);
clientSocket.close();
}
}
Createinput stream
attached to socket
Send lineto server
Read linefrom server
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
84/108
Example: Java Server (TCP)import java.io.*;import java.net.*;class TCPServer {
public static void main(String argv[]) throws Exception
{String clientSentence;
String capitalizedSentence;
ServerSocket welcomeSocket = new ServerSocket(6789);
while(true) {
Socket connectionSocket = welcomeSocket.accept();
BufferedReader inFromClient =
new BufferedReader(new
InputStreamReader(connectionSocket.getInputStream()));
Createwelcoming socket
at port 6789
Wait, on welcomingsocket for contactby client
Create inputstream, attached
to socket
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
85/108
Example: Java Server (TCP)
Read in linefrom socket
Create outputstream, attached
to socket
Write out lineto socket
End of while loop,loop back and wait foranother client connection
DataOutputStream outToClient =
new DataOutputStream(connectionSocket.getOutputStream());
clientSentence = inFromClient.readLine();
capitalizedSentence = clientSentence.toUpperCase() + '\n';
outToClient.writeBytes(capitalizedSentence);
}
}
}
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
86/108
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
87/108
Socket programming with UDPUDP: no connection betweenclient and server
no handshaking
sender explicitly attaches IPaddress and port ofdestination to each packet
server must extract IP address,port of sender from receivedpacket
UDP: transmitted data may bereceived out of order, or lost
application viewpointUDP provides unreliable transferof groups of bytes (datagrams)
between client and server
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
88/108
Client/server socket interaction: UDP
close
clientSocket
Server (running on hostid)
read reply from
clientSocket
create socket,clientSocket =
DatagramSocket()
Client
Create, address (hostid, port=x,
send datagram request
using clientSocket
create socket,port=x, for
incoming request:serverSocket =
DatagramSocket()
read request from
serverSocket
write reply to
serverSocket
specifying client
host address,
port number
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
89/108
Example: Java client (UDP)
sendPacket
to network from network
receive
Packet
inFromUser
keyboard monitor
Process
clientSocket
UDP
packet
input
stream
UDP
packet
UDP
socket
Output: sendspacket (TCP sent
byte stream)
Input: receivespacket (TCPreceived bytestream)
Clientprocess
client UDPsocket
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
90/108
Example: Java client (UDP)import java.io.*;import java.net.*;
class UDPClient {
public static void main(String args[]) throws Exception
{
BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in));
DatagramSocket clientSocket = new DatagramSocket();
InetAddress IPAddress = InetAddress.getByName("hostname");
byte[] sendData = new byte[1024];
byte[] receiveData = new byte[1024];
String sentence = inFromUser.readLine();
sendData = sentence.getBytes();
Createinput stream
Createclient socket
Translatehostname to IPaddress using DNS
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
91/108
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
92/108
Example: Java Server (UDP)import java.io.*;import java.net.*;
class UDPServer {
public static void main(String args[]) throws Exception
{
DatagramSocket serverSocket = new DatagramSocket(9876);
byte[] receiveData = new byte[1024];
byte[] sendData = new byte[1024];
while(true){
DatagramPacket receivePacket =
new DatagramPacket(receiveData, receiveData.length);
serverSocket.receive(receivePacket);
Createdatagram socket
at port 9876
Create space forreceived datagram
Receive
datagram
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
93/108
Example: Java Server (UDP) cont.String sentence = new String(receivePacket.getData());
InetAddress IPAddress = receivePacket.getAddress();
int port = receivePacket.getPort();
String capitalizedSentence = sentence.toUpperCase();
sendData = capitalizedSentence.getBytes();
DatagramPacket sendPacket =
new DatagramPacket(sendData, sendData.length, IPAddress,
port);
serverSocket.send(sendPacket);
}
}
}
Get IP addrport #, of
sender
Write outdatagramto socket
End of while loop,loop back and wait foranother datagram
Create datagramto send to client
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
94/108
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
95/108
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
96/108
Chapter 2: Outline2.1 Principles of app layer
protocols clients and servers
app requirements2.2 Web and HTTP
2.3 FTP
2.4 Electronic Mail
SMTP, POP3, IMAP
2.5 DNS
2.6 Socket programmingwith TCP
2.7 Socket programming
with UDP 2.8 Building a Web server
2.9Content distribution Network Web caching
Content distributionnetworks
P2P file sharing
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
97/108
Web caches (Proxy Server)
client
Proxy
server
clientoriginserver
originserver
user sets browser: Webaccesses via cache
browser sends all HTTPrequests to cache
object in cache: cachereturns object
else cache requests objectfrom origin server, thenreturns object to client
Goal: satisfy client request without involving origin server
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
98/108
More about Web caching Cache acts as both client and
server
Cache can do up-to-datecheck using If-modified-
since HTTP header Issue: should cache take risk
and deliver cached objectwithout checking?
Heuristics are used.
Typically cache is installed byISP (university, company,residential ISP)
Why Web caching? Reduce response time for
client request.
Reduce traffic on aninstitutions access link.
Internet dense with cachesenables poor contentproviders to effectively deliver
content
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
99/108
Caching Example (1)Assumptions
average object size = 100,000 bits
avg. request rate frominstitutions browser to originserves = 15/sec
delay from institutional router toany origin server and back torouter = 2 sec
Consequences utilization on LAN = 15%
utilization on access link = 100% total delay = Internet delay + access
delay + LAN delay
= 2 sec + minutes + milliseconds
originservers
publicInternet
institutional
network 10 Mbps LAN
1.5 Mbpsaccess link
institutionalcache
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
100/108
Example caching (2)origin
servers
publicInternet
institutional
network 10 Mbps LAN
10 Mbpsaccess link
institutionalcache
Possible solution
increase bandwidth of access linkto, say, 10 Mbps
Consequences
utilization on LAN = 15%
utilization on access link = 15%
Total delay = Internet delay + accessdelay + LAN delay
= 2 sec + msecs + msecs
often a costly upgrade
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
101/108
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
102/108
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
103/108
CDN Example HTTP request forwww.foo.com/sports/sports.html
DNS query for www.cdn.com
HTTP request forwww.cdn.com/www.foo.com/sports/ruth.gif
1
2
3
Origin server
CDNs authoritativeDNS server
NearbyCDN server
origin server
www.foo.com
distributes HTML Replaces:
http://www.foo.com/sports.ruth.gif
withhttp://www.cdn.com/www.foo.com/sports/ruth.gif
CDN company cdn.com distributes gif files uses its authoritative DNS server
to route redirect requests
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
104/108
P2P File SharingExample
Alice runs P2P clientapplication on hernotebook computer
Intermittently connectsto Internet; gets new IPaddress for eachconnection
Asks for Hey JudeApplication displays
other peers that havecopy of Hey Jude.
Alice chooses one of thepeers, Bob.
File is copied from BobsPC to Alices notebook:HTTP
While Alice downloads,other users uploadingfrom Alice.
Alices peer is both a Webclient and a transient
Web server.
All peers are servers =
highly scalable!
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
105/108
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
106/108
P2P: Problems with centralized directory
Single point of failure
Performance bottleneck
Copyright infringement
file transfer isdecentralized, butlocating content ishighly decentralized
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
107/108
P2P: Decentralized directory
Each peer is either agroup leader or assignedto a group leader.
Group leader tracks thecontent in all itschildren.
Peer queries group
leader; group leader mayquery other groupleaders.
ordinary peer
group-leader peer
neighoring relationships
in overlay network
Chapter 2 Summary
-
7/28/2019 2011-03-5 Chapter 2 - Application Layer
108/108
Chapter 2: SummaryOur study of network apps now complete!
application service requirements:
reliability, bandwidth, delay
Ubiquitous client-server paradigm
Internet transport service model
connection-oriented, reliable: TCP
unreliable, datagrams: UDP
specific protocols: HTTP FTP
SMTP, POP, IMAP DNS
socket programming content distribution
Most importantly: learned aboutprotocols
typical request/reply message exchange:
client requests info or service
server responds with data, status code
message formats: headers: fields giving info about data
data: info being communicated
control vs. data msgs
in-band, out-of-band centralized vs. decentralized stateless vs. stateful reliable vs. unreliable msg transfer l k d