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.

24 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
    Replies
    1. hiiii..
      this is very helpful link i got it through a lot of browsing .....
      have can i transmit the mac layer information to transport layer of tcp
      plzzzzzzzzzz

      Delete
  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
    4. hi sir, i am a beginner of ns2 i am trying to implement cross layer i am getting an like like you only .what the solution for that please help me for my research

      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
    Replies
    1. How can i pass information from mac layer to transport layer.....means cross layering between mac.cc and tcp.cc

      Delete
  13. ./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

    please help for this error

    ReplyDelete
  14. hiii every one i want to implement cross layer information exchange between transport and network layer???????
    Any type of help or suggestion .....anyone ????

    ReplyDelete
  15. hiii every one i want to implement cross layer information exchange between transport and network layer???????
    Any type of help or suggestion .....anyone ????

    ReplyDelete
  16. Hi, please help me with this.
    When I use this code for cross layer communication, I always get this error with the mac layer access syntax-
    $rt access-mac [$node_ set mac]
    The error is as follows:

    [root@localhost ex]# ns simple.tcl
    invalid command name ""
    while executing
    "$rt access-mac $node_"
    (file "simple.tcl" line 23)
    And also I've declared the mac object in aodv class even then error is still there.
    Then I modified the mac variable in simple.tcl file to that these such errors showed :

    [root@localhost ex]# ns simple.tcl
    can't read "mac_": no such variable
    while executing
    "subst $[subst $var]"
    (procedure "_o22" line 5)
    (SplitObject set line 5)
    invoked from within
    "$node_ set mac_"
    invoked from within
    "$rt access-mac [$node_ set mac_]"
    (file "simple.tcl" line 23)
    Kindly please suggest any solution to this error.
    Thank you!!

    ReplyDelete
  17. hi i need to transmit information from application to network layer, and network layer to application layer leaving transport layer , can you send the code and help me?????

    ReplyDelete
  18. Hello,
    I ran all the steps but I got the following error. How can I solve it?

    #Error:-----------------
    (_o17 cmd line 1)
    invoked from within
    "_o17 cmd acess-mac _o19"
    invoked from within
    "catch "$self cmd $args" ret"
    invoked from within
    "if [catch "$self cmd $args" ret] {
    set cls [$self info class]
    global errorInfo
    set savedInfo $errorInfo
    error "error when calling class $cls: $args" $..."
    (procedure "_o17" line 2)
    (SplitObject unknown line 2)
    invoked from within
    "$rt($i) acess-mac [$node_($i) set mac_(0)]"
    ("for" body line 7)
    invoked from within
    "for {set i 0} {$i < $val(nn) } {incr i} {
    set node_($i) [$ns_ node]
    $node_($i) random-motion 0
    # get the routing layer protocol
    set rt($i) [$n..."
    ------------------------

    Best regards.

    ReplyDelete