Files
scandocs/uni/masterarbeit/source/moversight/app/PendingTestApplication.cc
2014-06-30 13:58:10 +02:00

201 lines
6.3 KiB
C++

/*
* File: PendingTestApplication.cc
* Author: jgaebler
*
* Created on February 19, 2013, 5:01 PM
*/
#include "PendingTestApplication.h"
#include "Dispatcher.h"
#include "Moversight.h"
#include "common/transport/TransportAddress.h"
#include "mt/msg/GroupData.h"
#include "ms/Invitation.h"
#include "simutils/OmnetppIniUtils.h"
#include "ms/events/PeerLeftEvent.h"
#include "fd/events/PeerReconnectedEvent.h"
#include "mt/events/PendingPeersEvent.h"
#include "ms/events/JoinRequestEvent.h"
#include "ms/events/JoinConfirmEvent.h"
#include "ms/events/JoinRejectedEvent.h"
#include "ms/events/JoinAbortedEvent.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<<" "<<msg<<std::endl;
namespace ubeeme {
namespace moversight {
PendingTestApplication::PendingTestApplication(Moversight & m) : Application(m, "PendingTestApplication") {
}
PendingTestApplication::~PendingTestApplication() {
}
void
PendingTestApplication::initialise() {
dis->subscribe<PeerLeftEvent>(this);
dis->subscribe<PeerReconnectedEvent>(this);
dis->subscribe<PendingPeersEvent>(this);
dis->subscribe<JoinRequestEvent>(this);
dis->subscribe<JoinConfirmEvent>(this);
dis->subscribe<JoinAbortedEvent>(this);
dis->subscribe<JoinRejectedEvent>(this);
}
void
PendingTestApplication::finalise() {
}
void
PendingTestApplication::startTestCase(unsigned int i) {
switch (i) {
case 0:
testCase00();
break;
default:
break;
}//End switch
}
void
PendingTestApplication::receiveGroupData(const GroupData & data, const PeerID sender) {
std::stringstream buf;
buf << "receiveGroupData - receive group data from peer ID " << sender;
DEBUG(buf.str().c_str());
}
void
PendingTestApplication::testCase00() {
int moduleIndex = module.getLocalAddress().getHostAddress().get4().getDByte(3);
if (initApp) {
candidates = OmnetppIniUtils::getDestinationAddressesFromOmnetppIni(module);
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 (candidates.size() > 0) {
invitePeer(candidates.first());
candidates.pop();
}
else {
sendData();
}
module.scheduleTestCase(45);
}//End if
}
void
PendingTestApplication::invitePeer(TransportAddress & ta) {
std::stringstream buf;
buf << "invitePeer - invite peer at address " << ta;
DEBUG(buf.str().c_str());
PeerDescription pDesc;
;
dis->invitePeer(ta, pDesc);
}
void
PendingTestApplication::leaveGroup() {
DEBUG("leaveGroup - peer leave the group");
dis->leaveGroup();
}
void
PendingTestApplication::sendData() {
DEBUG("sendData - send 24 byte dummy data to the group");
GroupData data;
dis->sendMessage(data);
}
void
PendingTestApplication::handleEvent(const JoinRequestEvent & e) {
DEBUG("JoinRequest - invitation received");
std::stringstream buf;
buf << "JoinRequest - invitationID: " << e.getInvitation().getInvitationID() << " inviterID: " << e.getInvitation().getInviterID();
DEBUG(buf.str().c_str());
DEBUG("JoinRequest - accept invitation");
PeerDescription pDesc;
PeerResources resources;
dis->acceptInvitation(e.getInvitation(), "accept invitation", pDesc, resources);
}
void
PendingTestApplication::handleEvent(const JoinConfirmEvent & e) {
std::stringstream buf;
buf << "JoinConfirm - peer at TA: " << e.getInvitation().getInviteeAddress() << " accept invitation " << e.getInvitation().getInvitationID();
buf << " message: " << e.getMessage() << ", peer description: " << e.getDescription().getDescription();
DEBUG(buf.str().c_str());
}
void
PendingTestApplication::handleEvent(const JoinRejectedEvent & e) {
std::stringstream buf;
buf << "JoinRejected - invitation ID " << e.getInvitation().getInvitationID() << " aborted";
buf << " reason: " << e.getReason();
DEBUG(buf.str().c_str());
}
void
PendingTestApplication::handleEvent(const JoinAbortedEvent & e) {
std::stringstream buf;
buf << "JoinNotExecutable - invitation to peer " << e.getTransportAddress() << " aborted";
buf << " reason: " << e.getReason();
DEBUG(buf.str().c_str());
}
void
PendingTestApplication::handleEvent(const PendingPeersEvent & e) {
std::stringstream buf;
buf << "PendingPeers - peers " << e.getPeerIDList() << " are pending";
DEBUG(buf.str().c_str());
}
void
PendingTestApplication::handleEvent(const PeerReconnectedEvent & e) {
std::stringstream buf;
buf << "PeerReconnect - peer " << e.getPeerID() << " is reconnected";
DEBUG(buf.str().c_str());
}
void
PendingTestApplication::handleEvent(const PeerLeftEvent & e) {
std::stringstream buf;
buf << "PeerLeft - peer " << e.getPeer().getPeerID() << "@TA_" << e.getPeer().getLocalAddress() << " left the group";
DEBUG(buf.str().c_str());
}
}
}