CS8581 Networks Lab Manual Final
CS8581 Networks Lab Manual Final
LIST OF EXPERIMENTS
1. Learn to use commands like tcpdump, netstat, ifconfig, nslookup and traceroute.
Capture ping and traceroute PDUs using a network protocol analyzer and examine.
2. Write a HTTP web client program to download a web page using TCP sockets.
1
EX.NO : 1
Learn To Use Commands Like Tcpdump, Netstat, Ifconfig, Nslookup And Protocol Tracerout
DATE:
AIM: To learn to use commands like tcpdump, netstat, ifconfig, nslookup and protocol traceroute. Capture
ping and traceroute PDUs using a network analyzer and examine.
The tcpdump utility allows you to capture packets that flow within your network to assist in network trouble-
shooting. The following are several examples of using tcpdump with different options. Traffic is captured based on a
specified filter.
Netstat:
Netstat is a common command line TCP/IP networking available in most versions of Windows, Linux, UNIX and
other operating systems.
Netstat provides information and statistics about protocols in use and current TCP/IP network connections.
ipconfig :
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.
From the command prompt, type ipconfig to run the utility with default options. The output of the default command
contains the IP address, network mask, and gateway for all physical and virtual network adapter .
nslookup :
The nslookup (which stands for name server lookup) command is a network utility program used to obtain infor-
mation about internet servers. It finds name server information for domains by querying the Domain Name System .
Trace route:
Traceroute is a network diagnostic tool used to track the pathway taken by a packet on an IP network from source
to destination. Traceroute also records the time taken for each hop the packet makes during its route to the
destination
Commands:
Tcpdump:
Display traffic between 2 hosts:
To display all traffic between two hosts (represented by variables host1 and host2): # tcpdump host host1 and
host2
2
Display traffic from a source or destination host only:
To display traffic from only a source (src) or destination (dst) host: #
tcpdump src host
# tcpdump dst host
Display traffic for a specific protocol
Provide the protocol as an argument to display only traffic for a specific protocol, for example tcp, udp,
icmp, arp
# tcpdump protocol
For example to display traffic only for the tcp traffic :
# tcpdump tcp
Filtering based on source or destination port
To filter based on a source or destination port:
# tcpdump src port ftp
# tcpdump dst port http
2.Netstat
Netstat is a common command line TCP/IP networking available in most versions of
Windows, Linux, IX UNand other operating systems.
Netstat provides information and statistics about protocols in use and current TCP/IP network
connections. The Windows help screen (analogous to a Linux or UNIX for netstat reads as follows:
displays protocol statisticscurrent
and TCP/IP network connections.
#netstat
3. ipconfig
In Windows, ipconfigis 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.
3
From the command prompt, type ipconfig to run the utility with default options. The output of the
default command contains the IP address, network mask, and gateway for all physical and virtual net-
work adapter.
#ipconfig
4.nslookup
The nslookup (which stands for name server lookup) command is a network utility program used
to obtain information about internet servers. It finds name server information for domains by querying
the Domain Name System.
The nslookup command is a powerful tool for diagnosing DNS problems. You know you're expe-
riencing a DNS problem when you can access a resource by specifying its IP address but not its DNS
name.
#nslookup
5.Trace route:
Traceroute uses Internet Control Message Protocol (ICMP) echo packets with variable time to live
(TTL) values. The response time of each hop is calculated. To guarantee accuracy, each hop is queried
multiple times (usually three times) to better measure the response of that particular hop.
Traceroute is a network diagnostic tool used to track the pathway taken by a packet on an IP network
from source to destination. Traceroute also records the time taken for each hop the packet makes during
its route to the destination. Traceroute uses Internet Control Message Protocol (ICMP) echo packets
with variable time to live (TTL) values.
The response time of each hop is calculated. To guarantee accuracy, each hop is queried mul-
tiple times (usually three times) to better measure the response of that particular hop. Traceroute sends
packets with TTL values that gradually increase from packet to packet, starting with TTL value of one.
Routers decrement TTL values of packets by one when routing and discard packets whose TTL value
has reached zero, returning the ICMP error message ICMP Time Exceeded.
For the first set of packets, the first router receives the packet, decrements the TTL value and
drops the packet because it then has TTL value zero. The router sends an ICMP Time Exceeded mes-
sage back to the source. The next set of packets are given a TTL value of two, so the first router
forwards the packets, but the second router drops them and replies with ICMP Time Exceeded.
4
Proceeding in this way, traceroute uses the returned ICMP Time Exceeded messages to build a list of
routers that packets traverse, until the destination is reached and returns an ICMP Echo Reply message.
With the tracert command shown above, we're asking tracert to show us the path from the local com-
puter all the way to the network device with the hostname
www.google.com.
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 and
software p roblems. Determining the status of the network and various foreign hosts. The ping
command is usually used as a simple way to verify that a computer can communicate over the network
with another computer or network device. The ping command operates by send ing Internet Control
Message Protocol (ICMP) Echo Request messages to the destination computer and waiting for a
response
# ping172.16.6.2
#tracert google.com
5
VIVA(Pre &Post Lab) QUESTIONS:
1. Define network
2. Define network topology
3. What is OSI Layers.
4. What is the use of netstat command?
5. What is nslookup command?
6. What is the purpose of traceroute command?
7. What is ping command.
RESULT:
Thus the various networks commands like tcpdump, netstat, ifconfig, nslookup and traceroute ping are
executed successfully.
6
EX.NO : 2
HTTP FOR WEB PAGE UPLOAD AND DOWNLOAD
DATE :
AIM:
To write a java program for socket for HTTP for web page upload and download .
ALGORITHM:
Client:
1. Start.
2. Create socket and establish the connection with the server.
3. Read the image to be uploaded from the disk
4. Send the image read to the server 5. Terminate the connection 6. Stop.
Server:
1. Start
2. Create socket, bind IP address and port number with the created socket and make server a listening server.
3. Accept the connection request from the client
4. Receive the image sent by the client.
5. Display the image.
6. Close the connection.
7. Stop.
7
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 Client
out.close();
}
catch (Exception e)
{
System.out.println("Exception: " + e.getMessage());
soc.close();
}
soc.close();
}
}
Server
10
OUTPUT:
1. What is URL.
2. Why is http required?
3. What id http client?
4. what is WWW?
5. Compare HTTP and FTP.
6. Define Socket.
7. What do you mean by active web page?
8. What are the four Main properties of HTTP?
.
RESULT:
Thus the socket program for HTTP for web page upload and download was developed and exe-
cuted successfully.
11
AIM:
To write a java program for application using TCP Socket
ALGORITHM
Client
1. Start
2. Create the TCP socket
3. Establish connection with the server
4. Get the message to be echoed from the user
12
Server
1. Start
2. create TCP socket make it a listening Socket
3.Accept the connection request sent by the client for connection establishment
4. Receive the message sent by the client
5. Display the received message
6. Send the received message to the client from which it receives
7. Close the connection when client initiates termination and server becomes a listening server,
8. waiting for clients.
PROGRAM:
EchoServer.java
Create TCP socket, make it a listening socket
import java.net.*;
import java.io.*;
public class EServer
public static void main(String args[])
{
ServerSocket s=null;
String line;
DataInputStream is;
PrintStream ps;
Socket c=null;
try
{
s=new ServerSocket(9000);
}
catch(IOException e)
{
13
14
EClient.java
import java.net.*;
import java.io.*;
public class ECl ient
public static void main(String arg[])
{
Socket c=null;
String line;
DataInputStream is,is1;
PrintStream os;
try
{
InetAddress ia = InetAddress.getLocalHost();
c=new Socket(ia,9000);
}
catch(IOException e)
{
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)
{
15
}}
OUTPUT
Server
C:\Program Files\Java\jdk1.5.0\bin>javac EServer.java
C:\Program Files\Java\jdk1.5.0\bin>java EServer
C:\Program Files\Java\jdk1.5.0\bin>
Client
C:\Program Files\Java\jdk1.5.0\bin>javac EClient.java
C:\Program Files\Java\jdk1.5.0\bin>java EClient
Client: Hai Server
Server:Hai Server
Client: Hello
Server:Hello
Client:end
Server:end
Client:ds
Socket Closed!
B.Chat
ALGORITHM
Client
2. Create the UDP datagram socket
1. Start
3. Get the request message to be sent
from the user
4. Send the request message to the server
5. If the request message is “END” go to step 10
6. Wait for the reply message from the server
7. Receive the reply message sent by the server
8. Display the reply message received from the server
9. Repeat the steps from 3 to 8
10. Stop
Server
1. Start
2. Create UDP datagram socket, make it a listening socket
3. Receive the request message sent by the client
4. If the received message is “END” go to step 10
16
PROGRAM
UDPserver.java
import java.io.*;
import java.net.*;
class UDPserver
{
public static DatagramSocket ds;
public static byte buffer[]=new byte[1024];
public static int clientport=789,serverport=790;
public static void main(String args[])throws Exception
{
ds=new DatagramSocket(clientport);
System.out.println("press ctrl+c to quit the program");
BufferedReader dis=new BufferedReader(new InputStreamReader(System.in));
InetAddress ia=InetAddress.geyLocalHost();
while(true)
{
DatagramPacket p=new DatagramPacket(buffer,buffer.length);
ds.receive(p);
String psx=new String(p.getData(),0,p.getLength());
System.out.println("Client:" + psx);
System.out.println("Server:");
String str=dis.readLine();
if(str.equals("end"))
break;
buffer=str.getBytes();
ds.send(new DatagramPacket(buffer,str.length(),ia,serverport));
}
}
}
UDPclient.java
import java .io.*;
import java.net.*;
class UDPclient
17
Client
PROGRAM
File Server : import java.io.BufferedInputStream;
18
19
}
contents = new byte[size];
bis.read(contents, 0, size);
os.write(contents);
System.out.print("Sending file ... "+(current*100)/fileLength+"% complete!");
}
os.flush();
//File transfer done. Close the socket connection!
socket.close(); ssock.close();
File Client:
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.Socket;
20
socket.close();
System.out.println("File saved successfully!");
}
}
Output
server
21
E:\nwlab>client
E:\nwlab>java FileClient
File saved successfully!
E:\nwlab>
1. What is LAN.
2. Mention the roles of Transport layer.
3. State the differences between TCP and UDP
4. What are well-known ports?
5. What are MAC addresses?
6. What is TCP Echo Client Server?
7. Define the three states of TCP Connection establishment and termination.
8. List the types of sockets
RESULT:
Thus the java application program using TCP Sockets was developed and executed successfully.
22
AIM:
• The Domain Name System (DNS) is a hierarchical decentralized naming system for computers,
services, or other resources connected to the Internet or a private network. It associates various
information with domain names assigned to each of the participating entities.
• The domain name space refers a hierarchy in the internet naming structure. This hierarchy has
multiple levels (from 0 to 127), with a root at the top. The following diagram shows the domain
name space hierarchy.
• Name server contains the DNS database. This database comprises of various names and their
corresponding IP addresses. Since it is not possible for a single server to maintain entire DNS
database, therefore, the information is distributed among many DNS servers.
• Types of Name Servers
• Root Server is the top level server which consists of the entire DNS tree. It does not contain the
information about domains but delegates the authority to the other server
• Primary Server stores a file about its zone. It has authority to create, maintain, and update the
zone file.
• Secondary Server transfers complete information about a zone from another server which may be
primary or secondary server. The secondary server does not have authority to create or update a
zone file.
• DNS is a TCP/IP protocol used on different platforms. The domain name space is divided into
three different sections: generic domains, country domains, and inverse domain.
• The main function of DNS is to translate domain names into IP Addresses, which computers can
understand. It also provides a list of mail servers which accept Emails for each domain name.
Each domain name in DNS will nominate a set of name servers to be authoritative for its DNS
records.
ALGORITHM Server
1. Start
2. Create UDP datagram socket
3. Create a table that maps host name and IP address
23
PROGRAM
DNS Server
java import java.io.*;
import java.net.*;
public class udpdnsserver
{
private static int indexOf(String[] array, String str)
{
str = str.trim();
for (int i=0; i < array.length; i++)
{
if (array[i].equals(str))
return i;
}
return -1;
}
public static void main(String arg[])throws IOException
{
String[] hosts = {"yahoo.com", "gmail.com","cricinfo.com", "facebook.com"};
String[] ip = {"68.180.206.184", "209.85.148.19","80.168.92.140", "69.63.189.16"};
System.out.println("Press Ctrl + C to Quit");
while (true)
5. Wait for the reply from the server
{
DatagramSocket serversocket=new DatagramSocket(1362);
byte[] senddata = new byte[1021];
24
25
OUTPUT
Server javac udpdnsserver.java
java udpdnsserver
Press Ctrl + C to Quit Request for host yahoo.com
Request for host youtube.com
Client
>javac udpdnsclient.java
>java udpdnsclient
Enter the hostname : yahoo.com
IP Address: 68.180.206.184
>java udpdnsclient
Enter the hostname : cricinfo.com
IP Address: 80.168.92.140
>java udpdnsclient
Enter the hostname : youtube.com
IP Address: Host Not Found
RESULT:
Thus the java application program using UDP Sockets to implement DNS was developed and executed
successful
26
DATE :
AIM :
To use a tool like Wireshark to capture packets and examine the packets.
PROCEDURE:
2.Open Wireshark and select the network interface you want to capture packets on.
4.Perform the actions you want to capture, such as browsing a website or sending an email.
Once you have captured packets, you can examine them in Wireshark by following these steps:
2.Expand the sections of the packet to view its details, such as the source and destination ad-
3.Use Wireshark's filters and search functions to locate specific packets or information within
packets.
4.Analyze the packet information to understand the network traffic and identify any issues or
anomalies.
RESULT:
Thus using wireshark the packets are captured and examined successfully.
27
Aim:
ALGORITHM:
SERVER
2. Listen for new connection and when a connection arrives, accept it.
9. Stop.
CLIENT
7. Stop.
28
import java.io.*;
import java.net.*;
import java.util.*;
class Clientarp
{
public static void main(String args[])
{
try
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
Socket clsct=new Socket("127.0.0.1",139);
DataInputStream din=new DataInputStream(clsct.getInputStream());
DataOutputStream dout=new DataOutputStream(clsct.getOutputStream());
System.out.println("Enter the Logical address(IP):");
String str1=in.readLine(); dout.writeBytes(str1+'\n');
String str=din.readLine();
System.out.println("The Physical Address is: "+str);
clsct.close();
}
catch (Exception e)
{
System.out.println(e);
}
}
}
Server:
import java.io.*;
import java.net.*;
29
class Serverarp
try
Socket obj1=obj.accept();
while(true)
String str=din.readLine();
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(str.equals(ip[i]))
dout.writeBytes(mac[i]+'\n');
break;
obj.close();
catch(Exception e)
System.out.println(e);
30
Output:
E:\networks>java Serverarp
E:\networks>java Clientarp
31
Server:
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)
{
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());
32
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
33
Result :
Thus the program for implementing to display simulating ARP /RARP protocols.
34
DATE:
AIM:
To Study Network simulator (NS).and Simulation of Congestion Control Algorithms using
NS
35
Packet loss
Packet loss occurs when one or more packets of data travelling across a computer network
fail to reach their destination. Packet loss is distinguished as one of the three main error types
encountered in digital communications; the other two being bit error and spurious packets caused
due to noise.
Packets can be lost in a network because they may be dropped when a queue in the network
node overflows. The amount of packet loss during the steady state is another important property
of a congestion control scheme. The larger the value of packet loss, the more difficult it is for
transportlayer protocols to maintain high bandwidths, the sensitivity to loss of individual packets,
36
Throughput
Throughput is the main performance measure characteristic, and most widely used. In com-
munication networks, such as Ethernet or packet radio, throughput or network throughput is the
average rate of successful message delivery over a communication channel. Throughput is usually
measured inbitsper second (bit/s orbps), and sometimes in data packets per second or data packets
per time slot. This measures how soon the receiver is able to get a certain amount of data send by
the sender. It is determined as the ratio of the total data received to the end to end delay. Through-
put is an important factor which directly impacts the network performance.
Delay
Delay is the time elapsed while a packet travels from one point e.g., source premise or
network ingress to destination premise or network degrees. The larger the value of delay, the more
difficult it is for transport layer protocols to maintain highbandwidths. We will calculate end to
end delay
Queue Length
A queuing system in networks can be described as packets arriving for service, waiting for
service if it is not immediate, and if having waited for service, leaving the system after being
served. Thus queue length is very important characteristic to determine that how well the active
queue management of the congestion control algorithm has been working.
Program:
include <wifi_lte/wifi_lte_rtable.h>
struct r_hist_entry *elm, *elm2; int
num_later = 1;
elm = STAILQ_FIRST(&r_hist_);
while (elm != NULL && num_later <= num_dup_acks_){
num_later;
elm = STAILQ_NEXT(elm, linfo_)
37
if (elm != NULL){
elm = findDataPacketInRecvHistory(STAILQ_NEXT(elm,linfo_));
STAILQ_REMOVE(&r_hist_,elm2,r_hist_entry,linfo_);
delete elm2;
} else
elm = elm2;
elm2 = STAILQ_NEXT(elm, linfo_);
}
}
}
}
void DCCPTFRCAgent::removeAcksRecvHistory(){
struct r_hist_entry *elm1 = STAILQ_FIRST(&r_hist_);
struct r_hist_entry *elm2;
int num_later = 1;
while (elm1 != NULL && num_later <= num_dup_acks_){
num_later;
elm1 = STAILQ_NEXT(elm1, linfo_);
}
if(elm1 == NULL)
return;
38
Result:
Thus we have Studied Network simulator (NS) and Simulation of Congestion Control Al-
gorithms using NS.
39
Ex.No: 8
Study Of TCP/UDP Performance Using Simulation Tool.
DATE:
AIM:
• TCP is reliable protocol. That is, the receiver always sends either positive or negative
acknowledgement about the data packet to the sender, so that the sender always has bright
clue about whether the data packet is reached the destination or it needs to resend it.
• TCP ensures that the data reaches intended destination in the same order it was sent.
• TCP is connection oriented. TCP requires that connection between two remote points be
established before sending actual data.
• TCP provides error-checking and recovery mechanism.
• TCP provides end-to-end communication.
• TCP provides flow control and quality of service.
• TCP operates in Client/Server point-to-point mode.
• TCP provides full duplex server, i.e. it can perform roles of both receiver and sender.
• The User Datagram Protocol (UDP) is simplest Transport Layer communication protocol
available of the TCP/IP protocol suite. It involves minimum amount of communication
mechanism. UDP is said to be an unreliable transport protocol but it uses IP services which
provides best effort delivery mechanism.UDP is used when acknowledgement of data does
not hold any significance.
• UDP is good protocol for data flowing in one direction.
• UDP is simple and suitable for query based communications.
• UDP is not connection oriented.
• UDP does not provide congestion control mechanism.
• UDP does not guarantee ordered delivery of data.
• UDP is stateless.
• UDP is suitable protocol for streaming applications such as VoIP, multimedia streaming.
TCP Performance
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.
40
7. Create the applications and attach them to the tcp agent.
8. Connect tcp and tcp sink.
9. Run the simulation.
PROGRAM:
41
$ns at 1.2 "$ftp start"
$ns at 1.35 "$ns detach-agent $n1 $tcp ; $ns detach-agent $n3 $sink"
$ns at 3.0 "finish" proc
finish {} {
global ns f nf
$ns flush-trace close $f close $nf
puts "Running nam.." exec xgraph tcpout.tr -
geometry 600x800 & exec nam tcpout.nam &
exit 0
}
$ns run
Output
42
UDP Performance
ALGORITHM :
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 udpout.tr w]
$ns trace -all $f
set nf [open udpout.nam 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 r ight- 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 $udp 1
43
$udp1 set class_ 0 set cbr1 [new Appli-
cation/Traffic/CBR] $cbr1 attach-agent
$udp1 set null0 [new Agent/Null] $ns
attach-agent $n1 $null0
44
Output:
RESULT :
45
EX.NO: 9
Simulate The Distance Vector/Link State Routing Protocols Using NS2
DATE:
AIM:
To simulate the Distance vector and link state routing protocols using NS2.
46
b. Flooding
Flooding is a simple routing algorithm in which every incoming packet is sent through
every outgoing link except the one it arrived on. Flooding is used in bridging and in systems such
as Usenet and peer-to-peer file sharing and as part of some routing protocols, including OSPF,
DVMRP, and those used in ad-hoc wireless networks.There are generally two types of flooding
available, Uncontrolled Flooding and Controlled Flooding. Uncontrolled Flooding is the fatal law
of flooding. All nodes have neighbours and route packets indefinitely. More than two neighbours
creates a broadcast storm.
Controlled Flooding has its own two algorithms to make it reliable, SNCF (Sequence Num-
ber Controlled Flooding) and RPF (Reverse Path Flooding). In SNCF, the node attaches its own
address and sequence number to the packet, since every node has a memory of addresses and se-
quence numbers. If it receives a packet in memory, it drops it immediately while in RPF, the node
will only send the packet forward. If it is received from the next node, it sends it back to the sender.
Method
Routers using distance-vector protocol do not have knowledge of the entire path to a destina-
tion. Instead they use two methods:
1. Direction in which router or exit interface a packet should be forwarded.
2. Distance from its destination
Distance-vector protocols are based on calculating the direction and distance to any link in
a network. "Direction" usually means the next hop address and the exit interface. "Distance" is a
measure of the cost to reach a certain node. The least cost route between any two nodes is the route
with minimum distance. Each node maintains a vector (table) of minimum distance to every node.
The cost of reaching a destination is calculated using various route metrics. RIP uses the hop count
47
of the destination whereas IGRP takes into account other information such as node delay and avail-
able bandwidth.
Updates are performed periodically in a distance-vector protocol where all or part of a rout-
er's routing table is sent to all its neighbors that are configured to use the same distancevector
routing protocol. RIP supports cross-platform distance vector routing whereas IGRP is a Cisco
Systems proprietary distance vector routing protocol. Once a router has this information it is able
to amend its own routing table to reflect the changes and then inform its neighbors of the changes.
This process has been described as ‗routing by rumor‘ because routers are relying on the infor-
mation they receive from other routers and cannot determine if the information is actually valid
and true. There are a number of features which can be used to help with instability and inaccurate
routing information.
EGP and BGP are not pure distance-vector routing protocols because a distance-vector
protocol calculates routes based only on link costs whereas in BGP, for example, the local route
preference value takes priority over the link cost.
Count-to-infinity problem
The Bellman–Ford algorithm does not prevent routing loops from happening and suffers
from the count-to-infinity problem. The core of the count-to-infinity problem is that if A tells B
that it has a path somewhere, there is no way for B to know if the path has B as a part of it. To see
the problem clearly, imagine a subnet connected like A–B–C–D–E–F, and let the metric between
the routers be "number of jumps". Now suppose that A is taken offline. In the vectorupdate-process
B notices that the route to A, which was distance 1, is down – B does not receive the vector update
from A. The problem is, B also gets an update from C, and C is still not aware of the fact that A is
down – so it tells B that A is only two jumps from C (C to B to A), which is false. This slowly
propagates through the network until it reaches infinity (in which case the algorithm corrects itself,
due to the relaxation property of Bellman–Ford).
ALGORITHM:
48
LINK STATE ROUTING PROTOCOL
PROGRAM
set ns [new Simulator] $ns
rtproto LS set nf [open link-
state.nam w]
$ns namtrace-all $nf
set f0 [open linkstate.tr w]
$ns trace-all $f0
proc finish {} {
global ns f0 nf
$ns flush-trace
close $f0
close $nf
exec nam linkstate.nam &
exit 0
}
for {set i 0} {$i <7} {incr i} {
set n($i) [$ns node]
}
for {set i 0} {$i <7} {incr i} {
$ns duplex-link $n($i) $n([expr ($i+1)%7]) 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(3) $null0
$ns connect $udp0 $null0
$ns at 0.5 "$cbr0 start"
$ns rtmodel-at 1.0 down $n(1) $n(2)
$ns rtmodel-at 2.0 up $n(1) $n(2)
49
$ns at 4.5 "$cbr0 stop"
$ns at 5.0 "finish"
$ns run
Output:
50
DISTANCE VECTOR ROUTING ALGORITHM
ALGORITHM:
1. Create a simulator object
2. Set routing protocol to Distance Vector routing
3. Trace packets on all links onto NAM trace and text trace file
4. Define finish procedure to close files, flush tracing and run NAM
5. Create eight nodes
6. Specify the link characteristics between nodes
7. Describe their layout topology as a octagon
8. Add UDP agent for node n1
9. Create CBR traffic on top of UDP and set traffic parameters.
10. Add a sink agent to node n4
11. Connect source and the sink 12. Schedule events as follows:
a. Start traffic flow at 0.5
b. Down the link n3-n4 at 1.0
c. Up the link n3-n4 at 2.0
d. Stop traffic at 3.0
e. Call finish procedure at 5.0
13. Start the scheduler
14. Observe the traffic route when link is up and down
15. View the simulated events and trace file analyze it
16. Stop
PROGRAM
#Distance vector routing protocol – distvect.tcl
#Create a simulator object
set ns [new Simulator] #Use
distance vector routing
$ns rtproto DV #Open
the nam trace file set nf
[open out.nam w]
$ns namtrace-all $nf #
Open tracefile set nt
[open trace.tr w] $ns
trace-all $nt
#Define 'finish' procedure
proc finish {}
51
{ global ns nf $ns flush-trace #Close the trace file close $nf #Execute nam on the trace file
exit 0
}
# Create 8 nodes
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]
set n8 [$ns node]
# Specify link characterestics
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns duplex-link $n2 $n3 1Mb 10ms DropTail
$ns duplex-link $n3 $n4 1Mb 10ms DropTail
$ns duplex-link $n4 $n5 1Mb 10ms DropTail
$ns duplex-link $n5 $n6 1Mb 10ms DropTail
$ns duplex-link $n6 $n7 1Mb 10ms DropTail
$ns duplex-link $n7 $n8 1Mb 10ms DropTail
$ns duplex-link $n8 $n1 1Mb 10ms DropTail
# specify layout as a octagon
$ns duplex-link-op $n1 $n2 orient left-up
$ns duplex-link-op $n2 $n3 orient up
$ns duplex-link-op $n3 $n4 orient right-up
$ns duplex-link-op $n4 $n5 orient right
$ns duplex-link-op $n5 $n6 orient right-down
$ns duplex-link-op $n6 $n7 orient down
$ns duplex-link-op $n7 $n8 orient left-down
$ns duplex-link-op $n8 $n1 orient left
#Create a UDP agent and attach it to node n1
set udp0 [new Agent/UDP]
$ns attach-agent $n1 $udp0
#Create a CBR traffic source and attach it to udp0
exec nam -a out.nam &
52
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
#Create a Null agent (a traffic sink) and attach it to node n4
set null0 [new Agent/Null] $ns attach-agent $n4 $null0
#Connect the traffic source with the traffic sink
$ns connect $udp0 $null0
#Schedule events for the CBR agent and the network dynamics
$ns at 0.0 "$n1 label Source"
$ns at 0.0 "$n4 label Destination"
$ns at 0.5 "$cbr0 start"
$ns rtmodel-at 1.0 down $n3 $n4
$ns rtmodel-at 2.0 up $n3 $n4
$ns at 4.5 "$cbr0 stop"
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"
#Run the simulation
$ns run
OUTPUT
$ ns distvect.tcl
53
54
VIVA (Pre &Post Lab) Questions:
RESULT:
Thus the simulation for Distance vector and link state routing protocols was done using
NS2.
55
EX.NO : 10
Simulation Of Errordetection Code (Like CRC)
DATE:
AIM:
To implement error checking code using java.
The cyclic redundancy check, or CRC, is a technique for detecting errors in digital data, but
not for making corrections when errors are detected. It is used primarily in data transmission.
In the CRC method, a certain number of check bits, often called a checksum, are appended to
the message being transmitted. The receiver can determine whether or not the check bits agree with the
data, to ascertain with a certain degree of probability whether or not an error occurred in transmission.
CRC involves binary division of the data bits being sent by a predetermined divisor agreed
upon by the communicating system. The divisor is generated using polynomials. So, CRC is also called
polynomial code checksum.
CRC uses Generator Polynomial which is available on both sender and receiver side. An ex-
ample generator polynomial is of the form like x3 + x + 1. This generator polynomial represents key
1011. Another example is x2 + 1 that represents key 101.
Sender Side (Generation of Encoded Data from Data and Generator Polynomial (or Key)):
• The binary data is first augmented by adding k-1 zeros in the end of the data
• Use modulo-2 binary division to divide binary data by the key and store remainder of division.
• Append the remainder at the end of the data to form the encoded data and send the same
Perform modulo-2 division again and if remainder is 0, then there are no errors.
Modulo 2 Division:
• The process of modulo-2 binary division is the same as the familiar division process we use
for decimal numbers. Just that instead of subtraction, we use XOR here.
• In each step, a copy of the divisor (or data) is XORed with the k bits of the dividend (or key).
• The result of the XOR operation (remainder) is (n-1) bits, which is used for the next step after
1 extra bit is pulled down to make it n bits long.
• When there are no bits left to pull down, we have a result. The (n-1)-bit remainder which is
appended at the sender side.
56
ALGORITHM:
PROGRAM:
57
System.out.print("divisor bits are : "); for(int
i=0; i< divisor_bits; i++) Sys-
tem.out.print(divisor[i]);
System.out.println();
*/ tot_length=data_bits+divisor_bits-1; div=new int[tot_length]; rem=new int[tot_length];
/*------------------ CRC GENERATION----------------------- */
for(int i=0;i<data.length;i++)
div[i]=data[i];
System.out.print("Dividend (after appending 0's) are : "); for(int i=0; i< div.length; i++)
System.out.print(div[i]);
System.out.println();
for(int j=0; j<div.length; j++){
rem[j] = div[j];
}
rem=divide(div, divisor, rem);
for(int i=0;i<div.length;i++)
{
crc[i]=(div[i]^rem[i]);
}
System.out.println();
System.out.println("CRC code : ");
for(int i=0;i<crc.length;i++)
System.out.print(crc[i]);
/*-------------------ERROR DETECTION--------------------- */
System.out.println();
System.out.println("Enter CRC code of "+tot_length+" bits : "); for(int i=0; i<crc.length; i++)
crc[i]=Integer.parseInt(br.readLine());
System.out.print("crc bits are : ");
for(int i=0; i< crc.length; i++)
System.out.print(crc[i]);
System.out.println();
for(int j=0; j<crc.length; j++){
crc=new int[tot_length]; rem[j] = crc[j]; } rem=divide(crc, divisor, rem); for(int i=0; i<
rem.length; i++)
{ if(rem[i]!=0)
{
System.out.println("Error");
break; } if(i==rem.length-1)
System.out.println("No Error");
}
58
System.out.println("THANK YOU.... :)");
}
static int[] divide(int div[],int divisor[], int rem[])
{
int cur=0;
while(true)
{
for(int i=0;i<divisor.length;i++)
rem[cur+i]=(rem[cur+i]^divisor[i]);
while(rem[cur]==0 && cur!=rem.length-1)
cur++;
if((rem.length-cur)<divisor.length)
break;
}
return rem;
}
}
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
59
01
crc bits are : 101100101
Error
THANK YOU.... :)
BUILD SUCCESSFUL (total time: 1 minute 34 seconds)
RESULT:
Thus the above program for error checking code using was executed successfully.
60