#include <Gia.h>
Implementation of the Gia overlay as described in "Making Gnutella-like P2P Systems Scalable" by Y. Chawathe et al. published at SIGCOMM'03
Public Member Functions | |
void | initializeOverlay (int stage) |
initializes base class-attributes | |
void | finishOverlay () |
Writes statistical data and removes node from bootstrap oracle. | |
virtual void | changeState (int toStage) |
Set state to toStage. | |
void | updateTooltip () |
Marks nodes if they are ready. | |
~Gia () | |
Destructor. | |
void | handleTimerEvent (cMessage *msg) |
Processes "timer" self-messages. | |
void | handleUDPMessage (BaseOverlayMessage *msg) |
Processes messages from underlay. | |
virtual void | route (const OverlayKey &key, CompType destComp, CompType srcComp, cMessage *msg, const std::vector< TransportAddress > &sourceRoute=TransportAddress::UNSPECIFIED_NODES, RoutingType routingType=DEFAULT_ROUTING) |
Routes message through overlay. | |
void | handleAppMessage (cMessage *msg) |
Processes non-commonAPI messages. | |
void | sendToken (const GiaNode &dst) |
Protected Member Functions | |
void | joinOverlay () |
Join the overlay with a given nodeID in thisNode.key. | |
bool | acceptNode (const GiaNode &newNode, unsigned int degree) |
Decides if Node newNode will be accepted as new neighor. | |
void | addNeighbor (GiaNode &newNode, unsigned int degree) |
Adds newNode as new neighbor. | |
void | removeNeighbor (const GiaNode &newNode) |
Removes newNode from our NeighborList. | |
double | calculateLevelOfSatisfaction () |
Calculates level of satisfaction. | |
void | sendMessage_JOIN_REQ (const NodeHandle &dst) |
Sends JOIN_REQ_Message from node src to node dst. | |
void | sendMessage_JOIN_RSP (const NodeHandle &dst) |
Sends JOIN_RSP_Message from node src to node dst. | |
void | sendMessage_JOIN_ACK (const NodeHandle &dst) |
Sends JOIN_ACK_Message from node src to node dst. | |
void | sendMessage_JOIN_DNY (const NodeHandle &dst) |
Sends JOIN_DNY_Message from node src to node dst. | |
void | sendMessage_DISCONNECT (const NodeHandle &dst) |
Sends DISCONNECT_Message from node src to node dst. | |
void | sendMessage_UPDATE (const NodeHandle &dst) |
Sends UPDATE_Message from node src to node dst. | |
void | sendKeyListToNeighbor (const NodeHandle &dst) |
Sends KeyList to node dst. | |
void | updateNeighborList (GiaMessage *msg) |
Updates neighborlist with new capacity and connectiondegree informations from received message msg. | |
void | forwardSearchResponseMessage (SearchResponseMessage *msg) |
Forwards a search response message to the next node in reverse-path. | |
void | forwardMessage (GiaIDMessage *msg, bool fromApplication) |
Forwards a message to the next random selected node, biased random walk. | |
void | processSearchMessage (SearchMessage *msg, bool fromApplication) |
Processes search message msg. | |
void | sendSearchResponseMessage (const GiaNode &srcNode, SearchMessage *msg) |
Sends a response message to a received search query. | |
void | deliverSearchResult (SearchResponseMessage *msg) |
Delivers search result to application layer. | |
Protected Attributes | |
uint | maxNeighbors |
maximum number of neighbors | |
uint | minNeighbors |
minimum number of neighbors | |
uint | maxTopAdaptionInterval |
maximum topology adaption interval | |
uint | topAdaptionAggressiveness |
the topology adaption aggressiveness | |
double | maxLevelOfSatisfaction |
maximum level of satisfaction | |
double | updateDelay |
time between to update messages (in ms) | |
uint | maxHopCount |
maximum time to live for sent messages | |
uint | messageTimeout |
timeout for messages | |
uint | neighborTimeout |
timeout for neighbors | |
uint | sendTokenTimeout |
timeout for tokens | |
uint | tokenWaitTime |
delay to send a new token | |
double | keyListDelay |
delay to send the keylist to our neighbors | |
bool | outputNodeDetails |
output of node details? (on std::cout) | |
bool | optimizeReversePath |
use optimized reverse path? | |
double | levelOfSatisfaction |
current level of statisfaction | |
unsigned int | connectionDegree |
unsigned int | receivedTokens |
unsigned int | sentTokens |
GiaNode | thisGiaNode |
this node | |
NodeHandle | bootstrapNode |
next possible neighbor candidate | |
GiaMessageBookkeeping * | msgBookkeepingList |
pointer to a message bookkeeping list | |
uint | stat_joinCount |
number of sent join messages | |
uint | stat_joinBytesSent |
number of sent bytes of join messages | |
uint | stat_joinREQ |
number of sent join request messages | |
uint | stat_joinREQBytesSent |
number of sent bytes of join request messages | |
uint | stat_joinRSP |
number of sent join response messages | |
uint | stat_joinRSPBytesSent |
number of sent bytes of join response messages | |
uint | stat_joinACK |
number of sent join acknowledge messages | |
uint | stat_joinACKBytesSent |
number of sent bytes of join acknowledge messages | |
uint | stat_joinDNY |
number of sent join deny messages | |
uint | stat_joinDNYBytesSent |
number of sent bytes of join deny messages | |
uint | stat_disconnectMessages |
number of sent disconnect messages | |
uint | stat_disconnectMessagesBytesSent |
number of sent bytes of disconnect messages | |
uint | stat_updateMessages |
number of sent update messages | |
uint | stat_updateMessagesBytesSent |
number of sent bytes of update messages | |
uint | stat_tokenMessages |
number of sent token messages | |
uint | stat_tokenMessagesBytesSent |
number of sent bytes of token messages | |
uint | stat_keyListMessages |
number of sent keylist messages | |
uint | stat_keyListMessagesBytesSent |
number of sent bytes of keylist messages | |
uint | stat_routeMessages |
number of sent route messages | |
uint | stat_routeMessagesBytesSent |
number of sent bytes of route messages | |
uint | stat_maxNeighbors |
maximum number of neighbors | |
uint | stat_addedNeighbors |
number of added neighbors during life cycle of this node | |
uint | stat_removedNeighbors |
number of removed neighbors during life cycle of this node | |
uint | stat_numSatisfactionMessages |
number of satisfaction self-messages | |
double | stat_sumLevelOfSatisfaction |
sum of level of satisfaction | |
double | stat_maxLevelOfSatisfaction |
maximum level of satisfaction | |
cMessage * | satisfaction_timer |
timer for satisfaction self-message | |
cMessage * | update_timer |
timer for update self-message | |
cMessage * | timedoutMessages_timer |
timer for message timeout | |
cMessage * | timedoutNeighbors_timer |
timer for neighbors timeout | |
cMessage * | sendKeyList_timer |
timer for send keylist | |
cMessage * | sendToken_timer |
timer for send token | |
GiaKeyListModule * | keyListModule |
pointer to KeyListModule | |
GiaNeighbors * | neighbors |
pointer to neighbor list | |
GiaTokenFactory * | tokenFactory |
pointer to TokenFactory | |
GiaNeighborCandidateList | neighCand |
list of all neighbor candidates | |
GiaNeighborCandidateList | knownNodes |
list of known nodes in the overlay | |
GiaKeyList | keyList |
key list of this node |
Gia::~Gia | ( | ) |
Destructor.
01248 { 01249 cancelAndDelete(satisfaction_timer); 01250 cancelAndDelete(update_timer); 01251 cancelAndDelete(timedoutMessages_timer); 01252 cancelAndDelete(timedoutNeighbors_timer); 01253 cancelAndDelete(sendKeyList_timer); 01254 cancelAndDelete(sendToken_timer); 01255 delete msgBookkeepingList; 01256 }
void Gia::initializeOverlay | ( | int | stage | ) | [virtual] |
initializes base class-attributes
stage | the init stage |
Reimplemented from BaseOverlay.
00040 { 00041 // wait until IPAddressResolver initialized all interfaces and assigns addresses 00042 if(stage != MIN_STAGE_OVERLAY) 00043 return; 00044 00045 // Get parameters from omnetpp.ini 00046 maxNeighbors = par("maxNeighbors"); 00047 minNeighbors = par("minNeighbors"); 00048 maxTopAdaptionInterval = par("maxTopAdaptionInterval"); 00049 topAdaptionAggressiveness = par("topAdaptionAggressiveness"); 00050 maxLevelOfSatisfaction = par("maxLevelOfSatisfaction"); 00051 updateDelay = par("updateDelay"); 00052 maxHopCount = par("maxHopCount"); //obsolete 00053 messageTimeout = par("messageTimeout"); 00054 neighborTimeout = par("neighborTimeout"); 00055 sendTokenTimeout = par("sendTokenTimeout"); 00056 tokenWaitTime = par("tokenWaitTime"); 00057 keyListDelay = par("keyListDelay"); 00058 outputNodeDetails = par("outputNodeDetails"); 00059 optimizeReversePath = par("optimizeReversePath"); 00060 00061 // get references on necessary modules 00062 keyListModule = check_and_cast<GiaKeyListModule*> 00063 (parentModule()->submodule("keyListModule")); 00064 neighbors = check_and_cast<GiaNeighbors*> 00065 (parentModule()->submodule("neighbors")); 00066 tokenFactory = check_and_cast<GiaTokenFactory*> 00067 (parentModule()->submodule("tokenFactory")); 00068 00069 msgBookkeepingList = new GiaMessageBookkeeping(neighbors, messageTimeout); 00070 00071 // clear neighbor candidate list 00072 neighCand.clear(); 00073 knownNodes.clear(); 00074 00075 WATCH(thisGiaNode); 00076 WATCH(bootstrapNode); 00077 WATCH(levelOfSatisfaction); 00078 00079 // self-messages 00080 satisfaction_timer = new cMessage("satisfaction_timer"); 00081 update_timer = new cMessage("update_timer"); 00082 timedoutMessages_timer = new cMessage("timedoutMessages_timer"); 00083 timedoutNeighbors_timer = new cMessage("timedoutNeighbors_timer"); 00084 sendKeyList_timer = new cMessage("sendKeyList_timer"); 00085 sendToken_timer = new cMessage("sendToken_timer"); 00086 00087 // statistics 00088 stat_joinCount = 0; 00089 stat_joinBytesSent = 0; 00090 stat_joinREQ = 0; 00091 stat_joinREQBytesSent = 0; 00092 stat_joinRSP = 0; 00093 stat_joinRSPBytesSent = 0; 00094 stat_joinACK = 0; 00095 stat_joinACKBytesSent = 0; 00096 stat_joinDNY = 0; 00097 stat_joinDNYBytesSent = 0; 00098 stat_disconnectMessages = 0; 00099 stat_disconnectMessagesBytesSent = 0; 00100 stat_updateMessages = 0; 00101 stat_updateMessagesBytesSent = 0; 00102 stat_tokenMessages = 0; 00103 stat_tokenMessagesBytesSent = 0; 00104 stat_keyListMessages = 0; 00105 stat_keyListMessagesBytesSent = 0; 00106 stat_routeMessages = 0; 00107 stat_routeMessagesBytesSent = 0; 00108 stat_maxNeighbors = 0; 00109 stat_addedNeighbors = 0; 00110 stat_removedNeighbors = 0; 00111 stat_numSatisfactionMessages = 0; 00112 stat_sumLevelOfSatisfaction = 0.0; 00113 stat_maxLevelOfSatisfaction = 0.0; 00114 }
void Gia::finishOverlay | ( | ) | [virtual] |
Writes statistical data and removes node from bootstrap oracle.
Reimplemented from BaseOverlay.
01212 { 01213 // statistics 01214 01215 globalStatistics->addStdDev("GIA: JOIN-Messages Count", stat_joinCount); 01216 globalStatistics->addStdDev("GIA: JOIN Bytes sent", stat_joinBytesSent); 01217 globalStatistics->addStdDev("GIA: JOIN::REQ Messages", stat_joinREQ); 01218 globalStatistics->addStdDev("GIA: JOIN::REQ Bytes sent", stat_joinREQBytesSent); 01219 globalStatistics->addStdDev("GIA: JOIN::RSP Messages", stat_joinRSP); 01220 globalStatistics->addStdDev("GIA: JOIN::RSP Bytes sent", stat_joinRSPBytesSent); 01221 globalStatistics->addStdDev("GIA: JOIN::ACK Messages", stat_joinACK); 01222 globalStatistics->addStdDev("GIA: JOIN::ACK Bytes sent", stat_joinACKBytesSent); 01223 globalStatistics->addStdDev("GIA: JOIN::DNY Messages", stat_joinDNY); 01224 globalStatistics->addStdDev("GIA: JOIN::DNY Bytes sent", stat_joinDNYBytesSent); 01225 globalStatistics->addStdDev("GIA: DISCONNECT:IND Messages", stat_disconnectMessages); 01226 globalStatistics->addStdDev("GIA: DISCONNECT:IND Bytes sent", 01227 stat_disconnectMessagesBytesSent); 01228 globalStatistics->addStdDev("GIA: UPDATE:IND Messages", stat_updateMessages); 01229 globalStatistics->addStdDev("GIA: UPDATE:IND Bytes sent", stat_updateMessagesBytesSent); 01230 globalStatistics->addStdDev("GIA: TOKEN:IND Messages", stat_tokenMessages); 01231 globalStatistics->addStdDev("GIA: TOKEN:IND Bytes sent", stat_tokenMessagesBytesSent); 01232 globalStatistics->addStdDev("GIA: KEYLIST:IND Messages", stat_keyListMessages); 01233 globalStatistics->addStdDev("GIA: KEYLIST:IND Bytes sent", stat_keyListMessagesBytesSent); 01234 globalStatistics->addStdDev("GIA: ROUTE:IND Messages", stat_routeMessages); 01235 globalStatistics->addStdDev("GIA: ROUTE:IND Bytes sent", stat_routeMessagesBytesSent); 01236 globalStatistics->addStdDev("GIA: Neighbors max", stat_maxNeighbors); 01237 globalStatistics->addStdDev("GIA: Neighbors added", stat_addedNeighbors); 01238 globalStatistics->addStdDev("GIA: Neighbors removed", stat_removedNeighbors); 01239 globalStatistics->addStdDev("GIA: Level of satisfaction messages ", 01240 stat_numSatisfactionMessages); 01241 globalStatistics->addStdDev("GIA: Level of satisfaction max ",stat_maxLevelOfSatisfaction); 01242 globalStatistics->addStdDev("GIA: Level of satisfaction avg ", 01243 stat_sumLevelOfSatisfaction / stat_numSatisfactionMessages); 01244 bootstrapList->removeBootstrapNode(thisGiaNode); 01245 }
void Gia::changeState | ( | int | toStage | ) | [virtual] |
Set state to toStage.
toStage | the stage to change to |
Referenced by addNeighbor(), handleTimerEvent(), joinOverlay(), and removeNeighbor().
00125 { 00126 switch (toState) { 00127 case INIT: { 00128 state = INIT; 00129 00130 setOverlayReady(false); 00131 showOverlayNeighborArrow(thisGiaNode); 00132 00133 // set up local nodehandle 00134 //thisGiaNode.setNodeHandle(thisNode); 00135 thisGiaNode = thisNode; 00136 00137 callUpdate(thisNode, true); 00138 00139 // get possible bandwidth from ppp-Module 00140 double capacity = 0; 00141 00142 cModule* nodeModule = parentModule()->parentModule(); 00143 00144 int gateSize = nodeModule->gateSize("in"); 00145 00146 if(gateSize == 0) 00147 capacity += uniform(1,800000); 00148 else { 00149 // this relies on IPv4Underlay 00150 for (int i=0; i<gateSize; i++) { 00151 int gateID = nodeModule->gate("in",0)->id()+i; 00152 cGate* currentGate = nodeModule->gate(gateID); 00153 if (currentGate->isConnected()) 00154 capacity += check_and_cast<cBasicChannel *> 00155 (currentGate->fromGate()->channel())->datarate() 00156 - uniform(0,800000); 00157 } 00158 } 00159 00160 thisGiaNode.setCapacity(capacity); 00161 //thisGiaNode.setConnectionDegree(0); 00162 //thisGiaNode.setReceivedTokens(0); 00163 //thisGiaNode.setSentTokens(0); 00164 00165 connectionDegree = 0; 00166 receivedTokens = 0; 00167 sentTokens = 0; 00168 00169 if (outputNodeDetails) 00170 EV << "(Gia) Node details: " << thisGiaNode << endl; 00171 00172 // get our entry point to GIA-Overlay 00173 bootstrapNode = bootstrapList->getBootstrapNode(); 00174 if(!(bootstrapNode.isUnspecified())) 00175 knownNodes.add(bootstrapNode); 00176 //else { 00177 //assert(!(thisGiaNode.getNodeHandle().isUnspecified())); 00178 //bootstrapOracle->registerPeer(thisGiaNode.getNodeHandle()); 00179 //} 00180 00181 // register node at TokenFactory 00182 //tokenFactory->setNode(&thisGiaNode); 00183 tokenFactory->setNeighbors(neighbors); 00184 tokenFactory->setMaxHopCount(maxHopCount); 00185 00186 if (debugOutput) 00187 EV << "(Gia) Node " << thisGiaNode.key 00188 << " (" << thisGiaNode.ip << ":" 00189 << thisGiaNode.port << ") with capacity: " 00190 << thisGiaNode.getCapacity() << " entered INIT state." << endl; 00191 00192 parentModule()->parentModule()->bubble("Enter INIT state."); 00193 00194 // schedule satisfaction_timer 00195 cancelEvent(satisfaction_timer); 00196 scheduleAt(simulation.simTime(), satisfaction_timer); 00197 00198 // schedule timedoutMessages_timer 00199 cancelEvent(timedoutMessages_timer); 00200 scheduleAt(simulation.simTime() + messageTimeout, 00201 timedoutMessages_timer); 00202 00203 cancelEvent(timedoutNeighbors_timer); 00204 scheduleAt(simulation.simTime() + neighborTimeout, 00205 timedoutNeighbors_timer); 00206 00207 cancelEvent(sendToken_timer); 00208 scheduleAt(simulation.simTime() + sendTokenTimeout, 00209 sendToken_timer); 00210 00211 break; 00212 } 00213 case READY: 00214 state = READY; 00215 setOverlayReady(true); 00216 break; 00217 } 00218 updateTooltip(); 00219 }
void Gia::updateTooltip | ( | ) |
Marks nodes if they are ready.
Referenced by addNeighbor(), changeState(), and removeNeighbor().
00237 { 00238 if (ev.isGUI()) { 00239 // if (state == READY) { 00240 // parentModule()->parentModule()->displayString(). 00241 // setTagArg("i2", 1, ""); 00242 // displayString().setTagArg("i", 1, ""); 00243 // } else { 00244 // parentModule()->parentModule()->displayString(). 00245 // setTagArg("i2", 1, "red"); 00246 // displayString().setTagArg("i", 1, "red"); 00247 // } 00248 00249 std::stringstream ttString; 00250 00251 // show our predecessor and successor in tooltip 00252 ttString << thisNode << "\n# Neighbors: " 00253 << neighbors->getSize(); 00254 00255 parentModule()->parentModule()->displayString(). 00256 setTagArg("tt", 0, ttString.str().c_str()); 00257 parentModule()->displayString(). 00258 setTagArg("tt", 0, ttString.str().c_str()); 00259 displayString().setTagArg("tt", 0, ttString.str().c_str()); 00260 } 00261 }
void Gia::handleTimerEvent | ( | cMessage * | msg | ) | [virtual] |
Processes "timer" self-messages.
msg | A self-message |
Reimplemented from BaseOverlay.
00264 { 00265 if (msg == sendToken_timer) { 00266 tokenFactory->grantToken(); 00267 } else if (msg->isName("satisfaction_timer")) { 00268 // calculate level of satisfaction and select new neighbor candidate 00269 00270 levelOfSatisfaction = calculateLevelOfSatisfaction(); 00271 stat_numSatisfactionMessages++; 00272 stat_sumLevelOfSatisfaction += levelOfSatisfaction; 00273 if (levelOfSatisfaction > stat_maxLevelOfSatisfaction) 00274 stat_maxLevelOfSatisfaction = levelOfSatisfaction; 00275 00276 // start again satisfaction_timer 00277 scheduleAt(simulation.simTime() + (maxTopAdaptionInterval * 00278 pow(topAdaptionAggressiveness, 00279 -(1 - levelOfSatisfaction))), 00280 satisfaction_timer); 00281 00282 // Only search a new neighbor if level of satisfaction is 00283 // under level of maxLevelOfSatisfaction 00284 if(levelOfSatisfaction < maxLevelOfSatisfaction) { 00285 if(knownNodes.getSize() == 0) 00286 if(neighbors->getSize() == 0 && neighCand.getSize() == 0) 00287 knownNodes.add(bootstrapList->getBootstrapNode()); 00288 else 00289 return; 00290 00291 NodeHandle possibleNeighbor = knownNodes.getRandomCandidate(); 00292 00293 if(!(possibleNeighbor.isUnspecified()) && 00294 thisGiaNode != possibleNeighbor && 00295 !neighbors->contains(possibleNeighbor) && 00296 !neighCand.contains(possibleNeighbor)) { 00297 // try to add new neighbor 00298 neighCand.add(possibleNeighbor); 00299 sendMessage_JOIN_REQ(possibleNeighbor); 00300 } 00301 } 00302 } else if (msg->isName("update_timer")) { 00303 // send current capacity and degree to all neighbors 00304 for (uint i=0; i<neighbors->getSize(); i++) { 00305 sendMessage_UPDATE(neighbors->get(i)); 00306 } 00307 } else if (msg->isName("timedoutMessages_timer")) { 00308 // remove timedout messages 00309 msgBookkeepingList->removeTimedoutMessages(); 00310 scheduleAt(simulation.simTime() + messageTimeout, 00311 timedoutMessages_timer); 00312 } else if (msg->isName("timedoutNeighbors_timer")) { 00313 // remove timedout neighbors 00314 neighbors->removeTimedoutNodes(); 00315 if (neighbors->getSize() == 0) { 00316 changeState(INIT); 00317 } 00318 cancelEvent(timedoutNeighbors_timer); 00319 scheduleAt(simulation.simTime() + neighborTimeout, 00320 timedoutNeighbors_timer); 00321 } else if (msg->isName("sendKeyList_timer")) { 00322 if (keyList.getSize() > 0) { 00323 // send keyList to all of our neighbors 00324 for (uint i=0; i<neighbors->getSize(); i++) 00325 sendKeyListToNeighbor(neighbors->get(i)); 00326 } 00327 } else { 00328 // other self-messages are notoken-self-messages 00329 // with an encapsulated message 00330 const std::string id = msg->name(); 00331 if (id.substr(0, 16) == std::string("wait-for-token: ")) { 00332 cMessage* decapsulatedMessage = msg->decapsulate(); 00333 if (dynamic_cast<GiaIDMessage*>(decapsulatedMessage) != NULL) { 00334 GiaIDMessage* message = check_and_cast<GiaIDMessage*> 00335 (decapsulatedMessage); 00336 forwardMessage(message, false); 00337 } 00338 } else if (id.substr(0, 24) == std::string("wait-for-token-fromapp: ")) { 00339 cMessage* decapsulatedMessage = msg->decapsulate(); 00340 if (dynamic_cast<GiaIDMessage*>(decapsulatedMessage) != NULL) { 00341 GiaIDMessage* message = check_and_cast<GiaIDMessage*> 00342 (decapsulatedMessage); 00343 forwardMessage(message, true); 00344 } 00345 } 00346 delete msg; 00347 } 00348 }
void Gia::handleUDPMessage | ( | BaseOverlayMessage * | msg | ) | [virtual] |
Processes messages from underlay.
msg | Message from UDP |
Reimplemented from BaseOverlay.
00351 { 00352 if(debugOutput) 00353 EV << "(Gia) " << thisGiaNode << " received udp message" << endl; 00354 00355 cPolymorphic* ctrlInfo = msg->removeControlInfo(); 00356 if(ctrlInfo != NULL) 00357 delete ctrlInfo; 00358 00359 // Parse TokenMessages 00360 if (dynamic_cast<TokenMessage*>(msg) != NULL) { 00361 TokenMessage* giaMsg = check_and_cast<TokenMessage*>(msg); 00362 00363 // Process TOKEN-Message 00364 if ((giaMsg->getCommand() == TOKEN)) { 00365 if(debugOutput) 00366 EV << "(Gia) Received Tokenmessage from " 00367 << giaMsg->getSrcNode() << endl; 00368 00369 //neighbors->setReceivedTokens(giaMsg->getSrcNode(), giaMsg->getDstTokenNr()); 00370 neighbors->increaseReceivedTokens(giaMsg->getSrcNode()); 00371 updateNeighborList(giaMsg); 00372 } 00373 delete msg; 00374 } 00375 00376 // Process Route messages 00377 else if (dynamic_cast<GiaRouteMessage*>(msg) != NULL) { 00378 GiaRouteMessage* giaMsg = check_and_cast<GiaRouteMessage*>(msg); 00379 GiaNode oppositeNode(giaMsg->getSrcNode(), giaMsg->getSrcCapacity(), 00380 giaMsg->getSrcDegree()); 00381 00382 if((giaMsg->getCommand() == ROUTE)) { 00383 if(debugOutput) 00384 EV << "(Gia) Received ROUTE::IND from " << oppositeNode << endl; 00385 00386 if(state == READY) { 00387 //neighbors->decreaseReceivedTokens(giaMsg->getSrcNode()); 00388 updateNeighborList(giaMsg); 00389 forwardMessage(giaMsg, false); 00390 } 00391 } 00392 } 00393 00394 // Process KeyList-Messages 00395 else if (dynamic_cast<KeyListMessage*>(msg) != NULL) { 00396 KeyListMessage* giaMsg = check_and_cast<KeyListMessage*>(msg); 00397 GiaNode oppositeNode(giaMsg->getSrcNode(), giaMsg->getSrcCapacity(), 00398 giaMsg->getSrcDegree()); 00399 00400 if (giaMsg->getCommand() == KEYLIST) { 00401 if (debugOutput) 00402 EV << "(Gia) " << thisGiaNode 00403 << " received KEYLIST:IND message" << endl; 00404 // update KeyList in neighborList 00405 uint keyListSize = giaMsg->getKeysArraySize(); 00406 GiaKeyList neighborKeyList; 00407 for (uint k = 0; k < keyListSize; k++) 00408 neighborKeyList.addKeyItem(giaMsg->getKeys(k)); 00409 neighbors->setNeighborKeyList(giaMsg->getSrcNode(), neighborKeyList); 00410 } 00411 delete giaMsg; 00412 } 00413 00414 // Process Search-Messages 00415 else if (dynamic_cast<SearchMessage*>(msg) != NULL) { 00416 SearchMessage* giaMsg = check_and_cast<SearchMessage*>(msg); 00417 GiaNode oppositeNode(giaMsg->getSrcNode(), giaMsg->getSrcCapacity(), 00418 giaMsg->getSrcDegree()); 00419 00420 //neighbors->decreaseSentTokens(giaMsg->getSrcNode()); 00421 updateNeighborList(giaMsg); 00422 processSearchMessage(giaMsg, false); 00423 // } else { 00424 // EV << "(Gia) Message " << msg << " dropped!" << endl; 00425 // RECORD_STATS(numDropped++; bytesDropped += msg->byteLength()); 00426 // delete msg; 00427 // } 00428 } 00429 00430 // Process Search-Response-Messages 00431 else if (dynamic_cast<SearchResponseMessage*>(msg) != NULL) { 00432 SearchResponseMessage* responseMsg = 00433 check_and_cast<SearchResponseMessage*>(msg); 00434 forwardSearchResponseMessage(responseMsg); 00435 } 00436 00437 // Process Gia messages 00438 else if (dynamic_cast<GiaMessage*>(msg) != NULL) { 00439 GiaMessage* giaMsg = check_and_cast<GiaMessage*>(msg); 00440 00441 //assert(giaMsg->getSrcNode().moduleId != -1); 00442 GiaNode oppositeNode(giaMsg->getSrcNode(), giaMsg->getSrcCapacity(), 00443 giaMsg->getSrcDegree()); 00444 00445 if (debugOutput) 00446 EV << "(Gia) " << thisGiaNode << " received GIA- message from " 00447 << oppositeNode << endl; 00448 updateNeighborList(giaMsg); 00449 00450 // Process JOIN:REQ messages 00451 if (giaMsg->getCommand() == JOIN_REQUEST) { 00452 if (debugOutput) 00453 EV << "(Gia) " << thisGiaNode 00454 << " received JOIN:REQ message" << endl; 00455 if (acceptNode(oppositeNode, giaMsg->getSrcDegree())) { 00456 neighCand.add(oppositeNode); 00457 sendMessage_JOIN_RSP(oppositeNode); 00458 } else { 00459 if (debugOutput) 00460 EV << "(Gia) " << thisGiaNode << " denies node " 00461 << oppositeNode << endl; 00462 sendMessage_JOIN_DNY(oppositeNode); 00463 } 00464 } 00465 00466 // Process JOIN:RSP messages 00467 else if (giaMsg->getCommand() == JOIN_RESPONSE) { 00468 if(debugOutput) 00469 EV << "(Gia) " << thisGiaNode << " received JOIN:RSP message" 00470 << endl; 00471 if(neighCand.contains(oppositeNode)) { 00472 neighCand.remove(oppositeNode); 00473 if(acceptNode(oppositeNode, giaMsg->getSrcDegree())) { 00474 addNeighbor(oppositeNode, giaMsg->getSrcDegree()); 00475 00476 GiaNeighborMessage* msg = 00477 check_and_cast<GiaNeighborMessage*>(giaMsg); 00478 for(uint i = 0; i < msg->getNeighborsArraySize(); i++) { 00479 GiaNode temp = msg->getNeighbors(i); 00480 if(temp != thisGiaNode && temp != oppositeNode) 00481 knownNodes.add(temp); 00482 } 00483 00484 sendMessage_JOIN_ACK(oppositeNode); 00485 } else { 00486 if (debugOutput) 00487 EV << "(Gia) " << thisGiaNode << " denies node " 00488 << oppositeNode << endl; 00489 sendMessage_JOIN_DNY(oppositeNode); 00490 } 00491 } 00492 } 00493 00494 // Process JOIN:ACK messages 00495 else if (giaMsg->getCommand() == JOIN_ACK) { 00496 if (debugOutput) 00497 EV << "(Gia) " << thisGiaNode << " received JOIN:ACK message" 00498 << endl; 00499 if (neighCand.contains(oppositeNode) && 00500 neighbors->getSize() < maxNeighbors) { 00501 neighCand.remove(oppositeNode); 00502 addNeighbor(oppositeNode, giaMsg->getSrcDegree()); 00503 00504 GiaNeighborMessage* msg = 00505 check_and_cast<GiaNeighborMessage*>(giaMsg); 00506 00507 for(uint i = 0; i < msg->getNeighborsArraySize(); i++) { 00508 GiaNode temp = msg->getNeighbors(i); 00509 if(temp != thisGiaNode && temp != oppositeNode) 00510 knownNodes.add(msg->getNeighbors(i)); 00511 } 00512 } else { 00513 sendMessage_DISCONNECT(oppositeNode); 00514 } 00515 00516 } 00517 00518 // Process JOIN:DNY messages 00519 else if (giaMsg->getCommand() == JOIN_DENY) { 00520 if (debugOutput) 00521 EV << "(Gia) " << thisGiaNode << " received JOIN:DNY message" 00522 << endl; 00523 00524 if (neighCand.contains(oppositeNode)) 00525 neighCand.remove(oppositeNode); 00526 knownNodes.remove(oppositeNode); 00527 00528 } 00529 00530 00531 // Process DISCONNECT-Message 00532 else if (giaMsg->getCommand() == DISCONNECT) { 00533 if (debugOutput) 00534 EV << "(Gia) " << thisGiaNode << " received DISCONNECT:IND message" << endl; 00535 removeNeighbor(giaMsg->getSrcNode()); 00536 } 00537 00538 // Process UPDATE-Message 00539 else if (giaMsg->getCommand() == UPDATE) { 00540 if (debugOutput) 00541 EV << "(Gia) " << thisGiaNode << " received UPDATE:IND message" 00542 << endl; 00543 00544 neighbors->setConnectionDegree(giaMsg->getSrcNode(), 00545 giaMsg->getSrcDegree()); 00546 //neighbors->setCapacity(giaMsg->getSrcNode(), 00547 //giaMsg->getSrcCapacity()); 00548 } else { 00549 // Show unknown gia-messages 00550 if (debugOutput) { 00551 EV << "(Gia) NODE: "<< thisGiaNode << endl 00552 << " Command: " << giaMsg->getCommand() << endl 00553 << " HopCount: " << giaMsg->getHopCount() << endl 00554 << " SrcKey: " << giaMsg->getSrcNode().key << endl 00555 << " SrcIP: " << giaMsg->getSrcNode().key << endl 00556 << " SrcPort: " << giaMsg->getSrcNode().port << endl 00557 << " SrcCapacity: " << giaMsg->getSrcCapacity() << endl 00558 << " SrcDegree: " << giaMsg->getSrcDegree() << endl; 00559 00560 RECORD_STATS(numDropped++;bytesDropped += giaMsg->byteLength()); 00561 } 00562 } 00563 delete giaMsg; 00564 } else // PROCESS other messages than GiaMessages 00565 delete msg; // delete them all 00566 }
void Gia::route | ( | const OverlayKey & | key, | |
CompType | destComp, | |||
CompType | srcComp, | |||
cMessage * | msg, | |||
const std::vector< TransportAddress > & | sourceRoute = TransportAddress::UNSPECIFIED_NODES , |
|||
RoutingType | routingType = DEFAULT_ROUTING | |||
) | [virtual] |
Routes message through overlay.
The default implementation uses FindNode to determine next hops and a generic greedy routing algorithm provides with SendToKey.
key | destination key | |
destComp | the destination component | |
srcComp | the source component | |
msg | message to route | |
sourceRoute | If sourceRoute is given, the message gets sent via all nodes in the list before it is routed (nextHop is used as a proxy) | |
routingType | specifies the routing mode (ITERATIVE_ROUTING, ...) |
Reimplemented from BaseOverlay.
01009 { 01010 if ((destComp != TIER1_COMP) || (srcComp != TIER1_COMP)) { 01011 throw new cException("Gia::route(): Works currently " 01012 "only with srcComp=destComp=TIER1_COMP!"); 01013 } 01014 01015 if (state == READY) { 01016 GiaRouteMessage* routeMsg = new GiaRouteMessage("ROUTE"); 01017 routeMsg->setStatType(APP_DATA_STAT); 01018 routeMsg->setCommand(ROUTE); 01019 routeMsg->setHopCount(maxHopCount); 01020 routeMsg->setDestKey(key); 01021 routeMsg->setSrcNode(thisGiaNode); 01022 routeMsg->setSrcCapacity(thisGiaNode.getCapacity()); 01023 routeMsg->setSrcDegree(connectionDegree); 01024 routeMsg->setOriginatorKey(thisGiaNode.key); 01025 routeMsg->setOriginatorIP(thisGiaNode.ip); 01026 routeMsg->setOriginatorPort(thisGiaNode.port); 01027 routeMsg->setID(OverlayKey::random()); 01028 routeMsg->setLength(GIAROUTE_L(routeMsg)); 01029 routeMsg->encapsulate(msg); 01030 01031 01032 forwardMessage(routeMsg, true); 01033 } else { 01034 RECORD_STATS(numDropped++; bytesDropped += msg->byteLength()); 01035 delete msg; 01036 } 01037 }
void Gia::handleAppMessage | ( | cMessage * | msg | ) | [virtual] |
Processes non-commonAPI messages.
msg | non-commonAPIMessage |
Reimplemented from BaseOverlay.
01040 { 01041 // do we receive a keylist? 01042 if (dynamic_cast<GIAput*>(msg) != NULL) { 01043 GIAput* putMsg = check_and_cast<GIAput*>(msg); 01044 uint keyListSize = putMsg->getKeysArraySize(); 01045 for (uint k=0; k<keyListSize; k++) 01046 keyList.addKeyItem(putMsg->getKeys(k)); 01047 01048 // actualize vector in KeyListModule 01049 keyListModule->setKeyListVector(keyList.getVector()); 01050 01051 scheduleAt(simulation.simTime() + keyListDelay, sendKeyList_timer); 01052 01053 delete putMsg; 01054 } else if (dynamic_cast<GIAsearch*>(msg) != NULL) { 01055 if (state == READY) { 01056 GIAsearch* getMsg = check_and_cast<GIAsearch*>(msg); 01057 SearchMessage* searchMsg = new SearchMessage("SEARCH"); 01058 searchMsg->setCommand(SEARCH); 01059 searchMsg->setStatType(APP_DATA_STAT); 01060 searchMsg->setHopCount(maxHopCount); 01061 searchMsg->setDestKey(getMsg->getSearchKey()); 01062 searchMsg->setSrcNode(thisGiaNode); 01063 searchMsg->setSrcCapacity(thisGiaNode.getCapacity()); 01064 searchMsg->setSrcDegree(connectionDegree); 01065 searchMsg->setSearchKey(getMsg->getSearchKey()); 01066 searchMsg->setMaxResponses(getMsg->getMaxResponses()); 01067 searchMsg->setReversePathArraySize(0); 01068 searchMsg->setID(OverlayKey::random()); 01069 searchMsg->setLength(SEARCH_L(searchMsg)); 01070 01071 processSearchMessage(searchMsg, true); 01072 01073 delete getMsg; 01074 } else 01075 delete msg; 01076 } else { 01077 delete msg; 01078 EV << "(Gia) unkown message from app deleted!" << endl; 01079 } 01080 }
void Gia::sendToken | ( | const GiaNode & | dst | ) |
Referenced by GiaTokenFactory::grantToken().
00801 { 00802 TokenMessage* tokenMsg = new TokenMessage("TOKEN"); 00803 tokenMsg->setCommand(TOKEN); 00804 tokenMsg->setHopCount(maxHopCount); 00805 tokenMsg->setSrcNode(thisGiaNode); 00806 tokenMsg->setSrcCapacity(thisGiaNode.getCapacity()); 00807 tokenMsg->setSrcDegree(connectionDegree); 00808 tokenMsg->setSrcTokenNr(0/*dst.getReceivedTokens()*/);//??? 00809 tokenMsg->setDstTokenNr(/*dst.getSentTokens()+*/1); 00810 tokenMsg->setLength(TOKEN_L(tokenMsg)); 00811 00812 stat_tokenMessagesBytesSent += tokenMsg->byteLength(); 00813 stat_tokenMessages += 1; 00814 00815 sendMessageToUDP(dst, tokenMsg); 00816 }
void Gia::joinOverlay | ( | ) | [protected, virtual] |
Join the overlay with a given nodeID in thisNode.key.
Join the overlay with a given nodeID in thisNode.key. This method may be called by an application to join the overlay with a specific nodeID. It is also called if the node's IP address changes.
Reimplemented from BaseOverlay.
00117 { 00118 changeState(INIT); 00119 00120 if (bootstrapNode.isUnspecified()) 00121 changeState(READY); 00122 }
bool Gia::acceptNode | ( | const GiaNode & | newNode, | |
unsigned int | degree | |||
) | [protected] |
Decides if Node newNode will be accepted as new neighor.
newNode | Node to accept or deny | |
degree | the node's connection degree |
Referenced by handleUDPMessage().
00569 { 00570 if (neighbors->contains(nNode)) 00571 return false; 00572 00573 if (neighbors->getSize() < maxNeighbors) { 00574 // we have room for new node: accept node 00575 return true; 00576 } 00577 // we need to drop a neighbor 00578 NodeHandle dropCandidate = neighbors->getDropCandidate(nNode.getCapacity(), degree); 00579 if(!dropCandidate.isUnspecified()) { 00580 if (debugOutput) 00581 EV << "(Gia) " << thisGiaNode << " drops " 00582 << dropCandidate << endl; 00583 neighbors->remove(dropCandidate); 00584 sendMessage_DISCONNECT(dropCandidate); 00585 return true; 00586 } 00587 return false; 00588 }
void Gia::addNeighbor | ( | GiaNode & | newNode, | |
unsigned int | degree | |||
) | [protected] |
Adds newNode as new neighbor.
newNode | the node to add as a neighbor | |
degree | the node's connection degree |
Referenced by handleUDPMessage().
00592 { 00593 assert(neighbors->getSize() < maxNeighbors); 00594 00595 stat_addedNeighbors++; 00596 EV << "(Gia) " << thisGiaNode << " accepted new neighbor " << node << endl; 00597 parentModule()->parentModule()->bubble("New neighbor"); 00598 connectionDegree = neighbors->getSize(); 00599 changeState(READY); 00600 if (stat_maxNeighbors < neighbors->getSize()) { 00601 stat_maxNeighbors = neighbors->getSize(); 00602 } 00603 00604 cancelEvent(update_timer); 00605 scheduleAt(simulation.simTime() + updateDelay, update_timer); 00606 00607 //node.setSentTokens(5); 00608 //node.setReceivedTokens(5); 00609 00610 // send keyList to new Neighbor 00611 if (keyList.getSize() > 0) 00612 sendKeyListToNeighbor(node); 00613 neighbors->add(node, degree); 00614 00615 showOverlayNeighborArrow(node, false, 00616 "m=m,50,0,50,0;o=red,1"); 00617 updateTooltip(); 00618 }
void Gia::removeNeighbor | ( | const GiaNode & | newNode | ) | [protected] |
Removes newNode from our NeighborList.
newNode | NodeHandle of the node to remove from neighbors |
Referenced by handleUDPMessage().
00621 { 00622 stat_removedNeighbors++; 00623 00624 if (debugOutput) 00625 EV << "(Gia) " << thisGiaNode << " removes " << node 00626 << " from neighborlist." << endl; 00627 neighbors->remove(node); 00628 00629 connectionDegree = neighbors->getSize(); 00630 00631 if (neighbors->getSize() == 0) { 00632 changeState(INIT); 00633 } 00634 00635 deleteOverlayNeighborArrow(node); 00636 updateTooltip(); 00637 00638 cancelEvent(update_timer); 00639 scheduleAt(simulation.simTime() + updateDelay, update_timer); 00640 }
double Gia::calculateLevelOfSatisfaction | ( | ) | [protected] |
Calculates level of satisfaction.
Referenced by handleTimerEvent().
00643 { 00644 uint neighborsCount = neighbors->getSize(); 00645 if(neighborsCount < minNeighbors) 00646 return 0.0; 00647 00648 double total = 0.0; 00649 double levelOfSatisfaction = 0.0; 00650 00651 for (uint i=0; i < neighborsCount; i++) 00652 total += neighbors->get(i).getCapacity() / neighborsCount; 00653 00654 assert(thisGiaNode.getCapacity() != 0); 00655 levelOfSatisfaction = total / thisGiaNode.getCapacity(); 00656 00657 if ((levelOfSatisfaction > 1.0) || (neighborsCount >= maxNeighbors)) 00658 return 1.0; 00659 return levelOfSatisfaction; 00660 }
void Gia::sendMessage_JOIN_REQ | ( | const NodeHandle & | dst | ) | [protected] |
Sends JOIN_REQ_Message from node src to node dst.
dst,: | Destination |
Referenced by handleTimerEvent().
00664 { 00665 // send JOIN:REQ message 00666 GiaMessage* msg = new GiaMessage("JOIN_REQ"); 00667 msg->setCommand(JOIN_REQUEST); 00668 msg->setSrcNode(thisGiaNode); 00669 msg->setSrcCapacity(thisGiaNode.getCapacity()); 00670 msg->setSrcDegree(connectionDegree); 00671 msg->setLength(GIA_L(msg)); 00672 00673 stat_joinCount += 1; 00674 stat_joinBytesSent += msg->byteLength(); 00675 stat_joinREQ += 1; 00676 stat_joinREQBytesSent += msg->byteLength(); 00677 00678 sendMessageToUDP(dst, msg); 00679 }
void Gia::sendMessage_JOIN_RSP | ( | const NodeHandle & | dst | ) | [protected] |
Sends JOIN_RSP_Message from node src to node dst.
dst,: | Destination |
Referenced by handleUDPMessage().
00682 { 00683 // send JOIN:RSP message 00684 GiaNeighborMessage* msg = new GiaNeighborMessage("JOIN_RSP"); 00685 msg->setCommand(JOIN_RESPONSE); 00686 msg->setSrcNode(thisGiaNode); 00687 msg->setSrcCapacity(thisGiaNode.getCapacity()); 00688 msg->setSrcDegree(connectionDegree); 00689 00690 msg->setNeighborsArraySize(neighbors->getSize()); 00691 //TODO: add parameter maxSendNeighbors 00692 for(uint i = 0; i < neighbors->getSize(); i++) 00693 msg->setNeighbors(i, neighbors->get(i)); 00694 00695 msg->setLength(GIANEIGHBOR_L(msg)); 00696 00697 stat_joinCount += 1; 00698 stat_joinBytesSent += msg->byteLength(); 00699 stat_joinRSP += 1; 00700 stat_joinRSPBytesSent += msg->byteLength(); 00701 00702 sendMessageToUDP(dst, msg); 00703 }
void Gia::sendMessage_JOIN_ACK | ( | const NodeHandle & | dst | ) | [protected] |
Sends JOIN_ACK_Message from node src to node dst.
dst,: | Destination |
Referenced by handleUDPMessage().
00706 { 00707 // send JOIN:ACK message 00708 GiaNeighborMessage* msg = new GiaNeighborMessage("JOIN_ACK"); 00709 msg->setCommand(JOIN_ACK); 00710 msg->setSrcNode(thisGiaNode); 00711 msg->setSrcCapacity(thisGiaNode.getCapacity()); 00712 msg->setSrcDegree(connectionDegree); 00713 00714 msg->setNeighborsArraySize(neighbors->getSize()); 00715 //TODO: add parameter maxSendNeighbors 00716 for(uint i = 0; i < neighbors->getSize(); i++) 00717 msg->setNeighbors(i, neighbors->get(i)); 00718 00719 msg->setLength(GIANEIGHBOR_L(msg)); 00720 00721 stat_joinCount += 1; 00722 stat_joinBytesSent += msg->byteLength(); 00723 stat_joinACK += 1; 00724 stat_joinACKBytesSent += msg->byteLength(); 00725 00726 sendMessageToUDP(dst, msg); 00727 }
void Gia::sendMessage_JOIN_DNY | ( | const NodeHandle & | dst | ) | [protected] |
Sends JOIN_DNY_Message from node src to node dst.
dst,: | Destination |
Referenced by handleUDPMessage().
00730 { 00731 // send JOIN:DNY message 00732 GiaMessage* msg = new GiaMessage("JOIN_DENY"); 00733 msg->setCommand(JOIN_DENY); 00734 msg->setSrcNode(thisGiaNode); 00735 msg->setSrcCapacity(thisGiaNode.getCapacity()); 00736 msg->setSrcDegree(connectionDegree); 00737 msg->setLength(GIA_L(msg)); 00738 00739 stat_joinCount += 1; 00740 stat_joinBytesSent += msg->byteLength(); 00741 stat_joinDNY += 1; 00742 stat_joinDNYBytesSent += msg->byteLength(); 00743 00744 sendMessageToUDP(dst, msg); 00745 }
void Gia::sendMessage_DISCONNECT | ( | const NodeHandle & | dst | ) | [protected] |
Sends DISCONNECT_Message from node src to node dst.
dst,: | Destination |
Referenced by acceptNode(), and handleUDPMessage().
00748 { 00749 // send DISCONNECT:IND message 00750 GiaMessage* msg = new GiaMessage("DISCONNECT"); 00751 msg->setCommand(DISCONNECT); 00752 msg->setSrcNode(thisGiaNode); 00753 msg->setSrcCapacity(thisGiaNode.getCapacity()); 00754 msg->setSrcDegree(connectionDegree); 00755 msg->setLength(GIA_L(msg)); 00756 00757 stat_disconnectMessagesBytesSent += msg->byteLength(); 00758 stat_disconnectMessages += 1; 00759 00760 sendMessageToUDP(dst, msg); 00761 }
void Gia::sendMessage_UPDATE | ( | const NodeHandle & | dst | ) | [protected] |
Sends UPDATE_Message from node src to node dst.
dst,: | Destination |
Referenced by handleTimerEvent().
00764 { 00765 // send UPDATE:IND message 00766 GiaMessage* msg = new GiaMessage("UPDATE"); 00767 msg->setCommand(UPDATE); 00768 msg->setSrcNode(thisGiaNode); 00769 msg->setSrcCapacity(thisGiaNode.getCapacity()); 00770 msg->setSrcDegree(connectionDegree); 00771 msg->setLength(GIA_L(msg)); 00772 00773 stat_updateMessagesBytesSent += msg->byteLength(); 00774 stat_updateMessages += 1; 00775 00776 sendMessageToUDP(dst, msg); 00777 }
void Gia::sendKeyListToNeighbor | ( | const NodeHandle & | dst | ) | [protected] |
Sends KeyList to node dst.
dst,: | Destination |
Referenced by addNeighbor(), and handleTimerEvent().
00780 { 00781 // send KEYLIST:IND message 00782 KeyListMessage* msg = new KeyListMessage("KEYLIST"); 00783 msg->setCommand(KEYLIST); 00784 msg->setSrcNode(thisGiaNode); 00785 msg->setSrcCapacity(thisGiaNode.getCapacity()); 00786 msg->setSrcDegree(connectionDegree); 00787 00788 msg->setKeysArraySize(keyList.getSize()); 00789 for (uint i=0; i<keyList.getSize(); i++) 00790 msg->setKeys(i, keyList.get(i)); 00791 00792 msg->setLength(KEYLIST_L(msg)); 00793 00794 stat_keyListMessagesBytesSent += msg->byteLength(); 00795 stat_keyListMessages += 1; 00796 00797 sendMessageToUDP(dst, msg); 00798 }
void Gia::updateNeighborList | ( | GiaMessage * | msg | ) | [protected] |
Updates neighborlist with new capacity and connectiondegree informations from received message msg.
msg | Received message |
Referenced by handleUDPMessage().
00819 { 00820 if(neighbors->contains(msg->getSrcNode().key)) { 00821 neighbors->setConnectionDegree(msg->getSrcNode(),msg->getSrcDegree()); 00822 //neighbors->setCapacity(msg->getSrcNode(), msg->getSrcCapacity()); 00823 neighbors->updateTimestamp(msg->getSrcNode()); 00824 } 00825 }
void Gia::forwardSearchResponseMessage | ( | SearchResponseMessage * | msg | ) | [protected] |
Forwards a search response message to the next node in reverse-path.
msg | Message to forward to next node |
Referenced by handleUDPMessage(), and sendSearchResponseMessage().
00828 { 00829 if (responseMsg->getHopCount() != 0) { 00830 uint reversePathArraySize = responseMsg->getReversePathArraySize(); 00831 00832 // reached node which started search? 00833 if (reversePathArraySize == 0) { 00834 deliverSearchResult(responseMsg); 00835 } 00836 // forward message to next node in reverse path list 00837 else { 00838 NodeHandle targetNode = neighbors->get 00839 (responseMsg->getReversePath( 00840 reversePathArraySize-1)); 00841 00842 if(!(targetNode.isUnspecified())) { 00843 responseMsg->setDestKey(targetNode.key); 00844 responseMsg->setReversePathArraySize(reversePathArraySize-1); 00845 for (uint i=0; i<reversePathArraySize-1; i++) 00846 responseMsg->setReversePath(i, responseMsg->getReversePath(i)); 00847 responseMsg->setLength(responseMsg->length() - KEY_L); 00848 00849 stat_routeMessagesBytesSent += responseMsg->byteLength(); 00850 stat_routeMessages += 1; 00851 00852 if(responseMsg->getHopCount() > 0) 00853 RECORD_STATS(numAppDataForwarded++; bytesAppDataForwarded += 00854 responseMsg->byteLength()); 00855 00856 sendMessageToUDP(targetNode, responseMsg); 00857 } else { 00858 EV << "(Gia) wrong reverse path in " << *responseMsg 00859 << " ... deleted!" << endl; 00860 RECORD_STATS(numDropped++; 00861 bytesDropped += responseMsg->byteLength()); 00862 delete responseMsg; 00863 } 00864 } 00865 } 00866 // max hopcount reached. delete message 00867 else 00868 delete responseMsg; 00869 }
void Gia::forwardMessage | ( | GiaIDMessage * | msg, | |
bool | fromApplication | |||
) | [protected] |
Forwards a message to the next random selected node, biased random walk.
msg | Message to forward to next node | |
fromApplication | Marks if message is from application layer |
Referenced by handleTimerEvent(), handleUDPMessage(), processSearchMessage(), and route().
00872 { 00873 if (msg->getHopCount() == 0) { 00874 // Max-Hopcount reached. Discard message 00875 if (!fromApplication) 00876 tokenFactory->grantToken(); 00877 RECORD_STATS(numDropped++; bytesDropped += msg->byteLength()); 00878 delete msg; 00879 } else { 00880 // local delivery? 00881 if (msg->getDestKey() == thisGiaNode.key) { 00882 if(!fromApplication) 00883 tokenFactory->grantToken(); 00884 00885 if(debugOutput) 00886 EV << "(Gia) Deliver messsage " << msg 00887 << " to application at " << thisGiaNode << endl; 00888 00889 OverlayCtrlInfo* overlayCtrlInfo = 00890 new OverlayCtrlInfo(); 00891 00892 overlayCtrlInfo->setHopCount(msg->getHopCount()); 00893 overlayCtrlInfo->setSrcNode(msg->getSrcNode()); 00894 overlayCtrlInfo->setTransportType(ROUTE_TRANSPORT); 00895 overlayCtrlInfo->setDestComp(TIER1_COMP); // workaround 00896 overlayCtrlInfo->setSrcComp(TIER1_COMP); 00897 00898 msg->setControlInfo(overlayCtrlInfo); 00899 callDeliver(msg, msg->getDestKey()); 00900 } else { 00901 // forward message to next hop 00902 00903 // do we know the destination-node? 00904 if (neighbors->contains(msg->getDestKey())) { 00905 // yes, destination-Node is our neighbor 00906 NodeHandle targetNode = neighbors->get(msg->getDestKey()); 00907 GiaNeighborInfo* targetInfo= neighbors->get(targetNode); 00908 00909 if (targetInfo->receivedTokens == 0) { 00910 // wait for free token 00911 if (debugOutput) 00912 EV << "(Gia) No free Node, wait for free token" << endl; 00913 00914 //bad code 00915 std::string id; 00916 if (!fromApplication) 00917 id = "wait-for-token: " + msg->getID().toString(); 00918 else 00919 id = "wait-for-token-fromapp: " + 00920 msg->getID().toString(); 00921 cMessage* wait_timer = new cMessage(id.c_str()); 00922 wait_timer->encapsulate(msg); 00923 scheduleAt(simulation.simTime() + tokenWaitTime,wait_timer); 00924 return; 00925 } else { 00926 // decrease nextHop-tokencount 00927 neighbors->decreaseReceivedTokens(targetNode); 00928 //targetInfo->receivedTokens = targetInfo->receivedTokens - 1; 00929 00930 // forward msg to nextHop 00931 msg->setHopCount(msg->getHopCount()-1); 00932 msg->setSrcNode(thisGiaNode); 00933 msg->setSrcCapacity(thisGiaNode.getCapacity()); 00934 msg->setSrcDegree(connectionDegree); 00935 if (debugOutput) 00936 EV << "(Gia) Forwarding message " << msg 00937 << " to neighbor " << targetNode << endl; 00938 if (!fromApplication) 00939 tokenFactory->grantToken(); 00940 00941 stat_routeMessagesBytesSent += msg->byteLength(); 00942 stat_routeMessages += 1; 00943 00944 if(msg->getHopCount() > 0) 00945 RECORD_STATS(numAppDataForwarded++; bytesAppDataForwarded += 00946 msg->byteLength()); 00947 00948 sendMessageToUDP(targetNode, msg); 00949 } 00950 } else { 00951 // no => pick node with at least one token and highest capacity 00952 if (!msgBookkeepingList->contains(msg)) 00953 msgBookkeepingList->addMessage(msg); 00954 NodeHandle nextHop = msgBookkeepingList->getNextHop(msg); 00955 // do we have a neighbor who send us a token? 00956 if(nextHop.isUnspecified()) { 00957 // wait for free token 00958 if (debugOutput) 00959 EV << "(Gia) No free Node, wait for free token" << endl; 00960 std::string id; 00961 if (!fromApplication) 00962 id = "wait-for-token: " + msg->getID().toString(); 00963 else 00964 id = "wait-for-token-fromapp: " + 00965 msg->getID().toString(); 00966 cMessage* wait_timer = new cMessage(id.c_str()); 00967 wait_timer->encapsulate(msg); 00968 scheduleAt(simulation.simTime() + tokenWaitTime,wait_timer); 00969 return; 00970 } else { 00971 GiaNeighborInfo* nextHopInfo = neighbors->get(nextHop); 00972 if(nextHopInfo == NULL) { 00973 delete msg; 00974 return; //??? 00975 } 00976 // decrease nextHop-tokencount 00977 neighbors->decreaseReceivedTokens(nextHop); 00978 //nextHopInfo->receivedTokens--; 00979 00980 // forward msg to nextHop 00981 msg->setHopCount(msg->getHopCount()-1); 00982 msg->setSrcNode(thisGiaNode); 00983 msg->setSrcCapacity(thisGiaNode.getCapacity()); 00984 msg->setSrcDegree(connectionDegree); 00985 if (debugOutput) 00986 EV << "(Gia) Forwarding message " << msg 00987 << " to " << nextHop << endl; 00988 if (!fromApplication) 00989 tokenFactory->grantToken(); 00990 00991 stat_routeMessagesBytesSent += msg->byteLength(); 00992 stat_routeMessages += 1; 00993 00994 if(msg->getHopCount() > 0) 00995 RECORD_STATS(numAppDataForwarded++; bytesAppDataForwarded += 00996 msg->byteLength()); 00997 00998 sendMessageToUDP(nextHop, msg); 00999 } 01000 } 01001 } 01002 } 01003 }
void Gia::processSearchMessage | ( | SearchMessage * | msg, | |
bool | fromApplication | |||
) | [protected] |
Processes search message msg.
Generates Search_Response_Messages
msg | Search message | |
fromApplication | Marks if message is from application layer |
Referenced by handleAppMessage(), and handleUDPMessage().
01147 { 01148 OverlayKey searchKey = msg->getSearchKey(); 01149 01150 if (keyList.contains(searchKey)) { 01151 // this node contains search key 01152 sendSearchResponseMessage(thisGiaNode, msg); 01153 } 01154 01155 // check if neighbors contain search key 01156 for (uint i = 0; i < neighbors->getSize(); i++) { 01157 GiaKeyList* keyList = neighbors->getNeighborKeyList(neighbors->get(i)); 01158 if (keyList->contains(searchKey)) 01159 sendSearchResponseMessage(neighbors->get(i), msg); 01160 } 01161 01162 // forward search-message to next hop 01163 if (msg->getMaxResponses() > 0) { 01164 // actualize reverse path 01165 uint reversePathSize = msg->getReversePathArraySize(); 01166 01167 if (optimizeReversePath) 01168 for (uint i=0; i<reversePathSize; i++) { 01169 if (msg->getReversePath(i) == thisGiaNode.key) { 01170 // Our node already in ReversePath. 01171 // Delete successor nodes from ReversePath 01172 msg->setLength(msg->length() - (reversePathSize - i)*KEY_L); 01173 reversePathSize = i; // set new array size 01174 break; 01175 } 01176 } 01177 01178 msg->setReversePathArraySize(reversePathSize+1); 01179 msg->setReversePath(reversePathSize, thisGiaNode.key); 01180 msg->setLength(msg->length() + KEY_L); 01181 01182 forwardMessage(msg, fromApplication); 01183 } else { 01184 tokenFactory->grantToken(); 01185 delete msg; 01186 } 01187 }
void Gia::sendSearchResponseMessage | ( | const GiaNode & | srcNode, | |
SearchMessage * | msg | |||
) | [protected] |
Sends a response message to a received search query.
srcNode | Node which contains the searched key | |
msg | SearchMessage |
Referenced by processSearchMessage().
01084 { 01085 // does SearchMessage->foundNode[] already contain this node 01086 uint foundNodeArraySize = msg->getFoundNodeArraySize(); 01087 bool containsNode = false; 01088 for (uint i=0; i<foundNodeArraySize; i++) 01089 if (srcNode.key == msg->getFoundNode(i)) 01090 containsNode = true; 01091 01092 if (!containsNode && msg->getMaxResponses() > 0) { 01093 // add this node to SearchMessage->foundNode[] 01094 msg->setFoundNodeArraySize(foundNodeArraySize+1); 01095 msg->setFoundNode(foundNodeArraySize, srcNode.key); 01096 01097 // decrease SearchMessage->maxResponses 01098 msg->setMaxResponses(msg->getMaxResponses()-1); 01099 01100 // get first node in reverse-path 01101 uint reversePathArraySize = msg->getReversePathArraySize(); 01102 01103 if (reversePathArraySize == 0) { 01104 // we have the key 01105 // deliver response to application 01106 SearchResponseMessage* responseMsg = 01107 new SearchResponseMessage("ANSWER"); 01108 responseMsg->setCommand(ANSWER); 01109 responseMsg->setStatType(APP_DATA_STAT); 01110 responseMsg->setHopCount(maxHopCount); 01111 responseMsg->setSrcNode(thisGiaNode); 01112 responseMsg->setSrcCapacity(thisGiaNode.getCapacity()); 01113 responseMsg->setSrcDegree(connectionDegree); 01114 responseMsg->setSearchKey(msg->getSearchKey()); 01115 responseMsg->setFoundNode(srcNode); 01116 responseMsg->setID(OverlayKey::random()); 01117 responseMsg->setSearchHopCount(0); 01118 01119 responseMsg->setLength(SEARCHRESPONSE_L(responseMsg)); 01120 01121 deliverSearchResult(responseMsg); 01122 } else { 01123 uint reversePathArraySize(msg->getReversePathArraySize()); 01124 SearchResponseMessage* responseMsg = 01125 new SearchResponseMessage("ANSWER"); 01126 responseMsg->setCommand(ANSWER); 01127 responseMsg->setHopCount(maxHopCount); 01128 responseMsg->setSrcNode(srcNode); 01129 responseMsg->setSrcCapacity(srcNode.getCapacity()); 01130 responseMsg->setSrcDegree(connectionDegree); 01131 responseMsg->setSearchKey(msg->getSearchKey()); 01132 responseMsg->setFoundNode(srcNode); 01133 responseMsg->setReversePathArraySize(reversePathArraySize); 01134 for (uint i=0; i<reversePathArraySize; i++) 01135 responseMsg->setReversePath(i, msg->getReversePath(i)); 01136 responseMsg->setID(OverlayKey::random()); 01137 responseMsg->setSearchHopCount(reversePathArraySize); 01138 responseMsg->setLength(SEARCHRESPONSE_L(responseMsg)); 01139 01140 forwardSearchResponseMessage(responseMsg); 01141 } 01142 } 01143 }
void Gia::deliverSearchResult | ( | SearchResponseMessage * | msg | ) | [protected] |
Delivers search result to application layer.
msg | Search response message |
Referenced by forwardSearchResponseMessage(), and sendSearchResponseMessage().
01190 { 01191 OverlayCtrlInfo* overlayCtrlInfo = new OverlayCtrlInfo(); 01192 overlayCtrlInfo->setHopCount(msg->getSearchHopCount()); 01193 overlayCtrlInfo->setSrcNode(msg->getSrcNode()); 01194 overlayCtrlInfo->setTransportType(ROUTE_TRANSPORT); 01195 01196 GIAanswer* deliverMsg = new GIAanswer("GIA-Answer"); 01197 deliverMsg->setCommand(GIA_ANSWER); 01198 deliverMsg->setControlInfo(overlayCtrlInfo); 01199 deliverMsg->setSearchKey(msg->getSearchKey()); 01200 deliverMsg->setNode(msg->getFoundNode()); 01201 deliverMsg->setLength(GIAGETRSP_L(msg)); 01202 01203 send(deliverMsg, "to_app"); 01204 if (debugOutput) 01205 EV << "(Gia) Deliver search response " << msg 01206 << " to application at " << thisGiaNode << endl; 01207 01208 delete msg; 01209 }
uint Gia::maxNeighbors [protected] |
maximum number of neighbors
Referenced by acceptNode(), addNeighbor(), calculateLevelOfSatisfaction(), handleUDPMessage(), and initializeOverlay().
uint Gia::minNeighbors [protected] |
uint Gia::maxTopAdaptionInterval [protected] |
uint Gia::topAdaptionAggressiveness [protected] |
double Gia::maxLevelOfSatisfaction [protected] |
double Gia::updateDelay [protected] |
time between to update messages (in ms)
Referenced by addNeighbor(), initializeOverlay(), and removeNeighbor().
uint Gia::maxHopCount [protected] |
maximum time to live for sent messages
Referenced by changeState(), handleAppMessage(), initializeOverlay(), route(), sendSearchResponseMessage(), and sendToken().
uint Gia::messageTimeout [protected] |
uint Gia::neighborTimeout [protected] |
uint Gia::sendTokenTimeout [protected] |
uint Gia::tokenWaitTime [protected] |
double Gia::keyListDelay [protected] |
delay to send the keylist to our neighbors
Referenced by handleAppMessage(), and initializeOverlay().
bool Gia::outputNodeDetails [protected] |
bool Gia::optimizeReversePath [protected] |
double Gia::levelOfSatisfaction [protected] |
current level of statisfaction
Referenced by calculateLevelOfSatisfaction(), handleTimerEvent(), and initializeOverlay().
unsigned int Gia::connectionDegree [protected] |
Referenced by addNeighbor(), changeState(), forwardMessage(), handleAppMessage(), removeNeighbor(), route(), sendKeyListToNeighbor(), sendMessage_DISCONNECT(), sendMessage_JOIN_ACK(), sendMessage_JOIN_DNY(), sendMessage_JOIN_REQ(), sendMessage_JOIN_RSP(), sendMessage_UPDATE(), sendSearchResponseMessage(), and sendToken().
unsigned int Gia::receivedTokens [protected] |
Referenced by changeState().
unsigned int Gia::sentTokens [protected] |
Referenced by changeState().
GiaNode Gia::thisGiaNode [protected] |
this node
Referenced by acceptNode(), addNeighbor(), calculateLevelOfSatisfaction(), changeState(), deliverSearchResult(), finishOverlay(), forwardMessage(), handleAppMessage(), handleTimerEvent(), handleUDPMessage(), initializeOverlay(), processSearchMessage(), removeNeighbor(), route(), sendKeyListToNeighbor(), sendMessage_DISCONNECT(), sendMessage_JOIN_ACK(), sendMessage_JOIN_DNY(), sendMessage_JOIN_REQ(), sendMessage_JOIN_RSP(), sendMessage_UPDATE(), sendSearchResponseMessage(), and sendToken().
NodeHandle Gia::bootstrapNode [protected] |
next possible neighbor candidate
Referenced by changeState(), initializeOverlay(), and joinOverlay().
GiaMessageBookkeeping* Gia::msgBookkeepingList [protected] |
pointer to a message bookkeeping list
Referenced by forwardMessage(), handleTimerEvent(), initializeOverlay(), and ~Gia().
uint Gia::stat_joinCount [protected] |
number of sent join messages
Referenced by finishOverlay(), initializeOverlay(), sendMessage_JOIN_ACK(), sendMessage_JOIN_DNY(), sendMessage_JOIN_REQ(), and sendMessage_JOIN_RSP().
uint Gia::stat_joinBytesSent [protected] |
number of sent bytes of join messages
Referenced by finishOverlay(), initializeOverlay(), sendMessage_JOIN_ACK(), sendMessage_JOIN_DNY(), sendMessage_JOIN_REQ(), and sendMessage_JOIN_RSP().
uint Gia::stat_joinREQ [protected] |
number of sent join request messages
Referenced by finishOverlay(), initializeOverlay(), and sendMessage_JOIN_REQ().
uint Gia::stat_joinREQBytesSent [protected] |
number of sent bytes of join request messages
Referenced by finishOverlay(), initializeOverlay(), and sendMessage_JOIN_REQ().
uint Gia::stat_joinRSP [protected] |
number of sent join response messages
Referenced by finishOverlay(), initializeOverlay(), and sendMessage_JOIN_RSP().
uint Gia::stat_joinRSPBytesSent [protected] |
number of sent bytes of join response messages
Referenced by finishOverlay(), initializeOverlay(), and sendMessage_JOIN_RSP().
uint Gia::stat_joinACK [protected] |
number of sent join acknowledge messages
Referenced by finishOverlay(), initializeOverlay(), and sendMessage_JOIN_ACK().
uint Gia::stat_joinACKBytesSent [protected] |
number of sent bytes of join acknowledge messages
Referenced by finishOverlay(), initializeOverlay(), and sendMessage_JOIN_ACK().
uint Gia::stat_joinDNY [protected] |
number of sent join deny messages
Referenced by finishOverlay(), initializeOverlay(), and sendMessage_JOIN_DNY().
uint Gia::stat_joinDNYBytesSent [protected] |
number of sent bytes of join deny messages
Referenced by finishOverlay(), initializeOverlay(), and sendMessage_JOIN_DNY().
uint Gia::stat_disconnectMessages [protected] |
number of sent disconnect messages
Referenced by finishOverlay(), initializeOverlay(), and sendMessage_DISCONNECT().
uint Gia::stat_disconnectMessagesBytesSent [protected] |
number of sent bytes of disconnect messages
Referenced by finishOverlay(), initializeOverlay(), and sendMessage_DISCONNECT().
uint Gia::stat_updateMessages [protected] |
number of sent update messages
Referenced by finishOverlay(), initializeOverlay(), and sendMessage_UPDATE().
uint Gia::stat_updateMessagesBytesSent [protected] |
number of sent bytes of update messages
Referenced by finishOverlay(), initializeOverlay(), and sendMessage_UPDATE().
uint Gia::stat_tokenMessages [protected] |
uint Gia::stat_tokenMessagesBytesSent [protected] |
number of sent bytes of token messages
Referenced by finishOverlay(), initializeOverlay(), and sendToken().
uint Gia::stat_keyListMessages [protected] |
number of sent keylist messages
Referenced by finishOverlay(), initializeOverlay(), and sendKeyListToNeighbor().
uint Gia::stat_keyListMessagesBytesSent [protected] |
number of sent bytes of keylist messages
Referenced by finishOverlay(), initializeOverlay(), and sendKeyListToNeighbor().
uint Gia::stat_routeMessages [protected] |
number of sent route messages
Referenced by finishOverlay(), forwardMessage(), forwardSearchResponseMessage(), and initializeOverlay().
uint Gia::stat_routeMessagesBytesSent [protected] |
number of sent bytes of route messages
Referenced by finishOverlay(), forwardMessage(), forwardSearchResponseMessage(), and initializeOverlay().
uint Gia::stat_maxNeighbors [protected] |
uint Gia::stat_addedNeighbors [protected] |
number of added neighbors during life cycle of this node
Referenced by addNeighbor(), finishOverlay(), and initializeOverlay().
uint Gia::stat_removedNeighbors [protected] |
number of removed neighbors during life cycle of this node
Referenced by finishOverlay(), initializeOverlay(), and removeNeighbor().
uint Gia::stat_numSatisfactionMessages [protected] |
number of satisfaction self-messages
Referenced by finishOverlay(), handleTimerEvent(), and initializeOverlay().
double Gia::stat_sumLevelOfSatisfaction [protected] |
sum of level of satisfaction
Referenced by finishOverlay(), handleTimerEvent(), and initializeOverlay().
double Gia::stat_maxLevelOfSatisfaction [protected] |
maximum level of satisfaction
Referenced by finishOverlay(), handleTimerEvent(), and initializeOverlay().
cMessage* Gia::satisfaction_timer [protected] |
timer for satisfaction self-message
Referenced by changeState(), handleTimerEvent(), initializeOverlay(), and ~Gia().
cMessage* Gia::update_timer [protected] |
timer for update self-message
Referenced by addNeighbor(), initializeOverlay(), removeNeighbor(), and ~Gia().
cMessage* Gia::timedoutMessages_timer [protected] |
timer for message timeout
Referenced by changeState(), handleTimerEvent(), initializeOverlay(), and ~Gia().
cMessage* Gia::timedoutNeighbors_timer [protected] |
timer for neighbors timeout
Referenced by changeState(), handleTimerEvent(), initializeOverlay(), and ~Gia().
cMessage* Gia::sendKeyList_timer [protected] |
cMessage* Gia::sendToken_timer [protected] |
timer for send token
Referenced by changeState(), handleTimerEvent(), initializeOverlay(), and ~Gia().
GiaKeyListModule* Gia::keyListModule [protected] |
GiaNeighbors* Gia::neighbors [protected] |
pointer to neighbor list
Referenced by acceptNode(), addNeighbor(), calculateLevelOfSatisfaction(), changeState(), forwardMessage(), forwardSearchResponseMessage(), handleTimerEvent(), handleUDPMessage(), initializeOverlay(), processSearchMessage(), removeNeighbor(), sendMessage_JOIN_ACK(), sendMessage_JOIN_RSP(), updateNeighborList(), and updateTooltip().
GiaTokenFactory* Gia::tokenFactory [protected] |
pointer to TokenFactory
Referenced by changeState(), forwardMessage(), handleTimerEvent(), initializeOverlay(), and processSearchMessage().
GiaNeighborCandidateList Gia::neighCand [protected] |
list of all neighbor candidates
Referenced by handleTimerEvent(), handleUDPMessage(), and initializeOverlay().
GiaNeighborCandidateList Gia::knownNodes [protected] |
list of known nodes in the overlay
Referenced by changeState(), handleTimerEvent(), handleUDPMessage(), and initializeOverlay().
GiaKeyList Gia::keyList [protected] |
key list of this node
Referenced by addNeighbor(), handleAppMessage(), handleTimerEvent(), processSearchMessage(), and sendKeyListToNeighbor().