ALMTest Class Reference

#include <ALMTest.h>

Inheritance diagram for ALMTest:
BaseApp BaseRpc RpcListener

List of all members.

Public Member Functions

 ALMTest ()
 ~ALMTest ()
void initializeApp (int stage)
 initializes derived class-attributes

Protected Member Functions

void handleLowerMessage (cMessage *msg)
 processes self-messages
void handleReadyMessage (CompReadyMessage *msg)
 method to handle ready messages from the overlay
void handleTransportAddressChangedNotification ()
 This method gets call if the node has a new TransportAddress (IP address) because he changed his access network.
void handleUDPMessage (cMessage *msg)
 method to handle messages that come directly from the UDP gate
void handleUpperMessage (cMessage *msg)
 handleUpperMessage gets called of handleMessage(cMessage* msg) if msg arrivedOn from_upperTier (currently msg gets deleted in this function)
void handleTimerEvent (cMessage *msg)
void joinGroup (int i)
void leaveGroup (int i)
void sendDataToGroup (int i)
void handleMCast (ALMMulticastMessage *mcast)

Protected Attributes

cMessage * timer
int groupNum

Private Attributes

bool joinGroups
MessageObserverobserver
int msglen

Detailed Description

Definition at line 34 of file ALMTest.h.


Constructor & Destructor Documentation

ALMTest::ALMTest (  ) 

Definition at line 31 of file ALMTest.cc.

00032 {
00033     timer = new cMessage( "app_timer"); 
00034     joinGroups = true;
00035 }

ALMTest::~ALMTest (  ) 

Definition at line 37 of file ALMTest.cc.

00038 {
00039     cancelAndDelete( timer ); 
00040 }


Member Function Documentation

void ALMTest::handleLowerMessage ( cMessage *  msg  )  [protected, virtual]

processes self-messages

method to handle self-messages should be overwritten in derived application if needed

Parameters:
msg self-message method to handle non-commonAPI messages from the overlay
msg message to handle

Reimplemented from BaseApp.

Definition at line 68 of file ALMTest.cc.

00069 {
00070     ALMMulticastMessage* mcast = dynamic_cast<ALMMulticastMessage*>(msg);
00071     if ( mcast != 0 ) {
00072         handleMCast(mcast);
00073     }
00074 }

void ALMTest::handleMCast ( ALMMulticastMessage *  mcast  )  [protected]

Definition at line 141 of file ALMTest.cc.

Referenced by handleLowerMessage().

00142 {
00143     getParentModule()->getParentModule()->bubble("Received message!");
00144     EV << "[ALMTest::handleMCast()]\n"
00145        << "    App received data message for group: " << mcast->getGroupId()
00146        << endl;
00147 
00148     ALMTestTracedMessage* traced = check_and_cast<ALMTestTracedMessage*>(mcast->decapsulate());
00149     traced->setReceiverId(getId());
00150     observer->receivedMessage(traced);
00151 
00152     delete traced;
00153 
00154     delete mcast;
00155 }

void ALMTest::handleReadyMessage ( CompReadyMessage *  msg  )  [protected, virtual]

method to handle ready messages from the overlay

Parameters:
msg message to handle

Reimplemented from BaseApp.

Definition at line 76 of file ALMTest.cc.

00077 {
00078     if( (getThisCompType() - msg->getComp() == 1) && msg->getReady() ) {
00079         groupNum = 0;
00080         cancelEvent(timer);
00081         scheduleAt(simTime() + 1, timer);
00082     }
00083     delete msg;
00084 }

void ALMTest::handleTimerEvent ( cMessage *  msg  )  [protected, virtual]

Reimplemented from BaseRpc.

Definition at line 53 of file ALMTest.cc.

00054 {
00055     if( msg == timer ) {
00056         double random = uniform( 0, 1 );
00057         if( (random < 0.1 && joinGroups) || groupNum < 1 ) {
00058             joinGroup( ++groupNum );
00059         } else if( random < 0.2 && joinGroups ) {
00060             leaveGroup( groupNum-- );
00061         } else {
00062             sendDataToGroup( intuniform( 1, groupNum ));
00063         }
00064         scheduleAt( simTime() + 10, timer );
00065     }
00066 }

void ALMTest::handleTransportAddressChangedNotification (  )  [protected, virtual]

This method gets call if the node has a new TransportAddress (IP address) because he changed his access network.

Reimplemented from BaseApp.

Definition at line 86 of file ALMTest.cc.

00087 {
00088     //TODO: Implement
00089     assert(false);
00090 }

void ALMTest::handleUDPMessage ( cMessage *  msg  )  [protected, virtual]

method to handle messages that come directly from the UDP gate

Parameters:
msg message to handle

Reimplemented from BaseApp.

Definition at line 92 of file ALMTest.cc.

00093 {
00094     //TODO: Implement
00095     assert(false);
00096 }

void ALMTest::handleUpperMessage ( cMessage *  msg  )  [protected, virtual]

handleUpperMessage gets called of handleMessage(cMessage* msg) if msg arrivedOn from_upperTier (currently msg gets deleted in this function)

Parameters:
msg the message to handle

Reimplemented from BaseApp.

Definition at line 98 of file ALMTest.cc.

00099 {
00100     //TODO: Implement
00101     assert(false);
00102 }

void ALMTest::initializeApp ( int  stage  )  [virtual]

initializes derived class-attributes

Parameters:
stage the init stage

Reimplemented from BaseApp.

Definition at line 42 of file ALMTest.cc.

00042                                      {
00043     if( stage != (numInitStages()-1))
00044     {
00045         return;
00046     }
00047     observer = check_and_cast<MessageObserver*>(
00048             simulation.getModuleByPath("globalObserver.globalFunctions[0].function.observer"));
00049     joinGroups = par("joinGroups");
00050     msglen = par("messageLength");
00051 }

void ALMTest::joinGroup ( int  i  )  [protected]

Definition at line 104 of file ALMTest.cc.

Referenced by handleTimerEvent().

00105 {
00106     ALMSubscribeMessage* msg = new ALMSubscribeMessage;
00107     msg->setGroupId(OverlayKey(i));
00108     send(msg, "to_lowerTier");
00109 
00110     observer->joinedGroup(getId(), OverlayKey(i));
00111 }

void ALMTest::leaveGroup ( int  i  )  [protected]

Definition at line 113 of file ALMTest.cc.

Referenced by handleTimerEvent().

00114 {
00115     ALMLeaveMessage* msg = new ALMLeaveMessage;
00116     msg->setGroupId(OverlayKey(i));
00117     send(msg, "to_lowerTier");
00118 
00119     observer->leftGroup(getId(), OverlayKey(i));
00120 }

void ALMTest::sendDataToGroup ( int  i  )  [protected]

Definition at line 122 of file ALMTest.cc.

Referenced by handleTimerEvent().

00123 {
00124     ALMMulticastMessage* msg = new ALMMulticastMessage("Multicast message");
00125     msg->setGroupId(OverlayKey(i));
00126 
00127     ALMTestTracedMessage* traced = new ALMTestTracedMessage("Traced message");
00128     traced->setTimestamp();
00129     traced->setGroupId(OverlayKey(i));
00130     traced->setMcastId(traced->getId());
00131     traced->setSenderId(getId());
00132     traced->setByteLength(msglen);
00133 
00134     msg->encapsulate(traced);
00135 
00136     send(msg, "to_lowerTier");
00137 
00138     observer->sentMessage(traced);
00139 }


Member Data Documentation

int ALMTest::groupNum [protected]

Definition at line 57 of file ALMTest.h.

Referenced by handleReadyMessage(), and handleTimerEvent().

bool ALMTest::joinGroups [private]

Definition at line 64 of file ALMTest.h.

Referenced by ALMTest(), handleTimerEvent(), and initializeApp().

int ALMTest::msglen [private]

Definition at line 67 of file ALMTest.h.

Referenced by initializeApp(), and sendDataToGroup().

Definition at line 66 of file ALMTest.h.

Referenced by handleMCast(), initializeApp(), joinGroup(), leaveGroup(), and sendDataToGroup().

cMessage* ALMTest::timer [protected]

Definition at line 56 of file ALMTest.h.

Referenced by ALMTest(), handleReadyMessage(), handleTimerEvent(), and ~ALMTest().


The documentation for this class was generated from the following files:
Generated on Wed May 26 16:21:16 2010 for OverSim by  doxygen 1.6.3