Run scenario of DSR protocol multiple times in one session in ns2
Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Run scenario of DSR protocol multiple times in one session in ns2
Actually, I'm new in simulation project that I want to call another procedure from the following loop:
Code:
#call.tcl
source costtest1.tcl
for { set x 5} { $x <6} { incr x } {
input_Protocol_pramerters 20 $x 2.0 $x
}
puts "Done"
The other procedure includes the following DSR protocol to generate the performance evaluation for simulation scenario:
Code:
#costtest1.tcl
proc input_Protocol_pramerters {No_node No_connaction Rate iter} {
set cbr "cbr-"
set secn "scan-"
append cbr $iter
append secn $iter
set DSR_fileTr "DSR"
append DSR_fileTr $iter ".tr"
set DSR_fileNam "DSR"
append DSR_fileNam $iter ".nam"
puts $iter
#---- Generate Movement file ----
puts [eval exec "./setdest -v 1 -n $No_node -p 5 -M $No_connaction -t 100 -x 1000 -y 1000 >$secn"]
#---- Generate Movement file ----
puts [eval exec "ns cbrgen.tcl -type cbr -nn $No_node -seed 1.0 -mc $No_connaction -rate $Rate >$cbr"]
#---- Main simulation file to generate DSR.tr and DSR.nam
#----------------------------------------------------------------
# Definition of the physical layer
#----------------------------------------------------------------
set val(chan) Channel/WirelessChannel
set val(prop) Propagation/TwoRayGround
set val(netif) Phy/WirelessPhy
set val(mac) Mac/802_11
set val(ifq) CMUPriQueue
set val(ll) LL
set val(ant) Antenna/OmniAntenna
#-----------------------------------------------------------------
# Scenario parameters
#------------------------------------------------------------------
set val(x) 1500 ;# X dimension of the topography
set val(y) 1500 ;# Y dimension of the topography
set val(ifqlen) 50 ;# max packet in queue
set val(seed) 1.0 ;#random seed
set val(adhocRouting) DSR
set val(nn) $No_node ;# how many nodes are simulated
set val(cp) $cbr
set val(sc) $secn
set val(stop) 50 ;# simulation time
#----------------------------------------------------------------------
# Set up simulator objects
#----------------------------------------------------------------------
# create simulator instance
set ns_ [new Simulator]
# setup topography object
set topo [new Topography]
# create trace object for ns and nam
set tracefd [open $DSR_fileTr w]
$ns_ use-newtrace ;# use the new wireless trace file format
set namtrace [open $DSR_fileNam w]
$ns_ trace-all $tracefd
$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)
# define topology
$topo load_flatgrid $val(x) $val(y)
# Create God
set god_ [create-god $val(nn)]
$ns_ node-config -adhocRouting $val(adhocRouting) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channelType $val(chan) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON
# Create the specified number of nodes [$val(nn)] and "attach" them
# to the channel.
for {set i 0} {$i < $val(nn) } {incr i} {
set node_($i) [$ns_ node]
$node_($i) random-motion 0 ;# disable random motion
}
# Define node movement model
puts "Loading connection pattern..."
source $val(cp)
# Define traffic model
puts "Loading scenario file..."
source $val(sc)
# Define node initial position in nam
for {set i 0} {$i < $val(nn)} {incr i} {
# 50 defines the node size in nam, must adjust it according to your scenario
# The function must be called after mobility model is defined
# puts "Processing node $i"
$ns_ initial_node_pos $node_($i) 50
}
#
# Tell nodes when the simulation ends
#
for {set i 0} {$i < $val(nn) } {incr i} {
$ns_ at $val(stop).0 "$node_($i) reset";
}
$ns_ at $val(stop).0002 "puts \"NS EXITING...\" ; $ns_ halt"
# dump the initial simulation info to the trace file
puts $tracefd "M 0.0 nn $val(nn) x $val(x) y $val(y) rp $val(adhocRouting)"
puts $tracefd "M 0.0 sc $val(sc) cp $val(cp) seed $val(seed)"
puts $tracefd "M 0.0 prop $val(prop) ant $val(ant)"
puts "Starting Simulation..."
$ns_ run
# end Mail file
# Evaluate parametrs
puts [eval exec "awk -f End2endDelay_RoutingPackets.awk $DSR_fileTr"]
}
In the first iteration, I got the results:
Code:
5
num_nodes is set 20
warning: Please use -channel as shown in tcl/ex/wireless-mitf.tcl
INITIALIZE THE LIST xListHead
Loading connection pattern...
Loading scenario file...
Starting Simulation...
channel.cc:sendUp - Calc highestAntennaZ_ and distCST_
highestAntennaZ_ = 1.5, distCST_ = 550.0
SORTING LISTS ...DONE!
NS EXITING...
Packet Sent = 136.00
Packet Receive = 82.00
routingpkts = 123.00
Packet Delivery Ratio = 60.29
NRL = 1.50
Average end-to-end Delay (ms)= 13219.08
No. of dropped data (packets) = 21
No. of dropped data (bytes) = 11172
In the second iteration, I got the following error:
Code:
6
num_nodes is set 20
invalid command name "_o491 _o4"
while executing
"$ns_ get-nodetype"
(procedure "_o501" line 22)
(Object next line 22)
invoked from within
"_o501 next"
("eval" body line 1)
invoked from within
"eval $self next $args"
(procedure "_o501" line 3)
(Object next line 3)
invoked from within
"_o501 next"
("eval" body line 1)
invoked from within
"eval $self next $args "
(procedure "_o501" line 6)
(SRNodeNew init line 6)
invoked from within
"_o501 init "
(Class create line 1)
invoked from within
"SRNodeNew create _o501 "
invoked from within
"catch "$className create $o $args" msg"
invoked from within
"if [catch "$className create $o $args" msg] {
if [string match "__FAILED_SHADOW_OBJECT_" $msg] {
delete $o
return ""
}
global errorInfo
error "class $..."
(procedure "new" line 3)
invoked from within
"new SRNodeNew"
("eval" body line 1)
invoked from within
"eval new $nodeclass $args"
(procedure "_o491" line 8)
(Simulator create-node-instance line 8)
invoked from within
"_o491 create-node-instance"
("eval" body line 1)
invoked from within
"eval $self create-node-instance $args"
(procedure "_o491" line 6)
(Simulator create-wireless-node line 6)
invoked from within
"_o491 create-wireless-node"
("eval" body line 1)
invoked from within
"eval $self create-wireless-node $args"
(procedure "_o491" line 23)
(Simulator node line 23)
invoked from within
"$ns_ node"
(procedure "input_Protocol_pramerters" line 61)
invoked from within
"input_Protocol_pramerters 20 6 2.0 6"
(file "call.tcl" line 5)
The second iteration mean the second round of the loop. Which run the same simulation of the DSR protocol but with different values of the procedure parameters.
End2endDelay_RoutingPackets.awk calculate the results and nothing wrong with this file.
the problem in the protocol procedure when i call it more than one time.
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511
Rep:
Re. #3.
The simulation stops when no file `End2endDelay_RoutingPackets.awk´ is found.
Faking "End2endDelay_RoutingPackets.awk" with a copy of metrics.awk :
Code:
[knudfl@localhost sadeem-deyah]$ ns call.tcl
--------METRICS-----------
Total Packets Sent : 142
Total Packets Received : 137
Total Packets Dropped : 23
Total Packets Forwarded : 970
Packet Delivery Ratio : 96.48%
The total hop counts are : 4675
Average Hop Count : 34 hops
Routing Overhead : 0
Normalized Routing Load : 0.0000
Througphut of the network(KBps) : 0.0685
Average End to End Delay :8.359873229 ms
Total Energy Consumed :500000.000000
Protocol Energy Consumption :100.000000
5
num_nodes is set 20
warning: Please use -channel as shown in tcl/ex/wireless-mitf.tcl
INITIALIZE THE LIST xListHead
Loading connection pattern...
Loading scenario file...
Starting Simulation...
channel.cc:sendUp - Calc highestAntennaZ_ and distCST_
highestAntennaZ_ = 1.5, distCST_ = 550.0
SORTING LISTS ...DONE!
NS EXITING...
Done
[knudfl@localhost sadeem-deyah]$
... Where 'ns' is a copy of the executable "ns235-64-orig". I.e. a clean / stock ns-2.35/ns.
The files DSR.nam 309.9kB, DSR.tr 444.8kB are created.
$ nam DSR.nam & : A perfect animation.
you must put all the files in the path(/ns-allionone-2.34/ns-2.34/indep-utils/cmu-scen-gen/setdest/).
This is the contain of the (End2endDelay_RoutingPackets.awk) file:
Code:
BEGIN {
sends=0;
recvs=0;
routing_packets=0.0;
droppedBytes=0;
droppedPackets=0;
highest_packet_id =0;
sum=0;
recvnum=0;
}
{
time = $3;
packet_id = $41;
# CALCULATE PACKET DELIVERY FRACTION
if (( $1 == "s") && ( $35 == "cbr" ) && ( $19=="AGT" )) { sends++; }
if (( $1 == "r") && ( $35 == "cbr" ) && ( $19=="AGT" )) { recvs++; }
# CALCULATE DELAY
if ( start_time[packet_id] == 0 ) start_time[packet_id] = time;
if (( $1 == "r") && ( $35 == "cbr" ) && ( $19=="AGT" )) { end_time[packet_id] = time; }
else { end_time[packet_id] = -1; }
# CALCULATE TOTAL DSR OVERHEAD
if (($1 == "s" || $1 == "f") && $19 == "RTR" && $35 =="DSR") routing_packets++;
# DROPPED DSR PACKETS
if (( $1 == "d" ) && ( $35 == "cbr" ) && ( $3 > 0 ))
{
droppedBytes=droppedBytes+$37;
droppedPackets=droppedPackets+1;
}
#find the number of packets in the simulation
if (packet_id > highest_packet_id)
highest_packet_id = packet_id;
}
END {
for ( i in end_time )
{
start = start_time[i];
end = end_time[i];
packet_duration = end - start;
if ( packet_duration > 0 )
{ sum += packet_duration;
recvnum++;
}
}
delay=sum/recvnum;
NRL = routing_packets/recvs; #normalized routing load
PDF = (recvs/sends)*100; #packet delivery ratio[fraction]
printf("Packet Sent = %.2f\n",sends);
printf("Packet Receive = %.2f\n",recvs);
printf("routingpkts = %.2f\n",routing_packets++);
printf("Packet Delivery Ratio = %.2f\n",PDF);
printf("NRL = %.2f\n",NRL);
printf("Average end-to-end Delay (ms)= %.2f\n",delay*1000);
printf("No. of dropped data (packets) = %d\n",droppedPackets);
printf("No. of dropped data (bytes) = %d\n",droppedBytes);
}
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511
Rep:
Re #5.
Quote:
you must put all the files in the path(/ns-allionone-2.34/ns-2.34/indep-utils/cmu-scen-gen/setdest/).
Not really. I'm using the updated "ns-allinone-2.35_gcc5.tar.gz" https://drive.google.com/file/d/0B7S...ew?usp=sharing
... which will install all executable´s {ns, setdest, etc.} to /usr/local/bin/:
cd ns-2.35/
# make install
Required is a directory in any random location outside ns-allinone-2.35 .
Example:
Your result mean that you run the program one time with the value 5 and i want to run the program more than one time.
you could delete the loop and put the procedure call twice like this code:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.