From 2e82c888a02041fbe8fd0a541260407cca0e5e5f Mon Sep 17 00:00:00 2001 From: n-jay Date: Wed, 6 Dec 2023 12:25:44 +0530 Subject: [PATCH 01/43] Routing: Add LEACH routing protocol Adds the LEACH routing protocol functionality --- src/inet/node/leach/LeachBS.ned | 30 ++ src/inet/node/leach/LeachNode.ned | 30 ++ src/inet/routing/leach/Leach.cc | 480 +++++++++++++++++++++++++++ src/inet/routing/leach/Leach.h | 140 ++++++++ src/inet/routing/leach/Leach.ned | 31 ++ src/inet/routing/leach/LeachBS.cc | 126 +++++++ src/inet/routing/leach/LeachBS.h | 70 ++++ src/inet/routing/leach/LeachBS.ned | 29 ++ src/inet/routing/leach/LeackPkts.msg | 73 ++++ 9 files changed, 1009 insertions(+) create mode 100644 src/inet/node/leach/LeachBS.ned create mode 100644 src/inet/node/leach/LeachNode.ned create mode 100644 src/inet/routing/leach/Leach.cc create mode 100644 src/inet/routing/leach/Leach.h create mode 100644 src/inet/routing/leach/Leach.ned create mode 100644 src/inet/routing/leach/LeachBS.cc create mode 100644 src/inet/routing/leach/LeachBS.h create mode 100644 src/inet/routing/leach/LeachBS.ned create mode 100644 src/inet/routing/leach/LeackPkts.msg diff --git a/src/inet/node/leach/LeachBS.ned b/src/inet/node/leach/LeachBS.ned new file mode 100644 index 00000000000..8f45fc83e45 --- /dev/null +++ b/src/inet/node/leach/LeachBS.ned @@ -0,0 +1,30 @@ +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see http://www.gnu.org/licenses/. +// + +package inet.node.leach; + +import inet.node.inet.AdhocHost; +import inet.routing.leach.LeachBS; + +module LeachBS extends AdhocHost { + submodules: + LeachBS: LeachBS { + @display("p=825,226"); + } + connections: + LeachBS.ipOut --> tn.in++; + LeachBS.ipIn <-- tn.out++; + +} diff --git a/src/inet/node/leach/LeachNode.ned b/src/inet/node/leach/LeachNode.ned new file mode 100644 index 00000000000..824c31cec42 --- /dev/null +++ b/src/inet/node/leach/LeachNode.ned @@ -0,0 +1,30 @@ +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see http://www.gnu.org/licenses/. +// + +package inet.node.leach; + +import inet.node.inet.AdhocHost; +import inet.routing.leach.Leach; + +module LeachNode extends AdhocHost { + submodules: + LeachNode: Leach { + @display("p=825,226"); + } + connections: + LeachNode.ipOut --> tn.in++; + LeachNode.ipIn <-- tn.out++; + +} \ No newline at end of file diff --git a/src/inet/routing/leach/Leach.cc b/src/inet/routing/leach/Leach.cc new file mode 100644 index 00000000000..27a005b31eb --- /dev/null +++ b/src/inet/routing/leach/Leach.cc @@ -0,0 +1,480 @@ +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see http://www.gnu.org/licenses/. +// + +#include "Leach.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "inet/common/IProtocolRegistrationListener.h" +#include "inet/common/ModuleAccess.h" +#include "inet/common/ProtocolTag_m.h" +#include "inet/linklayer/common/InterfaceTag_m.h" +#include "inet/networklayer/common/L3AddressTag_m.h" +#include "inet/physicallayer/wireless/common/contract/packetlevel/SignalTag_m.h" +#include "inet/networklayer/common/L3AddressResolver.h" +#include "inet/common/lifecycle/LifecycleOperation.h" +#include "inet/common/lifecycle/ModuleOperations.h" +#include "inet/common/lifecycle/NodeStatus.h" +#include "inet/common/lifecycle/LifecycleController.h" + +namespace inet { + +Register_Enum(inet::Leach, (Leach::ch, Leach::nch)); +Define_Module(Leach); + +Leach::Leach() { + +} + +Leach::~Leach() { + stop(); + delete event; +} + +void Leach::initialize(int stage) { + RoutingProtocolBase::initialize(stage); + + //reads from omnetpp.ini + if (stage == INITSTAGE_LOCAL) { + sequencenumber = 0; + host = getContainingNode(this); + ift = getModuleFromPar(par("interfaceTableModule"), + this); + + clusterHeadPercentage = par("clusterHeadPercentage"); + numNodes = par("numNodes"); + + roundDuration = dblrand(0) * 10; + TDMADelayCounter = 1; + event = new cMessage("event"); + roundDuration = dblrand(0) * 10; + wasCH = false; + + vector nodeMemory(numNodes); // Localized NCH node memory with CH data + vector nodeCHMemory(numNodes); // Localized CH memory + vector extractedTDMASchedule(numNodes); // Localized NCH node memory with extracted TDMA data + + } else if (stage == INITSTAGE_ROUTING_PROTOCOLS) { + registerService(Protocol::manet, nullptr, gate("ipIn")); + registerProtocol(Protocol::manet, gate("ipOut"), nullptr); + } +} + +void Leach::start() { + // Search the 802154 interface + int num_802154 = 0; + NetworkInterface *ie; + NetworkInterface *i_face; + const char *name; + + for (int i = 0; i < ift->getNumInterfaces(); i++) { + ie = ift->getInterface(i); + name = ie->getInterfaceName(); + if (strstr(name, "wlan") != nullptr) { + i_face = ie; + num_802154++; + interfaceId = i; + } + } + + // One enabled network interface (in total) + if (num_802154 == 1) + interface80211ptr = i_face; + else + throw cRuntimeError("DSDV has found %i 80211 interfaces", num_802154); + CHK(interface80211ptr->getProtocolDataForUpdate())->joinMulticastGroup( + Ipv4Address::LL_MANET_ROUTERS); + + // schedules a random periodic event + event->setKind(SELF); + scheduleAt(simTime() + uniform(0.0, par("maxVariance").doubleValue()), + event); +} + +void Leach::stop() { + cancelEvent(event); + nodeMemory.clear(); + nodeCHMemory.clear(); + extractedTDMASchedule.clear(); + TDMADelayCounter = 1; +} + +void Leach::handleMessageWhenUp(cMessage *msg) { + // if node is sending message + if (msg->isSelfMessage()) { + double randNo = dblrand(1); + double threshold = generateThresholdValue(round); + + if (randNo < threshold && wasCH == false) { + setLeachState(ch); // Set state for GUI visualization + wasCH = true; + handleSelfMessage(msg); + } + + round += 1; + int intervalLength = 1.0 / clusterHeadPercentage; + if (fmod(round, intervalLength) == 0) { // reset values at end of number of subintervals + wasCH = false; + nodeMemory.clear(); + nodeCHMemory.clear(); + extractedTDMASchedule.clear(); + TDMADelayCounter = 1; + } + + // schedule another self message every time new one is received by node + event->setKind(SELF); + scheduleAt(simTime() + roundDuration, event); + // if node is receiving message + } else if (check_and_cast(msg)->getTag()->getProtocol() + == &Protocol::manet) { + processMessage(msg); + } else { + throw cRuntimeError("Message not supported %s", msg->getName()); + } +} + +void Leach::handleMessageWhenDown(cMessage *msg) { + delete msg; + OperationalBase::handleMessageWhenDown(msg); +} + +void Leach::handleSelfMessage(cMessage *msg) { + if (msg == event) { + if (event->getKind() == SELF) { + auto ctrlPkt = makeShared(); + + // Filling the LeachControlPkt fields + ctrlPkt->setPacketType(CH); + Ipv4Address source = (interface80211ptr->getProtocolData< + Ipv4InterfaceData>()->getIPAddress()); + ctrlPkt->setChunkLength(b(128)); ///size of Hello message in bits + ctrlPkt->setSrcAddress(source); + + //new control info for LeachControlPkt + auto packet = new Packet("LEACHControlPkt", ctrlPkt); + auto addressReq = packet->addTag(); + addressReq->setDestAddress(Ipv4Address(255, 255, 255, 255)); + addressReq->setSrcAddress(source); //let's try the limited broadcast + packet->addTag()->setInterfaceId( + interface80211ptr->getInterfaceId()); + packet->addTag()->setProtocol(&Protocol::manet); + packet->addTag()->setProtocol(&Protocol::ipv4); + + //broadcast to other nodes the hello message + send(packet, "ipOut"); + packet = nullptr; + ctrlPkt = nullptr; + } + } else { + delete msg; + } +} + +void Leach::processMessage(cMessage *msg) { + Ipv4Address selfAddr = + (interface80211ptr->getProtocolData()->getIPAddress()); + auto receivedCtrlPkt = + staticPtrCast( + check_and_cast(msg)->peekData()->dupShared()); + Packet *receivedPkt = check_and_cast(msg); + auto &leachControlPkt = receivedPkt->popAtFront(); + auto packetType = leachControlPkt->getPacketType(); + + // filter packet based on type and run specific functions + if (msg->arrivedOn("ipIn")) { + // first broadcast from CH to NCH nodes + if (packetType == 1) { + Ipv4Address CHAddr = receivedCtrlPkt->getSrcAddress(); + + auto signalPowerInd = receivedPkt->getTag(); + double rxPower = signalPowerInd->getPower().get(); + + addToNodeMemory(selfAddr, CHAddr, rxPower); + sendAckToCH(selfAddr, CHAddr); + + // ACK packet from NCH node to CH + } else if (packetType == 2 && leachState == ch) { + Ipv4Address nodeAddr = receivedCtrlPkt->getSrcAddress(); + + addToNodeCHMemory(nodeAddr); + if (nodeCHMemory.size() > 2) { + sendSchToNCH(selfAddr); + } + + // TDMA schedule from CH to NCH + } else if (packetType == 3) { + Ipv4Address CHAddr = receivedCtrlPkt->getSrcAddress(); + + int scheduleArraySize = receivedCtrlPkt->getScheduleArraySize(); + // Traverses through schedule array in packets and sets values into a vector in local node memory + for (int counter = 0; counter < scheduleArraySize; counter++) { + ScheduleEntry tempScheduleEntry = receivedCtrlPkt->getSchedule( + counter); + TDMAScheduleEntry extractedTDMAScheduleEntry; + extractedTDMAScheduleEntry.nodeAddress = + tempScheduleEntry.getNodeAddress(); + extractedTDMAScheduleEntry.TDMAdelay = + tempScheduleEntry.getTDMAdelay(); + extractedTDMASchedule.push_back(extractedTDMAScheduleEntry); + } + + // Finds TDMA slot for self by traversing through earlier generated vector + double receivedTDMADelay = -1; + for (auto &it : extractedTDMASchedule) { + if (it.nodeAddress == selfAddr) { + receivedTDMADelay = it.TDMAdelay; + break; + } + } + + if (receivedTDMADelay > -1) { // Only sends data to CH if self address is included in schedule + sendDataToCH(selfAddr, CHAddr, receivedTDMADelay); + } + // Data packet from NCH to CH + } else if (packetType == 4) { + Ipv4Address NCHAddr = receivedCtrlPkt->getSrcAddress(); + + sendDataToBS(selfAddr); + + // BS packet from CH to BS - deleted in the case of standard nodes + } else if (packetType == 5) { + delete msg; + } + } else { + throw cRuntimeError("Message arrived on unknown gate %s", + msg->getArrivalGate()->getName()); + } +} + +// Runs during node shutdown events +void Leach::handleStopOperation(LifecycleOperation *operation) { + cancelAndDelete(event); + +} + +// Runs during node crash events +void Leach::handleCrashOperation(LifecycleOperation *operation) { + cancelAndDelete(event); +} + +// Threshold value for CH selection +double Leach::Leach::generateThresholdValue(int round) { + int intervalLength = 1.0 / clusterHeadPercentage; + double threshold = (clusterHeadPercentage + / (1 - clusterHeadPercentage * (fmod(round, intervalLength)))); + + return threshold; +} + +// Add CH to non CH node memory +void Leach::addToNodeMemory(Ipv4Address nodeAddr, Ipv4Address CHAddr, + double energy) { + if (!isCHAddedInMemory(CHAddr)) { + nodeMemoryObject node; + node.nodeAddr = nodeAddr; + node.CHAddr = CHAddr; + node.energy = energy; + nodeMemory.push_back(node); + } +} + +// Add non CH to CH node memory for TDMA schedule generation +void Leach::addToNodeCHMemory(Ipv4Address NCHAddr) { + if (!isNCHAddedInCHMemory(NCHAddr)) { + TDMAScheduleEntry scheduleEntry; + scheduleEntry.nodeAddress = NCHAddr; + scheduleEntry.TDMAdelay = TDMADelayCounter; + nodeCHMemory.push_back(scheduleEntry); + TDMADelayCounter++; // Counter increases and sets slots for NCH transmission time + } +} + +// Checks non CH nodes memory for CH records +bool Leach::isCHAddedInMemory(Ipv4Address CHAddr) { + for (auto &it : nodeMemory) { + if (it.CHAddr == CHAddr) { + return true; + } + } + return false; +} + +// Checks CH nodes memory to generate TDMA schedule +bool Leach::isNCHAddedInCHMemory(Ipv4Address NCHAddr) { + for (auto &it : nodeCHMemory) { + if (it.nodeAddress == NCHAddr) { + return true; + } + } + return false; +} + +void Leach::generateTDMASchedule() { + for (auto &it : nodeCHMemory) { + ScheduleEntry scheduleEntry; + scheduleEntry.setNodeAddress(it.nodeAddress); + scheduleEntry.setTDMAdelay(it.TDMAdelay); + } +} + +// Set CH/non CH states for GUI visualization - optional +void Leach::setLeachState(LeachState ls) { + leachState = ls; +} + +// Send broadcast acknowledgement to CH from non CH nodes +void Leach::sendAckToCH(Ipv4Address nodeAddr, Ipv4Address CHAddr) { + auto ackPkt = makeShared(); + ackPkt->setPacketType(ACK); + ackPkt->setChunkLength(b(128)); ///size of Hello message in bits + ackPkt->setSrcAddress(nodeAddr); + + auto ackPacket = new Packet("LeachAckPkt", ackPkt); + auto addressReq = ackPacket->addTag(); + + addressReq->setDestAddress(getIdealCH(nodeAddr, CHAddr)); + addressReq->setSrcAddress(nodeAddr); + ackPacket->addTag()->setInterfaceId( + interface80211ptr->getInterfaceId()); + ackPacket->addTag()->setProtocol(&Protocol::manet); + ackPacket->addTag()->setProtocol(&Protocol::ipv4); + + send(ackPacket, "ipOut"); +} + +// Sends TDMA schedule to non CH nodes +void Leach::sendSchToNCH(Ipv4Address selfAddr) { + auto schedulePkt = makeShared(); + schedulePkt->setPacketType(SCH); + schedulePkt->setChunkLength(b(128)); ///size of Hello message in bits + schedulePkt->setSrcAddress(selfAddr); + + for (auto &it : nodeCHMemory) { + ScheduleEntry scheduleEntry; + scheduleEntry.setNodeAddress(it.nodeAddress); + scheduleEntry.setTDMAdelay(it.TDMAdelay); + schedulePkt->insertSchedule(scheduleEntry); + } + + auto schedulePacket = new Packet("LeachSchedulePkt", schedulePkt); + auto scheduleReq = schedulePacket->addTag(); + + scheduleReq->setDestAddress(Ipv4Address(255, 255, 255, 255)); + scheduleReq->setSrcAddress(selfAddr); + schedulePacket->addTag()->setInterfaceId( + interface80211ptr->getInterfaceId()); + schedulePacket->addTag()->setProtocol(&Protocol::manet); + schedulePacket->addTag()->setProtocol(&Protocol::ipv4); + + send(schedulePacket, "ipOut"); +} + +// Sends data to CH node +void Leach::sendDataToCH(Ipv4Address nodeAddr, Ipv4Address CHAddr, + double TDMAslot) { + auto dataPkt = makeShared(); + dataPkt->setPacketType(DATA); + double temperature = (double) rand() / RAND_MAX; + double humidity = (double) rand() / RAND_MAX; + + dataPkt->setChunkLength(b(128)); + dataPkt->setTemperature(temperature); + dataPkt->setHumidity(humidity); + dataPkt->setSrcAddress(nodeAddr); + + auto dataPacket = new Packet("LEACHDataPkt", dataPkt); + auto addressReq = dataPacket->addTag(); + + addressReq->setDestAddress(getIdealCH(nodeAddr, CHAddr)); + addressReq->setSrcAddress(nodeAddr); + dataPacket->addTag()->setInterfaceId( + interface80211ptr->getInterfaceId()); + dataPacket->addTag()->setProtocol(&Protocol::manet); + dataPacket->addTag()->setProtocol(&Protocol::ipv4); + + sendDelayed(dataPacket, TDMAslot, "ipOut"); +} + +// CH sends data to BS +void Leach::sendDataToBS(Ipv4Address CHAddr) { + auto bsPkt = makeShared(); + bsPkt->setPacketType(BS); + + bsPkt->setChunkLength(b(128)); + bsPkt->setCHAddr(CHAddr); + + auto bsPacket = new Packet("LEACHBsPkt", bsPkt); + auto addressReq = bsPacket->addTag(); + + addressReq->setDestAddress(Ipv4Address(10, 0, 0, 1)); + addressReq->setSrcAddress(CHAddr); + bsPacket->addTag()->setInterfaceId( + interface80211ptr->getInterfaceId()); + bsPacket->addTag()->setProtocol(&Protocol::manet); + bsPacket->addTag()->setProtocol(&Protocol::ipv4); + + sendDelayed(bsPacket, TDMADelayCounter, "ipOut"); + setLeachState(nch); // Set state for GUI visualization +} + +// Selects the ideal CH based on RSSI signal +Ipv4Address Leach::getIdealCH(Ipv4Address nodeAddr, Ipv4Address CHAddr) { + Ipv4Address tempIdealCHAddr = CHAddr; + double tempRxPower = 0.0; + if (nodeMemory.size() > 0) { + for (auto &it : nodeMemory) { + if (it.nodeAddr == nodeAddr) { + if (it.energy > tempRxPower) { + tempRxPower = it.energy; + tempIdealCHAddr = it.CHAddr; + continue; + } + } else { + continue; + } + } + } + return tempIdealCHAddr; +} + +void Leach::refreshDisplay() const { + const char *icon; + switch (leachState) { + case nch: + icon = ""; + break; + case ch: + icon = "status/green"; + break; + default: + throw cRuntimeError("Unknown LEACH status"); + } + auto &displayString = getDisplayString(); + if (*icon) { + displayString.setTagArg("i2", 0, icon); + host->getDisplayString().setTagArg("i2", 0, icon); + } else { + displayString.removeTag("i2"); + host->getDisplayString().removeTag("i2"); + } +} +} /* namespace inet */ diff --git a/src/inet/routing/leach/Leach.h b/src/inet/routing/leach/Leach.h new file mode 100644 index 00000000000..92157fd754a --- /dev/null +++ b/src/inet/routing/leach/Leach.h @@ -0,0 +1,140 @@ +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see http://www.gnu.org/licenses/. +// + +#ifndef INET_ROUTING_LEACH_LEACH_H_ +#define INET_ROUTING_LEACH_LEACH_H_ + +#include +#include +#include +#include +#include +#include +#include + +#include "inet/common/INETDefs.h" +#include "inet/common/packet/Packet.h" +#include "inet/networklayer/contract/IInterfaceTable.h" +#include "inet/networklayer/contract/ipv4/Ipv4Address.h" +#include "inet/networklayer/ipv4/IIpv4RoutingTable.h" +#include "inet/networklayer/ipv4/Ipv4Header_m.h" +#include "inet/networklayer/ipv4/Ipv4InterfaceData.h" +#include "inet/networklayer/ipv4/Ipv4RoutingTable.h" +#include "inet/routing/base/RoutingProtocolBase.h" +#include "LeackPkts_m.h" +#include "inet/mobility/contract/IMobility.h" +#include "inet/common/geometry/common/Coord.h" +#include "inet/mobility/base/StationaryMobilityBase.h" +#include "inet/power/contract/ICcEnergyStorage.h" +#include "inet/common/lifecycle/LifecycleController.h" + +using namespace std; + +namespace inet { + +class INET_API Leach: public RoutingProtocolBase { + +private: + + NetworkInterface *interface80211ptr = nullptr; + int interfaceId = -1; + unsigned int sequencenumber = 0; + cModule *host = nullptr; + Ipv4Address idealCH; + cMessage *event = nullptr; + int round; + +protected: + IInterfaceTable *ift = nullptr; + simtime_t dataPktSendDelay; + simtime_t CHPktSendDelay; + simtime_t roundDuration; + + int numNodes = 0; + double clusterHeadPercentage = 0.0; + + // object for storing CH data per node in vector array + struct nodeMemoryObject { + Ipv4Address nodeAddr; + Ipv4Address CHAddr; + double energy; + }; + + struct TDMAScheduleEntry { + Ipv4Address nodeAddress; + double TDMAdelay; + }; + + vector nodeMemory; // NCH nodes store data about CH broadcasts + vector nodeCHMemory; // CH store data about CH acknowledgements + vector extractedTDMASchedule; + bool wasCH; + +public: + Leach(); + virtual ~Leach(); + + enum LeachState { + nch, ch + }; // written in lower caps as it conflicts with enum in LeachPkts.msg file + + LeachState leachState; + double TDMADelayCounter; + + virtual int numInitStages() const override { + return NUM_INIT_STAGES; + } + virtual void initialize(int stage) override; + virtual void handleMessageWhenUp(cMessage *msg) override; + virtual void handleMessageWhenDown(cMessage *msg) override; + + void handleSelfMessage(cMessage *msg); + void processMessage(cMessage *msg); + + // lifecycle + virtual void handleStartOperation(LifecycleOperation *operation) override { + start(); + } + virtual void handleStopOperation(LifecycleOperation *operation) override; + virtual void handleCrashOperation(LifecycleOperation *operation) override; + void start(); + void stop(); + virtual void refreshDisplay() const override; + enum SelfMsgKinds { + SELF = 1, DATA2CH, DATA2BS + }; + + double generateThresholdValue(int subInterval); + + void sendDataToCH(Ipv4Address nodeAddr, Ipv4Address CHAddr, + double TDMAslot); + void sendDataToBS(Ipv4Address CHAddr); + void sendAckToCH(Ipv4Address nodeAddr, Ipv4Address CHAddr); + void sendSchToNCH(Ipv4Address selfAddr); + + void addToNodeMemory(Ipv4Address nodeAddr, Ipv4Address CHAddr, + double energy); + void addToNodeCHMemory(Ipv4Address NCHAddr); + bool isCHAddedInMemory(Ipv4Address CHAddr); + bool isNCHAddedInCHMemory(Ipv4Address NCHAddr); + void generateTDMASchedule(); + + virtual void setLeachState(LeachState ls); + Ipv4Address getIdealCH(Ipv4Address nodeAddr, Ipv4Address CHAddr); +}; + +} /* namespace inet */ + +#endif /* INET_ROUTING_LEACH_LEACH_H_ */ diff --git a/src/inet/routing/leach/Leach.ned b/src/inet/routing/leach/Leach.ned new file mode 100644 index 00000000000..0074d52b0ba --- /dev/null +++ b/src/inet/routing/leach/Leach.ned @@ -0,0 +1,31 @@ +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see http://www.gnu.org/licenses/. +// + +package inet.routing.leach; + +import inet.routing.contract.IManetRouting; + +simple Leach like IManetRouting +{ + parameters: + @display("i=block/routing"); + string interfaceTableModule; // The path to the InterfaceTable module + double maxVariance = default(1); + int numNodes = default(10); + double clusterHeadPercentage = default(0.5); + gates: + input ipIn; + output ipOut; +} diff --git a/src/inet/routing/leach/LeachBS.cc b/src/inet/routing/leach/LeachBS.cc new file mode 100644 index 00000000000..a87378edc62 --- /dev/null +++ b/src/inet/routing/leach/LeachBS.cc @@ -0,0 +1,126 @@ +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see http://www.gnu.org/licenses/. +// + +#include +#include +#include + +#include "inet/common/IProtocolRegistrationListener.h" +#include "inet/common/ModuleAccess.h" +#include "inet/common/ProtocolTag_m.h" +#include "inet/linklayer/common/InterfaceTag_m.h" +#include "inet/networklayer/common/L3AddressTag_m.h" +#include "inet/routing/leach/Leach.h" +#include "inet/physicallayer/wireless/common/contract/packetlevel/SignalTag_m.h" +#include "LeachBS.h" + +using namespace std; + +namespace inet { + +Define_Module(LeachBS); + +LeachBS::LeachBS() { + +} + +LeachBS::~LeachBS() { + // TODO Auto-generated destructor stub +} + +void LeachBS::initialize(int stage) { + RoutingProtocolBase::initialize(stage); + + //reads from omnetpp.ini + if (stage == INITSTAGE_LOCAL) { + sequencenumber = 0; + host = getContainingNode(this); + ift = getModuleFromPar(par("interfaceTableModule"), + this); + + bsPktReceived = 0; + + } else if (stage == INITSTAGE_ROUTING_PROTOCOLS) { + registerService(Protocol::manet, nullptr, gate("ipIn")); + registerProtocol(Protocol::manet, gate("ipOut"), nullptr); + } +} + +void LeachBS::start() { + /* Search the 80211 interface */ + int num_80211 = 0; + NetworkInterface *ie; + NetworkInterface *i_face; + const char *name; + + for (int i = 0; i < ift->getNumInterfaces(); i++) { + ie = ift->getInterface(i); + name = ie->getInterfaceName(); + if (strstr(name, "wlan") != nullptr) { + i_face = ie; + num_80211++; + interfaceId = i; + } + } + + // One enabled network interface (in total) + if (num_80211 == 1) + interface80211ptr = i_face; + else + throw cRuntimeError("DSDV has found %i 80211 interfaces", num_80211); + + CHK(interface80211ptr->getProtocolDataForUpdate())->joinMulticastGroup( + Ipv4Address::LL_MANET_ROUTERS); +} + +void LeachBS::stop() { + +} + +void LeachBS::handleMessageWhenUp(cMessage *msg) { + Ipv4Address nodeAddr = + (interface80211ptr->getProtocolData()->getIPAddress()); + // if node is sending message + if (msg->isSelfMessage()) { + delete msg; + } + // if node is receiving message + else if (check_and_cast(msg)->getTag()->getProtocol() + == &Protocol::manet) { + auto receivedCtrlPkt = + staticPtrCast( + check_and_cast(msg)->peekData()->dupShared()); + Packet *receivedPkt = check_and_cast(msg); + auto &leachControlPkt = receivedPkt->popAtFront(); + + auto packetType = leachControlPkt->getPacketType(); + + // filter packet based on type and run specific functions + if (msg->arrivedOn("ipIn")) { + if (packetType == 5) { + bsPktReceived += 1; + } else { + delete msg; + } + } else { + throw cRuntimeError("Message arrived on unknown gate %s", + msg->getArrivalGate()->getName()); + } + } else { + throw cRuntimeError("Message not supported %s", msg->getName()); + } +} + +} /* namespace inet */ diff --git a/src/inet/routing/leach/LeachBS.h b/src/inet/routing/leach/LeachBS.h new file mode 100644 index 00000000000..767fd3b340c --- /dev/null +++ b/src/inet/routing/leach/LeachBS.h @@ -0,0 +1,70 @@ +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see http://www.gnu.org/licenses/. +// + +#ifndef INET_ROUTING_LEACH_LEACHBS_H_ +#define INET_ROUTING_LEACH_LEACHBS_H_ + +#include "inet/common/INETDefs.h" +#include "inet/common/packet/Packet.h" +#include "inet/networklayer/contract/IInterfaceTable.h" +#include "inet/networklayer/contract/ipv4/Ipv4Address.h" +#include "inet/networklayer/ipv4/IIpv4RoutingTable.h" +#include "inet/networklayer/ipv4/Ipv4Header_m.h" +#include "inet/networklayer/ipv4/Ipv4InterfaceData.h" +#include "inet/networklayer/ipv4/Ipv4RoutingTable.h" +#include "inet/routing/base/RoutingProtocolBase.h" +#include "LeackPkts_m.h" +#include "Leach.h" + +namespace inet { + +// Base Station of network which acts as data sink +class INET_API LeachBS: public RoutingProtocolBase { +private: + int bsPktReceived; // number of packets received at BS + +public: + LeachBS(); + virtual ~LeachBS(); + + int interfaceId = -1; + NetworkInterface *interface80211ptr = nullptr; + IInterfaceTable *ift = nullptr; + unsigned int sequencenumber = 0; + cModule *host = nullptr; + +protected: + virtual int numInitStages() const override { + return NUM_INIT_STAGES; + } + virtual void initialize(int stage) override; + virtual void handleMessageWhenUp(cMessage *msg) override; + + virtual void handleStartOperation(LifecycleOperation *operation) override { + start(); + } + virtual void handleStopOperation(LifecycleOperation *operation) override { + stop(); + } + virtual void handleCrashOperation(LifecycleOperation *operation) override { + stop(); + } + void start(); + void stop(); +}; + +} /* namespace inet */ + +#endif /* INET_ROUTING_LEACH_LEACHBS_H_ */ diff --git a/src/inet/routing/leach/LeachBS.ned b/src/inet/routing/leach/LeachBS.ned new file mode 100644 index 00000000000..aaccbe08e71 --- /dev/null +++ b/src/inet/routing/leach/LeachBS.ned @@ -0,0 +1,29 @@ +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see http://www.gnu.org/licenses/. +// + +package inet.routing.leach; + +import inet.routing.contract.IManetRouting; + +simple LeachBS like IManetRouting +{ + parameters: + @display("i=block/routing"); + string interfaceTableModule; // The path to the InterfaceTable module + string routingTableModule; + gates: + input ipIn; + output ipOut; +} diff --git a/src/inet/routing/leach/LeackPkts.msg b/src/inet/routing/leach/LeackPkts.msg new file mode 100644 index 00000000000..79fd0dc9e8c --- /dev/null +++ b/src/inet/routing/leach/LeackPkts.msg @@ -0,0 +1,73 @@ +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see http://www.gnu.org/licenses/. +// + +import inet.common.INETDefs; +import inet.common.packet.chunk.Chunk; +import inet.networklayer.contract.ipv4.Ipv4Address; + +cplusplus {{ + #include + #include "inet/common/INETDefs.h" + #include "Leach.h" + #include "inet/networklayer/contract/ipv4/Ipv4Address.h" + using namespace std; + using namespace inet; + +}} + +namespace inet; + +enum LeachPktType { + CH = 1; + ACK = 2; + SCH = 3; + DATA = 4; + BS = 5; +} + +class ScheduleEntry extends cObject { + Ipv4Address nodeAddress; + double TDMAdelay; +} + +// Base packet including all fields used across other packet variants +class LeachControlPkt extends FieldsChunk { + LeachPktType packetType = static_cast(-1); + Ipv4Address srcAddress; + string fingerprint; + + ScheduleEntry schedule[]; +} + +// Data packet including fields for mock data +class LeachDataPkt extends LeachControlPkt { + double temperature; + double humidity; +} + +// Packet sent to BS from CH +class LeachBSPkt extends LeachControlPkt { + Ipv4Address CHAddr; +} + +// CH broadcast reception acknowledgement from NCH nodes +class LeachAckPkt extends LeachControlPkt { + +} + +// Packet with TDMA schedule from CH +class LeachSchedulePkt extends LeachControlPkt { + +} From 67c97be16b8eaf83466d63ab1ff8e4fb54cb9cfa Mon Sep 17 00:00:00 2001 From: n-jay Date: Wed, 6 Dec 2023 12:26:59 +0530 Subject: [PATCH 02/43] Examples: Add LEACH example simulation To showcase how protocol can be implemented in simulation setup --- examples/manetrouting/leach/Leach.ned | 48 ++++++++++++++ examples/manetrouting/leach/address.xml | 4 ++ examples/manetrouting/leach/omnetpp.ini | 86 +++++++++++++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 examples/manetrouting/leach/Leach.ned create mode 100644 examples/manetrouting/leach/address.xml create mode 100644 examples/manetrouting/leach/omnetpp.ini diff --git a/examples/manetrouting/leach/Leach.ned b/examples/manetrouting/leach/Leach.ned new file mode 100644 index 00000000000..749b55956b6 --- /dev/null +++ b/examples/manetrouting/leach/Leach.ned @@ -0,0 +1,48 @@ +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see http://www.gnu.org/licenses/. +// + +package inet.examples.manetrouting.leach; + +import inet.networklayer.configurator.ipv4.Ipv4NetworkConfigurator; +import inet.node.contract.INetworkNode; +import inet.node.inet.SensorNode; +import inet.physicallayer.wireless.common.contract.packetlevel.IRadioMedium; +import inet.visualizer.contract.IIntegratedVisualizer; +import inet.environment.common.PhysicalEnvironment; + +network Leach +{ + parameters: + int numNodes; + @display("bgb=200.8119,200.0099;bgg=100,1,grey95"); + @figure[title](type=label; pos=0,-1; anchor=sw; color=darkblue); + + submodules: + configurator: Ipv4NetworkConfigurator { + @display("p=512.39996,181.17"); + } + radioMedium: like IRadioMedium { + @display("p=512.39996,289.13998"); + } + physicalEnvironment: PhysicalEnvironment { + @display("p=512.39996,441.02997"); + } + host[numNodes]: like INetworkNode { + @display("i=misc/sensor2"); + } + baseStation: like INetworkNode { + @display("p=50,50;i=misc/sensorgateway"); + } +} diff --git a/examples/manetrouting/leach/address.xml b/examples/manetrouting/leach/address.xml new file mode 100644 index 00000000000..116b8d5051a --- /dev/null +++ b/examples/manetrouting/leach/address.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/examples/manetrouting/leach/omnetpp.ini b/examples/manetrouting/leach/omnetpp.ini new file mode 100644 index 00000000000..28c512dfc7d --- /dev/null +++ b/examples/manetrouting/leach/omnetpp.ini @@ -0,0 +1,86 @@ +[General] +network = Leach + +num-rngs = 2 +rng-class = omnetpp::cMersenneTwister +seed-0-mt= 4900 # used for node layout generation +seed-1-mt = 7 # used for threshold comparison + +**.arp.typename = "GlobalArp" + +*.radioMedium.typename = "Ieee802154NarrowbandScalarRadioMedium" +*.radioMedium.backgroundNoise.power = -100dBm +*.radioMedium.mediumLimitCache.centerFrequency = 2GHz + +*.host*.hasStatus = true +*.visualizer.energyStorageVisualizer.displayEnergyStorages = true + +*.configurator.config = xmldoc ("address.xml") + +*.baseStation.typename = "LeachBS" +*.host*.typename = "LeachNode" +*.host*.LEACHnode.clusterHeadPercentage = 0.05 +*.host*.LEACHnode.numNodes = 100 # set number of nodes to be injected into LEACH module + +*.numNodes = 100 #100 +*.host*.mobility.typename = "StationaryMobility" +*.host*.mobility.rng-0 = 0 # random number generator mapping + +*.host[*].mobility.initFromDisplayString = false + +**.constraintAreaMinX = 1m +**.constraintAreaMaxX = 100m +**.constraintAreaMinY = 1m +**.constraintAreaMaxY = 100m + +*.host*.wlan[0].typename = "Ieee802154NarrowbandInterface" +*.host*.wlan[0].radio.typename = "ApskScalarRadio" +*.host*.wlan[0].radio.centerFrequency = 2.5GHz # based on TI CC2520 +*.host*.wlan[0].radio.bandwidth = 2MHz +*.host*.wlan[0].radio.transmitter.power = 60.5mW # determines communication range - based on CC2520 +*.host*.wlan[0].radio.transmitter.preambleDuration = 192us # based on TI CC2520 +*.host*.wlan[0].radio.transmitter.headerLength = 6B # based on TI CC2520 +*.host*.wlan[0].radio.receiver.sensitivity = -98dBm # based on TI CC2520 +*.host*.wlan[0].radio.receiver.energyDetection = -85dBm +*.host*.wlan[0].radio.receiver.snirThreshold = 4dB +*.host*.wlan[0].radio.displayCommunicationRange = true + + +*.baseStation.wlan[0].typename = "Ieee802154NarrowbandInterface" +*.baseStation.wlan[0].radio.typename = "ApskScalarRadio" +*.baseStation.wlan[0].radio.centerFrequency = 2.5GHz +*.baseStation.wlan[0].radio.bandwidth = 2MHz +*.baseStation.wlan[0].radio.transmitter.power = 60.5mW +*.baseStation.wlan[0].radio.transmitter.preambleDuration = 192us +*.baseStation.wlan[0].radio.transmitter.headerLength = 6B +*.baseStation.wlan[0].radio.receiver.sensitivity = -98dBm +*.baseStation.wlan[0].radio.receiver.energyDetection = -85dBm +*.baseStation.wlan[0].radio.receiver.snirThreshold = 4dB +*.baseStation.wlan[0].radio.displayCommunicationRange = true + +*.host*.**.bitrate = 250kbps # based on TI CC2520 +*.baseStation.**.bitrate = 250kbps + +[Config LeachPower] +extends = General + +*.host*.energyStorage.typename = "SimpleCcBattery" +*.host*.energyStorage.nominalCapacity = 7200C # calculated for 2 x AA cells +*.host*.energyStorage.initialCapacity = 7100C +*.host*.energyStorage.nominalVoltage = 1.5V +*.host*.energyStorage.internalResistance = 0.1Ohm + +*.host*.wlan[0].radio.energyConsumer.typename = "StateBasedCcEnergyConsumer" +*.host*.wlan[0].radio.energyConsumer.offCurrentConsumption = 0A +*.host*.wlan[0].radio.energyConsumer.switchingCurrentConsumption = 1mA +*.host*.wlan[0].radio.energyConsumer.receiverIdleCurrentConsumption = 18.8mA # based on CC2520 +*.host*.wlan[0].radio.energyConsumer.receiverBusyCurrentConsumption = 24.8mA # based on CC2520 +*.host*.wlan[0].radio.energyConsumer.receiverReceivingCurrentConsumption = 26.3mA # based on CC2520 +*.host*.wlan[0].radio.energyConsumer.transmitterIdleCurrentConsumption = 25.8mA # based on CC2520 +*.host*.wlan[0].radio.energyConsumer.transmitterTransmittingCurrentConsumption = 33.6mA # based on CC2520 + +[Config LeachPathLoss] +extends = General + +*.host*.wlan[0].radio.displayInterferenceRange = true +*.radioMedium.pathLoss.typename = "LogNormalShadowing" From c1d93a64598c0be30a61aa7b093babd1ec933f0b Mon Sep 17 00:00:00 2001 From: n-jay Date: Wed, 6 Dec 2023 14:59:30 +0530 Subject: [PATCH 03/43] Add tests for LEACH protocol --- tests/fingerprint/examples.csv | 4 ++ tests/module/LeachSimpleTest.test | 107 ++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 tests/module/LeachSimpleTest.test diff --git a/tests/fingerprint/examples.csv b/tests/fingerprint/examples.csv index dc1642ea04c..9af9a3a4c5e 100644 --- a/tests/fingerprint/examples.csv +++ b/tests/fingerprint/examples.csv @@ -332,6 +332,10 @@ /examples/manetrouting/dsdv/, -f omnetpp.ini -c MultiIPv4 -r 0, 10s, 94c8-51dd/tplx;e9e8-7d0b/~tNl;e9f0-b256/~tND;e86f-d3fa/tyf, PASS, wireless adhoc Ipv4 /examples/manetrouting/dsdv/, -f omnetpp.ini -c DynamicIPv4 -r 0, 22s, 6699-04d7/tplx;3e2c-1eee/~tNl;eecc-7593/~tND;90d2-3ffa/tyf, PASS, wireless adhoc Ipv4 +/examples/manetrouting/leach/,-f omnetpp.ini -r 0, 100s, f58b-b959/tplx,PASS,wireless adhoc Ipv4 +/examples/manetrouting/leach/,-f omnetpp.ini -c LeachPower -r 0, 100s, 0db4-188a/tplx, PASS,wireless adhoc Ipv4 +/examples/manetrouting/leach/,-f omnetpp.ini -c LeachPathLoss -r 0, 100s, 1617-1827/tplx, PASS,wireless adhoc Ipv4 + # /examples/manetrouting/dymo/, -f omnetpp.ini -c _IPv4 -r 0 # abstract-config /examples/manetrouting/dymo/, -f omnetpp.ini -c IPv4 -r 0, 10s, 1a85-cb5d/tplx;dfe8-11b9/~tNl;483b-544e/tyf, PASS, wireless adhoc Ipv4 # /examples/manetrouting/dymo/, -f omnetpp.ini -c _IPv6 -r 0 # abstract-config diff --git a/tests/module/LeachSimpleTest.test b/tests/module/LeachSimpleTest.test new file mode 100644 index 00000000000..a70de7d0f00 --- /dev/null +++ b/tests/module/LeachSimpleTest.test @@ -0,0 +1,107 @@ +%description: +This example tests a simple run of the LEACH routing protocol +on IEEE 802.15.4 standard with 100 nodes +%#-------------------------------------------------------------------------------------------------------------- +%file: test.ned + +import inet.networklayer.configurator.ipv4.Ipv4NetworkConfigurator; +import inet.node.contract.INetworkNode; +import inet.node.inet.SensorNode; +import inet.physicallayer.wireless.common.contract.packetlevel.IRadioMedium; +import inet.visualizer.contract.IIntegratedVisualizer; +import inet.environment.common.PhysicalEnvironment; + +network SimpleNet +{ + parameters: + int numNodes; + @display("bgb=200.8119,200.0099;bgg=100,1,grey95"); + @figure[title](type=label; pos=0,-1; anchor=sw; color=darkblue); + + submodules: + configurator: Ipv4NetworkConfigurator { + @display("p=512.39996,181.17"); + } + radioMedium: like IRadioMedium { + @display("p=512.39996,289.13998"); + } + physicalEnvironment: PhysicalEnvironment { + @display("p=512.39996,441.02997"); + } + host[numNodes]: like INetworkNode { + @display("i=misc/sensor2"); + } + baseStation: like INetworkNode { + @display("p=50,50;i=misc/sensorgateway"); + } +} + +%#-------------------------------------------------------------------------------------------------------------- +%inifile: omnetpp.ini + +[General] +network = Leach + +num-rngs = 2 +rng-class = omnetpp::cMersenneTwister +seed-0-mt= 4900 # used for node layout generation +seed-1-mt = 7 # used for threshold comparison + +**.arp.typename = "GlobalArp" + +*.radioMedium.typename = "Ieee802154NarrowbandScalarRadioMedium" +*.radioMedium.backgroundNoise.power = -100dBm +*.radioMedium.mediumLimitCache.centerFrequency = 2GHz + +*.host*.hasStatus = true +*.visualizer.energyStorageVisualizer.displayEnergyStorages = true + +*.configurator.config = xmldoc ("address.xml") + +*.baseStation.typename = "LeachBS" +*.host*.typename = "LeachNode" +*.host*.LEACHnode.clusterHeadPercentage = 0.05 +*.host*.LEACHnode.numNodes = 100 # set number of nodes to be injected into LEACH module + +*.numNodes = 100 #100 +*.host*.mobility.typename = "StationaryMobility" +*.host*.mobility.rng-0 = 0 # random number generator mapping + +*.host[*].mobility.initFromDisplayString = false + +**.constraintAreaMinX = 1m +**.constraintAreaMaxX = 100m +**.constraintAreaMinY = 1m +**.constraintAreaMaxY = 100m + +*.host*.wlan[0].typename = "Ieee802154NarrowbandInterface" +*.host*.wlan[0].radio.typename = "ApskScalarRadio" +*.host*.wlan[0].radio.centerFrequency = 2.5GHz # based on TI CC2520 +*.host*.wlan[0].radio.bandwidth = 2MHz +*.host*.wlan[0].radio.transmitter.power = 60.5mW # determines communication range - based on CC2520 +*.host*.wlan[0].radio.transmitter.preambleDuration = 192us # based on TI CC2520 +*.host*.wlan[0].radio.transmitter.headerLength = 6B # based on TI CC2520 +*.host*.wlan[0].radio.receiver.sensitivity = -98dBm # based on TI CC2520 +*.host*.wlan[0].radio.receiver.energyDetection = -85dBm +*.host*.wlan[0].radio.receiver.snirThreshold = 4dB +*.host*.wlan[0].radio.displayCommunicationRange = true + + +*.baseStation.wlan[0].typename = "Ieee802154NarrowbandInterface" +*.baseStation.wlan[0].radio.typename = "ApskScalarRadio" +*.baseStation.wlan[0].radio.centerFrequency = 2.5GHz +*.baseStation.wlan[0].radio.bandwidth = 2MHz +*.baseStation.wlan[0].radio.transmitter.power = 60.5mW +*.baseStation.wlan[0].radio.transmitter.preambleDuration = 192us +*.baseStation.wlan[0].radio.transmitter.headerLength = 6B +*.baseStation.wlan[0].radio.receiver.sensitivity = -98dBm +*.baseStation.wlan[0].radio.receiver.energyDetection = -85dBm +*.baseStation.wlan[0].radio.receiver.snirThreshold = 4dB +*.baseStation.wlan[0].radio.displayCommunicationRange = true + +*.host*.**.bitrate = 250kbps # based on TI CC2520 +*.baseStation.**.bitrate = 250kbps + +%#-------------------------------------------------------------------------------------------------------------- +%file-exists: results/General-#0.sca + From 341edb5dc5aae50b85b0155593ae50b5668529d5 Mon Sep 17 00:00:00 2001 From: n-jay Date: Sat, 6 Jan 2024 10:06:39 +0530 Subject: [PATCH 04/43] Update license header format --- examples/manetrouting/leach/Leach.ned | 15 ++------------- src/inet/node/leach/LeachBS.ned | 15 ++------------- src/inet/node/leach/LeachNode.ned | 15 ++------------- src/inet/routing/leach/Leach.cc | 15 ++------------- src/inet/routing/leach/Leach.h | 15 ++------------- src/inet/routing/leach/Leach.ned | 15 ++------------- src/inet/routing/leach/LeachBS.cc | 15 ++------------- src/inet/routing/leach/LeachBS.h | 15 ++------------- src/inet/routing/leach/LeachBS.ned | 15 ++------------- src/inet/routing/leach/LeackPkts.msg | 15 ++------------- 10 files changed, 20 insertions(+), 130 deletions(-) diff --git a/examples/manetrouting/leach/Leach.ned b/examples/manetrouting/leach/Leach.ned index 749b55956b6..02c8b625c4a 100644 --- a/examples/manetrouting/leach/Leach.ned +++ b/examples/manetrouting/leach/Leach.ned @@ -1,17 +1,6 @@ // -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see http://www.gnu.org/licenses/. -// +// SPDX-License-Identifier: LGPL-3.0-or-later +// package inet.examples.manetrouting.leach; diff --git a/src/inet/node/leach/LeachBS.ned b/src/inet/node/leach/LeachBS.ned index 8f45fc83e45..475c17227b8 100644 --- a/src/inet/node/leach/LeachBS.ned +++ b/src/inet/node/leach/LeachBS.ned @@ -1,17 +1,6 @@ // -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see http://www.gnu.org/licenses/. -// +// SPDX-License-Identifier: LGPL-3.0-or-later +// package inet.node.leach; diff --git a/src/inet/node/leach/LeachNode.ned b/src/inet/node/leach/LeachNode.ned index 824c31cec42..f5dfcd038a2 100644 --- a/src/inet/node/leach/LeachNode.ned +++ b/src/inet/node/leach/LeachNode.ned @@ -1,17 +1,6 @@ // -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see http://www.gnu.org/licenses/. -// +// SPDX-License-Identifier: LGPL-3.0-or-later +// package inet.node.leach; diff --git a/src/inet/routing/leach/Leach.cc b/src/inet/routing/leach/Leach.cc index 27a005b31eb..62590613155 100644 --- a/src/inet/routing/leach/Leach.cc +++ b/src/inet/routing/leach/Leach.cc @@ -1,17 +1,6 @@ // -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see http://www.gnu.org/licenses/. -// +// SPDX-License-Identifier: LGPL-3.0-or-later +// #include "Leach.h" diff --git a/src/inet/routing/leach/Leach.h b/src/inet/routing/leach/Leach.h index 92157fd754a..b9e5000ef4d 100644 --- a/src/inet/routing/leach/Leach.h +++ b/src/inet/routing/leach/Leach.h @@ -1,17 +1,6 @@ // -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see http://www.gnu.org/licenses/. -// +// SPDX-License-Identifier: LGPL-3.0-or-later +// #ifndef INET_ROUTING_LEACH_LEACH_H_ #define INET_ROUTING_LEACH_LEACH_H_ diff --git a/src/inet/routing/leach/Leach.ned b/src/inet/routing/leach/Leach.ned index 0074d52b0ba..ae6d88ba666 100644 --- a/src/inet/routing/leach/Leach.ned +++ b/src/inet/routing/leach/Leach.ned @@ -1,17 +1,6 @@ // -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see http://www.gnu.org/licenses/. -// +// SPDX-License-Identifier: LGPL-3.0-or-later +// package inet.routing.leach; diff --git a/src/inet/routing/leach/LeachBS.cc b/src/inet/routing/leach/LeachBS.cc index a87378edc62..7120cdf9d3b 100644 --- a/src/inet/routing/leach/LeachBS.cc +++ b/src/inet/routing/leach/LeachBS.cc @@ -1,17 +1,6 @@ // -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see http://www.gnu.org/licenses/. -// +// SPDX-License-Identifier: LGPL-3.0-or-later +// #include #include diff --git a/src/inet/routing/leach/LeachBS.h b/src/inet/routing/leach/LeachBS.h index 767fd3b340c..bd4b9d98225 100644 --- a/src/inet/routing/leach/LeachBS.h +++ b/src/inet/routing/leach/LeachBS.h @@ -1,17 +1,6 @@ // -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see http://www.gnu.org/licenses/. -// +// SPDX-License-Identifier: LGPL-3.0-or-later +// #ifndef INET_ROUTING_LEACH_LEACHBS_H_ #define INET_ROUTING_LEACH_LEACHBS_H_ diff --git a/src/inet/routing/leach/LeachBS.ned b/src/inet/routing/leach/LeachBS.ned index aaccbe08e71..51abf2a7cd6 100644 --- a/src/inet/routing/leach/LeachBS.ned +++ b/src/inet/routing/leach/LeachBS.ned @@ -1,17 +1,6 @@ // -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see http://www.gnu.org/licenses/. -// +// SPDX-License-Identifier: LGPL-3.0-or-later +// package inet.routing.leach; diff --git a/src/inet/routing/leach/LeackPkts.msg b/src/inet/routing/leach/LeackPkts.msg index 79fd0dc9e8c..29e09af8686 100644 --- a/src/inet/routing/leach/LeackPkts.msg +++ b/src/inet/routing/leach/LeackPkts.msg @@ -1,17 +1,6 @@ // -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see http://www.gnu.org/licenses/. -// +// SPDX-License-Identifier: LGPL-3.0-or-later +// import inet.common.INETDefs; import inet.common.packet.chunk.Chunk; From 8be9a0f0966c23bf45f2bc2ac05651db50ffd70f Mon Sep 17 00:00:00 2001 From: n-jay Date: Sun, 7 Jan 2024 21:00:55 +0530 Subject: [PATCH 05/43] Fix header file paths --- src/inet/routing/leach/Leach.cc | 2 +- src/inet/routing/leach/Leach.h | 2 +- src/inet/routing/leach/LeachBS.cc | 4 ++-- src/inet/routing/leach/LeachBS.h | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/inet/routing/leach/Leach.cc b/src/inet/routing/leach/Leach.cc index 62590613155..64835f45429 100644 --- a/src/inet/routing/leach/Leach.cc +++ b/src/inet/routing/leach/Leach.cc @@ -2,7 +2,6 @@ // SPDX-License-Identifier: LGPL-3.0-or-later // -#include "Leach.h" #include #include @@ -24,6 +23,7 @@ #include "inet/common/lifecycle/ModuleOperations.h" #include "inet/common/lifecycle/NodeStatus.h" #include "inet/common/lifecycle/LifecycleController.h" +#include "inet/routing/leach/Leach.h" namespace inet { diff --git a/src/inet/routing/leach/Leach.h b/src/inet/routing/leach/Leach.h index b9e5000ef4d..02005904b5e 100644 --- a/src/inet/routing/leach/Leach.h +++ b/src/inet/routing/leach/Leach.h @@ -22,7 +22,7 @@ #include "inet/networklayer/ipv4/Ipv4InterfaceData.h" #include "inet/networklayer/ipv4/Ipv4RoutingTable.h" #include "inet/routing/base/RoutingProtocolBase.h" -#include "LeackPkts_m.h" +#include "inet/routing/leach/LeackPkts_m.h" #include "inet/mobility/contract/IMobility.h" #include "inet/common/geometry/common/Coord.h" #include "inet/mobility/base/StationaryMobilityBase.h" diff --git a/src/inet/routing/leach/LeachBS.cc b/src/inet/routing/leach/LeachBS.cc index 7120cdf9d3b..62028b768ed 100644 --- a/src/inet/routing/leach/LeachBS.cc +++ b/src/inet/routing/leach/LeachBS.cc @@ -11,9 +11,9 @@ #include "inet/common/ProtocolTag_m.h" #include "inet/linklayer/common/InterfaceTag_m.h" #include "inet/networklayer/common/L3AddressTag_m.h" -#include "inet/routing/leach/Leach.h" #include "inet/physicallayer/wireless/common/contract/packetlevel/SignalTag_m.h" -#include "LeachBS.h" +#include "inet/routing/leach/LeachBS.h" +#include "inet/routing/leach/Leach.h" using namespace std; diff --git a/src/inet/routing/leach/LeachBS.h b/src/inet/routing/leach/LeachBS.h index bd4b9d98225..ff51dd8aa71 100644 --- a/src/inet/routing/leach/LeachBS.h +++ b/src/inet/routing/leach/LeachBS.h @@ -14,8 +14,8 @@ #include "inet/networklayer/ipv4/Ipv4InterfaceData.h" #include "inet/networklayer/ipv4/Ipv4RoutingTable.h" #include "inet/routing/base/RoutingProtocolBase.h" -#include "LeackPkts_m.h" -#include "Leach.h" +#include "inet/routing/leach/LeackPkts_m.h" +#include "inet/routing/leach/Leach.h" namespace inet { From 751bc0fd73c31f8e5467a4b7165aa63578014cea Mon Sep 17 00:00:00 2001 From: n-jay Date: Sun, 7 Jan 2024 21:02:05 +0530 Subject: [PATCH 06/43] Remove C++ block from .msg definition --- src/inet/routing/leach/LeackPkts.msg | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/inet/routing/leach/LeackPkts.msg b/src/inet/routing/leach/LeackPkts.msg index 29e09af8686..538a96de815 100644 --- a/src/inet/routing/leach/LeackPkts.msg +++ b/src/inet/routing/leach/LeackPkts.msg @@ -6,16 +6,6 @@ import inet.common.INETDefs; import inet.common.packet.chunk.Chunk; import inet.networklayer.contract.ipv4.Ipv4Address; -cplusplus {{ - #include - #include "inet/common/INETDefs.h" - #include "Leach.h" - #include "inet/networklayer/contract/ipv4/Ipv4Address.h" - using namespace std; - using namespace inet; - -}} - namespace inet; enum LeachPktType { From 052beed3e8e63b7fb9b1cd1af557677ef137a360 Mon Sep 17 00:00:00 2001 From: n-jay Date: Mon, 8 Jan 2024 11:16:10 +0530 Subject: [PATCH 07/43] Move codebase under inet::leach namespace --- src/inet/routing/leach/Leach.cc | 4 +++- src/inet/routing/leach/Leach.h | 2 ++ src/inet/routing/leach/Leach.ned | 1 + src/inet/routing/leach/LeachBS.cc | 2 ++ src/inet/routing/leach/LeachBS.h | 2 ++ src/inet/routing/leach/LeachBS.ned | 1 + src/inet/routing/leach/LeackPkts.msg | 2 +- 7 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/inet/routing/leach/Leach.cc b/src/inet/routing/leach/Leach.cc index 64835f45429..40f7ee91811 100644 --- a/src/inet/routing/leach/Leach.cc +++ b/src/inet/routing/leach/Leach.cc @@ -26,8 +26,9 @@ #include "inet/routing/leach/Leach.h" namespace inet { +namespace leach { -Register_Enum(inet::Leach, (Leach::ch, Leach::nch)); +Register_Enum(inet::leach::Leach, (Leach::ch, Leach::nch)); Define_Module(Leach); Leach::Leach() { @@ -466,4 +467,5 @@ void Leach::refreshDisplay() const { host->getDisplayString().removeTag("i2"); } } +} /* namespace leach */ } /* namespace inet */ diff --git a/src/inet/routing/leach/Leach.h b/src/inet/routing/leach/Leach.h index 02005904b5e..8d8b1ef23db 100644 --- a/src/inet/routing/leach/Leach.h +++ b/src/inet/routing/leach/Leach.h @@ -32,6 +32,7 @@ using namespace std; namespace inet { +namespace leach { class INET_API Leach: public RoutingProtocolBase { @@ -124,6 +125,7 @@ class INET_API Leach: public RoutingProtocolBase { Ipv4Address getIdealCH(Ipv4Address nodeAddr, Ipv4Address CHAddr); }; +} /* namespace leach */ } /* namespace inet */ #endif /* INET_ROUTING_LEACH_LEACH_H_ */ diff --git a/src/inet/routing/leach/Leach.ned b/src/inet/routing/leach/Leach.ned index ae6d88ba666..fdb3c395de3 100644 --- a/src/inet/routing/leach/Leach.ned +++ b/src/inet/routing/leach/Leach.ned @@ -9,6 +9,7 @@ import inet.routing.contract.IManetRouting; simple Leach like IManetRouting { parameters: + @class("leach::Leach"); @display("i=block/routing"); string interfaceTableModule; // The path to the InterfaceTable module double maxVariance = default(1); diff --git a/src/inet/routing/leach/LeachBS.cc b/src/inet/routing/leach/LeachBS.cc index 62028b768ed..27fffce7771 100644 --- a/src/inet/routing/leach/LeachBS.cc +++ b/src/inet/routing/leach/LeachBS.cc @@ -18,6 +18,7 @@ using namespace std; namespace inet { +namespace leach { Define_Module(LeachBS); @@ -112,4 +113,5 @@ void LeachBS::handleMessageWhenUp(cMessage *msg) { } } +} /* namespace leach */ } /* namespace inet */ diff --git a/src/inet/routing/leach/LeachBS.h b/src/inet/routing/leach/LeachBS.h index ff51dd8aa71..b8870ed3de5 100644 --- a/src/inet/routing/leach/LeachBS.h +++ b/src/inet/routing/leach/LeachBS.h @@ -18,6 +18,7 @@ #include "inet/routing/leach/Leach.h" namespace inet { +namespace leach { // Base Station of network which acts as data sink class INET_API LeachBS: public RoutingProtocolBase { @@ -54,6 +55,7 @@ class INET_API LeachBS: public RoutingProtocolBase { void stop(); }; +} /* namespace leach */ } /* namespace inet */ #endif /* INET_ROUTING_LEACH_LEACHBS_H_ */ diff --git a/src/inet/routing/leach/LeachBS.ned b/src/inet/routing/leach/LeachBS.ned index 51abf2a7cd6..6158122b51f 100644 --- a/src/inet/routing/leach/LeachBS.ned +++ b/src/inet/routing/leach/LeachBS.ned @@ -9,6 +9,7 @@ import inet.routing.contract.IManetRouting; simple LeachBS like IManetRouting { parameters: + @class("leach::LeachBS"); @display("i=block/routing"); string interfaceTableModule; // The path to the InterfaceTable module string routingTableModule; diff --git a/src/inet/routing/leach/LeackPkts.msg b/src/inet/routing/leach/LeackPkts.msg index 538a96de815..e6771e3da27 100644 --- a/src/inet/routing/leach/LeackPkts.msg +++ b/src/inet/routing/leach/LeackPkts.msg @@ -6,7 +6,7 @@ import inet.common.INETDefs; import inet.common.packet.chunk.Chunk; import inet.networklayer.contract.ipv4.Ipv4Address; -namespace inet; +namespace inet::leach; enum LeachPktType { CH = 1; From 0796844d8e970cbbbb15a9307d58669770163b9d Mon Sep 17 00:00:00 2001 From: n-jay Date: Mon, 8 Jan 2024 11:28:08 +0530 Subject: [PATCH 08/43] Update enum checks --- src/inet/routing/leach/Leach.cc | 10 +++++----- src/inet/routing/leach/LeachBS.cc | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/inet/routing/leach/Leach.cc b/src/inet/routing/leach/Leach.cc index 40f7ee91811..d08e5b2d830 100644 --- a/src/inet/routing/leach/Leach.cc +++ b/src/inet/routing/leach/Leach.cc @@ -192,7 +192,7 @@ void Leach::processMessage(cMessage *msg) { // filter packet based on type and run specific functions if (msg->arrivedOn("ipIn")) { // first broadcast from CH to NCH nodes - if (packetType == 1) { + if (packetType == CH) { Ipv4Address CHAddr = receivedCtrlPkt->getSrcAddress(); auto signalPowerInd = receivedPkt->getTag(); @@ -202,7 +202,7 @@ void Leach::processMessage(cMessage *msg) { sendAckToCH(selfAddr, CHAddr); // ACK packet from NCH node to CH - } else if (packetType == 2 && leachState == ch) { + } else if (packetType == ACK && leachState == ch) { Ipv4Address nodeAddr = receivedCtrlPkt->getSrcAddress(); addToNodeCHMemory(nodeAddr); @@ -211,7 +211,7 @@ void Leach::processMessage(cMessage *msg) { } // TDMA schedule from CH to NCH - } else if (packetType == 3) { + } else if (packetType == SCH) { Ipv4Address CHAddr = receivedCtrlPkt->getSrcAddress(); int scheduleArraySize = receivedCtrlPkt->getScheduleArraySize(); @@ -240,13 +240,13 @@ void Leach::processMessage(cMessage *msg) { sendDataToCH(selfAddr, CHAddr, receivedTDMADelay); } // Data packet from NCH to CH - } else if (packetType == 4) { + } else if (packetType == DATA) { Ipv4Address NCHAddr = receivedCtrlPkt->getSrcAddress(); sendDataToBS(selfAddr); // BS packet from CH to BS - deleted in the case of standard nodes - } else if (packetType == 5) { + } else if (packetType == BS) { delete msg; } } else { diff --git a/src/inet/routing/leach/LeachBS.cc b/src/inet/routing/leach/LeachBS.cc index 27fffce7771..43227a38582 100644 --- a/src/inet/routing/leach/LeachBS.cc +++ b/src/inet/routing/leach/LeachBS.cc @@ -99,7 +99,7 @@ void LeachBS::handleMessageWhenUp(cMessage *msg) { // filter packet based on type and run specific functions if (msg->arrivedOn("ipIn")) { - if (packetType == 5) { + if (packetType == BS) { bsPktReceived += 1; } else { delete msg; From 7215b3ca267ae7bad41ca486d8991fe24d4f7fee Mon Sep 17 00:00:00 2001 From: n-jay Date: Mon, 8 Jan 2024 12:47:12 +0530 Subject: [PATCH 09/43] Parameterize network interface name --- src/inet/routing/leach/Leach.cc | 4 ++-- src/inet/routing/leach/Leach.h | 2 +- src/inet/routing/leach/Leach.ned | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/inet/routing/leach/Leach.cc b/src/inet/routing/leach/Leach.cc index d08e5b2d830..a6da5246078 100644 --- a/src/inet/routing/leach/Leach.cc +++ b/src/inet/routing/leach/Leach.cc @@ -2,7 +2,6 @@ // SPDX-License-Identifier: LGPL-3.0-or-later // - #include #include #include @@ -52,6 +51,7 @@ void Leach::initialize(int stage) { clusterHeadPercentage = par("clusterHeadPercentage"); numNodes = par("numNodes"); + netInterface = par("netInterface"); roundDuration = dblrand(0) * 10; TDMADelayCounter = 1; @@ -79,7 +79,7 @@ void Leach::start() { for (int i = 0; i < ift->getNumInterfaces(); i++) { ie = ift->getInterface(i); name = ie->getInterfaceName(); - if (strstr(name, "wlan") != nullptr) { + if (strstr(name, netInterface) != nullptr) { i_face = ie; num_802154++; interfaceId = i; diff --git a/src/inet/routing/leach/Leach.h b/src/inet/routing/leach/Leach.h index 8d8b1ef23db..8474bba0785 100644 --- a/src/inet/routing/leach/Leach.h +++ b/src/inet/routing/leach/Leach.h @@ -37,7 +37,6 @@ namespace leach { class INET_API Leach: public RoutingProtocolBase { private: - NetworkInterface *interface80211ptr = nullptr; int interfaceId = -1; unsigned int sequencenumber = 0; @@ -45,6 +44,7 @@ class INET_API Leach: public RoutingProtocolBase { Ipv4Address idealCH; cMessage *event = nullptr; int round; + const char *netInterface; protected: IInterfaceTable *ift = nullptr; diff --git a/src/inet/routing/leach/Leach.ned b/src/inet/routing/leach/Leach.ned index fdb3c395de3..73e9cdf42ee 100644 --- a/src/inet/routing/leach/Leach.ned +++ b/src/inet/routing/leach/Leach.ned @@ -15,6 +15,7 @@ simple Leach like IManetRouting double maxVariance = default(1); int numNodes = default(10); double clusterHeadPercentage = default(0.5); + string netInterface = default("wlan"); gates: input ipIn; output ipOut; From 298eff7e475b8d35a7ab857ff7b55f957e9b165d Mon Sep 17 00:00:00 2001 From: n-jay Date: Mon, 8 Jan 2024 13:12:27 +0530 Subject: [PATCH 10/43] Remove unused includes --- src/inet/routing/leach/Leach.cc | 9 --------- src/inet/routing/leach/Leach.h | 5 ----- src/inet/routing/leach/LeachBS.cc | 4 ---- 3 files changed, 18 deletions(-) diff --git a/src/inet/routing/leach/Leach.cc b/src/inet/routing/leach/Leach.cc index a6da5246078..a3ce17b6b1f 100644 --- a/src/inet/routing/leach/Leach.cc +++ b/src/inet/routing/leach/Leach.cc @@ -2,15 +2,6 @@ // SPDX-License-Identifier: LGPL-3.0-or-later // -#include -#include -#include -#include -#include -#include -#include -#include - #include "inet/common/IProtocolRegistrationListener.h" #include "inet/common/ModuleAccess.h" #include "inet/common/ProtocolTag_m.h" diff --git a/src/inet/routing/leach/Leach.h b/src/inet/routing/leach/Leach.h index 8474bba0785..b458a01ccab 100644 --- a/src/inet/routing/leach/Leach.h +++ b/src/inet/routing/leach/Leach.h @@ -5,13 +5,8 @@ #ifndef INET_ROUTING_LEACH_LEACH_H_ #define INET_ROUTING_LEACH_LEACH_H_ -#include -#include -#include #include #include -#include -#include #include "inet/common/INETDefs.h" #include "inet/common/packet/Packet.h" diff --git a/src/inet/routing/leach/LeachBS.cc b/src/inet/routing/leach/LeachBS.cc index 43227a38582..3db711ed764 100644 --- a/src/inet/routing/leach/LeachBS.cc +++ b/src/inet/routing/leach/LeachBS.cc @@ -2,10 +2,6 @@ // SPDX-License-Identifier: LGPL-3.0-or-later // -#include -#include -#include - #include "inet/common/IProtocolRegistrationListener.h" #include "inet/common/ModuleAccess.h" #include "inet/common/ProtocolTag_m.h" From 57c36ed7279cd4217baafa52ec743ee7f37fe56f Mon Sep 17 00:00:00 2001 From: n-jay Date: Thu, 11 Jan 2024 13:33:38 +0530 Subject: [PATCH 11/43] Fix uninitialized variable issue Causing inconsistent simulation fingerprints --- src/inet/routing/leach/Leach.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inet/routing/leach/Leach.h b/src/inet/routing/leach/Leach.h index b458a01ccab..0ac1cc35c95 100644 --- a/src/inet/routing/leach/Leach.h +++ b/src/inet/routing/leach/Leach.h @@ -38,7 +38,7 @@ class INET_API Leach: public RoutingProtocolBase { cModule *host = nullptr; Ipv4Address idealCH; cMessage *event = nullptr; - int round; + int round = 0; const char *netInterface; protected: From 8ba9c25802d8aa24f7991e90dac32a2b0ca46d35 Mon Sep 17 00:00:00 2001 From: n-jay Date: Thu, 11 Jan 2024 13:34:26 +0530 Subject: [PATCH 12/43] Amend destructor cancel event opreation --- src/inet/routing/leach/Leach.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/inet/routing/leach/Leach.cc b/src/inet/routing/leach/Leach.cc index a3ce17b6b1f..4b663689444 100644 --- a/src/inet/routing/leach/Leach.cc +++ b/src/inet/routing/leach/Leach.cc @@ -26,8 +26,8 @@ Leach::Leach() { } Leach::~Leach() { + cancelAndDelete(event); stop(); - delete event; } void Leach::initialize(int stage) { @@ -92,7 +92,7 @@ void Leach::start() { } void Leach::stop() { - cancelEvent(event); + nodeMemory.clear(); nodeCHMemory.clear(); extractedTDMASchedule.clear(); From ee9c1a9bcf10515f473f084c6477ecba53754a8e Mon Sep 17 00:00:00 2001 From: n-jay Date: Thu, 11 Jan 2024 13:42:37 +0530 Subject: [PATCH 13/43] Update fingerprint test values --- tests/fingerprint/examples.csv | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/fingerprint/examples.csv b/tests/fingerprint/examples.csv index 9af9a3a4c5e..39ebed85f20 100644 --- a/tests/fingerprint/examples.csv +++ b/tests/fingerprint/examples.csv @@ -332,9 +332,9 @@ /examples/manetrouting/dsdv/, -f omnetpp.ini -c MultiIPv4 -r 0, 10s, 94c8-51dd/tplx;e9e8-7d0b/~tNl;e9f0-b256/~tND;e86f-d3fa/tyf, PASS, wireless adhoc Ipv4 /examples/manetrouting/dsdv/, -f omnetpp.ini -c DynamicIPv4 -r 0, 22s, 6699-04d7/tplx;3e2c-1eee/~tNl;eecc-7593/~tND;90d2-3ffa/tyf, PASS, wireless adhoc Ipv4 -/examples/manetrouting/leach/,-f omnetpp.ini -r 0, 100s, f58b-b959/tplx,PASS,wireless adhoc Ipv4 -/examples/manetrouting/leach/,-f omnetpp.ini -c LeachPower -r 0, 100s, 0db4-188a/tplx, PASS,wireless adhoc Ipv4 -/examples/manetrouting/leach/,-f omnetpp.ini -c LeachPathLoss -r 0, 100s, 1617-1827/tplx, PASS,wireless adhoc Ipv4 +/examples/manetrouting/leach/,-f omnetpp.ini -r 0, 100s, 4e95-15b7/tplx,PASS,wireless adhoc Ipv4 +/examples/manetrouting/leach/,-f omnetpp.ini -c LeachPower -r 0, 100s, 4e95-15b7/tplx, PASS,wireless adhoc Ipv4 +/examples/manetrouting/leach/,-f omnetpp.ini -c LeachPathLoss -r 0, 100s, bc19-1ea2/tplx, PASS,wireless adhoc Ipv4 # /examples/manetrouting/dymo/, -f omnetpp.ini -c _IPv4 -r 0 # abstract-config /examples/manetrouting/dymo/, -f omnetpp.ini -c IPv4 -r 0, 10s, 1a85-cb5d/tplx;dfe8-11b9/~tNl;483b-544e/tyf, PASS, wireless adhoc Ipv4 From 439032d6e92d2e00fe97cf6dbad06ebb1fe434d7 Mon Sep 17 00:00:00 2001 From: n-jay Date: Thu, 11 Jan 2024 14:26:23 +0530 Subject: [PATCH 14/43] Update fingerprint test values --- tests/fingerprint/examples.csv | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/fingerprint/examples.csv b/tests/fingerprint/examples.csv index 39ebed85f20..dd01ad03b41 100644 --- a/tests/fingerprint/examples.csv +++ b/tests/fingerprint/examples.csv @@ -332,9 +332,9 @@ /examples/manetrouting/dsdv/, -f omnetpp.ini -c MultiIPv4 -r 0, 10s, 94c8-51dd/tplx;e9e8-7d0b/~tNl;e9f0-b256/~tND;e86f-d3fa/tyf, PASS, wireless adhoc Ipv4 /examples/manetrouting/dsdv/, -f omnetpp.ini -c DynamicIPv4 -r 0, 22s, 6699-04d7/tplx;3e2c-1eee/~tNl;eecc-7593/~tND;90d2-3ffa/tyf, PASS, wireless adhoc Ipv4 -/examples/manetrouting/leach/,-f omnetpp.ini -r 0, 100s, 4e95-15b7/tplx,PASS,wireless adhoc Ipv4 -/examples/manetrouting/leach/,-f omnetpp.ini -c LeachPower -r 0, 100s, 4e95-15b7/tplx, PASS,wireless adhoc Ipv4 -/examples/manetrouting/leach/,-f omnetpp.ini -c LeachPathLoss -r 0, 100s, bc19-1ea2/tplx, PASS,wireless adhoc Ipv4 +/examples/manetrouting/leach/,-f omnetpp.ini -r 0, 100s, d028-7203/tplx,PASS,wireless adhoc Ipv4 +/examples/manetrouting/leach/,-f omnetpp.ini -c LeachPower -r 0, 100s, d028-7203/tplx, PASS,wireless adhoc Ipv4 +/examples/manetrouting/leach/,-f omnetpp.ini -c LeachPathLoss -r 0, 100s, 76ca-cca8/tplx, PASS,wireless adhoc Ipv4 # /examples/manetrouting/dymo/, -f omnetpp.ini -c _IPv4 -r 0 # abstract-config /examples/manetrouting/dymo/, -f omnetpp.ini -c IPv4 -r 0, 10s, 1a85-cb5d/tplx;dfe8-11b9/~tNl;483b-544e/tyf, PASS, wireless adhoc Ipv4 From 9c05df0704f0f4c751ed6b97ca43bb8f2cf055b2 Mon Sep 17 00:00:00 2001 From: n-jay Date: Sat, 13 Jan 2024 16:00:07 +0530 Subject: [PATCH 15/43] Update network interface configuration flow --- src/inet/routing/leach/Leach.cc | 40 +++++++++++------------------ src/inet/routing/leach/Leach.h | 5 ++-- src/inet/routing/leach/Leach.ned | 1 - src/inet/routing/leach/LeachBS.cc | 42 +++++++++++++------------------ src/inet/routing/leach/LeachBS.h | 2 ++ 5 files changed, 35 insertions(+), 55 deletions(-) diff --git a/src/inet/routing/leach/Leach.cc b/src/inet/routing/leach/Leach.cc index 4b663689444..0c92c3bf7cc 100644 --- a/src/inet/routing/leach/Leach.cc +++ b/src/inet/routing/leach/Leach.cc @@ -37,12 +37,10 @@ void Leach::initialize(int stage) { if (stage == INITSTAGE_LOCAL) { sequencenumber = 0; host = getContainingNode(this); - ift = getModuleFromPar(par("interfaceTableModule"), - this); + interfaceTable.reference(this, "interfaceTableModule", true); clusterHeadPercentage = par("clusterHeadPercentage"); numNodes = par("numNodes"); - netInterface = par("netInterface"); roundDuration = dblrand(0) * 10; TDMADelayCounter = 1; @@ -62,28 +60,7 @@ void Leach::initialize(int stage) { void Leach::start() { // Search the 802154 interface - int num_802154 = 0; - NetworkInterface *ie; - NetworkInterface *i_face; - const char *name; - - for (int i = 0; i < ift->getNumInterfaces(); i++) { - ie = ift->getInterface(i); - name = ie->getInterfaceName(); - if (strstr(name, netInterface) != nullptr) { - i_face = ie; - num_802154++; - interfaceId = i; - } - } - - // One enabled network interface (in total) - if (num_802154 == 1) - interface80211ptr = i_face; - else - throw cRuntimeError("DSDV has found %i 80211 interfaces", num_802154); - CHK(interface80211ptr->getProtocolDataForUpdate())->joinMulticastGroup( - Ipv4Address::LL_MANET_ROUTERS); + configureInterfaces(); // schedules a random periodic event event->setKind(SELF); @@ -92,13 +69,24 @@ void Leach::start() { } void Leach::stop() { - nodeMemory.clear(); nodeCHMemory.clear(); extractedTDMASchedule.clear(); TDMADelayCounter = 1; } +void Leach::configureInterfaces() { + int numInterfaces = interfaceTable->getNumInterfaces(); + for (int i = 0; i < numInterfaces; i++) { + NetworkInterface *networkInterface = interfaceTable->getInterface(i); + // Only single wireless interface is required + if (networkInterface->isWireless()) { + interface80211ptr = networkInterface; + break; + } + } +} + void Leach::handleMessageWhenUp(cMessage *msg) { // if node is sending message if (msg->isSelfMessage()) { diff --git a/src/inet/routing/leach/Leach.h b/src/inet/routing/leach/Leach.h index 0ac1cc35c95..af589f3f3bf 100644 --- a/src/inet/routing/leach/Leach.h +++ b/src/inet/routing/leach/Leach.h @@ -33,16 +33,14 @@ class INET_API Leach: public RoutingProtocolBase { private: NetworkInterface *interface80211ptr = nullptr; - int interfaceId = -1; unsigned int sequencenumber = 0; cModule *host = nullptr; Ipv4Address idealCH; cMessage *event = nullptr; int round = 0; - const char *netInterface; + ModuleRefByPar interfaceTable; protected: - IInterfaceTable *ift = nullptr; simtime_t dataPktSendDelay; simtime_t CHPktSendDelay; simtime_t roundDuration; @@ -87,6 +85,7 @@ class INET_API Leach: public RoutingProtocolBase { void handleSelfMessage(cMessage *msg); void processMessage(cMessage *msg); + void configureInterfaces(); // lifecycle virtual void handleStartOperation(LifecycleOperation *operation) override { diff --git a/src/inet/routing/leach/Leach.ned b/src/inet/routing/leach/Leach.ned index 73e9cdf42ee..fdb3c395de3 100644 --- a/src/inet/routing/leach/Leach.ned +++ b/src/inet/routing/leach/Leach.ned @@ -15,7 +15,6 @@ simple Leach like IManetRouting double maxVariance = default(1); int numNodes = default(10); double clusterHeadPercentage = default(0.5); - string netInterface = default("wlan"); gates: input ipIn; output ipOut; diff --git a/src/inet/routing/leach/LeachBS.cc b/src/inet/routing/leach/LeachBS.cc index 3db711ed764..090b46f6311 100644 --- a/src/inet/routing/leach/LeachBS.cc +++ b/src/inet/routing/leach/LeachBS.cc @@ -33,8 +33,9 @@ void LeachBS::initialize(int stage) { if (stage == INITSTAGE_LOCAL) { sequencenumber = 0; host = getContainingNode(this); - ift = getModuleFromPar(par("interfaceTableModule"), - this); +// ift = getModuleFromPar(par("interfaceTableModule"), +// this); + interfaceTable.reference(this, "interfaceTableModule", true); bsPktReceived = 0; @@ -45,36 +46,27 @@ void LeachBS::initialize(int stage) { } void LeachBS::start() { - /* Search the 80211 interface */ - int num_80211 = 0; - NetworkInterface *ie; - NetworkInterface *i_face; - const char *name; - - for (int i = 0; i < ift->getNumInterfaces(); i++) { - ie = ift->getInterface(i); - name = ie->getInterfaceName(); - if (strstr(name, "wlan") != nullptr) { - i_face = ie; - num_80211++; - interfaceId = i; - } - } + /* Search the 802154 interface */ + configureInterfaces(); - // One enabled network interface (in total) - if (num_80211 == 1) - interface80211ptr = i_face; - else - throw cRuntimeError("DSDV has found %i 80211 interfaces", num_80211); - - CHK(interface80211ptr->getProtocolDataForUpdate())->joinMulticastGroup( - Ipv4Address::LL_MANET_ROUTERS); } void LeachBS::stop() { } +void LeachBS::configureInterfaces() { + int numInterfaces = interfaceTable->getNumInterfaces(); + for (int i = 0; i < numInterfaces; i++) { + NetworkInterface *networkInterface = interfaceTable->getInterface(i); + // Only single wireless interface is required + if (networkInterface->isWireless()) { + interface80211ptr = networkInterface; + break; + } + } +} + void LeachBS::handleMessageWhenUp(cMessage *msg) { Ipv4Address nodeAddr = (interface80211ptr->getProtocolData()->getIPAddress()); diff --git a/src/inet/routing/leach/LeachBS.h b/src/inet/routing/leach/LeachBS.h index b8870ed3de5..a2ffb1c0346 100644 --- a/src/inet/routing/leach/LeachBS.h +++ b/src/inet/routing/leach/LeachBS.h @@ -34,6 +34,7 @@ class INET_API LeachBS: public RoutingProtocolBase { IInterfaceTable *ift = nullptr; unsigned int sequencenumber = 0; cModule *host = nullptr; + ModuleRefByPar interfaceTable; protected: virtual int numInitStages() const override { @@ -41,6 +42,7 @@ class INET_API LeachBS: public RoutingProtocolBase { } virtual void initialize(int stage) override; virtual void handleMessageWhenUp(cMessage *msg) override; + void configureInterfaces(); virtual void handleStartOperation(LifecycleOperation *operation) override { start(); From 6947423ec1ba8f7c635624dcdd005f9bd0978bc7 Mon Sep 17 00:00:00 2001 From: n-jay Date: Sun, 14 Jan 2024 17:08:25 +0530 Subject: [PATCH 16/43] Add documentation in NED files --- src/inet/routing/leach/Leach.ned | 21 +++++++++++++++++++-- src/inet/routing/leach/LeachBS.ned | 17 +++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/inet/routing/leach/Leach.ned b/src/inet/routing/leach/Leach.ned index fdb3c395de3..92e011f4299 100644 --- a/src/inet/routing/leach/Leach.ned +++ b/src/inet/routing/leach/Leach.ned @@ -6,13 +6,30 @@ package inet.routing.leach; import inet.routing.contract.IManetRouting; +// +// This module provides the sensor implementation of +// Low-Energy Adaptive Clustering Hierarchy (LEACH) routing, a hierachical +// adhoc routing protocol for Wireless Sensor Networks. +// This implementation is designed to use a a single wireless interface and run on +// the IEEE 802.15.4 standard for MAC and Physical layers. +// Therefore the standard TDMA scheduling system has been implemented +// with delayed time slots due to the use of CSMA in the 802.15.4 standard. +// +// For more information on the algorithm, see the LEACH paper +// https://ieeexplore.ieee.org/document/926982 +// simple Leach like IManetRouting { parameters: + // properties @class("leach::Leach"); @display("i=block/routing"); - string interfaceTableModule; // The path to the InterfaceTable module - double maxVariance = default(1); + + // context parameters + string interfaceTableModule; + + // LEACH parameter group + double maxVariance = default(1); int numNodes = default(10); double clusterHeadPercentage = default(0.5); gates: diff --git a/src/inet/routing/leach/LeachBS.ned b/src/inet/routing/leach/LeachBS.ned index 6158122b51f..ab45dab5641 100644 --- a/src/inet/routing/leach/LeachBS.ned +++ b/src/inet/routing/leach/LeachBS.ned @@ -6,13 +6,26 @@ package inet.routing.leach; import inet.routing.contract.IManetRouting; +// +// This module provides the data sink implementation of +// Low-Energy Adaptive Clustering Hierarchy (LEACH) routing, a hierachical +// adhoc routing protocol for Wireless Sensor Networks. +// This implementation is designed to use a a single wireless interface and run on +// the IEEE 802.15.4 standard for MAC and Physical layers. +// This module simply receives data from the sensor nodes. +// +// For more information on the algorithm, see the LEACH paper +// https://ieeexplore.ieee.org/document/926982 +// simple LeachBS like IManetRouting { parameters: + // properties @class("leach::LeachBS"); @display("i=block/routing"); - string interfaceTableModule; // The path to the InterfaceTable module - string routingTableModule; + + // context parameters + string interfaceTableModule; gates: input ipIn; output ipOut; From 9dfd52098be6081445474ee681e924aadd19b20d Mon Sep 17 00:00:00 2001 From: n-jay Date: Mon, 15 Jan 2024 10:00:45 +0530 Subject: [PATCH 17/43] Delete redundant lines --- src/inet/routing/leach/LeachBS.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/inet/routing/leach/LeachBS.cc b/src/inet/routing/leach/LeachBS.cc index 090b46f6311..1a206de493f 100644 --- a/src/inet/routing/leach/LeachBS.cc +++ b/src/inet/routing/leach/LeachBS.cc @@ -33,8 +33,6 @@ void LeachBS::initialize(int stage) { if (stage == INITSTAGE_LOCAL) { sequencenumber = 0; host = getContainingNode(this); -// ift = getModuleFromPar(par("interfaceTableModule"), -// this); interfaceTable.reference(this, "interfaceTableModule", true); bsPktReceived = 0; From 2f6a9b6f69e36ea8547414f0017fb3ad695ff7c7 Mon Sep 17 00:00:00 2001 From: n-jay Date: Sat, 20 Jan 2024 19:27:23 +0530 Subject: [PATCH 18/43] Rename network interface variable --- src/inet/routing/leach/Leach.cc | 16 ++++++++-------- src/inet/routing/leach/Leach.h | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/inet/routing/leach/Leach.cc b/src/inet/routing/leach/Leach.cc index 0c92c3bf7cc..b1acecb4ba5 100644 --- a/src/inet/routing/leach/Leach.cc +++ b/src/inet/routing/leach/Leach.cc @@ -81,7 +81,7 @@ void Leach::configureInterfaces() { NetworkInterface *networkInterface = interfaceTable->getInterface(i); // Only single wireless interface is required if (networkInterface->isWireless()) { - interface80211ptr = networkInterface; + wirelessInterface = networkInterface; break; } } @@ -133,7 +133,7 @@ void Leach::handleSelfMessage(cMessage *msg) { // Filling the LeachControlPkt fields ctrlPkt->setPacketType(CH); - Ipv4Address source = (interface80211ptr->getProtocolData< + Ipv4Address source = (wirelessInterface->getProtocolData< Ipv4InterfaceData>()->getIPAddress()); ctrlPkt->setChunkLength(b(128)); ///size of Hello message in bits ctrlPkt->setSrcAddress(source); @@ -144,7 +144,7 @@ void Leach::handleSelfMessage(cMessage *msg) { addressReq->setDestAddress(Ipv4Address(255, 255, 255, 255)); addressReq->setSrcAddress(source); //let's try the limited broadcast packet->addTag()->setInterfaceId( - interface80211ptr->getInterfaceId()); + wirelessInterface->getInterfaceId()); packet->addTag()->setProtocol(&Protocol::manet); packet->addTag()->setProtocol(&Protocol::ipv4); @@ -160,7 +160,7 @@ void Leach::handleSelfMessage(cMessage *msg) { void Leach::processMessage(cMessage *msg) { Ipv4Address selfAddr = - (interface80211ptr->getProtocolData()->getIPAddress()); + (wirelessInterface->getProtocolData()->getIPAddress()); auto receivedCtrlPkt = staticPtrCast( check_and_cast(msg)->peekData()->dupShared()); @@ -323,7 +323,7 @@ void Leach::sendAckToCH(Ipv4Address nodeAddr, Ipv4Address CHAddr) { addressReq->setDestAddress(getIdealCH(nodeAddr, CHAddr)); addressReq->setSrcAddress(nodeAddr); ackPacket->addTag()->setInterfaceId( - interface80211ptr->getInterfaceId()); + wirelessInterface->getInterfaceId()); ackPacket->addTag()->setProtocol(&Protocol::manet); ackPacket->addTag()->setProtocol(&Protocol::ipv4); @@ -350,7 +350,7 @@ void Leach::sendSchToNCH(Ipv4Address selfAddr) { scheduleReq->setDestAddress(Ipv4Address(255, 255, 255, 255)); scheduleReq->setSrcAddress(selfAddr); schedulePacket->addTag()->setInterfaceId( - interface80211ptr->getInterfaceId()); + wirelessInterface->getInterfaceId()); schedulePacket->addTag()->setProtocol(&Protocol::manet); schedulePacket->addTag()->setProtocol(&Protocol::ipv4); @@ -376,7 +376,7 @@ void Leach::sendDataToCH(Ipv4Address nodeAddr, Ipv4Address CHAddr, addressReq->setDestAddress(getIdealCH(nodeAddr, CHAddr)); addressReq->setSrcAddress(nodeAddr); dataPacket->addTag()->setInterfaceId( - interface80211ptr->getInterfaceId()); + wirelessInterface->getInterfaceId()); dataPacket->addTag()->setProtocol(&Protocol::manet); dataPacket->addTag()->setProtocol(&Protocol::ipv4); @@ -397,7 +397,7 @@ void Leach::sendDataToBS(Ipv4Address CHAddr) { addressReq->setDestAddress(Ipv4Address(10, 0, 0, 1)); addressReq->setSrcAddress(CHAddr); bsPacket->addTag()->setInterfaceId( - interface80211ptr->getInterfaceId()); + wirelessInterface->getInterfaceId()); bsPacket->addTag()->setProtocol(&Protocol::manet); bsPacket->addTag()->setProtocol(&Protocol::ipv4); diff --git a/src/inet/routing/leach/Leach.h b/src/inet/routing/leach/Leach.h index af589f3f3bf..61b3549335e 100644 --- a/src/inet/routing/leach/Leach.h +++ b/src/inet/routing/leach/Leach.h @@ -32,7 +32,7 @@ namespace leach { class INET_API Leach: public RoutingProtocolBase { private: - NetworkInterface *interface80211ptr = nullptr; + NetworkInterface *wirelessInterface = nullptr; unsigned int sequencenumber = 0; cModule *host = nullptr; Ipv4Address idealCH; From e2c5cb03c51b9c441979e453cac368908641c41f Mon Sep 17 00:00:00 2001 From: n-jay Date: Sun, 4 Feb 2024 16:49:05 +0530 Subject: [PATCH 19/43] Rename sample LEACH network .ned --- examples/manetrouting/leach/{Leach.ned => LeachExample.ned} | 2 +- examples/manetrouting/leach/omnetpp.ini | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename examples/manetrouting/leach/{Leach.ned => LeachExample.ned} (98%) diff --git a/examples/manetrouting/leach/Leach.ned b/examples/manetrouting/leach/LeachExample.ned similarity index 98% rename from examples/manetrouting/leach/Leach.ned rename to examples/manetrouting/leach/LeachExample.ned index 02c8b625c4a..0b6215ad152 100644 --- a/examples/manetrouting/leach/Leach.ned +++ b/examples/manetrouting/leach/LeachExample.ned @@ -11,7 +11,7 @@ import inet.physicallayer.wireless.common.contract.packetlevel.IRadioMedium; import inet.visualizer.contract.IIntegratedVisualizer; import inet.environment.common.PhysicalEnvironment; -network Leach +network LeachExample { parameters: int numNodes; diff --git a/examples/manetrouting/leach/omnetpp.ini b/examples/manetrouting/leach/omnetpp.ini index 28c512dfc7d..11f4bf638c9 100644 --- a/examples/manetrouting/leach/omnetpp.ini +++ b/examples/manetrouting/leach/omnetpp.ini @@ -1,5 +1,5 @@ [General] -network = Leach +network = LeachExample num-rngs = 2 rng-class = omnetpp::cMersenneTwister From 9ed810b66b30bff4638d314b85f70163e2ad4a38 Mon Sep 17 00:00:00 2001 From: n-jay Date: Sun, 4 Feb 2024 17:46:17 +0530 Subject: [PATCH 20/43] Update @display coordinates --- examples/manetrouting/leach/LeachExample.ned | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/manetrouting/leach/LeachExample.ned b/examples/manetrouting/leach/LeachExample.ned index 0b6215ad152..6d3812c81ed 100644 --- a/examples/manetrouting/leach/LeachExample.ned +++ b/examples/manetrouting/leach/LeachExample.ned @@ -15,18 +15,18 @@ network LeachExample { parameters: int numNodes; - @display("bgb=200.8119,200.0099;bgg=100,1,grey95"); + @display("bgb=200,200;bgg=100,1,grey95"); @figure[title](type=label; pos=0,-1; anchor=sw; color=darkblue); submodules: configurator: Ipv4NetworkConfigurator { - @display("p=512.39996,181.17"); + @display("p=100,100"); } radioMedium: like IRadioMedium { - @display("p=512.39996,289.13998"); + @display("p=100,100"); } physicalEnvironment: PhysicalEnvironment { - @display("p=512.39996,441.02997"); + @display("p=100,100"); } host[numNodes]: like INetworkNode { @display("i=misc/sensor2"); From a6aeb1d8297ed3acea88aca2677d9b771a1d3a32 Mon Sep 17 00:00:00 2001 From: n-jay Date: Sun, 4 Feb 2024 17:53:55 +0530 Subject: [PATCH 21/43] Update sample network ini file Remove redundant RNG setting Update comments about RNG seed values --- examples/manetrouting/leach/omnetpp.ini | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/manetrouting/leach/omnetpp.ini b/examples/manetrouting/leach/omnetpp.ini index 11f4bf638c9..82b192253bf 100644 --- a/examples/manetrouting/leach/omnetpp.ini +++ b/examples/manetrouting/leach/omnetpp.ini @@ -2,9 +2,8 @@ network = LeachExample num-rngs = 2 -rng-class = omnetpp::cMersenneTwister -seed-0-mt= 4900 # used for node layout generation -seed-1-mt = 7 # used for threshold comparison +seed-0-mt= 4900 # used for node layout generation (can set any preferred value) +seed-1-mt = 7 # used for threshold comparison (can set any preferred value) **.arp.typename = "GlobalArp" From 85481e9b7706316ebeb729a40a257f3f6fbad2c2 Mon Sep 17 00:00:00 2001 From: n-jay Date: Sun, 4 Feb 2024 18:00:22 +0530 Subject: [PATCH 22/43] Add documentation for node .ned files --- src/inet/node/leach/LeachBS.ned | 15 +++++++++++++-- src/inet/node/leach/LeachNode.ned | 18 +++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/inet/node/leach/LeachBS.ned b/src/inet/node/leach/LeachBS.ned index 475c17227b8..b5c9b3685f5 100644 --- a/src/inet/node/leach/LeachBS.ned +++ b/src/inet/node/leach/LeachBS.ned @@ -7,7 +7,19 @@ package inet.node.leach; import inet.node.inet.AdhocHost; import inet.routing.leach.LeachBS; -module LeachBS extends AdhocHost { +// +// This module provides the data sink/base station implementation of +// Low-Energy Adaptive Clustering Hierarchy (LEACH) routing, a hierachical +// adhoc routing protocol for Wireless Sensor Networks. +// This implementation is designed to use a a single wireless interface and run on +// the IEEE 802.15.4 standard for MAC and Physical layers. +// This module simply receives data from the sensor nodes. +// +// For more information on the algorithm, see the LEACH paper +// https://ieeexplore.ieee.org/document/926982 +// +module LeachBS extends AdhocHost +{ submodules: LeachBS: LeachBS { @display("p=825,226"); @@ -15,5 +27,4 @@ module LeachBS extends AdhocHost { connections: LeachBS.ipOut --> tn.in++; LeachBS.ipIn <-- tn.out++; - } diff --git a/src/inet/node/leach/LeachNode.ned b/src/inet/node/leach/LeachNode.ned index f5dfcd038a2..9a7c6bda9f0 100644 --- a/src/inet/node/leach/LeachNode.ned +++ b/src/inet/node/leach/LeachNode.ned @@ -7,7 +7,20 @@ package inet.node.leach; import inet.node.inet.AdhocHost; import inet.routing.leach.Leach; -module LeachNode extends AdhocHost { +// +// This module provides the sensor node implementation of +// Low-Energy Adaptive Clustering Hierarchy (LEACH) routing, a hierachical +// adhoc routing protocol for Wireless Sensor Networks. +// This implementation is designed to use a a single wireless interface and run on +// the IEEE 802.15.4 standard for MAC and Physical layers. +// Therefore the standard TDMA scheduling system has been implemented +// with delayed time slots due to the use of CSMA in the 802.15.4 standard. +// +// For more information on the algorithm, see the LEACH paper +// https://ieeexplore.ieee.org/document/926982 +// +module LeachNode extends AdhocHost +{ submodules: LeachNode: Leach { @display("p=825,226"); @@ -15,5 +28,4 @@ module LeachNode extends AdhocHost { connections: LeachNode.ipOut --> tn.in++; LeachNode.ipIn <-- tn.out++; - -} \ No newline at end of file +} From bb14ffbec782703cf3dd5506cf978c447aec111c Mon Sep 17 00:00:00 2001 From: n-jay Date: Sun, 4 Feb 2024 22:19:30 +0530 Subject: [PATCH 23/43] Refactor LEACH routing protocol documentation --- src/inet/node/leach/LeachBS.ned | 5 ++--- src/inet/node/leach/LeachNode.ned | 6 +++--- src/inet/routing/leach/Leach.ned | 6 +++--- src/inet/routing/leach/LeachBS.ned | 5 ++--- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/inet/node/leach/LeachBS.ned b/src/inet/node/leach/LeachBS.ned index b5c9b3685f5..4654b134852 100644 --- a/src/inet/node/leach/LeachBS.ned +++ b/src/inet/node/leach/LeachBS.ned @@ -8,9 +8,8 @@ import inet.node.inet.AdhocHost; import inet.routing.leach.LeachBS; // -// This module provides the data sink/base station implementation of -// Low-Energy Adaptive Clustering Hierarchy (LEACH) routing, a hierachical -// adhoc routing protocol for Wireless Sensor Networks. +// This module provides Low-Energy Adaptive Clustering Hierarchy (LEACH) +// routing protocol for the data sink/base station. // This implementation is designed to use a a single wireless interface and run on // the IEEE 802.15.4 standard for MAC and Physical layers. // This module simply receives data from the sensor nodes. diff --git a/src/inet/node/leach/LeachNode.ned b/src/inet/node/leach/LeachNode.ned index 9a7c6bda9f0..6f24a11f1ec 100644 --- a/src/inet/node/leach/LeachNode.ned +++ b/src/inet/node/leach/LeachNode.ned @@ -8,9 +8,9 @@ import inet.node.inet.AdhocHost; import inet.routing.leach.Leach; // -// This module provides the sensor node implementation of -// Low-Energy Adaptive Clustering Hierarchy (LEACH) routing, a hierachical -// adhoc routing protocol for Wireless Sensor Networks. +// This module provides Low-Energy Adaptive Clustering Hierarchy (LEACH) +// routing protocol for sensor nodes. +// LEACH is a hierachical adhoc routing protocol for Wireless Sensor Networks. // This implementation is designed to use a a single wireless interface and run on // the IEEE 802.15.4 standard for MAC and Physical layers. // Therefore the standard TDMA scheduling system has been implemented diff --git a/src/inet/routing/leach/Leach.ned b/src/inet/routing/leach/Leach.ned index 92e011f4299..1b999c5c4cd 100644 --- a/src/inet/routing/leach/Leach.ned +++ b/src/inet/routing/leach/Leach.ned @@ -7,9 +7,9 @@ package inet.routing.leach; import inet.routing.contract.IManetRouting; // -// This module provides the sensor implementation of -// Low-Energy Adaptive Clustering Hierarchy (LEACH) routing, a hierachical -// adhoc routing protocol for Wireless Sensor Networks. +// This module provides Low-Energy Adaptive Clustering Hierarchy (LEACH) +// routing protocol for sensor nodes. +// LEACH is a hierachical adhoc routing protocol for Wireless Sensor Networks. // This implementation is designed to use a a single wireless interface and run on // the IEEE 802.15.4 standard for MAC and Physical layers. // Therefore the standard TDMA scheduling system has been implemented diff --git a/src/inet/routing/leach/LeachBS.ned b/src/inet/routing/leach/LeachBS.ned index ab45dab5641..aea8d883479 100644 --- a/src/inet/routing/leach/LeachBS.ned +++ b/src/inet/routing/leach/LeachBS.ned @@ -7,9 +7,8 @@ package inet.routing.leach; import inet.routing.contract.IManetRouting; // -// This module provides the data sink implementation of -// Low-Energy Adaptive Clustering Hierarchy (LEACH) routing, a hierachical -// adhoc routing protocol for Wireless Sensor Networks. +// This module provides Low-Energy Adaptive Clustering Hierarchy (LEACH) +// routing protocol for the data sink/base station. // This implementation is designed to use a a single wireless interface and run on // the IEEE 802.15.4 standard for MAC and Physical layers. // This module simply receives data from the sensor nodes. From c73ecaec2a66087f07d593546eb8221c10df40a4 Mon Sep 17 00:00:00 2001 From: n-jay Date: Thu, 8 Feb 2024 11:05:37 +0530 Subject: [PATCH 24/43] Add round duration variance parameter to NED --- src/inet/routing/leach/Leach.cc | 4 ++-- src/inet/routing/leach/Leach.h | 1 + src/inet/routing/leach/Leach.ned | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/inet/routing/leach/Leach.cc b/src/inet/routing/leach/Leach.cc index b1acecb4ba5..f9a624f6803 100644 --- a/src/inet/routing/leach/Leach.cc +++ b/src/inet/routing/leach/Leach.cc @@ -41,11 +41,11 @@ void Leach::initialize(int stage) { clusterHeadPercentage = par("clusterHeadPercentage"); numNodes = par("numNodes"); + roundDurationVariance = par("roundDurationVariance"); - roundDuration = dblrand(0) * 10; + roundDuration = dblrand(0) * roundDurationVariance; TDMADelayCounter = 1; event = new cMessage("event"); - roundDuration = dblrand(0) * 10; wasCH = false; vector nodeMemory(numNodes); // Localized NCH node memory with CH data diff --git a/src/inet/routing/leach/Leach.h b/src/inet/routing/leach/Leach.h index 61b3549335e..7c3eb942ad4 100644 --- a/src/inet/routing/leach/Leach.h +++ b/src/inet/routing/leach/Leach.h @@ -47,6 +47,7 @@ class INET_API Leach: public RoutingProtocolBase { int numNodes = 0; double clusterHeadPercentage = 0.0; + int roundDurationVariance = 0; // object for storing CH data per node in vector array struct nodeMemoryObject { diff --git a/src/inet/routing/leach/Leach.ned b/src/inet/routing/leach/Leach.ned index 1b999c5c4cd..b6e14b4e43b 100644 --- a/src/inet/routing/leach/Leach.ned +++ b/src/inet/routing/leach/Leach.ned @@ -32,6 +32,7 @@ simple Leach like IManetRouting double maxVariance = default(1); int numNodes = default(10); double clusterHeadPercentage = default(0.5); + int roundDurationVariance = default(10); gates: input ipIn; output ipOut; From 8293e221026e85ab095825323d730fd4c5065d23 Mon Sep 17 00:00:00 2001 From: n-jay Date: Thu, 15 Feb 2024 22:48:29 +0530 Subject: [PATCH 25/43] Update Leach NED parameters StartupDelay parameter --- src/inet/routing/leach/Leach.cc | 2 +- src/inet/routing/leach/Leach.ned | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/inet/routing/leach/Leach.cc b/src/inet/routing/leach/Leach.cc index f9a624f6803..8df84610e41 100644 --- a/src/inet/routing/leach/Leach.cc +++ b/src/inet/routing/leach/Leach.cc @@ -64,7 +64,7 @@ void Leach::start() { // schedules a random periodic event event->setKind(SELF); - scheduleAt(simTime() + uniform(0.0, par("maxVariance").doubleValue()), + scheduleAt(simTime() + uniform(0.0, par("startupDelay").doubleValue()), event); } diff --git a/src/inet/routing/leach/Leach.ned b/src/inet/routing/leach/Leach.ned index b6e14b4e43b..703573bbac7 100644 --- a/src/inet/routing/leach/Leach.ned +++ b/src/inet/routing/leach/Leach.ned @@ -29,7 +29,7 @@ simple Leach like IManetRouting string interfaceTableModule; // LEACH parameter group - double maxVariance = default(1); + volatile double startupDelay @unit(s) = default(uniform(0s, 1s)); int numNodes = default(10); double clusterHeadPercentage = default(0.5); int roundDurationVariance = default(10); From e99fabbf6bce1697931192c565820324118d3ca0 Mon Sep 17 00:00:00 2001 From: n-jay Date: Wed, 21 Feb 2024 10:58:00 +0530 Subject: [PATCH 26/43] Remove unused numNodes variable Update Leach class initialization and example simulation ini file --- examples/manetrouting/leach/omnetpp.ini | 1 - src/inet/routing/leach/Leach.cc | 7 +++---- src/inet/routing/leach/Leach.h | 1 - src/inet/routing/leach/Leach.ned | 1 - 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/examples/manetrouting/leach/omnetpp.ini b/examples/manetrouting/leach/omnetpp.ini index 82b192253bf..dae2f2d000e 100644 --- a/examples/manetrouting/leach/omnetpp.ini +++ b/examples/manetrouting/leach/omnetpp.ini @@ -19,7 +19,6 @@ seed-1-mt = 7 # used for threshold comparison (can set any preferred value) *.baseStation.typename = "LeachBS" *.host*.typename = "LeachNode" *.host*.LEACHnode.clusterHeadPercentage = 0.05 -*.host*.LEACHnode.numNodes = 100 # set number of nodes to be injected into LEACH module *.numNodes = 100 #100 *.host*.mobility.typename = "StationaryMobility" diff --git a/src/inet/routing/leach/Leach.cc b/src/inet/routing/leach/Leach.cc index 8df84610e41..1b6c97d568d 100644 --- a/src/inet/routing/leach/Leach.cc +++ b/src/inet/routing/leach/Leach.cc @@ -40,7 +40,6 @@ void Leach::initialize(int stage) { interfaceTable.reference(this, "interfaceTableModule", true); clusterHeadPercentage = par("clusterHeadPercentage"); - numNodes = par("numNodes"); roundDurationVariance = par("roundDurationVariance"); roundDuration = dblrand(0) * roundDurationVariance; @@ -48,9 +47,9 @@ void Leach::initialize(int stage) { event = new cMessage("event"); wasCH = false; - vector nodeMemory(numNodes); // Localized NCH node memory with CH data - vector nodeCHMemory(numNodes); // Localized CH memory - vector extractedTDMASchedule(numNodes); // Localized NCH node memory with extracted TDMA data + vector nodeMemory; // Localized NCH node memory with CH data + vector nodeCHMemory; // Localized CH memory + vector extractedTDMASchedule; // Localized NCH node memory with extracted TDMA data } else if (stage == INITSTAGE_ROUTING_PROTOCOLS) { registerService(Protocol::manet, nullptr, gate("ipIn")); diff --git a/src/inet/routing/leach/Leach.h b/src/inet/routing/leach/Leach.h index 7c3eb942ad4..d5cd024b9a9 100644 --- a/src/inet/routing/leach/Leach.h +++ b/src/inet/routing/leach/Leach.h @@ -45,7 +45,6 @@ class INET_API Leach: public RoutingProtocolBase { simtime_t CHPktSendDelay; simtime_t roundDuration; - int numNodes = 0; double clusterHeadPercentage = 0.0; int roundDurationVariance = 0; diff --git a/src/inet/routing/leach/Leach.ned b/src/inet/routing/leach/Leach.ned index 703573bbac7..5ff4f4e5955 100644 --- a/src/inet/routing/leach/Leach.ned +++ b/src/inet/routing/leach/Leach.ned @@ -30,7 +30,6 @@ simple Leach like IManetRouting // LEACH parameter group volatile double startupDelay @unit(s) = default(uniform(0s, 1s)); - int numNodes = default(10); double clusterHeadPercentage = default(0.5); int roundDurationVariance = default(10); gates: From f04b5be512cb34a55b92b7eacf6856c6e85ddc0d Mon Sep 17 00:00:00 2001 From: n-jay Date: Wed, 21 Feb 2024 18:34:34 +0530 Subject: [PATCH 27/43] Update cluster head percentage parameter Rename to cluster head ratio --- src/inet/routing/leach/Leach.cc | 10 +++++----- src/inet/routing/leach/Leach.h | 2 +- src/inet/routing/leach/Leach.ned | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/inet/routing/leach/Leach.cc b/src/inet/routing/leach/Leach.cc index 1b6c97d568d..33c07c7083b 100644 --- a/src/inet/routing/leach/Leach.cc +++ b/src/inet/routing/leach/Leach.cc @@ -39,7 +39,7 @@ void Leach::initialize(int stage) { host = getContainingNode(this); interfaceTable.reference(this, "interfaceTableModule", true); - clusterHeadPercentage = par("clusterHeadPercentage"); + clusterHeadRatio = par("clusterHeadRatio"); roundDurationVariance = par("roundDurationVariance"); roundDuration = dblrand(0) * roundDurationVariance; @@ -99,7 +99,7 @@ void Leach::handleMessageWhenUp(cMessage *msg) { } round += 1; - int intervalLength = 1.0 / clusterHeadPercentage; + int intervalLength = 1.0 / clusterHeadRatio; if (fmod(round, intervalLength) == 0) { // reset values at end of number of subintervals wasCH = false; nodeMemory.clear(); @@ -246,9 +246,9 @@ void Leach::handleCrashOperation(LifecycleOperation *operation) { // Threshold value for CH selection double Leach::Leach::generateThresholdValue(int round) { - int intervalLength = 1.0 / clusterHeadPercentage; - double threshold = (clusterHeadPercentage - / (1 - clusterHeadPercentage * (fmod(round, intervalLength)))); + int intervalLength = 1.0 / clusterHeadRatio; + double threshold = (clusterHeadRatio + / (1 - clusterHeadRatio * (fmod(round, intervalLength)))); return threshold; } diff --git a/src/inet/routing/leach/Leach.h b/src/inet/routing/leach/Leach.h index d5cd024b9a9..f6c5955fe14 100644 --- a/src/inet/routing/leach/Leach.h +++ b/src/inet/routing/leach/Leach.h @@ -45,7 +45,7 @@ class INET_API Leach: public RoutingProtocolBase { simtime_t CHPktSendDelay; simtime_t roundDuration; - double clusterHeadPercentage = 0.0; + double clusterHeadRatio = 0.0; int roundDurationVariance = 0; // object for storing CH data per node in vector array diff --git a/src/inet/routing/leach/Leach.ned b/src/inet/routing/leach/Leach.ned index 5ff4f4e5955..d29f1f0a4b3 100644 --- a/src/inet/routing/leach/Leach.ned +++ b/src/inet/routing/leach/Leach.ned @@ -24,13 +24,13 @@ simple Leach like IManetRouting // properties @class("leach::Leach"); @display("i=block/routing"); - + // context parameters - string interfaceTableModule; - + string interfaceTableModule; + // LEACH parameter group volatile double startupDelay @unit(s) = default(uniform(0s, 1s)); - double clusterHeadPercentage = default(0.5); + double clusterHeadRatio @unit(pct) = default(5pct); // Determines ratio of cluster heads in network, which is used for threshold function int roundDurationVariance = default(10); gates: input ipIn; From 510b0ca63781cba02ee1891ae0f704fbb4f7569a Mon Sep 17 00:00:00 2001 From: n-jay Date: Wed, 21 Feb 2024 23:20:42 +0530 Subject: [PATCH 28/43] Update clusterHeadRatio unit in Leach.ned --- src/inet/routing/leach/Leach.ned | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inet/routing/leach/Leach.ned b/src/inet/routing/leach/Leach.ned index d29f1f0a4b3..48aa9560897 100644 --- a/src/inet/routing/leach/Leach.ned +++ b/src/inet/routing/leach/Leach.ned @@ -30,7 +30,7 @@ simple Leach like IManetRouting // LEACH parameter group volatile double startupDelay @unit(s) = default(uniform(0s, 1s)); - double clusterHeadRatio @unit(pct) = default(5pct); // Determines ratio of cluster heads in network, which is used for threshold function + double clusterHeadRatio @unit(ratio) = default(0.05ratio); // Determines ratio of cluster heads in network, which is used for threshold function int roundDurationVariance = default(10); gates: input ipIn; From 5f04eacf34b06fd78406761b5bc9022914661f80 Mon Sep 17 00:00:00 2001 From: n-jay Date: Wed, 21 Feb 2024 23:21:47 +0530 Subject: [PATCH 29/43] Remove clusterHeadPercentage setting from example ini --- examples/manetrouting/leach/omnetpp.ini | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/manetrouting/leach/omnetpp.ini b/examples/manetrouting/leach/omnetpp.ini index dae2f2d000e..a7f757d0665 100644 --- a/examples/manetrouting/leach/omnetpp.ini +++ b/examples/manetrouting/leach/omnetpp.ini @@ -18,7 +18,6 @@ seed-1-mt = 7 # used for threshold comparison (can set any preferred value) *.baseStation.typename = "LeachBS" *.host*.typename = "LeachNode" -*.host*.LEACHnode.clusterHeadPercentage = 0.05 *.numNodes = 100 #100 *.host*.mobility.typename = "StationaryMobility" From 99e709fb3622e074fdd916bcf8d4d274cf9f0f7f Mon Sep 17 00:00:00 2001 From: n-jay Date: Wed, 21 Feb 2024 23:38:37 +0530 Subject: [PATCH 30/43] Refactor Leach.cc vectors --- src/inet/routing/leach/Leach.cc | 4 ---- src/inet/routing/leach/Leach.h | 6 +++--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/inet/routing/leach/Leach.cc b/src/inet/routing/leach/Leach.cc index 33c07c7083b..23282842b9b 100644 --- a/src/inet/routing/leach/Leach.cc +++ b/src/inet/routing/leach/Leach.cc @@ -47,10 +47,6 @@ void Leach::initialize(int stage) { event = new cMessage("event"); wasCH = false; - vector nodeMemory; // Localized NCH node memory with CH data - vector nodeCHMemory; // Localized CH memory - vector extractedTDMASchedule; // Localized NCH node memory with extracted TDMA data - } else if (stage == INITSTAGE_ROUTING_PROTOCOLS) { registerService(Protocol::manet, nullptr, gate("ipIn")); registerProtocol(Protocol::manet, gate("ipOut"), nullptr); diff --git a/src/inet/routing/leach/Leach.h b/src/inet/routing/leach/Leach.h index f6c5955fe14..bb60b5f2d19 100644 --- a/src/inet/routing/leach/Leach.h +++ b/src/inet/routing/leach/Leach.h @@ -60,9 +60,9 @@ class INET_API Leach: public RoutingProtocolBase { double TDMAdelay; }; - vector nodeMemory; // NCH nodes store data about CH broadcasts - vector nodeCHMemory; // CH store data about CH acknowledgements - vector extractedTDMASchedule; + vector nodeMemory; // Localized Non CH node memory with CH data + vector nodeCHMemory; // Localized CH memory to store NCH acknowledgements + vector extractedTDMASchedule; // Localized NCH node memory for extracted TDMA slot data bool wasCH; public: From ad80f49543c129b25da92bfee6b18b9a49c2a0d7 Mon Sep 17 00:00:00 2001 From: n-jay Date: Thu, 22 Feb 2024 11:18:08 +0530 Subject: [PATCH 31/43] Add support for configuring wireless interfaces --- src/inet/routing/leach/Leach.cc | 8 +++++--- src/inet/routing/leach/Leach.h | 1 + src/inet/routing/leach/Leach.ned | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/inet/routing/leach/Leach.cc b/src/inet/routing/leach/Leach.cc index 23282842b9b..d7ce258b8fc 100644 --- a/src/inet/routing/leach/Leach.cc +++ b/src/inet/routing/leach/Leach.cc @@ -41,6 +41,7 @@ void Leach::initialize(int stage) { clusterHeadRatio = par("clusterHeadRatio"); roundDurationVariance = par("roundDurationVariance"); + interfaces = par("interfaces"); roundDuration = dblrand(0) * roundDurationVariance; TDMADelayCounter = 1; @@ -71,13 +72,14 @@ void Leach::stop() { } void Leach::configureInterfaces() { + cPatternMatcher interfaceMatcher(interfaces, false, true, false); int numInterfaces = interfaceTable->getNumInterfaces(); for (int i = 0; i < numInterfaces; i++) { NetworkInterface *networkInterface = interfaceTable->getInterface(i); - // Only single wireless interface is required - if (networkInterface->isWireless()) { + if (networkInterface->isMulticast() + && interfaceMatcher.matches( + networkInterface->getInterfaceName())) { wirelessInterface = networkInterface; - break; } } } diff --git a/src/inet/routing/leach/Leach.h b/src/inet/routing/leach/Leach.h index bb60b5f2d19..41dff367a2b 100644 --- a/src/inet/routing/leach/Leach.h +++ b/src/inet/routing/leach/Leach.h @@ -39,6 +39,7 @@ class INET_API Leach: public RoutingProtocolBase { cMessage *event = nullptr; int round = 0; ModuleRefByPar interfaceTable; + const char *interfaces = nullptr; protected: simtime_t dataPktSendDelay; diff --git a/src/inet/routing/leach/Leach.ned b/src/inet/routing/leach/Leach.ned index 48aa9560897..cddf3828c01 100644 --- a/src/inet/routing/leach/Leach.ned +++ b/src/inet/routing/leach/Leach.ned @@ -29,6 +29,7 @@ simple Leach like IManetRouting string interfaceTableModule; // LEACH parameter group + string interfaces = default("*"); // Only single wireless interface is required volatile double startupDelay @unit(s) = default(uniform(0s, 1s)); double clusterHeadRatio @unit(ratio) = default(0.05ratio); // Determines ratio of cluster heads in network, which is used for threshold function int roundDurationVariance = default(10); From 2a7da9283b9ece61cc0a94d03fb3902cc4ec35d0 Mon Sep 17 00:00:00 2001 From: n-jay Date: Thu, 22 Feb 2024 11:48:25 +0530 Subject: [PATCH 32/43] Remove self-message kind --- src/inet/routing/leach/Leach.cc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/inet/routing/leach/Leach.cc b/src/inet/routing/leach/Leach.cc index d7ce258b8fc..a7e8be0dbc1 100644 --- a/src/inet/routing/leach/Leach.cc +++ b/src/inet/routing/leach/Leach.cc @@ -59,7 +59,6 @@ void Leach::start() { configureInterfaces(); // schedules a random periodic event - event->setKind(SELF); scheduleAt(simTime() + uniform(0.0, par("startupDelay").doubleValue()), event); } @@ -107,7 +106,6 @@ void Leach::handleMessageWhenUp(cMessage *msg) { } // schedule another self message every time new one is received by node - event->setKind(SELF); scheduleAt(simTime() + roundDuration, event); // if node is receiving message } else if (check_and_cast(msg)->getTag()->getProtocol() @@ -125,7 +123,6 @@ void Leach::handleMessageWhenDown(cMessage *msg) { void Leach::handleSelfMessage(cMessage *msg) { if (msg == event) { - if (event->getKind() == SELF) { auto ctrlPkt = makeShared(); // Filling the LeachControlPkt fields @@ -149,7 +146,6 @@ void Leach::handleSelfMessage(cMessage *msg) { send(packet, "ipOut"); packet = nullptr; ctrlPkt = nullptr; - } } else { delete msg; } From 8dcc7d590e6952bca4f714c7611c13a4928a3161 Mon Sep 17 00:00:00 2001 From: n-jay Date: Thu, 22 Feb 2024 12:52:51 +0530 Subject: [PATCH 33/43] Add support for configuring wireless interfaces In Base Station module --- src/inet/routing/leach/LeachBS.cc | 13 +++++++------ src/inet/routing/leach/LeachBS.h | 5 ++--- src/inet/routing/leach/LeachBS.ned | 7 +++++-- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/inet/routing/leach/LeachBS.cc b/src/inet/routing/leach/LeachBS.cc index 1a206de493f..825a6749d6d 100644 --- a/src/inet/routing/leach/LeachBS.cc +++ b/src/inet/routing/leach/LeachBS.cc @@ -31,9 +31,9 @@ void LeachBS::initialize(int stage) { //reads from omnetpp.ini if (stage == INITSTAGE_LOCAL) { - sequencenumber = 0; host = getContainingNode(this); interfaceTable.reference(this, "interfaceTableModule", true); + interfaces = par("interfaces"); bsPktReceived = 0; @@ -54,20 +54,21 @@ void LeachBS::stop() { } void LeachBS::configureInterfaces() { + cPatternMatcher interfaceMatcher(interfaces, false, true, false); int numInterfaces = interfaceTable->getNumInterfaces(); for (int i = 0; i < numInterfaces; i++) { NetworkInterface *networkInterface = interfaceTable->getInterface(i); - // Only single wireless interface is required - if (networkInterface->isWireless()) { - interface80211ptr = networkInterface; - break; + if (networkInterface->isMulticast() + && interfaceMatcher.matches( + networkInterface->getInterfaceName())) { + wirelessInterface = networkInterface; } } } void LeachBS::handleMessageWhenUp(cMessage *msg) { Ipv4Address nodeAddr = - (interface80211ptr->getProtocolData()->getIPAddress()); + (wirelessInterface->getProtocolData()->getIPAddress()); // if node is sending message if (msg->isSelfMessage()) { delete msg; diff --git a/src/inet/routing/leach/LeachBS.h b/src/inet/routing/leach/LeachBS.h index a2ffb1c0346..f6e6680aac3 100644 --- a/src/inet/routing/leach/LeachBS.h +++ b/src/inet/routing/leach/LeachBS.h @@ -30,11 +30,10 @@ class INET_API LeachBS: public RoutingProtocolBase { virtual ~LeachBS(); int interfaceId = -1; - NetworkInterface *interface80211ptr = nullptr; - IInterfaceTable *ift = nullptr; - unsigned int sequencenumber = 0; + NetworkInterface *wirelessInterface = nullptr; cModule *host = nullptr; ModuleRefByPar interfaceTable; + const char *interfaces = nullptr; protected: virtual int numInitStages() const override { diff --git a/src/inet/routing/leach/LeachBS.ned b/src/inet/routing/leach/LeachBS.ned index aea8d883479..c96c2629b9d 100644 --- a/src/inet/routing/leach/LeachBS.ned +++ b/src/inet/routing/leach/LeachBS.ned @@ -22,9 +22,12 @@ simple LeachBS like IManetRouting // properties @class("leach::LeachBS"); @display("i=block/routing"); - + // context parameters - string interfaceTableModule; + string interfaceTableModule; + + // Leach base station parameter group + string interfaces = default("*"); // Only single wireless interface is required gates: input ipIn; output ipOut; From 6008a9a3634e3c9dc9ba18ac357da8dc9adec5ec Mon Sep 17 00:00:00 2001 From: n-jay Date: Thu, 7 Mar 2024 13:09:08 +0530 Subject: [PATCH 34/43] Implement UDP packet transfers For control packet broadcast from CH to NCH. --- src/inet/routing/leach/Leach.cc | 116 ++++++++++++++++------------- src/inet/routing/leach/Leach.h | 5 ++ src/inet/routing/leach/LeachDefs.h | 18 +++++ 3 files changed, 89 insertions(+), 50 deletions(-) create mode 100644 src/inet/routing/leach/LeachDefs.h diff --git a/src/inet/routing/leach/Leach.cc b/src/inet/routing/leach/Leach.cc index a7e8be0dbc1..74cf09d5545 100644 --- a/src/inet/routing/leach/Leach.cc +++ b/src/inet/routing/leach/Leach.cc @@ -14,6 +14,7 @@ #include "inet/common/lifecycle/NodeStatus.h" #include "inet/common/lifecycle/LifecycleController.h" #include "inet/routing/leach/Leach.h" +#include "inet/transportlayer/contract/udp/UdpControlInfo.h" namespace inet { namespace leach { @@ -107,12 +108,9 @@ void Leach::handleMessageWhenUp(cMessage *msg) { // schedule another self message every time new one is received by node scheduleAt(simTime() + roundDuration, event); + } else { // if node is receiving message - } else if (check_and_cast(msg)->getTag()->getProtocol() - == &Protocol::manet) { processMessage(msg); - } else { - throw cRuntimeError("Message not supported %s", msg->getName()); } } @@ -123,29 +121,7 @@ void Leach::handleMessageWhenDown(cMessage *msg) { void Leach::handleSelfMessage(cMessage *msg) { if (msg == event) { - auto ctrlPkt = makeShared(); - - // Filling the LeachControlPkt fields - ctrlPkt->setPacketType(CH); - Ipv4Address source = (wirelessInterface->getProtocolData< - Ipv4InterfaceData>()->getIPAddress()); - ctrlPkt->setChunkLength(b(128)); ///size of Hello message in bits - ctrlPkt->setSrcAddress(source); - - //new control info for LeachControlPkt - auto packet = new Packet("LEACHControlPkt", ctrlPkt); - auto addressReq = packet->addTag(); - addressReq->setDestAddress(Ipv4Address(255, 255, 255, 255)); - addressReq->setSrcAddress(source); //let's try the limited broadcast - packet->addTag()->setInterfaceId( - wirelessInterface->getInterfaceId()); - packet->addTag()->setProtocol(&Protocol::manet); - packet->addTag()->setProtocol(&Protocol::ipv4); - - //broadcast to other nodes the hello message - send(packet, "ipOut"); - packet = nullptr; - ctrlPkt = nullptr; + broadcastCtrlToNCH(); } else { delete msg; } @@ -154,18 +130,18 @@ void Leach::handleSelfMessage(cMessage *msg) { void Leach::processMessage(cMessage *msg) { Ipv4Address selfAddr = (wirelessInterface->getProtocolData()->getIPAddress()); - auto receivedCtrlPkt = - staticPtrCast( - check_and_cast(msg)->peekData()->dupShared()); + auto receivedCtrlPkt = dynamic_cast(msg); + receivedCtrlPkt->popAtFront(); + Packet *receivedPkt = check_and_cast(msg); - auto &leachControlPkt = receivedPkt->popAtFront(); + auto &leachControlPkt = receivedCtrlPkt->peekAtFront(); auto packetType = leachControlPkt->getPacketType(); // filter packet based on type and run specific functions if (msg->arrivedOn("ipIn")) { // first broadcast from CH to NCH nodes if (packetType == CH) { - Ipv4Address CHAddr = receivedCtrlPkt->getSrcAddress(); + Ipv4Address CHAddr = leachControlPkt->getSrcAddress(); auto signalPowerInd = receivedPkt->getTag(); double rxPower = signalPowerInd->getPower().get(); @@ -175,7 +151,7 @@ void Leach::processMessage(cMessage *msg) { // ACK packet from NCH node to CH } else if (packetType == ACK && leachState == ch) { - Ipv4Address nodeAddr = receivedCtrlPkt->getSrcAddress(); + Ipv4Address nodeAddr = leachControlPkt->getSrcAddress(); addToNodeCHMemory(nodeAddr); if (nodeCHMemory.size() > 2) { @@ -184,12 +160,12 @@ void Leach::processMessage(cMessage *msg) { // TDMA schedule from CH to NCH } else if (packetType == SCH) { - Ipv4Address CHAddr = receivedCtrlPkt->getSrcAddress(); + Ipv4Address CHAddr = leachControlPkt->getSrcAddress(); - int scheduleArraySize = receivedCtrlPkt->getScheduleArraySize(); + int scheduleArraySize = leachControlPkt->getScheduleArraySize(); // Traverses through schedule array in packets and sets values into a vector in local node memory for (int counter = 0; counter < scheduleArraySize; counter++) { - ScheduleEntry tempScheduleEntry = receivedCtrlPkt->getSchedule( + ScheduleEntry tempScheduleEntry = leachControlPkt->getSchedule( counter); TDMAScheduleEntry extractedTDMAScheduleEntry; extractedTDMAScheduleEntry.nodeAddress = @@ -213,7 +189,7 @@ void Leach::processMessage(cMessage *msg) { } // Data packet from NCH to CH } else if (packetType == DATA) { - Ipv4Address NCHAddr = receivedCtrlPkt->getSrcAddress(); + Ipv4Address NCHAddr = leachControlPkt->getSrcAddress(); sendDataToBS(selfAddr); @@ -303,6 +279,34 @@ void Leach::setLeachState(LeachState ls) { leachState = ls; } +void Leach::broadcastCtrlToNCH() { + Packet *udpPacket = new Packet("LeachCtrlPkt"); + + auto udpHeader = makeShared(); + udpHeader->setSourcePort(LEACH_UDP_PORT); + udpHeader->setDestinationPort(LEACH_UDP_PORT); + udpHeader->setCrcMode(CRC_DISABLED); + udpPacket->insertAtFront(udpHeader); + + auto ctrlPayload = makeShared(); + ctrlPayload->setPacketType(CH); + ctrlPayload->setChunkLength(b(128)); + Ipv4Address source = + (wirelessInterface->getProtocolData()->getIPAddress()); + ctrlPayload->setSrcAddress(source); + udpPacket->insertAtBack(ctrlPayload); + + auto addressReq = udpPacket->addTag(); + addressReq->setDestAddress(Ipv4Address(255, 255, 255, 255)); + addressReq->setSrcAddress(source); + udpPacket->addTag()->setInterfaceId( + wirelessInterface->getInterfaceId()); + udpPacket->addTag()->setProtocol(&Protocol::manet); + udpPacket->addTag()->setProtocol(&Protocol::ipv4); + + send(udpPacket, "ipOut"); +} + // Send broadcast acknowledgement to CH from non CH nodes void Leach::sendAckToCH(Ipv4Address nodeAddr, Ipv4Address CHAddr) { auto ackPkt = makeShared(); @@ -353,27 +357,35 @@ void Leach::sendSchToNCH(Ipv4Address selfAddr) { // Sends data to CH node void Leach::sendDataToCH(Ipv4Address nodeAddr, Ipv4Address CHAddr, double TDMAslot) { - auto dataPkt = makeShared(); - dataPkt->setPacketType(DATA); + Packet *udpPacket = new Packet("LeachDataPkt"); + + auto udpHeader = makeShared(); + udpHeader->setSourcePort(LEACH_UDP_PORT); + udpHeader->setDestinationPort(LEACH_UDP_PORT); + udpHeader->setCrcMode(CRC_DISABLED); + udpPacket->insertAtFront(udpHeader); + + auto leachData = makeShared(); + leachData->setPacketType(DATA); + + leachData->setChunkLength(b(128)); double temperature = (double) rand() / RAND_MAX; double humidity = (double) rand() / RAND_MAX; + leachData->setTemperature(temperature); + leachData->setHumidity(humidity); + leachData->setSrcAddress(nodeAddr); + udpPacket->insertAtBack(leachData); - dataPkt->setChunkLength(b(128)); - dataPkt->setTemperature(temperature); - dataPkt->setHumidity(humidity); - dataPkt->setSrcAddress(nodeAddr); - - auto dataPacket = new Packet("LEACHDataPkt", dataPkt); - auto addressReq = dataPacket->addTag(); + auto addressReq = udpPacket->addTag(); addressReq->setDestAddress(getIdealCH(nodeAddr, CHAddr)); addressReq->setSrcAddress(nodeAddr); - dataPacket->addTag()->setInterfaceId( + udpPacket->addTag()->setInterfaceId( wirelessInterface->getInterfaceId()); - dataPacket->addTag()->setProtocol(&Protocol::manet); - dataPacket->addTag()->setProtocol(&Protocol::ipv4); + udpPacket->addTag()->setProtocol(&Protocol::manet); + udpPacket->addTag()->setProtocol(&Protocol::ipv4); - sendDelayed(dataPacket, TDMAslot, "ipOut"); + sendDelayed(udpPacket, TDMAslot, "ipOut"); } // CH sends data to BS @@ -398,6 +410,10 @@ void Leach::sendDataToBS(Ipv4Address CHAddr) { setLeachState(nch); // Set state for GUI visualization } +void Leach::sendUdpPacket(Packet *packet) { + send(packet, "ipOut"); +} + // Selects the ideal CH based on RSSI signal Ipv4Address Leach::getIdealCH(Ipv4Address nodeAddr, Ipv4Address CHAddr) { Ipv4Address tempIdealCHAddr = CHAddr; diff --git a/src/inet/routing/leach/Leach.h b/src/inet/routing/leach/Leach.h index 41dff367a2b..9f42594bf6d 100644 --- a/src/inet/routing/leach/Leach.h +++ b/src/inet/routing/leach/Leach.h @@ -9,6 +9,7 @@ #include #include "inet/common/INETDefs.h" +#include "inet/routing/leach/LeachDefs.h" #include "inet/common/packet/Packet.h" #include "inet/networklayer/contract/IInterfaceTable.h" #include "inet/networklayer/contract/ipv4/Ipv4Address.h" @@ -23,6 +24,7 @@ #include "inet/mobility/base/StationaryMobilityBase.h" #include "inet/power/contract/ICcEnergyStorage.h" #include "inet/common/lifecycle/LifecycleController.h" +#include "inet/transportlayer/udp/UdpHeader_m.h" using namespace std; @@ -103,12 +105,15 @@ class INET_API Leach: public RoutingProtocolBase { double generateThresholdValue(int subInterval); + void broadcastCtrlToNCH(); void sendDataToCH(Ipv4Address nodeAddr, Ipv4Address CHAddr, double TDMAslot); void sendDataToBS(Ipv4Address CHAddr); void sendAckToCH(Ipv4Address nodeAddr, Ipv4Address CHAddr); void sendSchToNCH(Ipv4Address selfAddr); + void sendUdpPacket(Packet *packet); + void addToNodeMemory(Ipv4Address nodeAddr, Ipv4Address CHAddr, double energy); void addToNodeCHMemory(Ipv4Address NCHAddr); diff --git a/src/inet/routing/leach/LeachDefs.h b/src/inet/routing/leach/LeachDefs.h new file mode 100644 index 00000000000..8cb96b0d740 --- /dev/null +++ b/src/inet/routing/leach/LeachDefs.h @@ -0,0 +1,18 @@ +// +// SPDX-License-Identifier: LGPL-3.0-or-later +// + +#ifndef INET_ROUTING_LEACH_LEACHDEFS_H_ +#define INET_ROUTING_LEACH_LEACHDEFS_H_ + +#include "inet/common/INETDefs.h" + +#define LEACH_UDP_PORT 269 + +namespace inet { + +} // namespace inet + + + +#endif /* INET_ROUTING_LEACH_LEACHDEFS_H_ */ From f4a4040557663d453a91fb43b81282c27cef8166 Mon Sep 17 00:00:00 2001 From: n-jay Date: Thu, 9 May 2024 23:03:49 +0530 Subject: [PATCH 35/43] Update radio receiver sensitivity and energy detection values The radio receiver sensitivity and energy detection values were updated to -110dBm for both the host and base station modules. --- tests/module/LeachSimpleTest.test | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/module/LeachSimpleTest.test b/tests/module/LeachSimpleTest.test index a70de7d0f00..3a908c29cbf 100644 --- a/tests/module/LeachSimpleTest.test +++ b/tests/module/LeachSimpleTest.test @@ -81,8 +81,8 @@ seed-1-mt = 7 # used for threshold comparison *.host*.wlan[0].radio.transmitter.power = 60.5mW # determines communication range - based on CC2520 *.host*.wlan[0].radio.transmitter.preambleDuration = 192us # based on TI CC2520 *.host*.wlan[0].radio.transmitter.headerLength = 6B # based on TI CC2520 -*.host*.wlan[0].radio.receiver.sensitivity = -98dBm # based on TI CC2520 -*.host*.wlan[0].radio.receiver.energyDetection = -85dBm +*.host*.wlan[0].radio.receiver.sensitivity = -110dBm +*.host*.wlan[0].radio.receiver.energyDetection = -110dBm *.host*.wlan[0].radio.receiver.snirThreshold = 4dB *.host*.wlan[0].radio.displayCommunicationRange = true @@ -94,8 +94,8 @@ seed-1-mt = 7 # used for threshold comparison *.baseStation.wlan[0].radio.transmitter.power = 60.5mW *.baseStation.wlan[0].radio.transmitter.preambleDuration = 192us *.baseStation.wlan[0].radio.transmitter.headerLength = 6B -*.baseStation.wlan[0].radio.receiver.sensitivity = -98dBm -*.baseStation.wlan[0].radio.receiver.energyDetection = -85dBm +*.baseStation.wlan[0].radio.receiver.sensitivity = -110dBm +*.baseStation.wlan[0].radio.receiver.energyDetection = -110dBm *.baseStation.wlan[0].radio.receiver.snirThreshold = 4dB *.baseStation.wlan[0].radio.displayCommunicationRange = true From 946b4561ff72a2f8ac859f9d782d96a044ded3d6 Mon Sep 17 00:00:00 2001 From: n-jay Date: Wed, 3 Jul 2024 18:40:21 +0530 Subject: [PATCH 36/43] Join multicast group for wireless interface --- src/inet/routing/leach/Leach.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/inet/routing/leach/Leach.cc b/src/inet/routing/leach/Leach.cc index 74cf09d5545..cfcb0c12b93 100644 --- a/src/inet/routing/leach/Leach.cc +++ b/src/inet/routing/leach/Leach.cc @@ -79,7 +79,8 @@ void Leach::configureInterfaces() { if (networkInterface->isMulticast() && interfaceMatcher.matches( networkInterface->getInterfaceName())) { - wirelessInterface = networkInterface; + wirelessInterface->joinMulticastGroup( + addressType->getLinkLocalManetRoutersMulticastAddress()) } } } From 162a92b215562d49d140714e8c58fd2d0664939c Mon Sep 17 00:00:00 2001 From: n-jay Date: Thu, 4 Jul 2024 12:58:34 +0530 Subject: [PATCH 37/43] Refactor protocol registration code Register wireless interface for multicast group --- src/inet/routing/leach/Leach.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/inet/routing/leach/Leach.cc b/src/inet/routing/leach/Leach.cc index cfcb0c12b93..2d0f14abf80 100644 --- a/src/inet/routing/leach/Leach.cc +++ b/src/inet/routing/leach/Leach.cc @@ -50,8 +50,7 @@ void Leach::initialize(int stage) { wasCH = false; } else if (stage == INITSTAGE_ROUTING_PROTOCOLS) { - registerService(Protocol::manet, nullptr, gate("ipIn")); - registerProtocol(Protocol::manet, gate("ipOut"), nullptr); + registerProtocol(Protocol::manet, gate("ipOut"), gate("ipIn")); } } @@ -79,8 +78,7 @@ void Leach::configureInterfaces() { if (networkInterface->isMulticast() && interfaceMatcher.matches( networkInterface->getInterfaceName())) { - wirelessInterface->joinMulticastGroup( - addressType->getLinkLocalManetRoutersMulticastAddress()) + wirelessInterface = networkInterface; } } } From 0770d2df52e3d17c5f45e02136e63d543fc3d768 Mon Sep 17 00:00:00 2001 From: n-jay Date: Sat, 6 Jul 2024 20:01:08 +0530 Subject: [PATCH 38/43] Add IsotropicScalarBackgroundNoise Added to radioMedium in omnetpp.ini --- examples/manetrouting/leach/omnetpp.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/manetrouting/leach/omnetpp.ini b/examples/manetrouting/leach/omnetpp.ini index a7f757d0665..c981a815934 100644 --- a/examples/manetrouting/leach/omnetpp.ini +++ b/examples/manetrouting/leach/omnetpp.ini @@ -8,6 +8,7 @@ seed-1-mt = 7 # used for threshold comparison (can set any preferred value) **.arp.typename = "GlobalArp" *.radioMedium.typename = "Ieee802154NarrowbandScalarRadioMedium" +*.radioMedium.backgroundNoise.typename = "IsotropicScalarBackgroundNoise" *.radioMedium.backgroundNoise.power = -100dBm *.radioMedium.mediumLimitCache.centerFrequency = 2GHz From 0c30c548e6397656989d4ddf0ada6011bc7f86fa Mon Sep 17 00:00:00 2001 From: n-jay Date: Mon, 8 Jul 2024 11:25:32 +0530 Subject: [PATCH 39/43] Implement UDP packet transfers for sending acknowledgement to CH The code changes add the necessary code to create a UDP packet and LeachAckPkt to send an acknowledgement to the CH (Cluster Head) from non-CH nodes. --- src/inet/routing/leach/Leach.cc | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/inet/routing/leach/Leach.cc b/src/inet/routing/leach/Leach.cc index 2d0f14abf80..e9a5d6b3087 100644 --- a/src/inet/routing/leach/Leach.cc +++ b/src/inet/routing/leach/Leach.cc @@ -308,22 +308,29 @@ void Leach::broadcastCtrlToNCH() { // Send broadcast acknowledgement to CH from non CH nodes void Leach::sendAckToCH(Ipv4Address nodeAddr, Ipv4Address CHAddr) { + Packet *udpPacket = new Packet("LeachAckPkt"); + + auto udpHeader = makeShared(); + udpHeader->setSourcePort(LEACH_UDP_PORT); + udpHeader->setDestinationPort(LEACH_UDP_PORT); + udpHeader->setCrcMode(CRC_DISABLED); + udpPacket->insertAtFront(udpHeader); + auto ackPkt = makeShared(); ackPkt->setPacketType(ACK); ackPkt->setChunkLength(b(128)); ///size of Hello message in bits ackPkt->setSrcAddress(nodeAddr); + udpPacket->insertAtBack(ackPkt); - auto ackPacket = new Packet("LeachAckPkt", ackPkt); - auto addressReq = ackPacket->addTag(); - + auto addressReq = udpPacket->addTag(); addressReq->setDestAddress(getIdealCH(nodeAddr, CHAddr)); addressReq->setSrcAddress(nodeAddr); - ackPacket->addTag()->setInterfaceId( + udpPacket->addTag()->setInterfaceId( wirelessInterface->getInterfaceId()); - ackPacket->addTag()->setProtocol(&Protocol::manet); - ackPacket->addTag()->setProtocol(&Protocol::ipv4); + udpPacket->addTag()->setProtocol(&Protocol::manet); + udpPacket->addTag()->setProtocol(&Protocol::ipv4); - send(ackPacket, "ipOut"); + send(udpPacket, "ipOut"); } // Sends TDMA schedule to non CH nodes From e840295234082c3fdea7c8729977f2500e6a701c Mon Sep 17 00:00:00 2001 From: n-jay Date: Mon, 8 Jul 2024 11:31:21 +0530 Subject: [PATCH 40/43] Implement UDP packet transfers for sending TDMA schedule to NCH --- src/inet/routing/leach/Leach.cc | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/inet/routing/leach/Leach.cc b/src/inet/routing/leach/Leach.cc index e9a5d6b3087..db61add2cd1 100644 --- a/src/inet/routing/leach/Leach.cc +++ b/src/inet/routing/leach/Leach.cc @@ -335,29 +335,35 @@ void Leach::sendAckToCH(Ipv4Address nodeAddr, Ipv4Address CHAddr) { // Sends TDMA schedule to non CH nodes void Leach::sendSchToNCH(Ipv4Address selfAddr) { + Packet *udpPacket = new Packet("LeachSchedulePkt"); + + auto udpHeader = makeShared(); + udpHeader->setSourcePort(LEACH_UDP_PORT); + udpHeader->setDestinationPort(LEACH_UDP_PORT); + udpHeader->setCrcMode(CRC_DISABLED); + udpPacket->insertAtFront(udpHeader); + auto schedulePkt = makeShared(); schedulePkt->setPacketType(SCH); schedulePkt->setChunkLength(b(128)); ///size of Hello message in bits schedulePkt->setSrcAddress(selfAddr); - for (auto &it : nodeCHMemory) { ScheduleEntry scheduleEntry; scheduleEntry.setNodeAddress(it.nodeAddress); scheduleEntry.setTDMAdelay(it.TDMAdelay); schedulePkt->insertSchedule(scheduleEntry); } + udpPacket->insertAtBack(schedulePkt); - auto schedulePacket = new Packet("LeachSchedulePkt", schedulePkt); auto scheduleReq = schedulePacket->addTag(); - scheduleReq->setDestAddress(Ipv4Address(255, 255, 255, 255)); scheduleReq->setSrcAddress(selfAddr); - schedulePacket->addTag()->setInterfaceId( + udpPacket->addTag()->setInterfaceId( wirelessInterface->getInterfaceId()); - schedulePacket->addTag()->setProtocol(&Protocol::manet); - schedulePacket->addTag()->setProtocol(&Protocol::ipv4); + udpPacket->addTag()->setProtocol(&Protocol::manet); + udpPacket->addTag()->setProtocol(&Protocol::ipv4); - send(schedulePacket, "ipOut"); + send(udpPacket, "ipOut"); } // Sends data to CH node From 4dbb7392fe850903361c6f089bbb14b32c684d3f Mon Sep 17 00:00:00 2001 From: n-jay Date: Mon, 8 Jul 2024 11:41:17 +0530 Subject: [PATCH 41/43] Implement UDP packet transfer for sending data from CH to BS Adds the necessary code to create a UDP packet and LeachBSPkt to send data from the Cluster Head (CH) to the Base Station (BS). --- src/inet/routing/leach/Leach.cc | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/inet/routing/leach/Leach.cc b/src/inet/routing/leach/Leach.cc index db61add2cd1..185915ed4a1 100644 --- a/src/inet/routing/leach/Leach.cc +++ b/src/inet/routing/leach/Leach.cc @@ -402,21 +402,28 @@ void Leach::sendDataToCH(Ipv4Address nodeAddr, Ipv4Address CHAddr, // CH sends data to BS void Leach::sendDataToBS(Ipv4Address CHAddr) { + Packet *udpPacket = new Packet("LeachBsPkt"); + + auto udpHeader = makeShared(); + udpHeader->setSourcePort(LEACH_UDP_PORT); + udpHeader->setDestinationPort(LEACH_UDP_PORT); + udpHeader->setCrcMode(CRC_DISABLED); + udpPacket->insertAtFront(udpHeader); + auto bsPkt = makeShared(); bsPkt->setPacketType(BS); - bsPkt->setChunkLength(b(128)); bsPkt->setCHAddr(CHAddr); + udpPacket->insertAtBack(bsPkt); - auto bsPacket = new Packet("LEACHBsPkt", bsPkt); - auto addressReq = bsPacket->addTag(); + auto addressReq = bsPacket->addTag(); addressReq->setDestAddress(Ipv4Address(10, 0, 0, 1)); addressReq->setSrcAddress(CHAddr); - bsPacket->addTag()->setInterfaceId( + udpPacket->addTag()->setInterfaceId( wirelessInterface->getInterfaceId()); - bsPacket->addTag()->setProtocol(&Protocol::manet); - bsPacket->addTag()->setProtocol(&Protocol::ipv4); + udpPacket->addTag()->setProtocol(&Protocol::manet); + udpPacket->addTag()->setProtocol(&Protocol::ipv4); sendDelayed(bsPacket, TDMADelayCounter, "ipOut"); setLeachState(nch); // Set state for GUI visualization From a1dc05364ef6a0a405f63b935de65939455604c5 Mon Sep 17 00:00:00 2001 From: n-jay Date: Tue, 9 Jul 2024 10:43:05 +0530 Subject: [PATCH 42/43] Update Base Station code to support UDP packets --- src/inet/routing/leach/LeachBS.cc | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/inet/routing/leach/LeachBS.cc b/src/inet/routing/leach/LeachBS.cc index 825a6749d6d..cb5b437a27f 100644 --- a/src/inet/routing/leach/LeachBS.cc +++ b/src/inet/routing/leach/LeachBS.cc @@ -38,8 +38,7 @@ void LeachBS::initialize(int stage) { bsPktReceived = 0; } else if (stage == INITSTAGE_ROUTING_PROTOCOLS) { - registerService(Protocol::manet, nullptr, gate("ipIn")); - registerProtocol(Protocol::manet, gate("ipOut"), nullptr); + registerProtocol(Protocol::manet, gate("ipOut"), gate("ipIn")); } } @@ -76,12 +75,10 @@ void LeachBS::handleMessageWhenUp(cMessage *msg) { // if node is receiving message else if (check_and_cast(msg)->getTag()->getProtocol() == &Protocol::manet) { - auto receivedCtrlPkt = - staticPtrCast( - check_and_cast(msg)->peekData()->dupShared()); + auto receivedCtrlPkt = dynamic_cast(msg); + receivedCtrlPkt->popAtFront(); Packet *receivedPkt = check_and_cast(msg); - auto &leachControlPkt = receivedPkt->popAtFront(); - + auto &leachControlPkt = receivedCtrlPkt->peekAtFront(); auto packetType = leachControlPkt->getPacketType(); // filter packet based on type and run specific functions From 6c85dee2b146828610a58a13bd03a2a559254041 Mon Sep 17 00:00:00 2001 From: n-jay Date: Tue, 9 Jul 2024 10:44:00 +0530 Subject: [PATCH 43/43] Fix issues with UDP packet support In sending CH data to BS --- src/inet/routing/leach/Leach.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/inet/routing/leach/Leach.cc b/src/inet/routing/leach/Leach.cc index 185915ed4a1..ef93c13fd6b 100644 --- a/src/inet/routing/leach/Leach.cc +++ b/src/inet/routing/leach/Leach.cc @@ -355,7 +355,7 @@ void Leach::sendSchToNCH(Ipv4Address selfAddr) { } udpPacket->insertAtBack(schedulePkt); - auto scheduleReq = schedulePacket->addTag(); + auto scheduleReq = udpPacket->addTag(); scheduleReq->setDestAddress(Ipv4Address(255, 255, 255, 255)); scheduleReq->setSrcAddress(selfAddr); udpPacket->addTag()->setInterfaceId( @@ -417,7 +417,7 @@ void Leach::sendDataToBS(Ipv4Address CHAddr) { udpPacket->insertAtBack(bsPkt); - auto addressReq = bsPacket->addTag(); + auto addressReq = udpPacket->addTag(); addressReq->setDestAddress(Ipv4Address(10, 0, 0, 1)); addressReq->setSrcAddress(CHAddr); udpPacket->addTag()->setInterfaceId( @@ -425,7 +425,7 @@ void Leach::sendDataToBS(Ipv4Address CHAddr) { udpPacket->addTag()->setProtocol(&Protocol::manet); udpPacket->addTag()->setProtocol(&Protocol::ipv4); - sendDelayed(bsPacket, TDMADelayCounter, "ipOut"); + sendDelayed(udpPacket, TDMADelayCounter, "ipOut"); setLeachState(nch); // Set state for GUI visualization }