next up previous contents
Next: Priority queue Up: Needed Changes Previous: Tracing support   Contents


Tcl library

Now we need to do some changes in Tcl files. Actually we are going to add our packet type, give default values for binded attributes and provide the needed infraestructure to create wireless nodes running our protoname routing protocol.

In tcl/lib/ns-packet.tcl you must locate the next code and add protoname to the list (as we do in line 2).

tcl/lib/ns-packet.tcl

1: foreach prot {
2:     Protoname
3:     AODV
4:     ARP
5:     # ...
6:     NV
7: } {
8:     add-packet-header $prot
9: }

Default values for binded attributes have to be given inside tcl/lib/ns-default.tcl. We must go to the end of the file and write something like the next code:

tcl/lib/ns-default.tcl

1: # ...
2: # Defaults defined for Protoname
3: Agent/Protoname set accessible_var_ true

Finally we have to modify tcl/lib/ns-lib.tcl. We need to add procedures for creating a node. Our interest will be centered around creating a wireless node with protoname as routing protocol.

The procedure node calls to the create-wireless-node procedure. This last one, among other tasks, is intended to set the routing agent for a node. We need to hack this procedure to create an instance of our protoname protocol.

tcl/lib/ns-lib.tcl

1:  Simulator instproc create-wireless-node args {
2:      # ...
3:      switch -exact $routingAgent_ {
4:          Protoname {
5:              set ragent [$self create-protoname-agent $node]
6:          }
7:          # ...
8:      }
9:      # ...
10: }

Then create-protoname-agent will be coded below as shown in the next example.

tcl/lib/ns-lib.tcl

1: Simulator instproc create-protoname-agent { node } {
2:         # Create Protoname routing agent
3:         set ragent [new Agent/Protoname [$node node-addr]]
4:         $self at 0.0 "$ragent start"
5:         $node set ragent_ $ragent
6:         return $ragent
7: }

Line 3 creates a new protoname agent with the node's address. This agent is scheduled to start at the begining of the simulation (line 4), and is assigned as the node's routing agent in line 5.


next up previous contents
Next: Priority queue Up: Needed Changes Previous: Tracing support   Contents
Francisco J. Ros 2004-12-30