-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetworkTreeBehavior.cpp
More file actions
59 lines (42 loc) · 2.5 KB
/
NetworkTreeBehavior.cpp
File metadata and controls
59 lines (42 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "NetworkBehavior.hpp"
using namespace omnetpp;
class NetworkTreeBehavior : public NetworkBehavior
{
public:
NetworkTreeBehavior();
protected:
virtual std::set<std::tuple<std::string,std::string>> handleEvent_partition() override;
virtual void handleEvent_endPartition(std::set<std::tuple<std::string,std::string>> gates) override;
};
Define_Module(NetworkTreeBehavior);
NetworkTreeBehavior::NetworkTreeBehavior() : NetworkBehavior() {}
std::set<std::tuple<std::string,std::string>> NetworkTreeBehavior::handleEvent_partition() {
std::set<std::tuple<std::string, std::string>> gates;
int numClients = this->getParentModule()->par("numClients");
int client = uniform(1, numClients - 1);
cGate *in = this->getParentModule()->getModuleByPath(("client[" + std::to_string(client) + "]").c_str())->gate("in_parent");
cGate *out = this->getParentModule()->getModuleByPath(("client[" + std::to_string(client) + "]").c_str())->gate("out_parent");
gates.insert(std::make_tuple(out->getFullPath(), out->getNextGate()->getFullPath()));
gates.insert(std::make_tuple(in->getPreviousGate()->getFullPath(), in->getFullPath()));
for(std::tuple<std::string,std::string> gate : gates) {
std::string modulePath0 = std::get<0>(gate).substr(0, std::get<0>(gate).rfind("."));
std::string gateName0 = std::get<0>(gate).substr(std::get<0>(gate).rfind(".") + 1);
cGate *gate0 = this->getParentModule()->getModuleByPath(modulePath0.c_str())->gate(gateName0.c_str());
gate0->disconnect();
}
return gates;
}
void NetworkTreeBehavior::handleEvent_endPartition(std::set<std::tuple<std::string, std::string>> gates) {
for(std::tuple<std::string,std::string> gate : gates) {
std::string modulePath0 = std::get<0>(gate).substr(0, std::get<0>(gate).rfind("."));
std::string gateName0 = std::get<0>(gate).substr(std::get<0>(gate).rfind(".") + 1);
std::string modulePath1 = std::get<1>(gate).substr(0, std::get<1>(gate).rfind("."));
std::string gateName1 = std::get<1>(gate).substr(std::get<1>(gate).rfind(".") + 1);
cChannel *channel = cDelayChannel::create("channel");
channel->par("delay").setDoubleValue(this->linkDelay);
cGate *gate0 = this->getParentModule()->getModuleByPath(modulePath0.c_str())->gate(gateName0.c_str());
cGate *gate1 = this->getParentModule()->getModuleByPath(modulePath1.c_str())->gate(gateName1.c_str());
gate0->connectTo(gate1, channel);
}
return;
}