A. Homogenous
multi-radio multi-channel
The radios and channels created in this section are
homogenous. The homogenous radios and channels are configured through
wireless TCL simulation script. According to the relationship between radio
number and channel number, CRCN provides three kinds of structures to satisfy different
requirements from users: (1) Equal number of radios and channels, (2) Single-radio multi-channel, (3) Unequal number of radios and channels.
(1) Equal number of radios
and channels
The
Component 1.Define the radio number in TCL script |
… set val(ni) 2 ;# 2 interface ... |
Component 2. New channel objects according to the interface number provided in 1 |
for {set i 0 } { $i < $val(ni)} {incr i} { set chan_($i) [new $val(chan)] ; # new channel objects } |
Component 3. Configure the radio
and channel option through the |
… $ns_ node-config -adhocRouting $val(rp) \ … -ifNum $val(ni)\ ; #configure the interface number for node -channel $chan_(0) ; # configure the first channel object … |
Component 4. Assign the channel objects to the simulator |
for {set i 0} {$i < $val(ni) } {incr i} { $ns_ add-channel $i $chan_($i) ; # pass the channel objects into channel array } |
Through the script
created as instructed in this section, the radio is associated with each
channel. Only routing layer is aware of each radio/channel. Users can refer to
section 2.2.2 Radio and Channel decision for the radio and channel decision.
(2) Single-radio multi-channel
For the creation of single-radio and multi-channel, user can refer to the details in CRMAC. The channel decision from the CR routing only need to be stored into the channelindex_ , which is newly added in packet header. The lower layer has been modified to support this decision.
(3)Unequal number of radios and channels
If user wants to
have unequal number of radios and channels, user can refer to the CR MAC detail 2.3.1(Part B. multi-radio,
multi-channel) about how to create the TCL script. The channel created as in
2.3.1 can be visible to both routing and MAC layer. Here is an example
script. Users should refer to section 2.2.2 about how to use the interface
provided for radio and channel decision.
B. Heterogeneous multi-radio and multi-channel
Similar to the creation of homogenous radios and channels, heterogeneous radios and channels are created through wireless simulation script. The following four components should be added into the simulation script by the user.
Component 1, 2 and 3 are the same in A.
Component 4. Assign different channel objects with different spectrum parameters to the simulator as follow. |
# configure the ns channel… $ns_ add-channel-new-phy 0 $chan_(1) 0.4 Propagation/FreeSpace #update this information for node 1 set node_(1) [$ns_ node] #;apply the change on node … $ns_ add-channel-new-phy 0 $chan_(0) 0.4 default … |
In the example above, add-channel-new-phy
is the newly added
A. Radio decision
In the routing modules, radio decision can be stored in the routing entry such as the rt->rt_if field in AODV routing packet header. When your routing protocol is going to send down the packet, the following code should be added. Example for modifying the routing module can be found in here.
Example for the radio or channel decision used in AODV protocol. |
… Scheduler::instance().schedule(targetlist[rt->rt_if], p, 0.); .. |
Downtarget array targetlist is created when the node is configured in TCL script. rt->rt_if is the radio decision specified by the routing packet.
The way to handle radio decision is the same for all of the three structures defined in section 2.2.1.
B. Channel decision
Equal number of radios and channels
When the radio and channel are created as in 2.2.1 A, channel is tied with each radio, thus, the radio decision is equal to the channel decision in this case.
Single radio
multi-channel
For
single radio multi-channel or the channels that are only visible to
Unequal
number of radios and channels
The
channel decision should be specified by routing algorithms through the channelindex_ of packet header. The low layer has
been modified to support this decision. The design structure for single radio
multi-channel and this part shares the common design at low layer.
A. Interference information
The interference information is associated with each node over each channel. Several kinds of interference information are provided: (1) Channel that has minimum interference, (2) Current interference value over a specific channel, and (3) Historical interference information of a specific channel.
To access the above information, routing module should have a pointer which points to the current node object. The code highlighted in bold in components 1 to 4, which are illustrated through AODV routing protocol, should be added in your routing module.
Component 1. Declare a Mobilenode pointer in routing module |
Class AODV{ … protected: MobileNode *node_; //pointer to mobilenode object … } |
Component 2. Initialize the Mobilenode pointer through in the command method of your routing module. |
int AODV::command(int argc, const char*const* argv) { … // for the node agent else if(strcmp(argv[1], "node") == 0) { node_= (MobileNode*)
TclObject::lookup(argv[2]); if (node_) { return TCL_OK; } return TCL_ERROR; } … } |
Component 3. Corresponding change should be made in ns-lib.tcl that creates routing agent if no such code exists. |
Simulator instproc create-aodv-agent { node } { # Create AODV routing agent set ragent [new Agent/AODV [$node node-addr]] $ragent node $node ; # to attach the node agent $self at 0.0 "$ragent start" ;# start BEACON/HELLO Messages $node set ragent_ $ragent return $ragent } |
Component 4. Option to select whether to record interference on all nodes |
for {set i 0} {$i < $val(nn) } {incr i} { set node_($i) [$ns_ node] $node_($i)
set recordIfall 1 ; # enable interference information collection $node_($i) random-motion 0 ;# disable random motion } |
If this option is added, the interference information about node i is provided. If the script is created through GUI, the interference information for all nodes is provided.
After adding the components as shown above, the interference information can be obtained as follows.
(1)Channel that has minimum interferences
Interface for obtaining channel with minimum interference around one node.
Module Mobilenode: use the following method to obtain channel number which has minimum interference. |
Class Mobilenode{ public: … // return the channel id that minimum interference int
ChannelwithMinimumIf{ return chanwithminiIf;} … } |
(2)Current interference value over a specific channel
Use the following method to obtain interference value. Please note the interference value is sometimes too small and you may need to scale it by some factor to see the result. This
Module Mobilenode: obtaining interference |
Class PacketPr { … //obtain the interference information for current node double getInterference(int channelno); … } |
(3)Historical interference information
Besides obtaining the channel with minimum interference, the interference information over each channel around can be obtained through the ITfile generated by the simulator. The format of the ITfile is as follow. User can obtain their information through ITfile according to this format.
ITfile format |
Timestamp node id interference channel id |
B. Noise
TCL command for setting noise for physical layer is as follow. This should be added in the simulation script if you want to define the noise.
TCL command: setting noise for physical layer |
Phy/WirelessPhy noise_ 0.1 ;# 0.1 can be replaced by any other noise value |
With the noise information and interference information,
user can change the physical layer of NS-2 to use SINR/
C. Traffic information
For CR routing, it is necessary to use the sensing traffic information to predict the future traffic information in the neighborhood, and derive the best user strategy. The interface this simulator providing are in the two formats (1) obtaining the current traffic information (2) obtaining the historical traffic information.
(1)Obtaining the current traffic information
Module Mobilenode: use the following function in bold to obtain traffic information |
class PacketPr { public: … int getTrafficCount() {return trafficcount;} … } |
User can access this function through the pointer to Mobilenode as in 1.4.3.A. For example, in the AODV, user can access traffic information like this way.
Module Mobilenode: use the following function in bold to obtain traffic information |
… int traffic= node_->PacketPr_.getTrafficCount(); … |
(2)Obtaining the historical traffic information
The historical traffic information is stored in the Trafficfile. User can obtain this information based on the format provided.
Trafficfile format |
Timestamp node id traffic information |
D. Channel Utilization
For some CR routing algorithms, they may need the channel utilization
for routing decision. For users who need channel utilization information, users
need to add the following codes in the
Step1: Add the timer definitions in the
Module Macxx.h:
add timers for channel utilization |
//Timer for channel utilization class ChanUtil_Timer : public TimerHandler { public: ChanUtil_Timer(Macxx *a) : TimerHandler() { a_ = a;} void expire(Event *e); protected: Macxx *a_; }; |
Module Macxx.h:
add timers for calculate channel utilization |
//Timer for Calculate channel utilization class CalChanUtil_Timer : public TimerHandler { public: CalChanUtil_Timer(Macxx *a) : TimerHandler() { a_ = a;} void expire(Event *e); protected: Macxx *a_; }; |
Step2: Add the timer functions’ implementation in the
Add the Module Macxx.cc:
add timer functions’ implementation |
//Timer for recording channel utilzation void ChanUtil_Timer::expire(Event *) { a_->ChanUtil_Calculate(); //Traffic timer expires for every node or the node specified resched(0.01); } //Timer for calculating channel utilzation void CalChanUtil_Timer::expire(Event *) { a_->CalChanUtil_Calculate(); //Traffic timer expires for every node or the node specified resched(1); } |
Step3: Add the timer definitions in the
Module Macxx.h:
add timers variable in Macxx class |
Class Macxx{ … friend class ChanUtil_Timer; friend class CalChanUtil_Timer; … public:
ChanUtil_Timer ChanUtil_Timer_;
CalChanUtil_Timer CalChanUtil_Timer_; void ChanUtil_Calculate(); //function for recording channel utilization void CalChanUtil_Calculate(); //function for calculating channel utilization void increaseChanUtil(){chanutilcount++;} void resetChanUtil() {chanutilcount=0;} int getChanUtil(){return chanutilcount;} … private: … int chanutilcount; … } |
Step4: Add the timer functions’ implementation in the
Module Macxx.cc:
add the related function implementation as defined in Macxx
class. |
void Macxx::ChanUtil_Calculate() { //if mac is not idle if(!is_idle()){ //increase channel utilization counter increaseChanUtil(); } } void Macxx::CalChanUtil_Calculate() { if (((fp = fopen("Chanfile", "a")) != NULL) ) { fprintf(fp, "%lf %d %lf\n", fclose(fp); resetChanUtil(); } else { printf("fail to open file"); } } |
After finishing the above steps, users are able to obtain two kinds of channel utilization information: (1) Current channel utilization information (2) Historical channel utilization information.
(1) Current channel utilization information
The current channel utilization information can be obtained through function getChanUtil() defined in class Macxx. User can obtain this information based on the format provided.
(2) Historical channel utilization information
The historical channel utilization information is stored in Chanfile. User can obtain this information based on the format provided.
Chanfile format |
Timestamp node id channel utilization |
Previous: CR Routing Overview Next: CR MAC Overview
Return to Main....