how to get a node state?

418 views
Skip to first unread message

Mehran Zamani

unread,
Jan 15, 2016, 1:31:52 AM1/15/16
to ns-3-users
hi
i am new in ns3 and i am trying to understand how olsr works inside ns3. i used an example in the examples named wifi-simple-adhoc-grid.cc
i want to get olsr routing table which i think i can get it from node state. but i don't know how to reach it since there is only olsrhelper defined in that code.
could someone help me with that. how can i get 1 hop (neighbor) or 2 hop routing table for a node [they change through time because our nodes moves, right] in that code?
should i change the code completely? how can i use getneibors function which is in ns3::olsr::OlsrState::GetNeighbors?

thanks in advance

Tommaso Pecorella

unread,
Jan 15, 2016, 11:27:53 AM1/15/16
to ns-3-users
Hi,

it really depends on what you want to do and how much the info needs to be precise (and timely).
You can print the routing table periodically, and check from that info the 1-hop neighbors. However, not all neighbors are in the routing table, just the ones that are actively being used.

Anyway, I'd start by double checking the tutorial and in particular how to access node's objects. You can get a pointer to the routing object and poke the neighbor table, eventually defining a new function.

However, the real question is: are you sure it's the right thing to do ? From the smell of it, you're going to have a "God mode" knowledge of the 1-hop neighbors, and this is not going to be very realistic...

Cheers,

T.

Mehran Zamani

unread,
Jan 15, 2016, 12:54:18 PM1/15/16
to ns-3-users
u seemed to be expert in this area. could u send the code that we can reach to one node 1 hop neighbors?

Mehran Zamani

unread,
Jan 22, 2016, 1:59:21 AM1/22/16
to ns-3-users
Nobody can help me!!!
really? i thought people are moving from ns2 to ns3 but now it turns out to be wrong. because lack of support and tutorials to move forward.

Tommaso Pecorella

unread,
Jan 22, 2016, 4:14:42 AM1/22/16
to ns-3-users
Hi,

are you joking, right ? Do you think that insulting us is the right way to receive help ?
Your question was ignored because we can't (and don't want) to flame people. My first reply was more than enough to point you in the only possible direction: studying.

Alas, from the question it is clear that you do not know the ns-3 routing protocol organization - you asked for the 1-hop neighbors and you didn't mention the routing protocol - or the technology you're thinking to (Wi-Fi? LTE? 802.15.4? WiMAX?).
Moreover, you're referring to a "node status". There's no such thing and it's explained in the tutorial and the manual. You did not read them.
Hence, the very first point is: incomplete question.

After suggestion that you need to study the basics, you ask for the code (?!?!) without even bothering to understand your previous mistakes. In other words, you asked for a piece of code without even bothering to explain exactly the problem boundaries.
Two big errors. The first is to not explain the problem. The second is to assume that we provide code. We give help, we can fix some bugs, but the code is your. We're not a bunch of programmers-for-hire-for-free.

I'll skip to comment further the last message. It's just too arrogant.

What is the next step ?
Simple, you can apologize. and fix your mistakes. Study and try to do what you asked by yourself and, eventually, ask for specific things.

In the meantime, I can (and will) ask you one thing: how's the weather in Halifax ?

T.

Mehran Zamani

unread,
Jan 22, 2016, 4:47:31 AM1/22/16
to ns-3-users
Hello sir

if u find my answer insulting, i apologize but i rather mention some points. first of all i complain about support and tutorial not specific person and secondly it is a poor support whether u like it or not but in the end i don't want to insult anyone.


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.

2- about me not saying protocol. come on. i tag it(olsr). do u know where is it?

3- i am happy to read 1000 page learning material to get what i want but the problem is that there isn't one.

4- there is no node state?!!! FYI nodes send hello message packet to check which nodes are neighbors and update their tables. cuz nodes are moving! (wireless u know?).
ns3::olsr::OlsrState
https://www.nsnam.org/doxygen/classns3_1_1olsr_1_1_olsr_state.html

5- i am eager to study the basics about it. thanks for your help.

by the way, it is warm here, i don't know about Halifax. you'd mistake me for another person.


thx

Tom Henderson

unread,
Jan 22, 2016, 11:01:45 AM1/22/16
to ns-3-...@googlegroups.com
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

Mehran Zamani

unread,
Feb 5, 2016, 12:22:47 AM2/5/16
to ns-3-users
Hi Tom
olsr routing table is not exactly what i wanted but i can determine which nodes are at 1 hop neighborhood by looking at next addresses in that table. it was a big help (breakthrough) and i thank you in advance and also apologize if i didn't clarify my question in the first place. i appreciate your effort.
Reply all
Reply to author
Forward
0 new messages