Comm Networks Lab
Comm Networks Lab
Prepared by Approved by
D.Vinod HoD-CSE
1
PROGRAM OUTCOMES (POs)
2
effective reports and design documentation, make effective presentations, and give and receive clear
instructions.
11. Project management and finance: Demonstrate knowledge and understanding of the
engineering management principles and apply these to one’s own work, as a member and leader in a
team, to manage projects and in multidisciplinary environments.
12. Life-long learning: Recognize the need for and have the preparation and ability to engage in
independent and lifelong learning in the broadest context of technological change.
PSO1. Analyze and design the analog and digital circuits or systems for a given specification and
function.
PSO2. Implement functional blocks of hardware-software co-designs for signal processing and
communication applications.
PSO3. Design, develop and test electronic and embedded systems for applications with real t ime
constraint and to develop managerial skills with ethical behavior to work in a sustainable environment.
3
INSTRUCTIONS TO STUDENTS FOR WRITING THE RECORD
In the record, the index page should be filled properly by writing the corresponding
experiment number, experiment name , date on which it was done and the page number.
1. Title: The title of the experiment should be written in the page in capital letters.
2. In the left top margin, experiment number and date should be written.
6. Procedure: Steps for doing the experiment and recording the readings should be briefly
described(flow chart/ Circuit Diagrams / programs in the case of computer/processor related
experiments)
7. Results: The results of the experiment must be summarized in writing and should be
fulfilling the aim.
a) Circuit/Program: Neatly drawn circuit diagrams for the experimental set up.
b) Design: The design of the circuit components for the experimental set up for
selecting the components should be clearly shown if necessary.
3. Observations:
iii) Relevant calculations should be shown. If repetitive calculations are needed, only show a
sample calculation and summarize the others in a table.
4
EC8563 COMMUNICATION NETWORKS LABORATORY LTPC
0 0 4 2
LIST OF EXPERIMENTS:
1. Implementation of Error Detection / Error Correction Techniques
2. Implementation of Stop and Wait Protocol and sliding window
3. Implementation and study of Goback-N and selective repeat protocols
4. Implementation of High Level Data Link Control
5. Implementation of IP Commands such as ping, Traceroute, nslookup.
6. Implementation of IP address configuration.
7. To create scenario and study the performance of network with CSMA / CA protocol and compare
with CSMA/CD protocols.
8. Network Topology - Star, Bus, Ring
9. Implementation of distance vector routing algorithm
10. Implementation of Link state routing algorithm
11. Study of Network simulator (NS) and simulation of Congestion Control Algorithms using NS
12. Implementation of Encryption and Decryption Algorithms using any programming language
TOTAL: 60 PERIODS
5
Course outcomes
Students will demonstrate skills to understand the given scenario and analyze the
CO2
performance of various protocols.
Students able to implement various routing algorithms so that all available links
CO 3
will be utilized effectively
Students will show the ability to derive various encryption and decryption
CO 4
algorithms.
Students shows skills to implement Stop and Wait, Go back N and Selective
CO 5
Repeat protocols..
6
S.NO LIST OF EXPERIMENTS PAGE NO.
1.a TCP Socket Program In Java For Chat Server And Client 8
1.b TCP Socket Program In Java For Chat Server And Client 12
7
EX.NO.1.a TCP SOCKET PROGRAM IN JAVA FOR CHAT SERVER AND CLIENT
AIM:
To develop a chat server and client program in Java using TCP socket.
ALGORITHM:
SERVER:
1. Create a server socket.
2. Wait for client to be connected.
3. Read client’s message and display it.
4. Get a message from user and send it.
5. Repeat step 3-4 until the client end.
6. Close the stream.
7. Close the server and client socket.
8. Stop.
CLIENT:
1. Create the client socket and establish connection with server.
2. Get a message from user and send it to server.
3. Read all inputs / outputs stream.
4. Close the client socket.
5. Stop.
Client Program
import java.io.*;
import java.net.*;
public class chatclient
{
public static void main (String args[]) throws Exception
{
8
Socket sock = new Socket("172.16.15.19",3000);
BufferedReader KeyRead = new BufferedReader(new InputStreamReader(System.in));
OutputStream ofstream = sock.getOutputStream();
PrintWriter pwrite = new PrintWriter(ofstream,true);
InputStream istream=sock.getInputStream();
BufferedReader receivedread=new BufferedReader(new InputStreamReader(istream));
System.out.println("client ready for chatting");
String receivemessage,sendmessage;
while(true)
{
sendmessage=KeyRead.readLine();
pwrite.println(sendmessage);
System.out.flush();
if((receivemessage=receivedread.readLine())!=null)
{
System.out.println(receivemessage);
}
}
}
}
Server Program
import java.io.*;
import java.net.*;
public class chatserver
{
public static void main(String args[])throws Exception
{
ServerSocket sersock=new ServerSocket(3000);
System.out.println("Server ready for chatting");
Socket sock=sersock.accept();
BufferedReader KeyRead = new BufferedReader(new InputStreamReader(System.in));
9
OutputStream ofstream=sock.getOutputStream();
PrintWriter pwrite=new PrintWriter(ofstream,true);
InputStream istream=sock.getInputStream();
BufferedReader receivedread = new BufferedReader(new InputStreamReader(istream));
String receivemessage,sendmessage;
while(true)
{
if((receivemessage = receivedread.readLine())!=null)
{
System.out.println(receivemessage);
}
sendmessage=KeyRead.readLine();
pwrite.println(sendmessage);
System.out.flush();
}
}
}
10
Output:
Result:
Thus the TCP chat server and client is performed using Java.
11
TCP SOCKET PROGRAM IN JAVA TO DISPLAY SYSTEM
EX.NO.1.b
SYSTEM CONFIGURATION
AIM:
To develop client server model in Java using TCP socket to display current systems date, time
and IP address.
ALGORITHM:
SERVER:
1. Create a socket.
2. Bind the socket to an address.
3. Listen for connection
4. Accept a connection.
5. Send and receive data.
CLIENT:
TCPDATECLIENT.JAVA
import java.net.*;
import java.io.*;
class tcpdateclient
{
public static void main(String args[])
{
Socket soc;
BufferedReader dis;
String sdate;
PrintStream ps;
try
{
InetAddress ia=InetAddress.getLocalHost();
if(args.length==0)
12
soc=new Socket(InetAddress.getLocalHost(),4444);
else soc=new Socket(InetAddress.getByName(args[0]),4444);
dis=new BufferedReader(new InputStreamReader(soc.getInputStream()));
sdate=dis.readLine();
System.out.println("the date and time on server is :"+sdate);
ps=new PrintStream(soc.getOutputStream());
ps.println(ia);
ps.close();
}
catch(IOException e)
{
System.out.println("the exception is"+e);
}
}
}
TCPDATESERVER.JAVA
import java.net.*;
import java.io.*;
import java.util.*;
class tcpdateserver
{
public static void main(String args[])
{
ServerSocket ss=null;
Socket cs;
PrintStream ps;
BufferedReader dis;
String inet;
try
{
ss=new ServerSocket(4444);
System.out.println("press ctrl+c to quit");
while(true)
{
cs=ss.accept();
ps=new PrintStream(cs.getOutputStream());
Date d=new Date();
ps.println(d);
dis=new BufferedReader(new InputStreamReader(cs.getInputStream()));
13
inet=dis.readLine();
System.out.println("client system IP address is:"+inet);
ps.close();
dis.close();
}}
catch(IOException e)
{
System.out.println("the ecxeption is"+e);
}}}
14
OUTPUT:
RESULT:
Thus the socket program for displaying current date, time and IP address is
implemented successfully.
15
EX NO:2 UDP SOCKET PROGRAM IN ‘C’ FOR FILE TRANSFER
AIM:
To develop UDP client and server model in ‘c’ to transfer a text file.
ALGORITHM:
SERVER:
1. Declare the variable and structure for a server datagram socket using socket using socket
function.
2. Bind the local IP address to the port number using bind function.
3. Specify the number of client that the server can connect using listen function.
4. After accepting,receive the message sent by the client using recv function.
5. The characters are fetched from file using ‘fopen’ and ‘fgetc’ function.
6. Then send the characters to the client using ‘send’ function.
7. Close the server socket and connection socket.
CLIENT:
Client
#include<sys/socket.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
main()
{
struct sockaddr_in cli,serv;
16
int sockfd,len;
char msg[50],rec[100];
sockfd=socket(AF_INET,SOCK_DGRAM,0);
cli.sin_family=AF_INET;
cli.sin_port=3261;
cli.sin_addr.s_addr=INADDR_ANY;
printf("enter the file name");
scanf("%s",msg);
sendto(sockfd,msg,sizeof(msg),0,(struct sockaddr *)&cli,sizeof(struct sockaddr));
printf("the received file content is"); len=sizeof(struct
sockaddr); recvfrom(sockfd,rec,sizeof(rec),0,(struct
sockaddr*)&cli,&len); printf("%s",rec);
close(sockfd);
}
Server
#include<sys/socket.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
main()
{
struct sockaddr_in serv,cli;
int sockfd,len,i=0;
char rec[50],ch[50];
FILE *fp;
sockfd=socket(AF_INET,SOCK_DGRAM,0);
serv.sin_family=AF_INET;
serv.sin_port=3261;
17
serv.sin_addr.s_addr=INADDR_ANY;
bind(sockfd,(struct sockaddr*)&serv,sizeof(struct sockaddr));
listen(sockfd,5); len=sizeof(struct sockaddr);
recvfrom(sockfd,rec,sizeof(rec),0,(structsockaddr*)&cli,&len);
printf("the file name is\n");printf("%s\n",rec);
fp=fopen(rec,"r");
if(fp==NULL)
{
printf("error");
exit(0);
}
while(fgets(ch,50,fp)!=NULL)
{
printf("%s",ch);
}
fcloseall();
sendto(sockfd,ch,sizeof(ch),0,(struct sockaddr*)&cli,sizeof(struct sockaddr));
close(sockfd);
}
18
Out put:
server:
[root@Localhost~]# cc su.c
[root@Localhost~]#./a.out
Test.txt
Hi,welcome.
Client:
[root@Localhost~]# cc cu.c
[root@Localhost~]#./a.out
Test.txt
Hi,welcome.
RESULT:
Thus the client server model using UDP socket has been developed successfully for File
Transfer.
19
EX. No. 3 PING COMMAND PROGRAM USING JAVA
AIM:
ALGORITHM:
PROGRAM:
import java.io.*;
import java.net.*;
class pingTest {
String ip = "127.0.0.1";
try {
Runtime r = Runtime.getRuntime();
Process p = r.exec(pingCmd);
InputStreamReader(p.getInputStream()));
String inputLine;
System.out.println(inputLine);
20
pingResult += inputLine;
in.close();
} catch (IOException e) {
System.out.println(e);
21
Output:
Result:
22
IMPLEMENTATION OF SLIDING WINDOW PROTOCOL USING
EX. NO. 4
JAVA
AIM:
To write a JAVA program to simulate a sliding window protocol that uses Selective Repeat
ARQ.
ALGORITHM:
SERVER:
CLIENT:
SENDER:
import java.net.*;
import java.io.*;
import java.rmi.*;
public class slidsender
23
{
Socket s=ser.accept();
PrintStream p;
int sptr=0,sws=8,nf,ano,i;
String ch;
do
p=new PrintStream(s.getOutputStream());
nf=Integer.parseInt(in.readLine());
p.println(nf);
if(nf<=sws-1)
for(i=1;i<=nf;i++)
sbuff[sptr]=in.readLine();
p.println(sbuff[sptr]);
sptr=++sptr%8;
24
}
sws-=nf;
System.out.print("Acknowledgment received");
ano=Integer.parseInt(in1.readLine());
sws+=nf;
else
break;
ch=in.readLine(); p.println(ch);
while(ch.equals("yes"));
s.close();
RECEIVER:
import java.net.*;
import java.io.*;
class slidreceiver
25
{
ch; System.out.println(); do
nf=Integer.parseInt(in.readLine());
if(nf<=rws-1)
for(i=1;i<=nf;i++)
{ rptr=++rptr%8;
rbuf[rptr]=in.readLine();
rws-=nf;
System.out.println("\nAcknowledgment sent\n");
p.println(rptr+1); rws+=nf; }
else break;
ch=in.readLine();
26
while(ch.equals("yes"));
27
OUTPUT:
RESULT:
Thus the program for sliding window protocol was implemented successfully.
28
EX. NO : 5 IMPLEMENTATION OF STOP & WAIT PROTOCOL
AIM
To implement the stop and wait protocol using Java .
PROCEDURE
Sender
Step1: sequence 0
Step2: Accept new packet and assign sequence to it.
Step3: Send packet sequence with sequence number sequence.
Step4: Set timer for recently sent packets.
Step5: If error free acknowledgment from receiver and NextFrameExpected -> sequence
then sequence NextFrameExpected.
Step6: If time out then go to step3.
Step7: Stop.
Receiver
Step1: Start.
Step2: NextFrameExpectedß 0, repeat steps 3 forever.
Step3: If error-free frame received and sequence= NextFrameExpected, then pass packet to higher
layer and NextFrameExpectedß NextFrameExpected+1(modulo 2).
Step4: Stop.
Sender.java
import java.io.*;
import java.net.*;
Socket sender;
ObjectOutputStream out;
ObjectInputStream in;
29
int n,i=0,sequence=0;
Sender(){}
try{
sequence=0;
out=new ObjectOutputStream(sender.getOutputStream());
out.flush();
in=new ObjectInputStream(sender.getInputStream());
str=(String)in.readObject();
packet=br.readLine();
n=packet.length();
do{
try{
if(i<n){
msg=String.valueOf(sequence);
msg=msg.concat(packet.substring(i,i+1));
}else if(i==n){
msg="end";out.writeObject(msg);break;
}out.writeObject(msg);
sequence=(sequence==0)?1:0;
30
out.flush();
System.out.println("data sent>"+msg);
ack=(String)in.readObject();
if(ack.equals(String.valueOf(sequence))){
i++;
}else{
sequence=(sequence==0)?1:0;
}}catch(Exception e){}
}while(i<n+1);
}catch(Exception e){}
finally{
try{
in.close();
out.close();
sender.close();
catch(Exception e){}
}}
s.run();
31
}}
Receiver.java
import java.io.*;
import java.net.*;
ServerSocket reciever;
Socket connection=null;
ObjectOutputStream out;
ObjectInputStream in;
String packet,ack,data="";
int i=0,sequence=0;
Receiver(){}
try{
connection=reciever.accept();
sequence=0;
out=new ObjectOutputStream(connection.getOutputStream());
out.flush();
in=new ObjectInputStream(connection.getInputStream());
out.writeObject("connected .");
32
do{ try{
packet=(String)in.readObject();
if(Integer.valueOf(packet.substring(0,1))==sequence){
data+=packet.substring(1);
sequence=(sequence==0)?1:0;
System.out.println("\n\nreceiver >"+packet);
else
}if(i<3){
out.writeObject(String.valueOf(sequence));i++;
}else{
out.writeObject(String.valueOf((sequence+1)%2));
i=0;
}}
catch(Exception e){}
}while(!packet.equals("end"));
System.out.println("Data recived="+data);
}catch(Exception e){}
finally{
try{in.close();
out.close();
33
reciever.close();
catch(Exception e){}
}}
while(true){
s.run();
34
.
.
RESULT:
AIM:
ALGORITHM:
PROGRAM:
#include<stdio.h>
#include<string.h>
void encrypt(char password[],int key)
{
unsigned int i;
for(i=0;i<strlen(password);++i)
{
password[i]=password[i]-key;
}
}
void decrypt(char password[],int key)
{
unsigned int i;
for(i=0;i<strlen(password);++i)
{
password[i]=password[i]+key;
}
.
}
int main()
{
char password[20];
printf("enter the password:\n");
scanf("%s",password);
printf("password=%s\n",password);
encrypt(password,0xFACA);
printf("encrypted value=%s\n",password);
decrypt(password,0xFACA);
printf("Decrypted value=%s\n",password);
return(0);
}
.
OUTPUT:
RESULT:
Thus the encryption and decryption of a data was executed successfully using ‘C’.
.
AIM:
ALGORITHM:
1. Initialize the variables.
2. Enter the string of bits.
3. Insert a flag value.
4. Insert a zero at the beginning and end of each flag value
PROGRAM:
#include<stdio.h>
#include<string.h>
main()
{
int i,j,count=0,nl;
char str[100];
printf("enter the bit string:");
gets(str);
for(i=0;i<strlen(str);i++)
{ count=0;
for(j=i;j<=(i+5);j++)
{
if(str[j]=='1')
{
count++;
}
}
if(count==6)
.
{
nl=strlen(str)+2;
for(;nl>=(i+5);nl--)
{
str[nl]=str[nl-1];
}
str[i+5]='0';
i=i+7;
}
}
puts(str);
}
.
OUTPUT:
000111110001
RESULT:
Thus the high level data link program was executed successfully.
.
AIM:
ALGORITHM:
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
char data[5];
int encoded[8],edata[7],syndrome[3];
int hmatrix[3][7] = {
1,0,0,0,1,1,1,
0,1,0,1,0,1,1,
0,0,1,1,1,0,1
};
char gmatrix[4][8]={"0111000","1010100","1100010","1110001"};
int main(){
int i,j;
scanf("%s",data);
printf("\nGenerator matrix\n");
for(i=0;i<4;i++)
printf("%s\n",gmatrix[i]);
printf("\nEncoded data ");
for(i=0;i<7;i++)
{
for(j=0;j<4;j++)
encoded[i]+=((data[j]-'0')*(gmatrix[j][i]-'0'));
encoded[i]=encoded[i]%2;
printf("%d ",encoded[i]);
}
printf("\nHamming code----- Decoding\n");
printf("Enter encoded bits as recieved : ");
for(i=0;i<7;i++)
scanf("%d",&edata[i]);
for(i=0;i<3;i++)
{
for(j=0;j<7;j++)
syndrome[i]+=(edata[j]*hmatrix[i][j]);
syndrome[i]=syndrome[i]%2;
}
for(j=0;j<7;j++)
if((syndrome[0]==hmatrix[0][j]) && (syndrome[1]==hmatrix[1][j])&&
(syndrome[2]==hmatrix[2][j]))
break;
if(j==7)
printf("\nError free\n");
else
{
printf("\nError recieved at bit number %d of data\n",j+1);
.
edata[j]=!edata[j];
printf("\nCorrect data should be : ");
for(i=0;i<7;i++)
printf("%d",edata[i]);
} getch();
return 0;
}
.
OUTPUT:
.
RESULT:
Thus the program for High Level Data Link was implemented successfully.
.
INTRODUCTION
The network simulator is discrete event packet level simulator.The network simulator covers a
very large number of applications of different kind of protocols of different network types consisting
of different network elements and traffic models. Network simulator is a package of tools that
simulates behavior of networks such as creating network topologies, log events that happen under any
load, analyze the events and understand the network. Well the main aim of our first experiment is to
learn how to use network simulator and to get acquainted with the simulated objects and understand
the operations of network simulation and we also need to analyze the behavior of the simulation object
using network simulation.
Initialization
To start a new simulator we write
1. set ns [new Simulator]
From the above command we get that a variable ns is being initialized by using the set command. Here
the code [new Simulator] is a instantiation of the class Simulator which uses the reserved word 'new'.
So we can call all the methods present inside the class simulator by using the variable ns.
In the above we create a output trace file out.tr and a nam visualization file out.nam. But in the Tcl
script they are not called by their names declared,while they are called by the pointers initialized for
them such as tracefile1 and namfile1 respectively.The line which starts with '#' are commented.The
next line opens the file 'out.tr' which is used for writing is declared 'w'.The next line uses a simulator
method trace-all by which we will trace all the events in a particular format.
The termination program is done by using a 'finish' procedure
In the above the word 'proc' is used to declare a procedure called 'finish'.The word 'global' is used to
tell what variables are being used outside the procedure.
'flush-trace' is a simulator method that dumps the traces on the respective files.the command 'close' is
used to close the trace files and the command 'exec' is used to execute the nam visualization.The
command 'exit' closes the application and returns 0 as zero(0) is default for clean exit.
Thus the entire operation ends at 125 seconds.To begin the simulation we will use the command
.
So we are creating a bi-directional link between n0 and n2 with a capacity of 10Mb/sec and a
propagation delay of 10ms.
In NS an output queue of a node is implemented as a part of a link whose input is that node to handle
the overflow at the queue.But if the buffer capacity of the output queue is exceeded then the last
packet arrived is dropped and here we will use a 'DropTail' option.Many other options such as
RED(Random Early Discard) mechanism, FQ(Fair Queuing), DRR(Deficit Round Robin),
SFQ(Stochastic Fair Queuing) are available.
So now we will define the buffer capacity of the queue related to the above link
01 #create nodes
02
.
TCP
TCP is a dynamic reliable congestion protocol which is used to provide reliable transport of packets
from one host to another host by sending acknowledgements on proper transfer or loss of packets.Thus
TCP requires bi-directional links in order for acknowledgements to return to the source.
Now we will show how to set up tcp connection between two nodes
52
.
The command 'set tcp [new Agent/TCP]' gives a pointer called 'tcp' which indicates the tcp agent
which is a object of ns.Then the command '$ns attach-agent $n0 $tcp' defines the source node of tcp
connection. Next the command 'set sink [new Agent/TCPSink]' defines the destination of tcp by a
pointer called sink. The next command '$ns attach-agent $n4 $sink' defines the destination node as
n4.Next, the command '$ns connect $tcp $sink' makes the TCP connection between the source and the
destination.i.e n0 and n4.When we have several flows such as TCP, UDP etc in a network. So, to
identify these flows we mark these flows by using the command '$tcp set fid_1'. In the last line we set
the packet size of tcp as 552 while the default packet size of tcp is 1000.
Well here we will learn in how to run a FTP connection over a TCP
53
.
In above,the command 'set ftp [new Application/FTP]' gives a pointer called 'ftp' which indicates the
FTP application.Next, we attach the ftp application with tcp agent as FTP uses the services of TCP.
UDP
The User datagram Protocol is one of the main protocols of the Internet protocol suite.UDP
helps the host to send send messages in the form of datagrams to another host which is present in a
Internet protocol network without any kind of requirement for channel transmission setup. UDP
provides a unreliable service and the datagrams may arrive out of order,appear duplicated, or go
missing without notice. UDP assumes that error checking and correction is either not necessary or
performed in the application, avoiding the overhead of such processing at the network interface level.
Time-sensitive applications often use UDP because dropping packets is preferable to waiting for
delayed packets, which may not be an option in a real-time system.
Similarly,the command 'set udp [new Agent/UDP]' gives a pointer called 'udp' which indicates the udp
agent which is a object of ns.Then the command '$ns attach-agent $n1 $udp' defines the source node of
udp connection. Next the command 'set null [new Agent/Null]' defines the destination of udp by a
pointer called null. The next command '$ns attach-agent $n5 $null' defines the destination node as
n5.Next, the command '$ns connect $udp $null' makes the UDP connection between the source and
the destination.i.e n1 and n5.When we have several flows such as TCP,UDP etc in a network. So, to
identify these flows we mark these flows by using the command '$udp set fid_2
54
.
Constant Bit Rate (CBR) is a term used in telecommunications, relating to the quality of service.When
referring to codecs, constant bit rate encoding means that the rate at which a codec's output data should
be consumed is constant. CBR is useful for streaming multimedia content on limited capacity channels
since it is the maximum bit rate that matters, not the average, so CBR would be used to take advantage
of all of the capacity. CBR would not be the optimal choice for storage as it would not allocate enough
data for complex sections (resulting in degraded quality) while wasting data on simple sections.
In the above we define a CBR connection over a UDP one. Well we have already defined the UDP
source and UDP agent as same as TCP. Instead of defining the rate we define the time interval
between the transmission of packets in the command '$cbr set rate_0.01Mb'. Next, with the help of the
command '$cbr set random _false' we can set random noise in cbr traffic.we can keep the noise by
setting it to 'false' or we can set the noise on by the command '$cbr set random _1'. We can set by
packet size by using the command '$cbr set packetSize_(packetsize).We can set the packet size up to
sum value in bytes.
Scheduling Events
In ns the tcl script defines how to schedule the events or in other words at what time which event will
occur and stop. This can be done using the command
$ns at .
55
.
When we will run the above program in ns then we can can visualize the network in the NAM. But
instead of giving random positions to the nodes, we can give suitable initial positions to the nodes and
can form a suitable topology. So, in our program we can give positions to the nodes in NAM in the
following way
We can also define the color of cbr and tcp packets for identification in NAM.For this we use the
following command
56
.
1. The first field is event.It gives you four possible symbols '+' '-' 'r' 'd'.These four symbols correspond
respectively to enqueued, dequeued, received and dropped.
2. The second field gives the time at which the event occurs
3. The third field gives you the input node of the link at which the event occurs
4. The fourth field gives you the the output node at which the event occurs
5. The fifth field shows the information about the packet type.i.e whether the packet is UDP or TCP
6. The sixth field gives the packet size
7. The seventh field give information about some flags
8. The eight field is the flow id(fid) for IPv6 that a user can set for each flow in a tcl script.It is also used
for specifying the color of flow in NAM display
9. The ninth field is the source address
10. The tenth field is the destination address
11. The eleventh field is the network layer protocol's packet sequence number
12. The last field shows the unique id of packet
57
.
cat out.tr
RESULT:
58
.
AIM:
To simulate a link failure and observe the congestion control algorithm using NS2.
ALGORITHM:
PROGRAM:
proc finish { } {
global ns nr nf
$ns flush-trace
close $nf
close $nr
exit 0 }
59
.
60
.
61
.
$ns run
62
.
OUTPUT:
RESULT:
63
.
AIM:
To simulate and observe traffic route of a network using distance vector routing protocol.
ALGORITHM:
PROGRAM:
$ns rtproto DV
64
.
# Open tracefile
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exit 0
# Create 8 nodes
65
.
66
.
#Schedule events for the CBR agent and the network dynamics
$ns run
67
.
Output:
RESULT:
68
.
AIM:
To simulate and observe traffic route of a network using distance vector routing protocol.
ALGORITHM:
PROGRAM:
69
.
proc finish { } {
global ns nf
$ns flush-trace
close $nf
exit 0
70
.
$ns rtproto DV
$ns at 35 "finish"
$ns run
71
.
OUTPUT:
RESULT:
Thus the Link State Routing algorithm was simulated by using NS2
72
.
AI M
ALGORITHM
5.If your frames reach the server it will send ACK signal to client otherwise it will send NACK signal
to client. 6.Stop the program
SOURCE CODE
import java.io.IOException;
import org.snmp4j.CommunityTarget;
import org.snmp4j.PDU;
import org.snmp4j.Snmp;
import org.snmp4j.Target;
import org.snmp4j.TransportMapping;
import org.snmp4j.event.ResponseEvent;
import org.snmp4j.mp.SnmpConstants;
import org.snmp4j.smi.Address;
import org.snmp4j.smi.GenericAddress;
73
.
public class
Server
for host yahoo.com Request for host cricinfo.com Request for host
youtube.com
Client
80.168.92.140 $ java udpdnsclient Enter the hostname : youtube.com IP Address: Host Not
Found
RESULT
74
Thus the DNA application program was executed.