-   Linux - Software (
-   -   how to add a nam file on leach protocol (

khedidja 03-30-2012 02:20 AM

how to add a nam file on leach protocol

I am working with leach protocol, and I need to visualise the simulation with nam simulator, so I add this code on tcl/ex/wireless.tcl to generate leach.nam:

proc ns-nam { ttype atype node } {
global ns_ namtrace

if { $namtrace == "" } {
return ""
set N [new NamSimulator/$ttype $atype]
$N target [$ns_ set nullAgent_]
$N attach $namtrace
$N set src_ [$node id]

$N node $node

return $T

set namtrace [open leach.nam w]
$ns_ namtrace-all-wireless $namtrace $opt(x) $opt(y)

puts $namtrace "M 0.0 nn $opt(nn) x $opt(x) y $opt(y) rp $opt(rp)"
puts $namtrace "M 0.0 sc $opt(sc) cp $opt(cp) seed $opt(seed)"
puts $namtrace "M 0.0 prop $opt(prop) ant $opt(ant)"

but, leach.nam contain only :
M 0.0 nn 101 x 1000 y 1000 rp leach
M 0.0 sc mit/uAMPS/sims/scen1000 cp none seed 0.0
M 0.0 prop Propagation/TwoRayGround ant Antenna/OmniAntenna
V -t * -v 1.0a5 -a 0
W -t * -x 1000 -y 1000
A -t * -n 1 -p 0 -o 0xffffffff -c 31 -a 1
A -t * -h 1 -m 2147483647 -s 0

please, help me. I need that

shimpisagar 07-06-2012 02:14 AM

Hi khedidja,

are you able to generate Nam file for leach ??? or still not?

jschiwal 07-06-2012 02:20 AM

Moved: This thread is more suitable in Linux-Software and has been moved accordingly to help your question get the exposure it deserves.

shimpisagar 07-06-2012 03:47 AM


sweetgrl07 03-14-2013 10:00 AM

how to generate leach.nam
still i am not able to run leach.nam in tcl/wireless.tcl
what should i do for run nam also??

knudfl 03-14-2013 12:40 PM

There is a "nam section" in this 'tcl/wireless.tcl' from
the additional module "pegasis/leach" > exidus-pegasis_ns-234-leach.tar.gz

wireless.tcl, line 224 :

# try for setup output nam file
set nam_vystup                [open $opt(rp).nam w]                 
$ns_ namtrace-all-wireless $nam_vystup $opt(x) $opt(y)
# end

Download link

Info, #5 here
→ → ""with this extension it is possible to
simulate protocols LEACH, LEACH-C, Stat-Clus, MTE and PEGASIS""

And #289 here
# 425
... And there may be more relevant info in posts between #289 and #425.


sweetgrl07 03-15-2013 12:28 AM

thanks dear

i am able to generate dsdv.nam file but nam is not open through which i can see my simulation. i want to open nam to see the simulation on graph but its only generated dsdv.nam file. please help me

knudfl 03-15-2013 02:58 AM

Post # 7.

What has dsdv to do with the thread subject "LEACH" ?
And you cannot get "dsdv.nam" from nothing ?
Some more information, please. File names, commands etc. (dsdv.tcl ?)


sweetgrl07 03-15-2013 04:24 AM

thanks knudfl

dsdv.nam is generated because in set properties i use dsdv algorithm now i m change with leach and this error occurs

@ubuntu:~/ns-allinone-2.35/ns-2.35/exidus_ns-234-leach/tcl/ex$ ns wireless.tcl
num_nodes is set 51
invalid command name "leach-create-mobile-node"
while executing
"leach-create-mobile-node $i"
invoked from within
"if { [string compare $opt(rp) "dsr"] == 0} {
for {set i 0} {$i < $opt(nn) } {incr i} {
dsr-create-mobile-node $i
} elseif { [string compare $op..."
(file "wireless.tcl" line 254)

this error was occuring while executing the leach.
and dsdv.nam is generated because in set properties i use dsdv algorithm now i m change with leach and this error occurs

knudfl 03-15-2013 02:24 PM

# 9 .

The idea with the 'Pegasis--leach' is (like other additional protocols)
to compile the .cc files into the executable 'ns'.

I have repacked the 'exidus-pegasis--leach' to be easier to use.
The new package name is exidus-pegasis-leach-ns234.patch.tar.gz .

Install : tar xvf ns-allinone-2.34.tar.gz
cd ns-allinone-2.34/
tar xvf exidus-pegasis-leach-ns234.patch.tar.gz
export CC=gcc41 CXX=g++41

Note 1: The files do not work in ns-2.35 .
Note 2: The new 'wireless.tcl' can be be run like :
$ ./ns wireless.tcl -x 20 -y 20


sweetgrl07 03-17-2013 08:43 AM

hello sir
i have installed ns2.34 and thn run your peagisis pakcage but still this error occur

~/ns-allinone-2.34/ns-2.34/leach-ns234/tcl/ex$ ns wireless.tcl -x 20 -y 20
num_nodes is set 51
invalid command name "leach-create-mobile-node"
while executing
"leach-create-mobile-node $i"
invoked from within
"if { [string compare $opt(rp) "dsr"] == 0} {
for {set i 0} {$i < $opt(nn) } {incr i} {
dsr-create-mobile-node $i
} elseif { [string compare $op..."
(file "wireless.tcl" line 254)

and still i am not able to open nam please help me sir

sweetgrl07 03-17-2013 09:05 AM

first i install ns2.34
then add your exidus-pegasis-leach-ns234.patch.tar.gz then run its gives above error
then i again try to give command of ./install
then in installation it gives this error ehat should i doo??

Warning: tclStubInit.c may be out of date.
Developers may want to run "make genstubs" to regenerate.
This warning can be safely ignored, do not report as a bug!
Installing libtcl8.4.a to /home/sweetgrl07/ns-allinone-2.34/lib/
cp: cannot create regular file `/home/sweetgrl07/ns-allinone-2.34/lib/#inst.24467#': Permission denied
rm: cannot remove `/home/sweetgrl07/ns-allinone-2.34/lib/libtcl8.4.a': Permission denied
mv: cannot stat `/home/sweetgrl07/ns-allinone-2.34/lib/#inst.24467#': No such file or directory
ranlib: could not create temporary file whilst writing archive: No more archived files
make: *** [install-binaries] Error 1
tcl8.4.18 installation failed.
Tcl is not part of the ns project. Please see
to see if they have a fix for your platform.
---------- Post added 03-17-13 at 07:36 PM ----------

D23 03-18-2013 05:03 AM

i installed leach on ns2.34 and ./test working fine and output is also coming right in leach.out but when i tried to run wireless.tcl file then i got following

pratibha@ubuntu:~/ns2/ns-allinone-2.34/ns-2.34/tcl/ex$ ns wireless.tcl
couldn't read file "tcl/lib/ns-mobilenode.tcl": no such file or directory
while executing
"source.orig tcl/lib/ns-mobilenode.tcl"
("uplevel" body line 1)
invoked from within
"uplevel source.orig[list $fileName]"
invoked from within
"if [$instance_ is_http_url $fileName] {
set buffer [$instance_ read_url $fileName]
uplevel eval $buffer
} else {
uplevel source.orig[list $fileName]
(procedure "source" line 8)
invoked from within
"source tcl/lib/ns-mobilenode.tcl"
(file "wireless.tcl" line 184)
i changed path of ns-mobilenode by giving full path but after that ./test gives error no such file or directory..
please help me asap...
thanx in advance..

knudfl 03-18-2013 05:37 AM

Post # 13, @D23 : Welcome to LQ.

"wireless.tcl" can be run with './test' in ns-allinone-2.34/ns-2.34/.

If you want to run 'ns wireless.tcl' in ns-2.34/tcl/ex/ :
cd ns-2.34/tcl/ex/
mkdir tcl
cd tcl/
ln -s ../../mobility/
ln -s ../../lib/
cd ../
Then you can do : ns wireless.tcl -x 1000 -y 1000
.. or / and whatever options you want to use.

Please see 'leach_test' (line 37) to know the options used when ./test is run.


knudfl 03-18-2013 05:55 AM

Post # 13, @sweetgrl07 : Which Ubuntu version are you using ? ?

About your errors : If you ever use 'sudo' with any ns2 command,
( like sudo tar xvf ns-allinone-* ) :
You will have no access to all files as unprivileged user,
i.e. the message "Permission denied" will appear.
And you will have to delete everything and start from scratch.

The install command is not really plain ./install, but :
export CC=gcc-4.1 CXX=g++-4.1 && ./install
( The gcc / g++ naming will vary with Ubuntu version :
Ubuntu 10.04 : like the above. Ubuntu 12.04 example : gcc41/g++41 ).


All times are GMT -5. The time now is 04:40 AM.