Monday, February 14, 2011

Exchanging Cross-layer information in NS2

I used this document to achieve cross-layer exchange of info in my wireless simulation in ns2. As an example, the routing layer and mac layer will be considered. This piece of code was based on the posts on the link below, but if you copy paste the code, there will be errors, and your simulation will not run. I made some corrections on the syntax and made it work in ns2.34.

http://jsun74.blogspot.com/2010/10/cross-layer-design-in-ns2-how-can.html

the author above requests that these sites be referred to instead:

http://blog.chinaunix.net/u3/94593/showart_2199303.html
http://www.baisi.net/thread-2471888-1-2.html

1. Accessing MAC Layer from Routing Layer.

Here the 802.11 mac and AODV routing protocol are used as an example:

a) Include in the aodv.h header file the mac-802_11.h file

# Include "mac/mac-802_11.h"

then, declare a mac object within the aodv class

Mac802_11 * this_mac;

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

int

AODV:: command (int argc, const char * const * argv) {
. . .
. . .
else if (argc == 3) {
if (strcmp (argv [1], "index") == 0) {
index = atoi (argv [2]);
return TCL_OK;
}
else if (strcmp (argv [1], "access-mac") == 0) {
this_mac = (Mac802_11 *) TclObject:: lookup (argv [2]);
if (this_mac == 0) {
fprintf (stderr, "Agent: %s lookup %s failed. \ n", argv [1], argv[2]);
return TCL_ERROR;
}
else {
printf ("This node's mac bss_id: %d \ n", this_mac-> bss_id ());
return TCL_OK;
}
}
. . .
. . .
}

c) Sample tcl script

# get the routing layer protocol
set rt ($i) [$ node_ ($ i) agent 255]
# establish access path to the mac
$rt ($i) acess-mac [$ node_ ($ i) set mac_ (0)]

d) this_mac can now be used from aodv to access 802.11 mac information

other method exists, that would be my topic on my succeding posts.

15 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Hi,
    Your code was very helpful..Can u help me to in transmitting the information from the mac layer to application layer??

    ReplyDelete
  3. The process should be the same.

    In step 1.a, instead of including the mac-802_11.h file into the aodv.h, include it in the header-file of your application.

    # Include "mac/mac-802_11.h"

    then, declare a mac object within the aodv class

    Mac802_11 * this_mac;

    then follow the same steps.

    ReplyDelete
  4. ah, correction above
    it should be:

    then, declare a mac object within your application class

    Mac802_11 * this_mac;

    then follow the same steps.

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. Hi,

    Your code is very helpful to me. I'm working on IEEE802.11e EDCA and my cross layer is between the Udp class and the Mac802_11e class. I follow all above instructions but I got an error when I include in the udp.h header file the mac-802_11e.h file which is :
    In file included from apps/udp.h:27,
    from apps/udp.cc:24:
    ./mac/802_11e/mac-802_11e.h: At global scope:
    ./mac/802_11e/mac-802_11e.h:120: error: ‘ETHER_ADDR_LEN’ was not declared in this scope
    ./mac/802_11e/mac-802_11e.h:121: error: ‘ETHER_ADDR_LEN’ was not declared in this scope
    ./mac/802_11e/mac-802_11e.h:122: error: ‘ETHER_ADDR_LEN’ was not declared in this scope
    ./mac/802_11e/mac-802_11e.h: In member function ‘u_int32_t EDCA_PHY_MIB::getHdrLen11()’:
    ./mac/802_11e/mac-802_11e.h:160: error: ‘ETHER_FCS_LEN’ was not declared in this scope
    ./mac/802_11e/mac-802_11e.h: At global scope:
    ./mac/802_11e/mac-802_11e.h:209: error: expected class-name before ‘{’ token
    ./mac/802_11e/mac-802_11e.h:234: error: ‘MacState’ has not been declared
    ./mac/802_11e/mac-802_11e.h:235: error: ‘MacState’ has not been declared
    ./mac/802_11e/mac-802_11e.h:390: error: ‘MacState’ does not name a type
    ./mac/802_11e/mac-802_11e.h:391: error: ‘MacState’ does not name a type
    ./mac/802_11e/mac-802_11e.h: In member function ‘int Mac802_11e::initialized()’:
    ./mac/802_11e/mac-802_11e.h:304: error: ‘Mac’ has not been declared
    make: *** [apps/udp.o] Error 1


    and this error belongs to #include "mac/mac-802_11.h" line,
    So would help me if you have an idea about how to fix this error, please? I'm stuck in this error from long time.

    Thanks for your help in advance.

    ReplyDelete
    Replies
    1. hi Red rose,
      can u help me how to make cross layer between transport and physical layers...how to call propagation.cc file in snoop.cc file .am beginner of ns2..am waiting for ur help.thanks in advance.
      by
      shiny

      Delete
    2. Hi Shiny John,
      I'm also a beginner of ns2, I used above short tutorial to make the cross layer, so why you don't use it? I think you should do the same:

      The process should be the same:

      1. Include the header file of propagation.cc which is as I think should be propagation.h in the snoop.h

      # Include "../propagation.h"

      then, declare an object of propagation class within the snoop.cc class

      propagation *test;

      then you have to follow the same steps in the tcl file. Actually, I follow same steps but I am stuck in errors as you can see the above error. You can also use the following link, (https://github.com/smtatapudi/ns2-contrib) they are following same procedure as mentioned above in their project. I'm still stuck in errors and if I successfully manage to do the cross layer, I will help you in details for your case.


      Delete
    3. See also this link, it belongs for the same author and it may help you http://wmnatupdiliman.blogspot.com/2011/08/exchanging-cross-layer-information-in.html

      Delete
  7. hi rose .. help me in how to write a program for cross layer design

    ReplyDelete
  8. Hi...
    This is really a helpful one. I would really appreciate your effort.

    But, I'd like to ask if we can follow the same steps to implement the cross layer (for example, phy to transport layer) other than the one in this post?

    Thanks

    ReplyDelete
  9. Hi frndz,
    I have tried to make a cross layer between snoop.cc and mac-802_11.cc by following the above steps. I got error when i add mac object this_mac. help me frndz to clear the following error
    In file included from tcp/snoop.cc:41:
    tcp/snoop.h:136: error: ISO C++ forbids declaration of ‘mac802_11’ with no type
    tcp/snoop.h:136: error: expected ‘;’ before ‘*’ token
    tcp/snoop.cc: In member function ‘virtual int Snoop::command(int, const char* const*)’:
    tcp/snoop.cc:154: error: overloaded function with no contextual type information
    tcp/snoop.cc:158: error: ‘this_mac’ was not declared in this scope
    make: *** [tcp/snoop.o] Error 1

    Thanks in advance

    ReplyDelete
  10. Hello sir,
    This code is very helpful.can u help me how to invoke RTS packet transmission from mac layer to routing(AODV) layer?

    ReplyDelete
  11. Good day Dear,

    I am trying to access the Mac Layer from the Routing layer of AODV. I followed all the steps but I think i have a problem with the last one, when i try to add the last step to my tcl script in order to get the right pointer, I am getting the following error
    can't read "rt(0)_o17": no such variable
    while executing
    "set rt($i)[$node_($i) agent 255]"
    ("for" body line 5)
    ..........
    My question is what rt stands for? is it the AODVagent?

    Regards!

    ReplyDelete
  12. Hi when i use your steps for cross layer from mac.h to tcp.c
    i get the following error while using make
    In file included from ./mobile/energy-model.h:48:0,
    from ./common/node.h:59,
    from ./mac/channel.h:47,
    from ./mac/phy.h:60,
    from ./mac/mac.h:48,
    from ./tcp/tcp.h:40,
    from ./trace/basetrace.h:41,
    from queue/errmodel.h:47,
    from queue/errmodel.cc:54:
    ./trace/trace.h:70:2: error: ‘BaseTrace’ does not name a type
    What might the problem be?
    i have included in tcp.h
    #include "mac/mac.h"
    Mac *m;
    and
    in tcp.cc

    int TcpAgent::command(int argc, const char*const* argv)
    {
    //edited here following your steps
    }

    Regards...

    ReplyDelete