Download 3rd Edition: Chapter 2

Document related concepts

Piggybacking (Internet access) wikipedia , lookup

Dynamic Host Configuration Protocol wikipedia , lookup

Recursive InterNetwork Architecture (RINA) wikipedia , lookup

Internet protocol suite wikipedia , lookup

Cracking of wireless networks wikipedia , lookup

Remote Desktop Services wikipedia , lookup

Lag wikipedia , lookup

Real-Time Messaging Protocol wikipedia , lookup

Zero-configuration networking wikipedia , lookup

Hypertext Transfer Protocol wikipedia , lookup

Transcript
Computer Networking
A Top-Down Approach Featuring the Internet
计算机网络-自顶向下方法与Internet特色
Chapter 2 Application Layer
Chapter goals
principles of network applications
transport-layer service models
Client/server
P2P
Processes Communication
application-level protocols
HTTP/FTP/SMTP / POP3 / IMAP/DNS
programming network applications
socket API
Socket Programming in Java
2
School of Computer Science & Technology
Chapter 2: roadmap
2.1 Principles of Network Applications
2.2 The Web and HTTP
2.3 File Transfer Protocol—FTP
2.4 Electronic Mail in the Internet
2.5 DNS- The Internet Directory Service
2.6 P2P File sharing
2.7 Socket Programming with TCP
2.8 Socket Programming with UDP
2.9 Building a Simple Web Server
2.10 Summary
3
School of Computer Science & Technology
Creating a network application
2.1Principles of Network
Applications
Write programs that
run on different end
systems
communicate over a
network.
e.g., Web server /
browser
No software written for
devices in network
core
application
transport
network
data link
physical
application
transport
network
data link
physical
application
transport
network
data link
physical
4
School of Computer Science & Technology
1. Application architectures
2.1Principles of Network
Applications
Application architecture is distinctly
different from the network architecture
network architecture: fixed
App architecture : how application is organized
over various end systems
Typical application architecture
Client-Server (C/S)
Peer-to-Peer (P2P)
Hybrid of client-server and P2P
5
School of Computer Science & Technology
Client-Server architecture
2.1Principles of Network
Applications
server:
 always-on host
 permanent, well-known IP
address
 server farms for scaling
clients:
C/S apps:
Web, FTP, Telnet, e-mail
easy management
server is bottleneck
 communicate with server
 may be intermittently
connected
 may have dynamic IP
addresses
6
School of Computer Science & Technology
Pure P2P architecture
2.1Principles of Network
Applications
no always on server at
the center of apps
arbitrary end systems
directly communicate
peers intermittently
connected and can
change IP addresses
example:
Gnutella
Highly scalable
But difficult to manage
7
School of Computer Science & Technology
Hybrid of client-server and P2P
2.1Principles of Network
Applications
Napster
File transfer P2P
File search centralized:
Instant messaging
Chatting between two users is P2P
Presence detection/location centralized:
8
School of Computer Science & Technology
2. Processes communicating
2.1Principles of Network
Applications
Process: program running within a host.
within same host, two processes communicate
using inter-process communication (IPC,
defined by OS).
processes in different hosts communicate by
exchanging messages through the network
9
School of Computer Science & Technology
2. 1 Client and Server Process
2.1Principles of Network
Applications
Client process: process that initiates communication
Server process: process that waits to be contacted
Note:
applications with P2P architectures have both client
processes & server processes
10
School of Computer Science & Technology
2.2 Sockets
2.1Principles of Network
Applications
 Any message sent from one process to another must go
through the underlying network.
 A process sends message into ,and receives messages
from, the network through its socket
host or
server
host or
server
process
controlled by
app developer
process
socket
socket
TCP with
buffers,
variables
Internet
controlled
by OS
TCP with
buffers,
variables
 Developers can
 choice of
transport
protocol;
 ability to fix a
few parameters
11
School of Computer Science & Technology
2.3 Addressing processes
2.1Principles of Network
Applications
for a process to receive messages, it must
have an identifier.
Q: does the IP address of the destination host suffice
for identifying the destination process?
A: No, many processes can be running on same host
identifier must include both the IP address and
port numbers.
port numbers:
 HTTP server: 80
 Mail server: 25
12
School of Computer Science & Technology
3. App-layer protocol
2.1Principles of Network
Applications
An Application-layer protocol defines:
Types of messages exchanged
 e.g., request & response messages
Syntax of message types
what fields in messages & how fields are delineated
Semantics of the fields
ie, meaning of information in fields
Rules for when and how processes send &
respond to messages
13
School of Computer Science & Technology
3. App-layer protocol
2.1Principles of Network
Applications
Public-domain protocols:
defined in RFCs, allows for interoperability
 e.g., HTTP, SMTP
Proprietary protocols:
e.g., KaZaA
application vs. app-layer protocol
protocol is a piece of a app.
14
School of Computer Science & Technology
4. What transport service does an app need?
2.1Principles of Network
Applications
reliable data transfer
bandwidth
 some apps (e.g., audio) can  bandwidth sensitive
tolerate some loss
app (e.g., multimedia)
 other apps (e.g., file transfer,
telnet) require 100% reliable  elastic bandwidth apps
data transfer
(mail, FTP)
Timing
some apps (Internet telephony,
interactive games) require low
delay to be “effective”
15
School of Computer Science & Technology
2.1.4 requirements of common apps
Application
Data loss
Bandwidth
Time Sensitive
file transfer
e-mail
Web documents
real-time audio/video
no loss
no loss
no loss
loss-tolerant
no
no
no
yes, 100’s msec
stored audio/video
interactive games
instant messaging
loss-tolerant
loss-tolerant
no loss
elastic
elastic
elastic
audio: 5kbps-1Mbps
video:10kbps-5Mbps
same as above
few kbps up
elastic
yes, few secs
yes, 100’s msec
yes and no
16
School of Computer Science & Technology
5. Internet services
2.1Principles of Network
Applications
TCP service:
UDP service:
connection-oriented
reliable transport
flow control:
congestion control:
does not provide: timing,
minimum bandwidth
guarantees
 unreliable data transfer
 does not provide:
 connection setup
 Reliability
 flow control
 congestion control
 timing, or bandwidth guarantee
Q: Why is there a UDP?
congestion control is harmful to apps that have minimum bandwidth
constraint ; some apps are loss-tolerant
School of Computer Science & Technology
17
Internet apps: application, transport protocols
Application
e-mail
remote terminal access
Web
file transfer
streaming multimedia
Internet telephony
Application
layer protocol
Underlying
transport protocol
SMTP [RFC 2821]
Telnet [RFC 854]
HTTP [RFC 2616]
FTP [RFC 959]
proprietary
(e.g. RealNetworks)
proprietary
(e.g., Dialpad)
TCP
TCP
TCP
TCP
TCP or UDP
typically UDP
18
School of Computer Science & Technology
Chapter 2: roadmap
2.1 Principles of Network Applications
2.2 The Web and HTTP
2.3 File Transfer Protocol—FTP
2.4 Electronic Mail in the Internet
2.5 DNS- The Internet Directory Service
2.6 P2P File sharing
2.7 Socket Programming with TCP
2.8 Socket Programming with UDP
2.9 Building a Simple Web Server
2.10 Summary
19
School of Computer Science & Technology
The Web and HTTP
2.2 The Web and HTTP
some jargon
Web page consists of base HTML-file which includes
several referenced objects
Object can be HTML file, image, Java applet, audio
file,…
if a web page contains a HTML file and 5 jpeg images, then
the web page has 6 objects: the base HTML file and 5 images.
Each object is addressable by a URL
 Uniform Resource Locator
www.someschool.edu/someDept/pic.gif
host name
path name
Object
School of Computer Science & Technology
20
Contents
2.2 The Web and HTTTP
1.Overview of HTTP
2.HTTP connections
Non-persistent HTTP connection
Persistent HTTP connection
3.HTTP message type and message format
Request message
Response message
4.Cookies
6.Web caching
7.Conditional GET
21
School of Computer Science & Technology
1. Overview of HTTP
2.2 The Web and HTTP
HTTP: hypertext transfer protocol
Web’s application layer
protocol
client/server model
defines
PC running
Explorer
How client requests web
pages ( written in
HTML/XML) from server
& how server transfers
web pages to client
Versions:
HTTP 1.0(RFC 1945)
HTTP 1.1( RFC 2616)
Server
running
Apache Web
server
Mac running
Navigator
22
School of Computer Science & Technology
1. Overview of HTTP
2.2 The Web and HTTP
HTTP Uses TCP as underlying transport
protocol :
client initiates TCP connection with the server at port
80
HTTP messages exchanged between browser and
Web server through their sockets
HTTP is “stateless”
server maintains no information about past client
requests
Protocols that maintain “state” are complex!
23
School of Computer Science & Technology
2. HTTP connections
2.2 The Web and HTTP
Nonpersistent Connection
at most one object is sent over a TCP connection.
HTTP/1.0 uses nonpersistent HTTP as default
Persistent Connection
Multiple objects can be sent over single TCP
connection between client and server.
HTTP/1.1 uses persistent connections in default mode
24
School of Computer Science & Technology
2.1 nonpersistent HTTP connection
Suppose user enters URL in the address of browser
www.someSchool.edu/someDepartment/home.index
1a. client initiates TCP
connection to HTTP server
2. client sends HTTP
request message
5. client receives
response message
6. Steps 1-5 repeated for
each of 10 jpeg objects
time
1b. server “accepts”
connection, notifying
client
3. server receives request
message, forms/Creates
response message
4. server closes the TCP
connection.
25
School of Computer Science & Technology
2.1 nonpersistent HTTP connection
2.2 The Web and HTTP
Question:
 How many connections?
Each TCP connection transports exactly one
request msg and one response msg
11 TCP connections
These connections are parallel or serial?
User can configures modern browsers to control the
degree of parallelism
Most browsers open 5 to 10 parallel TCP
connections, and each connection handles one
request-response transaction
26
School of Computer Science & Technology
2.1 Response time modeling
2.2 The Web and HTTP
RTT: time to send a small
packet to travel from client
to server and back.
Response time:
 one RTT to initiate TCP
connection
 one RTT for HTTP request
and first few bytes of HTTP
response to return
 file transmission time
total = 2RTT+transmit time
initiate TCP
connection
RTT
Request file
time to
transmit
file
RTT
File received
time
time
27
School of Computer Science & Technology
2.2 Persistent HTTP connection
2.2 The Web and HTTP
Nonpersistent HTTP issues:
requires 2 RTTs per object
OS must work and allocate host resources for each
TCP connection
browsers often open parallel TCP connections to fetch the
referenced objects
Persistent HTTP
server leaves connection open after sending response
subsequent HTTP messages between same
client/server are sent over the connection established
previously
28
School of Computer Science & Technology
2.2 Persistent HTTP connection
2.2 The Web and HTTP
Persistent connection without pipelining:
client issues new request only when previous response
has been received
one RTT for each referenced object
Persistent connection with pipelining:
client sends requests as soon as it encounters a
referenced object
as little as one RTT for all the referenced objects
default in HTTP/1.1
29
School of Computer Science & Technology
3. HTTP Message format : request
Two types of HTTP message (RFC2616)
request message and response message
Request Message format
ASCII (human-readable format)
request line
(GET, POST,
HEAD commands)
header
lines
Carriage return +
Line feed(0x0D0A)
indicates end
of message head
Mozilla= Mosaic +Godzilla
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)
30
School of Computer Science & Technology
3.1 HTTP Request Message
2.2 The Web and HTTP
General format of a request message
Method
GET
Entity body of the request message is empty
POST
Entity body includes some parameters sent to server
The server can create response message according to the
parameters received
HEAD
Similar to GET, but the response message has no object
Used for debug
31
School of Computer Science & Technology
3.1 Uploading form input
2.2 The Web and HTTP
Post method:
Web page often
includes forms
input is uploaded to
server in entity body
GET+URL method:
Uses GET method
Input is uploaded in the
URL field of request
line:
http://www.google.com/search?hl=zh-CN&q=abcdedg&lr=
Entity body
33
School of Computer Science & Technology
3.1 Method types supported
2.2 The Web and HTTP
HTTP/1.0
Only three methods: GET/POST/HEAD
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
34
School of Computer Science & Technology
3.2 HTTP Response Message
2.2 The Web and HTTP
35
School of Computer Science & Technology
3.2 HTTP Response Message
2.2 The Web and HTTP
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 ...
36
School of Computer Science & Technology
3.2 HTTP Response Message
2.2 The Web and HTTP
Status Code and phrase
200 OK
 request succeeded, requested object is returned in the response
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
School of Computer Science & Technology
37
4. User-server Interaction: cookies
2.2 The Web and HTTP
Many major Web sites
use cookies
Four components:
1) Set-cookie header line in the
HTTP response message
2) cookie header line in HTTP
request message
3) cookie file kept on user’s host
and managed by user’s
browser
4) back-end database at Web site
Example:
Susan access Internet
always from same PC
She visits a specific ecommerce site for first
time
When initial HTTP
requests arrives at site,
site creates a unique
ID and creates an entry
in backend database
for ID
39
School of Computer Science & Technology
Cookies: keeping “state” (cont.)
client
Cookie file
ebay: 8734
Cookie file
amazon: 1678
ebay: 8734
one week later:
Cookie file
amazon: 1678
ebay: 8734
server
usual http request msg
usual http response +
Set-cookie: 1678
usual http request msg
cookie: 1678
usual http response msg
usual http request msg
cookie: 1678
usual http response msg
server
creates ID
1678 for user
cookiespecific
action
cookiespectific
action
40
School of Computer Science & Technology
4. Cookies (continued)
2.2 The Web and HTTP
What cookies can
bring:
authorization
shopping carts
recommendations
user session state
(Web e-mail)
aside
Cookies and privacy:
 cookies permit sites to
learn a lot about you
 you may supply name
and e-mail to sites
 search engines use
redirection & cookies to
learn yet more
 advertising companies
obtain info across sites
41
School of Computer Science & Technology
6. Web Caching
2.2 The Web and HTTP
Goal: satisfy client request without involving origin
server
 user sets browser
 Web accesses via proxy
 browser sends all HTTP requests to the cache
 Cache acts as both client and server
 Typically cache is installed by ISP
42
School of Computer Science & Technology
6. More about Web caching
2.2 The Web and HTTP
Why Web caching?
reduce response time.
reduce traffic on the access link.
Internet dense with caches enables “poor”
content providers to effectively deliver content
so does P2P file sharing
43
School of Computer Science & Technology
6. Caching example
2.2 The Web and HTTP
origin
 average object size = 100,000
servers
bits
public
 avg. request rate from
Internet
institution’s browsers to origin
servers = 15/sec
 delay from institutional router to
1.5 Mbps
any origin server and back to
access link
router = 2 sec
institutional
network
10 Mbps LAN
 total delay = Internet delay +
access delay + LAN delay
= 2 sec + minutes +
institutional
milliseconds
cache
UtilizationLAN = (15 requests/sec)*(100kbits/Request)/10Mbps=0.15
UtilizationAccess = (15 Requests/sec)*(100kbits/Request)/1.5Mbps=1
44
School of Computer Science & Technology
6. Caching example
2.2 The Web and HTTP
Possible solution
increase bandwidth of access link to 10 Mbps
Consequences
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
45
School of Computer Science & Technology
6. Caching example
2.2 The Web and HTTP
Install a cache
hit rate is 0.4
40% requests will be satisfied
almost immediately(10ms)
60% requests satisfied by
origin server
utilization of access link
reduced to 60%, resulting in
negligible delays
total avg delay = Internet
delay + access delay + LAN
delay = 0.6*(2.01) s
+0.4*(0.01) ms
origin
servers
public
Internet
1.5 Mbps
access link
institutional
network
10 Mbps LAN
institutional
cache
46
School of Computer Science & Technology
7. Conditional GET
2.2 The Web and HTTP
An HTTP request Message is so called
conditional GET message if:
Use GET method, and
Includes an If-Modified-Since: header line
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: <date>
 server: response contains no object if cached copy is up-to-date:
HTTP/1.0 304 Not Modified
47
School of Computer Science & Technology
7. Conditional GET: example
2.2 The Web and HTTP
server
cache
HTTP request msg
If-modified-since:
<date>
HTTP response
object
not
modified
HTTP/1.0
304 Not Modified
HTTP request msg
If-modified-since:
<date>
HTTP response
object
modified
HTTP/1.0 200 OK
<data>
48
School of Computer Science & Technology
Chapter 2: roadmap
2.1 Principles of Network Applications
2.2 The Web and HTTP
2.3 File Transfer Protocol—FTP
2.4 Electronic Mail in the Internet
2.5 DNS- The Internet Directory Service
2.6 P2P—File sharing
2.7 Socket Programming with TCP
2.8 Socket Programming with UDP
2.9 Building a Simple Web Server
2.10 Summary
49
School of Computer Science & Technology
Introduction
2.4 Electronic Mail in the Internet
 E-mail is an asynchronous communication system
Three major components:
 user agents
 mail servers
 SMTP: simple mail transfer protocol
User Agent
 “mail reader/composer”
 composing, editing, reading mail messages
 e.g., Eudora, Outlook, Netscape Messenger
 outgoing, incoming messages stored on server
55
School of Computer Science & Technology
Introduction
2.4 Electronic Mail in the Internet
Mail Servers
the core of the e-mail infrastructure
mailbox contains incoming mails for user
message queue buffering the outgoing (to be sent)
mail messages
SMTP
principal application-layer protocol of e-mail
transfers mail from sender’s mail server to the
recipient’s mail server
client side
server side
runs over TCP, port 25
56
School of Computer Science & Technology
Introduction
2.4 Electronic Mail in the Internet
mail
server
user
agent
SMTP
SMTP
mail
server
user
agent
SMTP
user
agent
outgoing
message queue
user mailbox
mail
server
user
agent
user
agent
user
agent
57
School of Computer Science & Technology
1. SMTP [RFC 2821]
2.4 Electronic Mail in the Internet
SMTP transfers messages from sender’s mail
server to the recipient’s mail server
persistent TCP connection
Messages (header and body) must be in 7-bit
ASCII
save the scare transmission capacity
outdated….
SMTP server uses CRLF.CRLF to determine
end of message
58
School of Computer Science & Technology
1. SMTP operation
2.4 Electronic Mail in the Internet
1) Alice uses UA to compose
4) SMTP client sends Alice’s
message over the TCP
connection
5) Bob’s mail server places the
message in Bob’s mailbox
6) Bob invokes his UA to read
message
message and “to”
[email protected]
2) Alice’s UA sends message to
her mail server; message
placed in message queue
3) Client side of SMTP opens
TCP connection with Bob’s
mail server
1
user
agent
2
mail
server
3
mail
server
4
5
6
user
agent
59
School of Computer Science & Technology
2. Comparison with HTTP
2.4 Electronic Mail in the Internet
Common:
both used to transfer files from one host to another
both can use persistent TCP
Differences:
HTTP is a pull protocol and SMTP is a push protocol
SMTP requires each msg to be in 7-bit ASCII format
How a document consisting the text and image is
handles?
HTTP: each object encapsulated in its own response msg
SMTP: multiple objects sent in a multipart msg
61
School of Computer Science & Technology
3.1 Mail message format
2.4 Electronic Mail in the Internet
SMTP(RFC 822: standard
for text message format)
header lines
To:
From:
Subject:
different from SMTP
commands!
Blank line
header
body
body
the “message”, ASCII
characters only
62
School of Computer Science & Technology
3.2 multimedia extensions for non ASCII data
2.4 Electronic Mail in the Internet
MIME: Multipurpose Internet Mail Extension
 RFC 2045, 2056
Two key MIME headers
Content-Type
Content-Transfer-Encoding
MIME version
method used
to encode data
multimedia data
type, subtype,
parameter declaration
encoded data
From: [email protected]
To: [email protected]
Subject: Picture of yummy crepe.
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Type: image/jpeg
base64 encoded data .....
.........................
......base64 encoded data
School of Computer Science & Technology
63
3.3 The Received Message
2.4 Electronic Mail in the Internet
Receiving server appends a Received: header
line to the top of the received message
Received: from hambufer.edu by sushi.jp 12 Oct 98 15:27:51 GMT
Received: from crepes.fr by hamburger.edu; 12 Oct 98 15:27:39 GMT
From: [email protected]
To: [email protected]
Subject: Picture of yummy crepe.
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Type: image/jpeg
base64 encoded data ……
…………………………………………………
……………….. base64 encoded data
Multiple Received:header lines in a msg.
 bob configures his mail server to forward all of his mails to
sushi.jp
School of Computer Science & Technology
64
4. Mail access protocols
2.4 Electronic Mail in the Internet
user
agent
SMTP
SMTP
sender’s mail
server
access
protocol
user
agent
receiver’s mail
server
 SMTP: delivery/storage to receiver’s server
 Mail access protocol: retrieval from server
 POP: Post Office Protocol [RFC 1939]
authorization (agent <-->server) and download
 IMAP: Internet Mail Access Protocol [RFC 1730]
more features (more complex)
manipulation of stored msgs on server
 HTTP: Hotmail , Yahoo! Mail, etc.
65
School of Computer Science & Technology
Chapter 2: roadmap
2.1 Principles of Network Applications
2.2 The Web and HTTP
2.3 File Transfer Protocol—FTP
2.4 Electronic Mail in the Internet
2.5 DNS- The Internet Directory Service
2.6 P2P File sharing
2.7 Socket Programming with TCP
2.8 Socket Programming with UDP
2.9 Building a Simple Web Server
2.10 Summary
69
School of Computer Science & Technology
Introduction
2.5 DNS The Internet‘s
Directory Service
-
People: many identifiers:
I.D.card#, name, passport #
Internet hosts, routers:
IP address (32 bit) - used for addressing datagrams
“name”, e.g., ww.yahoo.com - used by humans
Q: How to map between IP addresses and domain
name ?
DNS
70
School of Computer Science & Technology
Introduction
2.5 DNS The Internet‘s
Directory Service
-
Domain Name System:
A distributed database
implemented in hierarchy of many name servers
An application-layer protocol
host, routers, name servers to communicate to
resolve names (address/name translation)
71
School of Computer Science & Technology
1. DNS Services
2.5 DNS The Internet‘s
Directory Service
-
Hostname to IP address translation
Host aliasing
Canonical and alias names
d7.a.sohu.com (Canonical)
www.sohu.com (alias)
Mail server aliasing
Load distribution (load balancing)
replicated Web servers: set of IP addresses for one
canonical name
72
School of Computer Science & Technology
2. Overview of How DNS Works?
2.5 DNS The Internet‘s
Directory Service
-
Why not centralize DNS?
single point of failure
traffic volume
distant centralized database
maintenance
doesn’t scale!
Classes of DNS server
Root DNS servers
Top-Level DNS servers
Authoritative DNS servers
73
School of Computer Science & Technology
2.1 Distributed, Hierarchical Database
2.5 DNS The Internet‘s
Directory Service
TLD Servers
Root DNS Servers
-
com DNS servers
yahoo.com
DNS servers
amazon.com
DNS servers
org DNS servers
edu DNS servers
pbs.org
DNS servers
poly.edu
umass.edu
DNS servers DNS servers
74
School of Computer Science & Technology
2.1 Distributed, Hierarchical Database
2.5 DNS The Internet‘s
Directory Service
-
Classes of DNS server
Root DNS servers
13 root servers labeled A through M
Top-Level servers
Authoritative DNS servers
75
School of Computer Science & Technology
2.1 Root DNS Servers
2.5 DNS The Internet‘s
Directory Service
a Verisign, Dulles, VA
c Cogent, Herndon, VA (also Los Angeles)
d U Maryland College Park, MD
g US DoD Vienna, VA
k RIPE London (also Amsterdam, Frankfurt)
h ARL Aberdeen, MD
j Verisign, ( 11 locations)
i Autonomica, Stockholm (plus 3 other locations)
-
m WIDE Tokyo
e NASA Mt View, CA
f Internet Software C. Palo Alto, CA
(and 17 other locations)
b USC-ISI Marina del Rey, CA
l ICANN Los Angeles, CA
76
School of Computer Science & Technology
2.1 Distributed, Hierarchical Database
2.5 DNS The Internet‘s
Directory Service
-
Classes of DNS server
Root DNS servers
Top-Level servers
responsible for com, org, net, edu, etc, and all toplevel country domains: cn uk, fr, ca, jp.
Authoritative DNS servers
77
School of Computer Science & Technology
2.1 Distributed, Hierarchical Database
2.5 DNS The Internet‘s
Directory Service
-
Classes of DNS server
Root DNS servers
Top-Level servers
Authoritative DNS servers
organization’s DNS servers
providing authoritative hostname to IP mappings
for organization’s hosts (e.g., Web and mail).
Can be maintained by organization or service provider
78
School of Computer Science & Technology
2.1 Local Name Server
2.5 DNS The Internet‘s
Directory Service
Does not strictly belong to the hierarchy
Each ISP (residential ISP, company,
university) has one.
-
Also called “default name server”
When a host makes a DNS query, query
is sent to its local DNS server
acts as a proxy, forwards the query into the
hierarchy.
79
School of Computer Science & Technology
2.1 Query : Iterative and Recursive
2.5 DNS The Internet‘s
Directory Service
-
root DNS server
recursive query:
 puts burden of name
resolution on
contacted name
server
local DNS server
2
3
7
6
TLD DNS
server
dns.poly.edu
iterated query:
5
1
8
 contacted server
replies with name of
server to contact
requesting host
 “I don’t know this
cis.poly.edu
name, but ask this
server”
4
authoritative DNS server
dns.cs.umass.edu
gaia.cs.umass.edu
80
School of Computer Science & Technology
2.1 Query Example
2.5 DNS The Internet‘s
Directory Service
-
root DNS
server
2
3
local DNS server
4
dns.poly.edu
5
TLD DNS
server
6
1
8
requesting host
cis.poly.edu
7
authoritative DNS server
dns.cs.umass.edu
gaia.cs.umass.edu
 Host at cis.poly.edu wants the IP address of
gaia.cs.umass.edu
School of Computer Science & Technology
81
2.2 DNS: caching
2.5 DNS The Internet‘s
Directory Service
-
once (any) server learns a mapping, it caches
the mapping
cache entries timeout after some time
local name servers often caches the TLD servers
root name servers not often visited
update/notify mechanisms under design by
IETF
Dynamic Updates in the Domain Name System (DNS
UPDATE) RFC 2136
83
School of Computer Science & Technology
3. DNS records
2.5 DNS The Internet‘s
Directory Service
DNS: distributed db storing resource records (RR)
(name, value, type, ttl)
- Type=A
name is hostname
value is IP address
Type=NS
 Type=CNAME
 name is alias name for
“canonical” (the real) name
Name =www.ibm.com
Value=servereast.bac
kup2.ibm.com
name is a domain
 value is canonical name
value is hostname of
 Type=MX
authoritative name
 value is canonical
server for this domain
 Name=alias name of mail server
84
School of Computer Science & Technology
Chapter 2: roadmap
2.1 Principles of Network Applications
2.2 The Web and HTTP
2.3 File Transfer Protocol—FTP
2.4 Electronic Mail in the Internet
2.5 DNS- The Internet Directory Service
2.6 P2P File sharing
2.7 Socket Programming with TCP
2.8 Socket Programming with UDP
2.9 Building a Simple Web Server
2.10 Summary
92
School of Computer Science & Technology
1. Architectures for Locating Contents
2.6 P2P File Sharing
Centralized Directory
Query Flooding
Exploiting Heterogeneity
94
School of Computer Science & Technology
1. Centralized Directory-Napster
2.6 P2P File Sharing
original “Napster” design
1) When app starts, it informs a
central server:
Bob
centralized
directory server
 IP address
 Shared contents
1
peers
2) Server checks the peers ‘s state
(on or off) periodically
1
 remove the entry
Example:
 Alice queries for “Hey Jude”
 Alice requests file from Bob
①inform and update
③file transfer
3
1
2
1
② Query for content
Alice
95
School of Computer Science & Technology
1. Centralized Directory-Napster
2.6 P2P File Sharing
Problems of Centralized Directory
Single point of failure
Performance bottleneck
Copyright infringement
file transfer is decentralized , but
locating content is highly centralized
96
School of Computer Science & Technology
2. Query
Flooding - Gnutella
2.6 P2P File Sharing
Peers form an overlay network
edge between peer X and Y if there’s a TCP connection
all active peers and edges form the overlay net
edge is not a physical link
a peer will typically be connected with < 10 overlay
neighbors
fully distributed
no central server
public domain protocol
97
School of Computer Science & Technology
2. Query
Flooding - Gnutella
2.6 P2P File Sharing
 Query message
sent over existing TCP
connections
 peers forward
Query message
 QueryHit
sent over
reverse
Query
path
File transfer:
HTTP
Query
QueryHit
QueryHit
Scalability:
limited scope
flooding
98
School of Computer Science & Technology
2. Query
Flooding - Gnutella
2.6 P2P File Sharing
 Joining peer X must find some other peer in Gnutella
network
 use list of candidate peers
 X sequentially attempts to make TCP with peers on list
until one connection setup with some peer Y
 X sends Ping message to Y; Y forwards Ping message.
(Ping also includes peer-count field)
 All peers receiving Ping message respond with Pong
message
 X receives many Pong messages. It can then setup
additional TCP connections
99
School of Computer Science & Technology
3. Exploiting Heterogeneity: KaZaA
2.6 P2P File Sharing
 Each peer is either a group
leader or assigned to a group
leader.
TCP connection between
peer and its group leader.
TCP connections between
some pairs of group leaders.
 Group leader tracks the
content in all its children.
ordinary peer
group-leader peer
neighoring relationships
in overlay network
100
School of Computer Science & Technology
3. Exploiting Heterogeneity: KaZaA
2.6 P2P File Sharing
Each file has a hash and a descriptor;
Client sends keyword query to its group leader;
If (match founded)
Group leader responds with matches;
else
group leader forwards query to other group leaders,
they respond with matches;
Client then selects files for downloading;
101
School of Computer Science & Technology
3. Exploiting Heterogeneity: KaZaA
2.6 P2P File Sharing
How to improve the performance?
Request queuing
Incentive priorities
Parallel downloading
102
School of Computer Science & Technology
Chapter 2: roadmap
2.1 Principles of Network Applications
2.2 The Web and HTTP
2.3 File Transfer Protocol—FTP
2.4 Electronic Mail in the Internet
2.5 DNS- The Internet Directory Service
2.6 P2P File sharing
2.7 Socket Programming with TCP
2.8 Socket Programming with UDP
2.9 Building a Simple Web Server
2.10 Summary
103
School of Computer Science & Technology
Introduction
2.7 Socket Programming
with TCP
Goal: learn how to build client/server application that
communicate using sockets
Socket API
 introduced in BSD4.1 UNIX,
1981
 explicitly created, used, and
released by apps
 client/server paradigm
 two types of transport service
via socket API:
 unreliable datagram
 reliable
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
104
School of Computer Science & Technology
1. Socket-programming with TCP
2.7 Socket Programming
with 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
process
controlled by
operating
system
TCP with
buffers,
variables
process
socket
socket
host or
server
internet
TCP with
buffers,
variables
controlled by
application
developer
controlled by
operating
system
host or
server
105
School of Computer Science & Technology
1. Socket-programming with TCP
2.7 Socket Programming
with TCP
Client/Server model
client initiating the
contact with the server
server process must
first be running
server must have
created socket (door)
that welcomes client’s
contact
106
School of Computer Science & Technology
1. Socket-programming with TCP
2.7 Socket Programming
with TCP
A client contacts the server by:
creating client-local TCP socket
specifies ( IP address, port number) of server process
client TCP establishes connection to server TCP
Server side
When contacted by a client, server TCP creates new
socket to communicate with the client
allows server to talk with multiple clients
source socket used to distinguish clients ( more in Chap 3)
107
School of Computer Science & Technology
1. Socket-programming with TCP
2.7 Socket Programming
with TCP
application viewpoint
TCP provides reliable, in-order transfer of bytes stream
(“pipe”) between the sender and the receiver.
What’s a stream?
 a sequence of characters
that flow into or out of a
process.
 input stream is attached to
some input source for the
process( keyboard or a
socket) .
 output stream is attached to
an output source, (monitor
or a socket).
108
School of Computer Science & Technology
2. An Example in Java
inFromUser
input
stream
monitor
Process
output
stream
inFromServer
2) server reads line from socket ,
converts the line to uppercase,
and sends back to the client
3) client reads and prints the
modified line received from the
socket (inFromServer
stream)
keyboard
outToServer
2.7 Socket Programming
with TCP
1) client reads line from keyboard
(inFromUser stream), and
sends to server via socket
(outToServer stream)
client
TCP
clientSocket
socket
to network
input
stream
TCP
socket
from network
109
School of Computer Science & Technology
2.1 Client/Server socket interaction
2.7 Socket Programming
with TCP
Server (running on hostid)
Client
create socket,
port=x, for
incoming request:
welcomeSocket =
ServerSocket()
TCP
wait for incoming
connection request connection
connectionSocket =
welcomeSocket.accept()
read request from
connectionSocket
write reply to
connectionSocket
close
connectionSocket
setup
create socket,
connect to hostid, port=x
clientSocket =
Socket()
send request using
clientSocket
read reply from
clientSocket
close
clientSocket
School of Computer Science & Technology
110
Example: Java server (TCP)
import java.io.*;
import java.net.*;
class TCPServer {
Create
welcoming socket
at port 6789
Wait, on welcoming
socket for contact
by client
Create input
stream, attached
to socket
public static void main(String argv[]) throws Exception
{
String clientSentence;
String capitalizedSentence;
ServerSocket welcomeSocket = new ServerSocket(65123);
while(true)
{
Socket connectionSocket = welcomeSocket.accept();
BufferedReader inFromClient = new BufferedReader(
new InputStreamReader(
connectionSocket.getInputStream()));
111
School of Computer Science & Technology
Example: Java server (TCP), cont
Create output
stream, attached
to socket
DataOutputStream outToClient =
new DataOutputStream(connectionSocket.getOutputStream());
Read in line
from socket
clientSentence = inFromClient.readLine();
capitalizedSentence = clientSentence.toUpperCase() + '\n';
Write out line
to socket
outToClient.writeBytes(capitalizedSentence);
}
}
}
End of while loop,
loop back and wait for
another client connection
112
School of Computer Science & Technology
Example: Java client (TCP)
TCPClient.java
Create
input stream
Create
client socket,
connect to server
Create
output stream
attached to socket
import java.io.*;
import java.net.*;
public class TCPClient
{ public static void main(String argv[]) throws Exception
{
String sentence;
String modifiedSentence;
BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in));
Socket clientSocket = new Socket(“localhost", 65123);
DataOutputStream outToServer =
new DataOutputStream (clientSocket.getOutputStream());
113
School of Computer Science & Technology
Example: Java client (TCP), cont.
Create
input stream
attached to socket
BufferedReader inFromServer =
new BufferedReader ( new
InputStreamReader (clientSocket.getInputStream()));
//input a line from keyboard
sentence = inFromUser.readLine();
Send line
to server
outToServer.writeBytes(sentence + '\n');
Read line
from server
modifiedSentence = inFromServer.readLine();
System.out.println("FROM SERVER: " + modifiedSentence);
clientSocket.close(); //close socket and TCP connection
}
}
114
School of Computer Science & Technology
Chapter 2: roadmap
2.1 Principles of Network Applications
2.2 The Web and HTTP
2.3 File Transfer Protocol—FTP
2.4 Electronic Mail in the Internet
2.5 DNS - The Internet Directory Service
2.6 P2P File sharing
2.7 Socket Programming with TCP
2.8 Socket Programming with UDP
2.9 Building a Simple Web Server
2.10 Summary
115
School of Computer Science & Technology
Introduction
2.8 Socket Programming
with UDP
UDP: no “connection” between client and server
no handshaking
sender explicitly attaches IP address and port of
destination to each packet
server must extract IP address, port of sender from
received packet
transmitted data received may be out of order, or lost
application viewpoint
UDP provides unreliable transfer
of groups of bytes (“datagrams”)
between client and server
116
School of Computer Science & Technology
1. Client/server socket interaction: UDP
2.8 Socket Programming
with UDP
Server (running on hostid)
create socket,
port=x, for
incoming request:
serverSocket =
DatagramSocket()
read request from
serverSocket
write reply to
serverSocket
specifying client
host address,
port number
Client
create socket,
clientSocket =
DatagramSocket()
Create, address (hostid, port=x,
send datagram request
using clientSocket
read reply from
clientSocket
close
clientSocket
117
School of Computer Science & Technology
2. Example: Java client (UDP)
Client
process
monitor
inFromUser
input
stream
Process
Input: receives
packet (TCP
received “byte
stream”)
packet (TCP sent
“byte stream”)
UDP
packet
receivePacket
Output: sends
sendPacket
2.8 Socket Programming
with UDP
keyboard
client
UDP
clientSocket
socket
to network
UDP
packet
UDP
socket
from network
118
School of Computer Science & Technology
Example: Java server (UDP)
import java.io.*;
import java.net.*;
Create
datagram socket
at port 65132
class UDPServer {
public static void main(String args[]) throws Exception
{
DatagramSocket serverSocket = new DatagramSocket(65123);
byte[] receiveData = new byte[1024];
byte[] sendData = new byte[1024];
while(true)
{
Create space for
received datagram
Receive
datagram
DatagramPacket receivePacket =
new DatagramPacket(receiveData, receiveData.length);
serverSocket.receive(receivePacket);
119
School of Computer Science & Technology
Example: Java server (UDP), cont
String sentence = new String(receivePacket.getData());
Get IP addr
port #, of
sender
InetAddress IPAddress = receivePacket.getAddress();
int port = receivePacket.getPort();
String capitalizedSentence = sentence.toUpperCase();
sendData = capitalizedSentence.getBytes();
Create datagram
to send to client
DatagramPacket sendPacket =
new DatagramPacket(sendData, sendData.length, IPAddress,
port);
Write out
datagram
to socket
serverSocket.send(sendPacket);
}
}
}
End of while loop,
loop back and wait for
another datagram
120
School of Computer Science & Technology
Example: Java client (UDP)
import java.io.*;
import java.net.*;
Create
input stream
Create
client socket
Translate
hostname to IP
address using DNS
type conversion
string to bytes array
public class UDPClient {
public static void main(String args[]) throws Exception
{
BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in));
DatagramSocket clientSocket = new DatagramSocket();
InetAddress IPAddress = InetAddress.getByName(“localhost");
byte[] sendData = new byte[1024];
byte[] receiveData = new byte[1024];
String sentence = inFromUser.readLine();
sendData = sentence.getBytes();
121
School of Computer Science & Technology
Example: Java client (UDP), cont.
Create datagram with
data-to-send,
length, IP addr, port
DatagramPacket sendPacket =
new DatagramPacket (sendData, sendData.length, IPAddress, 65123);
Send datagram
to server
clientSocket.send(sendPacket);
Read datagram
from server
clientSocket.receive(receivePacket);
DatagramPacket receivePacket =
new DatagramPacket(receiveData, receiveData.length);
String modifiedSentence =
new String (receivePacket.getData());
System.out.println("FROM SERVER:" + modifiedSentence);
clientSocket.close();
}
}
122
School of Computer Science & Technology
Chapter 2: roadmap
2.1 Principles of Network Applications
2.2 The Web and HTTP
2.3 File Transfer Protocol—FTP
2.4 Electronic Mail in the Internet
2.5 DNS- The Internet Directory Service
2.6 P2P File sharing
2.7 Socket Programming with TCP
2.8 Socket Programming with UDP
2.9 Building a Simple Web Server
2.10 Summary
123
School of Computer Science & Technology
Introduction
2.9 Building a Simple Web
Server
handles only one HTTP request
accepts the request and parses the header
obtains requested file from server’s file system
creates HTTP response message:
header lines + file
sends response message to client
after creating the server, you can request file
using a browser
see text and references for details
124
School of Computer Science & Technology
Chapter 2: Summary
Our study of network apps now complete!
 Application architectures
 specific protocols:
client-server/P2P/Hybrid
HTTP
 application service
FTP
requirements:
SMTP, POP, IMAP
 reliability, bandwidth, delay
DNS
 Internet transport service
 socket programming
model
with TCP and UDP
reliable: TCP
unreliable, datagrams: UDP
125
School of Computer Science & Technology
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
 control vs. data msgs
in-band, out-of-band
 centralized vs. decentralized
 stateless vs. stateful
 reliable vs. unreliable msg
transfer
 “complexity at network edge”
126
School of Computer Science & Technology
Homework and Program Assignment
homework:
P171: 1
P172: 4,6,8
P173: 9,
P175: 15
due date: 2 weeks
Programming Assignment (P.178):
assignment 1: multithreaded web server
due date
: 4 weeks
127
School of Computer Science & Technology