Inserting an externally controlled variable into NS2

 

Here we detail the steps of inserting a variable in the simulator that can be controlled by the tcl script. We demonstrate this by explaining how to insert QoS parameters into NS2 so that these could be different for different nodes.

 

1.      Insert a variable in the simulator class. The 802.11e QoS parameters like DIFS are in a class called PHY_MIB in mac/mac-802_11.h

 private:
            int  DIFStime;
 Add an observer function for this variable in the class.

 

2.      Change the appropriate algorithms in this class using the variable you created. Access to this variable is possible from upper layers (like MAC) through the pointer that layer has to the PHY_MIB layer. For instance we changed  the backoff computation using the cwmin, pf (persistance factor) variables we pass from the tcl script, to represent the 802_11e specific backoff computation.

 

3.      Insert a tcl variable in the file ns-default.tcl and specify a default value. For example write:
Mac/802_11 set DIFS_          0.000030
(Though the change was done in PHY_MIB class, here we need to write as was done above).

 

4.      Bind the tcl variable with the simulator internal variable.We should write in the PHY_MIB constructor:
    parent
®bind("DIFS_",&DIFSTime);

(parent is a pointer to a mac802_11 instance that is passed to the constructor)

 

5.      Recompile the simulator.

6.      Usage in the tcl script: Before creating a node, before defining  node-config parameters, you need to write:
    Mac/802_11 set DIFS_         <value>
if you want to override the default for this node.                                                                                                   

You can change this value number of times in the tcl script and this way create nodes with different values of this parameter.