0% found this document useful (0 votes)
42 views

Application Layer: Computer Networking: A Top Down Approach

The document provides an overview of the application layer and HTTP protocol. It discusses application layer architectures like client-server and peer-to-peer. It also describes how processes communicate across hosts using sockets and addresses. Finally, it summarizes the basic request-response behavior of HTTP where a client makes requests to a server using TCP connections.

Uploaded by

Adam Sanadi
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

Application Layer: Computer Networking: A Top Down Approach

The document provides an overview of the application layer and HTTP protocol. It discusses application layer architectures like client-server and peer-to-peer. It also describes how processes communicate across hosts using sockets and addresses. Finally, it summarizes the basic request-response behavior of HTTP where a client makes requests to a server using TCP connections.

Uploaded by

Adam Sanadi
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 141

Chapter 2

Application Layer
Computer
Networking: A
Top Down
Approach
6th edition
Jim Kurose, Keith Ross
Addison-Wesley
March 2012

Application Layer 2-1


Chapter 2: outline
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
2.4 electronic mail
 SMTP, POP3, IMAP
2.5 DNS

Application Layer 2-2


Principles of network applications
 Network application development is writing
programs that run on different end systems and
communicate with each other over the network.

 Example:
 Web application
 Peer-to-peer file sharing system

 Need not to write software that runs on network


core devices, such as routers or link-layer switches.

Application Layer 2-3


Network Application Architectures

 An application’s architecture is distinctly


different from the network architecture.

 Two predominant architectural paradigms


used in modern network applications:
 Client-Server
 Peer-to-Peer (P2P)

Application Layer 2-4


Client-Server Architecture :
 Always-on host, called the server, which services requests
from many other hosts, called clients.

 Characteristics:
 Clients do not directly communicate with each other

 The server has a fixed, well-known address, called an IP


address. Because the server is always on, a client can
always contact the server by sending a packet to the
server’s IP address.

 Applications with a client-server architecture include the


Web, FTP, Telnet, and e-mail.

Application Layer 2-5


 A single-server host is incapable of keeping up with
all the requests from clients. For this reason, a data
center, housing a large number of hosts, is often used
to create a powerful virtual server.

 Disadvantage:
 Infrastructure Intensive
 service providers must pay recurring
interconnection and bandwidth costs for sending
data and receiving data to and from Internet.

Application Layer 2-6


P2P architecture
 There is minimal (or no) reliance on dedicated
servers in data centers.
 Application exploits direct communication
between pairs of intermittently connected hosts,
called peers.
 The peers are not owned by the service provider,
but are instead desktops and laptops controlled by
users.
 Examples:
 Bit torrent, Limewire ,Skype

Application Layer 2-7


Features:
 Self-scalability
 Cost effective

Challenges:
 ISP Friendly
 Security
 Incentives

Application Layer 2-8


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

Application Layer 2-9


 In the context of a communication session between a
pair of processes, the process that initiates the
communication is labeled as the client. The process
that waits to be contacted to begin the session is the
server.
 In the Web, a browser process initializes contact with
a Web server process; hence the browser process is
the client and the Web server process is the server.
 P2P file sharing, when Peer A asks Peer B to send a
specific file, Peer A is the client and Peer B is the
server in the context of this specific communication
session.

Application Layer 2-10


Interface Between the Process and the
Computer Network
 A process sends messages into, and receives messages
from, the network through a software interface called a
socket.
 A socket is the interface between the application layer
and the transport layer within a host.

 It is also referred to as the Application Programming


Interface (API) between the application and the
network, since the socket is the programming interface
with which network applications are built.

 The application developer has control of everything on


the application-layer side of the socket but has little
control of the transport-layer side of the socket.

Application Layer 2-12


Addressing Processes
 In order for a process running on one host to send
packets to a process running on another host, the
receiving process needs to have an address.

 To identify the receiving process, two pieces of


information need to be specified:
(1) the address of the host and
(2) an identifier that specifies the receiving
process in the destination host.

 IP address
 port number
Application Layer 2-13
Transport Services Available to
Applications
 Services that a transport-layer protocol can offer
to applications invoking it can be classified into 4
dimensions :
1. Reliable data transfer
2. Throughput
3. Timing
4. Security

Application Layer 2-14


Transport Services Provided by
the Internet
 TCP Services
 Connection-oriented service
 Reliable data transfer service

 UDP Services

Application Layer 2-15


Application-Layer Protocols
 An application-layer protocol defines how an
application’s processes, running on different end
systems, pass messages to each other.
 An application-layer protocol defines:
 The types of messages exchanged, for example,
request messages and response messages
 The syntax of the various message types, such as the
fields in the message and how the fields are
delineated
 The semantics of the fields, that is, the meaning of
the information in the fields
 Rules for determining when and how a process
sends messages and responds to messages
Application Layer 2-16
Chapter 2: outline
2.1 principles of network 2.6 P2P applications
applications 2.7 socket programming
 app architectures with UDP and TCP
 app requirements
2.2 Web and HTTP
2.3 FTP
2.4 electronic mail
 SMTP, POP3, IMAP
2.5 DNS

Application Layer 2-17


Web and HTTP
 Web operates on demand.
 Easy for any individual to make information
available over the Web—everyone can become a
publisher at extremely low cost.
 Hyperlinks and search engines help us navigate
through an ocean of Web sites.
 Graphics stimulate our senses.
 Forms, JavaScript, Java applets, and many other
devices enable us to interact with pages and sites.
 Web serves as a platform for many killer
applications

Application Layer 2-18


 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.someschool.edu/someDept/pic.gif

host name path name

 Web browser
 Web server
Application Layer 2-19
Overview of HTTP
HTTP: hypertext transfer protocol
 Web’s application layer protocol

 HTTP is implemented in two programs: a client program


and a server program.

 The client program and server program, executing on


different end systems, talk to each other by exchanging
HTTP messages.

 HTTP defines the structure of these messages and how


the client and server exchange the messages.

Application Layer 2-20


HTTP overview

HT
TP
r equ
PC running e
st
HT
Firefox browser TP
res
pon
se

t
u es
req server
T P n se
HT s po running
r e Apache Web
T TP
H server

iphone running
Safari browser

HTTP request-response behavior


HTTP overview (continued)
Uses TCP:
•Client initiates TCP connection (creates socket) to
server, port 80
•Server accepts TCP connection from client HTTP
messages exchanged between browser (HTTP client)
and Web server (HTTP server)
•TCP connection closed
•Stateless protocol-server sends requested files to
clients without storing any state information about
the client.
Application Layer 2-22
Non persistent and persistent
connections

 Each request/response pair be sent over a


separate TCP connection - Non persistent
connection

 All of the requests and their corresponding


responses be sent over the same TCP
connection -Persistent connection

Application Layer 2-23


HTTP with Non-Persistent Connections
Example: page consists of a base HTML file and 10 JPEG images
suppose user enters URL:
www.someSchool.edu/someDepartment/home.index

1a. HTTP client initiates TCP


connection to HTTP server
www.someSchool.edu on port 80 1b. HTTP server“ accepts”
connection, notifying client

2. HTTP client sends HTTP


request message into TCP
connection socket. Message 3. HTTP server receives request
indicates that client wants message, forms response
object message containing requested
someDepartment/home.index object, and sends message into
its socket
time
Non-persistent HTTP (cont.)
4. HTTP server closes TCP
connection.
 5. HTTP client receives response
message , examines the HTML file,
and finds references to the 10 JPEG
objects.

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

Application Layer 2-25


Non-persistent HTTP: response time
 Round-Trip Time: time it takes for a small packet to
travel from client to server and then back to the client.

initiate TCP
connection
RTT
request
file
time to
RTT transmit
file
file
received

time time
HTTP with Persistent Connections

non-persistent HTTP persistent HTTP:


issues:  server leaves connection
 A brand-new connection open after sending
must be established and response
maintained for each  subsequent HTTP
requested object. messages between same
 Each object suffers a client/server sent over
delivery delay of two RTTs open connection
 client sends requests as
soon as it encounters a
referenced object
 as little as one RTT for all
the referenced objects

Application Layer 2-27


HTTP with Persistent Connections
 HTTP server closes a connection when it isn’t used
for a certain time (a configurable timeout interval).

 The default mode of HTTP uses persistent


connections with pipelining

Application Layer 2-28


HTTP Message Format
 Two types of HTTP messages: request, response

 HTTP Request Message

GET /somedir/page.html HTTP/1.1


Host: www.someschool.edu
Connection: close
User-agent: Mozilla/5.0
Accept-language: fr

Application Layer 2-29


 The first line of an HTTP request message is
called the request line; subsequent lines are called
the header lines.
 The request line has three fields: the method field,
the URL field, and the HTTP version field.
 The method field includes GET, POST, HEAD,
PUT, and DELETE.
 host on which the object resides.
 The browser is telling the server that it doesn’t
want to bother with persistent connections
 browser type that is making the request to the
server

Application Layer 2-30


Method field:

Application Layer 2-31


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

Application Layer 2-32


HTTP response message
HTTP/1.1 200 OK
Connection: close
Date: Tue, 09 Aug 2011 15:44:04 GMT
Server: Apache/2.2.3 (CentOS)
Last-Modified: Tue, 09 Aug 2011 15:11:03 GMT
Content-Length: 6821
Content-Type: text/html

(data data data data data ...)

Application Layer 2-33


HTTP response status codes
 status code appears in 1st line in server-to-client
response message.
 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
Application Layer 2-34
Application Layer 2-35
General format of an HTTP response
message

Application Layer 2-36


Trying out HTTP (client side) for yourself
1. Telnet to your favorite Web server:

telnet cis.poly.edu 80 opens TCP connection to port 80


(default HTTP server port) at cis.poly.edu.
anything typed in sent
to port 80 at cis.poly.edu

2. type in a GET HTTP request:


GET /~ross/ HTTP/1.1 by typing this in (hit carriage
Host: cis.poly.edu return twice), you send
this minimal (but complete)
GET request to HTTP server

3. look at response message sent by HTTP server!

Application Layer 2-37


User-server Interaction: cookies
 It is often desirable for a Web site to
identify users, either because the server
wishes to restrict user access or because
it wants to serve content as a function of
the user identity.

 For these purposes, HTTP uses cookies.


Cookies, defined in [RFC 6265], allow
sites to keep track of users. Most major
commercial Web sites use cookies today.

Application Layer 2-38


Contd…
Four components:
1) cookie header line in the HTTP
response message
2) cookie header line in next HTTP request
message
3) cookie file kept on user’s host, managed
by user’s browser
4) back-end database at Web site

Application Layer 2-39


Application Layer 2-40
 When the request comes into the Amazon Web server, the
server creates a unique identification number and creates an
entry in its back-end database that is indexed by the
identification number.
 The Amazon Web server then responds to Susan’s browser,
including in the HTTP response a Set-cookie: header, which
contains the identification number.
 When Susan’s browser receives the HTTP response message, it
sees the Setcookie: header. The browser then appends a line to
the special cookie file that it manages.
 This line includes the hostname of the server and the
identification number in the Set-cookie: header.

 As Susan continues to browse the Amazon site, each time she


requests a Web page, her browser consults her cookie file,
extracts her identification number for this site, and puts a
cookie header line that includes the identification number in the
HTTP request.
 Cookies can thus be used to create a user
session layer on top of stateless HTTP

 Although cookies often simplify the Internet


shopping experience for the user, they are
controversial because they can also be
considered as an invasion of privacy.

 Using a combination of cookies and user-


supplied account information, a Web site can
learn a lot about a user and potentially sell this
information to a third party.

Application Layer 2-42


Web Caching
 A Web cache—also called a proxy server—is a
network entity that satisfies HTTP requests on the
behalf of an origin Web server.

 The Web cache has its own disk storage and keeps
copies of recently requested objects in this storage.

 User’s browser can be configured so that all of the


user’s HTTP requests are first directed to the Web
cache.

Application Layer 2-43


Web caches (proxy server)
Goal: satisfy client request without involving origin server

HT proxy
TP u e st
req server req
HT ues P se
client TP t H TT p on
res res origin
pon T P
se HT server
u est
req e
TT P o ns
p
H r es
T TP
H

client origin
server

Application Layer
More about Web caching
 A cache is both a Why Web caching?
server and a client at  reduce response time for
the same time. client request.
 Web cache is  reduce traffic on an
purchased and institution’s access link.
installed by an
ISP(university,
company, residential
ISP)

Application Layer 2-45


Caching example:

Application Layer 2-46


assumptions:
 average object size: 1M bits
 average request rate from browsers to origin
servers:15/sec
 RTT from institutional router to any origin server: 2
sec (Internet delay)

 total response time = Internet delay + access delay +


LAN delay

Application Layer 2-47


 The traffic intensity on the LAN is
(15 requests/sec) (1 Mbits/request)/(100 Mbps) = 0.15

 Traffic intensity on the access link (from the Internet


router to institution router) is
(15 requests/sec) (1 Mbits/request)/(15 Mbps) = 1

 The average response time to satisfy requests is going


to be on the order of minutes.

 One possible solution is to increase the access rate


from 15 Mbps to, say, 100 Mbps. But institution must
upgrade its access link from 15 Mbps to 100 Mbps, a
costly proposition.
Application Layer 2-48
Application Layer 2-49
 Cache provides a hit rate of 0.4 for this institution.

 The remaining 60 percent of the requests still need to be


satisfied by the origin servers. But with only 60 percent
of the requested objects passing through the access link,
the traffic intensity on the access link is reduced from
1.0 to 0.6.

 Typically, a traffic intensity less than 0.8 corresponds to


a small delay, say, tens of milliseconds, on a 15 Mbps
link. This delay is negligible compared with the two
second Internet delay.

 Of course, have to purchase and install a Web cache.


But this cost is low—many caches use public-domain
software that runs on inexpensive PCs.
Application Layer 2-50
Conditional GET
 The copy of an object residing in the cache may
be stale - the object housed in the Web server
may have been modified since the copy was
cached at the client.

 HTTP has a mechanism that allows a cache to


verify that its objects are up to date. This
mechanism is called the conditional GET.
 An HTTP request message is a so-called
conditional GET message if
(1) the request message uses the GET method
(2) the request message includes an If-
Modified-Since: header line

Application Layer 2-51


Conditional GET
client server
 Goal: not send object if
cache has up-to-date
cached version HTTP request msg
If-modified-since: <date> object
 no object transmission
not
delay
modified
 lower link utilization HTTP response
before
 cache: specify date of HTTP/1.0
304 Not Modified <date>
cached copy in HTTP
request
If-modified-since: <date>
 server: response HTTP request msg
contains no object if If-modified-since: <date> object
cached copy is up-to- modified
date: HTTP response after
HTTP/1.0 304 Not HTTP/1.0 200 OK <date>
Modified <data>
Application Layer 2-52
Chapter 2: outline
2.1 principles of network 2.6 P2P applications
applications 2.7 socket programming
 app architectures with UDP and TCP
 app requirements
2.2 Web and HTTP
2.3 FTP
2.4 electronic mail
 SMTP, POP3, IMAP
2.5 DNS

Application Layer 2-53


File Transfer: FTP
 The user is sitting in front of one host (the local
host) and wants to transfer files to or from a
remote host.

 After providing this authorization information,


the user can transfer files from the local file
system to the remote file system and vice versa.
file transfer
FTP FTP FTP
user client server
interface
user
at host remote file
local file system
system

Application Layer 2-54


Contd..

 HTTP and FTP are both file transfer protocols and


have many common characteristics - both run on top
of TCP.
 Important differences:
 FTP uses two parallel TCP connections to
transfer a file, a control connection and a data
connection.
 FTP is said to send its control information out-of-
band.
 Data connections are non-persistent.
 FTP server must maintain state about the user.
Application Layer 2-55
FTP: separate control, data connections
TCP control connection,
 FTP client contacts FTP server server port 21
at port 21, using TCP
 client authorized over control TCP data connection,
connection FTP server port 20 FTP
client server
 client browses remote
directory, sends commands
over control connection  after transferring one file,
server closes data
 when server receives file connection
transfer command, server
opens 2nd TCP data connection  server opens another TCP
(for file) to client data connection to transfer
another file

Application Layer 2-56


FTP Commands and Replies
 The commands, from client to server, and
replies, from server to client, are sent
across the control connection in 7-bit
ASCII format.

 In order to delineate successive


commands, a carriage return and line feed
end each command.

 Each command consists of four uppercase


ASCII characters, some with optional
arguments.
Application Layer 2-57
FTP commands:
 USER username: Used to send the user identification
to the server.
 PASS password: Used to send the user password to
the server.
 LIST: Used to ask the server to send back a list of all
the files in the current remote directory.
 RETR filename: Used to retrieve a file from the
current directory of the remote host.
 STOR filename: Used to store a file into the current
directory of the remote host.

Application Layer 2-58


FTP Replies:
 331 Username OK, password required

 125 Data connection already open; transfer


starting

 425 Can’t open data connection

 452 Error writing file

Application Layer 2-59


Chapter 2: outline
2.1 principles of network 2.6 P2P applications
applications 2.7 socket programming
 app architectures with UDP and TCP
 app requirements
2.2 Web and HTTP
2.3 FTP
2.4 electronic mail
 SMTP, POP3, IMAP
2.5 DNS

Application Layer 2-60


Electronic Mail in the Internet
 It remains one of the Internet’s most important
and utilized applications.
 e-mail is an asynchronous communication
medium—people send and read messages when it
is convenient for them, without having to
coordinate with other people’s schedules.
 In contrast with postal mail, electronic mail is fast,
easy to distribute, and inexpensive.
 Modern e-mail has many powerful features,
including messages with attachments, hyperlinks,
HTML-formatted text, and embedded photos.

Application Layer 2-61


Application Layer 2-62
Three major components:
1. User agents
2. Mail servers
3. Simple Mail Transfer Protocol: SMTP

 Mailbox
 Message queue

Application Layer 2-63


 User agents allow users to read, reply to, forward,
save, and compose messages.
 When Alice is finished composing her message,
her user agent sends the message to her mail
server, where the message is placed in the mail
server’s outgoing message queue.
 When Bob wants to read a message, his user agent
retrieves the message from his mailbox in his mail
server.
 A typical message starts its journey in the sender’s
user agent, travels to the sender’s mail server, and
travels to the recipient’s mail server, where it is
deposited in the recipient’s mailbox.
 When Bob wants to access the messages in his
mailbox, the mail server containing his mailbox
authenticates Bob.
Application Layer 2-64
 If Alice’s server cannot deliver mail to Bob’s server,
Alice’s server holds the message in a message queue
and attempts to transfer the message later.

 Reattempts are often done every 30 minutes or so; if


there is no success after several days, the server
removes the message and notifies the sender (Alice)
with an e-mail message.

Application Layer 2-65


 SMTP is the principal application-layer protocol
for Internet electronic mail.

 It uses the reliable data transfer service of TCP


to transfer mail from the sender’s mail server to
the recipient’s mail server

 SMTP has two sides: a client side, which


executes on the sender’s mail server, and a
server side, which executes on the recipient’s
mail server.

Application Layer 2-66


SMTP
 SMTP defined in RFC 5321. SMTP transfers messages
from senders’ mail servers to the recipients’ mail
servers.

 Uses TCP to reliably transfer email message from


client to server, port 25

 it restricts the body (not just the headers) of all mail


messages to simple 7-bit ASCII.

 But today -it requires binary multimedia data to be


encoded to ASCII before being sent over SMTP; and it
requires the corresponding ASCII message to be
decoded back to binary after SMTP transport.
•SMTP does not normally use intermediate mail servers for
sending mail, even when the two mail servers are located at
opposite ends of the world.

Application Layer 2-68


Sample SMTP interaction
S: 220 yahoo.com
C: HELO gmail.com
S: 250 Hello gmail.com, pleased to meet you
C: MAIL FROM: <[email protected]>
S: 250 [email protected]... Sender ok
C: RCPT TO: <[email protected]>
S: 250 [email protected] ... Recipient ok
C: DATA
S: 354 Enter mail, end with "." on a line by itself
C: How are you?
C: How is your new job?
C: .
S: 250 Message accepted for delivery
C: QUIT
S: 221 yahoo.com closing connection Application Layer 2-69
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)

Application Layer 2-70


Comparison with HTTP:
 Both protocols are used to transfer files from one
host to another.
 Both persistent HTTP and SMTP use persistent
connections.

 HTTP is mainly a pull protocol whereas SMTP is a


push protocol.
 SMTP requires each message, including the body of
each message, to be in 7-bit ASCII format. HTTP
data does not impose this restriction.
 In HTTP each object encapsulated as separate
message, whereas SMTP places all of the message’s
objects into one message.
Mail message formats:
 When an e-mail message is sent from one person
to another, a header containing peripheral
information precedes the body of the message
itself.

From: [email protected]
To: [email protected]
Subject: Searching for the meaning of life.

Application Layer 2-72


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

Application Layer 2-73


Mail access protocol:

Application Layer 2-74


POP3:
 POP3 is an extremely simple mail access protocol.
short and quite readable. Because the protocol is so
simple, its functionality is rather limited.

 POP3 begins when the user agent opens a TCP


connection to the mail server on port 110.

 POP3 progresses through three phases:


1. Authorization
2. Transaction
3. Update.
Application Layer 2-75
POP3 protocol
S: +OK POP3 server ready
C: user bob
Authorization phase S: +OK
 client commands: C: pass hungry
S: +OK user successfully logged on
 user: declare username
C: list
 pass: password
S: 1 498
 server responses
S: 2 912
 +OK S: .
 -ERR C: retr 1
S: <message 1 contents>
Transaction phase, client: S: .
 list: list message numbers C: dele 1
 retr: retrieve message by C: retr 2
number S: <message 1 contents>
S: .
 dele: delete
C: dele 2
 quit C: quit
S: +OK POP3 server signing off
Application Layer 2-76
Transaction phase
 A user agent using POP3 can be configured to
1. download and delete
2. download and keep

 Download-and-delete mode- the user agent will


issue the list, retr, and dele commands.

 Download-and keep mode - the user agent leaves the


messages on the mail server after downloading them.

Application Layer 2-77


Update phase:
 After processing quit command POP3 server
enters update phase and removes message from
mailbox.

 During a POP3 session between a user agent and


the mail server, the POP3 server maintains some
state information; in particular, it keeps track of
which user messages have been marked deleted.

 However, the POP3 server does not carry state


information across POP3 sessions.

Application Layer 2-78


 With POP3 access, once Bob has downloaded his
messages to the local machine, he can create mail
folders and move the downloaded messages into the
folders.
 Bob can then delete messages, move messages across
folders, and search for messages (by sender name or
subject).
 But this paradigm—namely, folders and messages in
the local machine—poses a problem for the nomadic
user, who would prefer to maintain a folder hierarchy
on a remote server that can be accessed from any
computer.
 This is not possible with POP3—the POP3 protocol
does not provide any means for a user to create
remote folders and assign messages to folders.

Application Layer 2-79


IMAP
 An IMAP server will associate each message with a folder.

 Provides commands to allow users to create folders and


move messages from one folder to another.

 Provides commands that allow users to search remote


folders for messages matching specific criteria.

 IMAP server maintains user state information across IMAP


sessions

 Has commands that permit a user agent to obtain


components of messages.

Application Layer 2-80


Web-Based E-Mail
 More and more users today are sending and accessing
their e-mail through their Web browsers.
 Hotmail introduced Web-based access in the mid 1990s.
Now Web-based e-mail is also provided by Google,
Yahoo
 With this service, the user agent is an ordinary Web
browser, and the user communicates with its remote
mailbox via HTTP.
 When a recipient, such as Bob, wants to access a
message in his mailbox, the e-mail message is sent from
Bob’s mail server to Bob’s browser using the HTTP
protocol.
 When a sender, such as Alice, wants to send an e-mail
message, the e-mail message is sent from her browser to
her mail server over HTTP. Application Layer 2-81
DNS—The Internet’s Directory Service
 DNS is a directory service that translates hostnames to
IP addresses.
 The DNS is

(1) a distributed database implemented in a hierarchy of


DNS servers.
(2) an application-layer protocol that allows hosts to
query the distributed database.

 The DNS protocol runs over UDP and uses port 53


 DNS is commonly employed by other application-
layer protocols—including HTTP, SMTP, and FTP—
to translate user-supplied hostnames to IP addresses..
Application Layer 2-82
1. The user machine runs the client side of the DNS
application.
2. The browser extracts the hostname, from the
URL and passes the hostname to the client side of
the DNS application.
3. The DNS client sends a query containing the
hostname to a DNS server.
4. The DNS client eventually receives a reply,
which includes the IP address for the hostname.
5. Once the browser receives the IP address from
DNS, it can initiate a TCP connection to the
HTTP server process located at port 80 at that IP
address.

 DNS adds an additional delay


Application Layer 2-83
Other important services:
1. Host aliasing.

2. Mail server aliasing

3. Load distribution

Application Layer 2-84


Other services:
 Host aliasing: A host with a complicated hostname can have
one or more alias names. DNS can be invoked by an
application to obtain the canonical hostname for a supplied
alias hostname as well as the IP address of the host.

 Mail server aliasing: DNS can be invoked by a mail


application to obtain the canonical hostname for a supplied
alias hostname as well as the IP address of the host.

 Load distribution: DNS is also used to perform load


distribution among replicated servers, such as replicated
Web servers.
For replicated Web servers, a set of IP addresses is thus
associated with one canonical hostname. The DNS database
contains this set of IP addresses.
Overview of How DNS Works
 Centralized design

 The problems with a centralized design include:


1. A single point of failure
2. Traffic volume
3. Distant centralized database
4. Maintenance

Application Layer 2-86


A Distributed, Hierarchical
Database
 DNS uses a large number of servers, organized in
a hierarchical fashion and distributed around the
world. The mappings are distributed across the
DNS servers.

 Three classes of DNS servers


1. Root DNS servers
2. Top-level domain (TLD) DNS servers
3. Authoritative DNS servers

Application Layer 2-87


Application Layer 2-88
1. Root DNS servers: In the Internet there are 13 root
DNS servers most of which are located in North
America.
2. Top-level domain (TLD) servers. These servers
are responsible for top-level domains.
3. Authoritative DNS servers: Every organization
with publicly accessible hosts on the Internet must
provide publicly accessible DNS records that map
the names of those hosts to IP addresses.

 local DNS server :does not strictly belong to the


hierarchy of servers but is nevertheless central to the
DNS architecture.

Application Layer 2-89


DNS name root DNS server
resolution example
2
 host at cis.poly.edu 3
TLD DNS server
wants IP address for 4
gaia.cs.umass.edu
5

local DNS server


iterated query: dns.poly.edu
 contacted server replies 7 6
with name of server to 1 8
contact
 “I don’t know this authoritative DNS server
dns.cs.umass.edu
name, but ask this requesting host
server” cis.poly.edu

gaia.cs.umass.edu

Application Layer 2-90


Application Layer 2-91
DNS name root DNS server
resolution example
2 3
recursive query: 7
6
 puts burden of name TLD DNS
resolution on server
contacted name local DNS server
server dns.poly.edu 5 4
 heavy load at upper 1 8
levels of hierarchy?
authoritative DNS server
dns.cs.umass.edu
requesting host
cis.poly.edu

gaia.cs.umass.edu

Application Layer 2-92


DNS Caching
 In a query chain, when a DNS server receives a
DNS reply , it can cache the mapping in its local
memory.

 If a hostname/IP address pair is cached in a DNS


server and another query arrives to the DNS server
for the same hostname, the DNS server can provide
the desired IP address, even if it is not authoritative
for the hostname.

Application Layer 2-93


DNS Records and Messages
 The DNS servers that together implement the DNS
distributed database store resource records (RRs) -
provide hostname-to-IP address mappings.
 Each DNS reply message carries one or more
resource records.

Format: (Name, Value, Type, TTL)

 TTL is the time to live of the resource record; it


determines when a resource should be removed
from a cache.

Application Layer 2-94


DNS resource records:
 If Type=A, then Name is a hostname and Value is
the IP address for the hostname.
Ex: (relay1.bar.foo.com, 145.37.93.126, A)

 If Type=NS, then Name is a domain and Value is


the hostname of an authoritative DNS server that
knows how to obtain the IP addresses for hosts in
the domain
Example (foo.com, dns.foo.com, NS)

Application Layer 2-95


 If Type=CNAME, then Value is a canonical
hostname for the alias hostname Name
Example (foo.com, relay1.bar.foo.com, CNAME)

 If Type=MX, then Value is the canonical name of


a mail server that has an alias hostname Name.
Example (foo.com, mail.bar.foo.com, MX)

Application Layer 2-96


 If a DNS server is authoritative for a particular
hostname, then the DNS server will contain a
Type A record for the hostname.

 If a server is not authoritative for a hostname, then


the server will contain a Type NS record for the
domain that includes the hostname; it will also
contain a Type A record that provides the IP
address of the DNS server in the Value field of the
NS record.

Application Layer 2-97


DNS protocol, messages

Application Layer 2-98


Inserting Records into the DNS
Database
 A registrar is a commercial entity that verifies the
uniqueness of the domain name, enters the domain
name into the DNS database, and collects a small fee
from you for its services.
 Prior to 1999, a single registrar, Network Solutions,
had a monopoly on domain name registration for com,
net, and org domains. But now there are many
registrars competing for customers, and the Internet
Corporation for Assigned Names and Numbers
(ICANN) accredits the various registrars.
 When you register the domain name
networkutopia.com with some registrar, you also need
to provide the registrar with the names and IP
addresses of your primary and secondary authoritative
DNS servers.
 Suppose the names and IP addresses are
dns1.networkutopia.com, dns2.networkutopia.com,
212.212.212.1, and 212.212.212.2.
 For each of these two authoritative DNS servers, the
registrar would then make sure that a Type NS and a
Type A record are entered into the TLD com servers.

(networkutopia.com, dns1.networkutopia.com, NS)

(dns1.networkutopia.com, 212.212.212.1, A)
Application Layer 2-100
Peer-to-Peer Applications

Application Layer 2-101


Peer-to-Peer Applications
 A P2P architecture, there is minimal (or no)
reliance on always-on infrastructure servers.
 Pairs of intermittently connected hosts, called peers,
communicate directly with each other.
 The peers are not owned by a service provider, but
are instead desktops and laptops controlled by
users.
 3 basic application:
 File distribution : bit Torrent system
 Database distributed over a large community of peers:
DHT
 P2P Internet telephony :skype

Application Layer 2-102


P2P file distribution:
 In P2P file distribution, each peer can redistribute
any portion of the file it has received to any other
peers, thereby assisting the server in the
distribution process.

 The most popular P2P file distribution protocol is


BitTorrent, originally developed by Bram Cohen.

 Self scalable

Application Layer 2-103


Scalability of P2P Architectures

The distribution time is the time it takes to get a copy


of the file to all N peers.
Distribution time for the client-
server architecture
 In the client-server architecture, none of the peers aids
in distributing the file.

 the distribution time increases linearly with the


number of peers N.
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
 time to send N copies: NF/us ui

 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
Dc-s > max{NF/us,,F/dmin}
client-server approach

increases linearly in N
Application Layer 2-106
File distribution time: P2P
 server transmission: must
upload at least one copy F
us
 time to send one copy: F/us
di
 client: each client must network
download file copy ui
 min client download time: F/dmin
 clients: as aggregate must download NF bits
 max upload rate (limting max download rate) is us + Sui

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

increases linearly in N …
… but so does this, as each peer brings service capacity
Application Layer 2-107
BitTorrent
 BitTorrent is a popular P2P protocol for file
distribution.
 Collection of all peers participating in the
distribution of a particular file is called a torrent.
 Peers in a torrent download equal-size chunks of
the file from one another, with a typical chunk size
of 256 KBytes.
 While it downloads chunks it also uploads chunks
to other peers.
 Once a peer has acquired the entire file, it may
leave the torrent, or remain in the torrent and
continue to upload chunks to other peers.
Application Layer 2-108
How BitTorrent works?
 Each torrent has an infrastructure node called a tracker.
When a peer joins a torrent, it registers itself with the tracker and
periodically informs the tracker that it is still in the torrent.

tracker: tracks peers


participating in torrent

Alice arrives …
… obtains list
of peers from tracker
… and begins exchanging
file chunks with peers in torrent

Application Layer 2-109


BitTorrent: requesting, sending file
chunks
requesting chunks:
 at any given time, different peers have different subsets of
file chunks
 periodically, Alice asks each peer for list of chunks that
they have
 Alice will have a subset of chunks and will know which
chunks her neighbors have.
 Alice will make two important decisions:

1. Which chunks should she request first from her


neighbors?
2. to which of her neighbors should she send requested
chunks
 Alice requests missing chunks from peers, rarest first
Application Layer 2-110
sending chunks:
 Alice gives priority to the neighbors that are
currently supplying her data at the highest rate.
 Alice sends chunks to those four peers currently
sending her chunks at highest rate - unchoked
 other peers are choked by Alice (do not receive
chunks from her)
 re-evaluate top 4 every10 secs
 every 30 secs: randomly select another peer, starts
sending chunks --“optimistically unchoke” .
 newly chosen peer may join top 4
 All other neighboring peers besides these five
peers are “choked,” that is, they do not receive
any chunks from Alice.
Application Layer 2-111
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

higher upload rate: find better


trading partners, get file faster !

Application Layer 2-112


Distributed Hash Table (DHT)
 How to implement a simple database in a P2P
network.
 A centralized version of this simple database,
which will simply contain (key, value) pairs.
Key Value
John Washington 132-54-3570
Diana Louise Jones 761-55-3791
Xiaoming Liu 385-41-0902
Rakesh Gopal 441-89-1956
Linda Cohen 217-66-5609
……. ………
Lisa Kobayashi 177-23-0199

 key: movie title; value: IP address


Distributed database:
 Building such a database is straightforward with a client-
server architecture that stores all the (key, value) pairs in
one central server.
 Distributed, P2P version of the database that will store the
(key, value) pairs over millions of peers.
 In the P2P system, each peer will only hold a small subset of
the totality of the (key, value) pairs.
 Any peer can query the distributed database with a
particular key.
 The distributed database will then locate the peers that have
the corresponding (key, value) pairs and return the key-
value pairs to the querying peer.
 Any peer will also be allowed to insert new key-value pairs
into the database.
 Such a distributed database is referred to as a Distributed
Hash Table (DHT)
DHT service
 A key is the content name and the value is the IP-
address of a peer that has a copy of the content.

 So, if Bob and Charlie each have a copy of the latest


Linux distribution, then the DHT database will
include the following two key-value pairs: (Linux,
IPBob) and (Linux, IPCharlie).

 Since the DHT database is distributed over the


peers, some peer, say Dave, will be responsible for
the key “Linux” and will have the corresponding
key-value pairs.

Application Layer 2-115


 Now suppose Alice wants to obtain a copy of Linux.

 She first needs to know which peers have a copy of


Linux before she can begin to download it.

 She queries the DHT with “Linux” as the key. The


DHT then determines that the peer Dave is
responsible for the key “Linux.”

 The DHT then contacts peer Dave, obtains from


Dave the key-value pairs (Linux, IPBob) and
(Linux, IPCharlie), and passes them on to Alice.

 Alice can then download the latest Linux


distribution from either IPBob or IPCharlie.
Designing a DHT:
1. Randomly scatter the (key, value) pairs across all the
peers

2. Have each peer maintain a list of the IP addresses of


all participating peers.

 The querying peer sends its query to all other peers,


and the peers containing the (key, value) pairs that
match the key can respond with their matching pairs.

 Un-scalable approach

Application Layer 2-117


Designing a DHT:
 Assign an identifier to each peer, where each
identifier is an integer in the range [0, 2n-1] for some
fixed n.
 Each key to be an integer in the same range.
 To create integers out of such keys, we will use a
hash function that maps each key (e.g., social security
number) to an integer in the range[0, 2n-1].
 Since we are using hashes of key, rather than keys,
the distributed database is called as Distributed Hash
Table (DHT).
Storing the (key, value) pairs in
the DHT:
 Central issue here is defining a rule for assigning
keys to peers.

1. Assign each (key, value) pair to the peer whose


identifier is the closest to the key

2. Closest peer as the closest successor of the key.

Application Layer 2-119


Example:
 Suppose n=4 so that all the peer and key identifiers are in the
range [0, 15].
 Further suppose that there are eight peers in the system with
identifiers 1, 3, 4, 5, 8, 10, 12, and 15.
 Suppose we want to store the (key, value) pair (11, Johnny Wu)
in one of the eight peers.
 Using our closest convention, since peer 12 is the closest
successor for key 11, we therefore store the pair (11, Johnny Wu)
in the peer 12.
 If the key is exactly equal to one of the peer identifiers, we store
the (key, value) pair in that matching peer.
 If the key is larger than all the peer identifiers, we use a modulo-
2n convention, storing the (key, value) pair in the peer with the
smallest identifier.
 To determine closest peer, each peer need to keep
track of all the peers in the system - which is
completely impractical for a large-scale system
with millions of peers.

Application Layer 2-121


Circular DHT
• To address this problem of scale,
• Consider organizing the peers into a circle.
• In this circular arrangement, each peer only keeps track of its immediate successor and immediate predecessor

1
This circular arrangement of the peers is a special case of an overlay network.

3
15

4
12
5
10
8
Resolving a query

1 Who is responsible
for key 14 ?
value 3
15

4
12
5

10
8
Advantage:
The circular DHT provides a very elegant solution for
reducing the amount of overlay information each peer
must manage.
In particular, each peer needs only to be aware of two
peers, its immediate successor and its immediate
predecessor.

Disadvantage:
But this solution introduces yet a new problem.
Although each peer is only aware of two neighboring
peers, to find the node responsible for a key (in the worst
case), all N nodes in the DHT will have to forward a
message around the circle; N/2 messages are sent on
average.
Circular DHT with shortcuts
1 Who is responsible
value
for key 14 ?
3
15

4
12
5
10
8
• Each peer keeps track of IP addresses of predecessor,
successor, short cuts.
• Reduced from 6 to 3 messages.
• Shortcuts can significantly reduce the number of messages
used to process a query.
Peer churn Peers may come and go (churn)
1
Handling peer churn:
15 3 Each peer knows address of its
two successors
4 Each peer periodically pings its
two successors to check aliveness
12 If immediate successor leaves,
5
choose next successor as new
10 immediate successor
8
example: peer 5 abruptly leaves
Peer churn handling peer churn:
1
peers may come and go (churn)
each peer knows address of its
15 3 two successors
each peer periodically pings its
4 two successors to check aliveness
if immediate successor leaves,
12
choose next successor as new
immediate successor
10
8
example: peer 5 abruptly leaves
peer 4 detects peer 5’s departure; makes 8 its immediate
successor
 4 asks 8 who its immediate successor is; makes 8’s
immediate successor its second successor.
When a peer wants to join the DHT:
 Let’s say a peer with identifier 13 wants to join the DHT, and at
the time of joining, it only knows about peer 1’s existence in the
DHT.

 Peer 13 would first send peer 1 a message, saying “what will be


13’s predecessor and successor?”

 This message gets forwarded through the DHT until it reaches


peer 12, who realizes that it will be 13’s predecessor and that its
current successor, peer 15, will become 13’s successor.
 Next, peer 12 sends this predecessor and successor information
to peer 13. Peer 13 can now join the DHT by making peer 15 its
successor and by notifying peer 12 that it should change its
immediate successor to 13.

Application Layer 2-128


Socket Programming: Creating Network
Applications
 A typical network application consists of a pair of
programs—a client program and a server program
—residing in two different end systems.

 When these two programs are executed, a client


process and a server process are created, and these
processes communicate with each other by reading
from, and writing to, sockets.

Application Layer 2-129


 There are two types of network applications.
1. An implementation whose operation is specified in
a protocol standard, such as an RFC or some other
standards document; such an application is
sometimes referred to as “open,” since the rules
specifying its operation are known to all.

2. A proprietary network application. In this case the


client and server programs employ an application-
layer protocol that has not been openly published
in an RFC or elsewhere.

Application Layer 2-130


Socket Programming with UDP
Interaction between two communicating processes that use
UDP sockets.
Before the sending process can push a packet of data out the
socket door, when using UDP, it must first attach a
destination address to the packet.

After the packet passes through the sender’s socket, the


Internet will use this destination address to route the packet
through the Internet to the socket in the receiving process.

When the packet arrives at the receiving socket, the


receiving process will retrieve the packet through the socket,
and then inspect the packet’s contents and take appropriate
action.

Application Layer 2-131


 The sending process attaches to the packet a
destination address which consists of the
destination host’s IP address and the destination
socket’s port number.

 The sender’s source address— consisting of the IP


address of the source host and the port number of
the source socket—are also attached to the packet.

Application Layer 2-132


Example: Client-server application to demonstrate
socket programming for both UDP and TCP:

1. The client reads a line of characters (data) from


its keyboard and sends the data to the server.

2. The server receives the data and converts the


characters to uppercase.

3. The server sends the modified data to the client.

4. The client receives the modified data and


displays the line on its screen.

Application Layer 2-133


Socket-related activity of the client and server that
communicate over the UDP transport service
UDPClient.py
 code for the client side of the application:

from socket import *


serverName = ‘hostname’
serverPort = 12000
clientSocket = socket(socket.AF_INET,socket.SOCK_DGRAM)
message = raw_input(’Input lowercase sentence:’)
clientSocket.sendto(message,(serverName, serverPort))
modifiedMessage, serverAddress =
clientSocket.recvfrom(2048)
print modifiedMessage
clientSocket.close()

Application Layer 2-135


UDPServer.py
Code for server side of the application:

from socket import *


serverPort = 12000
serverSocket = socket(AF_INET, SOCK_DGRAM)
serverSocket.bind((’’, serverPort))
print ”The server is ready to receive”
while 1:
message, clientAddress = serverSocket.recvfrom(2048)
modifiedMessage = message.upper()
serverSocket.sendto(modifiedMessage, clientAddress)

Application Layer 2-136


Socket Programming with TCP
 TCP is a connection-oriented protocol
 When creating the TCP connection, we associate
with it the client socket address (IP address and
port number) and the server socket address (IP
address and port number)
 TCP server must be running as a process before
the client attempts to initiate contact.
 The server program must have a special door—
more precisely, a special socket—that welcomes
some initial contact from a client process running
on an arbitrary host.

Application Layer 2-137


Application Layer 2-138
Application Layer 2-139
TCPClient.py
from socket import *
serverName = ’servername’
serverPort = 12000
clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket.connect((serverName,serverPort))
sentence = raw_input(‘Input lowercase sentence:’)
clientSocket.send(sentence)
modifiedSentence = clientSocket.recv(1024)
print ‘From Server:’, modifiedSentence
clientSocket.close()

Application Layer 2-140


TCPServer.py
from socket import *
serverPort = 12000
serverSocket = socket(AF_INET,SOCK_STREAM)
serverSocket.bind((‘’,serverPort))
serverSocket.listen(1)
print ‘The server is ready to receive’
while 1:
connectionSocket, addr = serverSocket.accept()
sentence = connectionSocket.recv(1024)
capitalizedSentence = sentence.upper()
connectionSocket.send(capitalizedSentence)
connectionSocket.close()
Application Layer 2-141

You might also like