Monday, August 8, 2011

Exchanging Cross-layer information in NS2 via the Physical Layer

Accessing Phy Layer from Routing Layer.

The following steps demonstrates how to access Physical layer information from the routing protocol. The OLSR is used as an example:

a) Include in the OLSR.h header file the mobilenode.h file

#include <mobilenode.h>

then, declare a Phy object within the OLSR class

Phy* netif_;

this is possible because, Phy class is within the phy.h file, which is included in the mobilenode.h file

b) Add the following code in the command () function in aodv.cc

int
OLSR:: command (int argc, const char * const * argv) {
. . .
. . .
else if (argc == 3) {
...
...
else if (strcmp (argv [1], "access-phy") == 0) {
netif_ = (Phy *) TclObject:: lookup (argv[2]);
if (netif_ == 0) {
fprintf (stderr, "Agent: %s lookup %s failed. \n", argv[1], argv[2]);
return TCL_ERROR;
} else {
double x, y, z;
((MobileNode*) netif_->node())->getLoc(&x, &y, &z);
printf ("This node's location: %f %f \n", x, y);
return TCL_OK;
}
}
}
. . .
. . .
}

c) Sample tcl script

# get the routing protocol
set rt [$node_ agent 255]
# get the network interface
$rt access-phy [$node_ set netif_(0)]

d) netif_ can now be used from OLSR to access physical layer information


5 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Hi,
    This really helps, and thank for your instructions.
    But, could you tell me how to retrieve the signal strength information (distance information) of the two-ray ground reflection model in NS2 to use in the upper layer (let say the routing layer)?

    Thank you in advance.
    Looking forward to hearing from you...

    ReplyDelete
  3. Hi,
    I am here to request for your help. let me just to explain what i am trying to do. I want to access information available at the physical layer (SINR ) from the routing layer (AODV). In NS-2.34, the SINR is computed inside the file of the folder ns-2.34/mac/wireless-phyExt.cc. That function is described as below:

    double PowerMonitor::SINR(double Pr) {
    if (getPowerLevel()-Pr<=0) {
    // cout<<"PowerLevel lower than Pr"<log("PMX",msg);
    // exit(-1);
    return 0.0; //internal event contention, new msg arrives betweeen the expire of two timers.
    }
    return Pr/(getPowerLevel()-Pr); // this is SINR calculation

    Pr is calculated depending on the propagation model

    I want to get the value returned by the function SINR(double Pr) and use it at the upper layer (AODV). In order to achieve that, we know that we can only compute the SINR at the receiver. Then i used the Hello packets sent in the AODV routing protocol. I went to the header of Hello packet inside the file aodv.h I created a new variable of type integer that will hold the SINR value. I also went inside the function receiveHello() of the aodv.cc i wrote a function to extract that value. I followed the same approach described in the following link: http://jsun74.blogspot.com/2010/10/cross-layer-design-in-ns2-how-can.html. But unfornately I am getting the error below. I don't understand why ns-2.34 is complaining about some variables that are well declared but said they are undeclared. I can access successfully the MAC layer from the routing layer (AODV) but can't access the physical layer from Routing layer (AODV).

    from ./mobile/propagation.h:49:0,

    from ./mac/wireless-phyExt.h:62,

    from ./aodv/aodv.h:44,

    from aodv/aodv_logs.cc:32:

    ./mac/wireless-phy.h:130:38: error: expected identifier before 'r'

    ./mac/wireless-phy.h:130:38: error: expected ‘}’ before 'r'

    ./mac/wireless-phy.h:130:38: error: expected unqualified-id before 'r'

    ./mac/wireless-phy.h: In member function ‘bool& WirelessPhy::Is_node_on()’:

    ./mac/wireless-phy.h:97:37: error: ‘node_on_’ was not declared in this scope

    ./mac/wireless-phy.h: In member function ‘bool WirelessPhy::Is_sleeping()’:

    ./mac/wireless-phy.h:98:34: error: ‘status_’ was not declared in this scope

    ./mac/wireless-phy.h: At global scope:

    ./mac/wireless-phy.h:132:14: error: no matching function for call to
    ‘Sleep_Timer::Sleep_Timer()’

    ./mac/wireless-phy.h:132:14: note: candidates are:

    ./mac/wireless-phy.h:58:2: note: Sleep_Timer::Sleep_Timer(
    WirelessPhy*)

    ./mac/wireless-phy.h:58:2: note: candidate expects 1 argument, 0 provided

    ./mac/wireless-phy.h:56:7: note: Sleep_Timer::Sleep_Timer(const
    Sleep_Timer&)

    ./mac/wireless-phy.h:56:7: note: candidate expects 1 argument, 0 provided

    ./mac/wireless-phy.h:135:1: error: expected unqualified-id before ‘private’

    ./mac/wireless-phy.h:145:2: error: ‘friend’ used outside of class

    ./mac/wireless-phy.h:147:1: error: expected declaration before ‘}’ token

    make: *** [aodv/aodv_logs.o] Error 1


    Thank in advance!

    ReplyDelete
  4. Dear all,

    anyone can suggest...
    what to write in mac_802.11.cc file and
    what should be the sample tcl script

    if i want to access the Queue class from the mac layer(mac_802.11)

    thanking you......

    ReplyDelete
    Replies
    1. Hello there, how are you? Hope you are fine.
      If you find the solution for your problem as you mentioned above, please let me know. I have got the same problem, and I need your help ASAP.
      With best regards

      Delete