Professional Documents
Culture Documents
Computer Networks
Application Layer
Application-layer protocols:
one “piece” of the application; define
messages exchanged by apps and
actions taken.
the application
(API)
Application Program Interface (API) transport
Communication Software & Hardware network Controlled
by OS
Platform (OS + Hardware) link
physical
Application: communicating,
distributed processes application
transport
network
e.g., e-mail, Web, P2P file data link
sharing, instant messaging physical
modem
running in end systems
(hosts)
exchange messages to modem
implement application
Application-layer protocols
one “piece” of an app
define messages
exchanged by apps and
application
actions taken transport application
network transport
use communication data link network
physical data link
services provided by lower physical
layer protocols (TCP, UDP)
(“speaks first”)
typically requests service from modem
server,
Web: client implemented in
browser; e-mail: in mail reader
request
Server: reply
no always on server
arbitrary end systems modem
directly communicate
peers are intermittently modem
Highly scalable
But difficult to manage
Napster
File transfer P2P
File search centralized:
Peers register content at central server
Peers query same central server to locate content
Instant messaging
Chatting between two users is P2P
Presence detection/location centralized:
User registers its IP address with central server when it
comes online
User contacts central server to find IP addresses of
buddies
www.iust.ac.ir/computer/home.html
Entity Body
Entity Body
request line
(GET, POST,
GET /somedir/page.html HTTP/1.1
HEAD commands)
Host: www.someschool.edu
User-agent: Mozilla/4.0
header Connection: close
lines Accept-language:fr
If-modified-since:Sat, 2 Nov 2002 13:45:12
Carriage return, (carriage return, line feed)
line feed
indicates end
of message
status line
(protocol
status code HTTP/1.1 200 OK
status phrase) Connection: close
Date: Thu, 06 Aug 1998 12:00:15 GMT
Server: Apache/1.3.0 (Unix)
header
Last-Modified: Mon, 22 Jun 1998 …...
lines
Content-Length: 6821
MIME lines Content-Type: text/html
HEAD
The HEAD method is identical to GET except that the server must
not return any Entity-Body in the response.
HTTP/1.0 HTTP/1.1
GET GET, POST, HEAD
POST PUT
HEAD uploads file in entity
body to path specified
asks server to leave
in URL field
requested object out of
response DELETE
deletes file specified in
the URL field
Other Methods
OPTIONS, PATCH, COPY, MOVE, DELETE, LINK, UNLINK, TRACE,
WRAPPED, extension method.
Proxy-Authentication:
Public:
Retry-After:
Server:
WWW-Authenticate:
Set-Cookie:
Response Categories
Informational :100
Successful :200
Redirection :300
Client Error :400 (eg. 404 Not found)
Server Error :500
Cookie file
usual http request msg
amazon: 1678 cookie: 1678 cookie-
ebay: 8734 specific
usual http response msg action
one week later:
HTTP
Files
TCP
IP
FILE FILE
SYSTEM SYSTEM
SMTP
“mail reader” agent
SMTP
servers to send email agent
messages
“client”: sending mail
mail user
server (sending agent) agent
server
“server”: receiving mail
server (receiving agent) user
agent
user
agent
transfer of messages
closure
command/response interaction
commands: ASCII text
webmail.iust.ac.ir
1 mail
mail server user User2
user
User1 server agent
agent 2 6
3 4 5 user2@yahoo.com
yahoo.com
user1@webmail.iust.ac.ir
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)
webmail.iust.ac.ir User2
mail
User1 mail user
server
server agent
1 6
3 4 5
user 2 user2@yahoo.com
agent
yahoo.com
user1@webmail.iust.ac.ir
encoded data .
Text Video
example subtypes: plain, example subtypes: mpeg,
html quicktime
Image
example subtypes: jpeg, Application
gif other data that must be
processed by reader
Audio before “viewable”
example subtypes: basic example subtypes:
(8-bit mu-law encoded), msword, octet-stream
32kadpcm (32 kbps
coding)
--StartOfNextPart
Dear User1, Hear is a photo of iust in 1383 winter.
--StartOfNextPart
Content-Transfer-Encoding: base64
Content-Type: image/jpeg
base64 encoded data .....
.........................
......base64 encoded data
--StartOfNextPart
Do you like to receive more pictures?
.
pass: password
C: list
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>
dele: delete S: .
quit C: dele 2
C: quit
S: +OK POP3 server signing off
ac.ir.
root iust.ac.ir.
webmail . iust . ac . ir .
host
2nd-level top-level ce.iust.ac.ir.
subdomain
domain domain
new
Type=A Type=CNAME
name is hostname name is alias name for some
value is IP address “canonical” (the real) name
Type=NS www.ibm.com is really
name is domain (e.g. iust.ac.ir) servereast.backup2.ibm.com
value is IP address of authoritative
name server for this domain value is canonical name
Type=MX
value is name of mail-server
associated with name
org DNS Servers edu DNS Servers com DNS Servers ir DNS Servers
ac.ir DNS
Servers
iust.ac.ir
DNS Servers
Root Servers
Home
Server Operator Locations IP Addr ASN
VeriSign Global Registry
A Services
Dulles VA 198.41.0.4 19836
IPv4: 192.228.79.201
Information Sciences
B Institute
Marina Del Rey CA IPv6: tba
2001:478:65::53
Herndon VA; Los Angeles;
C Cogent Communications
New York City; Chicago
192.33.4.12 2149
www.icann.org
a:answer
root name server
recursive query: r:referral q
iterated query
puts burden of name 2
q:query
resolution on r3
contacted name q 4
server a 7
heavy load?
q a q a
intermediate name server
iterated query: local name server (Top Level) dns.org
dns.iust.ac.ir
contacted server 5 6
1 8
replies with name of
server to contact
authoritative name server
“I don’t know this dns.icann.org
name, but ask this requesting host
server”
www.icann.org
www.icann.org
ac.ir.
iust.ac.ir.
Local
Name Server
www.icann.org.
Client
The query contains the FQDN of the requested computer.
A forward lookup query is a request
Forward Lookup Query:
What is IP Address of www.icann.org
to map a name to an IP address.
Root server
3
4
Application DNS cache
5
Top-level
DNS query
1 10 Local DNS 6 domain server
2
server
DNS resolver 7
DNS response 9
8
Second-level
domain server
12bytes
number of questions number of answer RRs
msg header
number of authority RRs number of additional RRs
identification: 16 bit #
questions
for query, reply to query
(variable number of questions)
uses same #
answers
flags: (variable number of resource records)
query or reply authority
recursion desired (variable number of resource records)
identification flags
12bytes
Name, Type fields number of questions number of answer RRs
for a query number of authority RRs number of additional RRs
questions
RRs in response (variable number of questions)
to query answers
(variable number of resource records)
records for authority
authoritative servers (variable number of resource records)
additional information
additional “helpful” (variable number of resource records)
info that may be used
Client host
Service request for
128.2.194.242:80 Web server
(port 80)
(i.e., the Web server)
Client OS
Echo server
(port 7)
Application Software
(Network Application)
controlled by
controlled by application
process process
application developer
developer socket socket
TCP with TCP with controlled by
controlled by
buffers, operating
operating buffers, Network system
system variables variables
Client Connection
socket
bytes socket
Server IP Address
&
Client IP Address Port Number2
&
Port Number
outTOServer inFormUser
Input
Stream
Client
inFormServer
Process
Input
Output Stream
Stream
TCP socket
jamali@ iust.ac.ir June 23, 2010 Application Layer 2-147
Streams
write reply to
connectionSocket read reply from
clientSocket
close
connectionSocket close
clientSocket
clientSocket.close();
}
}
jamali@ iust.ac.ir June 23, 2010 Application Layer 2-151
Code Descriptions-
Descriptions-TCPClient.java
import java.io.*;
java.io and java.net are java packages.
The java.io package contains classes for
input (BufferedReader)
output (DataOutputStream)
streams.
import java.net.*;
The java.net package provides classes for network support.
It contains the
Socket (clientSocket object is derived from the Socket class) and
ServerSocket classes.
class TCPClient {
public static void main(String argv[ ]) throws Exception
{......}
}
First is beginning of a class definition block.
Class definition for the class named TCPClient.
A class contains variables and methods. The class TCPClient
has no class variables and exactly one method, the main()
method.
Java interpreter executes an application, starts by calling
the class's main method. The main method then calls all the
other methods required to run the application.
String sentence;
String modifiedSentence;
These lines declare objects of type String.
Object sentence is string typed by user and sent to server.
Object modifiedSentence is the string obtained from the server and sent
to the user's standard output.
The line
creates object clientSocket of type Socket.
performs a DNS look-up on the hostname to obtain the host's IP
address.
initiates the TCP connection between client and server.
sentence = inFromUser.readLine();
The above line places a line typed by the user into the string
sentence.
The string sentence continues to gather characters until the
user ends the line by typing a carriage return.
The line passes from standard input through the stream
inFromUser into the string sentence.
outToServer.writeBytes(sentence + '\n');
Line sends the string sentence augmented with a carriage return
into the outToServer stream.
The augmented sentence flows through the client's socket and into
the TCP pipe.
The client then waits to receive characters from the server.
modifiedSentence = inFromServer.readLine();
When characters arrive from the server, they flow through the
stream inFromServer and get placed into the string
modifiedSentence.
Characters continue to accumulate in modifiedSentence until the
line ends with a carriage return character.
clientSocket.close();
This last line
closes the socket and,
hence, closes the TCP connection between the client and the
server.
It causes TCP in the client to send a TCP message to TCP in the
server.
import java.io.*;
import java.net.*;
class TCPServer {
Create output
stream, attached DataOutputStream outToClient =
to socket new DataOutputStream(connectionSocket.getOutputStream());
Read in line
from socket clientSentence = inFromClient.readLine();
write reply to
serverSocket
specifying client read reply from
host address, clientSocket
port number close
clientSocket
inFromUser
Input
Stream
Input: receives
Process packet (TCP
received “byte
recievepacket
stream”)
sendpacket
UDP UDP
datagram datagram
packet packet
Output: sends
packet (TCP sent
“byte stream”)
To transport From
layer transport layer
jamali@ iust.ac.ir June 23, 2010 Application Layer 2-169
Example: UDPClient.java
import java.io.*;
import java.net.*;
class UDPClient {
public static void main(String args[]) throws Exception
{
Create
input stream BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in));
Create
client socket DatagramSocket clientSocket = new DatagramSocket();
Translate
InetAddress IPAddress = InetAddress.getByName("hostname");
hostname to IP
address using DNS byte[ ] sendData = new byte[1024];
byte[ ] receiveData = new byte[1024];
Create datagram
with data-to-send, DatagramPacket sendPacket =
length, IP addr, port new DatagramPacket(sendData, sendData.length, IPAddress, 9876);
The byte arrays sendData and receiveData will hold the data
the client sends and receives, respectively.
sendData = sentence.getBytes();
clientSocket.send(sendPacket);
In the above line, while waiting for the packet from the
server, the client creates a place holder for the packet,
receivePacket, an object of type DatagramPacket.
clientSocket.receive(receivePacket);
clientSocket.close();
This last line closes the socket. Because UDP is
connectionless, this line does not cause the client to send a
transport-layer message to the server (in contrast with
TCPClient).
import java.io.*;
import java.net.*;
class UDPServer {
public static void main(String args[ ]) throws Exception
Create {
datagram socket
DatagramSocket serverSocket = new DatagramSocket(9876);
at port 9876
byte[ ] receiveData = new byte[1024];
byte[ ] sendData = new byte[1024];
while(true)
{
Create space for
DatagramPacket receivePacket =
received datagram
new DatagramPacket(receiveData, receiveData.length);
Receive serverSocket.receive(receivePacket);
datagram
jamali@ iust.ac.ir June 23, 2010 Application Layer 2-180
Example: Example: UDPServer.java (cont.)
sendData = capitalizedSentence.getBytes();
Create datagram
DatagramPacket sendPacket =
to send to client new DatagramPacket(sendData, sendData.length, IPAddress,
port);
Write out
datagram serverSocket.send(sendPacket);
to socket }
}
} End of while loop,
loop back and wait for
another datagram
jamali@ iust.ac.ir June 23, 2010 Application Layer 2-181
Building a Simple Web Server
import java.io.*;
import java.net.*;
import java.util.*;
class WebServer {
public static void main(String argv[ ]) throws Exception
{
String requestMessageLine; contain the first line in the HTTP request message
contain the file name of the requested file
String fileName;
ServerSocket listenSocket = new ServerSocket(6789); When a request for a connection
two streams are created
String requestMessageLine;
String fileName;
BufferedReader inFromClient =
new BufferedReader(new InputStreamReader
(connectionSocket.getInputStream()));
DataOutputStream outToClient =
new DataOutputStream(connectionSocket. getOutputStream());
requestMessageLine = inFromClient.readLine();
Our server must now parse the line to extract the filename.
StringTokenizer tokenizedLine =
new StringTokenizer(requestMessageLine);
if (tokenizedLine.nextToken().equals("GET")) {
fileName = tokenizedLine.nextToken();
The server knows from the HTTP RFC that the file name for
the requested file is contained in the token that follows the
token containing "GET."
This file name is put in a string called fileName.
if (fileName.startsWith("/") == true )
fileName = fileName.substring(1);
if (fileName.endsWith(".jpg")) outToClient.writeBytes("Content-
Type: image/jpeg\r\n");
if (fileName.endsWith(".gif")) outToClient.writeBytes("Content-Type:
image/gif\r\n");
outToClient.write(fileInBytes, 0, numOfBytes);
The above command sends the requested file, fileInBytes, to the
TCP send buffer. TCP will concatenate the file, fileInBytes, to the
header lines just created, segment the concatenation if necessary,
and send the TCP segments to the client.
connectionSocket.close();
After serving one request for one file, the server performs some
housekeeping by closing the socket connectionSocket.
Java-tutorials:
“All About Sockets” (Sun tutorial),
http://www.javaworld.com/javaworld/jw-12-1996/jw-12-
sockets.html
“Socket Programming in Java: a tutorial,”
http://www.javaworld.com/javaworld/jw-12-1996/jw-12-
sockets.html
networks
browsers
Web server
networks
browsers
routers
servers
browsers
replicated
content
(mirror)
content sink
(cache)
router
content source
server
It also reduces:
Network caching:
Caching system is located on machine in the
path from multiple clients to multiple servers.
origin
servers
HTML, FTP, Search, Database
LAN router Internet
router
Internet
institutional institutional
network Cache(Proxy server)
Proxy Architecture
jamali@ iust.ac.ir June 23, 2010 Application Layer 2-208
Web Caches (Proxy web-
web-Server)
Goal: satisfy client request without involving origin server.
origin
user sets browser: Web server
accesses via cache
(proxy) Proxy
server
browser sends all HTTP
requests to cache client
(proxy)
object in cache: cache
returns object
else cache requests
object from origin
server, then returns client
object to client origin
server
in service
waiting Departure (response)
λ :Arrival (request)
Service Providing
Entity
Service Providing
Entity
LAN router
delay = delayup + delaydown ≈ delaydown
It is because: Lres >> Lreq λ
Request from clients
public
Consequence
Internet
40% requests will be satisfied
almost immediately
80.5 msecs
60% requests satisfied by origin
server Rlink =1.6 Mbps
62.5 msecs
access-link
utilization of access link (reduced
to 60%) = 0.6 *93.75= 56.25%
LAN
Link delay = 62.5/0.4375 = 143
11.8 msecs
msec
delay = 0.4* 11.8 + 0.6 x (2000 +
143 + 11.8) = 1297.6 msec
Rlan =10 Mbps Network
cache
Distribution
Node
2b 3
5 Mirror
Server
6
4
Client
1. Origin server informs RR of Content Availability.
2. Content Pushed to Distribution System.
3. Client Requests Content, Origin server redirects client to RR.
4. Client sends query to RR.
5. RR finds the most suitable Mirror Server.
6. Mirror server receives client request and provides services.
jamali@ iust.ac.ir June 23, 2010 Application Layer 2-221
More about CDNs
X
IP
Y
Overlay
IP
content,
human presence
2
1 5
5
2 5
3 3 4
4
5
Give me
1 5
4 Who has
register
INTERNET
Document x!
OK:
Document
Peer Z x?
IP = a.b.c.d
x
Advantages:
Search is generally efficient
Disadvantages
High cost on centralized index
Performance & scalability bottleneck
Vulnerable! Highly visible target
?
?
?
?
?
?
?
?
Query message
HTTP sent over QueryHit
existing TCP Query
connections
Gnutella on ports
6346 and 6347
peers forward Query
message
Query QueryHit
QueryHit sent over
reverse path QueryHit Query
Query
Scalability: limited
scopeflooding Query
Broadcast Messages
Ping: initiating message (“I’m here”)
Query: search pattern and TTL (time-to-live)
Back-Propagated Messages
Pong: reply to a ping, contains information about the peer
Query response: contains information about the
computer that has the needed file
Node-to-Node Messages
GET: return the requested file
PUSH: push the file to me
Peer living!
Advantages:
Easy to start
No maintenance needed
Hard to shut down
privacy
Disadvantages:
Inefficient search
Lot of network traffic
Bottlenecks (limited peers)
Advantages:
All the advantages of pure
Takes advantage of different peer capabilities
Disadvantages:
Super nodes might become bottlenecks for clients
Clients are disconnected when super peer leaves
Inefficient search (but better than Pure P2P)
Maintenance costs for super peers
Advantages
All advantages of super-peers
load of queries is shared among peers
less points of fail
Disadvantages
additional maintenance: nodes must notify all redundant
super-peers upon joining, leaving, updating files
Additional connections between super-peers required
1 2
4
4
1
5
1 4
6 5
1 7 4
6 5
1 7 4
6 5
Ex: Node 3
holds this
3
document
1 7 4
6 5
source
Interoperability
Any system/peer/application
Platform independency
Languages (C, Java, etc)
Systems platforms (Unix, Windows, etc)
Networking platforms (802.11, Bluetooth, TCP/IP, etc)
Ubiquity
Sensors, PDAs, routers, desktops, laptops, storage
systems
Objectives
Find peers and resources
Share files with anyone across the network
Create a particular group of peers across different
networks
Communicate securely with peers across public networks
Projects
Applications (24 projects)
Core (13 projects)
Demos (3 projects)
Forge (15 projects)
Other (12 projects)
Services (24 projects)
jamali@ iust.ac.ir June 23, 2010 Application Layer 2-274
JXTA (Sun) Protocols
J C
Peer Groups Peer Pipes Peer Monitoring X O
T R
Security A E
Distributed Computing
Distributed (www.distributed.net)
SETI@home (www.seti.org)
Genome@home (gah.stanford.edu)
Folding@home (www.stanford.edu/group/pandegroup/folding)
Global Grid Forum (www.globalgridforum.org)
Globus Project (www.globus.org)
File sharing
Napster (www.napster.com)
Gnutella (gnutella.wego.co)
Kazaa (www.kazaa.com)
Platforms
JXTA (www.jxta.org)
.NET (www.microsoft.com/net)
Collaboration
Groove (www.groove.net)
Endeavors (www.endeavors.com)
IPv6 as a p2p overlay
Working Groups
p2p.internet2.edu
www.openp2p.com
( @$ ١ ) .#
? !ب% راLAN1 = )در>( در-. ; ز"ن-)"
( @$ ١ ) .#
? !ب% LAN2 را ا ران1 6ر دهAB
.#
$
ضD E
= ا?> را-. ز"ن
origin
servers
access link1
public
Internet
access link2