Chapter2 ForStu
Chapter2 ForStu
Chapter 2
Application Layer 2.1 principles of network 2.6 P2P applications
applications 2.7 socket programming
2.2 Web and HTTP with UDP and TCP
2.3 FTP
A note on the use of these ppt slides:
We’re making these slides freely available to all (faculty, students, readers). Computer 2.4 electronic mail
They’re in PowerPoint form so you see the animations; and can add, modify,
and delete slides (including this one) and slide content to suit your needs. Networking: A Top § SMTP, POP3, IMAP
They obviously represent a lot of work on our part. In return for use, we only
ask the following: Down Approach 2.5 DNS
v If you use these slides (e.g., in a class) that you mention their source
(after all, we’d like people to use our book!)
6th edition
v If you post any slides on a www site, that you note that they are adapted Jim Kurose, Keith Ross
from (or perhaps identical to) our slides, and note our copyright of this
material.
Addison-Wesley
March 2012
Thanks and enjoy! JFK/KWR
2-1 2-2
2-3 2-4
Creating a network app application
transport
Application architectures
network
data link
2-5 2-6
2-7 2-8
Processes communicating Sockets
v process sends/receives messages to/from its socket
process: program running clients, servers v socket analogous to door
within a host client process: process that § sending process shoves message out door
v within same host, two initiates communication § sending process relies on transport infrastructure on
processes communicate server process: process that other side of door to deliver message to socket at
using inter-process waits to be contacted receiving process
communication (defined by
OS) application application
v processes in different hosts socket controlled by
process process app developer
communicate by exchanging v aside: applications with P2P
transport
messages architectures have client
transport
network network controlled
processes & server link Internet link by OS
processes physical physical
2-9 2-10
2-11 2-12
What transport service does an app need? Transport service requirements: common apps
data integrity throughput
v some apps (e.g., file transfer, v some apps (e.g.,
multimedia) require application data loss throughput time sensitive
web transactions) require
100% reliable data transfer minimum amount of
file transfer no loss elastic no
v other apps (e.g., audio) can
throughput to be e-mail no loss elastic no
tolerate some loss “effective” Web documents no loss elastic no
v other apps (“elastic apps”) real-time audio/video loss-tolerant audio: 5kbps-1Mbps yes, 100’s
timing make use of whatever video:10kbps-5Mbps msec
throughput they get stored audio/video loss-tolerant same as above
v some apps (e.g., Internet interactive games loss-tolerant few kbps up yes, few secs
telephony, interactive security text messaging no loss elastic yes, 100’s
games) require low delay msec
to be “effective” v encryption, data integrity, yes and no
…
2-13 2-14
2-19 2-20
HTTP overview (continued) HTTP connections
uses TCP: HTTP is “stateless” non-persistent HTTP persistent HTTP
client initiates TCP v server maintains no v at most one object v multiple objects can
v
connection (creates information about
socket) to server, port 80 past client requests sent over TCP be sent over single
v server accepts TCP connection TCP connection
connection from client aside § connection then between client, server
protocols that maintain
v HTTP messages “state” are complex! closed
(application-layer protocol v past history (state) must be v downloading multiple
messages) exchanged
between browser (HTTP
maintained objects required
client) and Web server
v if server/client crashes, their multiple connections
views of “state” may be
(HTTP server) inconsistent, must be
v TCP connection closed reconciled
2-21 2-22
v two types of HTTP messages: request, response method sp URL sp version cr lf request
v HTTP request message: line
header field name value cr lf
§ ASCII (human-readable format)
carriage return character header
line-feed character ~
~ ~
~ lines
request line
(GET, POST, GET /index.html HTTP/1.1\r\n
HEAD commands) Host: www-net.cs.umass.edu\r\n header field name value cr lf
User-Agent: Firefox/3.6.10\r\n
Accept: text/html,application/xhtml+xml\r\n cr lf
header Accept-Language: en-us,en;q=0.5\r\n
lines Accept-Encoding: gzip,deflate\r\n
Accept-Charset: ISO-8859-1,utf-8;q=0.7\r\n ~
~ entity body ~
~ body
carriage return, Keep-Alive: 115\r\n
line feed at start Connection: keep-alive\r\n
\r\n
of line indicates
end of header lines
2-27 2-28
Uploading form input Method types
POST method:
v web page often includes HTTP/1.0: HTTP/1.1:
form input v GET v GET, POST, HEAD
v input is uploaded to v POST v PUT
server in entity body v HEAD § uploads file in entity
§ asks server to leave body to path specified
URL method: requested object out in URL field
v uses GET method of response v DELETE
v input is uploaded in URL § deletes file specified in
field of request line: the URL field
www.somesite.com/animalsearch?monkeys&banana
2-29 2-30
2-37 2-38
Conditional GET
Chapter 2: outline
client server
v Goal: don’t send object if
cache has up-to-date 2.1 principles of network 2.6 P2P applications
cached version HTTP request msg
object
applications 2.7 socket programming
If-modified-since: <date>
§ no object transmission not § app architectures with UDP and TCP
delay modified
§ lower link utilization HTTP response § app requirements
before
HTTP/1.0
v cache: specify date of 304 Not Modified
<date> 2.2 Web and HTTP
cached copy in HTTP 2.3 FTP
request
If-modified-since:
2.4 electronic mail
<date> HTTP request msg § SMTP, POP3, IMAP
server: response contains If-modified-since: <date> object
v
modified 2.5 DNS
no object if cached copy after
HTTP response
is up-to-date: HTTP/1.0 200 OK <date>
HTTP/1.0 304 Not <data>
Modified
2-43 2-44
FTP: the file transfer protocol FTP: separate control, data connections
file transfer
FTP
user
FTP FTP v FTP client contacts FTP server TCP control connection,
server port 21
interface
client server at port 21, using TCP
user
at host remote file v client authorized over control TCP data connection,
local file system connection FTP server port 20 FTP
system client server
v client browses remote
directory, sends commands
over control connection v server opens another TCP
v transfer file to/from remote host v when server receives file
data connection to transfer
client/server model another file
v transfer command, server
§ client: side that initiates transfer (either to/from remote) opens 2nd TCP data v control connection: “out of
connection (for file) to client band”
§ server: remote host
v after transferring one file, v FTP server maintains
v ftp: RFC 959 server closes data connection “state”: current directory,
v ftp server: port 21 earlier authentication
2-45 2-46
2-47 2-48
Electronic mail outgoing
message queue
Electronic mail: mail servers
user mailbox
Three major components: user mail servers: user
agent agent
v user agents v mailbox contains incoming
v mail servers mail user messages for user mail user
server agent server agent
v simple mail transfer v message queue of outgoing
protocol: SMTP SMTP mail user (to be sent) mail messages SMTP mail user
server agent v SMTP protocol between server agent
Electronic Mail: SMTP [RFC 2821] Scenario: Alice sends message to Bob
1) Alice uses UA to compose 4) SMTP client sends Alice’s
v uses TCP to reliably transfer email message from message over the TCP
message “to”
client to server, port 25 [email protected] connection
v direct transfer: sending server to receiving 2) Alice’s UA sends message 5) Bob’s mail server places the
server to her mail server; message message in Bob’s mailbox
placed in message queue 6) Bob invokes his user agent
v three phases of transfer 3) client side of SMTP opens to read message
§ handshaking (greeting) TCP connection with Bob’s
§ transfer of messages mail server
§ closure
v command/response interaction (like HTTP, FTP) user
1 user mail mail
§ commands: ASCII text agent server server agent
2
§ response: status code and phrase 3 4 6
2-53 2-54
2-55 2-56
Mail access protocols POP3 protocol
S: +OK POP3 server ready
C: user bob
mail access
user
agent
SMTP SMTP protocol
user
agent
authorization phase S:
C:
+OK
pass hungry
(e.g., POP, v client commands: S: +OK user successfully logged on
IMAP) § user: declare username
§ pass: password C: list
sender’s mail receiver’s mail
S: 1 498
server server v server responses S: 2 912
v SMTP: delivery/storage to receiver’s server § +OK S: .
§ -ERR C: retr 1
v mail access protocol: retrieval from server S: <message 1 contents>
§ POP: Post Office Protocol [RFC 1939]: authorization, transaction phase, client: S: .
download v list: list message numbers C: dele 1
§ IMAP: Internet Mail Access Protocol [RFC 1730]: more v retr: retrieve message by C: retr 2
number
features, including manipulation of stored msgs on S: <message 1 contents>
server v dele: delete S: .
v quit C: dele 2
§ HTTP: gmail, Hotmail, Yahoo! Mail, etc. C: quit
S: +OK POP3 server signing off
2-57 2-58
2-59 2-60
DNS: domain name system DNS: services, structure
DNS services why not centralize DNS?
people: many identifiers: Domain Name System:
v hostname to IP address v single point of failure
§ SSN, name, passport # v distributed database translation
implemented in hierarchy of v traffic volume
Internet hosts, routers:
many name servers v host aliasing v distant centralized database
§ IP address (32 bit) - § canonical, alias names
used for addressing v application-layer protocol: hosts, v maintenance
datagrams name servers communicate to v mail server aliasing
§ “name”, e.g., resolve names (address/name v load distribution A: doesn’t scale!
www.yahoo.com - translation) § replicated Web
used by humans § note: core Internet function, servers: many IP
Q: how to map between IP implemented as application- addresses correspond
address and name, and layer protocol to one name
vice versa ? § complexity at network’s
“edge”
2-61 2-62
client wants IP for www.amazon.com; 1st approx: j. Verisign, Dulles VA (69 other sites ) i. Netnod, Stockholm (37 other sites)
m. W IDE Tokyo
v client queries root server to find com DNS server e. NASA Mt View, CA
f. Internet Software C. (5 other sites)
Palo Alto, CA (and 48 other
v client queries .com DNS server to get amazon.com DNS server sites)
v client queries amazon.com DNS server to get IP address for a. Verisign, Los Angeles CA 13 root name
www.amazon.com (5 other sites)
b. USC-ISI Marina del Rey, CA
“servers”
l. ICANN Los Angeles, CA worldwide
(41 other sites)
g. US DoD Columbus,
OH (5 other sites)
2-63 2-64
TLD, authoritative servers Local DNS name server
top-level domain (TLD) servers: v does not strictly belong to hierarchy
§ responsible for com, org, net, edu, aero, jobs, museums, v each ISP (residential ISP, company, university) has
and all top-level country domains, e.g.: uk, fr, ca, jp one
§ Network Solutions maintains servers for .com TLD § also called “default name server”
§ Educause for .edu TLD v when host makes DNS query, query is sent to its
authoritative DNS servers: local DNS server
§ organization’s own DNS server(s), providing § has local cache of recent name-to-address translation
authoritative hostname to IP mappings for organization’s pairs (but may be out of date!)
named hosts § acts as proxy, forwards query into hierarchy
§ can be maintained by organization or service provider
2-65 2-66
DNS name root DNS server DNS name root DNS server
resolution example resolution example
2 2 3
v host at cis.poly.edu 3
TLD DNS server recursive query: 7
6
wants IP address for 4
gaia.cs.umass.edu v puts burden of name TLD DNS
server
5 resolution on
local DNS server contacted name local DNS server
iterated query: dns.poly.edu server dns.poly.edu 5 4
v contacted server 7 6
replies with name of 1 8 v heavy load at upper 1 8
gaia.cs.umass.edu gaia.cs.umass.edu
2-67 2-68
DNS: caching, updating records DNS records
v once (any) name server learns mapping, it caches DNS: distributed db storing resource records (RR)
mapping RR format: (name, value, type, ttl)
§ cache entries timeout (disappear) after some time (TTL)
§ TLD servers typically cached in local name servers type=A type=CNAME
• thus root name servers not often visited
§ name is hostname § name is alias name for some
v cached entries may be out-of-date (best effort § value is IP address “canonical” (the real) name
name-to-address translation!) type=NS § www.ibm.com is really
§ if name host changes IP address, may not be known § name is domain (e.g., servereast.backup2.ibm.com
Internet-wide until all TTLs expire foo.com) § value is canonical name
v update/notify mechanisms proposed IETF standard § value is hostname of
authoritative name type=MX
§ RFC 2136 server for this domain § value is name of mailserver
associated with name
2-69 2-70
additional info (variable # of RRs) additional “helpful” additional info (variable # of RRs)
info that may be used
2-71 2-72
Inserting records into DNS Attacking DNS
v example: new startup “Network Utopia”
DDoS attacks Redirect attacks
v register name networkuptopia.com at DNS registrar
v Bombard root servers v Man-in-middle
(e.g., Network Solutions)
with traffic § Intercept queries
§ provide names, IP addresses of authoritative name server
(primary and secondary) § Not successful to date v DNS poisoning
§ registrar inserts two RRs into .com TLD server: § Traffic Filtering § Send bogus relies to
(networkutopia.com, dns1.networkutopia.com, NS) § Local DNS servers DNS server, which
(dns1.networkutopia.com, 212.212.212.1, A) cache IPs of TLD caches
v create authoritative server type A record for servers, allowing root Exploit DNS for DDoS
server bypass
www.networkuptopia.com; type MX record for v Send queries with
networkutopia.com v Bombard TLD servers
spoofed source
§ Potentially more address: target IP
dangerous
v Requires amplification
2-73 2-74
2-75 2-76
File distribution: client-server vs P2P File distribution time: client-server
Question: how much time to distribute file (size F) from v server transmission: must
one server to N peers? sequentially send (upload) N F
us
§ peer upload/download capacity is limited resource file copies:
di
§ time to send one copy: F/us
network
us: server upload § time to send N copies: NF/us ui
capacity
v client: each client must
download file copy
di: peer i download
file, size F us
u1 d1 u2 capacity § dmin = min client download rate
d2
server § min client download time: F/dmin
di
uN network (with abundant time to distribute F
bandwidth) ui to N clients using
dN Dc-s > max{NF/us,,F/dmin}
client-server approach
ui: peer i upload
capacity
increases linearly in N
2-77 2-78
time to distribute F
to N clients using DP2P > max{F/us,,F/dmin,,NF/(us + Sui)}
P2P approach
increases linearly in N …
… but so does this, as each peer brings service capacity
2-79 2-80
P2P file distribution: BitTorrent P2P file distribution: BitTorrent
v file divided into 256Kb chunks
v peer joining torrent:
v peers in torrent send/receive file chunks
§ has no chunks, but will
tracker: tracks peers torrent: group of peers accumulate them over time
participating in torrent exchanging chunks of a file from other peers
§ registers with tracker to get
list of peers, connects to
subset of peers
(“neighbors”)
v while downloading, peer uploads chunks to other peers
Alice arrives … v peer may change peers with whom it exchanges chunks
… obtains list v churn: peers may come and go
of peers from tracker
… and begins exchanging v once peer has entire file, it may (selfishly) leave or
file chunks with peers in torrent (altruistically) remain in torrent
2-81 2-82
2-83 2-84
Distributed Hash Table (DHT) Simple Database
Simple database with(key, value) pairs:
v Hash table
• key: human name; value: social security #
v DHT paradigm Key Value
John Washington 132-54-3570
v Circular DHT and overlay networks Diana Louise Jones 761-55-3791
Xiaoming Liu 385-41-0902
Rakesh Gopal 441-89-1956
v Peer churn
Linda Cohen 217-66-5609
……. ………
Lisa Kobayashi 177-23-0199
2-87 2-88
Assign key-value pairs to peers Circular DHT
v rule: assign key-value pair to the peer that has the • each peer only aware of
closest ID. immediate successor and
v convention: closest is the immediate successor of predecessor.
the key.
v e.g., ID space {0,1,2,3,…,63} 1
v suppose 8 peers: 1,12,13,25,32,40,48,60
§ If key = 51, then assigned to peer 60 60 12
§ If key = 60, then assigned to peer 60
§ If key = 61, then assigned to peer 1 13
48
25
40
32 “overlay network”
2-89 2-90
2-95 2-96
Socket programming Socket programming with UDP
Two socket types for two transport services: UDP: no “connection” between client & server
§ UDP: unreliable datagram v no handshaking before sending data
§ TCP: reliable, byte stream-oriented
v sender explicitly attaches IP destination address and
port # to each packet
v rcvr extracts sender IP address and port# from
Application Example: received packet
1. Client reads a line of characters (data) from its
keyboard and sends the data to the server. UDP: transmitted data may be lost or received
2. The server receives the data and converts out-of-order
characters to uppercase. Application viewpoint:
3. The server sends the modified data to the client. v UDP provides unreliable transfer of groups of bytes
4. The client receives the modified data and displays (“datagrams”) between client and server
the line on its screen.
2-97 2-98
2-101 2-102
2-103 2-104
Example app: TCP server Chapter 2: summary
Python TCPServer our study of network apps now complete!
from socket import *
v application architectures v specific protocols:
create TCP welcoming
serverPort = 12000
socket serverSocket = socket(AF_INET,SOCK_STREAM)
§ client-server § HTTP
serverSocket.bind((‘’,serverPort))
§ P2P § FTP
server begins listening for v application service
incoming TCP requests serverSocket.listen(1) § SMTP, POP, IMAP
requirements:
print ‘The server is ready to receive’
loop forever § reliability, bandwidth, delay § DNS
while 1:
server waits on accept() v Internet transport service § P2P: BitTorrent, DHT
connectionSocket, addr = serverSocket.accept()
for incoming requests, new
socket created on return
model v socket programming: TCP,
§ connection-oriented, UDP sockets
sentence = connectionSocket.recv(1024)
read bytes from socket (but reliable: TCP
not address as in UDP) capitalizedSentence = sentence.upper()
§ unreliable, datagrams: UDP
close connection to this connectionSocket.send(capitalizedSentence)
client (but not welcoming
socket) connectionSocket.close()
2-105 2-106
Chapter 2: summary
most importantly: learned about protocols!
2-107 1-108
application
packet (www browser,
OS
Transport (TCP/UDP)
packet
copy of all Network (IP)
capture Ethernet
frames Link (Ethernet)
(pcap) sent/receive
d Physical
2-109