Base class for the network layer. More...
#include <BaseNetwLayer.h>
Inherits BaseLayer.
Inherited by DummyRoute, Flood, ProbabilisticBroadcast, and WiseRoute.
Public Types | |
enum | BaseNetwMessageKinds { LAST_BASE_NETW_MESSAGE_KIND = 24000 } |
Message kinds used by this layer. More... | |
enum | BaseNetwControlKinds { LAST_BASE_NETW_CONTROL_KIND = 24500 } |
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 cMessage * | decapsMsg (NetwPkt *) |
decapsulate higher layer message from NetwPkt | |
virtual NetwPkt * | encapsMsg (cPacket *) |
Encapsulate higher layer packet into an NetwPkt. | |
Handle Messages | |
virtual void | handleUpperMsg (cMessage *msg) |
Handle messages from upper layer. | |
virtual void | handleLowerMsg (cMessage *msg) |
Handle messages from lower layer. | |
virtual void | handleSelfMsg (cMessage *msg) |
Handle self messages. | |
virtual void | handleLowerControl (cMessage *msg) |
Handle control messages from lower layer. | |
virtual void | handleUpperControl (cMessage *msg) |
Handle control messages from lower layer. | |
Protected Attributes | |
int | headerLength |
Length of the NetwPkt header Read from omnetpp.ini. | |
ArpInterface * | arp |
Pointer to the arp module. | |
int | myNetwAddr |
cached variable of my networ address | |
bool | coreDebug |
Enables debugging of this module. |
Base class for the network layer.
Definition at line 39 of file BaseNetwLayer.h.
Control message kinds used by this layer.
LAST_BASE_NETW_CONTROL_KIND |
Stores the id on which classes extending BaseNetw should continue their own control kinds. |
Definition at line 49 of file BaseNetwLayer.h.
{ LAST_BASE_NETW_CONTROL_KIND = 24500, };
Message kinds used by this layer.
LAST_BASE_NETW_MESSAGE_KIND |
Stores the id on which classes extending BaseNetw should continue their own message kinds. |
Definition at line 43 of file BaseNetwLayer.h.
{ LAST_BASE_NETW_MESSAGE_KIND = 24000, };
cMessage * BaseNetwLayer::decapsMsg | ( | NetwPkt * | msg | ) | [protected, virtual] |
decapsulate higher layer message from NetwPkt
Decapsulates the packet from the received Network packet
Reimplemented in DummyRoute.
Definition at line 59 of file BaseNetwLayer.cc.
Referenced by Flood::handleLowerMsg(), and handleLowerMsg().
{ cMessage *m = msg->decapsulate(); m->setControlInfo(new NetwControlInfo(msg->getSrcAddr())); // delete the netw packet delete msg; return m; }
NetwPkt * BaseNetwLayer::encapsMsg | ( | cPacket * | appPkt | ) | [protected, virtual] |
Encapsulate higher layer packet into an NetwPkt.
Encapsulates the received ApplPkt into a NetwPkt and set all needed header fields.
Reimplemented in DummyRoute, and Flood.
Definition at line 73 of file BaseNetwLayer.cc.
References arp, ArpInterface::getMacAddr(), NetwControlInfo::getNetwAddr(), headerLength, and myNetwAddr.
Referenced by handleUpperMsg().
{ int macAddr; int netwAddr; coreEV <<"in encaps...\n"; NetwPkt *pkt = new NetwPkt(appPkt->getName(), appPkt->getKind()); pkt->setBitLength(headerLength); NetwControlInfo* cInfo = dynamic_cast<NetwControlInfo*>(appPkt->removeControlInfo()); if(cInfo == 0){ EV << "warning: Application layer did not specifiy a destination L3 address\n" << "\tusing broadcast address instead\n"; netwAddr = L3BROADCAST; } else { coreEV <<"CInfo removed, netw addr="<< cInfo->getNetwAddr()<<endl; netwAddr = cInfo->getNetwAddr(); delete cInfo; } pkt->setSrcAddr(myNetwAddr); pkt->setDestAddr(netwAddr); coreEV << " netw "<< myNetwAddr << " sending packet" <<endl; if(netwAddr == L3BROADCAST) { coreEV << "sendDown: nHop=L3BROADCAST -> message has to be broadcasted" << " -> set destMac=L2BROADCAST\n"; macAddr = L2BROADCAST; } else{ coreEV <<"sendDown: get the MAC address\n"; macAddr = arp->getMacAddr(netwAddr); } pkt->setControlInfo(new NetwToMacControlInfo(macAddr)); //encapsulate the application packet pkt->encapsulate(appPkt); coreEV <<" pkt encapsulated\n"; return pkt; }
void BaseNetwLayer::handleLowerControl | ( | cMessage * | msg | ) | [protected, virtual] |
Handle control messages from lower layer.
Redefine this function if you want to process control messages from lower layers.
This function currently handles one messagetype: TRANSMISSION_OVER. If such a message is received in the network layer it is deleted. This is done as this type of messages is passed on by the BaseMacLayer.
It may be used by network protocols to determine when the lower layers are finished sending a message.
Implements BaseLayer.
Reimplemented in DummyRoute, ProbabilisticBroadcast, and WiseRoute.
Definition at line 157 of file BaseNetwLayer.cc.
References BaseMacLayer::TX_OVER.
{ switch (msg->getKind()) { case BaseMacLayer::TX_OVER: delete msg; break; default: EV << "BaseNetwLayer does not handle control messages called " << msg->getName() << endl; delete msg; } }
void BaseNetwLayer::handleLowerMsg | ( | cMessage * | msg | ) | [protected, virtual] |
Handle messages from lower layer.
Redefine this function if you want to process messages from lower layers before they are forwarded to upper layers
If you want to forward the message to upper layers please use sendUp which will take care of decapsulation and thelike
Implements BaseLayer.
Reimplemented in AdaptiveProbabilisticBroadcast, DummyRoute, Flood, ProbabilisticBroadcast, and WiseRoute.
Definition at line 123 of file BaseNetwLayer.cc.
References decapsMsg(), and BaseLayer::sendUp().
void BaseNetwLayer::handleUpperMsg | ( | cMessage * | msg | ) | [protected, virtual] |
Handle messages from upper layer.
Redefine this function if you want to process messages from upper layers before they are send to lower layers.
For the BaseNetwLayer we just use the destAddr of the network message as a nextHop
To forward the message to lower layers after processing it please use sendDown. It will take care of anything needed
Implements BaseLayer.
Reimplemented in DummyRoute, Flood, ProbabilisticBroadcast, and WiseRoute.
Definition at line 140 of file BaseNetwLayer.cc.
References encapsMsg(), and BaseLayer::sendDown().