Вы находитесь на странице: 1из 93

Computer Networks

CS F303
BITS Pilani Sanjay K. Sahay
Department of Computer Science and Information Systems
K K Birla Goa Campus

Module2 Lectures
Application Layer

Applications need their own protocols.

These applications are part of network protocol (in the


sense that they exchange messages with their peers on
other machines via logical connection) and part of
traditional application program (in the sense that they
interact with the windowing system, the file system, and
ultimately, the user).

BITS Pilani, K K Birla Goa Campus


Application Layer: Goals
conceptual, learn about protocols by
implementation aspects examining popular
of network application application-level
protocols protocols
transport-layer HTTP
service models FTP
client-server SMTP / POP3 / IMAP
paradigm DNS

peer-to-peer creating network


paradigm applications
socket API

BITS Pilani, K K Birla Goa Campus


Some Network Apps
e-mail voice over IP (e.g., Skype)
web real-time video
text messaging conferencing
remote login social networking
P2P file sharing search
multi-user network games
streaming stored video
(YouTube, .)

BITS Pilani, K K Birla Goa Campus


application
transport

Creating Network Apps network


data link
physical

write programs that:


run on (different) end systems
communicate over network
e.g., web server software
communicates with browser
software
application
transport

no need to write software for network


data link application
physical transport
network-core devices network
data link
physical
network-core devices do not
run user applications
applications on end systems
allows for rapid app
development, propagation
BITS Pilani, K K Birla Goa Campus
Application Architecture

Protocol layers
Client-server
Peer-to-peer (P2P)
Hybrid of P2P and Client Server Architecture
Process communication
Name, address and ports
Transport

BITS Pilani, K K Birla Goa Campus


Protocol Layers

BITS Pilani, K K Birla Goa Campus


Client-Server Architecture
server:
always-on host
permanent IP address
data centers for scaling

clients:
communicate with server
client/server may be intermittently connected
may have dynamic IP addresses
do not communicate directly with
each other

BITS Pilani, K K Birla Goa Campus


P2P Architecture
not always-on server peer-peer
arbitrary end systems directly
communicate
peers request service from
other peers, provide service in
return to other peers
self scalability new peers
bring new service capacity,
as well as new service
demands
peers are intermittently
connected and change IP
addresses
complex management
BITS Pilani, K K Birla Goa Campus
Hybrid of Client-Server and P2P

Skype
voice-over-IP P2P application
centralized server: finding address of remote party:
client-client connection: direct (not through server)

Instant messaging
chatting between two users is P2P
centralized service: client presence detection/location
o user registers its IP address with central server when it comes
online
o user contacts central server to find IP addresses of buddy

BITS Pilani, K K Birla Goa Campus


Process Communicating
process: program running clients, servers
within a host client process: process that
within same host, two initiates communication
processes communicate server process: process that
using inter-process waits to be contacted
communication (defined by
OS)
v aside: applications with P2P
processes in different hosts
architectures have client
communicate by exchanging
processes & server
messages
processes

BITS Pilani, K K Birla Goa Campus


Sockets
process sends/receives messages to/from its socket
socket analogous to door
sending process shoves message out door
sending process relies on transport infrastructure on other side
of door to deliver message to socket at receiving process

application application
socket controlled by
process process app developer

transport transport
network network
link Internet link
physical physical

BITS Pilani, K K Birla Goa Campus


Addressing Processes
to receive messages, identifier includes both IP
process must have identifier address and port numbers
associated with process on
host device has unique 32-
host.
bit IP address
example port numbers:
Q: does IP address of host
HTTP server: 80
on which process runs
suffice for identifying the mail server: 25
process? to send HTTP message to
A: no, many processes www.SomeInstitute.ac.in web
can be running on same server:
host IP address: 128.119.245.12
port number: 80

BITS Pilani, K K Birla Goa Campus


App-Layer Protocol Defines
types of messages
open 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 proprietary protocols:
delineated e.g., Skype
message semantics
meaning of information
in fields
rules for when and how
processes send & respond
to messages
BITS Pilani, K K Birla Goa Campus
What Transport Does an App Need?
data integrity throughput
some apps (e.g., file transfer, v some apps (e.g.,
web transactions) require multimedia) require
100% reliable data transfer minimum amount of
throughput to be
other apps (e.g., audio) can effective
tolerate some loss v other apps (elastic apps)
make use of whatever
timing throughput they get
some apps (e.g., Internet
telephony, interactive security
games) require low delay v encryption, data integrity,
to be effective

BITS Pilani, K K Birla Goa Campus


Transport Service Requirements: Common Apps

application data loss throughput time sensitive

file transfer no loss elastic no


e-mail no loss elastic no
Web documents no loss elastic no
real-time audio/video loss-tolerant audio: 5kbps-1Mbps yes, 100s
video:10kbps-5Mbps msec
stored audio/video loss-tolerant same as above
interactive games loss-tolerant few kbps up yes, few secs
text messaging no loss elastic yes, 100s
msec
yes and no

BITS Pilani, K K Birla Goa Campus


TCP and UDP
TCP UDP
Reliable data transfer Unreliable data transfer
Packet sequence # required Sequence # optional
Every packet is acked Not acked
Lost packets are retransmitted No retransmission
May cause long delay Quick and Lossy
Connection-oriented service Connection-less service
Good for reliable and delay insensitive Good for loss-tolerant and delay sensitive
applications applications
Applications: Email, http, ftp, etc. Telephony, Streaming multimedia
Flow control: Sender wont overwhelm receiver Does not provide flow control
Congestion control: Throttle sender when Does not provide congestion control
network overloaded
Does not provide: Timing, guarantee minimum Does not provide: : Timing, guarantee minimum
throughput, security throughput, security or connection setup

BITS Pilani, K K Birla Goa Campus


Internet Apps: Application-Transport Protocol
application underlying
application layer protocol transport protocol

e-mail SMTP [RFC 2821] TCP


remote terminal access Telnet [RFC 854] TCP
Web HTTP [RFC 2616] TCP
file transfer FTP [RFC 959] TCP
streaming multimedia HTTP (e.g., YouTube), TCP or UDP
RTP [RFC 1889]
Internet telephony SIP, RTP, proprietary
(e.g., Skype) TCP or UDP

BITS Pilani, K K Birla Goa Campus


Securing TCP

TCP & UDP SSL/TLS is at app layer


vno encryption Apps use SSL libraries,
vClear-text passwords which talk to TCP
sent into socket traverse SSL/TLS socket API
Internet in clear-text v Clear-text passwords sent
SSL/TLS into socket traverse
vprovides encrypted TCP Internet encrypted
connection
vdata integrity
vend-point authentication

BITS Pilani, K K Birla Goa Campus


Web and HTTP: Review
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, e.g.,
www.SomeInstitute.ac.in/someDept/pic.gif

host name path name

BITS Pilani, K K Birla Goa Campus


HTTP Overview
HTTP: hypertext
transfer protocol
Webs application layer
protocol PC running
Firefox browser
client/server model
client: browser that
requests, receives,
(using HTTP protocol) server
and displays Web running
objects Apache Web
server
server: Web server
sends (using HTTP
protocol) objects in iphone running
response to requests Safari browser

BITS Pilani, K K Birla Goa Campus


HTTP Overview
uses TCP: HTTP is stateless
client initiates TCP server maintains no
information about past
connection (creates socket) client requests
to server, port 80
server accepts TCP aside
connection from client protocols that maintain
state are complex!
HTTP messages (application- v past history (state) must be
layer protocol messages) maintained
exchanged between browser v if server/client crashes, their views
of state may be inconsistent,
(HTTP client) and Web must be reconciled
server (HTTP server)
TCP connection closed

BITS Pilani, K K Birla Goa Campus


HTTP Connections

non-persistent HTTP persistent HTTP


at most one object sent multiple objects can
over TCP connection be sent over single
connection then TCP connection
closed between client, server
downloading multiple
objects required
multiple connections

BITS Pilani, K K Birla Goa Campus


Non-Persistent HTTP
(contains text,
suppose user enters URL:
www.SomeInstitue.ac.in/someDepartment/home.index references to 10
jpeg images)
1a. HTTP client initiates TCP
connection to HTTP server 1b. HTTP server at host
(process) at www.SomeInstitute.ac.in waiting
www.SomeInstitute.ac.in on for TCP connection at port 80.
port 80 accepts connection, notifying
client
2. HTTP client sends HTTP request
message (containing URL) into TCP
connection socket. Message 3. HTTP server receives request
indicates that client wants object message, forms response message
SomeDepartment/home.index containing requested object, and
sends message into its socket

time

BITS Pilani, K K Birla Goa Campus


Non-Persistent HTTP
4. HTTP server closes TCP
connection.
5. HTTP client receives response
message containing html file,
displays html. Parsing html file,
finds 10 referenced jpeg objects

time
6. Steps 1-5 repeated for each of 10
jpeg objects

BITS Pilani, K K Birla Goa Campus


Non-Persistent HTTP: Response Time
RTT (definition): time for a small
packet to travel from client to
server and back
initiate TCP
HTTP response time: connection
one RTT to initiate TCP RTT
connection request
file
one RTT for HTTP request time to
RTT transmit
and first few bytes of HTTP file
response to return file
received
file transmission time
non-persistent HTTP response time time
time =
2RTT+ file transmission
time
BITS Pilani, K K Birla Goa Campus
Persistent HTTP
non-persistent HTTP issues: persistent HTTP:
requires 2 RTTs per object server leaves connection
OS overhead for each TCP open after sending response
connection subsequent HTTP messages
browsers often open parallel between same client/server
TCP connections to fetch sent over open connection
referenced objects client sends requests as
soon as it encounters a
referenced object
as little as one RTT for all
the referenced objects

BITS Pilani, K K Birla Goa Campus


HTTP Request Message
two types of HTTP messages: request, response
HTTP request message:
ASCII (human-readable format) carriage return character
line-feed character
request line
(GET, POST, GET /index.html HTTP/1.1\r\n
HEAD commands) Host: www.SomeInstitute.ac.in\r\n
User-Agent: Firefox/3.6.10\r\n
Accept: text/html,application/xhtml+xml\r\n
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
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
BITS Pilani, K K Birla Goa Campus
HTTP Request Message: General Format

method sp URL sp version cr lf request


line
header field name value cr lf
header
~
~ ~
~ lines

header field name value cr lf


cr lf

~
~ entity body ~
~ body

BITS Pilani, K K Birla Goa Campus


Uploading Form Input
POST method:
web page often includes
form input
input is uploaded to
server in entity body
URL method:
uses GET method
input is uploaded in URL
field of request line:
www.SomeSite.com/animalsearch?monkeys&banana

BITS Pilani, K K Birla Goa Campus


Method Types

HTTP/1.0: HTTP/1.1:
GET GET, POST, HEAD
POST PUT
HEAD uploads file in entity
asks server to leave body to path specified
requested object out in URL field
of response DELETE
deletes file specified in
the URL field

BITS Pilani, K K Birla Goa Campus


HTTP Response Message
status line
(protocol
status code HTTP/1.1 200 OK\r\n
status phrase) Date: Sun, 26 Sep 2010 20:09:20 GMT\r\n
Server: Apache/2.0.52 (CentOS)\r\n
Last-Modified: Tue, 30 Oct 2007 17:00:02 GMT
\r\n
header ETag: "17dc6-a5c-bf716880"\r\n
Accept-Ranges: bytes\r\n
lines
Content-Length: 2652\r\n
Keep-Alive: timeout=10, max=100\r\n
Connection: Keep-Alive\r\n
Content-Type: text/html;
charset=ISO-8859-1\r\n
\r\n
data, e.g., data data data data data ...
requested
HTML file

BITS Pilani, K K Birla Goa Campus


HTTP Response Status Codes
v status code appears in 1st line in server-to-client
response message.
v some sample codes:
200 OK
request succeeded, requested object later in this msg
301 Moved Permanently
requested object moved, new location specified later in this msg
(Location:)
400 Bad Request
request msg not understood by server
404 Not Found
requested document not found on this server
505 HTTP Version Not Supported
BITS Pilani, K K Birla Goa Campus
Trying out HTTP: Client Side (Yourself)
1. Telnet to your favorite Web server:

telnet www.iucaa.ernet.in 80 opens TCP connection to port 80


(default HTTP server port) at iucaa.ernet.in.
anything typed in sent
to port 80 at iucaa.ernet.in

2. type in a GET HTTP request:


by typing this in (hit carriage
GET /~ssahay/ HTTP/1.1
return twice), you send
Host: www.iucaa.ernet.in
this minimal (but complete)
GET request to HTTP server

3. look at response message sent by HTTP server!


(or use Wireshark to look at captured HTTP request/response)
BITS Pilani, K K Birla Goa Campus
User-Server State: Cookies
example:
many Web sites use cookies
four components: Susan always access Internet
from PC
1) cookie header line of
HTTP response visits specific e-commerce
message site for first time
2) cookie header line in when initial HTTP requests
next HTTP request arrives at site, site creates:
message
unique ID
3) cookie file kept on
users host, managed entry in backend
by users browser database for ID
4) back-end database at
Web site
BITS Pilani, K K Birla Goa Campus
Cookies: Keeping the State
client
server
ebay 8734
usual http request msg Amazon server
cookie file creates ID
usual http response 1678 for user create backend
ebay 8734
set-cookie: 1678 entry database
amazon 1678

usual http request msg


cookie: 1678 cookie- access
specific
usual http response msg action

one week later:


access
ebay 8734 usual http request msg
amazon 1678 cookie: 1678 cookie-
specific
usual http response msg action
BITS Pilani, K K Birla Goa Campus
Cookies: Uses-State-Privacy
aside
what cookies can be used cookies and privacy:
for: v cookies permit sites to learn a lot
about you
authorization v you may supply name and e-mail to
sites
shopping carts
recommendations
user session state (Web
e-mail)
how to keep state:
v protocol endpoints: maintain state at sender/receiver
over multiple transactions
v cookies: http messages carry state

BITS Pilani, K K Birla Goa Campus


Web Caches: Proxy Server
goal: satisfy client request without involving origin server
user sets browser: Web
accesses via cache
browser sends all HTTP proxy
requests to cache server
client
origin
object in cache: cache server
returns object
else cache requests
object from origin
server, then returns client origin
object to client server

BITS Pilani, K K Birla Goa Campus


More About Web Caching

cache acts as both why Web caching?


client and server reduce response time
server for original for client request
requesting client
reduce traffic on an
client to origin server
institutions access link
typically cache is
Internet dense with
installed by ISP
caches: enables poor
(university, company,
content providers to
residential ISP)
effectively deliver
content (so too does
P2P file sharing)
BITS Pilani, K K Birla Goa Campus
Caching Example
assumptions:
v avg object size: 100K bits
v avg request rate from browsers to origin origin
servers:15/sec servers
v avg data rate to browsers: 1.50 Mbps public
v RTT from institutional router to any Internet
origin server: 2 sec
v access link rate: 1.54 Mbps
consequences:
v LAN utilization: 0.15% problem! 1.54 Mbps
v access link utilization = 99% access link
v total delay = Internet delay + access
delay + LAN delay institutional
= 2 sec + minutes + usecs network
1 Gbps LAN

BITS Pilani, K K Birla Goa Campus


Caching Example: Fatter Access Link
assumptions:
v avg object size: 100K bits
v avg request rate from browsers to origin origin
servers:15/sec servers
v avg data rate to browsers: 1.50 Mbps public
v RTT from institutional router to any Internet
origin server: 2 sec
v access link rate: 1.54 Mbps 154 Mbps
consequences:
v LAN utilization: 1.5% 1.54 Mbps
154 Mbps
v access link utilization = 99% access link
v total delay = Internet delay + access 0.99%
delay + LAN delay institutional
= 2 sec + minutes + usecs network
1 Gbps LAN
msecs

Cost: increased access link speed (not cheap!)


BITS Pilani, K K Birla Goa Campus
Caching Example: Install Locally
assumptions:
v avg object size: 100K bits
v avg request rate from browsers to origin origin
servers:15/sec servers
v avg data rate to browsers: 1.50 Mbps public
v RTT from institutional router to any Internet
origin server: 2 sec
v access link rate: 1.54 Mbps
consequences:
v LAN utilization: 0.15% 1.54 Mbps
v access link utilization = access link
v total delay =
?
? institutional
network
1 Gbps LAN
How to compute link
utilization, delay? local web
cache

Cost: web cache (cheap!)


BITS Pilani, K K Birla Goa Campus
Caching Example: Install Locally
Calculating access link utilization,
delay with cache: origin
suppose cache hit rate is 0.4 servers
public
40% requests satisfied at cache, Internet
60% requests satisfied at origin
v access link utilization:
60% of requests use access link 1.54 Mbps
v data rate to browsers over access link =
0.6*1.54 Mbps = 0.92 Mbps access link
utilization = 0.92/1.54 = .59 institutional
network
1 Gbps LAN
v total delay
= 0.6 * (delay from origin servers) +0.4
* (delay when satisfied at cache) local web
= 0.6 (2.0) + 0.4 (~msecs) cache
= ~ 1.2 secs
less than with 154 Mbps link (and
cheaper too!)
BITS Pilani, K K Birla Goa Campus
Conditional GET
Goal: dont send object if client server
cache has up-to-date cached
version HTTP request msg
If-modified-since: <date> object
no object transmission not
delay modified
HTTP response before
lower link utilization HTTP/1.1
304 Not Modified <date>
cache: specify date of cached
copy in HTTP request
If-modified-since:
<date> HTTP request msg
server: response contains no If-modified-since: <date> object
modified
object if cached copy is up-to-
HTTP response after
date: <date>
HTTP/1.1 200 OK
HTTP/1.1 304 Not <data>
Modified
BITS Pilani, K K Birla Goa Campus
FTP: The File Transfer Protocol
file transfer
FTP FTP FTP
user client server
interface
user
at host remote file
local file system
system

v transfer file to/from remote host


v client/server model
client: side that initiates transfer (either to/from remote)
server: remote host
v ftp: RFC 959
v ftp server: port 21

BITS Pilani, K K Birla Goa Campus


FTP: Separate Control & Data Connection
TCP control connection,
FTP client contacts FTP server at server port 21
port 21, using TCP
client authorized over control TCP data connection,
FTP server port 20 FTP
connection client server
client browses remote directory,
sends commands over control
connection v server opens another TCP
when server receives file transfer data connection to transfer
another file
command, server opens 2nd TCP v control connection: out of
data connection (for file) to client band
after transferring one file, server v FTP server maintains state:
closes data connection current directory, earlier
authentication

BITS Pilani, K K Birla Goa Campus


FTP: Commands and Responses
sample commands: sample return codes
sent as ASCII text over status code and phrase (as in
control channel HTTP)
USER username 331 Username OK,
PASS password password required
LIST return list of file in 125 data connection
current directory already open;
transfer starting
RETR filename retrieves
(gets) file 425 Cant open data
connection
STOR filename stores
(puts) file onto remote host 452 Error writing
file

BITS Pilani, K K Birla Goa Campus


outgoing
Electronic Mail message queue
user mailbox
Three major components: user
agent
user agents
mail user
mail servers server agent
simple mail transfer protocol: SMTP
SMTP mail user
server agent
SMTP
User Agent
SMTP user
agent
a.k.a. mail reader mail
server
composing, editing, reading mail user
messages e.g., Outlook, agent
Thunderbird, MAC mail client user
agent
outgoing, incoming messages
stored on server
BITS Pilani, K K Birla Goa Campus
Electronic Mail: Mail Server
mail servers: user
agent
mailbox contains incoming mail user
messages for user server agent
message queue of outgoing SMTP mail user
(to be sent) mail messages server agent

SMTP protocol between mail SMTP


servers to send email SMTP user
agent
messages mail
server
client: sending mail user
agent
server
user
server: receiving mail agent
server
BITS Pilani, K K Birla Goa Campus
outgoing
Electronic Mail message queue
user mailbox
Three major components: user
agent
user agents
mail user
mail servers server agent
simple mail transfer protocol: SMTP
SMTP mail user
server agent
SMTP
User Agent
SMTP user
agent
a.k.a. mail reader mail
server
composing, editing, reading mail user
messages e.g., Outlook, agent
Thunderbird, iPhone mail client user
agent
outgoing, incoming messages
stored on server
BITS Pilani, K K Birla Goa Campus
Electronic Mail: Mail Server
mail servers: user
agent
mailbox contains incoming mail user
messages for user server agent
message queue of outgoing SMTP mail user
(to be sent) mail messages server agent

SMTP protocol between mail SMTP


servers to send email SMTP user
agent
messages mail
server
client: sending mail user
agent
server
user
server: receiving mail agent
server
BITS Pilani, K K Birla Goa Campus
Electronic Mail SMTP (RFC 2821)
uses TCP to reliably transfer email message from client
to server, port 25
direct transfer: sending server to receiving server
three phases of transfer
handshaking (greeting)
transfer of messages
closure
command/response interaction (like HTTP, FTP)
commands: ASCII text
response: status code and phrase
messages must be in 7-bit ASCI
BITS Pilani, K K Birla Goa Campus
Scenario: A sends Message to B
1) A uses UA to compose 4) SMTP client sends A
message to message over the TCP
B@SomeInstitute.ac.in connection
2) A UA sends message to her 5) B mail server places the
mail server; message placed message in Bobs mailbox
in message queue 6) B invokes his user agent to
3) client side of SMTP opens read message
TCP connection with B mail
server

1 user mail user


mail agent
agent server server
2 3 6
4
5
As mail server Bs mail server
BITS Pilani, K K Birla Goa Campus
Sample SMTP Interaction
C: telnet daakghar.iucaa.ernet.in 25
S: 220 iucaa.ernet.in
C: HELO goa.bits-pilani.ac.in
S: 250 Hello goa.bits-pilani.ac.in, pleased to meet you
C: MAIL FROM: <ssahay@goa.bits-pilani.ac.in>
S: 250 ssahay@goa.bits-pilani.ac.in... Sender ok
C: RCPT TO: <ssahay@iucaa.ernet.in>
S: 250 ssahay@iucaa.ernet.in ... 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 iucaa.ernet.in closing connection

BITS Pilani, K K Birla Goa Campus


SMTP Interaction: Try 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)

BITS Pilani, K K Birla Goa Campus


SMTP and HTTP
SMTP uses persistent comparison with HTTP:
connections HTTP: pull
SMTP requires message SMTP: push
(header & body) to be in
7-bit ASCII both have ASCII
SMTP server uses command/response
CRLF.CRLF to interaction, status codes
determine end of message
HTTP: each object
encapsulated in its own
response msg
SMTP: multiple objects
sent in multipart msg
BITS Pilani, K K Birla Goa Campus
Mail Message Format
SMTP: protocol for exchanging
email msgs header
blank
RFC 822: standard for text line
message format:
header lines, e.g.,
To: body

From:
Subject:
different from SMTP MAIL
FROM, RCPT TO:
commands!
Body: the message
ASCII characters only
BITS Pilani, K K Birla Goa Campus
Mail Access Protocols
user mail access user
SMTP SMTP protocol
agent agent
(e.g., POP,
IMAP)

senders mail receivers mail


server server

SMTP: delivery/storage to receivers server


mail access protocol: retrieval from server
POP: Post Office Protocol [RFC 1939]: authorization,
download
IMAP: Internet Mail Access Protocol [RFC 1730]: more
features, including manipulation of stored msgs on
server
HTTP: gmail, Hotmail, Yahoo! Mail, etc.
BITS Pilani, K K Birla Goa Campus
POP3 Protocol S: +OK POP3 server ready
C: user ssahay
S: +OK
authorization phase C: pass hungry
client commands: S: +OK user successfully logged on

user: declare username C: list


pass: password S: 1 498
S: 2 912
server responses
S: .
+OK C: retr 1
-ERR S: <message 1 contents>
S: .
transaction phase, client: C: dele 1
list: list message numbers C: retr 2
S: <message 1 contents>
retr: retrieve message by number S: .
dele: delete C: dele 2
C: quit
quit
S: +OK POP3 server signing off

BITS Pilani, K K Birla Goa Campus


POP3 and IMAP
more about POP3 IMAP
previous example uses keeps all messages in one
POP3 download and place: at server
delete mode allows user to organize
Bob cannot re-read e- messages in folders
mail if he changes keeps user state across
client sessions:
POP3 download-and- names of folders and
keep: copies of messages mappings between
on different clients message IDs and folder
POP3 is stateless across name
sessions

BITS Pilani, K K Birla Goa Campus


Domain Name System
people: many identifiers: Domain Name System:
Aadhar, name, passport # distributed database
Internet hosts, routers: implemented in hierarchy of
IP address (32 bit) - used many name servers
for addressing datagrams application-layer protocol: hosts,
name, e.g., name servers communicate to
www.yahoo.com - used resolve names (address/name
by humans translation)
note: core Internet function,
Q: how to map between IP implemented as application-
address and name, and vice layer protocol
versa ? complexity at networks
edge
BITS Pilani, K K Birla Goa Campus
DNS: Service and Structure
DNS services why not centralize DNS?
hostname to IP address single point of failure
translation traffic volume
host aliasing distant centralized database
canonical, alias names
maintenance
mail server aliasing A: doesnt scale!
load distribution
replicated Web
servers: many IP
addresses correspond
to one name

BITS Pilani, K K Birla Goa Campus


DNS: A Distributed Hierarchical Database
Root DNS Servers

com DNS servers org DNS servers edu DNS servers

pbs.org poly.edu umass.edu


yahoo.com amazon.com
DNS servers DNS serversDNS servers
DNS servers DNS servers

client wants IP for www.amazon.com; 1st approx:


client queries root server to find com DNS server
client queries .com DNS server to get amazon.com DNS server
client queries amazon.com DNS server to get IP address for
www.amazon.com

BITS Pilani, K K Birla Goa Campus


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
c. Cogent, Herndon, VA (5 other sites)
d. U Maryland College Park, MD k. RIPE London (17 other sites)
h. ARL Aberdeen, MD
j. Verisign, Dulles VA (69 other sites ) i. Netnod, Stockholm (37 other sites)

e. NASA Mt View, CA m. WIDE Tokyo


f. Internet Software C. (5 other sites)
Palo Alto, CA (and 48 other
sites)

a. Verisign, Los Angeles CA 13 root name


(5 other sites) servers worldwide
b. USC-ISI Marina del Rey, CA
l. ICANN Los Angeles, CA
(41 other sites)
g. US DoD Columbus,
OH (5 other sites)

BITS Pilani, K K Birla Goa Campus


TLD and Authoritative Servers
top-level domain (TLD) servers:
responsible for com, org, net, edu, aero, jobs, museums,
and all top-level country domains, e.g.: uk, fr, ca, jp
Network Solutions maintains servers for .com TLD
Educause for .edu TLD

authoritative DNS servers:


organizations own DNS server(s), providing authoritative
hostname to IP mappings for organizations named hosts
can be maintained by organization or service provider

BITS Pilani, K K Birla Goa Campus


Local DNS

does not strictly belong to hierarchy


each ISP (residential ISP, company, university) has
one
also called default name server
when host makes DNS query, query is sent to its
local DNS server
has local cache of recent name-to-address translation pairs
(but may be out of date!)
acts as proxy, forwards query into hierarchy

BITS Pilani, K K Birla Goa Campus


root DNS server
DNS: Name Resolution
2
3
host at cs.goa.bits-pilani.ac.in TLD DNS server
wants IP address for 4
cs.iitd.ac.in 5

local DNS server


iterated query: dns.goa.bits-pilani.ac.in
v contacted server 7 6
replies with name of 1 8
server to contact
v I dont know this authoritative DNS server
dns.cs.iitd.ac.in
name, but ask this requesting host
server cs.goa.bits-pilani.ac.in

cs.iitd.ac.in

BITS Pilani, K K Birla Goa Campus


root DNS server
DNS: Name Resolution
2 3
recursive query: 7
6
v puts burden of name TLD DNS
resolution on server
contacted name local DNS server
server dns.goa-bits-pilani.ac.in 5 4
v heavy load at upper 1 8
levels of hierarchy?
authoritative DNS server
dns.iitd.ac.in
requesting host
cs.goa.bits-pilani.ac.in

cs.iitd.ac.in

BITS Pilani, K K Birla Goa Campus


DNS: Caching and Updating Records
once (any) name server learns mapping, it caches
mapping
cache entries timeout (disappear) after some time (TTL)
TLD servers typically cached in local name servers
thus root name servers not often visited

cached entries may be out-of-date (best effort


name-to-address translation!)
if name host changes IP address, may not be known
Internet-wide until all TTLs expire
update/notify mechanisms proposed IETF standard
RFC 2136
BITS Pilani, K K Birla Goa Campus
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.goa.bits-
type=NS pilani.ac.in.com is really
servereast.backup2.goa.bit
name is domain (e.g., s-pilani.ac.in
foo.com) value is canonical name
value is hostname of type=MX
authoritative name value is name of mailserver
server for this domain associated with name

BITS Pilani, K K Birla Goa Campus


DNS Protocol and Messages
query and reply messages, both with same message
format identification flags
msg header # questions # answer RRs
v identification: 16 bit # for query,
reply to query uses same # # authority RRs # additional RRs
v Flags:
One or more questions (variable # of questions)
Present in both query and response.

One or more answers (variable # of RRs).


OpCodes (common values): Query (0) Present only in response messages
Regular Query, Notify (4) DNS NOTIFY, Update
(5) DNS UPDATE Only in response messages and gives info. about
Domain names regarding authoritative servers
RCODEs (common values): NoError (0) for the query (variable # of RRs)
No Error, FormErr (1) Format Error, ServFail (2)
Sever Failure, NXDomain (3)- Non-existent Only in response messages and provides additional
Domain, NotImp(4)-Not Implemented, Refused (5)- info. To help the resolver (variable # of RRs)
Query Refused

BITS Pilani, K K Birla Goa Campus


Interacting Record into DNS
example: new startup My Network
register name mysite.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:
(mysite.com, dns1.mysite.com, NS)
(dns1.mysite.com, 212.212.212.1, A)

create authoritative server type A record for


www.mysite.com; type MX record for mysite.com

BITS Pilani, K K Birla Goa Campus


Attacking DNS
DDoS attacks Redirect attacks
Bombard root servers with vMan-in-middle
traffic Intercept queries
Not successful to date vDNS poisoning
Traffic Filtering Send bogus replies to
Local DNS servers cache DNS server, bogus
IPs of TLD servers, records in the caches
allowing root server Exploit DNS for DDoS
bypass
vSend queries with spoofed
Bombard TLD servers source address: target IP
Potentially more vRequires amplification
dangerous
BITS Pilani, K K Birla Goa Campus
Pure P2P Architecture
no always-on server
arbitrary end systems
directly communicate
peers are intermittently
connected and change IP
addresses

examples:
file distribution
(BitTorrent)
VoIP (Skype)

BITS Pilani, K K Birla Goa Campus


File Distribution: Client-Server Vs. P2P
Question: how much time to distribute file (size F)
from one server to N peers?
peer upload/download capacity is limited resource
us: server upload
capacity

di: peer i download


file, size F u1 d1 capacity
us u2 d2
server
di
uN network (with abundant
bandwidth) ui
dN
ui: peer i upload
capacity

BITS Pilani, K K Birla Goa Campus


File Distribution Time: Client-Server
server transmission: must
sequentially send (upload) N F
us
file copies:
di
time to send one copy: F/us network
ui
time to send N copies: NF/us

v client: each client must download


file copy
dmin = min client download rate
min client download time: F/dmin

time to distribute F
to N clients using
client-server approach
Dcs > max{NF/us,,F/dmin}

increases linearly in N

BITS Pilani, K K Birla Goa Campus


File Distribution Time: P2P
server transmission: must
upload at least one copy F
us
time to send one copy: F/us di
v client: each client must network
ui
download file copy
min client download time: F/dmin
v clients: as aggregate must download NF bits
max upload rate (limting max download rate) is us + ui

time to distribute F
to N clients using DP2P > max{F/us,,F/dmin,,NF/(us + ui)}
P2P approach

increases linearly in N
but so does this, as each peer brings service capacity
BITS Pilani, K K Birla Goa Campus
Client-Sever Vs. P2P: Example
client upload rate = u, F/u = 1 hour, us = 10u, dmin us
3.5
P2P
Minimum Distribution Time

3
Client-Server
2.5

1.5

0.5

0
0 5 10 15 20 25 30 35

BITS Pilani, K K Birla Goa Campus


P2P File Distribution: BitTorrent
Tracker: tracks peers
participating in torrent
Torrent: set of all peers

A arrives Peers: nodes


obtains list participating
of peers from tracker In a file distribution
and begins exchanging
file chunks with peers in torrent

Torrent File: A file containing information about the tracker, Object ID, and file
Seeds/Leechers : Peers that have complete/incomplete file.
Files are segmented into equal size chunk (256 kB)
BITS Pilani, K K Birla Goa Campus
P2P File Distribution: BitTorrent
peer joining torrent:
has no chunks, but will
accumulate them over time
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
v peer may change peers with whom it exchanges chunks
v churn: peers may come and go
v once peer has entire file, it may (selfishly) leave or (altruistically) remain in torrent

BITS Pilani, K K Birla Goa Campus


BitTorrent: Requesting & Sending File Chunks

requesting chunks: sending chunks: tit-for-tat


at any given time, different v A sends chunks to those four
peers have different subsets peers currently sending her
of file chunks chunks at highest rate
periodically, A asks each other peers are choked by A (do not
peer for list of chunks that receive chunks from her)
re-evaluate top 4 every10 secs
they have
A requests missing chunks v every 30 secs: randomly select
from peers, rarest first another peer, starts sending
chunks
optimistically unchoke this
peer
newly chosen peer may join top 4
BITS Pilani, K K Birla Goa Campus
BitTorrent: Tit-For-Tat
(1) A optimistically unchokes B
(2) A becomes one of Bs top-four providers; B reciprocates
(3) B becomes one of As top-four providers

higher upload rate: find better


trading partners, get file faster !

BITS Pilani, K K Birla Goa Campus


Distributed Hash Table (DHT)

Hash table

DHT paradigm

Circular DHT and overlay networks

Peer churn

BITS Pilani, K K Birla Goa Campus


Simple Database
Simple database with(key, value) pairs:
key: human name; value: Aadhaar Card #
Key Value
Bijay Sinha 3622-5434-3570
Anita Sharma 7621-5593-3791
Sanjay Prasad 3285-4491-0902
Rakesh Gopal 6241-8349-1956
Prashant Ghosh 1527-6635-5609
.
Sandeep Rai 7271-2673-0199

key: movie title; value: IP address


BITS Pilani, K K Birla Goa Campus
Hash Table
More convenient to store and search on numerical
representation of key
key = hash(original key)

Original Key Key Value


Bijay Sinha 8962458 3622-5434-3570
Anita Sharma 7800356 7621-5593-3791
Sanjay Prasad 1567109 3285-4491-0902
Rakesh Gopal 2360012 6241-8349-1956
Prashant Ghosh 5430938 1527-6635-5609
.
Sandeep Rai 9290124 7271-2673-0199

BITS Pilani, K K Birla Goa Campus


Distributed Hash Table
Distribute (key, value) pairs over millions of peers
pairs are evenly distributed over peers
Any peer can query database with a key
database returns value for the key
To resolve query, small number of messages
exchanged among peers
Each peer only knows about a small number of
other peers
Robust to peers coming and going (churn)
BITS Pilani, K K Birla Goa Campus
Assign Key-Value Pairs to Peers
rule: assign key-value pair to the peer that has the
closest ID.
convention: closest is the immediate successor of the
key.
e.g., ID space {0,1,2,3,,63}
suppose 8 peers: 1,12,13,25,32,40,48,60
If key = 51, then assigned to peer 60
If key = 60, then assigned to peer 60
If key = 61, then assigned to peer 1

BITS Pilani, K K Birla Goa Campus


Circular DHT
each peer only aware of
immediate successor and
predecessor.
1

12
60

13

48
25

40
32 overlay network
BITS Pilani, K K Birla Goa Campus
Resolving a Query

1 What is the value


associated with key 53 ?
value 12

60

13

48
25
O(N) messages
on avgerage to resolve
query, when there 40
are N peers 32

BITS Pilani, K K Birla Goa Campus


Circular DHT with Shortcuts
1
value
12 What is the value for
key 53
60

13

48
25

40
32
each peer keeps track of IP addresses of predecessor,
successor, short cuts.
reduced from 6 to 3 messages.
possible to design shortcuts with O(log N) neighbors,
O(log N) messages in query
BITS Pilani, K K Birla Goa Campus
Peer Churn
1
handling peer churn:
3 vpeers may come and go (churn)
15
veach peer knows address of its two

4 successors
veach peer periodically pings its
12
5 two successors to check aliveness
vif immediate successor leaves, choose
10 next successor as new immediate
8
successor
example: peer 5 abruptly leaves

BITS Pilani, K K Birla Goa Campus


Peer Churn
1

3 handling peer churn:


15
vpeers may come and go (churn)
veach peer knows address of its two
4
successors
12 veach peer periodically pings its
two successors to check aliveness
10 vif immediate successor leaves, choose next
8
successor as new immediate successor

example: peer 5 abruptly leaves


peer 4 detects peer 5s departure; makes 8 its immediate successor
4 asks 8 who its immediate successor is; makes 8s immediate successor its
second successor.

BITS Pilani, K K Birla Goa Campus


Thanks!!!
Queries?

BITS Pilani, K K Birla Goa Campus

Вам также может понравиться