Hi, dear ns3 user:
I have difficulty to understand the following code in examples/stats/wifi-example-sim.cc
Config::Connect ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRx",
MakeCallback (&PacketCounterCalculator::PacketUpdate,
totalRx));
I find the MacRx trace source in wifi-mac.cc
.AddTraceSource ("MacRx",
"A packet has been received by this device, has been passed up from the physical layer "
"and is being forwarded up the local protocol stack. This is a non-promiscuous trace.",
MakeTraceSourceAccessor (&WifiMac::m_macRxTrace),
"ns3::Packet::TracedCallback")
and the corresponding m_macRxTrace' signature is
TracedCallback<Ptr<const Packet> > m_macRxTrace;
The signature of PacketUpdate is
void
PacketCounterCalculator::PacketUpdate (std::string path,
Ptr<const Packet> packet)
I know that
1. the 1st arguement path in PacketUpdate is related to the 1st arg in Config::Connect, which may be the context.
2. the 2nd arguement packet in PacketUpdate is what we concerned and we will retrive some infomation from it. when m_macTxTrace(packet), the code we write could be called.
SO:
Ptr<PacketCounterCalculator> totalRx =
CreateObject<PacketCounterCalculator>();
totalRx->SetKey ("wifi-rx-frames");
totalRx->SetContext ("node[1]");
How to understand when I make a callback from PacketUpdate and totalRx in Config::Connect?
I think only the PacketUpdate is enough, as the first Dataculator eample which I can understand:
Ptr<CounterCalculator<uint32_t> > totalTx =
CreateObject<CounterCalculator<uint32_t> >();
totalTx->SetKey ("wifi-tx-frames");
totalTx->SetContext ("node[0]");
Config::Connect ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTx",
MakeBoundCallback (&TxCallback, totalTx));
data.AddDataCalculator (totalTx);