A very simple MAC module template which provides de- and encapsulation of messages using the standard addresses and NetwToMacControlInfo of MiXiM. It also provides basic handling of lower layer messages. More...
#include <BaseMacLayer.h>
Inherits BaseLayer.
Inherited by BMacLayer, csma, CSMAMacLayer, LMacLayer, Mac80211, and UWBIRMac.
Public Types | |
enum | BaseMacMessageKinds { LAST_BASE_MAC_MESSAGE_KIND = 23000 } |
Message kinds used by this layer. More... | |
enum | BaseMacControlKinds { TX_OVER = 23500, PACKET_DROPPED, LAST_BASE_MAC_CONTROL_KIND } |
Control message kinds used by this layer. More... | |
Public Member Functions | |
virtual void | initialize (int) |
Initialization of the module and some variables. | |
Protected Member Functions | |
virtual void | handleUpperMsg (cMessage *msg) |
Handle messages comming from the network layer. | |
virtual void | handleLowerMsg (cMessage *msg) |
virtual void | handleSelfMsg (cMessage *msg) |
Handle self messages such as timer... | |
virtual void | handleLowerControl (cMessage *msg) |
Handle control messages from lower layer. | |
virtual void | handleUpperControl (cMessage *msg) |
Handle control messages from upper layer. | |
virtual cPacket * | decapsMsg (MacPkt *) |
decapsulate the network message from the MacPkt | |
virtual MacPkt * | encapsMsg (cPacket *) |
Encapsulate the NetwPkt into an MacPkt. | |
virtual Signal * | createSignal (simtime_t start, simtime_t length, double power, double bitrate) |
Creates a simple Signal defined over time with the passed parameters. | |
Mapping * | createConstantMapping (simtime_t start, simtime_t end, double value) |
Creates a simple Mapping with a constant curve progression at the passed value. | |
Mapping * | createRectangleMapping (simtime_t start, simtime_t end, double value) |
Creates a simple Mapping with a constant curve progression at the passed value and discontinuities at the boundaries. | |
ConstMapping * | createSingleFrequencyMapping (simtime_t start, simtime_t end, double centerFreq, double bandWith, double value) |
Creates a Mapping defined over time and frequency with constant power in a certain frequency band. | |
BaseConnectionManager * | getConnectionManager () |
Returns a pointer to this MACs NICs ConnectionManager module. | |
Protected Attributes | |
MacToPhyInterface * | phy |
Handler to the physical layer. | |
int | headerLength |
Pointer to the arp module. | |
int | myMacAddr |
MAC address (simply module id). | |
bool | coreDebug |
debug this core module? | |
int | phyHeaderLength |
The length of the phy header (in bits). |
A very simple MAC module template which provides de- and encapsulation of messages using the standard addresses and NetwToMacControlInfo of MiXiM. It also provides basic handling of lower layer messages.
Definition at line 43 of file BaseMacLayer.h.
Control message kinds used by this layer.
Definition at line 53 of file BaseMacLayer.h.
{ TX_OVER = 23500, PACKET_DROPPED, LAST_BASE_MAC_CONTROL_KIND, };
Message kinds used by this layer.
LAST_BASE_MAC_MESSAGE_KIND |
Stores the id on which classes extending BaseMac should continue their own message kinds. |
Definition at line 47 of file BaseMacLayer.h.
{ LAST_BASE_MAC_MESSAGE_KIND = 23000, };
Mapping * BaseMacLayer::createConstantMapping | ( | simtime_t | start, | |
simtime_t | end, | |||
double | value | |||
) | [protected] |
Creates a simple Mapping with a constant curve progression at the passed value.
Used by "createSignal" to create the bitrate mapping.
Definition at line 183 of file BaseMacLayer.cc.
References MappingUtils::createMapping(), Mapping::LINEAR, Mapping::setValue(), and DimensionSet::timeDomain.
Referenced by createSignal().
{ //create mapping over time Mapping* m = MappingUtils::createMapping(0.0, DimensionSet::timeDomain, Mapping::LINEAR); //set position Argument Argument startPos(start); //set mapping at position m->setValue(startPos, value); //set position Argument Argument endPos(end); //set mapping at position m->setValue(endPos, value); return m; }
Mapping * BaseMacLayer::createRectangleMapping | ( | simtime_t | start, | |
simtime_t | end, | |||
double | value | |||
) | [protected] |
Creates a simple Mapping with a constant curve progression at the passed value and discontinuities at the boundaries.
Used by "createSignal" to create the power mapping.
Definition at line 203 of file BaseMacLayer.cc.
References MappingUtils::addDiscontinuity(), MappingUtils::createMapping(), Mapping::LINEAR, MappingUtils::post(), MappingUtils::pre(), and DimensionSet::timeDomain.
Referenced by createSignal().
{ //create mapping over time Mapping* m = MappingUtils::createMapping(DimensionSet::timeDomain, Mapping::LINEAR); //set position Argument Argument startPos(start); //set discontinuity at position MappingUtils::addDiscontinuity(m, startPos, 0.0, MappingUtils::post(start), value); //set position Argument Argument endPos(end); //set discontinuity at position MappingUtils::addDiscontinuity(m, endPos, 0.0, MappingUtils::pre(end), value); return m; }
Signal * BaseMacLayer::createSignal | ( | simtime_t | start, | |
simtime_t | length, | |||
double | power, | |||
double | bitrate | |||
) | [protected, virtual] |
Creates a simple Signal defined over time with the passed parameters.
Convenience method to be able to create the appropriate Signal for the MacToPhyControlInfo without needing to care about creating Mappings.
NOTE: The created signal's transmission-power is a rectangular function. This method uses MappingUtils::addDiscontinuity to represent the discontinuities at the beginning and end of this rectangular function. Because of this the created mapping which represents the signal's transmission-power is still zero at the exact start and end. Please see the method MappingUtils::addDiscontinuity for the reason.
Reimplemented in Mac80211.
Definition at line 166 of file BaseMacLayer.cc.
References createConstantMapping(), createRectangleMapping(), Signal::setBitrate(), and Signal::setTransmissionPower().
Referenced by LMacLayer::attachSignal(), BMacLayer::attachSignal(), and CSMAMacLayer::encapsMsg().
{ simtime_t end = start + length; //create signal with start at current simtime and passed length Signal* s = new Signal(start, length); //create and set tx power mapping Mapping* txPowerMapping = createRectangleMapping(start, end, power); s->setTransmissionPower(txPowerMapping); //create and set bitrate mapping Mapping* bitrateMapping = createConstantMapping(start, end, bitrate); s->setBitrate(bitrateMapping); return s; }
cPacket * BaseMacLayer::decapsMsg | ( | MacPkt * | msg | ) | [protected, virtual] |
decapsulate the network message from the MacPkt
Decapsulates the network packet from the received MacPkt
Reimplemented in csma, and CSMA802154.
Definition at line 69 of file BaseMacLayer.cc.
Referenced by CSMAMacLayer::handleLowerMsg(), AlohaMacLayer::handleLowerMsg(), handleLowerMsg(), LMacLayer::handleSelfMsg(), and BMacLayer::handleSelfMsg().
{ cPacket *m = msg->decapsulate(); m->setControlInfo(new MacToNetwControlInfo(msg->getSrcAddr(), 0)); // delete the macPkt delete msg; coreEV << " message decapsulated " << endl; return m; }
MacPkt * BaseMacLayer::encapsMsg | ( | cPacket * | netwPkt | ) | [protected, virtual] |
Encapsulate the NetwPkt into an MacPkt.
Encapsulates the received NetwPkt into a MacPkt and set all needed header fields.
Reimplemented in AlohaMacLayer, CSMAMacLayer, and Mac80211.
Definition at line 84 of file BaseMacLayer.cc.
References NetwToMacControlInfo::getNextHopMac(), headerLength, and myMacAddr.
Referenced by handleUpperMsg().
{ MacPkt *pkt = new MacPkt(netwPkt->getName(), netwPkt->getKind()); pkt->setBitLength(headerLength); // copy dest address from the Control Info attached to the network // message by the network layer NetwToMacControlInfo* cInfo = static_cast<NetwToMacControlInfo*>(netwPkt->removeControlInfo()); coreEV <<"CInfo removed, mac addr="<< cInfo->getNextHopMac()<<endl; pkt->setDestAddr(cInfo->getNextHopMac()); //delete the control info delete cInfo; //set the src address to own mac address (nic module getId()) pkt->setSrcAddr(myMacAddr); //encapsulate the network packet pkt->encapsulate(netwPkt); coreEV <<"pkt encapsulated\n"; return pkt; }
BaseConnectionManager * BaseMacLayer::getConnectionManager | ( | ) | [protected] |
Returns a pointer to this MACs NICs ConnectionManager module.
Definition at line 247 of file BaseMacLayer.cc.
Referenced by Mac80211::initialize(), and csma::initialize().
{ cModule* nic = getParentModule(); return ChannelAccess::getConnectionManager(nic); }
void BaseMacLayer::handleLowerMsg | ( | cMessage * | msg | ) | [protected, virtual] |
If message arrives from lower layer, check whether it is for us. Send it up if yes.
This basic implementation just forwards all message that are broadcast (destAddr = L2BROADCAST) or destined for this node (destAddr = nic module getId()) to the network layer
Implements BaseLayer.
Reimplemented in AlohaMacLayer, BMacLayer, csma, CSMAMacLayer, LMacLayer, and Mac80211.
Definition at line 130 of file BaseMacLayer.cc.
References decapsMsg(), myMacAddr, and BaseLayer::sendUp().
{ MacPkt *mac = static_cast<MacPkt *>(msg); int dest = mac->getDestAddr(); int src = mac->getSrcAddr(); //only foward to upper layer if message is for me or broadcast if((dest == myMacAddr) || (dest == L2BROADCAST)) { coreEV << "message with mac addr " << src << " for me (dest=" << dest << ") -> forward packet to upper layer\n"; sendUp(decapsMsg(mac)); } else{ coreEV << "message with mac addr " << src << " not for me (dest=" << dest << ") -> delete (my MAC="<<myMacAddr<<")\n"; delete mac; } }
void BaseMacLayer::handleUpperMsg | ( | cMessage * | mac | ) | [protected, virtual] |
Handle messages comming from the network layer.
Here is the place to implement a real medium access functionality.
If message arrives from upper layer, make a MAC packet from it (encapsMsg) and send it down (sendDown).
Redefine this function if you want to process messages from upper layers before they are send to lower layers.
To forward the message to lower layers after processing it please use sendDown. It will take care of anything needed
Implements BaseLayer.
Reimplemented in BMacLayer, csma, CSMAMacLayer, LMacLayer, and Mac80211.
Definition at line 116 of file BaseMacLayer.cc.
References encapsMsg(), and BaseLayer::sendDown().
void BaseMacLayer::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 BaseLayer.
Reimplemented from BaseLayer.
Reimplemented in AlohaMacLayer, BMacLayer, csma, CSMA802154, CSMAMacLayer, LMacLayer, Mac80211, Mac80211MultiChannel, and UWBIRMac.
Definition at line 39 of file BaseMacLayer.cc.
References coreDebug, BaseModule::findHost(), MacToPhyInterface::getPhyHeaderLength(), headerLength, AddressingInterface::myMacAddr(), myMacAddr, phy, and phyHeaderLength.
{ BaseLayer::initialize(stage); if(stage==0) { // get handle to phy layer phy = FindModule<MacToPhyInterface*>::findSubModule(getParentModule()); headerLength= par("headerLength"); phyHeaderLength = phy->getPhyHeaderLength(); hasPar("coreDebug") ? coreDebug = par("coreDebug").boolValue() : coreDebug = false; } else if (stage==1) { // see if there is an addressing module available // otherwise use NIC modules id as MAC address AddressingInterface* addrScheme = FindModule<AddressingInterface*>::findSubModule(findHost()); if(addrScheme) { myMacAddr = addrScheme->myMacAddr(this); } else { myMacAddr = getParentModule()->getId(); } } }
int BaseMacLayer::headerLength [protected] |
Pointer to the arp module.
Length of the MacPkt header
Reimplemented in BMacLayer.
Definition at line 73 of file BaseMacLayer.h.
Referenced by LMacLayer::encapsMsg(), AlohaMacLayer::encapsMsg(), encapsMsg(), LMacLayer::handleSelfMsg(), csma::handleUpperMsg(), and initialize().
int BaseMacLayer::phyHeaderLength [protected] |
The length of the phy header (in bits).
Since the MAC layer has to create the signal for a transmission it has to know the total length of the packet and therefore needs the length of the phy header.
Definition at line 90 of file BaseMacLayer.h.
Referenced by initialize(), and Mac80211::packetDuration().