0% found this document useful (0 votes)
6 views107 pages

Module 1

The document outlines the principles of network applications, focusing on application layer protocols, client-server and peer-to-peer architectures, and transport services available to applications. It details the functioning of HTTP, including its connection types, request and response formats, and the use of cookies and web caching to enhance user experience. Additionally, it discusses the differences between TCP and UDP, emphasizing the importance of reliable data transfer and the various transport services provided by the Internet.

Uploaded by

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

Module 1

The document outlines the principles of network applications, focusing on application layer protocols, client-server and peer-to-peer architectures, and transport services available to applications. It details the functioning of HTTP, including its connection types, request and response formats, and the use of cookies and web caching to enhance user experience. Additionally, it discusses the differences between TCP and UDP, emphasizing the importance of reliable data transfer and the various transport services provided by the Internet.

Uploaded by

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

Syllabus

Module 1
Application Layer: Principles of Network Applications: Network Application Architectures,
Processes Communicating, Transport Services Available to Applications, Transport Services
Provided by the Internet, Application-Layer Protocols. The Web and HTTP: Overview of HTTP,
Non-persistent and Persistent Connections, HTTP Message Format, User-Server Interaction:
Cookies, Web Caching, The Conditional GET, File Transfer: FTP Commands & Replies, Electronic
Mail in the Internet: SMTP, Comparison with HTTP, Mail Message Format, Mail Access Protocols,
DNS; The Internet's Directory Service: Services Provided by DNS, Overview of How DNS Works,
DNS Records and Messages, Peer-to-Peer Applications: P2P File Distribution, Distributed Hash
Tables, Socket Programming: creating Network Applications: Socket Programming with UDP,
Socket Programming with TCP.
2.1 Principles of Network
Applications
Network-applications are the driving forces for the explosive
development of the internet.
• Examples of network-applications:
1) Web

2) Social networking (Facebook, Twitter)

3) File transfers

4) Video distribution (YouTube)

5) E-mail

6) Real-time video conferencing (Skype)

7) P2P file sharing

8) On-line games (World of Warcraft)


2.1.1 Network Application
Architectures
There are two different network application architecture, they are
• Client Server Architecture
• P2P Architecture
Client Server Architecture:
• In client-server architecture, there is an always-on host, called the server, which provides services when it
receives requests from many other hosts, called clients.
• Some of the better-known applications with a client-server architecture include the Web,FTP, Telnet, and
e-mail.
Peer-to-peer (P2P) Architecture
• In a P2P architecture, there is minimal dependence on dedicated servers in data centers.
• The application employs direct communication between pairs of intermittently connected hosts, called
peers.
• Features:
• Self-scalability
• Cost effective
2.1.2 Processes Communicating
• A Process is a program or application under execution.
• Processes on two different end systems communicate with each other
by exchanging messages across the computer network.
Client and Server Processes
• A network application consists of pairs of processes that send messages to each other over a
network.
• For example, in the Web application a client browser process exchanges messages with a Web
server process.
• In the context of a communication session between a pair of processes, the process that initiates
the communication is labeled as the client.
• The process that waits to be contacted to begin the session is the server
The Interface between the Process and the
Computer Network
Addressing Processes
• To identify the receiving-process, two pieces of information need to be specified:
• IP address of the destination-host.
• Port-number that specifies the receiving-process in the destination-host.
• In the Internet, the host is identified by IP address.
• An IP address is a 32-bit that uniquely identify thehost.
• Sending-process needs to identify receiving-process ‘.’ a host may run several
network-applications.
• For this purpose, a destination port-number is used.
• For example,
• A Web-server is identified by port-number 80.
• A mail-server is identified by port-number 25.
2.1.3 Transport Services Available
to Applications
•Networks usually provide more than one transport-layer protocols for different applications.

•An application-developer should choose certain protocol according to the type of


applications.

•Different protocols may provide different services.

•The possible services that a transport layer can offer to application layer can be
broadly classified into four dimensions
• Reliable Data Transfer

• Throughput

• Timing

• Security
Reliable Data Transfer
• Packets can get lost within a computer network.
• For example, a packet can overflow a buffer in a router, or can be discarded by a host or router
after having some of its bits corrupted.
• For many applications—such as electronic mail, file transfer, remote host access, Web document
transfers, and financial applications—data loss can have devastating consequences.
• Thus, to support these applications, something has to be done to guarantee that the data sent by
one end of the application is delivered correctly and completely to the other end of the application.
Throughput
• Transport-layer protocol could provide guaranteed available throughput at some specified rate.
• With such a service, the application could request a guaranteed throughput of r bits/sec, and the
transport protocol would then ensure that the available throughput is always at least r bits/sec.
• Such a guaranteed throughput service would appeal to many applications.
• For example, if an Internet telephony application encodes voice at 32 kbps, it needs to send data
into the network and have data delivered to the receiving application at this rate.
Timing
• A transport-layer protocol can also provide timing guarantees.
• Interactive real-time applications, such as Internet telephony, virtual environments,
teleconferencing, and multiplayer games require tight timing constraints on data delivery
in order to be effective.

Security
• Transport protocol can provide an application with one or more security services.
• For example, in the sending host, a transport protocol can encrypt all data transmitted by the
sending process, and in the receiving host, the transport-layer protocol can decrypt the data
before delivering the data to the receiving process.
• A transport protocol can provide security services like confidentiality, data integrity and endpoint
authentication
Transport Services Provided by the Internet
• The Internet makes two transport protocols available to applications, UDP and TCP

Application Data Loss Throughput Time Time Sensitive

File transfer/download No loss Elastic No

E-mail No loss Elastic No

Web documents No loss Elastic (few kbps) No

Internet-telephony/ Loss-tolerant Audio: few kbps–1 Mbps Video: Yes: 100s of ms


Video-conferencing 10 kbps–5 Mbps

Streaming stored audio/video Loss-tolerant Same as above Yes: few seconds

Interactive games Loss-tolerant Few kbps–10 kbps Yes: 100s of ms

Instant messaging No loss Elastic Yes and no


TCP service:
• Connection Oriented Service:
• Client and server exchanges control information with each other before the application level
messages begin to flow.
• 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 throughput guarantee, security
UDP service:
• Connectionless service
• No handshake between the two processes starts to communicate
• unreliable data transfer:
• between sending and receiving process
• does not provide:
• reliability, flow control, congestion control, timing, throughput guarantee, security,
orconnection setup
Internet apps: application,
transport protocols
Securing TCP
TCP & UDP
• no encryption
• cleartext passwds sent into socket traverse Internet in cleartext
SSL
• provides encrypted TCP connection
• data integrity
• end-point authentication
SSL is at app layer
• Apps use SSL libraries, which “talk” to TCP
SSL socket API
 cleartext passwds sent into socket traverse Internet encrypted
App-layer protocol
• 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
• open protocols:
• defined in RFCs
• allows for interoperability
• e.g., HTTP, SMTP
• proprietary protocols:
• e.g., Skype
Web and HTTP
First, a review…
• The HTTP(Hyper Text Transfer Protocol) is Web’s Application layer protocol.
• web page consists of objects
• object can be HTML file, JPEG image, Java applet, audio file,…
• web page consists of base HTML-file which includes several referenced objects
• each object is addressable by a URL, e.g.,
HTTP overview
HTTP: hypertext transfer protocol
• Web’s application layer protocol
• client/server model
• client: browser that requests, receives,
(using HTTP protocol) and “displays”
Web objects
• server: Web server sends (using HTTP
protocol) objects in response to requests
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
HTTP connections
non-persistent HTTP
• at most one object sent over TCP connection
• connection then closed
• downloading multiple objects required multiple connections

persistent HTTP
• multiple objects can be sent over single TCP connection between client, server
Non-persistent HTTP
Non-persistent HTTP (cont.)
Non-persistent HTTP: response time
RTT (definition): time for a small packet to travel from
client to server and back
HTTP 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
• non-persistent HTTP response time =
2RTT+ file transmission time
Persistent HTTP
non-persistent HTTP issues:
• OS overhead for each TCP connection
• requires 2 RTTs per object
persistent HTTP:
• server leaves connection open after sending response
• subsequent HTTP messages between same client/server sent over open
connection
• client sends requests as soon as it encounters a referenced object
• as little as one RTT for all the referenced objects
HTTP request message
HTTP request message: general format
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
Uploading form input
POST method:
• web page often includes form input
• input is uploaded to server in entity body
URL method:
• uses GET method
• input is uploaded in URL field of request line:

www.somesite.com/animalsearch?monkeys&banana
HTTP response message
General Format of HTTP response message
HTTP response status codes
• status code appears in 1st line in server-to-client response message.
• some sample codes:
200 OK
• request succeeded, requested object later in this msg
301 Moved Permanently
• requested object moved, new location specified later in this msg (Location:)
400 Bad Request
• request msg not understood by server
404 Not Found
• requested document not found on this server
505 HTTP Version Not Supported
Trying out HTTP (client side) for yourself
User-server state: cookies
many Web sites use cookies
four components:
1) cookie header line of HTTP response message
2) cookie header line in next HTTP request message
3) cookie file kept on user’s host, managed by user’s browser
4) back-end database at Web site
example:
• Susan always access Internet from PC
• visits specific e-commerce site for first time
• when initial HTTP requests arrives at site, site creates:
• unique ID
• entry in backend database for ID
Cookies: keeping “state”
client server

ebay 8734
usual http request msg Amazon server
cookie file creates ID
usual http response
1678 for user create backend
ebay 8734
set-cookie: 1678 entry database
amazon 1678
usual http request msg
cookie: 1678 cookie- access
specific
usual http response msg action

one week later:


access
ebay 8734 usual http request msg
amazon 1678 cookie: 1678 cookie-
specific
usual http response msg action
Application Layer 2-37
Cookies (continued)
what cookies can be used for:
• authorization
• shopping carts
• recommendations
• user session state (Web e-mail)
cookies and privacy:
• cookies permit sites to learn a lot about you
• you may supply name and e-mail to sites
Web caches (proxy server)
goal: satisfy client request without involving origin
server
• user sets browser: Web
accesses via cache
• browser sends all HTTP requests proxy
to cache HT st
TP u e
req server req
• object in cache: cache HT ues P se
client TP t H TT po n
res res origin
returns object pon T P server
se HT
• else cache requests object es
t
u
from origin server, then req e
TT P o ns
returns object to client p
H res
T TP
H

client origin
server

Application Layer 2-39


More about Web caching
• cache acts as both client and server
• server for original requesting client
• client to origin 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 (so too
does P2P file sharing)
Caching example:
assumptions:
 avg object size: 100K bits origin
 avg request rate from servers
browsers to origin public
servers:15/sec Internet
 avg data rate to browsers:
1.50 Mbps
 RTT from institutional router
to any origin server: 2 sec 1.54 Mbps
access link
 access link rate: 1.54 Mbps
problem! institutional
consequences: network
1 Gbps LAN
 LAN utilization: 15%
 access link utilization = 99%
 total delay = Internet delay
+ access delay + LAN delay
= 2 sec + minutes + usecs
Application Layer 2-41
Caching example: install local cache
assumptions:
 avg object size: 100K bits origin
 avg request rate from servers
browsers to origin public
servers:15/sec Internet
 avg data rate to browsers:
1.50 Mbps
 RTT from institutional router
to any origin server: 2 sec 1.54 Mbps
access link
 access link rate: 1.54 Mbps
institutional
consequences: network
 ?
LAN utilization: 15% 1 Gbps LAN
 ?
access link utilization = 100% local web
 Howdelay
total to compute
= Internetlink
delay + cache
utilization,
access delay + LANdelay?
delay
= 2 sec + minutes + usecs
Cost: web cache (cheap!)
Application Layer 2-42
Conditional GET
client server
• Goal: don’t send object if cache
has up-to-date cached version
• no object transmission HTTP request msg
delay If-modified-since: <date> object
• lower link utilization not
modified
• cache: specify date of cached HTTP response
before
copy in HTTP request HTTP/1.0
304 Not Modified <date>
If-modified-since: <date>
• server: response contains no
object if cached copy is up-to-
date: HTTP request msg
HTTP/1.0 304 Not Modified If-modified-since: <date> object
modified
HTTP response after
HTTP/1.0 200 OK <date>
<data>
Application Layer 2-43
FTP: the file transfer protocol
file transfer
FTP FTP FTP
user client server
interface
user
at host remote file
local file system
system

 transfer file to/from remote host


 client/server model
 client: side that initiates transfer (either to/from remote)
 server: remote host
 ftp server: port 21
FTP: separate control, data connections
TCP control connection,
• FTP client contacts FTP server at port 21, server port 21
using TCP
• client authorized over control connection TCP data connection,
FTP server port 20 FTP
• client browses remote directory, sends client server
commands over control connection
• when server receives file transfer
command, server opens 2nd TCP data
connection (for file) to client  server opens another TCP data
connection to transfer another file
• after transferring one file, server closes 
data connection control connection: “out of band”
 FTP server maintains “state”: current
directory, earlier authentication
FTP commands, responses
sample commands: sample return codes
• sent as ASCII text over control • status code and phrase (as in
channel HTTP)
• USER username • 331 Username OK, password
• PASS password required
• 125 data connection already
• LIST return list of file in current open; transfer starting
directory
• 425 Can’t open data
• RETR filename retrieves (gets) connection
file
• 452 Error writing file
• STOR filename stores (puts)
file onto remote host

Application Layer 2-46


Electronic mail outgoing
message queue
Three major components: user mailbox
• user agents user
agent
• mail servers
• simple mail transfer protocol: SMTP mail user
server agent
User Agent
• a.k.a. “mail reader” SMTP mail user
• composing, editing, reading mail messages server agent
• e.g., Outlook, Thunderbird, iPhone mail client SMTP
• outgoing, incoming messages stored on server
SMTP user
Mail servers: agent
mail
• mailbox contains incoming messages for user
server
• message queue of outgoing (to be sent) mail messages user
SMTP protocol: agent
• between mail servers to send email messages user
• client: sending mail server agent
• “server”: receiving mail server
Electronic Mail: SMTP [RFC 2821]
• uses TCP to reliably transfer email message from client to server, port 25
• direct transfer: sending server to receiving server
• three phases of transfer
• handshaking (greeting)
• transfer of messages
• closure
• command/response interaction (like HTTP, FTP)
• commands: ASCII text
• response: status code and phrase
• messages must be in 7-bit ASCI
Scenario: Alice sends message to Bob
1) Alice uses UA to compose message
“to” [email protected] 4) SMTP client sends Alice’s message
over the TCP connection
2) Alice’s UA sends message to her
mail server; message placed in 5) Bob’s mail server places the
message queue message in Bob’s mailbox
3) client side of SMTP opens TCP 6) Bob invokes his user agent to read
connection with Bob’s mail server message

1 user mail user


mail agent
agent server server
2 3 6
4
5
Alice’s mail server Bob’s mail server
Application Layer 2-49
Sample SMTP interaction
S: 220 hamburger.edu
C: HELO crepes.fr
S: 250 Hello crepes.fr, pleased to meet you
C: MAIL FROM: <[email protected]>
S: 250 [email protected]... Sender ok
C: RCPT TO: <[email protected]>
S: 250 [email protected] ... Recipient ok
C: DATA
S: 354 Enter mail, end with "." on a line by itself
C: Do you like ketchup?
C: How about pickles?
C: .
S: 250 Message accepted for delivery
C: QUIT
S: 221 hamburger.edu closing connection
Comparison with HTTP:
• HTTP: pull
• SMTP: push
• both have ASCII command/response interaction, status codes
• HTTP: each object encapsulated in its own response msg
• SMTP: multiple objects sent in multipart msg
Department of Computer Science & Engineering
Computer Network & Security(18CS52)
5th “A” Section

Module – 1

APPLICATION LAYER

Sneha N P
Assistant
Professor
Dept. of CSE,
ATMECE,Mysore
Mail message format
SMTP: protocol for
exchanging email msgs header
blank
RFC 822: standard for text line
message format:
• header lines, e.g.,
• To: body
• From:
• Subject:
different from SMTP MAIL
FROM, RCPT TO:
commands!
• Body: the “message”
• ASCII characters only
Application Layer 2-53
Mail access protocols
user
mail user
SMTP SMTP access
agent agent
protocol
(e.g., POP,
IMAP)

sender’s mail receiver’s mail


server server

• SMTP: delivery/storage to receiver’s server


• mail access protocol: retrieval from server
• POP: Post Office Protocol [RFC 1939]: authorization, download
• IMAP: Internet Mail Access Protocol [RFC 1730]: more features, including
manipulation of stored msgs on server
• HTTP: gmail, Hotmail, Yahoo! Mail, etc.

Application Layer 2-54


POP3 protocol
S: +OK POP3 server ready
C: user bob
authorization phase S: +OK
C: pass hungry
• client commands: S: +OK user successfully logged on
• user: declare username
C: list
• pass: password
S: 1 498
• server responses S: 2 912
• +OK S: .
• -ERR C: retr 1
S: <message 1 contents>
transaction phase, client: S: .
C: dele 1
• list: list message numbers
C: retr 2
• retr: retrieve message by S: <message 1 contents>
number S: .
• dele: delete C: dele 2
C: quit
• quit S: +OK POP3 server signing off
Application Layer 2-55
POP3 (more) and IMAP
more about POP3
• previous example uses POP3 “download and delete” mode
• Bob cannot re-read e-mail if he changes client
• POP3 “download-and-keep”: copies of messages on different clients
• POP3 is stateless across sessions
IMAP
• keeps all messages in one place: at server
• allows user to organize messages in folders
• keeps user state across sessions:
• names of folders and mappings between message IDs and folder name
Department of Computer Science & Engineering
Computer Network & Security(18CS52)
5th “A” Section

Module – 1

APPLICATION LAYER

Sneha N P
Assistant
Professor
Dept. of CSE,
ATMECE,Mysore
DNS: The Internet’s Directory Service
• people: many identifiers:
• SSN, name, passport #
• Internet hosts, routers:
• hostnames, e.g., www.yahoo.com,www.eurecom.fr - used by humans
• IP address (32 bit) – ex 121.7.104.83
Q: how to map between IP address and name, and vice versa ?

Domain Name System:


• distributed database implemented in hierarchy of many name servers
• application-layer protocol: hosts, name servers communicate to resolve names (address/name
translation)
Example:
DNS: services provided by DNS
DNS services
• Hostname to IP address translation
• Host aliasing
• Canonical- relay1.west-coast.enter-prise.com
• alias names- enterprise.com, www.enterprise.com
• Mail server aliasing
[email protected]
• Canonical- relay1.west-coast.Hotmail.com
• Load distribution
• replicated Web servers: many IP addresses correspond to one name
Overview of How DNS Works
why not centralize DNS?
• single point of failure
• traffic volume
• distant centralized database
• maintenance
DNS: a 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 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
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

c. Cogent, Herndon, VA (5 other sites)


d. U Maryland College Park, MD k. RIPE London (17 other sites)
h. ARL Aberdeen, MD
j. Verisign, Dulles VA (69 other sites ) i. Netnod, Stockholm (37 other sites)

e. NASA Mt View, CA m. WIDE Tokyo


f. Internet Software C. (5 other sites)
Palo Alto, CA (and 48 other
sites)

a. Verisign, Los Angeles CA 13 root name


(5 other sites)
b. USC-ISI Marina del Rey, CA
“servers”
l. ICANN Los Angeles, CA worldwide
(41 other sites)
g. US DoD Columbus,
OH (5 other sites)
TLD, authoritative servers
top-level domain (TLD) servers:
• responsible for com, org, net, edu, aero, jobs, museums, and all top-
level country domains, e.g.: uk, fr, ca, jp
• Network Solutions maintains servers for .com TLD
• Educause for .edu TLD
authoritative DNS servers:
• organization’s own DNS server(s), providing authoritative hostname to
IP mappings for organization’s named hosts
• can be maintained by organization or service provider
Local DNS 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
• has local cache of recent name-to-address translation pairs (but may be out of date!)
• acts as proxy, forwards query into hierarchy
DNS name resolution example root DNS server

2
• host at cis.poly.edu wants 3
TLD DNS server
IP address for 4
gaia.cs.umass.edu
5

local DNS server


iterated query: dns.poly.edu
 contacted server replies 7 6
1 8
with name of 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
root DNS server
DNS name resolution example
2 3
7
recursive query: 6
 puts burden of name TLD DNS
server
resolution on
contacted name local DNS server
server dns.poly.edu 5 4

1 8

authoritative DNS server


dns.cs.umass.edu
requesting host
cis.poly.edu

gaia.cs.umass.edu
DNS: caching, updating records
• once (any) name server learns mapping, it caches mapping
• cache entries timeout (disappear) after some time (TTL)
• TLD servers typically cached in local name servers
• thus root name servers not often visited
• cached entries may be out-of-date (best effort name-to-
address translation!)
• if name host changes IP address, may not be known Internet-wide
until all TTLs expire
Department of Computer Science & Engineering

Computer Network & Security(18CS52)


5th “A” Section

Module – 1

APPLICATION LAYER

Sneha N P
Assistant
Professor
Dept. of CSE,
ATMECE,Mysore
DNS records and messages
DNS: distributed db storing resource records (RR)
RR format: (name, value, type, ttl)

type=A type=CNAME
 name is hostname  name is alias name for some
 value is IP address “canonical” (the real) name
 Example: (relay1.foo.com,  www.ibm.com is really
145.37.93.126, A) servereast.backup2.ibm.com
type=NS  value is canonical name
• name is domain (e.g.,
foo.com) type=MX
• value is hostname of  value is name of
authoritative name mailserver associated with
server for this domain name
DNS protocol, messages
• query and reply messages, both with same message format
2 bytes 2 bytes

msg header identification flags


 identification: 16 bit # # questions # answer RRs
for query, reply to
# authority RRs # additional RRs
query uses same #
 flags: questions (variable # of questions)
 query or reply
 recursion desired answers (variable # of RRs)
 recursion available
 reply is authoritative authority (variable # of RRs)

additional info (variable # of RRs)


DNS protocol, messages
2 bytes 2 bytes

identification flags

# questions # answer RRs

# authority RRs # additional RRs

name, type fields


questions (variable # of questions)
for a query
RRs in
response answers (variable # of RRs)
to query
records for authority (variable # of RRs)
authoritative servers
additional “helpful” additional info (variable # of RRs)
info that may be used
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 into .com TLD server:
(networkutopia.com, dns1.networkutopia.com, NS)
(dns1.networkutopia.com, 212.212.212.1, A)
• create authoritative server type A record for
www.networkuptopia.com; type MX record for
networkutopia.com
Attacking DNS
DDoS attacks Redirect attacks
• Bombard root servers with traffic • Man-in-middle
• Not successful to date • Intercept queries
• Traffic Filtering • DNS poisoning
• Local DNS servers cache IPs of TLD • Send bogus relies to DNS server, which
servers, allowing root server bypass caches
• Bombard TLD servers Exploit DNS for DDoS
• Potentially more dangerous
• Send queries with spoofed source
address: target IP
• Requires amplification
Department of Computer Science & Engineering

Computer Network & Security(18CS52)


5th “A” Section

Module – 1

APPLICATION LAYER

Sneha N P
Assistant
Professor
Dept. of CSE,
ATMECE,Mysore
Pure P2P architecture
• no always-on server
• arbitrary end systems
directly communicate
• peers are intermittently
connected and change IP
addresses
examples:
• file distribution
(BitTorrent)
• Streaming (KanKan)
• VoIP (Skype)

Application Layer 2-76


File distribution: client-server vs P2P
Question: how much time to distribute file (size F) from one server to N peers?
• peer upload/download capacity is limited resource

us: server upload


capacity

u1 di: peer i download


file, size F us d1 u2 capacity
d2
server
di
uN network (with abundant
bandwidth) ui
dN
ui: peer i upload
capacity

Application Layer 2-77


File distribution time: client-server
• server transmission: must
sequentially send (upload) N F
us
file copies:
di
• time to send one copy: F/us network
ui
• time to send N copies: NF/us
 client: each client must
download file copy
 dmin = min client download
rate
 min client download time:
F/dmin time to distribute F
to N clients using
Dc-s > max{NF/us,,F/dmin}
client-server approach

increases linearly in N
Application Layer 2-78
File distribution time: P2P
• server transmission: must
upload at least one copy F
us
• time to send one copy: F/us
di
 client: each client must network
download file copy ui
 min client download time:
 F/dmin as aggregate must download NF
clients:
bits
 max upload rate (limting max download
timerate) is us + S
to distribute Fui
DP2P
to N clients using > max{F/us,,F/dmin,,NF/(us + Sui)}
P2P approach

increases linearly in N …
… but so does this, as each peer brings service capacity
Application Layer 2-79
Client-server vs. P2P: example
client upload rate = u, F/u = 1 hour, us = 10u, dmin ≥ us

3.5
P2P

Minimum Distribution Time


3
Client-Server
2.5

1.5

0.5

0
0 5 10 15 20 25 30 35

N
Application Layer 2-80
P2P file distribution: BitTorrent
 file divided into 256Kb chunks
 peers in torrent send/receive file chunks

tracker: tracks peers torrent: group of


participating in torrent peers exchanging
chunks of a file

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

Application Layer 2-81


P2P file distribution: BitTorrent
• peer joining torrent:
• has no chunks, but will
accumulate them over time
from other peers
• registers with tracker to get
list of peers, connects to
subset of peers (“neighbors”)

 while downloading, peer uploads chunks to other


peers
 peer may change peers with whom it exchanges
chunks
 churn: peers may come and go
 once peer has entire file, it may (selfishly) leave
or (altruistically) remain inLayer
Application torrent 2-82
BitTorrent: requesting, sending file chunks

requesting chunks: sending chunks: tit-for-


• at any given time, different tat
peers have different subsets  Alice sends chunks to
of file chunks those four peers currently
• periodically, Alice asks each sending her chunks at
highest rate
peer for list of chunks that  other peers are choked by
they have Alice (do not receive
• Alice requests missing chunks from her)
 re-evaluate top 4 every10
chunks from peers, rarest secs
first  every 30 secs: randomly
select another peer,
starts sending chunks
 “optimistically unchoke”
Application Layerthis peer 2-83
 newly chosen peer may join
BitTorrent: tit-for-tat
(1) Alice “optimistically unchokes” Bob
(2) Alice becomes one of Bob’s top-four providers; Bob reciprocates
(3) Bob becomes one of Alice’s top-four providers

higher upload rate: find


better trading partners,
get file faster !
Application Layer 2-84
Distributed Hash Table (DHT)
• Hash table

• DHT paradigm

• Circular DHT and overlay networks

• Peer churn
Department of Computer Science & Engineering

Computer Network & Security(18CS52)


5th “A” Section

Module – 1

APPLICATION LAYER

Sneha N P
Assistant
Professor
Dept. of CSE,
ATMECE,Mysore
Simple Database
Simple database with(key, value) pairs:
• key: social security #; value: human
nameValue Key
John Washington 132-54-3570
Diana Louise Jones 761-55-3791
Xiaoming Liu 385-41-0902
Rakesh Gopal 441-89-1956
Linda Cohen 217-66-5609
……. ………
Lisa Kobayashi 177-23-0199

• key: movie title; value: IP address


Distributed Hash Table (DHT)
• Distribute (key, value) pairs over millions of peers
• pairs are evenly distributed over peers
• Any peer can query database with a key
• database returns value for the key
• To resolve query, small number of messages exchanged among
peers
• Each peer only knows about a small number of other
peers
• Robust to peers coming and going (churn)
Hash Table
• More convenient to store and search
on numerical representation of key
• key = hash(original key)
Original Key Key Value
John Washington 8962458 132-54-3570
Diana Louise 7800356 761-55-3791
Jones
Xiaoming Liu 1567109 385-41-0902
Rakesh Gopal 2360012 441-89-1956
Linda Cohen 5430938 217-66-5609
……. ………
Lisa Kobayashi 9290124 177-23-0199
Assign key-value pairs to peers
• rule: assign key-value pair to the peer that has the
closest ID.
• convention: closest is the immediate successor of
the key.
• suppose 8 peers: 1,3,4,5,8,10,12,15
• If key = 6, then assigned to peer 8
• If key = 11, then assigned to peer 12
Circular DHT
• each peer only aware of
immediate successor and
predecessor.
1

3
15

4
12
5
10
8 “overlay network”
Resolving a query

1 What is the value


associated with key 11 ?
value 3
15

4
12
O(N) messages 5
on avgerage to resolve
query, when there 10
8
are N peers
Circular DHT with shortcuts
1 What is the value for
value key 11
3
15

4
12
5
10
8
• each peer keeps track of IP addresses of predecessor, successor,
short cuts.
• Reduces the number of messages.
• possible to design shortcuts with O(log N) neighbors, O(log N)
messages in query
Peer churn handling peer churn:
1 peers may come and go
(churn)
15 3 each peer knows address
of its two successors
each peer periodically
4
pings its
12 two successors to check
5
aliveness
10 if immediate successor
8 leaves, choose next
example: peer 5 abruptly leaves
successor as new
immediate successor
Peer churn handling peer churn:
1 peers may come and go
(churn)
15 3 each peer knows address
of its two successors
each peer periodically
4
pings its
12 two successors to check
aliveness
10 if immediate successor
8 leaves, choose next
example: peer 5 abruptly leaves
successor as new
•peer 4 detects peer 5’s departure; makes 8successor
immediate its immediate
successor
• 4 asks 8 who its immediate successor is; makes 8’s
immediate successor its second successor.
Socket programming
goal: learn how to build client/server applications that
communicate using sockets
socket: door between application process and end-end-
transport protocol

application application
socket controlled by
process process app developer

transport transport
network network controlled
link
by OS
link Internet
physical physical

Application Layer 2-96


Department of Computer Science & Engineering

Computer Network & Security(18CS52)


5th “A” Section

Module – 1

APPLICATION LAYER

Sneha N P
Assistant
Professor
Dept. of CSE,
ATMECE,Mysore
Socket programming
Two socket types for two transport services:
• UDP: unreliable datagram
• TCP: reliable, byte stream-oriented

Application Example:
1. Client reads a line of characters (data)
from its keyboard and sends the data to
the server.
2. The server receives the data and
converts characters to uppercase.
3. The server sends the modified data to
the client.
4. The client receives the modified data
Socket programming with
UDP
UDP: no “connection” between client & server
• no handshaking before sending data
• sender explicitly attaches IP destination address and
port # to each packet
• rcvr extracts sender IP address and port# from received
packet
UDP: transmitted data may be lost or received
out-of-order
Application viewpoint:
• UDP provides unreliable transfer of groups of bytes
(“datagrams”) between client and server

Application Layer
Client/server socket interaction:
UDP
server (running on serverIP) client
create socket:
create socket, port= x: clientSocket =
serverSocket = socket(AF_INET,SOCK_DGRAM)
socket(AF_INET,SOCK_DGRAM)
Create datagram with server IP and
port=x; send datagram via
read datagram from clientSocket
serverSocket

write reply to
serverSocket read datagram from
specifying clientSocket
client address,
port number close
clientSocket
Example app: UDP client
Python UDPClient
include Python’s socket
library from socket import *
serverName = ‘hostname’
serverPort = 12000
create UDP socket for clientSocket = socket(socket.AF_INET,
server

get user keyboard


socket.SOCK_DGRAM)
input message = raw_input(’Input lowercase sentence:’)
Attach server name, port to
message; send into socket clientSocket.sendto(message,(serverName, serverPort))
read reply characters from modifiedMessage, serverAddress =
socket into string
clientSocket.recvfrom(2048)
print out received string print modifiedMessage
and close socket
clientSocket.close()
Example app: UDP server
Python UDPServer
from socket import *
serverPort = 12000
create UDP socket serverSocket = socket(AF_INET, SOCK_DGRAM)
bind socket to local port
number 12000
serverSocket.bind(('', serverPort))
print “The server is ready to receive”
loop forever while 1:
Read from UDP socket into message, clientAddress = serverSocket.recvfrom(2048)
message, getting client’s
address (client IP and port) modifiedMessage = message.upper()
send upper case string serverSocket.sendto(modifiedMessage, clientAddress)
back to this client
Socket programming with
TCP
client must contact server • when contacted by client,
• server process must first be server TCP creates new socket
running for server process to
communicate with that
• server must have created particular client
socket (door) that welcomes
client’s contact
application viewpoint:
client contacts server by:
TCP provides reliable, in-order
• Creating TCP socket, byte-stream transfer (“pipe”)
specifying IP address, port between client and server
number of server process
• when client creates socket:
client TCP establishes
connection to server TCP
Client/server socket interaction:
TCP
server (running on hostid) client
create socket,
port=x, for incoming
request:
serverSocket = socket()

wait for incoming create socket,


connection request
TCP connect to hostid, port=x
connectionSocket = connection setup clientSocket = socket()
serverSocket.accept()

send request using


read request from clientSocket
connectionSocket

write reply to
connectionSocket read reply from
clientSocket
close
connectionSocket close
clientSocket
Example app: TCP client
Python TCPClient
from socket import *
serverName = ’servername’
create TCP socket for serverPort = 12000
server, remote port 12000
clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket.connect((serverName,serverPort))
sentence = raw_input(‘Input lowercase sentence:’)
No need to attach server clientSocket.send(sentence)
name, port
modifiedSentence = clientSocket.recv(1024)
print ‘From Server:’, modifiedSentence
clientSocket.close()
Example app: TCP server
Python TCPServer
from socket import *
create TCP welcoming
serverPort = 12000
socket serverSocket = socket(AF_INET,SOCK_STREAM)
serverSocket.bind((‘’,serverPort))
server begins listening for
incoming TCP requests
serverSocket.listen(1)
print ‘The server is ready to receive’
loop forever while 1:
server waits on accept() connectionSocket, addr = serverSocket.accept()
for incoming requests, new
socket created on return
sentence = connectionSocket.recv(1024)
read bytes from socket (but
not address as in UDP) capitalizedSentence = sentence.upper()
close connection to this
connectionSocket.send(capitalizedSentence)
client (but not welcoming connectionSocket.close()
socket)
Chapter 2:
summary
our study of network apps now complete!
• application architectures  specific protocols:
• client-server  HTTP
• P2P  FTP
• application service  SMTP, POP, IMAP
requirements:
 DNS
• reliability, bandwidth, delay
 P2P: BitTorrent,
• Internet transport service model
DHT
• connection-oriented,
reliable: TCP
 socket programming:
• unreliable, datagrams: UDP TCP, UDP sockets

You might also like