❍ client-server ❍ ftp
paradigm ❍ http
❍ peer-peer paradigm ❍ smtp/pop3
❍ transport layer
service models
❍ sockets API
1
Creating a network app
Write programs that application
transport
systems and
physical
❍ communicate over a
network
❍ e.g., Web: server software
communicates with browser
software
No software written for application
application
devices in network core
transport
transport network
network data link
Network core devices do
data link physical
❍ physical
Client-server architecture
server:
❍ always-on host
❍ permanent IP address
❍ server farms for scaling
clients:
❍ communicate with
server (speak first)
❍ may be intermittently
connected
❍ may have dynamic IP
addresses
❍ do not communicate
directly with each other
2
Pure P2P architecture
❒ no always-on server
❒ arbitrary end systems
directly communicate
❒ peers are intermittently
connected and may
change IP addresses
❒ example: Gnutella
Highly scalable
3
Processes communicating
Process: program running Client process: process
within a host that initiates
❒ within same host, two communication
processes communicate Server process: process
using inter-process that waits to be
communication (defined contacted
by OS)
❒ processes in different ❒ Note: applications in
hosts communicate by both client-server and
exchanging messages P2P architectures have
(of an application-layer client & server
protocol) processes
2a: Application Layer 7
1/19/05 (SSL)
4
Application and application-layer protocol
Application: communicating
processes application
transport
❍ running in different hosts network
data link
❍ exchange messages to
physical
implement app
❍ e.g., email, file transfer,
Web
Application-layer protocol
❍ one “piece” of an app
❍ defines messages application
application
exchanged by app and transport
transport
network
network
actions taken data link
data link
physical
physical
❍ delivery service provided
by lower layer protocols
5
What transport service does an app need?
Data loss Bandwidth
❒ some apps (e.g., audio) can ❒ some apps (e.g.,
tolerate some loss multimedia) require
❒ other apps (e.g., file minimum amount of
transfer, telnet) require bandwidth to be
100% reliable data
“effective”
transfer
❒ other apps (“elastic
Timing apps”) make use of
❒ some apps (e.g., whatever bandwidth
Internet telephony, they get
interactive games)
require low delay to be
“effective”
2a: Application Layer 11
1/19/05 (SSL)
6
Services provided by Internet
transport protocols
TCP service: UDP service:
❒ connection-oriented: setup ❒ unreliable data transfer
required between client, between sending and
server receiving users
❒ reliable transport between ❒ does not provide
sending and receiving users
connection setup,
❒ flow control: sender won’t reliability, flow control,
overwhelm receiver
congestion control, delay,
❒ congestion control: sender or bandwidth guarantee
throttled when network
overloaded
❒ does not provide delay, Q: why bother? Why is
minimum bandwidth there a UDP?
guarantees
7
Socket programming
Goal: learn how to write client and server programs
which communicate by sending data into sockets,
reading data out of sockets
Socket API
❒ introduced in BSD4.1 UNIX, 1981
❒ sockets are explicitly created, used, then released by
applications
❒ client/server paradigm
❒ API: choice of a transport protocol and ability to
specify a few parameters
❍ unreliable datagram
❍ reliable byte stream
Sockets
A socket is like a door between application process
and end-end transport protocol (TCP or UDP)
controlled by
controlled by process application
application process
developer
developer socket socket
TCP with TCP with controlled by
controlled by
buffers, operating
operating buffers, internet system
system variables variables
host or host or
server server
8
Socket programming with TCP
Client must contact server ❒ When client makes connect
❒ server process must first call, client TCP establishes
be running connection to server TCP
❒ server must have created ❒ When contacted by a new
socket (door) that client, server creates new
welcomes client’s contact socket for server process to
communicate with the client
Client contacts server by:
❍ allows server to talk with
❒ creating client-local TCP
multiple clients
socket
❒ specifying IP address, port application viewpoint
number of server process
for connect call TCP provides reliable, in-order
transfer of byte stream
between client and server
9
TCP Client/server interaction (in Java)
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
2a: Application Layer 19
1/19/05 (SSL)
10
Socket API for UDP (BSD Unix)
❒ Client side ❒ Server side
❍ socket(), returns client ❍ socket(), returns server
socket id socket id
❍ sendto(), sends to client ❍ bind(), binds server
socket, need to specify socket to server IP
destination’s IP address address and port
and port ❍ recvfrom(), receives
❍ recvfrom(), receives from server socket: data
from client socket: data and sender’s IP address
and sender’s IP address and port
and port ❍ sendto(), sends to server
❍ bind(), optional socket, need to specify
❒ note: needs timeout management; destination’s IP address
OS supplies local IP address and and port
port for client if bind() not used
write reply to
serverSocket
specifying client read reply from
host address, clientSocket
port number close
clientSocket
11
DNS: Domain Name System
People: many identifiers:
❍ SSN, name, passport # Domain Name System:
Internet hosts, routers: ❒ distributed database
implemented in hierarchy of
❍ IP address (32 bit)
many name servers
- used for addressing
datagrams
❒ application-layer protocol
used to resolve names
❍ “name”, e.g., (address/name translation)
www.yahoo.com - used ❍ note: core Internet
by humans function, implemented as
Required: map between application-layer protocol
name and IP addresses ❍ complexity at network’s
“edge”
DNS
DNS services Why not centralize DNS?
❒ Hostname to IP ❒ single point of failure
address translation ❒ traffic volume
❒ Host aliasing ❒ distant centralized
❍ Canonical and alias database
names ❒ maintenance
❒ Mail server aliasing
❒ Load distribution
doesn’t scale!
❍ Replicated Web
servers: set of IP
addresses for one
canonical name
12
Distributed, Hierarchical Database
Root DNS Servers
m WIDE Tokyo
e NASA Mt View, CA
f Internet Software C. Palo Alto,
CA (and 17 other locations)
13 root name
servers worldwide
b USC-ISI Marina del Rey, CA
l ICANN Los Angeles, CA
13
TLD and Authoritative Servers
❒ Top-level domain (TLD) servers: responsible
for com, org, net, edu, etc, and all top-level
country domains uk, fr, ca, jp.
❍ Verisign maintains servers for com TLD
❍ Educause for edu TLD
14
Example root DNS server
2
❒ Host at cis.poly.edu 3
TLD DNS server
wants IP address for 4
gaia.cs.umass.edu
5
gaia.cs.umass.edu
recursive query:
2 3
❒ puts burden of name
resolution on 6
7
contacted name TLD DNS serve
server
❒ heavy load?
local DNS server
4
iterated query: dns.poly.edu 5
❒ contacted server 1 8
replies with name of
server to contact authoritative DNS server
❒ “I don’t know this dns.cs.umass.edu
requesting host
name, but ask this cis.poly.edu
server”
gaia.cs.umass.edu
2a: Application Layer 30
1/19/05 (SSL)
15
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 database of 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 “cannonical” (the real) name
e.g., www.ibm.com is really
❒ Type=NS
servereast.backup2.ibm.com
❍ name is domain (e.g.
❍ value is cannonical name
foo.com)
❍ value is host name of ❒ Type=MX
name server for this
❍ value is host name of
domain
mailserver associated with
name
2a: Application Layer 32
1/19/05 (SSL)
16
DNS protocol, messages
DNS protocol : query and reply messages, both with
same message format
msg header
❒ identification: 16 bit #
for query, reply to query
has same #
❒ flags:
❍ query or reply
❍ recursion desired
❍ recursion available
❍ reply is authoritative
RRs in reponse
to query
records for
authoritative servers
additional “helpful”
info that may be used
17
Inserting records into DNS
❒ Example: just created startup “Network Utopia”
❒ Register name networkutopia.com at a registrar (e.g.,
Network Solutions)
❍ Need to provide registrar with names and IP addresses of
your authoritative name servers (primary and secondary)
❍ Registrar inserts two RRs for each server into the com TLD
server:
18
FTP: separate control, data connections
TCP control connection
❒ FTP client contacts FTP port 21
server at port 21, specifying
TCP as transport protocol
Client obtains authorization TCP data connection
❒ FTP port 20 FTP
over control connection client server
❒ Client browses remote
directory by sending ❒ Server opens a second TCP
commands over control data connection to transfer
connection.
another file.
❒ When server receives a
command for a file transfer, ❒ Control connection: “out of
the server opens a TCP data band”
connection to client ❒ FTP server maintains “state”:
❒ After transferring one file, current directory, earlier
server closes connection. authentication
19
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
20
The http protocol: more
Uses TCP service: http is “stateless”
❒ client initiates TCP ❒ server maintains no
connection (creates socket) information about
to server, port 80 past client requests
❒ server accepts TCP
connection from client aside
Protocols that maintain
❒ http protocol messages “state” are complex
exchanged between browser ❒ if server or client crashes,
(http client) and WWW their views of “state” may
server (http server) be inconsistent, must be
❒ TCP connection closed reconciled
HTTP connections
Nonpersistent HTTP Persistent HTTP
❒ At most one object is ❒ Multiple objects can
sent over a TCP be sent over single
connection. TCP connection
❒ HTTP/1.0 uses between client and
nonpersistent HTTP server.
❒ HTTP/1.1 uses
persistent connections
in default mode
21
Nonpersistent HTTP
(contains text,
Suppose user enters URL references to 10
www.someSchool.edu/someDepartment/home.index jpeg images)
time
2a: Application Layer 43
1/19/05 (SSL)
22
Response time modeling
Definition of RRT: time to send
a small packet to travel from
client to server and back.
Response time:
initiate TCP
❒ one RTT to initiate TCP connection
connection RTT
❒ one RTT for HTTP request request
and first few bytes of HTTP file
time to
response to return RTT
transmit
❒ file transmission time file
file
total = 2RTT+transmit time received
time time
Persistent HTTP
23
HTTP request message
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
Carriage return,
line feed (extra carriage return, line feed)
indicates end
of message
2a: Application Layer 47
1/19/05 (SSL)
24
Uploading form input
Post method:
❒ Web page often
includes form input URL method:
❒ Input is uploaded to ❒ Uses GET method
server in entity body ❒ Input is uploaded in
URL field of request
line:
www.somesite.com/animalsearch?monkeys&banana
Method types
HTTP/1.0 HTTP/1.1
❒ GET ❒ GET, POST, HEAD
❒ POST ❒ PUT
❒ HEAD ❍ uploads file in entity
body to path specified
❍ asks server to leave
in URL field
requested object out of
response ❒ DELETE
❍ deletes file specified in
the URL field
25
http message format: reply
status line
(protocol
status code HTTP/1.1 200 OK
status phrase) Connection: close
Date: Thu, 06 Aug 1998 12:00:15 GMT
Server: Apache/1.3.0 (Unix)
header
Last-Modified: Mon, 22 Jun 1998 …...
lines
Content-Length: 6821
Content-Type: text/html
26
Trying out HTTP (client side) for yourself
27
Cookies: keeping “state” (cont.)
client server
Cookie file usual http request msg server n e
da try i
tab n b
usual http response + creates ID as ac
e ke
ebay: 8734 Set-cookie: 1678 1678 for user nd
Cookie file
usual http request msg
amazon: 1678 cookie: 1678 cookie-
ss
ebay: 8734 specific acce
usual http response msg action
one week later:
ss
ce
ac
usual http request msg
Cookie file cookie-
cookie: 1678
amazon: 1678 spectific
ebay: 8734 usual http response msg action
Cookies (continued)
aside
What cookies can bring: Cookies and privacy:
❒ authorization ❒ cookies permit sites to
❒ shopping carts
learn a lot about you
❒ you may supply name
❒ recommendations
and e-mail to sites
❒ user session state
(Web e-mail)
❒ advertising companies
obtain info across
sites
28
Web caches (proxy server)
Goal: satisfy client request without involving origin server
client
origin
server
29
Caching example
origin
Assumptions
servers
❒ average object size = 100,000
bits public
Internet
❒ avg. request rate from
institution’s browsers to origin
servers = 15/sec
1.5 Mbps
❒ delay from institutional router
access link
to any origin server and back
to router = 2 sec institutional
network
10 Mbps LAN
Consequences
❒ utilization on LAN = 15%
❒ utilization on access link = 100%
❒ total delay = Internet delay + institutional
access delay + LAN delay cache
= 2 sec + minutes + milliseconds
2a: Application Layer 59
1/19/05 (SSL)
institutional
cache
30
Caching example (3)
origin
Install cache servers
❒ suppose hit rate is .4 public
Consequence Internet
❒ 40% requests will be satisfied
almost immediately
❒ 60% requests satisfied by
origin server 1.5 Mbps
access link
❒ utilization of access link
reduced to 60%, resulting in institutional
negligible delay (say 10 msec) network
10 Mbps LAN
❒ ave total delay = Internet
delay + access link delay + LAN
delay
= 0.6*(2 secs + 20 msecs) +
institutional
0.4* (0 + 0 + 10 msecs) cache
(note: ballpark calculations,
transmission time on access link not
included?) 2a: Application Layer 61
1/19/05 (SSL)
Conditional GET
31
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., Outlook, Eudora, pine, user
Netscape Messenger agent
user
❒ outgoing, incoming messages agent
stored on server
2a: Application Layer 63
1/19/05 (SSL)
32
Electronic Mail: smtp [RFC 2821]
1 mail
mail
server user
user server
2 agent
agent 3 6
4 5
33
Sample smtp interaction
(after TCP connection established)
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
2a: Application Layer 67
1/19/05 (SSL)
❒ 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)
34
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 (e.g., into base-64 encapsulated in its own
or quoted printable) response message
❒ smtp server uses ❒ smtp: multiple objects
CRLF.CRLF to determine message sent in a multipart
end of message message
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
MIME types
Content-Type: type/subtype; parameters
Text Video
❒ example subtypes: plain, ❒ example subtypes: mpeg,
html quicktime
Image
❒ example subtypes: jpeg,
Application
gif ❒ other data that must be
processed by reader
before “viewable”
Audio
❒ example subtypes:
❒ exampe subtypes: basic
(8-bit mu-law encoded), msword, octet-stream
32kadpcm (32 kbps
coding)
36
Multipart Type
From: alice@crepes.fr
To: bob@hamburger.edu
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 recipe?
37
P2P file sharing
❒ Alice chooses one of the
peers, Bob.
Example
❒ File is copied from Bob’s
❒ Alice runs P2P client
PC to Alice’s notebook:
application on her
HTTP
notebook computer
❒ While Alice downloads
❒ Intermittently
from Bob, other user
connects to Internet;
may download from
gets new IP address
Alice.
for each connection
❒ Alice’s notebook is both
❒ Asks for “Hey Jude”
a Web client and a
❒ Application displays transient Web server.
other peers that have
All peers are servers =
copy of Hey Jude.
highly scalable!
❍ IP address 1
❍ content
1 3
2) Alice queries for “Hey
2
Jude” 1
Alice
38
P2P: problems with centralized directory
39
Gnutella: protocol
File transfer:
❒ Query message HTTP
sent over existing TCP
connections
Query
❒ peers forward
QueryHit
Query message
y Qu
❒ QueryHit er ery
Qu it
sent over r yH
e
Qu
reverse
Query
path
QueryHit
Scalability: Qu
er
y
limited scope
flooding
2a: Application Layer 79
1/19/05 (SSL)
40
Gnutella: Peer joining
1. Joining peer X must find some other peer in
Gnutella network—use a list of candidate peers
2. X sequentially attempts to make TCP connection
with peers on list until connection setup with Y
3. X sends Ping message to Y; Y forwards Ping
message.
4. All peers receiving Ping message respond with
Pong message
5. X receives many Pong messages. It can then set
up additional TCP connections
Peer leaving: see homework problem
neighoring relationships
in overlay network
41
KaZaA: Querying
❒ Each file has a hash and a descriptor
❒ Client sends keyword query to its group
leader
❒ Group leader responds with matches
❍ peers that have files whose descriptors match keywords
❒ If group leader forwards query to other
group leaders, they respond with matches
❒ Client then selects files for download
❍ HTTP requests using hash as identifier sent to
peers holding desired file
2a: Application Layer 83
1/19/05 (SSL)
KaZaA tricks
❒ Request queueing
❍ Peer can be configured to limit the number of
simultaneous uploads to any value
❍ Requests in excess of limit join a local queue
❒ Incentive priorities
❍ Higher queueing priority to users who have uploaded
more files in the past than they have downloaded
❒ Parallel downloading
❍ Use byte-range header of HTTP to request different
portions of a file from different peers
42