Essential Network Commands Guide
Essential Network Commands Guide
AIM:
NETWORK COMMANDS
C:\>arp –a:
ARP is short form of address resolution protocol, It will show the IP address of your
computer along with the IP address and MAC address of your router.
C:\>hostname:
This is the simplest of all TCP/IP commands. It simply displays the name of your
computer.
C:\>ipconfig:
The ipconfig command displays information about the host (the computer your sitting
at)computer TCP/IP configuration.
C:\>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.
C:\>ipconfig /renew:
Using this command will renew all your IP addresses that you are currently (leasing)
borrowing from the DHCP server. This command is a quick problem solver if you are
having connection issues, but does not work if you have been configured with a static IP
address.
C:\>ipconifg /release:
This command allows you to drop the IP lease from the DHCP server.
C:\>ipconfig /flushdns:
This command is only needed if you’re having trouble with your networks DNS
configuration. The best time to use this command is after network configuration frustration
sets in, and you really need the computer to reply with flushed.
C:\>nbtstat –a:
This command helps solve problems with NetBIOS name resolution. (Nbt stands for
NetBIOS over TCP/IP)
Page | 1
C:\>netdiag:
Netdiag is a network testing utility that performs a variety of network diagnostic tests,
allowing you to pinpoint problems in your network. Netdiag isn’t installed by default, but
can be installed from the Windows XP CD after saying no to the install
C:\>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 specific interface.
C:\>netstat
Netstat displays a variety of statistics about a computers active TCP/IP connections. This
tool is most useful when you’re having trouble with TCP/IP applications such as HTTP,
C:\>ifconfig
C:\>nslookup
nslookup is used for diagnosing DNS problems. If you can access a resource by
specifying an IP address but not it’s DNS you have a DNS problem.
C:\>tracert
The tracert command displays a list of all the routers that a packet has to go through to
get from the computer where tracert is run to any other computer on the internet.
C:\>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.
C:\>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.
Page | 2
[Link].1a CODE STIMULATING PING COMMAND
DATE:
Page | 3
Client:
import [Link].*;
import [Link].*;
import [Link];
class pingclient
{
public static void main(String args[])throws Exception
{ String str;
int c=0; long t1,t2;
Socket s=new Socket("[Link]",5555);
DataInputStream dis=new DataInputStream([Link]());
PrintStream out=new PrintStream([Link]());
while(c<4) { t1=[Link]();
str="Welcome to network programming world";
[Link](str);
[Link]([Link]());
t2=[Link]();
[Link](";TTL="+(t2-t1)+"ms");
c++; }
[Link]();
}
}
Server
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
class pingserver
{
public static void main(String args[])throws Exception
{
ServerSocket ss=new ServerSocket(5555);
Socket s=[Link]();
int c=0;
while(c<4)
{
DataInputStream dis=new DataInputStream([Link]());
PrintStream out=new PrintStream([Link]());
String str=[Link]();
[Link]("Reply from"+[Link]()+";Length"+[Link]()); c++; }
Page | 4
[Link]();
}
}
OUTPUT
Server
D:\>javac [Link]
Note: [Link] uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
D:\>java pingserver
Client
D:\>javac [Link]
Note: [Link] uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
D:\>java pingclient
Reply from source/[Link];Length36 ;TTL=24ms
Reply from source/[Link];Length36 ;TTL=2ms
Reply from source/[Link];Length36 ;TTL=1ms
Reply source/[Link];Length36 ;TTL=2ms
Page | 5
[Link].1b CODE STIMULATING TRACEROUTE COMMAND
DATE:
TRACEROUTE
An Internet utility that describes the path in real time from the client machine to the
remote host being contacted. It reports the IP addresses of all the routers in between.
Trace route lets us see the route that IP datagram’s follow from one host to another. Trace
route also lets us use the IP source route option.
Page | 6
PROGRAM:
import [Link].*;
import [Link].*;
class TraceRoute
{
public static void main(String args[]) throws Exception
{
String str;
[Link](" Enter the website address to be traced : ");
BufferedReader buf1=new BufferedReader(new InputStreamReader([Link]));
String ip=[Link]();
Runtime H=[Link]();
Process p=[Link]("tracert " + ip);
InputStream in=[Link]();
BufferedReader buf2=new BufferedReader(new
InputStreamReader(in));
while((str=[Link]())!=null)
{
[Link](" " + str);
}
}
}
Page | 7
OUTPUT
Enter the website address to be traced :
[Link]
Trace complete.
Page | 8
[Link].2 HTTP WEB CLIENT PROGRAM TO DOWNLOAD A IMAGE USING
DATE: TCP SOCKETS
Page | 9
SERVER:
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
class Server {
public static void main(String args[]) throws Exception{
ServerSocket server=null;
Socket socket;
server=new ServerSocket(4000);
[Link]("Server Waiting for image");
socket=[Link]();
[Link]("Client connected.");
InputStream in = [Link]();
DataInputStream dis = new DataInputStream(in);
int len = [Link]();
[Link]("Image Size: " + len/1024 + "KB");
byte[] data = new byte[len];
[Link](data);
[Link]();
[Link]();
InputStream ian = new ByteArrayInputStream(data);
BufferedImage bImage = [Link](ian);
JFrame f = new JFrame("Server");
ImageIcon icon = new ImageIcon(bImage);
JLabel l = new JLabel();
[Link](icon);
[Link](l);
[Link]();
[Link](true);
}
}
Page | 10
CLIENT:
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class Client{
public static void main(String args[]) throws Exception{
Socket soc;
BufferedImage img = null;
soc=new Socket("localhost",4000);
[Link]("Client is running. ");
try {
[Link]("Reading image from disk. ");
img = [Link](new File("[Link]"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
[Link](img, "jpg", baos);
[Link]();
byte[] bytes = [Link]();
[Link]();
[Link]("Sending image to server. ");
OutputStream out = [Link]();
DataOutputStream dos = new DataOutputStream(out);
[Link]([Link]);
[Link](bytes, 0, [Link]);
[Link]("Image sent to server. ");
[Link]();
[Link]();
}catch (Exception e) {
[Link]("Exception: " + [Link]());
[Link]();
}
[Link]();
}
Page | 11
}
OUTPUT
CLIENT:
Z:\http>javac [Link]
Z:\http>java Client
Client is running.
Reading image from disk.
Sending image to server.
Image sent to server.
SERVER:
Z:\http>javac [Link]
Z:\http>java Server
Server Waiting for image
Client connected.
Page | 12
[Link].3a ECHO CLIENT AND ECHO SERVER USING TCP SOCKETS
DATE:
Page | 13
[Link] :
import [Link].*;
import [Link].*;
public class tcpechoserver
{
public static void main(String[] arg) throws IOException
{
ServerSocket sock = null;
import [Link].*;
import [Link].*;
public class tcpechoclient
{
public static void main(String[] args) throws IOException
` {
BufferedReader fromServer = null, fromUser = null;
PrintWriter toServer = null;
Socket sock = null;
try
{
if ([Link] == 0)
sock = new Socket([Link](),4000);
else
sock = new Socket([Link](args[0]),4000);
fromServer = new BufferedReader(new InputStreamReader([Link]()));
fromUser = new BufferedReader(new InputStreamReader([Link]));
toServer = new PrintWriter([Link](),true);
String Usrmsg, Srvmsg;
[Link]("Type \"bye\" to quit");
while (true)
{
[Link]("Enter msg to server : ");
Usrmsg = [Link]();
if (Usrmsg==null || [Link]("bye"))
{
[Link]("bye");
break;
}
else
[Link](Usrmsg);
Srvmsg = [Link]();
[Link](Srvmsg);
}
[Link]();
[Link]();
[Link]();
[Link]();
}
catch (IOException ioe)
Page | 15
{
[Link](ioe);
}
}
}
OUTPUT:
Server
javac [Link]
java tcpechoserver
Server Ready
Client Connected
Client [ hello ]
Client [ how are you ]
Client [ i am fine ]
Client [ ok ]
Client Disconnected
Client
javac [Link]
java tcpechoclient
Type "bye" to quit
Enter msg to server : hello
Server [ hello ]
Enter msg to server : how are you
Server [ how are you ]
Enter msg to server : i am fine
Server [ i am fine ]
Enter msg to server : ok
Server [ ok ]
Enter msg to server : bye
Page | 16
[Link].3b CHAT APPLICATION USING TCP SOCKETS
DATE:
Page | 17
[Link] :
import [Link].*;
import [Link].*;
public class Server
{
public static void main(String args[]) throws Exception
{
ServerSocket sersock=new ServerSocket(9999);
[Link]("Server ready for chatting");
Socket sock= [Link]();
BufferedReader sendRead= new BufferedReader(new InputStreamReader([Link]));
OutputStream ofstream=[Link]();
PrintWriter pwrite=new PrintWriter(ofstream,true);
InputStream istream=[Link]();
BufferedReader receivedread=new BufferedReader(new InputStreamReader(istream));
String receivemessage,sendmessage;
while(true)
{
if((receivemessage=[Link]())!=null)
{
[Link](receivemessage);
}
sendmessage=[Link]();
[Link](sendmessage);
[Link]();
}
}
}
[Link]:
import [Link].*;
import [Link].*;
public class Client
{
public static void main(String args[]) throws Exception
{
Socket sock=new Socket("localhost",9999);
BufferedReader sendRead= new BufferedReader(new InputStreamReader([Link]));
Page | 18
OutputStream ofstream=[Link]();
PrintWriter pwrite=new PrintWriter(ofstream,true);
InputStream istream=[Link]();
BufferedReader receivedread=new BufferedReader(new InputStreamReader(istream));
[Link]("client ready for chatting");
String receivemessage,sendmessage;
while(true)
{
sendmessage=[Link]();
[Link](sendmessage);
[Link]();
if((receivemessage=[Link]())!=null)
{
[Link](receivemessage);
}
}
}
}
OUTPUT:
SERVER:
Z:\>javac [Link]
Z:\>java Server
Server ready for chatting
welcome
Hello
CLIENT:
Z:\>javac [Link]
Z:\>java Client
client ready for chatting
welcome
Hello
Page | 19
[Link].3 c FILE TRANSFER USING TCP SOCKETS
DATE:
Page | 20
[Link]:
import [Link].*;
import [Link].*;
import [Link].*;
class Clientfile
{
public static void main(String args[])
try
{
BufferedReader in=new BufferedReader(new InputStreamReader([Link]));
Socket clsct=new Socket("localhost",9999);
DataInputStream din=new DataInputStream([Link]());
DataOutputStream dout=new DataOutputStream([Link]());
[Link]("Enter the file name:");
String str=[Link]();
[Link](str+'\n');
[Link]("Enter the new file name:");
String str2=[Link]();
String str1;
FileWriter f=new FileWriter(str2);
char buffer[];
while(true) { str1=[Link]();
if([Link]("-1"))
break;
[Link](str1);
buffer=new char[[Link]()];
[Link](0,[Link](),buffer,0);
[Link](buffer);
}
[Link]();
[Link]();
}
catch (Exception e)
{
[Link](e);
}}}
Page | 21
[Link]:
import [Link].*;
import [Link].*;
import [Link].*;
class Serverfile
{
public static void main(String args[])
{
try
{
ServerSocket obj=new ServerSocket(9999);
while(true)
{
Socket obj1=[Link]();
DataInputStream din=new DataInputStream([Link]());
DataOutputStream dout=new DataOutputStream([Link]());
String str=[Link]();
FileReader f=new FileReader(str);
BufferedReader b=new BufferedReader(f);
String s;
while((s=[Link]())!=null)
{
[Link](s);
[Link](s+'\n');
}
[Link]();
[Link]("-1\n");
}}
catch(Exception e)
{ [Link](e);
}
}
}
Page | 22
OUTPUT:
[Link]
computer lab
Dept of CSE
Velammal Institute
SERVER:
Z:\>javac [Link]
Note: [Link] uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Z:\>java Serverfile
computer lab
Dept of CSE
Velammal Institute
CLIENT:
Z:\>javac [Link]
Note: [Link] uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Z:\>java Clientfile
Enter the file name:
[Link]
Page | 23
[Link].4 SIMULATION OF DNS SERVER USING UDP SOCKETS
DATE:
Page | 24
[Link]
import [Link].*;
import [Link].*;
class dnsserver
{
public static void main(String args[])throws Exception
{
byte buffer[]=new byte[1024];
int clientport=789,serverport=790;
DatagramSocket ds=new DatagramSocket(clientport);
[Link]("Server Waiting");
BufferedReader buf=new BufferedReader(new InputStreamReader([Link]));
InetAddress ia=[Link]();
while(true)
{
DatagramPacket p=new DatagramPacket(buffer,[Link]);
[Link](p);
String psx=new String([Link](),0,[Link]());
[Link]("Client:" + psx);
InetAddress ib=[Link](psx);
[Link]("Server output:"+ib);
String str=[Link]();
if([Link]("end"))
break;
buffer=[Link]();
[Link](new DatagramPacket(buffer,[Link](),ia,serverport));
}
}
}
[Link]
import java .io.*;
import [Link].*;
class dnsclient
{
public static void main(String args[])throws Exception
{
byte buffer[]=new byte[1024];
Page | 25
int clientport=789,serverport=790;
DatagramSocket ds=new DatagramSocket(serverport);
BufferedReader buf=new BufferedReader(new InputStreamReader([Link]));
InetAddress ia=[Link]();
while(true)
{
[Link]("Enter the Website Name:");
String str=[Link]();
if([Link]("end"))
break;
buffer=[Link]();
[Link](new DatagramPacket(buffer,[Link](),ia,clientport));
DatagramPacket p=new DatagramPacket(buffer,[Link]);
[Link](p);
String psx=new String([Link](),0,[Link]());
[Link]("Server:" + psx);
}
}
}
OUTPUT
[Link]
z:\>javac [Link]
z:\>java dnsserver
Server Waiting
Client:[Link]
Server output:[Link]/[Link]
[Link]
z:\>java dnsclient
Enter the Website Name:
[Link]
Page | 26
[Link]
USE A TOOL LIKE WIRESHARK TO CAPTURE PACKETS AND EXAMINE
DATE: THE PACKETS
Page | 27
PROGRAM:
import sys
from [Link] import *
# Define the packet capturing function
def packet_handler(packet):
print([Link]())
OUTPUT:
chksum = 0xe877
src = [Link]
dst = [Link]
\options \
Page | 28
###[ TCP ]###
sport = 54321
dport = http
seq = 3665840854
ack = 2542707921
dataofs = 5
reserved = 0
flags = FA
window = 8760
chksum = 0x9d6c
urgptr =0
options = [('MSS', 1460), ('SAckOK', ''), ('Timestamp', (12576855, 2413)), ('NOP', None), ('WScale', 7)]
###[ Raw ]###
load = ''
Page | 29
[Link].6 a SIMULATION OF ARP PROTOCOL
DATE:
Page | 30
PROGRAM:
import [Link].*;
import [Link].*;
import [Link].*;
public class FindMAC
{
public static void main(String args[])throws IOException
{
getMacAdressByUseArp();
}
private static void getMacAdressByUseArp()throws IOException
{
String cmd="arp -a";
DataInputStream in=new DataInputStream([Link]().exec(cmd).getInputStream());
DataInputStream sin=new DataInputStream([Link]);
String str=null,ip,mac=null,find;
[Link]("Input IP address to find MAC address?");
find=[Link]();
int lindex;
boolean found=false;
do
{
str=[Link]();
if(str!=null && [Link]()>20)
{
str=[Link]();
ip=[Link](0,20).trim();
lindex=[Link]("dynamic");
if(lindex==-1)
lindex=[Link]("static");
if(lindex!=-1)
mac=[Link](22,lindex);
//[Link](ip+""+mac)
if([Link]([Link]()))
{
[Link]("MAC address="+mac);
Page | 31
found=true;
break;
}
}
}
while(str!=null);
if(!found)
[Link]("No MAC address [Link] valid IP address...");
}
}
OUTPUT:
Z:\>javac [Link]
Z:\>java FindMAC
Input IP address to find MAC address?
[Link]
MAC address=00-15-17-26-ea-34
Page | 32
[Link].6 b SIMULATION OF RARP PROTOCOL
DATE:
Page | 33
PROGRAM:
import [Link].*;
import [Link].*;
import [Link].*;
public class FindIP
{
public static void main(String args[])throws IOException
{
getipAdressByUseArp();
}
private static void getipAdressByUseArp()throws IOException
{
String cmd="arp -a";
DataInputStream in=new DataInputStream([Link]().exec(cmd).getInputStream());
DataInputStream sin=new DataInputStream([Link]);
String str=null,ip,mac=null,find;
[Link]("Input MAC address to find IP address?");
find=[Link]();
int lindex;
boolean found=false;
do
{
str=[Link]();
if(str!=null && [Link]()>20)
{
str=[Link]();
if([Link](0,5).equals("Inter")) continue;
ip=[Link](0,20).trim();
lindex=[Link]("dynamic");
if(lindex==-1)
lindex=[Link]("static");
if(lindex!=-1)
mac=[Link](22,lindex);
if([Link]([Link]()))
{
[Link]("ip address="+ip);
found=true;
Page | 34
break;
}
}
}
while(str!=null);
if(!found)
[Link]("No IP address [Link] valid MAC address...");
}
}
OUTPUT:
Z:\>javac [Link]
Z:\>java FindIP
Input MAC address to find IP address?
ec-8e-b5-a1-06-49
IP address=[Link]
Page | 35
[Link].7 SIMULATION OF ERROR CORRECTION CODE(LIKE CRC)
DATE:
Page | 36
Program:
import [Link].*;
class crc
{
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader([Link]));
[Link]("Enter Generator:");
String gen = [Link]();
[Link]("Enter Data:");
String data = [Link]();
String code = data;
while([Link]() < ([Link]() + [Link]() - 1))
code = code + "0";
code = data + div(code,gen);
[Link]("The transmitted Code Word is: " + code);
[Link]("Please enter the received Code Word: ");
String rec = [Link]();
if([Link](div(rec,gen)) == 0)
[Link]("The received code word contains no errors.");
else
[Link]("The received code word contains errors.");
}
static String div(String num1,String num2)
{
int pointer = [Link]();
String result = [Link](0, pointer);
String remainder = "";
for(int i = 0; i < [Link](); i++)
{
if([Link](i) == [Link](i))
remainder += "0";
else
remainder += "1";
}
while(pointer < [Link]()){
Page | 37
if([Link](0) == '0')
{
remainder = [Link](1, [Link]());
remainder = remainder + [Link]([Link](pointer));
pointer++;
}
result = remainder;
remainder = "";
for(int i = 0; i < [Link](); i++)
{
if([Link](i) == [Link](i))
remainder += "0";
else
remainder += "1";
}
}
return [Link](1,[Link]());
}
}
Output :-
(a) Without Error
Enter Generator:
1011
Enter Data:
1001010
The transmitted Code Word is: 1001010111
Please enter the received Code Word:
1001010111
The received code word contains no errors.
(b)With Error
Enter Generator:
1011
Enter Data:
1001010
The transmitted Code Word is: 1001010111
Please enter the received Code Word:
1110110111
The received code word contains errors.
Page | 38
[Link].8 a STUDY OF NETWORK SIMULATOR (NS2)
DATE:
NS2 SIMULATOR
How to start:
First of all, a simulator object has to be created. This is done with the command
set ns [new Simulator]
Now open a file for writing that is going to be used for the nam trace data.
set nf [open [Link] w]
Page | 39
$ns namtrace-all $nf
The first line opens the file '[Link]' for writing and gives it the file handle 'nf'. In the second
line the simulator object created above writes all simulation data that is going to be relevant for
nam into this [Link] next step is to add a 'finish' procedure that closes the trace file and starts
nam.
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam [Link] &
exit 0}
The next line tells the simulator object to execute the 'finish' procedure after 5.0 seconds
of simulation time.
$ns at 5.0 "finish"
ns provides a very simple way to schedule events with the 'at' command. The last line
finally starts the simulation.
#Run the simulation
$ns run
The file can be saved the now and try to run it with 'ns [Link]'.
# Insert your own code for topology creation and agent definitions, etc. here
A new node object is created with the command '$ns node'. The above code
creates two nodes and assigns them to the handles 'n0' and 'n1'. The next line connects the
two nodes.
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
This line tells the simulator object to connect the nodes n0 and n1 with a duplex link with
the bandwidth 1Megabit, a delay of 10ms and a DropTail queue. The file can be saved the
now and try to run it with 'ns [Link]'. nam will be started automatically and an output
is seen that resembles the picture below.
Page | 40
Commands to create a link between nodes:
Sending data:
The next step is to send some data from node n0 to node n1. In ns, data is always being
sent from one 'agent' to another. So the next step is to create an agent object that sends data from
node n0, and another agent object that receives the data on node n1.
#Create a UDP agent and attach it to node n0
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
# Create a CBR traffic source and attach it to udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
These lines create a UDP agent and attach it to the node n0, then attach a CBR traffic
generator to the UDP agent. CBR stands for 'constant bit rate'. Line 7 and 8 should be self-
explaining. The packet Size is being set to 500 bytes and a packet will be sent every 0.005
seconds (i.e. 200 packets per second).
The next lines create a Null agent which acts as traffic sink and attach it to node n1.
set null0 [new Agent/Null]
$ns attach-agent $n1 $null0
Now the two agents have to be connected with each other.
Page | 41
$ns connect $udp0 $null0
And now the CBR agent has to be informed when to send data and when to stop sending.
Note: It's probably best to put the following lines just before the line '$ns at 5.0 "finish"'.
Agents
Agents represent endpoints where network-layer packets are constructed or consumed,
and are used in the implementation of protocols at various layers.
This command attaches the <agent> to the <node>. An agent is typically created by set
agent [new Agent/AgentType] where Agent/AgentType defines the class definiton of the
specified agent type.
Topology
Now insert the following lines into the code to create four nodes.
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
The following piece of Tcl code creates three duplex links between the nodes.
The script can be saved and script can be started again. Sometimes the topology looks a
bit awkward in nam. In that case hit the 're-layout' button to make it look better, but it would be
Page | 42
nice to have some more control over the layout. Add the next three lines to your Tcl script and
start it again.
After successful installation, path setting and validation, execute NS2 programs.
$ ns [Link]
Page | 43
[Link].8 b SIMULATION OF CONGESTION CONTROL ALGORITHM
DATE: USING NS2
Page | 44
[Link]
set ns [new Simulator]
set nr [open thro_red.tr w]
$ns trace-all $nr
set nf [open [Link] w]
$ns namtrace-all $nf
proc finish { } {
global ns nr nf
$ns flush-trace
close $nf
close $nr
exec nam [Link] &
exit 0 }
Page | 45
set cbr0 [new Application/Traffic/CBR]
Page | 46
OUTPUT:
Page | 47
[Link].9 a SIMULATION OF DISTANCE VECTOR ROUTING PROTOCOL
DATE:
Page | 48
[Link]
Page | 50
[Link].9 b SIMULATION OF LINK STATE ROUTING PROTOCOL
DATE:
Page | 51
Program:
set ns [new Simulator]
set nr [open [Link] w]
$ns trace-all $nr
set nf [open [Link] w]
$ns namtrace-all $nf
proc finish { } {
global ns nr nf
$ns flush-trace
close $nf
close $nr
exec nam [Link] &
exit 0 }
Page | 53
[Link].10 STUDY OF TCP/UDP PERFORMACE USING SIMULATION
DATE: TOOL
TCP Performance
Page | 54
PROGRAM:
set ns [new Simulator]
$ns color 0 Blue
$ns color 1 Red
$ns color 2 Yellow
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set f [open [Link] w]
$ns trace-all $f
set nf [open [Link] w]
$ns namtrace-all $nf
proc finish {} {
global ns f nf
$ns flush-trace
close $f
close $nf
puts "Running nam.."
exec nam [Link] &
exit 0 }
$ns run
Page | 55
OUTPUT
Page | 56
UDP Performance
Page | 57
PROGRAM:
set ns [new Simulator]
$ns color 0 Blue
$ns color 1 Red
$ns color 2 Yellow
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set f [open [Link] w]
$ns trace-all $f
set nf [open [Link] w]
$ns namtrace-all $nf
$ns duplex-link $n0 $n2 5Mb 2ms DropTail
$ns duplex-link $n1 $n2 5Mb 2ms DropTail
$ns duplex-link $n2 $n3 1.5Mb 10ms DropTail
$ns duplex-link-op $n0 $n2 orient right-up
$ns duplex-link-op $n1 $n2 orient right-down
$ns duplex-link-op $n2 $n3 orient right
$ns duplex-link-op $n2 $n3 queuePos 0.5
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
set udp1 [new Agent/UDP]
$ns attach-agent $n3 $udp1
$udp1 set class_ 0
set cbr1 [new Application/Traffic/CBR]
OUTPUT:
Page | 59
[Link].11 PERFORMANCE EVALUATION OF ROUTING PROTOCOLS
DATE: USING SIMULATION TOOL
DISCUSSION:
• When a device has multiple paths to reach a destination, it always selects one path by
preferring it over others. This selection process is termed as Routing. Routing is done by special
network devices called routers or it can be done by means of software processes.
• The software based routers have limited functionality and limited scope. A router is always
configured with some default route. A default route tells the router where to forward a packet if
there is no route found for specific destination.
• In case there are multiple path existing to reach the same destination, router can make decision
based on the following information. Routes can be statically configured or dynamically learnt.
One route can be configured to be preferred over others. Most of the traffic on the internet and
intranets known as unicast data or unicast traffic is sent with specified destination. Routing
unicast data over the internet is called unicast routing.
• It is the simplest form of routing because the destination is already known. Hence the router
just has to look up the routing table and forward the packet to next hop.
• Multicasting in computer network is a group communication, where a sender(s)send data to
multiple receivers simultaneously. It supports one – to – many and many – to – many data
transmission across LANs or WANs. Through the process of multicasting, the communication
and processing overhead of sending the same data packet or data frame in minimized.
• Multicast IP Routing protocols are used to distribute data (for example, audio/video streaming
broadcasts) to multiple recipients. Using multicast, a source can send a single copy of data to a
single multicast address, which is then distributed to an entire group of recipients.
• The key difference between broadcast and multicast is that in the broadcast the packet is
delivered to all the host connected to the network whereas, in multicast packet is delivered to
intended recipients only.
• Multicast Message. Multicasting identifies logical groups of computers. A single message can
then be sent to the group. Multicast Message. Multicasting uses the Internet Group Management
Protocol (IGMP) to identify groups and group members.
Page | 60
(a) UNICAST ROUTING PROTOCOL
Page | 61
PROGRAM:
set ns [new Simulator]
exit 3 }
Page | 62
$ns duplex-link-op $n3 $n5 orient left-up
$ns duplex-link-op $n4 $n5 orient right-up
#Setup a TCP connection
set tcp [new Agent/TCP/Newreno]
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink/DelAck]
$ns attach-agent $n5 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
#Setup a FTP over TCP connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
$ns rtmodel-at 1.0 down $n1 $n4
$ns rtmodel-at 4.5 up $n1 $n4
$ns at 0.1 "$ftp start"
$ns at 6.0 "finish"
$ns run
OUTPUT:
Page | 63
(b) MULTICASTING ROUTING PROTOCOL
Page | 64
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 [Link] w]
$ns trace-all $tf
# 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]
# Create links
$ns duplex-link $n0 $n2 1.5Mb 10ms DropTail
$ns duplex-link $n1 $n2 1.5Mb 10ms DropTail
$ns duplex-link $n2 $n3 1.5Mb 10ms DropTail
$ns duplex-link $n3 $n4 1.5Mb 10ms DropTail
$ns duplex-link $n3 $n7 1.5Mb 10ms DropTail
$ns duplex-link $n4 $n5 1.5Mb 10ms DropTail
$ns duplex-link $n4 $n6 1.5Mb 10ms DropTail
# Routing protocol: say distance vector Protocols: CtrMcast, DM, ST, BST
set mproto DM
set mrthandle [$ns mrtproto $mproto {}]
Page | 65
$udp0 set dst_addr_ $group1
$udp0 set dst_port_ 0
set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp0\
# Transport agent for the traffic source set udp1 [new Agent/UDP]
# Create receiver
set rcvr1 [new Agent/Null]
$ns attach-agent $n5 $rcvr1
$ns at 1.0 "$n5 join-group $rcvr1 $group1"
set rcvr2 [new Agent/Null]
$ns attach-agent $n6 $rcvr2
$ns at 1.5 "$n6 join-group $rcvr2 $group1"
set rcvr3 [new Agent/Null]
$ns attach-agent $n7 $rcvr3
$ns at 2.0 "$n7 join-group $rcvr3 $group1"
# For nam
#Colors for packets from two mcast groups
$ns color 10 red
$ns color 11 green
$ns color 30 purple
$ns color 31 green
# Manual layout: order of the link is significant!
#$ns duplex-link-op $n0 $n1 orient right
#$ns duplex-link-op $n0 $n2 orient right-up
#$ns duplex-link-op $n0 $n3 orient right-down
# Show queue on simplex link n0->n1
#$ns duplex-link-op $n2 $n3 queuePos 0.5
# Group 0 source
$udp0 set fid_ 10
$n0 color red
$n0 label "Source 1"
# Group 1 source
$udp1 set fid_ 11
$n1 color green
$n1 label "Source 2"
$n5 label "Receiver 1"
Page | 67
OUTPUT:
Page | 68