LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 04-09-2018, 08:15 AM   #1
sadeem
LQ Newbie
 
Registered: Apr 2018
Location: Iraq-Babil
Posts: 4

Rep: Reputation: Disabled
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)
 
Old 04-09-2018, 05:38 PM   #2
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
Welcome to LQ.

Also ref. https://stackoverflow.com/questions/...procedure-loop
( and https://askubuntu.com/questions/1023...session-in-ns2 )

Please explain how "the second iteration" is started.

And please also show the file "End2endDelay_RoutingPackets.awk".

-

Last edited by knudfl; 04-09-2018 at 05:39 PM.
 
Old 04-09-2018, 06:28 PM   #3
sadeem
LQ Newbie
 
Registered: Apr 2018
Location: Iraq-Babil
Posts: 4

Original Poster
Rep: Reputation: Disabled
thanks

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.
 
Old 04-10-2018, 04:16 AM   #4
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
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.

metrics.awk https://drive.google.com/file/d/1gTZ...ew?usp=sharing (All ~250 ns2 analyzing scripts)

-

Last edited by knudfl; 04-10-2018 at 04:37 AM.
 
Old 04-10-2018, 06:20 AM   #5
sadeem
LQ Newbie
 
Registered: Apr 2018
Location: Iraq-Babil
Posts: 4

Original Poster
Rep: Reputation: Disabled
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);
  }
 
Old 04-10-2018, 11:16 AM   #6
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
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:
Code:
/home/../ns2/DSR/sadeem-deyah/{call.tcl, cbrgen.tcl, costtest1.tcl, End2endDelay_RoutingPackets.awk}
The new result with the right awk script is ...
Code:
$ ns call.tcl 
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 = 135.00
Packet Receive = 134.00
routingpkts = 74.00
Packet Delivery Ratio = 99.26
NRL = 0.55
Average end-to-end Delay (ms)= 28.86
No. of dropped data (packets) = 0
No. of dropped data (bytes)   = 0
Done
Files created: DSR.nam 662.4kB, DSR.tr 965.4kB , cbr-5 2.2kB, scan-5 22.1kB .

-
 
Old 04-10-2018, 11:46 AM   #7
sadeem
LQ Newbie
 
Registered: Apr 2018
Location: Iraq-Babil
Posts: 4

Original Poster
Rep: Reputation: Disabled
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:

Code:
#call.tcl
source costtest1.tcl
input_Protocol_pramerters 20 5 2.0 5
input_Protocol_pramerters 20 10 2.0 10
puts "Done"
 
  


Reply

Tags
ns2



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a nam file to see the scenario of leach protocol in NS2 ? Mehedi Hasan Linux - Newbie 1 09-01-2014 09:44 AM
How to run DSR in - ns2? cchan9213 Linux - Newbie 1 07-13-2014 04:49 PM
How to run DSR in - ns2? cchan9213 Linux - Wireless Networking 1 07-13-2014 03:48 AM
Multipath Design using DSR routing protocol in ns2 tandel kavita Linux - Wireless Networking 2 03-12-2013 03:45 PM
How to run DSR protocol in ns-2 NimeshaK Linux - Newbie 5 03-29-2012 06:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 02:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration