SlideShare a Scribd company logo
M.A.M. College of Engineering and Technology
Department of Information Technology
LAB MASTER RECORD
Course Code : CS3591
Course Name : Computer Networks
Year / Semester : III / V
Department : IT
Faculty Name : R.Rajavaishnavi
Regulation : AU-R2021
Academic year : 2024-25 ODD
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
Department Vision and Mission
Vision
To be a school of excellence by providing holistic education and fostering research in IT to produce
technically competent, socially and ethically responsible students.
Mission
1.To provide a solid foundation in computational engineering for a successful career in Information
Technology.
2.To provide technical support and facilities to enrich research and development in the field of
Information Technology.
3.To collaborate in interdisciplinary projects with academia and industry through emerging
technologies.
4.To inculcate professional behavior, lifelong learning with ethical values.
5.To empower engineers with excellent communication, teamwork, and interpersonal skills.
Program Educational Objectives(PEOs)
PEO
1
To be a skilled professional in providing technically feasible solutions in data driven
technology and security principles for industry and society.
PEO 2 To emerge as a developer & researcher by engaging in lifelong learning and adapting to
challenging environments.
PEO 3 To Exhibit entrepreneurship skills, leadership qualities and professional ethics to start new
ventures.
PEO 4 To be prepared for their career in the software industry or pursue higher studies.
PROGRAMME SPECIFIC OUTCOMES (PSOS)
PSO 1 To apply basic science, programming, algorithms, and data management for developing
software solutions.
PSO 2 To apply data driven technology and information security principles for developing
reliable information systems.
PROGRAMME OUTCOMES (POS)
PO1 Engineering knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialization to the solution of complex engineering
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
problems.
PO2 Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
PO3 Design/development of solutions: Design solutions for complex engineering problems
and design system components or processes that meet the specified needs with
appropriate consideration for the public health and safety, and the cultural, societal, and
environmental considerations.
PO4 Conduct investigations of complex problems: Use research-based knowledge and
research methods including design of experiments, analysis and interpretation of data,
and synthesis of the information to provide valid conclusions.
PO5 Modern tool usage: Create, select, and apply appropriate techniques, resources, and
modern engineering and IT tools including prediction and modelling to complex
engineering activities with an understanding of the limitations.
PO6 The engineer and society: Apply reasoning informed by the contextual knowledge to
assess societal, health, safety, legal and cultural issues and the consequent
responsibilities relevant to the professional engineering practice.
PO7 Environment and sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and
need for sustainable development.
PO8 Ethics: Apply ethical principles and commit to professional ethics and responsibilities
and norms of the engineering practice.
PO9 Individual and team work: Function effectively as an individual, and as a member or
leader in diverse teams, and in multidisciplinary settings.
PO10 Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend
and write effective reports and design documentation, make effective presentations, and
give and receive clear instructions
PO11 Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a
member and leader in a team, to manage projects and in multidisciplinary environments.
PO12: Life-long learning: Recognize the need for, and have the preparation and ability to
engage in independent and life-long learning in the broadest context of technological
change.
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
Syllabus
Course Objectives :
1. To learn and use network commands.
2. To learn socket programming.
3. To implement and analyze various network protocols.
4. To learn and use simulation tools.
5. To use simulation tools to analyze the performance of various network protocols.
List of Experiments
1.Learn to use commands like tcpdump, netstat, ifconfig, nslookup and traceroute. Capture ping and
traceroute PDUs using a network protocol analyzer and examine.
2.Write a HTTP web client program to download a web page using TCP sockets.
3.Applications using TCP sockets like:
Echo client and echo server
Chat
4.Simulation of DNS using UDP sockets.
5.Use a tool like wireshark to capture packets and examine the packets.
6.Write a code simulating ARP /RARP protocols.
7.Study of Network simulator (NS) and Simulation of Congestion Control Algorithms using NS.
8.Study of TCP/UDP performance using Simulation tool.
9.Simulation of Distance Vector/ Link State Routing algorithm.
10.Simulation of error correction code (like CRC).
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
Course Outcome
CO Details BTL
CO501.1 Develop the procedure to conduct the experiment using
programminglanguagesC,JavaandNetworksimulator(ns2) software K3 - Apply
CO501.2 Demonstrate skills at the level of precision (reliably, quickly, smoothly,
and accurately with negligible guidance)in performing the experiment K3 - Apply
CO501.3 Draw inferences from the experiment conducted K4 - Analyze
CO501.4 Demonstrate professionally the results obtained through the experiment
and present conclusions
K4 - Analyze
CO501.5 Demonstrate an understanding of the concepts, procedures, and
applications through verbal and written communication
K3 - Apply
CO501.6 Demonstrating an attitude at the level of valuing (attaching
values and expressing personal opinions by showing some definite
involvement and commitment)
K3 - Apply
CO and PO Mapping
CO PO
1
PO2 PO3 PO4 PO5 PO
6
PO7 PO8 PO
9
PO10 PO1
1
PO12 PSO1 PSO2
CO508.1 3 - - - - - - - 3 3 - - 3 3
CO508.2 3 - - - 3 - - 2 3 - 1 - 3 3
CO508.3 3 2 - 2 - 1 - - - 3 - - - -
CO508.4 3 - - - - - - - - 3 - - 3 3
CO508.5 3 - - - - - - - - 3 - 1 2 2
CO508.6 - - - - - 2 - 2 2 2 - 1 - -
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
INDEX
Sl. No. Name of the Experiment CO
Page
No.
1. Learn to use commands like tcpdump, netstat, ifconfig,
nslookup and traceroute. Capture ping and traceroute
PDUs using a network protocol analyzer and examine
CO501.1 6
2. Write a HTTP web client program to download a web
page using TCP sockets.
CO501.2 13
3. Applications using TCP sockets like:
● Echo client and echoserver
● Chat
CO501.2 19
4. Simulation of DNS using UDP sockets. CO501.2 32
5. Use a tool like wireshark to capture packets and examine
the packets.
CO501.2 34
6. Write a code simulating ARP /RARP protocols. CO501.2 37
7. Study of Network simulator (NS) and Simulation of
Congestion Control Algorithms using NS.
CO501.4 41
8. Study of TCP/UDP performance using Simulation tool. CO501.4 56
9. Simulation of Distance Vector/ Link State Routing
algorithm.
CO501.4 63
10 Simulation of error correction code (like CRC). CO501.6 76
Additional Experiments beyond the syllabus
Sl. No. Name of the Experiment CO Page
No.
11. SIMULATION OF GO BACK N PROTOCOL CO508.4 81
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
RUBRICS: Grading of Laboratory experiment / exercise
Criterion (marks) Marks Marks awarded
for the criterion
5 to 4 3 to 2 1 to 0
1. Correctness of
the Procedure
for the
experiment /
exercise (3)
All the steps are
followed in correct
sequence. Knows
how to proceed
theexperiment.
Some steps are
followed but error
occurred.
Proceeded the
experiment with
the guidance.
Steps are not
followed.Not showing
interest to do
theexperiment.
8 or 7 or 6 5 or 4 or 3 2 or 1 or 0
2. Skills level in
performing the
experiment /
exercise (8)
Show excellent
understanding of
the experiment.
All data is recorded and
neatly presented
Show minimal
Understanding of the
experiment. All data
is recorded and is not
presented neatly
Show nounderstanding ofthe
experiment. All data is not
recorded and is not
presented neatly
3 2 1
3. Inferences drawn
from the
experiment /
exercise (3)
Correct inferences have
been drawn and
presented professionally
Inferences drawn are
correctly but not
presented
professionally
Inferences drawn are partially
incorrectly or incorrect
3 2 1
4. Presentation of
results (3)
Calculation are present
neatly with
accurate results.
Calculation are
present neatly with
minor mistakes
Wrong calculations. Major
mistakes.
5 to 4 3 to 2 1 to 0
5. Clarity in
answering Viva
questions (5)
Almost all the
questions are
answered.
Partially answered Unable to answer.
3 2 1
6. Attitude
reflected in
doing the
experiment /
exercise (3)
The experiment is
completed on time.
Manual/Record
note is submitted
on time.
The experiment is
completed on time,
but the Manual /
Record note is not
submitted on time
The experiment is not
completed on time.
Observation / Record note is
not submitted on time.
Total marks out of 25
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
R.Rajavaishnavi Dr. K. Geetha
Lab in charge Head of the Department
Exp No. 01 Date:……………
Learn to use commands like tcpdump, netstat, ifconfig, nslookup and traceroute. Capture ping
and traceroute PDUs using a network protocol analyzer and examine.
Aim:
To learn the usage of commands like tcpdump, netstat, ifconfig, nslookup and traceroute. Capture ping
and traceroute PDUs using a network protocol analyzer and examine.
Theory:
1. tcp dump
tcpdump is a most powerful and widely used command-line packets sniffer or package analyzer
tool which is used to capture or filter TCP/IP packets that received or transferred over a network
on a specific interface. It saves the file in a pcap format, that can be viewed by tcpdump
command or a open source GUI based tool called Wireshark (Network Protocol Analyzier) that
reads tcpdumppcap format files.
2. netstat
In computing, netstat (network statistics) is a command-line network utility that displays
network connections for Transmission Control Protocol (both incoming and outgoing), routing
tables, and a number of network interface (network interface controller or software-defined
network interface) and network protocol statistics.
3. nslookup
nslookup is a network administration command-line tool available in many computer operating
systems for querying the Domain Name System (DNS) to obtain domain name or IP address
mapping, or other DNS records. The name "nslookup" means "name server lookup".
4. traceroute
In computing, traceroute computer network diagnostic commands for displaying the route
(path) and measuring transit delays of packets across an Internet Protocol (IP) network.
Traceroute proceeds unless all (three) sent packets are lost more than twice; then the connection
is lost and the route cannot be evaluated
Algorithm:
Step 1: Start
Step 2: Open the terminal
Step 3: Issue the Commands tcpdump, netstat, ifconfig, nslookup and traceroute with proper syntax
and perform ping and traceroute operation and capture packets using wireshark .
Step 4:Read the result
Step 5:Get the output
Program:
SNo Command Purpose Syntax
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
1 tcpdump dump traffic on a network tcpdump -i any
2 netstat Print network connections, routing
tables, interface statistics,
masquerade connections, and
multicast memberships
netstat -r
netstat –i
3 ifconfig configure a network interface Ifconfig
4 nslookup Nslookup is a program to query
Internet domain name servers.
Nslookup has two modes:
interactive and non-interactive.
Interactive mode allows the user
to query name servers for
information about various hosts and
domains or to print a list of hosts in
a domain. Non-interactive mode is
used to print just the name and
requested information for a host or
domain.
nslookup google.com
5 traceroute print the route packets trace to
network host
traceroute google.com
6 Ping send ICMP ECHO_REQUEST to
network hosts
ping google.com
Sample Input and Output:
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
1.tcp dump
tcpdump -i any >a.txt (the output is redirected to a.txt)
02:54:34.766681 IP6 fe80::3cf4:26ff:fe43:ccab > ff02::1: ICMP6, router advertisement, length 64
02:54:34.767405 IP 192.168.1.101.58668 > 192.168.1.1.domain: 57139+ PTR?
1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.f.f.ip6.arpa. (90)
02:54:34.770630 IP 192.168.1.1.domain> 192.168.1.101.58668: 57139 NXDomain 0/0/0 (90)
02:54:34.770828 IP 192.168.1.101.40513 > 192.168.1.1.domain: 14252+ PTR?
b.a.c.c.3.4.e.f.f.f.6.2.4.f.c.3.0.0.0.0.0.0.0.0.0.0.0.0.0.8.e.f.ip6.arpa. (90)
02:54:34.773912 IP 192.168.1.1.domain> 192.168.1.101.40513: 14252 NXDomain 0/0/0 (90)
02:54:34.774116 IP 192.168.1.101.56139 > 192.168.1.1.domain: 10338+ PTR? 1.1.168.192.in-
addr.arpa. (42)
02:54:34.777183 IP 192.168.1.1.domain> 192.168.1.101.56139: 10338 NXDomain 0/0/0 (42)
02:54:34.777346 IP 192.168.1.101.40647 > 192.168.1.1.domain: 25219+ PTR? 101.1.168.192.in-
addr.arpa. (44)
02:54:34.780386 IP 192.168.1.1.domain> 192.168.1.101.40647: 25219 NXDomain 0/0/0 (44)
2.netstat
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irttIface
192.168.122.0 * 255.255.255.0 U 0 0 0 virbr0
192.168.0.0 * 255.255.0.0 U 0 0 0 wlan0
default 192.168.1.1 0.0.0.0 UG 0 0 0 wlan0
[root@localhost~]#
3.ifconfig
[root@localhost~]# ifconfig
eth0 Link encap:EthernetHWaddr 6C:3B:E5:10:5C:11
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
Interrupt:20 Memory:f7c00000-f7c20000
4.traceroute google.com
[root@localhost~]# traceroute google.com
traceroute to google.com (172.217.163.78), 30 hops max, 60 byte packets
1 192.168.1.1 (192.168.1.1) 4.870 ms 4.803 ms 4.757 ms
2 * * *
3 10.71.201.82 (10.71.201.82) 379.988 ms 10.71.201.74 (10.71.201.74) 379.917 ms 380.296 ms
4 172.25.55.205 (172.25.55.205) 380.254 ms 379.772 ms 379.707 ms
5 172.26.56.79 (172.26.56.79) 379.664 ms 379.572 ms 379.547 ms
6 172.25.8.7 (172.25.8.7) 379.450 ms 372.567 ms 372.538 ms
7 * * *
8 * * *
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
9 * * *
10 72.14.217.58 (72.14.217.58) 162.217 ms 72.14.217.254 (72.14.217.254) 162.202 ms 162.126 ms
11 * * *
12 216.239.42.237 (216.239.42.237) 426.763 ms 72.14.237.164 (72.14.237.164) 106.196 ms
216.239.42.237 (216.239.42.237) 39.846 ms
13 maa05s02-in-f14.1e100.net (172.217.163.78) 40.925 ms 408.176 ms 108.170.253.119
(108.170.253.119) 96.572 ms
[root@localhost~]#
5.ping google.com
[root@localhost~]# ping google.com
PING google.com (172.217.163.78) 56(84) bytes of data.
64 bytes from maa05s02-in-f14.1e100.net (172.217.163.78): icmp_seq=1 ttl=114 time=42.1 ms
64 bytes from maa05s02-in-f14.1e100.net (172.217.163.78): icmp_seq=2 ttl=114 time=40.6 ms
64 bytes from maa05s02-in-f14.1e100.net (172.217.163.78): icmp_seq=3 ttl=114 time=39.2 ms
64 bytes from maa05s02-in-f14.1e100.net (172.217.163.78): icmp_seq=4 ttl=114 time=45.8 ms
64 bytes from maa05s02-in-f14.1e100.net (172.217.163.78): icmp_seq=5 ttl=114 time=43.9 ms
PreVivaQuestions:
1. What are the Two Interfaces provided by Protocols?
A. Service interface
B. Peer interface
✔ Service interface-defines the operations that local objects can perform on the protocol.
✔ Peer interface-defines the form and meaning of messages exchanged between protocol
peers to implement the communication service.
2. What is LAN?
A LAN is a common name used to describe a group of devices that share a geographic location.
LAN is limited to single building or campus.
3. For n devices in a network, what is the number of cable links required for a mesh and ring
topology?
Mesh topology – n (n-1)/2
Ring topology – n
4. Define Topology?
Network topology is the arrangement of the elements (links, nodes, etc.) of a communication
network
5. What are the Types of Topology?
There are five types of topology in computer networks:
a) Mesh Topology.
b) Star Topology.
c) Bus Topology.
d) Ring Topology.
e) Hybrid Topology
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
Post viva Questions
6. What is the Purpose of TCP Dump?
Tcp dump is used to dump traffic on a network.
7. What is the Purpose of netstat command?
Print network connections, routing tables, interface statistics, masquerade connections, and
multicast memberships.
8. What is the Purpose of ifconfig command?
It is used to configure a network interface.
It is used to send ICMP ECHO_REQUEST to network hosts
9. What is the Purpose of Traceroute command?
It is used to print the route packets trace to network host.
10. Which command is used to Test the connectivity between local machine and remote machine?
ping
Result:
Thus the commands are excuted and verified successfully
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
Exp No. 02 Date:……………
Write a HTTP web client program to download a web page using TCP sockets.
Aim:
To write a HTTP web client program to download a web page using TCP sockets
Theory:
Java Socket programming can be connection-oriented or connection-less.
Socket and ServerSocket classes are used for connection-oriented socket programming and
DatagramSocket and DatagramPacket classes are used for connection-less socket programming.
The client in socket programming must know two information:
● IP Address of Server, and
● Port number.
Here, we are going to make one-way client and server communication. In this application, client sends
a message to the server, server reads the message and prints it. Here, two classes are being used: Socket
and ServerSocket. The Socket class is used to communicate client and server. Through this class, we
can read and write message. The ServerSocket class is used at server-side. The accept() method of
ServerSocket class blocks the console until the client is connected. After the successful connection of
client, it returns the instance of Socket at server-side.
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
Socket class
A socket is simply an endpoint for communications between the machines. The Socket class can be
used to create a socket.
Important methods
Method Description
1) public InputStream getInputStream() returns the InputStream attached with this socket.
2) public OutputStream getOutputStream() returns the OutputStream attached with this socket.
3) public synchronized void close() closes this socket
ServerSocket class
The ServerSocket class can be used to create a server socket. This object is used to establish
communication with the clients.
Important methods
Method Description
1) public Socket accept()
returns the socket and establish a connection between server and
client.
2) public synchronized void
close()
closes the server socket.
Algorithm:
Step 1: Create URL object using url string.
Step 2:Create a BufferReader object using url.openStream() method.
Step 3:Create a BufferWriter object to write to a file.
Step 4:Read each line using BufferReader and write using BufferWriter.
Step 5:Open the downloaded contents using a brower.
Program:
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
public class Tester {
public static void main(String args[]) throws IOException {
download("http://www.google.com");
}
public static void download(String urlString) throws IOException {
URL url = new URL(urlString);
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
try(
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
BufferedWriter writer = new BufferedWriter(new FileWriter("page.html"));
) {
String line;
while ((line = reader.readLine()) != null) {
writer.write(line);
}
System.out.println("Page downloaded.");
}}}
Sample Input and Output:
Compile: javac Tester.java
Run : java Tester
Output: Page downloaded.
Open the downloaded content using browser
Pre Viva Questions
1. What is Flow Control?
Flow control refers to a set of procedures used to restrict the amount of data. The sender can
send before waiting for acknowledgment.
2. What is mean by Error Control?
Error control is a method that can be used to recover the corrupted data whenever possible.
These are two basic types of error control which are backward error control and forward error
control.
3. What is Bridge?
Bridge is a hardware networking device used to connect two LANs. A bridge operates at data
link layer of the OSI reference model.
4. What is a Rrepeater?
Repeater is a hardware device used to strengthen signals being transmitted on a network.
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
5. Define Router
A network layer device that connects networks with different physical media and translates
between different network architecture.
Post viva questions
6. What is a Switch?
A switch is a networking device that manages networked connections between devices on a star
networks.
7. What are the Functions of Bridge?
1. Connecting networks
2. Filtering information so that network traffic for one portion of the network does not congest
the rest of the network.
8. What is URL
A Uniform Resource Locator (URL), colloquially termed a web address,[1] is a reference to a
web resource that specifies its location on a computer network and a mechanism for retrieving
it.
9. What is the Socket.
Sockets allow communication between two different processes on the same or different
machines. A network socket is an internal endpoint for sending or receiving data within a node
on a computer network.
10. What is the Purpose of InputStreamReader in Java?
An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and
decodes them into characters using a specified charset.
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
Result:
Thus the program for HTTP web client program to download a web page using TCP sockets is
successfully executed and the content is opened and viewed by browser.
Exp No. 03 Date:……………
3 A: Creation of TCP Socket for Echo Client and Echo Server
Aim:
To create TCP Socket for Echo Client and Echo Server in JAVA
Algorithm:
Server
1.Create a socket and listen for client communication
2.Establish the connection
2.Receive client's message .
3.Read Client's message and display it
4.Send the message back to client
5.Repeat steps 2-4 until the client has something to send
6.Close the server socket
7.Stop
Client
1.Establish the server connection via specified port
2.Get a message from user
3.Send it to server
4.Receive echoed message
5.Read server's response and display it
6.Repeat steps 2-5 until there is some text to send
7.Close the client socket
8.Stop
// EchoServer.java : A Simple Echo Server Program
Server:
import java.io.*;
import java.net.*;
public class EchoServer
{
public static void main(String args[]) throws Exception
{
try
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
{
int Port;
BufferedReader Buf =new BufferedReader(new
InputStreamReader(System.in));
System.out.print(" Enter the Port Address : " );
Port=Integer.parseInt(Buf.readLine());
ServerSocket sok =new ServerSocket(Port);
System.out.println(" Server is Ready To Receive a Message. ");
System.out.println(" Waiting ..... ");
Socket so=sok.accept();
if(so.isConnected()==true)
System.out.println(" Client Socket is Connected Succecfully. ");
InputStream in=so.getInputStream();
OutputStream ou=so.getOutputStream();
PrintWriter pr=new PrintWriter(ou);
BufferedReader buf=new BufferedReader(new
InputStreamReader(in));
String str=buf.readLine();
System.out.println(" Message Received From Client : " + str);
System.out.println(" This Message is Forwarded To Client. ");
pr.println(str);
pr.flush();
}
catch(Exception e)
{
System.out.println(" Error : " + e.getMessage());
}}}
Client:
import java.io.*;
import java.net.*;
public class EchoClient
{
public static void main(String args[]) throws Exception
{
try {
int Port;
BufferedReader Buf =new BufferedReader(new
InputStreamReader(System.in));
System.out.print(" Enter the Port Address : " );
Port=Integer.parseInt(Buf.readLine());
Socket sok=new Socket("localhost",Port);
if(sok.isConnected()==true)
System.out.println(" Server Socket is Connected Succecfully. ");
InputStream in=sok.getInputStream();
OutputStream ou=sok.getOutputStream();
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
PrintWriter pr=new PrintWriter(ou);
BufferedReader buf1=new BufferedReader(new
InputStreamReader(System.in));
BufferedReader buf2=new BufferedReader(new
InputStreamReader(in));
String str1,str2;
System.out.print(" Enter the Message : ");
str1=buf1.readLine();
pr.println(str1);
pr.flush();
System.out.println(" Message Send Successfully. ");
str2=buf2.readLine();
System.out.println(" Message From Server : " + str2); }
catch(Exception e) {
System.out.println(" Error : " + e.getMessage());
}}}
Sample Input and Output:
D:New folderPGMEX_8_A_ECHO>javac EchoClient.java
D:New folderPGMEX_8_A_ECHO>java EchoClient
Enter the Port Address : 9999
Server Socket is Connected Succecfully.
Enter the Message : Hai
Message Send Successfully.
Message From Server : Hai
D:New folderPGMEX_8_A_ECHO>
D:New folderPGMEX_8_A_ECHO>javac EchoServer.java
D:New folderPGMEX_8_A_ECHO>java EchoServer
Enter the Port Address : 9999
Server is Ready To Receive a Message.
Waiting .....
Client Socket is Connected Succecfully.
Message Received From Client : Hai
This Message is Forwarded To Client.
D:New folderPGMEX_8_A_ECHO>
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
Result:
Thus the program to create TCP Socket for Echo Client and Echo Server in JAVA.
3 B: Creation of TCP Socket for Chat
Aim: To create a TCP Socket for Chatting in JAVA
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.Establish connection with the server socket.
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
Server:
import java.io.*;
import java.net.*;
public class GossipServer {
public static void main(String[] args) throws Exception {
ServerSocket sersock = new ServerSocket(3000);
System.out.println("Server ready for chatting");
Socket sock = sersock.accept( );
// reading from keyboard (keyRead object)
BufferedReader keyRead = new BufferedReader(new InputStreamReader(System.in));
// sending to client (pwrite object)
OutputStream ostream = sock.getOutputStream();
PrintWriter pwrite = new PrintWriter(ostream, true);
// receiving from server ( receiveRead object)
InputStream istream = sock.getInputStream();
BufferedReader receiveRead = new BufferedReader(new InputStreamReader(istream));
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
String receiveMessage, sendMessage;
while(true) {
if((receiveMessage = receiveRead.readLine()) != null) {
System.out.println(receiveMessage); }
sendMessage = keyRead.readLine();
pwrite.println(sendMessage);
pwrite.flush(); } } }
Client:
import java.io.*;
import java.net.*;
public class GossipClient {
public static void main(String[] args) throws Exception {
Socket sock = new Socket("127.0.0.1", 3000);
// reading from keyboard (keyRead object)
BufferedReader keyRead = new BufferedReader(new InputStreamReader(System.in));
// sending to client (pwrite object)
OutputStream ostream = sock.getOutputStream();
PrintWriter pwrite = new PrintWriter(ostream, true);
// receiving from server ( receiveRead object)
InputStream istream = sock.getInputStream();
BufferedReader receiveRead = new BufferedReader(new InputStreamReader(istream));
System.out.println("Start the chitchat, type and press Enter key");
String receiveMessage, sendMessage;
while(true) {
sendMessage = keyRead.readLine(); // keyboard reading
pwrite.println(sendMessage); // sending to server
pwrite.flush(); // flush the data
if((receiveMessage = receiveRead.readLine()) != null) //receive from server {
System.out.println(receiveMessage); // displaying at DOS prompt
}} }}
Output:
D:New folderPGMEX_8_B_TALK>javac GossipServer.java
D:New folderPGMEX_8_B_TALK>java GossipServer
Server ready for chatting
hai
how
i am fine
are you
D:New folderPGMEX_8_B_TALK>javac GossipClient.java
D:New folderPGMEX_8_B_TALK>java GossipClient
Start the chitchat, type and press Enter key
hai
how
i am fine
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
Result:
Thus the program to create a TCP Socket for Chatting in JAVA is successfully executed and verified
Ex:3.c Creation of TCP Sockets for File Transfer
Aim:
To create a TCP Socket for File Transfer
Algorithm
Server
1.Create a server socket
2.Wait for client to be connected.
3.Read the file name coming from client , uses input stream.
4.Open the file, using some input stream, and read the contents.
5.As the reading is going on, to send the contents each line separately.
6.Close the connection if all the contents are read and sent.
Client
1.Establish connection with the server socket
2.To take input for file name from keyboard. Remember, this file should exist on server. For this, it
uses input stream.To take input from the keyboard, a BufferedReader object, keyRead, is created. To
send the file name to the server, pwrite of PrintWriter
3.The file read from keyboard should be sent to the server. For this client uses output stream.
4.The file contents sent by the server, the client should receive and print on the console.To receive the
file contents from the server, socketRead of BufferedReader are created
Program:
Server
import java.net.*;
import java.io.*;
public class ContentsServer
{
public static void main(String args[]) throws Exception
{
// establishing the connection with the server
ServerSocket sersock = new ServerSocket(4000);
System.out.println("Server ready for connection");
Socket sock = sersock.accept();
// binding with port: 4000
System.out.println("Connection is successful and wating for chatting");
// reading the file name from client
InputStream istream = sock.getInputStream( );
BufferedReader fileRead =new BufferedReader(new InputStreamReader(istream));
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
String fname = fileRead.readLine( );
// reading file contents
BufferedReadercontentRead = new BufferedReader(new FileReader(fname) );
// keeping output stream ready to send the contents
OutputStream ostream = sock.getOutputStream( );
PrintWriter pwrite = new PrintWriter(ostream, true);
String str;
while((str = contentRead.readLine()) != null) // reading line-by-line from file
{
pwrite.println(str);
// sending each line to client
}
sock.close();
sersock.close(); // closing network sockets
pwrite.close();
fileRead.close();
contentRead.close();
}}
Client:
import java.net.*;
import java.io.*;
public class ContentsClient
{
public static void main( String args[ ] ) throws Exception
{
Socket sock = new Socket( "127.0.0.1", 4000);
// reading the file name from keyboard. Uses input stream
System.out.print("Enter the file name");
BufferedReader keyRead = new BufferedReader(new InputStreamReader(System.in));
String fname = keyRead.readLine();
// sending the file name to server. Uses PrintWriter
OutputStream ostream = sock.getOutputStream( );
PrintWriter pwrite = new PrintWriter(ostream, true);
pwrite.println(fname);
// receiving the contents from server. Uses input stream
InputStream istream = sock.getInputStream();
BufferedReader socketRead = new BufferedReader(new InputStreamReader(istream));
String str;
while((str = socketRead.readLine()) != null) // reading line-by-line
{
System.out.println(str);
}
pwrite.close(); socketRead.close(); keyRead.close();
}}
Output:
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
D:New folderPGMEX_8C_File_Transferserver>javac ContentsServer.java
D:New folderPGMEX_8C_File_Transferserver>java ContentsServer
Server ready for connection
Connection is successful and wating for chatting
D:New folderPGMEX_8C_File_Transferserver>
D:New folderPGMEX_8C_File_TransferClient>javac ContentsClient.java
D:New folderPGMEX_8C_File_TransferClient>java ContentsClient
Enter the file namea
HAI I AM GOOD
D:New folderPGMEX_8C_File_TransferClient>
Pre Viva Questions:
1. What is Echo?
In telecommunications, echo is the local display of data, either initially as it is locally sourced
and sent, or finally as a copy of it is received back from a remote destination.
2. What is a Port?
Ports are identified for each protocol and address combination by 16-bit unsigned numbers,
commonly known as the port number. The most common protocols that use port numbers are
the Transmission Control Protocol (TCP) and the User Datagram Protocol (UDP).
3. Who is Responsible for the global coordination of the DNS Root, IP addressing, and other
Internet protocol resources.?
IANA- The Internet Assigned Numbers Authority (IANA) is a standards organization that
oversees global IP address allocation, autonomous system number allocation, root zone
management in the Domain Name System (DNS), media types, and other Internet Protocol-
related symbols and Internet numbers.
4. What is the Default Port Number for Echo Protocol?
Port Number :7
5. What is FTP?
The File Transfer Protocol (FTP) is a standard network protocol used for the transfer of
computer files between a client and server on a computer network.
Post viva Questions
6. What are the Disadvantages of FTP clients?
● Usernames, passwords and files are sent in clear text
● Filtering active FTP connections is difficult on your local machine (passive is preferred)
● Servers can be spoofed to send data to a random port on an unintended computer
● Hard to script jobs
7. What is the Purpose of readLine() method in java?
readLine() method to read a file line by line
8. What is the Purpose of FileReader in Java?
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
FileReader is meant for reading streams of characters. For reading streams of raw bytes,
consider using a FileInputStream.
Parameters:
fileName - the name of the file to read from
9. What is the Purpose of the keyRead.readLine(); method in java?
This method returns the string containing the line read from the console.
Result:
Thus the program to create a TCP Socket for File Transfer is successfully executed
Exp No. 04 Date:……………
Create a UDP Socket to Simulate the behavior of DNS Service
Aim: To Create a UDP Socket to Simulate the behavior of DNS Service in JAVA
Algorithm
1.Establish Client and Server Socket Connection
2.Make the client query for IP Address of a host name to server
3.Resolve the IP address for requested host name queried by the client
4.Display the result
5.Do the step 2 to step 4 until nothing to be resolved.
Server:
import java.io.*;
import java.net.*;
class UDPserver
{
public static DatagramSocket ds;
public static byte buffer[]=new byte[1024];
public static int clientport = 789,serverport=790;
public static void main(String args[])throws Exception
{
ds=new DatagramSocket(clientport);
System.out.println("press ctrl+c to quit the program");
while(true)
{
DatagramPacket p=new DatagramPacket(buffer,buffer.length);
ds.receive(p);
String psx=new String(p.getData(),0,p.getLength());
System.out.println("Client:" + psx);
InetAddress ib=InetAddress.getByName(psx);
System.out.println("Server output:"+ib);
}}}
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
Client:
import java .io.*;
import java.net.*;
class UDPclient
{
public static DatagramSocket ds;
public static int clientport=789,serverport=790;
public static void main(String args[])throws Exception
{
byte buffer[]=new byte[1024];
ds=new DatagramSocket(serverport);
BufferedReader dis=new BufferedReader(new InputStreamReader(System.in));
System.out.println("server waiting");
InetAddress ia=InetAddress.getLocalHost();
while(true)
{
System.out.println("Client:");
String str=dis.readLine();
if(str.equals("end"))
break;
buffer=str.getBytes();
ds.send(new DatagramPacket(buffer,str.length(),ia,clientport));
}}}
Output
D:New folderPGMEX_9_D_DNS>javac UDPserver.java
D:New folderPGMEX_9_D_DNS>java UDPserver
press ctrl+c to quit the program
Client:www.facebook.com
Server output:www.facebook.com/31.13.78.35
Client:www.yahoo.com
Server output:www.yahoo.com/98.138.219.232
D:New folderPGMEX_9_D_DNS>javac UDPclient.java
D:New folderPGMEX_9_D_DNS>java UDPclient
server waiting
Client:
www.facebook.com
Client:
www.yahoo.com
PreViva Questions:
1. What is DNS?
Domain Name Systems(DNS) maps domain names with Internet Protocol(IP) address, thus
helping computer for translating human-readable(domain name) to machine-readable
language(IP address).
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
e.g.:https://www.freshersemploy.com
2. What is DNS Server?
DNS servers resolve IP address to respective hostnames and it maintains directory or database
to store the information.
3. What are the Different Types of Records in DNS?
Some of commonly used of DNS records are A, CNAME, NS, MX, PTR, SOA etc.
4. What is the Use of PTR in DNS?
PTR(Pointer) records are used for mapping IP addresses which are associated with hostname
name. It is also called has reverse DNS lookup as it resolves IP address to domain or hostname.
There must be A record for every PTR record. PTR is mainly used for the mail server.
5. Explain CNAME record?
CNAME record stands for Canonical Name record. It used as the alias for domain or the
Canonical name(another name) for a domain.
Post Viva Questions
6. What is DNS Zone?
A DNS zone file contains the mapping between a domain name, IP address, recourse records
etc. in text representative format. Also, DNS zone refers to the administrative responsibility in
the DNS.
7. Define TTL?
Time-to-live caches the DNS records for a specific period of time(when TTL expires, it has to
query new record). It helps in queries the records faster, eventually reducing the load on the
DNS server.
8. Explain MX record?
Mail Exchange(MX) record is a type of resource record which is used for email sending and
delivery. It must be specified in the DNS zone files mails for the domain.
9. What is Forward Lookup?
Forward Lookup is used to find the IP address through the domain name.
10. What is Reverse Lookup?
Reverse Lookup is used for finding the domain name through it IP.
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
Result:
Thus the program to Create a UDP Socket to Simulate the behavior of DNS Service in JAVA is
executed successfully.
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
Exp No. 06 Date:……………
Simulating ARP and RARP Protocols
AIM:
To simulate the behavior of ARP and RARP Protocols in JAVA
Algorithm:
1. Create a Process at Run Time
2. Pass the argument to determine the link layer address for address resolution
3. Determine the reader class to read the address determined, which contains ip address and mac
address
4. Display the result
Program:
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class ARP {
public static void main(String[] args) {
try{
String s1="arp -a";
Process p = Runtime.getRuntime().exec(s1);
BufferedReaderinputStream = new BufferedReader(newInputStreamReader(p.getInputStream()));
String s = "";
while ((s = inputStream.readLine()) != null) {
System.out.println(s);
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
Output
D:New folderPGMEX_3_ARP_RARP>javac ARP.java
D:New folderPGMEX_3_ARP_RARP>java ARP
Interface: 192.168.50.250 --- 0xa
Internet Address Physical Address Type
192.168.50.4 90-fb-a6-12-af-dd dynamic
192.168.50.255 ff-ff-ff-ff-ff-ff static
192.168.61.1 00-90-7f-43-84-0b dynamic
192.168.61.85 90-fb-a6-12-af-ba dynamic
192.168.61.102 90-fb-a6-12-af-27 dynamic
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
Pre Viva Questions:
1. Define Networking, Internetworking?
Networking – Interconnecting the individual host. Internetworking – Interconnecting the different
networks.
2. Define MAC address, IP address?
MAC address – is the physical address of a host. Its length is 48 bits. Eg:12:de:34:0f:1x:1d
IP address – is the logical address of a host. Its length is 32 bits. Eg:191.168.150.1
3. How we can identify a Host.
A host can be identified by its logical address (IP) and physical address(MAC).
4. Define Classfull and Classless addressing?
Classful addressing – Total address space is divided in to 5 classes called as Class ‘A’, Class ‘B’, Class
‘C’, Class’D’ and Class’E’ such that each class with their own prefix. Classless addressing – Here,
there are variable length blocks that belong to no class. The entire address space is divided in to blocks
based on organization needs.
5.What is Subnetting ?
Subnetting divides one large network into several smaller ones. Subnetting adds an intermediate level
of hierarchy in IP addressing.
Post Viva Questions:
6. What is Supernetting?
Supernetting combines several networks into one large one.
7. What is meant by Masking ?
Masking is a process that extracts the network address from an IP address. Subnet masking is a process
that extracts the subnetwork address from an IP address. A network or subnet address is obtained from
applying the bit-wise AND operation on the IP address and the mask.
8. What is the Function of Routing Table?
Every host or router has a routing table to route IP packets. In next hop routing instead of a complete
list of the stops the packet must make only the address of the next hop is listed in the routing table
9. What is Static and Dynamic Routing ?
A static routing table’s entries are updated manually by an administrator. A dynamic routing table’s
entries are updated automatically by a routing protocol.
10. What is the Maximum length of a Datagram?
The maximum length of a datagram is 65,535 bytes.
Result:
Thus the program to simulate the behavior of ARP and RARP Protocols in JAVA is successfully
executed.
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
Exp No. 07 a Date:……………
Study of Network simulator (NS)
Aim:
To study the NS2 Simulator
Steps to install NS2 in centos 6
STEP 1
From terminal login as super user and do the following.(internet must also be connected in order to
install the package dependencies.
yum install autoconf
yum install automake
yum install gcc-c++
yum install libX11-devel
yum install xorg-x11-proto-devel
yum install libXt-devel
And for nam installation (optional):
yum install libXmu-devel
STEP 2
From terminal go to the folder where the ns-allinone patch is placed and type the following to extract
$ tar -xzf ns-allinone-2.35.tar.gz
$ cd ns-allinone-2.35
$. /install
STEP 3
Now go to /etc folder and type
gedit ~/.bashrc
# LD_LIBRARY_PATH
OTCL_LIB=/your/path/ns-allinone-2.35/otcl-1.13
NS2_LIB=/your/path/ns-allinone-2.35/lib
X11_LIB=/usr/X11R6/lib
USR_LOCAL_LIB=/usr/local/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$X11_LIB:
$USR_LOCAL_LIB
# TCL_LIBRARY
TCL_LIB=/your/path/ns-allinone-2.35/tcl8.4.14/library
USR_LIB=/usr/lib
export TCL_LIBRARY=$TCL_LIB:$USR_LIB
# PATH
XGRAPH=/your/path/ns-allinone-2.35/bin:/your/path/ns-allinone-2.35/tcl8.4.14/unix:/your/path/ns-
allinone-2.31/tk8.4.14/unix
NS=/your/path/ns-allinone-2.35/ns-2.35/
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
NAM=/your/path/ns-allinone-2.35/nam-1.13/
PATH=$PATH:$XGRAPH:$NS:$NAM
Let it take effect immediately
source ~/.bashrc
Note: the step described above is important; otherwise, you cannot run ns successfully.
or you can restart your X windows.i.e. logout and then login, or reboot your system, to make it work.)
Now, the installation has been completed. If you try:
$ ns
Then a "%" will appear on the screen.type "exit" to quit the mode and back to "$"
Network Simulator 2 (NS2) : Tools For Tcl Scripts In NS2
Tools for generating TCL Script for NS2
NS2 a very common and widely used tool to simulate small and large area networks. Tcl scripts are
widely used in NS-2 simulation tool. Tcl scripts are used to set up a wired or wireless communication
network, and then run these scripts via the NS-2 for getting the simulation results.Several tools are
available to design networks and generate TCL scripts some of them are discussed below
Trace Files Generated in NS2
NS2 currently supports a number of different types of trace files. In addition to its own format, NS2
also has the Nam trace format, which contains the necessary information from the simulation to drive
the Nam visualizer. Both of these trace formats are very specific when it comes to giving details about
the events that occur during an NS2 simulation.
Traces and monitors represent the only support for data collection in ns-2. Traces record events related
to the generation, enqueueing, forwarding, and dropping of packets. Each event corresponds to a line
of ASCII characters, which contains information on the event type and the information stored into the
packet
NS-2 provides three kinds of formats for wired networks: Tracing, Monitoring and NAM trace file.
I. Tracing: Trace file format is given below:
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
Operation performed in the simulation
● Simulation time of event occurrence
● Node 1 of what is being traced
● Node 2 of what is being traced
● Packet type
● Packet size
● Flags
● IP flow identifier
● Packet source node address
● Packet destination node address
● Sequence number
● Unique packet identifier
Network Simulator 2 (NS2) : Monitoring & Examples For NS2
Monitoring
Queue monitoring refers to the capability of tracking the dynamics of packets at a queue (or other
object). A queue monitor tracks packet arrival/departure/drop statistics, and may optionally compute
averages of these values. Monitoring was useful tools to find detail information about queue.
Flow monitor trace format is given below:
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
III. NAM trace files which are used by NAM for visualization of ns simulations. The NAM trace file
should contain topology information like nodes, links, queues, node connectivity etc as well as packet
trace information. A NAM trace file has a basic format to it. Each line is a NAM event. The first
character on the line defines the type of event and is followed by several flags to set options on that
event. There are 2 sections in that file, static initial configuration events and animation events. All
events with -t * in them are configuration events and should be at the beginning of the file.
Example of NAM file is:
7. Advantages and Disadvantages of NS2
Advantages
1. Cheap- Does not require costly equipment
2. Complex scenarios can be easily tested.
3. Results can be quickly obtained-more ideas can be tested in a smaller time frame.
4. Supported protocols
5. Supported platforms
6. Modularity
7. Popular
Disadvantages
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
1. Real system too complex to model. i.e. complicated structure.
2. Bugs are unreliable
Result:
The foundations of NS2 are studied
Exp No. 07 b Date:……………
Simulation of Congestion Control Algorithms using NS.
Aim : To simulate the behavior of TCP congestion control using NS 2
Algorithm
Step 1:Create a network simulator object ns to invoke simulation
Step 2:Using an object open a file in write mode
Step 3:Using the aforesaid object write all the trace output into the file
Step 4:Using an object create a file to write all nam window output into it
Step 5:Set color to represent each flow
Step 6:Create 6 nodes
Step 7: Create duplex-link from node 0 to node n2 of bandwidth 2Mb with delay 10ms using
DropTail Queue
Step 8: Create duplex-link from node 1 to node n2 of bandwidth 2Mb with delay 10ms using
DropTail Queue
Step 9:Create duplex-link from node 2 to node n3 of bandwidth 0.3Mb with delay 200ms using
DropTail Queue
Step 10:Create duplex-link from node 3 to node n4 of bandwidth 0.5Mb with delay 40ms using
DropTail Queue
Step 11:Create duplex-link from node 3 to node n5 of bandwidth 0.5Mb with delay 30ms using
DropTail Queue
Step 12:Attach tcp reno agents to node 0 as tcp1
Step 13:Attach tcp reno agents to node 1 as tcp2
Step 14:Attach tcp reno agents to node 2 as tcp3
Step 15:Attach tcp reno agents to node 1 as tcp4
Step 16:Set fid 1 for tcp 1
Step 17:Set fid 2 for tcp 2
Step 18:Set fid 3 for tcp 3
Step 19:Set fid 4 for tcp 4
Step 20:Attach sink agents to node 4, node 5, node 3 and node 4
Step 21:Establish the traffic between the source and sink
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
Step 22:Setup a FTP traffic generator on "tcp"
Step 23:Attach ping agent to node 0 and node 4 ,connect it to calculate RTT
Step 24:Create a method to call ping.cc file
Step 25:Initiate the start and stop of the traffic profiles
Step 26:Set the end of simulation at 80 th second
Step 27:P lot the congestion window # cwnd_ used from tcp-reno.cc file
Step 28:Call the finish procedure to execute the nam window file and congestion trace file
Step 30:Run the simulation.
Code:
set ns [new Simulator]
set f [ open congestion.tr w ]
$ns trace-all $f
set nf [ open congestion.nam w ]
$ns namtrace-all $nf
$ns color 1 Red
$ns color 2 Blue
$ns color 3 White
$ns color 4 Green
#to create nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
# to create the link between the nodes with bandwidth, delay and queue
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns duplex-link $n2 $n3 0.3Mb 200ms DropTail
$ns duplex-link $n3 $n4 0.5Mb 40ms DropTail
$ns duplex-link $n3 $n5 0.5Mb 30ms DropTail
# Sending node with agent as Reno Agent
set tcp1 [new Agent/TCP/Reno]
$ns attach-agent $n0 $tcp1
set tcp2 [new Agent/TCP/Reno]
$ns attach-agent $n3 $sink3
set sink4 [new Agent/TCPSink]
$ns attach-agent $n4 $sink4
# establish the traffic between the source and sink
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
$ns connect $tcp1 $sink1
$ns connect $tcp2 $sink2
$ns connect $tcp3 $sink3
$ns connect $tcp4 $sink4
# Setup a FTP traffic generator on "tcp"
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
$ftp1 set type_ FTP
set ftp2 [new Application/FTP]
$ftp2 attach-agent $tcp2
$ftp2 set type_ FTP
set ftp3 [new Application/FTP]
$ftp3 attach-agent $tcp3
$ftp3 set type_ FTP
set ftp4 [new Application/FTP]
$ftp4 attach-agent $tcp4
$ftp4 set type_ FTP
# RTT Calculation Using Ping ------------------------------------------------
set p0 [new Agent/Ping]
$ns attach-agent $n0 $p0
set p1 [new Agent/Ping]
$ns attach-agent $n4 $p1
# Method call from ping.cc file
Agent/Ping instproc recv {from rtt} {
$self instvar node_
puts "node [$node_ id] received ping answer from 
$from with round-trip-time $rtt ms."
}
# ---------------------------------------------------------------------------
# start/stop the traffic
$ns at 0.2 "$p0 send"
$ns at 0.3 "$p1 send"
$ns at 0.5 "$ftp1 start"
$ns at 0.6 "$ftp2 start"
$ns at 0.7 "$ftp3 start"
$ns at 0.8 "$ftp4 start"
# Set simulation end time
$ns at 80.0 "finish"
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
# procedure to plot the congestion window
# cwnd_ used from tcp-reno.cc file
proc plotWindow {tcpSource outfile} {
global ns
set now [$ns now]
set cwnd_ [$tcpSource set cwnd_]
# the data is recorded in a file called congestion.xg.
puts $outfile "$now $cwnd_"
$ns at [expr $now+0.1] "plotWindow $tcpSource $outfile"
}
set outfile [open "congestion.xg" w]
$ns at 0.0 "plotWindow $tcp1 $outfile"
proc finish {} {
exec nam congestion.nam &
exec xgraph congestion.xg -geometry 300x300 &
exit 0
}
# Run simulation
$ns run
Sample Input and Output:
Pre Viva Questions:
1. What is NS2
NS2 stands for Network Simulator Version 2. It is an open-source event-driven simulator
designed specifically for research in computer communication networks.
2. What are the languages used by NS2
TCL and C++
3. Why two languages are used in NS2
NS2 uses OTcl to create and configure a network, and uses C++ to run simulation. All C++
codes need to be compiled and linked to create an executable file.
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
4. What is the purpose of C++ in ns2
● When you are dealing with a packet, or - when you need to modify existing NS2
modules.
● This option perhaps discourages most of the beginners from using NS2. This book
particularly aims at helping the readers understand the structure of NS2 and feel more
comfortable in modifying NS2 modules.
5. What are the tools for generating TCL Script for NS2
● NS2 scenario Generator (NSG):
● Visual Network Simulator (VNS):
● NS 2 Workbench
● Network Simulation by Mouse (NSBM)
6. What are the Advantages of NS2
Advantages
● Cheap- Does not require costly equipment
● Complex scenarios can be easily tested.
● Results can be quickly obtained-more ideas can be tested in a smaller time
frame.
● Supported protocols
● Supported platforms
● Modularity
● Popular
7. What are the Disadvantages of NS2?
● Real system too complex to model. i.e. complicated structure.
● Bugs are unreliable
Post Viva Questions
8. Define Congestion
When too many packets rushing to a node or a part of network, the network performance
degrades. This situation is called as congestion.
9. What is Open Loop Congestion Control
Open loop congestion control policies are applied to prevent congestion before it happens. The
congestion control is handled either by the source or the destination.
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
10. Explain Retransmission Policy :
It is the policy in which retransmission of the packets are taken care. If the sender feels that a
sent packet is lost or corrupted, the packet needs to be retransmitted. This transmission may
increase the congestion in the network.
11. Explain Window Policy :
The type of window at the sender side may also affect the congestion. Several packets in the
Go-back-n window are resent, although some packets may be received successfully at the
receiver side. This duplication may increase the congestion in the network and making it worse.
12. Explain Discarding Policy :
A good discarding policy adopted by the routers is that the routers may prevent congestion and
at the same time partially discards the corrupted or less sensitive package and also able to
maintain the quality of a message.
In case of audio file transmission, routers can discard less sensitive packets to prevent
congestion and also maintain the quality of the audio file.
Result:
Thus the program to simulate the behavior of TCP congestion control using NS 2
Exp No. 08 Date:……………
Study of TCP/UDP performance using Simulation tool.
Aim:
To study the performance of TCP UDP using NS2
Algorithm:
Step 1:Create a network simulator object ns to invoke simulation
Step 2:Using an object open a file in write mode
Step 3:Using the a foresaid object write all the trace output into the file
Step 4:Using an object create a file to write all nam window output into it
Step 5:Set color to represent each flow
Step 6:Create 4 nodes
Step 7:Connect node 0 and node 2 with droptail Queue of 2 Mbps
Step 8:Connect node 1 and node 2 with droptail Queue of 2 Mbps
Step 9:Connect node 2 and node 3 with droptail Queue of 4 Mbps
Step 10:Create a TCP agent and attach to node 0 and TCP sink to node 3
Step 11:Create a UDP agent and attach to node 1 and null agent to node 3
Step 12:Set fid 1 for tcp and fid 2 udp
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
Step 13:Invoke ftp agent to generate traffic of 1 mbps and attach to UDP agent
Step 14:Invoke CBR agent to generate traffic of 1 mbps and attach to TCP agent
Step 15:Invoke the data transmission process for TCP and UDP at 0.1 second
Step 16:Run the simulation
Step 17:Vary the bandwidth of the link and check the how TCP and UDP behaves in NAM window
Code:
#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 file
set nf [open out.nam w]
set f [ open congestion.tr w ]
$ns trace-all $f
$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
#Close the NAM trace file
close $nf
#Execute NAM on the trace file
exec nam out.nam &
exit 0
}
#Create four nodes
set 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 4Mb 20ms DropTail
#Set Queue Size of link (n2-n3) to 10
$ns queue-limit $n2 $n3 10
#Give node position (for NAM)
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
$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
#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 connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
$ftp set packet_size_ 1000
$ftp set rate_ 1mb
$ftp set random_ false
#Setup a UDP connection
set udp [new Agent/UDP]
$ns attach-agent $n1 $udp
set 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 0.1 "$ftp start"
$ns at 14.0 "$ftp stop"
$ns at 14.5 "$cbr stop"
#Call the finish procedure after 5 seconds of simulation time
$ns at 15.0 "finish"
#Print CBR packet size and interval
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
puts "CBR packet size = [$cbr set packet_size_]"
puts "CBR interval = [$cbr set interval_]"
#Run the simulation
$ns run
Output:
PreViva Questions:
1. Which layer is responsible for Process-to-Process Delivery of a packet?
Transport layer
2. What are the Fields on which the UDP Checksum is calculated? Why?
UDP checksum includes a pseudo header, the UDP header and the data coming from the
application layer.
3. What is TCP?
TCP provides a connection oriented, reliable byte stream service. The connection oriented
means the two applications using TCP must establish a TCP connection with each other before
they can exchange data.
4. What are the Functions of Transport Layer?
The Transport Layer is responsible for end-to-end data transport
Primary functions include:
● Provision of connection oriented or connectionless service.
● Disassembling and reassembling data.
● Setup and release of connections across the network
5. What is Socket Address
Process-to-process delivery needs two identifiers, IP address and the port number, at each end
to make a connection. The combination of an IP address and a port number is called a socket
address.
Post Viva questions
6. State the Command in ns2 to print CBR packet size
puts "CBR packet size = [$cbr set packet_size_]"
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
7. State the Command in ns2 to print CBR interval
puts "CBR interval = [$cbr set interval_]"
8. Which Command is used to run the tcl script
$ns run
9. Why Null agent is used to Receive packets from UDP source.
null agent will not send ack.
10. Which Agent is used in the receiver side to Receive TCP packets
Sink agent
11. How to Define Different Colors for Data Flows (for NAM)
$ns color 1 Blue //flow id 1
$ns color 2 Red //flow id 2
12. Write the Procedure to Stop the Simulation in ns2?
$ns at 15.0 "finish" //15.0 refers the simulation time
13. Give an example to Connect Two Nodes with duplex channel of 2mbps bandwidth
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
Result:
Study of TCP/UDP performance is done using NS2
Exp No. 09A Date:……………
Simulation of Distance Vector Routing
Aim: To simulate the behavior of Distance Vector Routing
Algorithm:
Step 1:Create a network simulator object ns to invoke simulation
Step 2:Using an object open a file in write mode
Step 3:Using the a foresaid object write all the trace output into the file
Step 4:Using an object create a file to write all nam window output into it
Step 5:Create 4 Nodes so that they are placed in a rectangular position
Step 6:Create Duplex Links for each node of 10 mbps bandwidth and delay of 10 ms
Step 7:Set one node as Source and attach TCP agent and FTP traffic generator
Step 8:Set one node as Destination and attach TCP sink
Step 9:Set routing protocol as Distance Vector
Step 10:Make any two links down and up at different timings and see how the routing is happening in
NAM window
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
Step 11:Run the Simulation
Program:
set ns [new Simulator]
set nf [open out.nam w]
$ns namtrace-all $nf
set tr [open out.tr w]
$ns trace-all $tr
proc finish {} {
global nf ns tr
$ns flush-trace
close $tr
exec nam out.nam &
exit 0
}
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
$ns duplex-link $n0 $n1 10Mb 10ms DropTail
$ns duplex-link $n1 $n2 10Mb 10ms DropTail
$ns duplex-link $n0 $n3 10Mb 10ms DropTail
$ns duplex-link $n3 $n2 10Mb 10ms DropTail
$ns duplex-link-op $n0 $n1 orient right
$ns duplex-link-op $n1 $n2 orient down
$ns duplex-link-op $n3 $n2 orient right
$ns duplex-link-op $n0 $n3 orient down
set tcp [new Agent/TCP]
$ns attach-agent $n0 $tcp
set ftp [new Application/FTP]
$ftp attach-agent $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n2 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
$ns rtmodel-at 5.0 down $n1 $n2
$ns rtmodel-at 10.0 up $n1 $n2
$ns rtmodel-at 12.0 down $n0 $n3
$ns rtproto DV
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
$ns at 1.0 "$ftp start"
$ns at 15.0 "finish"
$ns run
Sample Input and Output:
Result:
Thus the simulation of Distance Vector Routing is carried out using NS2
Exp No. 9b Date:……………
Simulation of Link State Routing
Aim:
To simulate the behavior of Link State Routing
Algorithm:
Step 1:Create a network simulator object ns to invoke simulation
Step 2:Using an object open a file in write mode
Step 3:Using the a foresaid object write all the trace output into the file
Step 4:Using an object create a file to write all nam window output into it
Step 5:Create 4 Nodes so that they are placed in a rectangular position
Step 6:Create Duplex Links for each node of 10 mbps bandwidth and delay of 10 ms
Step 7:Set one node as Source and attach TCP agent and FTP traffic generator
Step 8:Set one node as Destination and attach TCP sink
Step 9:Set routing protocol as Link State
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
Step 10:Make any two links down and up at different timings and see how the routing is happening in
NAM window
Step 11:Run the Simulation
Program:
set ns [new Simulator]
set nf [open out.nam w]
$ns namtrace-all $nf
set tr [open out.tr w]
$ns trace-all $tr
proc finish {} {
global nf ns tr
$ns flush-trace
close $tr
exec nam out.nam &
exit 0
}
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
$ns duplex-link $n0 $n1 10Mb 10ms DropTail
$ns duplex-link $n1 $n2 10Mb 10ms DropTail
$ns duplex-link $n0 $n3 10Mb 10ms DropTail
$ns duplex-link $n3 $n2 10Mb 10ms DropTail
$ns duplex-link-op $n0 $n1 orient right
$ns duplex-link-op $n1 $n2 orient down
$ns duplex-link-op $n3 $n2 orient right
$ns duplex-link-op $n0 $n3 orient down
set tcp [new Agent/TCP]
$ns attach-agent $n0 $tcp
set ftp [new Application/FTP]
$ftp attach-agent $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n2 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
$ns rtmodel-at 5.0 down $n1 $n2
$ns rtmodel-at 10.0 up $n1 $n2
$ns rtmodel-at 12.0 down $n0 $n3
$ns rtproto LS
$ns at 1.0 "$ftp start"
$ns at 15.0 "finish"
$ns run
Output
Pre Viva Questions:
1. What is Routing?
Routing is a process of selecting paths in a network through which network traffic is sent.
2. Advantages of Distance Vector Routing?
It is simpler to configure and maintain than link state routing.
3. What are the features of link state routing protocols
Link state packet – A small packet that contains routing information.
Link state database – A collection information gathered from link state packet.
Shortest path first algorithm (Dijkstra algorithm) – A calculation performed on the
database results into shortest path
Routing table – A list of known paths and interfaces.
4. What is Hop Count .
Hop count is the number of routers occurring in between the source and destination network.
5. What are the Features of RIP
1. Updates of the network are exchanged periodically.
2. Updates (routing information) are always broadcast.
3. Full routing tables are sent in updates.
4. Routers always trust on routing information received from neighbor routers. This is also
known as Routing on rumours.
Post Viva Questions
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
6. What is Static Routing?
Static routing is a process in which we have to manually add routes in routing table
7. What are the Advantages of Static Routing?
● No routing overhead for router CPU which means a cheaper router can be used to do
routing.
● It adds security because only administrator can allow routing to particular networks
only.
● No bandwidth usage between routers.
8. What are the Features of Dynamic Routing?
A dynamic protocol have following features:
● The routers should have the same dynamic protocol running in order to exchange
routes.
● When a router finds a change in the topology then router advertises it to all other
routers.
9. What are the Advantages of Dynamic Routing?
● Easy to configure.
● More effective at selecting the best route to a destination remote network and also for
discovering remote network.
10. What are the Disadvantages of Dynamic Routing?
● Consumes more bandwidth for communicating with other neighbors.
● Less secure than static routing.
●
Result:
Thus the simulation of Link State Routing is carried out using NS2.
Exp No. 10 Date:……………
Simulation of Error Correction Code
Aim:
To simulate the behavior of Error Correction Code in java
Algorithm:
Step 1:Get the input in the form of bits.
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
Step 2:Append zeros as redundancy bits .
Step 3:Divide the appended data using a divisor polynomial.
Step 4:The resulting data should be transmitted to the receiver.
Step 5:At the receiver the received data is entered.
Step 6:The same process is repeated at the receiver.
Step 7:If the remainder is zero there is no error otherwise there is some error in the received bits
Step 8:Run the program.
Program:
import java.util.Scanner;
class CRC{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
//Input Data Stream
System.out.print("Enter data stream: ");
String datastream = sc.nextLine();
System.out.print("Enter generator: ");
String generator = sc.nextLine();
int data[] = new int[datastream.length() + generator.length() - 1];
int divisor[] = new int[generator.length()];
for(int i=0;i<datastream.length();i++)
data[i] = Integer.parseInt(datastream.charAt(i)+"");
for(int i=0;i<generator.length();i++)
divisor[i] = Integer.parseInt(generator.charAt(i)+"");
//Calculation of CRC
for(int i=0;i<datastream.length();i++){
if(data[i]==1)
for(int j=0;j<divisor.length;j++)
data[i+j] ^= divisor[j];
}
//Display CRC
System.out.print("The CRC code is: ");
for(int i=0;i<datastream.length();i++)
data[i] = Integer.parseInt(datastream.charAt(i)+"");
for(int i=0;i<data.length;i++) System.out.print(data[i]);
System.out.println();
//Check for input CRC code
System.out.print("Enter CRC code: ");
datastream = sc.nextLine();
System.out.print("Enter generator: ");
generator = sc.nextLine();
data = new int[datastream.length() + generator.length() - 1];
divisor = new int[generator.length()];
for(int i=0;i<datastream.length();i++)
data[i] = Integer.parseInt(datastream.charAt(i)+"");
for(int i=0;i<generator.length();i++)
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
divisor[i] = Integer.parseInt(generator.charAt(i)+"");
//Calculation of remainder
for(int i=0;i<datastream.length();i++){
if(data[i]==1)
for(int j=0;j<divisor.length;j++)
data[i+j] ^= divisor[j];
}
//Display validity of data
boolean valid = true;
for(int i=0;i<data.length;i++)
if(data[i]==1){
valid = false;
break;}
if(valid==true) System.out.println("Data stream is valid");
else System.out.println("Data stream is invalid. CRC error occured.");
}}
//https://darshangajara.com/2013/10/30/crc-java/
//https://www.tutorialspoint.com/what-is-algorithm-for-computing-the-crc
Output:
Enter data stream: 101010
Enter generator: 11111
The CRC code is: 1010101010
Enter CRC code: 1010100010
Enter generator: 11111
Data stream is invalid. CRC error occurred.
Pre Viva Questions:
1. What are the Main Feature of Data Link Layer?
The two main features of data kink layer are flow control and error control.
2. What is Flow Control
Flow control coordinates that amount of data that can be sent before receiving ACK It is
one of the most important duties of the data link layer.
3. What is Error Control
Error control in the data link layer is based on ARQ (automatic repeat request), which is the
retransmission of data.
The term error control refers to methods of error detection and retransmission.
4. What is ARQ
Anytime an error is detected in an exchange, specified frames are retransmitted. This
process is called ARQ.
5. What is Stop and Wait ARQ
The sending devise keeps the copy of the last frame transmitted until it receives an
acknowledgement for that frame. Keeping a copy allows the sender to retransmit lost or
damaged frames until they are received correctly.
6. Define Piggybacking
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
It’s a method to combine a data frame with an ACK.
Post Viva Questions
7. What are the Types of HUB
Types of Hub
● Active Hub:- These are the hubs which have their own power supply and can clean,
boost and relay the signal along with the network. It serves both as a repeater as well as
wiring centre. These are used to extend the maximum distance between nodes.
● Passive Hub :- These are the hubs which collect wiring from nodes and power supply
from active hub. These hubs relay signals onto the network without cleaning and
boosting them and can’t be used to extend the distance between nodes.
8. What is a Bridge
Bridge – A bridge operates at data link layer. A bridge is a repeater, with add on the
functionality of filtering content by reading the MAC addresses of source and destination. It is
also used for interconnecting two LANs working on the same protocol. It has a single input and
single output port, thus making it a 2 port device.
9. What is CRC
CRC or Cyclic Redundancy Check is a method of detecting accidental changes/errors in the
communication channel.CRC uses Generator Polynomial which is available on both sender and
receiver side.
10. What is HDLC
High-Level Data Link Control (HDLC) is a bit-oriented code-transparent synchronous data link
layer protocol.
HDLC provides both connection-oriented and connectionless service.
Result:
Thus the java program to simulate the behavior of Error Correction Code is executed successfully.
ADDITIONAL EXPERIMENTS BEYOND THE SYLLABUS
Exp No. 11 Date:……………
SIMULATION OF GO BACK N PROTOCOL
Aim:
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
To Simulate and to study of Go Back N protocol.
ALGORITHM FOR GO BACK N
1. The source node transmits the frames continuously.
2. Each frame in the buffer has a sequence number starting from 1 and increasing up to the window
size.
3. The source node has a window i.e. a buffer to store the frames. This buffer size is the number of
frames to be transmitted continuously.
4. The size of the window depends on the protocol designer.
5. For the first frame, the receiving node forms a positive acknowledgement if the frame is received
without error.
6. If subsequent frames are received without error (up to window size) cumulative positive
acknowledgement is formed.
7. If the subsequent frame is received with error, the cumulative acknowledgment error-free frames are
transmitted. If in the same window two frames or more frames are received with error, the second and
the subsequent error frames are neglected. Similarly even the frames received without error after the
receipt of a frame with error are neglected.
8.The source node retransmits all frames of window from the first error frame.
9. If the frames are errorless in the next transmission and if the acknowledgment is error free, the
window slides by the number of error-free frames being transmitted.
10. If the acknowledgment is transmitted with error, all the frames of window at source are
retransmitted, and window doesn’t slide.
11. This concept of repeating the transmission from the first error frame in the window is called as
GOBACKN transmission flow control protocol
# PROGRAM FOR GOBACK N:
#send packets one by one
set ns [new Simulator]
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
set n5 [$ns node]
$n0 color "purple"
$n1 color "purple"
$n2 color "violet"
$n3 color "violet"
$n4 color "chocolate"
$n5 color "chocolate"
$n0 shape box ;
$n1 shape box ;
$n2 shape box ;
$n3 shape box ;
$n4 shape box ;
$n5 shape box ;
$ns at 0.0 "$n0 label SYS0"
$ns at 0.0 "$n1 label SYS1"
$ns at 0.0 "$n2 label SYS2"
$ns at 0.0 "$n3 label SYS3"
$ns at 0.0 "$n4 label SYS4"
$ns at 0.0 "$n5 label SYS5"
set nf [open goback.nam w]
$ns namtrace-all $nf
set f [open goback.tr w]
$ns trace-all $f
$ns duplex-link $n0 $n2 1Mb 20ms DropTail
$ns duplex-link-op $n0 $n2 orient right-down
$ns queue-limit $n0 $n2 5
$ns duplex-link $n1 $n2 1Mb 20ms DropTail
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link $n2 $n3 1Mb 20ms DropTail
$ns duplex-link-op $n2 $n3 orient right
$ns duplex-link $n3 $n4 1Mb 20ms DropTail
$ns duplex-link-op $n3 $n4 orient right-up
$ns duplex-link $n3 $n5 1Mb 20ms DropTail
$ns duplex-link-op $n3 $n5 orient right-down
Agent/TCP set_nam_tracevar_true
set tcp [new Agent/TCP]
$tcp set fid 1
$ns attach-agent $n1 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n4 $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 0.05 "$ftp start"
$ns at 0.06 "$tcp set windowlnit 6"
$ns at 0.06 "$tcp set maxcwnd 6"
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
$ns at 0.25 "$ns queue-limit $n3 $n4 0"
$ns at 0.26 "$ns queue-limit $n3 $n4 10"
$ns at 0.305 "$tcp set windowlnit 4"
$ns at 0.305 "$tcp set maxcwnd 4"
$ns at 0.368 "$ns detach-agent $n1 $tcp ; $ns detach-agent $n4 $sink"
$ns at 1.5 "finish"
$ns at 0.0 "$ns trace-annotate "Goback N end""
$ns at 0.05 "$ns trace-annotate "FTP starts at 0.01""
$ns at 0.06 "$ns trace-annotate "Send 6Packets from SYS1 to SYS4""
$ns at 0.26 "$ns trace-annotate "Error Occurs for 4th packet so not sent ack for the Packet""
$ns at 0.30 "$ns trace-annotate "Retransmit Packet_4 to 6""
$ns at 1.0 "$ns trace-annotate "FTP stops""
proc finish {} {
global ns nf
$ns flush-trace
close $nf
puts "filtering..."
#exec tclsh../bin/namfilter.tcl goback.nam
#puts "running nam..."
exec nam goback.nam &
exit 0
}
$ns run
OUTPUT:
PreViva Questions:
1.What is Error Control mechnism?
Ans:Error control in data link layer is the process of detecting and correcting data frames that
have been corrupted or lost during transmission.
2.What is NS2?
NS2 stands for Network Simulator Version 2. It is an open-source event-driven simulator
designed specifically for research in computer communication networks.
3.What are the languages used by NS2
Prepared By: R.Rajavaishnavi, AP, Dept. of IT
TCL and C++
4. What is ARQ
Anytime an error is detected in an exchange, specified frames are retransmitted. This
process is called ARQ.
5. What is Stop and Wait ARQ
The sending devise keeps the copy of the last frame transmitted until it receives an
acknowledgement for that frame. Keeping a copy allows the sender to retransmit lost or
damaged frames until they are received correctly.
Post Viva Questions
6. What is a Bridge
Bridge – A bridge operates at data link layer. A bridge is a repeater, with add on the
functionality of filtering content by reading the MAC addresses of source and destination. It is
also used for interconnecting two LANs working on the same protocol. It has a single input and
single output port, thus making it a 2 port device.
7. What is CRC
CRC or Cyclic Redundancy Check is a method of detecting accidental changes/errors in the
communication channel.CRC uses Generator Polynomial which is available on both sender and
receiver side.
8. What is HDLC
High-Level Data Link Control (HDLC) is a bit-oriented code-transparent synchronous data link
layer protocol.
HDLC provides both connection-oriented and connectionless service.
9. Define Piggybacking
It’s a method to combine a data frame with an ACK.
Result:
Thus the Go back N protocol in Ns2 is studied.
Prepared By: R.Rajavaishnavi, AP, Dept. of IT

More Related Content

PDF
IT6511 Networks Laboratory
PDF
Cn lab manual sb 19_scsl56 (1)
DOCX
Cs8581 networks lab manual 2017
PDF
Np lab
PDF
Computer Networks - CS3591 - Question Bank and Important 2 Marks Questions wi...
DOC
Biology for Engineers Course plan new 30.06.20
PPTX
Course Introduction - Importance of CN, Applications of CN.pptx
PDF
SE LAB MANUAL (R16).pdf
IT6511 Networks Laboratory
Cn lab manual sb 19_scsl56 (1)
Cs8581 networks lab manual 2017
Np lab
Computer Networks - CS3591 - Question Bank and Important 2 Marks Questions wi...
Biology for Engineers Course plan new 30.06.20
Course Introduction - Importance of CN, Applications of CN.pptx
SE LAB MANUAL (R16).pdf

Similar to MASTER RECORD computer networks Anna University (20)

DOCX
Data and Digital Communication.docx
DOC
Dc course file
PDF
Classifcation using Machine Learning and deep learning
PDF
OS lab manual1234512345123451234512345.pdf
PPTX
CO ATTAINMENT-2023 (1).pptx and program outcomess
PDF
Final 22POP13 Lab Manual- By SBL & PK.pdf
DOCX
Resume atulpal singh
DOC
01.B.E. CSE final.doc
PDF
01.b.e. cse final
DOCX
Pallavi's Resume
PDF
Ece syllabus 2017 regulation
PDF
03. B.E. ECE final.pdf
PDF
Web Technology LAB MANUAL for Undergraduate Programs
PDF
2017 BE CSE Syllabus Anna University Affiliated Colleges
PDF
2017 reg ece syllabus
PDF
NAAC PPT1
PDF
OOAD & ST LAB MANUAL.pdfOose feasibility study in detail Oose feasibility stu...
DOC
Digital principles and Computer architecture CP
PDF
B.Tech. Lab Record for Data Communication & Computer Networks
Data and Digital Communication.docx
Dc course file
Classifcation using Machine Learning and deep learning
OS lab manual1234512345123451234512345.pdf
CO ATTAINMENT-2023 (1).pptx and program outcomess
Final 22POP13 Lab Manual- By SBL & PK.pdf
Resume atulpal singh
01.B.E. CSE final.doc
01.b.e. cse final
Pallavi's Resume
Ece syllabus 2017 regulation
03. B.E. ECE final.pdf
Web Technology LAB MANUAL for Undergraduate Programs
2017 BE CSE Syllabus Anna University Affiliated Colleges
2017 reg ece syllabus
NAAC PPT1
OOAD & ST LAB MANUAL.pdfOose feasibility study in detail Oose feasibility stu...
Digital principles and Computer architecture CP
B.Tech. Lab Record for Data Communication & Computer Networks
Ad

Recently uploaded (20)

PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Cell Types and Its function , kingdom of life
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Cell Structure & Organelles in detailed.
PPTX
Institutional Correction lecture only . . .
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Classroom Observation Tools for Teachers
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Basic Mud Logging Guide for educational purpose
PDF
Sports Quiz easy sports quiz sports quiz
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Cell Types and Its function , kingdom of life
Microbial diseases, their pathogenesis and prophylaxis
Cell Structure & Organelles in detailed.
Institutional Correction lecture only . . .
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Renaissance Architecture: A Journey from Faith to Humanism
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
TR - Agricultural Crops Production NC III.pdf
Classroom Observation Tools for Teachers
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPH.pptx obstetrics and gynecology in nursing
Basic Mud Logging Guide for educational purpose
Sports Quiz easy sports quiz sports quiz
O5-L3 Freight Transport Ops (International) V1.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Ad

MASTER RECORD computer networks Anna University

  • 1. M.A.M. College of Engineering and Technology Department of Information Technology LAB MASTER RECORD Course Code : CS3591 Course Name : Computer Networks Year / Semester : III / V Department : IT Faculty Name : R.Rajavaishnavi Regulation : AU-R2021 Academic year : 2024-25 ODD Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 2. Department Vision and Mission Vision To be a school of excellence by providing holistic education and fostering research in IT to produce technically competent, socially and ethically responsible students. Mission 1.To provide a solid foundation in computational engineering for a successful career in Information Technology. 2.To provide technical support and facilities to enrich research and development in the field of Information Technology. 3.To collaborate in interdisciplinary projects with academia and industry through emerging technologies. 4.To inculcate professional behavior, lifelong learning with ethical values. 5.To empower engineers with excellent communication, teamwork, and interpersonal skills. Program Educational Objectives(PEOs) PEO 1 To be a skilled professional in providing technically feasible solutions in data driven technology and security principles for industry and society. PEO 2 To emerge as a developer & researcher by engaging in lifelong learning and adapting to challenging environments. PEO 3 To Exhibit entrepreneurship skills, leadership qualities and professional ethics to start new ventures. PEO 4 To be prepared for their career in the software industry or pursue higher studies. PROGRAMME SPECIFIC OUTCOMES (PSOS) PSO 1 To apply basic science, programming, algorithms, and data management for developing software solutions. PSO 2 To apply data driven technology and information security principles for developing reliable information systems. PROGRAMME OUTCOMES (POS) PO1 Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals, and an engineering specialization to the solution of complex engineering Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 3. problems. PO2 Problem analysis: Identify, formulate, review research literature, and analyze complex engineering problems reaching substantiated conclusions using first principles of mathematics, natural sciences, and engineering sciences. PO3 Design/development of solutions: Design solutions for complex engineering problems and design system components or processes that meet the specified needs with appropriate consideration for the public health and safety, and the cultural, societal, and environmental considerations. PO4 Conduct investigations of complex problems: Use research-based knowledge and research methods including design of experiments, analysis and interpretation of data, and synthesis of the information to provide valid conclusions. PO5 Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern engineering and IT tools including prediction and modelling to complex engineering activities with an understanding of the limitations. PO6 The engineer and society: Apply reasoning informed by the contextual knowledge to assess societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to the professional engineering practice. PO7 Environment and sustainability: Understand the impact of the professional engineering solutions in societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable development. PO8 Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of the engineering practice. PO9 Individual and team work: Function effectively as an individual, and as a member or leader in diverse teams, and in multidisciplinary settings. PO10 Communication: Communicate effectively on complex engineering activities with the engineering community and with society at large, such as, being able to comprehend and write effective reports and design documentation, make effective presentations, and give and receive clear instructions PO11 Project management and finance: Demonstrate knowledge and understanding of the engineering and management principles and apply these to one’s own work, as a member and leader in a team, to manage projects and in multidisciplinary environments. PO12: Life-long learning: Recognize the need for, and have the preparation and ability to engage in independent and life-long learning in the broadest context of technological change. Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 4. Syllabus Course Objectives : 1. To learn and use network commands. 2. To learn socket programming. 3. To implement and analyze various network protocols. 4. To learn and use simulation tools. 5. To use simulation tools to analyze the performance of various network protocols. List of Experiments 1.Learn to use commands like tcpdump, netstat, ifconfig, nslookup and traceroute. Capture ping and traceroute PDUs using a network protocol analyzer and examine. 2.Write a HTTP web client program to download a web page using TCP sockets. 3.Applications using TCP sockets like: Echo client and echo server Chat 4.Simulation of DNS using UDP sockets. 5.Use a tool like wireshark to capture packets and examine the packets. 6.Write a code simulating ARP /RARP protocols. 7.Study of Network simulator (NS) and Simulation of Congestion Control Algorithms using NS. 8.Study of TCP/UDP performance using Simulation tool. 9.Simulation of Distance Vector/ Link State Routing algorithm. 10.Simulation of error correction code (like CRC). Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 5. Course Outcome CO Details BTL CO501.1 Develop the procedure to conduct the experiment using programminglanguagesC,JavaandNetworksimulator(ns2) software K3 - Apply CO501.2 Demonstrate skills at the level of precision (reliably, quickly, smoothly, and accurately with negligible guidance)in performing the experiment K3 - Apply CO501.3 Draw inferences from the experiment conducted K4 - Analyze CO501.4 Demonstrate professionally the results obtained through the experiment and present conclusions K4 - Analyze CO501.5 Demonstrate an understanding of the concepts, procedures, and applications through verbal and written communication K3 - Apply CO501.6 Demonstrating an attitude at the level of valuing (attaching values and expressing personal opinions by showing some definite involvement and commitment) K3 - Apply CO and PO Mapping CO PO 1 PO2 PO3 PO4 PO5 PO 6 PO7 PO8 PO 9 PO10 PO1 1 PO12 PSO1 PSO2 CO508.1 3 - - - - - - - 3 3 - - 3 3 CO508.2 3 - - - 3 - - 2 3 - 1 - 3 3 CO508.3 3 2 - 2 - 1 - - - 3 - - - - CO508.4 3 - - - - - - - - 3 - - 3 3 CO508.5 3 - - - - - - - - 3 - 1 2 2 CO508.6 - - - - - 2 - 2 2 2 - 1 - - Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 6. INDEX Sl. No. Name of the Experiment CO Page No. 1. Learn to use commands like tcpdump, netstat, ifconfig, nslookup and traceroute. Capture ping and traceroute PDUs using a network protocol analyzer and examine CO501.1 6 2. Write a HTTP web client program to download a web page using TCP sockets. CO501.2 13 3. Applications using TCP sockets like: ● Echo client and echoserver ● Chat CO501.2 19 4. Simulation of DNS using UDP sockets. CO501.2 32 5. Use a tool like wireshark to capture packets and examine the packets. CO501.2 34 6. Write a code simulating ARP /RARP protocols. CO501.2 37 7. Study of Network simulator (NS) and Simulation of Congestion Control Algorithms using NS. CO501.4 41 8. Study of TCP/UDP performance using Simulation tool. CO501.4 56 9. Simulation of Distance Vector/ Link State Routing algorithm. CO501.4 63 10 Simulation of error correction code (like CRC). CO501.6 76 Additional Experiments beyond the syllabus Sl. No. Name of the Experiment CO Page No. 11. SIMULATION OF GO BACK N PROTOCOL CO508.4 81 Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 7. RUBRICS: Grading of Laboratory experiment / exercise Criterion (marks) Marks Marks awarded for the criterion 5 to 4 3 to 2 1 to 0 1. Correctness of the Procedure for the experiment / exercise (3) All the steps are followed in correct sequence. Knows how to proceed theexperiment. Some steps are followed but error occurred. Proceeded the experiment with the guidance. Steps are not followed.Not showing interest to do theexperiment. 8 or 7 or 6 5 or 4 or 3 2 or 1 or 0 2. Skills level in performing the experiment / exercise (8) Show excellent understanding of the experiment. All data is recorded and neatly presented Show minimal Understanding of the experiment. All data is recorded and is not presented neatly Show nounderstanding ofthe experiment. All data is not recorded and is not presented neatly 3 2 1 3. Inferences drawn from the experiment / exercise (3) Correct inferences have been drawn and presented professionally Inferences drawn are correctly but not presented professionally Inferences drawn are partially incorrectly or incorrect 3 2 1 4. Presentation of results (3) Calculation are present neatly with accurate results. Calculation are present neatly with minor mistakes Wrong calculations. Major mistakes. 5 to 4 3 to 2 1 to 0 5. Clarity in answering Viva questions (5) Almost all the questions are answered. Partially answered Unable to answer. 3 2 1 6. Attitude reflected in doing the experiment / exercise (3) The experiment is completed on time. Manual/Record note is submitted on time. The experiment is completed on time, but the Manual / Record note is not submitted on time The experiment is not completed on time. Observation / Record note is not submitted on time. Total marks out of 25 Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 8. R.Rajavaishnavi Dr. K. Geetha Lab in charge Head of the Department Exp No. 01 Date:…………… Learn to use commands like tcpdump, netstat, ifconfig, nslookup and traceroute. Capture ping and traceroute PDUs using a network protocol analyzer and examine. Aim: To learn the usage of commands like tcpdump, netstat, ifconfig, nslookup and traceroute. Capture ping and traceroute PDUs using a network protocol analyzer and examine. Theory: 1. tcp dump tcpdump is a most powerful and widely used command-line packets sniffer or package analyzer tool which is used to capture or filter TCP/IP packets that received or transferred over a network on a specific interface. It saves the file in a pcap format, that can be viewed by tcpdump command or a open source GUI based tool called Wireshark (Network Protocol Analyzier) that reads tcpdumppcap format files. 2. netstat In computing, netstat (network statistics) is a command-line network utility that displays network connections for Transmission Control Protocol (both incoming and outgoing), routing tables, and a number of network interface (network interface controller or software-defined network interface) and network protocol statistics. 3. nslookup nslookup is a network administration command-line tool available in many computer operating systems for querying the Domain Name System (DNS) to obtain domain name or IP address mapping, or other DNS records. The name "nslookup" means "name server lookup". 4. traceroute In computing, traceroute computer network diagnostic commands for displaying the route (path) and measuring transit delays of packets across an Internet Protocol (IP) network. Traceroute proceeds unless all (three) sent packets are lost more than twice; then the connection is lost and the route cannot be evaluated Algorithm: Step 1: Start Step 2: Open the terminal Step 3: Issue the Commands tcpdump, netstat, ifconfig, nslookup and traceroute with proper syntax and perform ping and traceroute operation and capture packets using wireshark . Step 4:Read the result Step 5:Get the output Program: SNo Command Purpose Syntax Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 9. 1 tcpdump dump traffic on a network tcpdump -i any 2 netstat Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships netstat -r netstat –i 3 ifconfig configure a network interface Ifconfig 4 nslookup Nslookup is a program to query Internet domain name servers. Nslookup has two modes: interactive and non-interactive. Interactive mode allows the user to query name servers for information about various hosts and domains or to print a list of hosts in a domain. Non-interactive mode is used to print just the name and requested information for a host or domain. nslookup google.com 5 traceroute print the route packets trace to network host traceroute google.com 6 Ping send ICMP ECHO_REQUEST to network hosts ping google.com Sample Input and Output: Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 10. 1.tcp dump tcpdump -i any >a.txt (the output is redirected to a.txt) 02:54:34.766681 IP6 fe80::3cf4:26ff:fe43:ccab > ff02::1: ICMP6, router advertisement, length 64 02:54:34.767405 IP 192.168.1.101.58668 > 192.168.1.1.domain: 57139+ PTR? 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.f.f.ip6.arpa. (90) 02:54:34.770630 IP 192.168.1.1.domain> 192.168.1.101.58668: 57139 NXDomain 0/0/0 (90) 02:54:34.770828 IP 192.168.1.101.40513 > 192.168.1.1.domain: 14252+ PTR? b.a.c.c.3.4.e.f.f.f.6.2.4.f.c.3.0.0.0.0.0.0.0.0.0.0.0.0.0.8.e.f.ip6.arpa. (90) 02:54:34.773912 IP 192.168.1.1.domain> 192.168.1.101.40513: 14252 NXDomain 0/0/0 (90) 02:54:34.774116 IP 192.168.1.101.56139 > 192.168.1.1.domain: 10338+ PTR? 1.1.168.192.in- addr.arpa. (42) 02:54:34.777183 IP 192.168.1.1.domain> 192.168.1.101.56139: 10338 NXDomain 0/0/0 (42) 02:54:34.777346 IP 192.168.1.101.40647 > 192.168.1.1.domain: 25219+ PTR? 101.1.168.192.in- addr.arpa. (44) 02:54:34.780386 IP 192.168.1.1.domain> 192.168.1.101.40647: 25219 NXDomain 0/0/0 (44) 2.netstat Kernel IP routing table Destination Gateway Genmask Flags MSS Window irttIface 192.168.122.0 * 255.255.255.0 U 0 0 0 virbr0 192.168.0.0 * 255.255.0.0 U 0 0 0 wlan0 default 192.168.1.1 0.0.0.0 UG 0 0 0 wlan0 [root@localhost~]# 3.ifconfig [root@localhost~]# ifconfig eth0 Link encap:EthernetHWaddr 6C:3B:E5:10:5C:11 UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) Interrupt:20 Memory:f7c00000-f7c20000 4.traceroute google.com [root@localhost~]# traceroute google.com traceroute to google.com (172.217.163.78), 30 hops max, 60 byte packets 1 192.168.1.1 (192.168.1.1) 4.870 ms 4.803 ms 4.757 ms 2 * * * 3 10.71.201.82 (10.71.201.82) 379.988 ms 10.71.201.74 (10.71.201.74) 379.917 ms 380.296 ms 4 172.25.55.205 (172.25.55.205) 380.254 ms 379.772 ms 379.707 ms 5 172.26.56.79 (172.26.56.79) 379.664 ms 379.572 ms 379.547 ms 6 172.25.8.7 (172.25.8.7) 379.450 ms 372.567 ms 372.538 ms 7 * * * 8 * * * Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 11. 9 * * * 10 72.14.217.58 (72.14.217.58) 162.217 ms 72.14.217.254 (72.14.217.254) 162.202 ms 162.126 ms 11 * * * 12 216.239.42.237 (216.239.42.237) 426.763 ms 72.14.237.164 (72.14.237.164) 106.196 ms 216.239.42.237 (216.239.42.237) 39.846 ms 13 maa05s02-in-f14.1e100.net (172.217.163.78) 40.925 ms 408.176 ms 108.170.253.119 (108.170.253.119) 96.572 ms [root@localhost~]# 5.ping google.com [root@localhost~]# ping google.com PING google.com (172.217.163.78) 56(84) bytes of data. 64 bytes from maa05s02-in-f14.1e100.net (172.217.163.78): icmp_seq=1 ttl=114 time=42.1 ms 64 bytes from maa05s02-in-f14.1e100.net (172.217.163.78): icmp_seq=2 ttl=114 time=40.6 ms 64 bytes from maa05s02-in-f14.1e100.net (172.217.163.78): icmp_seq=3 ttl=114 time=39.2 ms 64 bytes from maa05s02-in-f14.1e100.net (172.217.163.78): icmp_seq=4 ttl=114 time=45.8 ms 64 bytes from maa05s02-in-f14.1e100.net (172.217.163.78): icmp_seq=5 ttl=114 time=43.9 ms PreVivaQuestions: 1. What are the Two Interfaces provided by Protocols? A. Service interface B. Peer interface ✔ Service interface-defines the operations that local objects can perform on the protocol. ✔ Peer interface-defines the form and meaning of messages exchanged between protocol peers to implement the communication service. 2. What is LAN? A LAN is a common name used to describe a group of devices that share a geographic location. LAN is limited to single building or campus. 3. For n devices in a network, what is the number of cable links required for a mesh and ring topology? Mesh topology – n (n-1)/2 Ring topology – n 4. Define Topology? Network topology is the arrangement of the elements (links, nodes, etc.) of a communication network 5. What are the Types of Topology? There are five types of topology in computer networks: a) Mesh Topology. b) Star Topology. c) Bus Topology. d) Ring Topology. e) Hybrid Topology Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 12. Post viva Questions 6. What is the Purpose of TCP Dump? Tcp dump is used to dump traffic on a network. 7. What is the Purpose of netstat command? Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships. 8. What is the Purpose of ifconfig command? It is used to configure a network interface. It is used to send ICMP ECHO_REQUEST to network hosts 9. What is the Purpose of Traceroute command? It is used to print the route packets trace to network host. 10. Which command is used to Test the connectivity between local machine and remote machine? ping Result: Thus the commands are excuted and verified successfully Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 13. Exp No. 02 Date:…………… Write a HTTP web client program to download a web page using TCP sockets. Aim: To write a HTTP web client program to download a web page using TCP sockets Theory: Java Socket programming can be connection-oriented or connection-less. Socket and ServerSocket classes are used for connection-oriented socket programming and DatagramSocket and DatagramPacket classes are used for connection-less socket programming. The client in socket programming must know two information: ● IP Address of Server, and ● Port number. Here, we are going to make one-way client and server communication. In this application, client sends a message to the server, server reads the message and prints it. Here, two classes are being used: Socket and ServerSocket. The Socket class is used to communicate client and server. Through this class, we can read and write message. The ServerSocket class is used at server-side. The accept() method of ServerSocket class blocks the console until the client is connected. After the successful connection of client, it returns the instance of Socket at server-side. Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 14. Socket class A socket is simply an endpoint for communications between the machines. The Socket class can be used to create a socket. Important methods Method Description 1) public InputStream getInputStream() returns the InputStream attached with this socket. 2) public OutputStream getOutputStream() returns the OutputStream attached with this socket. 3) public synchronized void close() closes this socket ServerSocket class The ServerSocket class can be used to create a server socket. This object is used to establish communication with the clients. Important methods Method Description 1) public Socket accept() returns the socket and establish a connection between server and client. 2) public synchronized void close() closes the server socket. Algorithm: Step 1: Create URL object using url string. Step 2:Create a BufferReader object using url.openStream() method. Step 3:Create a BufferWriter object to write to a file. Step 4:Read each line using BufferReader and write using BufferWriter. Step 5:Open the downloaded contents using a brower. Program: import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; public class Tester { public static void main(String args[]) throws IOException { download("http://www.google.com"); } public static void download(String urlString) throws IOException { URL url = new URL(urlString); Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 15. try( BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); BufferedWriter writer = new BufferedWriter(new FileWriter("page.html")); ) { String line; while ((line = reader.readLine()) != null) { writer.write(line); } System.out.println("Page downloaded."); }}} Sample Input and Output: Compile: javac Tester.java Run : java Tester Output: Page downloaded. Open the downloaded content using browser Pre Viva Questions 1. What is Flow Control? Flow control refers to a set of procedures used to restrict the amount of data. The sender can send before waiting for acknowledgment. 2. What is mean by Error Control? Error control is a method that can be used to recover the corrupted data whenever possible. These are two basic types of error control which are backward error control and forward error control. 3. What is Bridge? Bridge is a hardware networking device used to connect two LANs. A bridge operates at data link layer of the OSI reference model. 4. What is a Rrepeater? Repeater is a hardware device used to strengthen signals being transmitted on a network. Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 16. 5. Define Router A network layer device that connects networks with different physical media and translates between different network architecture. Post viva questions 6. What is a Switch? A switch is a networking device that manages networked connections between devices on a star networks. 7. What are the Functions of Bridge? 1. Connecting networks 2. Filtering information so that network traffic for one portion of the network does not congest the rest of the network. 8. What is URL A Uniform Resource Locator (URL), colloquially termed a web address,[1] is a reference to a web resource that specifies its location on a computer network and a mechanism for retrieving it. 9. What is the Socket. Sockets allow communication between two different processes on the same or different machines. A network socket is an internal endpoint for sending or receiving data within a node on a computer network. 10. What is the Purpose of InputStreamReader in Java? An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes them into characters using a specified charset. Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 17. Result: Thus the program for HTTP web client program to download a web page using TCP sockets is successfully executed and the content is opened and viewed by browser. Exp No. 03 Date:…………… 3 A: Creation of TCP Socket for Echo Client and Echo Server Aim: To create TCP Socket for Echo Client and Echo Server in JAVA Algorithm: Server 1.Create a socket and listen for client communication 2.Establish the connection 2.Receive client's message . 3.Read Client's message and display it 4.Send the message back to client 5.Repeat steps 2-4 until the client has something to send 6.Close the server socket 7.Stop Client 1.Establish the server connection via specified port 2.Get a message from user 3.Send it to server 4.Receive echoed message 5.Read server's response and display it 6.Repeat steps 2-5 until there is some text to send 7.Close the client socket 8.Stop // EchoServer.java : A Simple Echo Server Program Server: import java.io.*; import java.net.*; public class EchoServer { public static void main(String args[]) throws Exception { try Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 18. { int Port; BufferedReader Buf =new BufferedReader(new InputStreamReader(System.in)); System.out.print(" Enter the Port Address : " ); Port=Integer.parseInt(Buf.readLine()); ServerSocket sok =new ServerSocket(Port); System.out.println(" Server is Ready To Receive a Message. "); System.out.println(" Waiting ..... "); Socket so=sok.accept(); if(so.isConnected()==true) System.out.println(" Client Socket is Connected Succecfully. "); InputStream in=so.getInputStream(); OutputStream ou=so.getOutputStream(); PrintWriter pr=new PrintWriter(ou); BufferedReader buf=new BufferedReader(new InputStreamReader(in)); String str=buf.readLine(); System.out.println(" Message Received From Client : " + str); System.out.println(" This Message is Forwarded To Client. "); pr.println(str); pr.flush(); } catch(Exception e) { System.out.println(" Error : " + e.getMessage()); }}} Client: import java.io.*; import java.net.*; public class EchoClient { public static void main(String args[]) throws Exception { try { int Port; BufferedReader Buf =new BufferedReader(new InputStreamReader(System.in)); System.out.print(" Enter the Port Address : " ); Port=Integer.parseInt(Buf.readLine()); Socket sok=new Socket("localhost",Port); if(sok.isConnected()==true) System.out.println(" Server Socket is Connected Succecfully. "); InputStream in=sok.getInputStream(); OutputStream ou=sok.getOutputStream(); Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 19. PrintWriter pr=new PrintWriter(ou); BufferedReader buf1=new BufferedReader(new InputStreamReader(System.in)); BufferedReader buf2=new BufferedReader(new InputStreamReader(in)); String str1,str2; System.out.print(" Enter the Message : "); str1=buf1.readLine(); pr.println(str1); pr.flush(); System.out.println(" Message Send Successfully. "); str2=buf2.readLine(); System.out.println(" Message From Server : " + str2); } catch(Exception e) { System.out.println(" Error : " + e.getMessage()); }}} Sample Input and Output: D:New folderPGMEX_8_A_ECHO>javac EchoClient.java D:New folderPGMEX_8_A_ECHO>java EchoClient Enter the Port Address : 9999 Server Socket is Connected Succecfully. Enter the Message : Hai Message Send Successfully. Message From Server : Hai D:New folderPGMEX_8_A_ECHO> D:New folderPGMEX_8_A_ECHO>javac EchoServer.java D:New folderPGMEX_8_A_ECHO>java EchoServer Enter the Port Address : 9999 Server is Ready To Receive a Message. Waiting ..... Client Socket is Connected Succecfully. Message Received From Client : Hai This Message is Forwarded To Client. D:New folderPGMEX_8_A_ECHO> Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 20. Result: Thus the program to create TCP Socket for Echo Client and Echo Server in JAVA. 3 B: Creation of TCP Socket for Chat Aim: To create a TCP Socket for Chatting in JAVA 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.Establish connection with the server socket. 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 Server: import java.io.*; import java.net.*; public class GossipServer { public static void main(String[] args) throws Exception { ServerSocket sersock = new ServerSocket(3000); System.out.println("Server ready for chatting"); Socket sock = sersock.accept( ); // reading from keyboard (keyRead object) BufferedReader keyRead = new BufferedReader(new InputStreamReader(System.in)); // sending to client (pwrite object) OutputStream ostream = sock.getOutputStream(); PrintWriter pwrite = new PrintWriter(ostream, true); // receiving from server ( receiveRead object) InputStream istream = sock.getInputStream(); BufferedReader receiveRead = new BufferedReader(new InputStreamReader(istream)); Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 21. String receiveMessage, sendMessage; while(true) { if((receiveMessage = receiveRead.readLine()) != null) { System.out.println(receiveMessage); } sendMessage = keyRead.readLine(); pwrite.println(sendMessage); pwrite.flush(); } } } Client: import java.io.*; import java.net.*; public class GossipClient { public static void main(String[] args) throws Exception { Socket sock = new Socket("127.0.0.1", 3000); // reading from keyboard (keyRead object) BufferedReader keyRead = new BufferedReader(new InputStreamReader(System.in)); // sending to client (pwrite object) OutputStream ostream = sock.getOutputStream(); PrintWriter pwrite = new PrintWriter(ostream, true); // receiving from server ( receiveRead object) InputStream istream = sock.getInputStream(); BufferedReader receiveRead = new BufferedReader(new InputStreamReader(istream)); System.out.println("Start the chitchat, type and press Enter key"); String receiveMessage, sendMessage; while(true) { sendMessage = keyRead.readLine(); // keyboard reading pwrite.println(sendMessage); // sending to server pwrite.flush(); // flush the data if((receiveMessage = receiveRead.readLine()) != null) //receive from server { System.out.println(receiveMessage); // displaying at DOS prompt }} }} Output: D:New folderPGMEX_8_B_TALK>javac GossipServer.java D:New folderPGMEX_8_B_TALK>java GossipServer Server ready for chatting hai how i am fine are you D:New folderPGMEX_8_B_TALK>javac GossipClient.java D:New folderPGMEX_8_B_TALK>java GossipClient Start the chitchat, type and press Enter key hai how i am fine Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 22. Result: Thus the program to create a TCP Socket for Chatting in JAVA is successfully executed and verified Ex:3.c Creation of TCP Sockets for File Transfer Aim: To create a TCP Socket for File Transfer Algorithm Server 1.Create a server socket 2.Wait for client to be connected. 3.Read the file name coming from client , uses input stream. 4.Open the file, using some input stream, and read the contents. 5.As the reading is going on, to send the contents each line separately. 6.Close the connection if all the contents are read and sent. Client 1.Establish connection with the server socket 2.To take input for file name from keyboard. Remember, this file should exist on server. For this, it uses input stream.To take input from the keyboard, a BufferedReader object, keyRead, is created. To send the file name to the server, pwrite of PrintWriter 3.The file read from keyboard should be sent to the server. For this client uses output stream. 4.The file contents sent by the server, the client should receive and print on the console.To receive the file contents from the server, socketRead of BufferedReader are created Program: Server import java.net.*; import java.io.*; public class ContentsServer { public static void main(String args[]) throws Exception { // establishing the connection with the server ServerSocket sersock = new ServerSocket(4000); System.out.println("Server ready for connection"); Socket sock = sersock.accept(); // binding with port: 4000 System.out.println("Connection is successful and wating for chatting"); // reading the file name from client InputStream istream = sock.getInputStream( ); BufferedReader fileRead =new BufferedReader(new InputStreamReader(istream)); Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 23. String fname = fileRead.readLine( ); // reading file contents BufferedReadercontentRead = new BufferedReader(new FileReader(fname) ); // keeping output stream ready to send the contents OutputStream ostream = sock.getOutputStream( ); PrintWriter pwrite = new PrintWriter(ostream, true); String str; while((str = contentRead.readLine()) != null) // reading line-by-line from file { pwrite.println(str); // sending each line to client } sock.close(); sersock.close(); // closing network sockets pwrite.close(); fileRead.close(); contentRead.close(); }} Client: import java.net.*; import java.io.*; public class ContentsClient { public static void main( String args[ ] ) throws Exception { Socket sock = new Socket( "127.0.0.1", 4000); // reading the file name from keyboard. Uses input stream System.out.print("Enter the file name"); BufferedReader keyRead = new BufferedReader(new InputStreamReader(System.in)); String fname = keyRead.readLine(); // sending the file name to server. Uses PrintWriter OutputStream ostream = sock.getOutputStream( ); PrintWriter pwrite = new PrintWriter(ostream, true); pwrite.println(fname); // receiving the contents from server. Uses input stream InputStream istream = sock.getInputStream(); BufferedReader socketRead = new BufferedReader(new InputStreamReader(istream)); String str; while((str = socketRead.readLine()) != null) // reading line-by-line { System.out.println(str); } pwrite.close(); socketRead.close(); keyRead.close(); }} Output: Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 24. D:New folderPGMEX_8C_File_Transferserver>javac ContentsServer.java D:New folderPGMEX_8C_File_Transferserver>java ContentsServer Server ready for connection Connection is successful and wating for chatting D:New folderPGMEX_8C_File_Transferserver> D:New folderPGMEX_8C_File_TransferClient>javac ContentsClient.java D:New folderPGMEX_8C_File_TransferClient>java ContentsClient Enter the file namea HAI I AM GOOD D:New folderPGMEX_8C_File_TransferClient> Pre Viva Questions: 1. What is Echo? In telecommunications, echo is the local display of data, either initially as it is locally sourced and sent, or finally as a copy of it is received back from a remote destination. 2. What is a Port? Ports are identified for each protocol and address combination by 16-bit unsigned numbers, commonly known as the port number. The most common protocols that use port numbers are the Transmission Control Protocol (TCP) and the User Datagram Protocol (UDP). 3. Who is Responsible for the global coordination of the DNS Root, IP addressing, and other Internet protocol resources.? IANA- The Internet Assigned Numbers Authority (IANA) is a standards organization that oversees global IP address allocation, autonomous system number allocation, root zone management in the Domain Name System (DNS), media types, and other Internet Protocol- related symbols and Internet numbers. 4. What is the Default Port Number for Echo Protocol? Port Number :7 5. What is FTP? The File Transfer Protocol (FTP) is a standard network protocol used for the transfer of computer files between a client and server on a computer network. Post viva Questions 6. What are the Disadvantages of FTP clients? ● Usernames, passwords and files are sent in clear text ● Filtering active FTP connections is difficult on your local machine (passive is preferred) ● Servers can be spoofed to send data to a random port on an unintended computer ● Hard to script jobs 7. What is the Purpose of readLine() method in java? readLine() method to read a file line by line 8. What is the Purpose of FileReader in Java? Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 25. FileReader is meant for reading streams of characters. For reading streams of raw bytes, consider using a FileInputStream. Parameters: fileName - the name of the file to read from 9. What is the Purpose of the keyRead.readLine(); method in java? This method returns the string containing the line read from the console. Result: Thus the program to create a TCP Socket for File Transfer is successfully executed Exp No. 04 Date:…………… Create a UDP Socket to Simulate the behavior of DNS Service Aim: To Create a UDP Socket to Simulate the behavior of DNS Service in JAVA Algorithm 1.Establish Client and Server Socket Connection 2.Make the client query for IP Address of a host name to server 3.Resolve the IP address for requested host name queried by the client 4.Display the result 5.Do the step 2 to step 4 until nothing to be resolved. Server: import java.io.*; import java.net.*; class UDPserver { public static DatagramSocket ds; public static byte buffer[]=new byte[1024]; public static int clientport = 789,serverport=790; public static void main(String args[])throws Exception { ds=new DatagramSocket(clientport); System.out.println("press ctrl+c to quit the program"); while(true) { DatagramPacket p=new DatagramPacket(buffer,buffer.length); ds.receive(p); String psx=new String(p.getData(),0,p.getLength()); System.out.println("Client:" + psx); InetAddress ib=InetAddress.getByName(psx); System.out.println("Server output:"+ib); }}} Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 26. Client: import java .io.*; import java.net.*; class UDPclient { public static DatagramSocket ds; public static int clientport=789,serverport=790; public static void main(String args[])throws Exception { byte buffer[]=new byte[1024]; ds=new DatagramSocket(serverport); BufferedReader dis=new BufferedReader(new InputStreamReader(System.in)); System.out.println("server waiting"); InetAddress ia=InetAddress.getLocalHost(); while(true) { System.out.println("Client:"); String str=dis.readLine(); if(str.equals("end")) break; buffer=str.getBytes(); ds.send(new DatagramPacket(buffer,str.length(),ia,clientport)); }}} Output D:New folderPGMEX_9_D_DNS>javac UDPserver.java D:New folderPGMEX_9_D_DNS>java UDPserver press ctrl+c to quit the program Client:www.facebook.com Server output:www.facebook.com/31.13.78.35 Client:www.yahoo.com Server output:www.yahoo.com/98.138.219.232 D:New folderPGMEX_9_D_DNS>javac UDPclient.java D:New folderPGMEX_9_D_DNS>java UDPclient server waiting Client: www.facebook.com Client: www.yahoo.com PreViva Questions: 1. What is DNS? Domain Name Systems(DNS) maps domain names with Internet Protocol(IP) address, thus helping computer for translating human-readable(domain name) to machine-readable language(IP address). Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 27. e.g.:https://www.freshersemploy.com 2. What is DNS Server? DNS servers resolve IP address to respective hostnames and it maintains directory or database to store the information. 3. What are the Different Types of Records in DNS? Some of commonly used of DNS records are A, CNAME, NS, MX, PTR, SOA etc. 4. What is the Use of PTR in DNS? PTR(Pointer) records are used for mapping IP addresses which are associated with hostname name. It is also called has reverse DNS lookup as it resolves IP address to domain or hostname. There must be A record for every PTR record. PTR is mainly used for the mail server. 5. Explain CNAME record? CNAME record stands for Canonical Name record. It used as the alias for domain or the Canonical name(another name) for a domain. Post Viva Questions 6. What is DNS Zone? A DNS zone file contains the mapping between a domain name, IP address, recourse records etc. in text representative format. Also, DNS zone refers to the administrative responsibility in the DNS. 7. Define TTL? Time-to-live caches the DNS records for a specific period of time(when TTL expires, it has to query new record). It helps in queries the records faster, eventually reducing the load on the DNS server. 8. Explain MX record? Mail Exchange(MX) record is a type of resource record which is used for email sending and delivery. It must be specified in the DNS zone files mails for the domain. 9. What is Forward Lookup? Forward Lookup is used to find the IP address through the domain name. 10. What is Reverse Lookup? Reverse Lookup is used for finding the domain name through it IP. Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 28. Result: Thus the program to Create a UDP Socket to Simulate the behavior of DNS Service in JAVA is executed successfully. Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 29. Exp No. 06 Date:…………… Simulating ARP and RARP Protocols AIM: To simulate the behavior of ARP and RARP Protocols in JAVA Algorithm: 1. Create a Process at Run Time 2. Pass the argument to determine the link layer address for address resolution 3. Determine the reader class to read the address determined, which contains ip address and mac address 4. Display the result Program: import java.io.BufferedReader; import java.io.InputStreamReader; public class ARP { public static void main(String[] args) { try{ String s1="arp -a"; Process p = Runtime.getRuntime().exec(s1); BufferedReaderinputStream = new BufferedReader(newInputStreamReader(p.getInputStream())); String s = ""; while ((s = inputStream.readLine()) != null) { System.out.println(s); } } catch (Exception e) { e.printStackTrace(); } } } Output D:New folderPGMEX_3_ARP_RARP>javac ARP.java D:New folderPGMEX_3_ARP_RARP>java ARP Interface: 192.168.50.250 --- 0xa Internet Address Physical Address Type 192.168.50.4 90-fb-a6-12-af-dd dynamic 192.168.50.255 ff-ff-ff-ff-ff-ff static 192.168.61.1 00-90-7f-43-84-0b dynamic 192.168.61.85 90-fb-a6-12-af-ba dynamic 192.168.61.102 90-fb-a6-12-af-27 dynamic Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 30. Pre Viva Questions: 1. Define Networking, Internetworking? Networking – Interconnecting the individual host. Internetworking – Interconnecting the different networks. 2. Define MAC address, IP address? MAC address – is the physical address of a host. Its length is 48 bits. Eg:12:de:34:0f:1x:1d IP address – is the logical address of a host. Its length is 32 bits. Eg:191.168.150.1 3. How we can identify a Host. A host can be identified by its logical address (IP) and physical address(MAC). 4. Define Classfull and Classless addressing? Classful addressing – Total address space is divided in to 5 classes called as Class ‘A’, Class ‘B’, Class ‘C’, Class’D’ and Class’E’ such that each class with their own prefix. Classless addressing – Here, there are variable length blocks that belong to no class. The entire address space is divided in to blocks based on organization needs. 5.What is Subnetting ? Subnetting divides one large network into several smaller ones. Subnetting adds an intermediate level of hierarchy in IP addressing. Post Viva Questions: 6. What is Supernetting? Supernetting combines several networks into one large one. 7. What is meant by Masking ? Masking is a process that extracts the network address from an IP address. Subnet masking is a process that extracts the subnetwork address from an IP address. A network or subnet address is obtained from applying the bit-wise AND operation on the IP address and the mask. 8. What is the Function of Routing Table? Every host or router has a routing table to route IP packets. In next hop routing instead of a complete list of the stops the packet must make only the address of the next hop is listed in the routing table 9. What is Static and Dynamic Routing ? A static routing table’s entries are updated manually by an administrator. A dynamic routing table’s entries are updated automatically by a routing protocol. 10. What is the Maximum length of a Datagram? The maximum length of a datagram is 65,535 bytes. Result: Thus the program to simulate the behavior of ARP and RARP Protocols in JAVA is successfully executed. Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 31. Exp No. 07 a Date:…………… Study of Network simulator (NS) Aim: To study the NS2 Simulator Steps to install NS2 in centos 6 STEP 1 From terminal login as super user and do the following.(internet must also be connected in order to install the package dependencies. yum install autoconf yum install automake yum install gcc-c++ yum install libX11-devel yum install xorg-x11-proto-devel yum install libXt-devel And for nam installation (optional): yum install libXmu-devel STEP 2 From terminal go to the folder where the ns-allinone patch is placed and type the following to extract $ tar -xzf ns-allinone-2.35.tar.gz $ cd ns-allinone-2.35 $. /install STEP 3 Now go to /etc folder and type gedit ~/.bashrc # LD_LIBRARY_PATH OTCL_LIB=/your/path/ns-allinone-2.35/otcl-1.13 NS2_LIB=/your/path/ns-allinone-2.35/lib X11_LIB=/usr/X11R6/lib USR_LOCAL_LIB=/usr/local/lib export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$X11_LIB: $USR_LOCAL_LIB # TCL_LIBRARY TCL_LIB=/your/path/ns-allinone-2.35/tcl8.4.14/library USR_LIB=/usr/lib export TCL_LIBRARY=$TCL_LIB:$USR_LIB # PATH XGRAPH=/your/path/ns-allinone-2.35/bin:/your/path/ns-allinone-2.35/tcl8.4.14/unix:/your/path/ns- allinone-2.31/tk8.4.14/unix NS=/your/path/ns-allinone-2.35/ns-2.35/ Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 32. NAM=/your/path/ns-allinone-2.35/nam-1.13/ PATH=$PATH:$XGRAPH:$NS:$NAM Let it take effect immediately source ~/.bashrc Note: the step described above is important; otherwise, you cannot run ns successfully. or you can restart your X windows.i.e. logout and then login, or reboot your system, to make it work.) Now, the installation has been completed. If you try: $ ns Then a "%" will appear on the screen.type "exit" to quit the mode and back to "$" Network Simulator 2 (NS2) : Tools For Tcl Scripts In NS2 Tools for generating TCL Script for NS2 NS2 a very common and widely used tool to simulate small and large area networks. Tcl scripts are widely used in NS-2 simulation tool. Tcl scripts are used to set up a wired or wireless communication network, and then run these scripts via the NS-2 for getting the simulation results.Several tools are available to design networks and generate TCL scripts some of them are discussed below Trace Files Generated in NS2 NS2 currently supports a number of different types of trace files. In addition to its own format, NS2 also has the Nam trace format, which contains the necessary information from the simulation to drive the Nam visualizer. Both of these trace formats are very specific when it comes to giving details about the events that occur during an NS2 simulation. Traces and monitors represent the only support for data collection in ns-2. Traces record events related to the generation, enqueueing, forwarding, and dropping of packets. Each event corresponds to a line of ASCII characters, which contains information on the event type and the information stored into the packet NS-2 provides three kinds of formats for wired networks: Tracing, Monitoring and NAM trace file. I. Tracing: Trace file format is given below: Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 33. Operation performed in the simulation ● Simulation time of event occurrence ● Node 1 of what is being traced ● Node 2 of what is being traced ● Packet type ● Packet size ● Flags ● IP flow identifier ● Packet source node address ● Packet destination node address ● Sequence number ● Unique packet identifier Network Simulator 2 (NS2) : Monitoring & Examples For NS2 Monitoring Queue monitoring refers to the capability of tracking the dynamics of packets at a queue (or other object). A queue monitor tracks packet arrival/departure/drop statistics, and may optionally compute averages of these values. Monitoring was useful tools to find detail information about queue. Flow monitor trace format is given below: Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 34. III. NAM trace files which are used by NAM for visualization of ns simulations. The NAM trace file should contain topology information like nodes, links, queues, node connectivity etc as well as packet trace information. A NAM trace file has a basic format to it. Each line is a NAM event. The first character on the line defines the type of event and is followed by several flags to set options on that event. There are 2 sections in that file, static initial configuration events and animation events. All events with -t * in them are configuration events and should be at the beginning of the file. Example of NAM file is: 7. Advantages and Disadvantages of NS2 Advantages 1. Cheap- Does not require costly equipment 2. Complex scenarios can be easily tested. 3. Results can be quickly obtained-more ideas can be tested in a smaller time frame. 4. Supported protocols 5. Supported platforms 6. Modularity 7. Popular Disadvantages Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 35. 1. Real system too complex to model. i.e. complicated structure. 2. Bugs are unreliable Result: The foundations of NS2 are studied Exp No. 07 b Date:…………… Simulation of Congestion Control Algorithms using NS. Aim : To simulate the behavior of TCP congestion control using NS 2 Algorithm Step 1:Create a network simulator object ns to invoke simulation Step 2:Using an object open a file in write mode Step 3:Using the aforesaid object write all the trace output into the file Step 4:Using an object create a file to write all nam window output into it Step 5:Set color to represent each flow Step 6:Create 6 nodes Step 7: Create duplex-link from node 0 to node n2 of bandwidth 2Mb with delay 10ms using DropTail Queue Step 8: Create duplex-link from node 1 to node n2 of bandwidth 2Mb with delay 10ms using DropTail Queue Step 9:Create duplex-link from node 2 to node n3 of bandwidth 0.3Mb with delay 200ms using DropTail Queue Step 10:Create duplex-link from node 3 to node n4 of bandwidth 0.5Mb with delay 40ms using DropTail Queue Step 11:Create duplex-link from node 3 to node n5 of bandwidth 0.5Mb with delay 30ms using DropTail Queue Step 12:Attach tcp reno agents to node 0 as tcp1 Step 13:Attach tcp reno agents to node 1 as tcp2 Step 14:Attach tcp reno agents to node 2 as tcp3 Step 15:Attach tcp reno agents to node 1 as tcp4 Step 16:Set fid 1 for tcp 1 Step 17:Set fid 2 for tcp 2 Step 18:Set fid 3 for tcp 3 Step 19:Set fid 4 for tcp 4 Step 20:Attach sink agents to node 4, node 5, node 3 and node 4 Step 21:Establish the traffic between the source and sink Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 36. Step 22:Setup a FTP traffic generator on "tcp" Step 23:Attach ping agent to node 0 and node 4 ,connect it to calculate RTT Step 24:Create a method to call ping.cc file Step 25:Initiate the start and stop of the traffic profiles Step 26:Set the end of simulation at 80 th second Step 27:P lot the congestion window # cwnd_ used from tcp-reno.cc file Step 28:Call the finish procedure to execute the nam window file and congestion trace file Step 30:Run the simulation. Code: set ns [new Simulator] set f [ open congestion.tr w ] $ns trace-all $f set nf [ open congestion.nam w ] $ns namtrace-all $nf $ns color 1 Red $ns color 2 Blue $ns color 3 White $ns color 4 Green #to create nodes set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] set n4 [$ns node] set n5 [$ns node] # to create the link between the nodes with bandwidth, delay and queue $ns duplex-link $n0 $n2 2Mb 10ms DropTail $ns duplex-link $n1 $n2 2Mb 10ms DropTail $ns duplex-link $n2 $n3 0.3Mb 200ms DropTail $ns duplex-link $n3 $n4 0.5Mb 40ms DropTail $ns duplex-link $n3 $n5 0.5Mb 30ms DropTail # Sending node with agent as Reno Agent set tcp1 [new Agent/TCP/Reno] $ns attach-agent $n0 $tcp1 set tcp2 [new Agent/TCP/Reno] $ns attach-agent $n3 $sink3 set sink4 [new Agent/TCPSink] $ns attach-agent $n4 $sink4 # establish the traffic between the source and sink Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 37. $ns connect $tcp1 $sink1 $ns connect $tcp2 $sink2 $ns connect $tcp3 $sink3 $ns connect $tcp4 $sink4 # Setup a FTP traffic generator on "tcp" set ftp1 [new Application/FTP] $ftp1 attach-agent $tcp1 $ftp1 set type_ FTP set ftp2 [new Application/FTP] $ftp2 attach-agent $tcp2 $ftp2 set type_ FTP set ftp3 [new Application/FTP] $ftp3 attach-agent $tcp3 $ftp3 set type_ FTP set ftp4 [new Application/FTP] $ftp4 attach-agent $tcp4 $ftp4 set type_ FTP # RTT Calculation Using Ping ------------------------------------------------ set p0 [new Agent/Ping] $ns attach-agent $n0 $p0 set p1 [new Agent/Ping] $ns attach-agent $n4 $p1 # Method call from ping.cc file Agent/Ping instproc recv {from rtt} { $self instvar node_ puts "node [$node_ id] received ping answer from $from with round-trip-time $rtt ms." } # --------------------------------------------------------------------------- # start/stop the traffic $ns at 0.2 "$p0 send" $ns at 0.3 "$p1 send" $ns at 0.5 "$ftp1 start" $ns at 0.6 "$ftp2 start" $ns at 0.7 "$ftp3 start" $ns at 0.8 "$ftp4 start" # Set simulation end time $ns at 80.0 "finish" Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 38. # procedure to plot the congestion window # cwnd_ used from tcp-reno.cc file proc plotWindow {tcpSource outfile} { global ns set now [$ns now] set cwnd_ [$tcpSource set cwnd_] # the data is recorded in a file called congestion.xg. puts $outfile "$now $cwnd_" $ns at [expr $now+0.1] "plotWindow $tcpSource $outfile" } set outfile [open "congestion.xg" w] $ns at 0.0 "plotWindow $tcp1 $outfile" proc finish {} { exec nam congestion.nam & exec xgraph congestion.xg -geometry 300x300 & exit 0 } # Run simulation $ns run Sample Input and Output: Pre Viva Questions: 1. What is NS2 NS2 stands for Network Simulator Version 2. It is an open-source event-driven simulator designed specifically for research in computer communication networks. 2. What are the languages used by NS2 TCL and C++ 3. Why two languages are used in NS2 NS2 uses OTcl to create and configure a network, and uses C++ to run simulation. All C++ codes need to be compiled and linked to create an executable file. Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 39. 4. What is the purpose of C++ in ns2 ● When you are dealing with a packet, or - when you need to modify existing NS2 modules. ● This option perhaps discourages most of the beginners from using NS2. This book particularly aims at helping the readers understand the structure of NS2 and feel more comfortable in modifying NS2 modules. 5. What are the tools for generating TCL Script for NS2 ● NS2 scenario Generator (NSG): ● Visual Network Simulator (VNS): ● NS 2 Workbench ● Network Simulation by Mouse (NSBM) 6. What are the Advantages of NS2 Advantages ● Cheap- Does not require costly equipment ● Complex scenarios can be easily tested. ● Results can be quickly obtained-more ideas can be tested in a smaller time frame. ● Supported protocols ● Supported platforms ● Modularity ● Popular 7. What are the Disadvantages of NS2? ● Real system too complex to model. i.e. complicated structure. ● Bugs are unreliable Post Viva Questions 8. Define Congestion When too many packets rushing to a node or a part of network, the network performance degrades. This situation is called as congestion. 9. What is Open Loop Congestion Control Open loop congestion control policies are applied to prevent congestion before it happens. The congestion control is handled either by the source or the destination. Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 40. 10. Explain Retransmission Policy : It is the policy in which retransmission of the packets are taken care. If the sender feels that a sent packet is lost or corrupted, the packet needs to be retransmitted. This transmission may increase the congestion in the network. 11. Explain Window Policy : The type of window at the sender side may also affect the congestion. Several packets in the Go-back-n window are resent, although some packets may be received successfully at the receiver side. This duplication may increase the congestion in the network and making it worse. 12. Explain Discarding Policy : A good discarding policy adopted by the routers is that the routers may prevent congestion and at the same time partially discards the corrupted or less sensitive package and also able to maintain the quality of a message. In case of audio file transmission, routers can discard less sensitive packets to prevent congestion and also maintain the quality of the audio file. Result: Thus the program to simulate the behavior of TCP congestion control using NS 2 Exp No. 08 Date:…………… Study of TCP/UDP performance using Simulation tool. Aim: To study the performance of TCP UDP using NS2 Algorithm: Step 1:Create a network simulator object ns to invoke simulation Step 2:Using an object open a file in write mode Step 3:Using the a foresaid object write all the trace output into the file Step 4:Using an object create a file to write all nam window output into it Step 5:Set color to represent each flow Step 6:Create 4 nodes Step 7:Connect node 0 and node 2 with droptail Queue of 2 Mbps Step 8:Connect node 1 and node 2 with droptail Queue of 2 Mbps Step 9:Connect node 2 and node 3 with droptail Queue of 4 Mbps Step 10:Create a TCP agent and attach to node 0 and TCP sink to node 3 Step 11:Create a UDP agent and attach to node 1 and null agent to node 3 Step 12:Set fid 1 for tcp and fid 2 udp Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 41. Step 13:Invoke ftp agent to generate traffic of 1 mbps and attach to UDP agent Step 14:Invoke CBR agent to generate traffic of 1 mbps and attach to TCP agent Step 15:Invoke the data transmission process for TCP and UDP at 0.1 second Step 16:Run the simulation Step 17:Vary the bandwidth of the link and check the how TCP and UDP behaves in NAM window Code: #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 file set nf [open out.nam w] set f [ open congestion.tr w ] $ns trace-all $f $ns namtrace-all $nf #Define a 'finish' procedure proc finish {} { global ns nf $ns flush-trace #Close the NAM trace file close $nf #Execute NAM on the trace file exec nam out.nam & exit 0 } #Create four nodes set 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 4Mb 20ms DropTail #Set Queue Size of link (n2-n3) to 10 $ns queue-limit $n2 $n3 10 #Give node position (for NAM) Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 42. $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 #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 connection set ftp [new Application/FTP] $ftp attach-agent $tcp $ftp set type_ FTP $ftp set packet_size_ 1000 $ftp set rate_ 1mb $ftp set random_ false #Setup a UDP connection set udp [new Agent/UDP] $ns attach-agent $n1 $udp set 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 0.1 "$ftp start" $ns at 14.0 "$ftp stop" $ns at 14.5 "$cbr stop" #Call the finish procedure after 5 seconds of simulation time $ns at 15.0 "finish" #Print CBR packet size and interval Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 43. puts "CBR packet size = [$cbr set packet_size_]" puts "CBR interval = [$cbr set interval_]" #Run the simulation $ns run Output: PreViva Questions: 1. Which layer is responsible for Process-to-Process Delivery of a packet? Transport layer 2. What are the Fields on which the UDP Checksum is calculated? Why? UDP checksum includes a pseudo header, the UDP header and the data coming from the application layer. 3. What is TCP? TCP provides a connection oriented, reliable byte stream service. The connection oriented means the two applications using TCP must establish a TCP connection with each other before they can exchange data. 4. What are the Functions of Transport Layer? The Transport Layer is responsible for end-to-end data transport Primary functions include: ● Provision of connection oriented or connectionless service. ● Disassembling and reassembling data. ● Setup and release of connections across the network 5. What is Socket Address Process-to-process delivery needs two identifiers, IP address and the port number, at each end to make a connection. The combination of an IP address and a port number is called a socket address. Post Viva questions 6. State the Command in ns2 to print CBR packet size puts "CBR packet size = [$cbr set packet_size_]" Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 44. 7. State the Command in ns2 to print CBR interval puts "CBR interval = [$cbr set interval_]" 8. Which Command is used to run the tcl script $ns run 9. Why Null agent is used to Receive packets from UDP source. null agent will not send ack. 10. Which Agent is used in the receiver side to Receive TCP packets Sink agent 11. How to Define Different Colors for Data Flows (for NAM) $ns color 1 Blue //flow id 1 $ns color 2 Red //flow id 2 12. Write the Procedure to Stop the Simulation in ns2? $ns at 15.0 "finish" //15.0 refers the simulation time 13. Give an example to Connect Two Nodes with duplex channel of 2mbps bandwidth $ns duplex-link $n0 $n2 2Mb 10ms DropTail Result: Study of TCP/UDP performance is done using NS2 Exp No. 09A Date:…………… Simulation of Distance Vector Routing Aim: To simulate the behavior of Distance Vector Routing Algorithm: Step 1:Create a network simulator object ns to invoke simulation Step 2:Using an object open a file in write mode Step 3:Using the a foresaid object write all the trace output into the file Step 4:Using an object create a file to write all nam window output into it Step 5:Create 4 Nodes so that they are placed in a rectangular position Step 6:Create Duplex Links for each node of 10 mbps bandwidth and delay of 10 ms Step 7:Set one node as Source and attach TCP agent and FTP traffic generator Step 8:Set one node as Destination and attach TCP sink Step 9:Set routing protocol as Distance Vector Step 10:Make any two links down and up at different timings and see how the routing is happening in NAM window Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 45. Step 11:Run the Simulation Program: set ns [new Simulator] set nf [open out.nam w] $ns namtrace-all $nf set tr [open out.tr w] $ns trace-all $tr proc finish {} { global nf ns tr $ns flush-trace close $tr exec nam out.nam & exit 0 } set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] $ns duplex-link $n0 $n1 10Mb 10ms DropTail $ns duplex-link $n1 $n2 10Mb 10ms DropTail $ns duplex-link $n0 $n3 10Mb 10ms DropTail $ns duplex-link $n3 $n2 10Mb 10ms DropTail $ns duplex-link-op $n0 $n1 orient right $ns duplex-link-op $n1 $n2 orient down $ns duplex-link-op $n3 $n2 orient right $ns duplex-link-op $n0 $n3 orient down set tcp [new Agent/TCP] $ns attach-agent $n0 $tcp set ftp [new Application/FTP] $ftp attach-agent $tcp set sink [new Agent/TCPSink] $ns attach-agent $n2 $sink $ns connect $tcp $sink $tcp set fid_ 1 $ns rtmodel-at 5.0 down $n1 $n2 $ns rtmodel-at 10.0 up $n1 $n2 $ns rtmodel-at 12.0 down $n0 $n3 $ns rtproto DV Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 46. $ns at 1.0 "$ftp start" $ns at 15.0 "finish" $ns run Sample Input and Output: Result: Thus the simulation of Distance Vector Routing is carried out using NS2 Exp No. 9b Date:…………… Simulation of Link State Routing Aim: To simulate the behavior of Link State Routing Algorithm: Step 1:Create a network simulator object ns to invoke simulation Step 2:Using an object open a file in write mode Step 3:Using the a foresaid object write all the trace output into the file Step 4:Using an object create a file to write all nam window output into it Step 5:Create 4 Nodes so that they are placed in a rectangular position Step 6:Create Duplex Links for each node of 10 mbps bandwidth and delay of 10 ms Step 7:Set one node as Source and attach TCP agent and FTP traffic generator Step 8:Set one node as Destination and attach TCP sink Step 9:Set routing protocol as Link State Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 47. Step 10:Make any two links down and up at different timings and see how the routing is happening in NAM window Step 11:Run the Simulation Program: set ns [new Simulator] set nf [open out.nam w] $ns namtrace-all $nf set tr [open out.tr w] $ns trace-all $tr proc finish {} { global nf ns tr $ns flush-trace close $tr exec nam out.nam & exit 0 } set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] $ns duplex-link $n0 $n1 10Mb 10ms DropTail $ns duplex-link $n1 $n2 10Mb 10ms DropTail $ns duplex-link $n0 $n3 10Mb 10ms DropTail $ns duplex-link $n3 $n2 10Mb 10ms DropTail $ns duplex-link-op $n0 $n1 orient right $ns duplex-link-op $n1 $n2 orient down $ns duplex-link-op $n3 $n2 orient right $ns duplex-link-op $n0 $n3 orient down set tcp [new Agent/TCP] $ns attach-agent $n0 $tcp set ftp [new Application/FTP] $ftp attach-agent $tcp set sink [new Agent/TCPSink] $ns attach-agent $n2 $sink $ns connect $tcp $sink $tcp set fid_ 1 Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 48. $ns rtmodel-at 5.0 down $n1 $n2 $ns rtmodel-at 10.0 up $n1 $n2 $ns rtmodel-at 12.0 down $n0 $n3 $ns rtproto LS $ns at 1.0 "$ftp start" $ns at 15.0 "finish" $ns run Output Pre Viva Questions: 1. What is Routing? Routing is a process of selecting paths in a network through which network traffic is sent. 2. Advantages of Distance Vector Routing? It is simpler to configure and maintain than link state routing. 3. What are the features of link state routing protocols Link state packet – A small packet that contains routing information. Link state database – A collection information gathered from link state packet. Shortest path first algorithm (Dijkstra algorithm) – A calculation performed on the database results into shortest path Routing table – A list of known paths and interfaces. 4. What is Hop Count . Hop count is the number of routers occurring in between the source and destination network. 5. What are the Features of RIP 1. Updates of the network are exchanged periodically. 2. Updates (routing information) are always broadcast. 3. Full routing tables are sent in updates. 4. Routers always trust on routing information received from neighbor routers. This is also known as Routing on rumours. Post Viva Questions Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 49. 6. What is Static Routing? Static routing is a process in which we have to manually add routes in routing table 7. What are the Advantages of Static Routing? ● No routing overhead for router CPU which means a cheaper router can be used to do routing. ● It adds security because only administrator can allow routing to particular networks only. ● No bandwidth usage between routers. 8. What are the Features of Dynamic Routing? A dynamic protocol have following features: ● The routers should have the same dynamic protocol running in order to exchange routes. ● When a router finds a change in the topology then router advertises it to all other routers. 9. What are the Advantages of Dynamic Routing? ● Easy to configure. ● More effective at selecting the best route to a destination remote network and also for discovering remote network. 10. What are the Disadvantages of Dynamic Routing? ● Consumes more bandwidth for communicating with other neighbors. ● Less secure than static routing. ● Result: Thus the simulation of Link State Routing is carried out using NS2. Exp No. 10 Date:…………… Simulation of Error Correction Code Aim: To simulate the behavior of Error Correction Code in java Algorithm: Step 1:Get the input in the form of bits. Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 50. Step 2:Append zeros as redundancy bits . Step 3:Divide the appended data using a divisor polynomial. Step 4:The resulting data should be transmitted to the receiver. Step 5:At the receiver the received data is entered. Step 6:The same process is repeated at the receiver. Step 7:If the remainder is zero there is no error otherwise there is some error in the received bits Step 8:Run the program. Program: import java.util.Scanner; class CRC{ public static void main(String args[]){ Scanner sc = new Scanner(System.in); //Input Data Stream System.out.print("Enter data stream: "); String datastream = sc.nextLine(); System.out.print("Enter generator: "); String generator = sc.nextLine(); int data[] = new int[datastream.length() + generator.length() - 1]; int divisor[] = new int[generator.length()]; for(int i=0;i<datastream.length();i++) data[i] = Integer.parseInt(datastream.charAt(i)+""); for(int i=0;i<generator.length();i++) divisor[i] = Integer.parseInt(generator.charAt(i)+""); //Calculation of CRC for(int i=0;i<datastream.length();i++){ if(data[i]==1) for(int j=0;j<divisor.length;j++) data[i+j] ^= divisor[j]; } //Display CRC System.out.print("The CRC code is: "); for(int i=0;i<datastream.length();i++) data[i] = Integer.parseInt(datastream.charAt(i)+""); for(int i=0;i<data.length;i++) System.out.print(data[i]); System.out.println(); //Check for input CRC code System.out.print("Enter CRC code: "); datastream = sc.nextLine(); System.out.print("Enter generator: "); generator = sc.nextLine(); data = new int[datastream.length() + generator.length() - 1]; divisor = new int[generator.length()]; for(int i=0;i<datastream.length();i++) data[i] = Integer.parseInt(datastream.charAt(i)+""); for(int i=0;i<generator.length();i++) Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 51. divisor[i] = Integer.parseInt(generator.charAt(i)+""); //Calculation of remainder for(int i=0;i<datastream.length();i++){ if(data[i]==1) for(int j=0;j<divisor.length;j++) data[i+j] ^= divisor[j]; } //Display validity of data boolean valid = true; for(int i=0;i<data.length;i++) if(data[i]==1){ valid = false; break;} if(valid==true) System.out.println("Data stream is valid"); else System.out.println("Data stream is invalid. CRC error occured."); }} //https://darshangajara.com/2013/10/30/crc-java/ //https://www.tutorialspoint.com/what-is-algorithm-for-computing-the-crc Output: Enter data stream: 101010 Enter generator: 11111 The CRC code is: 1010101010 Enter CRC code: 1010100010 Enter generator: 11111 Data stream is invalid. CRC error occurred. Pre Viva Questions: 1. What are the Main Feature of Data Link Layer? The two main features of data kink layer are flow control and error control. 2. What is Flow Control Flow control coordinates that amount of data that can be sent before receiving ACK It is one of the most important duties of the data link layer. 3. What is Error Control Error control in the data link layer is based on ARQ (automatic repeat request), which is the retransmission of data. The term error control refers to methods of error detection and retransmission. 4. What is ARQ Anytime an error is detected in an exchange, specified frames are retransmitted. This process is called ARQ. 5. What is Stop and Wait ARQ The sending devise keeps the copy of the last frame transmitted until it receives an acknowledgement for that frame. Keeping a copy allows the sender to retransmit lost or damaged frames until they are received correctly. 6. Define Piggybacking Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 52. It’s a method to combine a data frame with an ACK. Post Viva Questions 7. What are the Types of HUB Types of Hub ● Active Hub:- These are the hubs which have their own power supply and can clean, boost and relay the signal along with the network. It serves both as a repeater as well as wiring centre. These are used to extend the maximum distance between nodes. ● Passive Hub :- These are the hubs which collect wiring from nodes and power supply from active hub. These hubs relay signals onto the network without cleaning and boosting them and can’t be used to extend the distance between nodes. 8. What is a Bridge Bridge – A bridge operates at data link layer. A bridge is a repeater, with add on the functionality of filtering content by reading the MAC addresses of source and destination. It is also used for interconnecting two LANs working on the same protocol. It has a single input and single output port, thus making it a 2 port device. 9. What is CRC CRC or Cyclic Redundancy Check is a method of detecting accidental changes/errors in the communication channel.CRC uses Generator Polynomial which is available on both sender and receiver side. 10. What is HDLC High-Level Data Link Control (HDLC) is a bit-oriented code-transparent synchronous data link layer protocol. HDLC provides both connection-oriented and connectionless service. Result: Thus the java program to simulate the behavior of Error Correction Code is executed successfully. ADDITIONAL EXPERIMENTS BEYOND THE SYLLABUS Exp No. 11 Date:…………… SIMULATION OF GO BACK N PROTOCOL Aim: Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 53. To Simulate and to study of Go Back N protocol. ALGORITHM FOR GO BACK N 1. The source node transmits the frames continuously. 2. Each frame in the buffer has a sequence number starting from 1 and increasing up to the window size. 3. The source node has a window i.e. a buffer to store the frames. This buffer size is the number of frames to be transmitted continuously. 4. The size of the window depends on the protocol designer. 5. For the first frame, the receiving node forms a positive acknowledgement if the frame is received without error. 6. If subsequent frames are received without error (up to window size) cumulative positive acknowledgement is formed. 7. If the subsequent frame is received with error, the cumulative acknowledgment error-free frames are transmitted. If in the same window two frames or more frames are received with error, the second and the subsequent error frames are neglected. Similarly even the frames received without error after the receipt of a frame with error are neglected. 8.The source node retransmits all frames of window from the first error frame. 9. If the frames are errorless in the next transmission and if the acknowledgment is error free, the window slides by the number of error-free frames being transmitted. 10. If the acknowledgment is transmitted with error, all the frames of window at source are retransmitted, and window doesn’t slide. 11. This concept of repeating the transmission from the first error frame in the window is called as GOBACKN transmission flow control protocol # PROGRAM FOR GOBACK N: #send packets one by one set ns [new Simulator] set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] set n4 [$ns node] Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 54. set n5 [$ns node] $n0 color "purple" $n1 color "purple" $n2 color "violet" $n3 color "violet" $n4 color "chocolate" $n5 color "chocolate" $n0 shape box ; $n1 shape box ; $n2 shape box ; $n3 shape box ; $n4 shape box ; $n5 shape box ; $ns at 0.0 "$n0 label SYS0" $ns at 0.0 "$n1 label SYS1" $ns at 0.0 "$n2 label SYS2" $ns at 0.0 "$n3 label SYS3" $ns at 0.0 "$n4 label SYS4" $ns at 0.0 "$n5 label SYS5" set nf [open goback.nam w] $ns namtrace-all $nf set f [open goback.tr w] $ns trace-all $f $ns duplex-link $n0 $n2 1Mb 20ms DropTail $ns duplex-link-op $n0 $n2 orient right-down $ns queue-limit $n0 $n2 5 $ns duplex-link $n1 $n2 1Mb 20ms DropTail $ns duplex-link-op $n1 $n2 orient right-up $ns duplex-link $n2 $n3 1Mb 20ms DropTail $ns duplex-link-op $n2 $n3 orient right $ns duplex-link $n3 $n4 1Mb 20ms DropTail $ns duplex-link-op $n3 $n4 orient right-up $ns duplex-link $n3 $n5 1Mb 20ms DropTail $ns duplex-link-op $n3 $n5 orient right-down Agent/TCP set_nam_tracevar_true set tcp [new Agent/TCP] $tcp set fid 1 $ns attach-agent $n1 $tcp set sink [new Agent/TCPSink] $ns attach-agent $n4 $sink $ns connect $tcp $sink set ftp [new Application/FTP] $ftp attach-agent $tcp $ns at 0.05 "$ftp start" $ns at 0.06 "$tcp set windowlnit 6" $ns at 0.06 "$tcp set maxcwnd 6" Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 55. $ns at 0.25 "$ns queue-limit $n3 $n4 0" $ns at 0.26 "$ns queue-limit $n3 $n4 10" $ns at 0.305 "$tcp set windowlnit 4" $ns at 0.305 "$tcp set maxcwnd 4" $ns at 0.368 "$ns detach-agent $n1 $tcp ; $ns detach-agent $n4 $sink" $ns at 1.5 "finish" $ns at 0.0 "$ns trace-annotate "Goback N end"" $ns at 0.05 "$ns trace-annotate "FTP starts at 0.01"" $ns at 0.06 "$ns trace-annotate "Send 6Packets from SYS1 to SYS4"" $ns at 0.26 "$ns trace-annotate "Error Occurs for 4th packet so not sent ack for the Packet"" $ns at 0.30 "$ns trace-annotate "Retransmit Packet_4 to 6"" $ns at 1.0 "$ns trace-annotate "FTP stops"" proc finish {} { global ns nf $ns flush-trace close $nf puts "filtering..." #exec tclsh../bin/namfilter.tcl goback.nam #puts "running nam..." exec nam goback.nam & exit 0 } $ns run OUTPUT: PreViva Questions: 1.What is Error Control mechnism? Ans:Error control in data link layer is the process of detecting and correcting data frames that have been corrupted or lost during transmission. 2.What is NS2? NS2 stands for Network Simulator Version 2. It is an open-source event-driven simulator designed specifically for research in computer communication networks. 3.What are the languages used by NS2 Prepared By: R.Rajavaishnavi, AP, Dept. of IT
  • 56. TCL and C++ 4. What is ARQ Anytime an error is detected in an exchange, specified frames are retransmitted. This process is called ARQ. 5. What is Stop and Wait ARQ The sending devise keeps the copy of the last frame transmitted until it receives an acknowledgement for that frame. Keeping a copy allows the sender to retransmit lost or damaged frames until they are received correctly. Post Viva Questions 6. What is a Bridge Bridge – A bridge operates at data link layer. A bridge is a repeater, with add on the functionality of filtering content by reading the MAC addresses of source and destination. It is also used for interconnecting two LANs working on the same protocol. It has a single input and single output port, thus making it a 2 port device. 7. What is CRC CRC or Cyclic Redundancy Check is a method of detecting accidental changes/errors in the communication channel.CRC uses Generator Polynomial which is available on both sender and receiver side. 8. What is HDLC High-Level Data Link Control (HDLC) is a bit-oriented code-transparent synchronous data link layer protocol. HDLC provides both connection-oriented and connectionless service. 9. Define Piggybacking It’s a method to combine a data frame with an ACK. Result: Thus the Go back N protocol in Ns2 is studied. Prepared By: R.Rajavaishnavi, AP, Dept. of IT