Objective: To detect the idle MAC address of a wireless node every 0.0005 seconds
Implementation Scheme:
Solution 1: print the is_idle () value in a handler loop.
Implementation: Refer to season29, simulate the DSR handler class in the DSR protocol, and create an idletimer class in the mac-802_11.h
Class idletimer: Public handler {
Public:
Idletimer (mac802_11 * I ){
Interval = 0.0005;
Idle = I;
}
Void start (){
Schedle: instance (). Schedule (this, & intr, 0.0005 );
}
Void handle (event * E );
PRIVATE:
Double interval;
Event intr;
Mac802_11 * idle;
};
Set idletimer to a friend Meta class in mac802_11 and declare an idletimer it.
Handle function definition for idletimer class in mac-802_11.cc
Void idletimer: handle (event * E ){
Int isid;
Isid = idle-> is_idle ();
Fprintf (stdout, "% d \ n", isid); // print whether idle, 1-idle, 0-busy
Schedle: instance (). Schedule (this, & intr, interval );
}
Start the timer it. Start () in mac802_11: mac802_11 (). Note that it (this) must be added at the end of the function name)
That is, mac802_11: mac802_11 ():
MAC (), phymib _ (this), macmib _ (this), mconditioned _ (this), mhnav _ (this ),
Mhrecv _ (this), mhsend _ (this ),
Mhdefer _ (this), mhbackoff _ (this), IT (this) // I don't know what this is.
A major problem with this solution: it is difficult to determine which node's Mac is idle. The number of nodes 1 and 0 is about multiple of the expected number of nodes.
Solution 2: Use the command function
Add a judgment in the Command () function of mac802_11
If (argc = 2 ){
If (strcmp (argv [1], "Check-idle") = 0 ){
Fprintf (stdout, "% 2.9f % d \ n", schedut: instance (). Clock (), is_idle (); // print the time and idle time
Return tcl_ OK;
}
}
In the Tcl File
Set n0_mac [$ N0 set Mac _ (0)] # [] indicates that the MAC layer of node 0 appears to be selected. The entire sentence is to use n0_mac to represent the MAC layer of node 0.
For {set I 0} {$ I <38001} {incr I }{
$ NS at [expr 1 + $ I * 0.0005] "$ n0_mac cmd check-idle"
} # Check the idle state of node 0 every 0.0005 seconds from 1 second to 20 seconds
When running NS **. TCL> **. Data, the node idle status at each time point is displayed in **. Data.
Transferred from:Kevinking's personal space
The purpose of this log is to set MAC layer parameters for each node in the Tcl script.