NL-Assignment No 2 - AY2023-2024
NL-Assignment No 2 - AY2023-2024
Assignment No 02
Lab Outcomes (LO):
LO1 Analyze network administration commands and examine their use in different network
LO2 Make use of network simulation concept to implement a network topology on the basis
LO3 Build different network scenarios using NS2 to measure their performance behaviour.
LO4 Develop client server architecture with the help of socket programming.
LO5 Analyze the traffic flow of various connectionless and connection-oriented protocols.
LO6 Design a network for the given scenario using cisco packet tracer.
Answer:
Client Program:
#include<sys/types.h>
#include<sys/socket.h>
#include<stdio.h>
#include<netinet/in.h>
#include <unistd.h>
#include<string.h>
#include<strings.h>
#include <arpa/inet.h>
void main()
{
int b,sockfd,sin_size,con,n,len;
//char buff[256];
char operator;
int op1,op2,result;
if((sockfd=socket(AF_INET,SOCK_STREAM,0))>0)
printf("socket created sucessfully\n");
//printf("%d\n", sockfd);
struct sockaddr_in servaddr;
servaddr.sin_family=AF_INET;
servaddr.sin_addr.s_addr=inet_addr("127.0.0.1");
servaddr.sin_port=6006;
write(sockfd,&operator,10);
write(sockfd,&op1,sizeof(op1));
write(sockfd,&op2,sizeof(op2));
read(sockfd,&result,sizeof(result));
printf("Operation result from server=%d\n",result);
close(sockfd);
}
Server Program:
#include<sys/types.h>
#include<sys/socket.h>
#include<stdio.h>
#include<netinet/in.h>
#include <unistd.h>
#include<string.h>
#include <arpa/inet.h>
void main()
{
int b,sockfd,connfd,sin_size,l,n,len;
char operator;
int op1,op2,result;
if((sockfd=socket(AF_INET,SOCK_STREAM,0))>0)
printf("socket created sucessfully\n"); //socket creation
servaddr.sin_family=AF_INET;
servaddr.sin_addr.s_addr=inet_addr("127.0.0.1");
servaddr.sin_port=6006;
//printf("%d\n",b);
write(connfd,&result,sizeof(result));
close(sockfd);
}
Q.2 Select appropriate system call which results in the sending of SYN packets? (BL3-LO4)
(A) socket
(B) bind
(C) listen
(D) connect
Answer (D)
socket () creates a new socket of a certain socket type, identified by an integer number, and allocates
system resources to it.
bind () is typically used on the server side, and associates a socket with a socket address structure, i.e. a
specified local port number and IP address.
listen () is used on the server side, and causes a bound TCP socket to enter listening state.
connect () is used on the client side, and assigns a free local port number to a socket. In case of a TCP
socket, it causes an attempt to establish a new TCP connection.
When connect () is called by client, following three-way handshake happens to establish the connection
in TCP.
1) The client requests a connection by sending a SYN (synchronize) message to the server.
2) The server acknowledges this request by sending SYN-ACK back to the client.
3) The client responds with an ACK, and the connection is established.
Q.3Apply the concept of routing to write a Tcl script that forms a network consisting of 7
nodes, numbered from 1 to 7, forming a ring topology. The links have a 512Kbps
bandwidth with 5ms delay. Set the routing protocol to DV (Distance vector). Send UDP
packets from node 1 to node 4 with the rate of 100 packets/sec (using default packet size).
Start transmission at 0.01. Bring down the link between node 2 and node 3 at 0.4. Finish
the transmission at 1.000. [BL3, LO3]
Answer: Routing is the process of selecting a path for traffic in a network or between or across
multiple networks. Broadly, routing is performed in many types of networks, including circuit-
switched networks, such as the public switched telephone network (PSTN), and computer
networks, such as the Internet.
#Simulation program to genrate coneection oriented and connectionless trafic over given
network which uses static and dynamic routing.
close $nr
exec nam apsit.nam &
exit 0
}
#Create nodes by using looping constructs.
for { set i 1 } { $i < 8} { incr i 1 } {
set n($i) [$ns node]}
#Create links between the nodes
Q.4 Apply the fundamentals of (TCP)Connection Oriented and Connectionless (UDP) traffic to
develop given network topology by using NS2. [BL3, LO3]
The network consists of five nodes n0 to n4. In this scenario, node n0 sends constant bit-rate (CBR) traffic
to node n3(connectionless), and node n1 transfers data to node n4 using a file transfer protocol
(FTP)(connection oriented). These two carried traffic sources are carried by transport layer protocols User
Datagram Protocol (UDP) and Transmission Control Protocol (TCP), respectively. In NS2, the transmitting
object of these two protocols are a UDP agent and a TCP agent, while the receivers are a Null agent and a
TCP sink agent, respectively.
Sender Receiver
Answer:
Tcl script:
proc finish {} {
global ns nr nf
$ns flush-trace
close $nr
close $nf
exit 0
$ns run
Q.5 (A) Identify phase/phases of Connection Oriented Protocol from following snippet NS2
Simulation Trace file? Justify your answer. [BL3, LO2]
Answer: Connection Oriented Protocol service involves three phases, Connection setup phase, Data
transfer phase and Connection release phase.
In given snippet of NS2 simulation trace file two phases are involved i.e. Connection setup phase and Data
transfer phase. Since, third record represents packet has been sent from node0 to node1 having packet size
40, sequence no and packet_id 0 as a SYN packet to establish connection. Sixth record represents
acknowledgment for SYN packet sent from node1 to node 0 having sequence no 0 and packet_id 1. Here
connection established successfully in between node0 and node1.
Hereafter data packets has been sent from node0 to node1 having packet size 1040 that means after
connection setup data gets transferred in between node0 and node1.
Q.5 (B) Make use of following snippet of NS2 Simulation Trace file to identify no. of segments
transferred from Source node 0 to Destination node 1 of Simulation. [BL3, LO2]
(A) 4
(B) 3
(C) 2
(D) 1
Answer: (B)
Explanation: A TCP segment consists of data bytes to be sent and a header that is added to the data by TCP.
Above trace file has three records having their packet size 1040bytes that means packet consist of data as
well as header. That means total three segments have transferred from Source node 0 to Destination node
1. Other packet transmitted in between Source node0 to Destination node1 is to establish connection.