NS3 Context and having static variables For nodes that run C code

119 views
Skip to first unread message

Rob Kers

unread,
Sep 10, 2018, 11:36:24 AM9/10/18
to ns-3-users
Hi there!

I have the following two questions: What is context (or schedule with context) and how much is affected when a context is switched? I've read this part here about context https://www.nsnam.org/docs/manual/html/events.html . However, it's not clear to me what is changed if the context is switched. I'm asking because I've got the following problem.

I developing a sensor network and want to simulate this network. Since the real life sensors with embedded software run only C, I want to write my simulator logic in C as well. The mind set is: develop a network that can run on the embedded platform and test it using NS3. This means that the code should be as close to an efficient implementation in the embedded platform as possible. Since I can work with statics (global vars that are easily accessible from any function) in my embedded environment, I would like to do the same in my simulator. However, If I write C wrappers for my C++ class (NS3 node for example) to interface with the PHY layer in NS3, I have difficulties to determine my "context" (again, not sure how the word "context" in NS3 is used). I do not have access to a Node object anymore, since i'm in C. Therefore calling using "this->" is impossible. Ideally I would like to get a C equivallent of "this". This is however hard (if not impossible) to achieve with work arounds. Therefore, this has to be solved differently. 

I have the following options:

- pass to every C function a pointer to a shared C struct where all data of a node is saved (parameters, states, etc). However, this is pollution to my C code for the embedded platform. For example, this would mean that every function becomes "sendBeacon(NodeStruct * nodeStruct)" in stead of simply "sendBeacon()".
- switch static variable context every time the scope is changed from one node to the other. This involves implementing a switching algorithm and does not guarantee that NS3 is executing functions in the background that have a different scope/context. With this I truly mean changing all static pointers to data every time a context switch happens.
- run every single node in a separate thread. With this, one can initialise global variable/statics that are only accessible from within that thread. However, I'm afraid for performance impact and shared resource problems.

Any help is much appreciated! Thanks in advance!


Rob Kers

unread,
Sep 11, 2018, 4:00:25 AM9/11/18
to ns-3-users
Hi all!

I think I understand the context and how it can help by getting the right info in my C functions. By writing a C wrapper ( for example getMac()) that calls to a C++ object, which knows the context. I keep you posted

Op maandag 10 september 2018 17:36:24 UTC+2 schreef Rob Kers:

abhishekreddy billakanti

unread,
Sep 11, 2018, 5:55:20 AM9/11/18
to ns-3-...@googlegroups.com
sir
i need a leach routing protocol  source code using ns3

regards
abhishek

--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+...@googlegroups.com.
To post to this group, send email to ns-3-...@googlegroups.com.
Visit this group at https://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.

Rob Kers

unread,
Sep 11, 2018, 6:32:02 AM9/11/18
to ns-3-users
Not sure if this is the right thread for that. You better search for a C/C++ implementation. If you found one you might have to port it.

Op dinsdag 11 september 2018 11:55:20 UTC+2 schreef abhishekreddy billakanti:
Reply all
Reply to author
Forward
0 new messages