/* * File: ApplicationLevelMulticastTestApplication.cc * Author: jgaebler * * Created on February 17, 2012, 5:02 PM */ #include "ApplicationLevelMulticastTestApplication.h" #include "../Moversight.h" #include "../Dispatcher.h" #include "../app/PeerDescription.h" #include "../simutils/OmnetppIniUtils.h" #include "StreamMessage.h" #include "../simutils/statistics/VectorStatistic.h" #include "ms/events/GroupClosedEvent.h" #include "ms/events/GroupCreatedEvent.h" #include "ms/events/JoinRequestEvent.h" #undef DEBUG #define DEBUG(msg) if (module.isPrintDebugAPP()) \ MOV_DEBUG << "APP@"<<(dis->getLocalState()==DISJOINED?"TA_":"");\ if(dis->getLocalState()==DISJOINED){MOV_DEBUG << module.getLocalAddress();}\ else{MOV_DEBUG<< dis->getMembershipService().getLocalID();}MOV_DEBUG<<" "<subscribe(this); dis->subscribe(this); dis->subscribe(this); } void ApplicationLevelMulticastTestApplication::finalise() { } /** * @brief Invites a peer to a the moversight group. * @param ta The transport address of the peer to invite. */ void ApplicationLevelMulticastTestApplication::invitePeer(TransportAddress & ta) { std::stringstream buf; buf << "invitePeer - invite peer at address " << ta; DEBUG(buf.str().c_str()); PeerDescription pDesc; dis->invitePeer(ta, pDesc); } /** * @brief Sends dummy data to the group to simulate application traffic. */ void ApplicationLevelMulticastTestApplication::sendData() { DEBUG("sendData - stream dummy data to the group"); StreamMessage data; dis->sendMessage(data); VectorStatistic vs("sendStream"); vs.record(GenericTime::currentTime()); }//End /** * @brief Starts the given test case. * @param i The number of the test case to start. */ void ApplicationLevelMulticastTestApplication::startTestCase(unsigned int i) { switch (i) { case 0: testCase00(); break; case 1: testCase01(); break; default: break; }//End switch }//End startTestCase /** * @brief Executes test case 00 */ void ApplicationLevelMulticastTestApplication::testCase00() { int moduleIndex = module.getLocalAddress().getHostAddress().get4().getDByte(3); if (initApp) { candidates = OmnetppIniUtils::getDestinationAddressesFromOmnetppIni(module); waitCounter = 5; initApp = false; if (moduleIndex == 1) { module.scheduleTestCase(45); }//End if }//End if //------------------------------------------------------------------ //run the app //------------------------------------------------------------------ if (moduleIndex == 1) { // starts counting at 1 //we have more candidates? if (candidatesIndex < candidates.size()) { if (waitCounter > 0) { waitCounter--; } else { invitePeer(candidates.get(candidatesIndex++)); } } else { sendData(); } module.scheduleTestCase(45); }//End if }//End testCase00 /** * @brief Executes test case 01. */ void ApplicationLevelMulticastTestApplication::testCase01() { std::cerr << "TC01 not implemented yet" << endl; } /** * @brief Called, have the local peer received a stream data message. * @param data The received message. * @param sender The sender of the message. */ void ApplicationLevelMulticastTestApplication::receiveStreamMessage(const StreamMessage & data, const PeerID sender) { std::stringstream buf; buf << "receiveStreamMessage - receive stream message from peer ID " << sender; DEBUG(buf.str().c_str()); VectorStatistic vs("receiveStream"); vs.record(GenericTime::currentTime()); } /** * @brief Handle an incoming JoinRequestEvent. * @param e The event. */ void ApplicationLevelMulticastTestApplication::handleEvent(const JoinRequestEvent & e) { DEBUG("invitationReceived - invitation received"); std::stringstream buf; buf << "invitationReceived - invitationID: " << e.getInvitation().getInvitationID() << " inviterID: " << e.getInvitation().getInviterID(); DEBUG(buf.str().c_str()); // if(module.localAddress() == 1 || module.localAddress() == 3 ){ // // MOV_DEBUG << "APP_invitationReceived@TA_" << module.localAddress() << " reject invitation" << endl; // gc->rejectInvitaion(invitation, "peer placing strategy not supported"); // // }//End if // else{ DEBUG("invitationReceived - accept invitation"); PeerDescription pDesc; PeerResources resources; dis->acceptInvitation(e.getInvitation(), "accept invitation", pDesc, resources); // }//End else } /** * @brief Handle an incoming GroupCreatedEvent. * @param e The event */ void ApplicationLevelMulticastTestApplication::handleEvent(const GroupCreatedEvent & e) { DEBUG("group created"); } /** * @brief Handle an incoming GroupClosedEvent. * @param e The event. */ void ApplicationLevelMulticastTestApplication::handleEvent(const GroupClosedEvent & e) { DEBUG("group closed"); } } }