Closed laikinlong closed 1 year ago
I thin I found the solution: you have to create, in the omnetpp.ini file, an app for each node to communicate with the BS. What I wrote is the following:
**.host*.numApps = 1
**.app[0].typename = "UdpBasicApp"
**.app[0].startTime = uniform(10s, 30s)
**.app[0].sendInterval = 1s
**.app[0].destAddresses = "baseStation"
**.app[0].localPort = 9001
**.app[0].destPort = 9001
**.app[0].messageLength = 100B
The code should be self-explanatory. There, each node will send UDP msgs. I'm looking for a simple way to keep track of the packet loss rate since it's UDP, I'll post here my solution if you tell me that it'll be useful to you. It'll probably a python script that looks through the results folder.
I think the problem is the random number generation. In my case, all the "randNo" is greater than the threshold. Therefore, the node keeps sending self-message. When I adjust the threshold, the node can send the message.
How can I adjust the random number generation range since "randNo" is too close? (eg. 0.86701, 0.867887, 0.868607, 0.867511, 0.866799, 0.868309)
Thanks for your help!
I think the code in generateThresholdValue
is incorrect, and that the first line lacks of parenthesis (there's a division by one).
For the random number generation, I think you'll have to go through C++ random generators documentation.
@RomainBerthomieu
I thin I found the solution: you have to create, in the omnetpp.ini file, an app for each node to communicate with the BS. What I wrote is the following:
I haven't written the model with UDP in mind as my work involves the network layer. In its current state this model simply sends CPackets to the destination at any specific time.
The code you've mentioned in https://github.com/Agr-IoT/LEACH/issues/5#issuecomment-1304779117 does not work & is actually wrong because it specifies a static destination address as baseStation
. This won't work for our use case as the destination addresses dynamically change for each node during runtime.
As for packet loss, I'm currently tracking the final packet loss count using the backoffLimitReached scalar value.
I think the code in generateThresholdValue is incorrect, and that the first line lacks of parenthesis (there's a division by one).
I will double-check this and update the code. If you believe there are other places where code amendments are needed, I welcome pull requests.
@RomainBerthomieu, I double-checked the code in generateThresholdValue
with the formula provided in the original LEACH paper and could not find a discrepancy. Appreciate if you could take another look and verify.
For the random number generation, I think you'll have to go through C++ random generators documentation.
This was rectified in commit: https://github.com/Agr-IoT/LEACH/commit/f1a8777d3d4787c813f15e79ed09c1e244f44806 by using the built-in OMNETPP RNG.
@laikinlong, https://github.com/Agr-IoT/LEACH/issues/5#issue-1437334225 should be resolved with the latest commit: https://github.com/Agr-IoT/LEACH/commit/2eecf8ae1e5163cfe6f4f691c7822b6df5cb0e6a
I am trying to simulate the code. However, the node is keeping self-message events. How can the node send a message to another node? Thanks for your help!
Log: ** Event 1 t=0.38344152132 SimpleNet.host[0].LEACHnode (Leach, id=54) on selfmsg event (omnetpp::cMessage, id=27)
** Event 2 t=0.477665111655 SimpleNet.host[1].LEACHnode (Leach, id=96) on selfmsg event (omnetpp::cMessage, id=54)
** Event 3 t=0.528894921532 SimpleNet.host[4].LEACHnode (Leach, id=222) on selfmsg event (omnetpp::cMessage, id=135)
** Event 4 t=0.791725033429 SimpleNet.host[2].LEACHnode (Leach, id=138) on selfmsg event (omnetpp::cMessage, id=81)
** Event 5 t=0.812168726465 SimpleNet.host[3].LEACHnode (Leach, id=180) on selfmsg event (omnetpp::cMessage, id=108)
** Event 6 t=5 SimpleNet.host[0].energyStorage (SimpleEpEnergyStorage, id=41) on selfmsg timer (omnetpp::cMessage, id=1)
INFO: Residual capacity = 0.49 (49%) ** Event 7 t=5 SimpleNet.host[1].energyStorage (SimpleEpEnergyStorage, id=83) on selfmsg timer (omnetpp::cMessage, id=28)
INFO: Residual capacity = 0.49 (49%) ** Event 8 t=5 SimpleNet.host[2].energyStorage (SimpleEpEnergyStorage, id=125) on selfmsg timer (omnetpp::cMessage, id=55)
INFO: Residual capacity = 0.49 (49%) ** Event 9 t=5 SimpleNet.host[3].energyStorage (SimpleEpEnergyStorage, id=167) on selfmsg timer (omnetpp::cMessage, id=82)
INFO: Residual capacity = 0.49 (49%) ** Event 10 t=5 SimpleNet.host[4].energyStorage (SimpleEpEnergyStorage, id=209) on selfmsg timer (omnetpp::cMessage, id=109)
INFO: Residual capacity = 0.49 (49%) ** Event 11 t=10 SimpleNet.host[0].energyStorage (SimpleEpEnergyStorage, id=41) on selfmsg timer (omnetpp::cMessage, id=1)
INFO: Residual capacity = 0.48 (48%) ** Event 12 t=10 SimpleNet.host[1].energyStorage (SimpleEpEnergyStorage, id=83) on selfmsg timer (omnetpp::cMessage, id=28)
INFO: Residual capacity = 0.48 (48%) ** Event 13 t=10 SimpleNet.host[2].energyStorage (SimpleEpEnergyStorage, id=125) on selfmsg timer (omnetpp::cMessage, id=55)
INFO: Residual capacity = 0.48 (48%) ** Event 14 t=10 SimpleNet.host[3].energyStorage (SimpleEpEnergyStorage, id=167) on selfmsg timer (omnetpp::cMessage, id=82)
INFO: Residual capacity = 0.48 (48%) ** Event 15 t=10 SimpleNet.host[4].energyStorage (SimpleEpEnergyStorage, id=209) on selfmsg timer (omnetpp::cMessage, id=109)
INFO: Residual capacity = 0.48 (48%) ...