I want to implement energy model in unetstack, I know it's theory but don't know how to implement it in the unetstack as I'm still learning it. Please provide the steps involved in it. Basic code skeleton will also be helpful.
Expected Output : I expect the output that every node after transmitting/receiving packets, it prints out the remaining energy.
The most natural place to keep track of energy would be in the PHYSICAL (phy
) agent. Assuming you are using the HalfDuplexModem
phy
in a UnetSim, I'd subclass it and monitor the TxFrameNtf
and RxFrameNtf
by overriding the send()
method. I'd then add relevant energy
attribute to keep track of the energy usage.
Example Groovy code:
import org.arl.fjage.Message
import org.arl.unet.sim.HalfDuplexModem
class MyHalfDuplexModem extends HalfDuplexModem {
float energy = 1000 // change to whatever initial energy your node has
@Override
boolean send(Message m) {
if (m instanceof TxFrameNtf) energy -= 10 // change according to your model
if (m instanceof RxFrameNtf) energy -= 1 // change according to your model
return super.send(m)
}
}
Finally, in the simulation DSL, you can replace the default HalfDuplexModem
by your customized version:
modem.model = MyHalfDuplexModem