Lab Program1
Lab Program1
Implement three nodes point – to – point networks with duplex links between
them. Set the queue size, vary the bandwidth and find the number of packets
dropped.
Topology
#Create nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
#create links, specify the type, nodes, bandwidth, delay and ARQ algorithm
for it
#set udp0 packet to red color and udp1 packet to blue color
$udp0 set class_ 1
$udp1 set class_ 2
AWK file
BEGIN { count=0;
}
{
if ($1=="d")
count++
}
END{
printf("Number of packets dropped is = %d\n", count);
}
Output:
[root@localhost 21cs52]# awk -f lab1.awk lab1.tr
Number of packets dropped is = 4065
Explanation
The command sets a queue limit for a specific link or channel between nodes in
the simulation.
● $ns: This refers to the network simulator object in ns-2. It's a common prefix
for many commands in ns-2 scripts.
● queue-limit: This is a command or function used to set the queue limit for a
specific link or channel.
● $n0 and $n2: These are node identifiers. In ns-2, nodes are typically
represented by variables like $n0, $n1, $n2, etc.
● 10: This is the queue limit value you are setting for the link or channel
between nodes $n0 and $n2. It means that the queue associated with this link
will not allow more than 10 packets to be enqueued.
● set udp0 [new Agent/UDP]: This line creates a new UDP agent and assigns
it to the variable udp0.
● $ns attach-agent $n0 $udp0: This line attaches the UDP agent udp0 to the
node represented by the variable $n0. In network simulations, agents are
entities responsible for generating and processing packets.
● set udp1 [new Agent/UDP]: Similarly, this line creates another UDP agent
and assigns it to the variable udp1.
● $ns attach-agent $n1 $udp1: This line attaches the UDP agent udp1 to the
node represented by the variable $n1.
● set null3 [new Agent/Null]: This line creates a new Null agent, which is
often used as a sink or endpoint that discards any packets it receives.
● $ns attach-agent $n3 $null3: This line attaches the Null agent null3 to the
node represented by the variable $n3. This configuration suggests that node
$n3 will act as a destination that discards incoming packets, possibly serving
as a simulation endpoint or sink.
In summary, the code sets up two nodes ($n0 and $n1) with UDP agents (udp0 and
udp1) and another node ($n3) with a Null agent (null3). This is a basic setup for
sending UDP traffic between nodes in a network simulation.
We are creating Constant Bit Rate (CBR) traffic applications and attaching
them to the UDP agents in your ns-2 network simulation.
set cbr0 [new Application/Traffic/CBR]: This line creates a new CBR traffic
application and assigns it to the variable cbr0.
$cbr0 attach-agent $udp0: This line attaches the CBR traffic application cbr0 to
the UDP agent udp0.
set cbr1 [new Application/Traffic/CBR]: Similarly, this line creates another CBR
traffic application and assigns it to the variable cbr1.
$cbr1 attach-agent $udp1: This line attaches the CBR traffic application cbr1 to the
UDP agent udp1.
This indicates that CBR traffic will be generated by the application and sent using
the UDP agent associated with node $n1.
● We are setting the class parameter for the UDP agents in your ns-2 network
simulation. In ns-2, the "class" parameter is used to categorize or differentiate traffic
classes.
● $udp0 set class_ 1: This line sets the "class_" parameter of the UDP agent udp0 to the
value 1. This implies that the traffic generated by udp0 belongs to class 1.
● $udp1 set class_ 2: Similarly, this line sets the "class_" parameter of the UDP agent udp1
to the value 2. This indicates that the traffic generated by udp1 belongs to class 2.
● Assigning different classes to traffic sources allows for the simulation of multiple classes
of traffic with potentially different characteristics or quality of service requirements. In a
network simulation, you might define different behaviors, such as different delay or loss
characteristics, for traffic belonging to different classes.
● These lines of code in an ns-2 simulation script establish connections between the UDP
agents (udp0 and udp1) and the Null agent (null3). In the context of ns-2, the connect
command is typically used to define links between network components.
● $ns connect $udp0 $null3: This line connects the UDP agent udp0 to the Null agent null3.
In a network simulation, this connection could represent a communication link or path
between the source (UDP agent) and the destination (Null agent). It essentially sets up a
path for traffic generated by udp0 to flow to the Null agent null3.
● $ns connect $udp1 $null3: Similarly, this line connects the UDP agent udp1 to the Null
agent null3. It establishes another communication link or path for the traffic generated by
udp1 to reach the Null agent null3.
● We are configuring the parameters for the CBR traffic application associated with cbr1
in your ns-2 simulation script.
● $cbr1 set packetSize_ 500Mb: This line sets the "packetSize_" parameter of the CBR
traffic application cbr1 to 500 megabits (Mb). This parameter typically defines the size
of each packet generated by the CBR traffic source. In this case, it implies that each
packet will be 500 megabits in size.
● $cbr1 set interval_ 0.005: This line sets the "interval_" parameter of the CBR traffic
application cbr1 to 0.005 seconds. The "interval_" parameter usually represents the
time interval between successive packets generated by the CBR source. In this case, it
suggests that a new packet will be generated every 0.005 seconds.
● These parameter settings define the characteristics of the traffic generated by the
CBR source associated with cbr1. The packet size and inter-packet interval are
important factors that influence the traffic pattern in the simulation. Adjusting these
parameters allows you to control the rate and size of the packets generated by the CBR
traffic source.
We are scheduling events in your ns-2 simulation script using the at command.
$ns at 0.1 "$cbr0 start": This line schedules the start of the CBR traffic application associated
with cbr0 at time 0.1 seconds in the simulation. The start method is used to initiate the
generation of CBR traffic from the specified source.
$ns at 0.1 "$cbr1 start": Similarly, this line schedules the start of the CBR traffic application
associated with cbr1 at time 0.1 seconds. It initiates the generation of CBR traffic from the
second source.
$ns at 10.0 "finish": This line schedules the event labeled as "finish" to occur at time 10.0
seconds in the simulation. The event named "finish" could be a user-defined event or a
placeholder for some action or condition that you want to trigger after a specific duration.
These scheduled events help define the timeline of actions in your simulation. The CBR
traffic sources are started at 0.1 seconds, and something labeled "finish" is triggered at 10.0
seconds.
We are using an AWK script to process output data, likely from a network simulation.
● BEGIN { count=0; }: This is the BEGIN block, which is executed before processing
any input lines. In this case, it initializes a variable count to 0.
● if ($1=="d") count++: In the main body of the AWK script, it checks if the first field
($1) of the input line is equal to "d". If true, it increments the count variable. This
suggests that the script is counting the number of lines where the first field is "d," which
could indicate dropped packets in a network simulation.
● In summary, this AWK script processes input data, likely from a simulation log or
output, and counts the number of lines where the first field is "d," assuming that "d"
signifies dropped packets. The result is printed as the "Number of packets dropped."