Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes

ALMTest Class Reference

#include <ALMTest.h>

Inheritance diagram for ALMTest:
BaseApp BaseRpc BaseTcpSupport RpcListener

List of all members.

Public Member Functions

 ALMTest ()
 ~ALMTest ()
void initializeApp (int stage)
 initializes derived class-attributes
void finishApp ()
 collects statistical data of derived app

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
bool sendMessages
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.

{
    timer = new cMessage( "app_timer"); 
    joinGroups = true;
    sendMessages = true;
    observer = NULL;
}

ALMTest::~ALMTest (  ) 

Definition at line 39 of file ALMTest.cc.

{
    cancelAndDelete( timer ); 
}


Member Function Documentation

void ALMTest::finishApp (  )  [virtual]

collects statistical data of derived app

Reimplemented from BaseApp.

Definition at line 57 of file ALMTest.cc.

{
    cancelEvent(timer);
    observer->nodeDead(getId());
}

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 78 of file ALMTest.cc.

{
    ALMMulticastMessage* mcast = dynamic_cast<ALMMulticastMessage*>(msg);
    if ( mcast != 0 ) {
        handleMCast(mcast);
    }
}

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

Definition at line 151 of file ALMTest.cc.

Referenced by handleLowerMessage().

{
    getParentModule()->getParentModule()->bubble("Received message!");
    EV << "[ALMTest::handleMCast()]\n"
       << "    App received data message for group: " << mcast->getGroupId()
       << endl;

    ALMTestTracedMessage* traced = check_and_cast<ALMTestTracedMessage*>(mcast->decapsulate());
    traced->setReceiverId(getId());
    observer->receivedMessage(traced);

    delete traced;

    delete mcast;
}

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 86 of file ALMTest.cc.

{
    if( (getThisCompType() - msg->getComp() == 1) && msg->getReady() ) {
        groupNum = 0;
        cancelEvent(timer);
        scheduleAt(simTime() + 1, timer);
    }
    delete msg;
}

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

Definition at line 63 of file ALMTest.cc.

{
    if( msg == timer ) {
        double random = uniform( 0, 1 );
        if( (random < 0.1 && joinGroups) || groupNum < 1 ) {
            joinGroup( ++groupNum );
        } else if( random < 0.2 && joinGroups ) {
            leaveGroup( groupNum-- );
        } else if ( sendMessages ) {
            sendDataToGroup( intuniform( 1, groupNum ));
        }
        scheduleAt( simTime() + 10, timer );
    }
}

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 96 of file ALMTest.cc.

{
    //TODO: Implement
    assert(false);
}

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 102 of file ALMTest.cc.

{
    //TODO: Implement
    assert(false);
}

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 108 of file ALMTest.cc.

{
    //TODO: Implement
    assert(false);
}

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

initializes derived class-attributes

Parameters:
stage the init stage

Reimplemented from BaseApp.

Definition at line 44 of file ALMTest.cc.

{
    if( stage != (numInitStages()-1))
    {
        return;
    }
    observer = check_and_cast<MessageObserver*>(
            simulation.getModuleByPath("globalObserver.globalFunctions[0].function.observer"));
    joinGroups = par("joinGroups");
    msglen = par("messageLength");
    sendMessages = par("sendMessages");
}

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

Definition at line 114 of file ALMTest.cc.

Referenced by handleTimerEvent().

{
    ALMSubscribeMessage* msg = new ALMSubscribeMessage;
    msg->setGroupId(OverlayKey(i));
    send(msg, "to_lowerTier");

    observer->joinedGroup(getId(), OverlayKey(i));
}

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

Definition at line 123 of file ALMTest.cc.

Referenced by handleTimerEvent().

{
    ALMLeaveMessage* msg = new ALMLeaveMessage;
    msg->setGroupId(OverlayKey(i));
    send(msg, "to_lowerTier");

    observer->leftGroup(getId(), OverlayKey(i));
}

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

Definition at line 132 of file ALMTest.cc.

Referenced by handleTimerEvent().

{
    ALMMulticastMessage* msg = new ALMMulticastMessage("Multicast message");
    msg->setGroupId(OverlayKey(i));

    ALMTestTracedMessage* traced = new ALMTestTracedMessage("Traced message");
    traced->setTimestamp();
    traced->setGroupId(OverlayKey(i));
    traced->setMcastId(traced->getId());
    traced->setSenderId(getId());
    traced->setByteLength(msglen);

    msg->encapsulate(traced);

    send(msg, "to_lowerTier");

    observer->sentMessage(traced);
}


Member Data Documentation

int ALMTest::groupNum [protected]

Definition at line 58 of file ALMTest.h.

Referenced by handleReadyMessage(), and handleTimerEvent().

bool ALMTest::joinGroups [private]

Definition at line 65 of file ALMTest.h.

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

int ALMTest::msglen [private]

Definition at line 70 of file ALMTest.h.

Referenced by initializeApp(), and sendDataToGroup().

bool ALMTest::sendMessages [private]

Definition at line 67 of file ALMTest.h.

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

cMessage* ALMTest::timer [protected]

Definition at line 57 of file ALMTest.h.

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


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