CN LAB Manual
CN LAB Manual
CN LAB Manual
Computer Networks
Laboratory Manual
1. Analyze VLAN communication using CPT
a) Sketch and Simulate three VLANS
b) Setup an extended VLAN using Trunk Interface
c) Inter VLAN Routing
------------------------------------------------------------------------------------------------
a) Sketch and Simulate three VLANS
VLANs (Virtual LANs) are logical grouping of devices in the same broadcast domain.
VLANs are usually configured on switches by placing some interfaces into one broadcast
domain and some interfaces into another. VLANs can be spread across multiple switches, with
each VLAN being treated as its own subnet or broadcast domain. This means that frames
broadcasted onto the network will be switched only between the ports within the same VLAN.
A VLAN acts like a physical LAN, but it allows hosts to be grouped together in the same
broadcast domain even if they are not connected to the same switch. Here are the main reasons
why you should use VLANs in your network:
Divides one single Broadcast domain into Multiple Broadcast domains.
VLANs increase the number of broadcast domains while decreasing their
size.
▪ VLANs reduce security risks by reducing the number of hosts that receive
▪ copies of frames that the switches flood (Layer 2 security)
▪ you can keep hosts that hold sensitive data on a separate VLAN to improve
security.
▪ Vlan 1 is the default VLAN
▪ We can create VLANS from 2 two 1001
▪ Can be configured on a manageable switches only
Switch>enable
Switch#config t
Switch#config terminal
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#vlan 10
Switch(config-vlan)#name green
Switch(config-vlan)#exit
Switch(config)#vlan 20
Switch(config-vlan)#name Red
Switch(config-vlan)#exit
Switch(config)#vlan 30
Switch(config-vlan)#name blue
Switch(config-vlan)#end
Assign port –VLAN
Switch(config)# interfecae (interfece type> <interface no)
Switch(config-if)#switchport mode access
Switch(config-if)# switchport access vlan <No>
Blue vlan
Switch(config)#interface range f0/7-8
Switch(config-if-range)#switchport mode access
Switch(config-if-range)#switchport access vlan 30
Switch(config-if-range)#
Green Vlan(10)
Switch(config)#interface range f0/1-4,f0/9,f0/12
Switch(config-if-range)#switchport mode access
Switch(config-if-range)#switchport access
Switch(config-if-range)#switchport access vlan 10
Switch(config-if-range)#
1b) Set up an extended VLAN using TRUNK interface
TRUNKING
● A trunk interface is an interface that is connected to another switch. This type of
interface can carry traffic of multiple VLANs.
● A singele VLAN can span over Multiple Switches.
● User of the same VLAN-may connect on two or more switches in the LAN . ●
Passing the same Vlan Traffic between switches using single link
FRAME TAGGING
● In order to make sures that same Vlan Uses on different switches
communicate with each other there is a method of tagging happen on trunk
links.
● Tag is added before a frame is send and removed once it is on trunk link.
● Frame includes source and Destination MAC entries
● Tag Includes the Vlan-ID
Trunk Configuration
Switch(config)#interface<interface type><interface no>
Switch(config-if)#switchport mode trunk
Switch(config-if)#switchport trunk encapsulation dotq
Spanning tree protocol is a layer 2 network protocol used to prevent looping within a network
topology. STP was created to avoid the problems that arises when computers compete for
the ability to use the shared telecommunications path on local area network(LAN).when too
many computers try to send at the same time overall network performance is affected and can
bring all traffic to a near halt.
STP prevents the condition known as bridge looping.It uses the spanning tree algorithm to
find the shortest path between source and destination end devices.
Configuration
3. Setup a Router based wide area network using Dynamic routing (RIP, EIGRP, OSPF).
a) Set up a network of 3 and 4 routers. Configure routing in each router and test the network.
Scenareo #1
b) Create 4 equal sized subnets in the subnet N1 and test the network.
Common principles of configuration
a) Plan Subnet ID
b) Decide the IP addresses for each Subnet
c) Configure IP addresses ( along with the subnet mask ) for the end PCs
d) Configure IP address of the Gateway in every PC
e) Configure IP addresses for the Router interfaces
• First DNS server enter the IP address of the next DNS server
• Second DNS server, enter the Name and IP address of the Web server
Scenario #3 : A client and a hierarchy of DNS servers and a Web Server
Set up and test a DHCP enabled LAN with 10 nodes . Use subnet ID 1.1.1.0/24.
b) Set up 2 different DHCP pools in the same subnet. Restrict the access to some of the nodes.
c) Set up a subnet N1 with subnet ID 10.0.0.0/8. Set up another subnet N2 with subnet ID
10.0.0.0/8. Connect these two subnets using a public network using NAT.
PART-B
Q7. A ) Write a C/C++ program to implement the data link layer framing
methods. A) bit stuffing B) Character stuffing.
SOLUTION: #include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int a[20],b[30],i,j,k,count,n;
clrscr();
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]);
getch();
}
Output:
Enter the number of bits: 10
1
0
1
0
1
1
1
1
1
1
Data after stuffing: 10101111101
Q7.B) Write a C/C++ program to implement the data link
layer framing methods. B) Character stuffing
SOLUTION: //program for character stuffing
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<process.h>
void main()
clrscr();
printf("enter string:\n");
scanf("%s",&a);
n=strlen(a);
printf("enter position\n");
scanf("%d",&pos);
if(pos>n)
scanf("%d",&pos);
}
ch=getche();
b[0]='d';
b[1]='l';
b[2]='e';
b[3]='s';
b[4]='t';
b[5]='x';
j=6;
while(i<n)
if(i==pos-1)
b[j]='d';
b[j+1]='l';
b[j+2]='e';
b[j+3]=ch;
b[j+4]='d';
b[j+5]='l';
b[j+6]='e';
j=j+7;
if(a[i]=='d'&&a[i+1]=='l'&& a[i+2]=='e')
b[j]='d';
b[j+1]='l';
b[j+2]='e;
j=j+3;
b[j]=a[i];
i++;
j++;
b[j]='d';
b[j+1]='l';
b[j+2]='e';
b[j+3]='e';
b[j+4]='t';
b[j+5]='x';
b[j+6]='\0';
printf("%s",b);
getch();
#include <time.h>
#include <cstdlib>
#include<ctime>
#include <unistd.h>
using namespace std;
class timer {
private:
unsigned long begTime;
public:
void start() {
begTime = clock();
}
unsigned long elapsedTime() {
return ((unsigned long) clock() - begTime) / CLOCKS_PER_SEC;
}
bool isTimeout(unsigned long seconds) {
return seconds >= elapsedTime();
}
};
int main()
{
int frames[] = {1,2,3,4,5,6,7,8,9,10};
unsigned long seconds = 5;
srand(time(NULL));
timer t;
cout<<"Sender has to send frames : ";
for(int i=0;i<10;i++)
cout<<frames[i]<<" ";
cout<<endl;
int count = 0;
bool delay = false;
cout<<endl<<"Sender\t\t\t\t\tReceiver"<<endl;
do
{
bool timeout = false;
cout<<"Sending Frame : "<<frames[count];
cout.flush();
cout<<"\t\t";
t.start();
if(rand()%2)
{
int to = 24600 + rand()%(64000 - 24600) + 1;
for(int i=0;i<64000;i++)
for(int j=0;j<to;j++) {}
}
if(t.elapsedTime() <= seconds)
{
cout<<"Received Frame : "<<frames[count]<<" ";
if(delay)
{
cout<<"Duplicate";
delay = false;
}
cout<<endl;
count++;
}
else
{
cout<<"---"<<endl;
cout<<"Timeout"<<endl;
timeout = true;
}
t.start();
if(rand()%2 || !timeout)
{
int to = 24600 + rand()%(64000 - 24600) + 1;
for(int i=0;i<64000;i++)
for(int j=0;j<to;j++) {}
if(t.elapsedTime() > seconds )
{
cout<<"Delayed Ack"<<endl;
count--;
delay = true;
}
else if(!timeout)
cout<<"Acknowledgement : "<<frames[count]-1<<endl;
}
}while(count!=10);
return 0;
}
OUTPUT
Sender has to send frames : 1 2 3 4 5 6 7 8 9 10
Sender Receiver
Sending Frame : 1 Received Frame : 1
Acknowledgement : 1
Sending Frame : 2 ---
Timeout
Sending Frame : 2 Received Frame : 2
Acknowledgement : 2
Sending Frame : 3 Received Frame : 3
Acknowledgement : 3
Sending Frame : 4 Received Frame : 4
Acknowledgement : 4
Sending Frame : 5 Received Frame : 5
Acknowledgement : 5
Sending Frame : 6 Received Frame : 6
Acknowledgement : 6
Sending Frame : 7 Received Frame : 7
Delayed Ack
Sending Frame : 7 Received Frame : 7 Duplicate
Delayed Ack
Sending Frame : 7 ---
Timeout
Sending Frame : 7 Received Frame : 7 Duplicate
Acknowledgement : 7
Sending Frame : 8 ---
Timeout
Delayed Ack
Sending Frame : 7 Received Frame : 7
Acknowledgement : 7
Sending Frame : 8 Received Frame : 8
Acknowledgement : 8
Sending Frame : 9 Received Frame : 9
Delayed Ack
Sending Frame : 9 ---
Timeout
Sending Frame : 9 Received Frame : 9 Duplicate
Delayed Ack
Sending Frame : 9 Received Frame : 9 Duplicate
Acknowledgement : 9
Sending Frame : 10 ---
Timeout
Sending Frame : 10 Received Frame : 10
Acknowledgement : 10
10. Write a C/++ Program for ERROR detecting code using CRC-CCITT (16bit).
SOLUTION: #include<stdio.h>
#include<conio.h>
int main(void)
{
int data[50],div[16],rem[16];
int datalen, divlen, i,j,k;
int ch;
clrscr();
printf("Enter the data: ");
i = 0;
while((ch = fgetc(stdin)) != '\n')
{
if(ch == '1')
data[i] = 1;
else
data[i] = 0;
i++;
}
datalen = i;
printf("\nEnter the divisor: ");
i = 0;
while((ch = fgetc(stdin)) != '\n')
{
if(ch == '1')
div[i] = 1;
else
div[i] = 0;
i++;
}
divlen = i;
for(i = datalen ; i < datalen + divlen - 1 ; i++)
data[i] = 0;
datalen = datalen + divlen - 1;
for(i = 0 ; i < divlen ; i++)
rem[i] = data[i]; k = divlen-1;
while(k < datalen)
if(rem[0] == 1)
{
for(i = 0 ; i < divlen ; i++)
rem[i] = rem[i] ^ div[i];
}
Else
{
if(k == datalen-1)
break;
for(i = 0 ; i < divlen-1 ; i++)
{
rem[i] = rem[i+1];
printf("%d",rem[i]);
}
rem[i] = data[++k];
printf("%d\n",rem[i]);
}
j=1;
for(i = datalen - divlen + 1 ; i < datalen ; i++)
{
data[i] = rem[j++];
}
printf("\nThe data to be sent is\n");
for(i = 0 ; i < datalen ; i++)
printf("%d",data[i]);
getch();
return 0;
}
OUTPUT: Enter the data: 10101111
Enter the divisor: 1011
0011
0111
1111
1001
0100
1000
0110
The data to be sent is 10101111110
Q5) Write a C/C++ Program for Congestion control using Leaky Bucket Algorithm..
SOLUTION : #include<stdio.h>
#include<stdlib.h>
#include<unistd.h
>
#define NOF_PACKETS 10
int rand(int a)
{
int rn = (random() % 10) % a;
return rn == 0 ? 1 : rn;
}
int main()
{
int packet_sz[NOF_PACKETS], i, clk, b_size, o_rate, p_sz_rm=0, p_sz, p_time, op;
for(i = 0; i<NOF_PACKETS; ++i)
packet_sz[i] = rand(6) * 10;
for(i = 0; i<NOF_PACKETS; ++i)
printf("\npacket[%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<NOF_PACKETS; ++i)
{
if( (packet_sz[i] + p_sz_rm) > b_size)
if(packet_sz[i] > b_size)/*compare the packet siz with bucket size*/
printf("\n\nIncoming packet size (%dbytes) is Greater than bucket capacity
(%dbytes)-PACKET REJECTED", packet_sz[i], b_size);
else
printf("\n\nBucket capacity exceeded-PACKETS REJECTED!!");
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(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)/*packet size remaining comparing with output rate*/
op = p_sz_rm, p_sz_rm = 0;
else
op = o_rate, p_sz_rm -= o_rate;
printf("\nPacket of size %d Transmitted", op);
printf("----Bytes Remaining to Transmit: %d", p_sz_rm);
}
else
{
printf("\nTime left for transmission: %d units", p_time-clk);
printf("\nNo packets to transmit!!");
}
}
}
}
}
// Driver code
int main() {
int sockfd;
char buffer[MAXLINE];
char *hello = "Hello from server";
struct sockaddr_in servaddr, cliaddr;
memset(&servaddr, 0, sizeof(servaddr));
memset(&cliaddr, 0, sizeof(cliaddr));
int len, n;
return 0;
}
// CLIENT SIDE CODE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
// Driver code
int main() {
int sockfd;
char buffer[MAXLINE];
char *hello = "Hello from client";
struct sockaddr_in servaddr;
memset(&servaddr, 0, sizeof(servaddr));
int n, len;
close(sockfd);
return 0;
}
Output :
$ ./server
Client : Hello from client
Hello message sent.
$ ./client
Hello message sent.
Server : Hello from server