Hello everyone! I'm new to ns-3 and I'm currently working on my master thesis, doing some simulations on VANET. After searching for my specific problem with static variables, I could not find anything here related to it.
I'm making a Propagation Loss Model that will read RSSI values from a tracefile, in order to use real measured values in the simulation.
In my current implementation i have a std::map that stores RSSI values with respect to (origin_node,destination_node,simtime).
There are other class members which are necessary, just to check if the model can be used ( in order to limit the usage of the model outside of the data range).
Those are simTime ( which keeps the simulation time to obtain the correspondent RSSI when calcRxPower is called), nodeNum (to check orig and dest values) and duration (to check if simtime is within data boundaries).
Currently have 2 approaches:
- Using non-static variables and defining parameters with Config::Set and Config::SetDefault
- Using static variables and loading parameters by calling static class methods (doesn't work)The problem here is that i want to make this map a static member of my propagation model class and load the values from the file into that variable.
I've managed to do it without using static members, by making it load the traceFile on the constructor. Although, i noticed that when the constructor is called the attributes (set on the simulation script with Config::SetDefault before running simulation) are still undefined. If I change all the variables to static and change the loadtracefile method to static as well, removing the .AddAtribute(because it doesn't work with static members). Then i obtain this error:
[2300/2543] Linking build/libns3-dev-propagation-debug.dylib Undefined symbols for architecture x86_64: "ns3::RealSignalPropagationLossModel::m_duration", referenced from: ns3::RealSignalPropagationLossModel::LoadTraceFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in propagation-loss-model.cc.1.o ns3::RealSignalPropagationLossModel::SetLinkRSSI(int, int, int, double) in propagation-loss-model.cc.1.o ns3::RealSignalPropagationLossModel::SetParameters(double, int) in propagation-loss-model.cc.1.o ns3::RealSignalPropagationLossModel::DoCalcRxPower(double, ns3::Ptr<ns3::MobilityModel>, ns3::Ptr<ns3::MobilityModel>) const in propagation-loss-model.cc.1.o "ns3::RealSignalPropagationLossModel::m_nodeRssi", referenced from: ns3::RealSignalPropagationLossModel::LoadTraceFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in propagation-loss-model.cc.1.o ns3::RealSignalPropagationLossModel::SetLinkRSSI(int, int, int, double) in propagation-loss-model.cc.1.o ns3::RealSignalPropagationLossModel::DoCalcRxPower(double, ns3::Ptr<ns3::MobilityModel>, ns3::Ptr<ns3::MobilityModel>) const in propagation-loss-model.cc.1.o "ns3::RealSignalPropagationLossModel::m_traceFile", referenced from: ns3::RealSignalPropagationLossModel::RealSignalPropagationLossModel() in propagation-loss-model.cc.1.o "ns3::RealSignalPropagationLossModel::m_nodeNum", referenced from:The code for both versions of the model is in attachment.So, my questions are: - What is the issue of using static variables in the class? Is it recommended or not? knowing that in this case i want the model to be exactly the same for each vehicle - Why can't I use .AddAtribute when the members are static in the class? - When I do Config::SetDefault for all the parameters (with the non-static version of the model) first and then do .AddPropagationLoss to the channel, why aren't these members set when the constructor of the class runs? Are the attributes only set before the constructor runs? Hope you can help me with this. Thanks in advance.