Changeset 5743 for source/ariba
- Timestamp:
- Aug 6, 2009, 2:32:48 PM (15 years ago)
- Location:
- source/ariba/overlay
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
source/ariba/overlay/BaseOverlay.cpp
r5738 r5743 74 74 } 75 75 76 /// erases a link descriptor 77 void BaseOverlay::eraseDescriptor( const LinkID& link, bool communication ) { 78 for ( vector<LinkDescriptor*>::iterator i = links.begin(); i!= links.end(); i++) { 79 LinkDescriptor* ld = *i; 80 if ((communication ? ld->communicationId : ld->overlayId) == link) { 81 delete ld; 82 links.erase(i); 83 break; 84 } 85 } 86 } 87 88 /// adds a link descriptor 89 LinkDescriptor* BaseOverlay::addDescriptor( const LinkID& link ) { 90 LinkDescriptor* desc = getDescriptor( link ); 91 if ( desc == NULL ) { 92 desc = new LinkDescriptor(); 93 desc->overlayId = link; 94 links.push_back(desc); 95 } 96 return desc; 97 } 98 99 /// returns a auto-link descriptor 76 100 LinkDescriptor* BaseOverlay::getAutoDescriptor( const NodeID& node, const ServiceID& service ) { 77 101 BOOST_FOREACH( LinkDescriptor* lp, links ) … … 84 108 } 85 109 86 void BaseOverlay::eraseDescriptor( const LinkID& link, bool communication ) { 87 for ( vector<LinkDescriptor*>::iterator i = links.begin(); i!= links.end(); i++) { 88 LinkDescriptor* ld = *i; 89 if ((communication ? ld->communicationId : ld->overlayId) == link) { 90 delete ld; 91 links.erase(i); 92 break; 93 } 94 } 95 } 96 97 LinkDescriptor* BaseOverlay::addDescriptor( const LinkID& link ) { 98 LinkDescriptor* desc = getDescriptor( link ); 99 if ( desc == NULL ) { 100 desc = new LinkDescriptor(); 101 desc->overlayId = link; 102 links.push_back(desc); 103 } 104 return desc; 105 } 106 107 /// returns a direct link relay descriptor to the given relay node 108 LinkDescriptor* BaseOverlay::getRelayDescriptor( const NodeID& relayNode ) { 109 BOOST_FOREACH( LinkDescriptor* lp, links ) 110 if (lp->remoteNode == relayNode && 111 lp->service == OverlayInterface::OVERLAY_SERVICE_ID && 112 lp->relay == false && 113 lp->up) 114 return lp; 115 return NULL; 116 } 117 118 /// find a proper relay node 119 const NodeID BaseOverlay::findRelayNode( const NodeID id ) { 110 /// returns a direct local link relay descriptor for the given remote node 111 LinkDescriptor* BaseOverlay::getRelayDescriptor( const NodeID& id ) { 112 113 // get used next hop towards node 120 114 LinkDescriptor* rld = NULL; 121 115 NodeID relayNode = NodeID::UNSPECIFIED; 122 123 // get used next hop towards node124 116 LinkID rlid = overlayInterface->getNextLinkId(id); 125 while ( relayNode.isUnspecified() && !rlid.isUnspecified() && rld == NULL ) { 126 117 if ( relayNode.isUnspecified() && !rlid.isUnspecified() && rld == NULL ) { 127 118 // get descriptor of first hop 128 119 rld = getDescriptor(rlid); 129 logging_info( rld ); 130 131 // is first hop a relay path? yes-> try to find real link! 132 if ( rld->relay ) 133 relayNode = getRelayDescriptor(rld->localRelay)->remoteNode; 120 121 // is first hop a relay path use local relay 122 if ( rld->relay ) relayNode = rld->localRelay; 134 123 135 124 // no-> a proper relay node has been found … … 150 139 } 151 140 152 // do not return myself or use the node as relay node 153 if (relayNode == nodeId) 154 return NodeID::UNSPECIFIED; 155 else { 156 logging_info( "Returning relay node " << relayNode.toString() ); 157 return relayNode; 158 } 159 } 160 161 /// forwards a message over relays/directly using link descriptor 162 seqnum_t BaseOverlay::sendMessage( Message* message, const LinkDescriptor* ld ) { 163 164 // directly send message 165 if ( !ld->communicationId.isUnspecified() && ld->communicationUp ) { 166 logging_debug("Send: Sending message via Base Communication"); 167 return bc->sendMessage( ld->communicationId, message ); 168 } 169 170 // relay message 171 else if ( ld->relay ) { 172 173 logging_debug("Send: Relaying message to node " 174 << ld->remoteNode.toString() 175 << " using relay " << ld->localRelay 176 ); 177 /* 178 // get local relay link descriptor and mark as used for relaying 179 LinkDescriptor* rld = getRelayDescriptor(ld->localRelay); 180 if (rld==NULL) { 181 logging_error("Send: Relay descriptor for relay " << 182 ld->localRelay.toString() << " is unknown."); 183 return -1; 184 } 185 rld->markAsRelay();*/ 186 187 // create a information relay message to inform the relay about 188 OverlayMsg overlay_msg( OverlayMsg::typeRelay, ld->service, nodeId ); 189 RelayMessage relayMsg( RelayMessage::typeInform, ld->remoteRelay, ld->remoteNode, ld->remoteLinkId ); 190 relayMsg.encapsulate( message ); 191 overlay_msg.encapsulate( &relayMsg ); 192 193 // route message to relay node in order to inform it! 194 logging_debug("sendMessage: Sending message over relayed link with" << ld ); 195 sendOverlay( &overlay_msg, ld->localRelay ); 196 return 0; 197 } 198 199 // error 200 else { 201 logging_error( "Could not send message descriptor=" << ld ); 202 return -1; 203 } 204 return -1; 205 } 206 141 // no local relay found-> damn! 142 if (relayNode.isUnspecified()) return NULL; 143 144 // get descriptor 145 BOOST_FOREACH( LinkDescriptor* lp, links ) 146 if (lp->remoteNode == relayNode && 147 lp->service == OverlayInterface::OVERLAY_SERVICE_ID && 148 lp->relay == false && 149 lp->up) 150 return lp; 151 152 return NULL; 153 } 154 155 /// returns the link descriptor that is actually used for sending a message over the overöay 207 156 LinkDescriptor* BaseOverlay::getSendDescriptor( const NodeID& nodeid, bool follow ) { 208 157 for (size_t i=0; i<links.size(); i++) … … 221 170 } 222 171 172 NodeID BaseOverlay::getRelayNode( const NodeID& remoteNode ) { 173 LinkDescriptor* rld = getRelayDescriptor(remoteNode); 174 return rld!=NULL ? rld->remoteNode : NodeID::UNSPECIFIED; 175 } 176 223 177 /// routes a message over the overlay or directly sends it when a link is open 224 seqnum_t BaseOverlay::sendOverlay( Message* message, const NodeID& nodeid ) { 178 seqnum_t BaseOverlay::sendOverlay( Message* message, const NodeID& nodeid, const NodeID& remoteRelay ) { 179 /// send message directly to a neighbor 225 180 for (size_t i=0; i<links.size(); i++) 226 181 if ( !links[i]->relay && … … 230 185 links[i]->remoteNode == nodeid && 231 186 links[i]->service == OverlayInterface::OVERLAY_SERVICE_ID) { 187 188 // mark as relay and send message 232 189 links[i]->markAsRelay(); 233 190 return sendMessage( message, links[i] ); 234 break; 235 } 191 } 192 193 /// send relayed message over the overlay 194 if (!remoteRelay.isUnspecified()) { 195 // create a information relay message to inform the relay about 196 OverlayMsg overlay_msg( 197 OverlayMsg::typeRelay, OverlayInterface::OVERLAY_SERVICE_ID, nodeId); 198 RelayMessage relayMsg( RelayMessage::typeInform, remoteRelay, nodeid, LinkID::UNSPECIFIED ); 199 relayMsg.encapsulate( message ); 200 overlay_msg.encapsulate( &relayMsg ); 201 202 // get local relay link 203 LinkDescriptor* rld = getRelayDescriptor(nodeid); 204 205 // local relay available? send to local relay! 206 if (rld!=NULL) { 207 rld->markAsRelay(); 208 sendMessage(&overlay_msg, rld); 209 } else 210 overlayInterface->routeMessage(remoteRelay, &overlay_msg); 211 212 // finished 213 return 0; 214 } 215 216 // common case: send message over the overlay 236 217 overlayInterface->routeMessage(nodeid, message); 237 218 return 0; 219 } 220 221 /// forwards a message over relays/directly using link descriptor 222 seqnum_t BaseOverlay::sendMessage( Message* message, const LinkDescriptor* ld ) { 223 224 // directly send message 225 if ( !ld->communicationId.isUnspecified() && ld->communicationUp ) { 226 logging_debug("Send: Sending message via Base Communication"); 227 return bc->sendMessage( ld->communicationId, message ); 228 } 229 230 // relay message 231 else if ( ld->relay ) { 232 233 // sending a relayed message 234 logging_debug("Send: Relaying message to node " 235 << ld->remoteNode.toString() 236 << " using relay " << ld->localRelay 237 ); 238 239 // create a information relay message to inform the relay about 240 OverlayMsg overlay_msg( OverlayMsg::typeRelay, ld->service, nodeId ); 241 RelayMessage relayMsg( RelayMessage::typeInform, ld->remoteRelay, ld->remoteNode, ld->remoteLinkId ); 242 relayMsg.encapsulate( message ); 243 overlay_msg.encapsulate( &relayMsg ); 244 245 // route message to relay node in order to inform it! 246 logging_debug("sendMessage: Sending message over relayed link with" << ld ); 247 sendOverlay( &overlay_msg, ld->localRelay ); 248 return 0; 249 } 250 251 // error 252 else { 253 logging_error( "Could not send message descriptor=" << ld ); 254 return -1; 255 } 256 return -1; 238 257 } 239 258 … … 258 277 259 278 // create relay link descriptor 260 NodeID relayNode = findRelayNode(remoteNode); 279 LinkDescriptor* rld = getRelayDescriptor(remoteNode); 280 NodeID relayNode = rld != NULL ? rld->remoteNode : NodeID::UNSPECIFIED; 261 281 262 282 // add descriptor … … 454 474 const LinkID BaseOverlay::establishLink( 455 475 const EndpointDescriptor& ep, const NodeID& nodeid, 456 const ServiceID& service, const LinkID& linkid ) {476 const ServiceID& service, const NodeID& remoteRelay, const LinkID& linkid ) { 457 477 458 478 LinkID link_id = linkid; … … 460 480 // establish link via overlay 461 481 if (!nodeid.isUnspecified()) 462 link_id = establishLink( nodeid, service, link_id );482 link_id = establishLink( nodeid, service, remoteRelay, link_id ); 463 483 464 484 // establish link directly if only ep is known 465 //if (nodeid.isUnspecified())466 establish Link( ep, service, link_id );485 if (nodeid.isUnspecified()) 486 establishDirectLink( ep, service, link_id ); 467 487 468 488 return link_id; … … 470 490 471 491 /// call base communication's establish link and add link mapping 472 const LinkID BaseOverlay::establish Link( const EndpointDescriptor& ep,492 const LinkID BaseOverlay::establishDirectLink( const EndpointDescriptor& ep, 473 493 const ServiceID& service, const LinkID& linkid ) { 474 494 … … 502 522 /// establishes a link between two arbitrary nodes 503 523 const LinkID BaseOverlay::establishLink( const NodeID& node, 504 const ServiceID& service, const LinkID& link_id ) {524 const ServiceID& service, const NodeID& remoteRelay, const LinkID& link_id ) { 505 525 506 526 // do not establish a link to myself! … … 509 529 // create a link descriptor 510 530 LinkDescriptor* ld = createLinkDescriptor( node, service, link_id ); 531 ld->remoteRelay = remoteRelay; 511 532 512 533 // create link request message with own link id … … 809 830 810 831 // if link is a relayed link ->convert to direct link 811 if (ld->relay ) {832 if (ld->relay && !ld->remoteLinkId.isUnspecified() ) { 812 833 logging_info( "Converting to direct link: " << ld ); 813 834 ld->up = true; … … 1025 1046 1026 1047 // drop initiator link 1027 1028 1048 if(bcLink != LinkID::UNSPECIFIED){ 1029 1049 bc->dropLink( bcLink ); -
source/ariba/overlay/BaseOverlay.h
r5624 r5743 160 160 bool isStarted(); 161 161 162 /// Tries to establish a direct or overlay link 163 const LinkID establishLink(const EndpointDescriptor& ep, 164 const NodeID& node, const ServiceID& service, 165 const NodeID& remoteRelay = NodeID::UNSPECIFIED, 166 const LinkID& linkid = LinkID::UNSPECIFIED); 167 162 168 /** 163 169 * Starts a link establishment procedure to the specfied node … … 169 175 */ 170 176 const LinkID establishLink(const NodeID& node, const ServiceID& service, 177 const NodeID& remoteRelay = NodeID::UNSPECIFIED, 171 178 const LinkID& linkid = LinkID::UNSPECIFIED); 172 173 /**174 * Starts a link establishment procedure to the specified175 * endpoint and to the specified service. Concurrently it tries to176 * establish a relay link over the overlay using the nodeid177 */178 const LinkID establishLink(const EndpointDescriptor& ep, const NodeID& nodeid,179 const ServiceID& service, const LinkID& linkid = LinkID::UNSPECIFIED);180 179 181 180 /** … … 183 182 * endpoint and to the specified service 184 183 */ 185 const LinkID establish Link(const EndpointDescriptor& ep,184 const LinkID establishDirectLink(const EndpointDescriptor& ep, 186 185 const ServiceID& service, const LinkID& linkid = LinkID::UNSPECIFIED); 187 186 … … 412 411 413 412 /// returns a direct link relay descriptor to the given relay node 414 LinkDescriptor* getRelayDescriptor( const NodeID& relayNode ); 415 416 /// find a proper relay node that is directly connected to this node 417 const NodeID findRelayNode( const NodeID id ); 413 LinkDescriptor* getRelayDescriptor( const NodeID& remoteNode ); 414 415 /// returns the local relay node to a given remote node 416 NodeID getRelayNode( const NodeID& remoteNode ); 417 418 /// returns the direct link the message to a neighbor is send to 419 LinkDescriptor* getSendDescriptor( const NodeID& nodeid, bool follow = true ); 420 421 /// routes a message over the overlay or directly sends it when a link is open 422 seqnum_t sendOverlay( Message* message, const NodeID& nodeid, 423 const NodeID& remoteRelay = NodeID::UNSPECIFIED ); 418 424 419 425 /// forwards a message over relays/overlay/directly using link descriptor 420 426 seqnum_t sendMessage( Message* message, const LinkDescriptor* ld ); 421 422 LinkDescriptor* getSendDescriptor( const NodeID& nodeid, bool follow = true );423 424 /// routes a message over the overlay or directly sends it when a link is open425 seqnum_t sendOverlay( Message* message, const NodeID& nodeid );426 427 427 428 /// creates a link descriptor, applys relay semantics if possible -
source/ariba/overlay/modules/chord/Chord.cpp
r5736 r5743 57 57 58 58 // create routing table 59 this->table = new chord_routing_table(_nodeid, 2);59 this->table = new chord_routing_table(_nodeid, 4); 60 60 orphan_removal_counter = 0; 61 61 discovery_count = 0; … … 71 71 72 72 /// helper: sets up a link using the base overlay 73 LinkID Chord::setup(const EndpointDescriptor& endp, const NodeID& node ) {73 LinkID Chord::setup(const EndpointDescriptor& endp, const NodeID& node, const NodeID& remoteRelay ) { 74 74 logging_debug("Request to setup link to " << endp.toString() ); 75 75 76 // check if we already have a connection 76 77 for (int i=0; i<table->size(); i++) 77 78 if ((*table)[i]->id == node && !((*table)[i]->info.isUnspecified())) … … 89 90 90 91 // establish link via base overlay 91 return baseoverlay.establishLink(endp, node, OverlayInterface::OVERLAY_SERVICE_ID );92 return baseoverlay.establishLink(endp, node, OverlayInterface::OVERLAY_SERVICE_ID, remoteRelay ); 92 93 } 93 94 … … 105 106 Discovery dmsg; 106 107 dmsg.setSourceEndpoint(&baseoverlay.getEndpointDescriptor()); 108 dmsg.setSourceRelay(baseoverlay.getRelayNode(destination)); 107 109 dmsg.setFollowType(Discovery::normal); 108 110 dmsg.setTTL((uint8_t) ttl); … … 120 122 Discovery dmsg; 121 123 dmsg.setSourceEndpoint(&baseoverlay.getEndpointDescriptor()); 124 dmsg.setSourceRelay(baseoverlay.getRelayNode(nodeid)); 122 125 dmsg.setFollowType(Discovery::successor); 123 126 dmsg.setTTL((uint8_t)3); … … 130 133 Discovery dmsg; 131 134 dmsg.setSourceEndpoint(&baseoverlay.getEndpointDescriptor()); 135 dmsg.setSourceRelay(baseoverlay.getRelayNode(nodeid)); 132 136 dmsg.setFollowType(Discovery::predecessor); 133 137 dmsg.setTTL((uint8_t)3); … … 332 336 // check if source node can be added to routing table and setup link 333 337 if (m->getSource() != nodeid && table->is_insertable(m->getSource())) 334 setup(*dmsg->getSourceEndpoint(), m->getSource() );338 setup(*dmsg->getSourceEndpoint(), m->getSource(), dmsg->getSourceRelay() ); 335 339 336 340 // delegate discovery message -
source/ariba/overlay/modules/chord/Chord.h
r5668 r5743 81 81 82 82 // helper: sets up a link using the "base overlay" 83 LinkID setup( const EndpointDescriptor& endp, const NodeID& node = NodeID::UNSPECIFIED ); 83 LinkID setup( const EndpointDescriptor& endp, 84 const NodeID& node = NodeID::UNSPECIFIED, 85 const NodeID& remoteRelay = NodeID::UNSPECIFIED ); 84 86 85 87 // helper: sends a message using the "base overlay" -
source/ariba/overlay/modules/chord/messages/Discovery.h
r5681 r5743 70 70 this->follow_type = msg.follow_type; 71 71 this->ttl = msg.ttl; 72 this->source_relay = msg.source_relay; 72 73 this->source_endpoint = msg.source_endpoint; 73 74 } … … 99 100 } 100 101 102 inline void setSourceRelay( const NodeID& relay ) { 103 source_relay = relay; 104 } 105 106 inline const NodeID& getSourceRelay() const { 107 return source_relay; 108 } 101 109 private: 102 110 uint8_t follow_type; 103 111 uint8_t ttl; 104 112 EndpointDescriptor source_endpoint; 113 NodeID source_relay; 105 114 }; 106 115 … … 112 121 113 122 // serialize end-point 114 X && source_ endpoint;123 X && source_relay && source_endpoint; 115 124 } sznEnd(); 116 125 -
source/ariba/overlay/modules/onehop/OneHop.cpp
r5624 r5743 154 154 } else { 155 155 bootstrapLinks.push_back( 156 baseoverlay.establish Link( bootstrapEp,156 baseoverlay.establishDirectLink( bootstrapEp, 157 157 OverlayInterface::OVERLAY_SERVICE_ID ) 158 158 ); … … 314 314 315 315 logging_debug( "building up link to node in overlay " << node.toString() ); 316 const LinkID link = baseoverlay.establish Link( *((*i).second),316 const LinkID link = baseoverlay.establishDirectLink( *((*i).second), 317 317 OverlayInterface::OVERLAY_SERVICE_ID ); 318 318
Note:
See TracChangeset
for help on using the changeset viewer.