- Home Page of ProjectGuideline.com ›
- Forums ›
- Get Help to do your B.E., and M.E., M.Tech., & M.S., Project in Ns2 ›
- list of tcl object
hi to all
i have a problem in ns2
i want to add multiple routes in a node
and i found out that add-routes can do that all you need is to provide dest and list of link(tcl object)
the problem is i dont know the write way create list in tcl
further when i tried
lappend target_list $b
and issue this command three time with differnt b value
and the issue this comand
set num [llength target_list]
puts “nos of element in target list $num”
it prints 1 🙁
and when i use
foreach link $target_list {
puts ” link $link is in array”
}
it only print one value
plz help wat would be the problem
I think that you are handling the list in a correct way.
The reason for the problem may be as follows :
If you are creating a list and adding members from one function (or scope) and referring it in another function(or scope), then you may use it as a global variable or
instant variable as follows :
# if you are creating the list here and adding members here
# or any other procedure binded with an agent
Agent/myagent instproc handlelilst {
$self instvar target_list
foreach link $target_list {
puts " link $link is in array"
}
}
proc handlelilst {
global target_list
foreach link $target_list {
puts " link $link is in array"
}
}
Probably this info will help you to solve the problem.
If you are still having the same problem, then post some meaningful portion of the code or the whole script then only one can identify the error.
thnx for the reply
yes there was a scope problem and i have done it as you have said
now list is maintain correctly and now that problem is resolved
but when i call
Agent/rtProto/SLRA instproc madd-route {peerAddr dst check nodeid} {
$self instvar nextHop_
global multi test target_list
puts "check $check"
set node_ [$self id2handle $nodeid]
set dest_ [$self id2handle $dst]
# $node_ set multi $multipath_
if { $multi !=1} {
puts "for subnet $dst the link is $peerAddr"
set ns_ [Simulator instance]
set nullAgent_ [$ns_ set nullAgent_]
set a [$dest_ set address_]
set b [$ns_ link $node_ $peerAddr]
#set target [$b head]
if { $test == 1 } {
lset target_list 0 $b
set test 2
} else {
lappend target_list $b
puts " target list $target_list"
}
set num [llength target_list]
puts "nos of element in target list $num"
foreach link $target_list {
puts " link $link is in array"
}
if { $check == 1 } {
#$node_ delete-routes [$dst id] $nextHop_($dst) $nullAgent_
if { $nextHop_($dest_) != "" } {
$node_ delete-route [$dst id] $nextHop_($dst) $nullAgent_
}
$node_ add-routes $dst $target_list
$node_ set multipath_ 1
#Node set multipath_ 1
}
}
}
it gives following error
ns: _o371 madd-route 3 5 1 2: can’t read “class::”: no such variable
while executing
“warn “$class::$proc cannot install multiple routes””
invoked from within
“if !$multiPath_ {
if {[llength $ifs] > 1} {
warn “$class::$proc cannot install multiple routes”
set ifs [lindex $ifs 0]
}
$self add-route $id [$ifs he…”
(procedure “_o16” line 3)
(Node add-routes line 3)
invoked from within
“$node_ add-routes $dst $target_list”
(procedure “_o371” line 44)
(Agent/rtProto/SLRA madd-route line 44)
invoked from within
“_o371 madd-route 3 5 1 2”
[/code]