Hi All,
    Thank Aslinda for his(her) reply.

    I noticed that the argument type of function get_node_by_address() is
nsaddr_t,  which is defined:
      typedef int32_t nsaddr_t;
    so I don't think that I passed a value "1" to the function is a problem.

     In fact, I defined a topology composed by 11 nodes in .tcl script file,
I just want to make a try how to access node coordination in C++, so pass
whatever value between 0-10 is OK. By the way, I want to know that is it
necessary that my Node class defined in my own C++ file has to inherit from
class Node(in ns-2.34/common/node.h) or MobileNode(in
ns-2.34/common/mobilenode.h) ?

     Could anyone be kind enough to tell the generic procedure of accessing
node coordination in C++ ?

Thank you very much and any suggestion will be appreciated!


On Sun, Sep 11, 2011 at 4:52 AM, Aslinda Hassan <aslinda.has...@mun.ca>wrote:

> Hi..
>
> First of all, why did you put value 1 in the function
> get_node_by_address()? Is 1 is one of your mobilenode? If not, then you need
> to replace value 1 with a mobile node's address.  If you check aodv,cc for
> example, in AODV constructor, you could see that index is referring to
> node's address.
>
> At any rate, I have some experience in using methods in both links.
>  Although I did not receive the same problem as yours, I did encounter
> segmentation fault error when using getLoc() function.  My code managed to
> run smoothly when using method in the second link.
>
> Good luck
> Aslinda Hassan
> Computer Engineering Research Lab
> Faculty of Engineering and Applied Science
> Memorial University of Newfoundland
>
>
>
> -----Original Message-----
> From: ns-users-boun...@isi.edu [mailto:ns-users-boun...@isi.edu] On Behalf
> Of Su Jinzhao
> Sent: Saturday, September 10, 2011 11:58 AM
> To: ns-users@ISI.EDU
> Subject: [ns] Questions on difference about node position in nam file and
> those accessed in C++
>
>
> Hello, friends.
>
> I want to access node coordinates in C++ and node coordinates are initially
> defined in Otcl.
>
>     I referenced these two articles on accessing node coordinates in C++:
>
>
> http://getch.wordpress.com/2011/02/10/finding-node-positionvelocity-and-speed-in-ns2-34/
>
>
> http://getch.wordpress.com/2011/02/08/obtaining-node-position-and-energy-dynamically-in-ns2/
>
>     my .cc file is like this:
>     double x,y,z;
>     MobileNode *iNode = (MobileNode*)(Node::get_node_by_address(1));
>     iNode->getLoc(&x,&y,&z);
>
>    cout << "node1:" << x << " " << y << " " << z << endl;
>
>  And my tcl script is defined like this:
>
>    set val(nn)        11 ;#num of nodes
>    set val(xLimit)        100
>    set val(yLimit)        100
>
>    for {set i 0} {$i < $val(nn)} {incr i} {
>    set node_($i) [$ns node]
>    $node_($i) set X_ [expr {$val(xLimit)*rand()}]
>    $node_($i) set Y_ [expr {$val(yLimit)*rand()}]
>    $node_($i) set Z_ 0.0
> }
>
>    I expect that coordinates of node_(1) defined in my tcl script should be
> print out, however, the result is:
>    node1:7.62437e-316 7.62415e-316 1.3793e-312
>
>     So I am curious that why do these coordinates so small, is there
> anything wrong in my code?(I also searched the NS mail list, the code
> snippet is similar)
>
>    Here is the part of coordinates in the nam trace file:
>    n -t * -a 8 -s 8 -S UP -v circle -c black -i black -x 20.682385433783001
> -y 8.8519855909291589 -Z 0.0
>    n -t * -a 4 -s 4 -S UP -v circle -c black -i black -x 69.835971468051881
> -y 33.172463547984357 -Z 0.0
>    n -t * -a 0 -s 0 -S UP -v circle -c black -i black -x 84.052622403974013
> -y 72.424743591074247 -Z 0.0
>    n -t * -a 10 -s 10 -S UP -v circle -c black -i black -x
> 65.31614762047127 -y 68.493057260519379 -Z 0.0
>    n -t * -a 9 -s 9 -S UP -v circle -c black -i black -x 75.321826746371485
> -y 33.942126265700033 -Z 0.0
>    n -t * -a 5 -s 5 -S UP -v circle -c black -i black -x 29.594850973037467
> -y 0.66030384072116755 -Z 0.0
>    n -t * -a 1 -s 1 -S UP -v circle -c black -i black -x 42.665535184864666
> -y 79.649852020502948 -Z 0.0
>    n -t * -a 6 -s 6 -S UP -v circle -c black -i black -x 97.726651000663011
> -y 91.823368143208029 -Z 0.0
>    n -t * -a 2 -s 2 -S UP -v circle -c black -i black -x 75.062908593128867
> -y 82.3047247167233 -Z 0.0
>    n -t * -a 7 -s 7 -S UP -v circle -c black -i black -x 75.348382897371607
> -y 80.271356124557258 -Z 0.0
>    n -t * -a 3 -s 3 -S UP -v circle -c black -i black -x 95.508313968548691
> -y 8.232869397957284 -Z 0.0
>
>    So I want to know that why does the coordinates accessed by
> get_node_by_address() function is not the same as those in nam trace file
> or in the nam GUI ?
>
> Thank you very much, any suggestions is appreciated.
>
> --
> Su Jinzhao(苏金钊)
>
>
> This electronic communication is governed by the terms and conditions at
> http://www.mun.ca/cc/policies/electronic_communications_disclaimer_2011.php
>



-- 
Su Jinzhao(苏金钊)

Reply via email to