Thiru Rec
Thiru Rec
21HC57P-NETWORKS LABORATORY
NAME : SRINIVAS B
REGISTER NO :113022104147
ROLL NO :VH12423
YEAR :2022-2026
SEMESTER :V
BONAFIDE CERTIFICATE
NAME: ........................................................................................................................YEAR: .......................
Certified that this is the bonafide record of work done by the above student in the
Submitted for the University Practical Examination held on at VEL TECH HIGH
TECH Dr. RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE,No.60, AVADI – ALAMATHI ROAD,
AVADI, CHENNAI -600 062.
Signature of Examiners:
MISSION:
1. To impart the attributes of global engineers to face industrial challenges with social
relevance.
2. To indoctrinate as front runners through moral practices.
3. To attain the skills through lifelong learning.
VISION:
To blend academic learning process and innovative ideas producing self-confident graduates
with skills and knowledge to compete in the changing world.
MISSION:
PEO-1:
PEO-2:
PEO- 4:
Be capable of productive employment in the field of Computer Science and Engineering with
competing technical expertise, good interpersonal skill.
PEO-5:
Utilize their broad educational experience, ethics, and professionalism to make a positive
impact on their local and professional communities.
PO1: Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals,
and an engineering specialization to the solution of complex engineering problems.
PO2: Problem analysis: Identify, formulate, research literature, and analyze complex engineering
Problems reaching substantiated conclusions using first principles of mathematics, natural sciences, and
engineering sciences.
PO3: Design/development of solutions: Design solutions for complex engineering problems and design
system components or processes that meet the specified needs with appropriate consideration for the
public health and safety, and the cultural, societal, and environmental considerations.
PO4: Conduct investigations of complex problems: Use research-based knowledge and research
Methods including design of experiments, analysis and interpretation of data, and synthesis of the
Information to provide valid conclusions.
PO5: Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities with an
understanding of the limitations.
PO6: The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to the
professional engineering practice.
PO7: Environment and sustainability: Understand the impact of the professional engineering solutions in
societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable
development.
PO8: Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms
of the engineering practice.
PO9: Individual and team work: Function effectively as an individual, and as a member or leader in
diverse teams, and in multidisciplinary settings.
PO10: Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend and write effective
reports and design documentation, make effective presentations, and give and receive clear instructions.
PO11: Project management and finance: Demonstrate knowledge and understanding of the engineering
and management principles and apply these to one’s own work, as a member and leader in a team, to
manage projects and in multidisciplinary environments.
PO12: Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.
● Applying the current and gained knowledge and modern techniques not only in the
Computers but in all related fields.
COURSE OBJECTIVES:
COURCE OUTCOME:
SOFTWARE:
1. C / C++ / Java / Python / Equivalent Compiler 30Nos
2. Network simulator like NS2/Glomosim/OPNET/ Packet Tracer / Equivalent
JAVA
Java is a high-level programming language originally developed by Sun
Microsystems. Java runs on a variety of platforms, such as Windows, Mac OS, and the
various versions of UNIX. Java programming were "Simple, Robust,
Portable,Platform-independent, Secured, High Performance, Multithreaded,
Architecture Neutral, Object-Oriented, Interpreted, and Dynamic".
NS2
NS2 stands for Network Simulator Version 2. It is an open-source event-driven
simulator designed specifically for research in computer communication networks. It
provides substantial support to simulate bunch of protocols like TCP, FTP, UDP, https
and DSR.It simulates wired and wireless network. It is primarily Unix Based. It uses
TCL as its scripting language.
CS8581.1 3 2 - - - - - - - - -
CS8581.2 3 1 2 - - - - - - - - -
CS8581.3 - 2 - - - - - - -
CS8581.4 2 1 2 - - - - - - - - -
CS8581.5 3 1 1 - 2 - - - - - - -
CS8581 3 1 2 - 2 - - - - - - -
CO-PSO MATRIX
COURSE PSO 3
CS8581.1 2
CS8581.2 3
CS8581.3 3
CS8581.4 3
CS8581.5 2
CS8581 3
Accredited by NBA, New Delhi & Accredited by NAAC with “A” Grade & CGPA of 3.27
COURSE OBJECTIVES:
To learn and use network commands.
To learn socket programming.
To implement and analyze various network protocols.
To learn and use simulation tools.
To use simulation tools to analyze the performance of various network protocols.
PREREQUISITE:
COURSE OUTCOMES:
COURSE OUTCOMES MAPPING WITH PROGRAM OUTCOMES AND PROGRAM SPECIFIC OUTCOMES
CO No. PO-1 PO-2 PO-3 PO-4 PO-5 PO-6 PO-7 PO-8 PO-9 PO-10 PO-11 PO- PSO-1 PSO-2
12
C507.1 3 3 1 - - - - - - - - - 3 2
C507.2 3 2 1 - - - - - - - - - 3 2
C507.3 3 2 1 - - - - - - - - - 3 2
C507.4 3 2 1 - - - - - - - - - 3 2
C507.5 3 2 1 - - - - - - - - - 3 2
Note: - 1: Slight 2: Moderate 3: Substantial
LIST OF EXPERIMENTS
Total: 60 Periods
LEARNING RESOURCES:
TEXT BOOKS:
REFERENCES:
AIM: To learn to use commands like tcpdump, netstat, ifconfig, nslookup and traceroute
ping.
COMMANDS:
1.tcpdump:
tcpdump is a most powerful and widely used command-line packets sniffer or package
analyzer tool which is used to capture or filter TCP/IP packets that received or transferred
over a network on a specificinterface. Display traffic between 2 hosts
2.netstat
#netstat
3. ipconfig
In Windows, ipconfig is a console application designed to run from the Windows command
prompt. This utility allows you to get the IP address information of a Windows computer.
Using ipconfigFrom the command prompt, type ipconfig to run the utility with default
options. The output of thedefault command contains the IP address, network mask, and
gateway for all physical and virtualnetwork adapter.
#ipconfig
4.nslookup
The nslookup (which stands for name server lookup) command is a network utility program
usedto obtain information about internet servers. It finds name server information for
domains by queryingthe Domain Name System.The nslookup command is a powerful tool for
diagnosing DNS problems.
#nslookup
5.tracert:
Traceroute uses Internet Control Message Protocol (ICMP) echo packets with variable time
to live(TTL) values. The response time of each hop is calculated.
6.Ping:
The ping command sends an echo request to a host available on the network. Using this
command,you can check if your remote host is responding well or not. Tracking and isolating
hardware andsoftware problems. Determining the status of the network and various foreign
hosts. The pingcommand is usually used as a simple way to verify that a computer can
communicate over the networkwith another computer or network device.
# ping172.16.6.2
7.hostname:
This is the simplest of all TCP/IP commands. It simply displays the name of your
computer.
#hostname
8. ipconfig /all
This command displays detailed configuration information about your TCP/IP connection
including Router, Gateway, DNS, DHCP, and type of Ethernet adapter in your system.
#ipconfig /all
9. pathping
Pathping is unique to Window’s, and is basically a combination of the Ping and
Tracert commands. Pathping traces the route to the destination address then
launches a 25 second test of each router along the way, gathering statistics on the
rate of data loss along each hop.
#pathping
10.route
The route command displays the computers routing table. A typical computer, with a single
network interface, connected to a LAN, with a router is fairly simple and generally doesn’t
pose any network problems. But if you’re having trouble accessing other computers on your
network, you can use the route command to make sure the entries in the routing table are
correct.
#route
Date : 03/08/24
Capture ping and traceroute PDUs using a network protocol analyser and examine.
ALGORITHM:
5. Using get run time () method, executes the specified command in a separate process.
PROGRAM:
importjava.util.*;
try
/* Process class provides methods for performing input from the process, performing output
to the process. class Runtime that allows the application to interface with the environment in
which the application is running. getRuntime-Returns the runtime object . getInputStream()
method gets the input stream of the subprocess */
while(scan.hasNextLine())
System.out.println(scan.nextLine());
catch(Exception ex)
System.out.println("error"+ex);
P1.Ping(args[0]);
OUTPUT:
Result:
ALGORITHM:
Server
Client
PROGRAM:
Client Program
import java.io.*;
import java.net.*;
importjava.util.Calendar;
class pingClient
String str;
int c=0;
long t1,t2;
while(c<4)
t1=System.currentTimeMillis();
out.println(str);
System.out.println(dis.readLine());
t2=System.currentTimeMillis();
System.out.println(";TTL="+(t2-t1)+"ms"); c++;
s.close();
Server Program
import java.io.*;
import java.net.*;
importjava.util.*;
importjava.text.*;
class pingServer
s=ss.accept();
int c=0;
while(c<4)
String str=dis.readLine();
s.close();
OUTPUT:
Date : 06/08/24
Write a HTTP web client program to download a web page using TCP sockets
Aim:
To write a java program for download a web page using TCP Socket.
Algorithm:
1.Start the program
2.Provide the address of the web page, which can be downloaded.
3.Get the information of the web page using the socket method.
4.Download the corresponding web page.
Aim:
To write a java program for download a web page using TCP Socket.
Algorithm:
1.Start the program
2.Provide the address of the web page, which can be downloaded.
3.Get the information of the web page using the socket method.
4.Download the corresponding web page.
Aim:
To write a java program for download a web page using TCP Socket.
AIM: To write a java program for download a webpage using TCP Scoket.
ALGORITHM:
PROGRAM:
import java.io.*;
import java.net.*;
InetAddress add=InetAddress.getByName("www.google.com");
out.println("GET / HTTP/1.1");
out.println("Host:www.google.com:80");
out.println("Connection:Close");
out.println();
boolean loop=true;
while(loop)
if(in.ready())
int i=0;
while(i!=-1)
i=in.read();
sb.append((char)i);
loop=false;
System.out.println(sb.toString());
s.close();
OUTPUT :
Date: 13.08.24
Applications using TCP sockets like: Echo client and echo server
AIM :To write a java program for Echo client and echo server using socket.
ALGORITHM:
Client
1. Start
9. Stop
Server
1. Start
3. Accept the connection request sent by the client for connection establishment
7. Close the connection when client initiates termination and server becomes a listening
server, waiting for clients.
8. Stop.
PROGRAM:
Client Program
import java.net.*;
import java.io.*;
Socket c=null;
String line;
DataInputStream is,is1;
PrintStream os;
try
InetAddress ia = InetAddress.getLocalHost();
c=new Socket(ia,9000);
System.out.println(e);
try
os=new PrintStream(c.getOutputStream());
is=new DataInputStream(System.in);
is1=new DataInputStream(c.getInputStream());
while(true)
System.out.println("Client:");
line=is.readLine();
os.println(line);
System.out.println("Server:" + is1.readLine());
catch(IOException e)
System.out.println("Socket Closed!");
Server Program
import java.net.*;
import java.io.*;
ServerSocket s=null;
String line;
DataInputStream is;
PrintStream ps;
Socket c=null;
try
s=new ServerSocket(9000);
catch(IOException e)
System.out.println(e);
try
c=s.accept();
is=new DataInputStream(c.getInputStream());
ps=new PrintStream(c.getOutputStream());
while(true)
line=is.readLine();
ps.println(line);
System.out.println(e);
OUTPUT :
Date: 13.08.24
ALGORITHM:
Client
5. The client accept the connection and to send the data from client to server.
6. The client communicates the server to send the end of the message
Server
5. The server accept the connection and to send the data from server to client and vice versa
7. The server communicates the client to send the end of the message.
PROGRAM:
Client Program
import java.net.*;
import java.io.*;
Socket c=null;
String line;
DataInputStream is,is1;
PrintStream os;
try
c=new Socket("localhost",9999);
catch(IOException e)
System.out.println(e);
try
is=new DataInputStream(System.in);
is1=new DataInputStream(c.getInputStream());
do
System.out.println("Client:");
line=is.readLine();
os.println(line);
System.out.println("Server:" + is1.readLine());
while(line.equalsIgnoreCase("quit")==false);
is1.close();
os.close();
catch(IOException e)
Server Program
import java.net.*;
import java.io.*;
String line;
DataInputStream is=null,is1=null;
PrintStream os=null;
Socket c=null;
try
s=new ServerSocket(9999);
catch(IOException e)
System.out.println(e);
try
c=s.accept();
is=new DataInputStream(c.getInputStream());
is1=new DataInputStream(System.in);
os=new PrintStream(c.getOutputStream());
do
line=is.readLine();
System.out.println("Client:"+line);
System.out.println("Server:");
line=is1.readLine();
os.println(line);
while(line.equalsIgnoreCase("quit")==false);
is.close();
os.close();
catch(IOException e)
System.out.println(e);
OUTPUT:
Date: 13.08.24
ALGORITHM:
Client
1. Start.
5. After getting approval from the server ,the client get the content of the file from the server
7. Stop.
Server
1. Start.
3. Server reads the filename and sends the data stored in the file for the‘get’ request.
4. It reads the data from the input stream and writes it to a file in theserver for the ‘put’
instruction.
6. Stop.
PROGRAM:
Client Program
import java.net.*;
import java.io.*;
pwrite.println(fname);
String str;
System.out.println(str);
Server Program
import java.net.*;
import java.io.*;
String str;
input.txt
Srinivas
Subramani
Tamizharasi
Sukumar
Sowmiya
Thejasri
OUTPUT:
Date: 09.09.24
ALGORITHM:
Client
5. The client accept the connection and to send the host name from client to server.
6. The client communicates the server to get the ip address from the relevant host name
Server
7. The server accept the connection and to send the ip address to client
7. The server communicate the client to send the end of the message.
PROGRAM:
Client Program
import java.io.*;
import java.net.*;
InetAddress ipaddress;
if (args.length == 0)
ipaddress = InetAddress.getLocalHost();
else
ipaddress = InetAddress.getByName(args[0]);
senddata1 = sentence.getBytes();
clientsocket.send(pack);
clientsocket.receive(recvpack);
clientsocket.close();
Server Program
import java.net.*;
str = str.trim();
if (array[i].equals(str)) return i;
return -1;
while (true)
serversocket.receive(recvpack);
String capsent;
senddata = capsent.getBytes();
serversocket.send(pack);
serversocket.close();
OUTPUT:
Date: 16.09.24
AIM: To write a java program for simulating ARP protocols using TCP.
ALGORITHM:
Client
Server
3. Server maintains the table in which IP and corresponding MAC addresses are
stored.
5. Map the IP address with its MAC address and return the MAC address to client
PROGRAM:
Client Program
import java.io.*;
import java.net.*;
import java.util.*;
class Clientarp
try
String str1=in.readLine();
dout.writeBytes(str1+'\n');
String str=din.readLine();
s.close();
catch (Exception e)
System.out.println(e);
Server Program
import java.io.*;
import java.net.*;
import java.util.*;
class Serverarp
try
Socket obj1=obj.accept();
while(true)
String str=din.readLine();
String ip[]={"165.165.80.80","165.165.79.1","192.168.7.3"};
String mac[]={"07:01:02:01:2C:4B","4A:30:10:21:10:1A","47:20:1B:2E:08:EE"};
for(int i=0;i<ip.length;i++)
if(str.equals(ip[i]))
dout.writeBytes(mac[i]+'\n');
break;
obj.close();
catch(Exception e)
System.out.println(e);
OUTPUT:
Result:
Date: 16.09.24
AIM: To write a java program for simulating RARP protocols using UDP.
ALGORITHM:
Client
Server
2. Server maintains the table in which IP and corresponding MAC addresses are
stored.
4. Map the IP address with its MAC address and return the IP address to client.
PROGRAM:
Client Program
import java.io.*;
import java.net.*;
import java.util.*;
class Clientrarp
InetAddress addr=InetAddress.getByName("localhost");
String str=in.readLine();
sendbyte=str.getBytes();
client.send(sender);
client.receive(receiver);
client.close();
catch(Exception e)
System.out.println(e);
Server Program
import java.io.*;
import java.net.*;
class Serverrarp
try
while(true)
server.receive(receiver);
String s=str.trim();
InetAddress addr=receiver.getAddress();
int port=receiver.getPort();
String ip[]={"165.165.80.80","165.165.79.1","192.168.7.3"};
String mac[]={"07:01:02:01:2C:4B","4A:30:10:21:10:1A","47:20:1B:2E:08:EE"};
for(int i=0;i<ip.length;i++)
if(s.equals(mac[i]))
sendbyte=ip[i].getBytes();
server.send(sender);
break;
catch(Exception e)
System.out.println(e);
OUTPUT:
AIM:
To Study Network simulator (NS) and Simulation of Congestion Control Algorithms
using NS
THEORY:
The above figure shows the basic architecture of NS2. NS2 provides users with an
executable command ns which takes on input argument, the name of a Tcl simulation
scripting file. Users are feeding the name of a Tcl simulation script (which sets up a
simulation) as an input argument of an NS2 executable command ns.
In most cases, a simulation trace file is created, and is used to plot graph and/or to
create animation. NS2 consists of two key languages: C++ and Object-oriented Tool
Command Language (OTcl). While the C++ defines the internal mechanism (i.e., a backend)
of the simulation objects, the OTcl sets up simulation by assembling and configuring the
objects as well as scheduling discrete events (i.e., a frontend).
The C++ and the OTcl are linked together using TclCL. Mapped to a C++ object,
variables in the OTcl domains are sometimes referred to as handles. Conceptually, a handle
(e.g., n as a Node handle) is just a string (e.g.,_o10) in the OTcl domain, and does not contain
any functionality. instead, the functionality (e.g., receiving a packet) is defined in the mapped
C++ object (e.g., of class Connector). In the OTcl domain, a handle acts as a frontend which
interacts with users and other OTcl objects. It may defines its own procedures and variables
to facilitate the interaction. Note that the member procedures and variables in the OTcl
NS2 provides a large number of built-in C++ objects. It is advisable to use these C++
objects to set up a simulation using a Tcl simulation script. However, advance users may find
these objects insufficient. They need to develop their own C++ objects, and use a OTcl
configuration interface to put together these objects. After simulation, NS2 outputs either
text-based or animation-based simulation results. To interpret these results graphically and
interactively, tools such as NAM (Network AniMator) and XGraph are used. To analyze a
particular behaviour of the network, users can extract a relevant subset of text-based data and
transform it to a more conceivable presentation
Tcl scripting:
• Tcl is a general purpose scripting language. [Interpreter]
• Tcl runs on most of the platforms such as Unix, Windows, and Mac.
• The strength of Tcl is its simplicity.
• It is not necessary to declare a data type for variable prior to the usage
Basics of TCL
Variables
Command Substitution
set a 5 set len [string length foobar]
set b $a set len [expr [string length foobar] + 9]
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 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
}
Once we define several nodes, we can define the links that connect them. An example of a
definition of a link is:
$ns duplex-link $n0 $n2 10Mb 10ms DropTail
Which means that $n0 and $n2 are connected using a bi-directional link that has 10ms of
propagation delay and a capacity of 10Mb per sec for each direction.
The command $ns attach-agent $n0 $tcp defines the source node of the tcp connection.
The command set sink [new Agent /TCPSink]Defines the behavior of the destination node
of TCP and assigns to it a pointer called sink.
The below shows the definition of a CBR application using a UDP agent
The command $ns attach-agent $n4 $sink defines the destination node. The command $ns
connect $tcp $sink finally makes the TCP connection between the source and destination
nodes.
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
Sliding.tcl
proc finish {} {
global ns
$ns flush-trace
# close $nf
puts "running nam..."
exec nam sliding.nam &
exit 0
}
$ns run
OUTPUT:
Date: 25.09.24
AIM:
To simulate the performance of TCP/UDP using NS2.
Algorithm
1. Create a Simulator object.
2. Set routing as dynamic.
3. Open the trace and nam trace files.
4. Define the finish procedure.
5. Create nodes and the links between them.
6. Create the agents and attach them to the nodes.
7. Create the applications and attach them to the tcp agent.
8. Connect tcp and tcp sink.
9. Run the simulation
PROGRAM:
wired.tcl
#create nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
wired.tr
Date: 03.10.24
AIM:
To simulate and study the Distance Vector routing algorithm using simulation.
SOFTWARE REQUIRED:
NS-2
THEORY:
Distance Vector Routing is one of the routing algorithm in a Wide Area Network for
computing shortest path between source and destination. The Router is one main devices used
in a wide area network. The main task of the router is Routing. It forms the routing table and
delivers the packets depending upon the routes in the table-either directly or via an
intermediate devices.
Each router initially has information about all its neighbours. Then this information will be
shared among nodes.
ALGORITHM:
1. Create a simulator object
2. Define different colors for different data flows
3. Open a nam trace file and define finish procedure then close the trace file, and execute nam
on trace file.
4. Create n number of nodes using for loop
5. Create duplex links between the nodes
6. Setup UDP Connection between n(0) and n(5)
7. Setup another UDP connection between n(1) and n(5)
8. Apply CBR Traffic over both UDP connections
9. Choose distance vector routing protocol to transmit data from sender to receiver.
10. Schedule events and run the program.
PROGRAM:
RESULT:
Thus the Distance vector Routing Algorithm was Simulated and studied.
Date: 03.10.24
AIM:
To simulate and study the link state routing algorithm using simulation.
SOFTWARE REQUIRED:
NS-2
THEORY:
In link state routing, each router shares its knowledge of its neighborhood with every other
router in the internet work. (i) Knowledge about Neighborhood: Instead of sending its
entire routing table a router sends info about its neighborhood only. (ii) To all Routers: each
router sends this information to every other router on the internet work not just to its neighbor
.It does so by a process called flooding. (iii)Information sharing when there is a change:
Each router sends out information about the neighbors when there is change.
PROCEDURE:
The Dijkstra algorithm follows four steps to discover what is called the shortest path
tree(routing table) for each router:The algorithm begins to build the tree by identifying its
roots. The root router’s trees the router itself. The algorithm then attaches all nodes that can
be reached from the root. The algorithm compares the tree’s temporary arcs and identifies the
arc with the lowest cumulative cost. This arc and the node to which it connects are now a
permanent part of the shortest path tree. The algorithm examines the database and identifies
every node that can be reached from its chosen node. These nodes and their arcs are added
temporarily to the tree.
The last two steps are repeated until every node in the network has become a permanent part
of the tree.
ALGORITHM:
1. Create a simulator object
2. Define different colors for different data flows
3. Open a nam trace file and define finish procedure then close the trace file, and execute nam
on trace file.
4. Create n number of nodes using for loop
5. Create duplex links between the nodes
6. Setup UDP Connection between n(0) and n(5)
7. Setup another UDP connection between n(1) and n(5)
8. Apply CBR Traffic over both UDP connections
9. Choose Link state routing protocol to transmit data from sender to receiver.
10. Schedule events and run the program.
PROGRAM:
set ns [new Simulator]
OUTPUT:
RESULT:
Thus the simulation for Link state routing was done usingNS2.
Date: 14.10.24
A) UNICAST PROTOCOL
AIM:
To write a ns2 program for implementing unicast routing protocol.
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 file
set file1 [open out.tr w]
$ns trace-all $file1
#Open the NAM trace file
set file2 [open out.nam w]
$ns namtrace-all $file2
#Define a 'finish' procedure
proc finish {}
{
global ns file1 file2
exit 3
}
# Next line should be commented out to have the static routing
$ns rtproto DV
#Create six nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n4 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
#Create links between the nodes
$ns duplex-link $n0 $n1 0.3Mb 10ms DropTail
$ns duplex-link $n1 $n2 0.3Mb 10ms DropTail
$ns duplex-link $n2 $n3 0.3Mb 10ms DropTail
$ns duplex-link $n1 $n4 0.3Mb 10ms DropTail
$ns duplex-link $n3 $n5 0.5Mb 10ms DropTail
$ns duplex-link $n4 $n5 0.5Mb 10ms DropTail
AIM:
To write a ns2 program for implementing multicasting routing protocol.
ALGORITHM:
1. Start the program.
2. Declare the global variables ns for creating a new simulator.
3. Set the color for packets.
4. Open the network animator file in the name of file2 in the write mode.
5. Open the trace file in the name of file 1 in the write mode.
6. Set the multicast routing protocol to transfer the packets in network.
7. Create the multicast capable no of nodes.
8. Create the duplex-link between the nodes including the delay time,bandwidth and
dropping queue mechanism.
9. Give the position for the links between the nodes.
10. Set a udp connection for source node.
11. Set the destination node ,port and random false for the source and destination files.
12. Setup a traffic generator CBR for the source and destination files.
13. Down the connection between any nodes at a particular time.
14. Create the receive agent for joining and leaving if the nodes in the group.
15. Define the finish procedure.
16. In the definition of the finish procedure declare the global variables.
17. Close the trace file and namefile and execute the network animation file.
18. At the particular time call the finish procedure.
19. Stop the program.
PROGRAM:
# Create scheduler
#Create an event scheduler wit multicast turned on
set ns [new Simulator -multicast on]
#$ns multicast
#Turn on Tracing
set tf [open output.tr w]
$ns trace-all $tf
# Turn on nam Tracing
set fd [open mcast.nam w]
$ns namtrace-all $fd
# Create nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
set n6 [$ns node]
set n7 [$ns node]
OUTPUT:
RESULT:
Thus the case study about the different routing algorithms to select the network path with
its optimum and economical during data transfer is done.
AIM:
To implement error-checking code using Java.
ALGORITHM:
1. Start the Program
2. Given a bit string, append 0S to the end of it (the number of 0s is the same as the degree
of the generator polynomial) let B(x) be the polynomial corresponding to B.
3. Divide B(x) by some agreed on polynomial G(x) (generator polynomial) and determine
the remainder R(x). This division is to be done using Modulo 2 Division.
4. Define T(x) = B(x) –R(x)
5. (T(x)/G(x) => remainder 0)
6. Transmit T, the bit string corresponding to T(x).
7. Let T’ represent the bit stream the receiver gets and T’(x) the associated polynomial. The
receiver divides T1(x) by G(x). If there is a 0 remainder, the receiver concludes T = T’
and no error occurred otherwise, the receiver concludes an error occurred and requires a
retransmission
8. Stop the Program
PROGRAM:
import java.io.*;
class crc_gen
{
public static void main(String args[]) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int[] data;
int[] div;
int[] divisor;
int[] rem;
int[] crc;
int data_bits, divisor_bits, tot_length;
System.out.println("Enter number of data bits : "); data_bits=Integer.parseInt(br.readLine());
data=new int[data_bits];
System.out.println("Enter data bits : ");
for(int i=0; i<data_bits; i++)
data[i]=Integer.parseInt(br.readLine());
System.out.println("Enter number of bits in divisor : ");
divisor_bits=Integer.parseInt(br.readLine()); divisor=new int[divisor_bits];
System.out.println("Enter Divisor bits : ");
for(int i=0; i<divisor_bits; i++)
divisor[i]=Integer.parseInt(br.readLine());
System.out.print("Data bits are : ");
for(int i=0; i< data_bits; i++)
System.out.print(data[i]);
System.out.println();
System.out.print("divisor bits are : ");
OUTPUT :
Enter number of data bits :
7
Enter data bits :
1
0
1
1
0
0
1
Enter number of bits in divisor :
3
Enter Divisor bits :
1
0
1
Dividend (after appending 0's) are : 101100100
CRC code :
101100111
Enter CRC code of 9 bits :
1
0
1
1
0
0
1
0
1
crc bits are : 101100101
Error
THANK YOU.... :)
BUILD SUCCESSFUL (total time: 1 minute 34 seconds)
RESULT:
AIM:
To Simulate and to study of Go Back N protocol
ALGORITHM :
PROGRAM :
#send packets one by one
set ns [new Simulator] set n0 [$ns node]
set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] set n4 [$ns node] set n5 [$ns node] $n0
color "purple" $n1 color "purple" $n2 color "violet" $n3 color "violet" $n4 color "chocolate"
$n5
color "chocolate" $n0 shape box ;
$n1 shape box ; $n2 shape box ; $n3 shape box ; $n4 shape box ; $n5 shape box ;
$ns at 0.0 "$n0 label SYS0"
$ns at 0.0 "$n1 label SYS1"
$ns at 0.0 "$n2 label SYS2"
$ns at 0.0 "$n3 label SYS3"
$ns at 0.0 "$n4 label SYS4"
$ns at 0.0 "$n5 label SYS5"
set nf [open goback.nam w] $ns namtrace-all $nf
set f [open goback.tr w] $ns trace-all $f
OUTPUT
AIM:
To write a ns2 program for implementing carrier sense multiple access.
ALGORITHM:
1. Start the program.
2. Declare the global variables ns for creating a new simulator.
PROGRAM:
set ns [new Simulator]
$ns color 1 blue
$ns color 2 red
set fi1 [open out.tr w]
set winfile [open WinFile w]
$ns trace-all $fi1
set fi2 [open out.nam w]
$ns namtrace-all $fi2
proc finish {}
{
global ns fi1 fi2
$ns flush-trace
close $fi1
close $fi2
exec nam out.nam &
exit 0
}
set n0 [$ns node]
set n1 [$ns node]
OUTPUT: