Changeset 5803 for source/ariba/overlay/modules/chord
- Timestamp:
- Aug 10, 2009, 5:55:19 PM (15 years ago)
- Location:
- source/ariba/overlay/modules/chord
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
source/ariba/overlay/modules/chord/Chord.cpp
r5780 r5803 58 58 // create routing table 59 59 this->table = new chord_routing_table(_nodeid, 2); 60 61 // init counters62 60 orphan_removal_counter = 0; 63 61 discovery_count = 0; … … 92 90 93 91 // establish link via base overlay 94 return baseoverlay.establishLink(endp, node, OverlayInterface::OVERLAY_SERVICE_ID, 95 remoteRelay ); 92 return baseoverlay.establishLink(endp, node, OverlayInterface::OVERLAY_SERVICE_ID, remoteRelay ); 96 93 } 97 94 … … 100 97 if (link.isUnspecified()) return 0; 101 98 return baseoverlay.sendMessage(msg, link); 102 }103 104 const LinkID& Chord::get_next_hop( const NodeID& id ) const {105 BOOST_FOREACH( const back_route& br, back_routes )106 if (br.id==id) return br.link;107 const route_item* item = table->get_next_hop(id);108 if (item==NULL) return LinkID::UNSPECIFIED;109 return item->info;110 99 } 111 100 … … 123 112 124 113 // get next hop 125 LinkID next_link =get_next_hop(destination);126 if ( !next_link.isUnspecified()) send(&cmsg, next_link);114 const route_item* item = table->get_next_hop(destination); 115 if (item!=NULL && !item->info.isUnspecified()) send(&cmsg, item->info); 127 116 } 128 117 … … 190 179 void Chord::routeMessage(const NodeID& destnode, Message* msg) { 191 180 // get next hop 192 LinkID next_link =get_next_hop(destnode);181 const route_item* item = table->get_next_hop(destnode); 193 182 194 183 // message for this node? yes-> delegate to base overlay 195 if ( destnode == nodeid)184 if (item->id == nodeid || destnode == nodeid) 196 185 baseoverlay.incomingRouteMessage( msg, LinkID::UNSPECIFIED, nodeid ); 197 186 … … 199 188 ChordMessage cmsg(ChordMessage::route, nodeid, destnode); 200 189 cmsg.encapsulate(msg); 201 send(&cmsg, next_link);190 send(&cmsg, item->info); 202 191 } 203 192 } … … 214 203 /// @see OverlayInterface.h 215 204 const LinkID& Chord::getNextLinkId( const NodeID& id ) const { 216 return get_next_hop(id); 205 // get next hop 206 const route_item* item = table->get_next_hop(id); 207 208 // returns a unspecified id when this is itself 209 if (item == NULL || item->id == nodeid) 210 return LinkID::UNSPECIFIED; 211 212 /// return routing info 213 return item->info; 217 214 } 218 215 … … 223 220 // all nodes that I know, fingers, succ/pred 224 221 for (size_t i = 0; i < table->size(); i++){ 225 if ( /*(*table)[i]->ref_count != 0226 && */!(*table)[i]->info.isUnspecified())222 if ((*table)[i]->ref_count != 0 223 && !(*table)[i]->info.isUnspecified()) 227 224 nodelist.push_back((*table)[i]->id); 228 225 } … … 309 306 case M::route: { 310 307 // find next hop 311 LinkID next_link = get_next_hop(m->getDestination()); 312 313 // add to back-routes 314 bool found = false; 315 BOOST_FOREACH( back_route br, back_routes) { 316 if (br.id == m->getSource()) { 317 br.link = link; 318 br.lastseen = time(NULL); 319 found = true; 320 break; 321 } 322 } 323 if (!found) { 324 back_route br; 325 br.id = m->getSource(); 326 br.link = link; 327 br.lastseen = time(NULL); 328 back_routes.push_back(br); 329 } 308 const route_item* item = table->get_next_hop(m->getDestination()); 330 309 331 310 // next hop == myself? 332 311 if (m->getDestination() == nodeid) { // yes-> route to base overlay 333 312 logging_debug("Send message to baseoverlay"); 334 baseoverlay.incomingRouteMessage( m, next_link, remote );313 baseoverlay.incomingRouteMessage( m, item->info, remote ); 335 314 } 336 315 // no-> route to next hop 337 316 else { 338 //logging_debug("Route chord message to "339 //<< item->id.toString() << " (destination=" << m->getDestination() << ")");340 send(m, next_link);317 logging_debug("Route chord message to " 318 << item->id.toString() << " (destination=" << m->getDestination() << ")"); 319 send(m, item->info); 341 320 } 342 321 break; … … 378 357 logging_debug("Discovery split: routing discovery message to successor " 379 358 << succ_item->id.toString() ); 380 cmsg_s.setDestination(succ_item->id);381 359 send(&cmsg_s, succ_item->info); 382 360 } … … 392 370 logging_debug("Discovery split: routing discovery message to predecessor " 393 371 << pred_item->id.toString() ); 394 cmsg_p.setDestination(pred_item->id);395 372 send(&cmsg_p, pred_item->info); 396 373 } … … 399 376 else { 400 377 // find next hop 401 LinkID next_link = get_next_hop(m->getDestination()); 402 // logging_debug("routing discovery message to " << 403 // linkitem->id.toString() ); 404 send(m, next_link); 378 const route_item* item = table->get_next_hop(m->getDestination()); 379 if (item == NULL || item->id == nodeid) break; 380 logging_debug("routing discovery message to " << 381 item->id.toString() ); 382 send(m, item->info); 405 383 } 406 384 break; … … 453 431 void Chord::eventFunction() { 454 432 stabilize_counter++; 455 if (stabilize_counter < 0 || stabilize_counter >= 2) {433 if (stabilize_counter < 0 || stabilize_counter == 4) { 456 434 457 435 // reset counter … … 487 465 orphan_removal_counter++; 488 466 if (orphan_removal_counter <0 || orphan_removal_counter >= 4) { 489 back_routes.clear();490 /* for (vector<back_route>::iterator i = back_routes.begin();491 i!=back_routes.end(); i++) {492 back_route& br = *i;493 if (difftime(br.lastseen,time(NULL))>5) i =494 back_routes.erase(i)-1;495 }496 */497 467 logging_info("Running orphan removal"); 498 468 orphan_removal_counter = 0; -
source/ariba/overlay/modules/chord/Chord.h
r5756 r5803 80 80 int discovery_count; 81 81 82 class back_route {83 public:84 NodeID id;85 LinkID link;86 time_t lastseen;87 };88 vector<back_route> back_routes;89 90 const LinkID& get_next_hop( const NodeID& id ) const;91 92 82 // helper: sets up a link using the "base overlay" 93 83 LinkID setup( const EndpointDescriptor& endp, -
source/ariba/overlay/modules/chord/messages/ChordMessage.h
r5776 r5803 88 88 } 89 89 90 void setSource(const NodeID& source ) {91 this->source = source;92 }93 94 90 const NodeID& getSource() const { 95 91 return source; 96 }97 98 void setDestination(const NodeID& destination ) {99 this->destination = destination;100 92 } 101 93
Note:
See TracChangeset
for help on using the changeset viewer.