0% found this document useful (0 votes)
92 views108 pages

CN-LAB Manual (Proper)

The Computer Networks Lab Manual for the academic year 2023-2024 outlines a series of experiments focused on socket programming, IP address retrieval, and TCP communication. It includes detailed instructions for implementing various networking concepts using Java, along with algorithms and source code examples. The manual also features viva questions to assess understanding of key networking principles.

Uploaded by

merwinofficial24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views108 pages

CN-LAB Manual (Proper)

The Computer Networks Lab Manual for the academic year 2023-2024 outlines a series of experiments focused on socket programming, IP address retrieval, and TCP communication. It includes detailed instructions for implementing various networking concepts using Java, along with algorithms and source code examples. The manual also features viva questions to assess understanding of key networking principles.

Uploaded by

merwinofficial24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 108

Computer Networks Lab

Manual

Academic Year: 2018-19 EVEN SEM


COMPUTER NETWORKS LAB - [IT P61]

COMPUTER NETWORKS
LAB MANUAL

III YEAR
VI SEMESTER
ACADEMIC YEAR: 2023-2024

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


1
Computer Networks Lab
Manual

List of Experiments

Sl. Experiment
No
1 Study of Socket Programming
2 Finding The IP Address
TCP Sockets
3 TCP-One Way Communication
4 TCP-Two Way Communication
5 Date Time Server
6 Echo Command
7 File Transfer
UDP Communication
8 UDP-One Way Communication
9 UDP-Two Way Communication
10 UDP DNS Server/Client
Raw Socket Programming
11 Ping Command
12 Talk Command
Remote Invocations
Remote Method Invocation-
13
Factorial of a given number
14 Simple Calculator
15 Remote Command Execution
Using Simulators
16 Study of NS2
17 Simple Topology Creation using NS - 2
18 Performance comparison of MAC protocols
19 Distance Vector routing using NS2
20 Study of TCP/UDP performance.
Content Beyond the Syllabus
21 Implementation of Subnetting
22 socket for HTTP for web page upload and download
23 Implementing A Wireless Sensor Network
24 Simulate A Mobile Adhoc Network

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


2
Computer Networks Lab
Manual

EX.NO 1 STUDY OF SOCKET PROGRAMMING

AIM
To study the various methods of Socket programming.

IMPLEMENTATION OF SOCKET PROGRAMMING

Sockets provide the communication mechanism between two computers


using TCP. A client program creates a socket on its end of the communication
and attempts to connect that socket to a server.

When the connection is made, the server creates a socket object on its
end of the communication. The client and server can now communicate by
writing to and reading from the socket.

The java.net.Socket class represents a socket, and the


java.net.ServerSocket class provides a mechanism for the server program to
listen for clients and establish connections with them.

The following steps occur when establishing a TCP connection between


two computers using sockets:

 The server instantiates a ServerSocket object, denoting which port


number communication is to occur on.
 The server invokes the accept() method of the ServerSocket class. This
method waits until a client connects to the server on the given port.

 After the server is waiting, a client instantiates a Socket object, specifying


the server name and port number to connect to.

 The constructor of the Socket class attempts to connect the client to the
specified server and port number. If communication is established, the
client now has a Socket object capable of communicating with the server.

 On the server side, the accept() method returns a reference to a new


socket on the server that is connected to the client's socket.

After the connections are established, communication can occur using I/O
streams. Each socket has both an OutputStream and an InputStream. The

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


3
Computer Networks Lab
Manual

client's OutputStream is connected to the server's InputStream, and the client's


InputStream is connected to the server's OutputStream.

Socket Programming is implemented using the following two modules


1. Server.java 2. Client.java
These modules are used to establish a point to point communication
between two process using socket programming. The creation of socket can be
achieved by the constructors like ServerSocket(), Socket(), these processes
then communicate using readline and println().

TCP/IP PROTOCOL
TCP/IP Sockets are used to implement, reliable, bidirectional, persistent,
point to point stream-based connection between host on the internet. TCP/IP
provides end-to-end connectivity specifying how data should be formatted,
addressed, transmitted, routed and received at the destination.
There are two types of sockets available:1. ServerSocket and 2. Socket.
They connect to them on published ports when the ServerSocket created it will
register itself with the system as having an internet in client connection. A
server socket waits for requests to come in over the network. It performs some
operation based on that request, and then possibly returns a result to the
requester.

SERVERSOCKET CLASS:
The java.net.ServerSocket class is used by server applications to obtain a
port and listen for client requests
If the ServerSocket constructor does not throw an exception, it means
that your application has successfully bound to the specified port and is ready
for client requests.
When the ServerSocket invokes accept(), the method does not return
until a client connects. After a client does connect, the ServerSocket creates a
new Socket on an unspecified port and returns a reference to this new Socket.
A TCP connection now exists between the client and server, and
communication can begin.

CLIENT SOCKET
The creation of socket is done through the constructor of the class
socket. The creation of the socket objects implicates establishes a connection
between the client and the server. he java.net.Socket class represents the
socket that both the client and server use to communicate with each other. The

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


4
Computer Networks Lab
Manual

client obtains a Socket object by instantiating one, whereas the server obtains a
Socket object from the return value of the accept() method.

CONSTRUCTOR OF SERVERSOCKET
Methods Description

ServerSocket(int Port) Creates ServerSocket on the


specified port with a queue length of
50.
ServerSocket(int Port,int Maxqueue). Creates a ServerSocket on the
specified port with a maximum queue
length of maxqueue.
ServerSocket(int Port, int Creates a SeverSocket on the
Maxqueue,Inet Addres local Address) specified with a maximum queue
length of the maxqueue on a
multihost,local address specifies the
IP Address.
Socket(String hostname, int Port) Creates a Socket contain the local
host to the named host the port can
throw an unknown host exception or
an IOException.
Socket(InetAddress,IPAddress,int Creates a Socket using a preexisting
port) Inet Address object and a port can
throw an IOException.
The ServerSocket has one additional method called accept() which is a
blocking call that will wait for a client to initiate communication.

CONSTRUCTOR OF SOCKET
Methods Description
This method attempts to connect to
the specified server at the specified
public Socket(String host, int port) port. If this constructor does not
throws UnknownHostException throw an exception, the connection is
successful and the client is
connected to the server.
public Socket(InetAddress host, int This method is identical to the
port) throws IOException previous constructor, except that the

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


5
Computer Networks Lab
Manual

host is denoted by an InetAddress


object.
Connects to the specified host and
public Socket(String host, int port,
port, creating a socket on the local
InetAddress localAddress, int
host at the specified address and
localPort) throws IOException.
port.
This method is identical to the
public Socket(InetAddress host, int
previous constructor, except that the
port, InetAddress localAddress, int
host is denoted by an InetAddress
localPort) throws IOException.
object instead of a String
Creates an unconnected socket. Use
public Socket() the connect() method to connect this
socket to a server.

METHODS
The following I/O Streams related methods are also available in the socket.
Methods Description
InputStream getInput Stream() Return the InputStream associated
with the invoking socket.
OutputStream get outputstream() Return the output stream associated
with the invoking socket.
Void close Close both the inputstream and
outputstream.

INET ADDRESSING
Every computer on the internet has an address. An internet is a number
that uniquely identifies each computer on the net. There are 32bit in an IP
Address and we often refer to them has sequence of four number between 0
and 255 separated by the data. This makes them easier to remember because
they are not randomly assigned, they are hierarchically assigned. The first few
bits define which class of network lettered A, B, C, D or E. The address
represents internet or on a class C network since there are 2 million networks in
class C.

Methods Description
static InetAddress
Returns an InetAddress object
getByAddress(byte[] addr)
given the raw IP address .

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


6
Computer Networks Lab
Manual

Create an InetAddress based on


static InetAddress
the provided host name and IP
getByAddress(String host, byte[] addr)
address.
static InetAddress getByName(String Determines the IP address of a
host) host, given the host's name.
Returns the IP address string in
String getHostAddress()
textual presentation.
Gets the host name for this IP
String getHostName()
address.
static InetAddress InetAddress
Returns the local host.
getLocalHost()
Converts this IP address to a
String toString()
String.

RESULT: Thus the various methods of Socket Programming have been


studied.

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


7
Computer Networks Lab
Manual

VIVA QUESTIONS
1. What is a Socket?
Sockets are the fundamental technology for programming software to
communicate on TCP/IP networks. A socket provides a bidirectional
communication endpoint for sending and receiving data with another socket.

2. What is the difference between a socket and a port?


A socket is part of the interface the OS presents to applications to
allow them to send and receive network data.
A port is part of the address in the TCP and UDP protocols. It is used
to help the OS identify which application should get the data that is received.

3. What are the types of sockets available?


 Datagram sockets
 Stream sockets

4. Define client socket.


A client opens a socket by specifying the host address and port
number for the server of the socket. The host address gives the network
location (i.e., which computer) and the port selects a particular server from
all the possible servers that may be running on that host.

5. Define Server socket.


The server socket command creates a listening socket, and then new
sockets are created when clients make connections to the server.

6. Give the Server socket method


ServerSocket(int Port, int Maxqueue,Inet Addres local Address)

7. Give the Server socket method


Socket(InetAddress host, int port)

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


8
Computer Networks Lab
Manual

EX.NO 2 FINDING THE IP ADDRESS

AIM
To write a java program to find the IP address of the system.

ALGORITHM
Step 1: Start the program
Step 2: Create an object for the class InetAddress.
Step 3: The IP address of the system is retrieved using the method
getLocalHost().
Step 4: The system name is retrieved using the method getHostName().
Step 5: The IP address of other system can be retrieved using the
method getByName(),by passing the system name as
parameter.
Step 6: Stop the program.

SOURCE CODE
import java.io.*;
import java.net.*;
class address
{
public static void main (String args [])throws UnknownHostException
{
// To get local machine’s IP address
InetAddress ip=InetAddress.getLocalHost();
// Gets the local machine’s name
System.out.println("\n IP address is :"+ip);
String s1= ip.getHostName();
System.out.println("\n System name is:"+s1);
//To receive other machine’s name
ip=InetAddress.getByName("MITIT080");
System.out.println("\n Name of other system is :"+ip);
}
}

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


9
Computer Networks Lab
Manual

OUTPUT

RESULT

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


10
Computer Networks Lab
Manual

Thus the java program to find the IP address is executed and output is
verified successfully.

VIVA QUESTIONS
1. What is an IP address?
An Internet Protocol address (IP address) is a numerical label
assigned to each device (e.g., computer, printer) participating in a computer
network that uses the Internet Protocol for communication.

2. How many bits are used for IP address?


IP address uses a 32-bit number

3. How many bits does IPv4 and IP v6 have for IP address?


32 bits - Internet Protocol Version 4 (IPv4),
128 bits – IP v 6
4. Who manages IP address?
IANA- Internet Assigned Numbers Authority

5. What is the range of IP address?


IPv4 addresses are represented in dot-decimal notation, which
consists of four decimal numbers, each ranging from 0 to 255, separated by
dots, e.g., 172.16.254.1. Each part represents a group of 8 bits (octet) of the
address.

6. What are the different classes of IP address?


IP V4 has 5 different classes A,B,C,D,E

7. What is the purpose of each class?


Class A,B,C – used for unicasting
Class D - Multicast
Class E - Broadcast

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


11
Computer Networks Lab
Manual

EX.NO 3 TCP-ONE WAY COMMUNICATION

AIM
To write a java program to implement one way communication using TCP

ALGORITHM
SERVER
Step 1: Start the program.
Step 2: Import the necessary java.net package and other packages.
Step 3: Create objects for ServerSocket, Socket, DataInputStream and
PrintStream to transfer
the data.
Step 4: The readLine method reads the message .
Step 5: Using PrintStream transfer the data in OutputStream via a port.
Step 6: The data is transferred from server until an “end ” string occurs.
Step 7: If an “end ” is encountered, close the socket and exit the
program.
Step 8: Stop the program.
CLIENT
Step 1: Start the program.
Step 2: Import the necessary java.net package and other packages.
Step 3: Create objects for Socket and DataInputStream to receive the
server data.
Step 4: The getInputStream method gets the data from the socket.
Step 5: The readLine method reads the message received from server.
Step 6: The socket will close, when an end is encountered
Step 8: Stop the program.

SOURCE CODE
CLIENT
import java.io.*;
import java.net.*;
class TcpOneWayChatClient
{

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


12
Computer Networks Lab
Manual

public static void main(String args[]) throws IOException


{
// Establishes connection to the specified IP and Port Number
Socket sock=new Socket("localHost",8000);
String str;
// Receives the messages from the server
DataInputStream dis=new DataInputStream(sock.getInputStream());
System.out.println("Connection established successfully!");
System.out.println("Listening for server...");
while(true)
{
// Reads the input from server
str=dis.readLine();
System.out.println("Message Received:"+str);
if (str.equals("end"))
{
//Close the socket
sock.close();
break;
}
}
}
}
SOURCE CODE
SERVER
import java.io.*;
import java.net.*;
import java.util.*;
class TcpOneWayChatServer
{

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


13
Computer Networks Lab
Manual

public static void main(String a[])throws IOException


{
// Establishes connection to the specified IP and Port Number
ServerSocket servsock=new ServerSocket(8000);
// Opens the socket and binds the connection on the port number 8000
Socket sock=servsock.accept();
//DataInputStream dis=new DataInputStream(System.in);
Scanner s=new Scanner(System.in);
PrintStream ps=new PrintStream(sock.getOutputStream());
System.out.println("Connection established successfully!");
System.out.println("You can start sending messages now!");
System.out.println("Enter 'end' to quit");
while(true)
{
System.out.println("Enter message to send:");
// reads the input message string from the input device
String str=s.nextLine();
ps.println(str);
//checks for end of message
if(str.equals("end"))
{
//Closes the socket
servsock.close();
break;
}
}
}
}
OUTPUT :
SERVER

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


14
Computer Networks Lab
Manual

CLIENT

RESULT
Thus the TCP one way communication program is executed and output is
verified successfully.

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


15
Computer Networks Lab
Manual

VIVA QUESTIONS

1. Expand TCP.
Transmission Control Protocol
2. What is TCP one way communication mean?
It is the process of transmitting data either from a server or a client in one
direction. i.e only the sender will transmit data.
3. In which layer does TCP exist?
In the transport layer
4. What form of communication does TCP represent?
Stream communication
5. What is the purpose of a readline method?
The readline method reads the user input

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


16
Computer Networks Lab
Manual

EX.NO 4 TCP-TWO WAY COMMUNICATION

AIM
To write a java program to implement two way communication using TCP

ALGORITHM
SERVER
Step 1: Start the Program.
Step 2: Import java.net package and other packages.
Step 3: Create objects for ServerSocket, Socket and PrintStream to
transfer message from server.
Step 4: Create object for DataInputStream to receive the client data.
Step 5: The readLine method reads the message entered by the server
Step 6: The PrintStream class transfers the data through the
OutputStream via a port.
Step 7: Using if statement , message is transmitted until an “end” string is
transferred.
Step 8: Using another if statement, message is received until an “end”
string is found
Step 9: Close the socket and Stop the program.
CLIENT
Step 1: Start the Program.
Step 2: Import java.net package and other packages.
Step 3: Create object for Socket to connect to the specified port.
Step 4: Create object for DataInputStream and PrintStream to send and
receive message.
Step 5: The readLine method reads the message received from the server
Step 6: Using if statement, message is received until an “end” string is
found
Step 7: Using another if statement , message is transmitted until an “end”
string is entered
Step 8: Close the socket and Stop the program

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


17
Computer Networks Lab
Manual

SOURCE CODE

CLIENT

import java.io.*;
import java.net.*;
import java.lang.*;
class TcpTwoWayChatClient
{
public static void main(String args[])throws IOException
{
String str, str1;
// Creates object for socket
//Establishes connection to the specified IP and Port Number
Socket sock=new Socket("LocalHost",8000);
//Receives the data from the socket
DataInputStream mydis=new DataInputStream(sock.getInputStream());
//Reads the message from the keyboard
Scanner s=new Scanner (System.in);
//Transmits data to the socket
PrintStream ps =new PrintStream(sock.getOutputStream());
System.out.println("Connection established successfully!");
System.out.println("You can start chat now!");
System.out.println("Enter 'end' to quit from chat");
System.out.println("Listening for server...");
while(true)
{
//Reads the message received from the server
str=mydis.readLine();
System.out.println("Msg received at Server::"+str);
//Checks for end of message
if(str.equals("end"))
{
//Closes the socket
sock.close();
break;
}
System.out.println("Enter the msg to send: ");
//Reads the message to be sent

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


18
Computer Networks Lab
Manual

str1=s.nextLine();
ps.println(str1);
//Checks for end of message
if(str1.equals("end"))
{
//Closes the socket
sock.close();
break;
}
}
}
}

SERVER

import java.io.*;
import java.net.*;
import java.lang.*;
import java.util.*;
class TcpTwoWayChatServer
{
public static void main(String a[])throws IOException
{
String str, str1;
//Creates the server socket for the specified port
ServerSocket servsock=new ServerSocket(8000);
//Opens the socket and binds the connection
Socket sock=servsock.accept();
//Transmits data to the socket
PrintStream ps=new PrintStream(sock.getOutputStream());
//To read the data
Scanner s=new Scanner(System.in);
//Receives the data from the socket
DataInputStream mydis=new DataInputStream(sock.getInputStream());
System.out.println("Connection established successfully!");
System.out.println("You can start chat now!");
System.out.println("Enter 'end' to quit from chat");
while(true)
{
System.out.println("Server:");

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


19
Computer Networks Lab
Manual

//Reads the message to be sent


str=s.nextLine();
ps.println(str);
//Checks for end of message
if(str.equals("end"))
{
//Closes the socket
servsock.close();
break;
}
str1=mydis.readLine();
System.out.println("Client:"+str1);
if(str1.equals("end"))
{
servsock.close();
break;
}
}
}
}
OUTPUT:
SERVER

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


20
Computer Networks Lab
Manual

CLIENT

RESULT
Thus the java program for TCP two way communication is executed and
output is verified successfully

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


21
Computer Networks Lab
Manual

VIVA QUESTIONS

1. What does TCP two way communication mean?


It is the process where both the client and server can exchange
messages i.e send and reply
2. What is the purpose of a println statement?
Println method transmits the data through the socket
3. In which layer does TCP exist?
In the transport layer
4. Can you give few instances where tcp is used?
TCP is suited for applications that require high reliability, and
transmission time is relatively less critical. Udp 1 way and 2 way
5. Give Examples for TCP
HTTP, HTTPs, FTP, SMTP, Telnet
6. Applications of TCP
Web browsing, email and file transfer are common applications that
make use of TCP

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


22
Computer Networks Lab
Manual

EX.NO 5 DATE TIME SERVER USING TCP

AIM:-
To write a java program to implement Date and Time Server using TCP.

Code for Program of date server and client in Java


// Date Client

import java.io.*;
import java.net.*;

class DateClient
{
public static void main(String args[]) throws Exception
{
Socket soc=new Socket(InetAddress.getLocalHost(),5217);
BufferedReader in=new BufferedReader( new InputStreamReader(
soc.getInputStream() ) );
System.out.println(in.readLine());
}
}

// Date Server

import java.net.*;
import java.io.*;
import java.util.*;
class DateServer
{
public static void main(String args[]) throws Exception
{
ServerSocket s=new ServerSocket(5217);
while(true)
{
System.out.println("Waiting For Connection ...");
Socket soc=s.accept();

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


23
Computer Networks Lab
Manual

DataOutputStream out=new
DataOutputStream(soc.getOutputStream());
out.writeBytes("Server Date" + (new Date()).toString() + "\n");
out.close();
soc.close();
}

}
}
OUTPUT:-

RESULT:-

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


24
Computer Networks Lab
Manual

Thus Date and Time sever program using TCP is executed and output is
verified.

EX. NO 6 ECHO COMMAND

AIM
To write a program in java to demonstrate the ECHO command.

ALGORITHM
ECHO SERVER
1. Start the program.
2. Import java.net and other necessary packages.
3. In a try block, create objects for Socket, ServerSocket, BufferedReader
and PrintStream
4. GetInputstream and GetOutputstream methods are used to receive
and send message.
5. Store the message in a string and display the message
6. Send the same received message to the client using println.

ECHO CLIENT
1. Start the program.
2. Import java.net and other necessary packages.
3. Create an object for Inetaddress to get localhost IP address.
4. Create object for the socket class and establish connection in the port
number 9000.
5. Create objects for Printstream and bufferedreader.
6. GetInputstream and getoutputstream methods are used to receive and
send message.
7. Get the user input and store it in a string.
8. Pass the message to the server through the socket using println
method.
9. The readline method reads the echo message from the server.
10. The received message is displayed.

SOURCE CODE

ECHO SERVER

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


25
Computer Networks Lab
Manual

import java.net.*;
import java.io.*;
public class EchoServer
{
public static void main(String args[])
{
String line;
try
{
ServerSocket sersoc = new ServerSocket(9000);
Socket soc = sersoc.accept();
BufferedReader br = new BufferedReader(new
InputStreamReader(soc.getInputStream()));
PrintStream ps = new PrintStream(soc.getOutputStream());
while(true)
{
line = br.readLine();
System.out.println("Received from Client: " + line);
ps.println(line);
}
}
catch(IOException e)
{
System.out.println(e);
}
}
}

ECHO CLIENT

import java.net.*;
import java.io.*;
import java.util.*;
public class EchoClient
{
public static void main(String arg[])
{
String line;
try

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


26
Computer Networks Lab
Manual

{
InetAddress ip = InetAddress.getLocalHost();
Socket soc = new Socket(ip,9000);
PrintStream ps = new PrintStream(soc.getOutputStream());
Scanner s=new Scanner(System.in);
BufferedReader br = new BufferedReader(new
InputStreamReader(soc.getInputStream()));
while(true)
{
System.out.print("Client: ");
line = s.nextLine();
ps.println(line);
System.out.println("Echo from Server: " + br.readLine());
}
}
catch(IOException e)
{
System.out.println(e);
}
}
}

OUTPUT:

SERVER

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


27
Computer Networks Lab
Manual

CLIENT

RESULT

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


28
Computer Networks Lab
Manual

Thus the java program to demonstrate the ECHO command has been
executed and verified successfully.

VIVA QUESTIONS

1.Define ECHO command


Echo is a term used to describe when data is sent to a computer or
other network device, and that information is sent back to verify the
information was received.
2. Give example where ECHO is used.
Terminals may perform echo for a connection.
3. Give the types of Echo
Local Echo, Remote Echo
4. What is Local Echo?
Local echo is where the sending device itself displays the sent data
5. What is Remote Echo?
Remote echo, where the receiving device returns the sent data that it
receives to the sender

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


29
Computer Networks Lab
Manual

EX. NO 7 FILE TRANSFER USING TCP (FTP)

AIM
To write a program in java to perform file transfer using TCP.

ALGORITHM
SERVER
1. Start the program.
2. Import java.net and other necessary packages.
3. Create objects for ServerSocket and Socket to send the packet
from server.
4. Using BufferedReader get the input file from client.
5. Check whether the received file name exist
6. If the file exist, read the file and send it to client.
7. Else, print file does not exist.
8. Stop the program.

CLIENT
1. Start the program.
2. Import java.net and other necessary Packages.
3. Create objects for Socket and BufferedReader .
4. Get the user input as text file name
5. Send the file name to the server through the println method
6. Using Readline method, read the contents of the file until a null is
encountered.
7. Print the received message.
8. Stop the program.

PROGRAM

CLIENT:
import java.io.*;
import java.net.*;
import java.util.*;
public class FileClient
{
public static void main(String args[])throws IOException

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


30
Computer Networks Lab
Manual

{
try
{
Socket soc = new Socket(InetAddress.getLocalHost(), 1187);
BufferedReader br = new BufferedReader(new
InputStreamReader(soc.getInputStream()));
PrintStream ps = new PrintStream(soc.getOutputStream());
Scanner s=new Scanner(System.in);
String input;
System.out.println("Enter the text file name");
String fileName = s.nextLine();
ps.println(fileName);
while((input = br.readLine()) != null)
{
System.out.println(input);
}
System.out.println("The file is Received successfully");
soc.close();
}
catch(Exception e)
{
System.out.println("Error: " + e);
}
}
}

SERVER :
import java.io.*;
import java.net.*;
public class FileServer
{
public static void main(String args[])throws IOException
{
try
{
ServerSocket sersoc = new ServerSocket(1187);
Socket soc = sersoc.accept();
BufferedReader br = new BufferedReader(new
InputStreamReader(soc.getInputStream()));
PrintStream ps = new PrintStream(soc.getOutputStream());

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


31
Computer Networks Lab
Manual

String fileName = br.readLine();


File f = new File(fileName);
if(f.exists())
{
BufferedReader fbf = new BufferedReader(new
FileReader(fileName));
String line;
while((line = fbf.readLine()) != null)
{
ps.println(line);
ps.flush();
}
System.out.println("The File Send successfully");
}
else
{
System.out.println("File not exists");
}
soc.close();
}
catch(IOException e)
{
System.out.println("Error: " + e);
}
}
}
OUTPUT:
SERVER

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


32
Computer Networks Lab
Manual

CLIENT

RESULT

Thus the java program for talk command is executed and verified
successfully.

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


33
Computer Networks Lab
Manual

VIVA QUESTIONS
1. Define FTProgram.
The FTP (file transfer program) utility is used to transfer files
between a local machine and remote network machine using the File
Transfer protocol.
2. In which operating systems does FTP works.
Files can be transferred between unix systems and also non-unix
systems like windows operating system using FTP.
3. Expand FTP.
File Transfer Protocol.
4. What is the port number used by FTP.
Port number 21 is used by FTP protocol.
5. What is the role of FTP.
The File Transfer Protocol (FTP) is used to connect to remote
computers, list shared files, and either upload or download files between
local and remote computers.
6. What are the advantages of FTP?
FTP runs over TCP, which provides a connection-oriented, guaranteed
data-delivery service. FTP is a character-based command interface,
although many FTP applications have graphical interfaces.

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


34
Computer Networks Lab
Manual

EX.NO 8 UDP-ONE WAY COMMUNICATION

AIM
To write a program in java to perform one way message transfer using
the User Datagram Protocol (UDP).

ALGORITHM
SERVER
1. Start the program.
2. Import java.net and other necessary packages.
3. Create objects for DatagramSocket and DatagramPacket to send the
packet from server.
4. Create an object for the class byte.
5. Get user input data and convert it into bytes and send the bytes using
DatagramPacket and DatagramSocket.
6. Get user input in a loop and send data until the user input sends “end”.
7. If end is encountered, exit sending data.
8. Stop the program.

CLIENT
1. Start the program.
1. Import java.net and other necessary Packages.
2. Create objects for DatagramSocket and Datagrampacket to receive the
packet data from server.
3. Create an object for byte class.
4. Receive the data from sender using receive() method and store it to a
string.
5. Receive method receives the data from the server
6. Run a loop and store the data in the string until the received message
is “end”.
7. Print the received message.
8. Stop the program.

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


35
Computer Networks Lab
Manual

PROGRAM
CLIENT:
import java.io.*;
import java.net.*;
class UdpOneWayChatClient
{
public static void main(String args[])throws Exception
{
DatagramSocket ds = new DatagramSocket(8000);
DatagramPacket dp;
byte buff[] = new byte[1024];
String str;
while(true)
{
dp = new DatagramPacket(buff, buff.length);
ds.receive(dp);
str = new String (dp.getData(),0, dp.getLength());
System.out.println("Server: " + str);
}
}
}
SERVER :
import java.io.*;
import java.net.*;
import java.util.*;
class UdpOneWayChatServer
{
public static void main(String args[ ])throws IOException
{
DatagramSocket ds = new DatagramSocket();
DatagramPacket dp;
byte buff[] = new byte[1024];
String str;
Scanner s=new Scanner(System.in);
while(true)
{
System.out.print("Server:");
str = s.nextLine();
buff = str.getBytes();

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


36
Computer Networks Lab
Manual

dp = new DatagramPacket(buff, buff.length,


InetAddress.getLocalHost(), 8000);
ds.send(dp);
}
}
}
OUTPUT:
SERVER

CLIENT

RESULT:
Thus the java program to perform one way message transfer using the
User Datagram Protocol (UDP).

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


37
Computer Networks Lab
Manual

EX.NO 9 UDP-TWO WAY COMMUNICATION

AIM
To write a java program to perform two way message transfer using the
user datagram protocol(UDP).
ALGORITHM
SERVER
1. Start the program.
2. Import java.net and other necessary packages.
3. Create objects for DatagramSocket and DatagramPacket to receive
packet data from client.
4. Create an object for InetAddress of the LocalHost.
5. Receive the client data using receive() method and store it in a string.
6. Run a loop and store the data in the string until the received message
is “end”.
7. Print the received client’s message.
8. Get user input in the same loop and send the data until the user input
is “end”.
9. Convert the user input into bytes and send the byte using
DatagramPacket and DatagramSocket.
10. If end is encountered, exit the sending data to client.
11. Stop the program.

CLIENT
1. Start the program.
2. Import java.net and other necessary packages.
3. Create objects for DatagramSocket and DatagramPacket to receive
packet data from server.
4. Create an object for InetAddress of the LocalHost.
5. Receive the server data using receive() method and store it in a string.
6. Run a loop and store the data in the string until the received message
is “end”.
7. Print the received server’s message.
8. Get user input in the same loop and send data until the user input is
end.

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


38
Computer Networks Lab
Manual

9. Convert the user input into bytes and send the byte using
DatagramPacket and DatagramSocket.
10. If end is encountered, exit sending data to server.
11. Stop the program.

SOURCE CODE
SERVER
import java.io.*;
import java.net.*;
import java.util.*;
class UdpTwoWayChatServer
{
public static void main(String a[])throws Exception
{
//Creates an object for Datagram socket
DatagramSocket ds = new DatagramSocket();
DatagramPacket dp, dp1;
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
Scanner s=new Scanner(System.in);
String msg, msg1;
byte sendbuff[] = new byte[1024];
while(true)
{
System.out.print("Server: ");
msg = s.nextLine();
//converts message into bytes
sendbuff = msg.getBytes();
dp = new DatagramPacket(sendbuff, sendbuff.length,
InetAddress.getLocalHost(), 8000);
//send method sends data
ds.send(dp);
byte recbuff[] = new byte[1024];
dp1 = new DatagramPacket(recbuff, recbuff.length);
//receive method receives data
ds.receive(dp1);
msg1 = new String (dp1.getData(), 0, dp1.getLength());
System.out.println("Client:" + msg1);
}

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


39
Computer Networks Lab
Manual

}
}

CLIENT

import java.io.*;
import java.net.*;
import java.lang.*;
import java.util.*;
class UdpTwoWayChatClient
{
public static void main(String a[])throws IOException
{
//Creates an object for Datagram socket
DatagramSocket ds=new DatagramSocket(8000);
DatagramPacket dp, dp1;
Scanner s=new Scanner(System.in);
byte b[] = new byte[1024];
String msg, msg1;
while(true)
{
dp = new DatagramPacket(b, b.length);
ds.receive(dp);
msg = new String (dp.getData(), 0, dp.getLength());
System.out.println("Server: " + msg);
System.out.print("Client: ");
msg1 = s.nextLine();
byte b1[] = msg1.getBytes();
dp1 = new DatagramPacket(b1, b1.length, dp.getAddress(),
dp.getPort());
ds.send(dp1);
}
}
}

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


40
Computer Networks Lab
Manual

OUTPUT:
SERVER

CLIENT

RESULT

Thus the java program to perform two way message transfer using the
User Datagram Protocol (UDP).

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


41
Computer Networks Lab
Manual

EX NO: 10 UDP DNS SERVER/CLIENT

AIM:
To implement a DNS server and client in java using UDP sockets.

ALGORITHM:

1. Create a datagram socket


2. Get domain name from user
3. Create a datagram packet and send domain name to the server
4. Create a datagram packet to receive server message
5. Read server's response
6. If ip address then display it else display "Domain does not exist"
7. Close the client socket
8. Stop

Program

import java.net.*;
public class Dns
{
public static void main(String args[]) throws UnknownHostException
{
InetAddress ipAddress = InetAddress.getLocalHost();
System.out.println(ipAddress);
ipAddress = InetAddress.getByName("www.google.com");
System.out.println(ipAddress);
ipAddress = InetAddress.getByName("www.mvit.edu.in");
System.out.println(ipAddress);
}
}

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


42
Computer Networks Lab
Manual

OUTPUT:

RESULT
Thus domain name requests by the client are resolved into their respective
logical address using lookup method.

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


43
Computer Networks Lab
Manual

VIVA QUESTIONS
1. Expand UDP
User Datagram Protocol
2. What is the difference between TCP and UDP?
TCP is connection oriented – once a connection is established, data
can be sent bidirectional.
UDP is a simpler, connectionless Internet protocol. Multiple messages
are sent as packets in chunks using UDP.
3. What form of communication does UDP represent ?
Datagram communication
4. Can you give few instances where UDP is used?
UDP is suitable for applications that need fast, efficient transmission,
such as games. UDP's stateless nature is also useful for servers that answer
small queries from huge numbers of clients.
5. Give Examples for UDP
DNS, DHCP, TFTP, SNMP, RIP, VOIP.
6. What are the applications of UDP?
UDP is commonly used in Domain Name System, Voice over IP, Trivial
File Transfer Protocol and online games.

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


44
Computer Networks Lab
Manual

EX.NO 11 PING COMMAND

AIM
To write a program in java to demonstrate the usage of PING command.

ALGORITHM
PINGSERVER
1.Start the program.
2. Import java.net and other necessary packages.
3. In a try block, create objects for server and client sockets .
4. Inputstream and Outputstream methods , gets data and transmits data to
the client
5. The for loop limits the number of times the server is pinged by the client.
6. If an exception occurs , the control is transferred to the catch block.
PINGCLIENT
1. Start the program.
2. Import java.net and other necessary packages.
3. Create the necessary socket
4. In a try block, get the user input as ip address
5. Inputstream and Outputstream methods ,gets data from the server and
transmits data to the server
6. If a connection exists with the server ,then a msg is displayed as
“Pinging”
7. Within a for loop, sleep method is used for 2000 ms to wait for a reply
from server.
8. If receiver is pinged, then a reply message is received within the
specified time .
9. Else, Request timed out message occurs
10. Socket is closed

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


45
Computer Networks Lab
Manual

SOURCE CODE

PING SERVER
import java.io.*;
import java.net.*;
public class PingServer
{
public static void main(String a[]) throws IOException
{
String line1, line2;
int i;
System.out.println("Ping Server");
try
{
ServerSocket sersoc = new ServerSocket(9999);
Socket soc = sersoc.accept();
BufferedReader br = new BufferedReader(new
InputStreamReader(soc.getInputStream()));
PrintStream ps = new PrintStream(soc.getOutputStream());
for(i = 0; i < 4; i++)
{
line1 = br.readLine();
System.out.println("Pinged by client");
ps.println(line1 + " reply from host:bytes=3<time<1ms TT<=128");
}
}
catch(Exception e)
{
System.out.println("Error: " + e);
}
}
}
PING CLIENT

import java.lang.System;
import java.io.*;
import java.net.*;
public class PingClient
{
public static void main(String args[])

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


46
Computer Networks Lab
Manual

{
int i, j;
String remoteIP;
try
{
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter the IP address: ");
String ip = br.readLine();
Socket soc = new Socket(ip, 9999);
BufferedReader mybr = new BufferedReader(new
InputStreamReader(soc.getInputStream()));
PrintStream ps = new PrintStream(soc.getOutputStream());
System.out.println("Pinging " + ip + " with 32 bytes of data");
for (i = 0; i < 4; i++)
{
ps.println(ip);
ps.flush();
remoteIP = mybr.readLine();
if (remoteIP != null)
{
Thread.sleep(2000);
System.out.println("Reply from " + remoteIP);
}
else
{
for (i = 0; i < 4; i++)
{
Thread.sleep(2000);
System.out.println("Request time out");
}
}
}
soc.close();
ps.close();
}
catch (IOException e)
{
System.out.println("Error: " + e);
}

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


47
Computer Networks Lab
Manual

catch(InterruptedException e)
{
System.out.println(e);
}
}
}
OUTPUT:
SERVER

CLIENT

RESULT

Thus the java program to execute ping command is verified


successfully.

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


48
Computer Networks Lab
Manual

VIVA QUESTIONS
1. What is the Ping Command?
The ping command is a Command Prompt command used to test the
ability of the source computer to reach a specified destination computer. The
ping command is usually used as a simple way verify that a computer can
communicate over the network with another computer or network device.

2. What is the functionality of a Ping command?


The ping command operates by sending Internet Control Message
Protocol (ICMP) Echo Request messages to the destination computer and
waiting for a response. How many of those responses are returned, and how
long it takes for them to return, are the two major pieces of information that
the ping command provides.

3. Give a few commands related to Ping .


The ping command is often used with other networking related
Command Prompt commands like tracert, ipconfig, netstat etc

4. Give examples for Ping command

Ping 192.168.1.22
Ping www.google.com

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


49
Computer Networks Lab
Manual

EX.NO 12 TALK COMMAND

AIM
To write a program in java to demonstrate the use of TALK command.

ALGORITHM
SERVER
1. Start the program.
2. Create server and client sockets.
3. Use input streams to get the message from user.
4. Use output stream to send message to the client.
5. Using while loop ,send the message to the client and also receive
message using println.
6. Stop the program.

CLIENT
1. Start the program.
2. Create a client socket that connects to the required host and port.
3. Input streams read message given by server and print it.
4. Output streams to write message to the server.
5. Using while loop , send the message to the server and also receive
message using println.
6. Stop the program.

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


50
Computer Networks Lab
Manual

SOURCE CODE
TALK SERVER
import java.io.*;
import java.net.*;
public class TalkServer
{
public static void main (String args[]) throws Exception
{
ServerSocket sersoc = new ServerSocket(9999);
Socket soc = sersoc.accept();
BufferedReader socbf = new BufferedReader(new
InputStreamReader(soc.getInputStream()));
PrintStream ps = new PrintStream(soc.getOutputStream());
BufferedReader bf = new BufferedReader(new
InputStreamReader(System.in));
String line1, line2;
while(true)
{
line1 = socbf.readLine();
System.out.println("Message Received: " + line1);
line2 = bf.readLine();
ps.println(line2);
ps.flush();
}
}
}

TALK CLIENT

import java.io.*;
import java.net.*;
public class TalkClient
{
public static void main(String args[])
{
String line1;
try
{
Socket soc = new Socket("LocalHost", 9999);

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


51
Computer Networks Lab
Manual

BufferedReader socbf = new BufferedReader(new


InputStreamReader(soc.getInputStream()));
PrintWriter pw = new PrintWriter(soc.getOutputStream());
BufferedReader bf = new BufferedReader(new
InputStreamReader(System.in));
while(true)
{
line1 = bf.readLine();
pw.println(line1);
pw.flush();
System.out.println("Message received: " + socbf.readLine());
}
}
catch(IOException e)
{
System.err.println(e);
}
}
}

OUTPUT:
TALK SERVER

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


52
Computer Networks Lab
Manual

TALK CLIENT

RESULT :
Thus the java program for talk command is executed and verified
successfully.

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


53
Computer Networks Lab
Manual

EX.NO 13 REMOTE METHOD INVOCATIONS (RMI)

AIM
To write a program in java to illustrate Remote Method Invocation.

ALGORITHM
1. Start the program.
2. Establish the connection between the client and the server to calculate
the factorial operation.
3. In the interface file, the fact method is declared.
4. In the implementation file, the fact() is defined ,which performs the
actual factorial operation.
5. In the server, the try block calls the implementation file which
indicates that the server is ready for execution.
6. In the client ,URL or the name of the host has been specified and
declared as string.
7. User input is also obtained in the client end.
8. The client program also calls the fact() in the implement() file .
9. The result is displayed
Note:
1.Create four files interface,implementation,server and client in separate
notepads.
2. During exection, compile the interface and implementations first and then the
server and client.
3.After compiling the server, start the rmiregistry .

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


54
Computer Networks Lab
Manual

SOURCE CODE

INTERFACE
import java.rmi.*;
import java.rmi.server.*;
public interface FactInterface extends Remote
{
public int fact (int n) throws RemoteException;
}

IMPLEMENTATION
import java.rmi.*;
import java.rmi.server.*;

public class FactImplementation extends UnicastRemoteObject implements


FactInterface
{
public FactImplementation() throws RemoteException
{
}
public int fact(int n) throws RemoteException
{
int f = 1;
for(int i = 1; i <= n; i++)
{
f = f * i;
}
return f;
}

SERVER
import java.rmi.*;
import java.net.*;
// start rmiregistry (in command prompt)
public class RmiServer
{
public static void main(String args[]) throws RemoteException
{
try
{

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


55
Computer Networks Lab
Manual

FactImplementation fi = new FactImplementation();


Naming.rebind("server", fi);
System.out.println("Server ready");
}
catch(Exception e)
{
System.out.println("Exception:" + e);
}
}
}
CLIENT
import java.rmi.*;
import java.io.*;
public class RmiClient
{
public static void main(String args[]) throws RemoteException
{
try
{
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));

System.out.println("Enter the server name or ip address");


String url = br.readLine();

String host="rmi://" + url + "/server";


FactInterface serv = (FactInterface) Naming.lookup(host);

System.out.println("Enter a number:");
int n = Integer.parseInt(br.readLine());

int fact = serv.fact(n);


System.out.println("Factorial of " + n + " is " + fact);
}
catch(Exception e)
{
System.out.println("Error " + e);
}
}
}

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


56
Computer Networks Lab
Manual

OUTPUT
SERVER

CLIENT

RESULT
Thus the java program is executed and output is verified successfully.

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


57
Computer Networks Lab
Manual

EX NO: 14 PROGRAMS USING RPC / RMI SIMPLE CALCULATOR

AIM:
To implement simple calculator on a remote host and invoke operations
from a client.

ALGORITHM:

Interface:
Declare server's remote interface for all calculator operation by extending
Remote interface

Implementation:
Define basic calculator operations such as summation, difference,
product, quotient and
remainder by extending UnicastRemoteObject.

Server:
1. Create a calculator object
2. Register the object with the RMI registry on the server machine using rebind
method

Client
1. Obtain operands from the user
2. Lookup for the Calculator service on the remote server
3. Call all arithmetic operations on the remote server
4. Display result of various arithmetic operations.

Procedure
1. Compile the four java files (Interface, Implementation, Server and Client)
2. Generate stub by compiling the implementation file using RMI compiler
3. Distribute the class files of Client, Interface and Stub to the clients
4. Start the RMI registry on the server
5. Start the server
6. Call procedures that exist on the remote host from client machine.

PROGRAM:
// Declares remote method interfaces--CalcInf.java
import java.rmi.*;
public interface CalcInf extends Remote

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


58
Computer Networks Lab
Manual

{
public long add(int a, int b) throws RemoteException;
public int sub(int a, int b) throws RemoteException;
public long mul(int a, int b) throws RemoteException;
public int div(int a, int b) throws RemoteException;
public int rem(int a, int b) throws RemoteException;
}

// Implement Remote behavior--CalcImpl.java


import java.rmi.*;
import java.rmi.server.*;
public class CalcImpl extends UnicastRemoteObject implements CalcInf
{
public CalcImpl() throws RemoteException { }
public long add(int a, int b) throws RemoteException
{
return a + b;
}
public int sub(int a, int b) throws RemoteException
{
int c = a > b ? a - b : b - a;
return c;
}
public long mul(int a, int b) throws RemoteException
{
return a * b;
}
public int div(int a, int b) throws RemoteException
{
return a / b;
}
public int rem(int a, int b) throws RemoteException
{
return a % b;
}
}

// Server that names the service implemented--CalcServer.java


import java.rmi.*;
public class CalcServer

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


59
Computer Networks Lab
Manual

{
public static void main(String args[])
{
try
{
CalcInf C = new CalcImpl();
Naming.rebind("CalcService", C);
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
}
// Client that invokes remote host methods--CalcClient.java
import java.rmi.*;
import java.net.*;
public class CalcClient
{
public static void main(String[] args) throws Exception
{
try
{
CalcInf C = (CalcInf) Naming.lookup("rmi://" +
args[0] + "/CalcService");
int a, b;

if (args.length != 3)
{
System.out.println("Usage: java CalcClient
<remoteip><operand1><operand2>");
System.exit(-1);
}
a = Integer.parseInt(args[1]);
b = Integer.parseInt(args[2]);
System.out.println( "\nBasic Remote Calc\n" );
System.out.println("Summation : " + C.add(a, b));
System.out.println("Difference : " + C.sub(a, b));
System.out.println("Product : " + C.mul(a, b));
System.out.println("Quotient : " + C.div(a, b));

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


60
Computer Networks Lab
Manual

System.out.println("Remainder : " + C.rem(a, b));


}
catch (Exception E)
{
System.out.println(E.getMessage());
}
}
}

OUTPUT
Server
C:\>javac CalcInf.java
C:\>javac CalcImpl.java
C:\>javac CalcServer.java
C:\>javac CalcClient.java
C:\>rmic CalcImpl
C:\>start rmiregistry
C:\>java CalcServer

Client
C:\>java CalcClient 172.16.6.45 6 8
Basic Remote Calc
Summation : 14
Difference : 2
Product : 48
Quotient : 0

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


61
Computer Networks Lab
Manual

Remainder : 6

RESULT
Thus remote procedure calls for basic operations of a calculator is executed
using Java RMI.

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


62
Computer Networks Lab
Manual

VIVA QUESTIONS
1. Define RMI.

The Java Remote Method Invocation (RMI) system allows an object


running in one Java Virtual Machine (VM) to invoke methods on an object
running in another Java VM. RMI provides for remote communication
between programs written in the Java programming language.
2. Difference between RMI and RPC.
RPC- Invokes functions through a proxy.
RMI – invokes methods through a proxy. RMI is the object oriented
equivalent to RPC (Remote procedure call).

3. Expand RMI and RPC.


RMI – Remote Method Invocation
RPC – Remote Procedure Call

4. Differentiate Stub and Skeleton.


Stub program appears in the client side and helps the client
communicate with the server.
Skeleton appears on the server end and provides the required service to
the client.
CLIENT --> STUB --> ... Network ... --> SKELETON --> REMOTE
OBJECT

5. Define Rmiregistry.
Remote objects are listed in the rmiregistry. Clients will get a reference
to the remote object by querying the rmiregistry. After that, the client can
call methods on the remote objects. The rmiregistry is a separate process
that has to be started before remote objects can be added to it

6. Expand RCE.
RCE – Remote Command Execution

7. Define RCE.
RCE is a command that enables certain commands to be xecuted from
a remote system. Eg: Notepad ,calculator can be accessed from a
remote system.

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


63
Computer Networks Lab
Manual

EXPT. NO 15 REMOTE COMMAND EXECUTION

AIM
To perform remote command execution (ie) command entered by the user
at the client should be executed by the server.

ALGORITHM

SERVER
1. Start the program.
2. Create server and client socket.
3. Create a runtime object using get Runtime() method.
4. Create a process object p.
5. Read the command entered by the user at the client using input
streams.
6. Execute the command using the exec ().
7. Stop the program.
CLIENT
1. Start the program.
2. Create a client socket corresponding to the required server and port.
3. Promote the user to enter the command.
4. Read the command using input streams.
5. Write the command to the server using output streams.
6. Close the streams and socket.
7. Stop the program.

PROGRAM
CLIENT:
import java.io.*;
import java.net.*;
public class RCEclient
{
public static void main(String a[])throws UnknownHostException,IOException
{
Socket c = new Socket("localhost",1000);
System.out.println("Enter cmd:");
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


64
Computer Networks Lab
Manual

String s = br.readLine();
PrintStream ps = new PrintStream(c.getOutputStream());
ps.println(s);
}
}
SERVER :
import java.io.*;
import java.net.*;
import java.lang.*;
class RCEserver
{
public static void main(String a[])throws IOException,
UnknownHostException, InterruptedException
{
ServerSocket ss = new ServerSocket(1000);
Socket cs = ss.accept();
Runtime r = Runtime.getRuntime();
Process p = null;
BufferedReader br = new BufferedReader(new
InputStreamReader(cs.getInputStream()));
String s = br.readLine();
System.out.println(s);
p = r.exec(s);
}
}
OUTPUT
SERVER

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


65
Computer Networks Lab
Manual

CLIENT

RESULT
Thus the java program to execute RCE is verified successfully.

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


66
Computer Networks Lab
Manual

EX.NO:16 STUDY OF NS2


AIM
To study and implement the NS2 using network simulation.
HISTORY BEHIND NS
The goal of vint project, collaborative projects between USC/IS, LBL/UC
Berkley and Xerox pakc, is to extend the ns simulator so that network research
that can study the complex interaction between protocols in complex topologies
and with a rich set of traffic generates the primary components of simulation
and scheduler connection oriented and connectionless protocols, trace
supporting routing, topology generation, multicast support and queue
management.
THE EVENT DRIVEN NETWORK STIMULATOR NS
NS is an event driver network stimulator developed at UC Berkely that
stimulates variety of IP network.web CBR,VBR routes queue management
mechanism such as drop tail, RED and CBQ, routing algorithm such as Dijkstra
and more.
NS also implements multitasking and some of the MAC layer protocol for
LAN simulations. Currently ,NS written in C++ and OTCL is available.

OTCL:TCL interpreter with Simulation


------
------
Result
------
--- OO extension NS simulation library Q
OTCL script
Analysis
Simulation (*)event schedule object
Program (*)network component object
(*)network setup helping.
THE OBJECT ORIENTED TCL SCRIPT INTERPRETER
In a simplified user’s view, is object oriented TOL script interpreter. That
has a simulation event scheduler and network components object libraries and
network setup module libraries.

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


67
Computer Networks Lab
Manual

C++ AND OTCL: THE DUALITY


The following figure shows an object hierarchy example in C++ and OTCL
one thing to note in the figure is linkage forming a hierarchy there is a matching
OTCL object hierarchy very similar.
TAKING USE OF TCL
For configuration setup and “One time” stuff. Manipulating existing C++
object for performing thing required.
NETWORK ARCHITECTURE
a) This network consist of 4 nodes(n0,n1,n2,n3)
b) The duplex links between n0 and n2, n1 & n3 have 2mpbs of bandwidth
and 10ms of delay.
c) The duplex link between n2 and n3 has 1.7mbps bandwidth and 20ms of
delay.
d) Each node uses a drop tail queue of which the maximum size is 10.
e) “TCP” agent is attached to n0, and a connection is established to a top
“sink” age attached to n3.
f) As default, the maximum size of a packet that a “TCP” agent can
generate is 1kb.
g) A TCP “sink” agent generates and sends ACK packets to sender and free
received packets.
TWO NODE ONE LINE
To transmit data from one node to another first node should be
constructed and a link is established for transmitting data between links.

SENDING DATA
Once the nodes are constructed we can have process of transmitting from
node 0 to node 1.
0

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


68
Computer Networks Lab
Manual

VIEWING WITH AN X GRAPH


When we run the simulation on x graph window the required should open
and the output files are created used with gunplot.
MULTICASTING ROUTING
B
A

D C

Configuration Group A Group B


Nodes {A,B,D} {B,D,Css}

NS2 SIMULATION CODE WITH EXAMPLES


Size-aware scheduling consists of two parts: packet classification
and packet differentiation. Therefore, corresponding modules (size-aware
classifier and corresponding AQM schemes like RIO-PS) need to be
installed. Step-by-step instructions can be found here. When all the
modules have been installed, we now see an illustrative scenario in which
flows of size 5 packets or below being identified as short flows, and enjoy
high priorities in packet delivery. Figure 1depicts the simulation topology.

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


69
Computer Networks Lab
Manual

Figure 1: Simulation Topology

In this simple example, there are two parallel TCP sessions sharing a single bottleneck link
between node 1 and node 2 (of capacity 700kb).
# Create a dumbbell topology
$ns duplex-link $s(0) $n(0) 1Mb 5ms DropTail
$ns duplex-link $s(1) $n(0) 1Mb 5ms DropTail

$ns duplex-link $n(0) $n(1) 1Mb 20ms


RED/myRIO
$ns duplex-link $n(1) $n(2) 700Kb 25ms
RED/myRIO

$ns duplex-link $n(2) $r(0) 1Mb 5ms DropTail


$ns duplex-link $n(2) $r(1) 1Mb 5ms DropTail

One of the sessions runs from node 3 to node 5, periodically


transmitting 1000 packets. Therefore, all flows in this session are long
according to our definition. On the contrary, in the session fro m node 4 to
node 6, only 4 packets are transmitted in each flow. The simulation script is shown below:

# Create sessions
proc build-fore-tcp { idx size intv stime } {
global ns ftcp fsink
set ftcp($idx) [new Agent/TCP/Newreno]
set fsink($idx) [new Agent/TCPSink]
$ns at $stime "start-conn 1 $idx $intv $size"
}

proc start-conn { firsttime idx intv size } {


global ns ftcp fsink s r
set now [$ns now]
if { $firsttime == 0 } {
$ns detach-agent $s([expr $idx%2]) $ftcp($idx)
$ns detach-agent $r([expr $idx%2]) $fsink($idx)
$ftcp($idx) reset
$fsink($idx) reset
}
$ns attach-agent $s([expr $idx%2]) $ftcp($idx)

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


70
Computer Networks Lab
Manual

$ns attach-agent $r([expr $idx%2]) $fsink($idx)


$ns connect $ftcp($idx) $fsink($idx)
$ftcp($idx) set fid_ 0
$ftcp($idx) proc done {} "close-conn $idx $intv $size"
$ftcp($idx) advanceby $size
}
proc close-conn { idx intv size } {
global ns
set now [$ns now]
$ns at [expr $now + $intv] "start-conn 0 $idx $intv $size"
puts "at $now + $intv start next"
}
set forel_intv 1
set fores_intv 0.05
set ssize 4
set lsize 1000
build-fore-tcp 1 $ssize 1 0.1
build-fore-tcp 0 $lsize $forel_intv 0.5
for {set i 0} {$i < 5} { incr i} {
build-fore-tcp [expr 2*$i+3] $ssize $fores_intv [expr 1.2+$i*0.1]
}

Node 0 is the "size-aware classifier", which counts the incoming


packets from each flow. Once the count exceeds a certain threshold (in
this case 5), the remaining packets from the corresponding flow are
identified as long flow packets. In the simulation, long flow packets are
colored in blue. All the other packets, i.e., packets from flows of size less
than 5, and the first 5 packets from a long flow, are all identified as short
flow packets, and colored in red in the simulation.
To upload a size-aware classifier with threshold set to 5 to node 0, do the following:
# Load a size-aware classifier to node 0

set cls [new Classifier/Hash/SizeAware


128]
$cls set default_ -1
$cls set flowlen_thr_ 5
$cls set refresh_intv_ 2
$cls set dynamic_update_ 0

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


71
Computer Networks Lab
Manual

set n(0) [node_with_classifier $cls]

As a result, all packets between node 4 and node 6 are colored in red:

Figure 2: Packets from short flows.

For flows of size bigger than 5, the first 5 packets are colored in red, and
the remaining packets are colored in blue:

Figure 3: Packets from long flows.


At the bottleneck link (link between node 1 and node 2), a differentiated

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


72
Computer Networks Lab
Manual

dropping scheme is employed. This is achieved by:


$ns duplex-link $n(1) $n(2) 700Kb 25ms
RED/myRIO
$ns duplex-link-op $n(1) $n(2) orient right

Queue/RED/myRIO set gentle_ true


Queue/RED/myRIO set thresh_ 1
Queue/RED/myRIO set maxthresh_ 15
Queue/RED/myRIO set weight_ 10
Queue/RED/myRIO set setbit_ false

set redq [[$ns link $n(1) $n(2)] queue]


$redq set q_weight_ [expr 1.0/2]
$redq set linterm_ [expr 4.0]
$ns queue-limit $n(1) $n(0) 30

Notice that to obtain a more drastic effect of size-aware differentiation, we


choose a relatively high ratio between long and short flow packet dropping
rate (weight_ is set to 10).

When congestion happens, low priority packets are dropped at a faster


rate (on average 10 times faster) than that for high priority packets. This is
illustrated in Figure 4:

Figure 4: More blue packets are dropped than red packets

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


73
Computer Networks Lab
Manual

As a result, high priority flows, or short flows, are transmitted at a rate


higher than that of low priority flows, or long flows, as TCP flows are
responsive to packet drops. That is the basic scheme of our size-aware
scheduling. Figure 5 shows packets generated from the two sessions,
after some packets are dropped:

Figure 5: Red packets are generated faster than blue packets.

#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 source file
set nf [open out.nam w]
$ns namtrace-all $nf
#define ‘Finish’ procedure.
Proc finish {
global ns OF
$ ns flush-trace
close $ns #(close the event scheduler object.)
exec nam out nam & #(execute NAM file using this

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


74
Computer Networks Lab
Manual

command.)
exit 0
}
#create four nodes
set n0 [$ns node]
set n1 [$ns node]
set n3 [$ns node]
set n4 [$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 2mb 10ms Droptail
#set queue – limit size of link (n2-n3) to 10
$ns queue–limit $n2 $n3 10
#Give node position (for NAM)
$ns duplex – link –op $n2 orient right-down
$ns duplex – link – op $n1 orient right-up
$ns duplex – link – op $n2 $n3 orient right
#Monitor the queue for link (n2-n3) (for NAM)
$ns duplex-link-op $n2 $n3 queue-pos 0.5
#Setup a TCP connection.
set tcp [new Agent/TCP]
$tcp set class 2
$ns attach-agent $n0 $tcp
set sink [ new Agent/TCP sink]
$ ns attach-agent $n3 $sink
$ ns connect $tcp $sink
#Setup a FTP over TCP connection
set ftp [new Application / FTP]
$ftp attach-agent $tcp
#Setup a FTP connection for particular time period.
$ns at <time> “$ftp start” # (start the FTP traffic generation)
$ns at <time> “$ftp stop” # (stop the FTP traffic generation)

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


75
Computer Networks Lab
Manual

Running NS2
A OTcl script is generally composed as follows:
􀂾 Create a new simulator object
􀂾 Turn on tracing
􀂾 Create network (physical layer)
􀂾 Create link and queue (data-link layer)
􀂾 Define routing protocol
􀂾 Create transport connection (transport layer)
􀂾 Create traffic (application layer)
􀂾 Insert errors
The overall simulation procedure in the NS is shown below. NS is composed of
OTcl (Object-oriented Tool Command Language) Script and Interpreter. NS
simulation results can be observed through graphs by analyzing the trace file or
viewing animations with NAM.

After successful installation, path setting and validation, execute NS2 programs.
$ ns filename.tcl

RESULT

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


76
Computer Networks Lab
Manual

Thus the NS2 simulator experiment is studied.


Ex.No: 17 SIMPLE TOPOLOGY CREATION USING NS - 2

AIM: To create simple topology using Network Simulator – 2.

ALGORITHM:
Step 1: Start network simulator OTCL editor.
Step 2: Create new simulator using set ns [new Simulator] syntax
Step 3: Create Trace route to Network Animator set nf [open out.nam w] $ns namtrace-all
$nf
Step 4: Create procedure to trace all path
proc create_testnet {}
{
global s1 s2 r1 k1
set s1 [$ns node]
set s2 [$ns node]
set r1 [$ns node]
set k1 [$ns node]
}
Step 5: Create full duplex connection using
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms RED
$ns duplex-link $n2 $n3 1.7Mb 20ms RED
$ns duplex-link $n4 $n5 2Mb 10ms RED
$ns duplex-link $n2 $n8 2Mb 10ms RED
$ns duplex-link $n4 $n10 2Mb 5ms DropTail
Step 4: #Define a 'finish' procedure
Step 5: Run and Execute the program.
$ns run

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


77
Computer Networks Lab
Manual

PROGRAM:
#Create a simulator object
set ns [new Simulator]
#Open the NAM trace file
set nf [open o.nam w]
$ns namtrace-all $nf
# 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]
set n7 [$ns node]
set n8 [$ns node]
set n10 [$ns node]
#Create links between the nodes
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms RED
$ns duplex-link $n2 $n3 1.7Mb 20ms RED
$ns duplex-link $n4 $n5 2Mb 10ms RED
$ns duplex-link $n2 $n8 2Mb 10ms RED
$ns duplex-link $n4 $n10 2Mb 5ms DropTail
#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 o.nam &
exit 0
}
#Call the finish procedure
$ns at 1.0 "finish"
#Run the simulation
$ns run

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


78
Computer Networks Lab
Manual

OUTPUT:

RESULT: Thus the implemented simple topology using NS-2

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


79
Computer Networks Lab
Manual

\
Ex.No: 18 PERFORMANCE COMPARISONS OF MAC PROTOCOLS

AIM: To compare various MAC Protocols performance using NS-2

ALGORITHM:

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


80
Computer Networks Lab
Manual

PROGRAM:
#Create a simulator object
set ns [new Simulator]
#Define different colors for data flows (for NAM)
$ns color 1 Blue
$ns color 2 Red
#Open the NAM trace file
set nf [open out.nam w]
$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 1.7Mb 20ms DropTail
#Set Queue Size of link (n2-n3) to 10
$ns queue-limit $n2 $n3 10

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


81
Computer Networks Lab
Manual

#Give node position (for NAM)


$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right
#Monitor the queue for link (n2-n3). (for NAM)
$ns duplex-link-op $n2 $n3 queuePos 0.5
#Setup a TCP connection
set tcp [new Agent/TCP]
$tcp set class_ 2
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n3 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
#Setup a FTP over TCP connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
#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

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


82
Computer Networks Lab
Manual

$cbr set random_ false


#Schedule events for the CBR and FTP agents
$ns at 0.1 "$cbr start"
$ns at 1.0 "$ftp start"
$ns at 4.0 "$ftp stop"
$ns at 4.5 "$cbr stop"
#Detach tcp and sink agents (not really necessary)
$ns at 4.5 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink"
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"
#Print CBR packet size and interval
puts "CBR packet size = [$cbr set packet_size_]"
puts "CBR interval = [$cbr set interval_]"
#Run the simulation
$ns run
OUTPUT:

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


83
Computer Networks Lab
Manual

RESULT: Thus the MAC Protocols performance compared by using NS-2 and output verified by
using Network Animator.

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


84
Computer Networks Lab
Manual

EX NO: 19 Distance Vector Routing Protocol

Aim:
To write a program to show the distance Vector Routing algorithm using NS 2

Algorithm:
1. Start the program
2. Create a simulator object
3. Use distance vector routing
4. Open the nam trace file
5. Define 'finish' procedure
6. Close the trace file
7. Execute nam on the trace file
8. Create 8 nodes
9. Specify link characteristics
10. specify layout as a octagon
11. Create a UDP agent and attach it to node n1
12. Create a CBR traffic source and attach it to udp0
13. Create a Null agent (a traffic sink) and attach it to node n4
14. Connect the traffic source with the traffic sink
15. Schedule events for the CBR agent and the network dynamics
16. Call the finish procedure after 5 seconds of simulation time
17. Run the simulation
18. Stop the program

Program

#Distance vector routing protocol – distvect.tcl


#Create a simulator object
set ns [new Simulator]
#Use distance vector routing
$ns rtproto DV
#Open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
# Open tracefile
set nt [open trace.tr w]
$ns trace-all $nt
#Define 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
#Close the trace file
close $nf

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


85
Computer Networks Lab
Manual

#Execute nam on the trace file


exec nam -a out.nam &
exit 0
}
# Create 8 nodes
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
set n6 [$ns node]
set n7 [$ns node]
set n8 [$ns node]
# Specify link characterestics
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns duplex-link $n2 $n3 1Mb 10ms DropTail
$ns duplex-link $n3 $n4 1Mb 10ms DropTail
$ns duplex-link $n4 $n5 1Mb 10ms DropTail
$ns duplex-link $n5 $n6 1Mb 10ms DropTail
$ns duplex-link $n6 $n7 1Mb 10ms DropTail
$ns duplex-link $n7 $n8 1Mb 10ms DropTail
$ns duplex-link $n8 $n1 1Mb 10ms DropTail
# specify layout as a octagon
$ns duplex-link-op $n1 $n2 orient left-up
$ns duplex-link-op $n2 $n3 orient up
$ns duplex-link-op $n3 $n4 orient right-up
$ns duplex-link-op $n4 $n5 orient right
$ns duplex-link-op $n5 $n6 orient right-down
$ns duplex-link-op $n6 $n7 orient down
$ns duplex-link-op $n7 $n8 orient left-down
$ns duplex-link-op $n8 $n1 orient left
#Create a UDP agent and attach it to node n1
set udp0 [new Agent/UDP]
$ns attach-agent $n1 $udp0
#Create a CBR traffic source and attach it to udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
#Create a Null agent (a traffic sink) and attach it to node n4
set null0 [new Agent/Null]
$ns attach-agent $n4 $null0
#Connect the traffic source with the traffic sink
$ns connect $udp0 $null0
#Schedule events for the CBR agent and the network dynamics
$ns at 0.0 "$n1 label Source"

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


86
Computer Networks Lab
Manual

$ns at 0.0 "$n4 label Destination"


$ns at 0.5 "$cbr0 start"
$ns rtmodel-at 1.0 down $n3 $n4
$ns rtmodel-at 2.0 up $n3 $n4
$ns at 4.5 "$cbr0 stop"
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"
#Run the simulation
$ns run

Output
$ ns distvect.tcl

RESULT
Thus implemented the program of distance Vector Routing algorithm using NS 2

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


87
Computer Networks Lab
Manual

Viva Voce:

1. What Is Simulation?

Simulation is the imitation of some real thing, state of affairs or process.


In health professions education, simulation is a methodology to help
achieve educational goals. Healthcare simulation encompasses a range of
activities that share a broad but common purpose: To improve the safety,
effectiveness and efficiency of healthcare services.

2. What are the four files on the NS2 simulator?


The four files include the .tcl file, the .awk file, the .tr file and the nam file.

3. What is the use of a tr file?


The tr file is mainly used to analyse our data.It is given as input to nam file.

4. What does $1,$2,..... indicate in the awk file?


The $1, $2,.... indicate the columns that represent different events in the
ex3.tr file.

5. How do we increase the throughput?


The throughput is increased by decreasing the bandwidth.

6. Write the keys for understanding the distance vector routing?


The three keys for understanding the algorithm are,
 Knowledge about the whole networks
 Routing only to neighbors
 Information sharing at regular intervals
What are the protocols in application layer ?
The protocols defined in application layer are
 TELNET
 FTP
 SMTP
 SMTP

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


88
Computer Networks Lab
Manual

Ex.No: 20 Study of TCP/UDP performance.


AIM
To study the various methods of Socket programming.

INTRODUCTION:

Wireless communication technology is making immense progress and has


become widely popular for access networks over past few years. These
wireless access networks, such as Wireless Local Area Networks and cellular
networks are usually connected to a wired backbone network. Although TCP
and UDP are considered very reliable in wired networks and a lot of researches
have been done on their behavior in wireless networks, there performance in
hybrid networks is a matter of concern. Hybrid network has characteristics very
different from those of wired networks and wireless networks Although many
researches have been done to measure and analyze the TCP and UDP traffic
over wireless networks or MANET but there was no comparison done for the
hybrid networks with Mobile IP. NS2 is used as the simulation tool and studied
various parameters in the hybrid environment to evaluate the behavior of two
different transport layer protocols with Mobile IP being used as the protocol
between two different networks.

TCP
TCP Transport layer is made for process to process delivery, it deliver
packets from one process to another. Transmission Control Protocol (TCP) is a
connection oriented point-to-point protocol. It creates a virtual connection
between two TCPs to send data. It also uses flow and error control mechanism
at transport level. It is extensively used in the Internet.
UDP
User Datagram Protocol (UDP) is used as a transport layer protocol for
transfer of data across Internet Protocol based network. The protocol uses
datagrams to deliver the data. UDP is different in many ways with TCP. As TCP
is connection oriented protocol where it set up a connection first then transfer
data and terminate the connection, but in UDP there is no connection
establishment between sender and receiver. The messages are broken into
datagrams and send across the network. Each packet act as an individual
message and is handled separately. Since each datagram has to keep more
information than a TCP packet, the size of data it can carry is considerably low
as compared to TCP. All the datagrams can follow any path to reach to the

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


89
Computer Networks Lab
Manual

destination and hence the order in which they reach is not fixed. Neither the
sender sends any acknowledgement to the sender that the datagram is
received. Hence this protocol is considered as unreliable as it does not
guarantee that the whole data reached to the destination or not. While these
were some demerits with UDP yet it is used in various applications where some
data loss is tolerable like multimedia. Since in UDP there is no
acknowledgement service hence the network has lower overhead and hence a
better throughput and thus is faster than TCP which is suitable for the
applications like multimedia.
Performance of TCP
Bandwidth Limitation
Wireless wide area networks offer limited raw bit rates which have to be
shared between several users whereas wireless LAN offers sufficient bandwidth
Longer Latency Delay
Wireless media exhibit longer latency delays than wired ones, this affects
TCP throughput and increases the interactive delays perceived by the user.
Vulnerable Transmission Losses
Transmission losses are more in wireless media, so there is a need to find
a solution which aims at alleviating this deficiency.
User mobility
Wireless networks enable the user to move around. hosts. When a host is
moving from one cell to another handoff (or must be followed. During a handoff,
all necessary information must be transferred between the two base stations so
that the mobile host can continue to be connected. TCP exhibits Limited
bandwidth and longer latency delay in wireless networks and transmission
errors are also more in wireless media, also when there are mobile nodes, the
user mobility is a bigger concern. So there it would be beneficial to study the
TCP behavior in a hybrid network rather than in wireless network or wired
network as both have its pros and cons.

Performance of UDP
Performance of UDP in wireless networks for any closed wired network,
the nature of the connections, the number of nodes and location of the
recipients, what each needs to get from the transmission, and the response
time of each node is UDP`s performance can be best. Some researches have
found that packet drop is more in UDP protocol as compared to TCP in a

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


90
Computer Networks Lab
Manual

wireless network. Transmission speed also more in UDP. The behavior of UDP
in wired network and wireless network is mixed so there is a need to study the
behavior of UDP in a hybrid network where it can show the mixed behavior.

Result :
It is analyzed TCP and UDP protocols in the hybrid network with Mobile
IP and analyzed some performance metrics.

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


91
Computer Networks Lab
Manual

ADDITIONAL EXPERIMENTS – Content beyond the Syllabus

EX.NO 21 Implementation of Subnetting

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


92
Computer Networks Lab
Manual

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


93
Computer Networks Lab
Manual

VIVA VOCE:

1. What do you mean by subnetting?

Subnetting divides one large network into several smaller ones. It adds an
intermediate level of hierarchy in IP addressing.

2. Give some examples of private network addresses.

10.0.0.0 with a subnet mask of 255.0.0.0172.16.0.0 with subnet mask of


255.240.0.0192.168.0.0 with subnet mask of 255.255.0.0

3. What is IP address?

The internet address (IP address) is 32bits that uniquely and universally
defines a host or router on the internet.

The portion of the IP address that identifies the network is called netid. The
portion of the IP address that identifies the host or router on the network is
called hostid.

4. What is subnet mask?

A subnet mask is combined with an IP address in order to identify two parts:


the extended network address and the host address. Like an IP address, a
subnet mask is made up of 32 bits.

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


94
Computer Networks Lab
Manual

EX.NO 22 socket for HTTP for web page upload and download

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


95
Computer Networks Lab
Manual

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


96
Computer Networks Lab
Manual

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


97
Computer Networks Lab
Manual

VIVA VOCE:

1. What does an HTML document describe?


Web pages

2. What is a valid XML document?


A "Valid" XML document is a "Well Formed" XML document, which also
conforms to the rules of a Document Type Definition (DTD)

3. What is HTTPS?
Hyper Text Transfer Protocol Secure sockets (HTTPS) is a protocol for
transmission of encrypted hypertext over Secure Sockets Layer.

4. Discuss the TCP connections needed in FTP.


FTP establishes two connections between the hosts. One connection
is used for data transfer, the other for control information. The control
connection uses very simple rules of C.S.E Department, REC
communication. The data connection needs more complex rules due to
the variety of data types transferred.

5. Discuss the basic model of FTP.


The client has three components: the user interface, the client
control process, and the client data transfer process. The server has two
components: the server control process and the server data transfer
process. The control connection is made between the control processes.
The data connection is made between the data transfer processes.

Ex: No: 23
IMPLEMENTING A WIRELESS SENSOR NETWORK

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


98
Computer Networks Lab
Manual

AIM:
To simulate a wireless sensor network using NS2.

SOFTWARE REQUIREMENTS:
NS-2 Simulator

THEORY:
A wireless sensor network (WSN) consists of a large number of small sensor nodes that are
deployed in the area in which a factor is to be monitored. In wireless sensor network, energy model is
one of the optional attributes of a node. The energy model denotes the level of energy in a mobile
node. The components required for designing energy model includes initialEnergy, txPower, rxPower,
and idlePower. The “initialEnergy” represents the level of energy the node has at the initial stage of
simulation. “txPower” and “rxPower” denotes the energy consumed for transmitting and receiving the
packets. If the node is a sensor, the energy model should include a special component called
“sensePower”. It denotes the energy consumed during the sensing operation. Apart from these
components, it is important to specify the communication range (RXThresh_) and sensing range of a
node (CSThresh_). The sample 18.tcl designs a WSN in which sensor nodes are configured with
different communication and sensing range. Base Station is configured with highest communication
range. Data Transmission is established between nodes using UDP agent and CBR traffic.

ALGORITHM:
1. Create a simulator object
2. Define a setting options for wireless channel
3. Create trace file and name file
4. Setup topography object and nodes
5. Provide initial location of mobile nodes
6. Setup a UDP connection between nodes
7. Printing the window size

PROGRAM:
# Define setting options
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation
model set val(netif) Phy/WirelessPhy ;#
network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue;# interface queue
type set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna
model set val(ifqlen) 50 ;# max
packet in ifq
set val(nn) 10 ;# number of
mobilenodes set val(rp) DSDV ;#
routing protocol
set val(x) 500 ;# X dimension of topography

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


99
Computer Networks Lab
Manual

set val(y) 400 ;# Y dimension of


topography set val(stop) 150 ;# time of simulation
end
set ns [new Simulator]

#Creating trace file and


nam file set tracefd [open
dsdv.tr w]
set windowVsTime2 [open win.tr w]
set namtrace [open dsdv.nam w]
$ns trace-all $tracefd
$ns namtrace-all-wireless $namtrace $val(x) $val(y)
# set up topography object
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)

# configure the nodes


$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channelType $val(chan) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace ON
for {set i 0} {$i < $val(nn) } { incr i } {
set node_($i) [$ns node]
}

# Provide initial location of mobilenodes


$node_(0) set X_ 5.0
$node_(0) set Y_ 800.0
$node_(0) set Z_ 0.0
$node_(1) set X_ 8.0
$node_(1) set Y_ 650.0
$node_(1) set Z_ 0.0
$node_(2) set X_ 60.0
$node_(2) set Y_ 450.0
$node_(2) set Z_ 0.0

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


100
Computer Networks Lab
Manual

$node_(3) set X_ 10.0


$node_(3) set Y_ 480.0
$node_(3) set Z_ 0.0
#another four
$node_(4) set X_ 350.0
$node_(4) set Y_ 500.0
$node_(4) set Z_ 0.0
$node_(5) set X_ 150.0
$node_(5) set Y_ 850.0
$node_(5) set Z_ 0.0
$node_(6) set X_ 200.0
$node_(6) set Y_ 500.0
$node_(6) set Z_ 0.0
#$node_(7) set X_ 320.0
$node_(7) set X_ 320.0
$node_(7) set Y_ 650.0
$node_(7) set Z_ 0.0
#another four
$node_(8) set X_ 250.0
$node_(8) set Y_ 700.0
$node_(8) set Z_ 0.0
$node_(9) set X_ 400.0
$node_(9) set Y_ 800.0
$node_(9) set Z_ 0.0

##################################
#copy of the data
##################################
#####Attack Node
$node_(5) color Green
$ns at 10.0 "$node_(5) color Green"
$ns at 10.0 "$node_(5) label EndUser"

# Set a udp connection between node_(5) and node_(8)


set udp [new Agent/UDP]
set sink [new Agent/LossMonitor]
#$ns attach-agent $node_(5) $udp
#$ns attach-agent $node_(8) $sink
$ns attach-agent $node_(8) $udp
$ns attach-agent $node_(5) $sink
$ns connect $udp $sink
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$node_(8) color Green
$ns at 10.0 "$node_(8) color yellow"
$ns at 10.0 "$node_(5) label node5 "

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


101
Computer Networks Lab
Manual

$ns at 10.0 "$node_(8) label node8 "


$ns at 10.0 "$cbr start"
$ns at 10.45 "$cbr stop"

# Set a udp connection between node_(8) and node_(6)


set udp1 [new Agent/UDP]
set sink1 [new Agent/LossMonitor]
$ns attach-agent $node_(8) $udp1
$ns attach-agent $node_(6) $sink1
$ns connect $udp1 $sink1
set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp1
$node_(6) color yellow
$ns at 10.0 "$node_(6) color yellow"
$ns at 10.0 "$node_(6) label node6 "
$ns at 10.0 "$cbr1 start"
$ns at 10.45 "$cbr1 stop"

# Set a udp connection between node_(8) and node_(6)


set udp2 [new Agent/UDP]
set sink2 [new Agent/LossMonitor]
$ns attach-agent $node_(5) $udp2
$ns attach-agent $node_(8) $sink2
$ns connect $udp2 $sink2
set cbr2 [new Application/Traffic/CBR]
$cbr2 attach-agent $udp2
$node_(6) color yellow
$ns at 12.0 "$cbr2 start"
$ns at 13.45 "$cbr2 stop"

# Set a udp connection between node_(8) and node_(6)


set udp3 [new Agent/UDP]
set sink3 [new Agent/LossMonitor]
$ns attach-agent $node_(8) $udp3
$ns attach-agent $node_(6) $sink3
$ns connect $udp3 $sink3
set cbr3 [new Application/Traffic/CBR]
$cbr3 attach-agent $udp1
$node_(6) color yellow
$ns at 14.0 "$cbr3 start"
$ns at 16.45 "$cbr3 stop"

# Printing the window size


proc plotWindow {tcpSource file} {
global nss
set time 0.01

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


102
Computer Networks Lab
Manual

set now [$ns now]


set cwnd [$tcpSource set cwnd_]
puts $file "$now $cwnd"
$ns at [expr $now+$time] "plotWindow $tcpSource $file" }
#$ns at 10.1 "plotWindow $tcp $windowVsTime2"

# Define node initial position in nam


for {set i 0} {$i < $val(nn)} { incr i } {
# 30 defines the node size for nam
$ns initial_node_pos $node_($i) 30
}

# Telling nodes when the simulation ends for {set i 0} {$i < $val(nn) } { incr i } {
#$ns at $val(stop) "$node_($i) reset";
#$ns at 200.25 "$node_($i) reset";
$ns at 21.25 "$node_($i) reset";
}
$ns at 0.00 "$ns trace-annotate \"Wireless Mac Ptotocol \""
$ns at 10.0 "$ns trace-annotate \" Data send in node5 to node8 \""
$ns at 10.0 "$ns trace-annotate \" Data send in node6 to node8 \""
$ns at 10.45 "$ns trace-annotate \" Data Collision \""
$ns at 12.00 "$ns trace-annotate \"Data send in node5 to node8\""
$ns at 14.00 "$ns trace-annotate \"Data send in node6 to node8\""
$ns at 21.25 "$ns trace-annotate \"End simulation\""
$ns at 21.25 "$ns nam-end-wireless 21.01"
$ns at 21.25 "stop"
$ns at 22.01 "puts \"end simulation\" ; $ns halt" proc stop {} {
global ns tracefd namtrace
$ns flush-trace close $tracefd
close $namtrace
exec nam dsdv.nam &
$ns run
exit 0
}

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


103
Computer Networks Lab
Manual

Result : Thus simulated a wireless sensor network using NS2.

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


104
Computer Networks Lab
Manual

Ex:No: 24 SIMULATE A MOBILE ADHOC NETWORK

AIM:
To simulate a Mobile Adhoc network (MANET) using NS2.

SOFTWARE REQUIREMENTS:
Network Simulator -2

THEORY:
A mobile ad hoc network or MANET does not depend on a fixed infrastructure for its
networking operation. MANET is an autonomous and short-lived association of group of mobile nodes
that communicate with each other over wireless links. A node can directly communicate to the
nodes that lie within its communication range. If a node wants to communicate with a node that is
not directly within its communication range, it uses intermediate nodes as routers.

ALGORITHM:
1. Create a simulator object
2. Set the values for the parameter
3. Open a nam trace file and define finish procedure then close the trace file, and execute nam on
trace file.
4. Create the nodes that forms a network numbered from 0 to 3
5. Schedule events and run the program.

PROGRAM:
set val(chan) Channel/WirelessChannel
set val(prop) Propagation/TwoRayGround set val(netif) Phy/WirelessPhy
set val(mac) Mac/802_11
set val(ifq) Queue/DropTail/PriQueue set val(ll) LL
set val(ant) Antenna/OmniAntenna set val(ifqlen) 50
set val(nn) 3
set val(rp) DSDV
set ns [new Simulator]

set tf [open output.tr w]


$ns trace-all $tf

set tf1 [open output.nam w]


$ns namtrace-all-wireless $tf1 100 100

set topo [new Topography]


$topo load_flatgrid 100 100

create-god $val(nn)

$ns node-config -adhocRouting $val(rp) \


-llType $val(ll) \

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


105
Computer Networks Lab
Manual

-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channelType $val(chan) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace OFF \
-macTrace OFF \
-movementTrace OFF

set node0 [$ns node] set node1 [$ns node] set node2 [$ns node]

$ns initial_node_pos $node0 10


$ns initial_node_pos $node1 10
$ns initial_node_pos $node2 10

$node0 set X_ 25.0


$node0 set Y_ 50.0
$node0 set Z_ 0.0

$node1 set X_ 50.0


$node1 set Y_ 50.0
$node1 set Z_ 0.0

$node2 set X_ 65.0


$node2 set Y_ 50.0
$node2 set Z_ 0.0

set tcp1 [new Agent/TCP]


$ns attach-agent $node0 $tcp1

set ftp [new Application/FTP]


$ftp attach-agent $tcp1

set sink1 [new Agent/TCPSink]


$ns attach-agent $node2 $sink1

$ns connect $tcp1 $sink1

$ns at 10.0 "$node1 setdest 50.0 90.0 0.0"


$ns at 50.0 "$node1 setdest 50.0 10.0 0.0"

$ns at 0.5 "$ftp start"

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


106
Computer Networks Lab
Manual

$ns at 1000 "$ftp stop"

$ns at 1000 "finish" proc finish {} { global ns tf tf1


$ns flush-trace close $tf
exec nam output.nam &
exit 0
}

$ns run

Result: Thus simulated a Mobile Adhoc network (MANET) using NS2.

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


107
Computer Networks Lab
Manual

Viva Voce:
1. Discuss issues in designing MAC protocol for adhoc-networks.
1. Bandwidth Efficiency
2. Quality of Service support
3. Synchronization
4. Hidden and Exposed Terminal Problems

2. Explain about mobile adhoc network


An ad hoc network is a network that is composed of individual devices communicating with
each other directly. Many ad hoc networks are local area networks where computers or other
devices are enabled to send data directly to one another rather than going through a centralized
access point
.
3. What are the characteristics of an ideal routing-protocol for Adhoc networks?
a. The protocol must be fully distributed as centralized routing involves high controloverhead
and hence is not scalable.
b. It must be adaptive to frequent topology changes caused by mobility of nodes.
c. Route-computation & maintenance must involve a minimum no. of nodes.
d. It must be localized, as global state maintenance involves a huge state propagation control-
overhead.
e. It must be loop-free and free from state routes.

4. RTS/CTS period is called


(a) Waiting period
(b) Contention period
(c) Running period
(d) none of these

MVIT / DEPT OF IT / III YR / VI SEM / COMPUTER NETWORKS LAB MANUAL


108

You might also like