Professional Documents
Culture Documents
• Course Overview
• Course Administration
• What is network?
• What is Internet?
• Network Structure
– Edge, Access Network (Physical Media), Network Core
• Circuit Switching and Packet Switching
2
Computer Networks CS F303 BITS Pilani, Pilani Campus
Course Objective
4
Computer Networks CS F303 BITS Pilani, Pilani Campus
Course Administration
• Instruction delivery
– Lecture classes
• 12:00 – 12:50 pm [Tue, Th] and 5:00 – 5:50 PM [Fri]
– Lab classes
• Start from the first week of Feb (detail will be posted on MS Teams)
• Course page Information
– Lectures and course material will be available at MS Teams
– For assessments NALANDA will be used (https://nalanda-aws.bits-pilani.ac.in)
• Evaluation Plan
– Mid Semester Test @25%
– Quiz (Two) @20% [10% each]
– Lab Assessment @20%
– Comprehensive exam @35% 5
Computer Networks CS F303 BITS Pilani, Pilani Campus
Text Book
6
Computer Networks CS F303 BITS Pilani, Pilani Campus
What is a Network?
9
Computer Networks CS F303 BITS Pilani, Pilani Campus
Network Structure
10
Computer Networks CS F303 BITS Pilani, Pilani Campus
Physical Media-Guided
• Twisted pair
– Two insulated copper wires
– Transmission rates supported are 100 Mbps, 1 Gbps, 10 Gbps
• Coaxial Cable
– Two concentric copper conductors
– Multiple channels on cable
• Fiber Optic Cable
– Glass fiber carrying light pulses, each pulse a bit
– High speed operation (10 Gbps to 100 Gbps)
– Low error rate
11
Computer Networks CS F303 BITS Pilani, Pilani Campus
Physical Media-Unguided
13
Computer Networks CS F303 BITS Pilani, Pilani Campus
Internet structure: network of networks
access access
net net
access
net
access
net
access
net
access
net
access access
net access net
net
14
Computer Networks CS F303 BITS Pilani, Pilani Campus
Internet structure: network of networks
Option: connect each access ISP to every other access ISP?
access access
net net
access
net
access
access net
net
access
access net
net
access
net
access
net
access
net
access
net
access access
net access net
net
15
Computer Networks CS F303 BITS Pilani, Pilani Campus
Internet structure: network of networks
Option: connect each access ISP to a global transit ISP? Customer
and provider ISPs have economic agreement.
access access
net net
access
net
access
access net
net
access
access net
net
global
access
net
ISP access
net
access
net
access
net
access
net
access
net
access access
net access net
net
16
Computer Networks CS F303 BITS Pilani, Pilani Campus
Internet structure: network of networks
Single global ISP does not scale, there are multiple global ISPs ….
access access
net net
access
net
access
access net
net
access
access net
net
ISP A
access access
net ISP B net
access
ISP C
net
access
net
access
net
access
net
access access
net access net
net
17
Computer Networks CS F303 BITS Pilani, Pilani Campus
Internet structure: network of networks
Multiple global ISPs must be interconnected
access access
Internet exchange point
net net
access
net
access
access net
net
access
IXP access
net
net
ISP A
access
ISP C
net
access
net
access
IXP access
net
net
ISP A
access
ISP C
net
access
net
access
net regional net
access
net
access access
net access net
net
19
Computer Networks CS F303 BITS Pilani, Pilani Campus
Internet structure: network of networks
… and content provider networks (e.g., Google, Microsoft, Akamai ) may run
their own network, to bring services, content close to end users
access access
net net
access
net
access
access net
net
access
IXP access
net
net
ISP A
Content provider network
access IXP access
net ISP B net
access
ISP B
net
access
net
access
net regional net
access
net
access access
net access net
net
20
Computer Networks CS F303 BITS Pilani, Pilani Campus
Internet structure: network of networks
POP: point-of-presence
to/from backbone
peering
… …
…
…
…
to/from customers
23
Computer Networks CS F303 BITS Pilani, Pilani Campus
Network Core: Circuit Switching
24
Computer Networks CS F303 BITS Pilani, Pilani Campus
Circuit Switching: FDM and TDM
Example:
FDM
4 users
frequency
time
TDM
frequency
time 25
Computer Networks CS F303 BITS Pilani, Pilani Campus
Circuit Switch: Numerical example
• How long does it take to send a file of 640,000 bits from host A to host B
over a circuit-switched network?
– All links are 1.536 Mbps
– Each link uses TDM with 24 slots/sec
– 500 msec to establish end-to-end circuit
26
Computer Networks CS F303 BITS Pilani, Pilani Campus
Network Core: Packet Switching
transmission
A C
propagation
B D
nodal
processing queueing
28
Computer Networks CS F303 BITS Pilani, Pilani Campus
Caravan Analogy [.1]
100 km 100 km
ten-car toll toll
caravan booth booth
• Cars “propagate” at 100 km/hr
• Toll booth takes 12 sec to service a car (car transmission time)
• Car is analogous to bit; caravan is analogous to packet
• Question:
– How long until caravan is lined up before 2nd toll booth?
29
Computer Networks CS F303 BITS Pilani, Pilani Campus
Caravan analogy [..2]
100 km 100 km
ten-car toll toll
caravan booth booth
30
Computer Networks CS F303 BITS Pilani, Pilani Campus
Queuing Delay
• R=link bandwidth (bps)
• L=packet length (bits)
• a=average packet arrival rate
La/R > 1: more “work” arriving than can be serviced, average delay infinite!
La/R <= 1: delays become large
La/R ~ 0: average queueing delay small
31
Computer Networks CS F303 BITS Pilani, Pilani Campus
“Real” Internet delays and routes
• http://traceroute.org
3 probes 3 probes
3 probes
32
Computer Networks CS F303 BITS Pilani, Pilani Campus
Packet switching versus circuit switching
• Circuit-switching:
– How many users are supported?
• Packet switching:
– with 35 users, probability > 10 active at Exercise: How did we get value 0.0004?
same time is less than .0004 *
• Packet Loss
• Throughput
– Amount of bits transferred in a unit time
• Instantaneous throughput
– e.g., P2P file sharing applications displays instantaneous throughput during downloads
• Average throughput
34
Computer Networks CS F303 BITS Pilani, Pilani Campus
Exercise
35
Computer Networks CS F303 BITS Pilani, Pilani Campus
Layered (Modular) Network Model (OSI)
36
Computer Networks CS F303 BITS Pilani, Pilani Campus
Layering of Airline Functionality
airplane routing airplane routing airplane routing airplane routing airplane routing
TCP UDP…
Applications
38
Computer Networks CS F303 BITS Pilani, Pilani Campus
source
message
segment
M application Layer Encapsulation
Ht M transport
datagram Hn Ht M network
frame Hl Hn Ht M link
physical
link
physical
switch
destination Hn Ht M network
M application H l Hn Ht M link Hn Ht M
Ht M transport physical
Hn H t M network
Hl Hn Ht M link router
physical
39
Computer Networks CS F303 BITS Pilani, Pilani Campus
Summary
40
Computer Networks CS F303 BITS Pilani, Pilani Campus
Thank You!
41
TCP UDP…
Applications
2
Computer Networks CS F303 BITS Pilani, Pilani Campus
What is a Network Application?
3
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Application architectures
• Client-server
• Peer-to-Peer (P2P)
• Hybrid of client-server and P2P
4
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Client-Server Architecture
Server:
– “always-on” host
– Permanent IP address
– For scaling, data center is used to create
large powerful virtual server
Clients:
– Communicate with server
– May be intermittently connected
– May have dynamic IP addresses
– Clients do not communicate directly
with each other
5
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Pure P2P Architecture
• No “always-on” server
• Arbitrary end systems directly
communicate
• Peers are connected and change IP
addresses
– example: Freenet and BitTorrent (File Sharing
Apps)
6
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Hybrid of client-server and P2P
Skype
– Internet telephony application
– Finding address of remote party: centralized server(s)
– Client-client connection is direct (not through server)
Instant messaging
– Chatting between two users is P2P
– Presence detection/location centralized:
• User registers its IP address with central server when it comes online
• User contacts central server to find IP addresses of buddies
7
Computer Networks (CS F303) BITS Pilani, Pilani Campus
How Network Applications
Communicate?
• Process sends/receives messages host or host or
server server
to/from its Socket
– Socket is the interface between the controlled by
application layer and the transport layer app developer
process process
within the host
socket socket
TCP with TCP with
• Within same host, two processes buffers, Internet buffers,
variables variables
communicate using inter-process
communication
controlled
by OS
• Processes in different hosts
communicate by exchanging
messages
8
Computer Networks (CS F303) BITS Pilani, Pilani Campus
How to identify a process running on a
machine?
• To receive messages, process must have
host or
identifier host or
server server
• Data loss
– Some apps (e.g., audio, video) can tolerate some loss
– Other apps (e.g., file transfer, telnet) require 100% reliable data transfer
• 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
– ex. E-mail, File Transfer
• Timing
– Some apps (e.g., Internet telephony, interactive games) require low delay to be
“effective”
10
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Web and HTTP [1994]
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 URLs:
https://www.bits-pilani.ac.in/pilani/computerscience/ProgrammesOffered
https://www.bits-pilani.ac.in/pilani/computerscience/Faculty
11
Computer Networks (CS F303) BITS Pilani, Pilani Campus
HTTP Overview [.1]
12
Computer Networks (CS F303) BITS Pilani, Pilani Campus
HTTP Overview [..2]
Uses TCP:
• Client initiates TCP connection (creates
socket) to server at port 80
initiate TCP
• Server accepts TCP connection from client connection
RTT
request
• HTTP messages exchanged between file
browser (HTTP client) and Web server RTT
time to
transmit
(HTTP server) file
file
received
• TCP connection closed
time time
13
Computer Networks (CS F303) BITS Pilani, Pilani Campus
HTTP Request Message
data, e.g.,
requested
HTML file
15
Computer Networks (CS F303) BITS Pilani, Pilani Campus
HTTP Response status 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
– the HTTP version used in the request is not supported by the server.
16
Computer Networks (CS F303) BITS Pilani, Pilani Campus
How a Webpage transfers?
• Let’s assume a web page consists of a base HTML file and 5 JPEG images.
– https://www.bits-pilani.ac.in/Pilani/SustainableEnvironment
17
Computer Networks (CS F303) BITS Pilani, Pilani Campus
HTTP Connections
Non-persistent HTTP
• At most one object is sent over a TCP connection
• HTTP/1.0 uses non-persistent HTTP
Persistent HTTP
• Multiple objects can be sent over single TCP
connection between client and server.
• Persistent with Pipeline vs. Persistent without
Pipeline
• HTTP/1.1 uses persistent connections in default
mode
18
Computer Networks (CS F303) BITS Pilani, Pilani Campus
HTTP Method Types
HTTP/1.0: HTTP/1.1:
• GET • GET, POST, HEAD
• POST • PUT
• HEAD – uploads file in entity body
– asks server to leave to path specified in URL
requested object out of field
response • DELETE
– deletes file specified in the
URL field
19
Computer Networks (CS F303) BITS Pilani, Pilani Campus
State in HTTP using “Cookies”
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
origin
server
Proxy
server
client
client
origin
server
21
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Conditional GET
client server
• Goal: don’t send object if cache
has up-to-date cached version HTTP request msg
If-modified-since: <date> object
not
• cache: specify date of cached modified
HTTP response
before
copy in HTTP request HTTP/1.0
304 Not Modified
<date>
If-modified-since: <date>
Assumptions:
avg object size: 1000 K bits origin
avg request rate from browsers to origin servers
public
servers: 15 req/sec Internet
avg data rate to browsers: 1Mbps
RTT from institutional router to any origin
server: 2 sec
access link rate: 15 Mbps 15 Mbps
access link
institutional
network
100 Mbps LAN
23
Computer Networks (CS F303) BITS Pilani, Pilani Campus
HTTP/2 [Proposed in 2015]
• Limitations of HTTP/1.1
– It processes only one outstanding request per TCP connection
– Forcing browsers to use multiple TCP connections to process multiple requests
simultaneously
– HTTP1.x used to process text commands which makes it slower
• Motivation
– To improve internet user experience and effectiveness
– Webpages comprise resource-intensive multimedia content
– To make it more secure, reliable with improved performance
• What is stream?
– Bi-directional sequence of text format frames
sent over the HTTP/2 protocol exchanged
between the server and client
26
Computer Networks (CS F303) BITS Pilani, Pilani Campus
HTTP/2.0 Connection
• Stream: A bidirectional flow of bytes
within an established connection, which
may carry one or more messages.
• Message: A complete sequence of
frames that map to a logical request or
response message.
• Frame: The smallest unit of
communication in HTTP/2, each
containing a frame header, which at a
minimum identifies the stream to which
the frame belongs.
27
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Domain Name System (DNS)
• The domain name system maps the name people use to locate a website to
the IP address that a computer uses to locate a website.
28
Computer Networks CS F303 BITS Pilani, Pilani Campus
DNS Structure – Distributed Hierarchical
Database
Root DNS Servers
… …
30
Computer Networks CS F303 BITS Pilani, Pilani Campus
DNS Services
• Load distribution
– Replicated Web servers: many IP addresses correspond to one name
31
Computer Networks CS F303 BITS Pilani, Pilani Campus
DNS Query Processing - Recursive root DNS server
2 3
7
6
TLD DNS
server
1 8
gaia.cs.umass.edu
32
Computer Networks CS F303 BITS Pilani, Pilani Campus
DNS Query Processing - Iterative root DNS server
2
• TLD server may know only of an 3
intermediate DNS server for the TLD DNS server
4
hostname, which in turn knows the
authoritative DNS server for the 5
hostname. local DNS server
dns.poly.edu
7 6
1 8
• DNS responses are usually cached to
improve the delay performance and to authoritative DNS server
reduce the number of DNS messages dns.cs.umass.edu
requesting host
– e.g., Local DNS server caches the TLD server cis.poly.edu
information
gaia.cs.umass.edu
33
Computer Networks CS F303 BITS Pilani, Pilani Campus
DNS Records
DNS: distributed database for 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
www.ibm.com is really
type=NS servereast.backup2.ibm.com
– name is domain (e.g., value is canonical name
foo.com)
– value is hostname of type=MX
authoritative name value is name of mailserver associated
server for this domain with name (host name, i.e.,
mailserver alias)
34
Computer Networks CS F303 BITS Pilani, Pilani Campus
DNS Messages
• Query and reply messages, both with same message format
• Explore DNS protocol in Lab Session #2
2 bytes 2 bytes
36
Computer Networks CS F303 BITS Pilani, Pilani Campus
FTP: File Transfer Protocol
file transfer
FTP FTP FTP
user client server
interface
user
at host remote file
local file system
system
37
Computer Networks CS F303 BITS Pilani, Pilani Campus
FTP: Connections
TCP control connection,
• Control connection server port 21
– Authorization, directory listing
etc. TCP data connection,
FTP server port 20 FTP
client server
• When server receives file
transfer command,
– Server opens 2nd TCP data
connection (for file) to client
38
Computer Networks CS F303 BITS Pilani, Pilani Campus
FTP Commands and Responses
39
Computer Networks CS F303 BITS Pilani, Pilani Campus
eMail
outgoing
user message queue
Three major components: agent
user mailbox
• User agents mail user
server
– e.g., Outlook, Thunderbird agent
40
Computer Networks CS F303 BITS Pilani, Pilani Campus
SMTP [RFC 5321, Original RFC 821]
• Uses TCP to reliably transfer email message from client to server, port 25
• Direct transfer: sender’s mail server to receiver’s mail server
• Three phases of transfer
– Handshaking (greeting)Transfer of messagesConnection Closure
• Command/response interaction (like HTTP, FTP)
– Commands: ASCII text
– Response: status code and phrase
• Messages must be in 7-bit ASCII
– Painful for multimedia data
41
Computer Networks CS F303 BITS Pilani, Pilani Campus
Mail Transfer Process
S: 220 hamburger.edu
C: HELO crepes.fr
S: 250 Hello crepes.fr, pleased to meet you
C: MAIL FROM: <alice@crepes.fr>
S: 250 alice@crepes.fr... Sender ok
C: RCPT TO: <bob@hamburger.edu>
S: 250 bob@hamburger.edu ... 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 42
Computer Networks CS F303 BITS Pilani, Pilani Campus
Mail Access Protocols
45
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Thank You!
46
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Computer Networks (CS F303)
BITS Pilani Virendra Singh Shekhawat
Department of Computer Science and Information Systems
Pilani Campus
Today’s Agenda
2
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Peer to Peer (P2P) Architecture
• No always-on server
• Arbitrary end systems directly communicate
• Peers are intermittently connected
• Examples
– File distribution (BitTorrent)
– Streaming (KanKan)
– VoIP (Skype)
3
Computer Networks CS F303 BITS Pilani, Pilani Campus
File Distribution: P2P vs CS
How much time required to distribute file (size F) from one server to N peers?
– peer upload/download capacity is limited resource
4
Computer Networks CS F303 BITS Pilani, Pilani Campus
File Distribution Time – Client Server
• Server transmission: must F
sequentially send (upload) N us
file copies: di
network
– Time to send N copies: NF/us ui
time to distribute F
to N clients using
client-server approach Dc-s > max{NF/us,,F/dmin}
5
Computer Networks CS F303 BITS Pilani, Pilani Campus
File Distribution Time - Peer to Peer
• Server transmission: must upload at least one copy
F
– time to send one copy: F/us us
di
Client: each client must download file copy network
Slowest client download time: F/dmin ui
Time to distribute F
to N clients using
P2P approach
DP2P > max{F/us,,F/dmin,,NF/(us + Sui)}
6
Computer Networks CS F303 BITS Pilani, Pilani Campus
Exercise
7
Computer Networks (CS F303) BITS Pilani, Pilani Campus
CS vs P2P: Example
1.5
0.5
0
0 5 10 15 20 25 30 35
N
8
Computer Networks CS F303 BITS Pilani, Pilani Campus
P2P File Distribution: BitTorrent
9
Computer Networks CS F303 BITS Pilani, Pilani Campus
The lookup problem
N2 N3
N1
Internet
Key = “data item”
Value = video lecture ?
Client
Publisher
N4 N6 Lookup(“data item”)
N5
Decentralized network with several peers (servers/clients)
How to find specific peer that hosts desired data within this network?
10
Computer Networks CS F303 BITS Pilani, Pilani Campus
P2P Protocols
Napster
Gnutella
Kazaa (Skype is based on Kazaa)
11
Computer Networks CS F303 BITS Pilani, Pilani Campus
Distributed Hash Table (DHT)
• Each Peer hold a small subset of the total (key, value) pairs
• Any Peer can query the distributed database with a particular key
– Distributed DB locate the Peers that have the corresponding (key, value)
pairs and return to the querying Peer
– Each peer only knows about a small number of other peers
– Any Peer can insert new (key, value) pairs into the DB
– Robust to peers coming and going (churn)
12
Computer Networks CS F303 BITS Pilani, Pilani Campus
DHT Implementation [.1]
• Randomly scatter the (key, value) pairs across all the peers
• The peers containing the (key, value) pairs that match the key can respond
with matching pairs
• Hash function assigns each “node” and “key” an m-bit identifier using a
base hash function such as SHA-1
– Node_ID = hash(IP, Port)
N63
– Key_ID = hash(original key) N60 N2
k7
ID Space: 0 to 2m-1 k58
N10
Here: m = 6 k11
N50 k16
Range = 64
k46 N20
Assign (key-value) pair to the peer that has N40 k39 k25
16
Computer Networks CS F303 BITS Pilani, Pilani Campus
The Chord algorithm –
Scalable node localization
• Search in finger table for the node
which is
most immediatly precedes key
19
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Computer Networks (CS F303)
BITS Pilani Virendra Singh Shekhawat
Department of Computer Science and Information Systems
Pilani Campus
Next…
• Clients and servers communicate with each other by reading from and writing to socket
descriptors.
application application
socket controlled by
process process app developer
transport transport
network network controlled
link by OS
link Internet
physical physical
3
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Socket Programming [..2]
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 and displays the line on its screen.
4
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Socket Programming with UDP
5
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Socket Programming with TCP
Application viewpoint:
TCP provides reliable, in-order byte-stream transfer (“pipe”)
between client and server.
6
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Socket Structure [.1]
struct sockaddr
{
unsigned short int sa_family; // address family, AF_xxx
char sa_data[14] ; // 14 bytes of protocol address
}
7
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Socket Structure [..2]
• Parallel structure to sockaddr
struct sockaddr_in
{
short int sin_family; // Address family (e.g., AF_INET)
unsigned short int sin_port; // Port number (e.g., htons (2240)
struct in_addr sin_addr; // Internet address
unsigned char sin_zero[8]; // same size as sockaddr
}
struct in_addr
{ unsigned long s_addr;
}
• sin_zero is used to pad the structure to the length of a structure sockaddr and hence is set to all zeros with
the function memset()
• Important – you can cast sockaddr_in to a pointer of type struct sockaddr and vice versa
• sin_family corresponds to sa_family and should be set to “AF_INET”.
• sin_port and sin_addr must be in NBO
8
Computer Networks (CS F303) BITS Pilani, Pilani Campus
NBO & HBO Conversion Functions
• Very Important: Even if your machine is Big-Endian m/c, but you put your bytes in NBO before putting
them on to the network for portability
9
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Primary Socket System Calls
10
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Socket System Calls:
Connectionless (e.g., UDP)
11
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Socket System Calls: Connection-
Oriented (e.g., TCP)
12
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Socket System Calls [.1]
13
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Socket System Calls [..2]
14
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Socket System Calls […3]
• SEND: int send(int sockfd, const void *msg, int len, int flags);
– msg: message you want to send
– len: length of the message
– flags := 0
– returned: the number of bytes actually sent
• RECEIVE: int recv(int sockfd, void *buf, int len, unsigned int flags);
– buf: buffer to receive the message
– len: length of the buffer (“don’t give me more!”)
– flags := 0
– returned: the number of bytes received
15
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Socket System Calls [….4]
• SEND (DGRAM-style): int sendto(int sockfd, const void *msg, int len, int flags, const struct sockaddr *to, int
tolen);
– msg: message you want to send
– len: length of the message
– flags := 0
– to: socket address of the remote process
– tolen: = sizeof(struct sockaddr)
– returned: the number of bytes actually sent
• RECEIVE (DGRAM-style): int recvfrom(int sockfd, void *buf, int len, unsigned int flags, struct sockaddr
*from, int *fromlen);
– buf: buffer to receive the message
– len: length of the buffer (“don’t give me more!”)
– from: socket address of the process that sent the data
– fromlen:= sizeof(struct sockaddr)
– flags := 0
– returned: the number of bytes received
#include <sys/types.h>
#include <netinet/in.h>
18
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Simple TCP Client
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#define SERVER_PORT 5888
int main()
{ int sockfd, clifd,len;
char buf[256];
struct sockaddr_in servaddr;
sockfd = socket( AF_INET, SOCK_STREAM, 0);
if (sockid < 0) { printf(“ Server socket error"); exit(1); }
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(SERVER_PORT);
servaddr.sin_addr.s_addr = inet_addr(“172.24.2.4”);
read(sockfd,buf,256);
printf(“Client Received%s\n",buf);
Close(sockfd);
}
19
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Simple UDP Server
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#define SERVER_PORT 9988
int main()
{ int sockfd, clilen;
char buf[256];
struct sockaddr_in servaddr, cliaddr;
sockfd = socket( AF_INET, SOCK_DGRAM, 0);
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(SERVER_PORT);
servaddr.sin_addr.s_addr =htonl(INADDR_ANY);
if (bind(sockfd,(struct sockaddr*)&servaddr,sizeof(servaddr)) <0 )
{ printf(“Server Bind Error”); exit(1); }
for(; ; )
{ clilen= sizeof(cliaddr);
recvfrom(sockfd,buf,256,0,(struct sockaddr*)&cliaddr,&clilen);
printf(“Server Received:%s\n”,buf);
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(SERVER_PORT);
servaddr.sin_addr.s_addr = inet_addr(SERVER_IPADDR);
cliaddr.sin_family = AF_INET;
cliaddr.sin_port = htons(0);
cliaddr.sin_addr.s_addr =htonl(INADDR_ANY);
bind(sockfd,(struct sockaddr*)&cliaddr,sizeof(cliaddr));
recvfrom(sockfd,buf,256,0,NULL,NULL);
printf(“Clinet Received: %s \n”,buf);
close(sockfd);
} 21
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Thank You!
22
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Computer Networks (CS F303)
BITS Pilani Virendra Singh Shekhawat
Department of Computer Science and Information Systems
Pilani Campus
Topics
• Transport Layer
– Transport Layer Services
• Multiplexing/Demultiplexing
– Connectionless and Connection Oriented
» TCP and UDP
• Reliable data transfer (Protocol design)
• Flow control
• Congestion control
2
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Transport Layer Services and Protocols
3
Computer Networks (CS F303) BITS Pilani, Pilani Campus
TP Layer vs. Network Layer
• Network layer: logical communication between hosts
• But certain services can be offered by the TP layer even when the network
layer doesn’t offer
– e.g., Reliable data transfer
4
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Transport Layer Services
5
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Process-to-Process Delivery Service
Multiplexing at sendening time:
Demux at receiving time:
handle data from multiple use header info to deliver
sockets, add transport header received segments to correct
socket
application
6
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Demultiplexing at Receiver
7
3-7
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Connectionless (UDP) Demultiplexing
• Recall: when creating datagram to send into UDP socket, must specify
• Destination IP address
• Destination port #
8
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Example: Connectionless Demultiplexing
DatagramSocket serverSocket
DatagramSocket = new DatagramSocket DatagramSocket
mySocket2 = new mySocket1 = new
(6428);
DatagramSocket DatagramSocket
(9157); application
(5775);
application application
P1
P3 P4
transport
transport transport
network
network link network
link physical link
physical physical
10
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Example: Connection Oriented Demux
application
application P4 P5 P6 application
P1 P2 P3
transport
transport transport
network
network link network
link physical link
physical server: IP physical
address B
13
Computer Networks (CS F303) BITS Pilani, Pilani Campus
UDP Segment Header
length, in bytes of
32 bits UDP segment,
source port # dest port # including header
length checksum
Why is there a UDP?
• No connection establishment
application
(which can add delay)
data
(payload) • simple: no connection state
at sender, receiver
• small header size
UDP segment format • no congestion control: UDP
can blast away as fast as
desired
14
Computer Networks (CS F303) BITS Pilani, Pilani Campus
UDP Checksum
15
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Principles of Reliable Data Transfer
16
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Principles of Reliable Data Transfer
17
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Principles of Reliable Data Transfer
send receive
side side
We will:
• Incrementally develop sender, receiver sides of reliable data
transfer protocol (rdt)
• Consider only unidirectional data transfer
– But control info will flow on both directions!
• Use finite state machines (FSM) to specify sender, receiver
event causing state transition
actions taken on state transition
State: when in this “state”
next state uniquely state state
1 event
determined by next 2
event actions
20
Computer Networks (CS F303) BITS Pilani, Pilani Campus
rdt1.0: reliable transfer over a reliable channel
sender receiver
21
Computer Networks (CS F303) BITS Pilani, Pilani Campus
rdt2.0: channel with bit errors
• Underlying channel may flip bits in packet
– Don’t worry… Checksum is there to detect bit errors
22
Computer Networks (CS F303) BITS Pilani, Pilani Campus
rdt2.0: FSM Specification
rdt_send(data)
sndpkt = make_pkt(data, checksum) receiver
udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
isNAK(rcvpkt)
Wait for rdt_rcv(rcvpkt) &&
Wait for call
ACK or udt_send(sndpkt) corrupt(rcvpkt)
from above
NAK
udt_send(NAK)
rdt_rcv(rcvpkt) &&
notcorrupt(rcvpkt)
extract(rcvpkt,data)
deliver_data(data)
udt_send(ACK)
24
Computer Networks (CS F303) BITS Pilani, Pilani Campus
rdt2.0: Error Scenario
rdt_send(data)
sndpkt = make_pkt(data, checksum)
udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
isNAK(rcvpkt)
Wait for call Wait for rdt_rcv(rcvpkt) &&
from above ACK or udt_send(sndpkt) corrupt(rcvpkt)
NAK
udt_send(NAK)
rdt_rcv(rcvpkt) &&
notcorrupt(rcvpkt)
extract(rcvpkt,data)
deliver_data(data)
udt_send(ACK)
25
Computer Networks (CS F303) BITS Pilani, Pilani Campus
rdt2.0 Has a fatal flaw!
26
Computer Networks (CS F303) BITS Pilani, Pilani Campus
rdt2.1: Sender, handles garbled ACK/NAKs
rdt_send(data)
sndpkt = make_pkt(0, data, checksum)
udt_send(sndpkt) rdt_rcv(rcvpkt) &&
( corrupt(rcvpkt) ||
Wait for call Wait for
ACK or NAK
isNAK(rcvpkt) )
0 from
0 udt_send(sndpkt)
above
rdt_rcv(rcvpkt)
&& notcorrupt(rcvpkt) rdt_rcv(rcvpkt)
&& isACK(rcvpkt) && notcorrupt(rcvpkt)
&& isACK(rcvpkt)
L
L
Wait for Wait for
ACK or NAK call 1 from
rdt_rcv(rcvpkt) && 1 above
( corrupt(rcvpkt) ||
isNAK(rcvpkt) ) rdt_send(data)
27
Computer Networks (CS F303) BITS Pilani, Pilani Campus
rdt2.1: Receiver, handles garbled ACK/NAKs
extract(rcvpkt,data)
deliver_data(data)
sndpkt = make_pkt(ACK, chksum)
udt_send(sndpkt)
28
Computer Networks (CS F303) BITS Pilani, Pilani Campus
rdt2.1: Discussion
Sender:
• Seq # added to pkt
• Two seq. #’s (0,1) will suffice. Why?
• Must check if received ACK/NAK corrupted
• Twice as many states
– State must “remember” whether “current” pkt has 0 or 1 seq. #
Receiver:
• Must check if received packet is duplicate
– State indicates whether 0 or 1 is expected pkt seq #
– For an out of order received packet, it sends ACK for it
• Note: Receiver can not know if its last ACK/NAK received OK at sender
29
Computer Networks (CS F303) BITS Pilani, Pilani Campus
rdt2.2: NAK Free Protocol
• New assumption: Underlying channel can also lose packets (data or ACKs)
– Checksum, seq. #, ACKs, retransmissions will be of help, but not enough
31
Computer Networks (CS F303) BITS Pilani, Pilani Campus
rdt 3.0 Sender and Receiver FSM
32
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Thank You!
33
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Computer Networks (CS F303)
BITS Pilani Virendra Singh Shekhawat
Department of Computer Science and Information Systems
Pilani Campus
Topics
• Transport Layer
• Reliable data transfer (Protocol design)
– Stop and Wait vs. Pipelining (Sliding Window)
– Go Back N and Selective Repeat Protocols
• Flow control
• Congestion control
2
Computer Networks (CS F303) BITS Pilani, Pilani Campus
rdt3.0: Channels with errors and loss
• New assumption: Underlying channel can also lose packets (data or ACKs)
– Checksum, seq. #, ACKs, retransmissions will be of help, but not enough
3
Computer Networks (CS F303) BITS Pilani, Pilani Campus
rdt 3.0 Sender and Receiver FSM
4
Computer Networks (CS F303) BITS Pilani, Pilani Campus
rdt3.0 in action
5
Computer Networks (CS F303) BITS Pilani, Pilani Campus
rdt3.0 (Lost ACK and Premature Timeout)
6
Computer Networks (CS F303) BITS Pilani, Pilani Campus
rdt3.0: Performance
sender receiver
first packet bit transmitted, t = 0
last packet bit transmitted, t = L / R
U L/R .008
= = = 0.00027
sender 30.008
RTT + L / R microsec
7
onds
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Pipelining: Increased Utilization
sender receiver
first packet bit transmitted, t = 0
last bit transmitted, t = L / R
Increase utilization
by a factor of 3!
U 3*L/R .024
= = = 0.0008
sender 30.008
RTT + L / R microsecon
ds
8
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Pipelined Protocols
9
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Pipelining Protocols Requirements
10
Computer Networks (CS F303) BITS Pilani, Pilani Campus
GBN Protocol
Sender window (N=4) Sender Receiver
012345678 send pkt0
012345678 send pkt1
012345678 send pkt2 receive pkt0, send ack0
012345678 send pkt3 Xloss receive pkt1, send ack1
(wait)
receive pkt3, discard,
012345678 rcv ack0, send pkt4 (re)send ack1
012345678 rcv ack1, send pkt5 receive pkt4, discard,
(re)send ack1
ignore duplicate ACK receive pkt5, discard,
(re)send ack1
pkt 2 timeout
012345678 send pkt2
012345678 send pkt3
012345678 send pkt4 rcv pkt2, deliver, send ack2
012345678 send pkt5 rcv pkt3, deliver, send ack3
rcv pkt4, deliver, send ack4
rcv pkt5, deliver, send ack5
11
Computer Networks (CS F303) BITS Pilani, Pilani Campus
GBN Sender
12
Computer Networks (CS F303) BITS Pilani, Pilani Campus
GBN Sender FSM
rdt_send(data)
if (nextseqnum < base+N) {/*If we are allowed to send packets*/
sndpkt[nextseqnum] = make_pkt(nextseqnum,data,chksum)
udt_send(sndpkt[nextseqnum])
if (base == nextseqnum) /*If there are no packets in flight*/
start_timer
nextseqnum++
}
L else
refuse_data(data)
base=0
nextseqnum=0
timeout
start_timer
Wait
udt_send(sndpkt[base])
rdt_rcv(rcvpkt) udt_send(sndpkt[base+1])
&& corrupt(rcvpkt) …
udt_send(sndpkt[nextseqnum-1])
L
rdt_rcv(rcvpkt) &&
notcorrupt(rcvpkt)
base = getacknum(rcvpkt)+1 /*Increase left size of the window*/
If (base == nextseqnum)
stop_timer
else
start_timer 13
Computer Networks (CS F303) BITS Pilani, Pilani Campus
GBN Receiver FSM
• Always send ACK for correctly-received pkt with highest in-order seq #
– Need only to remember “expectedseqnum”
• If out-of-order pkt arrived
– Discard it
– Re-ACK pkt with the highest in-order seq #
default
udt_send(sndpkt) rdt_rcv(rcvpkt)
&& notcurrupt(rcvpkt)
L && hasseqnum(rcvpkt,expectedseqnum)
expectedseqnum=0 Wait extract(rcvpkt,data)
sndpkt = deliver_data(data)
make_pkt(expectedseqnum,ACK,chksum) sndpkt = make_pkt(expectedseqnum,ACK,chksum)
udt_send(sndpkt)
expectedseqnum++
14
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Selective Repeat Protocol
sender window (N=4) sender receiver
012345678 send pkt0
012345678 send pkt1
012345678 send pkt2 receive pkt0, send ack0
012345678 send pkt3 Xloss receive pkt1, send ack1
(wait)
receive pkt3, buffer,
012345678 rcv ack0, send pkt4 send ack3
012345678 rcv ack1, send pkt5 receive pkt4, buffer,
send ack4
record ack3 arrived receive pkt5, buffer,
send ack5
pkt 2 timeout
012345678 send pkt2
012345678 record ack4 arrived
012345678 rcv pkt2; deliver pkt2,
record ack5 arrived
012345678 pkt3, pkt4, pkt5; send ack2
16
Computer Networks (CS F303) BITS Pilani, Pilani Campus
SR Protocol: Windows
Events at Sender
Data from above
Timeout
ACK(n) in [sendbase,sendbase+N-1]
Events at Receiver
Pkt n in [rcvbase, rcvbase+N-1]
Pkt n in [rcvbase-N,rcvbase-1]
Otherwise
17
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Selective Repeat Dilemma
0123012 pkt0
0123012 pkt1 0123012
0123012 pkt2 0123012
X 0123012
X
timeout
retransmit pkt0 X
0123012 pkt0
will accept packet
with seq number 0
18
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Relation between Window Size and
Sequence Number
• Sequence numbers range for K bits
– 0 to 2K-1
• What should be the window size N for
– Selective Repeat
– Go Back N
19
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Thank You!
20
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Computer Networks (CS F303)
BITS Pilani Virendra Singh Shekhawat
Department of Computer Science and Information Systems
Pilani Campus
Topics
• Transport Layer
• TCP Protocol
– Connection Establishment
– TCP Segment Structure
– Reliable data transfer
– Flow control
– Congestion control
2
Computer Networks (CS F303) BITS Pilani, Pilani Campus
TCP [RFCs: 793,1122,1223,2018,2581]
4
Computer Networks (CS F303) BITS Pilani, Pilani Campus
TCP: Wireshark Capture
5
Computer Networks (CS F303) BITS Pilani, Pilani Campus
TCP Sequence Numbers and ACKs
TCP views data as stream of bytes
outgoing segment from sender Sequence number reflects stream of transmitted bytes not segments
source port #
Sequence number of a segment – Byte stream number of the first byte in the
dest port #
segment
sequence number window size
acknowledgement number N
rwnd
checksum urg pointer
sender sequence number space
application application
network network
choose x
req_conn(x)
ESTAB
acc_conn(x)
ESTAB
8
Computer Networks (CS F303) BITS Pilani, Pilani Campus
TCP 3-way Handshake
9
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Lost ACK Scenario
10
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Premature Timeout
11
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Cumulative ACK
12
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Is TCP GBN or SR…?
13
Computer Networks (CS F303) BITS Pilani, Pilani Campus
TCP Connection Close
LAST_ACK
FINbit=1, seq=y
TIMED_WAIT can no longer
send data
ACKbit=1; ACKnum=y+1
timed wait
for 2*max CLOSED
segment lifetime
CLOSED
14
Computer Networks (CS F303) BITS Pilani, Pilani Campus
TCP Connection States-Client and Server
15
Computer Networks (CS F303) BITS Pilani, Pilani Campus
TCP Flow Control
16
Computer Networks (CS F303) BITS Pilani, Pilani Campus
TCP Timeout
17
Computer Networks (CS F303) BITS Pilani, Pilani Campus
RTT Estimation
EstimatedRTT = (1-)*EstimatedRTT + *SampleRTT
– Influence of past sample decreases exponentially fast
– Typical value of = 0.125
RTT: gaia.cs.umass.edu to fantasia.eurecom.fr
350
300
250
RTT (milliseconds)
200
150
100
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
18
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Timeout Interval
• Timeout Interval
– Estimated RTT + “Safety margin”
– Large variation in Estimated RTT large safety margin
DevRTT = (1-)*DevRTT +
*|SampleRTT-EstimatedRTT|
(typically, = 0.25)
19
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Example: Timeout Interval
• Consider three RTT samples (in ms): 150, 200 and 210 in that order. Assume
initial estimated RTT= 200 ms, initial DevRTT = 50 ms, β = 0.25 and α = 0.125
20
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Next…
• Transport Layer
• TCP Protocol
– Connection Establishment
– TCP Segment Structure
– Reliable data transfer
– Flow control
– Timeout Estimation
– Congestion control
21
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Network Congestion…?
10 Mbps
1.5 Mbps
100 Mbps
• Why is it a problem?
– Different sources compete for resources inside
network
– Sources are unaware of current state of resource
– Sources are unaware of each other
– In many situations will result in < 1.5 Mbps of
throughput (congestion collapse)
22
Computer Networks CS F303 BITS Pilani, Pilani Campus
Congestion Control
• What is congestion
– Too many sources sending too much data too fast for network to handle
• Congestion results in
– Packet losses
– Packet delays
– Throughput reduction
23
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Causes/Cost of Congestion [.1]
delay
R/2
lout
lin R/2
lin R/2
24
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Causes/Cost of Congestion [..2]
25
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Causes/Cost of Congestion […3]
• Cost of congestion
– Retransmission for dropped packets
26
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Causes/Cost of Congestion [….4]
27
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Causes/Cost of Congestion […..5]
29
Computer Networks (CS F303) BITS Pilani, Pilani Campus
TCP Congestion Control
• Approach
– Sending rate is a function of perceived congestion
30
Computer Networks (CS F303) BITS Pilani, Pilani Campus
TCP Congestion Control
32
Computer Networks (CS F303) BITS Pilani, Pilani Campus
FSM Description of TCP Congestion Control
33
Computer Networks (CS F303) BITS Pilani, Pilani Campus
Example: TCP Congestion Control
a) Identify the intervals of time when TCP slow start is
operating.
b) Identify the intervals of time when TCP congestion
avoidance is operating.
c) What is the ssthresh value between transmission round 7-
10?
d) What is the congestion window value at transmission round
11?
e) How many segments have been sent till transmission round
11? (including 11th transmission round)
f) Identify the intervals of time when TCP fast retransmission
and fast recovery is used?
34
Computer Networks (CS F303) BITS Pilani, Pilani Campus
TCP Sawtooth Behavior
Congestion
Window Timeouts
may still
occur
time
AIMD saw tooth
behavior: probing
for bandwidth
36
Computer Networks (CS F303) BITS Pilani, Pilani Campus
TCP Throughput
W/2
38
Computer Networks (CS F303) BITS Pilani, Pilani Campus