CN Lab Manual
CN Lab Manual
DINDIGUL
(Approved by AICTE and Affiliated to Anna University, Chennai)
SBM NAGAR, THAMARAIPADI, TR I CH Y ROAD, DINDIGUL - 624 005.
TAMILNADU.
NAME :
BRANCH :
REG.No :
SBM COLLEGE OF ENGINEERING AND TECHNOLOGY, DINDIGUL
(Approved by AICTE and Affiliated to Anna University, Chennai)
SBM NAGAR, THAMARAIPADI, TRICHY ROAD, DINDIGUL - 624 005.
TAMILNADU.
BONAFIDE CERTIFICATE
Register Number:
Dindigul - 5.
AIM:
To execute an all types of command in command prompt
ALGORITHM:
Step 1: Open a terminal or command prompt.
Step 2: Use the "ping" command to test network connectivity to a specified host or IPaddress.
Step 3: Use the "traceroute" or "tracert" command to trace the route of packets fromthe local
system to a specified host or IP address.
Step 4: Use the "nslookup" or "dig" command to query DNS (Domain Name System)for
information about a specified domain name or IP address.
Step 5: Use the "netstat" command to display active network connections, including open
portsand listening services.
Step 6: Use the "ifconfig" or "ipconfig" command to display information about the network
interfaces on the local system, including IP address, subnet mask, and MACaddress.
Step 7: Use the "tcpdump" or "wireshark" command-line tools to capture and analyze
networktraffic in real-time.
NETWORK COMMANDS:
1.PING
Command to enter: ping
Ping is used to test whether one network host is able to communicate with another
2. IPCONFIG
Command to enter: ipconfig
The ipconfig command displays basic IP address configuration information for the
Windowsdevice you are working on.
3. GETMAC
Command to enter: getmac
The getmac command provides an easy way to find the MAC address of your device. If you see
more than one MAC address for your device, it will have multiple network adapters. As an example, a
laptop withboth Ethernet and Wi-Fi will have two separate MAC addresses.
4. HOSTNAME:
Command to enter: hostname
The hostname command provides you with an easy wayof identifying the hostname that has been
assigned to your Windows device.
5. ARP
Command to enter: arp -a
ARP stands for Address Resolution Protocol and the command is used to map an IP address to
a MAC address.
6. NSLOOKUP:
Command to enter: nslookup
NSLookup is useful for diagnosing DNS name resolution problems
7. NBTSTAT:
Command to enter: nbtstat
Windows uses different methods to associate NetBIOS names with IP addresses; these include broadcast and
LMHost lookup.
8. NET:
Command to enter: net
The net command is definitely a versatile one, allowing you to manage many differentaspects of a
network and its settings such as network shares, users and print jobs
9. NETSTAT:
Command to enter: nbtstat
Run netstat and you’ll see a list of active connections, with more being added every few seconds. It will
describe the protocol being used, the local address, the foreign address, andthe connection state
10. NETSH:
Command to enter: netsh
When you run the netsh command on its own, the command prompt will be shifted into network shell
mode. Within this mode, there are several different “contexts”, such as one forDHCP-related commands,
one for diagnostics and one for routing.
11. TRACERT:
Command to enter: tracert
Byusing the tracert command you can trace the route a packet takes before reaching its destination,
and see information on each “hop” along the route
12. TASKKILL:
Command to enter: taskkill
Instead of using task manager, we may use taskkill to kill the process in command prompt.
13. PATHPING:
Command to enter: pathping
Pathping combines that best of both ping and tracert into a single utility.Enter pathpingfollowed by a
hostname into the command prompt and it will initiate what looks like a regular old tracert command
RESULT:
These commands help monitor, troubleshoot, configure network settings, and transfer files to ensure
efficient network operation.
Ex. no:2
Date:
HTTP web client program to download a web page using TCP sockets
AIM:
To develop a Java program that uses the requests module to send an HTTP GET request todownload a web
page from a specified URL.
ALGORITHM:
Step 1: Import the requests module to send HTTP requests.
Step 2: Define the URL of the web page to download.
Step 3: Send an HTTP GET request to the URL using the requests.get() method.
Step 4: Retrieve the response from the HTTP request and store it in a variable.
Step 5: Print the status code ofthe response to confirm the request was successful.
Step 6: Optionally, save the HTML content of the web page to a file or manipulate the dataas needed.
CLIENT:
1 Start the program, declare the variables
2 Create a socket using the socket structure socket(AF_INET, SOCK_STREAM,0)3 Set the
socket family, IP address and the port using the server address
4 Set the socket address of 8 bytes to zero using the memset() function5 Establish
the connection to the server
6 Read web address to be downloaded and send it to the server as a request7 Receive
the message from the server for a search result
8 Display the file which is downloaded
9 Terminate the connection and compile and execute.
SERVER:
}
public static void main(String args[])throws IOException{
String url = "https://www.espn.in/";
DownloadWebPage(url);}
}
RESULT:
Thus, the java program to implement socket for HTTP for web page upload and downloadwas
executed successfully and output was verified
Ex. no:3 a) TCP ECHO SERVER/CLIENT
Date:
AIM:
To implement Echo Server/Client in java using TCP socket.
ALGORITHM:
Server:
1. Create a server socket.
2. Wait for client to be connected.
3. Read text fromthe client
4. Echo the text back to the client.
5. Repeat steps 4-5 until ‘bye’ or ‘null’ is read.
6. Close the I/O streams
7. Close the server socket
8. Stop
Client:
RESULT:
Thus data from client to server is echoed back to the client to check reliability/noise level of the
channel
Ex. no:3 b) TCP CHAT SERVER/CLIENT
Date:
AIM:
To implement a chat server and client in java using TCP sockets
ALGORITHM:
Server:
1. Create a server socket
2. Wait for client to be connected.
3. Read Client's message and display it
4. Get a message from user and send it to client
5. Repeat steps 3-4 until the client sends "end"
6. Close all streams
7. Close the server and client socket
8. Stop
Client:
1. Create a client socket and establish connection with the server
2. Get a message from user and send it to server
3. Read server's response and display it
4. Repeat steps 2-3 until chat is terminated with "end" message
5. Close all input/output streams
6. Close the client socket
7. Stop
PROGRAM:
tcpchatserver.java
import java.io.*;
import java.net.*; class
tcpchatserver
{
public static void main(String args[])throws Exception
{
PrintWriter toClient;
BufferedReader fromUser, fromClient;try
{
ServerSocket Srv = new ServerSocket(5555);
System.out.print("\nServer started\n"); Socket Clt =
Srv.accept(); System.out.println("Client connected");
toClient = new PrintWriter(new BufferedWriter(new
OutputStreamWriter(Clt.getOutputStream())), true);
fromClient = new BufferedReader(new InputStreamReader(Clt.getInputStream()));fromUser =
new BufferedReader(new InputStreamReader(System.in));
String CltMsg, SrvMsg;
while(true)
{
CltMsg= fromClient.readLine();
if(CltMsg.equals("end"))
break;
else
{
System.out.println("\nServer <<< " + CltMsg);
System.out.print("Message to Client : ");
SrvMsg = fromUser.readLine();
toClient.println(SrvMsg);
}
}
System.out.println("\nClient Disconnected");fromClient.close();
toClient.close();
fromUser.close();
Clt.close();
Srv.close();
}
catch (Exception E)
{
System.out.println(E.getMessage());
}
}
}
tcpchatclient.java
import java.io.*;
import java.net.*;
class tcpchatclient
{
public static void main(String args[])throws Exception
{
Socket Clt; PrintWriter
toServer;
BufferedReader fromUser, fromServer;try
{
if (args.length > 1)
{
System.out.println("Usage: java hostipaddr");
System.exit(-1);
}
if (args.length == 0)
Clt = new Socket(InetAddress.getLocalHost(),5555); else
Clt = new Socket(InetAddress.getByName(args[0]), 5555);
toServer = new PrintWriter(new BufferedWriter(new
OutputStreamWriter(Clt.getOutputStream())), true);
fromServer = new BufferedReader(new InputStreamReader(Clt.getInputStream()));fromUser =
new BufferedReader(new InputStreamReader(System.in));
String CltMsg, SrvMsg; System.out.println("Type \"end\" to Quit");while
(true)
{
System.out.print("\nMessage to Server : ");
CltMsg = fromUser.readLine();
toServer.println(CltMsg);
if (CltMsg.equals("end")) break;
SrvMsg = fromServer.readLine();
System.out.println("Client <<< " + SrvMsg);
}
}
catch(Exception E)
{
System.out.println(E.getMessage());
}}}
RESULT:
Thus, boththe client and server exchange data using TCP socket programming.
Ex. no:4 Simulation of DNS using UDP sockets
Date:
AIM:
To implement a DNS server and client in java using UDP sockets.
ALGORITHM:
Server:
1. Define a arrayof hosts and its corresponding IP address in another array
2. Create a datagram socket
3. Create a datagram packet to receive client request
4. Read the domain name from client to be resolved
5. Lookup the host array for the domain name
6. If found then retrieve corresponding address
7. Construct a datagram packet to send response back to the client
8. Repeat steps 3-7 to resolve further requests from clients
9. Close the server socket
10.Stop
Client:
1. Create a datagram socket
2. Get domain name from user
3. Construct a datagram packet to send domain name to the server
4. Create a datagram packet to receive server message
5. If it contains IP address then display it, else display "Domain does not exist"
6. Close the client socket
7. Stop
PROGRAM:
udpdnsserver.java
import java.io.*;
import java.net.*;
public class udpdnsserver
{
private static int indexOf(String[] array, String str)
{
str = str.trim();
for (int i=0; i < array.length; i++)
{
if (array[i].equals(str)) return i;
}
return -1;
}
public static void main(String arg[])throws IOException
{
String[] hosts = {"yahoo.com", "gmail.com", "cricinfo.com", "facebook.com"}; String[] ip =
{"68.180.206.184", "209.85.148.19", "80.168.92.140", "69.63.189.16"};
System.out.println("Press Ctrl + C to Quit");while (true)
{
DatagramSocket serversocket=new DatagramSocket(1362); byte[] senddata = newbyte[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();
}
}
udpdnsclient.java
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();
}
}
RESULT:
Thus domain name requests by the client are resolved into their respective logical address using lookup
method
Ex. no:5 Using Wireshark to capture packets and examine the packets
Date:
INTRODUCTION:
Wireshark is a free and open-source network protocol analyzer used for troubleshooting, analysis,
software and protocol development, and education. It allows users to capture and view network traffic in
real-time and analyze network packets to identify potential issues or vulnerabilities. Wireshark supports a
wide range of protocols and can be used on various platforms including Windows, macOS, and Linux.
Wireshark captures packets in real-time and displays them in a user-friendly graphical interface. It supports
hundreds of protocols and allows users to drill down to the lowest levels of a network packet to analyze
individual fields and bits. Additionally, it offers powerful filtering capabilities, allowing users to focus on
specific network traffic patterns or issues.
AIM:
To capture and examine packets in my computer network using Wireshark.
ALGORITHM:
1. Download and install Wireshark on your computer.
2. Launch Wireshark and select the network interface you want to capture packets from.
3. Start the packet capture by clicking the "Capture" button in the Wireshark userinterface.
4. Use the Wireshark filters to capture only the packets you are interested in examining.
5. Stop the packet capture when you have captured enough packets for your analysis.
6. Analyse the captured packets by examining the packet headers and contents.
7. Use the various Wireshark tools and features to analyse the packet data, such as the packet
list,packet details, and packet tree views.
8. Save the captured packet data and analysis results for further analysis or future reference.
STEPS:
1. Open Wireshark and select the network interface you want to capture packets from.
2. Click the "Start" button in Wireshark to begin capturing packets.
3. Perform the network activity you want to capture packets for
6. Identify any issues or anomalies in the network activity and troubleshoot as needed.
RESULT:
Thus, the packets were captured and examined using Wireshark tool
Ex. no:6 a) ARP CLIENT/SERVER
Date:
AIM:
To know the physical address of a host when its logical address is known using ARPprotocol.
ALGORITHM:
Server:
1. Create a server socket.
2. Accept client connection.
3. Read IP address fromthe client request
4. Check its configuration file and compare with its logical address.
5. If there is a match, send the host physical address.
6. Stop
Client:
1. Create a socket.
2. Send IP address to the target machine
3. Receive target's response
4. If it is a MAC address then display it and go to step 6
5. Display "Host not found"
6. Stop
PROGRAM:
Arpclient.java
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);
}
}
}
arpserver.java
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[]={"192.168.4.215","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);
}
}
}
RESULT:
Thus, using ARP protocol MAC address is obtained.
Ex. no:6 b) RARP CLIENT/SERVER
Date:
AIM:
To know the logical address of a host when its physical address is known using
RARP protocol.
ALGORITHM:
Server:
1. Create a server socket.
2. Accept client connection.
3. Read MAC address from the client request
4. Check its configuration file and compare with its physical address.
5. If there is a match, send the host logical address.
6. Stop
Client:
1. Create a socket.
2. Send physical address to the target machine
3. Receive target's response
4. If it is a IP address then display it and go to step 6
5. Display "Host not found"
6. Stop
Program:
Rarpserver.java
import java.io.*;
import java.net.*;
import java.util.*;
class Serverrarp
{
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"};
String mac[]={"6A:08:AA:C2","8A:BC:E3:FA"};
for(int i=0;i<mac.length;i++)
{
if(str.equals(mac[i]))
{
dout.writeBytes(ip[i]+'\n');
break;
}
}
obj.close();
}
}
catch(Exception e)
{
System.out.println(e);
}
}
rarpclient.java
import java.io.*;
import java.net.*;
import java.util.*;
class Clientrarp
{
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 Physical Addres (MAC):");
String str1=in.readLine();
dout.writeBytes(str1+'\n');
String str=din.readLine();
System.out.println("The Logical address is(IP): "+str);
clsct.close();
}
catch (Exception e)
{
System.out.println(e);
}
}
}
RESULT:
Thus using RARP protocol IP address is obtained
Ex. no:7 Study of Network simulator (NS) and Simulation of
Date: Congestion Control Algorithms using NS.
Aim:
Provide users with practical feedback such as accuracy, efficiency, cost, etc., when designing
real world systems.
Simulations take the building/rebuilding phase out of the loop by using the model already
created in the design phase. Effective means for teaching or demonstrating concepts to
students.
A few popular network simulators are NS-2, OPNET, GLOMOSIM, etc.
The root of the hierarchy is the TclObject class that is the superclass of all OTcl library objects(scheduler,
network components, timers and the other objects including NAM related ones). As an ancestor class of
TclObject, NsObject class is the superclass of all basic network component objects that handle packets,
which may compose compound network objects such as nodes and links. The basic network components are
further divided into two subclasses, Connector and Classifier, based on the number of the possible output
data paths. The basic network objects that have only one output data path are under the Connector class, and
switching objects that have possible multiple output data paths are under the Classifier class.
Running NS2:
A OTcl script is generally composed as follows:
Create a new simulator object
Turn on tracing
Create network (physical layer)
Create link and queue (data-link layer)
Define routing protocol
Create transport connection (transport layer)
Create traffic (application layer)
Insert errors
PROGRAM:
# Create a simulator object
set ns [new Simulator]
# Define different colors
# for data flows (for NAM)
$ns color 1 Blue
$ns color 2 Red
# Open the NAM trace fileset
nf [open out.nam w]
$ns namtrace-all $nf
# Define a 'finish' procedureproc
finish {} {
global ns nf
$ns flush-trace
# Close the NAM trace file
close $nf
# Execute NAM on the trace fileexec
nam out.nam &
exit 0
}
# Create four nodesset
n0 [$ns node] set n1
[$ns node] set n2 [$ns
node] set n3 [$ns
node]
# Create links between the nodes
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns duplex-link $n2 $n3 1.7Mb 20ms DropTail# Set
Queue Size of link (n2-n3) to 10
$ns queue-limit $n2 $n3 10
# Give node position (for NAM)
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right
# Monitor the queue for link (n2-n3). (for NAM)
$ns duplex-link-op $n2 $n3 queuePos 0.5#
Setup a TCP connection
set tcp [new Agent/TCP]
$tcp set class_ 2
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n3 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
# Setup a FTP over TCP connectionset ftp
[new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
# Setup a UDP connectionset
udp [new Agent/UDP]
$ns attach-agent $n1 $udpset
null [new Agent/Null]
$ns attach-agent $n3 $null
$ns connect $udp $null
$udp set fid_ 2
# Setup a CBR over UDP connection set cbr
[new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ 1000
$cbr set rate_ 1mb
$cbr set random_ false
# Schedule events for the CBR and FTP agents
$ns at 0.1 "$cbr start"
$ns at 1.0 "$ftp start"
$ns at 4.0 "$ftp stop"
$ns at 4.5 "$cbr stop"
# Detach tcp and sink agents#
(not really necessary)
$ns at 4.5 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink"# Call the
finish procedure after
# 5 seconds of simulation time
$ns at 5.0 "finish"
# Print CBR packet size and interval
puts "CBR packet size = [$cbr set packet_size_]"puts
"CBR interval = [$cbr set interval_]"
# Run the simulation
$ns run
RESULT:
Thus, the concepts of Network Simulator [NS2] were studied successfully
Ex. no:8 a) STUDY OF TCP PERFORMANCE
Date:
AIM:
To studyand simulate the performance of TCP using NS2
Connection establishment
To establish a connection, TCP uses a three-way handshake. Before a client attempts to connect with a
server, the server must first bind to a port to open it up for connections: this is called a passive open. Once
the passive open is established, a client may initiate an active open. To establish a connection, the three-way
(or 3-step) handshake occurs:
1. SYN: The active open is performed by the client sending a SYN to the server. It sets the segment's
sequence number to a random value A.
2. SYN-ACK: In response, the server replies with a SYN-ACK. The acknowledgment number is set to one
more than the received sequence number (A + 1), and the sequence number that the server chooses for the
packet is another random number, B.
3. ACK: Finally, the client sends an ACK back to the server. The sequence number is set to the received
acknowledgement value i.e. A + 1, and the acknowledgement number is set to one more than the received
sequence number i.e. B + 1.
At this point, boththe client and server have received an acknowledgment of the connection.
Data transfer
There are a few key features that set TCP apart from User Datagram Protocol:
Ordered data transfer - the destination host rearranges according to sequence number
Retransmission of lost packets - anycumulative stream not acknowledged is retransmitted
Error-free data transfer (The checksum in UDP is optional)
Flow control - limits the rate a sender transfers data to guarantee reliable delivery. The receiver
continually hints the sender on how much data can be received (controlled by the sliding window).
When the receiving host's buffer fills, the next acknowledgment contains a 0 in the window size, to
stop transfer and allow the data in the buffer to be processed.
Congestion control
Reliable transmission
TCP uses a sequence number to identify each byte of data. The sequence number identifies the order of the
bytes sent from each computer so that the data can be reconstructed in order, regardless of any
fragmentation, disordering, or packet loss that may occur during transmission. For every payload byte
transmitted the sequence number must be incremented. In the first two steps of the 3-way handshake, both
computers exchange an initial sequence number (ISN). This number can be arbitrary, and should in fact be
unpredictable to defend against TCP Sequence Prediction Attacks.
Maximum segment size
The Maximum segment size (MSS) is the largest amount of data, specified in bytes, that TCP is willing to
send in a single segment. For best performance, the MSS should be set small enough to avoid IP
fragmentation, which can lead to excessive retransmissions if there is packet loss. To try to accomplish this,
typically the MSS is negotiated using the MSS option when the TCP connection is established, in which
case it is determined by the maximum transmission unit (MTU) size of the data link layer of the networks to
which the sender and receiver are directly attached. Furthermore, TCP senders can use Path MTU discovery
to infer
the minimum MTU along the network path between the sender and receiver, and use this to dynamically
adjust the MSS to avoid IP fragmentation within the network.
Connection termination
The connection termination phase uses, at most, a four-way handshake, with each side of the connection
terminating independently. When an endpoint wishes to stop its half of the connection, it transmits a FIN
packet, which the other end acknowledges with an ACK. Therefore, a typical tear-down requires a pair of
FIN and ACK segments from each TCP endpoint.
A connection can be "half-open", in which case one side has terminated its end, but the other has not. The
side that has terminated can no longer send any data into the connection, but the other side can. The
terminating side should continue reading the data until the other side terminates as well.
It is also possible to terminate the connection by a 3-way handshake, when host A sends a FIN and host B
replies with a FIN & ACK (merely combines 2 steps into one) and host A replies with an ACK. This is
perhaps the most common method.
It is possible for both hosts to send FINs simultaneously then both just have to ACK. This could possibly be
considered a 2-way handshake since the FIN/ACK sequence is done in parallel for both directions.
Some host TCP stacks may implement a "half-duplex" close sequence, as Linux or HP-UX do. If such a host
actively closes a connection but still has not read all the incoming data the stack already received from the
link, this host sends a RST instead of a FIN (Section 4.2.2.13in RFC 1122). This allows a TCP application to
be sure the remote application has read all the data the former sent—waiting the FIN from the remote side,
when it actively closes the connection. However, the remote TCP stack cannot distinguish between a
Connection Aborting RST and this Data Loss RST. Both cause the remote stack to throw away all the data it
received, but that the application still didn't read.
Some application protocols may violate the OSI model layers, using the TCP open/close handshaking for the
application protocol open/close handshaking - these may find the RST problem on active close.
TCP ports
TCP uses the notion of port numbers to identify sending and receiving application end-points on a host, or
Internet sockets. Each side of a TCP connection has an associated 16-bit unsigned port number (0-65535)
reserved by the sending or receiving application. Arriving TCP data packets are identified as belonging to a
specific TCP connection by its sockets, that is, the combination of source host address, source port,
destination host address, and destination port. This means that a server computer can provide several clients
with several services simultaneously, as long as a client takes care of initiating any simultaneous connections
to one destination port from different source ports.
Port numbers are categorized into three basic categories: well-known, registered, and dynamic/private. The
well-known ports are assigned by the Internet Assigned Numbers Authority (IANA) and are typically used
by system-level or root processes. Well-known applications running as servers and passively listening for
connections typically use these ports. Some examples include: FTP (21), SSH (22), TELNET (23), SMTP
(25) and HTTP (80). Registered ports are typically used by end user applications as ephemeral source ports
when contacting servers.
ALGORITHM:
1. Create a simulator object.
2. Open the nam and trace output files.
3. Create network nodes A, R, and B.
4. Create duplex links between A and R, and between R and B, with specified bandwidth and delay.
5. Set the queue size at node R to 7 packets, including the packet being sent.
6. Create a TCP sending agent and attach it to node A, and a TCP receive agent (a traffic sink) and
attach it to node B.
7. Schedule the TCP connection to start sending data at T=0 and stop at T=10.0. Trace some variables
for the sending agent, such as congestion window size and maximum sequence number.
8. Run the simulation and save the trace output to the name and trace files. Close the files when finished.
PROGRAM:
# basic1.tcl simulation: A---R---B
#Create a simulator object
RESULT:
Thus, the study of TCP performance and simulation using NS2 was performed successfully.
Ex. no:8 b) STUDY OF UDP PERFORMANCE
Date:
AIM:
To study and simulate the performance of UCP using NS2.
Checksum
The checksum field is used for error-checking of the header and data. If no checksum is generated by the
transmitter, the field uses the value all-zeros. This field is not optional for IPv6.
Checksum computation
The method used to compute the checksum is defined in RFC 768: Checksum is the 16-bit one's complement
of the one's complement sum of a pseudo header of information from the IPheader, the UDP header, and the
data, padded with zero octets at the end (if necessary) to make a multiple of two octets. In other words, all
16- bit words are summed using one's complement arithmetic. The sum is then one's complemented to yield
the value of the UDP checksum field. If the checksum calculation results in the value zero (all 16 bits 0) it
should be sent as the one's complement (all 1's).The difference between IPv4 and IPv6 is in the data used to
compute thechecksum
Comparison of UDP and TCP
Transmission Control Protocol is a connection-oriented protocol, which means that it requires handshaking
to set up end-to-end communications. Once a connection is set up user data may be sent bi-directionally over
theconnection.
Reliable – TCP manages message acknowledgment, retransmission and timeout. Multiple attempts
to deliver the message are made. If it gets lost along the way, the server will re-request the lost part.
In TCP, there's either no missing data, or, in case of multiple timeouts, the connection is dropped.
Ordered – if two messages are sent over a connection in sequence, the first message will reach the
receiving application first. When data segments arrive in the wrong order, TCP buffers the out-of-
orderdata until all data can be properlyre-ordered and delivered to the application.
Heavyweight – TCP requires three packets to set up a socket connection, before any user data can
be sent. TCP handle’s reliability and congestion control. Streaming – Data is read as a byte stream;
no distinguishing indications are transmitted to signal message (segment) boundaries.
UDP is a simpler message-based connectionless protocol. Connectionless protocols do not setup a dedicated
end-to-end connection. Communication is achieved by transmitting information in one direction from
source to destination without verifying the readiness or state of the receiver.
Unreliable – When a message is sent, it cannot be known if it will reach its destination; it could get
lost along the way. There is no concept of acknowledgment, retransmission or timeout.
Not ordered – If two messages are sent to the same recipient, the order in which they arrive cannot
be predicted.
Datagrams – Packets are sent individually and are checked for integrity only if they arrive. Packets
have definite boundaries which are honored upon receipt, meaning a read operation at the receiver
socket will yield an entire message as it was originally sent.
ALGORITHM:
1. Create a new network simulator instance and open trace files.
2. Create network nodes using node() function.
3. Create network links using duplex-link() and duplex-link-op() functions. Attach agents
andapplications to nodes:
a. Create UDP agent and CBR application and attach them to node n2. Set packet size and
intervalfor CBR.
b. Create UDP agent and CBR application and attach them to node nl. Set packet size and
intervalforor
RESULT:
Thus, the study of UCP performance and simulation using NS2 was performed successfully.
Ex. no:9 a) SIMULATION OF DISTANCE VECTOR ROUTING PROTOCOL
Date:
AIM:
To create distance vector routing protocol using NS2 simulator.
ALGORITHM:
PROGRAM:
set ns [new Simulator] set
nf [open out.nam w]
$ns namtrace-all $nfset
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-upset 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 $sinkset
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"
RESULT:
Thus, the above program to do the Distance Vector Routing Protocol was executed and output is verified.
Ex. no:9 b) SIMULATION OF LINK STATE ROUTING PROTOCOL
Date: USING NS2
AIM:
To create link state routing protocol using NS2 simulator.
ALGORITHM:
Step1.Create a simulator object ns.
Step2.Create 6 nodes namely n0 to n5, then create the duplex link between these nodesusing the object ns.
Step3.Assign node positions for each and every node.
Step4.Set the queue size for the link and monitor the queue to avoid packet loss. Step5.Create agent
and sources for each end nodes to establish the TCP connection. Step6.Schedule events for the CBR
and FTP agents based on link state routing protocol. Step7.Create finish procedure.
Step8.Run the simulator.
PROGRAM:
set ns [new Simulator]set
nr [open thro.tr w]
$ns trace-all $nr
set nf [open thro.nam w]
$ns namtrace-all $nf
proc finish { } { global
ns nr nf
$ns flush-trace
close $nf close
$nr
exec nam thro.nam &exit
0}
for { set i 0 } { $i < 12} { incr i 1 } {set
n($i) [$ns node]}
for {set i 0} {$i < 8} {incr i} {
$ns duplex-link $n($i) $n([expr $i+1]) 1Mb 10ms DropTail}
$ns duplex-link $n(0) $n(8) 1Mb 10ms DropTail
$ns duplex-link $n(1) $n(10) 1Mb 10ms DropTail
$ns duplex-link $n(0) $n(9) 1Mb 10ms DropTail
$ns duplex-link $n(9) $n(11) 1Mb 10ms DropTail
$ns duplex-link $n(10) $n(11) 1Mb 10ms DropTail
$ns duplex-link $n(11) $n(5) 1Mb 10ms DropTailset udp0
[new Agent/UDP]
$ns attach-agent $n(0) $udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0 set
null0 [new Agent/Null]
$ns attach-agent $n(5) $null0
$ns connect $udp0 $null0 set
udp1 [new Agent/UDP]
$ns attach-agent $n(1) $udp1
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 500
$cbr1 set interval_ 0.005
$cbr1 attach-agent $udp1 set
null1 [new Agent/Null]
$ns attach-agent $n(5) $null1
$ns connect $udp1 $null1
$ns rtproto LS
$ns rtmodel-at 10.0 down $n(11) $n(5)
$ns rtmodel-at 15.0 down $n(7) $n(6)
$ns rtmodel-at 30.0 up $n(11) $n(5)
$ns rtmodel-at 20.0 up $n(7) $n(6)
$udp0 set fid_ 1
$udp1 set fid_ 2
$ns color 1 Red
$ns color 2 Green
$ns at 1.0 "$cbr0 start"
$ns at 2.0 "$cbr1 start"
$ns at 45 "finish"
$ns run
RESULT:
Thus, the above program to do the Link state Routing Protocol was executed and output is verified.
Ex. no:10 SIMULATION OF AN ERROR CORRECTION CODE - CRC
Date:
AIM:
To study Error detecting and error correcting codes (CRC, Hamming code and Checksum).
CRC Checker
Case 1:
o The functionality of the CRC checker is similar to the CRC generator.
o When the string 1001110 is received at the receiving end, then CRC checker performs the modulo-2
division.
o A string is divided bythe same divisor, i.e., 1011.
o In this case, CRC checker generates the remainder of zero. Therefore, the data is accepted.
Case 2:
o The functionality of the CRC checker is similar to the CRC generator.
o When the string 1000110 is received at the receiving end, then CRC checker performsthe modulo-2
division.
o A string is divided bythe same divisor, i.e., 1011.
o In this case, CRC checker generates the non-zero remainder (011). Therefore, the datais discarded.
ALGORITHM:
I. Open the editor and type the program for error detection
RESULT:
Tues the study of Error correction code CRC Cyclic Redundancy Check (CRC) was
completed successfully.