CN Master Manual Program Final Part 2
CN Master Manual Program Final Part 2
SIMULATION-INTRODUCTION
Network simulation is an important tool in developing, testing and evaluating network protocols.
Simulation can be used without the target physical hardware, making it economical and practical for
almost any scale of network topology and setup. It is possible to simulate a link of any bandwidth and
delay, even if such a link is currently impossible in the real world. With simulation, it is possible to set
each simulated node to use any desired software. This means that meaning deploying software is not an
issue. Results are also easier to obtain and analyse, because extracting information from important points
in the simulated network is as done by simply parsing the generated trace files.
Introduction to NS-2:
NS2 is an open-source simulation tool that runs on Linux. It is a discreet event simulator targeted
at networking research and provides substantial support for simulation of routing, multicast protocols
and IP protocols, such as UDP, TCP, RTP and SRM over wired and wireless (local and satellite)
networks.
Tcl is a very simple programming language and it is a general purpose scripting language. [Interpreter].
Tcl runs on most of the platforms such as Unix, Windows, and Mac. The strength of Tcl is its simplicity.
It is not necessary to declare a data type for variable prior to the usage.
Syntax of TCL
Tcl scripts are made up of commands separated by newlines or semicolons. Commands all have the
same basic form illustrated by the following example:
expr 20 + 10
This command computes the sum of 20 and 10 and returns the result, 30. You can try out this example
and all the others in this page by typing them to a Tcl application such as tclsh; after a command
completes, tclsh prints its result.
Each Tcl command consists of one or more words separated by spaces. In this example there are four
words: expr, 20, +, and 10. The first word is the name of a command and the other words are arguments
to that command. All Tcl commands consist of words,
The expr command treats all of its arguments together as an arithmetic expression, computes the result
of that expression, and returns the result as a string. In the expr command the division into words isn't
significant: you could just as easily have invoked the same command as
expr 20+10
However, for most commands the word structure is important, with each word used for a distinct
purpose.
All Tcl commands return results. If a command has no meaningful result, then it returns an empty string
as its result
Variables
Tcl allows you to store values in variables and use the values later in commands. The set command is
used to write and read variables.
The command returns the new value of the variable. You can read the value of a variable by invoking
set with only a single argument:
Control structures
Tcl provides a complete set of control structures including commands for conditional execution, looping,
and procedures. Tcl control structures are just commands that take Tcl scripts as arguments. The example
below creates a Tcl procedure called power, which raises a base to an integer power:
This script consists of a single command, proc. The proc command takes three arguments: the name of
a procedure, a list of argument names, and the body of the procedure, which is a Tcl script. Note that
everything between the curly brace at the end of the first line and the curly brace on the last line is passed
verbatim to proc as a single argument. The proc command creates a new Tcl command named power
that takes two arguments. You can then invoke power with commands like the following:
power 2 6
power 1.15 5
When power is invoked, the procedure body is evaluated. While the body is executing it can access its
arguments as variables: base will hold the first argument and p will hold the second.
The body of the power procedure contains three Tcl commands: set, while, and return. The while
command does most of the work of the procedure. It takes two arguments, an expression ($p > 0) and
a body, which is another Tcl script.
The while command evaluates its expression argument using rules similar to those of the C
programming language and if the result is true (nonzero) then it evaluates the body as a Tcl script. It
repeats this process over and over until eventually the expression evaluates to false (zero). In this case
the body of the while command multiplied the result value by base and then decrements p.
When p reaches zero the result contains the desired power of base. The return command causes the
procedure to exit with the value of variable result as the procedure's result.
This line declares a new variable as using the set command, you can call this variable as you wish, in
general people declares it as ns because it is an instance of the Simulator class, so an object the code[new
Simulator] is indeed the installation of the class Simulator using the reserved word new. In order to have
output files with data on the simulation (trace files) or files used for visualization (nam files), we need
to create the files using open command:
The above creates a trace file called “out.tr” and a nam visualization trace file called “out.nam”. Within
the tcl script, these files are not called explicitly by their names, but instead by pointers that are declared
above and called “tracefile1”and “namfile” respectively. Remark that they begin with a # symbol. The
second line open the file “out.tr” to be used for writing, declared with the letter “w”. The third line uses
a simulator method called trace-all that have as parameter the name of the file where the traces will go.
The last line tells the simulator to record all simulation traces in NAM input format. It also gives the file
name that the trace will be written to later by the command $ns flush-trace. In our case, this will be the
file pointed at by the pointer “$namfile”, i.e. the file “out.tr”. The termination of the program is done
using a “finish “procedure.
proc finish { } {
global ns tracefile1 namfile
$ns flush-trace
Close $tracefile1
Close $namfile
Exec nam out.nam &
Exit 0
}
The word proc declares a procedure in this case called finish and without arguments. The word global
is used to tell that we are using variables declared outside the procedure. The simulator method “flush-
trace will dump the traces on the respective files. The tcl command “close “closes the trace files defined
before and “exec” executes the nam program for visualization. The command exit will end the
application and return the number 0 as status to the system. Zero is the default for a clean exit. Other
values can be used to say that is a exit because something fails. At the end of ns program, we should
call the procedure “finish “and specify at what time the termination should occur. For example, will be
used to call “finish “at time 125sec.Indeed, the at method of the simulator allows us to schedule events
explicitly. The simulation can then begin using the command
The node is created which is printed by the variable n0. When we shall refer to that node in the script
we shall thus write $n0. Once we define several nodes, we can define the links that connect them. An
example of a definition of a link is:
Which means that $n0 and $n2 are connected using a bi-directional link that has 10ms of propagation
delay and a capacity of 10Mb per sec for each direction. To define a directional link instead of a bi-
directional one, we should replace “duplexlink” by “simplex-link”. In NS, an output queue of a node
is implemented as a part of each link whose input is that node. The definition of the link then includes
the way to handle overflow at that queue. In our case, if the buffer capacity of the output queue is
exceeded then the last packet to arrive is dropped. Many alternative options exist, such as the RED
(Random Early Discard)
Mechanism, the FQ (Fair Queuing), the DRR (Deficit Round Robin), the stochastic Fair Queuing (SFQ)
and the CBQ (which including a priority and a round-robin scheduler). In ns, an output queue of a node
is implemented as a part of each link whose input is that node. We should also define the buffer capacity
of the queue related to each link. An example would be:
Agents and Applications We need to define routing (sources, destinations) the agents (protocols) the
application that use them.
FTP over TCP TCP is a dynamic reliable congestion control protocol. It uses Acknowledgements
created by the destination to know whether packets are well received. There are number variants of the
TCP protocol, such as Tahoe, Reno, NewReno, Vegas. The type of agent appears in the first line: The
command $ns attach-agent $n0 $tcp defines the source node of the tcp connection. The command
defines the behaviour of the destination node of TCP and assigns to it a pointer called sink.
Above shows the definition of a CBR application using a UDP agent The command $ns attach-agent
$n4 $sink defines the destination node. The command $ns connect $tcp $sink finally makes the TCP
connection between the source and destination nodes. TCP has many parameters with initial fixed
defaults values that can be changed if mentioned explicitly. For example, the default TCP packet size
has a size of 1000bytes.This can be changed to another value, say 552bytes, using the command $tcp
set packetSize_ 552. When we have several flows, we may wish to distinguish them so that we can
identify them with different colours in the visualization part. This is done by the command $tcp set fid_
1 that assigns to the TCP connection a flow identification of “1”. We shall later give the flow
identification of “2”to the UDP connection.
CBR over UDP A UDP source and destination is defined in a similar way as in the case of TCP. Instead
of defining the rate in the command $cbr set rate_ 0.01Mb, one can define the time interval between
transmission of packets using the command.
Scheduling Events NS is a discrete event based simulation. The tcp script defines when event should
occur. The initializing command set ns [new Simulator] creates an event scheduler, and events are then
scheduled using the format:
The scheduler is started when running ns that is through the command $ns run. The beginning and end
of the FTP and CBR application can be done through the following command Structure of Trace Files
When tracing into an output ASCII file, the trace is organized in 12 fields as follows in fig shown below,
the meaning of the fields is: Event Time from Nodeto Node PKT Type PKT Size Flags Fid Src Addr
Dest Addr Seq Num Pkt id
1. The first field is the event type. It is given by one of four possible symbols r, +, -, d which
correspond respectively to receive (at the output of the link), enqueued, dequeued and dropped.
2. The second field gives the time at which the event occurs.
3. Gives the input node of the link at which the event occurs.
4. Gives the output node of the link at which the event occurs.
5. Gives the packet type (e.g. CBR or TCP)
6. Gives the packet size
7. Some flags
8. This is the flow id (fid) of IPv6 that a user can set for each flow at the input
OTcl script one can further use this field for analysis purposes; it is also used when specifying
stream color for the NAM display.
$ns at <time><event>
$ns at 0.1 $cbr start
$ns at 1.0 $ftp start
$ns at 124.0 $ftp stop
$ns at 124.5 $cbr stop
NS2 Scenarios Generator (NSG) is a tcl script generator tool used to generate TCL Scripts
automatically!!!
NSG is a Java based tool that runs on any platform and can generate TCL Scripts for Wired as well as
Wireless Scenarios for Network Simulator - 2. The procedure to execute these TCL Scripts on NS-2 is
same as those of manually written TCL Scripts.
it opens a graphical user interface on top of the window click on scenario, select the type of connection
(new wired scenario/wireless scenario).
To create nodeclick on node tab and click on the screen, you can create any no of nodes as per the need.
PROGRAM 1
TITLE
Implement Three nodes point – to – point network with duplex links between them for different
topologies. 1Set the queue size, vary the bandwidth, and find the number of packets dropped for
various iterations.
AIM
Analyze the traffic between the nodes using different bandwidth, propagation delay and queue size of
point to point duplex link and its effects on packet transmission.
DESCRIPTION
Ns2(network simulator2) is used for this experiment, in which point to point duplex link is created
between the node with varying queuing capacity of node. Bandwidth, propagation delay of a point to
point link and queuing capacity of a node is very important to minimize the affect on packet
transmission. Ns2 simulated data traffic analyzed by setting the different bandwidth, propagation delay
and queuing capacity of a link and correspondingly its effect on packet transmission is noted. Unix grep
commands are used for analyzing the out.tr trace log file generated upon executing the ns2 simulation
script for determining the packet drops.
INPUT
(a) Different Bandwidth, propagation delay & queuing capacity of node of duplex link
(b) Unix grep commands for analyzing the out.tr trace log file for determining the number of
packet drop.
EXPECTED OUTPUT
(a) generate the out.tr trace log file and out.nam network animation file.
(b) number of packet drop
STEPS
• To start NSG2 open terminal
java -jar NSG2.jar
• Connect source to destination node by dragging TCP to TCP Sink (Virtual connection)
• Click on application tab =>select application type(FTP)
=>enter start time and stop time
• Click on TCP and then drag(FTP0)
• Click on parameter tab =>enter simulation time, trace file and nam file
• Click on TCL tab to generate code
• Save the code with the file name with extension .tcl
• Run the code in terminal by typing ns filename.tcl
• It would generate an animated topology window where transmission of packets between nodes
can be viewed
• Now press the play button in topology window and the simulation begins
• To find the no of packets dropped type the following code in terminal
grep -c “^d” filename.tr
• To see the trace file contents open the file as
gedit filename.tr
• Trace file contains 12 columns:
• Event type, Event time, From node, To node, Packet type, Packet size, Flax, Flow id, Source
address, Destination address, Sequence id, Packet id
PROGRAM
Prg1.tcl
proc Finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam prog1.nam &
exit 0
}
puts "simulation starts..."
$ns run
RESULT
5. What is a packet?
A packet is the unit of data that is routed between an origin and a destination on the Internet or any
other packet-switched network.
6. Define jitter?
Jitter is defined as a variation in the delay of received packets. At the sending side, packets are sent in
a continuous stream with the packets spaced evenly apart. Due to network congestion, improper
queuing, or configuration errors, this steady stream can become lumpy, or the delay between each
packet can vary instead of remaining constant.
PROGRAM 2
TITLE
Implement simple ESS and with transmitting nodes in wire-less LAN by simulation and determine the
performance with respect to transmission of packets.
AIM
To understand how Extended Service Set is created and works by providing services to nodes in wireless
LAN and analyzing the wireless traffic for determining packet drops.
DESCRIPTION
In this experiment, network simulator2 is used to create a IEEE 802.11 Wireless LAN consisting of
mobile nodes and Extended Service set. An extended service set (ESS) is one or more interconnected
basic service sets (BSSs) and their associated LANs. Each BSS consists of a single access point (AP)
together with all wireless client devices (stations, also called STAs) creating a local or enterprise 802.11
wireless LAN (WLAN). Wireless mobile nodes
INPUT
EXPECTED OUTPUT
STEPS
PROGRAM
#===================================
# Simulation parameters setup
#===================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 6 ;# number of mobilenodes
set val(rp) DSDV ;# routing protocol
set val(x) 810 ;# X dimension of topography
set val(y) 600 ;# Y dimension of topography
set val(stop) 10.0 ;# time of simulation end
#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]
#===================================
# Mobile node parameter setup
#===================================
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON
#===================================
# Nodes Definition
#===================================
#Create 6 nodes
set n0 [$ns node]
$n0 set X_ 270
$n0 set Y_ 408
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 503
$n1 set Y_ 404
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 710
$n2 set Y_ 416
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20
set n3 [$ns node]
$n3 set X_ 621
$n3 set Y_ 191
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20
set n4 [$ns node]
$n4 set X_ 402
$n4 set Y_ 176
$n4 set Z_ 0.0
$ns initial_node_pos $n4 20
set n5 [$ns node]
$n5 set X_ 249
$n5 set Y_ 174
$n5 set Z_ 0.0
$ns initial_node_pos $n5 20
#===================================
# Configure mobile nodes x, y speed
#===================================
$ns at 1.5 "$n1 setdest 390.0 460.0 40.0"
$ns at 1.5 "$n4 setdest 472.0 510.0 50.0"
$ns at 1.5 "$n5 setdest 523.0 570.0 40.0"
#===================================
# Agents Definition
#===================================
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n5 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500
#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 2.0 "$ftp0 stop"
#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam out.nam &
exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "\$n$i reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run
RESULT
3. Define BSS?
The basic service set (BSS) is a set of all stations that can communicate with each other at PHY
layer. Every BSS has an identification (ID) called the BSSID, which is the MAC address of the
access point servicing the BSS.
There are two types of BSS: Independent BSS (also referred to as IBSS), and infrastructure BSS. An
independent BSS (IBSS) is an ad hoc network that contains no access points, which means they
cannot connect to any other basic service set.
4. Define ESS?
An extended service set (ESS) is a set of connected BSSs. Access points in an ESS are connected
by a distribution system. Each ESS has an ID called the SSID which is a 32-byte (maximum)
character string.
PROGRAM 3
TITLE
Write a program for error detecting code using CRC-CCITT (16- bits).
DESCRIPTION
If we consider the data unit 1001 and divisor or polynomial generator 1011their polynomial
representation is:
• Now string of n 0s (one less than that of divisor) is appended to data. Now data is 1001000 and
its corresponding polynomial representation is x6 + x3.
• The division of x6+x3 by x3+x+ 1 is shown in fig.
• The polynomial generator should have following properties:
1. It should have at least two terms.
2. The coefficient of the term x0 should be 1.
3. It should not be divisible by x.
4. It should be divisible by x+ 1.
PROGRAM
import java.util.Scanner;
class crc{
public static void main(String args[])
{ int i,j,k;
int[] r;
int[] z;
Scanner sc=new Scanner(System.in);
System.out.print("enter no.of Data Bit:");
int n=sc.nextInt();
System.out.println("enter the no.of generator Bits:");
int m=sc.nextInt();
int[] d=new int[n+m];
int[] g=new int[m];
System.out.println("Enter the Data Bits");
for(i=0;i<n;i++)
d[i]=sc.nextInt();
System.out.println("Enter the Generator Bits");
for(j=0;j<m;j++)
g[j]=sc.nextInt();
for(i=0;i<m-1;i++)
d[n+i]=0;
r=new int[m+n];
z=new int[m];
for(i=0;i<m;i++)
{
r[i]=d[i];
z[i]=0;
}
for(i=0;i<n;i++)
{
k=0;
int msb=r[i];
for(j=i;j<m+i;j++)
{
if(msb==0)
r[j]=xor(r[j],z[k]);
else
r[j]=xor(r[j],g[k]);
k++;
}
r[m+i]=d[m+i];
}
System.out.print("the Code bit added : ");
for(i=n;i<n+m-1;i++)
{
d[i]=r[i];
System.out.print(d[i]);
}
System.out.println("the Code Data is : ");
for(i=0;i<n+m-1;i++)
System.out.print(d[i]);
}
RESULT
3. What is CRC?
CRC, is the most powerful of the redundancy checking techniques, is based on binary division.
6. Define Retransmission?
Retransmission is a technique in which the receiver detects the occurrence of an error and asks the sender
to resend the message. Resending is repeated until a message arrives that the receiver believes is error-
freed.
8. Define Encoder?
A device or program that uses predefined algorithms to encode, or compress audio or video data for
storage or transmission use. A circuit that is used to convert between digital video and analog video.
9. Define Decoder?
A device or program that translates encoded data into its original format (e.g. it decodes the data). The
term is often used in reference to MPEG-2 video and sound data, which must be decoded before it is
output.
PROGRAM 4
TITLE
Implement transmission of ping messages/trace route over a network topology consisting of 6 nodes and
find the number of packets dropped due to congestion in the network.
AIM
To understand the working principle of ICMP Ping message and deeper insights into the congestion
scenario caused by successive ping message among nodes.
DESCRIPTION
Ping is the one of popular mechanism for internet control messaging protocol. Ping message is used for
determining the reachability and aliveness of the remote/ destination machine in a network. In this
experiment, network simulator2 is used for creating network topology consisting of 6 nodes
interconnected by point to point duplex link. Nodes on the created topology issues ping command to the
other nodes in the network and generate traffic. Node upon receiving the ping message will respond by
sending a ping reply message to the requesting node and generate return traffic in the network.
Successive ping message by different nodes generates huge traffic on the network and causes packet
drop.
INPUT
EXPECTED OUTPUT
STEPS
• Click on parameter tab =>enter simulation time, trace file and nam file
• Click on TCL tab to generate code
• Save the code with the file name with extension .tcl
• The highlighted code need to be edited in the program
• Run the code in terminal by typing ns filename.tcl
• It would generate an animated topology window where transmission of packets between nodes
can be viewed
• Now press the play button in topology window and the simulation begins
• To find the no of packets dropped type the following code in terminal
grep -c “^d” filename.tr
PROGRAM
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam prog2.nam &
exit 0
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run
RESULT
1. Define Ping?
Ping is a computer network administration software utility used to test the reachability of a host on an
Internet Protocol (IP) network. It measures the round-trip time for messages sent from the originating
host to a destination computer that are echoed back to the source.
3. Define Bandwidth?
Bandwidth is the amount of data that can be transmitted in a fixed amount of time
4. Define a router?
Routers perform the traffic directing functions on the Internet. Data sent through the internet, such
as a web page or email, is in the form of data packets. A packet is typically forwarded from one
router to another router through the networks until it reaches its destination node
PROGRAM 5
TITLE
Write a program to find the shortest path between vertices using bellman-ford algorithm.
DESCRIPTION
Bellman-Ford algorithm solves the single-source shortest-path problem in the general case in which
edges of a given digraph can have negative weight as long as G contains no negative cycles.
This algorithm, like Dijkstra's algorithm uses the notion of edge relaxation but does not use with greedy
method. Again, it uses d[u] as an upper bound on the distance d[u, v] from u to v.
The algorithm progressively decreases an estimate d[v] on the weight of the shortest path from the source
vertex s to each vertex v in V until it achieve the actual shortest-path. The algorithm returns Boolean
TRUE if the given digraph contains no negative cycles that are reachable from source vertex s otherwise
it returns Boolean FALSE.
BELLMAN-FORD (G, w, s)
1. INITIALIZE-SINGLE-SOURCE (G, s)
2. for each vertex i = 1 to V[G] - 1 do
3. for each edge (u, v) in E[G] do
4. RELAX (u, v, w)
5. For each edge (u, v) in E[G] do
6. if d[u] + w(u, v) < d[v] then
7. return FALSE
8. return TRUE
Asymptotic complexity:
Conclusion:
PROGRAM
import java.util.Scanner;
}
System.out.print("enter the source vertex:");
source=scanner.nextInt();
bellmanFord(numvertex,source,numedges,edgemat);
}
}
RESULT
4. What is RIP?
RIP, short for Routing Information Protocol is used by routers to send data from one network to another.
It efficiently manages routing data by broadcasting its routing table to all other routers within the
network. It determines the network distance in units of hops.
PROGRAM 6
TITILE
Implement an Ethernet LAN using n nodes and set multiple traffic nodes and plot congestion window
for different source / destination.
AIM
To understand working principle of Ethernet LAN and congestion scenario using multiple data traffic.
DESCRIPTION
➢ Ethernet LAN denoted by IEEE 802.3 is one of the popular computer networking technology. In
this experiment, ns2 simulator is used for creating Ethernet LAN and set the two different data
traffic between pair of nodes using TCP as transport layer agent. Simulated data traffic between
pair of nodes is analysed for determining the packet drop due to congestion in the network.
Congestion window for each TCP traffic is plotted on graph using xgraph tool.
INPUT
• Ethernet LAN Bandwidth, propagation delay, Queue Type and channel type
• two TCP traffic between pair of nodes
• initial Congestion window for both the traffic.
• Unix grep command for analyzing the out.tr trace log file for determining the number of packet
drop.
EXPECTED OUTPUT
• generate the out.tr trace log file, winfile0, winfile1 and out.nam network animation file.
• Generate Windowsize_file0, WindowSize_file1 holding congestion window size of both the
traffic at different instance of time.
• number of packet drop.
• Xgraph plotted graph of depicting the congestion window of both the traffic.
STEPS
• Connect source to destination node by dragging TCP to TCP Sink (Virtual connection)
• Click on application tab =>select application type(FTP)
=>enter start time and stop time
• Click on TCP and then drag(FTP0)
• Click on parameter tab =>enter simulation time, trace file and nam file
• Click on TCL tab to generate code
• Save the code with the file name with extension .tcl
• Run the code in terminal by typing ns filename.tcl
• It would generate an animated topology window where transmission of packets between nodes
can be viewed
• Now press the play button in topology window and the simulation begins
• To find the no of packets dropped type the following code in terminal
grep -c “^d” filename.tr
• To see the trace file contents open the file as
gedit filename.tr
PROGRAM
set lan [$ns newLan "$n3 $n4 $n5" 1Mb 40ms LLQueue/DropTail Mac/802_3 channel]
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam prog6.nam &
exec xgraph WinFileReno WinFileNewReno &
exit 0
}
RESULT
4. Describe session?
A session is a semi-permanent interactive information interchange between two or more
communicating devices or between a computer and user (see login session)
5. What is Demodulation?
It is the process of converting an analog signal to digital signal
PROGRAM 7
TITLE
DESCRIPTION
The main concept of the leaky bucket algorithm is that the output data flow remains constant despite the
variant input traffic, such as the water flow in a bucket with a small hole at the bottom. In case the bucket
contains water (or packets) then the output flow follows a constant rate, while if the bucket is full any
additional load will be lost because of spillover. In a similar way if the bucket is empty the output will
be zero.
From network perspective, leaky bucket consists of a finite queue (bucket) where all the incoming
packets are stored in case there is space in the queue, otherwise the packets are discarded. In order to
regulate the output flow, leaky bucket transmits one packet from the queue in a fixed time (e.g. at every
clock tick). In the following figure we can notice the main rationale of leaky bucket algorithm, for both
the two approaches
(e.g. leaky bucket with water (a) and with packets (b)).
PROGRAM
import java.util.*;
class prg7
{
public static void main(String args[])
{
for(i=0;i<nop;i++)
datarate[i]=sc.nextInt();
for(i=0;i<nop;i++)
{
if(datarate[i]>size)
System.out.println("bucket overflow");
else
{
temp=datarate[i];
while(temp>opr)
{
System.out.println("packet transmission"+opr);
temp=temp-opr;
}
System.out.println("packet transmission"+temp);
}
}
}
}
RESULT
Over-provisioning
Traffic shaping
Packet scheduling