- The first is the *. h/CC file:
- ./Trace/basetrace. H, CC: basetrace base class
- ./Trace/trace. H, CC: trace class implementation
- ./Trace/cmu-trace.h, CC: especially the nam_format function in the cmu-trace.cc.
Note: The above three classes are inheritance relationships. The subsequent classes contain a basetrace * Pt _ pointer, which is used for packet tracking and analysis. This class is very important for many occasions. Specifically, in the implementation of C ++ code, you must first check whether it is empty. For example, in CMU-trace
- Common/Mobilenode. CC: this file is the main class for moving nodes. The set_destination function records the paths of all nodes. As follows:
{
.....
If (namchan _! = 0 ){
Double V = speed _ * SQRT (DX _ * DX _) + (Dy _ * Dy _));
Sprintf (nwrk _,
"N-T % F-S % d-x % F-Y % f-u % F-V % F-T % F ",
Schedck: instance (). Clock (),
Nodeid _,
X _, Y _,
Speed _ * DX _, speed _ * Dy _,
(V! = 0 )? Len/V: 0 .);
Namdump ();
}
}
Because I ignore this, the namchan _ is not bound to the node during the custom protocol, so the generated Nam file cannot display the node movement process. In contrast, other simulation scripts, such as the Tcl/EX/wireless. TCL file, can be used. The problem was detected only after midnight.
Implementation of the above binding process in the Tcl/lib/ns-lib.tcl file simulator instproc create-Wireless-node implementation, detailed can refer to the specific code. This function is automatically called when a node is generated. It is not bound because the function is not called when a node is created.
Solution: Add the following code to ***-create-mobile-node.
Set namtracefd [$ NS _ Get-Nam-traceall]
If {$ namtracefd! = ""}{
$ Node namattach $ namtracefd
}
- Tcl/lib/ns-lib.tcl, mainly including simulator level support;
This file contains an initial_node_pos function, that is, the location and size of the initialization node, which is mainly used for display in Nam.
Simulator instproc initial_node_pos {nodep size}
At the same time, the corresponding information will be output to the NAM file, which mainly includes the following information: node ID specified by-S, location (x, y, z), size-Z, mark-V, color-black
N-T *-S 0-x 68.594620455333327-y 93.540876681702628-Z 0-Z 5-V circle-C black
- Tcl/lib/ns-namsupp.tcl, mainly including node-level Nam support, including the following available functions:
Node instproc shape {shape}: Set the node shape
Node instproc color {color} sets the node color
Node instproc label {STR}
Node instproc label-color {STR}
Node instproc label-At {STR}
Note: The preceding functions are valid only at the beginning of the node and are invalid during running.
- Tcl/lib/ns-nam.tcl: mainly including functions related to Nam simulator, little effect.
Finally, you can use Nam-P to display Nam parameters and types.
Recently, I encountered a problem that in the NAM file generated by my simulation, only records of moving nodes, but no records of data packets, were found. Check the CC file, knowing that the format in the cmu-trace.cc file is not called, and further determine the problem appears in the following line:
If (Pt _-> namchannel ())
Nam_format (p, offset );
After GDB traces, it is found that the if condition of the call to this place is not met, that is, the namchan _ of Pt _ (see the previous section, which is a basetrace base class Object) is null.
Further check to find that layers of data packets must be bound to the trace object in the simulator instproc create-Wireless-node function in the ns-lib.tcl by doing the following:
#
# This trace target is used to log changes in direction
# And velocity for the mobile node.
#
Set tracefd [$ self get-NS-traceall]
If {$ tracefd! = ""}{
$ Node nodetrace $ tracefd
$ Node agenttrace $ tracefd
}
Set namtracefd [$ self get-Nam-traceall]
If {$ namtracefd! = ""}{
$ Node namattach $ namtracefd
}
The above red is the key. In addition to the above, you also need to enable the trace switch for each layer. This is done by calling
Simulator instproc node-config implementation. The strange thing is that I cannot directly set the following settings:
$ NS _ mactrace $ mactrace
Required:
$ NS _ node-config-adhocrouting $ OPT (RP )/
-Lltype $ OPT (LL )/
-Mactype $ OPT (MAC )/
-Ifqtype $ OPT (ifq )/
-Ifqlen $ OPT (ifqlen )/
-Anttype $ OPT (ANT )/
-Proptype $ OPT (PROP )/
-Phytype $ OPT (netif )/
-Topoinstance $ Topo/
-Agenttrace on/
-Routertrace on/
-Mactrace on/
-Movementtrace off/
-Channel $ Chan
In this way, the corresponding MAC, router, and Agent layer records can be generated in the NAM file. Of course, the premise is that the protocols you develop must have these layers.