Test class for the application layer. More...
#include <TestApplLayer.h>
Inherits BaseApplLayer.
Inherited by BurstApplLayer.
Public Types | |
enum | TestApplMessageKinds { SEND_BROADCAST_TIMER = LAST_BASE_APPL_MESSAGE_KIND, BROADCAST_MESSAGE, BROADCAST_REPLY_MESSAGE, LAST_TEST_APPL_MESSAGE_KIND } |
Message kinds used by this layer. | |
Public Member Functions | |
virtual void | initialize (int) |
Initialization of the module and some variables. | |
Protected Member Functions | |
virtual void | handleSelfMsg (cMessage *) |
Handle self messages such as timer... | |
virtual void | handleLowerMsg (cMessage *) |
Handle messages from lower layer. | |
void | sendBroadcast () |
send a broadcast packet to all connected neighbors | |
void | sendReply (ApplPkt *msg) |
send a reply to a broadcast message | |
Protected Attributes | |
cMessage * | delayTimer |
Timer message for scheduling next message. | |
bool | coreDebug |
Enables debugging of this module. |
Test class for the application layer.
In this implementation all nodes randomly send broadcast packets to all connected neighbors. Every node who receives this packet will send a reply to the originator node.
Definition at line 38 of file TestApplLayer.h.
void TestApplLayer::handleLowerMsg | ( | cMessage * | msg | ) | [protected, virtual] |
Handle messages from lower layer.
There are two kinds of messages that can arrive at this module: The first (kind = BROADCAST_MESSAGE) is a broadcast packet from a neighbor node to which we have to send a reply. The second (kind = BROADCAST_REPLY_MESSAGE) is a reply to a broadcast packet that we have send and just causes some output before it is deleted
Reimplemented from BaseApplLayer.
Reimplemented in BurstApplLayerBattery.
Definition at line 56 of file TestApplLayer.cc.
References sendReply().
{ ApplPkt *m; switch( msg->getKind() ){ case BROADCAST_MESSAGE: m = static_cast<ApplPkt *>(msg); coreEV << "Received a broadcast packet from host["<<m->getSrcAddr()<<"] -> sending reply\n"; sendReply(m); break; case BROADCAST_REPLY_MESSAGE: m = static_cast<ApplPkt *>(msg); coreEV << "Received reply from host["<<m->getSrcAddr()<<"]; delete msg\n"; delete msg; break; default: EV <<"Error! got packet with unknown kind: " << msg->getKind()<<endl; delete msg; } }
void TestApplLayer::handleSelfMsg | ( | cMessage * | msg | ) | [protected, virtual] |
Handle self messages such as timer...
A timer with kind = SEND_BROADCAST_TIMER indicates that a new broadcast has to be send (sendBroadcast).
There are no other timer implemented for this module.
Reimplemented from BaseApplLayer.
Reimplemented in BurstApplLayer, and BurstApplLayerBattery.
Definition at line 84 of file TestApplLayer.cc.
References delayTimer, and sendBroadcast().
{ switch( msg->getKind() ){ case SEND_BROADCAST_TIMER: sendBroadcast(); delete msg; delayTimer = NULL; break; default: EV << "Unknown selfmessage! -> delete, kind: "<<msg->getKind() <<endl; delete msg; } }
void TestApplLayer::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 BasicModule.
Then we will set a timer to indicate the first time we will send a message
Reimplemented from BaseApplLayer.
Reimplemented in BurstApplLayer, and BurstApplLayerBattery.
Definition at line 36 of file TestApplLayer.cc.
References coreDebug, and delayTimer.
{ BaseApplLayer::initialize(stage); if(stage == 0) { hasPar("coreDebug") ? coreDebug = par("coreDebug").boolValue() : coreDebug = false; delayTimer = new cMessage( "delay-timer", SEND_BROADCAST_TIMER ); } else if(stage==1) { scheduleAt(simTime() + dblrand() * 10, delayTimer); } }
void TestApplLayer::sendBroadcast | ( | ) | [protected] |
send a broadcast packet to all connected neighbors
This function creates a new broadcast message and sends it down to the network layer
Definition at line 101 of file TestApplLayer.cc.
References BaseApplLayer::headerLength, BaseApplLayer::myApplAddr(), and BaseLayer::sendDown().
Referenced by BurstApplLayerBattery::handleSelfMsg(), BurstApplLayer::handleSelfMsg(), and handleSelfMsg().
{ ApplPkt *pkt = new ApplPkt("BROADCAST_MESSAGE", BROADCAST_MESSAGE); pkt->setDestAddr(-1); // we use the host modules getIndex() as a appl address pkt->setSrcAddr( myApplAddr() ); pkt->setBitLength(headerLength); // set the control info to tell the network layer the layer 3 // address; pkt->setControlInfo( new NetwControlInfo(L3BROADCAST) ); coreEV << "Sending broadcast packet!\n"; sendDown( pkt ); }