Last week, I've got few messages asking me similar questions. The question was why do I see the following error message when running NS2 and how do I fix it?
invalid command name
The Cause of the Error Message
This message is an OTcl error message, saying that the NS2 (or more precisely the OTcl interpreter) does not understand the current statement.
For example, by default, the following OTcl statement will cause an error:
Agent/GPSR set sport_ 255
since NS2 does not understand "Agent/GPSR"
The Syntax of OTcl
OTcl is an interpreter which interprets OTcl command line by line. Each line begins with a keyword such as "set", "new", etc.
The above example statement begins with "Agent/GPSR" which is known to OTcl as a string, not a command. Therefore, OTcl creates an error message when encountering this message.
How Do We Fix It?
To fix this problem, you first need to understand you own need. The above statement has two problem
1. Agent/GPSR is unknown to NS2. You need to declare this class before you can use it. To do so, please read the following post.
2. In most cases, you would not set the value of a variable belonging to a class. But you will do so with a variable belonging to an object. So, after fixing the former problem, you will have to do the following:
set agent [new Agent/GPSR]
$agent set sport_ 255
where first you create an object $agent of class Agent/GPSR. Then you set the instvar sport_ of $agent to be 255
======================================================
T. Issaraiyakul and E. Hossain, “Introduction to Network Simulator NS2”, Springer 2009. Buy it now from
You may also find lecture notes and other resource at the following website: http://www.ece.ubc.ca/~teerawat/NS2.htm
No comments:
Post a Comment