A very simple layer template. More...
#include <BaseLayer.h>
Inherits BatteryAccess.
Inherited by Aggregation, BaseApplLayer, BaseMacLayer, BaseNetwLayer, NetworkStackTrafficGen, and SensorApplLayer.
Public Member Functions | |
virtual void | initialize (int) |
Initialization of the module and some variables. | |
virtual void | handleMessage (cMessage *) |
Called every time a message arrives. | |
virtual void | finish () |
Called when the simulation has finished. | |
Protected Member Functions | |
Handle Messages | |
virtual void | handleSelfMsg (cMessage *msg)=0 |
Handle self messages such as timer... | |
virtual void | handleUpperMsg (cMessage *msg)=0 |
Handle messages from upper layer. | |
virtual void | handleLowerMsg (cMessage *msg)=0 |
Handle messages from lower layer. | |
virtual void | handleLowerControl (cMessage *msg)=0 |
Handle control messages from lower layer. | |
virtual void | handleUpperControl (cMessage *msg)=0 |
Handle control messages from upper layer. | |
Convenience Functions | |
void | sendDown (cMessage *msg) |
Sends a message to the lower layer. | |
void | sendUp (cMessage *msg) |
Sends a message to the upper layer. | |
void | sendControlUp (cMessage *msg) |
Sends a control message to an upper layer. | |
void | sendControlDown (cMessage *msg) |
Sends a control message to a lower layer. | |
void | recordPacket (PassedMessage::direction_t dir, PassedMessage::gates_t gate, const cMessage *m) |
Protected Attributes | |
bool | doStats |
Do we track statistics? | |
int | catPassedMsg |
Blackboard category for PassedMessage BBItems. | |
PassedMessage * | passedMsg |
The last message passed through this layer. | |
int | hostId |
This layers hosts id. | |
gate ids | |
int | upperGateIn |
int | upperGateOut |
int | lowerGateIn |
int | lowerGateOut |
int | upperControlIn |
int | upperControlOut |
int | lowerControlIn |
int | lowerControlOut |
A very simple layer template.
This module provides basic abstractions that ease development of a network or MAC layer.
Definition at line 38 of file BaseLayer.h.
void BaseLayer::handleMessage | ( | cMessage * | msg | ) | [virtual] |
Called every time a message arrives.
The basic handle message function.
Depending on the gate a message arrives handleMessage just calls different handle*Msg functions to further process the message.
You should not make any changes in this function but implement all your functionality into the handle*Msg functions called from here.
Definition at line 73 of file BaseLayer.cc.
References handleLowerControl(), handleLowerMsg(), handleSelfMsg(), handleUpperControl(), and handleUpperMsg().
{ if (msg->isSelfMessage()){ handleSelfMsg(msg); } else if(msg->getArrivalGateId()==upperGateIn) { recordPacket(PassedMessage::INCOMING,PassedMessage::UPPER_DATA,msg); handleUpperMsg(msg); } else if(msg->getArrivalGateId()==upperControlIn) { recordPacket(PassedMessage::INCOMING,PassedMessage::UPPER_CONTROL,msg); handleUpperControl(msg); } else if(msg->getArrivalGateId()==lowerControlIn){ recordPacket(PassedMessage::INCOMING,PassedMessage::LOWER_CONTROL,msg); handleLowerControl(msg); } else if(msg->getArrivalGateId()==lowerGateIn) { recordPacket(PassedMessage::INCOMING,PassedMessage::LOWER_DATA,msg); handleLowerMsg(msg); } else if(msg->getArrivalGateId()==-1) { /* Classes extending this class may not use all the gates, f.e. * BaseApplLayer has no upper gates. In this case all upper gate- * handles are initialized to -1. When getArrivalGateId() equals -1, * it would be wrong to forward the message to one of these gates, * as they actually don't exist, so raise an error instead. */ opp_error("No self message and no gateID?? Check configuration."); } else { /* msg->getArrivalGateId() should be valid, but it isn't recognized * here. This could signal the case that this class is extended * with extra gates, but handleMessage() isn't overridden to * check for the new gate(s). */ opp_error("Unknown gateID?? Check configuration or override handleMessage()."); } }
virtual void BaseLayer::handleUpperMsg | ( | cMessage * | msg | ) | [protected, pure virtual] |
Handle messages from upper layer.
This function is pure virtual here, because there is no reasonable guess what to do with it by default.
Implemented in BaseApplLayer, BaseMacLayer, BaseNetwLayer, SensorApplLayer, BMacLayer, csma, CSMAMacLayer, LMacLayer, Mac80211, DummyRoute, Flood, ProbabilisticBroadcast, WiseRoute, Aggregation, and NetworkStackTrafficGen.
Referenced by handleMessage().
void BaseLayer::initialize | ( | int | stage | ) | [virtual] |
Initialization of the module and some variables.
First we have to initialize the module from which we derived ours, in this case BaseModule. This module takes care of the gate initialization.
Reimplemented from BaseModule.
Reimplemented in BaseApplLayer, BaseMacLayer, BaseNetwLayer, TestApplLayer, BurstApplLayer, BurstApplLayerBattery, SensorApplLayer, TrafficGen, AlohaMacLayer, BMacLayer, csma, CSMA802154, CSMAMacLayer, LMacLayer, Mac80211, Mac80211MultiChannel, UWBIRMac, AdaptiveProbabilisticBroadcast, DummyRoute, Flood, ProbabilisticBroadcast, WiseRoute, Aggregation, and NetworkStackTrafficGen.
Definition at line 36 of file BaseLayer.cc.
References catPassedMsg, doStats, BaseModule::findHost(), Blackboard::getCategory(), hostId, passedMsg, and BaseModule::utility.
{ BatteryAccess::initialize(stage); if(stage==0){ if (hasPar("stats") && par("stats").boolValue()) { doStats = true; passedMsg = new PassedMessage(); catPassedMsg = utility->getCategory(passedMsg); passedMsg->fromModule = getId(); hostId = findHost()->getId(); } else { doStats = false; } upperGateIn = findGate("upperGateIn"); upperGateOut = findGate("upperGateOut"); lowerGateIn = findGate("lowerGateIn"); lowerGateOut = findGate("lowerGateOut"); upperControlIn = findGate("upperControlIn"); upperControlOut = findGate("upperControlOut"); lowerControlIn = findGate("lowerControlIn"); lowerControlOut = findGate("lowerControlOut"); } }
void BaseLayer::sendDown | ( | cMessage * | msg | ) | [protected] |
Sends a message to the lower layer.
Short hand for send(msg, lowerGateOut);
You have to take care of encapsulation We recommend that you use a pair of functions called encapsMsg/decapsMsg.
Definition at line 108 of file BaseLayer.cc.
Referenced by CSMAMacLayer::handleLowerControl(), WiseRoute::handleLowerMsg(), Flood::handleLowerMsg(), WiseRoute::handleSelfMsg(), ProbabilisticBroadcast::handleSelfMsg(), LMacLayer::handleSelfMsg(), Aggregation::handleUpperMsg(), WiseRoute::handleUpperMsg(), Flood::handleUpperMsg(), DummyRoute::handleUpperMsg(), BaseNetwLayer::handleUpperMsg(), BaseMacLayer::handleUpperMsg(), Mac80211::sendACKframe(), TrafficGen::sendBroadcast(), NetworkStackTrafficGen::sendBroadcast(), TestApplLayer::sendBroadcast(), Mac80211::sendBROADCASTframe(), Mac80211::sendCTSframe(), SensorApplLayer::sendData(), Mac80211::sendDATAframe(), BMacLayer::sendDataPacket(), BMacLayer::sendMacAck(), BMacLayer::sendPreamble(), and Mac80211::sendRTSframe().
{ recordPacket(PassedMessage::OUTGOING,PassedMessage::LOWER_DATA,msg); send(msg, lowerGateOut); }
void BaseLayer::sendUp | ( | cMessage * | msg | ) | [protected] |
Sends a message to the upper layer.
Short hand for send(msg, upperGateOut); You have to take care of decapsulation and deletion of superflous frames. We recommend that you use a pair of functions decapsMsg/encapsMsg.
Definition at line 113 of file BaseLayer.cc.
Referenced by Mac80211::handleBroadcastMsg(), Mac80211::handleDATAframe(), Aggregation::handleLowerMsg(), WiseRoute::handleLowerMsg(), ProbabilisticBroadcast::handleLowerMsg(), Flood::handleLowerMsg(), DummyRoute::handleLowerMsg(), CSMAMacLayer::handleLowerMsg(), AlohaMacLayer::handleLowerMsg(), BaseNetwLayer::handleLowerMsg(), BaseMacLayer::handleLowerMsg(), LMacLayer::handleSelfMsg(), and BMacLayer::handleSelfMsg().
{ recordPacket(PassedMessage::OUTGOING,PassedMessage::UPPER_DATA,msg); send(msg, upperGateOut); }