How can I fix this error invalid command name "_o10 in NS2 - tcl

You are missing the MIH / MIPv6 addition provided by ns-2.29-nist-mob-022707.tgz.This is for ns-2.29,but I usens-allinone-2.35.Is it the same procedure? Thanks!
This is my code link
https://drive.google.com/file/d/1Aan1OeAh5tIeDrt5MjgFTqvNSeahNWVy/view?usp=sharing
While running my tcl script for new protocol in NS2 it shows error as:
num_nodes is set 10
invalid command name "Agent/MIHUser/IFMNGMT/MIPV6/Handover/Handover1"
while executing
"Agent/MIHUser/IFMNGMT/MIPV6/Handover/Handover1 create _o216 "
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 Agent/MIHUser/IFMNGMT/MIPV6/Handover/Handover1"
invoked from within
"set handover [new Agent/MIHUser/IFMNGMT/MIPV6/Handover/Handover1]"
(file "bear2.tcl" line 177)
How can I modify it?

Related

Tcl:Is there a way to show which line in tcl throw an error?

When I source a tcl file, error will be report when run to a unknown command.
Tcl> source run.tcl
$inside tcl file$$> setup_desgin
Design setup...
Done
$inside tcl file$$> my_prove
Info: proving started
Info: ....
Info: ....
$inside tcl file$$> ::unknown my_pro
invalid command name "my_pro"
Is there a way to show the line number of the error line in tcl file as below?
Tcl> source run.tcl
$inside tcl file$$> setup_desgin
Design setup...
Done
$inside tcl file$$> my_prove
Info: proving started
Info: ....
Info: ....
$inside tcl file$$> ::unknown my_pro
invalid command name "my_pro" (run.tcl:5)
We want this because we may have a very big run.tcl with minions of line.
It's actually quite difficult to get this information in general. The accurate line number information is only available at present when the code is on the execution stack. Fortunately, you can find out what's going on with a leave-step trace (intercepting unknown would only work for unknown commands; tracing lets all errors be caught). In the code below, I've put it on eval, but in a more practical example you'd put it on source or something like that.
set errorlineSet 0
proc LEAVESTEP {cmd code result op args} {
global errorline errorlineSet
if {$code == 1} {
if {!$errorlineSet} {
set errorline [dict get [info frame -4] line]
}
set errorlineSet 1
} else {
set errorlineSet 0
}
}
try {
trace add execution eval leavestep LEAVESTEP
eval {
sdfgsldfjg; # This is line 17
}
} on error {msg opt} {
puts "ERROR: $msg (line: $errorline) (local line: [dict get $opt -errorline])"
} finally {
trace remove execution eval leavestep LEAVESTEP
}
When I save all that to a file and run it, it prints this:
ERROR: invalid command name "sdfgsldfjg" (line: 17) (local line: 3)
As you can see, there is also the -errorline key in the result option dictionary, but that's mapped to 3 in this case and that's rather misleading! It uses that value because of backward compatibility, but I'm not convinced that it is all that helpful.
You can redefine the unknown command and use the info frame command in it to get the location. Something like:
# Save the default unknown if you want
rename ::unknown ::original_unknown
proc ::unknown {name args} {
set caller [info frame -1]
dict with caller {
switch $type {
source {
puts stderr "invalid command name \"$name\" (in file $file:$line)"
}
proc {
if {[info exists lambda]} {
puts stderr "invalid command name \"$name\" (in lambda $lambda:$line)"
} else {
puts stderr "invalid command name \"$name\" (in proc $proc:$line)"
}
}
eval {
puts stderr "invalid command name \"$name\" (in eval {$cmd}:$line)"
}
precompiled {
puts stderr "Invalid command name \"$name\""
}
}
}
}
Example usage:
% source my_unknown.tcl
% source bad.tcl
invalid command name "put" (in file /home/shawn/src/bad.tcl:3)

Why is ::cmdline::getoptions throwing an error?

Why does the following code:
#!/usr/bin/env tclsh
package require cmdline;
set options {{d.arg "" "destination directory"}}
set usage ": $::argv0 \[options] filename ...\noptions:"
set params [::cmdline::getoptions ::argv $options $usage]
throw the following error upon execution of ./main.tcl -help?
main : ./main.tcl [options] filename ...
options:
-d value destination directory <>
-help Print this message
-? Print this message
while executing
"error [usage $optlist $usage]"
(procedure "::cmdline::getoptions" line 15)
invoked from within
"::cmdline::getoptions ::argv $options $usage"
invoked from within
"set params [::cmdline::getoptions ::argv $options $usage]"
(file "./main.tcl" line 8)
It should display the usage information, but I didn't expect the error afterwards. Did I do something wrong?
From what I understand from the docs (emphasis mine):
The options -?, -help, and -- are implicitly understood. The first two abort option processing by throwing an error and force the generation of the usage message, whereas the the last aborts option processing without an error, leaving all arguments coming after for regular processing, even if starting with a dash.
using -help or -? will always throw an error.
Further down in the docs you can see an example where try { ... } trap { ... } is being used in conjunction with ::cmdline::getoptions, which might be how you might want to do it:
try {
array set params [::cmdline::getoptions ::argv $options $usage]
} trap {CMDLINE USAGE} {msg o} {
# Trap the usage signal, print the message, and exit the application.
# Note: Other errors are not caught and passed through to higher levels!
puts $msg
exit 1
}

invalid command name "Agent/LeachAgent"

I try to implement a simple scenario for LEACH protocol but I get this error:
Creating Sensors ...
invalid command name "Agent/LeachAgent"
while executing
"Agent/LeachAgent create _o2340 "
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 Agent/LeachAgent"
("for" body line 3)
invoked from within
"for {set i 1} {$i <= $val(nsn)} {incr i} {
set agent($i) [new Agent/LeachAgent]
$ns attach-agent $node_($i) $agent($i)
$agent($i) set packetSize_..."
(file "newleach3.tcl" line 187)
I use ubuntu 16.04 and ns-allinone-2.35 . when I ran my tcl file for the first time, i did not get this error.
Change your script to use Agent/RCAgent/LeachAgent as class name:
set agent($i) [new Agent/RCAgent/LeachAgent]
From what I can see, there is no Agent/LeachAgent in ns-allinone-2.35.
I was not successful in writing a correct code for attaching Leach protocol in my scenario, but I found that mannasim has a Mannasim Script Generator (MSG). It is a front-end for TCL simulation scripts easy creation.

Tcl Error: can't rename to "::sha2::SHA256Init": command already exists

I'm having issues with the pki library while using sha256. Here's is the following line of code that I am having issues with:
package require pki
set $signature "whatever"
set $keydata "some real 256 RSA key"
set key [::pki::pkcs::parse_key $keydata]
set sig [some_class::base64_url_encode -input [::pki::sign $signature $key sha256]]
And here is the following error message I get:
can't rename to "::sha2::SHA256Init": command already exists
while executing
"rename ::sha2::${c}-${key} ::sha2::$c"
(procedure "SwitchTo" line 38)
invoked from within
"SwitchTo $e"
("foreach" body line 3)
invoked from within
"foreach e [KnownImplementations] {
if {[LoadAccelerator $e]} {
SwitchTo $e
break
}
}"
(in namespace eval "::sha2" script line 3)
invoked from within
"namespace eval ::sha2 {
variable e {}
foreach e [KnownImplementations] {
if {[LoadAccelerator $e]} {
SwitchTo $e
break
}
}
..."
(file "/usr/local/naviserverXXXX/lib/tcllib1.15/sha1/sha256.tcl" line 820)
invoked from within
"source /usr/local/naviserverXXXX/lib/tcllib1.15/sha1/sha256.tcl"
("package ifneeded sha256 1.0.3" script)
invoked from within
"package require sha256"
(procedure "::pki::sign" line 16)
invoked from within
"::pki::sign $signature $key sha256"
Then I tried doing this:
catch {namespace delete ::sha256}
package require pki
set $signature "whatever"
set $keydata "some real 256 RSA key"
set key [::pki::pkcs::parse_key $keydata]
set sig [some_class::base64_url_encode -input [::pki::sign $signature $key sha256]]
And now I get a different error saying that sha256 is being loaded from a different library:
can't rename to "::sha2::SHA256Init": command already exists
while executing
"rename ::sha2::${c}-${key} ::sha2::$c"
(procedure "SwitchTo" line 38)
invoked from within
"SwitchTo $e"
("foreach" body line 3)
invoked from within
"foreach e [KnownImplementations] {
if {[LoadAccelerator $e]} {
SwitchTo $e
break
}
}"
(in namespace eval "::sha2" script line 3)
invoked from within
"namespace eval ::sha2 {
variable e {}
foreach e [KnownImplementations] {
if {[LoadAccelerator $e]} {
SwitchTo $e
break
}
}
..."
(file "/web/dev/project-directory/httpd/lib/tcllib1.15/sha1/sha256.tcl" line 820)
invoked from within
"source /web/dev/project-directory/httpd/lib/tcllib1.15/sha1/sha256.tcl"
("package ifneeded sha256 1.0.3" script)
invoked from within
"package require sha256"
(procedure "::pki::sign" line 16)
invoked from within
"::pki::sign $signature $key sha256"
I've tried restarting the server and the same error keeps on popping up. Is there a problem with the server loading and not booting with the correct library dependencies?

Why can't I access errorInfo and errorCode

I have the following code:
$ cat ~/tmp/2.tcl
set zero 0
proc p1 {} {
if {[catch {expr 1/$zero} err]} {
puts "errorCode=$errorCode"
puts "errorInfo=$errorInfo"
}
}
p1
When I source it, I get error accessing errorCode:
$ tclsh ~/tmp/2.tcl
can't read "errorCode": no such variable
while executing
"puts "errorCode=$errorCode""
(procedure "p1" line 3)
invoked from within
"p1"
(file "~/tmp/2.tcl" line 9)
I tried changing to $::errorCode, but did not help.
Can you see what is wrong?
The errorInfo and errorCode variables are globals. You should either use the global command to bring them into scope or use their fully-qualified names (i.e., precede with ::).
It might be easier to pick the information out of the result options dictionary (a new feature in 8.5).
Starting from Tcl 8.5 [catch] doesn't set the errorCode and errorInfo global variables. (As Donal has pointed out, it still does, so they can be accessed as $::errorCode and $::errorInfo). And in addition it puts their values into a dictionary which name is to be specified as the third argument. The following code
#!/usr/bin/tclsh
set zero 0
proc p1 {} {
if {[catch {expr 1/$zero} err opts] == 1} {
puts "errorCode=[dict get $opts -errorcode]"
puts "errorInfo=[dict get $opts -errorinfo]"
}
}
p1
prints
errorCode=NONE
errorInfo=can't read "zero": no such variable
while executing
"expr 1/$zero"
in Tcl 8.5.19, and
errorCode=TCL READ VARNAME
errorInfo=can't read "zero": no such variable
while executing
"expr 1/$zero"
in Tcl8.6.6.
You'd probably want to use $::zero in the division after which the result would be
errorCode=ARITH DIVZERO {divide by zero}
errorInfo=divide by zero
while executing
"expr 1/$::zero"