0% found this document useful (0 votes)
13 views109 pages

0793843d-4e09-4f2b-baeb-0cf9d33c9c8b

Uploaded by

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

0793843d-4e09-4f2b-baeb-0cf9d33c9c8b

Uploaded by

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

DEPARTMENT OF COMPUTER SCIENCE

COMPUTER NETWORKS LAB MANUAL

III Year B.Tech. CSE I-Sem SECTION: C

List of Experiments

1. Implement the data link layer framing methods such as character, character-stuffing and bit

stuffing.

2. Write a program to compute CRC code for the polynomials CRC-12, CRC-16 and CRC CCIP

3. Develop a simple data link layer that performs the flow control using the sliding window protocol,

and loss recovery using the Go-Back-N mechanism.

4. Implement Dijsktra’ s algorithm to compute the shortest path through a network

5. Take an example subnet of hosts and obtain a broadcast tree for the subnet.

6. Implement distance vector routing algorithm for obtaining routing tables at each node.

7. Implement data encryption and data decryption

8. Write a program for congestion control using Leaky bucket algorithm.

9. Write a program for frame sorting technique used in buffers.

10. Wireshark

i. Packet Capture Using Wire shark

ii. Starting Wire shark

iii. Viewing Captured Traffic

iv. Analysis and Statistics & Filters.

11. How to run Nmap scan

12. Operating System Detection using Nmap

13. Do the following using NS2 Simulator

i. NS2 Simulator-Introduction

ii. Simulate to Find the Number of Packets Dropped

iii. Simulate to Find the Number of Packets Dropped by TCP/UDP

iv. Simulate to Find the Number of Packets Dropped due to Congestion

v. Simulate to Compare Data Rate& Throughput.

vi. Simulate to Plot Congestion for Different Source/Destination

vii. Simulate to Determine the Performance with respect to Transmission of Packets

Computer Networks Lab Page 1


ACCREDITED BY NAAC & NBA
(Approved by AICTE, New Delhi, Affiliated to JNTUH)
Koheda Road, M.P. Patelguda Post, Ibrahimpatnam(M), Ranga Reddy Dist-501510.
.

Computer Networks Lab Page 2


AIM:

To prevent being interpreted as information. For example, many frame-based


protocols, such as X.25, signal the beginning and end of a frame with six consecutive 1 bits.
Therefore, if the actual data being transmitted has six 1 bits in a row, a zero is inserted after
thefirst 5 so that the dat is not interpreted as a frame delimiter. Of course, on the receiving
end, the stuffed bits must be discarded.

For protocols that require a fixed-size frame, bits are sometimes inserted to make the frame
size equal to this set size.

For protocols that required a continuous stream of data, zero bits are sometimes inserted to
ensurethat the stream is not broken.

import java.util.*;

import java.lang.*;

import java.io.*;

public class

Bitstuffing

public static void main(String args[])throws IOException

System.out.println("enter the binary message");

BufferedReader br=new BufferedReader(new

InputStreamReader(System.in));String str=br.readLine();

String res=new

String();int count=0;

for(int i=0;i<str.length();i++)

Computer Networks Lab Page 3


System.out.println(str.charAt(i));

if(str.charAt(i)!='1'&&str.charAt(i)!='0')

System.out.println("enter the binary values");

return;

if(str.charAt(i)=='1')

count++; res=res+str.

charAt(i);

else

res=res+str.charAt(i)

;count=0;

if(count==5)

res=res+'0'

;count=0;

System.out.println("the original message:"+str);

System.out.println("the Bitstuffing

Computer Networks Lab Page 4


message:"+res);

Computer Networks Lab Page 5


res="01111110"+res+"01111110";

System.out.println("the message stuffing:"+res);

enter the binary

message011111101

the original message:011111101

the Bitstuffing message:0111110101

the message stuffing:01111110011111010101111110

enter the binary

message10110

Computer Networks Lab Page 6


the original message:10110

the Bitstuffing

message:10110

the message stuffing:011111101011001111110

Computer Networks Lab Page 7


Computer Networks Lab Page 8
AIM:

One the bits are stuffed and sent by the sender the receiver receives the msg.The
receiver has to decode it. The algorithm used is destuffin algorithm. It removes a bit when
consequtive 5 ones appear.

1. Input the stuffed sequence.2. Remove start of frame from sequence.3. For every bit in input,a.
Append bit to output sequence. b. Is bit a 1?Yes: Increment count. If count is 5, remove next
bit (which is0) and reset count. No: Set count to 0.4. Remove end of frame bits from sequence.

import java.util.*;

import

java.lang.*;

import java.io.*;

public class Bitunstuffing

public static void main(String args[])throws IOException

System.out.println("enter the binary message");

BufferedReader br=new BufferedReader(new

InputStreamReader(System.in));String str=br.readLine();

String res=new

String();int count=0;

for(int i=8;i<str.length()-8;i++)

System.out.println(str.charAt(i));

if(str.charAt(i)!='1'&&str.charAt(i)!='0')

Computer Networks Lab Page 9


Computer Networks Lab Page 10
System.out.println("enter the binary values");

return;

if(str.charAt(i)=='1')

count++; res=res+str.

charAt(i);

else

res=res+str.charAt(i)

;count=0;

if(count==5)

i++;

count=0;

System.out.println("the string is:"+res);

enter the binary message

Computer Networks Lab Page 11


the string is:011111101

enter the binary message

the string is:10110

Computer Networks Lab Page 12


AIM:

DESCRIPTION: 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 extrabyte. 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.

import java.io.*;

import java.util.*;

import

java.lang.*;

public class Bytestuffing

public static void main(String args[])throws IOException

System.out.println("enter message");

BufferedReader br=new BufferedReader(new

InputStreamReader(System.in));String str=br.readLine();

String res=new String();

System.out.println("enter starting

flag");char sf=br.readLine().charAt(0);

System.out.println("enter ending

flag"); char ef=br.readLine().charAt(0);

for(int i=0;i<str.length();i++)

System.out.println(“\n”);
Computer Networks Lab Page 13
Computer Networks Lab Page 14
System.out.println(str.charAt(i));

if(str.charAt(i)==sf)

res=res+str.charAt(i)+sf;

else

if(str.charAt(i)==e

f)

res=res+str.charAt(i)+ef;

else

res=res+str.charAt(i);

System.out.println("the original messsage is:\n" + str);

System.out.println("the stuffed message is:\n"+res);

res=sf+res+ef;

System.out.println("the message after stuffing :\n"+res);

enter

message

Computer Networks Lab Page 15


cnoslab

enter starting flag

Computer Networks Lab Page 16


enter ending

flagb

the original messsage

is:cnoslab

the stuffed message

is:cnoslaabb

the message after

stuffing:acnoslaabbb

enter

message

aceec

enter starting

flaga

enter ending

Computer Networks Lab Page 17


flage

Computer Networks Lab Page 18


a

the original messsage

is:aceec

the stuffed message

is:aacceecc

the message after

stuffing:aaacceeccc

Computer Networks Lab Page 19


AIM:

DESCRIPTION:

1. Input stuffed sequence.


2. Remove start of frame from sequence (DLE STX).
3. For every character in input,
a. Append character to output sequence.
b. Is character DLE?Yes: Remove next DLE from input sequence. No: Continue.
4. Remove stop of frame character to output sequence (DLE ETX).

import java.io.*;

import java.util.*;

import

java.lang.*;

public class Byteunstuffing

public static void main(String args[])throws IOException

System.out.println("enter message");

BufferedReader br=new BufferedReader(new

InputStreamReader(System.in));String str=br.readLine();

String res=new

String();char

sf=str.charAt(0);

char

ef=str.charAt(str.length()-1);

for(int i=1;i<str.length()-1;i++)

Computer Networks Lab Page 20


if(str.charAt(i)==sf)

Computer Networks Lab Page 21


++i;

res=res+str.charAt(i);

else if(str.charAt(i)==ef)

++i;

res=res+str.charAt(i);

else

res=res+str.charAt(i)

System.out.println("the string is:\n"+res);

enter

message

acnoslaabbb

the string is:

cnoslab

enter message

aaacceecc

c the string

Computer Networks Lab Page 22


is:aceec

Computer Networks Lab Page 23


AIM:

DESCRIPTION:
1. Let r be the degree of G(x). Append r zero bits to the low-order end of theframe, so it now
contains m+rbits and corresponds to the polynomial x^r M(x).
2. Divide the bit string corresponding to G(X) into the bit string corresponding to x^r M(x) using
modulo-2division.
3. Subtract the remainder (which is always r or fewer bits) from the bit stringcorresponding to
x^r M(x) using modulo-2 subtraction. The result is the checksummed frame to be transmitted.
Call its polynomialT(x).The CRC-CCITT polynomial is x^16+ x^12+ x^5+ 1

import

java.lang.*;

import java.util.*;

import java.io.*;

class CRC

public static void main(String args[]) throws IOException

CRCFN obj=new

CRCFN();obj.send();

obj.receive();

class CRCFN

int n,h,l,dl;

char p[]=new char[50];

char t[]=new char[50];

char om[]=new
Computer Networks Lab Page 24
char[50];

Computer Networks Lab Page 25


char dv[]=new

char[50];char r[]=new

char[50]; int i,j,k,z;

String str1=new String("");

String str2=new String("");

String poly=new String("");

String tempdiv=new

String(""); void send() throws

IOException

BufferedReader br =new BufferedReader(new InputStreamReader(System.in));

System.out.println("enter crc to be used");

System.out.println("enter 12 for crc -12 \n 160 for crc 16\n 161 for

crc-16-cit\n");n=Integer.parseInt(br.readLine());

if(!((n==12||(n==160)||(n==161))))

System.out.println("invalid");

System.exit(0);

System.out.println("\nat sender

side");System.out.println(" ");

System.out.println("\n enter the original frame");

str1=br.readLine();

om=str1.toCharArray();

for(int

Computer Networks Lab Page 26


i=0;i<om.length;i++)

System.out.print(om[i]);

Computer Networks Lab Page 27


h=om.length

;str2+=str1;

System.out.println("\n lenght and original message\n"+h+"\t\n"+str2);

if(n==12)

poly+=("1100000001111

");

str2+=("000000000000");

System.out.println(poly+" \n"+tempdiv+" \n" + str2);

else if(n==160)

str2+=("000000000000");

System.out.println(poly+" \n"+tempdiv+" \n" +str2);

else if(n==161)

str2+=("0000000000000000");

Computer Networks Lab Page 28


System.out.println(poly+" \n" +tempdiv+" \n"+str2);

else

Computer Networks Lab Page 29


System.out.println("invalid");

System.exit(0);

dv=str2.toCharArray();

p=poly.toCharArray();

t=tempdiv.toCharArray(

);l=p.length;

dl=dv.length;

System.out.println("\nlenght of polynamial and dividend\n"+l+"\t\n "+dl);

System.out.println("\naugmented didvdend\n");

for(int i=0;i<dv.length;i++)

System.out.print(dv[i]);

System.out.println("\n");

System.out.println("\ngenerator\n"

);for(int i=0;i<p.length;i++)

System.out.print(p[i]);

System.out.println("\n");

System.out.println("\ntemp

data\n");for(int i=0;i<t.length;i++)

System.out.print(t[i]);

System.out.println("\nthe divisor for each step\nof

modulo-2");for(i=0;i<h;i++)

if(dv[i]=='0')

Computer Networks Lab Page 30


for(j=i,k=0;j<(l+i)&&k<l;j++,k++)

if(dv[j]==t[k])

dv[j]='0';

else

dv[j]='1';

else if(dv[i]=='1')

for(j=i,k=0;j<(l+i)&&k<l;j++,k++)

if(dv[j]==p[k])

dv[j]='0';

else

dv[j]='1';

else if((dv[i]!='0')||(dv[i]!='1'))

System.out.println("invalid frame");

System.exit(0);

for(z=i;z<(l+i);z++)

Computer Networks Lab Page 31


System.out.print(dv[z]);

for(i=h,j=0;i<=(dl-1);i++,j++)

r[j]=dv[i];

String rstr=new String(r);

System.out.println("\nthe reminder

is\n"+rstr);str1+=rstr;

System.out.println("\n the frame sent is:\n"+str1);

void receive()throws IOException

//char

om[50],dv[50],r[20];char

om[]=new char[50]; char

dv[]=new char[50]; char

r[]=new char[50];

int i,j,k,z,c=0;

String omstr=new String("");

BufferedReader br=new BufferedReader(new InputStreamReader(System.

in));System.out.println("\n at the receiver\n");

System.out.println(" ................ \n");

System.out.println("\n enter the frame

received:\n");omstr=br.readLine();

om=omstr.toCharArray(

Computer Networks Lab Page 32


);

for(i=0;i<om.length;i++)

Computer Networks Lab Page 33


dv[i]=om[i];

//strcpy(dv,om);

System.out.println("\n the divisor for each step \n of modulo-2 division

is:\n");for(i=0;i<=h-1;i++)

if(dv[i]=='0')

for(j=i,k=0;j<(l+i)&&k<l;j++,k++)

if(dv[j]==t[k])

dv[j]='0';

else

dv[j]='1';

else if(dv[i]=='1')

for(j=i,k=0;j<(l+i)&&k<l;j++,k++)

if(dv[j]==p[k])

dv[j]='0';

else

dv[j]='1';

Computer Networks Lab Page 34


else

System.out.println("invalid frame\n");

System.exit(0);

for(z=i;z<13+i;z++)

System.out.print(dv[z]);

for(i=h,j=0;i<=(dl-1);i++,j++)

r[j]=dv[i];

if(r[j]=='0')

c++;

//r[j]='\0';

System.out.println("\n the remainder

is\n");for(int q=0;q<r.length;q++)

System.out.print(r[q]);

System.out.println("\n\n\n"+c);

if(c==l-1)

System.out.println("\n the frame received is error free:\n");

//om[h]='\0';

System.out.println("\n the original frame is \n");

Computer Networks Lab Page 35


for(int

q=0;q<om.length;q++)

System.out.print(om[q]);

System.out.println("\n the original message is

\n");for(int x=0;x<h;x++)

System.out.print(om[x]);

else

System.out.println("\n received frame is corrupted:FRAME HAVE ERRORS\n");

enter crc to be used

enter 12 for
crc-12160 for crc-
16
161 for crc-16-ccitt
12

at the sender side


.........................

enter the original


frame10110
10110
Length and original
message5
10110
1100000001111
0000000000000
10110000000000000
length of polynomial and
dividend13

Computer Networks Lab Page 36


17
augmented
didvdend
101100000000000
00

Computer Networks Lab Page 37


Generator

temp data

the divisor for each


stepof modulo-2
0111000001111
0010000010001
0100000100010
0100001001011
010001011001

the remainder
is
100010011001

the frame sent is:


101101000100110
01

at the receiver
.........................

enter the frame


received:
10110100010011001

the divisor for each


stepof modulo-2
division is:
0111010000110
0010100000010
0101000000100
0110000000111
0000000000000

the remainder is
000000000000012
the frame received is error free:

Computer Networks Lab Page 38


the original frame is

the original message is

Computer Networks Lab Page 39


10110

enter crc to be
usedenter 12 for
crc-12 160 for
crc-16
161 for crc-16-ccitt
32
Invalid

Computer Networks Lab Page 40


Computer Networks Lab Page 41
AIM:

#include<stdio.h
>
#include<conio.h
>void main()

char
sender[50],receiver[50];int
i,winsize;
printf("\n ENTER THE WINDOWS SIZE : ");
scanf("%d",&winsize);
printf("\n SENDER WINDOW IS EXPANDED TO STORE MESSAGE OR
WINDOW \n");printf("\n ENTER THE DATA TO BE SENT: ");
fflush(stdin);
gets(sender);
for(i=0;i<winsize;i+
+)
receiver[i]=sender[i]
;receiver[i]=NULL;
printf("\n MESSAGE SEND BY THE SENDER:\n");
puts(sender);
printf("\n WINDOW SIZE OF RECEIVER IS
EXPANDED\n");printf("\n ACKNOWLEDGEMENT
FROM RECEIVER \n");
Computer Networks Lab Page 42
for(i=0;i<winsize;i++)
;printf("\n ACK:%d",i);
printf("\n MESSAGE RECEIVED BY RECEIVER IS : ");
puts(receiver);

Computer Networks Lab Page 43


printf("\n WINDOW SIZE OF RECEIVER IS SHRINKED \n");
getch();

Computer Networks Lab Page 44


AIM:

DESCRIPTION: Let the node at which we are starting be called the initial node. Let the distance of
node Y be the distance from the initial node to Y. Dijkstra's algorithm will assign some initial
distance values and will try to improve them step by step.

1.Assign to every node a tentative distance value: set it to zero for our initial node and to infinity
for all other nodes.
2.Mark all nodes unvisited. Set the initial node as current. Create a set of the unvisited nodes
called the consisting of all the nodes except the initial node.
3.For the current node, consider all of its unvisited neighbors and calculate their
distances. For example, if the current node A is marked with a tentative distance of 6, and the
edge connecting it with a neighbor B has length 2, then the distance to B (through A) will be
6+2=8. If this distance is less than the previously recorded tentative distance of B, then
overwrite that distance. Even though a neighbor has been examined, it is not marked as
"visited" at this time, and it remainsin the .
4.When we are done considering all of the neighbors of the current node, mark the current node
as visited and remove it from the . A visited node will never be checked again; its
distancerecorded now is final and minimal.
5.If the destination node has been marked visited (when planning a route between two specific
nodes) or if the smallest tentative distance among the nodes in the is infinity
(when planning a complete traversal), then stop. The algorithm has finished.
6.Set the unvisited node marked with the smallest tentative distance as the next "current node"
and go back to step

Import java.io.*;

Import

java.lang.*;Import

java.util.*; class

STATES

Int l;

Int p;

Int label;

//state

Computer Networks Lab Page 45


[10];class

DIJ

Computer Networks Lab Page 46


public static void main(String args[]) throws IOException

BufferedReader br=new BufferedReader(new

InputStreamReader(System.in));int INF=1000;

int path[]=new int[10];

int x,y;

int route[]=new int[10];

int dist[][]=new int[10][10];

STATES state[]=new

STATES[10];

for(i=0;i<10;i++)

state[i] = new STATES();

System.out.println("Enter no.of

nodes");

n=Integer.parseInt(br.readLine());

for(i=1;i<=n;i++)

System.out.println("enter the no.of neighbours for node ::"+i);

j=Integer.parseInt(br.readLine());

System.out.println("enter Neighbour number ,Distance");

for(k=0;k<j;k++)

Computer Networks Lab Page 47


dest=Integer.parseInt(br.readLine());

dist[i][temp1]=dest;

Computer Networks Lab Page 48


for(i=1;i<=n;i++)

for(j=1;j<=n;j++)

if(i==j && dist[i][j]==0)

System.out.print("\t

"+dist[i][j]);else if(i!=j &&

dist[i][j]==0)

System.out.print("\t "+99);

else

System.out.print("\t "+dist[i][j]);

System.out.println("\n");

System.out.println("To find the path \n\n enter starting node");

t=Integer.parseInt(br.readLine());

System.out.println("Enter ending

node");

s=Integer.parseInt(br.readLine());

for(i=1;i<=n;i++)

Computer Networks Lab Page 49


state[i].p=-1;

state[i].l=INF

Computer Networks Lab Page 50


state[i].label=0;

state[t].l=0;

state[t].label=1

;k=t;

do

for(i=1;i<=n;i++)

if(dist[k][i]!=0 && state[i].label==0)

if(state[k].l+dist[k][i]<state[i].l)

state[i].p=k;

state[i].l=state[k].l+dist[k][i];

k=0;

min=INF;

for(i=1;i<=n;i++

if(state[i].label==0 && state[i].l<min)

Computer Networks Lab Page 51


min=state[i].l;

Computer Networks Lab Page 52


k=i;

state[k].label=1;

i=0;

k=s;

System.out.println("\n Shortest Path

is:");x=0;

do

path[i]=k+1

;route[x]=k;

x++;

i++;

k=state[k].p;

}while(k>0);

for(y=x-1;y>=0;y--

System.out.print(route[y]+"->");

System.out.println("\n Minimum cost is "+min);

enter no. of

Computer Networks Lab Page 53


nodes5

Computer Networks Lab Page 54


enter the no. of neighbours for node ::

13

enter Neighbour

number ,Distance2

enter the no.of neighbours for node ::

22

enter Neighbour

number ,Distance1

enter the no.of neighbours for node ::

33

enter Neighbour

number ,Distance1

Computer Networks Lab Page 55


enter the no.of neighbours for node ::

42

enter Neighbour

number ,Distance3

enter the no.of neighbours for node ::

52

enter Neighbour

number ,Distance1

matrix

0 2 1 99 3

2 0 2 99 99

1 2 0 2 99

99 99 2 0 2

Computer Networks Lab Page 56


3 99 99 2 0

to find the path

enter starting

node1

enter ending

node4

Shortest Path

is:1->3->4->

Minimum cost is 3

enter no.of

nodes4

enter the no.of neighbours for node ::

12

enter Neighbour

number ,Distance3

enter the no.of neighbours for node ::

24

enter Neighbour

number ,Distance1

Computer Networks Lab Page 57


enter the no.of neighbours for node ::

31

enter Neighbour

number ,Distance4

enter the no.of neighbours for node ::

44

enter Neighbour

number ,Distance3

matrix

0 99 2 2

Computer Networks Lab Page 58


2 0 1 1

99 99 0 1

2 1 1 0

to find the path

enter starting

node1

enter ending

node2

Shortest Path

is:1->4->2->

Minimum cost is 3

Computer Networks Lab Page 59


AIM:

DESCRIPTION: Distance Vector means that Routers are advertised as vector of distance and
Direction. Direction is simply next hop address and exit interface and Distance means hop count.
Routers using distance vector protocol do not have knowledge of the entire path to a destination.
Instead DV uses two methods:
1.Direction in which router or exit interface a packet should be forwarded.
2.Distance from its destination.
In distance vector routing, the least cost route between any two nodes is the route with minimum
distance. In this protocol, as the name implies, each node maintains a vector (table) of minimum
distance to every node. As the name suggests the DV protocol is based on calculating the direction
and distance to any link in a network. The cost of reaching a destination is calculated using various
route metrics. RIP uses the hop count of the destination whereas IGRP takes into account other
information such as node delay and available bandwidth.

Updates are performed periodically in a distance-vector protocol where all or part of a router's
routing table is sent to all its neighbors that are configured to use the same distance-vector routing
protocol. RIP supports cross-platform distance vector routing whereas IGRP is a Cisco Systems
proprietary distance vector routing protocol. Once a router has this information it is able to amend
its own routing table to reflect the changes and then inform its neighbors of the changes. This
process has been described as routing by rumor because routers are relying on the information they
receive from other routers and cannot determine if the information is actually valid and true. There
are a number of features which can be used to help with instability and inaccurate routing
information.

#include<stdio.h>
int dist[50][50],temp[50][50],n,i,j,k,x;
void dvr();
int main()

printf("\nEnter the number of nodes :


");scanf("%d",&n);
printf("\nEnter the distance matrix :
\n");for(i=0;i<n;i++)

Computer Networks Lab Page 60


Computer Networks Lab Page 61
for(j=0;j<n;j++)

scanf("%d",&dist[i][j]);
dist[i][i]=0;
temp[i][j]=j;

printf("\n");

dvr();
printf("To enter new cost between the nodes enter value of i &j:");
scanf("%d",&i);
scanf("%d",&j);
printf("enter the new
cost");scanf("%d",&x);
dist[i][j]=x;
printf("After
update\n\n");dvr();
return 0;

void dvr()

for (i = 0; i < n; i++)


for (j = 0; j < n;
j++)
for (k = 0; k < n; k++)
if (dist[i][k] + dist[k][j] < dist[i][j])

dist[i][j] = dist[i][k] + dist[k][j];


Computer Networks Lab Page 62
Computer Networks Lab Page 63
temp[i][j] = k;

for(i=0;i<n;i++)

printf("\n\nRouting Table for Router:: %d is \n",i+1);


printf("To\tCost\tNext\n");
for(j=0;j<n;j++)

if ((temp[i][j]+1)==(j+1))
printf("\n%d\t %d\t --",j+1,dist[i][j]);
else
printf("\n%d\t %d\t %d",j+1,dist[i][j],temp[i][j]+1);

printf("\n\n");

enter the number of nodes ::

enter the cost matrix ::

0 5 2 3 99

5 0 4 99 3

2 4 0 99 4

3 99 99 0 99

Computer Networks Lab Page 64


99 3 4 99 0

Routing Table for router 1 is

To Cost Next

--

--

--

--

Routing Table for router 2 is

To Cost Next

--

--

--

--

Routing Table for router 3 is

To Cos Next
t
--

--

--

--

Routing Table for router

4isToCost Next

1 3 --

Computer Networks Lab Page 65


--

Routing Table for router 5is

To Cos Next
t

--

--

--

enter the number of nodes ::

enter the cost matrix ::

2 3 99 99

5 2 78

99 4 2 1

6 99 3 6

Routing Table for router 1is

To Cos Next
t
--
--
Computer Networks Lab Page 66
Computer Networks Lab Page 67
10
11

Routing Table for router 2is

To Cos Next
t
--

--

--
--

Routing Table for router 3is

To Cos Next
t

--

--
--

Routing Table for router 4is

To Cost Next

--

--

--

Computer Networks Lab Page 68


Computer Networks Lab Page 69
AIM:

DESCRIPTION:
Kruskal's algorithm is used to obtain the broadcast tree from the given subnet.
This algorithm constructs a minimal spanning tree for a connected weighted graph G.

SOURCE CODE:

#include<stdio.h
>
#include<conio.h
> #define
VERTEX 5
#define FALSE -1
#define TRUE 1
void create_graph(int [][VERTEX],int [][VERTEX],int []);
void prims(int [][VERTEX],int [][VERTEX],int []);
void display(int
[][VERTEX]);void main(){
int graph[VERTEX][VERTEX];

clrscr();
create_graph(graph,tree,selected);
prims(graph,tree,selected);
display(tree);

void create_graph(int graph[][VERTEX],int tree[][VERTEX],int


selected[]){int i,j;
printf("\nIf there is No Edge B/W Two Nodes,It's Weight is
99");for(i = 0; i < VERTEX; i++) {
for(j = 0; j < VERTEX; j++) {
printf("\nEnter weight between %d Node %d Node",i,j);
scanf("%d",&graph[i][j]);
tree[i][j] = 0;
}}
for(i = 0; i<VERTEX; i++) {
selected[i] = FALSE;
Computer Networks Lab Page 70
}}

Computer Networks Lab Page 71


void prims(int graph[][VERTEX], int tree[][VERTEX], int
selected[VERTEX]){int ne = 1;
int x,y;
selected[0] = TRUE;
while(ne <
VERTEX) {int min =
99,i,j;
for(i = 0; i < VERTEX; i++){
if(selected[i] == TRUE)
{ for(j = 0; j<VERTEX;
j++) {
if(selected[j] ==
FALSE) {if(min >
graph[i][j]){
min = graph[i][j];
x = i;
y = j;

}}
tree[x][y] = 1;
tree[y][x] = 1;
selected[y] =
TRUE;ne++;

void display(int tree[][VERTEX])

int i,j;
printf("%6c",' ');
for(i =0;i<VERTEX;i++)
printf("%6d",i+1);
printf("\n");
for( i = 0; i<VERTEX; i++)

printf("%6d",i+1) ;
for(j = 0; j<VERTEX; j++)
Computer Networks Lab Page 72
printf("%6d",tree[i][j]);
printf("\n");

Computer Networks Lab Page 73


If there is No Edge B/W Two Nodes,It's Weight is
99Enter weight between 0 Node 0 Node
Enter weight between 1 Node 0
Node5 Enter weight between 1 Node
1 Node99Enter weight between 1
Node 2 Node4 Enter weight between
1 Node 3 Node99Enter weight
between 1 Node 4 Node3 Enter
weight between 2 Node 0 Node2
Enter weight between 2 Node 1
Node4 Enter weight between 2 Node
2 Node99Enter weight between 2
Node 3 Node4 Enter weight between
2 Node 4 Node4 Enter weight
between 3 Node 0 Node3 Enter
weight between 3 Node 1 Node99
Enter weight between 3 Node 2
Node99Enter weight between 3 Node
3 Node99Enter weight between 3
Node 4 Node99Enter weight between
4 Node 0 Node99Enter weight
between 4 Node 1 Node3 Enter
weight between 4 Node 2 Node4
Enter weight between 4 Node 3
Node99Enter weight between 4 Node
4 Node99

1 0
2 0
3 1
4 1
5 0

Computer Networks Lab Page 74


Computer Networks Lab Page 75
AIM:

DESCRIPTION:
RSA is an Internet encryption and authentication system that uses analgorithm developed in 1977
by Ron Rivest, Adi Shamir, and Leonard Adleman. The RSA algorithm is the most commonly used
encryptionand authentication algorithm and is included as part of the Web browsers from
Microsoft and Netscape.

#include<stdio.h
>
#include<math.h
>
#include<conio.h
>void main()

int m,n,d,e,val,count1,count2,p,q,i,j,k,pn,a[10],op;
int c=1; clrscr();
printf("\nRSA ALGORITHM");
printf("\nEnter the Plain Text :");
scanf("%d",&m);
printf("\nKey
Generation\n");
for(p=1;p<=180;p++)

for(q=1;q<=180;q++)

if(p==q)
goto
one;
if(p*q>m
)

one:

Computer Networks Lab Page 76


c or(i=1;i<=p;i++)
o if(p%i==0)
u count1++;
n count2=0;
t for(i=1;i<=q;i++
1 )if(q%i==0)
= count2++;
0 if((count1==2)&&(count2==2))
; goto two;
f

Computer Networks Lab Page 77


}

printf("\n1.prime numbers p=%d\tq=%d",p,q);


n=p*q;
printf("\n2.n=%d",n);
pn=(p-1)*(q-1);

for(e=1;e<=180;e++)

count1=0;
for(i=1;i<=e;i++
)
if(e%i==0
)
count1++
;
if(count1==2
)
three: val=gcd(pn,e
);if(val==1)
goto three;
printf("\n4.e=%d",e);
for(d=1;d<=180;d++
)if((d*e)%pn==1)
goto four;
four: printf("\n5.d=%d",d);
printf("\nEncryption \nCipher text is :
");k=1;
for(i=1;i<=(e/2);i++)

k=k*c;
k=k%n;
}
if(e%2!=0
)
k=k*(m%n);
c=k%n;
printf("%d",c);
printf("\nDecryption\nPlain text is :
");k=1;

for(i=1;i<=(d/2);i++)

Computer Networks Lab Page 78


op=((int)pow(c,2))%
n;k=k*op;

Computer Networks Lab Page 79


k=k%n;
}
if(d%2!=0)
k=k*(c%n)
;
printf("%d",k%n);
getch();

int gcd(int pn,int e)

int c,j;
for(j=1;j<=pn;j++
)

if((pn%j==0)&&(e%j==0
))c=j;

return c;

RSA ALGORITHM
Enter the Plain Text :
56Key Generation
1.prime numbers p=2
q=2
92.n=58
3.pn=28
4.e=3
5.d=19
Encryption
Cipher text is :
50Decryption
Plain text is :56

Computer Networks Lab Page 80


Computer Networks Lab Page 81
AIM:

DESCRIPTION:

SOURCE CODE:
#include<iostream.
h>#include<dos.h>
#include<stdlib.h>
void bktInput(int,int)
#define bucketSize
512void main()

int oprate,
pktSize;
randomize();
cout<<"Enter output rate :
";cin>>oprate;
for(int i=1;i<=5;i++)

delay(random(1000));
pktSize=random(100
0);
cout<<"\nPacket no "<<i<<"\tPacket size = "<<pktSize;
bktInput(pktSize,oprate);

void bktInput(int ps,int or)

if(ps>bucketSize)
cout<<"\n\t\tBucket
overflow";else

delay(500);
while(ps>or
)

cout<<"\n\t\t"<<or<<" bytes
outputted.";ps=ps-or;
delay(500);

if (ps>0)
cout<<"\n\t\tLast "<<ps<<" bytes sent\t";
Computer Networks Lab Page 82
cout<<"\n\t\tBucket output successful";

Computer Networks Lab Page 83


Computer Networks Lab Page 84
Computer Networks Lab Page 85
AIM:

SOURCE CODE:
#include
<stdlib.h>
#include <time.h>
#include
<stdio.h>
#include
<conio.h>
#include
<string.h>#define
FSize 3
typedef struct packet{int SeqNum; char
Data[FSize+1];}packet;struct packet *readdata, *transdata;
int divide(char *msg) {
int msglen, NoOfPacket, i,
j;msglen = strlen(msg);
NoOfPacket =
msglen/FSize;
if ((msglen%FSize)!=0) NoOfPacket++;
readdata = (struct packet *)malloc(sizeof(packet) *
NoOfPacket);for(i = 0; i < NoOfPacket; i++) {
readdata[i].SeqNum = i + 1;
for (j = 0; (j < FSize) && (*msg != '\0'); j++,
msg++)readdata[i].Data[j] = *msg;
readdata[i].Data[j] = '\0';

printf("\nThe Message has been divided as


follows\n");printf("\nPacket No. Data\n\n");
for (i = 0; i < NoOfPacket; i++)
printf(" %2d %s\n",
readdata[i].SeqNum,readdata[i].Data);
return NoOfPacket;

void shuffle(int
NoOfPacket) {int *Status;
int i, j, trans;

Computer Networks Lab Page 86


randomize(
);
Status=(int * )calloc(NoOfPacket, sizeof(int));
transdata = (struct packet *)malloc(sizeof(packet) *
NoOfPacket);for (i = 0; i < NoOfPacket;) {
trans = rand()%NoOfPacket;

Computer Networks Lab Page 87


if (Status[trans]!=1) {
transdata[i].SeqNum =
readdata[trans].SeqNum;
strcpy(transdata[i].Data, readdata[trans].Data);
i++; Status[trans] = 1;

free(Status);

void sortframes(int
NoOfPacket) {packet temp;
int i, j;
for (i = 0; i < NoOfPacket; i++)
for (j = 0; j < NoOfPacket – i-1; j++)
if (transdata[j].SeqNum > transdata[j +
1].SeqNum) {temp.SeqNum =
transdata[j].SeqNum; strcpy(temp.Data,
transdata[j].Data); transdata[j].SeqNum =
transdata[j + 1].SeqNum; strcpy(transdata[j].Data,
transdata[j + 1].Data); transdata[j + 1].SeqNum =
temp.SeqNum; strcpy(transdata[j + 1].Data,
temp.Data);

void receive(int
NoOfPacket) {int i;
printf("\nPackets received in the following order\n");
for (i = 0; i < NoOfPacket; i++) printf("%4d", transdata[i].SeqNum);
sortframes(NoOfPacket);
printf("\n\nPackets in order after sorting..\n");
for (i = 0; i < NoOfPacket; i++) printf("%4d", transdata[i].SeqNum);
printf("\n\nMessage received is :\n");
for (i = 0; i < NoOfPacket; i++) printf("%s", transdata[i].Data);

void main()
{char *msg;
int
NoOfPacket;
Computer Networks Lab Page 88
clrscr();
printf("\nEnter The message to be Transmitted :\n");

Computer Networks Lab Page 89


scanf("%[^\n]", msg);
NoOfPacket =
divide(msg);
shuffle(NoOfPacket);
receive(NoOfPacket);
free(readdata);
free(transdata);
getch();

Output
Enter The messgae to be
Transmitted :hi, it was nice meeting
u on Sunday
The Message has been divided as
followsPacket No. Data
hi,
it
wa
sn
ice
me
eti
ng
uo
ns
und
ay

Packets received in the following

order4 2 6 3 5 1 8 9 11 7 12 10
Packets in order after sorting..

1 2 3 4 5 6 7 8 9 10 11 12

Message received is :

hi, it was nice meeting u on sunday

Computer Networks Lab Page 90


AIM: WORK WITH WIRESHARK TOOL FOR

Computer Networks Lab Page 91


i. PACKET CAPTURE USING WIRE SHARK
ii. STARTING WIRE SHARK
iii. VIEWING CAPTURED TRAFFIC
iv. ANALYSIS AND STATISTICS & FILTERS.

DESCRIPTION:

Computer Networks Lab Page 92


Computer Networks Lab Page 93
AIM: WITH COMMANDS SHOW HOW TO RUN NMAP SCAN AND OPERATING SYSTEM DETECTION
USINGNMAP

DESCRIPTION:

sudo apt-get install nmap

sudo nmap target_IP or domain.com

Ex : sudo nmap 185.52.53.2-222

Ex : sudo nmap 185.52.53.0/24

Computer Networks Lab Page 94


Ex : sudo nmap –p 80,443 185.52.53.222

Computer Networks Lab Page 95


AIM: DO THE FOLLOWING USING NS2 SIMULATOR

i. NS2 SIMULATOR-INTRODUCTION
ii. SIMULATE TO FIND THE NUMBER OF PACKETS DROPPED
iii. SIMULATE TO FIND THE NUMBER OF PACKETS DROPPED BY TCP/UDP
iv. SIMULATE TO FIND THE NUMBER OF PACKETS DROPPED DUE TO CONGESTION
v. SIMULATE TO COMPARE DATA RATE & THROUGHPUT.
vi. SIMULATE TO PLOT CONGESTION FOR DIFFERENT SOURCE/DESTINATION
vii. SIMULATE TO DETERMINE THE PERFORMANCE WITH RESPECT TO
TRANSMISSION OFPACKETS.

DESCRIPTION:

Network Simulator version 2 (NS-2) is discrete event packet level simulator. The
network simulator covers a very large number of application of different kind of
protocols of different network types consisting of different network elements and
traffic models. NS-2 isa package of tools that simulates behavior of networks such as
creating network topologies, log events that happen under any load, analyze the
events and understand the network. The aim of this first experiment is to learn how to
use NS-2, to get acquainted with the simulated objects and understand the operations
of network simulation. We will also look at how to analyze the outcome of a
simulation

Creating a tcl (Tool Command Language) file:

Create a simulation process


Create nodes
Create links
Create events( transfer of data….)

TOPOLOGY: Define a topology

With four nodes.


One node acts as router that forwards the data.
Two nodes have to send data to the fourth node.
Distinguish the data flows from the two nodes from each other.
Show how a queue can be monitored to see how full it is, and how many
packets arebeing discarded.

SOURCE CODE:

Computer Networks Lab Page 96


#Create a simulator object

Computer Networks Lab Page 97


set ns [new Simulator]

#Open the nam trace file


set nf [open out.nam w]
$ns namtrace-all $nf

#Define a 'finish' procedure


proc finish {} {
global ns nf
$ns flush-trace
#Close the trace
file
close $nf
#Execute nam on the trace
fileexec nam out.nam &
exit 0

set n0 [$ns
node] set n1
[$ns node] set
n2 [$ns node]
set n3 [$ns
node]

$ns duplex-link $n0 $n2 1Mb 10ms DropTail


$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns duplex-link $n3 $n2 1Mb 10ms DropTail

$ns duplex-link-op $n0 $n2 orient right-down


$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right

#Create a UDP agent and attach it to node n0


set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
# Create a CBR traffic source and attach it to udp0

set cbr0 [new Application/Traffic/CBR]


$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0

Computer Networks Lab Page 98


#Create a UDP agent and attach it to node n1

set udp1 [new Agent/UDP]

Computer Networks Lab Page 99


$ns attach-agent $n1 $udp1

# Create a CBR traffic source and attach it to udp1

set cbr1 [new Application/Traffic/CBR]


$cbr1 set packetSize_ 500
$cbr1 set interval_ 0.005
$cbr1 attach-agent
$udp1set null0 [new
Agent/Null]
$ns attach-agent $n3 $null0

$ns connect $udp0 $null0


$ns connect $udp1 $null0

$ns at 0.5 "$cbr0 start"


$ns at 1.0 "$cbr1 start"
$ns at 4.0 "$cbr1 stop"
$ns at 4.5 "$cbr0 stop"

$udp0 set class_ 1


$udp1 set class_ 2

$ns color 1 Blue


$ns color 2 Red

$ns duplex-link-op $n2 $n3 queuePos 0.5

# Insert your own code for topology creation and agent definitions, etc.

here#Call the finish procedure after 5 seconds simulation time


$ns at 5.0 "finish"

#Run the simulation


$ns run

Computer Networks Lab Page


Computer Networks Lab Page
PROGRAM 16

Computer Networks Lab Page


AIM: implement Hierarchial Routing

DESCRIPTION:
Routing that is based on hierarchical addressing.
Note: Most Transmission Control Protocol/Internet Protocol (TCP/IP) routing is based on a
two-level hierarchical routing in which an IP address is divided into a network portion and a host
portion. Gatewaysuse only the network portion until an IP datagram reaches a gateway that can
deliver
it directly. Additional levels of hierarchical routing are introduced by the addition of subnetworks.

include<stdio.h>

#include<conio.h

>

#include<string.h

>

#include<ctype.h

>struct hierar

char

node[10];char

line[10]; int

hops;

state[20];

void

main()

int i,boo,small,t1,t2,j,n;

char
Computer Networks Lab Page
ch,rnode[10],temp[10];

clrscr();

printf(“Enter number of nodes”

);scanf(“%d”,&n);

printf(“Enter %d node,line,hops”

,n);for(i=0;i<n;i++)

Computer Networks Lab Page


scanf(“%s %s %d”,&state[i].node,&state[i].line,&state[i].hops);

printf(“ \n node \t \t line \t \t hops”);

for(i=0;i<n;i++)

printf(“%s \t \t %s \t \t %d \n”,state[i].node,state[i].line,state[i].hops);printf(

“Enter starting point”);

scanf(“%s”,&rnode);

printf(“\n node \t \t line \t \t hops \n”);

for(i=0;i<n;i++)

t1=toascii(rnode[0]);

if(t1=t2)

boo=0;

else

boo=1;

if(boo=0

printf(“%s \t \t %s \t \t %d \n”,state[i].node,state[i].line,state[i].hops);

else

printf(“%c”,state[i].node[0]); printf(

“\t \t %s”,state[i].line);

strcpy(temp,state[i].node);

small=state[i].hops;

for(j=i;temp[0]==state[i].node[0];j++

Computer Networks Lab Page


)

Computer Networks Lab Page


if(state[j].hops<smal

l)

small=state[j].hops;

i++;

printf(“\t \t %d \n”,small);

getch();

Enter number of nodes

7Enter 7 node,line,hops

1A

1B 1B

1C 1C

2A 1B

2B 1B

2C 1B

2D 1B

NODE LINE HOP


S
1A

1B 1B

1C 1C

2A 1B
Computer Networks Lab Page
2B 1B

Computer Networks Lab Page


2C 1B
2D 1B

Enter starting point 1A

NODE LINE HOP


S
1A

1B 1B

1C 1C
1B

Computer Networks Lab Page

You might also like