Changeset 5316 for source/ariba/overlay/BaseOverlay.cpp
- Timestamp:
- Jul 24, 2009, 8:53:41 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
source/ariba/overlay/BaseOverlay.cpp
r5284 r5316 245 245 BaseOverlay::BaseOverlay() : 246 246 bc(NULL), overlayInterface(NULL), nodeId(NodeID::UNSPECIFIED), 247 spovnetId(SpoVNetID::UNSPECIFIED), initiatorLink(LinkID::UNSPECIFIED),248 s tate(BaseOverlayStateInvalid), sideport(&SideportListener::DEFAULT) {247 spovnetId(SpoVNetID::UNSPECIFIED), state(BaseOverlayStateInvalid), 248 sideport(&SideportListener::DEFAULT), started(false) { 249 249 } 250 250 … … 268 268 Timer::setInterval( 500 ); 269 269 Timer::start(); 270 271 started = true; 272 state = BaseOverlayStateInvalid; 270 273 } 271 274 … … 285 288 bc->unregisterMessageReceiver( this ); 286 289 bc->unregisterEventListener( this ); 290 291 started = false; 292 state = BaseOverlayStateInvalid; 293 } 294 295 bool BaseOverlay::isStarted(){ 296 return started; 287 297 } 288 298 … … 292 302 const EndpointDescriptor& bootstrapEp) { 293 303 294 ovl.visShowNodeBubble ( ovlId, nodeId, "joining..." ); 304 if(id != spovnetId){ 305 logging_error("attempt to join against invalid spovnet, call initiate first"); 306 return; 307 } 308 309 310 //ovl.visShowNodeBubble ( ovlId, nodeId, "joining..." ); 295 311 logging_info( "Starting to join spovnet " << id.toString() << 296 312 " with nodeid " << nodeId.toString()); 297 313 298 // contact the spovnet initiator and request to join. if the join is granted we will 299 // receive further information on the structure of the overlay that is used in the spovnet 300 // but first, we have to establish a link to the initiator... 301 spovnetId = id; 302 state = BaseOverlayStateJoinInitiated; 303 304 initiatorLink = bc->establishLink( bootstrapEp ); 305 logging_info("join process initiated for " << id.toString() << "..."); 314 if(bootstrapEp == EndpointDescriptor::UNSPECIFIED && state == BaseOverlayStateInvalid){ 315 316 // bootstrap against ourselfs 317 logging_debug("joining spovnet locally"); 318 319 overlayInterface->joinOverlay(); 320 state = BaseOverlayStateCompleted; 321 BOOST_FOREACH( NodeListener* i, nodeListeners ) 322 i->onJoinCompleted( spovnetId ); 323 324 //ovl.visChangeNodeIcon ( ovlId, nodeId, OvlVis::ICON_ID_CAMERA ); 325 //ovl.visChangeNodeColor( ovlId, nodeId, OvlVis::NODE_COLORS_GREEN ); 326 327 logging_debug("starting overlay bootstrap module"); 328 overlayBootstrap.start(this, spovnetId, nodeId); 329 overlayBootstrap.publish(bc->getEndpointDescriptor()); 330 331 } else { 332 333 // bootstrap against another node 334 logging_debug("joining spovnet remotely against " << bootstrapEp.toString()); 335 336 const LinkID& lnk = bc->establishLink( bootstrapEp ); 337 bootstrapLinks.push_back(lnk); 338 logging_info("join process initiated for " << id.toString() << "..."); 339 } 306 340 } 307 341 … … 310 344 logging_info( "Leaving spovnet " << spovnetId ); 311 345 bool ret = ( state != this->BaseOverlayStateInvalid ); 346 347 logging_debug("stopping overlay bootstrap module"); 348 overlayBootstrap.stop(); 349 overlayBootstrap.revoke(); 312 350 313 351 logging_debug( "Dropping all auto-links" ); … … 329 367 overlayInterface->leaveOverlay(); 330 368 331 // leave spovnet 332 if( state != BaseOverlayStateInitiator ) { 333 // then, leave the spovnet baseoverlay 334 OverlayMsg overMsg( OverlayMsg::typeBye, nodeId ); 335 bc->sendMessage( initiatorLink, &overMsg ); 336 337 // drop the link and set to correct state 338 bc->dropLink( initiatorLink ); 339 initiatorLink = LinkID::UNSPECIFIED; 340 } 369 // drop still open bootstrap links 370 BOOST_FOREACH( LinkID lnk, bootstrapLinks ) 371 bc->dropLink( lnk ); 341 372 342 373 // change to inalid state 343 374 state = BaseOverlayStateInvalid; 344 ovl.visShutdown( ovlId, nodeId, string("") );375 //ovl.visShutdown( ovlId, nodeId, string("") ); 345 376 346 377 // inform all registered services of the event … … 362 393 363 394 spovnetId = id; 364 state = BaseOverlayStateInitiator;365 395 366 396 overlayInterface = OverlayFactory::create( *this, param, nodeId, this ); … … 368 398 logging_fatal( "overlay structure not supported" ); 369 399 state = BaseOverlayStateInvalid; 400 401 BOOST_FOREACH( NodeListener* i, nodeListeners ) 402 i->onJoinFailed( spovnetId ); 403 370 404 return; 371 405 } 372 373 // bootstrap against ourselfs374 overlayInterface->joinOverlay();375 BOOST_FOREACH( NodeListener* i, nodeListeners )376 i->onJoinCompleted( spovnetId );377 378 ovl.visChangeNodeIcon ( ovlId, nodeId, OvlVis::ICON_ID_CAMERA );379 ovl.visChangeNodeColor( ovlId, nodeId, OvlVis::NODE_COLORS_GREEN );380 406 } 381 407 … … 695 721 LinkDescriptor* ld = getDescriptor(id, true); 696 722 697 // handle initiator link698 if( state == BaseOverlayStateJoinInitiated && id == initiatorLink){723 // handle bootstrap link we initiated 724 if( std::find(bootstrapLinks.begin(), bootstrapLinks.end(), id) != bootstrapLinks.end() ){ 699 725 logging_info( 700 726 "Join has been initiated by me and the link is now up. " << … … 759 785 const address_v* local, const address_v* remote) { 760 786 787 // erase bootstrap links 788 vector<LinkID>::iterator it = std::find( bootstrapLinks.begin(), bootstrapLinks.end(), id ); 789 if( it != bootstrapLinks.end() ) bootstrapLinks.erase( it ); 790 761 791 // get descriptor for link 762 792 LinkDescriptor* ld = getDescriptor(id, true); … … 800 830 const address_v* local, const address_v* remote) { 801 831 logging_debug( "Link fail with base communication link id=" << id ); 832 833 // erase bootstrap links 834 vector<LinkID>::iterator it = std::find( bootstrapLinks.begin(), bootstrapLinks.end(), id ); 835 if( it != bootstrapLinks.end() ) bootstrapLinks.erase( it ); 802 836 803 837 // get descriptor for link … … 927 961 logging_debug("received join reply message"); 928 962 JoinReply* replyMsg = overlayMsg->decapsulate<JoinReply>(); 929 assert(state == BaseOverlayStateJoinInitiated);930 963 931 964 // correct spovnet? … … 942 975 943 976 // drop initiator link 944 bc->dropLink( initiatorLink ); 945 initiatorLink = LinkID::UNSPECIFIED; 946 state = BaseOverlayStateInvalid; 977 978 if(bcLink != LinkID::UNSPECIFIED){ 979 bc->dropLink( bcLink ); 980 981 vector<LinkID>::iterator it = std::find( 982 bootstrapLinks.begin(), bootstrapLinks.end(), bcLink); 983 if( it != bootstrapLinks.end() ) 984 bootstrapLinks.erase(it); 985 } 947 986 948 987 // inform all registered services of the event 949 988 BOOST_FOREACH( NodeListener* i, nodeListeners ) 950 989 i->onJoinFailed( spovnetId ); 990 951 991 return true; 952 992 } … … 956 996 spovnetId.toString() ); 957 997 998 logging_debug( "Using bootstrap end-point " 999 << replyMsg->getBootstrapEndpoint().toString() ); 1000 1001 // 958 1002 // create overlay structure from spovnet parameter set 959 overlayInterface = OverlayFactory::create( 960 *this, replyMsg->getParam(), nodeId, this ); 961 962 // overlay structure supported? no-> fail! 963 if( overlayInterface == NULL ) { 964 logging_error( "overlay structure not supported" ); 965 966 bc->dropLink( initiatorLink ); 967 initiatorLink = LinkID::UNSPECIFIED; 968 state = BaseOverlayStateInvalid; 1003 // if we have not boostrapped yet against some other node 1004 // 1005 1006 if( overlayInterface == NULL ){ 1007 1008 logging_debug("first-time bootstrapping"); 1009 1010 overlayInterface = OverlayFactory::create( 1011 *this, replyMsg->getParam(), nodeId, this ); 1012 1013 // overlay structure supported? no-> fail! 1014 if( overlayInterface == NULL ) { 1015 logging_error( "overlay structure not supported" ); 1016 1017 if(bcLink != LinkID::UNSPECIFIED){ 1018 bc->dropLink( bcLink ); 1019 1020 vector<LinkID>::iterator it = std::find( 1021 bootstrapLinks.begin(), bootstrapLinks.end(), bcLink); 1022 if( it != bootstrapLinks.end() ) 1023 bootstrapLinks.erase(it); 1024 } 1025 1026 // inform all registered services of the event 1027 BOOST_FOREACH( NodeListener* i, nodeListeners ) 1028 i->onJoinFailed( spovnetId ); 1029 1030 return true; 1031 } 1032 1033 // everything ok-> join the overlay! 1034 state = BaseOverlayStateCompleted; 1035 overlayInterface->createOverlay(); 1036 1037 overlayInterface->joinOverlay( replyMsg->getBootstrapEndpoint() ); 1038 1039 // update ovlvis 1040 //ovl.visChangeNodeColor( ovlId, nodeId, OvlVis::NODE_COLORS_GREEN); 969 1041 970 1042 // inform all registered services of the event 971 1043 BOOST_FOREACH( NodeListener* i, nodeListeners ) 972 i->onJoinFailed( spovnetId ); 973 974 return true; 975 } 976 977 // everything ok-> join the overlay! 978 state = BaseOverlayStateCompleted; 979 overlayInterface->createOverlay(); 980 logging_debug( "Using bootstrap end-point " 981 << replyMsg->getBootstrapEndpoint().toString() ); 982 overlayInterface->joinOverlay( replyMsg->getBootstrapEndpoint() ); 983 984 // update ovlvis 985 ovl.visChangeNodeColor( ovlId, nodeId, OvlVis::NODE_COLORS_GREEN); 986 987 // inform all registered services of the event 988 BOOST_FOREACH( NodeListener* i, nodeListeners ) 989 i->onJoinCompleted( spovnetId ); 1044 i->onJoinCompleted( spovnetId ); 1045 1046 } else { 1047 1048 // this is not the first bootstrap, just join the additional node 1049 logging_debug("not first-time bootstrapping"); 1050 overlayInterface->joinOverlay( replyMsg->getBootstrapEndpoint() ); 1051 1052 } // if( overlayInterface == NULL ) 990 1053 991 1054 return true; … … 1103 1166 1104 1167 // --------------------------------------------------------------------- 1105 // handle bye messages1106 // ---------------------------------------------------------------------1107 case OverlayMsg::typeBye: {1108 logging_debug( "received bye message from " <<1109 overlayMsg->getSourceNode().toString() );1110 1111 /* if we are the initiator and receive a bye from a node1112 * the node just left. if we are a node and receive a bye1113 * from the initiator, we have to close, too.1114 */1115 if( overlayMsg->getSourceNode() == spovnetInitiator ) {1116 1117 bc->dropLink( initiatorLink );1118 initiatorLink = LinkID::UNSPECIFIED;1119 state = BaseOverlayStateInvalid;1120 1121 logging_fatal( "initiator ended spovnet" );1122 1123 // inform all registered services of the event1124 BOOST_FOREACH( NodeListener* i, nodeListeners )1125 i->onLeaveFailed( spovnetId );1126 1127 } else {1128 // a node that said goodbye and we are the initiator don't have to1129 // do much here, as the node also will go out of the overlay1130 // structure1131 logging_info( "node left " << overlayMsg->getSourceNode() );1132 }1133 1134 return true;1135 1136 }1137 1138 // ---------------------------------------------------------------------1139 1168 // handle link request forwarded through the overlay 1140 1169 // --------------------------------------------------------------------- 1141 1170 case OverlayMsg::typeLinkRequest: { 1171 1172 logging_debug( "received link request on link" ); 1142 1173 1143 1174 // decapsulate message … … 1261 1292 case OverlayMsg::typeRelay: { 1262 1293 1294 logging_debug( "received relay request on link" ); 1295 1263 1296 // decapsulate message 1264 1297 RelayMessage* relayMsg = overlayMsg->decapsulate<RelayMessage>(); … … 1347 1380 // --------------------------------------------------------------------- 1348 1381 case OverlayMsg::typeKeepAlive: { 1382 1383 logging_debug( "received keep-alive on link" ); 1384 1349 1385 if ( ld != NULL ) { 1350 1386 //logging_force("Keep-Alive for "<< ld->overlayId); … … 1358 1394 // --------------------------------------------------------------------- 1359 1395 case OverlayMsg::typeDirectLink: { 1396 1397 logging_debug( "received direct link replacement request" ); 1398 1360 1399 LinkDescriptor* rld = getDescriptor( overlayMsg->getRelayLink() ); 1361 1400 logging_force( "Received direct link convert notification for " << rld ); … … 1380 1419 1381 1420 } /* switch */ 1421 1382 1422 return false; 1383 1423 } … … 1398 1438 } 1399 1439 1400 vector<NodeID> BaseOverlay::getOverlayNeighbors( ) const {1440 vector<NodeID> BaseOverlay::getOverlayNeighbors(bool deep) const { 1401 1441 // the known nodes _can_ also include our node, so we remove ourself 1402 vector<NodeID> nodes = overlayInterface->getKnownNodes( );1442 vector<NodeID> nodes = overlayInterface->getKnownNodes(deep); 1403 1443 vector<NodeID>::iterator i = find( nodes.begin(), nodes.end(), this->nodeId ); 1404 1444 if( i != nodes.end() ) nodes.erase( i ); … … 1499 1539 // drop links 1500 1540 BOOST_FOREACH( const LinkDescriptor* ld, oldlinks ) { 1501 if (!ld->communicationId.isUnspecified() && ld->communicationId == initiatorLink) { 1541 1542 vector<LinkID>::iterator it = std::find( 1543 bootstrapLinks.begin(), bootstrapLinks.end(), ld->communicationId); 1544 1545 if (!ld->communicationId.isUnspecified() && it != bootstrapLinks.end() ){ 1502 1546 logging_force( "Not dropping initiator link: " << ld ); 1503 1547 continue;
Note:
See TracChangeset
for help on using the changeset viewer.