Bugzilla – Bug 2186
Add ns3::Callback capability to DCE-Linux SysctlGet API
Last modified: 2015-09-28 09:44:00 EDT
Created attachment 2152 [details]
Patch to implement the described enhancement
When running a DCE-Linux simulation, the current API for LinuxStackHelper::SysctlGet requires passing a function pointer [void (*callback)(std::string,std::string)] to a callback function. This function is then called after the Sysctl Get is executed. The parameters passed to the function include "path" std::string that was queried, and the "value" std::string that the kernel returned.
If the simulation has more than one DCE-Linux node that use this API, then it can be difficult to tell which node returned which value. A simple solution is to define a separate function for each node, but this is neither convenient nor good coding practice, especially as the number of nodes increases.
A better and more elegant way would be to define an overloaded API call that uses an ns3::Callback instead of a function pointer. The ns3::Callback can be a Bound Callback that has extra arguments (like a functor or closure).
The attached patch implements the additional API that uses a Callback.
Created attachment 2154 [details]
Example code that uses proposed new API
There is a #define on line #141 that controls whether the original or the new (proposed) API is used.
It is commented out and when commented out, the example code will use the original API.
If it is uncommented, and the #define takes effect, the example code will use the new (proposed) API.