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!