0% found this document useful (0 votes)
120 views72 pages

CN Lab Manual

The document discusses simulating and implementing error detection and correction techniques. It describes using NETSIM software and a LAN trainer kit to: 1) Simulate longitudinal redundancy check for error detection and hamming codes for error correction. 2) Implement a hamming technique program in C++ to detect and correct single bit errors in received data. 3) The program is executed successfully, demonstrating hamming code error detection and correction.

Uploaded by

vino dhini
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)
120 views72 pages

CN Lab Manual

The document discusses simulating and implementing error detection and correction techniques. It describes using NETSIM software and a LAN trainer kit to: 1) Simulate longitudinal redundancy check for error detection and hamming codes for error correction. 2) Implement a hamming technique program in C++ to detect and correct single bit errors in received data. 3) The program is executed successfully, demonstrating hamming code error detection and correction.

Uploaded by

vino dhini
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/ 72

1(A).

SIMULATION OF ERROR DETECTION AND ERROR


CORRECTION TECHNIQUES

AIM:
To simulate error detection and correction using NETSIM and LAN trainer kit

APPARATUS REQUIRED:
1. PC
2. NETSIM software
3. LAN trainer kit

ALGORITHM:
ERROR DETECTION

 Go to NETSIM
 Select error detection option using longitudinal redundancy check
 Input data is entered (8 alphabets)
 Link the input data and the corresponding error is displayed

ERROR CORRECTION

 Here, select the error correction option using hamming codes


 Enter the input data and adjust the position
 Link and get the output

PROCEDURE:

 Connect the LAN trainer kit


 Click on error detection and correction option
 Enter the input data for error correction and detection
 Link the output
OUTPUT:

LONGITUDINAL REDUNDANCY CHECK:


HAMMING CODE:

RESULT:

Thus the hamming technique has been simulated and verified using
NETSIM.
1 (B). IMPLEMENTATION OF ERROR DETECTION AND
ERROR CORRECTION TECHNIQUES

AIM:

To implement the hamming technique for detecting and correcting


single bit error in received data.

ALGORITHM:

1. Open Turbo C++ software and type the program for error detection

2. Get the input in the form of bits.

3. Append I6 zeros as redundancy bits.

4. Divide the appended data using a divisor polynomial.

5. The resulting data should be transmitted to the receiver.

6. At the receiver the received data is entered.

7. The same process is repeated at the receiver.

8. If the remainder is zero there is no error otherwise there is some error


in the received bits.

9. Run the program.

PROCEDURE:

1. Open C editor window.


2. Type program and save it.
3. Compile the program.
4. Observe the result.
PROGRAM:

#include<conio.h>

#include<math.h>

#include <stdio.h>

int main()

int data[7],rec[7],i,c1,c2,c3,c;

printf("this works for message of 4 bits in size \n enter message bit one by
one:");

scanf("%d%d%d%d", &data[0],&data[1],&data[2],&data[4]);

data[6]=data[0]^data[2]^data[4];

data[5]=data[0]^data[1]^data[4];

data[3]=data[0]^data[1]^data[2];

printf("\nthe encoded bits are given below: \n");

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

printf("%d ",data[i]);

printf("\nenter the received data bits one by one: ");

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

scanf("%d",&rec[i]);

c1=rec[6]^rec{4]^rec[2]^rec[0];

c2=rec[5]^rec[4]^rec[1]rec[0];

c3=rec[3]^rec[2]^rec[1]^rec[0];

c=c3*4+c2*2+c1;
if(c==0)

printf("\n congratulations there is no error:" );

else

printf("\n error on ,the postion: %d \nthe correct message is \n",c);

if(rec[7-c]==0) '

rec[7-c]=1;

else

rec[7-c]=0;

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

printf("%d ",rec[i]);

getch() ;

}
OUTPUT:

this works for message of 4 bits in size


enter message bit one by one:1
0
1
0

the encoded bits are given below:


0182401824182401824
enter the received data bites one by one:1
0
1
0
0
0
1

error on the position:3


the correct message is
1010101

RESULT:

Thus the program error detection & correction has been executed and verified
successfully.
2 (A). SIMULATION OF STOP AND WAIT PROTOCOL AND
SLIDING WINDOW

AIM:

To Simulate and to study stop and Wait protocol using NETSIM and
LAN trainer kit.

APPARATUS REQUIREMENTS:

1.PC

2.NS-2 Simulator

3.LAN Trainer kit

ALGORITHM:

Step I: Start with the window size from the transmitting node

Step 2: After transmission of a frame the transmitting node waits for a


reply from the receiving node.

Step 3: If the transmitted frame reaches the receiver without error, the
receiver transmits a Positive Acknowledgement.

Step 4: If the transmitted frame reaches the receiver with error, the
receiver do not transmit acknowledgement.

Step 5: If the transmitter receives a positive acknowledgement it


transmits the next frame if any. Else if the transmission timer expires, it
retransmits the same frame again.

Step 6: If the transmitted acknowledgment reaches the Transmitter


without error, the Transmitter transmits the next frame if any.

Step 7: If the transmitted frame reaches the Transmitter with error, the
Transmitter transmits the same frame.

Step 8: This concept of the Transmitting node waiting after


transmission for a reply from the receiver is known as STOP and
WAIT.
PROCEDURE (LAN Trainer kit)

1. Connect the LAN trainer kit to PC.


2. Open LT01 trainer kit icon.
3. Go to Stop and Wait menu in window.
4. Click search and get tha IP address host name of the system.
5. Select one system as sender and another as receiver.
6. In sender click one receiver option.
7. Note down the corresponding output and plot graph.

PROCEDURE (NETSIM) :

1. Open NETSIM.
2. Click on Programming -->Transmission flow.
3. Click on sample option and select wait protocol.
4. Select file to transmitted and error rate.
5. Click on link and then animate.
STOP AND WAIT :

Data frame=1 is flowing from node 1 to node 2 with no error


Acknowledgement from Node 2 to Node 1.

RESULT:

Thus the performance of stop and wait protocol using LAN Trainer and
NETSIM was done.
2(B). IMPLEMENTATION OF STOP AND WAIT PROTOCOL
AND SLIDING WINDOW

AIM:

To implement the hamming technique for detecting and correcting single bit
error in received data.

SOFTWARE REQUIREMENTS: Turbo C

ALGORITHM:

1. Start the program


2. Declare the variable i,j, number of frames , x ,x1, x2 and initialize x1 =
10
3. Use rand ()to generate random share and number of frames is computed
by rand() / 200.
4. Then store noframes as no frame /8
5. Then print the no of frames
6. Using while loop check noframes <0
7. Print the sliding frames
8. Using srand () increment the sleep value
9. Store the value of rand () /10 in x. check the value of x.
10. If the value of x is even go to the sleep mode to print the waiting second
11. If the value of x is odd then send the frame and also the
acknowledgement is printed
12. End of the stop and wait protocol
13. Stop the program
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int i,j,noframes,x,x1=10,x2;
clrscr();
for(i=0;i<200;i++)
rand();
noframes=rand()/200;
i=1;
j=1;
noframes=noframes/8;
printf("\n number of frames is %d",noframes);
getch();
while(noframes>0)
{
printf("\n sending frame %d",i);
srand(x1++);
x=rand()%10;
if(x%2==0)
{
for(x2=1;x2<2;x2++)
{
printf("waiting for %d seconds \n",x2);
stop(x2);
}
printf("sending frame %d",i);
srand(x1++);
x=rand()%10;
}
printf("\n ACK for frame %d",j);
noframes=-1;
i++;
j++;
}
printf("\n end of stop and wait protocol\n");
printf("\n.......\n");
getch();
}
OUTPUT:

No of frames is 4
Sending frame 1
Waiting for 1 seconds

Sending frame 1
Ack for frame 1
Sending frame 2
Waiting for 1 seconds

Sending frame 2
Ack for frame 2
Sending frame 3
Ack for frame 3

Sending frame 4
Ack for frame 4

End of stop and wait protocol

RESULT:
Thus the program for implement of stop and wait protocol has been
executed successfully
3. SIMULATION AND STUDY OF GOBACK-N AND SELECTIVE
REPEAT PROTOCOLS

AIM:

To implement and study of Goback-N and selective repeat protocols


using NETSIM and LQN trainer kit

APPARATUS REQUIREMENTS:

1. PC

2. NS-2 Simulator

3. LAN Trainer kit

ALGORITHM FOR GO BACK N

1. The source node transmits the frames continuously.

2. Each frame in the buffer has a sequence number starting from 1 and
increasing up to the window size.

3. The source node has a window i.e. a buffer to store the frames. This
buffer size is the number of frames to be transmitted continuously

4. The size of the window depends on the protocol designer.

5. For the first frame, the receiving node forms a positive


acknowledgement if the frame is received without error.

6. If subsequent frames are received without error (up to window size)


cumulative positive acknowledgement is formed.

7. If the subsequent frame is received with error, the cumulative


acknowledgment error-free frames are transmitted. if in the same window
two frames or more frames are received with error, the second and the
subsequent error frames are neglected. Similarly even the frames
received without error after the receipt of a frame with error are
neglected.
ALGORITHM: SELECTIVE REPEAT

1. The source node transmits the frames continuously.

2. Each frame in the buffer has a sequence number starting from I and
increasing up to the window size.

3. The source node has a window i.e. a buffer to store the frames. This
buffer size is the number of frames to be transmitted continuously.

4. The receiver has a buffer to store the received fTames. The size of the
buffer depends upon the window size defined by the protocol designer.

5. The size of the window depends according to the protocol designer.

6. The source node transmits frames continuously till the window size is
exhausted. If any of the frames are received with error only those frames
are requested for retransmission

7. If all the frames are received without error, a cumulative positive


acknowledgement is sent.

8. If there is an error in frame 3, an acknowledgement for the frame 2 is


sent and then only Frame 3 is retransmitted. Now the window slides to
get the next frames to the window.

9. If acknowledgment is transmitted with error, all the frames of window


are retransmitted. Else ordinary window sliding takes place. (" ln
implementation part, Acknowledgment error is not considered)

10. If all the frames transmitted are errorless the next transmission is
carried out for the new window.

11. This concept of repeating the transmission for the error frames only
is called Selective Repeat transmission flow control protocol.
SELECTIVE REPEAT :

Data frame=1 is flowing from node 1 to node 2 with no error


Acknowledgement from Node 2 to Node 1.
GO BACK-N

Data frame=1 is flowing from node 1 to node 2 with no error


Acknowledgement from Node 2 to Node 1.

RESULT:

Thus the performance of Go back-N and Selective repeat protocols was


done using NETSIM and LAN Trainer kit
4. IMPLEMENTATION OF HIGH LEVEL DATA LINK CONTROL

AIM:

To implement High level data link control using NETSIM

ALGORITHM:

1. Start the program


2. Declare the variable count,src_router,i,j,k,w,v,min,cost_matrix
dist,last,flag
3. Use flag()to count the number of routers.
4. Using for loop check the distance of routers .
5. Print the shortest path of source router.
6. Stop the program
PROGRAM:
#include<stdio.h>
#include<string.h>
int main()
{
int count,src_router,i,j,k,w,v,min;
int cost_matrix[100][100],dist[100],last[100];
int flag[100];
printf("\nenter the no of routers:");
scanf("%d",&count);
printf("\n enter the cost matrix values:");
for(i=0;i<count;i++)
{
for(j=0;j<count;j++)
{
printf("\n%d->%d:",i,j);
scanf("%d",&cost_matrix[i][j]);
if(cost_matrix[i][j]<0)
cost_matrix[i][j]=1000;
}
}
printf("\nenter the source router:");
scanf("%d",&src_router);
for(v=0;v<count;v++)
{
flag[v]=0;
last[v]=src_router;
dist[v]=cost_matrix[src_router][v];
}
flag[src_router]=1;
for(i=0;i<count;i++)
{
min=1000;
for(w=0;w<count;w++)
{
if(flag[w])
if(dist[w]<min)
{
v=w;
min=dist[w];
}
}
flag[v]=1;
for(w=0;w<count;w++)
{
if(flag[w])
if(min+cost_matrix[v][w]<dist[w])
{
dist[w]=min+cost_matrix[v][w];
last[w]=v;
}
}
}
for(i=0;i<count;i++)
printf("\n%d==>%d:path taken:%d",src_router,i,i);
w=i;
while(w!=src_router)
{
printf("\n<--%d",last[w]);
w=last[w];
}
printf("\nshortest path cost:%d",dist[i]);
return 0;
}
OUTPUT:
enter the cost matrix values:
0->0:3

0->1:4

1->0:5

1->1:6

enter the source router:1

1==>0:path taken:0

shortest path cost:5


1==>1:path taken:1
shortest path cost:6

RESULT:

Thus the shortest path using High level data link was executed.
5. IMPLEMENTATION OF IP COMMANDS SUCH AS PING
and TRACE ROUTE

AIM:

To write a java program demonstrate the usage of PING command.

ALGORITHM:

Step 1: start the program.

Step 2: Include necessary package in java.

Step 3: To create a process object p to implement the ping command.

Step 4: declare one Buffered Reader stream class object.

Step 5: Get the details of the server

5.1: length of the IP address.

5.2: time required to get the details.

5.3: send packets, receive packets and lost packets.

5.4: minimum, maximum and average times.

Step 6: print the results.

Step 7: Stop the program.


PROGRAM:

//PING

import java.io.*;

import java.net.*;

class pingserver

public static void main(String args[])

Try

String str;

System.out.print(" Enter the IP Address to be Ping : ");

BufferedReader buf1=new BufferedReader(new


InputStreamReader(System.in));

String ip=buf1.readLine();

Runtime H=Runtime.getRuntime();

Process p=H.exec("ping " + ip);

InputStream in=p.getInputStream();

BufferedReader buf2=new BufferedReader(new InputStreamReader(in));


while((str=buf2.readLine())!=null)

System.out.println(" " + str);

}}

catch(Exception e)

System.out.println(e.getMessage());

}}
OUTPUT:

Enter the IP address to the ping:192.168.0.1

Pinging 192.168.0.1: with bytes of data =32

Reply from 192.168.0.11:bytes=32 time<1ms TTL = 128

Reply from 192.168.0.11:bytes=32 time<1ms TTL = 128

Reply from 192.168.0.11:bytes=32 time<1ms TTL = 128

Reply from 192.168.0.11:bytes=32 time<1ms TTL = 128

Ping statistics for 192.168.0.1

Packets: sent=4,received=4,lost=0(0% loss),approximate round trip time in


milliseconds:

Minimum = 1ms,maximum=4ms,average=2ms
TRACE ROUTE

Client:

//pingclient.java

import java.io.*;

import java.net.*;

import java.util.Calendar;

class pingclient

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

String str;

int c=0;

long t1,t2;

Socket s=new Socket("192.168.42.65",5555);

DataInputStream dis=new DataInputStream(s.getInputStream());

PrintStream out=new PrintStream(s.getOutputStream());

while(c<4)

0t1=System.currentTimeMillis();

str="Welcome to network programming world";

out.println(str);

System.out.println(dis.readLine());

t2=System.currentTimeMillis();

System.out.println(";TTL="+(t2-t1)+"ms");

c++;

s.close();}}
//pingserver.java

import java.io.*;

import java.net.*;

import java.util.*;

import java.text.*;

class pingserver

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

ServerSocke tss=new ServerSocket(5555);

Socket s=ss.accept();

int c=0;

while(c<4)

DataInputStream dis=new DataInputStream(s.getInputStream());

PrintStream out=new PrintStream(s.getOutputStream());

String str=dis.readLine();

out.println("Reply from"+InetAddress.getLocalHost()+";Length"+str.length());

c++;

s.close();

}
OUTPUT:

//Client:

Reply from User/192.168.42.65;Length36

;TTL=228ms

Reply from User/192.168.42.65;Length36

;TTL=3ms

Reply from User/192.168.42.65;Length36

;TTL=2ms

Reply from User/192.168.42.65;Length36

;TTL=2ms

RESULT:
Thus the ping and trace route configuration has been executed successfully.
6. IMPLEMENTATION OF IP ADDRESS CONFIGURATION

AIM:

To write a program to find the IP address of the system.

ALGORITHM:

1. Start

2. Declare IP address and hostname.

3. Using the function get Host by name() to find the address of the system.

4. Get the name of the system by using the get Host Name() function.

5. By specifying the system name find out the IP address of the system using the
function

6. Stop the program.


PROGRAM:

import socket

hostname = socket.gethostname()

IPAddr = socket.gethostbyname(hostname)

print("Your Computer Name is:" + hostname)

print("Your Computer IP Address is:" + IPAddr)

OUTPUT:

Your Computer Name is: ECE

Your Computer IP Address is:192.168.5.92

RESULT:
Thus the IP address configuration was executed successfully.
7. TO CREATE SCENARIO AND STUDY THE PERFORMANCE OF
NETWORK WITH CSMA/CA PROTOCOL AND COMPARE WITH
CSMA/CA PROTOCOLS

AIM:

To study and implement the Carrier Sense Multiple Access with collision
avoidance.

APPARATUS REQUIRED:

1. Pentium PC

2. Eclipse

3. Java

ALGORITHM:

1. Start

2. Initialize k+0

3. Check for the channel idleness

4. If the channel is busy, wait for IFS (Inter Frame Space) time

5. Again check for the channel idleness

6. If the channel is busy, keep on checking channel idleness

7. If the channel is idle, choose a random number.

8. Wait for R slots

9. Send frame now

10. Set wait time for receiving acknowledgment


11. If the acknowledgement is received, then the transmission will be
completed

12. Else, go for checking the channel idleness

13. Stop
CSMA/CA PROGRAM

CLIENT 1

import java.io.*; import java.net.*;

public class client

public static void main(String[] args)

try

System.out.println("============ Client 1 ==============="); client cli =


new client();

int R = 0;

Boolean bln = false;

for(int k=1; k<=15;k++)

System.out.println("attempt : "+k);

// is idle channel? System.out.println("is Channel idle? ");

int i = 0;

while(true)

System.out.print(i=i+1); if(cli.isidle())

System.out.println("\n Channel idle"); System.out.println("Wait IFS time 5000");


// wait for IFS time Thread.sleep(8000);

// is still idle channel? System.out.println("is still idle?");

if(cli.isidle())

System.out.println("Still idle");

// Choose random number R = 2^k-1;

System.out.println("Selected Random number :"+R); time:

System.out.println("waiting for R slot"+R*6000);

// wait R slot Thread.sleep(R*6000);

// send frame System.out.println("Message sent");

// Timer runs and wait for time out System.out.println("Wait for time
out :"+10000);

// ack check if(cli.isidle())

System.out.println("Ackreceived");

bln = true;

break;

else

System.out.println("Busy, goes to channel idle check");

}
}

if(bln == true)

break;

catch (InterruptedException e)

System.out.println(e);

Boolean isidle()

try

Socket soc= new Socket("localhost",137); soc.close();

return true;

catch (Exception e)

return false;

}
}

CLIENT 2

import java.io.*; import java.net.*;

public class server

public static void main(String[] args)

try

System.out.println("============ Client 2 ==============="); while(true)

ServerSocket ss = new ServerSocket(137); System.out.println("Waiting for


connection"); ss.accept();

ss.close(); System.out.println("Connected");

catch(Exception e)

System.out.println(e);

}
OUTPUT:

Case 1: dont run client 2 (Channel Busy always)

============ Client 1 ==============

attempt : 1

is Channel idle? 123456789101112131415161718192021222324

Case 2: stop client2 on is still idle (Channel busy after IFS time)

============ Client 1 ==============

attempt : 1

is Channel idle?

Channel idle

Wait IFS time 5000 is still idle?

Busy, goes to channel idle check 2345678910

Case 3: stop client2 on Ack received check (Collision occured)

============ Client 1 ==============

attempt : 1

is Channel idle?

Channel idle

Wait IFS time 5000 is still idle?


Still idle

Selected Random number :2 waiting for R slot time: 12000 Message sent

Wait for time out : 10000 Ack not received

attempt : 2

is Channel idle?

Case 4: CSMA/CA ack received

============ Client 1 ===============

attempt : 1

is Channel idle?

Channel idle

Wait IFS time 5000 is still idle?

Still idle

Selected Random number :2 waiting for R slot time: 12000 Message sent

Wait for time out : 10000 Ack received

RESULT:

Thus the CSMA/CA is implemented and studied successfully.


8. NETWORK TOPOLOGY - STAR, BUS, RING

AIM:

To study the performance of token bus, token ring and star protocol through
simulation and using LAN trainer kit.

APPARATUS REQUIRED:

1. PC.

2. NETSIM software.

PROCEDURE :

1. Open NETSIM menu.


2. Go to simulation menu and select LAN.
3. Select the token bus and token ring.
4. Then device selection menu appears choose the topology and device.
5. After that result select the appears the topology at an device link click appears.
6. Then work server will appear trap bus topology and place the node.

PROCEDURE IN LAN TRAINER:

1. Connect system 1, system 2, system 3,and system 4 as a ring. Here system


1 is transmitter and system as receiver system 2 and 3 avoid.

2. At the system 1, enter the neighbor input address of system 2 and click
insert ring.

3. At the system 2, enter the neighbor input address of system 3 and click
insert ring.

4. After the transfer of five between the systems if you want to receive another
file from another system click receive again.
TOKEN BUS:
TOKEN RING:
STAR TOPOLOGY:
RESULT:

Thus the simulation and implementation of token ring and token bus protocol
using and LAN trainer kit was implemented successfully
9 (A). SIMULATION OF DISTANCE VECTOR ROUTING ALGORITHM

AIM:

To implement distance vector routing algorithm using NETSIM software.

APPARATUS REQUIRED:

1. PC.

2. NETSIM software.

ALGORITHM:

Step 1. To start with router, the router of the assign an cost a router, the router
that was the text permanent.

Step 2. Examine the each neighbor router of the router that was the last
permanent router.

Step 3. Assign smallest cost of each router sent the router with smallest
cumulative cost and make it permanent.

Step 4. Repeat the following steps with there is no change in routing until for
all router.

Step 5. Take the router entry that is not in your own routing table but exist in
anyone.

Step 6. Repeat the steps for all routing to check whether changes are made in
anyone of the router if yes then repeat the step.
PROCEDURE:

1. To begin the implementation open network of network academic.


2. Click one programming and select vector routing algorithm.
3. Click on simple more.
4. Then correct the router.
5. Click on the link option note down the table.
DISTANCE VECTOR:
RESULT:

Thus the distance vector routing algorithm was implemented using NETSIM
software.
9(B). IMPLEMENTATION OF DISTANCE VECTOR ROUTING
ALGORITHM

AIM:

To implement distance vector routing algorithm using C.

ALGORITHM

1. Start the program


2. By conversion, the distance of the node to itself is assigned to zero and when
a node is unreachable the distance is accepted.
3. Accept the input distance matrix between each node.
4. Store the distance between node in suitable variable.
5. Calculate the minimum distance between two nodes by iterating.
 If the distance between the two node is large then the calculated alternative
available path replace the existing distance with the calculated distance.
6. Print the shortest path calculated.
7. Stop the program.
Program:

#include<stdio.h>
#include<conio.h>
struct node
{
unsigned dist[20];
unsigned from[20];
}rt[10];
void main()
{
int costmat[20][30];
int nodes,i,j,k,count=0;
printf("\n enter the number of nodes");
scanf("%d",&nodes);
printf("\n enter the cost matrix");
for(i=0;i<nodes;i++)
{
for(j=0;j<nodes;j++)
{
scanf("%d",&costmat[i][j]);
costmat[i][i]=0;
rt[i].dist[j]=costmat[i][j];
rt[i].from[j]=j;
}
}
do
{
count=0;
for(i=0;i<nodes;i++)
for(j=0;j<nodes;j++)
for(k=0;k<nodes;k++)
if(rt[i].dist[j]>costmat[i][k]+rt[k].dist[j])
{
rt[i].dist[j]=rt[i].dist[k]+rt[k].dist[j];
rt[i].from[j]=k;
count++;
}
}
while(count!=0);
for(i=0;i<nodes;i++)
{
printf("\nfor router%d\n",i+1);
for(j=0;j<nodes;j++)
{
printf("\t\n node %d via %d distance %d",j+1,rt[i].from[j]+1,rt[i].dist[j]);
}
}
printf("\n\n");
getch();
}
Output:
Enter the number of nodes3

Enter the cost matrix0 2 7


201
710

for router1

node 1 via 1 distance 0


node 2 via 2 distance 2
node 3 via 2 distance 3
for router2

node 1 via 1 distance 2


node 2 via 2 distance 0
node 3 via 3 distance 1
for router3

node 1 via 2 distance 3


node 2 via 2 distance 1
node 3 via 3 distance 0

Result:
Thus the implementation of distance vector routing protocol has been executed
successfully.
10(A). SIMULATION OF LINK STATE ROUTING ALGORITHM

AIM:

To simulate the link state routing algorithm using NETSIM.

APPARATUS REQUIRED:

1. PC

2. NETSIM software

ALGORITHM:

Step 1. To start with router, the router of the assign a cost of their router.

Step 2. Examine the each neighbor router of the router that was the permanent router.

Step 3. Assign the cumulative cost of the each router find the router with smallest
cumulative cost and make it permanent.

Step 4. Repeat the step 3 until every router becomes permanent.

PROCEDURE:

1. To start with the experiment open NETSIM software.


2. Open programming option on tire panel and click on shortest path algorithm.
3. Then click on the sample mode.
4. Connect the router and assign cost for the router.
5. Click on the link option and note down the table.
RESULT:

Thus the shortest path using link state algorithm was executed using NETSIM
software.
10(B). IMPLEMENTATION OF LINK STATE ROUTING ALGORITHM

AIM:

To write a program and implement link state routing algorithm using C

Algorithm

1. Star the program.


2. Initialize the variables.
3. Count the number of routers and its cost.
4. Go to for loop increment the cost matrix value.
5. Check the flag values to check the distance and print the shortest path of the
router.
6. Stop the program.
PROGRAM:

#include<stdio.h>

#include<string.h>

int main()

int count,src_router,i,j,k,w,v,min;

int cost_matrix[100][100],dist[100],last[100];

int flag[100];

printf("\nenter the no of routers:");

scanf("%d",&count);

printf("\n enter the cost matrix values:");

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

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

printf("\n%d->%d:",i,j);

scanf("%d",&cost_matrix[i][j]);

if(cost_matrix[i][j]<0)

cost_matrix[i][j]=1000;

printf("\nenter the source router:");

scanf("%d",&src_router);
for(v=0;v<count;v++)

flag[v]=0;

last[v]=src_router;

dist[v]=cost_matrix[src_router][v];

flag[src_router]=1;

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

min=1000;

for(w=0;w<count;w++)

if(flag[w])

if(dist[w]<min)

v=w;

min=dist[w];

flag[v]=1;

for(w=0;w<count;w++)

if(flag[w])
if(min+cost_matrix[v][w]<dist[w])

dist[w]=min+cost_matrix[v][w];

last[w]=v;

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

printf("\n%d==>%d:path taken:%d",src_router,i,i);

w=i;

while(w!=src_router)

printf("\n<--%d",last[w]);

w=last[w];

printf("\nshortest path cost:%d",dist[i]);

return 0;

}
Output:
Enter the no of routers=3

Enter the cost matrix values:

0->0:

[exam47@cselinux~]$./a.out

Enter the no of routers=2

Enter the cost matrix values:

0 ->0:3

0 ->1:4

1 ->0:5

1 ->1:6

Enter the source router:1

1= =>0: Path taken: 0

<- -1

Shortest path cost: 5

1= =>1: Path taken: 1

Shortest path cost: 6

Result:

Thus the program to implementation of link state routing has been executed.
11. STUDY OF NETWORK SIMULATOR (NS).AND SIMULATION OF
CONGESTION CONTROL ALGORITHMS USING NS.

Aim:

To Study of Network simulator (NS).and Simulation of Congestion Control


Algorithms using NS.

INTRODUCTION:

ns (from network simulator) is a name for series of discrete event network


simulators, specifically ns-1, ns-2 and ns-3. All of them are discrete-event network
simulator, primarily used in research and teaching. ns-3 is free software, publicly
available under the GNU GPLv2 license for research, development, and use.

The goal of the ns-3 project is to create an open simulation environment for
networking research that will be preferred inside the research community
It should be aligned with the simulation needs of modern networking research.

 It should encourage community contribution, peer review, and validation of


the software.

Since the process of creation of a network simulator that contains a sufficient number
of high quality validated, tested and actively maintained models requires a lot of
work, ns-3 project spreads this workload over a large community of users and
developers

ns-1:

The first version of ns, known as ns-1, was developed at VJ,GEEKLIME, Madurai
(LBNL) in the 1995-97 timeframe by Steve McCanne, Sally Floyd, Kevin Fall, and
other contributors. This was known as the LBNL Network Simulator, and derived
from an earlier simulator known as REAL by S. Keshav. The core of the simulator
was written in C++, with Tcl-based scripting of simulation scenarios.[5] Long-
running contributions have also come from Sun Microsystems, the UC Berkeley
Daedelus, and Carnegie Mellon Monarch projects.
ns-2 :

In 1996-97, ns version 2 (ns-2) was initiated based on a refactoring by Steve


McCanne. Use of Tcl was replaced by MIT's Object Tcl (OTcl), an object-oriented
dialect Tcl. The core of ns-2 is also written in C++, but the C++ simulation objects
are linked to shadow objects in OTcl and variables can be linked between both
language realms. Simulation scripts are written in the OTcl language, an extension
of the Tcl scripting language. Presently, ns-2 consists of over 300,000 lines of source
code, and there is probably a comparable amount of contributed code that is not
integrated directly into the main distribution (many forks of ns-2 exist, both
maintained and unmaintained). It runs on GNU/Linux, FreeBSD, Solaris, Mac OS
X and Windows versions that support Cygwin. It is licensed for use under version 2
of the GNU General Public License.

ns-3 :

A team led by Tom Henderson, George Riley, Sally Floyd, and Sumit Roy, applied
for and received funding from the U.S. National Science Foundation (NSF) to build
a replacement for ns-2, called ns-3. This team collaborated with the Planete project
of INRIA at Sophia Antipolis, with Mathieu Lacage as the software lead, and formed
a new open source project.

In the process of developing ns-3, it was decided to completely abandon


backward compatibility with ns-2. The new simulator would be written from scratch,
using the C++ programming language. Development of ns-3 began in July 2006. A
framework for generating Python bindings (pybindgen) and use of the Waf build
system were contributed by Gustavo Carneiro.

The first release, ns-3.1 was made in June 2008, and afterwards the project
continued making quarterly software releases, and more recently has moved to three
releases per year. ns-3 made its eighteenth release (ns-3.18) in the third quarter of
2013.
Current status of the three versions is:
 x ns-1 is no longer developed nor maintained, x
 ns-2 build of 2009 is not actively maintained (and is not being accepted for
journal publications)
 ns-3 is actively developed (but not compatible for work done on ns-2).

Design:

ns-3 is built using C++ and Python with scripting capability. The ns-3 library is
wrapped to python thanks to the pybindgen library which delegates the parsing of
the ns-3 C++ headers to gccxml and pygccxml to generate automatically the
corresponding C++ binding glue. These automatically-generated C++ files are
finally compiled into the ns-3 python module to allow users to interact with the C++
ns-3 models and core through python scripts. The ns-3 simulator features an
integrated attribute-based system to manage default and per-instance values for
simulation parameters. All of the configurable default values for parameters are
managed by this system, integrated with command-line argument processing,
Doxygen documentation, and an XML-based and optional GTK-based configuration
subsystem.

 The large majority of its users focuses on wireless simulations which involve
models for Wi-Fi, WiMAX, or LTE for layers 1 and 2 and routing protocols
such as OLSR and AODV.

Components:
ns-3 is split over couple dozen modules containing one or more models for
real-world network devices and protocols.

ns-3 has more recently integrated with related projects: the Direct Code
Execution extensions allowing the use of C or C++-based applications and Linux
kernel code in the simulations.
Simulation workflow:

The general process of creating a simulation can be divided into several steps:

1. Topology definition: to ease the creation of basic facilities and define their
interrelationships, ns-3 has a system of containers and helpers that facilitates
this process.
2. Model development: models are added to simulation (for example, UDP,
IPv4, point to-point devices and links, applications); most of the time this is
done using helpers.
3. Node and link configuration: models set their default values (for example, the
size of packets sent by an application or MTU of a point-to-point link); most
of the time this is done using the attribute system.
4. Execution: simulation facilities generate events, data requested by the user is
logged.
5. Performance analysis: after the simulation is finished and data is available as
a time stamped event trace. This data can then be statistically analysed with
tools like R to draw conclusions.
6. Graphical Visualization: raw or processed data collected in a simulation can
be graphed using tools like Gnuplot, matplotlib or XGRAPH.
Examples of network simulators:
There are many both free/open-source and proprietary network simulators.
Examples of notable network simulation software are, ordered after how often they
are mentioned in research papers:
1. ns (open source)
2. OPNET (proprietary software)
3. NetSim (proprietary software)
Uses of network simulators:
Network simulators serve a variety of needs. Compared to the cost and time
involved in setting up an entire test bed containing multiple networked computers,
routers and data links, network simulators are relatively fast and inexpensive. They
allow engineers, researchers to test scenarios that might be particularly difficult or
expensive to emulate using real hardware - for instance, simulating a scenario with
several nodes or experimenting with a new protocol in the network. Network
simulators are particularly useful in allowing researchers to test new networking
protocols or changes to existing protocols in a controlled and reproducible
environment. A typical network simulator encompasses a wide range of networking
technologies and can help the users to build complex networks from basic building
blocks such as a variety of nodes and links. With the help of simulators, one can
design hierarchical networks using various types of nodes like computers, hubs,
bridges, routers, switches, links, mobile units etc.

Various types of Wide Area Network (WAN) technologies like TCP, ATM,
IP etc. and Local Area Network (LAN) technologies like Ethernet, token rings etc.,
can all be simulated with a typical simulator and the user can test, analyze various
standard results apart from devising some novel protocol or strategy for routing etc.
Network simulators are also widely used to simulate battlefield networks in
Network-centric warfare.

Packet loss:
When one or more packets of data travelling across a computer network fail
to reach their destination. Packet loss is distinguished as one of the three main error
types encountered in digital communications; the other two being bit error and
spurious packets caused due to noise. Packets can be lost in a network because they
may be dropped when a queue in the network node overflows. The amount of packet
loss during the steady state is another important property of a congestion control
scheme. The larger the value of packet loss, the more difficult it is for transport layer
protocols to maintain high bandwidths, the sensitivity to loss of individual packets,
as well as to frequency and patterns of loss among longer packet sequences is
strongly dependent on the application itself.

Throughput
This is the main performance measure characteristic, and most widely used.
In communication networks, such as Ethernet or packet radio, throughput or network
throughput is the average rate of successful message delivery over a communication
channel. The throughput is usually measured in bits per second (bit/s or bps), and
sometimes in data packets per second or data packets per time slot This measure how
soon the receiver is able to get a certain amount of data send by the sender. It is
determined as the ratio of the total data received to the end to end delay. Throughput
is an important factor which directly impacts the network performance.

Delay:
Delay is the time elapsed while a packet travels from one point e.g., source
premise or network ingress to destination premise or network degrees. The larger
the value of delay, the more difficult it is for transport layer protocols to maintain
high bandwidths. We will calculate end to end delay.

Queue Length:
A queuing system in networks can be described as packets arriving for service,
waiting for service if it is not immediate, and if having waited for service, leaving
the system after being served. Thus queue length is very important characteristic to
determine that how well the active queue management of the congestion control
algorithm has been working.

RESULT:
Thus the study of Network simulator (NS2) was studied.
12. ENCRYPTION AND DECRYPTION USING PROGRAMMING
LANGUAGE

AIM:

To write a C program to implement ENCRYPTION AND DECRYPTION


of data.

ALGORITHM

ENCRYPTION

Get the text to be encrypted (plain text) and key text.

a. Find the length of the plain text.

b. For i=1 to length of plain text

c. Find the binary equivalent of the character of plain text.

d. Find the binary equivalent of the character of key text

e. Find the XOR of above two values.

The resulting value will be the encrypted format (cipher text) of the plain text.

ALGORITHM

DECRYPTION

Get the text to be decrypted (cipher text) and key text. Find the length of the cipher
text. For i=1 to length of cipher text

a. Find the binary equivalent of the character of cipher text.

b. Find the binary equivalent of the character of key text

c. Find the XOR of above two values.

The resulting value will be the decrypted format (original plain text) of the cipher
plain text.
PROGRAM:

# include<stdio.h>
#include<conio.h>
void main ( )
{
static int s, i, k,n,c[100];
printf(“\n program 1: encryption and 2. decryption”);
scanf (“%d”, &s);
switch (s)
{ case 1: printf(“enter the key value:”);
scanf(“%d”, &k);
printf(“enter the length of text:”);
scanf(“%d”, &n);
printf(“enter the data to be encrypted:”);
for (i=0;i<=n;i++)
scanf(“%c”, &c[i]);
for (i=0;i<=n;i++)
{c[i]=c[i]+k;
if (c[i]>90)
c[i]=c[i]-26;}
printf(“encrypted data”);
for (i=1;i<=n;i++)
printf(“%c”, c[i]);
break;
case 2: printf(“enter the key value:”);
scanf(“%d”, &k);
printf(“enter the length of text:”);
scanf(“%d”, &n);
printf(“enter the data to be decrypted:”);
for (i=0;i<=n;i++)
scanf(“%c”, &c[i]);
for (i=0;i<=n;i++)
{c[i]=c[i]-k;
if (c[i]<65)
c[i]=c[i]+26;}
printf(“decrypted data”);
for (i=1;i<=n;i++)
printf(“%c”, c[i]);
break;
case 3: break;
getch ();
}
}
OUTPUT:

Program 1: Encryption and 2. Decryption


1. ENCRYPTION
Enter the key value: 1
Enter the length of text: 5
Enter the data to be encrypted: HELLO
Encrypted data: IFMMP

2. DECRYPTION
Enter the key value: 1
Enter the length of text: 5
Enter the data to be decrypted: IFMMP
Decrypted data: HELLO

RESULT:

Thus the Data Encryption and Decryption was studied using Turbo C software.

You might also like