simulation ns2

260 views
Skip to first unread message

sadjid...@gmail.com

unread,
Aug 28, 2020, 3:52:52 PM8/28/20
to Network Simulator 2 (NS2)
hi guys, pleeease help mee,  i have a problem while excuting this program :
#=== Input parameters =====================================
set val(nd) 5;  #distance between nodes
set val(retx) 1; #retransmission attempt for repeater
set val(filename) try1;  #for different output file name
set val(cwmin) 0;  #Contention Window (mininum)
set val(cwmax) 8;  #Contention Window (maximum)
set val(num) 250;  #number of nodes
set val(random) 1;  #random number for seed
set nodedist $val(nd);
set retransmission $val(retx);
set fn $val(filename);
set cwmin $val(cwmin);
set cwmax $val(cwmax);
set random $val(random);
$defaultRNG seed $random;#deterministic into Random

#=== Configure RF model parameters ========================
Antenna/OmniAntenna set Gt_ 1.0
Antenna/OmniAntenna set Gr_ 1.0
#=== Node configuration options ===========================
set val(chan) Channel/WirelessChannel;# channel type
set val(prop) Propagation/TwoRayGround;# radio-propagation model
set val(netif) Phy/WirelessPhyExt;# network interface type
set val(mac) Mac/802_11Ext;# 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) 20;# max packet in ifq
set val(nn) 250;#$val(num);# number of mobilenodes
set val(x) 2000;# X dimension of topography
set val(y) 200;# Y dimension of topography
set val(stop) 100;# time of simulation end
set val(rtg) DumbAgent;# routing protocol
#=== Create a ns simulator ================================
set ns_ [new Simulator]
#=== Setup topography object ==============================
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
set god_ [create-god $val(nn)]
$god_ off
#=== Open the NS trace file ===============================
set tracefile [open out_$fn.tr w]
$ns_ use-newtrace
$ns_ trace-all $tracefile
#=== Open the NAM trace file ==============================
set namfile [open out_$fn.nam w]
$ns_ namtrace-all-wireless $namfile $val(x) $val(y)
#=== Configure the Nodes ==================================
set chan [new $val(chan)]
$ns_ node-config -adhocRouting $val(rtg)\
-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 OFF\
-macTrace OFF\
-phyTrace OFF

set node_(0) [$ns_ node]


#=== Creating node objects ================================
for {set i 0} {$i<$val(nn)} {incr i} {
set ID_($i) $i
set node_($i) [$ns_ node]
$node_($i) set id_ $ID_($i)
$node_($i) set address_ $ID_($i)
$node_($i) set X_ [expr $i * $nodedist]
$node_($i) set Y_ 50
$node_($i) set Z_ 0.0
$node_($i) random-motion 0;# disable random motion
}
#=== PBC Agents Definition ================================
for {set i 0} {$i<1} {incr i} {
set agent_($i) [new Agent/PBC]
$ns_ attach-agent $node_($i) $agent_($i)
$agent_($i) set payloadSize 500
$agent_($i) set periodicBroadcastInterval 0.01
$agent_($i) set periodicBroadcastVariance 0.01
$agent_($i) set modulationScheme 1
$agent_($i) singleBroadcast
#packetType (0 = safety, 1 = service)
#Safety Type packet, set the channel number to -99
$agent_($i) set channel_ -99
$agent_($i) set type_dsrc_ 0
}
for {set i 1} {$i<$val(nn)} {incr i} {
set agent_($i) [new Agent/PBC]
$ns_ attach-agent $node_($i) $agent_($i)
$agent_($i) set payloadSize 500
$agent_($i) set periodicBroadcastInterval 0.5
$agent_($i) set periodicBroadcastVariance 0.05
#$agent_($i) set modulationScheme 1
$agent_($i) Repeater ON $retransmission
#packetType (0 = safety, 1 = service)
#Safety Type packet, set the channel number to -99
$agent_($i) set channel_ -99
$agent_($i) set type_dsrc_ 0
}
#=== Define node initial position in nam ==================
for {set i 0} {$i<$val(nn)} {incr i} {
$ns_ initial_node_pos $node_($i) 0
}
#=== Define a 'finish' procedure ==========================
proc finish {} {
global ns_ tracefile namfile
$ns_ flush-trace
close $tracefile
close $namfile
#exec nam scenario1.nam &
}
#=== Tell node to stop ====================================
for {set i 0} {$i < $val(nn) } { incr i } {
$ns_ at $val(stop).0 "$node_($i) reset";
}
$ns_ at $val(stop) "$ns_ nam-end-wireless $val(stop)"
$ns_ at $val(stop) "finish"
$ns_ at $val(stop).0002 "puts \"End Simulation\" ; $ns_ halt"
puts "Starting Simulation..."
$ns_ run
--------------------------------------------- it shows me this errors : ---------------------------------

$ ns appendix.tcl

num_nodes is set 250

INITIALIZE THE LIST xListHead

 

    (_o4033 cmd line 1)

    invoked from within

"_o4033 cmd Repeater ON 1"

    invoked from within

"catch "$self cmd $args" ret"

    invoked from within

"if [catch "$self cmd $args" ret] {

set cls [$self info class]

global errorInfo

set savedInfo $errorInfo

error "error when calling class $cls: $args" $..."

    (procedure "_o4033" line 2)

    (SplitObject unknown line 2)

    invoked from within

"$agent_($i) Repeater ON $retransmission"

    ("for" body line 8)

    invoked from within

"for {set i 1} {$i<$val(nn)} {incr i} {

set agent_($i) [new Agent/PBC]

$ns_ attach-agent $node_($i) $agent_($i)

$agent_($i) set payloadSize 500

$agent_..."

    (file "appendix.tcl" line 93)

knudfl

unread,
Aug 28, 2020, 6:41:22 PM8/28/20
to Network Simulator 2 (NS2)
Hi.

Looks like it should be edited to .....
$agent_($i) set Repeater ON $retransmission

And you can try adding a "multicast" line after "set ns_ [new Simulator]"
set ns_ [new Simulator]
$ns_ multicast             #; added
....  that may bring you a bit forward in the trouble shooting.

sadjida lebid

unread,
Aug 28, 2020, 7:12:20 PM8/28/20
to ns-u...@googlegroups.com
thank you sir, when i edited  
$agent_($i) set Repeater ON $retransmission
it showed me this : does this mean that the simulation is working ?
$ ns appendix.tcl
num_nodes is set 250
INITIALIZE THE LIST xListHead
Starting Simulation...
channel.cc:sendUp - Calc highestAntennaZ_ and distCST_
highestAntennaZ_ = 1.5,  distCST_ = 2090.1
SORTING LISTS ...DONE!
--- Classfier::no-slot{} default handler (tcl/lib/ns-lib.tcl) ---
        _o26: no target for slot 0
        _o26 type: Classifier/Port
content dump:
classifier _o26
        0 offset
        0 shift
        2147483647 mask
        1 slots
                slot 255: _o17 (Agent/DumbAgent)
---------- Finished standard no-slot{} default handler ----------


thank you

--
You received this message because you are subscribed to the Google Groups "Network Simulator 2 (NS2)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-users+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ns-users/5438a534-6716-4401-8105-981b1ab31e20n%40googlegroups.com.


--
                     Lebid Sadjida 
Etudiante en Master 2 Réseaux et Télécommunications. 
Département de Télécommunication.
Faculté de Génie Electrique.
Université Djilali Liabes de Sidi Bel Abbes.

knudfl

unread,
Aug 29, 2020, 6:16:36 AM8/29/20
to Network Simulator 2 (NS2)
Hi.

As said in my previous post,  please try editing to
set ns_ [new Simulator]
$ns_ multicast             #; added
....  that may bring you a bit forward in the trouble shooting, not a solution ... and `$ns_ multicast´  may be surplus.
* My impression is that this simulation (appendix.tcl) is too complex for a stock executable 'ns'.
.... You may have some information of the "appendix" origin.  A link, please.

sadjida lebid

unread,
Aug 29, 2020, 6:29:29 AM8/29/20
to ns-u...@googlegroups.com
hello sir,
yes sir when i tried it, it showed me more errors: 
$ ns appendix.tcl
num_nodes is set 250
INITIALIZE THE LIST xListHead
ns: _o5037 drop 0 -1 -1: can't read "protocols_(-1)": no such variable
    while executing
"$protocols_($iface) drop $replicator $src $dst $iface"
    (procedure "_o40" line 3)
    (mrtObject drop line 3)
    invoked from within
"[$node_ getArbiter] drop $self $src $dst $iface"
    (procedure "_o5037" line 3)
    (Classifier/Replicator/Demuxer drop line 3)
    invoked from within
"_o5037 drop 0 -1 -1"


**yes i have a pdf file (joshi.pdf) where you can find information about this code. 
thank you.

Joshi.pdf

knudfl

unread,
Aug 29, 2020, 12:04:06 PM8/29/20
to Network Simulator 2 (NS2)
Hi.

Joshi.pdf = 196555289.pdf  →   https://core.ac.uk/download/pdf/196555289.pdf

Well, please consider reading APPENDIX C = ns-2.34/apps/pbc.h  → edited / new code
.... and APPENDIX D = ns-2.34/apps/pbc.cc  → new code.

Can be tricky to translate a pdf to usable C++ code.  You should also expect more issues with the tcl code.
I managed to get usable c++ code from the pdf  .... 

Build example ...
cd ns-allinone-2.35/
tar xvf vanet-emergency-Joshi-3_ns235.tar
./install

sadjida lebid

unread,
Aug 30, 2020, 3:54:46 PM8/30/20
to ns-u...@googlegroups.com
hello sir,
i tried what you told me to do but the same errors occurred 
 $ ns appendix.tcl
num_nodes is set 250
INITIALIZE THE LIST xListHead
Starting Simulation...
channel.cc:sendUp - Calc highestAntennaZ_ and distCST_
highestAntennaZ_ = 1.5,  distCST_ = 2090.1
SORTING LISTS ...DONE!
--- Classfier::no-slot{} default handler (tcl/lib/ns-lib.tcl) ---
        _o26: no target for slot 0
        _o26 type: Classifier/Port
content dump:
classifier _o26
        0 offset
        0 shift
        2147483647 mask
        1 slots
                slot 255: _o17 (Agent/DumbAgent)
---------- Finished standard no-slot{} default handler ----------

knudfl

unread,
Aug 30, 2020, 7:39:14 PM8/30/20
to Network Simulator 2 (NS2)
Hi.

This is my result with the simulation ....
$ ns235-vanet-emergency64 1-vanet-PBC.tcl
num_nodes is set 250
INITIALIZE THE LIST xListHead
can't read "debug_": no such variable
    (Object set line 1)
    invoked from within
"CMUTrace/Send set debug_"
    invoked from within
"catch "$c set $var" val"

    invoked from within
"if [catch "$self cmd $args" ret] {
set cls [$self info class]
global errorInfo
set savedInfo $errorInfo
error "error when calling class $cls: $args" $..."
    (procedure "_o4015" line 2)

    (SplitObject unknown line 2)
    invoked from within
"$agent target $sndT"
    (procedure "_o15" line 43)
    (Node/MobileNode add-target line 43)
    invoked from within
"$self add-target $agent $port"
    (procedure "_o15" line 15)
    (Node attach line 15)
    invoked from within
"$node attach $agent"
    (procedure "_o4" line 2)
    (Simulator attach-agent line 2)
    invoked from within
"$ns_ attach-agent $node_($i) $agent_($i)"
    ("for" body line 3)
    invoked from within

"for {set i 0} {$i < 1 } { incr i } {
set agent_($i) [new Agent/PBC]
$ns_ attach-agent $node_($i) $agent_($i)
$agent_($i) set payloadSize 500
$agent_($..."
    (file "1-vanet-PBC.tcl" line 129)

..... The file is a direct copy of the pdf appendix B  →  1-vanet-PBC.tcl + your settings

Which OS are you using ?   Name, version, architecture please. Like Ubuntu 16.04.7 - amd64.
... With the right OS installed to a hard disk partition, you shouldn't get "Classifier::no-slot{} default handler"
? May be you are using a copy of the executable 'ns' without the edited PBC = vanet-emergency-Joshi-3_ns235.tar ?
... It's a good idea to use an executable "ns-new-name".  Not ~all ns executable´s can be named 'ns'.

sadjida lebid

unread,
Aug 30, 2020, 8:12:23 PM8/30/20
to ns-u...@googlegroups.com
hello sir,
i did change the codes ns-allinone-2.35/ns2.35/apps/pbc.cc nd pbc.cc with the ones in the appendix C and D.
i'm not using ubuntu cause i couldn't install it on my pc
so i'm using virtual machine virtual box 6.1.8. fedora 12 =>>
image.png


knudfl

unread,
Aug 31, 2020, 4:05:35 AM8/31/20
to Network Simulator 2 (NS2)
Hi.

Fedora 12 is one of the best ns2 friendly OS, so perfect !
( Is just so that most students are using the worst possible for ns2 :   Ubuntu.)
Is your OS 32 or 64bit  ?   →  $ uname -m

May be you got created a better copy of  { pbc.cc, pbc.h } ?
The new executable `ns235-vanet-emergency64´ starts with an identical error from the default PBC examples:
$ ./ns235-vanet-emergency64 broadcast_validation.tcl
num_nodes is set 200

INITIALIZE THE LIST xListHead
can't read "debug_": no such variable

$ ./ns235-vanet-emergency64 unicast_validation.tcl  
num_nodes is set 3

INITIALIZE THE LIST xListHead
can't read "debug_": no such variable
............ The two examples are  ns-2.35/ex/802.11/{broadcast_validation.tcl  unicast_validation.tcl}.

Can you please attach / upload your { pbc.cc, pbc.h }.  Then I will test with Fedora 12 or similar.

sadjida lebid

unread,
Aug 31, 2020, 7:17:13 PM8/31/20
to ns-u...@googlegroups.com
hello sir, 
it is 64bits,
i didn't understand sir, i also had struggles in copying files from fedora to windows. I can't copy paste files now either texts . What should i do? any solution please ! 

i uploaded the original files (old) that were in ns-2.35 first  and the new ones (from the appendix)

thank you.

pbc_old.cc
pbc_old.h
pbc.cc
pbc.h

knudfl

unread,
Sep 1, 2020, 6:06:20 AM9/1/20
to Network Simulator 2 (NS2)
Hi.

Don't know where you got those "-old " files. Don't seem to look like any known file.
Besides that, there is no code difference from your {pbc.cc, pbc.h} to my `vanet-emergency-Joshi-3_ns235.tar´.

Ref. ns2-INFO: Both VirtualBox and wmWare have resulted in poor unusable 'ns' executable since 2017.
So either you have a "VirtualBox error" or you are using a wrong copy of the executable 'ns' to get "Classifier::no-slot{} default handler".

Safe method is to use a new name for the new 'ns'
cd ns-allinone-2.35/
tar xvf vanet-emergency-Joshi-3_ns235.tar
./install
cd ns-2.35/
cp ns ns235-emergency                 ### or any new name by your choice
# cp ns235-emergency /usr/local/bin/
------- Simulation --------
ns235-emergency  file.tcl

I.e. if you have multiple 'ns' save them to usr/local/bin/[ns-any-name]

About the simulation (appendix C) :  Some  PBC settings are missing, ref. https://dsn.tm.kit.edu/medien/downloads_old/Documentation-NS-2-80211Ext-2008-02-22.pdf
.... The simulation also handles nix routing .... so I added this after  `set ns_ [new Simulator]´ :
#=== Create a ns simulator ================================
set ns_ [new Simulator]

# ---------------------------------------------------------
# ---------------------------------------------------------
Agent/PBC set payloadSize 200 ; #(in bytes)
Agent/PBC set periodicBroadcastInterval 0.1          ;# (in seconds)
Agent/PBC set periodicBroadcastVariance 0.1        ;# (in seconds)
Agent/PBC set modulationScheme 0        ; # the default modulation scheme for data is BPSK
Simulator set nix-routing 0
$ns_ set-nix-routing
# ---------------------------------------
# ---------------------------------------


So know the simulation has an issue with nix routing.
Reply all
Reply to author
Forward
0 new messages