BCS653 Computer Networks Lab Files
BCS653 Computer Networks Lab Files
10. Study of Network Simulator (NS) and Simulation of Congestion Control Algorithms using
NS.
1. Implementation of Stop and Wait Protocol in C.
#include<stdio.h>
int sender();
int recv();
int timer=0,wait_for_ack=-1,frameQ=0,cansend=1,t=0;
main()
{
int i,j;
int frame[5];
if(i==frame[t])
{
frameQ++;
t++;
}
if(frameQ==0)
printf("NO FRAME TO SEND at time=%d \n",i);
if(frameQ>0 && cansend==1)
{
printf("FRAME SEND AT TIME=%d\n",i);
cansend=-1;
frameQ--;
timer++;
printf("timer in sender=%d\n",timer);
}
if(frameQ>0 && cansend==-1)
printf("FRAME IN Q FOR TRANSMISSION AT
TIME=%d\n",i);
if(frameQ>0)
t++;
}
printf("frameQ=%d\n",frameQ);
printf("i=%d t=%d\n",i,t);
printf("value in frame=%d\n",frame[t]);
return 0;
}
int recv(int i )
{ printf("timer in recvr=%d\n",timer);
if(timer>0)
{
timer++;
}
if(timer==3)
{
printf("FRAME ARRIVED AT TIME= %d\n",i);
wait_for_ack=0;
timer=0;
}
else
printf("WAITING FOR FRAME AT TIME %d\n",i);
return 0;
}
}
2. Implementation of Sliding Window Protocol.
#include<stdio.h>
int main()
{
int w,i,f,frames[50];
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;
}
3. Study of Socket Programming and Client – Server model
AIM: To conduct an experiment to demonstrate the working of file transfer with the UDP Server
and Client.
APPARATUS REQUIRED: PC with network simulation software. The Network Interface Card
must be provided with an IP Address.
PROCEDURE: In main window, enter Cd network ,Cd layer, Cd Phy_Lyr , ./main Choose
Layers - Transport Layer - Socket - UDP. After choosing UDP protocol, Click on “Let’s Begin”
button on both the systems. To start the server, click on the Server Socket. Click on the Bind
button, which will bind the socket. To start the Client, first enter the IP Address of a machine
where the server is listening. Enter the file name as a request as shown in Screen. Click on
socket to initiate the client socket. Click on the bind option. Click on the Send To button to
write the request. Click on the RecvFrom button, which will be highlighted upon receiving a
request in server system. Click on the Send To button to write the file contents in the server
system. Click on RecvFrom button in the client system to read the contents of the file.
Observe the text for the output of the file as shown in Screen.
RESULT: Thus the working of Client – Server Model concept was understood and output was
verified.
4. Write a code simulating ARP protocols.
arpserver.c
#include<stdio.h>
#include<sys/types.h>
#include<sys/shm.h>
#include<string.h>
main()
{
int shmid,a,i;
char *ptr,*shmptr;
shmid=shmget(3000,10,IPC_CREAT|0666);
shmptr=shmat(shmid,NULL,0);
ptr=shmptr;
for(i=0;i<3;i++)
{
puts("Enter the name:");
scanf("%s",ptr);
a=strlen(ptr);
printf("String length:%d",a);
ptr[a]=' ';
puts("Enter ip:");
ptr=ptr+a+1;
scanf("%s",ptr);
ptr[a]='\n';
ptr=ptr+a+1;
}
ptr[strlen(ptr)]='\0';
printf("\nARP table at serverside is=\n%s",shmptr);
shmdt(shmptr);
}
arpclient.c
#include<stdio.h>
#include<string.h>
#include<sys/types.h>
#include<sys/shm.h>
main()
{
int shmid,a;
char *ptr,*shmptr;
char ptr2[51],ip[12],mac[26];
shmid=shmget(3000,10,0666);
shmptr=shmat(shmid,NULL,0);
puts("The ARPtable is:");
printf("%s",shmptr);
printf("\n1.ARP\n2.RARP\n3.EXIT\n");
scanf("%d",&a);
switch(a)
{
case 1:
puts("Enter ip address:");
scanf("%s",ip);
ptr=strstr(shmptr,ip);
ptr-=8;
sscanf(ptr,"%s%*s",ptr2);
printf("mac addr is:%s",ptr2);
break;
case 2:
puts("Enter mac addr");
scanf("%s",mac);
ptr=strstr(shmptr,mac);
sscanf(ptr,"%*s%s",ptr2);
printf("%s",ptr2);
break;
case 3:
exit(1);
}
}
5. Running and using services/commands like ping, trace route, nslookup, arp, telnet, ftp,
etc.
All commands related to Network configuration which includes how to switch to privilege mode
and normal mode and how to configure router interface and how to save this configuration to
flash memory or permanent memory.
Traceroute:
Tracert is a command which can show you the path a packet of information takes from your
computer to one you specify. It will list all the routers it passes through until it reaches its
destination, or fails to and is discarded. In addition to this, it will tell you how long each 'hop'
from router to router takes.
nslookup:
pathping:
A better version of tracert that gives you statics about packet lost and latency.
Route:
In IP networks, routing tables are used to direct packets from one subnet to another.
The Route command provides the device’s routing tables. To get this result, just type
route print. The Route command returns the routing table, and the user can make
changes by Commands such as Route Add, Route Delete, and Route Change, which
allows modifying the routing table as a requirement.
ARP:
ARP stands for Address Resolution Protocol. Although network communications can
readily be thought of as an IP address, the packet delivery depends ultimately on the
media access control (MAC). This is where the protocol for address resolution comes
into effect. You can add the remote host IP address, which is an arp -a command, in
case you have issues to communicate with a given host. The ARP command provides
information like Address, Flags, Mask, IFace, Hardware Type, Hardware Address, etc.
Hostname
To communicate with each and other, the computer needs a unique address. A
hostname can be alphabetic or alphanumeric and contain specific symbols used
specifically to define a specific node or device in the network. For example, a hostname
should have a domain name (TLD) of the top-level and a distance between one and 63
characters when used in a domain name system (DNS) or on the Internet.
Steps to Determine Your Computer’s Name
Aim: Study of different types of Network cables and Practically implement the
cross-wiredcable and straight through cable using clamping tool.
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 timefor 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.
2. 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 (layer 1) 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.
a. Classification of IP address
b. Sub netting
c. Super netting
Apparatus (Software): NA
d. Classification of IP address
As show in figure we teach how the ip addresses are classified and when they are used.
e. Sub netting
Why we Develop sub netting and How to calculate subnet mask and how to identify subnet
address.
f. Super netting
Why we develop super netting and How to calculate supernet mask and how to
identify supernetaddress.
9. Connect the computers in Local Area Network.
On the host computer, follow these steps to share the Internet connection:
Click Properties.
6. Click the Advanced tab.
7. Under Internet Connection Sharing, select the Allow other network users to
connectthrough this computer's Internet connection check box.
8. If you are sharing a dial-up Internet connection, select the Establish a dial-up
connectionwhenever 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.
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?
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
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
followingitems list, and then click Properties.
Note: You can also assign a unique static IP address in the range of 192.168.0.2 to
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.
In Congestion-control, end systems throttle back in order to avoid congesting the network.
The mechanism is similar to end-to-end flow controls, but the intention is to reduce
congestion in the network, not the receiver.
Open Loop Technique and closed Loop Technique are utilized in ns-2 program for congestion control.
Open loop
o Acknowledgement policy.
o Retransmission policy.
o Discarding policy.
o Window policy.
o Admission policy.
Closed loop
o Explicit feedback.
o Back pressure.
o Implicit feedback.
o Choke packet.
Architecture-for-control-congestion
Sample NS2 program for Congestion control
include <wifi_lte/wifi_lte_rtable.h>
int num_later = 1;
elm = STAILQ_FIRST(&r_hist_);
num_later;
if (elm != NULL){
elm = findDataPacketInRecvHistory(STAILQ_NEXT(elm,linfo_));
if (elm != NULL){
while(elm2 != NULL){
STAILQ_REMOVE(&r_hist_,elm2,r_hist_entry,linfo_);
delete elm2;
} else
elm = elm2;
} }
}}
void DCCPTFRCAgent::removeAcksRecvHistory(){
int num_later = 1;
if(elm1 == NULL)
return;
while(elm2 != NULL){
if (elm2->type_ == DCCP_ACK){
STAILQ_REMOVE(&r_hist_,elm2,r_hist_entry,linfo_);
delete elm2;
} else {
elm1 = elm2;
start = STAILQ_NEXT(start,linfo_);
return start;