Cs3591 Computer Networks Lab Mannual

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

Om Sakthi

ADHIPARASAKTHI COLLEGE OF ENGINEERING


G.B.Nagar, Kalavai-632506, Vellore District.

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

CS3591 – COMPUTER NETWORK LABORATORY

NAME:

REG.NO:

YEAR: SEM:
Om Sakthi
ADHIPARASAKTHI COLLEGE OF ENGINEERING
G.B. Nagar, Kalavai – 632 506, Vellore District, Tamil Nadu.

DEPARTMENT OF ELECTRONICS &COMMUNCATION ENGINEERING

CERTIFICATE

Certified that is the bonafide record of work done by Mr/Ms____________________ with

Enrollment Number____________________Third year/ VIth Semester B.E COMPUTER SCIENCE

AND ENGINEERING in Anna University during the year 2023 in respect of practical

CS3591 – COMPUTER NETWORK LABORATORY

Submitted for the Practical Examination held on ________________________

SIGNATURE OF FACULTY-IN-CHARGE SIGNATURE OF HEAD OF THE

DEPARTMENT

Internal Examiner External Examiner


CONTENTS
CONTENTS

EX.NO DATE TITLE SIGNATURE


Implementation of IP Commands such as
1 tcpdump, netstat, ifconfig, nslookup and
traceroute
2 HTTP client java program to download a
webpage
3 a) Implementation Of TCP Echo client and Echo
server
3 b)
Implementation Of TCP Talk socket program
4
Simulation of DNS using UDP sockets
5 Wireshark to capture packets and examine the
packets
6 a) Simulation Of ARP Protocol

6 b) Simulation Of RARP Protocol

7 Network simulator (NS) and Simulation of


Congestion Control Algorithms using NS

8 Study of TCP/UDP performance


using Simulation tool.
9 a) Implementation of
Distance Vector Routing
9 b) : Implementation Of Link State Routing
Algorithm
10
Implementation Of Cyclic Redundancy Check(CRC)
EXP NO: 1 Implementation of IP Commands such as tcpdump, netstat, ifconfig, nslookup and
traceroute
DATE:

AIM:
To Learn to use commands like tcpdump, netstat, ifconfig, nslookup and traceroute.

PROCEDURE:
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.
-i Specify an interface on which to capture.
-c Specify the number of packets to receive.
-v, -vv, -vvv Increase the level of detail(verbosity).
-w Write captured data to a file.
-r Read captured data from a file.

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 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 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 Shows connections for the protocol specified by proto; proto may be any of:
proto 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.
-v When used in conjunction with -b, will display sequence of components
involved in creating the connection or listening port for all executables.

interval Redisplays selected statistics, pausing interval seconds between each display.
Press CTRL+C to stop redisplaying statistics. If omitted, netstat will print the
current configuration information once.
Syntax
netstat [-a] [-e] [-n] [-o] [-p Protocol] [-r] [-s] [Interval]
Parameters Used
without parameters without parameters displays active TCP connections.
-a Displays all active TCP connections and the TCP and UDP ports on
which the computer is listening.
-e Displays Ethernet statistics, such as the number of bytes and packets
sent and received. This parameter can be combined with -s.

-n Displays active TCP connections, however, addresses and port


numbers are expressed numerically and no attempt is made to
determine names.

-o Displays active TCP connections and includes the process ID (PID) for
each connection. You can find the application based on the PID on the
Processes tab in Windows Task Manager. This parameter can be
combined with -a, -n, and -p.
-p Shows connections for the protocol specified by Protocol. In this case,
the protocol can be tcp, udp, tcpv6, or udpv6. If this parameter is used
with -s to display statistics by protocol, Protocol can be tcp, udp, icmp,
ip, tcpv6, udpv6, icmpv6, or ipv6.

-s Displays statistics by protocol. By default, statistics are shown for the


TCP,UDP, ICMP, and IP protocols. If the IPv6 protocol for Windows
XP is installed,statistics are shown for the TCP over IPv6, UDP over
IPv6, ICMPv6, and IPv6 protocols. The -p parameter can be used to
specify a set of protocols.

-r Displays the contents of the IP routing table. This is equivalent to the


route print command.
Interval Redisplays the selected information every Interval seconds. Press
CTRL+C to stop the redisplay. If this parameter is omitted, netstat
prints the selected information only once.

/? Displays help at the command prompt.

3. Ifconfig

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. It also allows some control over active TCP/IP connections. Ipconfig replaced the
older winipcfg utility.
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
Syntax
ipconfig [/all] [/renew [Adapter]] [/release [Adapter]] [/flushdns] [/displaydns] [/registerdns]
[/showclassid Adapter] [/setclassid Adapter [ClassID]]
Parameters Used
without parameters displays the IP address, subnet mask, and default gateway for all
adapters.

/all Displays the full TCP/IP configuration for all adapters. Without this
parameter, ipconfig displays only the IP address, subnet mask, and
default gateway values for each adapter. Adapters can represent
physical interfaces, such as installed network adapters, or logical
interfaces, such as dial-up connections.
/renew Renews DHCP configuration for all adapters (if an adapter is not
[Adapter] specified) or for a specific adapter if the Adapter parameter is
included. This parameter is available only on computers with
adapters that are configured to obtain an IP address automatically. To
specify an adapter name, type the adapter name that appears when
you use ipconfig without parameters.
/release Sends a DHCPRELEASE message to the DHCP server to release the
[Adapter] current DHCP configuration and discard the IP address configuration
for either all adapters (if an adapter is not specified) or for a specific
adapter if the Adapter parameter is included. This parameter disables
TCP/IP for adapters configured to obtain an IP address
automatically. To specify an adapter name, type the adapter name
that appears when you use ipconfig without parameters.
/flushdns Flushes and resets the contents of the DNS client resolver cache.
During DNS troubleshooting, you can use this procedure to discard
negative cache entries from the cache, as well as any other entries
that have been added dynamically
/displaydns Displays the contents of the DNS client resolver cache, which
includes both entries preloaded from the local Hosts file and any
recently obtained resource records for name queries resolved by the
computer. The DNS Client service uses this information to resolve
frequently queried names quickly,before querying its configured
DNS servers.
/registerdns Initiates manual dynamic registration for the DNS names and IP
addresses that are configured at a computer. You can use this
parameter to troubleshoot a failed DNS name registration or resolve
a dynamic update problem between a client and the DNS server
without rebooting the client computer. The DNS settings in the
advanced properties of the TCP/IP protocol determine which names
are registered in DNS.
/showclassid Adapter Displays the DHCP class ID for a specified adapter. To see
the DHCP class ID for all adapters, use the asterisk (*) wildcard
character in place of Adapter. This parameter is available only on
computers with adapters that are configured to obtain an IP address
automatically.
/setclassid Adapter [ClassID] Configures the DHCP class ID for a specified
adapter. To set the DHCP class ID for all adapters, use the asterisk
(*) wildcard character in place of Adapter. This parameter is
available only on computers with adapters that are configured to
obtain an IP address automatically. If a DHCP class ID is not
specified, the current class ID is removed.

Examples:
Ipconfig To display the basic TCP/IP configuration for all adapters
ipconfig /all To display the full TCP/IP configuration for all adapters
ipconfig /renew "Local Area To renew a DHCP-assigned IP address configuration for
Connection" only
the Local Area Connection adapter
ipconfig /flushdns To flush the DNS resolver cache when troubleshooting DNS
name resolution problems
ipconfig /showclassid Local To display the DHCP class ID for all adapters with names
that start with Local
ipconfig /setclassid "Local To set the DHCP class ID for the Local Area Connection
Area Connection" TEST adapter to TEST
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.

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.l.google.com [209.85.225.104]
over a maximum of 30 hops:
1 <1 ms <1 ms <1 ms 10.1.0.1
2 35 ms 19 ms 29 ms 98.245.140.1
3 11 ms 27 ms 9 ms te-0-3.dnv.comcast.net [68.85.105.201]
...
13 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 iy-f104.1e100.net [209.85.225.104]
Trace complete.

tracert -j 10.12.0.1 10.29.3.1 10.1.44.1 www.google.com

Result:

Thus the above list of primitive networking commands has been executed successfully.
EXP NO: 2 HTTP client java program to download a webpage
DATE:

AIM
To develop HTTP client java program to download a webpage using TCP sockets.
ALGORITHM:
1) Start the program.
2) Create a socket which binds the Ip address of server and the port address to acquire service.
3) After establishing connection send to the web server.
4) Open a file and store the received data into the file.
5) Print content of the file.
6) Close the socket.
7) End the program.

PROGRAM
import java.io.*;
import java.net.*;
public class SocketHTTPClient {
public static void main(String[] args) {
String hostName = "www.apce.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.apce.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
GET / HTTP/1.1
Host: www.martinbroadhurst.com
<html>
<body>
<div id="search-container" class="search-box-wrapper hide">
<div class="search-box">
<form role="search" method="get" class="search-f
orm" action="http://www.martinbroadhurst.com/">
<label>
<span class="screen-reader-text">Search
for:</span>
<input type="search" class="search-field
" placeholder="Search &hellip;" value="" name="s" />
</label>
<input type="submit" class="search-submit" value="Search" />
</form> </div>
</div>
</header><!-- #masthead -->
<div id="main" class="site-main">
<div id="main-content" class="main-content">
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
</div><!-- .entry-content -->
</article><!-- #post-## -->
</div><!-- #content -->
</div><!-- #primary -->
</div><!-- #main-content -->
<div id="secondary">
<div id="primary-sidebar" class="primary-sidebar widget-area" ro
le="complementary">
<aside id="search-2" class="widget widget_search"><form role="se
arch" method="get" class="search-form" action="http://www.martinbroadhurst.com/">
<label>
<span class="screen-reader-text">Search
for:</span>
<input type="search" class="search-field
" placeholder="Search &hellip;" value="" name="s" />
</label>
<input type="submit" class="search-submit" value
="Search" />
<ul>
<li>
<a href="http://www.martinbroadhurst.com/sgi-stl
-documentation.html">SGI STL Documentation</a>
</li>
<li>
<a href="http://www.martinbroadhurst.com/combina
torial-algorithms.html">Combinatorial algorithms</a>
</li>
<li>
<a href="http://www.martinbroadhurst.com/parsing
-by-generation.html">Parsing by generation</a>
</li>
<li>
</li>
</ul>
<li><a href="https://wordpress.org/" title="Powered by W
ordPress, state-of-the-art semantic personal publishing platform.">WordPress.org
</a></li> </ul>
</aside> </div><!-- #primary-sidebar -->
</div><!-- #secondary -->

</div><!-- #main -->

<footer id="colophon" class="site-footer" role="contentinfo">

<div class="site-info">
<a href="https:/
/wordpress.org/">Proudly powered by WordPress</a>
</div><!-- .site-info -->
</footer><!-- #colophon -->
</div><!-- #page -->

</body>
</html>

RESULT
The webpage is successfully downloaded and the contents are displayed
EXP NO: 3 a) Implementation Of TCP Echo client and Echo server
DATE:

AIM

To create a java program for implementing socket program of TCP Echo client and Echo
server
ALGORITHM:

Step 1:Start the program.


Step 2:Create the client and server socket.
Step 3:Bind the server address in the client socket.
Step 4:Send message from client socket to server socket.
Step 5:Server socket reads the message from client socket display it and rewrite back to client
socket.
Step 6:Client socket display the echoed message from server socket.
Step 7:Stop the program.

PROGRAM:

Echo client program:


import java.io.*;
import java.net.*;
import java.util.*;
public class echoclient
{
public static void main(String args[])throws Exception
{
Socket c=null;
DataInputStream usr_inp=null;
DataInputStream din=new DataInputStream(System.in);
DataOutputStream dout=null;
try
{
c=new Socket("127.0.0.1",5678);
usr_inp=new DataInputStream(c.getInputStream());
dout=new DataOutputStream(c.getOutputStream());
}
catch(IOException e)
{
}
if(c!=null || usr_inp!=null || dout!=null)
{
String unip;
while((unip=din.readLine())!=null)
{
dout.writeBytes(""+unip);
dout.writeBytes("\n");
System.out.println("\n the echoed message");
System.out.println(usr_inp.readLine());
System.out.println("\n enter your message");
}
System.exit(0);
}
din.close();
usr_inp.close();
c.close();
}
}

Echo server program:


import java.io.*;
import java.net.*;
public class echoserver
{
public static void main(String args[])throws Exception
{
ServerSocket m=null;
Socket c=null;
DataInputStream usr_inp=null;
DataInputStream din=new DataInputStream(System.in);
DataOutputStream dout=null;
try
{
m=new ServerSocket(5678);
c=m.accept();
usr_inp=new DataInputStream(c.getInputStream());
dout=new DataOutputStream(c.getOutputStream());
}
catch(IOException e)
{}
if(c!=null || usr_inp!=null)
{
String unip;
while(true)
{
System.out.println("\nMessage from Client...");
String m1=(usr_inp.readLine());
System.out.println(m1);
dout.writeBytes(""+m1);
dout.writeBytes("\n");
}
}
dout.close();
usr_inp.close();
c.close();
}
}

OUTPUT
Client:
C:\Program Files\Java\jdk1.6.0\bin>java echoclient
hello
The echoed message
hello
Enter your message
Server:
C:\Program Files\Java\jdk1.6.0\bin>java echoserver
Message from Client...
hello

RESULT:
Thus the program for implementing TCP Echo client and server is successfully executed using java
program
EXP NO: 3 b) Implementation Of TCP chat program
DATE:

AIM
To create a java program for implementing of TCP chat socket program

ALGORITHM:

Step 1:Start the program.


Step 2:Create the client and server socket.
Step 3:Bind the server address in the client socket.
Step 4:Send message from client socket to server socket.
Step 5:Server socket reads the message from client socket , display it and give response
message back to client socket.
Step 6:Client socket in term reads message from server socket and write reply message back to
server socket.
Step 7:Repeat this above procedure until user enters exit message.
Step 8:Stop the program.

PROGRAM:

Talk client:
import java.io.*;
import java.net.*;
public class talkclient
{
public static void main(String args[])throws Exception
{
Socket c=null;
DataInputStream usr_inp=null;
DataInputStream din=new DataInputStream(System.in);
DataOutputStream dout=null;
try
{
c=new Socket("127.0.0.1",1234);
usr_inp=new DataInputStream(c.getInputStream());
dout=new DataOutputStream(c.getOutputStream());
}
catch(IOException e)
{}
if(c!=null || usr_inp!=null || dout!=null)
{
String unip;
System.out.println("\nEnter the message for server:");
while((unip=din.readLine())!=null)
{
dout.writeBytes(""+unip);
dout.writeBytes("\n");
System.out.println("reply");
System.out.println(usr_inp.readLine());
System.out.println("\n enter your message:");
}
System.exit(0);
}
din.close();
usr_inp.close();
c.close();
}
}

Talk server:
import java.io.*;
import java.net.*;
public class talkserver
{
public static void main(String args[])throws Exception
{
ServerSocket m=null;
Socket c=null;
DataInputStream usr_inp=null;
DataInputStream din=new DataInputStream(System.in);
DataOutputStream dout=null;
try
{
m=new ServerSocket(1234);
c=m.accept();
usr_inp=new DataInputStream(c.getInputStream());
dout=new DataOutputStream(c.getOutputStream());
}
catch(IOException e)
{}
if(c!=null||usr_inp!=null)
{
String unip;
while(true)
{
System.out.println("\nmessage from client:");
String m1=usr_inp.readLine();
System.out.println(m1);
System.out.println("enter your message:");
unip=din.readLine();
dout.writeBytes(""+unip);
dout.writeBytes("\n");
}
}
dout.close();
usr_inp.close();
c.close();
}
}
OUTPUT
Client:
C:\Program Files\Java\jdk1.6.0\bin>java talkclient
Enter your message:
hai
reply
hello
enter your message:
Server:
C:\Program Files\Java\jdk1.6.0\bin>java talkserver
message from client:
hai
enter your message:
hello
message from client:

RESULT:
Thus the socket program for implementation of TCP talk is successfully executed .
EXP NO: 4 Simulation of DNS using UDP sockets
DATE:

AIM
To develop a java program to simulate Domain Name Server using UDP socket.
ALGORITHM:
8) Start the program.
9) Create a socket which binds the Ip address of server and the port address to acquire
10) After establishing connection Client sends the domain name to the Server.
11) Server resolves the Domain Name to IP Address and sends back to Client.
12) Close the socket.
13) End the program.

PROGRAM
/ UDP DNS Server
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)
{
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 udpdnsclient
{
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 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
javacudpdnsserver.java
java udpdnsserver
Press Ctrl + C to Quit Request for host yahoo.com
Request for host cricinfo.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 Domain Name Server program to convert domain name to IP address is successfully executed
EXP NO: 5 Wireshark to capture packets and examine the packets
DATE:

AIM
EXP NO: 6(a) Simulation Of ARP Protocol
DATE:

AIM
To write a java program for simulating ARP protocols using TCP.

ALGORITHM

CLIENT

1) Start the program


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

SERVER

1) Start the program


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

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);
Socket obj1=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"};
Stringmac[]={"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:

E:\networks>java Serverarp
E:\networks>java Clientarp
Enter the Logical address(IP):
165.165.80.80
The Physical Address is: 6A:08:AA:C2

RESULT:
Thus the program for simulating ARP protocols using TCP is successfully executed.
EXP NO: 6(b) Simulation Of RARP Protocol
DATE:

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

CLIENT
1) Start the program
2) Using datagram sockets UDP function is established.
3) Get the MAC address to be converted into IP address.
4) Send this MAC address to server.
5) Server returns the IP address to client.

SERVER
1) Start the program.
2) Server maintains the table in which IP and corresponding MAC addresses are stored.
3) Read the MAC address which is send by the client.
4) Map the IP address with its MAC address and return the IP address to client.

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=new DatagramPacket(sendbyte,sendbyte.length,addr,1309);
client.send(sender);
DatagramPacket receiver=new DatagramPacket(receivebyte,receivebyte.length);
client.receive(receiver);
String s=new String(receiver.getData());
System.out.println("The Logical Address is(IP): "+s.trim());
client.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}

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:

I:\ex>java Serverrarp12
I:\ex>java Clientrarp12
Enter the Physical address (MAC):
6A:08:AA:C2
The Logical Address is(IP): 165.165.80.80

RESULT:
Thus the simulation for RARP protocol using UDP is successfully executed.
EX-NO 7 Study of Network simulator (NS) and Simulation of Congestion
DATE: Control Algorithms using NS

Aim:

To Study of Network simulator (NS).and Simulation of Congestion Control Algorithms using


NS

NET WORK SIMULATOR (NS2)


Ns overview

Ns programming: A Quick start

Case study I: A simple Wireless network

Case study II: Create a new agent in Ns
Ns overview

Ns Status

Periodical release (ns-2.26, Feb 2003)

Platform support

FreeBSD, Linux, Solaris, Windows and Mac

Ns unctionalities
Routing, Transportation, Traffic sources,Queuing
disciplines, QoS

Wireless

Ad hoc routing, mobile IP, sensor-MAC


Tracing, visualization and various utilitie
NS(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 facilitate visual 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:

14) ns (open source)


15) OPNET (proprietary software)
16) 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 widely used 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
occurs when one or morepacketsof data travelling across a computer networkfail to reachtheir
destination. Packet loss is distinguished as one of the three main error types encountered in digital
communications; the other two being bit errorand 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,
as well as to frequency and patterns of loss among longer packet sequences is strongly dependent
on the application itself.
Throughput

This is the main performance measure characteristic, and most widely used.
Incommunicationnetworks, such asEthernetorpacket radio, throughputor network throughputis
the average rate of successfulmessage delivery over a communication channel. The throughput is
usually measured inbitsper second (bit/s orbps), andsometimes indata packetsper second or data
packets pertime slotThis measure 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 valueof 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 thesystem 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.

RESULT
Thus the study of Network simulator (NS2)was studied
EX.NO:9 a) IMPLEMENTATION OF DISTANCE VECTOR ROUTING
DATE:

AIM:
To implement the concept of distance vector routing using NetSim.

DISTANCE VECTOR ROUTING:

Distance Vector Routing is one of the routing algorithms used in a Wide Area
Network for computing shortest path between source and destination.
The router is one of the main devices used in a wide area network. The main task
of the
router is routing. It forms the routing table and delivers the packets depending
upon the routes in the table – either directly or via an intermediate device
(perhaps another router).
Each router initially has information about its all neighbors (i.e., it is directly
connected). After a period of time, each router exchanges its routing table among
its neighbors. After certain number of exchanges, all routers will have the full
routing information about the area of the network.
After each table exchange, router re computes the shortest path between the
routers.
The algorithm used for this routing is called Distance Vector Routing.

ALGORITHM:

• Repeat the following steps until there is no change in the routing


table for all routers.
1. Take the Next Router routing table and its neighbor routing table.
2. Add the router entry that is not in your own routing table, but
exists in any one of the other routing tables. If the new router entry
exists in more than one neighbor, then find the minimum cost
among them. The minimum cost value details are taken as a new
entry: such as source router, intermediate router, destination
router and cost value, etc.
3. Update the source router routing table cost value if both the
destination router and the intermediate router field value have
the same value as any one of the neighbors’ routing entry.
4. Update the source router’s routing table entry with the new
advertised one if the intermediate router value in the source table
is not same, but the cost value is greater than the its neighbor’s
entry.
5. Write the next stage of routing table into the file. Repeat steps 1 to

5 for all routers.

Check whether any changes are made in any of the routers. If yes,
then repeat the above steps, otherwise, quit the process

DESCRIPTION:
To begin with the experiment, open NetSim

Click on Programming from the file panel and select Distance Vector Routing.
The scenario will be obtained as shown below. Follow the steps.

When you select the User mode, you have to write your own program in
C/C++, compile and link to NetSim software for validation.

Click on the button to view the file path.

Continue with the steps as given for sample mode.

OUTPUT:
RESULT:
Thus the concept of Distance Vector Routing was implemented successfully and the output was
verified.
EX.NO:9 b)
DATE: IMPLEMENTATION OF LINK STATE ROUTING
ALGORITHM

AIM:
To implement the concept Link state routing Algorithm using a n etsim.

INTRODUCTION:

The router is one of the main devices used in a wide area network. The main task of
the router is routing. It forms the routing table and delivers the packets depending upon
the routes in the table – either directly or via an intermediate device (perhaps
another router).
Link state algorithm is a method used to find the shortest path between a source router
and a destination router based on the distance and route the packets through that

route.

ALGORITHM:

1.
Start with the router: the root of the tree
2.
Assign a cost of 0 to this router and make it the first permanent router.
3.
Examine each neighbor router of the router that was the last permanent router.
4.
Assign a cumulative cost to each router and make it temporary.
5.
Among the list of temporary routers
5. a. Find the router with the smallest cumulative cost and make it permanent.
5. b. If a router can be reached from more than one direction
5. b.1. Select the direction with the shortest cumulative
cost.
6. Repeat steps 3 to 5 until every router becomes permanent. Description
To begin with the experiment, open NetSim

Click on Programming from the file panel and select Link State Routing

The scenario will be obtained as shown below. Follow the steps.


When you select the User mode, you have to write your own program in C/C++,
compile and link to NetSim software for validation.

Click on the button for details on how to proceed with your own code.

Click on the button to view the file path.

Continue with the steps as given for sample mode.


Inference (to be filled up by the
students)
Here, Router 1 is taken as the source and Router 3 as the destination. The paths
are connected with input as the distance. The figure indicated in red line shows the
shortest path.

RESULT:
Thus the concept of Link State Routing was implemented using netsim and output was
verified
EX:NO:10 IMPLEMENTATION OF CYCLIC REDUNDANCY CHECK(CRC)
DATE:
AIM:
To write a c program to implement the concept of Cyclic Redundancy Check(CRC)
ALGORITHM:
STEP 1: Start the program.
STEP 2: Get the input binary data and divisor bits from the user
STEP 3: Add divisor length minus one zero’s at the end of binary input data bits.
STEP 4: Divide input binary data bits with divisor bits using module XOR format.
STEP 5: Remainder bits are taken as CRC bits and replace the added zero in data
bits with the CRC code to make the transmitted data bits.
STEP 6: In receiver side ,divide the received data bits a (Data + CRC) with the
same divisor. If remainder is zero accept (no error) or reject (Error detected).
STEP 7: Stop the program.

Program:
/*Cyclic Redundancy check*/
#include<stdio.h>
#include<string.h>
// length of the generator polynomial
#define N strlen(gen_poly)
// data to be transmitted and received
char data[28];
// CRC value
char check_value[28];
// generator polynomial
char gen_poly[10];
// variables
int data_length,i,j;
void CRC(void);
// function that performs XOR operation
void XOR( )
{
// if both bits are the same, the output is 0
// if the bits are different the output is 1
for(j = 1;j < N; j++)
check_value[j] = (( check_value[j] == gen_poly[j])?'0':'1');
}
// Function to check for errors on the receiver side
void receiver()
{
// get the received data
printf("Enter the received data: ");
scanf("%s", data);
printf("\n-----------------------------\n");
printf("Data received: %s", data);
// Cyclic Redundancy Check
crc( );
// Check if the remainder is zero to find the error
for(i=0;(i<N-1) && (check_value[i]!='1');i++);
if(i<N-1)
printf("\nError detected\n\n");
else
printf("\nNo error detected\n\n");
}

void crc()
{
// initializing check_value
for(i=0;i<N;i++)
check_value[i]=data[i];
do{
// check if the first bit is 1 and calls XOR function
if(check_value[0]=='1')
XOR();
// Move the bits by 1 position for the next computation
for(j=0;j<N-1;j++)
check_value[j]=check_value[j+1];
// appending a bit from data
check_value[j]=data[i++];
}while(i<=data_length+N-1);
// loop until the data ends
}
int main()
{
// get the data to be transmitted
printf("\nEnter data to be transmitted: ");
scanf("%s",data);
printf("\n Enter the Generating polynomial: ");
// get the generator polynomial
scanf("%s",gen_poly);
// find the length of data
data_length=strlen(data);
// appending n-1 zeros to the data
for(i=data_length;i<data_length+N-1;i++)
data[i]='0';
printf("\n----------------------------------------");
// print the data with padded zeros
printf("\n Data padded with n-1 zeros : %s",data);
printf("\n----------------------------------------");
// Cyclic Redundancy Check
crc();
// print the computed check value
printf("\nCRC or Check value is : %s",check_value);
// Append data with check_value(CRC)
for(i=data_length;i<data_length+N-1;i++)

data[i]=check_value[i-data_length];
printf("\n----------------------------------------");
// printing the final data to be sent
printf("\n Final data to be sent : %s",data);
printf("\n----------------------------------------\n");
// Calling the receiver function to check errors
receiver();
return 0;
}

OUTPUT
Enter data to be transmitted: 1001101
Enter the Generating polynomial: 1011
----------------------------------------
Data padded with n-1 zeros : 1001101000
----------------------------------------
CRC or Check value is : 101
----------------------------------------
Final data to be sent : 1001101101
----------------------------------------
Enter the received data: 1001101101
-----------------------------
Data received: 1001101101
No error detected

RESULT:
Thus the c program to implement the concept of Cyclic Redundancy Check(CRC) was
successfully executed and output was verified

You might also like