Hi Samira,

I had the same question and i got the following reply from Mr. Keven  
Sheth that turned out to be useful. What he answered specifically is  
how to calculate the distances between to nodes, which uses the  
coordinates of the nodes by accessing them from struct mb_node in file  
God.cc (in ./mobile). After retrieving the nodes coordinates i think  
it becomes an easy task to pass them to the MAC layer.

I also found the same solution that Keven proposed at this link:
http://www.cse.msu.edu/~wangbo1/ns2/nshowto2.html

Below i will paste Keven's original reply. I hope it turns out useful.

Cheers,
Mathiew

------------KEVIN'S REPLY--------------------
Hi Mathiew

I needed to the same in my project.
what I did is used god object.
you can study  and you can do many more things using it .
here I am just describing what I did:

I added following function in ns-2.33/mobile/god.cc (you will need to  
add declaration in god.h)

double God::getdistance(int i,int k)

{

double x1=mb_node[i]->X();

double y1=mb_node[i]->Y();

double x2=mb_node[k]->X();

double y2=mb_node[k]->Y();

double distance;

distance=sqrt(((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)));

return distance;

}
then I was able to get distance between two nodes by writing following  
code in c++


God::instance()->getdistance(i,k);  // i and k are the id of the nodes

you will also need to include following statements in your .tcl file

1 after creating topography

set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)

set god_ [create-god $val(nn)]

2. when you are dynamically creating nodes

for { set i 0 } { $i < $val(nn) } { incr i } {
     set node_($i) [$ns_ node $i]
     $node_($i) random-motion 0 ;# disable random motion
     $god_ new_node $node_($i)
}

following is a function of my agent for your reference:

void Manetconf::neighbors(int i)
{
  int nodes=God::instance()->nodes();
  cout<<"neighbors of node "<<i<<":"<<endl;
  for(int k=0;k<nodes;k++)
  {
   if(k!=i)
   {
    if(God::instance()->IsNeighbor(i,k))
     cout<<k<<":"<<God::instance()->getdistance(i,k)<<" yes"<<endl;
    else
     cout<<k<<":"<<God::instance()->getdistance(i,k)<<" no"<<endl;
   }
  }
  cout<<endl;
}

-----------------------------------










Quoting samyar....@gmail.com:

> hi Mathiew
>
> I have exactly same as your problem. I want to send node coordinate   
> or position to MAC layer and amke some desicion base on this   
> information. can i ask you which routing and MAC do you use?
> anyway i think we have tosend this information through routing layer  
>  and not bye TCL.
> my email: samyar....@gmail.com
>
> and my name is SAMIRA .
>
> thanks a lot
>




Reply via email to