JNTUA Computer Networks Lab Manual R20
JNTUA Computer Networks Lab Manual R20
me/jntua
LAB Manual
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
SUBJECT NAME: Computer Network LAB
BRANCH: CSE
COURSE: B.TECH
REGULATION: R20
EXP NO: 1
To Study different types of Network cables
Date:
AIM: To Study different types of Network cables (Copper and Fiber) and prepare cables
(Straight and Cross) to connect Two or more systems. Use crimping tool to connect jacks. Use
LAN tester to connect the cables.
Hardware Requirement
RJ-45 connector,
Climping Tool,
Twisted pair Cable
Software Requirement
Command Prompt and Packet Tracer.
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.
Output:
1. Remove the outmost vinyl shield for 12mm at one end of the cable (we call this side A-side).
2. Arrange the metal wires in parallel
3. Insert the metal wires into RJ45 connector on keeping the metal wire arrangement.
4. Set the RJ45 connector (with the cable) on the pliers, and squeeze it tightly.
5. Make the other side of the cable (we call this side B-side) in the same way.
6. After you made it, you don't need to take care of the direction of the cable.
IO connector crimping: Run the full length of Ethernet cable in place, from endpoint to
endpoint, making sure to leave excess.
At one end, cut the wire to length leaving enough length to work, but not too
much excess. Strip off about 2 inches of the Ethernet cable sheath.
Align each of the colored wires according to the
layout of the jack.Use the punch down tool to insert
each wire into the jack.
Repeat the above steps for the second RJ45 jack.
Step 1 : Skin off the cable jacket 3.0 cm long cable stripper up to cable
Step 2: Untwist each pair and straighten each wire 190 0 1.5 cm long.
Step 3 : Cut all the wires
Step 4 : Insert the wires into the RJ45 connector right white orange left brown the pins facing
up
Step 5 : Place the connector into a crimping tool, and squeeze hard so that the handle
reaches its full swing.
Step 6: Use a cable tester to test for proper continuity
Result:
Cable Crimping, Standard Cabling and Cross Cabling, IO connector crimping and
testing the crimped cable using a cable tester are done successfully
EXP-1(b): To Install and configure Network Devices: HUB, Switch and Routers. Consider both
manageable and non-manageable switches. Do the logical configuration of the system. Set the
bandwidth of different ports.
1. 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, so
that the signal can cover longer distances. Repeater have two ports ,so cannot be use to connect for
more than two devices
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.
3. 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.
4. Bridge: A network bridge connects multiple network segments at the data link layer (Layer 2) of
the OSI model. In Ethernet networks, the term bridge formally means a device that behaves
according to the IEEE 802.1 D standard. 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.
5. 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.
6. Gate Way: 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.
EXP 1(c):
Install and Configure Wired and Wireless NIC and transfer files between systems in Wired
LANand Wireless LAN. Consider both adhoc and infrastructure mode of operation.
Objectives
Part 1: Identify and Work with PC NICs
Part 2: Identify and Use the System Tray Network Icons
Background / Scenario
This lab requires you to determine the availability and status of the network interface cards
(NICs) on the PC that you use. Windows provides a number of ways to view and work with
your NICs.
In this lab, you will access the NIC information of your PC and change the status of these cards.
Required Resources
1 PC (Windows 7 or 8 with two NICs, wired and wireless, and a wireless connection)
Procedure:
Disconnect all cables connected to the computer and open the case. Locate an available
PCI slot (white slots) and insert the network card and secure the card with the screw that
came with it. Once the adapter has been installed and secured close the computer case,
connect all the cables and turn it on.
After installing the adapter driver it should be working find, now let’s configure the card
for use on anetwork.
Click on the Start button and select Settings then
Control Panel.Double click on the System icon
Click on the Hardware tab.
Result:
Installation and configuration of Wired and Wireless (remotely) NIC and transfer files
between systems inLAN and Wireless LAN between two systems in a LAN have been
done successfully.
EXP NO: 2
Networking commands
Date:
AIM: Work with the commands Ping, Tracert, Ipconfig, pathping, telnet, ftp, getmac, ARP,
Hostname, Nbtstat, netdiag, and Nslookup
Procedure:
1. Open Command Prompt, and then type ipconfig. From the display of the ipconfig
command, ensure that the network adapter for the TCP/IP configuration you are testing
is not in a Media disconnected state.
2. At the command prompt, ping the loopback address by typing ping 127.0.0.1.
3. Ping the IP address of the computer.
4. Ping the IP address of the default gateway. If the ping command fails, verify that the
default gateway IP address is correct and that the gateway (router) is operational.
5. Ping the IP address of a remote host (a host that is on a different subnet).
If the ping command fails, verify that the remote host IP address is correct, that the
remote host is operational, and that all of the gateways (routers) between this
computer and the remote host are operational.
6. Ping the IP address of the DNS server.
If the ping command fails, verify that the DNS server IP address is correct that the
DNS server is operational, and that all of the gateways (routers) between this
computer and the DNS server are operational.
Tracer network:
Open Command Prompt, and type the following:
tracert host_name
Or
tracert ip_address
where host_name or ip_address is the host name or IP address, respectively, of the remote
computer.
If you do not want the tracert command to resolve and display the names of all routers in the
path, use the -d parameter. This expedites the display of the path. For example, to trace a
path from this computer towww.microsoft.com without displaying the router names, type the
following at a command prompt:
Net stat utilities to debug the network issues:
Displays active TCP connections, ports on which the computer is listening, Ethernet
statistics, the IP routing table, IPv4 statistics (for the IP, ICMP, TCP, and UDP protocols),
and IPv6 statistics (for the IPv6, ICMPv6, TCP over IPv6, and UDP over IPv6 protocols).
Syntax
netstat [-a] [-e] [-n] [-o] [-p Protocol] [-r] [-s] [Interval]
Parameters
-a
Displays all active TCP connections and the TCP and UDP ports on which the computer is
listening.
-e
Displays Ethernet statistics, such as the number of bytes and packets sent and received
This parameter can be combined with -s.
-n
Displays active TCP connections, however, addresses and port numbers are expressed
numerically and no attempt is made to determine names.
-o
Displays active TCP connections and includes the process ID (PID) for each connection.
You can find the application based on the PID on the Processes tab in Windows Task
Manager. This parameter can be combined with -a, -n, and -p.
-p Protocol
Shows connections for the protocol specified by Protocol. In this case, the Protocol can
be tcp, udp, tcpv6, or udpv6. If this parameter is used with -s to display statistics by
protocol, Protocol can be tcp, udp,icmp, ip, tcpv6, udpv6, icmpv6, or ipv6.
-s
Displays statistics by protocol. By default, statistics are shown for the TCP, UDP, ICMP,
and IP protocols. If the IPv6 protocol for Windows XP is installed, statistics are shown
for the TCP over IPv6, UDP over IPv6, ICMPv6, and IPv6 protocols. The -p parameter
can be used to specify a set of protocols.
-r
Displays the contents of the IP routing table. This is equivalent to the route print command.
Interval
Redisplays the selected information every Interval seconds. Press CTRL+C to stop the
redisplay. If this parameter is omitted, netstat prints the selected information only once.
/? Displays help at the command prompt
Result:
Thus the Configure Internet connection and use IPCONFIG, PING / Tracer and Net stat
utilities to establish interconnection between systems have been done successful
10
EXP NO: 3
Find all the IP addresses on your network
Date:
AIM: To Find all the IP addresses on your network. Unicast, Multicast, and Broadcast on your
network.
Description:
There are two ways to find IP addresses on network systems. You can find them manually or you
can use an IP scanner, which is designed to automatically find the IP addresses within a certain
range.
With a scanner such as SolarWinds IPAM, you can run automated scans to identify new devices
and more easily manage IP addresses.
The basic steps for manually creating a list of device IP addresses on a network include:
Use an IP discovery tool to automatically locate devices and collect critical data
SolarWinds IPAM is built to scan your network for all IP addresses, checks their statuses, and
reports the details. IP Address Manager also uses automated subnet discovery and neighbor
discovery techniques to help identify and accurately manage IP subnets, address blocks, and
connected hosts to present real-time IP address information.
11
Output:
12
EXP NO: 4
Packet tracer software to build network topology
Date:
AIM: To Use Packet tracer software to build network topology and configure using Distance
vector routing protocol.
Description:
It is under dynamic routing algorithm. This algorithm operates by having each route maintains a
table giving the least known distance to reach destination and include line in used to get these.
These are updated by changing information with neighbour. This is called “Bell mann ford
algorithm” and “fod fick” algorithm.
Procedure:
#include<stdlib.h>
#define nul 1000
#define nodes 10
int no;
struct node
{
int a[nodes][4];
}router[nodes];
void init(int r)
{
int i;
for(i=1;i<=no;i++)
{
router[r].a[i][1]=i;
router[r].a[i][2]=999;
router[r].a[i][3]=nul;
}
router[r].a[r][2]=0;
router[r].a[r][3]=r;
13
}
void inp(int r)
{
int i;
printf("\nEnter distance from the node %d to other nodes",r);
printf("\nPls Enter 999 of there is no direct route\n",r);
for(i=1;i<=no;i++)
{
if(i!=r)
{
printf("\nEnter dist to node %d:",i);
scanf("%d",&router[r].a[i][2]);
router[r].a[i][3]=i;
}}}
void display(int r)
{
int i,j;
printf("\n\nThe routing table for node %d is as follows:",r);
for(i=1;i<=no;i++)
{
if(router[r].a[i][2]>=99)
printf("\n\t\t\t%d\tno link\tno hop",router[r].a[i][1]);
else
printf("\n\t\t\t%d\t\t%d",router[r].a[i][1],router[r].a[i][2],router[r].a[i][3]);
}}
void dv_algo(int r)
{
int i,j,z;
for(i=0;i<=no;i++)
{
if(router[r].a[i][2]!=999&&router[r].a[i][2]!=0)
{
for(j=1;j<=no;j++)
{
z=router[r].a[i][2]+router[i].a[j][2];
if(router[r].a[j][2]>z)
{
router[r].a[j][2]=z;
router[r].a[j][3]=i;
}}}}}
14
int main()
{
int i,j,x,y;
char choice;
printf("Enter the no.of nodes required(less than 10 pls):");
scanf("%d",&no);
for(i=1;i<=no;i++)
{
init(i);
inp(i);
}
printf("\nTne configuration of the nodes after initialization is as follows:");
for(i=1;i<=no;i++)
display(i);
for(i=1;i<=no;i++)
dv_algo(i);
printf("\nThe configuration of the nodes after computation of paths is as follows:");
for(i=1;i<=no;i++)
display(i);
while(1)
{
printf("\n\nWanna continue (y/n):");
scanf("%c",&choice);
if(choice=='n')
break;
printf("\nEnter the nodes btn which the shortest path is to be found:\n");
scanf("%d%d",&x,&y);
printf("\nThe length of the shortest path is %d",router[x].a[y][2]);
}}
15
16
Output:
17
EXP NO: 5
Link State routing protocol
Date:
AIM: Use Packet tracer software to build network topology and configure using Link State
routing protocol.
Procedure:
Link state routing works on the following principle.
• Discover the neighbour and keep their network address.
• Measure the delay or cost to each of its neighbour.
• Construct a packet telling all it has just learned.
• Send the packet to all router.
• Compute the shortest path to every router.
Open the Cisco Packet Tracer software.
• Add the router and PCs according to our design.
• Configure all the routers and PCs.
• Trace the destination in PC’s command prompt.
• Verify the output.
#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<string.h>
#include<math.h>
#define IN 99
#define N 6
int dijkstra(int cost[][N],int source,int target);
char
interface[6][6][20]={{"0","0","0","0","0","0"},{"0","0","192.1.1.1","0","200.1.1.1"},{"0","0","0
","0",
"198.1.1.2","0"},{"0","192.1.1.3","0","198.1.1.3","0","200.1.1.2"},{"0","0","200.1.1.3","0","200
.1.1.4
","0"}};
int main()
{
int cost[N][N],i,j,w,ch,co;
char ip[10];
int source,target,x,y;
printf("\t the shortest path algorithm(DIJKSRTRA'S ALGORITHM in c\n\n");
for(i=1;i<N;i++)
18
for(j=1;j<N;j++)
cost[i][j]=IN;
for(x=1;x<N;x++)
{
for(y=x+1;y<N;y++)
{
printf("enter the weight of the path between node%d and %d:",x,y);
scanf("%d",&w);
cost[x][y]=cost[y][x]=w;
}
printf("\n");
}
for(x=1;x<N;x++)
{
for(y=1;y<N;y++)
{
printf("%s:\t",interface[x][y]);
//scanf("%s",&ip);
//interface[x][y][20]=ip;
}
printf("\n");
}
printf("\nEnter the source:");
scanf("%d",&source);
printf("\nEnter the target");
scanf("%d",&target);
co=dijsktra(cost,source,target);
printf("\nThe Shortest Path:%d",co);
return 0;
}
int dijsktra(int cost[][N],int source,int target)
{
int dist[N],prev[N],selected[N]={0},i,m,min,start,d,j,x,y;
char path[N];int path1[N];
for(i=0;i<N;i++)
{
dist[i]=IN;
prev[i]=-1;
}
start=source;
19
selected[start]=1;
dist[start]=0;
while(selected[target]==0)
{
min=IN;
m=0;
for(i=1;i<N;i++)
{
d=dist[start]+cost[start][i];
if(d<dist[i]&&selected[i]==0)
{
dist[i]=d;
prev[i]=start;
}
if(min>dist[i]&&selected[i]==0)
{
min=dist[i];
m=i;
}}
start=m;
selected[start]=1;
}
start=target;
j=0;
while(start!=-1)
{
path[j++]=start+64;
path1[j++]=start;
start=prev[start];
}
path[j]='\0';
strrev(path);
printf("%s",path);
printf("\n");
for(j=j-1;j>=0;j--)
{
printf("%d\t",path1[j]);
if(j>0)
{
x=path1[j];
20
y=path1[j-1];
printf("%s\t%s\n",interface[x][y],interface[y][x]);
}}
return dist[target];
}
21
Output:
22
EXP NO: 6
JAVA RMI Basic Calculator
Date:
RMI called as remote method innovaction, by using rmi to develop calculator program in java
Program:
Calc.java
import java.rmi.Remote;
import java.rmi.RemoteException;
Calcimpl.java
23
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
super();
return a+b;
return a-b;
24
return a*b;
return a/b;
Calcserv.java
import java.rmi.Naming;
CalcServer()
try
Naming.rebind("rmi://localhost:1099/CalculatorService", c);
25
catch (Exception e)
System.out.println("Exception:"+e);
new CalcServer();
CalculatorClient
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.net.MalformedURLException;
import java.rmi.NotBoundException;
try
26
Calc c = (Calc)
Naming.lookup("rmi://localhost/CalculatorService");
System.out.println( c.subtraction(4, 3) );
System.out.println( c.addition(4, 5) );
System.out.println( c.multiplication(3, 6) );
System.out.println( c.divition(9, 3) );
System.out.println();
System.out.println("MalformedURLException");
System.out.println(murle);
System.out.println();
System.out.println("RemoteException");
System.out.println(re);
System.out.println();
27
System.out.println("NotBoundException");
System.out.println(nbe);
catch (java.lang.ArithmeticExceptionae)
System.out.println();
System.out.println("java.lang.ArithmeticException");
System.out.println(ae);
Output:
28
29
EXP NO: 7
Chatting application using JAVA TCP and UDP sockets
Date:
AIM: Implement a Chatting application using JAVA TCP and UDP sockets.
Procedure:
1. In any Client/Server Application, we need to run the server before the client, because the
server keeps waiting for the client to be connected.
2. Server keeps listening for the client on an assigned IP & Port
3. For establishing connection client must know the IP & Port of the server.
4. When we start Client Application, It creates a connection to the server.
5. After the Successful connection Client & Server Applications can send & receive
messages.
Source Code:
charsever.java
import java.net.*;
import java.io.*;
public class chatserver
{
public static void main(String args[]) throws Exception
{
ServerSocket ss=new ServerSocket(2000);
Socket sk=ss.accept();
BufferedReader cin=new BufferedReader(new
InputStreamReader(sk.getInputStream()));
PrintStream cout=new PrintStream(sk.getOutputStream());
BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
String s;
while ( true )
{
s=cin.readLine();
if (s.equalsIgnoreCase("END"))
{
cout.println("BYE");
break;
}
System. out.print("Client : "+s+"\n");
System.out.print("Server : ");
s=stdin.readLine();
30
cout.println(s);
}
ss.close();
sk.close();
cin.close();
cout.close();
stdin.close();
}
}
chatclient.java
import java.net.*;
import java.io.*;
public class chatclient
{
public static void main(String args[]) throws Exception
{
Socket sk=new Socket("127.0.0.1",2000);
BufferedReader sin=new BufferedReader(new
InputStreamReader(sk.getInputStream()));
PrintStream sout=new PrintStream(sk.getOutputStream());
BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
String s;
while ( true )
{
System.out.print("Client : ");
s=stdin.readLine();
sout.println(s);
s=sin.readLine();
System.out.print("Server : "+s+"\n");
if ( s.equalsIgnoreCase("BYE") )
break;
}
sk.close();
sin.close();
sout.close();
stdin.close();
}
}
31
output:
Server:
E:\nwlab>javac *.java
E:\nwlab>java chatserver
Client : hi
Server : hi
Client:
E:\nwlab>java chatclient
Client : hi
Server : hi
Client :
32
EXP NO: 8
Hello and Echo commands using JAVA
Date:
AIM: Hello command is used to know whether the machine at the other end is working or not.
Echo command is used to measure the round trip time to the neighbour. Implement Hello and
Echo commands using JAVA.
Source Code:
import java.util.Scanner;
public class Echo
{
public static void main (String[] args)
{
String inData;
Scanner scan = new Scanner( System.in );
Output:
C:\> javac Echo.java
C:\> java Echo
Enter the data:
This is what the user typed.
You entered: This is what the user typed.
33
EXP NO: 9
Inspect HTTP Traffic
Date:
Wireshark is a software protocol analyzer, or “packet sniffer” application, used for network
troubleshooting, analysis, software and protocol development, and education. As data streams
travel back and forth over the network, the sniffer “captures” each protocol data unit (PDU) and
can decode and analyze its content according to the appropriate RFC or other specifications.
Wireshark is a useful tool for anyone working with networks and can be used with most labs in
the CCNA courses for data analysis and troubleshooting. This lab provides instructions for
downloading and installing Wireshark.
Required Resources
Wireshark has become the industry standard packet-sniffer program used by network engineers.
This open source software is available for many different operating systems, including Windows,
Mac, and Linux. In this lab, you will download and install the Wireshark software program on
your PC.
34
C. Choose the software version you need based on your PC architecture and operating system.
For instance, if you have a 64-bit PC
35
installing the new version. It is recommended that you remove the old version of
Wireshark prior to installing another version. Click Yes to uninstall the previous version
of Wireshark.
c. If this is the first time that you have installed Wireshark, or after you have completed the
uninstall process, you will navigate to the Wireshark Setup wizard. Click Next.
d. Continue advancing through the installation process. Click I Agree when the License
Agreement window displays
36
e. Keep the default settings on the Choose Components window and click Next
37
g. You can change the installation location of Wireshark, but unless you have limited disk
space, it is recommended that you keep the default location.
h. To capture live network data, WinPcap must be installed on your PC. If WinPcap is
already installed on your PC, the Install check box will be unchecked. If your installed
version of WinPcap is older than the version that comes with Wireshark, it is
recommended that you allow the newer version to be installed by clicking the Install
38
39
l. Wireshark starts installing its files, and a separate window displays with the status of the
installation. Click Next when the installation is complete.
40
Result:
41
EXP NO: 10
Network Simulater-2
Date:
AIM: Install Network Simulator 2/3. Create a wired network using dumbbell topology. Attach
agents, generate both FTP and CBR traffic, and transmit the traffic. Vary the data rates and
evaluate the performance using metric throughput, delay, jitter and packet loss.
Description:
Network Simulator (Version 2), widely known as NS2, is simply an event driven simulation tool
that has proved useful in studying the dynamic nature of communication networks. Simulation of
wired as well as wireless network functions and protocols (e.g., routing algorithms, TCP, UDP)
can be done using NS2. In general, NS2 provides users with a way of specifying such network
protocols and simulating their corresponding behaviors. Due to its flexibility and modular nature,
NS2 has gained constant popularity in the networking research community since its birth in
1989. Ever since, several revolutions and revisions have marked the growing maturity of the
tool, thanks to substantial contributions from the players in the field. Among these are the
University of California and Cornell University who developed the REAL network simulator,1
the foundation which NS is based on. Since 1995 the Defense Advanced Research Projects
Agency (DARPA) supported development of NS through the Virtual Inter Network Testbed
(VINT) project . Currently the National Science Foundation (NSF) has joined the ride in
development. Last but not the least, the group of Researchers and developers in the community
are constantly working to keep NS2 strong and versatile.
NS uses two languages because simulator has two different kinds of things it needs to do. On one
hand, detailed simulations of protocols requires a systems programming language which can
efficiently manipulate bytes, packet headers, and implement algorithms that run over large data
sets. For these tasks run-time speed is important and turn-around time (run simulation, find bug,
fix bug, recompile, re-run) is less important. On the other hand, a large part of network research
involves slightly varying parameters or configurations, or quickly exploring a number of
scenarios.
In these cases, iteration time (change the model and re-run) is more important. Since
configuration runs once (at the beginning of the simulation), run-time of this part of the task is
less important. NS meets both of these needs with two languages, C++ and OTcl.
Tcl scripting
42
Basics of TCL
Syntax: command arg1 arg2 arg3
Hello World!
puts stdout{Hello, World!} Hello, World!
NS Simulator Preliminaries.
1. Initialization and termination aspects of the ns simulator.
2. Definition of network nodes, links, queues and topology.
3. Definition of agents and of applications.
4. The nam visualization tool.
5. Tracing and random variables.
Output:
43
EXP NO: 11
Network Simulater-2 FTP & CBR Traffic
Date:
AIM: Create a static wireless network. Attach agents, generate both FTP and CBR traffic, and
transmit the traffic. Vary the data rates and evaluate the performance using metric throughput,
delay, jitter and packet loss.
DESCRIPTION
NS uses two languages because simulator has two different kinds of things it needs to do. On one
hand, detailed simulations of protocols requires a systems programming language which can
efficiently manipulate bytes, packet headers, and implement algorithms that run over large data
sets. For these tasks run-time speed is important and turn-around time (run simulation, find bug,
fix bug, recompile, re-run) is less important. On the other hand, a large part of network research
involves slightly varying parameters or configurations, or quickly exploring a number of
scenarios.
In these cases, iteration time (change the model and re-run) is more important. Since
configuration runs once (at the beginning of the simulation), run-time of this part of the task is
less important. NS meets both of these needs with two languages, C++ and OTcl.
Tcl scripting
In order to have output files with data on the simulation (trace files) or files used for
visualization (nam files), we need to create the files using ―open command:
The above creates a dta trace file called out.tr and a nam visualization trace file called out.
nam.Within the tcl script, these files are not called explicitly by their names, but instead by
pointers that are declared above and called ―tracefile1 and ―namfile respectively. Remark that
44
they begins with a # symbol. The second line open the file ―out.tr to be used for writing,
declared with the letter ―w. The third line uses a simulator method called trace-all that have as
parameter the name of the file where the traces will go.
Proc finish { } {
global ns tracefile1 namfile
$ns flush-trace
Close $tracefile1
Close $namfile
Exec nam out.nam &
Exit 0
}
45
TCP has many parameters with initial fixed defaults values that can be changed if mentioned
explicitly. For example, the default TCP packet size has a size of 1000bytes.This can be
changed to another value, say 552bytes, using the command $tcp set packetSize_ 552.
When we have several flows, we may wish to distinguish them so that we can identify them
with different colors in the visualization part. This is done by the command $tcp set fid_ 1 that
assigns to the TCP connection a flow identification of ―1.We shall later give the flow
identification of ―2‖ to the UDP connection.
Output:
46
EXP NO: 12
Network Simulater-2 FTP & CBR Traffic
Date:
AIM: Create a mobile wireless network. Attach agents, generate both FTP and CBR traffic, and
transmit the traffic. Vary the data rates and evaluate the performance using metric throughput,
delay, jitter and packet loss.
Description:
A wireless sensor network (WSN) consists of a large number of small sensor nodes that are
deployed in the area in which a factor is to be monitored. In wireless sensor network, energy
model is one of the optional attributes of a node. The energy model denotes the level of energy in
a mobile node. The components required for designing energy model includes initialEnergy,
txPower, rxPower, and idlePower. The “initialEnergy” represents the level of energy the node
has at the initial stage of simulation. “txPower” and “rxPower” denotes the energy consumed for
transmitting and receiving the packets. If the node is a sensor, the energy model should include a
special component called “sensePower”. It denotes the energy consumed during the sensing
operation. Apart from these components, it is important to specify the communication range
(RXThresh_) and sensing range of a node (CSThresh_). The sample 18.tcl designs a WSN in
which sensor nodes are configured with different communication and sensing range. Base
Station is configured with highest communication range. Data Transmission is established
between nodes using UDP agent and CBR traffic.
Algorithm:
1. Create a simulator object
2. Define setting options for wireless channel
3. Create trace file and name file
4. Setup topography object and nodes
5. Provide initial location of mobile nodes
6. Setup a UDP connection between nodes
7. Printing the window size
Program:
# Define setting options
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
47
48
49
50
51
proc stop {} {
global ns tracefd namtrace
$ns flush-trace
close $tracefd
close $namtrace
exec nam dsdv.nam &
exit 0
}
$ns run
Expected Output:
52
ADDITIONAL EXPERIMENTS
EXP NO: 13
SIMULATE A MOBILE ADHOC NETWORK
Date:
SOFTWARE REQUIREMENTS:
Network Simulator -2
THEORY:
A mobile ad hoc network or MANET does not depend on a fixed infrastructure for its
networking operation. MANET is an autonomous and short-lived association of group of mobile
nodes that communicate with each other over wireless links. A node can directly communicate to
the nodes that lie within its communication range. If a node wants to communicate with a node
that is not directly within its communication range, it uses intermediate nodes as routers.
ALGORITHM:
PROGRAM:
set val(chan) Channel/WirelessChannel
set val(prop) Propagation/TwoRayGround
set val(netif) Phy/WirelessPhy
set val(mac) Mac/802_11
set val(ifq) Queue/DropTail/PriQueue
set val(ll) LL
set val(ant) Antenna/OmniAntenna
set val(ifqlen) 50
set val(nn) 3
set val(rp) DSDV
set ns [new Simulator]
set tf [open output.tr w]
$ns trace-all $tf
set tf1 [open output.nam w]
53
54
EXPECTED OUTPUT:
55
EXP NO: 14
SIMULATE A MOBILE ADHOC NETWORK
Date:
AIM: To implement a Transport Control Protocol in sensor network through the simulator.
SOFTWARE REQUIREMENTS:
Network Simulator -2
THEORY:
The Transmission Control Protocol (TCP) is one of the main protocols of the Internet protocol
suite. It originated in the initial network implementation in which it complemented the Internet
Protocol (IP). Therefore, the entire suite is commonly referred to as TCP/IP. TCP provides
reliable, ordered, and error-checked delivery of a stream of octets (bytes) between applications
running on hosts communicating by an IP network. Major Internet applications such as the
World Wide Web, email, remote administration, and file transfer rely on TCP. Applications that
do not require reliable data stream service may use the User Datagram Protocol (UDP), which
provides a connectionless datagram service that emphasizes reduced latency over reliability.
ALGORITHM:
PROGRAM:
set ns [new Simulator]
#Define different colors for data flows (for NAM)
$ns color 1 Blue
$ns color 2 Red
#Open the Trace files
set file1 [open out.tr w]
set winfile [open WinFile w]
56
57
Expected Output:
58