CN_record
CN_record
NAGERCOIL
(ANNA UNIVERSITY CONSTITUENT COLLEGE)
KONAM, NAGERCOIL – 629 004
REGISTER NO:
UNIVERSITY COLLEGE OF ENGINEERING
NAGERCOIL
(ANNA UNIVERSITY CONSTITUENT COLLEGE)
KONAM, NAGERCOIL – 629 004
Register No:
Exp Page
No. Date Name of the Experiments No. Sign.
Aim:
To learn to use commands like tcpdump, netstat, ifconfig, nslookup, and traceroute.
1. Tcpdump:
The tcpdump utility allows you to capture packets that flow within your network to
assist in network troubleshooting. The following are several examples of using tcpdump with
different options. Traffic is captured based on a specified filter.
Options Description
-D Print a list of network interfaces.
Many other options and arguments can be used with tcpdump. The following are some
specific examples of the power of the tcpdump utility.
1. 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
3. 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
4. Filtering based on source or destination port
To filter on source or destination port:
#tcpdump src port ftp
#tcpdump dst port http
2. Netstat
Netstat is a common command-line TCP/IP networking utility 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. 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 -a -b -e -n -o -p proto -r -s -v -interval
-a Displays all connections and listening ports.
-b Displays the executable involved in creating each connection or
listening port. In some cases well-known executables host multiple
independent components, and in these cases the sequence of
components involved in creating the connection or listening port is
displayed. In this case the executable name is in [ ] at the bottom, on top
is the component it called, and so forth until TCP/IP was reached. Note
that this option can be time-consuming and will fail unless you have
sufficient permissions.
-e Displays Ethernet statistics. This may be combined with the -s option.
-n Displays addresses and port numbers in numerical form.
-o Displays the owning process ID associated with each connection.
-p proto Shows connections for the protocol specified by proto; proto may be
any of: TCP, UDP, TCPv6, or UDPv6. If used with the -s option to
display per-protocol statistics, proto may be any of: IP, IPv6, ICMP,
ICMPv6, TCP, TCPv6, UDP, or UDPv6.
-r Displays the routing table.
-s Displays per-protocol statistics. By default, statistics are shown for IP,
IPv6, ICMP, ICMPv6, TCP, TCPv6, UDP, and UDPv6; the -p option
may be used to specify a subset of the default.
5. Traceroute
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 multiple times (usually three times) to better measure the
response of that particular hop.
tracert www.google.com
With the tracert command shown above, we’re asking tracert to show us the path from the
local computer all the way to the network device with the hostname www.google.com.
Tracing route to www.google.com
[209.85.225.104] over a maximum of 30 hops:
1 <1 ms <1 ms <1 ms 10.1.0.1
2 3 ms 19 ms 29 ms 98.245.140.1
3 1 ms 27 ms 9 ms te-0-3-0.dfw.comcast.net [68.85.105.201]
...
11 81 ms 76 ms 75 ms 209.85.241.37
14 84 ms 91 ms 87 ms 209.85.248.102
15 76 ms 112 ms 76 ms y-f104-le100.net [209.85.225.104]
Trace complete.
tracert j 10.12.0.1 10.29.3.1 10.44.1 www.google.com
Result:
Thus the basic networking commands were executed successfully.
Ex. No: 2
Implementation of HTTP web client to download a web page using TCP sockets
Date: 27-08-2024
Aim:
To write a java program for socket for HTTP for webpage upload and download.
Algorithm:
Step 1: Start.
Step 2: Get the frame size from the user.
Step 3: To create the frame based on the user request.
Step 4: To send frames to server from client side.
Step 5: If your frames reach the server, it will send ACK signal to client otherwise, it
will send NACK signal to client.
Step 6: Stop.
Program:
import java.io.*;
import java.net.*;
public class SocketHTTPClient
{
public static void main(String[] args)
{
String hostName="www.google.com";
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.google.com\n\n");
String inputLine;
while((inputLine=in.readLine())!=null)
{
System.out.println(inputLine);
}
}
catch(IOException e)
{
System.out.println("Couldn't get I/O for the connection to "+hostName);
System.exit(1);
}
}
}
Output:
Result:
Thus the program for creating sockets HTTP web page to download was implemented successfully.
Implementation of Echo Client and Echo Server Application
Ex No : 3A
Date : 03-09-2024 Using TCP Socket
Aim :
To write a program to develop application using TCP sockets like Echoclient and Echoserver.
Algorithm :
Step 1: Start.
Step 2: Get the frame size from the user.
Step 3: To create the frame based on the user request.
Step 4: To send frames to server from the client side.
Step 5: If your frames reach the server it will send ACK signal to the client otherwise it will
send NACK signal to client.
Step 6: Stop.
Program :
Echoclient.java
import java.io.*;
import java.net.*;
public class Echoclient{
public static void main(String[] args){
try{
Socket s=new Socket("127.0.0.1",9999);
BufferedReader r=new BufferedReader(new InputStreamReader(s.getInputStream()));
PrintWriter w=new PrintWriter(s.getOutputStream(),true);
BufferedReader con= new BufferedReader(new InputStreamReader(System.in));
String line;
do{
{
line=r.readLine();
if(line!=null)
System.out.println(line);
line=con.readLine();
w.println(line);
}
}
while(!line.trim().equals("bye"));
}catch(Exception err){
System.err.println(err);
}
}
}
Echoserver.java
import java.io.*;
import java.net.*;
public class Echoserver{
public Echoserver(int portnum){
try{
server=new ServerSocket(portnum);
}
catch(Exception err)
{
System.out.println(err);
}
}
public void server(){
try{
while(true)
{
Socket client=server.accept();
BufferedReader r=new BufferedReader(new InputStreamReader(client.getInputStream()));
PrintWriter w=new PrintWriter(client.getOutputStream(),true);
w.println("Welcome to the java Echoserver type bye to close");
String line;
do{
line=r.readLine();
if(line!=null)
w.println("GOT:"+line);
System.out.println(line);
}
while(!line.trim().equals("bye"));
client.close();
}
}
catch(Exception err)
{
System.err.println(err);
}
}
public static void main(String[] args){
Echoserver echoserver=new Echoserver(9999);
echoserver.server();
}
private ServerSocket server;
}
Output :
Result :
Thus a program to develop an application using TCP sockets like Echoclient and Echo server
was written and executed successfully.
Ex No : 3B IMPLEMENTATION OF CHAT APPLICATION USING TCP SOCKETS
Date : 03/09/2024
Aim :
To implement a chat application using TCP socket.
Concept :
chatclient.java
import java.net.*;
import java.io.*;
public class chatclient
{
public static void main(String args[])throws Exception{
Socket sk=new Socket("127.0.0.1",2000);
BufferedReader sin=new BufferedReader(new InputStreamReader(sk.getInputStream()));
PrintStream sout=new PrintStream(sk.getOutputStream());
BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
String s;
while(true)
{
System.out.print("Client::");
s=stdin.readLine();
sout.println(s);
s=sin.readLine();
System.out.print("Server:"+s+"\n");
if(s.equalsIgnoreCase("BYE"))
break;
}
sk.close();
sin.close();
sout.close();
stdin.close();
}
}
Output :
Result:
Thus the program for chat application using TCP socket was written and executed successfully.
EX.NO: 4
Simulation of DNS Using UDP Sockets
DATE:09/09/24
AIM:
ALGORITHM:
Step 1: Start
Step 2: Get the frame size from the user.
Step3: To create the frame based on the user request
Step 4: To send frames to server from the client side.
Step 5: If your frames reach the server it will send Ack signal to client otherwise it will
Send Send NACK signal to client.
Step 6: Stop.
PROGRAM:
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 args[]) 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");
DatagramSocket serverSocket = new DatagramSocket(1362);
byte[] sendData = new byte[1021];
byte[] receiveData = new byte[1021];
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
while (true) {
serverSocket.receive(receivePacket);
String sentence = new String(receivePacket.getData());
InetAddress ipAddress = receivePacket.getAddress();
int port = receivePacket.getPort();
System.out.println("Request for host " + sentence);
if (indexOf(hosts, sentence) != -1) {
String capsent = ip[indexOf(hosts, sentence)];
sendData = capsent.getBytes();
} else {
String capsent = "Host Not Found";
sendData = capsent.getBytes();
}
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length,
ipAddress, port);
serverSocket.send(sendPacket);
}
}
}
UDP DNS Client:
import java.io.*;
import java.net.*;
public class DNSClient {
public static void main(String args[]) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(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 packet = new DatagramPacket(sendData, sendData.length, ipAddress,
portAddr);
clientSocket.send(packet);
DatagramPacket receivePacket = new DatagramPacket(receiveData,
receiveData.length);
clientSocket.receive(receivePacket);
String modified = new String(receivePacket.getData());
System.out.println("IP Address: " + modified);
clientSocket.close();
}
}
OUTPUT:
RESULT:
Thus the program for DNS application using UDP socket was executed successfully.
Ex No: 05 Capturing and Examining the Packets using Wireshark
Date: 10-09-2024
Aim:
To capture and examine the packets using the wireshark tool.
If you are a Linux user, you will find Wireshark in its package repositories.
By selecting the current interface, we can get the traffic traversing through that interface. The version used
here is 3.0.3. This version will open as:
The Wireshark software window is shown above, and all the processes on the network are carried
within this screen only.
The options given on the list are the Interface list options. A number of interface options will be
present. The selection of any option will determine all the traffic.
The above arrow shows the packet content written in hexadecimal or ASCII format.
And the information above the packet content is the details of the packet header.
It will continue listening to all the data packets, and you will get a lot of data. If you want to see a
particular data, then you can click on the red button. The traffic will be stationary, and you can note the
parameters like time, source, destination, the protocol being used, length, and the Info. To view in-depth
details, you can click on that particular address; a lot of the information will be displayed below that.
There will be detailed information on HTTP packets, TCP packets, etc. The red button is shown below:
The screen/interface of the Wireshark is divided into five parts:
o The first part contains a menu bar and the options displayed below it. This part is at the top
of the window. File and capture menu options are commonly used in Wireshark. The capture
menu allows you to start the capturing process. The File menu is used to open and save a
capture file.
o The second part is the packet listing window. It determines the packet flow or the captured
packets in the traffic. It includes the packet number, time, source, destination, protocol,
length, and info. We can sort the packet list by clicking on the column name.
o Next comes the packet header- a detailed window. It contains detailed information
about the components of the packets. The protocol info can also be expanded or
minimized according to the information required.
o The bottom window called the packet contents window, displays the content in
ASCII and hexadecimal format.
o At last, is the filter field which is at the top of the display. The captured packets on the
screen can be filtered based on any component according to your requirements. For
example, if we want to see only the packets with the HTTP protocol, we can apply
filters to that option. All the packets with HTTP as the protocol will only be displayed
on the screen, shown below:
You can also select the connection to which your computer is connected. For example, in this PC, we
have chosen the current network, i.e., the ETHERNET.
There is a filter block below the menu bar, from where a large amount of data can be filtered. For
example, if we apply a filter for HTTP, only the interfaces with the HTTP will be listed.
If you want to filter according to the source, right-click on the source you want to filter select 'Apply
as Filter' and choose '...and filter.'
Steps for the permanent colorization are: click on the 'View' option on the menu bar and select
'Colouring Rules.' The table will appear like the image shown below:
For the network administrator job, advanced knowledge of Wireshark is considered a requirement. So,
it is essential to understand the concepts of the software. It contains these 20 default coloring rules
which can be added or removed according to the requirements.
Select the option 'View' and then choose 'Colorize Packet List,' which is used to
toggle the color on and off.
IP Addresses: It was designed for the devices to communicate with each other on a local network or
over the Internet. It is used for host or network interface identification. It provides the location of the
host and the capacity to establish the path to the host in that network. Internet Protocol is the set of
predefined rules or terms under which the communication should be conducted. The types of IP
addresses are IPv4 and IPv6.
• IPv4 is a 32-bit address in which each group represents 8 bits ranging from 0 to 255.
• IPv6 is a 128-bit address.
IP addresses are assigned to the host either dynamically or static IP address. Most private users have
dynamic IP addresses while business users or servers have static IP addresses. Dynamic address changes
whenever the device is connected to the Internet.
Computer Ports: The computer ports work in combination with the IP address directing all outgoing
and incoming packets to their proper places. There are well-known ports to work with like FTP (File
Transfer Protocol), which has port no. 21, etc. All the port have the purpose of directing all packets in
the predefined direction.
Protocol: The Protocol is a set of predefined rules. They are considered as the standardized way of
communication. One of the most used protocols is TCP/IP. It stands for Transmission Control Protocol/
Internet Protocol.
OSI model: OSI model stands for Open System Interconnect. OSI model has seven layers,namely, the
Application layer, the Presentation layer, the Session layer, the Transport layer, the Network layer,
the Data link layer, and the physical layer. OSI model gives a detailed representation and explanation
of the transmission and reception of data through the layers. OSI model supports both connection less and
connection-oriented communication modes over the network layer. The OSI model was developed by the
ISO (International Standard Organization).
Whenever we type any commands in the filter command box, it turns green if your command is correct.
It turns red if it is incorrect or the Wireshark does not recognize your command.
Wireshark packet sniffing
Wireshark is a packet sniffing program that administrators can use to isolate and troubleshoot problems on
the network. It can also be used to capture sensitive data like usernames and passwords. It can also be used
in the wrong way (hacking) to eavesdrop.
Packet sniffing is defined as the process of capturing the packets of data flowing across a computer network.
The Packet sniffer is a device or software used for the process of sniffing.
As soon as we open the browser, and type any address of the website, the traffic will start showing, and the
exchange of the packets will also start. The image for this is shown below:
It is the process used to know the passwords and usernames for the particular website. Let’s take an
example of gmail.com. Below are the steps:
o Right-click on the particular network and select 'Follow', and then 'TCP Stream.' You can see that
all the data is secured in the encrypted form.
In the arrow shown above, the 'show and save data as' has many choices. These options are- ASCII, C
Arrays, EBCDIC (Extended Binary Coded Decimal Interchange Code), etc. EBCDIC is used in
mainframe and mid-range IBM computer operating systems.
Wireshark Statistics
The Wireshark provides a wide domain of statistics. They are listed below:
I/O Graphs
It shows the graph for the network traffic. The graph will look similar but changes as per the traffic
involved. There is a table below the figure, which has some filters. Using the'+' sign, you can add more
filters and using the '-sign you can remove the existing filters.
You can also change the color. For every particular filter, you can add a coloured layer, which increases
the visibility of the graph.
The tick option under the 'Enabled,' displays the layer according to your requirements.
Result:
Thus the packets were successfully captured and examined using the Wireshark tool..
Ex No: 6A Simulating ARP Protocols
Date:21/9/24
Aim:
To write a program for simulating ARP protocols.
Algorithm:
Client:
Step 1: Start.
Step 2: Accept the socket connection is established between client and server.
Step 3: Get IP address to be connected into mac.
Step 4: Send this IP address to server.
Step 5: Server returns MAC address to client.
Server:
Step 1: Start.
Step 2: Accept the socket which is created by client.
Step 3: Server maintains table in which IP and corresponding MAC address.
Step 4: Read IP address which is send by client.
Step 5: Map the IP address woth MAC addresss and return the MAC address to client.
PROGRAM:
Clientarp:
import java.io.*;
import java.net.*;
public class Clientarp{
public static void main(String[] args){
try {
BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
Socket sok = new Socket(“127.0.01”,5604);
BufferedReader din = new BufferedReader(new
InputStreamReader(sok.getInputStream()));
PrintWriter dout = new PrinterWriter(sok.getOutSTream(),true);
System.out.println(“Enter the logical address (IP):”);
String str1 = buff.readLine();
Dout.println(str1);
String str = din.readLine();
System.out.println(“The physical address is:” +str);
Sok.close();
}
Catch (Exception e){
System.out.println(e);
}
}
}
Serverarp:
import java.io.*;
import java.net.*;
public class Serverarp{
public static void main(String[] args){
try{
ServerSocket serverSocket = new ServerSocket(5604)){
System.out.println(“server is renning…”);
While (true){
try (Socket clientSocket = serverSocket.accept();
BufferedReader din = new BufferedReader(new
InputStreamReader(clientSocket.getOutputStream()));
DataOutputStream dout = new
DataOutputStream(clientSocket.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”};
boolean found = false;
for(int I =0; i<ip.length; i++){
if(Str.equals(ip[i])){
dout.writeBytes(mac[i]+’\n’);
found = true;
break;
}
}
if (!found){
dout.writeBytes(“IP not found\n”);
}
}
Catch (IOException e){
System.out.println(“Error handling client:”+e.getMessage());
}
}
}
Catch (IOException e){
System.out.println(“Server error:”+e.getMessage());
}
}
}
OUTPUT:
RESULT:
Thus the program to concurrency communicate using TCP Soclet
Was executed successfully.
Ex.No:8 STUDY OF TCP/UDP PERFORMANCE USING SIMULATION TOOL
Date: 08/10/2024
AIM:
To the study of TCP/UDP performance using Simulation tool.
TOOLS USED:
Opnet Simulator.
INTRODUCTION:
The transport layer protocols provide connection- oriented sessions and reliable data delivery
services. This paper seeks to reflect a comparative analysis between the two transport layer protocols,
which are TCP/IP and UDP/IP, as well to observe the effect of using these two protocols in a client server
network. The similarities and differences between TCP and UDP over the Internet are also presented in our
work. We implement a network structure using Opnet Modeler and finally, based on the practical results
obtained we present the conclusions-showing the difference between these two protocols and how they
work.
The transport layer is not just another layer. It is the heart of the whole protocol hierarchy. Its task is
to provide reliable, cost-effective data transport from the source machine to the destination machine,
independently of the physical network or networks currently in use.
TCP and UDP are transport layer components that provide the connection point through which
applications access network services. TCP and UDP use IP, which is a lower-layer best effort delivery
service. IP encapsulates TCP packets and UDP datagrams and delivers this information across router-
connected internet works.
The ultimate goal of the transport layer is to provide efficient, reliable, and cost-effective service to
its users, normally processes in the application layer. To achieve this goal, the transport layer makes use of
the services provided by the network layer. Without the transport layer, the whole concept of layered
protocols would make little sense e.g. The Transport Layer prepares applications data for transport over the
network and processes network data to be used by applications. It is responsible for the end-to-end transfer
of data over the network and is the four of the OSI model. The Transport layer meets a number of
functions:
- enabling the applications to communicate over the network at the same time when using
a single device;
A big difference between TCP and UDP is the congestion control algorithm. For the TCP,
congestion algorithm prevents the sender from overrunning the network capacity, while TCP can adapt the
sender's rate with the network capacity and attempt to avoid potential congestions problems.
User Datagram Protocol (UDP), another transport protocol in IP networks, is described c.g. The
User Datagram Protocol (UDP) provides an unreliable connectionless delivery service using IP to transport
messages between machines e.g. [5]. It uses IP to carry messages, but adds the ability to distinguish among
multiple destinations within a given host computer. Is a connectionless protocol which doesn't provide flow
control, reliability or error recovery and the retransmissions of data in case of errors must be ordered by
other protocols. UDP is designed for applications that do not have to recompose the data segment that
arrives from the sender. In another way, application-level protocols are directly responsible for the security
of data transmitted.
Difference from the TCP is that there is no mechanism for error detections. If applications that use
UDP doesn't have their own mechanism for information retrieval can lose those data and be forced to
retransmitted again. On the other side this applications are not slow down by the confirmation process and
the memory will be available for work much faster.
SIMULATION RESULTS:
The simulation time is set for two hours data transfer between LAN network and the server with no
packet latency and packet discard ratio of 0% while packets traverse thru the WAN. The task response
time, in seconds, Fig. 1, shows how long the application need to be completed. The time hen using TCP to
complete the task is greater that the one using UDP. When using TCP, source and destination need to
perform a three-way handshake before starting sending data and all amount of data need to be acknowledge
by the destination when it is receive, so is taking more time than UDP, which doesn't perform this tasks.
The main difference between these two protocols is that TCP provides reliability and congestion
control services, while UDP is orientated to improve performance. The most important and common thing
that TCP and UDP are using is the ability to set a host-to-host communication channel, so the packets will
be delivered between processes running on two different computers. UDP is the right choice for application
where reliability is not a must but the speed and performance is. Instead, TCP, even if it takes more time for
the processes, has additional functions like same order delivery, reliability and flow control. As future
work, we plan to conduct several studies regarding packets routing in computer networks to improve the
fairness of data transmissions using different network protocols.
RESULT:
Thus the study of TCP/UDP performance using simulation tool was executed successfully.
Ex No:9A
Date:15/10/24 Simulation of Distance Vector Routing Algorithm
AIM:
TO simulate and study the distance vector routing using simulation using NS2.
ALGORITHM:
There are several various of flooding algorithm most work roughly as follows.
1) Each node act as both a transmitter and receiver.
2) Each node tries to forward every message to every one of its neighbours except the source
node. This results in every message eventually being delivered to all reachable parts of the
network.
PROGRAM:
set ns [new Simulator]
set nf [open out.nam w]
$ns namtrace-all $nf
set tr [open out.tr w]
$ns trace-all $tr
proc finish {} {
global nf ns tr
$ns flush-trace
close $tr
exec nam out.nam &
exit 0
}
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
$ns duplex-link $n0 $n1 10Mb 10ms DropTail
$ns duplex-link $n1 $n3 10Mb 10ms DropTail
$ns duplex-link $n2 $n1 10Mb 10ms DropTail
$ns duplex-link-op $n0 $n1 orient right-down
$ns duplex-link-op $n1 $n3 orient right
$ns duplex-link-op $n2 $n1 orient right-up
set tcp [new Agent/TCP]
$ns attach-agent $n0 $tcp
set ftp [new Application/FTP]
$ftp attach-agent $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n3 $sink
set udp [new Agent/UDP]
$ns attach-agent $n2 $udp
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
set null [new Agent/Null]
$ns attach-agent $n3 $null
$ns connect $tcp $sink
$ns connect $udp $null
$ns rtmodel-at 1.0 down $n1 $n3
$ns rtmodel-at 2.0 up $n1 $n3
$ns rtproto DV
$ns at 0.0 "$ftp start"
$ns at 0.0 "$cbr start"
$ns at 5.0 "finish"
$ns run
OUTPUT:
RESULT:
Thus the distance vector routing algorithm was simulated and studied.
Ex No:9B
Date:15/10/24 SIMULATION OF LINK STATE ROUTING ALGORITHM
AIM:
To simulate and study link state routing algorithm using NS2 simulation.
ALGORITHM:
Step 1: Create a simulator object.
Step 2: Define different colors for different data flows.
Step 3: Open a nam trace file and define finish procedure the close trace file.
Step 4: Create n numbers of nodes using for loop.
Step 5: Create duplex links between nodes.
Step 6: Setup UDP connection between n(1) and n(5).
Step 7: Setup another UDP connection between n(1) and n(5)
Step 8: Apply CBR traffic over both UDP connection.
Step 9: Choose link state routing protocol to transmit data.
Step 10: Run the program.
PROGRAM:
set ns [new Simulator]
set nf [open out.nam w]
$ns namtrace-all $nf
set tr [open out.tr w]
$ns trace-all $tr
proc finish {} {
global nf ns tr
$ns flush-trace
close $tr
exec nam out.nam &
exit 0
}
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
$ns duplex-link $n0 $n1 10Mb 10ms DropTail
$ns duplex-link $n1 $n3 10Mb 10ms DropTail
$ns duplex-link $n2 $n1 10Mb 10ms DropTail
$ns duplex-link-op $n0 $n1 orient right-down
$ns duplex-link-op $n1 $n3 orient right
$ns duplex-link-op $n2 $n1 orient right-up
set tcp [new Agent/TCP]
$ns attach-agent $n0 $tcp
set ftp [new Application/FTP]
$ftp attach-agent $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n3 $sink
set udp [new Agent/UDP]
$ns attach-agent $n2 $udp
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
set null [new Agent/Null]
$ns attach-agent $n3 $null
$ns connect $tcp $sink
$ns connect $udp $null
$ns rtmodel-at 1.0 down $n1 $n3
$ns rtmodel-at 2.0 up $n1 $n3
$ns rtproto LS
$ns at 0.0 "$ftp start"
$ns at 0.0 "$cbr start"
$ns at 5.0 "finish"
$ns run
OUTPUT:
RESULT:
Thus the program for creating simulation of link state routing was implemented
successfully.
Ex No:10 Simulation of an Error Correction Code (like CRC)
Date:22/10/24
AIM:
To Simulate the Cyclic Redundancy Check using data.
Algorithm:
Step 1: Start
Step 2: Open the editor and type the program.
Step 3: Get the input in the form of bits.
Step 4: Append the redundancy bits.
Step 5: Divide the append data using division polynomial.
Step 6: The resultant data should be transmitted both to the receiver.
Step 7: The same process repeated at receiver.
Step 8: Stop.
Program:
import java.io.*;
class CRC{
public static void main(String args[]) throws IOException{
BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
System.out.println("Enter Generator:");
String gen=br.readLine();
System.out.println("Enter Data:");
String data=br.readLine();
String code=data;
while (code.length()<(data.length()+gen.length()-1))
code=code + "0";
code=data + div(code, gen);
System.out.println("The transmitted Code Word is: " + code);
System.out.println("Please enter the received Code Word:");
String rec=br.readLine();
if (Integer.parseInt(div(rec, gen))==0)
System.out.println("The received code word contains no error.");
else
System.out.println("The received code word contains error.");
}
static String div(String num1, String num2)
{ int pointer=num2.length();
String result=num1.substring(0, pointer);
String remainder="";
for (int i=0;i<num2.length(); i++) {
if (result.charAt(i)==
num2.charAt(i)) remainder += "0";
else
remainder += "1";
}
while (pointer<num1.length()) {
if (remainder.charAt(0)=='0')
{
remainder=remainder.substring(1);
remainder=remainder+ num1.charAt(pointer);
pointer++;
}
result=remainder;
remainder="";
for (int i=0;i<num2.length();i++){
if (result.charAt(i)==num2.charAt(i))
remainder+="0";
else
remainder+="1";
}
}
return remainder.substring(1);
}
}
OUTPUT:
Result:
Thus the error detection and error correction was implemented
successfully.