0% found this document useful (0 votes)
71 views36 pages

R20 CN Lab Manual

The document is a certificate template for students of SAI Ganapathi Engineering College, detailing their practical lab work in the Computer Science and Engineering department. It includes an index of various experiments related to networking, data link layer framing methods, and algorithms, along with procedures and sample programs for implementation. The document is structured to certify students' completion of specified experiments during their academic year.

Uploaded by

Kittu
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)
71 views36 pages

R20 CN Lab Manual

The document is a certificate template for students of SAI Ganapathi Engineering College, detailing their practical lab work in the Computer Science and Engineering department. It includes an index of various experiments related to networking, data link layer framing methods, and algorithms, along with procedures and sample programs for implementation. The document is structured to certify students' completion of specified experiments during their academic year.

Uploaded by

Kittu
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/ 36

SAI GANAPATHI ENGINEERING COLLEGE (6F)

(APPROVED BY AICTE, NEW DELHI, AFFILIATED TO JNTU-GV, AP)


GIDIJALA (V), ANANDAPURAM (M), VISAKHAPATNAM-531173

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

CERTIFICATE

This is to certify that Mr./Miss…………….......................


Bearing Hall Ticket No……………………... of……………..
Branch of…………..BTech…………. Semester had done……...
Number of experiments during the academic year………………
In the lab of……………………………………..

Signature of the Head of the Dept. Signature of Laboratory in-charge

Date: Date:

Signature of the Internal Examiner Signature of the External Examiner

Date: Date:

1
INDEX

Page
S.No Name of the Experiment DATE No Remarks
1. Study of Network devices in detail and connect
the computers in Local Area Network.

2. Write a Program to implement the data link


layer framing methods such as
i) Character stuffing ii) bit stuffing.
3. Write a Program to implement data link layer
framing method checksum.

4. Write a program for Hamming Code generation


for error detection and correction.

5. Write a Program to implement on a data set of


characters the three CRC polynomials – CRC 12,
CRC 16 and CRC CCIP.
6. Write a Program to implement Sliding window
protocol for Goback N.

7. Write a Program to implement Sliding window


protocol for Selective repeat.

8. Write a Program to implement Stop and Wait


Protocol.

9. Write a program for congestion control using


leaky bucket algorithm.
10. Write a Program to implement Dijkstra‘s
algorithm to compute the Shortest path through
a graph.

11. Write a Program to implement Distance vector


routing algorithm by obtaining routing table at
each node (Take an example subnet graph with
weights indicating delay between nodes).
12. Write a Program to implement Broadcast tree by
taking subnet of hosts.

2
EXPERIMENT-1

a) AIM: Study of different types of Network cables and practically implement the cross-
wired cable and straight through cable using clamping tool.

APPARATUS(Components): RJ-45 connector, crimping Tool, Twisted pair Cable

PROCEDURE: To do these practical following steps should be done:

1. Start by stripping off about 2 inches of the plastic jacket off the end of the cable. Be very
careful at this point, as to not nick or cut into the wires, which are inside. Doing so could
alter the characteristics of your cable, or even worse render is useless. Check the wires, one
more time for nicks or cuts. If there are any, just whack the whole end off, and start over.

2. Spread the wires apart but be sure to hold onto the base of the jacket with your other hand.
You do not want the wires to become untwisted down inside the jacket. Category 5 cable
must only have 1/2 of an inch of 'untwisted' wire at the end; otherwise, it will be 'out of
spec'. At this point, you obviously have ALOT more than 1/2 of an inch of un-twisted wire.

3. You have 2 end jacks, which must be installed on your cable. If you are using a pre-made
cable, with one of the ends whacked off, you only have one end to install - the crossed over
end. Below are two diagrams, which show how you need to arrange the cables for each type
of cable end. Decide at this point which end you are making and examine the associated
picture below.

Diagram shows you how to prepare Cross wired connection

4
Diagram shows you how to prepare straight through wired connection

5
b) AIM: Study of following Network Devices in Detail
 Repeater
 Hub
 Switch
 Bridge
 Router
 Gate Way

APPARATUS (Software): No software or hardware needed.

PROCEDURE: Following should be done to understand this practical.


Repeater: Functioning at Physical Layer. A repeater is an electronic device that receives a signal
and retransmits it at a higher level and/or higher power, or onto the other side of an obstruction, sothat
the signal can cover longer distances. Repeaters have two ports, so cannot be used to connect for more
than two devices.

Hub: An Ethernet hub, active hub, network hub, repeater hub, hub or concentrator is a device
for connecting multiple twisted pair or fiber optic Ethernet devices together and making them act as a
single network segment. Hubs work at the physical layer of the OSI model. The device is a form of
multiport repeater. Repeater hubs also participate in collision detection, forwarding a jam signal to all
ports if it detects a collision.

Switch: A network switch or switching hub is a computer networking device that


connects network segments. The term commonly refers to a network bridge that processes and
routes data at the data link layer (layer 2) of the OSI model. Switches that additionally
process data at the network layer (layer 3 and above) are often referred to as Layer 3 switches
or multilayer switches.

6
Bridge: A network bridge connects multiple network segments at the data link layer of the OSI
model. In Ethernet networks, the term bridge formally means a device that behaves according to the
IEEE 802.1 D standards. A bridge and switch are very much alike; a switch being a bridge with
numerous ports. Switch or Layer 2 switch is often used interchangeably with bridge. Bridges can

analyze incoming data packets to determine if the bridge is able to send the given packet to another
segment of the network.

Router: A router is an electronic device that interconnects two or more computer networks, and
selectively interchanges packets of data between them. Each data packet contains address
information that a router can use to determine if the source and destination are on the same
network, or if the data packet must be transferred from one network to another. Where multiple
routers are used in a large collection of interconnected networks, the routers exchange information
about target system addresses, so that each router can build up a table showing the preferred paths
between any two systems on the interconnected networks.

Gateway:

7
In a communications network, a network node equipped for interfacing with another network that uses
different protocols.
* A gateway may contain devices such as protocol translators, impedance matching devices, rate
converters, fault isolators, or signal translators as necessary to provide system interoperability. It also
requires the establishment of mutually acceptable administrative procedures between both networks.
* A protocol translation/mapping gateway interconnects networks with different network protocol
technologies by performing the required protocol conversions.

8
c) AIM: Study of network IP

 Classification of IP address
 Sub netting
 Super netting

APPARATUS (Software): NA

PROCEDURE: Following is required to be study under this practical.


 Classification of IP address

As show in figure we teach how the ip addresses are classified and when they are used.

Class Address Range Supports


Class A 1.0.0.1 to 126.255.255.254 Supports 16 million hosts on each of 127 networks.
Class B 128.1.0.1 to 191.255.255.254 Supports 65,000 hosts on each of 16,000 networks.
Class C 192.0.1.1 to 223.255.254.254 Supports 254 hosts on each of 2 million networks.
Class D 224.0.0.0 to 239.255.255.255 Reserved for multicast groups.
Class E 240.0.0.0 to 254.255.255.254 Reserved.

 Sub netting
Why we Develop sub netting and How to calculate subnet mask and how to identify subnet address.

 Super netting
Why we develop super netting and How to calculate supernet mask and how to identify supernet
address.

9
d) AIM: Connect the computers in Local Area Network.

PROCEDURE:

On the host computer, follow these steps to share the Internet connection:

1. Log on to the host computer as Administrator or as Owner.


2. Click Start, and then click Control Panel.
3. Click Network and Internet Connections.
4. Click Network Connections.
5. Right-click the connection that you use to connect to the Internet. For example, if you connect to the
Internet by using a modem, right-click the connection that you want under Dial-up / other network
available.
6. Click Properties.
7. Click the Advanced tab.
8. Under Internet Connection Sharing, select the Allow other network users to connect through this
computer's Internet connection check box.
9. If you are sharing a dial-up Internet connection, select the Establish a dial-up connection whenever a
computer on my network attempts to access the Internet check box if you want to permit your computer
to automatically connect to the Internet.
10. Click OK. You receive the following message: When Internet Connection Sharing is enabled, your
LAN adapter will be set to use IP address 192.168.0.1. Your computer may lose connectivity with other
computers on your network. If these other computers have static IP addresses, it is a good idea to set them to
obtain their IP addresses automatically. Are you sure you want to enable Internet Connection Sharing?
11. Click Yes.
The connection to the Internet is shared to other computers on the local area network (LAN).
The network adapter that is connected to the LAN is configured with a static IP address of 192.168.0.1 and
a subnet mask of 255.255.255.0

On the client computer

To connect to the Internet by using the shared connection, you must confirm the LAN adapter IP
configuration, and then configure the client computer. To confirm the LAN adapter IP configuration,
follow these steps:

1. Log on to the client computer as Administrator or as Owner.


2. Click Start, and then click Control Panel.
3. Click Network and Internet Connections.
4. Click Network Connections.
5. Right-click Local Area Connection and then click Properties.
6. Click the General tab, click Internet Protocol (TCP/IP) in the connection uses the following items
list, and then click Properties.
7. In the Internet Protocol (TCP/IP) Properties dialog box, click Obtain an IP address automatically (if
it is not already selected), and then click OK.

Note: You can also assign a unique static IP address in the range of 192.168.0.2 to 192.168.0.254. For
example, you can assign the following static IP address, subnet mask, and default gateway:

8. IP Address 192.168.31.202
9. Subnet mask 255.255.255.0
10. Default gateway 192.168.31.1
11. In the Local Area Connection Properties dialog box, click OK.
12. Quit Control Panel.
10
EXPERIMENT-2
AIM: Write a Program to implement the data link layer framing methods such as
i) Character stuffing ii) bit stuffing.

i) PROGRAM:

#include<stdio.h>
#include<string.h>
void main()
{
int i,k=0,n,j=6;
char s[100],res[100]=" ",a[100]=" ";
printf("Enter the string:");
gets(s);
strcpy(res,"dlestx");
for(i=0;s[i]!='\0';i++)
{
if(s[i]=='d'&&s[i+1]=='l'&&s[i+2]=='e')
{
res[j]='d';
res[j+1]='l';
res[j+2]='e';
j=j+3;
}
res[j]=s[i];
j++;
}
strcat(res,"dleetx");
printf("Stuffed char:%s",res);
n=strlen(res);
for(i=6;i<n-6;i++)
{
if(res[i]=='d'&&res[i+1]=='l'&&res[i+2]=='e')
{
i=i+3;
}
a[k]=res[i];
k++;
}
printf("\nDestuffed char:%s",a);
}

OUTPUT:
Enter the string:hello
Stuffed char:dlestxhellodleetx
Destuffed char:hello

13
ii)PROGRAM:
a)
#include<stdio.h>
#include<string.h>
void main()
{
int a[20],b[30],i,j,k,count,n;
printf("Enter frame length:");
scanf("%d",&n);
printf("Enter input frame (0's & 1's only):");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
i=0; count=1; j=0;
while(i<n)
{
if(a[i]==1)
{
b[j]=a[i];
for(k=i+1;a[k]==1 && k<n && count<5;k++)
{
j++;
b[j]=a[k];
count++;
if(count==5)
{
j++;
b[j]=0;
}
i=k;
}}
else
{
b[j]=a[i];
}
i++;
j++;
}
printf("After stuffing the frame is:");
for(i=0;i<j;i++)
printf("%d",b[i]);
}
OUTPUT:
Enter frame length:7
Enter input frame (0's & 1's only):
1
1
1
1
1
1
1
After stuffing the frame is:11111011

14
b)
#include <stdio.h>
#include <string.h>
int main() {
char data[100], stuffedData[200];
int i, count = 0, j = 0;
printf("Enter the data: ");
scanf("%s", data);
for(i = 0; i < strlen(data); i++) {
if(data[i] == '1') {
count++;
stuffedData[j++] = data[i];
}
else {
count = 0;
stuffedData[j++] = data[i];
}
if(count == 5) {
count = 0;
stuffedData[j++] = '0';
}
}
stuffedData[j] = '\0';
printf("Data after bit stuffing: %s\n", stuffedData);
return 0;
}

OUTPUT:

Enter the data:111111111011111


Data after bit stuffing:11111011110111110

15
EXPERIMENT-3
AIM: Write a Program to implement data link layer framing method checksum.

PROGRAM:

#include <stdio.h>
#include <string.h>
// Function to find the One's complement of the given binary string
void Ones_complement(char* data) {
for (int i = 0; i < strlen(data); i++) {
if (data[i] == '0')
data[i] = '1';
Else
data[i] = '0';
}
}

// Function to return the checksum value of the given string when divided in K size blocks
void checkSum(char* data, int block_size, char* result) {
int n = strlen(data);

// Check if data size is divisible by block_size


// Otherwise add '0' at the front of the data
if (n % block_size != 0) {
int pad_size = block_size - (n % block_size);
for (int i = 0; i < pad_size; i++) {
memmove(data + 1, data, strlen(data) + 1);
data[0] = '0';
}
}

// Binary addition of all blocks with carry


// First block of data stored in result variable
strncpy(result, data, block_size);
result[block_size] = '\0';

// Loop to calculate the block-wise addition of data


for (int i = block_size; i < n; i += block_size) {
// Stores the data of the next block
char next_block[block_size + 1];
strncpy(next_block, data + i, block_size);
next_block[block_size] = '\0';

// Stores the binary addition of two blocks


char additions[block_size + 1];
int sum = 0, carry = 0;
16
// Loop to calculate the binary addition of the current two blocks of k size
for (int k = block_size - 1; k >= 0; k--) {
sum += (next_block[k] - '0') + (result[k] - '0');
carry = sum / 2;
if (sum == 0) {
additions[k] = '0';
sum = carry;
}
else if (sum == 1) {
additions[k] = '1';
sum = carry;
} else if (sum == 2) {
additions[k] = '0';
sum = carry;
}
else {
additions[k] = '1';
sum = carry;
}
}

// After binary addition of two blocks with carry, if carry is 1 then apply binary addition
char final[block_size + 1];
if (carry == 1) {
for (int l = block_size - 1; l >= 0; l--) {
if (carry == 0) {
final[l] = additions[l];
}
else if (((additions[l] - '0') + carry) % 2 == 0) {
final[l] = '0';
carry = 1;
}
else {
final[l] = '1';
carry = 0;
}
}
strncpy(result, final, block_size);
}
else {
strncpy(result, additions, block_size);
}
}

// Return One's complements of result value which represents the required checksum value
Ones_complement(result);
}
17
// Function to check if the received message is the same as the sender's message
int checker(char* sent_message, char* rec_message, int block_size) {
char sender_checksum[block_size + 1];
char receiver_checksum[block_size + 1];

// Checksum Value of the sender's message


checkSum(sent_message, block_size, sender_checksum);

// Concatenate sender's checksum to receiver's message


char combined_message[strlen(rec_message) + block_size + 1];
strcpy(combined_message, rec_message);
strcat(combined_message, sender_checksum);

// Checksum value for the receiver's message


checkSum(combined_message, block_size, receiver_checksum);

// If receiver's checksum value is 0


for (int i = 0; i < block_size; i++) {
if (receiver_checksum[i] != '0')
return 0; // Error
}
return 1; // No Error
}

// Driver Code
int main() {
char sent_message[] = "10000101011000111001010011101101";
char recv_message[] = "10000101011000111001010011101101";
int block_size = 8;
if (checker(sent_message, recv_message, block_size)) {
printf("No Error");
}
else {
printf("Error");
}
return 0;
}

OUTPUT:

No Error

18
EXPERIMENT-4
AIM: Write a program for Hamming Code generation for error detection and correction.

PROGRAM:

#include <math.h>
#include <stdio.h>

// Store input
bits
int input[32];

// Store hamming
code
int code[32];

int ham_calc(int, int);


void solve(int input[], int);

// Function to calculate bit for ith position


int ham_calc(int position, int c_l)
{
int count = 0, i, j;
i = position - 1;

// Traverse to store Hamming Code


while (i < c_l) {
for (j = i; j < i + position; j++) {
// If current bit is 1
if (code[j] == 1)
count++;
}
// Update i
i = i + 2 * position;
}
if (count % 2 == 0)
return 0;
else
return 1;
}
// Function to calculate hamming
code void solve(int input[], int n)
{
int i, p_n = 0, c_l, j, k; i = 0;
// Find msg bits having set bit at x'th position of number
while (n > (int)pow(2, i) - (i + 1)) {
p_n++;
i++;
}
c_l = p_n + n; j = k = 0;
// Traverse the msgBits
19
for (i = 0; i < c_l; i++) {
// Update the code
if (i == ((int)pow(2, k) - 1)) {
code[i] = 0;
k++;
}

// Update the code[i] to the input character at index j


else {
code[i] = input[j];
j++;
}
}

// Traverse and update the hamming code


for (i = 0; i < p_n; i++) {

// Find current position


int position = (int)pow(2, i);

// Find value at current position


int value = ham_calc(position, c_l);

// Update the code


code[position - 1] = value;
}

// Print the Hamming Code


printf("\nThe generated Code Word is: ");
for (i = 0; i < c_l; i++) {
printf("%d", code[i]);
}
}

// Driver Code
void main()
{
// Given input message Bit
input[0] = 0;
input[1] = 1;
input[2] = 1;
input[3] = 1;
int N = 4;

// Function Call
solve(input, N);
}

OUTPUT:

The generated Code Word is: 0001111

20
EXPERIMENT-5

AIM: Write a program to implement on a data set of characters the three CRC polynomials – CRC 12, CRC
16 and CRC CCIP.

PROGRAM:

#include<conio.h>
#include<string.h>
#include<dos.h>
#include<stdlib.h>
int copy();
int check();
int i,j,k,t,count=0,num=0;
int gen[10],frame[30],rem[30],temp[30];
void main()
{
char c,plym[50];
char ch[]={'0','1','2','3','4','5','6','7','8','9'};
clrscr();
printf("\t\t\t**CYCLIC REDUNDANCY CHECK-12**\n\n\n");
for(i=0;i<50;i++)
plym[i]='\0';
for(i=0;i<30;i++)
temp[i]=rem[i]=frame[i]='\0';
for(i=0;i<10;i++)
gen[i]='\0';
printf("enter the polynomial:");
gets(plym);
plym[strlen(plym)]=' ';
for(i=0;i<strlen(plym);i++)
{
if(plym[i]=='x')
{
i++;
for(;plym[i]!=' ';count,i++)
{
}
if(count==3)
{
for(i=i-1,j=3;j<=9;j++)
if(plym[i]==ch[j])
{
printf("\Enter the polynomial's");
printf("degree is high");
getch();
22
exit(0);
}
for(j=0,num=10;j<=2;j++)
if(plym[i]==ch[j])
{
num=num+j;
frame[num]=1;
}
}
if(count==2)
{
for(i=i-1,j=1,num=0;j<=9;j++)
if(plym[i]==ch[j])
num=j;
frame[num]=1;
}
if(count==0)
frame[1]=1;
count=0;
}
else if(plym[i]=='1')
frame[0]=1;
}
printf("Frame is:");
for(i=12,j=0;i>=0;i--,j++)
{
temp[j]=frame[i];
printf("%d",frame[i]);
}
printf("\n\n\n>>>>both high & low orders");
printf("bits of GENERATOR must be 1<<<<");
printf("\n enter the generator:");
for(num=i=0;(c=getchar())!='\n';i++,num)
{
if(c=='1')
gen[i]=1;
else if(c=='0')
gen[i]=0;
else
{
printf("\nEnter the GENERATOR");
printf("is other then 0 or 1");
getch();
exit(0);
}
}
for(j=13,i=i-1;i>0;i--,j++)
23
temp[j]=0;
printf("\n\n Frame after appending 0's:");
copy();
check();
printf("\n The REMAINDER is:");
for(i=13;i<j;i++)
{
temp[i]=rem[i];
printf("%d",rem[i]);
}
printf("\n\n\n Transmitting FRAME....");
delay(10000);
printf("\n\n\n Transmitted FRAME is:");
copy();
check();
printf("\n frame received");
printf("\n\n\n checking for errors..");
delay(10000);
printf("\n\n\n received frame is:");
copy();
check();
printf("\n the remainder is:");
for(i=13;i<j;i++)
printf("%d",rem[i]);
printf("\n DATA SENT SUCCESSFULLY");
getch();
}
check()
{
for(i=0;i<=12;i++)
{
if(rem[i]==0)
continue;
else
{
for(k=0,t=i;k<num;k++,t++)
{
if(rem[t]==1&&gen[k]==1)
rem[t]=0;
else if(rem[t]==0&&gen[k]==0)
rem[t]=0;
else if(rem[t]==1&&gen[k]==0)
rem[t]=1;
else if(rem[t]==0&&gen[k]==1)
rem[t]=1;
}
}
24
}
return 0;
}
copy()
{
for(i=0;i<j;i++)
{
printf("%d",temp[i]);
rem[i]=temp[i];
}
return 0;
}

OUTPUT:

***CYCLIC REDUNDANCY CHECK-12***


enter the polynomial: x^8 x^7 x^3 x^2
1 FRAME is: 0000110001101
>>>>both high & low ordersbits of GENERATOR must be 1
<<<< enter the generator: 10011
FRAME after appending 0's:
00001100011010000 The REMAINDER is: 0101
Transmitting FRAME......
Transmitted FRAME is: 00001100011010101 frame received
checking for errors......
received frame is:
00001100011010101the remainder is:
0000
DATA SENT SUCCESSFULLY

25
EXPERIMENT-6
AIM: Write a program to implement Sliding window protocol for Goback N.

PROGRAM:

#include<stdio.h>
int main()
{
int windowsize,sent=0,ack,i;
printf("enter window size\n");
scanf("%d",&windowsize);
while(1)
{
for(i=0;i<windowsize;i++)
{
printf("Frame %d has been transmitted.\n",sent);
sent++;
if(sent==windowsize)
break;
}
printf("\nPlease enter the last Acknowledgement received.\n");
scanf("%d",&ack);
if(ack==windowsize)
break;
else
sent=ack;
}
return 0;
}

OUTPUT:
enter window size
8
Frame 0 has been transmitted.
Frame 1 has been transmitted.
Frame 2 has been transmitted.
Frame 3 has been transmitted.
Frame 4 has been transmitted.
Frame 5 has been transmitted.
Frame 6 has been transmitted.
Frame 7 has been transmitted.
Please enter the last Acknowledgement received.
2
Frame 2 has been transmitted.
Frame 3 has been transmitted.
Frame 4 has been transmitted.
Frame 5 has been transmitted.
26
Frame 6 has been transmitted.
Frame 7 has been transmitted.
Please enter the last Acknowledgement received. 8

27
EXPERIMENT-7
AIM: Write a program to implement Sliding window protocol for Selective repeat.

PROGRAM:

#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");
printf("After sending %d frames at each stage sender waits for acknowledgement sent by the receiver\n\n",w);
for(i=1;i<=f;i++)
{
if(i%w==0)
{
printf("%d\n",frames[i]);
printf("Acknowledgement of above frames sent is received by sender\n\n");
}
else
printf("%d",frames[i]);
}
if(f%w!=0)
printf("\nAcknowledgement of above frames sent is received by sender\n");
return 0;
}

OUTPUT:

Enter window size:4


Enter number of frames to transmit:5
Enter 5 frames:6
4
8
9
2
With sliding window protocol the frames will be sent in the following manner(assuming no corruption of frames)
After sending 4 frames at each stage sender waits for acknowledgement sent by the receiver
6489
Acknowledgement of above frames sent is received by sender
2
Acknowledgement of above frames sent is received by sender

28
EXPERIMENT-8
AIM: Write a Program to implement Stop and Wait Protocol.

PROGRAM:

#include<stdio.h>
#include<stdbool.h>
#include<string.h>
bool valid(char f[8])
{
int c=0;
for(int i=0;i<8;i++){
if(f[i]=='0' || f[i]=='1')
c++;
}
if(c==8)
return true;
else
return false;
}
int main()
{
int s;
int fcount1=0,fcount2=0,fcount3=0,fcount4=0;
printf("1:ERROR FREE CHANNEL\n2:FRAME WITH ERROR\n3:ACK IS LOST\n4:FRAME IS LOST\n");
printf("Enter the choice:");
scanf("%d",&s);
switch(s)
{
case 1:
for(int i=1;i<=4;i++){
char f[8];
printf("Enter the value of frame %d:",i);
scanf("%s",f);
printf("ack%d, frame %d is received\n",i,i);
fcount1++;
}
if(fcount1==4)
printf("\nAll frames received successfully");
break;
case 2:
for(int i=1;i<=4;i++){
int e=0;
while(e!=1){
char f[8];

29
printf("Enter the value of frame %d:",i);
scanf("%s",f);
if(valid(f)){
printf("ack%d, frame %d is received
\n",i,i);
e=1;
fcount2++;
}
else{
printf("Nack%d-frame %d is in error\n",i,i);
printf("re-enter the value of frame%d\n",i);
e=0;
}
}
}
if(fcount2==4)
printf("\nAll frames received successfully");
break;
case 3:
for(int i=1;i<=4;i++){
int e=0;
while(e!=1){
char f[8];
printf("Enter the value of frame %d:",i);
scanf("%s",f);
if(i<=3){
if(valid(f)){
printf("ack%d, frame %d is received\n",i,i);
e=1;
fcount3++;
}
else{
printf("Error in the received frame\n");
e=0;
}
}
else{
printf("Ack lost...\n");
printf("Re-enter the frame 4:");
scanf("%s",f);
printf("ack%d, frame %d is received\n",i,i);
fcount3++;
e=1;
}
}
}

30
if(fcount3==4)
printf("\nAll frames received successfully");
break;
case 4:
for(int i=1;i<=4;i++){
int e=0;
while(e!=1){
char f[8]={0};
printf("Enter the value of frame %d:",i);
scanf("%s",f);
if(strlen(f)<=1){
printf("Frame %d is missing\n",i);
printf("Re-Enter the Frame\n");
continue;
}
if(valid(f)){
printf("ack%d, frame %d is received\n",i,i);
e=1;
fcount4++;
}
else{
printf("Error in the received frame\n");
e=0;
}
}
}
if(fcount4==4)
printf("\nAll frames received successfully");
break;
default:
printf("Invalid Choice");
}
}

OUTPUT:

1:ERROR FREE CHANNEL


2:FRAME WITH ERROR
3:ACK IS LOST
4:FRAME IS LOST
Enter the choice:1
Enter the value of frame 1:10101010
ack1, frame 1 is received
Enter the value of frame 2:11001100
ack2, frame 2 is received
Enter the value of frame 3:11100010

31
ack3, frame 3 is received
Enter the value of frame 4:11110000
ack4, frame 4 is received
All frames received successfully

32
EXPERIMENT-8
AIM: Write a program for congestion control using leaky bucket algorithm.

PROGRAM:

#include<stdio.h>
#include<stdlib.h>
int rand_num(int a)
{
int rn=(rand()%10)%a;
return rn==0?1:rn;
}
int main()
{
int packet_sz[5],i,clk,b_size,o_rate,p_sz_rm=0,p_sz,p_time;
for(i=0;i<5;++i)
packet_sz[i]=rand_num(6)*10;
for(i=0;i<5;++i)
printf("packet[%d]:%d bytes\t",i,packet_sz[i]);
printf("\nEnter the Output rate:");
scanf("%d",&o_rate);
printf("Enter the Bucket Size:");
scanf("%d",&b_size);
for(i=0; i<5; ++i)
{
if((packet_sz[i]+p_sz_rm)>b_size)
{
if(packet_sz[i] > b_size)
printf("\n\nIncomming packet size (%d) is Greater than bucket capacity-PACKET REJECTED",packet_sz[i]);
}
else
{
p_sz_rm+=packet_sz[i];
printf("\n\nIncoming Packet size: %d",packet_sz[i]);
printf("\nBytes remaining to Transmit:%d",p_sz_rm);
p_time = rand_num(4)*10;
printf("\nTime left for transmission: %d units",p_time);
for(clk=10; clk<=p_time; clk+=10)
{
sleep(1);
if(p_sz_rm)
{
if(p_sz_rm <= o_rate)
{
printf("\n Packet of size %dTransmitted",p_sz_rm);

33
p_sz_rm=0;
}
else
{
p_sz_rm-=o_rate;
}
printf("\n Packet of size %d Transmitted",o_rate);
printf(" Bytes Remaining after Transmission: %d",p_sz_rm);
}
else
{
printf("\n No packets to transmit!!");
printf(" Time Left:%d",p_time-clk);
}
}
}
}
}

OUTPUT:
packet[0]:10 bytes packet[1]:10 bytes packet[2]:20 bytes packet[3]:10 bytes packet[4]:10
bytes
Enter the Output rate:20
Enter the Bucket Size:50

Incoming Packet size: 10


Bytes remaining to Transmit:10
Time left for transmission: 30 units
Packet of size 10Transmitted
Packet of size 20 Transmitted Bytes Remaining after Transmission: 0
No packets to transmit!! Time Left:10
No packets to transmit!! Time Left:0

Incoming Packet size: 10


Bytes remaining to Transmit:10
Time left for transmission: 10 units
Packet of size 10Transmitted
Packet of size 20 Transmitted Bytes Remaining after Transmission: 0

Incoming Packet size: 20


Bytes remaining to Transmit:20
Time left for transmission: 10 units
Packet of size 20Transmitted
Packet of size 20 Transmitted Bytes Remaining after Transmission: 0

Incoming Packet size: 10

34
Bytes remaining to Transmit:10
Time left for transmission: 10 units
Packet of size 10Transmitted
Packet of size 20 Transmitted Bytes Remaining after Transmission: 0

Incoming Packet size: 10


Bytes remaining to Transmit:10
Time left for transmission: 10 units
Packet of size 10Transmitted
Packet of size 20 Transmitted Bytes Remaining after Transmission: 0
No packets to transmit!! Time Left:0

35
EXPERIMENT-10
AIM: Write a Program to implement Dijkstra‘s algorithm to compute the Shortest path through a graph.

PROGRAM:

#include<stdio.h>
int main()
{
int n,AB,BC,CD,BE,EF,FH,AG,GH,HD,EG,P1,P2;
printf("Enter the number of nodes in subnet:");
scanf("%d",&n);
printf("Computation of shortest path connecting node A & node D is as follows\n");
printf("Enter the distance between Node A and Node B:");
scanf("%d",&AB);
printf("Enter the distance between Node B and Node C:");
scanf("%d",&BC);
printf("Enter the distance between Node C and Node D:");
scanf("%d",&CD);
printf("Enter the distance between Node B and Node E:");
scanf("%d",&BE);
printf("Enter the distance between Node E and Node F:");
scanf("%d",&EF);
printf("Enter the distance between Node F and Node H:");
scanf("%d",&FH);
printf("Enter the distance between Node A and Node G:");
scanf("%d",&AG);
printf("Enter the distance between Node G and Node H:");
scanf("%d",&GH);
printf("Enter the distance between Node H and Node D:");
scanf("%d",&HD);
printf("Enter the distance between Node E and Node G:");
scanf("%d",&EG);
printf("Computation of path from node A to node D is path P1 or path P2\n");
printf("Path P1:(A->B)+(B->E)+(E->G)+(G->H)+(H->D) \n");
P1=AB+BE+EG+GH+HD;
printf("Path P1= %d\n",P1);
printf("Path P2:(A->B)+(B->E)+(E->F)+(F->H)+(H->D) \n");
P2=AB+BE+EF+FH+HD;
printf("Path P2= %d\n",P2);
if(P1<P2)
printf("Path connecting node A and node D is P1=%d",P1);
else
printf("Path connecting node A and node D is P2=%d",P2);
return 0;
}
36
OUTPUT:

Enter the number of nodes in subnet:7


Computation of shortest path connecting node A & node D is as follows
Enter the distance between Node A and Node B:4
Enter the distance between Node B and Node C:2
Enter the distance between Node C and Node D:6
Enter the distance between Node B and Node E:3
Enter the distance between Node E and Node F:5
Enter the distance between Node F and Node H:3
Enter the distance between Node A and Node G:2
Enter the distance between Node G and Node H:1
Enter the distance between Node H and Node D:4
Enter the distance between Node E and Node G:6
Computation of path from node A to node D is path P1 or path P2
Path P1:(A->B)+(B->E)+(E->G)+(G->H)+(H->D)
Path P1= 18
Path P2:(A->B)+(B->E)+(E->F)+(F->H)+(H->D)
Path P2= 19
Path connecting node A and node D is P1=18

37
EXPERIMENT-11
AIM: Write a Program to implement Distance vector routing algorithm by obtaining routing table at each node
(Take an example subnet graph with weights indicating delay between nodes).

PROGRAM:

#include<stdio.h>
int main()
{
int n,P[4],JH,HG,JK,KG,JA,AG,JI,IG,value=P[1],index=1,i;
printf("Enter the number of nods in subnet:");
scanf("%d",&n);
printf("Computation of shortest path from node J to node G applying Distance Vector Routing Algorithm\n");
printf("Possible paths connecting node J & node G are P1/P2/P3/P4\n");
printf("Path P1: JH + HG\n");
printf("Enter the values of JH & HG:");
scanf("%d %d",&JH,&HG);
P[1]=JH+HG;
printf("Path P1= %d\n",P[1]);
printf("Path P2: JK + KG\n");
printf("Enter the values of JK & KG:");
scanf("%d %d",&JK,&KG);
P[2]=JK+KG;
printf("Path P2= %d\n",P[2]);
printf("Path P3: JA + AG\n");
printf("Enter the values of JA & AG:");
scanf("%d %d",&JA,&AG);
P[3]=JA+AG;
printf("Path P3= %d\n",P[3]);
printf("Path P4: JI + IG\n");
printf("Enter the values of JI & IG:");
scanf("%d %d",&JI,&IG);
P[4]=JI+IG;
printf("Path P4= %d\n",P[4]);
//SORTING
for(i=1;i<=4;i++){
if(P[i]<value){
value=P[i];
index=i;
}
}
printf("The shortest path connecting Node J & Node G is:P%d = %d",index,P[index]);
return 0;
}
OUTPUT:
38
Enter the number of nods in subnet:10
Computation of shortest path from node J to node G applying Distance Vector Routing Algorithm
Possible paths connecting node J & node G are P1/P2/P3/P4
Path P1: JH + HG
Enter the values of JH & HG:12 6
Path P1= 18
Path P2: JK + KG
Enter the values of JK & KG:7 4
Path P2= 11
Path P3: JA + AG
Enter the values of JA & AG:3 9
Path P3= 12
Path P4: JI + IG
Enter the values of JI & IG:2 5
Path P4= 7
The shortest path connecting Node J & Node G is:P1 = 18

39
EXPERIMENT-12
AIM: Write a Program to implement Broadcast tree by taking subnet of hosts.

PROGRAM:

#include<stdio.h>
#include<stdlib.h>
void main()
{
unsigned int compad[4];
unsigned int mask[4];
unsigned int netadr[4];
int i;
clrscr();
printf("Enter the ip address:\n");
scanf("%u%*c%u%*c%u%*c%u%*c",&compad[3],&compad[2],&compad[1],&compad[0]);
printf("Enter the subnet address:\n");
scanf("%u%*c%u%*c%u%*c%u%*c",&mask[3],&mask[2],&mask[1],&mask[0]);
for(i=0;i<4;i++)
{
netadr[i]= compad[i]&mask[i];
}
printf("\nNetwork address is:\n");
printf("%u.%u.%u.%u",netadr[3],netadr[2],netadr[1],netadr[0]);
printf("\nsubnet address is:\n");
printf("%u.%u.%u.%u",mask[3],mask[2],mask[1],mask[0]);
printf("\nip address is:\n");
printf("%u.%u.%u.%u",compad[3],compad[2],compad[1],compad[0]);
getch();
}

OUTPUT:

Enter the ip address:


165.765.2.57
Enter the subnet address:
255.654.345.0
Network address is:
165.652.0.0
subnet address is:
255.654.345.0
ip address is:
165.765.2.57

40

You might also like