Professional Documents
Culture Documents
Application Layer
Application layer
• • 2.6 P2P applications
2.1 Principles of network applications
• 2.2 Web and HTTP • 2.7 Socket programming
• 2.3 FTP with TCP
• 2.4 Electronic Mail • 2.8 Socket programming
– SMTP, POP3, IMAP with UDP
• 2.5 DNS
Our goals: • learn about protocols by
• conceptual, examining popular
implementation aspects application-level
of network application protocols
protocols – HTTP
– transport-layer – FTP
– SMTP / POP3 / IMAP
service models – DNS
– client-server • programming network
paradigm applications
– peer-to-peer – socket API
paradigm
Some network apps
• voice over IP
e-mail
• web
real-time video conferencing
• instant
grid computing
messaging
• remote login
• P2P file sharing
• multi-user network games
• streaming stored video clips
Creating a network app application
transport
network
data link
physical
write programs that
– run on (different) end systems
– communicate over network
– e.g., web server software
communicates with browser
software
No need to write software for application
transport
network-core devices network
data link
application
– Network-core devices do not physical
transport
network
run user applications data link
physical
– applications on end systems
allows for rapid app
development, propagation
• • 2.6 P2P applications
2.1 Principles of network applications
• 2.2 Web and HTTP • 2.7 Socket programming
• 2.3 FTP with TCP
• 2.4 Electronic Mail • 2.8 Socket programming
– SMTP, POP3, IMAP with UDP
• 2.5 DNS • 2.9 Building a Web server
Application architectures
• Client-server
• Peer-to-peer (P2P)
• Hybrid of client-server and P2P
Client-server architecture
server:
– always-on host
– permanent IP address
– server farms for scaling
clients:
– communicate with server
– may be intermittently connected
client/server
– may have dynamic IP addresses
– do not communicate directly
with each other
Pure P2P architecture
• no always-on server
• arbitrary end systems
directly communicate peer-peer
• peers are intermittently
connected and change IP
addresses
API: (1) choice of transport protocol; (2) ability to fix a few parameters (lots more
on this later)
Addressing processes
• to receive messages, process
must have identifier
• host device has unique 32-bit
IP address
• Q: does IP address of host
suffice for identifying the
process?
Addressing processes
• to receive messages, process • identifier includes both IP
must have identifier address and port numbers
• host device has unique 32-bit associated with process on
IP address host.
• Q: does IP address of host on • Example port numbers:
which process runs suffice for – HTTP server: 80
identifying the process? – Mail server: 25
– A: No, many processes • to send HTTP message to
can be running on gaia.cs.umass.edu web
same host server:
– IP address: 128.119.245.12
– Port number: 80
• more shortly…
App-layer protocol defines
• Types of messages Public-domain protocols:
exchanged, • defined in RFCs
– e.g., request, response • allows for interoperability
• Message syntax: • e.g., HTTP, SMTP
– what fields in messages &
how fields are delineated Proprietary protocols:
• Message semantics • e.g., Skype
– meaning of information in
fields
• Rules for when and how
processes send & respond
to messages
What transport service does an app need?
Data loss Throughput
some apps (e.g., multimedia) require
• some apps (e.g., audio) can minimum amount of throughput to be
tolerate some loss “effective”
other apps (“elastic apps”) make use of
• other apps (e.g., file transfer,
whatever throughput they get
telnet) require 100% reliable Security
data transfer Encryption, data integrity, …
Timing
• some apps (e.g., Internet
telephony, interactive
games) require low delay
to be “effective”
Transport service requirements of common apps
Application Underlying
Application layer protocol transport protocol
www.someschool.edu/someDept/pic.gif
u est
P req se Server
T T o n
H
resp running
TP Apache Web
HT
server
Mac running
Navigator
HTTP overview (continued)
Uses TCP: HTTP is “stateless”
• client initiates TCP connection • server maintains no
(creates socket) to server, port information about past
80 client requests
• server accepts TCP connection
aside
from client
Protocols that maintain “state”
• HTTP messages (application- are complex!
layer protocol messages) past history (state) must be
exchanged between browser maintained
(HTTP client) and Web server if server/client crashes, their
(HTTP server) views of “state” may be
• TCP connection closed inconsistent, must be
reconciled
HTTP connections
Persistent HTTPHTTP
Nonpersistent
• Multiple
At most one
objects
object
canisbe
sent
sent
over
over
a TCP
single
connection.
TCP connection
between client and server.
Nonpersistent HTTP
(contains text,
Suppose user enters URL www.someSchool.edu/someDepartment/home.index
references to 10
jpeg images)
time
Nonpersistent HTTP (cont.)
time
6. Steps 1-5 repeated for each of 10
jpeg objects
Non-Persistent HTTP: Response time
Definition of RTT: time for a
small packet to travel from
client to server and back.
initiate TCP
Response time: connection
• one RTT to initiate TCP RTT
connection request
file
• one RTT for HTTP request time to
RTT
and first few bytes of HTTP transmit
file
response to return file
received
• file transmission time
total = 2RTT+transmit time time time
Persistent HTTP
request line
(GET, POST, GET /somedir/page.html HTTP/1.1
HEAD commands) Host: www.someschool.edu
User-agent: Mozilla/4.0
header Connection: close
lines Accept-language:fr
www.somesite.com/animalsearch?monkeys&banana
Method types
HTTP/1.0 HTTP/1.1
• GET • DELETE
– deletes file specified in the URL
• POST field
• HEAD
– asks server to leave
• TRACE
requested object out of – Echoes request msg
response
from server
HTTP/1.1
• GET, POST, HEAD • OPTIONS
• PUT – Returns HTTP methods
– uploads file in entity body that the server supports
to path specified in URL
field • CONNECT
– TCP/IP tunnel for HTTP
HTTP response message
status line
(protocol
status code HTTP/1.1 200 OK
status phrase) Connection close
Date: Thu, 06 Aug 1998 12:00:15 GMT
header Server: Apache/1.3.0 (Unix)
lines Last-Modified: Mon, 22 Jun 1998 …...
Content-Length: 6821
Content-Type: text/html
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
Trying out HTTP (client side) for yourself
ebay 8734
usual http request msg
Amazon server
cookie file usual http response creates ID
Set-cookie: 1678 1678 for user create
ebay 8734 entry
amazon 1678
usual http request msg
cookie: 1678 cookie- access
specific
one week later: usual http response msg action backend
database
access
ebay 8734 usual http request msg
amazon 1678 cookie: 1678 cookie-
spectific
usual http response msg action
Cookies (continued)
aside
Cookies and privacy:
What cookies can bring: cookies permit sites to learn a lot
• authorization about you
you may supply name and e-mail
• shopping carts to sites
• recommendations
• user session state (Web e-
mail)
How to keep “state”:
protocol endpoints: maintain state at sender/receiver
over multiple transactions
cookies: http messages carry state
Web caches (proxy server)
Goal: satisfy client request without involving origin server
client
origin
server
More about Web caching
• cache
Why Webacts
caching?
as both client and server
• reduce
typicallyresponse
cache is time
installed
for client
by ISPrequest
(university, company,
• residential ISP)on an institution’s access link.
reduce traffic
• Internet dense with caches: enables “poor” content providers
to effectively deliver content (but so does P2P file sharing)
Caching example
origin
Assumptions servers
• average object size = 100,000 bits
public
• avg. request rate from institution’s Internet
browsers to origin servers = 15/sec
• delay from institutional router to
any origin server and back to
1.5 Mbps
router = 2 sec access link
Consequences institutional
• utilization on LAN = 15% network
10 Mbps LAN
• utilization on access link = 100%
• total delay = Internet delay + access
delay + LAN delay
= 2 sec + minutes + milliseconds institutional
cache
Caching example (cont)
origin
possible solution servers
• increase bandwidth of access link
public
to, say, 10 Mbps Internet
consequence
• utilization on LAN = 15%
• utilization on access link = 15% 10 Mbps
• Total delay = Internet delay + access access link
delay + LAN delay
institutional
= 2 sec + msecs + msecs network
10 Mbps LAN
• often a costly upgrade
institutional
cache
Caching example (cont)
origin
possible solution: install cache servers
• suppose hit rate is 0.4 public
consequence Internet
• 40% requests will be satisfied
almost immediately
• 60% requests satisfied by origin
server 1.5 Mbps
• utilization of access link reduced access link
to 60%, resulting in negligible institutional
delays (say 10 msec) network
10 Mbps LAN
• total avg delay = Internet delay
+ access delay + LAN delay = .
6*(2.01) secs + .4*milliseconds <
1.4 secs
institutional
cache
Conditional GET
cache server
• Goal: don’t send object if cache
has up-to-date cached version HTTP request msg
• cache: specify date of cached If-modified-since:
object
copy in HTTP request <date>
not
If-modified-since: modified
<date> HTTP response
HTTP/1.0
• server: response contains no 304 Not Modified
object if cached copy is up-to-
date:
HTTP request msg
HTTP/1.0 304 Not
If-modified-since:
Modified <date> object
modified
HTTP response
HTTP/1.0 200 OK
<data>
Application layer
• • 2.6 P2P applications
2.1 Principles of network applications
• 2.2 Web and HTTP • 2.7 Socket programming
• 2.3 FTP with TCP
• 2.4 Electronic Mail • 2.8 Socket programming
– SMTP, POP3, IMAP with UDP
• 2.5 DNS • 2.9 Building a Web server
FTP: the file transfer protocol
Sample return
commands:
codes
• sent
statusascode
ASCIIand
textphrase
over control
(as in HTTP)
channel
• 331
USERUsername
usernameOK, password required
• 125
PASSdata password
connection already open; transfer
• starting
LIST return list of file in current directory
• 425 Can’t open data connection
• RETR filename retrieves (gets) file
• 452 Error writing file
• STOR filename stores (puts) file onto remote host
Application layer
• • 2.6 P2P applications
2.1 Principles of network applications
• 2.2 Web and HTTP • 2.7 Socket programming
• 2.3 FTP with TCP
• 2.4 Electronic Mail • 2.8 Socket programming
– SMTP, POP3, IMAP with UDP
• 2.5 DNS
outgoing
Electronic Mail message queue
user mailbox
user
Three major components: agent
• user agents mail
user
• mail servers server
agent
• simple mail transfer protocol: SMTP
mail
SMTP server user
SMTP agent
User Agent
• a.k.a. “mail reader” SMTP
• composing, editing, reading mail mail user
messages server agent
1 mail
mail
server user
user server
2 agent
agent 3 6
4 5
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
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)
SMTP: final words
•Comparison
SMTP uses persistent
with HTTP:connections
• SMTP requires message (header & body) to be in 7-bit ASCII
• HTTP: pull
• SMTP server uses CRLF.CRLF to determine end of message
• 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
Mail message format
SMTP: protocol for exchanging email msgs
RFC 822: standard for text message format: header
blank
• header lines, e.g., line
– To:
– From:
– Subject: body
different from SMTP commands!
• body
– the “message”, ASCII characters only
Mail access protocols
SMTP SMTP access
user
user protocol
agent
agent
gaia.cs.umass.edu
DNS name
resolution example
recursive query:
puts burden of name
resolution on contacted
name server
heavy load?
DNS: caching and updating records
• once (any) name server learns mapping, it caches
mapping
– cache entries timeout (disappear) after some
time
– TLD servers typically cached in local name
servers
• Thus root name servers not often visited
• update/notify mechanisms under design by IETF
– RFC 2136
– http://www.ietf.org/html.charters/dnsind-charter.html
DNS records
DNS: distributed db storing resource records (RR)
RR format: (name, value, type, ttl)
Type=A Type=CNAME
name is hostname name is alias name for some
value is IP address “canonical” (the real) name
www.ibm.com is really
• Type=NS servereast.backup2.ibm.com
value is canonical name
– name is domain (e.g. foo.com)
– value is hostname of
authoritative name server for Type=MX
this domain value is name of mailserver
associated with name
DNS protocol, messages
DNS protocol : query and reply messages, both with same message format
msg header
identification: 16 bit # for
query, reply to query uses
same #
flags:
query or reply
recursion desired
recursion available
reply is authoritative
DNS protocol, messages
RRs in response
to query
records for
authoritative servers
additional “helpful”
info that may be used
Inserting records into DNS
• example: new startup “Network Utopia”
• register name networkuptopia.com at DNS registrar (e.g.,
Network Solutions)
– provide names, IP addresses of authoritative name server (primary
and secondary)
– registrar inserts two RRs into com TLD server:
2: Application Layer 74
Application layer
• 2.1 Principles of network applications
• 2.6 P2P applications
– app architectures • 2.7 Socket programming
– app requirements with TCP
• 2.2 Web and HTTP • 2.8 Socket programming
• 2.4 Electronic Mail with UDP
– SMTP, POP3, IMAP
• 2.5 DNS
2: Application Layer 75
Pure P2P architecture
• no always-on server
• arbitrary end systems
directly communicate peer-peer
• peers are intermittently
connected and change IP
addresses
• Three topics:
– File distribution
– Searching for information
– Case Study: Skype
2: Application Layer 76
File Distribution: Server-Client vs P2P
Question : How much time to distribute file from
one server to N peers?
us: server upload
Server
bandwidth
ui: peer i upload
u1 d1 u2 bandwidth
us d2
di: peer i download
File, size F bandwidth
dN
Network (with
uN abundant bandwidth)
File distribution time: server-client
Server
• server sequentially F u1 d1 u2
us d2
sends N copies:
Network (with
– NF/us time dN
abundant bandwidth)
uN
• client i takes F/di
time to download
Time to distribute F
to N clients using
client/server approach = dcs = max { NF/us, F/min(di) }
i
increases linearly in N
(for large N)
File distribution time: P2P
Server
• server must send one copy:
F u1 d1 u2
F/us time us d2
3.5
P2P
Minimum Distribution Time
3
Client-Server
2.5
1.5
0.5
0
0 5 10 15 20 25 30 35
N
File distribution: BitTorrent
P2P file distribution
obtain list
of peers
trading
chunks
peer
BitTorrent (1)
• file divided into 256KB chunks.
• peer joining torrent:
– has no chunks, but will accumulate them over
time
– registers with tracker to get list of peers, connects
to subset of peers (“neighbors”)
• while downloading, peer uploads chunks to other peers.
• peers may come and go
• once peer has entire file, it may (selfishly) leave or
(altruistically) remain
BitTorrent (2)
Pulling Chunks Sending Chunks: tit-for-tat
Alice sends chunks to four neighbors
• at any given time, different currently sending her chunks at the
peers have different highest rate
re-evaluate top 4 every 10 secs
subsets of file chunks every 30 secs: randomly select another
• periodically, a peer (Alice) peer, starts sending chunks
newly chosen peer may join top 4
asks each neighbor for list
“optimistically unchoke”
of chunks that they have.
• Alice sends requests for her
missing chunks
– rarest first
BitTorrent: Tit-for-tat
(1) Alice “optimistically unchokes” Bob
(2) Alice becomes one of Bob’s top-four providers; Bob reciprocates
(3) Bob becomes one of Alice’s top-four providers
3
15
12
5
10
8
1110 0100
1110
1100
1110 0101
1110
as closest 1010
1000
successor
Circular DHT with Shortcuts
1
Who’s resp
for key 1110?
3
15
12
5
10
8
10
8
• Peer 5 abruptly leaves
• Peer 4 detects; makes 8 its immediate successor; asks 8 who
its immediate successor is; makes 8’s immediate successor
its second successor.
• What if peer 13 wants to join?
P2P Case study: Skype
Skype clients (SC)
• inherently P2P: pairs of
users communicate.
• proprietary application- Skype
layer protocol (inferred login server Supernode
via reverse engineering) (SN)
controlled by
controlled by process application
application process
developer
developer socket socket
controlled by TCP with TCP with controlled by
buffers, operating
operating buffers, internet variables system
system variables
host or host or
server server
Socket programming with TCP
Client must contact server • When contacted by client, server
• server process must first be TCP creates new socket for
running server process to communicate
• server must have created with client
socket (door) that welcomes – allows server to talk with
client’s contact multiple clients
Client contacts server by: – source port numbers used to
• creating client-local TCP socket distinguish clients (more in
Chap 3)
• specifying IP address, port
number of server process
application viewpoint
• When client creates socket:
client TCP establishes TCP provides reliable, in-order
connection to server TCP transfer of bytes (“pipe”)
between client and server
Client/server socket interaction: TCP
Server (running on hostid) Client
create socket,
port=x, for
incoming request:
welcomeSocket =
ServerSocket()
write reply to
connectionSocket read reply from
clientSocket
close
connectionSocket close
clientSocket
Stream jargon
keyboard monitor
inFromUser
input
keyboard or socket. stream
inFromServer
outToServer
output input
stream stream
client
clientSocket
TCP
socket TCP
socket
sentence = inFromUser.readLine();
Send line
to server outToServer.writeBytes(sentence + '\n');
clientSocket.close();
}
}
Example: Java server (TCP)
import java.io.*;
import java.net.*;
class TCPServer {
Create output
stream, attached
DataOutputStream outToClient =
to socket
new DataOutputStream(connectionSocket.getOutputStream());
Read in line
from socket clientSentence = inFromClient.readLine();
write reply to
serverSocket
specifying read datagram from
client address, clientSocket
port number close
clientSocket
Example: Java client (UDP)
keyboard monitor
inFromUser
input
stream
Client
Process
process Input: receives packet
(recall thatTCP
Output: sends packet received “byte
(recall stream”)
receivePacket
sendPacket
that TCP sent “byte UDP UDP
packet packet
stream”)
client
clientSocket UDP
socket UDP
socket
class UDPClient {
public static void main(String args[]) throws Exception
{
Create
input stream BufferedReader inFromUser =
Create new BufferedReader(new InputStreamReader(System.in));
client socket
DatagramSocket clientSocket = new DatagramSocket();
Translate
hostname to IP InetAddress IPAddress = InetAddress.getByName("hostname");
address using DNS
byte[] sendData = new byte[1024];
byte[] receiveData = new byte[1024];
String modifiedSentence =
new String(receivePacket.getData());
class UDPServer {
public static void main(String args[]) throws Exception
Create {
datagram socket
at port 9876 DatagramSocket serverSocket = new DatagramSocket(9876);
while(true)
{
Create space for
received datagram DatagramPacket receivePacket =
new DatagramPacket(receiveData, receiveData.length);
Receive serverSocket.receive(receivePacket);
datagram
Example: Java server (UDP), cont
String sentence = new String(receivePacket.getData());
Get IP addr
port #, of InetAddress IPAddress = receivePacket.getAddress();
sender
int port = receivePacket.getPort();
sendData = capitalizedSentence.getBytes();
Create datagram
to send to client DatagramPacket sendPacket =
new DatagramPacket(sendData, sendData.length, IPAddress,
port);
Write out
datagram serverSocket.send(sendPacket);
to socket }
}
} End of while loop,
loop back and wait for
another datagram
Summary
our study of network apps now complete!
specific protocols:
• application architectures
HTTP
– client-server
FTP
– P2P
SMTP, POP, IMAP
– hybrid DNS
• application service P2P: BitTorrent, Skype
requirements: socket programming
– reliability, bandwidth, delay
• Internet transport service model
– connection-oriented, reliable: TCP
– unreliable, datagrams: UDP
Summary
Most importantly: learned about protocols
• typical request/reply Important themes:
control vs. data msgs
message exchange: in-band, out-of-band
– client requests info or service centralized vs. decentralized
– server responds with data, stateless vs. stateful
status code reliable vs. unreliable msg transfer
“complexity at network edge”
• message formats:
– headers: fields giving info
about data
– data: info being
communicated