CS计算机代考程序代写 database dns Java FTP cache Chapter 2 Application Layer

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:
 If you use these slides (e.g., in a class) in substantially unaltered form, 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 you note that they are adapted from (or perhaps identical to) our slides, and 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
Computer Networking: A Top Down Approach , 6th edition.
Jim Kurose, Keith Ross
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:
 conceptual, implementation aspects of network application protocols
 transport-layer service models
 client-server paradigm

learn about protocols by examining popular application-level protocols
 HTTP  DNS
programming network applications
 socket API

2: Application Layer 3

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

Creating a network app
write programs that
 run on (different) end systems
 communicate over network
 e.g., web server software communicates with browser software
little software written for devices in network core
 network core devices do not run user applications
 applications on end systems allows for rapid app development, propagation
application
transport network data link physical
application
transport network data link physical
application
transport network data link physical
2: Application Layer 5

Chapter 2: Application layer
 2.1 Principles of network applications
 app architectures  app requirements
 2.2 Web and HTTP  2.5 DNS
 2.7 Socket programming with TCP
2: Application Layer 6

Application architectures
 Client-server
2: Application Layer 7

Client-server architecture
client/server
server:
 always-on host
 permanent IP address
 server farms for scaling
clients:
 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., multimedia) require minimum amount of bandwidth to be “effective”
 other apps (“elastic apps”) make use of whatever bandwidth they get
 some apps (e.g., audio) can tolerate some loss
 other apps (e.g., file transfer, telnet) require 100% reliable data
transfer
Timing
 some apps (e.g., Internet telephony, interactive games) require low delay to be “effective”
2: Application Layer 9

Transport service requirements of common apps
Application
file transfer e-mail Web documents real-time audio/video
stored audio/video interactive games instant messaging
Data loss
no loss
no loss
no loss loss-tolerant
loss-tolerant loss-tolerant no loss
Bandwidth
Time Sensitive
no
no
no
yes, 100’s msec
elastic
elastic
elastic
audio: 5kbps-1Mbps video:10kbps-5Mbps yes, few secs same as above
few kbps up elastic
yes, 100’s msec yes and no
2: Application Layer 10

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

Internet apps: application, transport protocols
Application
e-mail remote terminal access
Web file transfer streaming multimedia
Internet telephony
Application layer protocol
SMTP [RFC 2821] Telnet [RFC 854] HTTP [RFC 2616] FTP [RFC 959] proprietary
(e.g. RealNetworks) proprietary
(e.g., Vonage,Dialpad)
Underlying transport protocol
TCP
TCP
TCP
TCP
TCP or UDP
typically UDP
2: Application Layer 12

Processes communicating
Process: program running within a host.
 within same host, two processes communicate using inter-process communication (defined by OS).
 processes in different hosts communicate by exchanging messages
Client process: process that initiates communication
Server process: process that waits to be contacted
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, 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?
 identifier includes both IP address and port numbers associated with process on host.
 A: No, many
processes can be
running on same host 


Example port numbers:  HTTP server: 80
 Mail server: 25
to send HTTP message to gaia.cs.umass.edu web server:
 IP address: 128.119.245.12  Port number: 80
more shortly…
2: Application Layer 15

App-layer protocol defines
 Types of messages exchanged,
 e.g., request, response
 Message syntax:
 what fields in messages & how fields are delineated
 Message semantics
 meaning of information in
fields
 Rules for when and how processes send & respond to messages
Public-domain protocols:
 defined in RFCs
 allows for
interoperability
 e.g., HTTP, SMTP Proprietary protocols:  e.g., Skype
2: Application Layer 16

Chapter 2: Application layer
 2.1 Principles of network applications
 app architectures  app requirements
 2.2 Web and HTTP  2.5 DNS
 2.7 Socket programming with TCP
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 protocol
 client/server model
 client: browser that requests, receives, “displays” Web objects
 server: Web server sends objects in response to requests
 HTTP 1.0: RFC 1945
 HTTP 1.1: RFC 2068
PC running Explorer
Mac running Navigator
Server running
Apache Web server
2: Application Layer 19

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

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

Nonpersistent HTTP
Suppose user enters URL
www.someSchool.edu/someDepartment/home.index
(contains text, references to 10
jpeg images)
1a. HTTP client initiates TCP connection to HTTP server (process) at www.someSchool.edu on port 80
2. HTTP client sends HTTP request message (containing URL) into TCP connection socket. Message indicates that client wants object someDepartment/home.index
time
1b. HTTP server at host www.someSchool.edu waiting for TCP connection at port 80. “accepts” connection, notifying client
3. HTTP server receives request message, forms response message containing requested object, and sends message into its socket
2: Application Layer 22

Nonpersistent HTTP (cont.)
time
5. HTTP client receives response message containing html file, displays html. Parsing html file, finds 10 referenced jpeg objects
6. Steps 1-5 repeated for each of 10 jpeg objects
4. HTTP server closes TCP connection.
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,
HEAD commands)
header lines
Carriage return, line feed indicates end
of message
GET /somedir/page.html HTTP/1.1
Host: www.someschool.edu
User-agent: Mozilla/4.0
Connection: close
Accept-language:fr
(extra carriage return, line feed)
2: Application Layer 24

HTTP response message
status line (protocol status code status phrase)
header lines
data, e.g., requested HTML file
HTTP/1.1 200 OK
Connection close
Date: Thu, 06 Aug 1998 12:00:15 GMT
Server: Apache/1.3.0 (Unix)
Last-Modified: Mon, 22 Jun 1998 ……
Content-Length: 6821
Content-Type: text/html
data data data data data …
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
Host: cis.poly.edu
By typing this in (hit carriage 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
 GET
 POST
 HEAD
 asks server to leave requested object out of response
HTTP/1.1
 GET, POST, HEAD  PUT
 uploads file in entity body to path specified in URL field
 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.
Response time:
 one RTT to initiate TCP connection
initiate TCP connection
RTT
request file
RTT
file received
time
time to transmit file
time
 one RTT for HTTP request and first few bytes of HTTP response to return
 file transmission time total = 2RTT+transmit time
2: Application Layer 30

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

Web caches (proxy server)
Goal: satisfy client request without involving origin server
 user sets browser: Web accesses via cache
 browser sends all HTTP requests to cache
origin server
client
Proxy server
 object in cache: cache returns object
 else cache requests object from origin server, then returns object to client
client
origin server
2: Application Layer 32

More about Web caching
 cache acts as both client and server
 typically cache is installed by ISP (university, company, residential ISP)
Why Web caching?
 reduce response time for client request
 reduce traffic on an institution’s access 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
Assumptions
 average object size = 100,000 bits
 avg. request rate from institution’s browsers to origin servers = 15/sec
 delay from institutional router to any origin server and back to router = 2 sec
Consequences
 utilization on LAN = 15%
 utilization on access link = 100%
 total delay = Internet delay + access delay + LAN delay
= 2 sec + minutes + milliseconds
origin servers
institutional network
1.5 Mbps access link
10 Mbps LAN
institutional cache
public Internet
2: Application Layer 34

Caching example (cont)
possible solution
 increase bandwidth of access link to, say, 10 Mbps
consequence
 utilization on LAN = 15%
 utilization on access link = 15%
 Total delay = Internet delay + access delay + LAN delay
= 2 sec + msecs + msecs
 often a costly upgrade
origin servers
institutional network
10 Mbps access link
10 Mbps LAN
institutional cache
public Internet
2: Application Layer 35

Caching example (cont)
possible solution: install cache
 suppose hit rate is 0.4 consequence
 40% requests will be satisfied almost immediately
 60% requests satisfied by origin server
 utilization of access link reduced to 60%, resulting in negligible delays (say 10 msec)
 total avg delay = Internet delay + access delay + LAN delay = .6*(2.01) secs + .4*milliseconds < 1.4 secs origin servers institutional network 1.5 Mbps access link 10 Mbps LAN institutional cache public Internet 2: Application Layer 36 Conditional GET cache server object not modified  Goal: don’t send object if cache has up-to-date cached version  cache: specify date of cached copy in HTTP request If-modified-since:
 server: response contains no object if cached copy is up- to-date:
HTTP/1.0 304 Not
Modified
object modified
HTTP request msg
If-modified-since:

HTTP response
HTTP/1.0
304 Not Modified
HTTP request msg
If-modified-since:

HTTP response
HTTP/1.0 200 OK
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:  SSN, name, passport #
Internet hosts, routers:
 IP address (32 bit) – used for addressing datagrams
 “name”, e.g., www.yahoo.com – used by humans
Q: map between IP addresses and name ?
Domain Name System:
 distributed database implemented in hierarchy of many name servers
 application-layer protocol host, routers, name servers to communicate to resolve names (address/name translation)
 note: core Internet function, implemented as application-layer protocol
 complexity at network’s “edge”
2: Application Layer 39

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

Distributed, Hierarchical Database
com DNS servers
yahoo.com DNS servers
Root DNS Servers org DNS servers
pbs.org DNS servers
edu DNS servers
poly.edu umass.edu DNS serversDNS servers
amazon.com 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
e NASA Mt View, CA
f Internet Software C. Palo Alto, CA (and 36 other locations)
a Verisign, Dulles, VA
c Cogent, Herndon, VA (also LA) d U Maryland College Park, MD g US DoD Vienna, VA
h ARL Aberdeen, MD
j Verisign, ( 21 locations)
k RIPE London (also 16 other locations)
i Autonomica, Stockholm (plus 28 other locations)
m WIDE Tokyo (also Seoul, Paris, SF)
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 resolution example
 Host at cis.poly.edu wants IP address for gaia.cs.umass.edu
iterated query:
 contacted server replies with name of server to contact
 “I don’t know this name, but ask this server”
root DNS server
2
3
4
5
6
dns.cs.umass.edu
gaia.cs.umass.edu
TLD DNS server
local DNS server
dns.poly.edu
7
18
authoritative DNS server
requesting host
cis.poly.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
 introduced in BSD4.1 UNIX, 1981
 explicitly created, used, released by apps
 client/server paradigm
 two types of transport
service via socket API:
 unreliable datagram
 reliable, byte stream- oriented
socket
a host-local, application-created, OS-controlled interface (a “door”) into which application process can both send and receive messages to/from another application process
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 application developer
controlled by operating system
host or server
internet
controlled by application developer
controlled by operating system
host or server
process
process
socket
socket
TCP with buffers, variables
TCP with buffers, variables
2: Application Layer 50

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

Client/server socket interaction: TCP
Server (running on hostid)
Client
create socket,
port=x, for
incoming request:
welcomeSocket = ServerSocket()
TCP connection setup
create socket,
connect to hostid, port=x clientSocket =
Socket()
send request using
clientSocket
read reply from
clientSocket
close
clientSocket
wait for incoming connection request connectionSocket = welcomeSocket.accept()
read request from
connectionSocket
write reply to
connectionSocket
close
connectionSocket
2: Application Layer 52

Stream jargon
 A stream is a sequence of characters that flow into or out of a process.
 An input stream is attached to some input source for the process, e.g., keyboard or socket.
 An output stream is attached to an output source, e.g., monitor or socket.
keyboard
input stream
monitor
Client
Process
process
output stream
input stream
client TCP
clientSocket
socket TCP socket
to network from network
2: Application Layer 53
outToServer inFromUser
inFromServer

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 {
Create client socket,
connect to server
Create input stream
Create output stream attached to socket
public static void main(String argv[]) throws Exception
{
String sentence;
String modifiedSentence;
Socket clientSocket = new Socket(“hostname”, 6789);
BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in));
DataOutputStream outToServer =
new DataOutputStream(clientSocket.getOutputStream());
2: Application Layer 55

Example: Java client (TCP), cont.
Create input stream attached to socket
Send line to server
Read line from server
} }
BufferedReader inFromServer =
new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
//————————————— sentence = inFromUser.readLine();
outToServer.writeBytes(sentence + ‘\n’); modifiedSentence = inFromServer.readLine(); System.out.println(“FROM SERVER: ” + modifiedSentence); clientSocket.close();
2: Application Layer 56

Example: Java server (TCP)
Create welcoming socket at port 6789
Wait, on welcoming socket for contact by client
Create input stream, attached
to socket
{ String clientSentence; String capitalizedSentence;
ServerSocket welcomeSocket = new ServerSocket(6789); while(true) {
Socket connectionSocket = welcomeSocket.accept();
BufferedReader inFromClient =
new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
import java.io.*; import java.net.*;
class TCPServer {
public static void main(String argv[]) throws Exception
2: Application Layer 57

Example: Java server (TCP), cont
Create output stream, attached to socket
Read in line from socket
Write out line to socket
}}
DataOutputStream outToClient =
new DataOutputStream(connectionSocket.getOutputStream());
clientSentence = inFromClient.readLine();
capitalizedSentence = clientSentence.toUpperCase() + ‘\n’; } outToClient.writeBytes(capitalizedSentence);
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  client-server
 application service requirements:
 reliability, bandwidth, delay
 Internet transport service model
 connection-oriented, reliable: TCP
 unreliable, datagrams: UDP
 specific protocols:  HTTP
 DNS
 socket programming
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