26 #include <UDPControlInfo_m.h>
27 #include <IPAddressResolver.h>
63 (getParentModule()->getSubmodule(
"keyListModule"));
65 (getParentModule()->getSubmodule(
"neighbors"));
67 (getParentModule()->getSubmodule(
"tokenFactory"));
142 cModule* nodeModule = getParentModule()->getParentModule();
144 if(!nodeModule->hasGate(
"pppg$i"))
145 capacity += uniform(1,800000);
148 int gateSize = nodeModule->gateSize(
"pppg$i");
149 for (
int i=0; i<gateSize; i++) {
150 cGate* currentGate = nodeModule->gate(
"pppg$i",i);
151 if (currentGate->isConnected())
152 capacity += check_and_cast<cDatarateChannel *>
153 (currentGate->getPreviousGate()->getChannel())->getDatarate()
168 EV <<
"(Gia) Node details: " <<
thisGiaNode << endl;
190 getParentModule()->getParentModule()->bubble(
"Enter INIT state.");
247 std::stringstream ttString;
250 ttString <<
thisNode <<
"\n# Neighbors: "
253 getParentModule()->getParentModule()->getDisplayString().
254 setTagArg(
"tt", 0, ttString.str().c_str());
255 getParentModule()->getDisplayString().
256 setTagArg(
"tt", 0, ttString.str().c_str());
257 getDisplayString().setTagArg(
"tt", 0, ttString.str().c_str());
265 }
else if (msg->isName(
"satisfaction_timer")) {
301 }
else if (msg->isName(
"update_timer")) {
306 }
else if (msg->isName(
"timedoutMessages_timer")) {
311 }
else if (msg->isName(
"timedoutNeighbors_timer")) {
320 }
else if (msg->isName(
"sendKeyList_timer")) {
329 const std::string
id = msg->getName();
330 if (
id.substr(0, 16) == std::string(
"wait-for-token: ")) {
331 cPacket* packet = check_and_cast<cPacket*>(msg);
332 cMessage* decapsulatedMessage = packet->decapsulate();
333 if (dynamic_cast<GiaIDMessage*>(decapsulatedMessage) != NULL) {
335 (decapsulatedMessage);
338 }
else if (
id.substr(0, 24) == std::string(
"wait-for-token-fromapp: ")) {
339 cPacket* packet = check_and_cast<cPacket*>(msg);
340 cMessage* decapsulatedMessage = packet->decapsulate();
341 if (dynamic_cast<GiaIDMessage*>(decapsulatedMessage) != NULL) {
343 (decapsulatedMessage);
354 EV <<
"(Gia) " <<
thisGiaNode <<
" received udp message" << endl;
356 cPolymorphic* ctrlInfo = msg->removeControlInfo();
361 if (dynamic_cast<TokenMessage*>(msg) != NULL) {
367 EV <<
"(Gia) Received Tokenmessage from "
378 else if (dynamic_cast<GiaRouteMessage*>(msg) != NULL) {
385 EV <<
"(Gia) Received ROUTE::IND from " << oppositeNode << endl;
396 else if (dynamic_cast<KeyListMessage*>(msg) != NULL) {
404 <<
" received KEYLIST:IND message" << endl;
408 for (uint32_t k = 0; k < keyListSize; k++)
416 else if (dynamic_cast<SearchMessage*>(msg) != NULL) {
432 else if (dynamic_cast<SearchResponseMessage*>(msg) != NULL) {
439 else if (dynamic_cast<GiaMessage*>(msg) != NULL) {
447 EV <<
"(Gia) " <<
thisGiaNode <<
" received GIA- message from "
448 << oppositeNode << endl;
455 <<
" received JOIN:REQ message" << endl;
462 << oppositeNode << endl;
470 EV <<
"(Gia) " <<
thisGiaNode <<
" received JOIN:RSP message"
479 for(uint32_t i = 0; i < msg->getNeighborsArraySize(); i++) {
480 GiaNode temp = msg->getNeighbors(i);
489 << oppositeNode << endl;
498 EV <<
"(Gia) " <<
thisGiaNode <<
" received JOIN:ACK message"
508 for(uint32_t i = 0; i < msg->getNeighborsArraySize(); i++) {
509 GiaNode temp = msg->getNeighbors(i);
522 EV <<
"(Gia) " <<
thisGiaNode <<
" received JOIN:DNY message"
535 EV <<
"(Gia) " <<
thisGiaNode <<
" received DISCONNECT:IND message" << endl;
542 EV <<
"(Gia) " <<
thisGiaNode <<
" received UPDATE:IND message"
553 <<
" Command: " << giaMsg->
getCommand() << endl
583 << dropCandidate << endl;
597 EV <<
"(Gia) " <<
thisGiaNode <<
" accepted new neighbor " << node << endl;
598 getParentModule()->getParentModule()->bubble(
"New neighbor");
601 if (stat_maxNeighbors < neighbors->getSize()) {
617 "m=m,50,0,50,0;ls=red,1");
626 EV <<
"(Gia) " <<
thisGiaNode <<
" removes " << node
627 <<
" from neighborlist." << endl;
652 for (uint32_t i=0; i < neighborsCount; i++)
658 if ((levelOfSatisfaction > 1.0) || (neighborsCount >=
maxNeighbors))
672 msg->setBitLength(
GIA_L(msg));
738 msg->setBitLength(
GIA_L(msg));
756 msg->setBitLength(
GIA_L(msg));
772 msg->setBitLength(
GIA_L(msg));
811 tokenMsg->setBitLength(
TOKEN_L(tokenMsg));
834 if (reversePathArraySize == 0) {
841 reversePathArraySize-1));
846 for (uint32_t i=0; i<reversePathArraySize-1; i++)
848 responseMsg->setBitLength(responseMsg->getBitLength() -
KEY_L);
855 responseMsg->getByteLength());
859 EV <<
"(Gia) wrong reverse path in " << *responseMsg
860 <<
" ... deleted!" << endl;
876 if (!fromApplication)
887 EV <<
"(Gia) Deliver messsage " << msg
899 msg->setControlInfo(overlayCtrlInfo);
913 EV <<
"(Gia) No free Node, wait for free token" << endl;
917 if (!fromApplication)
920 id =
"wait-for-token-fromapp: " +
922 cPacket* wait_timer =
new cPacket(
id.c_str());
923 wait_timer->encapsulate(msg);
937 EV <<
"(Gia) Forwarding message " << msg
938 <<
" to neighbor " << targetNode << endl;
939 if (!fromApplication)
947 msg->getByteLength());
960 EV <<
"(Gia) No free Node, wait for free token" << endl;
962 if (!fromApplication)
965 id =
"wait-for-token-fromapp: " +
967 cPacket* wait_timer =
new cPacket(
id.c_str());
968 wait_timer->encapsulate(msg);
973 if(nextHopInfo == NULL) {
987 EV <<
"(Gia) Forwarding message " << msg
988 <<
" to " << nextHop << endl;
989 if (!fromApplication)
997 msg->getByteLength());
1008 const std::vector<TransportAddress>& sourceRoute,
1012 throw cRuntimeError(
"Gia::getRoute(): Works currently "
1013 "only with srcComp=destComp=TIER1_COMP!");
1029 routeMsg->setBitLength(
GIAROUTE_L(routeMsg));
1030 routeMsg->encapsulate(msg);
1043 if (dynamic_cast<GIAput*>(msg) != NULL) {
1046 for (uint32_t k=0; k<keyListSize; k++)
1055 }
else if (dynamic_cast<GIAsearch*>(msg) != NULL) {
1059 searchMsg->setCommand(
SEARCH);
1068 searchMsg->setReversePathArraySize(0);
1070 searchMsg->setBitLength(
SEARCH_L(searchMsg));
1079 EV <<
"(Gia) unkown message from app deleted!" << endl;
1088 bool containsNode =
false;
1089 for (uint32_t i=0; i<foundNodeArraySize; i++)
1091 containsNode =
true;
1104 if (reversePathArraySize == 0) {
1127 responseMsg->setCommand(
ANSWER);
1129 responseMsg->setSrcNode(srcNode);
1130 responseMsg->setSrcCapacity(srcNode.
getCapacity());
1133 responseMsg->setFoundNode(srcNode);
1134 responseMsg->setReversePathArraySize(reversePathArraySize);
1135 for (uint32_t i=0; i<reversePathArraySize; i++)
1138 responseMsg->setSearchHopCount(reversePathArraySize);
1169 for (uint32_t i=0; i<reversePathSize; i++) {
1173 msg->setBitLength(msg->getBitLength() - (reversePathSize - i)*
KEY_L);
1174 reversePathSize = i;
1181 msg->setBitLength(msg->getBitLength() +
KEY_L);
1199 deliverMsg->setControlInfo(overlayCtrlInfo);
1204 send(deliverMsg,
"appOut");
1206 EV <<
"(Gia) Deliver search response " << msg