CS 8581-Lab-Manual

Download as pdf or txt
Download as pdf or txt
You are on page 1of 39

1

Ex: No 1 Basic Networking Commands


Aim:
To study the basic networking commands.

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)

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.
Navigate to the CD ROM drive letter and open the support\tools folder on the XP CD and
click the setup.exe icon in the support\tools folder.
2

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, and FTP.

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:\>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:\>ping: Ping is the most basic TCP/IP command, and it’s the same as placing a phone
call to your best friend. You pick up your telephone and dial a number, expecting your best
friend to reply with “Hello” on the other end. Computers make phone calls to each other
over a network by using a Ping command. The Ping commands main purpose is to place
a phone call to another computer on the network, and request an answer. Ping has 2 options
it can use to place a phone call to another computer on the network. It can use the
computers name or IP address.

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.

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.

RESULT:

Outcome:
Thus the student can know to implement networking comments using comments.
3

Application:
(1) IP routing
(2) Internet Control Message Protocol

Viva voce:

1) What is a Link?

2) What are the layers of the OSI reference model?

3) What is backbone network?

4) What is a LAN?

5) What is a node?
4

EXP: 2 FILE DOWNLOAD USING HTTP


Aim
To Write a C Program to down load the file using HTTP
Algorithm:

1.Create a URL object and pass url as string to download the webpage.
URL example = new URL(pass url of webpage you want to download)
2. Create Buffered Reader object and pass getInputStream() Method of URL in Input
Stream object.
3. Create a string object to read each line one by one from stream.
4. Write each line in html file where webpage will be downloaded.
5. Close all objects.
6. Catch exceptions if url failed to download.

Program:
Client2.java

import javax.swing.*;
import java.net.*;
import java.awt.image.*;
import javax.imageio.*;
import java.io.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Client2{
public static void main(String args[]) throws Exception{
Socket soc;
BufferedImage img = null;
soc=new Socket("localhost",4000);
System.out.println("Client is running. ");
try {
System.out.println("Reading image from disk. ");
img = ImageIO.read(new File("intel.jpg"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(img, "jpg", baos);
baos.flush();
byte[] bytes = baos.toByteArray();
baos.close();
System.out.println("Sending image to server. ");
OutputStream out = soc.getOutputStream();
DataOutputStream dos = new DataOutputStream(out);
dos.writeInt(bytes.length);
dos.write(bytes, 0, bytes.length);
5

System.out.println("Image sent to server. ");


dos.close();
out.close();
}
catch (Exception e)
{
System.out.println("Exception: " + e.getMessage());
soc.close();
}
soc.close();
}
}

Program:

Server2.java

import java.net.*;
import java.io.*;
import java.awt.image.*;
import javax.imageio.*;
import javax.swing.*;
class Server2 {
public static void main(String args[]) throws Exception{
ServerSocket server=null;
Socket socket;
server=new ServerSocket(4000);
System.out.println("Server Waiting for image");
socket=server.accept();
System.out.println("Client connected.");
InputStream in = socket.getInputStream();
DataInputStream dis = new DataInputStream(in);
int len = dis.readInt();
System.out.println("Image Size: " + len/1024 + "KB");
byte[] data = new byte[len];
dis.readFully(data);
dis.close();
in.close();
InputStream ian = new ByteArrayInputStream(data);
BufferedImage bImage = ImageIO.read(ian);
JFrame f = new JFrame("Server");
ImageIcon icon = new ImageIcon(bImage);
JLabel l = new JLabel();
l.setIcon(icon);
f.add(l);
f.pack();
f.setVisible(true);
}
}
6

Result:

Outcome:

Thus the student can know to implement C Program to download the file using HTTP.

Application:

(1). Download files

Viva voce:

1.HTML stands forAs

2.What type of language is HTML?

3. What does an HTML document describe?

4.Links in HTML are defined with what tag?

5.How many heading styles are there in HTML?

6 .What are the headings in HTML?


7

EXP: 3A SOCKET PROGRAM FOR ECHO.

AIM

To write a socket program for implementation of echo.


ALGORITHM
Client Side
1. Start the program.
2. Create a socket which binds the Ip address of server and the port address to acquire
service.
3. After establishing connection send a data to server.
4. Receive and print the same data from server.
5. Close the socket.
6. End the program.

Server Side
1. Start the program.
2. Create a server socket to activate the port address.
3. Create a socket for the server socket which accepts the connection.
4. After establishing connection receive the data from client.
5. Print and send the same data to client.
6. Close the socket.
7. End the program.

Program
Echo Client
import java.io.*;
import java.net.*;
import java.util.*;
public class echoclient
{
public static void main(String args[])throws Exception
{
8

Socket c=null;
DataInputStream usr_inp=null;
DataInputStream din=new DataInputStream(System.in);
DataOutputStream dout=null;
try
{
c=new Socket("127.0.0.1",5678);
usr_inp=new DataInputStream(c.getInputStream());
dout=new DataOutputStream(c.getOutputStream());
}
catch(IOException e)
{
}
if(c!=null || usr_inp!=null || dout!=null)
{
String unip;
while((unip=din.readLine())!=null)
{
dout.writeBytes(""+unip);
dout.writeBytes("\n");
System.out.println("\n the echoed message");
System.out.println(usr_inp.readLine());
System.out.println("\n enter your message");
}
System.exit(0);
}
din.close();
usr_inp.close();
c.close();
}
}
Program:
9

Echo Server:
import java.io.*;
import java.net.*;
public class echoserver
{

public static void main(String args[])throws Exception


{
ServerSocket m=null;
Socket c=null;
DataInputStream usr_inp=null;
DataInputStream din=new DataInputStream(System.in);
DataOutputStream dout=null;
try
{
m=new ServerSocket(5678);
c=m.accept();
usr_inp=new DataInputStream(c.getInputStream());
dout=new DataOutputStream(c.getOutputStream());
}
catch(IOException e)
{}
if(c!=null || usr_inp!=null)
{
String unip;
while(true)
{
System.out.println("\nMessage from Client...");
String m1=(usr_inp.readLine());
System.out.println(m1);
dout.writeBytes(""+m1);
dout.writeBytes("\n");
10

}
}
dout.close();
usr_inp.close();
c.close();
}
}

Result:

Outcome:
Thus the student can know to implement a socket program for implementation of
echo.
Application:
(1) Create data form server
Viva voce:
1. What are functions of different layers?
2. Differentiate between TCP/IP Layers and OSI Layers
3. Why header is required?
4. What is the use of adding header and trailer to frames?

.
11

EXP: 3B SOCKET PROGRAM FOR CHAT.

AIM
To write a socket program for implementation of chat.

ALGORITHM
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.

Program
//talkclient.java
import java.io.*;
import java.net.*;
public class talkclient
{
public static void main(String args[])throws Exception
{
Socket c=null;
DataInputStream usr_inp=null;
DataInputStream din=new DataInputStream(System.in);
DataOutputStream dout=null;
try
{
c=new Socket("127.0.0.1",1234);
usr_inp=new DataInputStream(c.getInputStream());
dout=new DataOutputStream(c.getOutputStream());
}
catch(IOException e)
{}
12

if(c!=null || usr_inp!=null || dout!=null)


{
String unip;
System.out.println("\nEnter the message for server:");
while((unip=din.readLine())!=null)
{
dout.writeBytes(""+unip);
dout.writeBytes("\n");
System.out.println("reply");
System.out.println(usr_inp.readLine());
System.out.println("\n enter your message:");
}
System.exit(0);
}
din.close();
usr_inp.close();
c.close();
}
}

Program
//talkserver.java
import java.io.*;
import java.net.*;
public class talkserver
{
public static void main(String args[])throws Exception
{
ServerSocket m=null;
Socket c=null;
DataInputStream usr_inp=null;
DataInputStream din=new DataInputStream(System.in);
13

DataOutputStream dout=null;
try
{
m=new ServerSocket(1234);
c=m.accept();
usr_inp=new DataInputStream(c.getInputStream());
dout=new DataOutputStream(c.getOutputStream());
}
catch(IOException e)
{}
if(c!=null||usr_inp!=null)
{
String unip;
while(true)
{
System.out.println("\nmessage from client:");
String m1=usr_inp.readLine();
System.out.println(m1);
System.out.println("enter your message:");
unip=din.readLine();
dout.writeBytes(""+unip);
dout.writeBytes("\n");
}
}
dout.close();
usr_inp.close();
c.close();
}}
Result:
14

Outcome:
Thus the student can know to implement a client-server application for chat using
TCP.
Application:
(1)Facebook
(2)Gmail
Viva voce:
1. What Are The Two Broad Classes Of Middleware In Client Server Environment?
2. What Are General Middleware In Client Server Environment?
3. What Are The Five Major Technologies That Can Be Used To Create Client/server
Applications In Client Server Environment?
4. What Are All The Base Services Provided By The Os In Client Server Environment?
5. What Are Super Servers In Client Server Environment?
15

EXP: 3C FILE TRANSFER IN CLIENT & SERVER

AIM
To Perform File Transfer in Client & Server Using TCP/IP.
Algorithm:

1) Start the program.


2) Write program for client program.
3) Inside client package use objects of DataInputStream class and DataOutputStream class.
4) In server program by creating object for FileInputStream transfer data from file to byte
array.
5) Using object of BufferedReader class send the byte array to the client system.
6) Run client program then run server program.
7) Get the output.
8) Stop the program.

Program:
Clientfile.java
import java.io.*;
import java.net.*;
import java.util.*;
class Clientfile
{
public static void main(String args[])
{
try
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
Socket clsct=new Socket("127.0.0.1",9191);
DataInputStream din=new DataInputStream(clsct.getInputStream());
DataOutputStream dout=new DataOutputStream(clsct.getOutputStream());
16

System.out.println("Enter the file name:");


String str=in.readLine();
dout.writeBytes(str+'\n');
System.out.println("Enter the new file name:\n(First file content copied to this new file)");
String str2=in.readLine();
String str1,ss;
FileWriter f=new FileWriter(str2);
char buffer[];
while(true)
{
str1=din.readLine();
if(str1.equals("-1")) break;
System.out.println(str1);
buffer=new char[str1.length()];
str1.getChars(0,str1.length(),buffer,0);
f.write(buffer);
}
f.close();
clsct.close();
}
catch (Exception e)
{
System.out.println(e);
}
}
}

Program:
Serverfile.java
import java.io.*;
import java.net.*;
import java.util.*;
17

class Serverfile
{
public static void main(String args[])
{
try
{
ServerSocket obj=new ServerSocket(9191);
while(true)
{
Socket obj1=obj.accept();
DataInputStream din=new DataInputStream(obj1.getInputStream());
DataOutputStream dout=new DataOutputStream(obj1.getOutputStream());
String str=din.readLine();
FileReader f=new FileReader(str);
BufferedReader b=new BufferedReader(f);
String s;
while((s=b.readLine())!=null)
{
System.out.println(s);
dout.writeBytes(s+'\n');
}
f.close();
dout.writeBytes("-1\n");
}
}
catch(Exception e)
{
System.out.println(e);}
}
}
18

RESULT:

Outcome:
Thus the student can know to implement File Transfer in Client & Server Using
TCP/IP.
Application:
(1) Terminals
Viva voce:
1. Can we create logs for ftp authenticated sessions ?
2. How to deny specific users access to the FTP server ?
3. Local users cannot log in. How to resolve this issue?
4. What is FTP ?
19

Ex No: 4 Program for Domain Name System (DNS) using UDP sockets

Aim:
To write a java program to simulate DNS using UDP sockets
Algorithm:
Server
1. Create two ports, server port and client port.
2. Create a datagram socket and bind it to client port.
3. Create a datagram packet to receive client message.
4. Wait for client's data and accept it.
5. Read Client's message.
6. Get data from user.
7. Create a datagram packet and send message through server port.
8. Repeat steps 3-7 until the client has something to send.
9. Close the server socket.
10. Stop.
Client
1. Create two ports, server port and client port.
2. Create a datagram socket and bind it to server port.
3. Get data from user.
4. Create a datagram packet and send data with server ip address and client port.
5. Create a datagram packet to receive server message.
6. Read server's response and display it.
7. Repeat steps 3-6 until there is some text to send.
8. Close the client socket.
9. Stop.

Program:
//Clientdns12.java
import java.io.*;
import java.net.*;
import java.util.*;
20

class Clientdns12
{

public static void main(String args[])


{
try
{
DatagramSocket client=new DatagramSocket();
InetAddress addr=InetAddress.getByName("127.0.0.1");
byte[] sendbyte=new byte[1024];
byte[] receivebyte=new byte[1024];
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the DOMAIN NAME or IP adress:");
String str=in.readLine();
sendbyte=str.getBytes();
DatagramPacket sender=new DatagramPacket(sendbyte,sendbyte.length,addr,1309);
client.send(sender);
DatagramPacket receiver=new DatagramPacket(receivebyte,receivebyte.length);
client.receive(receiver);
String s=new String(receiver.getData());
System.out.println("IP address or DOMAIN NAME: "+s.trim());
client.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}

//Serverdns12.java
import java.io.*;
import java.net.*;
21

import java.util.*;
class Serverdns12
{
public static void main(String args[])
{
try
{
DatagramSocket server=new DatagramSocket(1309);
while(true)
{
byte[] sendbyte=new byte[1024];
byte[] receivebyte=new byte[1024]
DatagramPacket receiver=new DatagramPacket(receivebyte,receivebyte.length);
server.receive(receiver);
String str=new String(receiver.getData());
String s=str.trim();
//System.out.println(s);
InetAddress addr=receiver.getAddress();
int port=receiver.getPort();
String ip[]={"165.165.80.80","165.165.79.1"};
String name[]={"www.aptitudeguru.com","www.downloadcyclone.blogspot.com"};
for(int i=0;i<ip.length;i++)
{
if(s.equals(ip[i]))
{
sendbyte=name[i].getBytes();
DatagramPacket sender=new
DatagramPacket(sendbyte,sendbyte.length,addr,port);
server.send(sender);
break;
}
else if(s.equals(name[i]))
{
22

sendbyte=ip[i].getBytes();
DatagramPacket sender=new
DatagramPacket(sendbyte,sendbyte.length,addr,port);
server.send(sender);
break;
}
}

break;
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}

RESULT:

Outcome:
Thus the student can know to simulate DNS using UDP sockets.
Application:
1. Finding the ip address for the particular web address and vice verse.
Viva voce:
1. Explain udp.
2. List out common tcp/ip protocols
23

Ex No: 5(a) Program for Address Resolutuion Protocol (ARP) using UDP

Aim:
To write a java program for simulating ARP protocols using TCP
ALGORITHM:

Client

1. Start the program


2. Using socket connection is established between client and server.
3. Get the IP address to be converted into MAC address.
4. Send this IP address to server.
5. Server returns the MAC address to client.

Server

1. Start the program


2. Accept the socket which is created by the client.
3. Server maintains the table in which IP and corresponding MAC addresses are stored.
4. Read the IP address which is send by the client.
5. Map the IP address with its MAC address and return the MAC address to client.

//Clientarp12.java
import java.io.*;
import java.net.*;
import java.util.*;
class Clientarp12
{
public static void main(String args[])
{
try
{
DatagramSocket client=new DatagramSocket();
InetAddress addr=InetAddress.getByName("127.0.0.1");

byte[] sendbyte=new byte[1024];


byte[] receivebyte=new byte[1024];
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the logical address (IP):");
String str=in.readLine();
sendbyte=str.getBytes();
DatagramPacket sender=new DatagramPacket(sendbyte,sendbyte.length,addr,1309);
client.send(sender);
DatagramPacket receiver=new DatagramPacket(receivebyte,receivebyte.length);
client.receive(receiver);
String s=new String(receiver.getData());
System.out.println("The Physical Address is(MAC): "+s.trim());
client.close();
}
catch(Exception e)
{
24

System.out.println(e);
}
}
}

//Serverarp12.java
import java.io.*;
import java.net.*;
import java.util.*;
class Serverarp12
{
public static void main(String args[])
{
try
{
DatagramSocket server=new DatagramSocket(1309);
while(true)
{
byte[] sendbyte=new byte[1024];
byte[] receivebyte=new byte[1024];
DatagramPacket receiver=new DatagramPacket(receivebyte,receivebyte.length);
server.receive(receiver);
String str=new String(receiver.getData());
String s=str.trim();
//System.out.println(s);
InetAddress addr=receiver.getAddress();
int port=receiver.getPort();
String ip[]={"165.165.80.80","165.165.79.1"};
String mac[]={"6A:08:AA:C2","8A:BC:E3:FA"};
for(int i=0;i<ip.length;i++)
{
if(s.equals(ip[i]))
{
sendbyte=mac[i].getBytes();
DatagramPacket sender=new DatagramPacket(sendbyte,sendbyte.length,addr,port);
server.send(sender);
break;
}
}
break;

}
}
catch(Exception e)
{
System.out.println(e);
}
}
}

Result:
25

Outcome:
Thus the student can know to write a java program to simulate address resolution protocol.
Application:
1. Masking

Viva voce:
1. Explain ARP.
2. To Which Osi Layer Does Arp Belong?
3. What Is The Use Of Arp?
26

Ex No: 5(b) Program for Reverse Address Resolutuion Protocol (RARP)


using UDP

Aim:
To write a java program for simulating RARP protocols using TCP
ALGORITHM:

Client

1. Start the program


2. Using socket connection is established between client and server.
3. Get the MAC address to be converted into IP address.
4. Send this MAC address to server.
5. Server returns the IP address to client.

Server

1. Start the program


2. Accept the socket which is created by the client.
3. Server maintains the table in which MAC and corresponding IP addresses are stored.
4. Read the MAC address which is send by the client.
5. Map the MAC address with its IP address and return the IP address to client.

// Clientrarp12.java
import java.io.*;
import java.net.*;
import java.util.*;
class Clientrarp12
{
public static void main(String args[])
{
try
{
DatagramSocket client=new DatagramSocket();
InetAddress addr=InetAddress.getByName("127.0.0.1");
byte[] sendbyte=new byte[1024];
byte[] receivebyte=new byte[1024];
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
27

System.out.println("Enter the Physical address (MAC):");


String str=in.readLine();
sendbyte=str.getBytes();
DatagramPacket sender=new
DatagramPacket(sendbyte,sendbyte.length,addr,1309);
client.send(sender);
DatagramPacket receiver=new
DatagramPacket(receivebyte,receivebyte.length);
client.receive(receiver);
String s=new String(receiver.getData());
System.out.println("The Logical Address is(IP): "+s.trim());
client.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}

// Serverrarp12.java
import java.io.*;
import java.net.*;
import java.util.*;
class Serverrarp12
{
public static void main(String args[])
{
try
{
DatagramSocket server=new DatagramSocket(1309);
while(true)
{
28

byte[] sendbyte=new byte[1024];


byte[] receivebyte=new byte[1024];
DatagramPacket receiver=new DatagramPacket(receivebyte,receivebyte.length);
server.receive(receiver);
String str=new String(receiver.getData());
String s=str.trim();
//System.out.println(s);
InetAddress addr=receiver.getAddress();
int port=receiver.getPort();
String ip[]={"165.165.80.80","165.165.79.1"};
String mac[]={"6A:08:AA:C2","8A:BC:E3:FA"};
for(int i=0;i<ip.length;i++)
{
if(s.equals(mac[i]))
{
sendbyte=ip[i].getBytes();
DatagramPacket sender=new
DatagramPacket(sendbyte,sendbyte.length,addr,port);
server.send(sender);
break;
}
}
break;
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
29

Result:

Outcome:
Thus the student can know to write a java program to simulate reverse address resolution
protocol.
Application:
1Masking
Viva voce:
1.Explain RARP.
2.To Which Osi Layer Does Arp Belong?
3.What Is the Use Of Rarp?
30

EX NO. 6 SIMULATION OF CONGESTION CONTROL ALGORITHM

AIM:
To simulate a link failure and observe the congestion control algorithm using NS2.

ALGORITHM:

1. Create a simulation object


2. Set routing protocol to routing
3. Trace packets and all links onto NAM trace and to trace file
4. Create right nodes
5. Describe their layout topology as octagon
6. Add a sink agent to node
7. Connect source and sink.

PROGRAM:
set ns [new Simulator]
set nr [open thro_red.tr w]
$ns trace-all $nr
set nf [open thro.nam w]
$ns namtrace-all $nf proc finish { } { global ns nr nf
$ns flush-trace close $nf
close $nr
exec nam thro.nam &
exit 0 }
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]
$ns duplex-link $n0 $n3 1Mb 10ms RED
$ns duplex-link $n1 $n3 1Mb 10ms RED
$ns duplex-link $n2 $n3 1Mb 10ms RED
$ns duplex-link $n3 $n4 1Mb 10ms RED
$ns duplex-link $n4 $n5 1Mb 10ms RED
31

$ns duplex-link $n4 $n6 1Mb 10ms RED


$ns duplex-link $n4 $n7 1Mb 10ms RED
$ns duplex-link-op $n0 $n3 orient right-up
$ns duplex-link-op $n3 $n4 orient middle
$ns duplex-link-op $n2 $n3 orient
right-down
$ns duplex-link-op $n4 $n5 orient
right-up
$ns duplex-link-op $n4 $n7 orient
right-down
$ns duplex-link-op $n1 $n3
orient right
$ns duplex-link-op $n6 $n4
orient left set udp0 [new
Agent/UDP]
$ns attach-agent $n2
$udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent
$udp0 set null0
[new Agent/Null]
$ns attach-agent $n5 $null0
$ns connect $udp0
$null0 set udp1 [new
Agent/UDP]
$ns attach-agent $n1 $udp1
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 500
$cbr1 set interval_ 0.005
32

$cbr1 attach-agent
$udp1 set null0
[new Agent/Null]
$ns attach-agent $n6 $null0
$ns connect $udp1
$null0 set udp2 [new
Agent/UDP]
$ns attach-agent $n0 $udp2
set cbr2 [new Application/Traffic/CBR]
$cbr2 set packet size_ 500
$cbr2 set interval_ 0.005
$cbr2 attach-agent
$udp2 set null0
[new Agent/Null]
$ns attach-agent $n7 $null0
$ns connect $udp2 $null0
$udp0 set fid_ 1
$udp1 set fid_ 2
$udp2 set fid_ 3
$ns color 1 Red
$ns color 2 Green
$ns color 2 Blue
$ns at 0.1 "$cbr0 start"
$ns at 0.2 "$cbr1 start"
$ns at 0.5 "$cbr2 start"
$ns at 4.0 "$cbr2 stop"
$ns at 4.2 "$cbr1 stop"
$ns at 4.5 "$cbr0 stop"
$ns at 5.0 "finish"
$ns run
Result:
33

Outcome:
Thus the student can know congestion control algorithm is simulated by using NS2
Application:
1. Marketing
Viva voce:
1. What is the difference between physical topology and logical topology?
2. What is the Packet Sniffer?
34

EX NO: 7(A) SIMULATION OF DISTANCE VECTOR


ROUTING ALGORITHM
Aim:
To simulate and study the Distance Vector routing algorithm using simulation.

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:
set ns [new Simulator]
set nr [open thro.tr w]
$ns trace-all $nr
set nf [open thro.nam w]
$ns namtrace-all $nf proc finish { } {
global ns nr nf
$ns flush-trace close $nf
close $nr
exec nam thro.nam &
exit 0
}
for { set i 0 } { $i < 12} { incr i 1 } {
set n($i) [$ns node]}
for {set i 0} {$i < 8} {incr i} {
35

$ns duplex-link $n($i) $n([expr $i+1]) 1Mb 10ms DropTail }


$ns duplex-link $n(0) $n(8) 1Mb 10ms DropTail
$ns duplex-link $n(1) $n(10) 1Mb 10ms DropTail
$ns duplex-link $n(0) $n(9) 1Mb 10ms DropTail
$ns duplex-link $n(9) $n(11) 1Mb 10ms DropTail
$ns duplex-link $n(10) $n(11) 1Mb 10ms DropTail
$ns duplex-link $n(11) $n(5) 1Mb 10ms DropTail
set udp0 [new Agent/UDP]
$ns attach-agent $n(0) $udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent
$udp0 set null0 [new
Agent/Null]
$ns attach-agent $n(5) $null0
$ns connect $udp0 $null0
set udp1 [new Agent/UDP]
$ns attach-agent $n(1) $udp1
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 500
$cbr1 set interval_ 0.005
$cbr1 attach-agent
$udp1 set null0 [new
Agent/Null]
$ns attach-agent $n(5) $null0
$ns connect $udp1 $null0
$ns rtproto DV
$ns rtmodel-at 10.0 down $n(11) $n(5)
$ns rtmodel-at 15.0 down $n(7) $n(6)
$ns rtmodel-at 30.0 up $n(11) $n(5)
$ns rtmodel-at 20.0 up $n(7) $n(6)
$udp0 set fid_ 1
36

$udp1 set fid_ 2


$ns color 1 Red
$ns color 2 Green
$ns at 1.0 "$cbr0 start"
$ns at 2.0 "$cbr1 start"
$ns at 45 "finish"
$ns run

RESULT:

Outcome:
Thus the student can know to write Distance vector Routing Algorithm
Application:
1. Mobile Nodes
Viva voce:
1. Compare connection oriented and connection less protocols.
2.What is MTU?
3.Explain the working of Distance vector routing.
4.Differentiate Proactive and Reactive routing Protocols.
5.What are the different attributes for calculating the cost of a path?
37

EX NO: 7(B) SIMULATION OF LINK STATE ROUTING


ALGORITHM
Aim:
To simulate and study the link state routing algorithm using simulation.

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]
set nr [open thro.tr w]
$ns trace-all $nr
set nf [open thro.nam w]
$ns namtrace-all $nf proc finish { } { global ns nr nf
$ns flush-trace close $nf
close $nr
exec nam thro.nam &
exit 0
}
for { set i 0 } { $i < 12} { incr i 1 } {
set n($i) [$ns node]}
for {set i 0} {$i < 8} {incr i} {
$ns duplex-link $n($i) $n([expr $i+1]) 1Mb 10ms DropTail }
38

$ns duplex-link $n(0) $n(8) 1Mb 10ms DropTail


$ns duplex-link $n(1) $n(10) 1Mb 10ms DropTail
$ns duplex-link $n(0) $n(9) 1Mb 10ms DropTail
$ns duplex-link $n(9) $n(11) 1Mb 10ms DropTail
$ns duplex-link $n(10) $n(11) 1Mb 10ms DropTail
$ns duplex-link $n(11) $n(5) 1Mb 10ms DropTail
set udp0 [new Agent/UDP]
$ns attach-agent $n(0) $udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent
$udp0 set null0 [new
Agent/Null]
$ns attach-agent $n(5) $null0
$ns connect $udp0 $null0
set udp1 [new Agent/UDP]
$ns attach-agent $n(1) $udp1
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 500
$cbr1 set interval_ 0.005
$cbr1 attach-agent
$udp1 set null0 [new
Agent/Null]
$ns attach-agent $n(5) $null0
$ns connect $udp1 $null0
$ns rtproto LS
$ns rtmodel-at 10.0 down $n(11) $n(5)
$ns rtmodel-at 15.0 down $n(7) $n(6)
$ns rtmodel-at 30.0 up $n(11) $n(5)
$ns rtmodel-at 20.0 up $n(7) $n(6)
$udp0 set fid_ 1
$udp1 set fid_ 2
$ns color 1 Red
39

$ns color 2 Green


$ns at 1.0 "$cbr0 start"
$ns at 2.0 "$cbr1 start"
$ns at 45 "finish"
$ns run

RESULT:

Outcome:
Thus the student can know to simulate and study the link state routing algorithm.
Application:
1. Connections between node
Viva Questions:
1. What is Routing?
2. What is Dynamic rouitng?
3. What are the two steps in link state routing?
4. Compare link state and Distance Vector routing
5. What are all the route metric used in Link state routing?

You might also like