Documente Academic
Documente Profesional
Documente Cultură
PART A
1. Implement four nodes point – to – point network with duplex links between
them. Analyze the network performance by setting the queue size, vary the
bandwidth and find the number of packets dropped.
PROCEDURE
#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]
#===================================
# Nodes Definition
#===================================
#Create 4 nodes
set n0 [$ns node]
set n1 [$ns node]
#===================================
# Links Definition
#===================================
#Createlinks between nodes
$ns duplex-link $n0 $n1 .1Mb 10ms DropTail
$ns queue-limit $n0 $n1 20
$ns duplex-link $n1 $n2 20Mb 10ms DropTail
$ns queue-limit $n1 $n2 20
$ns duplex-link $n2 $n3 20Mb 10ms DropTail
$ns queue-limit $n2 $n3 20
#===================================
# Agents Definition
#===================================
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n3 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500
#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 20.0 "$ftp0 stop"
#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefilenamfile
$ns flush-trace
close $tracefile
close $namfile
execnam p1.nam &
puts "Number of pkts dropped"
execgrep -c "^d" p1.tr &
DEPT. of ECE, KVGCE, SULLIA, D.K Page 3
COMPUTER NETWORKS LABORATORY(15ECL68)
set t [exec grep "^+" p1.tr | grep -c "tcp"]
#set r [exec grep "^r" p1.tr | grep -c "tcp"]
puts "Throughput is [expr $t/20] packtes per secs"
exit 0
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run
#program 2
# <http://wushoupong.googlepages.com/nsg>
#===================================
# Simulation parameters setup
#===================================
setval(stop) 20 ;# time of simulation end
#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]
$ns color 1 blue
$ns color 2 red
#Open the NS trace file
settracefile [open kv.tr w]
$ns trace-all $tracefile
#===================================
# Nodes Definition
#===================================
#Create 4 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
#===================================
# Links Definition
#===================================
#Createlinks between nodes
$ns duplex-link $n0 $n1 100Mb 10ms DropTail
$ns queue-limit $n0 $n1 50
#===================================
# Agents Definition
#===================================
#Setup a TCP connection
set tcp1 [new Agent/TCP]
$ns attach-agent $n0 $tcp1
set sink2 [new Agent/TCPSink]
$ns attach-agent $n3 $sink2
$ns connect $tcp1 $sink2
$tcp1 set packetSize_ 1500
#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp1
$ns at 1.0 "$ftp0 start"
$ns at 20.0 "$ftp0 stop"
#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefilenamfile
$ns flush-trace
close $tracefile
close $namfile
execnamkv.nam&
set a [ exec grep "^+" kv.tr | grep -c "tcp" ]
set b [ exec grep -c "^+" kv.tr ]
puts "number of tcp packets sent is $a"
puts "number of udp packets sent is $b"
#exec grep "^+" kv.tr | cut -d " " -f 5 | grep -c "cbr" &
exit 0
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run
#===================================
# Simulation parameters setup
#===================================
setval(stop) 10.0 ;# time of simulation end
#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]
#===================================
# Nodes Definition
#===================================
#Create 6 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
#===================================
# Links Definition
#===================================
#Createlinks between nodes
$ns duplex-link $n0 $n2 100.0Mb 10ms DropTail
$ns queue-limit $n0 $n2 50
$ns duplex-link $n1 $n2 100.0Mb 10ms DropTail
$ns queue-limit $n1 $n2 50
$ns duplex-link $n2 $n3 100.0Mb 10ms DropTail
$ns queue-limit $n2 $n3 50
setlan [$ns newLan "$n3 $n4 $n5 " 0.5Mb 40ms LL Queue/DropTail MAC/802_3 Channel]
#===================================
# Agents Definition
#===================================
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n4 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500
#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
DEPT. of ECE, KVGCE, SULLIA, D.K Page 11
COMPUTER NETWORKS LABORATORY(15ECL68)
$ns at 1.0 "$ftp0 start"
$ns at 2.0 "$ftp0 stop"
#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefilenamfile
$ns flush-trace
close $tracefile
close $namfile
execnametr.nam&
setTcpSize [ exec grep "^r" etr.tr | grep "tcp" | tail -n 1 | cut -d " " -f 6]
setnumTcp [ exec grep "^r" etr.tr | grep -c "tcp" ]
settcpTime 19.0
#set UdpSize 1000
setUdpSize [ exec grep "^r" etr.tr | grep "cbr" | tail -n 1 | cut -d " " -f 6]
setnumUdp [ exec grep "^r" etr.tr | grep -c "cbr" ]
setudpTime 19.0
puts "the throughput of FTP is"
puts "[expr (($numTcp * $TcpSize)/$tcpTime)] bytes per second "
puts "the throughput of UDP is"
puts "[expr (($numUdp * $UdpSize)/$udpTime)] bytes per second "
exit 0
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run
#===================================
# Simulation parameters setup
#===================================
setval(stop) 20.0 ;# time of simulation end
#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]
#===================================
# Nodes Definition
#===================================
#Create 9 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
#===================================
# Links Definition
#===================================
#Createlinks between nodes
$ns duplex-link $n0 $n2 0.5Mb 100ms DropTail
$ns queue-limit $n0 $n2 3
$ns duplex-link $n1 $n2 0.5Mb 100ms DropTail
$ns queue-limit $n1 $n2 3
$ns duplex-link $n2 $n3 0.5Mb 100ms DropTail
$ns queue-limit $n2 $n3 3
setlan [$ns newLan "$n3 $n4 $n5 $n6 $n7 $n8" 0.5Mb 200ms LL Queue/DropTail MAC/802_3 Channel]
#===================================
# Agents Definition
#===================================
#Setup a TCP/Reno connection
set tcp0 [new Agent/TCP/Reno]
$ns attach-agent $n0 $tcp0
set sink2 [new Agent/TCPSink]
$ns attach-agent $n7 $sink2
$ns connect $tcp0 $sink2
$tcp0 set packetSize_ 1500
#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP/Reno connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 1.0 "plot $tcp0 $r"
$ns at 20.0 "$ftp0 stop"
#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefilenamfile
$ns flush-trace
close $tracefile
close $namfile
execnam v5.nam &
execxgraph -m reno new &
exit 0
}
PROCEDURE
#===================================
# Simulation parameters setup
#===================================
#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]
#===================================
# Mobile node parameter setup
#===================================
#===================================
# Nodes Definition
#===================================
#Create 7 nodes
set n0 [$ns node]
$n0 set X_ 384
$n0 set Y_ 332
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 238
$n1 set Y_ 331
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 589
DEPT. of ECE, KVGCE, SULLIA, D.K Page 19
COMPUTER NETWORKS LABORATORY(15ECL68)
$n2 set Y_ 330
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20
set n3 [$ns node]
$n3 set X_ 107
$n3 set Y_ 320
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20
set n4 [$ns node]
$n4 set X_ 258
$n4 set Y_ 102
$n4 set Z_ 0.0
$ns initial_node_pos $n4 20
set n5 [$ns node]
$n5 set X_ 530
$n5 set Y_ 106
$n5 set Z_ 0.0
$ns initial_node_pos $n5 20
set n6 [$ns node]
$n6 set X_ 720
$n6 set Y_ 316
$n6 set Z_ 0.0
$ns initial_node_pos $n6 20
#===================================
# Agents Definition
#===================================
#===================================
# Applications Definition
#===================================
#===================================
# Termination
#===================================
PART B
Theory:
High-Level Data Link Control (HDLC) is a bit-oriented code-transparent
synchronous data link layer protocol developed by the International Organization
for Standardization (ISO) providing services like:
Framing
Error detection and frame retransmission
Flow control
HDLC provides both connection-oriented and connectionless service.
HDLC can be used for point-to-multipoint connections, but is now used almost
exclusively to connect one device to another, using Asynchronous Balanced
Mode (ABM). The original master-slave modes Normal Response Mode (NRM)
and Asynchronous Response Mode (ARM) are rarely used.
HDLC defines three types of frames:
Information frames (I-frames): It is used to transport user data and
control information relating to user data.
Supervisory frames (S-frames): It is used only to transport control
information-frames are reserved for system management
Unnumbered frames (U-frames): It is intended for managing the link
itself.
HDLC Framing methods:
Starting and ending flags, with bit stuffing
Starting and ending characters, with character stuffing
Character count
Physical layer coding violations
This flag can create a type of problem .That is, if the flag pattern appears in the data,
we need to somehow inform the receiver that this is not the end of the frame.
It is done by stuffing 1 single bit (instead of 1 byte) to prevent the pattern from
looking like a flag. The strategy is called bit stuffing.
Bit stuffing is the process of adding one extra 0 whenever five consecutive 1s follow
a 0 in the data, so that the receiver does not mistake the pattern 0111110 for a flag.
Scenario:
Figure below shows bit stuffing at the sender and bit removal at the receiver.
count=0;
//the following code search the five ones in given
string
for (j=i;j<(i+5)&&str[j]!='\0';j++)
{
if(str[j]=='1')
{
count++;
}
}
//if there is five ones then following code execute to bit
stuffing after five ones
if(count==5)
{
strcat(dest,"111110");
i=i+5;
}
else
{
char temp[2];
temp[0]=str[i];
temp[1]='\0';
strcat(dest,temp);
i++;
}
}
Output:
b. Byte Stuffing:
In byte stuffing (or character stuffing), a special byte is added to the data section of the
frame when there is a character with the same pattern as the flag.
The data section is stuffed with an extra byte. This byte is usually called the escape
character (ESC), which has a predefined bit pattern.
Whenever the receiver encounters the ESC character, it removes it from the data section
and treats the next character as data, not a delimiting flag.
Figure below describes the scenario
Code:
#include<stdio.h>
#include<string.h>
int main()
{
char str[50],dest[50]="";
int i;
printf("enter the character string: ");
gets(str);
printf("\noriginal data:\n");
puts(str);
strcat(dest,"dlestx");
for(i=0;i<strlen(str);)
{
if((str[i]=='d'&&str[i+1]=='l'&& str[i+2]=='e'))
{
else
{
strcat(dest,"dledle");
i=i+3;
}
else
{
char temp[2];
temp[0]=str[i];
temp[1]='\0';
Output:
Theory:
In computer communication theory relating to packet-switched networks, a distance-
vector routing protocol is one of the two major classes of intra domain routing protocols,
the other major class being the link-state protocol. Distance-vector routing protocols use
the Bellman–Ford algorithm, Ford–Fulkerson algorithm, or DUAL FSM (in the case
of System’s protocols) to calculate paths.
A distance-vector routing protocol requires that a router inform its neighbors of topology
changes periodically.
A distance-vector routing protocol requires that a router inform its neighbors of topology
changes periodically.
The term distance vector refers to the fact that the protocol manipulates vectors (arrays)
of distances to other nodes in the network. The distance vector algorithm was the
original ARPANET routing algorithm and was also used in the Internet under the name
of RIP (Routing Information Protocol).
Examples of distance-vector routing protocols include RIPv1 and RIPv2, IGRP, EIGRP,
and Babel.
Scenario:
Output:
Algorithm:
Scenario:
Code:
#include<stdio.h>
void dijikstras(int cost[10][10],int dist[10],int n,int v)
{
int i,u,w,count,flag[10],min;
for(i=1;i<=n;i++)
{
flag[i]=0;
dist[i]=cost[v][i];
}
flag[v]=1; dist[v]=0;
count=2;
while(count<n)
{
for(i=1,min=999;i<=n;i++)
{
if(dist[i]<min &&! flag[i])
{
min=dist[i];
u=i;
}
}
flag[u]=i; count++;
for(w=1;w<=n;w++)
{
if(dist[u]+cost[u][w]<dist[w] &&! flag[w])
Theory:
In networking, error detection refers to the techniques used to detect noise or other impairments
introduced into data while it is transmitted from source to destination. Error detection ensures
reliable delivery of data across vulnerable networks.
Advantages:
Error detection minimizes the probability of passing incorrect frames to the destination,
known as undetected error probability.
Checks consistency of the delivered message, and to recover data that has been
determined to be corrupted by adding some redundancy (i.e., some extra data) to a
message, which receivers can use.
Recovers data that has been determined to be corrupted.
This Cyclic Redundancy Check is the most powerful and easy to implement technique.
CRC is based on binary division.
Receiver Side:
Here the remainder is all zeros, hence the data received has no error
char t[128],cs[128],g[]="10001000000100001";
int a,e,c;
void xor()
{
for(c=1;c<N;c++)
cs[c]=((cs[c]==g[c])?'0':'1');
}
void crc()
{
for(e=0;e<N;e++)
cs[e]=t[e];
do{
if(cs[0]=='1')
xor();
for(c=0;c<N-1;c++)
{
cs[c]=cs[c+1];
}
cs[c]=t[e++];
}while(e<=a+N-1);
}
void main()
{
printf("\nEnter the polynomial:");
scanf("%s",t);
printf("\nGenerator polynomial is:%s",g); a=strlen(t);
for(e=a;e<a+N-1;e++)
t[e]='0';
printf("\nModified t[u] is: %s",t);
crc();
printf("\nChecksum is:%s",cs);
for(e=a;e<a+N-1;e++)
t[e]=cs[e-a];
Output:
Case 1: Without Error
Figure shows an example of communication using this protocol. It is still very simple. The sender sends
one frame and waits for feedback from the receiver. When the ACK arrives, the sender sends the next
frame. Note that sending two frames in the protocol involves the sender in four events and the
receiver in two events.
CODE:
#include <conio.h>
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
#define MAX_SEQ 1
#define TOT_PACKETS 8
#define inc(k) if(k<MAX_SEQ) k++; else k=0;
typedef struct
{
int data;
}packet;
typedef struct
{
int seq;
int ack;
packet info;
DEPT. of ECE, KVGCE, SULLIA, D.K Page 45
COMPUTER NETWORKS LABORATORY(15ECL68)
}frame;
frame DATA;
typedef enum{frame_arrival} event_type;
if(flag==0)
{
from_network_layer(&buffer);
s.info = buffer;
s.seq = frame_to_send;
printf("SENDER : Info = %d Seq No = %d ",s.info,s.seq);
turn = 'r';
to_physical_layer(&s);
flag = 1;
}
wait_for_event_sender(&event);
if(turn=='s')
{
from_network_layer(&buffer);
inc(frame_to_send);
s.info = buffer;
s.seq = frame_to_send;
printf("SENDER : Info = %d Seq No = %d ",s.info,s.seq);
turn = 'r';
to_physical_layer(&s);
}
}
/*__________________________________________________________________________*/
void reciever()
{
static int frame_expected=0;
frame r,s;
event_type event;
wait_for_event_reciever(&event);
if(turn=='r')
from_physical_layer(&r);
if(r.seq==frame_expected)
{
to_network_layer(&r.info);
inc(frame_expected);
}
turn = 's';
to_physical_layer(&s);
}
}
/*__________________________________________________________________________*/
void from_network_layer(packet *buffer)
{
(*buffer).data = i;
i++;
}
/*___________________________________________________________________________*/
void to_physical_layer(frame *s)
{
DATA = *s;
}
/*___________________________________________________________________________*/
void to_network_layer(packet *buffer)
{
printf("RECIEVER :Packet %d recieved , Ack Sent\n",(*buffer).data);
if(i>TOT_PACKETS) //if all packets recieved then disconnect
{
DISCONNECT = 1;
printf("\nDISCONNECTED");
}
}
output:
Notes
In the Go-Back-N Protocol, the sequence numbers are modulo 2m, where m is the size of
the sequence number field in bits.
The send window is an abstract concept defining an imaginary box of size 2m − 1 with
three variables: Sf, Sn, and Ssize.
The send window can slide one or more slots when a valid acknowledgment arrives.
The receive window is an abstract concept defining an imaginary box
of size 1 with one single variable Rn. The window slides when a correct frame has
arrived; sliding occurs one slot at a time.
CODE:#include<stdio.h>
int main()
{
int w,i,f,frames[50];
printf("Enter window size: ");
scanf("%d",&w);
printf("\nEnter number of frames to
transmit: "); scanf("%d",&f);
printf("\nEnter %d frames: ",f);
for(i=1;i<=f;i++)
scanf("%d",&frames[i]);
printf("\nWith sliding window protocol the frames will be sent in the following manner
(assuming no corruption of frames)\n\n");
for(i=1;i<=f;i++)
{
if(i%w==0)
{
printf("%d\n",frames[i]);
return 0;
}
output:
Resending packet 3
Received data of packet 3 is 300
Received data of packet 4 is 400
Received data of packet 5 is 500
All packets sent successfully
Theory
Theory:
Congestion Control
Congestion is a situation in Communication Networks in which too many packets are
present in a network.
Congestion in a network may occur when the load on the network i.e. the number of
packets sent to the network is greater than the capacity of the network i.e. the number of
packets a network can handle.
Causes Of Congestion
Congestion can occur due to several reasons. Below are listed important causes:
The major cause of congestion is often the bursty nature of traffic
Long queue of steam of packets and insufficient memory at the router to process
the queued up packets on several input lines which need to be out on the same
output line, in that case packet loss occurs
Timed-out(repeatedly) of the packets though routers are facilitated with more
memory
Packets arrive at the destination, the will be discarded, due to time out, so
instead of been dropped at any intermediate router (in case memory is restricted)
Slow processors also cause Congestion. router CPU is slow at performing the
task required for them (Queuing buffers, updating tables, reporting any exceptions
etc.), queue can build up even if there is excess of line capacity.
Low-Bandwidth lines can also cause congestion.
Effects of Congestion
Increases the load to the network
Reduces the throughput and increases the delay
LEAKY BUCKET
#include<stdio.h>
#include<time.h>
void main()
{
int a[5],buck_rem=0,buck_cap=0,rate=0,i,sent,recv;
clrscr();
printf("\n enter the bucket capacity \n");
scanf("%d",&buck_cap);
printf("enter the rate of transmission \n");
scanf("%d",&rate);
srand(time(NULL));
for(i=0;i<5;i++)
a[i]=rand()%80+1;
printf("CLOCK PKT_SIZE RECEIVED SENT REMAINING \n");
for(i=0;i<5;i++)
{
if((buck_rem+a[i])>buck_cap)
recv=-1;
else
{
recv=a[i];
buck_rem=buck_rem+a[i];
}
if(buck_rem!=0)
{
sleep(1);
if(buck_rem<rate)
{
sent=buck_rem;
buck_rem=0;
}
else
{
sent=rate;
buck_rem=buck_rem-rate;
}
}
else
sent=0;
if(recv==-1)
printf("\n%d\t%d\t[d]\t%d\t%d\t\n",i,a[i],sent,buck_rem);
else
printf("\n%d\t%d\t%d\t%d\t%d\n",i,a[i],recv,sent,buck_rem);
}
getch();
}
Viva Questions
1. Explain the functions of OSI layers ?
2. Differentiate between TCP/IP Layers and OSI Layers
3. Why header is required?
4. What is the use of adding header and trailer to frames?
5. What is encapsulation?
6. Why fragmentation requires?
7. What is MTU?
8. Which layer imposes MTU?
9. Differentiate between flow control and congestion control.
10. Differentiate between Point-to-Point Connection and End-to-End connections.
11. What are protocols running in different layers?
12. What is Protocol Stack?
13. Differentiate between TCP and UDP.
14. Differentiate between Connectionless and connection oriented connection.
15. Why frame sorting is required?
16. What is meant by subnet?
17. What is meant by Gateway?
18. What is an IP address?
19. What is MAC address?
20. Why IP address is required when we have MAC address?
21. What is meant by port?
22. What are ephemerical port number and well known port numbers?
23. What is a socket?
24. What are the parameters of socket()?
25. Describe bind(), listen(), accept(),connect(), send() and recv().
26. What are system calls? Mention few of them.
27. What is IPC? Name three techniques.
28. Explain mkfifo(), open(), close() with parameters.
29. What is meant by file descriptor?
30. What is meant by traffic shaping?
31. How do you classify congestion control algorithms?
32. Differentiate between Leaky bucket and Token bucket.
33. How do you implement Leaky bucket?