WEB T
WEB T
Ghaziabad UP
Create a socket for HTTP for web page upload and download
7
Write a program to implement RPC (Remote Procedure Call)
8
Implementation of Subnetting .
9
14. Running and using services/commands like ping, traceroute, arp, telnet, etc.
15. Network packet analysis using tools like Wireshark, tcpdump, etc.
16. Network simulation using tools like Cisco Packet Tracer, NetSim, OMNeT++,
NS2, NS3, etc
EXPERIMENT-1
Theory: Ethernet cable Color-coded wiring sequences exist as a cabling industry standard. It allows
cabling technicians to reliably predict how Ethernet cable is terminated on both ends so they can follow
other technicians' work without having to guess or spend time deciphering the function and connections
of each wire pair. Ethernet cable jack wiring follows the T568A and T568B standards.
There are two kinds of Ethernet cables you can make, Straight Through and Crossover.
Standard Cabling:
1. 10BaseT and 100BaseT are most common mode of LAN. You can use UTP category-5 cable for
both modes.
2. A straight cable is used to connect a computer to a hub
CROSSOVER CABLES - The purpose of a Crossover Ethernet cable is to directly connect one
computer to another computer (or device) without going through a router, switch or hub.
Bulk RJ45 Crimpable Connectors for CAT-6
IO connector crimping: Run the full length of Ethernet cable in place, from
endpoint to endpoint,making sure to leave excess.
At one end, cut the wire to length leaving enough length to work, but not too much excess.
Strip off about 2 inches of the Ethernet cable sheath.
Align each of the colored wires according to the layout of the jack.
Use the punch down tool to insert each wire into the jack.
Repeat the above steps for the second RJ45 jack.
Result:
Cable Crimping, Standard Cabling and Cross Cabling, IO connector crimping and testing the crimped
cable using a cable tester are done successfully
EXPERIMENT-2
Objective: Configuration of router, hub, switch etc. (using real devices or
simulators)
2. Hub: An Ethernet hub, active hub, network hub, repeater hub, hub or concentrator
is a device for connecting multiple twisted pair or fiber optic Ethernet devices together and making them
act as a single network segment. Hubs work at the physical layer (layer 1) of the OSI model. The device
is a form of multiport repeater. Repeater hubs also participate in collisiondetection, forwarding a jam
signal to all ports if it detects a collision.
3. Switch: A network switch or switching hub is a computer networking device that connects
network segments. The term commonly refers to a network bridge that processes and routes data at the
data link layer (layer 2) of the OSI model. Switches that additionally process data at the network layer
(layer 3 and above) are often referred to as Layer 3 switches or multilayer switches.
4. Bridge: A network bridge connects multiple network segments at the data link layer (Layer 2)
of the OSI model. In Ethernet networks, the term bridge formally means a device that behavesaccording
to the IEEE 802.1D standard. A bridge and switch are very much alike; a switch beinga bridge with
numerous ports. Switch or Layer 2 switch is often used interchangeably with bridge .Bridges can analyze
incoming data packets to determine if the bridge is able to send the given packet to another segment of
the network.
5. Router: A router is an electronic device that interconnects two or more computer networks,
and selectively interchanges packets of data between them. Each data packet contains address information
that a router can use to determine if the source and destination are on the same network, or if the data
packet must be transferred from one network to another. Where multiple routers are used in a large
collection of interconnected networks, the routers exchange information about target system addresses,
so that each router can build up a table showing the preferred paths between any two systems on the
interconnected networks.
6. Gate Way: In a communications network, a network node equipped for interfacing with another
network that uses different protocols.
• A gateway may contain devices such as protocol translators, impedance matching devices, rate
converters, fault isolators, or signal translators as necessary to provide system interoperability. It also
requires the establishment of mutually acceptable administrative procedures between both networks.
• A protocol translation/mapping gateway interconnects networks with different network protocol
technologies by performing the required protocol conversions.
EXPERIMENT-3
Objective: Implementation of Stop and Wait Protocol and Sliding Window
Protocol.
#include<stdio.h>
int main()
{
int w,i,f,frames[50];
for(i=1;i<=f;i++)
scanf("%d",&frames[i]);
printf("\nWith sliding window protocol the frames will be sent in the following manner (assuming no
corruption of frames)\n\n");
printf("After sending %d frames at each stage sender waits for acknowledgement sent by the receiver\n\n",w);
for(i=1;i<=f;i++)
{
if(i%w==0)
{
printf("%d\n",frames[i]);
printf("Acknowledgement of above frames sent is received by sender\n\n");
}
else
printf("%d ",frames[i]);
}
if(f%w!=0)
printf("\nAcknowledgement of above frames sent is received by sender\n");
return 0;
}
Output
Enter window size: 3
Enter number of frames to transmit: 5
Enter 5 frames: 12 5 89 4 6
With sliding window protocol the frames will be sent in the following manner (assuming no corruption
of frames)
After sending 3 frames at each stage sender waits for acknowledgement sent by the receiver
12 5 89
Acknowledgement of above frames sent is received by sender
46
Acknowledgement of above frames sent is received by sender
Experiment 4
Objective: Study of Socket Programming and Client – Server model
DESCRIPTION:
Socket
A socket is formally defined as an endpoint for communication between an application program,
and the underlying network protocols.
The two modes of services available are
Connection-oriented service
Connection less service
CONNECTION-LESS
In a connection –less mode an application program sends its data immediately without waiting
for connection establishment. As a result the application program may waste its time by sending data
when the other end is not ready to accept it. Moreover,data may not arrive at the other end if the network
decides to discards it. If data arrives at the destination, it may not arrive in the same order as it was
transmitted.
The connectionless mode is often said to provide best effort service, since the network would try
its best to deliver the information but cannot guarantee the delivery.
The figure shows the sequence of system calls for a connectionless communication. No connection is
established prior to data transfer. The recvfrom call returns when a Complete UDP data gram has been
received.
Socket system calls for connection less service
The following figure illustrates the example of client/server relationship of the socket APIs for a
connectionless protocol (UDP).
Simple Echo Client Server Using UDP:
accept()
When an application is listening for stream-oriented connections from other hosts, it is notified of such
events (cf. select() function) and must initialize the connection using the accept() function. Accept()
creates a new socket for each connection and removes the connection from the listen queue. It takes the
following arguments:
sockfd, the descriptor of the listening socket that has the connection queued.
cliaddr, a pointer to a sockaddr structure to receive the client's address information.
addrlen, a pointer to a socklen_t location that specifies the size of the client address structure passed to
accept(). When accept() returns, this location indicates how many bytes of the structure were actually
used.
The accept() function returns the new socket descriptor for the accepted connection, or -1 if an error
occurs. All further communication with the remote host now occurs via this new socket.
Datagram sockets do not require processing by accept() since the receiver may immediately respond to
the request using the listening socket.
Prototype
int accept(intsockfd,structsockaddr*cliaddr,socklen_t*addrlen);
connect()
The connect() system call connects a socket, identified by its file descriptor, to a remote host specified
by that host's address in the argument list.
Certain types of sockets are connectionless, most commonly user datagram protocol sockets. For these
sockets, connect takes on a special meaning: the default target for sending and receiving data gets set to
the given address, allowing the use of functions such as send() and recv() on connectionless sockets.
connect() returns an integer representing the error code: 0 represents success, while -1 represents an error.
Prototype
int connect(intsockfd,conststructsockaddr*serv_addr,socklen_taddrlen);
Sending and receiving data over a socket
After a connection is established, there are several ways to send information over the socket.
read()
The most common way of reading data from a socket is using the read () system call, which is defined
like this:
Since datagram sockets aren’t connected to a remote host, we need to give the destination address before
we send a packet.
The prototype is:
intsendto(intsockfd, const void *msg, intlen, unsigned int flags, const
structsockaddr *to, inttolen);
This call is basically the same as the call to send() with the addition of two other pieces of information.
to is a pointer to a structsockaddr (which you’ll probably have as a structsockaddr_in and cast it at the
last minute) which contains the destination IP address and port.
tolen can simply be set to sizeof(structsockaddr).
Just like with send(), sendto() returns the number of bytes actually sent (which, again, might be less than
the number of bytes you told it to send!), or -1 on error.
Socket Address
structsockaddr_in
structsockaddr_in {
u_charsin_len;
u_shortsin_family; // Address family
u_shortsin_port; // Port number
struct in_addrsin_addr; // Internet or IP address
char sin_zero[8]; // Same size as structsockaddr
};
The sin_family field is the address family (always AF_INET for TCP and UDP).
The sin_port field is the port number, and the sin_addr field is the Internet address. The sin_zero field is
reserved, and you must set it to hexadecimal zeroes.
Data type structin_addr - this data type is used in certain contexts to contain an Internet host address. It
has just one field, named s_addr, which records the host address number as an unsigned long int.
sockaddr_in is a "specialized" sockaddr.
sin_addr could be u_long.
sin_addr is 4 bytes and 8 bytes are unused.
sockaddr_in is used to specify an endpoint.
The sin_port and sin_addr must be in Network Byte Order.
EXPERIMENT-5
Objective: Write a code simulating ARP /RARP protocols
C Program To Simulate ARP/RARP:
//ARP SERVER
#include<stdio.h>
#include<sys/types.h>
#include<sys/shm.h>
#include<string.h>
main()
{
int shmid, a, i;
char *ptr, *shmptr;
shmid=shmget(3000,10,IPC_CREAT | 0666);
shmptr=shmat(shmid,NULL,0);
ptr=shmptr;
for(i=0;i<3;i++)
{
puts("enter the mac");
scanf("%s",ptr);
a=strlen(ptr);
printf("string length:%d",a);
ptr[a]= ' ' ;
puts("enter ip");
ptr=ptr+a+1;
scanf("%s",ptr);
ptr[a]='\n' ;
ptr= ptr+a+1;
}
ptr[strlen(ptr)]= '\0';
printf("\n ARP table at serverside is=\n%s", shmptr);
shmdt(shmptr);
}
//ARP CLIENT
#include<stdio.h>
#include<string.h>
#include<sys/types.h>
#include<sys/shm.h>
main()
{
int shmid,a;
char *ptr, *shmptr;
char ptr2[51], ip[12], mac[26];
shmid=shmget(3000,10,0666);
shmptr=shmat(shmid,NULL,0);
puts("the arp table is");
printf("%s",shmptr);
printf("\n1.ARP\n 2.RARP\n 3.EXIT\n");
scanf("%d",&a);
switch(a)
{
case 1:
puts("enter ip address");
scanf("%s",ip);
ptr=strstr(shmptr, ip);
ptr-=8;
sscanf(ptr,"%s%*s",ptr2);
printf("mac addr is %s",ptr2);
break;
case 2:
puts("enter mac addr");
scanf("%s",mac);
ptr=strstr(shmptr, mac);
sscanf(ptr,"%*s%s",ptr2);
printf("%s",ptr2);
break;
case 3:
exit(1);
}}
OUTPUT:
the arp table is
a.b.c.d 1.2.3.4
e.f.g.h 5.6.7.8
i.j.k.l 9.1.2.3
1.ARP
2. RARP
3. EXIT
enter your choice: 1
enter ip address: 1.2.3.4
mac addr is a.b.c.d
enter your choice:2
enter mac address: e.f.g.h
ip addr is 5.6.7.8
EXPERIMENT-6
Objective: Write a code simulating PING and TRACEROUTE commands
Algorithm:
Server
Step1: Start the program.
Step2: Import necessary packages.
Step3: Initialize the ping server with both sockets as null value.
Step4: Start the server socket.
Step5: At the client give the IP address of the server(by using ifconfig command in command
prompt).
Step6: The client program is then started by starting socket.
Step7: At the receiver end, the client is pinged and traced. Step8: Stop the program.
Client
Step1: Start the program.
Step2: Import necessary packages.
Step3: Initialize the ping client with both sockets as null value.
Step4: Start the socket.
Step5: Get the IP address of the server.
Step6: Ping the server.
Step7: At the receiver end, the server is pinged and traced.
Step8: Stop the program.
pingclient.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
int main() {
int clientSocket;
struct sockaddr_in serverAddr;
char buffer[1024];
// Create socket
if ((clientSocket = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
perror("Socket creation failed");
exit(EXIT_FAILURE);
}
// Connect to server
if (connect(clientSocket, (struct sockaddr *)&serverAddr, sizeof(serverAddr)) < 0) {
perror("Connection to server failed");
exit(EXIT_FAILURE);
}
t2 = (long)time(NULL);
printf("; TTL=%ldms\n", (t2 - t1) * 1000); // Print round-trip time
}
// Close socket
close(clientSocket);
return 0;
}
pingserver.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
int main() {
char buffer[1024];
// Create socket
exit(EXIT_FAILURE);
serverAddr.sin_family = AF_INET;
serverAddr.sin_port = htons(PORT);
serverAddr.sin_addr.s_addr = INADDR_ANY;
exit(EXIT_FAILURE);
}
if (listen(serverSocket, 5) < 0) {
perror("Listen failed");
exit(EXIT_FAILURE);
perror("Acceptance failed");
exit(EXIT_FAILURE);
// Close sockets
close(clientSocket);
close(serverSocket);
return 0;
Output:
Pingserver.c
Pingclient.c
; TTL=0ms
; TTL=0ms
; TTL=0ms
; TTL=0ms
EXPERIMENT-7
Objective: Create a socket for HTTP for web page upload and download
Algorithm:
Server
Step 1: Create a socket and bind to the address. Leave socket unconnected.
Step 2: Leave socket in passive mode, making it ready for use by a server.
Step 3: Repeatedly call accept to receive the next request from a client to handle the response with
thethrough socket.
Client
Step 1: Begin with a connection passed from the server (i.e., a socket for the connection).
Step 2: Use input streams; get the message from user to be given to the server.
Step 3: Use input streams read message given by server and print it.
Step 4: Use output streams to write message to the server.
Step 5: Close the connection and exit, i.e., slave terminates after handling all requests from one
client.
C Program:
ConServer.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
int main() {
int server_socket, client_socket;
struct sockaddr_in server_addr, client_addr;
socklen_t client_addr_len = sizeof(client_addr);
// Create a socket
server_socket = socket(AF_INET, SOCK_STREAM, 0);
if (server_socket < 0) {
perror("Socket creation failed");
exit(EXIT_FAILURE);
}
// Set up the server address struct
server_addr.sin_family = AF_INET;
server_addr.sin_addr.s_addr = INADDR_ANY;
server_addr.sin_port = htons(PORT);
handle_client(client_socket);
close(client_socket);
}
close(server_socket);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
int main() {
int client_socket;
char buffer[BUFFER_SIZE];
int num, square;
// Create a socket
if (client_socket < 0) {
exit(EXIT_FAILURE);
server_addr.sin_family = AF_INET;
server_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
server_addr.sin_port = htons(PORT);
perror("Connection failed");
close(client_socket);
exit(EXIT_FAILURE);
close(client_socket);
exit(EXIT_FAILURE);
close(client_socket);
exit(EXIT_FAILURE);
num = atoi(buffer);
close(client_socket);
exit(EXIT_FAILURE);
close(client_socket);
exit(EXIT_FAILURE);
square = atoi(buffer);
close(client_socket);
return 0;
}
ConClient2.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
int main() {
int client_socket;
char buffer[BUFFER_SIZE];
// Create a socket
if (client_socket < 0) {
exit(EXIT_FAILURE);
server_addr.sin_family = AF_INET;
server_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
server_addr.sin_port = htons(PORT);
perror("Connection failed");
close(client_socket);
exit(EXIT_FAILURE);
close(client_socket);
exit(EXIT_FAILURE);
close(client_socket);
exit(EXIT_FAILURE);
num = atoi(buffer);
close(client_socket);
exit(EXIT_FAILURE);
close(client_socket);
exit(EXIT_FAILURE);
square = atoi(buffer);
close(client_socket);
return 0;
}
Output:
ConServer.c
ConClient1.c
Enter a number: 2
Square of 2 is 4
=== Code Execution Successful ===
ConClient2.c
CLIENT 2:
Enter the number to find square: 3
Square of 3 is 9
=== Code Execution Successful ===
EXPERIMENT-8
cl=clnt_create(argv[1],SQUARE_PROG,SQUARE_VERS,"tcp");
in.arg1=atol(argv[2]);
if(cl==NULL)
{
printf("\nerror:%s",strerror(errno));
exit(-1);
}
if((outp=squareproc_1(&in,cl))==NULL)
{
printf("\nerror :%s",clnt_sperror(cl,argv[1]));
exit(-1);
}
// .h FILENAME: square.h
struct square_in
{
/*input arg*/
long arg1;
};
struct square_out
{
/*op result*/
long res1;
};
program SQUARE_PROG
{
version SQUARE_VERS
{
square_out SQUAREPROC(square_in)=1; /*proc no=1*/
}=1; /*version no*/
}=0x31230000;/*prog no*/
Output:
[root@localhost~]#rpcgen -C square.x
[root@localhost~]#cc -c client.c -o client.o
[root@localhost~]#cc -c square_clnt.c -o square_clnt.o
[root@localhost~]#cc -c square_xdr.c -o square.xdr.o
[root@localhost~]#cc -o client client.o square_clnt.o square_xdr.o
[root@localhost~]#cc -c client.c server.c square_xdr.c
[root@localhost~]#cc -c server.c -o server.o
[root@localhost~]#cc -c square_svc.c -o square_svc.o
[root@localhost~]#cc -o server server.o square_svc.o square_xdr.o
[root@localhost~]#./server &
[1] 2264
[root@localhost~]#./client localhost 4
result is: 16
EXPERIMENT-9
Algorithm:
Step1: Get the input from the user by using scanner method.
Step 2: Read the input by using nextLine() and store it. Step 3: Split the string based on string by
using split(“\\”)Step4 : Convert it into binary.
Step 5: calculating the network mask by using math and logarithmic
Step 6: get the first address by ANDding the last n bits with 0.
Step7 : get the last address by ANDding the last n bits with 1.
Program:
//…Calculation of mask…//
#include <stdio.h>
#include <math.h>
#include <string.h>
int main() {
int fbip[32];
for (int i = 0; i < 32; i++) {
char fip[4][9] = {"", "", "", ""}; // Array to store binary strings of each byte
char bit = fbip[i] + '0'; // Convert integer 0 or 1 back to character '0' or '1'
printf("%ld", strtol(fip[i], NULL, 2)); // Convert binary string to integer and print
if (i != 3) {
printf(".");
printf("\n");
return 0;
}
Output:
Algorithm:
Server
Step1: Start the program and create server and client sockets.
Step2: Use input streams to get the message from user.
Step3: Use output streams to send message to the client.
Step4: Wait for client to display this message and write a new one to be displayed by the server.
Step5: Display message given at client using input streams read from socket.
Step6: Stop the program.
Client
Step1: Start the program and create a client socket that connects to the required host and port.
Step2: Use input streams read message given by server and print it.
Step3: Use input streams; get the message from user to be given to the server.
Step4: Use output streams to write message to the server.
Step5: Stop the program.
Program:GossipServer.java
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
int main() {
int server_socket, client_socket;
struct sockaddr_in server_addr, client_addr;
socklen_t addr_size;
char buffer[BUFFER_SIZE];
int n;
// Create a socket
server_socket = socket(AF_INET, SOCK_STREAM, 0);
if (server_socket < 0) {
perror("Socket creation failed");
exit(EXIT_FAILURE);
}
// Configure server address struct
server_addr.sin_family = AF_INET;
server_addr.sin_addr.s_addr = INADDR_ANY;
server_addr.sin_port = htons(PORT);
int main() {
int client_socket;
struct sockaddr_in server_addr;
char buffer[BUFFER_SIZE];
int n;
// Create a socket
client_socket = socket(AF_INET, SOCK_STREAM, 0);
if (client_socket < 0) {
perror("Socket creation failed");
exit(EXIT_FAILURE);
}
/tmp/29ZmhVAMi6.o
Start the chitchat, type and press Enter key
Client: hi
Server: hello
Server
Client
Server.c
{/*… Register service on port 15123…*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <fcntl.h>
int main() {
socklen_t addr_size;
char buffer[BUFFER_SIZE];
int file_fd;
if (server_socket < 0) {
exit(EXIT_FAILURE);
server_addr.sin_family = AF_INET;
server_addr.sin_addr.s_addr = INADDR_ANY;
server_addr.sin_port = htons(PORT);
close(server_socket);
exit(EXIT_FAILURE);
if (listen(server_socket, 5) < 0) {
perror("Listen failed");
close(server_socket);
exit(EXIT_FAILURE);
addr_size = sizeof(client_addr);
if (client_socket < 0) {
perror("Accept failed");
close(server_socket);
exit(EXIT_FAILURE);
close(client_socket);
close(server_socket);
exit(EXIT_FAILURE);
lseek(file_fd, 0, SEEK_SET);
// Read the file into the buffer and send it to the client
if (bytes_sent < 0) {
perror("Send failed");
close(file_fd);
close(client_socket);
close(server_socket);
exit(EXIT_FAILURE);
close(file_fd);
close(client_socket);
close(server_socket);
return 0;
Client.c
// Receive the file data from the server and write it to the file
printf("Receiving file: %s\n", filename);
while ((bytes_received = recv(client_socket, buffer, BUFFER_SIZE, 0)) > 0) {
write(file_fd, buffer, bytes_received);
total_bytes_received += bytes_received;
}
if (bytes_received < 0) {
perror("Receive failed");
} else {
printf("File transfer complete, received %d bytes\n", total_bytes_received);
}
close(file_fd);
close(client_socket);
return 0;
}
Output:
/tmp/QMKfTlKyXD.o
Objective: Applications using TCP and UDP Sockets like DNS & SNMP
Algorithm:
Server
Step1: Start the program.
Step2: Create the socket for the server.
Step3: Bind the socket to the port.
Step4: Listen for the incoming client connection.
Step5: Receive the IP address from the client to be resolved.
Step6: Get the domain name for the client.
Step7: Check the existence of the domain in the server.
Step8: If domain matches then send the corresponding address to the client.
Step9: Stop the program execution
Client
Step1: Start the Program.
Step2: Create the socket for the client.
Step3: Connect the socket to the Server.
Step4: Send the host name to the server to be resolved.
Step5: If the server corresponds then print the address and terminate the process
Program:
Clientdns.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
int main() {
int sockfd;
struct sockaddr_in server_addr;
char send_buffer[BUFFER_SIZE];
char receive_buffer[BUFFER_SIZE];
socklen_t addr_len;
struct sockaddr_in from_addr;
Serverdns.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#define PORT 1309
#define BUFFER_SIZE 1024
int main() {
int sockfd;
struct sockaddr_in server_addr, client_addr;
char send_buffer[BUFFER_SIZE];
char receive_buffer[BUFFER_SIZE];
socklen_t addr_len;
int n;
// IP addresses and corresponding domain names
char *ips[] = {"165.165.80.80", "165.165.79.1"};
char *names[] = {"www.skct.edu", "www.sonika.com"};
int records_count = sizeof(ips) / sizeof(ips[0]);
// Create a UDP socket
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (sockfd < 0) {
perror("Socket creation failed");
exit(EXIT_FAILURE);
}
// Configure server address struct
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(PORT);
server_addr.sin_addr.s_addr = INADDR_ANY;
// Bind the socket to the specified port
if (bind(sockfd, (struct sockaddr*)&server_addr, sizeof(server_addr)) < 0) {
perror("Bind failed");
close(sockfd);
exit(EXIT_FAILURE);
}
printf("Server ready for DNS resolution\n");
// Server loop
while (1) {
addr_len = sizeof(client_addr);
n = recvfrom(sockfd, receive_buffer, BUFFER_SIZE, 0, (struct sockaddr*)&client_addr,
&addr_len);
if (n < 0) {
perror("Receive failed");
continue;
}
receive_buffer[n] = '\0'; // Null-terminate the received string
printf("Received: %s\n", receive_buffer);
// Find the corresponding IP address or domain name
int found = 0;
for (int i = 0; i < records_count; i++) {
if (strcmp(receive_buffer, ips[i]) == 0) {
strncpy(send_buffer, names[i], BUFFER_SIZE);
found = 1;
break;
} else if (strcmp(receive_buffer, names[i]) == 0) {
strncpy(send_buffer, ips[i], BUFFER_SIZE);
found = 1;
break;
}
}
if (!found) {
strncpy(send_buffer, "Not found", BUFFER_SIZE);
}
// Send the response to the client
sendto(sockfd, send_buffer, strlen(send_buffer), 0, (struct sockaddr*)&client_addr, addr_len);
}
// Close the socket
close(sockfd);
return 0;
}
Sample Output:
/tmp/KcSNNAezWG.o
Server ready for DNS resolution
Received: https://www.google.com/
=== Session Ended. Please Run the code again ===
/tmp/WKLFYRVnEv.o
Enter the DOMAIN NAME or IP address: Google
APPLICATIONS (SNMP)
Algorithm:
Step 1: Using start method the system is used to receive SNMP request.
Step 2: The assigned Port no 162 are used to send and reciver trap.
Step 3: Set the address using the format ("udp:127.0.0.1/161")
Step 4: Create a variable binding and add the object identifier in OID format.
Step 5: Create the Protocol data unit object
Step 6: Listen enable listening for SNMP packet by using listen ().
Step 8: Get method asynchronous GET request PDU is send to the given target.
Step 7: Send a new get request for single OID and return response event for the request only, if
notimeout has occurred.
Step 8: Send a new get request for multiple OIDS and return response event for the request only, if
notimeout has occurred.
Step 9: Create target method which contains information about where the data should be fetched
andhow to return.
Step 10: If response is not NULL then no time out has occurred and the response was
successfullydelivered.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
int sockfd;
char send_buffer[BUFFER_SIZE];
char receive_buffer[BUFFER_SIZE];
socklen_t addr_len;
if (sockfd < 0) {
exit(EXIT_FAILURE);
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(PORT);
server_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
if (n < 0) {
perror("Receive failed");
close(sockfd);
exit(EXIT_FAILURE);
close(sockfd);
return 0;
}Sample Output:
Ns Functionalities
Routing, Transportation, Traffic sources,queuing disciplines, QoS
Wireless
Ad hoc routing, mobile IP, sensor-MAC Tracing, visualization and various utilitiesNS(Network
Simulators) Most of the commercial simulators are GUI driven, while some network simulators are CLI
driven. The network model / configuration describe the state of the network (nodes, routers, switchesand
links) and the events (data transmissions, packet error etc.). The important outputs of simulations are the
trace files. Trace files log every packet, every event that occurred in the simulation and are used for
analysis. Network simulators can also provide other tools to facilitate visual analysis of trends and
potential trouble spots.
Most network simulators use discrete event simulation, in which a list of pending "events" is stored, and
those events are processed in order, with some events triggering future events such as the event of the
arrival of a packet at one node triggering the event of the arrival of that packet at a downstream node.
Simulation of networks is a very complex task. For example, if congestion is high, then estimation of the
average occupancy is challenging because of high variance. To estimate the likelihood of a buffer
overflow in a network, the time required for an accurate answer can be extremely large. Specialized
techniques such as "control variants" and "importance sampling" have been developed to speed
simulation.
Examples of network simulators
There are many both free/open-source and proprietary network simulators. Examples of notable network
simulation software are, ordered after how often they are mentioned in research papers:
ns (open source)
OPNET (proprietary software)
NetSim (proprietary software)
Uses of network simulators
Network simulators serve a variety of needs. Compared to the cost and time involved in setting up an
entire test bed containing multiple networked computers, routers and data links, network simulators are
relatively fast and inexpensive. They allow engineers, researchers to test scenarios that might be
particularly difficult or expensive to emulate using real hardware - for instance,simulating a scenario with
several nodes or experimenting with a new protocol in the network. Network simulators are particularly
useful in allowing researchers to test new networking protocols or changes to existing protocols in a
controlled and reproducible environment. A typical network simulator encompasses a wide range of
networking technologies and can help the users to build complex networks from basic building blocks
such as a variety of nodes and links. With the help of simulators, one can design hierarchical networks
using various types of nodes like computers, hubs, bridges, routers, switches, links, mobile units etc.
Various types of Wide Area Network (WAN) technologies like TCP, ATM, IP etc. and Local Area
Network (LAN) technologies like Ethernet, token rings etc., can all be simulated with a typical simulator
and the user can test, analyse various standard results apart from devising some novel protocol or strategy
for routing etc. Network simulators are also widely used to simulate battlefield networks in Network-
centric warfare There are a wide variety of network simulators, ranging from the very simple to the very
complex. Minimally, a network simulator must enable a user to represent a network topology, specifying
the nodes on the network, the links between those nodes and the traffic between the nodes. More
complicated systems may allow the user to specify everything about the protocols used to handle traffic
in a network. Graphical applications allow users to easily visualize the workings of their simulated
environment. Text-based applications may provide a less intuitive interface, but may permit more
advanced forms of customization.
Packet loss occurs when one or more packets of data travelling across a computer network fail to reach
their destination. Packet loss is distinguished as one of the three main error types encountered in digital
communications; the other two being bit error and spurious packets caused due to noise. Packets can be
lost in a network because they may be dropped when a queue in the network node overflows. The amount
of packet loss during the steady state is another important property of a congestion control scheme. The
larger the value of packet loss, the more difficult it is for transport layer protocols to maintain high
bandwidths, the sensitivity to loss of individual packets, as well as to frequency and patterns of loss
among longer packet sequences is strongly dependent on the application itself.
Throughput
This is the main performance measure characteristic, and most widely used. In communication networks,
such as Ethernet or packet radio, throughput or network throughput is the average rate of successful
message delivery over a communication channel. The throughput is usually measured in bit sper second
(bit/s orbps), and sometimes in data packet sper second or data packets per time slot This measure how
soon the receiver is able to get a certain amount of data send by the sender. It is determined as the ratio
of the total data received to the end to end delay. Throughput is an important factor which directly impacts
the network performance
Delay
Delay is the time elapsed while a packet travels from one point e.g., source premise or network ingress
to destination premise or network degrees. The larger the valueof delay, the more difficult it is for
transport layer protocols to maintain high bandwidths. We will calculate end to end delay
Queue Length
A queuing system in networks can be described as packets arriving for service, waiting for service if it is
not immediate, and if having waited for service, leaving the system after being served. Thus queue length
is very important characteristic to determine that how well the active queue management of the
congestion control algorithm has been working.
EXPERIMENT-13
Objective: Perform a case study about the different routing algorithms to select the
network path with its optimum andeconomical during data transfer. i. Link State routing
ii. Flooding iii. Distance vector
b) FLOODING
Flooding is a simple routing algorithm in which every incoming packet is sent through every
outgoing link except the one it arrived on Flooding is used in bridging and in systems such as Usenet and
peer-to-peer file sharing and as part of some routing protocols, including OSPF, DVMRP, and those
used in ad-hoc wireless networks. There are generally two types of flooding available, Uncontrolled
Flooding and Controlled Flooding. Uncontrolled Flooding is the fatal law of flooding. All nodes have
neighbors and route packets indefinitely. More than two neighbors create a broadcast storm. Controlled
Flooding has its own two algorithms to make it reliable, SNCF (Sequence Number Controlled Flooding)
and RPF (Reverse Path Flooding). In SNCF, the node attaches its own address and sequence number to
the packet, since every node has a memory of addresses and sequence numbers. If it receives a packet in
memory, it drops it immediately while in RPF, the node will only send the packet forward. If it is
received from the next node, it sends it back to the sender.
Algorithm
There are several variants of flooding algorithm. Most work roughly as follows:
1. Each node acts as both a transmitter and a receiver.
2. Each node tries to forward every message to every one of its neighbours except the source node.
This results in every message eventually being delivered to all reachable parts of the network.
Algorithms may need to be more complex than this, since, in some case, precautions have to be taken
to avoid wasted duplicate deliveries and infinite loops, and to allow messages to eventually expire from
the system. A variant of flooding called selective flooding partially addresses these issues by only sending
packets to routers in the same direction. In selective flooding the routers don't send every incoming
packet on every line but only on those lines which are going approximately in the right direction.
Advantages
packet can be delivered, it will (probably multiple times).
Since flooding naturally utilizes every path through the network, it will also use the shortest path.
Thisalgorithm is very simple to implement.
Disadvantages
Flooding can be costly in terms of wasted bandwidth. While a message may only have one destination it
has to be sent to every host. In the case of a ping flood or a denial of service attack, it can be harmful to
the reliability of a computer network. Messages can become duplicated in the network further increasing
the load on the networks bandwidth as well as requiring an increase in processing complexity to disregard
duplicate messages. Duplicate packets may circulate forever, unless certain precautions are taken: Use a
hop count or a time to live count and include it with each packet. This value should take into account the
number of nodes that a packet may have to pass through on the way to its destination.
c) DISTANCE VECTOR ROUTING PROTOCOL USING NS2
In computer communication theory relating to packet-switched networks, a distance vector routing
protocol is one of the two major classes of routing protocols, the other major class being the link-state
protocol. Distance-vector routing protocols use the Bellman–Ford algorithm, Ford–Fulkerson algorithm,
or DUAL FSM (in the case of Cisco Systems protocols) to calculate paths.
A distance-vector routing protocol requires that a router informs its neighbours of topology changes
periodically. Compared to link-state protocols, which require a router to inform all the nodes in a
network of topology changes, distance-vector routing protocols have less computational complexity and
message overhead. The term distance vector refers to the fact that the protocol manipulates vectors
(arrays) of distances to other nodes in the network. The vector distance algorithm was the original
ARPANET routing algorithm and was also used in the internet under the name of RIP (Routing
Information Protocol). Examples of distance-vector routing protocols include RIPv1 and RIPv2 and
IGRP.
Method:
Routers using distance-vector protocol do not have knowledge of the entire path to a destination.
Instead they use two methods:
1. Direction in which router or exit interface a packet should be forwarded.
2. Distance from its destination
Distance-vector protocols are based on calculating the direction and distance to any link in a network.
"Direction" usually means the next hop address and the exit interface. "Distance" is a measure of the
cost to reach a certain node. The least cost route between any two nodes is the route with minimum
distance. Each node maintains a vector (table) of minimum distance to every node. The cost of reaching
a destination is calculated using various route metrics. RIP uses the hop count of the destination whereas
IGRP takes into account other information such as node delay and available bandwidth. Updates are
performed periodically in a distance-vector protocol where all or part of a router's routing table is sent
to all its neighbors that are configured to use the same distance-vector routing protocol. RIP supports
cross-platform distance vector routing whereas IGRP is a Cisco Systems proprietary distance vector
routing protocol. Once a router has this information it is able to amend its own routing table to reflect
the changes and then inform its neighbors of the changes. This process has been described as routing by
rumor‘ because routers are relying on the information they receive from other routers and cannot
determine if the information is actually valid and true. There are a number of features which can be used
to help with instability and inaccurate routing information.
EGP and BGP are not pure distance-vector routing protocols because a distance-vector protocol
calculates routes based only on link costs whereas in BGP, for example, the local route preference value
takes priority over the link cost.
Count-to-infinity problem
The Bellman–Ford algorithm does not prevent routing loops from happening and suffers from the count
to infinity problem. The core of the count-to-infinity problem is that if A tells B that it has a path
somewhere, there is no way for B to know if the path has B as a part of it. To see the problem clearly,
imagine a subnet connected like A–B–C–D–E–F, and let the metric between the routers be "number of
jumps". Now suppose that A is taken offline. In the vector-update-process B notices that the route to A,
which was distance 1, is down – B does not receive the vector update from A. The problem is, B also
gets an update from C, and C is still not aware of the fact that A is down – so it tells B that A is only two
jumps from C (C to B to A), which is false. This slowly propagates through the network until it reaches
infinity (in which case the algorithm corrects itself, due to the relaxation property of Bellman–Ford).
EXPERIMENT-14
Objective: Running and using services/commands like ping, traceroute, arp, telnet, etc
Tracert / traceroute
Tracert: Determines the path taken to a destination by sending Internet Control Message Protocol
(ICMP) Echo Request messages to the destination with incrementally increasing Time to Live (TTL)
field values. The path displayed is the list of near-side router interfaces of the routers in the path between
a source host and a destination. The near-side interface is the interface of the router that is closest to the
sending host in the path. Used without parameters, tracert displays help.
This diagnostic tool determines the path taken to a destination by sending ICMP Echo Request messages
with varying Time to Live (TTL) values to the destination. Each router along the path is required to
decrement the TTL in an IP packet by at least 1 before forwarding it.
Effectively, the TTL is a maximum link counter. When the TTL on a packet reaches 0, the router is
expected to return an ICMP Time Exceeded message to the source computer. Tracert determines the path
by sending the first Echo Request message with a TTL of 1 and incrementing the TTL by 1 on each
subsequent transmission until the target responds or the maximum number of hops is reached. The
maximum number of hops is 30 by default and can be specified using the -h parameter.
The path is determined by examining the ICMP Time Exceeded messages returned by intermediate
routers and the Echo Reply message returned by the destination. However, some routers do not return
Time Exceeded messages for packets with expired TTL values and are invisible to the tracert command.
In this case, a row of asterisks (*) is displayed for that hop.
Examples:
To trace the path to the host named www.google.co.in use following command
tracert www.google.co.in
To trace the path to the host named www.google.com and prevent the resolution of each IP
address to its name, type:
tracert -d www.google.com
To trace the path to the host named www.google.com and use the loose source route
10.12.0.1-10.29.3.1-10.1.44.1, type:
tracert -j 10.12.0.1 10.29.3.1 10.1.44.1 www.google.com
Syntax
tracert [-d] [-h MaximumHops] [-j HostList] [-w Timeout] [TargetName]
Parameters
-d Prevents tracert from attempting to resolve the IP addresses of intermediate routers to their names.
This can speed up the display of tracert results.
-h MaximumHops Specifies the maximum number of hops in the path to search for the target (destination).
The default is 30 hops.
-j HostList Specifies that Echo Request messages use the Loose Source Route option in the IP header with
the set of intermediate destinations specified in HostList. With loose source routing, successive
intermediate destinations can be separated by one or multiple routers. The maximum number of addresses
or names in the host list is 9. The HostList is a series of IP addresses (in dotted decimal notation) separated
by spaces.
-w Timeout Specifies the amount of time in milliseconds to wait for the ICMP Time Exceeded or Echo
Reply message corresponding to a given Echo Request message to be received. If not received within
the time-out, an asterisk (*) is displayed. The default time-out is 4000 (4 seconds).
Ping
Verifies IP-level connectivity to another TCP/IP computer by sending Internet Control Message Protocol
(ICMP) Echo Request messages. The receipt of corresponding Echo Reply messages are displayed, along
with round-trip times. Ping is the primary TCP/IP command used to troubleshoot connectivity,
reachability, and name resolution.
You can use ping to test both the computer name and the IP address of the computer. If pinging the IP
address is successful, but pinging the computer name is not, you might have a name resolution
problem. In this case, ensure that the computer name you are specifying can be resolved through the
local Hosts file, by using Domain Name System (DNS) queries, or through NetBIOS name resolution
techniques.
To test a TCP/IP configuration by using the ping command:
To quickly obtain the TCP/IP configuration of a computer, open Command Prompt, and then
type ipconfig . From the display of the ipconfig command, ensure that the network adapter for the
TCP/IP configuration you are testing is not in a Media disconnected state.
At the command prompt, ping the loopback address by typing ping 127.0.0.1
Ping the IP address of the computer.
Ping the IP address of the default gateway. If the ping command fails, verify that the default gateway IP
address is correct and that the gateway (router) is operational.
Ping the IP address of a remote host (a host that is on a different subnet). If the ping command fails,
verify that the remote host IP address is correct, that the remote host is operational, and that all of the
gateways (routers) between this computer and the remote host are operational.
Ping the IP address of the DNS server. If the ping command fails, verify that the DNS server IP address
is correct, that the DNS server is operational, and that all of the gateways (routers) between this
computer and the DNS server are operational.
ARP
Displays and modifies entries in the Address Resolution Protocol (ARP) cache, which contains one or
more tables that are used to store IP addresses and their resolved Ethernet or Token Ring physical
addresses. There is a separate table for each Ethernet or Token Ring network adapter installed on your
computer.
Syntax
arp [-a [InetAddr] [-N IfaceAddr]] [-g [InetAddr] [-N IfaceAddr]] [-d InetAddr [IfaceAddr]]
[-s InetAddr EtherAddr [IfaceAddr]]
Parameters
Used without parameters displays help
-a [InetAddr] Displays current ARP cache tables for all interfaces. To display the ARP
[-N IfaceAddr] cache entry for a specific IP address, use arp -a with the InetAddr
parameter, where InetAddr is an IP address. To display the ARP cache
table for a specific interface, use the -N IfaceAddr parameter where
IfaceAddr is the IP address assigned to the interface.
The -N parameter is case-sensitive.
-g [InetAddr] Identical to -a.
[-N IfaceAddr]
-d InetAddr [IfaceAddr] Deletes an entry with a specific IP address, where InetAddr is the IP
address. To delete an entry in a table for a specific interface, use the
IfaceAddr parameter where IfaceAddr is the IP address assigned to the
interface. To delete all entries, use the asterisk (*) wildcard character in
place of InetAddr.
-s InetAddr EtherAddr [IfaceAddr] Adds a static entry to the ARP cache that resolves the IP address
InetAddr to the physical address EtherAddr. To add a static ARP cache
entry to the table for a specific interface, use the IfaceAddr parameter
where IfaceAddr is an IP address assigned to the interface.
Examples:
To display the ARP cache tables for all interfaces use following command
arp -a
To display the ARP cache table for the interface that is assigned the IP address 192.168.42.171
TELNET
The telnet command is used for connection and communication with a remote or local host via the
Telnet TCP/IP protocol.
You can enter a domain or IP address and try connecting to it via the chosen port. In case the port is not
specified, telnet utility tries to connect via the default port 23.
The command is really useful in cases when you need to check whether the needed port is open on your
computer and on the side of the remote host.
How to use Telnet
For Windows
5. Telnet is enabled now, so we can run it in the same way as other commands:
for example:
telnet namecheap.com 80
If you see the blank output after that, you have connected successfully. To quit you can press CTRL +
C or any key:
As a result of successful telnet, we can conclude, that the entered domain or IP exists, and the chosen
port is open on your computer and on the side of the target host.
If connection has not been established, the following error will appear:
EXPERIMENT-15
Objective: Network packet analysis using tools like Wireshark, tcpdump, etc.
Theory:
tcpdump
The fundamental tool of almost all network traffic collection is tcpdump. It is an open-source
application that comes installed on almost all Unix-like operating systems. Tcpdump is an excellent
collection tool and comes complete with a very complex filtering language. It’s essential to know how
to filter the data at collection time to end up with a manageable chunk of data to analyze. Capturing all
data from a network device on even a moderately busy network can create too much data to analyze
efficiently.
In some rare cases, allowing tcpdump to output its capture directly to your screen may be enough to
find what you’re looking for. For example, in writing this article, captured some traffic and noticed that
machine was sending traffic to an IP address . It turns out that machine was sending data to a Google IP
address of 172.217.11.142.
It seems that even when Chrome is not running in the foreground it remains running as a service. it
would not have necessarily noticed this without a packet analysis to tip me off. it re-captured some
more tcpdump data but this time told tcpdump to write the data to a file that itopened in Wireshark
(more on that later). Here’s that entry:
Tcpdump is a favorite tool among sysadmins because it is a command-line tool. This means that it
doesn’t require a full-blown desktop to run. It is unusual for production servers to provide a desktop
because of the resources that would take, so command-line tools are preferred. As with many advanced
tools, tcpdump has a very rich and arcane language that takes some time to master.
Key Features:
Command line tool
Packet capture capabilities
Free to use
A few of the very basic commands involve selecting the network interface from which to collect data,
and writing that data to a file so it can be exported for analysis elsewhere. The -i and -w switches are
used for this.
# tcpdump -i eth0 -w tcpdump_packets
tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
^C51 packets captured
This produces a capture file:
file tcpdump_packets
tcpdump_packets: tcpdump capture file (little-endian) - version 2.4 (Ethernet, capture length 262144)
The standard TCP capture file is a pcap file. It is not text so it can only be read by an analysis program
that knows how to read pcap files.
Wireshark
Wireshark is probably the next best-known tool in any sysadmin’s toolkit. It can not only capture data,
but also provides some advanced analysis tools. Adding to its appeal, Wireshark is open source, and has
been ported over to almost every server operating system that exists. Starting life named Ethereal,
Wireshark now runs everywhere, including as a standalone portable app.
If you’re analyzing traffic on a server with a desktop installed, Wireshark can do it all for you. The
collected packets can then be analyzed all in one spot. However, desktops are not common on servers, so
in many cases, you’ll want to capture the network data packets remotely and then pull the resulting pcap
file into Wireshark.
At first launch, Wireshark allows you to either load an existing pcap file, or start capturing. If you elect
to capture network traffic, you can optionally specify filters to pare down the amount of data Wireshark
collects. Since its analysis tools are so good, it’s less important to ensure you surgically identify the data
at collection time with Wireshark. If you don’t specify a filter, Wireshark will simply collect all network
data that your selected interface observes.
One of the most useful tools Wireshark provides is the ability to follow a stream. It’s probably most
useful to think of a stream as an entire conversation. In the screenshot below we can see a lot of data has
been captured, but what is most interested in is that Google IP address. itcan right-click it and Follow the
TCP Stream to see the entire conversation.
If you’ve captured traffic elsewhere, you can import the pcap file using Wireshark’s File -
> Open dialogue. The same filters and tools that can be used for natively captured network data are
available for imported files.
EXPERIMENT-16
Objective: Network simulation using tools like Cisco Packet Tracer, NetSim,
OMNeT++, NS2, NS3, etc
Theory:
Simulation is a very important technology in modern time. Computer assisted simulation can model
hypothetical and real-life objects or activities on a computer to study the well-designed structure. A network
simulator is a system of implementing the network on the computer through which the performance of the network
is calculated. The computer assisted simulation technologies are applied in the simulation of networking
algorithms. The functional network field is narrower than general simulation and it is natural that more specific
requirements will be placed on network simulations.
Network simulator allows the researchers to test the scenarios that are difficult or expensive to simulate in
real world.Design of various network topologies using nodes, hosts, hubs, bridges, routers and mobile units etc. is
possible. The network simulators are of various types which can be compared on the basis of: range (simple to the
complex), specification of nodes, links and traffic between the nodes. Specifying about the protocols used to handle
traffic in a network, user friendly applications (allow users to easily visualize the simulated environment.), text-
based applications (permit more advanced forms of customization) and programming-oriented tools (providing a
programming framework that customizes to create an application that simulates the networking environment to be
tested).
Network simulators are used by people from different areas such as academic researchers, industrialized
sectors and Quality Assurance (QA) to design, simulate and analyze the performance of different network
protocols. They can also be used to evaluate the outcome of the different parameters of the protocols being studied.
Normally a network simulator comprises ofwide range of networking technologies and protocols that help users
to build complex networks from basic building blocks like clusters of nodes and links. With their help, different
network topologies can be designed using various types of nodes such as end-hosts, network bridges, routers, hubs,
optical link-layer devices and mobile units.
Simulation of networks is a very difficult task. For example, if blocking is high, then evaluation of the
average occupancy is challenging because of high variance. To evaluate the probability of buffer overflow in a
network, the time required for a precise answer can be enormously large. Techniques like "control variants" and
“sampling" have been developed to speed simulation.
A typical simulator encompasses a wide range of networking technologies and can help the users to build
complex networks from basic building blocks such as selection of nodes and links. Various types of nodes in
Hierarchical networks resembling computers, hubs, bridges, routers, links, switches mobile units etc can be
designed with the help of simulators.
Various types of Wide Area Network (WAN) technologies like TCP, ATM, IP etc. and Local Area
Network (LAN) technologies like Ethernet, token rings etc., can be imitated with a simulator and the user can
examine various standard resultsapart from devising some novel protocol or routing strategy. Network simulators
are widely used to simulate battlefield networks in Network-centric warfare.
There are ample varieties of simulators, ranging from simple to complex. A simple simulator must enable
a user to represent network topology, to specify nodes on the network, the links and the traffic between the nodes.
More complex systems may permit the user to specify everything about the protocols used to handle traffic in a
network. User friendly applications permit users to envision easily the working mechanism of their simulated
situation. Text-based applications offer a less sensitive interface, but permits more advanced forms of
customization.
Overview of Network Simulators
Currently there are many network simulators that have different features in different aspects. Short lists
of the current network simulators include NS-2, NS-3, OPNET, OMNeT++, NETSIM, QualNet, and J-Sim. These
network simulators are selected for discussion regarding their features, advantages and restrictions.
NS2
The Ns2 is a discrete event simulator targeted at packet level networking research and provides
substantial support to simulate group of protocols like TCP, UDP, FTP and HTTP. It comprises of two
simulation tools. Ns-2 is primarily UNIX basedand fully simulates a layered wire or wireless network
from the physical radio transmission channel to high-level applications. The simulator is written in C++
and a script language called OTcl.
C++: C++ is fast to run but slower to change, making it suitable for detailed protocol implementation.
Otcl: OTcl runs much slower but can be changed very quickly (and interactively), making it ideal
for simulation configuration. Ns provides glue to make objects and variables appear on both languages.
NS2 uses an OTcl interpreter by which the user writes an OTcl script that defines the network,
(number of nodes and links) the transaction in the network (sources destinations, type of traffic) and the
type of protocols used. The outcome of the simulation is a trace file that can be used for data processing
(calculate delay, throughput etc). To visualize the simulation, a program called Network Animator
(NAM) is used. It visualizes the packets as they propagate throughout the network. The ns- 2 simulator
has numerous features that make it suitable for our simulations.
Advantages:
1. NS2 has large number of available models, realistic mobility models, powerful and flexible scripting
and simulation setup, large user community and ongoing development.
2. NS2 provides an easy traffic and movement pattern by including an efficient energy model.
3. It provides a set of randomized mobility model and there are several projects to bring advanced
mobility models to the simulators.
4. Complex scenarios can be easily tested.
5. Popular for its modularity.
Limitations:
1. NS2 needs to be recompilation every time if there is a change in the user code.
2. Real system is too complex to model i.e. complicated infrastructure.
NS3
The ns-3 simulator is a discrete-event network simulator for Internet systems, targeted primarily
for research and learning purpose. The ns-3 project, started in 2006, is open-source free software, licensed
under the GNU GPLv2 license. It will rely on the current contributions of the community to develop new
models, debug or maintain the existing ones, and share the results. Ns3 is mainly used on LINUX systems
and not limited to internet based systems alone.
C++: implementation of simulation and core model.Ns-3 is built as a library which may be statically
or dynamically linked to a C++ main program. These libraries describe the beginning of simulation and
their topology.
Python: C++ wrapped by Python. Python programs to import an “ns3” module. The features of NS3 simulator
are given below.
Advantages:
1. High modularity than its ancestor NS2.
2. Support simulation for TCP, UDP, ICMP, IPv4, multicast routing, P2P and CSMA protocols.
3. Support for ported code should make model validation easier and more credible.
4. Much more flexible than any other simulators.
5. Wide range of use in both optimization and expansion of the existing networks.
Limitations:
1. NS3 still suffers from lack of credibility.
2. NS3 is intended to replicate the successful mode of NS2 in which various organizations contributed to
the models and components based on the framework of NS2.
3. NS3 needs a lot of specialized maintainers in order to avail the merits of NS3 as the commercial
OPNET networksimulators.
4. Active maintainers are required to respond to the user questions, bug reports and help to Test & validate
the system.
OMNET++
It is a component-based, modular and open architecture discrete event simulator framework. The
most common use of OMNeT++ is for simulation of networks, but it is also used for queuing network
simulations and other areas as well. It is licensed under its own Academic Public License, which permits
GNU Public License like freedom but only in noncommercial settings. It provides component
architecture for models.
C++: The C++ class library comprises of simulation kernel and utility classes (for random number
generation, statistics collection, topology discovery etc) -- this one is used to create simulation
components (simple modules and channels); infrastructure to assemble simulations from these
components and configure (NED language, ini files); runtime user interfaces or environments for
simulations (Tkenv, Cmdenv); an Eclipse-based simulation IDE for designing, running and evaluating
simulations; extension interfaces for real-time simulation, emulation, MRIP, parallel distributed
simulation, database connectivity and so on.
The OMNeT++ components include:
NETSIM
NetSim is a discrete event simulator developed by Tetcos in 1997, in association with Indian
Institute of Science. It has also been featured with Computer Networks and Internets V edition by Dr.
Douglas Comer, published by Prentice Hall. It has an object-oriented system simulating environment to
support simulation and analysis of voice and data communication scenarios for High Frequency Global
Communication Systems (HFGCS).
Java: It creating fast, platform independent software that could be used in simple, consumer electronic
products. Java designed for simple, efficient, platform-independent program for creating WWW-based
programs. Using Java one can create small programs called applets that are entrenched into an HTML
document and viewable on any Java-compatible browser. Java applets are compiled into a set of byte-
codes, or machine-independent processing instructions.
Features:
NetSim modeling and simulation are supported for Aloha, Slotted Aloha, Token Ring/Bus, Ethernet
CSMA/CD, Fast Ethernet, WLAN - IEEE 802.11 a/b/g/n and e, X.25, Frame Relay, TCP, UDP, IPv4
and IPv6, Routing - RIP, OSPF, BGP,MPLS, MANET, GSM, CDMA, Wire-less Sensor Network,
Zigbee, Cognitive radio)[5].
It simulates a wide variety of Cisco routers, including 2500 series, 2600 series, 2800 series, and 3600
series, as well asthe Cisco Catalyst 1900 series, 2900 series, and 3500 series switches. Protocol libraries
are available as open C code for user modification. This can help to avoid the time consuming process
such as encoding, customization and configuring commercial simulators to meet customer specific needs.
Along with the Boson Virtual Packet Technology engine NetSim utilizes Boson’s proprietary Router &
Simulator EROUTER software technologies, to produce individual packets. These packets are routed
and switched through the simulated network, allowing the simulator to build an appropriate virtual
routing table and simulate proper networking. Other simulation products on the market do not support
this level of functionality.
It can be used to create a simulation of the topology of corporate network and help practice trouble-
shooting without using devices on the production network.
Advantages:
1. NetSim has a GUI which features drag and drop functionality for devices, links etc. i.e. Modeling in
NetSim is simple and user friendly.
2. It has a built in analysis framework that provides intra and inter-protocol performance comparison
with graphical options.
3. Data packet and control packet flow can be visual-ized through NetSim built-in packet animator.
4. It is easy to learn all about NetSim.
Limitations:
1. NetSim is a single process discrete event simulator. A single event queue is used for the simulation
which at any given time contains one entry for each station on the network.
2. Free version of NetSim is not available.
Cisco Packet Tracer
Cisco Packet Tracer is a powerful network simulation program that allows students to experiment with
network behavior and ask “what if” questions. As an integral part of the Networking Academy
comprehensive learning experience, Packet Tracer provides simulation, visualization, authoring,
assessment, and collaboration capabilities to facilitate the teaching and learning of complex technology
concepts.
Packet Tracer supplements physical equipment in the classroom by allowing students to create a network
with an almost unlimited number of devices, encouraging practice, discovery, and troubleshooting. The
simulation-based learning environment helps students develop 21st century skills such as decision
making, creative and critical thinking, and problem solving. Packet Tracer complements the Networking
Academy curricula, allowing instructors to easily teach and demonstrate complex technical concepts and
networking systems design. Instructors can customize individual or multiuser activities, providing hands-
on lessons for students that offer value and relevance in their classrooms. Students can build, configure,
and troubleshoot networks using virtual equipment and simulated connections, alone or in collaboration
with other students. Packet Tracer offers an effective, interactive environment for learning networking
concepts and protocols. Most importantly, Packet Tracer helps students and instructors create their own
virtual “network worlds” for exploration, experimentation, and explanation of networking concepts and
technologies.
Packet Tracer’s drag-and-drop interface allows students to configure and validate system
architecture
Key Features Packet Tracer Workspaces:
Cisco Packet Tracer has two workspaces—logical and physical. The logical workspace allows users to
build logical network topologies by placing, connecting, and clustering virtual network devices. The
physical workspace provides a graphical physical dimension of the logical network, giving a sense of
scale and placement in how network devices such as routers, switches, and hosts would look in a real
environment. The physical view also provides geographic representations of networks, including multiple
cities, buildings, and wiring closets.