2.3.1 Create CR multi-channel environments

A. Single-radio multi-channel

The following four components should be added by user to create the multi-channel environments. The channels created in this part have identical spectrum parameters. Please note that if you are using GUI provided by this simulator, this section can be skipped.

 

Component 1.Define the channel number in TCL script

set val(channum)        2                           ;# 2 channels are available in the network

 

Component 2. New channel objects according to the interface number provided in Component 1.

for {set i 0 } { $i < $val(channum)} {incr i} {

    set chan_($i) [new $val(chan)]                 ; #new channel objects

}  

 

Component 3. Configure the multiple channel option

       …

        $ns_ node-config -adhocRouting $val(rp) \

        …

                          -ChannelNum $val(channum)\         ;# configure channel number

                          -channel $chan_(0)                           ;#configure the first channel object

         …

 

Component 4. Assign the channel objects to the channel array of the simulator

       … 

for {set i 0} {$i < $val(ni) } {incr i} {

    $ns_ add-channel $i $chan_($i)       ; # initialize the channel array with channel objects

}

      …

 

 

B. Multi-radio multi-channel

The following four components should be added by user to create the multi-radio, multi-channel environments for MAC. The channels created in this part have identical spectrum parameters. Please note that if you are using GUI provided by this simulator, this section can be skipped.

 

Component 1.Define the radio and channel number in TCL script

set val(ni)        2               ;# number of radios

set val(channum)        2                           ;# 2 channels are available for each radio

 

Component 2. New channel objects according to the radio and channel number provided in Component 1.

for {set i 0} { $i < [expr $val(ni)*$val(channum)]} {incr i} {

              set chan_($i) [new $val(chan)]

  }

 

Component 3. Configure the multiple radio and channel option

$ns_ node-config -ifNum $val(ni) -channel $chan_(0)

$ns_ node-config -ChannelNum $val(channum)

 

Component 4. Assign the channel objects to the channel array of the simulator

for {set i 0} {$i < [expr $val(ni)*$val(channum)] } {incr i} {

           $ns_ add-channel $i $chan_($i)

}

 

2.3.2 Channel/RaDIO decision

The channel decision from CR MAC or DSA algorithm should be set through the interfaces provided as follow, which reflects the channel that the receiver is using to receive packet. A new field channelindex_ is added into the packet header. After CR MAC or DSA make channel decision, this decision can be stored into this field.

Module packet.h:

struct hdr_cmn {

        …

        int channelindex_;

        …

}

 

The code as follow should be added in the sendDown function for wirelessphy. In our design, multiple channel object pointer is used to index the channel object. Hence, it is appropriate to use channel index derived in CR MAC or DSA algorithms to differentiate channel, which helps to achieve conflict free or reduce interference among neighboring nodes. channelindex_ defined in the packet header can carry this information from CR routing, CR MAC or DSA to the wireless physical layer. (Please note that this part is already added in the code we provide.)

 

Module WirelessPhy: Interface for channel decision in MAC

void WirelessPhy::sendDown(Packet *p)

{

             …

            // Send the packet

            //channel_->recv(p, this);

           //send packet over the channel specified by channel index.

            multichannel[hdr_cmn::access(p)->channelindex_]->recv(p, this);

          …

}

 

If user’s MAC is for single-radio and multi-channel network, the above code change is enough to differentiate different channels for MAC protocols. However, users still need to design their own collision avoidance mechanism or DSA according to the NS-2 protocol design structures.

 

If user’s MAC is for multi-radio and multi-channel network, codes related to the radio selection is needed besides the channel decision code as above. Depending on the usages of each radio, users need to add code in the MAC layer to differentiate what current radio is for. For example, if each node has 2 radios: radio 1 is assigned to common control channel; radio 2 is assigned to data channel. In user’s code for MAC, user need to restrict the radio 1 only to handle the control packets, and radio 2 only to handle the data packets. To provide flexibility for this simulator, we do not add any restrictions for the multi-radio, multi-channel MAC. Users also need to choose appropriate routing protocol for their multi-radio, multi-channel MAC. To differentiate the current radio from one another, users can just use the index_, which is declared in Mac.

2.3.3 Txpower decision

Packet will be transmitted using the default transmission power if transmission power is not specified in simulation script. However, as CR MAC and DSA algorithms may control the txpower over each channel to control the interference to primary users or nearing neighbors, it is necessary to provide an interface, which can control the txpower during the simulation.

 

The DSA algorithm can be implemented in the following functions, which are in bold.

 

Module Mobilenode: Interface for obtaining the transmission power from DSA algorithms.

Class PacketPr{

public:

   …

    //Obtain DSA decision according to different input parameters.

double getDSAPr(int receivernode);     

double getDSAPr(int receivernode, int channelindex);

 

   …

}

 

Then, add the following interface for controlling the maximum transmission power and obtaining DSA power decision. Please note that other physical layer can be modified in the similar way.

 

Module WirelessPhy: Interface for channel decision in MAC

int  WirelessPhy::sendUp(Packet *p)

{

       …

          double DSAPr= (MobileNode*)node()->PacketPr_.getDSAPr();

          //if the Pr is within the limit range of user, assign DSAPr to Pr.

         Pr=DSAPr;    

      …

}

 

To determine the txpower, the DSA algorithms need to know the identity of sender and receiver. In some DSA algorithms (such as game based), sender and receiver has negotiated the channel decision, and thus the power control algorithm compute the txpower over the negotiated channel.

 

2.3.4 Information needed by CR MAC

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. Users can use the corresponding API into their algorithm to obtain the information.

 

(1)Channel that has minimum interferences

Interface for obtaining channel number with minimum interference around one node. Use the following method to obtain channel number which has minimum interference.

 

Module Mobilenode: obtain channel with minimum interference

Class PacketPr{

…

        //return the channel id with 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.

 

Module Mobilenode: Interface for channel decision in MAC

Class PacketPr {

        …

//obtain the interference information for current node     

double getInterference(int channelno);

…

}

 

(3)Historical interference information

To obtain the historical information of node i, the following option to select whether to record interference on node i should be added in simulation script by the user.

 

TCL script: add the interference option

for {set i 0} {$i < $val(nn) } {incr i} {

                        set node_($i) [$ns_ node]

                $node_($i) set SingleIfMultiChan 1      ;

                $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 using GUI, the interference information for all nodes is provided by default.

 

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/SNR reception model according to their needs.

 

C. Traffic information

For intelligent based MAC, 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

Use the following function in bold to obtain traffic information.

 

Module Mobilenode: obtain traffic information

class PacketPr {

public:

     …

     int getTrafficCount() {return trafficcount;}

     …

}

 

Users can access this function through the pointer to mobilenode. For example, in the MAC for 802.11, users can access traffic information like this way.

 

Module Mobilenode: obtain traffic information

…

int traffic= ((MobileNode*)(netif_->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

 

Previous: CR MAC Overview        Next: Software and Installation

Return to Main