On 01/22/2016 01:47 AM, Mehran Zamani wrote:
>
>
> 1- about my problem, i ask about the code i meant the instruction(single
> line of code) that i can reach to node status. i want to know which
> nodes are at 1 hop distance of arbitrary node.
There is no single line of code that provides the information you ask
for. Tommaso outlined an approach on how to obtain this information.
If you have a pointer to the Olsr routing protocol instance, you can get
its full routing table, output as a std::vector of entries:
std::vector< RoutingTableEntry >
ns3::olsr::RoutingProtocol::GetRoutingTableEntries () const
You can then iterate this vector and look for all 1-hop distance.
So, if you have a pointer (an ns-3 smart pointer) to the Node of interest:
Ptr<Node> node = ...;
then you can obtain the Olsr routing protocol pointer as follows:
Ptr<Ipv4> ipv4Ptr = node->GetObject<Ipv4> ();
Ptr<Ipv4RoutingProtocol> ipv4Routing = ipv4Ptr->GetRoutingProtocol ();
// Obtain the Ipv4ListRouting interface
Ptr<Ipv4ListRouting> ipv4ListRouting = DynamicCast<Ipv4ListRouting>
(ipv4Routing);
// A list routing protocol has multiple Ipv4Routing protocols. Find
OLSR in this list
Ptr<olsr::RoutingProtocol> olsrProtocol;
int16_t priority;
for (uint32_t i = 0; i < ipv4ListRouting->GetNRoutingProtocols (); i++)
{
Ptr<Ipv4RoutingProtocol> proto =
ipv4ListRouting->GetRoutingProtocol (i, priority);
olsrProtocol = DynamicCast<olsr::RoutingProtocol> (proto);
if (olsrProtocol != 0)
{
break; // found the protocol we are looking for
}
}
NS_ASSERT_MSG (olsrProtocol, "Didn't find OLSR on this node");
>
> 5- i am eager to study the basics about it. thanks for your help.
So then you should be able to take this pointer and call the method
GetRoutingTableEntries () on it, and then look through each entry in the
vector that is returned, and check its distance.
The list of neighbors will change over time, so you will probably want
to schedule an event for some simulation time in the future, to call the
above. The way to do this is to encapsulate all of the above statements
into a new function, and schedule that function for a simulation time of
interest (in ns-3, events are function calls). The tutorial explains
how to do this generally.
As an aside, you asked for a one line statement of how to get the
one-hop neighbors, and learned that it doesn't exist. It will take
several statements (the ones above, plus the ones you need to provide to
iterate the routing table entries).
If you are so inclined, you might consider to contribute back, at a
future date, a small patch to our existing OlsrHelper that encapsulates
all of the above statements into a new method such as:
std::vector<RoutingTableEntries> GetRoutingTableEntries (Ptr<Node>
node) const;
or even something like
std::vector<uint32_t> GetOneHopNeighborNodeIds (Ptr<Node> node) const;
and then provide the patch to our bug tracker or to a maintainer, to
improve the helper API over time.
- Tom