0% found this document useful (0 votes)
12 views60 pages

Chapter2 Tostudent

Uploaded by

stevenrhinewlh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views60 pages

Chapter2 Tostudent

Uploaded by

stevenrhinewlh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 60

Chapter 2

Application Layer

A note on the use of these ppt slides:


We’re making these slides freely available to all (faculty, students, readers).
They’re in PowerPoint form so you can add, modify, and delete slides
(including this one) and slide content to suit your needs. They obviously
represent a lot of work on our part. In return for use, we only ask the
following: Computer Networking:
❑ If you use these slides (e.g., in a class) in substantially unaltered form, A Top Down Approach ,
that you mention their source (after all, we’d like people to use our book!)
❑ If you post any slides in substantially unaltered form on a www site, that 6th edition.
you note that they are adapted from (or perhaps identical to) our slides, and Jim Kurose, Keith Ross
note our copyright of this material.

Thanks and enjoy! JFK/KWR

All material copyright 1996-2007


J.F Kurose and K.W. Ross, All Rights Reserved
2: Application Layer 1
Chapter 2: Application layer
 2.1 Principles of  2.7 Socket programming
network applications with TCP
 2.2 Web and HTTP
 2.5 DNS

2: Application Layer 2
Chapter 2: Application Layer
Our goals:  learn about protocols
 conceptual, by examining popular
implementation application-level
aspects of network protocols
application protocols ❖ HTTP
❖ transport-layer ❖ DNS
service models  programming network
❖ client-server applications
paradigm ❖ socket API

2: Application Layer 3
Some network apps
 e-mail  voice over IP
 web  real-time video
 instant messaging conferencing
 remote login  grid computing
 P2P file sharing
 multi-user network
games
 streaming stored video
clips

2: Application Layer 4
Creating a network app application
transport
network
data link

write programs that physical

❖ run on (different) end


systems
❖ communicate over network
❖ e.g., web server software
communicates with browser
software application

little software written for


transport
network
data link
devices in network core
application
physical
transport
network
❖ network core devices do data link
physical
not run user applications
❖ applications on end systems
allows for rapid app
development, propagation
2: Application Layer 5
Chapter 2: Application layer
 2.1 Principles of  2.7 Socket programming
network applications with TCP
❖ app architectures
❖ app requirements
 2.2 Web and HTTP
 2.5 DNS

2: Application Layer 6
Application architectures
 Client-server

2: Application Layer 7
Client-server architecture
server:
❖ always-on host
❖ permanent IP address
❖ server farms for
scaling
clients:
client/server ❖ communicate with server
❖ may be intermittently
connected
❖ may have dynamic IP
addresses
❖ do not communicate
directly with each other
2: Application Layer 8
What transport service does an app need?
Data loss Bandwidth
 some apps (e.g., audio) can  some apps (e.g.,
tolerate some loss multimedia) require
 other apps (e.g., file minimum amount of
transfer, telnet) require bandwidth to be
100% reliable data
“effective”
transfer
 other apps (“elastic
Timing apps”) make use of
 some apps (e.g., whatever bandwidth
Internet telephony, they get
interactive games)
require low delay to be
“effective”
2: Application Layer 9
Transport service requirements of common apps

Application Data loss Bandwidth 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, 100’s msec
video:10kbps-5Mbps
stored audio/video loss-tolerant same as above yes, few secs
interactive games loss-tolerant few kbps up yes, 100’s msec
instant messaging no loss elastic yes and no

2: Application Layer 10
Internet transport protocols services

TCP service: UDP service:


 connection-oriented: setup  unreliable data transfer
required between client and between sending and
server processes receiving process
 reliable transport between  does not provide:
sending and receiving process connection setup,
 flow control: sender won’t reliability, flow control,
overwhelm receiver congestion control, timing,
or bandwidth guarantee
 congestion control: throttle
sender when network
overloaded Q: why bother? Why is
 does not provide: timing, there a UDP?
minimum bandwidth
guarantees
2: Application Layer 11
Internet apps: application, transport protocols

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 proprietary TCP or UDP
(e.g. RealNetworks)
Internet telephony proprietary
(e.g., Vonage,Dialpad) typically UDP

2: Application Layer 12
Processes communicating
Process: program running Client process: process
within a host. that initiates
 within same host, two
communication
processes communicate Server process: process
using inter-process that waits to be
communication (defined contacted
by OS).
 processes in different
hosts communicate by
exchanging messages

2: Application Layer 13
Addressing processes
 to receive messages,
process must have
identifier
 host device has unique
32-bit IP address
 Q: does IP address of
host on which process
runs suffice for
identifying the process?

2: Application Layer 14
Addressing processes
 to receive messages,  identifier includes both
process must have IP address and port
identifier numbers associated with
 host device has unique process on host.
32-bit IP address  Example port numbers:
 Q: does IP address of ❖ HTTP server: 80
host on which process ❖ Mail server: 25
runs suffice for  to send HTTP message
identifying the to gaia.cs.umass.edu web
process? server:
❖ A: No, many ❖ IP address: 128.119.245.12
processes can be ❖ Port number: 80
running on same host  more shortly…
2: Application Layer 15
App-layer protocol defines
 Types of messages Public-domain protocols:
exchanged,  defined in RFCs
❖ e.g., request, response  allows for
 Message syntax: interoperability
❖ what fields in messages &
 e.g., HTTP, SMTP
how fields are delineated
Proprietary protocols:
 Message semantics
❖ meaning of information in
 e.g., Skype
fields
 Rules for when and how
processes send &
respond to messages
2: Application Layer 16
Chapter 2: Application layer
 2.1 Principles of  2.7 Socket programming
network applications with TCP
❖ app architectures
❖ app requirements
 2.2 Web and HTTP
 2.5 DNS

2: Application Layer 17
Web and HTTP
First some jargon
 Web page consists of objects
 Object can be HTML file, JPEG image, Java
applet, audio file,…
 Web page consists of base HTML-file which
includes several referenced objects
 Each object is addressable by a URL
 Example URL:
www.someschool.edu/someDept/pic.gif

host name path name

2: Application Layer 18
HTTP overview

HTTP: hypertext
transfer protocol
 Web’s application layer PC running
protocol Explorer

 client/server model
❖ client: browser that
requests, receives, Server
“displays” Web objects running
Apache Web
❖ server: Web server
server
sends objects in
response to requests
Mac running
 HTTP 1.0: RFC 1945 Navigator
 HTTP 1.1: RFC 2068

2: Application Layer 19
HTTP overview (continued)
Uses TCP: HTTP is “stateless”
 client initiates TCP  server maintains no
connection (creates socket) information about
to server, port 80 past client requests
 server accepts TCP
connection from client aside
Protocols that maintain
 HTTP messages (application- “state” are complex!
layer protocol messages)  past history (state) must
exchanged between browser be maintained
(HTTP client) and Web
 if server/client crashes,
server (HTTP server)
their views of “state” may
 TCP connection closed
be inconsistent, must be
reconciled

2: Application Layer 20
HTTP connections
Nonpersistent HTTP Persistent HTTP
 At most one object is  Multiple objects can
sent over a TCP be sent over single
connection. TCP connection
 HTTP/1.0 uses between client and
nonpersistent HTTP server.
 HTTP/1.1 uses
persistent connections
in default mode

2: Application Layer 21
Nonpersistent HTTP
(contains text,
Suppose user enters URL references to 10
www.someSchool.edu/someDepartment/home.index jpeg images)

1a. HTTP client initiates TCP


connection to HTTP server
(process) at
1b. HTTP server at host
www.someSchool.edu waiting
www.someSchool.edu on port 80
for TCP connection at port 80.
“accepts” connection, notifying
client
2. HTTP client sends HTTP
request message (containing
URL) into TCP connection 3. HTTP server receives request
socket. Message indicates message, forms response
that client wants object message containing requested
someDepartment/home.index object, and sends message
into its socket

time
2: Application Layer 22
Nonpersistent HTTP (cont.)

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

2: Application Layer 23
HTTP request message

 two types of HTTP messages: request, response


 HTTP request message:
❖ ASCII (human-readable format)

request line
(GET, POST, GET /somedir/page.html HTTP/1.1
HEAD commands) Host: www.someschool.edu
User-agent: Mozilla/4.0
header Connection: close
lines Accept-language:fr

Carriage return,
line feed (extra carriage return, line feed)
indicates end
of message
2: Application Layer 24
HTTP response 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
Content-Type: text/html

data, e.g., data data data data data ...


requested
HTML file

2: Application Layer 25
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!

2: Application Layer 26
HTTP request message: general format

2: Application Layer 27
Method types
HTTP/1.0 HTTP/1.1
 GET  GET, POST, HEAD
 POST  PUT
 HEAD ❖ uploads file in entity
body to path specified
❖ asks server to leave
in URL field
requested object out of
response  DELETE
❖ deletes file specified in
the URL field

2: Application Layer 28
HTTP response status codes
In first line in server->client response message.
A few sample codes:
200 OK
❖ request succeeded, requested object later in this message
301 Moved Permanently
❖ requested object moved, new location specified later in
this message (Location:)
400 Bad Request
❖ request message not understood by server
404 Not Found
❖ requested document not found on this server
505 HTTP Version Not Supported
2: Application Layer 29
Non-Persistent HTTP: Response time
(performance)
Definition of RTT: time to
send a small packet to
travel from client to
server and back. initiate TCP
connection
Response time: RTT
 one RTT to initiate TCP request
file
connection time to
RTT
transmit
 one RTT for HTTP file
request and first few file
received
bytes of HTTP response
to return time time
 file transmission time
total = 2RTT+transmit time
2: Application Layer 30
Persistent HTTP

Nonpersistent HTTP issues: Persistent without pipelining:


 requires 2 RTTs per object  client issues new request
 OS overhead for each TCP only when previous
connection response has been received
 browsers often open parallel  one RTT for each
TCP connections to fetch referenced object
referenced objects Persistent with pipelining:
Persistent HTTP  default in HTTP/1.1
 server leaves connection  client sends requests as
open after sending response soon as it encounters a
 subsequent HTTP messages referenced object
between same client/server  as little as one RTT for all
sent over open connection the referenced objects

2: Application Layer 31
Web caches (proxy server)
Goal: satisfy client request without involving origin server

 user sets browser: origin


server
Web accesses via
cache Proxy
 browser sends all server
client
HTTP requests to
cache
❖ object in cache: cache
returns object
❖ else cache requests
object from origin client
origin
server, then returns server
object to client
2: Application Layer 32
More about Web caching
 cache acts as both Why Web caching?
client and server  reduce response time
 typically cache is for client request
installed by ISP  reduce traffic on an
(university, company, institution’s access
residential ISP) link.
 Internet dense with
caches: enables “poor”
content providers to
effectively deliver
content (but so does
P2P file sharing)
2: Application Layer 33
Caching example
origin
Assumptions servers
 average object size = 100,000
public
bits Internet
 avg. request rate from
institution’s browsers to origin
servers = 15/sec
1.5 Mbps
 delay from institutional router access link
to any origin server and back
institutional
to router = 2 sec network
10 Mbps LAN
Consequences
 utilization on LAN = 15%
 utilization on access link = 100%
institutional
 total delay = Internet delay +
cache
access delay + LAN delay
= 2 sec + minutes + milliseconds
2: Application Layer 34
Caching example (cont)
origin
possible solution servers
 increase bandwidth of access
public
link to, say, 10 Mbps Internet
consequence
 utilization on LAN = 15%
 utilization on access link = 15% 10 Mbps
 Total delay = Internet delay + access link
access delay + LAN delay institutional
= 2 sec + msecs + msecs network
10 Mbps LAN
 often a costly upgrade

institutional
cache

2: Application Layer 35
Caching example (cont)
origin
possible solution: install servers
cache public
 suppose hit rate is 0.4 Internet
consequence
 40% requests will be
satisfied almost immediately
1.5 Mbps
 60% requests satisfied by
access link
origin server
 utilization of access link institutional
reduced to 60%, resulting in network
10 Mbps LAN
negligible delays (say 10
msec)
 total avg delay = Internet
delay + access delay + LAN institutional
delay = .6*(2.01) secs +
.4*milliseconds < 1.4 secs cache

2: Application Layer 36
Conditional GET

 Goal: don’t send object if cache server


cache has up-to-date cached HTTP request msg
version If-modified-since:
object
 cache: specify date of
<date>
not
cached copy in HTTP request modified
HTTP response
If-modified-since:
HTTP/1.0
<date> 304 Not Modified
 server: response contains no
object if cached copy is up-
HTTP request msg
to-date: If-modified-since:
HTTP/1.0 304 Not <date> object
Modified modified
HTTP response
HTTP/1.0 200 OK
<data>
2: Application Layer 37
Chapter 2: Application layer
 2.1 Principles of  2.7 Socket programming
network applications with TCP
 2.2 Web and HTTP
 2.5 DNS

2: Application Layer 38
DNS: Domain Name System

People: many identifiers: Domain Name System:


❖ SSN, name, passport #  distributed database
Internet hosts, routers: implemented in hierarchy of
many name servers
❖ IP address (32 bit) -
 application-layer protocol
used for addressing
host, routers, name servers to
datagrams
communicate to resolve names
❖ “name”, e.g., (address/name translation)
www.yahoo.com - used
❖ note: core Internet
by humans
function, implemented as
Q: map between IP application-layer protocol
addresses and name ? ❖ complexity at network’s
“edge”

2: Application Layer 39
DNS
DNS services Why not centralize DNS?
 hostname to IP  single point of failure
address translation  traffic volume
 host aliasing  distant centralized
❖ Canonical, alias names database
 mail server aliasing  maintenance
 load distribution
❖ replicated Web doesn’t scale!
servers: set of IP
addresses for one
canonical name

2: Application Layer 40
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 a 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
2: Application Layer 41
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
a Verisign, Dulles, VA
c Cogent, Herndon, VA (also LA)
d U Maryland College Park, MD k RIPE London (also 16 other locations)
g US DoD Vienna, VA
h ARL Aberdeen, MD i Autonomica, Stockholm (plus
j Verisign, ( 21 locations) 28 other locations)
e NASA Mt View, CA m WIDE Tokyo (also Seoul,
f Internet Software C. Palo Alto, Paris, SF)
CA (and 36 other locations)

13 root name
servers worldwide
b USC-ISI Marina del Rey, CA
l ICANN Los Angeles, CA

2: Application Layer 42
TLD and Authoritative Servers
 Top-level domain (TLD) servers:
❖ responsible for com, org, net, edu, etc, and all
top-level country domains uk, fr, ca, jp.
❖ Network Solutions maintains servers for com TLD
❖ Educause for edu TLD
 Authoritative DNS servers:
❖ organization’s DNS servers, providing
authoritative hostname to IP mappings for
organization’s servers (e.g., Web, mail).
❖ can be maintained by organization or service
provider

2: Application Layer 43
Local Name Server
 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
❖ acts as proxy, forwards query into hierarchy

2: Application Layer 44
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

iterated query: local DNS server


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

gaia.cs.umass.edu

2: Application Layer 45
DNS: caching and updating records
 once (any) name server learns mapping, it caches
mapping
❖ cache entries timeout (disappear) after some
time
❖ TLD servers typically cached in local name
servers
• Thus root name servers not often visited
 update/notify mechanisms under design by IETF
❖ RFC 2136
❖ http://www.ietf.org/html.charters/dnsind-charter.html

2: Application Layer 46
Inserting records into DNS
 example: new startup “Network Utopia”
 register name networkuptopia.com at DNS registrar
(e.g., Network Solutions)
❖ provide names, IP addresses of authoritative name server
(primary and secondary)
❖ registrar inserts two RRs (resource records) into com TLD
server:

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


(dns1.networkutopia.com, 212.212.212.1, A)

 create authoritative server Type A record (IP


address) for www.networkuptopia.com; Type NS
record (name servers) for networkutopia.com
 How do people get IP address of your Web site?

2: Application Layer 47
Chapter 2: Application layer
 2.1 Principles of  2.7 Socket programming
network applications with TCP
 2.2 Web and HTTP
 2.5 DNS

2: Application Layer 48
Socket programming
Goal: learn how to build client/server application that
communicate using sockets

Socket API socket


 introduced in BSD4.1 UNIX,
a host-local,
1981 application-created,
 explicitly created, used, OS-controlled interface
released by apps (a “door”) into which
 client/server paradigm application process can
 two types of transport both send and
service via socket API: receive messages to/from
another application
❖ unreliable datagram
process
❖ reliable, byte stream-
oriented

2: Application Layer 49
Socket-programming using TCP
Socket: a door between application process and end-
end-transport protocol (UCP or TCP)
TCP service: reliable transfer of bytes from one
process to another

controlled by
controlled by process application
application process
developer
developer socket socket
TCP with TCP with controlled by
controlled by
buffers, operating
operating buffers, internet system
system variables variables

host or host or
server server

2: Application Layer 50
Socket programming with TCP
Client must contact server  When contacted by client,
 server process must first server TCP creates new
be running socket for server process to
 server must have created communicate with client
socket (door) that ❖ allows server to talk with
welcomes client’s contact multiple clients
❖ source port numbers
Client contacts server by:
used to distinguish
 creating client-local TCP
clients (more in Chap 3)
socket
 specifying IP address, port application viewpoint
number of server process
TCP provides reliable, in-order
 When client creates
transfer of bytes (“pipe”)
socket: client TCP
between client and server
establishes connection to
server TCP
2: Application Layer 51
Client/server socket interaction: TCP
Server (running on hostid) Client
create socket,
port=x, for
incoming request:
welcomeSocket =
ServerSocket()

TCP create socket,


wait for incoming
connection request connection setup connect to hostid, port=x
connectionSocket = clientSocket =
welcomeSocket.accept() Socket()

send request using


read request from clientSocket
connectionSocket

write reply to
connectionSocket read reply from
clientSocket
close
connectionSocket close
clientSocket
2: Application Layer 52
Stream jargon
keyboard monitor

 A stream is a sequence of
characters that flow into

inFromUser
or out of a process. input
stream

 An input stream is Client


attached to some input Process
process
source for the process,
e.g., keyboard or socket.
 An output stream is
attached to an output

inFromServer
outToServer
source, e.g., monitor or
output input
stream stream

socket.
client TCP
clientSocket
socket TCP
socket

to network from network

2: Application Layer 53
Socket programming with TCP
Example client-server app:
1) client reads line from
standard input (inFromUser
stream) , sends to server via
socket (outToServer
stream)
2) server reads line from socket
3) server converts line to
uppercase, sends back to
client
4) client reads, prints modified
line from socket
(inFromServer stream)

2: Application Layer 54
Example: Java client (TCP)
import java.io.*;
import java.net.*;
class TCPClient {

public static void main(String argv[]) throws Exception


{
String sentence;
String modifiedSentence;
Create
client socket, Socket clientSocket = new Socket("hostname", 6789);
connect to server
Create BufferedReader inFromUser =
input stream new BufferedReader(new InputStreamReader(System.in));

Create DataOutputStream outToServer =


output stream new DataOutputStream(clientSocket.getOutputStream());
attached to socket
2: Application Layer 55
Example: Java client (TCP), cont.

Create BufferedReader inFromServer =


input stream new BufferedReader(new
attached to socket InputStreamReader(clientSocket.getInputStream()));
//---------------------------------------
sentence = inFromUser.readLine();
Send line
to server outToServer.writeBytes(sentence + '\n');

Read line modifiedSentence = inFromServer.readLine();


from server
System.out.println("FROM SERVER: " + modifiedSentence);

clientSocket.close();

}
}
2: Application Layer 56
Example: Java server (TCP)
import java.io.*;
import java.net.*;

class TCPServer {

public static void main(String argv[]) throws Exception


{
String clientSentence;
Create String capitalizedSentence;
welcoming socket
ServerSocket welcomeSocket = new ServerSocket(6789);
at port 6789
while(true) {
Wait, on welcoming
socket for contact Socket connectionSocket = welcomeSocket.accept();
by client
BufferedReader inFromClient =
Create input new BufferedReader(new
stream, attached InputStreamReader(connectionSocket.getInputStream()));
to socket

2: Application Layer 57
Example: Java server (TCP), cont

Create output
stream, attached DataOutputStream outToClient =
to socket new DataOutputStream(connectionSocket.getOutputStream());
Read in line
from socket clientSentence = inFromClient.readLine();

capitalizedSentence = clientSentence.toUpperCase() + '\n';


Write out line
outToClient.writeBytes(capitalizedSentence);
to socket
}
}
} End of while loop,
loop back and wait for
another client connection

2: Application Layer 58
Chapter 2: Summary
our study of network apps now complete!
 application architectures  specific protocols:
❖ client-server ❖ HTTP
❖ DNS
 application service
requirements:  socket programming
❖ reliability, bandwidth,
delay
 Internet transport
service model
❖ connection-oriented,
reliable: TCP
❖ unreliable, datagrams: UDP

2: Application Layer 59
Chapter 2: Summary
Most importantly: learned about protocols

 typical request/reply
message exchange:
❖ client requests info or
service
❖ server responds with
data, status code
 message formats:
❖ headers: fields giving
info about data
❖ data: info being
communicated

2: Application Layer 60

You might also like