Cn Lab Manual
Cn Lab Manual
Course: - B. Tech
Year: 3rd /6th Sem
SUBMITTED BY SUBMITTED TO
NAME: Amitesh Pandey NAME: Mr. Arun Kumar Takuli
Mr. Neeraj Chauhan
Section: A
Designation: Assistant Professor
Roll No: 2201920130025
Experiment – 01
Objective: Implementation of Stop and Wait Protocol and Sliding Window Protocol.
Concept:
It is the simplest flow control method. In this, the sender will transmit one frame at a time to the
receiver. The sender will stop and wait for the acknowledgement from the receiver.
This time (i.e. the time joining message transmitting and acknowledgement receiving) is the sender’s
waiting time, and the sender is idle during this time.
When the sender gets the acknowledgement (ACK), it will send the next data packet to the receiver
and wait for the disclosure again, and this process will continue as long as the sender has the data to
send.
While sending the data from the sender to the receiver, the data flow needs to be controlled. If the
sender is trans- mitting the data at a rate higher than the receiver can receive and process it, the data
will get lost.
The Flow-control methods will help in ensuring that the data doesn't get lost. The flow control
method will check that the senders send the data only at a rate that the receiver can receive and
process.
1. Error correction in Stop-and-Wait ARQ is done by keeping a copy of the sent frame and
retransmitting of the frame when the timer expires.
2. In Stop-and-Wait ARQ, we use sequence numbers to number the frames. The sequence
numbers are based on modulo-2 arithmetic
3. In Stop-and-Wait ARQ, the acknowledgment number always announces in modulo-2
arithmetic the se- quence number of the next frame expected.
Socket sender;
ObjectOutputStream out;
ObjectInputStream in; String packet,ack,str, msg; int n,i=0,sequence=0;
sequence=0;
ObjectInputStream(sender.getInputStream());
packet=br.readLine(); n=packet.length();
msg=String.valueOf(sequence); msg=msg.concat(packet.substring(i,i+1));
}out.writeObject(msg); sequence=(sequence==0)?1:0;
out.flush();
}else{
}}catch(Exception e){}
}while(i<n+1);
}catch(Exception e){}
} catch(Exception
e){}
}} public static void main(String args[]){ Sender s=new Sender(); s.run(); }}
ServerSocket reciever;
Socket connection=null;
ObjectOutputStream out;
ObjectInputStream in; String packet,ack,data=""; int i=0,sequence=0; Receiver(){} public void
run(){ try{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); reciever = new
ServerSocket(2005,10); System.out.println("waiting for connection...");
connection=reciever.accept(); sequence=0;
System.out.println("Connection established :"); out=new
ObjectOutputStream(connection.getOutputStream()); out.flush();
do{ try{
packet=(String)in.readObject();
if(Integer.valueOf(packet.substring(0,1))==sequence){ data+=packet.substring(1);
sequence=(sequence==0)?1:0;
System.out.println("\n\nreceiver>"+packet);
} else
}if(i<3){ out.writeObject(String.valueOf(sequence));i++;
}else{
out.writeObject(String.valueOf((sequence+1)%2)); i=0; }} catch(Exception e){}
}while(!packet.equals("end")); System.out.println("Data recived="+data);
out.writeObject("connection ended .");
out.close(); reciever.close();
} catch(Exception
e){}
s.run();
RESULT:
Concept:
The client–server model of computing is a distributed application structure that partitions tasks or
workloads between the providers of a resource or service, called servers, and service requesters, called
clients. Often clients and servers communicate over a computer network on separate hardware, but
both client and server may reside in the same system. A server host runs one or more server programs
which share their resources with clients. A client does not share any of its resources, but requests a
server's content or service function. Clients therefore initiate communication sessions with servers
which await incoming requests.
PROCEDURE:
In main window, enter Cd network, Cd layer, Cd Phy_Lyr , ./main Choose Layers - Transport Layer -
Socket - UDP. After choosing UDP protocol, Click on “Let’s Begin” button on both the systems. To
start the server, click on the Server Socket. Click on the Bind button, which will bind the socket. To
start the Client, first enter the IP Address of a machine where the server is listening. Enter the file name
as a request as shown in Screen. Click on socket to initiate the client socket. Click on the bind option.
Click on the Send To button to write the request. Click on the Recv From button, which will be
highlighted upon receiving a request in server system. Click on the Send To button to write the file
contents in the server system. Click on Recv From button in the client system to read the contents of
the file. Observe the text for the output of the file as shown in Screen.
Java Programming:
Client-Side Program:
try {
Socket soc = new Socket("localhost",6666);
ObjectOutputStream out = new ObjectOutputStream(soc.getOutputStream());
out.writeUTF("Hello Server");
out.flush(); out.close();
soc.close();
}
catch(Exception e)
{
System.out.println(e);
}}
Server-Side Program:
catch(Exception e)
{
System.out.println(e);
}
}
}
OUTPUT:
Objective:
To write a program for simulating arp/rarp protocols
ALGORITHM:
server
1. Create a server socket and bind it to port.
2. Listen for new connection and when a connection arrives, accept it.
3. Send server‟s date and time to the client.
4. Read client‟s IP address sent by the client.
5. Display the client details.
6. Repeat steps 2-5 until the server is terminated.
7. Close all streams.
8. Close the server socket.
9. Stop.
Client
1. Create a client socket and connect it to the server‟s port number.
2. Retrieve its own IP address using built-in function.
3. Send its address to the server.
4. Display the date & time sent by the server.
5. Close the input and output streams.
6. Close the client socket.
7. Stop.
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"}; 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);
}
}
}
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();
//System.out.println(s);
InetAddress addr=receiver.getAddress(); int port=receiver.getPort();
Objective: To Write The java program for simulating ping and traceroute commands.
Concept:
PING Command
The ping command is a very common method for troubleshooting the accessibility of devices.
It uses a series of Internet Control Message Protocol (ICMP) Echo messages to determine:
1.Whether a remote host is active or inactive.
2.The round-trip delay in communicating with the host.
3.Packet loss.
The ping command first sends an echo request packet to an address, and then waits for a reply.
The ping is successful only if:
1.The echo request gets to the destination, and
2.The destination is able to get an echo reply back to the source within a predetermined time called a
timeout. The default value of this timeout is two seconds on Cisco routers.
TRACEROUTE Command
1.The trace route command is used to discover the routes that packets actually take when traveling to their
destination. The device (for example, a router or a PC) sends out a sequence of User Datagram Protocol
(UDP) data grams to an invalid port address at the remote host.
2.Three data grams are sent, each with a Time-To-Live (TTL) field value set to one. The TTL value of 1
causes the datagram to “timeout” as soon as it hits the first router in the path; this router then responds
with an ICMP Time Exceeded Message (TEM) indicating that the datagram has expired.
3.Another three UDP messages are now sent, each with the TTL value set to 2, which causes the second
router to return ICMP TEMs. This process continues until the packets actually reach the other destination.
4.Since these data grams are trying to access an invalid port at the destination host, ICMP Port
Unreachable Messages are returned, indicating an unreachable port; this event signals the Trace route
program that it is finished.
ALGORITHM:
Objective: To learn handling and configuration of networking hardware like RJ-45 connector, CAT-6
cables, crimping tool, etc.
Brief Theory
RJ 45- Registered Jack 45 (RJ45) is a standard type of physical connector for network cables. RJ45
connectors are most commonly seen with Ethernet cables and networks. Modern Ethernet cables feature
small plastic plugs on each end that are inserted into the RJ45 jacks of Ethernet devices.
CAT-6 Cable- Category 6 Cable (Cat 6), is a standardized twisted pair cable for Ethernet and other
network physical layers.
Crimping Tool- Crimping Tool is a device used to conjoin two pieces of metal by deforming one or both
of them in a way that causes them to hold each other.
Result: Configuration of networking hardware like RJ-45 connector, CAT-6 cable, crimping tool, etc. is
learned
EXPERIMENT - 6
Objective: Configuration of router, hub, switch etc. (using real devices or simulators).
Apparatus (Components): Cisco Packet Tracer
Procedure:
Configuration of Hub using Star Topology
Step 1: Open Cisco packet Tracer Software and choose Generic Hub on workspace.
Step 2: Now choose end device as Generic. Connect end devices with Hub (Choose automatic
connection type).
Step 3 - Now click on each end device and enter IP address such as 10.0.0.1 and label the device with
corresponding IP address using text tool available in cisco packet tracer.
Step 4: Now select Simple Message(PDU) from right side of window and click over sender
node and on receiver node.
Step 5: Now click on simulation and click on AutoPlay to see effect.
Configuration of Roter
Step 1: Open Cisco Packet Tracer software and then click on Router and then over Generic, then drag it
over workspace.
Step 2: Design topology as shown in the diagram above.
Step 3: Now click on each end device and enter IP address such as 10.0.0.1 and label the device with
corresponding IP address using text tool available in cisco packet tracer. Be ensure that router should
connect two different networks.
Step 4: Double click router and type router commands to configure router at interface fa0/0 and fa0/1
Router>enable
Router#configure terminal
Router(config)#hostname R1
Router(config)#interface fastethernet 0/0
Router(config-if)# 10.0.0.1 255.0.0.0
Router(config-if)# no shut down
Step 5: Now select Simple Message from right side of window and click over sender node and on receiver
node.
Step 6: Now click on simulation and click on AutoPlay to see effect.
Objective: Running and using services/commands like ping, traceroute, nslookup, arp, telnet, ftp, etc.
Apparatus (Components): Cmd, Cisco Packet Tracer
Procedure: In this experiment students must understand basic networking commands e.g. ping, tracert
etc.
All commands related to Network configuration which includes how to switch to privilege mode and
normal mode and how to configure router interface and how to save this configuration to flash memory or
permanent memory.
This command includes
• Configuring the Router commands • General Commands to configure network • Privileged Mode
commands of a router Router Processes & Statistics IP Commands • Other IP Command e.g. show ip
route etc.
ping:
Verifies IP-level connectivity to another TCP/IP computer by sending Internet Control Message Protocol
(ICMP) Echo Request messages. The receipt of corresponding Echo Reply messages is displayed, along
with round-trip times. Ping is the primary TCP/IP command used to troubleshoot connectivity,
reachability, and name resolution.
You can use ping to test both the computer name and the IP address of the computer. If pinging the IP
address is successful, but pinging the computer name is not, you might have a name Cesolution problem.
In this case, ensure that the computer name you are specifying can b resolved through the local Hosts file,
by using Domain Name System (DNS) queries, or through NetBIOS name resolution techniques.
Traceroute:
Determines the path taken to a destination by sending Internet Control Message Protocol
(ICMP) Echo Request messages to the destination with incrementally increasing Time to Live (TTL) field
values. The path displayed is the list of near-side router interfaces of the routers in the path between a
source host and a destination. The near-side interface is the interface of the router that is closest to the
sending host in the path. Used without parameters, tracert displays help.
To trace the path to the host named www.google.co.in use following command
tracert www.google.co.in
Arp:
Displays and modifies entries in the Address Resolution Protocol (ARP) cache, which contains one or
more tables that are used to store IP addresses and their resolved Ethernet or Token Ring physical
addresses. There is a separate table for each Ethernet or Token Ring network adapter installed on your
computer.
To display the ARP cache tables for all interfaces use following command
arp -a
Nslookup (stands for "Name Server Lookup") is a useful command for getting information from DNS
server. It is a network administration tool for querying the Domain Name System (DNS) to obtain domain
name or IP address mapping or any other specific DNS record. It is also used to troubleshoot DNS related
problems.
Netstat:
Displays active TCP connections, ports on which the computer is listening, Ethernet statistics,
the IP routing table, IPv4 statistics (for the IP, ICMP, TCP, and UDP protocols), and IPv6 statistics (for the
IPv6, ICMPv6, TCP over IPv6, and UDP over IPv protocols).
Result: Successfully ran and used services/commands like ping, traceroute, nslookup, arp, telnet, ftp, etc.
EXPERIMENT - 8
Objective: Network packet analysis using tools like Wireshark, tcpdump, etc.
Apparatus (Components): Wireshark, tcpdump
1. TCPDUMP:
The fundamental tool of almost all network traffic collection is tcpdump. It is an open-source application
that comes installed on almost all Unix-like operating systems. Tcpdump is an excellent collection tool
and comes complete with a very complex filtering language. It's important to know how to filter the data
at collection time in order to end up with a manageable chunk of data to analyze. Capturing all data from
a network device on even a moderately busy network can create too much data to analyze easily.
In some rare cases, allowing tcpdump to output its capture directly to your screen may be enough to find
what you're looking for. For example, in writing this article, I captured some traffic and noticed that my
machine was sending traffic to an IP I did not recognize. It turns out that my machine was sending data to
a Google IP address of 172.217.11.142. Since I did not have any Google products running, nor Gmail
open, I did not know why this was happening. I examined my system and found this:
[~]$ ps -ef | grep google
user 1985 1881 0 10:16? 00:00:00/opt/google/chrome/chrome --type-service
It seems that even when Chrome not running in the foreground it remains running as a service. I would
not have necessarily noticed this without a packet analysis to tip me off. I re- captured some more
tcpdump data but this time told tcpdump to write the data to a file that I opened in Wireshark (more on
that later).
Tcpdump is a favorite tool among sysadmins because it is a command-line tool. This means that it doesn't
require a full-blown desktop to run. It is unusual for production servers to provide a desktop because of
the resources that would take, so command-line tools are preferred. As with many advanced tools,
tcpdump has a very rich and arcane language that takes some time to master. A few of the very basic
commands involve selecting the network interface from which to collect data, and writing that data to a
file so it can be exported for analysis elsewhere. The -i and -w switches are used for this.
# tcpdump -i eth0 -w tcpdump_packets
tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes "C51 packets
captured
This produces a capture file:
file tcpdump_packets
tcpdump packets: tcpdump capture file (little-endian) - version 2.4 (Ethernet, capture length 262144)
The standard TCP capture file is a pcap file. It is not text so it can only be read by an analysis program
that knows how to read pcap files.
2. WinDump
Most useful open source tools are eventually cloned to other operating systems. When this happens, the
application is said to have been ported over. Windump is a port of tcpdump and behaves in very similar
ways.
One major difference between WinDump and tcpdump is that Windump needs the WinpCap library
installed prior to being able to run WinDump. Despite both WinDump and WinpCap being provided by
the same maintainer, they are separate downloads.
WinpCap is an actual library that needs to be installed. But, once it is installed, WinDump is an .exe file
that needs no installation so it can just run. That may be something to keep in mind if you're running a
Windows network. You don't necessarily need WinDump installed on every machine since you can just
copy it over as needed, but you will want WinpCap installed in order to support WinDump.
As with tcpdump, WinDump can output network data to the screen for analysis, be filtered in the same
way, and also write data to a pcap file for analysis offsite.
3. Wireshark
wireshark is probably the next best-known tool in any sysadmin's toolkit. It can not only capture data, but
also provides some advanced analysis tools. Adding to its appeal, Wireshark is open source, and has been
ported over to almost every server operating system that exists. Starting life named Etheral, Wireshark
now runs everywhere, including as a standalone portable app.
If you're analyzing traffic on a server with a desktop installed, Wireshark can do it all for you. It can
collect the data, and then analyze it all in one spot. However, desktops are not common on servers, so in
many cases, you'll want to capture the network data remotely and then pull the resulting pcap file into
Wireshark.
At first launch, Wireshark allows you to either load an existing pcap file, or start capturing. If you elect to
capture network traffic, you can optionally specify filters to pare down the amount of data Wireshark
collects. Since its analysis tools are so good, it's less important to ensure you surgically identify the data
at collection time with Wireshark. If you don't specify a filter, Wireshark will simply collect all network
data that your selected interface observes.
Result: Network packet analysis using tools like Wireshark, tcpdump, etc. is done and understood.
EXPERIMENT - 9
Objective: Network simulation using tools like Cisco Packet Tracer, NetSim, OMNeT++, NS2, NS3, etc.
Apparatus (Components): Wireshark, tcpdump
Brief Theory:
Network simulation- In computer network research, network simulation is a technique whereby a
software program models the behavior of a network by calculating the interaction between the different
network entities.
Cisco Packet Tracer- Packet Tracer allows users to create simulated network topologies by dragging and
dropping routers, switches and various other types of network devices. A physical connection between
devices is represented by a 'cable' item. Cisco Systems claims that Packet Tracer is useful for network
experimentation.
NetSim-NetSim is an end-to-end, full stack, packet level network simulator and emulator. It provides
network engineers with a technology development environment for protocol modeling, network R&D and
military communications.
A network simulator enables users to virtually create a network comprising of devices, links, applications
etc, and study the behavior and performance of the Network.
Components
The main ingredients of OMNeT++ are:
• Simulation kernel library (C++)
• The NED topology description language
• Simulation IDE based on the Eclipse platform
• Interactive simulation runtime GUI (Qtenv)
• Command-line interface for simulation execution (Cmdenv) Utilities (makefile creation tool, etc.)
• Documentation, sample simulations, etc.
NS2- NS2 stands for Network Simulator Version 2. It is an open-source event-driven simulator designed
specifically for research in computer communication networks.Ns2 is an event driven simulator, which is
a open source simulator mainly used for academic research in the areas of Computer Networks,
MANETS, WSNs.NS-2 can be used to implement network protocols such as TCP and UPD, traffic source
behavior such as FTP, Telnet, Web, CBR and VBR, router queue management mechanism such as Drop
Tail, RED and CBQ, routing algorithms and many more. In ns2, C++ is used for detailed protocol
implementation and Otel is used for the setup.
Features of NS2
1. It is a discrete event simulator for networking research.
2. It provides substantial support to simulate bunch of protocols like TCP, FTP, UDP, https and DSR.
3. It simulates wired and wireless network.
4. It is primarily Unix based.
5. Uses TCL as its scripting language.
6. Otel: Object oriented support
7. Telcl: C++ and otel linkage
8. Discrete event scheduler
NS3- Computer network simulation in the sense connection of two or more computer system linked
together for communication. Networking is the practice of interfacing two or more computing devices
with each other for the purpose of sharing data. Computer networks are built with a combination of
hardware and software.ns-3 is a discrete-event network simulator, targeted primarily for research and
educational use. ns-3 is free software, licensed under the GNU GPLv2 license, and is publicly available
for research, development, and use.
NS-3 is intended to provide better support than in NS-2 for the following items:
• Modularity of components
• Scalability of simulations
• Integration/reuse of externally developed code and software utilities
• Emulation
• Tracing and statistics
• Validation
Result- Network simulation is done using tools like Cisco Packet Tracer, NetSim, OMNeT++, NS2, NS3,
etc.
EXPERIMENT - 10
Objective:
To implement socket programming date and time display from client to server using TCP
and UDP Sockets.
Concept:
Socket Programming
Sockets provide the communication mechanism between two computers. A client program
creates a socket on its end of the communication and attempts to connect that socket to a
server.
When the connection is made, the server creates a socket object on its end of the
communication.
The client and server can now communicate by writing to and reading from the socket.
Client–server model
The client–server model of computing is a distributed application structure that partitions
tasks or workloads between the providers of a resource or service, called servers, and service
requesters, called clients.
Often clients and servers communicate over a computer network on separate hardware, but
both client and server may reside in the same system.
A server host runs one or more server programs which share their resources with clients. A
client does not share any of its resources, but requests a server's content or service function.
Clients therefore initiate communication sessions with servers which await incoming
requests.
Examples of computer applications that use the client–server model are Email, network printing, and
the World Wide Web.
Algorithm:
Server:
Step1: Create a server socket and bind it to port.
Step 2: Listen for new connection and when a connection arrives, accept it.
Step 3: Send server’s date and time to the client.
Step 4: Read client’s IP address sent by the client.
Step 5: Display the client details.
Step 6: Repeat steps 2-5 until the server is
terminated. Step 7: Close the server socket.
Client
Step1: Create a client socket and connect it to the server’s port number.
Step2: Retrieve its own IP address using built-in function.
Step3: Send its address to the server.
Step4: Display the date & time sent by the server.
Step5: Close the client socket
dis=newDataInputStream(s.getInputStream());inet=dis.readLine(); System.out.println("THE
CLIENT SYSTEM ADDRESS IS :"+inet);
/* …This method is used to request for closing or terminating an
object…*/ ps.close();}} dateclient.java
/* …Socket class is having a constructor through this Client program can request to server to
get connection…*/ Socket soc;
DataInputStream dis;
String sdate;
PrintStreamps;
/*…getLocalHost() method: Returns the name of the local computer…*/
InetAddressia=InetAddress.getLocalHost();
/*… Open your connection to a server, at port 8020…*/ soc=new
Socket(ia,8020);
/*… Get an input file handle from the socket and read the input…*/
/*…getInputStream()-This method take the permission to write the data from client program
to server program and server program to client program…*/
dis=new DataInputStream(soc.getInputStream()); sdate=dis.readLine();
System.out.println("THE date in the server is:"+sdate);
/* …getOutputStream()-This method is used to take the permission to read data from client system
by the server or from the server system by the client…*/ ps=new
PrintStream(soc.getOutputStream()); ps.println(ia);}
UDP Program:
Server.java
/*…import java packages…*/ import java.net.*;
import java.io.*; importjava.util.*;
/*..receiving the packet from client…*/
cs.send(sp); cs.receive(rp);
String time=new String(rp.getData()); System.out.println(time);
/*…This method is used to request for closing or terminating an object…*/ cs.close(); } }
Conclusion: Implemented socket programming date and time display from client to server using TCP
and UDP Sockets.
Exp 01 upar-> Exp 05 niche