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

1388 lines
49 KiB
C++
Executable File

/*
* File: TestApplication.cc
* Author: jgaebler
*
* Created on April 20, 2011, 11:33 AM
*/
#include "TestApplication.h"
#include "Dispatcher.h"
#include "Moversight.h"
#include "ms/PeerResources.h"
#include "common/transport/TransportAddress.h"
#include "mt/msg/GroupData.h"
#include "ms/Invitation.h"
#include "simutils/OmnetppIniUtils.h"
#include "StreamMessage.h"
#include "ms/events/GroupCreatedEvent.h"
#include "ms/events/PeerJoinedEvent.h"
#include "ms/events/GroupClosedEvent.h"
#include "ms/events/JoinRequestEvent.h"
#include "ms/events/JoinConfirmEvent.h"
#include "ms/events/JoinRejectedEvent.h"
#include "ms/events/JoinAbortedEvent.h"
#include "ms/events/PeerLeftEvent.h"
#include "fd/events/PeerReconnectedEvent.h"
#include "simutils/events/StartMeasuringEvent.h"
#include "simutils/events/StopMeasuringEvent.h"
#include "mt/events/PendingPeersEvent.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 {
/**
* @brief Constructor
* @param m A reference to the moversight instance
*/
TestApplication::TestApplication(Moversight & m) : Application(m, "TestApplication"), joinDelayStat(m, "joinDelay"), dtDelayStat(m, "dtDelay"), leaveDelayStat(m, "leaveDelay"), rejoinSuccessDuration(m, "rejoinSuccess"), groupSizeStat(m, "groupSize"), groupSize(0) {
numberOfPeers = module.par("numberOfPeers");
numberOfMobilePeers = module.par("numberOfMobilePeers");
clusterSize = (numberOfPeers + numberOfMobilePeers) / module.getMaxPeerCount();
if ((numberOfPeers + numberOfMobilePeers) % module.getMaxPeerCount() != 0) {
clusterSize++;
}
}
/**
* @brief Destructor
*/
TestApplication::~TestApplication() {
}
void
TestApplication::initialise() {
dis->subscribe<GroupCreatedEvent>(this);
dis->subscribe<PeerJoinedEvent>(this);
dis->subscribe<GroupClosedEvent>(this);
dis->subscribe<JoinRequestEvent>(this);
dis->subscribe<JoinConfirmEvent>(this);
dis->subscribe<JoinRejectedEvent>(this);
dis->subscribe<JoinAbortedEvent>(this);
dis->subscribe<PeerLeftEvent>(this);
dis->subscribe<PeerReconnectedEvent>(this);
dis->subscribe<StartMeasuringEvent>(this);
dis->subscribe<StopMeasuringEvent>(this);
dis->subscribe<PendingPeersEvent>(this);
}
void
TestApplication::finalise() {
dis->unsubscribeAll(this);
}
/**
* @brief Invites a peer to a the moversight group.
* @param ta The transport address of the peer to invite.
*/
void
TestApplication::invitePeer(TransportAddress & ta) {
std::stringstream buf;
buf << "invitePeer - invite peer at address " << ta;
DEBUG(buf.str().c_str());
PeerDescription pDesc;
joinDelayStat.startRecord();
dis->invitePeer(ta, pDesc);
dis->signal(new StartMeasuringEvent("REJOIN"));
}
/**
* @brief Leaves the current group. The peer leafs the current group be
* emitting a LeaveAnnounce within the current group.
*/
void
TestApplication::leaveGroup() {
DEBUG("leaveGroup - peer leave the group");
leaveDelayStat.startRecord();
dis->leaveGroup();
dis->signal(new StartMeasuringEvent("TG"));
}
/**
* @brief Sends dummy data to the group to simulate application traffic.
*/
void
TestApplication::sendData() {
DEBUG("sendData - send 24 byte dummy data to the group");
GroupData data;
dtDelayStat.startRecord();
VectorStatistic vs("sendGroupData");
vs.record(GenericTime::currentTime());
dis->sendMessage(data);
}//End
/**
* @brief Starts the given test case.
* @param i The number of the test case to start.
*/
void
TestApplication::startTestCase(unsigned int i) {
switch (i) {
case 0:
testCase00();
break;
case 1:
testCase01();
break;
case 2:
testCase02();
break;
case 3:
testCase03();
break;
case 4:
testCase04();
break;
case 5:
testCase05();
break;
case 6:
testCase06();
break;
case 7:
testCase07();
break;
case 8:
testCase08();
break;
case 9:
testCase09();
break;
case 10:
testCase10();
break;
case 11:
testCase11();
break;
case 12:
testCase12();
break;
case 13:
testCase13();
break;
case 14:
testCase14();
break;
case 15:
testCase15();
break;
case 16:
testCase16();
break;
case 17:
testCase17();
break;
case 18:
testCase18();
break;
case 19:
testCase19();
break;
case 20:
testCase20();
break;
case 21:
testCase21();
break;
case 22:
testCase22();
break;
default:
break;
}//End switch
}//End startTestCase
/**
* @brief Executes test case 00
*/
void
TestApplication::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 (candidates.size() > 0) {
if (waitCounter > 0) {
waitCounter--;
module.scheduleTestCase(45);
}
if (candidatesIndex < candidates.size()) {
invitePeer(candidates.get(candidatesIndex++));
module.scheduleTestCase(45);
}
module.scheduleTestCase(45);
}//End if
}//End if
}
/**
* @brief Execute testcase01: every tc 1, 1 peer leaving + rejoining
*/
void
TestApplication::testCase01() {
DEBUG("TC 1 ");
int moduleIndex = module.getLocalAddress().getHostAddress().get4().getDByte(3);
if (initApp) {
candidates = OmnetppIniUtils::getDestinationAddressesFromOmnetppIni(module);
createRoster();
initApp = false;
if (moduleIndex == 1) {
module.scheduleTestCase(82);
}//End if
if (moduleIndex == 2) {
module.scheduleTestCase(88);
}
}//End if
else {
// leave at 92
if (moduleIndex == 1) {
leaveGroup();
}
//invite at 98
if (moduleIndex == 2) {
//
//we have more candidates?
if (candidates.size() > 0) {
if (candidatesIndex < candidates.size()) {
invitePeer(candidates.get(candidatesIndex++));
}
}//End if
}
}
}
/**
* @brief Execute testcase02: 6 peers, 2 peer leaving + rejoining
*/
void
TestApplication::testCase02() {
int moduleIndex = module.getLocalAddress().getHostAddress().get4().getDByte(3);
if (initApp) {
candidates = OmnetppIniUtils::getDestinationAddressesFromOmnetppIni(module);
createRoster();
initApp = false;
if (moduleIndex == 1 || moduleIndex == 2) {
module.scheduleTestCase(82);
}//End if
if (moduleIndex == 3) {
module.scheduleTestCase(88);
}
}//End if
else {
// leave at 92
if (moduleIndex == 1 || moduleIndex == 2) {
leaveGroup();
}
//invite at 98
if (moduleIndex == 3) {
//
//we have more candidates?
if (candidates.size() > 0) {
if (candidatesIndex < candidates.size()) {
invitePeer(candidates.get(candidatesIndex++));
module.scheduleTestCase(0.00000000000001);
}
}//End if
}
}
}
/**s
* @brief Execute testcase03: 6 peers, 3 peers leaving + rejoining
*/
void
TestApplication::testCase03() {
int moduleIndex = module.getLocalAddress().getHostAddress().get4().getDByte(3);
if (initApp) {
candidates = OmnetppIniUtils::getDestinationAddressesFromOmnetppIni(module);
createRoster();
initApp = false;
if (moduleIndex > 3) {
module.scheduleTestCase(82);
}//End if
if (moduleIndex == 1) {
module.scheduleTestCase(88);
}
}//End if
else {
// leave at 92
if (moduleIndex > 3) {
leaveGroup();
}
//invite at 98
if (moduleIndex == 1) {
//
//we have more candidates?
if (candidates.size() > 0) {
if (candidatesIndex < candidates.size()) {
invitePeer(candidates.get(candidatesIndex++));
module.scheduleTestCase(0.001);
}
}//End if
}
}
}
/**
* @brief Execute testcase04: every tc 21, 2 peers leaving + rejoining
*/
void
TestApplication::testCase04() {
int moduleIndex = module.getLocalAddress().getHostAddress().get4().getDByte(3);
if (initApp) {
candidates = OmnetppIniUtils::getDestinationAddressesFromOmnetppIni(module);
createRoster();
initApp = false;
if (moduleIndex == 10 || moduleIndex == 20) {
module.scheduleTestCase(82);
}//End if
if (moduleIndex == 1) {
module.scheduleTestCase(88);
}
}//End if
else {
// leave at 92
if (moduleIndex == 10 || moduleIndex == 20) {
leaveGroup();
}
//invite at 98
if (moduleIndex == 1) {
//
//we have more candidates?
if (candidates.size() > 0) {
if (candidatesIndex < candidates.size()) {
invitePeer(candidates.get(candidatesIndex++));
module.scheduleTestCase(0.01);
}
}//End if
}
}
}
/**
* @brief Execute testcase05: 12 peers, tc 22 (3 peers leaving + rejoining)
*/
void
TestApplication::testCase05() {
int moduleIndex = module.getLocalAddress().getHostAddress().get4().getDByte(3);
if (initApp) {
candidates = OmnetppIniUtils::getDestinationAddressesFromOmnetppIni(module);
createRoster();
initApp = false;
if (moduleIndex > 7 && moduleIndex < 11) {
module.scheduleTestCase(82);
}//End if
if (moduleIndex == 1) {
module.scheduleTestCase(88);
}
}//End if
else {
// leave at 92
if (moduleIndex > 7 && moduleIndex < 11) {
leaveGroup();
}
//invite at 98
if (moduleIndex == 1) {
//
//we have more candidates?
if (candidates.size() > 0) {
if (candidatesIndex < candidates.size()) {
invitePeer(candidates.get(candidatesIndex++));
module.scheduleTestCase(0.001);
}
}//End if
}
}
}
/**
* @brief Execute testcase06: 12 peers, tc 23
*/
void
TestApplication::testCase06() {
int moduleIndex = module.getLocalAddress().getHostAddress().get4().getDByte(3);
if (initApp) {
candidates = OmnetppIniUtils::getDestinationAddressesFromOmnetppIni(module);
createRoster();
initApp = false;
if (moduleIndex > 5 && moduleIndex < 11) {
module.scheduleTestCase(82 + moduleIndex * 0.01);
}//End if
if (moduleIndex == 1) {
module.scheduleTestCase(88);
}
}//End if
else {
// leave at 92
if (moduleIndex > 5 && moduleIndex < 11) {
leaveGroup();
}
//invite at 98
if (moduleIndex == 1) {
//
//we have more candidates?
if (candidates.size() > 0) {
if (candidatesIndex < candidates.size()) {
invitePeer(candidates.get(candidatesIndex++));
module.scheduleTestCase(0.01);
}
}//End if
}
}
}
/**
* @brief Execute testcase07: 12 peers, tc 3
*/
void
TestApplication::testCase07() {
int moduleIndex = module.getLocalAddress().getHostAddress().get4().getDByte(3);
if (initApp) {
candidates = OmnetppIniUtils::getDestinationAddressesFromOmnetppIni(module);
createRoster();
initApp = false;
if (moduleIndex > 4 && moduleIndex < 11) {
module.scheduleTestCase(82 + moduleIndex * 0.01);
}//End if
if (moduleIndex == 1) {
module.scheduleTestCase(88);
}
}//End if
else {
// leave at 92
if (moduleIndex > 4 && moduleIndex < 11) {
leaveGroup();
}
//invite at 98
if (moduleIndex == 1) {
//
//we have more candidates?
if (candidates.size() > 0) {
if (candidatesIndex < candidates.size()) {
invitePeer(candidates.get(candidatesIndex++));
module.scheduleTestCase(0.01);
}
}//End if
}
}
}
/**
* @brief Execute testcase08: 24 tc 22
*/
void
TestApplication::testCase08() {
int moduleIndex = module.getLocalAddress().getHostAddress().get4().getDByte(3);
if (initApp) {
candidates = OmnetppIniUtils::getDestinationAddressesFromOmnetppIni(module);
createRoster();
initApp = false;
if (moduleIndex < 3 || (moduleIndex > 10 && moduleIndex < 13) || (moduleIndex > 20 && moduleIndex < 23)) {
module.scheduleTestCase(82 + (candidatesIndex++)*0.01);
}//End if
if (moduleIndex == 3) {
module.scheduleTestCase(88);
}
}//End if
else {
// leave at 92
if (moduleIndex != 3) {
leaveGroup();
}
else {
//
//we have more candidates?
if (candidates.size() > 0) {
if (candidatesIndex < candidates.size()) {
invitePeer(candidates.get(candidatesIndex++));
module.scheduleTestCase(0.01);
}
}//End if
}
}
}
/**
* @brief Execute testcase09: 24, tc23
*/
void
TestApplication::testCase09() {
int moduleIndex = module.getLocalAddress().getHostAddress().get4().getDByte(3);
if (initApp) {
candidates = OmnetppIniUtils::getDestinationAddressesFromOmnetppIni(module);
createRoster();
initApp = false;
if (moduleIndex < 4 || moduleIndex == 5 || (moduleIndex > 10 && moduleIndex < 14) ||
moduleIndex == 15 || (moduleIndex > 20 && moduleIndex < 24)) {
module.scheduleTestCase(82 + (candidatesIndex++)*0.01);
}//End if
if (moduleIndex == 4) {
module.scheduleTestCase(88);
}
}//End if
else {
// leave at 92
if (moduleIndex != 4) {
leaveGroup();
}
else {
//
//we have more candidates?
if (candidates.size() > 0) {
if (candidatesIndex < candidates.size()) {
invitePeer(candidates.get(candidatesIndex++));
module.scheduleTestCase(0.01);
}
}//End if
}
}
}
/**
* @brief Execute testcase10: 24 tc3
*/
void
TestApplication::testCase10() {
int moduleIndex = module.getLocalAddress().getHostAddress().get4().getDByte(3);
if (initApp) {
candidates = OmnetppIniUtils::getDestinationAddressesFromOmnetppIni(module);
createRoster();
initApp = false;
if ((moduleIndex > 2 && moduleIndex < 8) || (moduleIndex > 12 && moduleIndex < 18) ||
(moduleIndex > 22)) {
module.scheduleTestCase(82 + (candidatesIndex++)*0.01);
}//End if
if (moduleIndex == 1) {
module.scheduleTestCase(88);
}
}//End if
else {
// leave at 92
if (moduleIndex != 1) {
leaveGroup();
}
else {
//
//we have more candidates?
if (candidates.size() > 0) {
if (candidatesIndex < candidates.size()) {
invitePeer(candidates.get(candidatesIndex++));
module.scheduleTestCase(0.01);
}
}//End if
}
}
}
/**
* @brief Execute testcase11: 48 tc22
*/
void
TestApplication::testCase11() {
int moduleIndex = module.getLocalAddress().getHostAddress().get4().getDByte(3);
if (initApp) {
candidates = OmnetppIniUtils::getDestinationAddressesFromOmnetppIni(module);
createRoster();
initApp = false;
if ((moduleIndex > 6 && moduleIndex < 9) || moduleIndex == 10 ||
(moduleIndex > 16 && moduleIndex < 19) || moduleIndex == 20 ||
(moduleIndex > 26 && moduleIndex < 29) || (moduleIndex > 36 && moduleIndex < 39) ||
moduleIndex > 46) {
module.scheduleTestCase(82 + (candidatesIndex++)*0.01);
}//End if
if (moduleIndex == 1) {
module.scheduleTestCase(88);
}
}//End if
else {
// leave at 92
if (moduleIndex != 1) {
leaveGroup();
}
else {
//
//we have more candidates?
if (candidates.size() > 0) {
if (candidatesIndex < candidates.size()) {
invitePeer(candidates.get(candidatesIndex++));
module.scheduleTestCase(0.01);
}
}//End if
}
}
}
/**
* @brief Execute testcase12: 48 tc23
*/
void
TestApplication::testCase12() {
int moduleIndex = module.getLocalAddress().getHostAddress().get4().getDByte(3);
if (initApp) {
candidates = OmnetppIniUtils::getDestinationAddressesFromOmnetppIni(module);
createRoster();
initApp = false;
if ((moduleIndex > 5 && moduleIndex < 11) || (moduleIndex > 15 && moduleIndex < 21) || moduleIndex == 20 ||
(moduleIndex > 25 && moduleIndex < 31) || (moduleIndex > 35 && moduleIndex < 41) ||
moduleIndex > 45) {
module.scheduleTestCase(82 + (moduleIndex * 0.01));
}//End if
if (moduleIndex == 1) {
module.scheduleTestCase(88);
}
}//End if
else {
// leave at 92
if (moduleIndex != 1) {
leaveGroup();
}
else {
//
//we have more candidates?
if (candidates.size() > 0) {
if (candidatesIndex < candidates.size()) {
invitePeer(candidates.get(candidatesIndex++));
module.scheduleTestCase(0.01);
}
}//End if
}
}
}
/**
* @brief Execute testcase13: 48 tc 3
*/
void
TestApplication::testCase13() {
int moduleIndex = module.getLocalAddress().getHostAddress().get4().getDByte(3);
if (initApp) {
candidates = OmnetppIniUtils::getDestinationAddressesFromOmnetppIni(module);
createRoster();
initApp = false;
if ((moduleIndex > 4 && moduleIndex < 10) || (moduleIndex > 14 && moduleIndex < 20) ||
(moduleIndex > 24 && moduleIndex < 30) || (moduleIndex > 34 && moduleIndex < 40) ||
moduleIndex > 44) {
module.scheduleTestCase(82 + (moduleIndex * 0.01));
}//End if
if (moduleIndex == 1) {
module.scheduleTestCase(88);
}
}//End if
else {
// leave at 92
if (moduleIndex != 1) {
leaveGroup();
}
else {
//
//we have more candidates?
if (candidates.size() > 0) {
if (candidatesIndex < candidates.size()) {
invitePeer(candidates.get(candidatesIndex++));
module.scheduleTestCase(0.01);
}
}//End if
}
}
}
/**
* @brief Execute testcase14: 72 tc 22
*/
void
TestApplication::testCase14() {
int moduleIndex = module.getLocalAddress().getHostAddress().get4().getDByte(3);
if (initApp) {
candidates = OmnetppIniUtils::getDestinationAddressesFromOmnetppIni(module);
createRoster();
initApp = false;
if (moduleIndex < 3 || (moduleIndex > 9 && moduleIndex < 13) ||
(moduleIndex > 19 && moduleIndex < 23) || (moduleIndex > 30 && moduleIndex < 33) ||
(moduleIndex > 40 && moduleIndex < 43) || (moduleIndex > 50 && moduleIndex < 53) ||
(moduleIndex > 60 && moduleIndex < 63) || moduleIndex > 70) {
module.scheduleTestCase(82 + (moduleIndex * 0.01));
}//End if
if (moduleIndex == 3) {
module.scheduleTestCase(88);
}
}//End if
else {
// leave at 92
if (moduleIndex != 3) {
leaveGroup();
}
else {
//
//we have more candidates?
if (candidates.size() > 0) {
if (candidatesIndex < candidates.size()) {
invitePeer(candidates.get(candidatesIndex++));
module.scheduleTestCase(0.01);
}
}//End if
}
}
}
/**
* @brief Execute testcase15: 72 tc 23
*/
void
TestApplication::testCase15() {
int moduleIndex = module.getLocalAddress().getHostAddress().get4().getDByte(3);
if (initApp) {
candidates = OmnetppIniUtils::getDestinationAddressesFromOmnetppIni(module);
createRoster();
initApp = false;
if ((moduleIndex > 5 && moduleIndex < 11) || (moduleIndex > 15 && moduleIndex < 21) ||
(moduleIndex > 25 && moduleIndex < 31) || (moduleIndex > 35 && moduleIndex < 41) ||
(moduleIndex > 45 && moduleIndex < 51) || (moduleIndex > 55 && moduleIndex < 61) ||
(moduleIndex > 65 && moduleIndex < 71)) {
module.scheduleTestCase(82 + (moduleIndex * 0.01));
}//End if
if (moduleIndex == 1) {
module.scheduleTestCase(88);
}
}//End if
else {
// leave at 92
if (moduleIndex != 1) {
leaveGroup();
}
else {
//
//we have more candidates?
if (candidates.size() > 0) {
if (candidatesIndex < candidates.size()) {
invitePeer(candidates.get(candidatesIndex++));
module.scheduleTestCase(0.01);
}
}//End if
}
}
}
/**
* @brief Execute testcase16: 72 tc 3
*/
void
TestApplication::testCase16() {
int moduleIndex = module.getLocalAddress().getHostAddress().get4().getDByte(3);
if (initApp) {
candidates = OmnetppIniUtils::getDestinationAddressesFromOmnetppIni(module);
createRoster();
initApp = false;
if (moduleIndex == 1 || (moduleIndex > 6 && moduleIndex < 12) || (moduleIndex > 16 && moduleIndex < 22) ||
(moduleIndex > 26 && moduleIndex < 32) || (moduleIndex > 36 && moduleIndex < 42) ||
(moduleIndex > 46 && moduleIndex < 52) || (moduleIndex > 56 && moduleIndex < 62) ||
(moduleIndex > 66 && moduleIndex < 72)) {
module.scheduleTestCase(82 + (moduleIndex * 0.015));
}//End if
if (moduleIndex == 2) {
module.scheduleTestCase(88);
}
}//End if
else {
// leave at 92
if (moduleIndex != 2) {
leaveGroup();
}
else {
//
//we have more candidates?
if (candidates.size() > 0) {
if (candidatesIndex < candidates.size()) {
invitePeer(candidates.get(candidatesIndex++));
module.scheduleTestCase(0.01);
}
}//End if
}
}
}
/**
* @brief Execute testcase17: 96 tc22
*/
void
TestApplication::testCase17() {
int moduleIndex = module.getLocalAddress().getHostAddress().get4().getDByte(3);
if (initApp) {
candidates = OmnetppIniUtils::getDestinationAddressesFromOmnetppIni(module);
createRoster();
initApp = false;
if ((moduleIndex > 2 && moduleIndex < 5) || moduleIndex == 10 || (moduleIndex > 12 && moduleIndex < 15) ||
moduleIndex == 20 || (moduleIndex > 22 && moduleIndex < 25) || moduleIndex == 30 || (moduleIndex > 32 && moduleIndex < 35) ||
moduleIndex == 40 || (moduleIndex > 42 && moduleIndex < 45) || (moduleIndex > 52 && moduleIndex < 55) ||
(moduleIndex > 62 && moduleIndex < 65) || (moduleIndex > 72 && moduleIndex < 75) ||
(moduleIndex > 82 && moduleIndex < 85) || (moduleIndex > 92 && moduleIndex < 95)) {
module.scheduleTestCase(82 + (moduleIndex * 0.03));
}//End if
if (moduleIndex == 1) {
module.scheduleTestCase(88);
}
}//End if
else {
// leave at 92
if (moduleIndex != 1) {
leaveGroup();
}
else {
//
//we have more candidates?
if (candidates.size() > 0) {
if (candidatesIndex < candidates.size()) {
invitePeer(candidates.get(candidatesIndex++));
module.scheduleTestCase(0.03);
}
}//End if
}
}
}
/**
* @brief Execute testcase18: 96 tc 23
*/
void
TestApplication::testCase18() {
int moduleIndex = module.getLocalAddress().getHostAddress().get4().getDByte(3);
if (initApp) {
candidates = OmnetppIniUtils::getDestinationAddressesFromOmnetppIni(module);
createRoster();
initApp = false;
if (moduleIndex < 5 || (moduleIndex > 9 && moduleIndex < 15) ||
(moduleIndex > 19 && moduleIndex < 25) || (moduleIndex > 29 && moduleIndex < 35) ||
(moduleIndex > 39 && moduleIndex < 45) || (moduleIndex > 49 && moduleIndex < 55) ||
(moduleIndex > 59 && moduleIndex < 65) || (moduleIndex > 69 && moduleIndex < 75) ||
(moduleIndex > 79 && moduleIndex < 85) || (moduleIndex > 89 && moduleIndex < 95)) {
module.scheduleTestCase(82 + (moduleIndex * 0.015));
}//End if
if (moduleIndex == 5) {
module.scheduleTestCase(88);
}
}//End if
else {
// leave at 92
if (moduleIndex != 5) {
leaveGroup();
}
else {
//
//we have more candidates?
if (candidates.size() > 0) {
if (candidatesIndex < candidates.size()) {
invitePeer(candidates.get(candidatesIndex++));
module.scheduleTestCase(0.015);
}
}//End if
}
}
}
/**
* @brief Execute testcase19: 96 tc3
*/
void
TestApplication::testCase19() {
int moduleIndex = module.getLocalAddress().getHostAddress().get4().getDByte(3);
if (initApp) {
candidates = OmnetppIniUtils::getDestinationAddressesFromOmnetppIni(module);
createRoster();
initApp = false;
if ((moduleIndex > 3 && moduleIndex < 9) || (moduleIndex > 13 && moduleIndex < 19) ||
(moduleIndex > 23 && moduleIndex < 29) || (moduleIndex > 33 && moduleIndex < 39) ||
(moduleIndex > 43 && moduleIndex < 49) || (moduleIndex > 53 && moduleIndex < 59) ||
(moduleIndex > 63 && moduleIndex < 69) || (moduleIndex > 73 && moduleIndex < 79) ||
(moduleIndex > 83 && moduleIndex < 89) || (moduleIndex > 93)) {
module.scheduleTestCase(82 + (moduleIndex * 0.015));
}//End if
if (moduleIndex == 1) {
module.scheduleTestCase(88);
}
}//End if
else {
// leave at 92
if (moduleIndex != 1) {
leaveGroup();
}
else {
//
//we have more candidates?
if (candidates.size() > 0) {
if (candidatesIndex < candidates.size()) {
invitePeer(candidates.get(candidatesIndex++));
module.scheduleTestCase(0.02);
}
}//End if
}
}
}
/**
* @brief: Micha's testcase: all 96 peer alone in their "partition"
*/
void
TestApplication::testCase20() {
int moduleIndex = module.getLocalAddress().getHostAddress().get4().getDByte(3);
if (initApp) {
candidates = OmnetppIniUtils::getDestinationAddressesFromOmnetppIni(module);
waitCounter = 5;
initApp = false;
}//End if
//------------------------------------------------------------------
//run the app
//------------------------------------------------------------------
if (moduleIndex == 1) { // starts counting at 1
//we have more candidates?
if (candidates.size() > 0) {
if (candidatesIndex < candidates.size()) {
invitePeer(candidates.get(candidatesIndex++));
module.scheduleTestCase(0.02);
}
}//End if
}//End if
}
void
TestApplication::testCase21() {
int moduleIndex = module.getLocalAddress().getHostAddress().get4().getDByte(3);
//------------------------------------------------------------------
//run the app
//------------------------------------------------------------------
if (moduleIndex == 1) { // starts counting at 1
Roster roster;
roster.setNextPeerID(5);
//roster.setNumberOfClusters(3);
roster.setViewID(10);
PeerDescription dummyPDesc;
PeerResources dummyPRes;
TransportAddress ta = getNewTransportAddress(1);
ta.setPort(module.getLocalAddress().getPort());
MemberDescription mDesc1(1, ta, JOINED, 0, dummyPDesc, dummyPRes);
roster.addMemberDescription(mDesc1);
ta.setPort(module.getLocalAddress().getPort());
MemberDescription mDesc2(2, ta, JOINED, 1, dummyPDesc, dummyPRes);
roster.addMemberDescription(mDesc2);
ta.setPort(module.getLocalAddress().getPort());
MemberDescription mDesc3(3, ta, JOINED, 2, dummyPDesc, dummyPRes);
roster.addMemberDescription(mDesc3);
dis->setupGroupFromRoster(roster, module.getLocalAddress().getHostAddress().get4().getDByte(3));
TransportAddress ta2(IPvXAddress("192.168.0.3"), module.getLocalAddress().getPort());
invitePeer(ta2);
}//End if
}
/**
* @brief Method to create a roster from which the group is set up.
*/
void
TestApplication::createRoster() {
int numberOfAllPeers = numberOfPeers + numberOfMobilePeers;
Roster roster;
roster.setNextPeerID(numberOfAllPeers + 1);
// roster.setNumberOfClusters(clusterSize);
roster.setViewID(numberOfAllPeers + 1);
PeerDescription dummyPDesc;
PeerResources dummyPRes;
ClusterID cID = 0;
if (clusterSize <= 1) {
// necessary to make sure if the numberOfPeers is equal or smaller than
// the maxPeerCount that only one cluster is created!
// roster.setNumberOfClusters(1);
roster.setViewID(numberOfAllPeers + 1);
roster.setNextPeerID(numberOfAllPeers + 1);
}
for (int i = 1; i <= numberOfAllPeers; i++) {
TransportAddress ta = getNewTransportAddress(i);
ta.setPort(module.getLocalAddress().getPort());
MemberDescription mDesc(i, ta, JOINED, cID, dummyPDesc, dummyPRes);
roster.addMemberDescription(mDesc);
if ((i % module.getMaxPeerCount()) == 0) {
cID++;
}//End if
}
dis->setupGroupFromRoster(roster, module.getLocalAddress().getHostAddress().get4().getDByte(3));
}
/**
* @brief Getting a transportAddress for a given index.
* @param i The index of the peer a TA is searched for.
* @return The created TA.
*/
TransportAddress
TestApplication::getNewTransportAddress(int i) {
std::stringstream taStream;
taStream << "192.168.0." << i;
std::string s(taStream.str());
return TransportAddress(IPvXAddress(s.c_str()));
}
/**
* @brief Callback method. This method is called by moversight to signal that the local peer have receive a group data message.
* @param dat The received group data.
* @param sender The sending peer ID.
*/
void
TestApplication::receiveGroupData(const GroupData & dat, const PeerID sender) {
std::stringstream buf;
buf << "receiveGroupData - receive group data from peer ID " << sender;
DEBUG(buf.str().c_str());
dtDelayStat.stopRecord();
VectorStatistic vs("receiveGroupData");
vs.record(GenericTime::currentTime());
}
void
TestApplication::testCase22() {
int moduleIndex = module.getLocalAddress().getHostAddress().get4().getDByte(3);
if (initApp) {
candidates = OmnetppIniUtils::getDestinationAddressesFromOmnetppIni(module);
waitCounter = 5;
initApp = false;
}//End if
//------------------------------------------------------------------
//run the app
//------------------------------------------------------------------
if (moduleIndex == 1) { // starts counting at 1
//we have more candidates?
if (candidates.size() > 0) {
if (candidatesIndex < candidates.size()) {
std::cerr << "peer " << moduleIndex << " invitePeer " << candidates.get(candidatesIndex) << "\n";
invitePeer(candidates.get(candidatesIndex++));
module.scheduleTestCase(10);
}
}//End if
}//End if
if (moduleIndex == 2) { // starts counting at 1
if (groupSize >= 2) {
//we have more candidates?
if (candidates.size() > 0) {
if (candidatesIndex < candidates.size()) {
std::cerr << "peer " << moduleIndex << " invitePeer " << candidates.get(candidatesIndex) << "\n";
invitePeer(candidates.get(candidatesIndex++));
}
}
}//End if
module.scheduleTestCase(10);
}//End if
}
/**
* @brief Callback method. This method is called by moversight to signal
* that a the local instance have received an invitation.
* @param invitation The received invitation.
*/
void
TestApplication::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 Callback method. This method is called by moversight to signal that the remote peer have accepted the invitation from the local peer.
* @param inv The corresponding invitation.
* @param pDesc The provided peer description of the remote peer.
* @param message A short application message from the remote peer, used to introduce itself within the group.
*/
void
TestApplication::handleEvent(const JoinConfirmEvent & e) {
std::stringstream buf;
buf << "receiveInvitationResponse - 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());
}
/**
* @brief Callback method. This method is called by moversight to signal that the invitation process is aborted.
* @param inv The corresponding invitation.
* @param reason The abort reason.
*/
void
TestApplication::handleEvent(const JoinRejectedEvent & e) {
std::stringstream buf;
buf << "invitationAborted - invitation ID " << e.getInvitation().getInvitationID() << " aborted";
buf << " reason: " << e.getReason();
DEBUG(buf.str().c_str());
}
/**
* @brief Callback method. This method is called by moversight to signal that the invitation process is aborted.
* @param ta The transport address of the peer to invite.
* @param reason The abort reason.
*/
void
TestApplication::handleEvent(const JoinAbortedEvent & e) {
std::stringstream buf;
buf << "invitationAborted - invitation to peer " << e.getTransportAddress() << " aborted";
buf << " reason: " << e.getReason();
DEBUG(buf.str().c_str());
}
void
TestApplication::handleEvent(const GroupCreatedEvent & e) {
groupSize = 1;
groupSizeStat.record(groupSize);
PeerResources myResources(100);
dis->setLocalPeerResources(myResources);
}
/**
* @brief Called, if the group closed.
*/
void
TestApplication::handleEvent(const GroupClosedEvent & e) {
DEBUG("group closed");
leaveDelayStat.stopRecord();
}
void
TestApplication::handleEvent(const PeerJoinedEvent & e) {
std::stringstream buf;
buf << "peerJoined - peer " << e.getPeerID() << "@TA_" << e.getTransportAddress() << " joined group successfully (" << e.getDescription().getDescription() << ")";
DEBUG(buf.str().c_str());
dis->signal(new StopMeasuringEvent("REJOIN"));
joinDelayStat.stopRecord();
groupSizeStat.record(++groupSize);
}
/**
* @brief Signals, that a dedicated peer is pending.
* @param pId The id of the pending peer.
* @param ta The transport address of the pending peer. - TODO not needed!!
*/
void
TestApplication::handleEvent(const PendingPeersEvent & e) {
std::stringstream buf;
buf << "peerIsPending - peer " << e.getPeerIDList() << " is pending";
DEBUG(buf.str().c_str());
}
/**
* @brief Signal the reconnection of the pending peer.
* @param pId The peer ID of the reconnected peer.
* @param ta Its transport address. - TODO not needed either
*/
void
TestApplication::handleEvent(const PeerReconnectedEvent & e) {
std::stringstream buf;
buf << "peerReconnected - peer " << e.getPeerID() << " is reconnected";
DEBUG(buf.str().c_str());
}
/**
* @brief Signals, that a dedicated peer has left the group.
* @param peer The left peer.
*/
void
TestApplication::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());
groupSizeStat.record(--groupSize);
dis->signal(new StartMeasuringEvent("TG"));
}
/**
* @brief Starts the measuring of the given parameter.
* @param s The measurement to start measuring.
*/
void
TestApplication::handleEvent(const StartMeasuringEvent & e) {
std::string startS = "start" + e.getMeasurement();
VectorStatistic vs(startS.c_str());
if (e.getMeasurement() == "REJOIN") {
vs.record(GenericTime::currentTime());
rejoinSuccessDuration.startRecord();
}
if (e.getMeasurement() == "TG") {
vs.record(GenericTime::currentTime());
leaveDelayStat.startRecord();
}
}
/**
* @brief Starts the measuring of the given parameter.
* @param s The measurement to start measuring.
*/
void
TestApplication::handleEvent(const StopMeasuringEvent & e) {
std::string startS = "stop" + e.getMeasurement();
VectorStatistic vs(startS.c_str());
if (e.getMeasurement() == "REJOIN") {
vs.record(GenericTime::currentTime());
rejoinSuccessDuration.startRecord();
}
if (e.getMeasurement() == "TG") {
vs.record(GenericTime::currentTime());
leaveDelayStat.stopRecord();
}
}
}//End namespace moversight
}//End namespace ubeeme