Public Types | Public Member Functions | Protected Member Functions | Protected Attributes

BaseNetwLayer Class Reference
[netwLayer - network layer modulesbaseModules - base module classes of MiXiM]

Base class for the network layer. More...

#include <BaseNetwLayer.h>

Inherits BaseLayer.

Inherited by DummyRoute, Flood, ProbabilisticBroadcast, and WiseRoute.

Collaboration diagram for BaseNetwLayer:
Collaboration graph
[legend]

List of all members.

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

Functions to redefine by the programmer

These are the functions provided to add own functionality to your modules. These functions are called whenever a self message or a data message from the upper or lower layer arrives respectively.

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.
ArpInterfacearp
 Pointer to the arp module.
int myNetwAddr
 cached variable of my networ address
bool coreDebug
 Enables debugging of this module.

Detailed Description

Base class for the network layer.

Author:
Daniel Willkomm

Definition at line 39 of file BaseNetwLayer.h.


Member Enumeration Documentation

Control message kinds used by this layer.

Enumerator:
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.

Message kinds used by this layer.

Enumerator:
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.


Member Function Documentation

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().

{
    NetwPkt *m = static_cast<NetwPkt *>(msg);
    coreEV << " handling packet from " << m->getSrcAddr() << endl;
    sendUp(decapsMsg(m));
}

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().

{
  assert(dynamic_cast<cPacket*>(msg));
    sendDown(encapsMsg(static_cast<cPacket*>(msg)));
}


The documentation for this class was generated from the following files: