CS3591 - Computer Networks Lab

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 65

JP COLLEGE OF ENGINEERING

College Road, Ayikudi, Tenkasi – 627852


Affiliated to Anna University and Approved by AICTE

DEPARTMENT OF COMPUTER SCIENCE AND

ENGINEERING PRACTICAL RECORD WORK

CS3591- COMPUTER NETWORKS

SEMESTER-V

Name of the Student :………………………………………………

Register Number :………………………………………………


JP COLLEGE OF ENGINEERING
College Road, Ayikudi, Tenkasi – 627852
Affiliated to Anna University and Approved by AICTE

BONAFIDE CERTIFICATE
Certified that this is a record work done for CS3591- COMPUTER NETWORKS
Selvan/Selvi.……………………….………with registerNo…..........................................Studying
in the fifth semester BE (Computer Science And Engineering)in JP COLLEGE OF
ENGINEERING, during the academic year 2023-2024.

Staff Incharge Head of the Department

Submitted for the Anna University Practical examination held at

JP COLLEGE OF ENGINEERING on………………………

INTERNAL EXAMINER EXTERNAL EXAMINER


INDEX

Ex.No DATE LIST OF EXPERIMENTS P.No MARK SIGNATURE

1 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

3.a Applications using TCP sockets like Echo


client and echo server

3.b Applications using TCP sockets like Echo


Chat

4 Simulationof DNS using UDP sockets.

5 Use a tool like Wireshark to capture packets


and examine the packets

6 Write a code simulating ARP /RARP


protocols

6.b Program for Reverse Address Resolution


Protocol (RARP) using UDP

7 Study of Network simulator (NS) &


Simulation of Congestion Control Algorithms
using NS

8 Study of TCP/UDP performance using


Simulation tool
INDEX

Ex.No DATE LIST OF EXPERIMENTS P.No MARK SIGNATURE

9 Simulation of Distance Vector/ Link State


Routing algorithm

10 Simulation of Error Correction Code (like


CRC)
To use commands like tcpdump, netstat, ifconfig, nslookup and traceroute.
Capture ping and traceroute PDUs using a network protocol analyzer and
examine.

EX.NO: 1
DATE:
AIM:

Commands:

Tcpdump:

Display traffic between 2 hosts:

To display all traffic between two hosts (represented by variables host1 and host2):

# tcpdumphost host1 and host2


Display traffic from a source or destination host only:

To display traffic from only a source (src) or destination (dst) host:

# tcpdump srchost

# 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, UNIX and other operating systems.
Netstat provides information and statistics about protocols in use and current TCP/IP
networkconnections. The Windows help screen (analogous to a Linux or UNIX for netstat reads
as follows: displays protocol statistics and current TCP/IP network connections.
#netstat

3. ipconfig
In Windows, ipconfig is a console application designed to run from the Windows
command Prompt. This utility allows you to get the IP address information of a Windows
computer.
Using ipconfig
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.
#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 queryingthe Domain Name System.
The nslookup command is a powerful tool for diagnosing DNS problems. You know
you're experiencing a DNS problem when you can access a resource by specifying its IP
address but not itsDNS name.
#nslookup

5. Trace route:

Trace route 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. Trace route is a network diagnostic tool used to track the pathway taken by a
packet on an IP network from source to destination. Trace route also records the time taken for
each hop the packet makes during its route to the destination. Trace route 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 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 message 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. Proceeding in this way, trace route 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
localcomputer all the way to the network device with the hostname www.google.com.

#tracert 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 problems. 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 sending Internet Control Message Protocol (ICMP) Echo Request messages to the
destination computer and waiting for a response
# ping172.16.6.2

RESULT:
Write a HTTP web client program to download a web page using TCP sockets

EX.NO: 2
DATE:
AIM:

ALGORITHM:
PROGRAM:
import java.io.*;
import java.net.*;
public class SocketHTTPClient
{
public static void main(String[] args)
{
String hostName =
"www.sunnetwork.in"; int portNumber =
80;
try
{
Socket socket = new Socket(hostName, portNumber);
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
BufferedReader in =new BufferedReader(new InputStreamReader(socket.getInputStream()));
out.println("GET / HTTP/1.1\nHost: www.sunnetwork.in\n\n");
String inputLine;
while ((inputLine = in.readLine()) != null)
{
System.out.println(inputLine);
}
}
catch (UnknownHostException e)
{
System.err.println("Don't know about host " + hostName);System.exit(1);
}
catch (IOException e)
{
System.err.println("Couldn't get I/O for the connection to " + hostName);System.exit(1);
}
}
}
OUTPUT:

RESULT:
Applications using TCP sockets like Echo client and echo server

EX.NO:3a
DATE:
AIM:

a.Echo client and echo

server: ALGORITHM:

Client:

Server:
PROGRAM:
EchoServer.java
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)
{
System.out.println(e);
}
try
{
c=s.accept();
is=new
DataInputStream(c.getInputStream());
ps=new PrintStream(c.getOutputStream());
while(true)
{
line=is.readLine();
ps.println(line);
}
}
catch(IOException e)
{
System.out.println(e);
}
}
}

EClient.java
import java.net.*;
import java.io.*;
public class EClient
{ 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)
{
System.out.println("Socket Closed!");
}
}}
OUTPUT:
Server

Client
Applications using TCP sockets like Echo Chat

EX.NO:3b
DATE:
AIM:

b.Chat:
ALGORITHM:
Client:

Server:
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
{
public static DatagramSocket ds;
public static int clientport=789,serverport=790;
public static void main(String args[])throws Exception
{
byte buffer[]=new byte[1024]; ds=new DatagramSocket(serverport);
BufferedReader dis=new BufferedReader(new InputStreamReader(System.in));
System.out.println("server waiting");
InetAddress ia=InetAddress.getLocalHost();
while(true)
{
System.out.println("Client:");
String str=dis.readLine();
if(str.equals("end"))
break;
buffer=str.getBytes();
ds.send(new DatagramPacket(buffer,str.length(),ia,clientport));
DatagramPacket p=new DatagramPacket(buffer,buffer.length);
ds.receive(p);
String psx=new String(p.getData(),0,p.getLength());
System.out.println("Server:" + psx);
}
}
}
OUTPUT:

RESULT:
Simulation of DNS using UDP sockets.
EX.NO: 4
DATE:

Aim :

Algorithm:
PROGRAM:
UDP DNS Server
import java.io.*;
import java.net.*;
public class
dnsserver
{
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 = {"zoho.com", "gmail.com","google.com", "facebook.com"};
String[] ip = {"172.28.251.59",
"172.217.11.5","172.217.11.14","31.13.71.36"};
System.out.println("Press Ctrl + C to Quit");while (true)
{
DatagramSocket serversocket=new DatagramSocket(1362);
byte[] senddata = new byte[1021];
byte[] receivedata = new byte[1021];
DatagramPacket recvpack = new
DatagramPacket(receivedata,receivedata.length); serversocket.receive(recvpack);
String sen = new String(recvpack.getData());
InetAddress ipaddress =
recvpack.getAddress(); int port =
recvpack.getPort();
String capsent;
System.out.println("Request for host " +
sen); if(indexOf (hosts, sen) != -1)
capsent = ip[indexOf (hosts,
sen)]; else
capsent = "Host Not Found";
senddata =
capsent.getBytes();
DatagramPacket pack = new DatagramPacket (senddata, senddata.length,ipaddress,port);
serversocket.send(pack);
serversocket.close();
}
}
}
//UDP DNS Client:

import java.io.*;
import java.net.*;
public class dnsclient
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(newInputStreamReader(System.in));
DatagramSocket clientsocket = new DatagramSocket();
InetAddress ipaddress;
if (args.length == 0)
ipaddress = InetAddress.getLocalHost();
else
ipaddress = InetAddress.getByName(args[0]);
byte[] senddata = new byte[1024];
byte[] receivedata = new
byte[1024]; int portaddr = 1362;
System.out.print("Enter the hostname : ");
String sentence = br.readLine();
senddata = sentence.getBytes();
DatagramPacket pack = new DatagramPacket(senddata,senddata.length,ipaddress,portaddr);
clientsocket.send(pack);
DatagramPacket recvpack =new DatagramPacket(receivedata,receivedata.length);
clientsocket.receive(recvpack);
String modified = new
String(recvpack.getData());
System.out.println("IP Address: " + modified);
clientsocket.close();
}

}
OUTPUT

Server

Client

RESULT:
Use a tool like Wireshark to capture packets and examine the packets

EX.NO:5
DATE:
AIM:

Wireshark:
Wireshark is an open-source packet analyzer, which is used for education, analysis, software
development, communication protocol development, and network troubleshooting.
It is used to track the packets so that each one is filtered to meet our specific needs. It is
commonly called as a sniffer, network protocol analyzer, and network analyzer. It is also used by network
security engineers to examine security problems.
Wireshark is a free to use application which is used to apprehend the data back and forth. It is
often called as a free packet sniffer computer application. It puts the network card into an unselective
mode, i.e., to accept all the packets which it receives.
Uses of Wireshark:
1. It is used by network security engineers to examine security problems.
2. It allows the users to watch all the traffic being passed over the network.
3. It is used by network engineers to troubleshoot network issues.
4. It also helps to troubleshoot latency issues and malicious activities on your network.
5. It can also analyze dropped packets.
6. It helps us to know how all the devices like laptop, mobile phones, desktop, switch, routers, etc.,
communicate in a local network or the rest of the world.
PACKET:
A packet is a unit of data which is transmitted over a network between the origin and the
destination. Network packets are small, i.e., maximum 1.5 Kilobytes for Ethernet packets and 64
Kilobytes for IP packets. The data packets in the Wireshark can be viewed online and can be analyzed
offline.
Functionality of Wireshark:
Wireshark is similar to tcpdump in networking. Tcpdump is a common packet analyzer which
allows the user to display other packets and TCP/IP packets, being transmitted and received over a
network attached to the computer. It has a graphic end and some sorting and filtering functions.
Wireshark users can see all the traffic passing through the network.
Wireshark can also monitor the unicast traffic which is not sent to the network's MAC address
interface. But, the switch does not pass all the traffic to the port. Hence, the promiscuous mode is not
sufficient to see all the traffic. The various network taps or port mirroring is used to extend capture at any
point.
Port mirroring is a method to monitor network traffic. When it is enabled, the switch sends the
copies of all the network packets present at one port to another port.
What is color coding in Wireshark?
The packets in the Wireshark are highlighted with blue, black, and green color. These colors help users to
identify the types of traffic. It is also called as packet colorization. The kinds of coloring rules in the
Wireshark are temporary rules and permanent rules. The temporary rules are there until the program is in
active mode or until we quit the program.
PROCEDURE:
1. Open theWireshark application.
2. Select the current interface. Eg. WiFi

3. Select capture option to capture the live packets.


4. Save packet data captured.
5. Filter option can be used based upon many criteria.

6. Search for packet on many criteria.


7. click on the 'View' option on the menu bar and select 'Coloring Rules.' The table will appear
like the image shown below:
8. Select the option 'View' and then choose 'Colorize Packet List,' which is used to toggle the color
on and off.

RESULT:
Write a code simulating ARP /RARP protocols

EX.NO:6
DATE:
AIM:

(a) Program for ARP

ALGORITHM:
Client

Server
PROGRAM
Client:
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.*;
import java.util.*;
class Serverarp
{
public static void main(String args[])
{
try{
ServerSocket obj=new
ServerSocket(139);
Socketobj1=obj.accept();
while(true)
{
DataInputStream din=new DataInputStream(obj1.getInputStream());
DataOutputStream dout=new
DataOutputStream(obj1.getOutputStream()); 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);
}}}
OUTPUT:
(b) Program for Reverse Address Resolution Protocol (RARP) using UDP

ALGORITHM:
Client:

Server:
PROGRAM:
Client:
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));
System.out.println("Enter the Physical address (MAC):")
String str=in.readLine();
sendbyte=str.getBytes();
DatagramPacket sender=newDatagramPacket(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);
}}}
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()); String
s=str.trim();
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);}}}
OUTPUT:

RESULT:
Study of Network simulator (NS) & Simulation of Congestion Control Algorithms using NS

EX.NO:7
DATE:
AIM:

Theory:
NET WORK SIMULATOR (NS2)
Ns Overview

 Ns Status
 Periodical release (ns-2.26, Feb2003)Platform support
 FreeBSD, Linux, Solaris, Windows and Mac

Ns functionalities

Routing, Transportation, Traffic sources,Queuing disciplines, QoS

Congestion Control Algorithms

 Slow start
 Additive increase/multiplicative decrease
Fast retransmit and Fast recovery

Case Study: A simple Wireless network.

 Ad hoc routing, mobile IP, sensor-MACTracing, visualization and variousutilitieNS


(Network Simulators)
Most of the commercial simulators are GUI driven, while some network simulators are CLI
driven. The network model / configuration describes the state of the network (nodes,routers,
switches, links) and the events (data transmissions, packet error etc.). An important output of
simulations are the trace files. Trace files log every packet, every event that occurred in the
simulation and are used for analysis. Network simulators can also provide other tools to
facilitatevisual analysis of trends and potential trouble spots.
Most network simulators use discrete event simulation, in which a list of pending
"events" is stored, and those events are processed in order, with some events triggering future
events—such as the event of the arrival of a packet at one node triggering the event of the
arrival of that packet at a downstream node.
Simulation of networks is a very complex task. For example, if congestion is high, then
estimation of the average occupancy is challenging because of high variance. To estimate the
likelihood of a buffer overflow in a network, the time required for an accurate answer can be
extremely large. Specialized techniques such as "control variates" and "importance sampling"
have been developed to speed simulation.
Examples of network simulators
There are many both free/open-source and proprietary network simulators. Examples of
notable network simulation software are, ordered after how often they are mentioned in research
papers:
ns (open source)
OPNET (proprietary software)
NetSim (proprietary software)

Uses of network simulators


Network simulators serve a variety of needs. Compared to the cost and time involved in
setting up an entire test bed containing multiple networked computers, routers and data links,
network simulators are relatively fast and inexpensive. They allow engineers, researchers to test
scenarios that might be particularly difficult or expensive to emulate using real hardware - for
instance, simulating a scenario with several nodes or experimenting with a new protocol in the
network. Network simulators are particularly useful in allowing researchers to test new
networking protocols or changes to existing protocols in a controlled and reproducible
environment. A typical network simulator encompasses a wide range of networking technologies
and can help the users to build complex networks from basic building blocks such as a variety of
nodes and links. With the help of simulators, one can design hierarchical networks using various
types of nodes like computers, hubs, bridges, routers, switches, links, mobile units etc.Various
types of Wide Area Network (WAN) technologies like TCP, ATM, IP etc. and Local Area
Network (LAN) technologies like Ethernet, token rings etc., can all be simulated with a typical
simulator and the user can test, analyze various standard results apart from devising some novel
protocol or strategy for routing etc. Network simulators are also widelyused to simulate battlefield
networks in Network-centric warfare.
There are a wide variety of network simulators, ranging from the very simple to the very
complex. Minimally, a network simulator must enable a user to represent a network topology,
specifying the nodes on the network, the links between those nodes and the traffic between the
nodes. More complicated systems may allow the user to specify everything about the protocols
used to handle traffic in a network. Graphical applications allow users to easily visualize the
workings of their simulated environment. Text-based applications may provide a less intuitive
interface, but may permit more advanced forms of customization.
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 packetscaused
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, as well as to frequency and patterns of loss among longer packet sequences is strongly
dependent on the application itself.
Throughput
Throughput is the main performance measure characteristic, and most widely used. In
communication 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. Throughput 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.
Congestion control Algorithms
Slow-start is used in conjunction with other algorithms to avoid sending more data than the
network is capable of transmitting, that is, to avoid causing network congestion. The additive
increase/multiplicative decrease (AIMD) algorithm is a feedback control algorithm. AIMD
combines linear growth of the congestion window with an exponential reduction when a
congestion takes place. Multiple flows using AIMD congestion control will eventually converge
to use equal amounts of a contended link. Fast Retransmit is an enhancement to TCP that
reducesthe time a sender waits before retransmitting a lost segment.
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_);
}
if (elm != NULL)
{
elm = findDataPacketInRecvHistory(STAILQ_NEXT(elm,linfo_));
if (elm != NULL)
{
elm2 = STAILQ_NEXT(elm,
linfo_); while(elm2 != NULL)
{
if (elm2->seq_num_ < seq_num && elm2->t_recv_ <time)
{ 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;
elm2 = STAILQ_NEXT(elm1,
linfo_); while(elm2 != NULL){
if (elm2->type_ == DCCP_ACK)
{ STAILQ_REMOVE(&r_hist_,elm2,r_hist_entry,linfo_);
delete elm2;
}
else
{
elm1 = elm2;
}
elm2 = STAILQ_NEXT(elm1, linfo_);
}
}
inline r_hist_entry *DCCPTFRCAgent::findDataPacketInRecvHistory(r_hist_entry
*start)
{
while(start != NULL && start->type_ ==
DCCP_ACK) start =
STAILQ_NEXT(start,linfo_);
return start;
}

RESULT:
Study of TCP/UDP performance using Simulation tool

EX.NO:8
DATE:

AIM:

TCP Performance:
Algorithm:
PROGRAM:

set ns [new Simulator]


$ns color 0 Blue
$ns color 1 Red
$ns color 2 Yellowset n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set
n3 [$ns node]
set f [open tcpout.tr w]
$ns trace-all $f
set nf [open tcpout.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 right-down
$ns duplex-link-op $n2 $n3 orient right
$ns duplex-link-op $n2 $n3 queuePos 0.5set tcp [new Agent/TCP]
$tcp set class_ 1
set sink [new Agent/TCPSink]
$ns attach-agent $n1 $tcp
$ns attach-agent $n3 $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$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-traceclose $f
close $nf
puts "Running nam.."
exec xgraph tcpout.tr -geometry 600x800 &exec nam tcpout.nam
& exit 0
}$ns run
OUTPUT:
UDP Performance
ALGORITHM :
PROGRAM:
set ns [new Simulator]
$ns color 0 Blue
$ns color 1 Red
$ns color 2 Yellowset 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 right-down
$ns duplex-link-op $n2 $n3 orient right
$ns duplex-link-op $n2 $n3 queuePos 0.5set 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]
$cbr1 attach-agent $udp1set null0 [new Agent/Null]
$ns attach-agent $n1 $null0set null1 [new Agent/Null]
$ns attach-agent $n1 $null1
$ns connect $udp0 $null0
$ns connect $udp1 $null1
$ns at 1.0 "$cbr0 start"
$ns at 1.1 "$cbr1 start" puts [$cbr0 set packetSize_]puts [$cbr0
set interval_]
$ns at 3.0 "finish"proc finish {} { global ns f nf
$ns flush-traceclose $f
close $nf
puts "Running nam.." exec nam udpout.nam
& exit 0
}
$ns run
OUTPUT:

RESULT:
Simulation of Distance Vector/ Link State Routing algorithm

EX.NO: 9
DATE:
AIM:

ALGORITHM:
LINK STATE ROUTING
PROTOCOL PROGRAM
set ns [new Simulator]
$ns rtproto LS
set nf [open linkstate.nam w]
$ns namtrace-all $nf
set f0 [open linkstate.tr w]
$ns trace-all $f0proc finish {} { global ns f0 nf
$ns flush-traceclose $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 $udp0set 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)
$ns at 4.5 "$cbr0 stop”
$ns at 5.0 "finish"
$ns run
OUTPUT:
DISTANCE VECTOR ROUTING
ALGORITHM ALGORITHM:
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 fileset nf [open out.nam w]
$ns namtrace-all $nf# Open tracefile
set nt [open trace.tr w]
$ns trace-all $nt
#Define 'finish' procedureproc finish {}
{ global ns nf
$ns flush
-trace
#Close the trace fileclose $nf
#Execute nam on the trace fileexec nam
-a out.nam &exit 0
}
# Create 8 nodesset 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
-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 n1set udp0 [new Agent/UDP]
$ns attach
-agent $n1 $udp0
#Create a CBR traffic source and attach it to udp0set 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 n4set 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 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 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:

RESULT:
Simulation of Error Correction Code (like CRC)
EX.NO:10
DATE:
AIM:

ALGORITHM:
PROGRAM:
import java.io.*;
class crc_gen
{
public static void main(String args[]) throws IOException {
BufferedReader br=new BufferedReader(newInputStreamReader(System.in));
int[] data;
int[] div;
int[] divisor;
int[] rem;
int[] crc;
int data_bits, divisor_bits, tot_length;
System.out.println("Enter number of data bits : ");
data_bits=Integer.parseInt(br.readLine());
data=new int[data_bits];
System.out.println("Enter data bits : ");
for(int i=0; i<data_bits; i++)
data[i]=Integer.parseInt(br.readLine());
System.out.println("Enter number of bits in divisor : ");
divisor_bits=Integer.parseInt(br.readLine());
divisor=new int[divisor_bits];
System.out.println("Enter Divisor bits : ");
for(int i=0; i<divisor_bits; i++)
divisor[i]=Integer.parseInt(br.readLine());
System.out.print("Data bits are : ");
for(int i=0; i< data_bits; i++)
System.out.print(data[i]);
System.out.println();
System.out.print("divisor bits are : ");
for(int i=0; i< divisor_bits; i++)
System.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=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++)
{
//append dividend and
remainder
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++)
{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"); }
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 :

RESULT:

You might also like