Changeset 3690 for source/ariba/overlay/BaseOverlay.cpp
- Timestamp:
- May 26, 2009, 1:40:23 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
source/ariba/overlay/BaseOverlay.cpp
r3374 r3690 1 // [Licen ce]1 // [License] 2 2 // The Ariba-Underlay Copyright 3 3 // … … 35 35 // official policies, either expressed or implied, of the Institute of 36 36 // Telematics. 37 // [Licen ce]37 // [License] 38 38 39 39 #include "BaseOverlay.h" … … 43 43 #include "ariba/CommunicationListener.h" 44 44 #include "ariba/SideportListener.h" 45 46 #include "ariba/overlay/messages/OverlayMsg.h" 47 #include "ariba/overlay/messages/JoinRequest.h" 48 #include "ariba/overlay/messages/JoinReply.h" 49 #include "ariba/overlay/messages/LinkRequest.h" 45 50 46 51 namespace ariba { … … 175 180 void BaseOverlay::createSpoVNet(const SpoVNetID& id, const OverlayParameterSet& param, const SecurityParameterSet& sec, const QoSParameterSet& qos){ 176 181 177 // 178 // set the state that we are an initiator, 179 // this way incoming messages are handled correctly 180 // 181 182 logging_info( "creating spovnet " + id.toString() << " with nodeid " << nodeId.toString() ); 182 // set the state that we are an initiator, this way incoming messages are 183 // handled correctly 184 logging_info( "creating spovnet " + id.toString() << 185 " with nodeid " << nodeId.toString() ); 183 186 184 187 spovnetId = id; … … 192 195 } 193 196 194 //195 197 // bootstrap against ourselfs 196 //197 198 198 overlayInterface->joinOverlay(); 199 BOOST_FOREACH( NodeListener* i, nodeListeners ) {199 BOOST_FOREACH( NodeListener* i, nodeListeners ) 200 200 i->onJoinCompleted( spovnetId ); 201 }202 201 203 202 ovl.visChangeNodeIcon ( ovlId, nodeId, OvlVis::ICON_ID_CAMERA ); … … 205 204 } 206 205 207 const LinkID BaseOverlay::establishLink(const NodeID& node, const ServiceID& service){ 208 209 // TODO: if this is not a onehop overlay the operation will go asynchronously 210 const EndpointDescriptor& endpoint = overlayInterface->resolveNode( node ); 211 if( endpoint == EndpointDescriptor::UNSPECIFIED ){ 212 logging_error( "could not resolve node to endpoint. unable to establish link" ); 213 return LinkID::UNSPECIFIED; 214 } 215 216 logging_debug( "baseoverlay called to establish link between node " << 217 node.toString() << " on endpoint " << endpoint.toString() << 218 " for service " << service.toString() ); 219 220 return establishLink( endpoint, service ); 221 } 222 223 const LinkID BaseOverlay::establishLink(const EndpointDescriptor& ep, const ServiceID& service){ 206 207 /// establishes a link between two arbitrary nodes 208 const LinkID BaseOverlay::establishLink( const NodeID& node, 209 const ServiceID& service, const LinkID& link_id ) { 224 210 225 211 if( !communicationListeners.contains( service ) ){ … … 228 214 } 229 215 230 const LinkID link = bc->establishLink( ep ); 216 // copy link id 217 LinkID linkid = link_id; 218 219 // create link id if necessary 220 if (linkid.isUnspecified()) linkid = LinkID::create(); 221 222 // debug message 223 logging_debug( "BaseOverlay called to establish link between node " << 224 node.toString() << " for service " << service.toString() ); 225 226 // create link request message with own link id 227 OverlayMsg overlay_msg( OverlayMsg::OverlayMessageTypeLinkRequest, service, nodeId ); 228 uint32_t nonce = (uint32_t)(rand() ^ (rand() << 16) ^ time(NULL)); 229 LinkRequest link_request_msg( nonce, &bc->getEndpointDescriptor() ); 230 overlay_msg.encapsulate( &link_request_msg ); 231 pendingLinks.insert( make_pair(nonce, linkid) ); 232 233 // debug message 234 logging_debug( "BaseOverlay routes LinkRequest message to node " << node.toString() ); 235 236 // route message to overlay node 237 overlayInterface->routeMessage( node, &overlay_msg ); 238 239 CommunicationListener* receiver = communicationListeners.get( service ); 240 assert( receiver != NULL ); 241 242 LinkItem item (linkid, NodeID::UNSPECIFIED, service, receiver); 243 linkMapping.insert( make_pair(linkid, item) ); 244 245 return linkid; 246 } 247 248 const LinkID BaseOverlay::establishLink( const EndpointDescriptor& ep, 249 const ServiceID& service, const LinkID& linkid ){ 250 251 if( !communicationListeners.contains( service ) ){ 252 logging_error( "no registered listener on serviceid " << service.toString() ); 253 return LinkID::UNSPECIFIED; 254 } 255 256 const LinkID link = bc->establishLink( ep, linkid ); 231 257 232 258 CommunicationListener* receiver = communicationListeners.get( service ); … … 260 286 seqnum_t BaseOverlay::sendMessage(const Message* message, const LinkID& link ){ 261 287 262 logging_debug( "baseoverlay is sending message on link " << link.toString() );288 logging_debug( "baseoverlay is sending data message on link " << link.toString() ); 263 289 264 290 LinkMapping::iterator i = linkMapping.find( link ); … … 268 294 } 269 295 270 OverlayMsg overmsg( OverlayMsg::OverlayMessageTypeData, i->second.service, nodeId ); 296 OverlayMsg overmsg( 297 OverlayMsg::OverlayMessageTypeData, i->second.service, nodeId ); 271 298 overmsg.encapsulate( const_cast<Message*>(message) ); 272 299 … … 342 369 return overlayInterface->resolveNode( node ); 343 370 } 371 344 372 345 373 bool BaseOverlay::bind(CommunicationListener* listener, const ServiceID& sid){ … … 567 595 } 568 596 597 569 598 bool BaseOverlay::receiveMessage(const Message* message, 570 const LinkID& link, const NodeID& /*the nodeid is invalid in this case! removed var to prevent errors*/ ){ 571 572 OverlayMsg* overlayMsg = ((Message*)message)->decapsulate<OverlayMsg>(); 599 const LinkID& link, const NodeID& 600 /*the nodeid is invalid in this case! removed var to prevent errors*/ ){ 601 602 // decapsulate overlay message 603 logging_debug( "go msg " << message->toString()); 604 OverlayMsg* overlayMsg = const_cast<Message*>(message)->decapsulate<OverlayMsg>(); 573 605 if( overlayMsg == NULL ) return false; 574 606 … … 577 609 if( item != linkMapping.end() ) item->second.markused(); 578 610 579 // 580 // handle user date that we forward to the 581 // appropriate service using the service id 582 // in the message. as we don't know the class 583 // of message that the service handles, we 584 // forward it as a pure Message* 585 // 586 611 /* ************************************************************************ 612 /* handle user date that we forward to the appropriate service using the 613 * service id in the message. as we don't know the class of message that 614 * the service handles, we forward it as a pure Message 615 */ 587 616 if( overlayMsg->isType(OverlayMsg::OverlayMessageTypeData) ) { 588 617 … … 601 630 } // if( overlayMsg->isType(OverlayMsg::OverlayMessageTypeData) ) 602 631 603 // 604 // handle spovnet instance join requests 605 // 606 632 /* ************************************************************************ 633 /* Handle spovnet instance join requests 634 */ 607 635 else if( overlayMsg->isType(OverlayMsg::OverlayMessageTypeJoinRequest) && 608 636 state == BaseOverlayStateInitiator){ … … 614 642 joinReq->getSpoVNetID().toString() ); 615 643 616 // 617 // make sure that the node actually wants to join 618 // the correct spovnet id that we administrate 619 // 620 644 /* make sure that the node actually wants to join 645 * the correct spovnet id that we administrate */ 621 646 if( joinReq->getSpoVNetID() != spovnetId ){ 622 647 logging_error( "received join request for spovnet we don't handle " << … … 641 666 joiningNodes.push_back( overlayMsg->getSourceNode() ); 642 667 643 // 644 // send back our spovnetid, default overlay parameters, 645 // join allow result, and ourself as the endpoint 646 // to bootstrap the overlay against 647 // 648 668 // send back our spovnetid, default overlay parameters, join allow 669 // result, and ourself as the end-point to bootstrap the overlay against 649 670 OverlayMsg retmsg( OverlayMsg::OverlayMessageTypeJoinReply, nodeId ); 650 671 JoinReply replyMsg( spovnetId, OverlayParameterSet::DEFAULT, … … 656 677 return true; 657 678 658 } // else if( overlayMsg->isType(OverlayMsg::OverlayMessageTypeJoinRequest) && state == BaseOverlayStateInitiator)659 660 // 661 / / handle replies to spovnet instance join requests662 //663 679 } // else if( overlayMsg->isType(OverlayMsg::OverlayMessageTypeJoinRequest) 680 // && state == BaseOverlayStateInitiator) 681 682 /* ************************************************************************ 683 * handle replies to spovnet instance join requests 684 */ 664 685 else if( overlayMsg->isType(OverlayMsg::OverlayMessageTypeJoinReply) && 665 686 state == BaseOverlayStateJoinInitiated){ 666 687 667 logging_debug( "baseoverlay received message of type OverlayMessageTypeJoinReply" ); 688 logging_debug( 689 "baseoverlay received message of type OverlayMessageTypeJoinReply"); 668 690 669 691 JoinReply* replyMsg = overlayMsg->decapsulate<JoinReply>(); 670 692 logging_info( "received spovnet join reply" ); 671 693 672 // 673 // make sure that we actually wanted to get 674 // into the spovnet whose id is in the message 675 // 676 694 // ensure that we actually wanted to get into the spovnet whose id is 695 // in the message 677 696 if( replyMsg->getSpoVNetID() != spovnetId ){ 678 697 logging_error( "received spovnet join reply for spovnet " << … … 681 700 spovnetId.toString() ); 682 701 683 // state does not change here, maybe 684 // the reply does come in later 702 // state does not change here, maybe the reply does come in later 685 703 return false; 686 704 } 687 705 688 // 689 // if we did not get access to the spovnet 690 // notify of the failure and 706 // if we did not get access to the spovnet notify of the failure and 691 707 // close the link to the initiator 692 //693 694 708 if( ! replyMsg->getJoinAllowed() ){ 695 709 … … 708 722 } 709 723 710 logging_info( "join request has been accepted for spovnet " << spovnetId.toString() ); 711 712 // 713 // if we did get access to the spovnet 714 // we try to create the overlay structure 715 // as given in the reply message 716 // 717 718 overlayInterface = OverlayFactory::create( *this, replyMsg->getParam(), nodeId, this ); 724 logging_info( "join request has been accepted for spovnet " << 725 spovnetId.toString() ); 726 727 // if we did get access to the spovnet we try to create the overlay 728 // structure as given in the reply message 729 overlayInterface = OverlayFactory::create( *this, 730 replyMsg->getParam(), nodeId, this ); 719 731 720 732 if( overlayInterface == NULL ){ … … 726 738 727 739 // inform all registered services of the event 728 BOOST_FOREACH( NodeListener* i, nodeListeners ) {740 BOOST_FOREACH( NodeListener* i, nodeListeners ) 729 741 i->onJoinFailed( spovnetId ); 730 }731 742 732 743 return true; 733 744 } 734 745 735 // 736 // now start the join process for the overlay. 737 // the join process for the spovnet baseoverlay 738 // is now complete. we use the endpoint for 739 // overlay structure bootstrapping that the 740 // initiator provided in his reply message 741 // 742 746 /* now start the join process for the overlay. the join process for the 747 * spovnet baseoverlay is now complete. we use the endpoint for overlay 748 * structure bootstrapping that the initiator provided in his reply 749 * message */ 743 750 state = BaseOverlayStateCompleted; 744 751 ovl.visChangeNodeColor( ovlId, nodeId, OvlVis::NODE_COLORS_GREEN); … … 757 764 758 765 759 // 760 // handle update messages for link establishment 761 // 762 766 /* ************************************************************************ 767 * handle update messages for link establishment 768 */ 763 769 else if( overlayMsg->isType(OverlayMsg::OverlayMessageTypeUpdate) ){ 764 770 765 logging_debug( "baseoverlay received message of type OverlayMessageTypeUpdate" ); 771 logging_debug( 772 "baseoverlay received message of type OverlayMessageTypeUpdate" 773 ); 766 774 767 775 const NodeID& sourcenode = overlayMsg->getSourceNode(); 768 776 const ServiceID& service = overlayMsg->getService(); 769 777 770 // 771 // we should have a linkmapping for the link, otherwise 772 // we ignore update messages 773 // 774 778 // linkmapping for the link available? no-> ignore 775 779 LinkMapping::iterator i = linkMapping.find( link ); 776 if( i == linkMapping.end() ) {780 if( i == linkMapping.end() ) { 777 781 logging_warn( "received overlay update message for link " << 778 782 link.toString() << " for which we have no mapping" ); … … 780 784 } 781 785 782 //783 786 // update our link mapping information for this link 784 // 785 786 bool changed = ( i->second.node != sourcenode ) || ( i->second.service != service ); 787 787 bool changed = 788 ( i->second.node != sourcenode ) || 789 ( i->second.service != service ); 788 790 i->second.node = sourcenode; 789 791 i->second.service = service; 790 792 791 //792 793 // if our link information changed, we send out an update, too 793 //794 795 794 if( changed ){ 796 795 OverlayMsg overMsg( OverlayMsg::OverlayMessageTypeUpdate, i->second.service, nodeId ); … … 798 797 } 799 798 800 //801 799 // set the correct listener service for the linkitem 802 800 // now we can tell the registered service of the linkup event 803 //804 805 801 if( !communicationListeners.contains( service ) ){ 806 802 logging_warn( "linkup event for service that has not been registered" ); … … 810 806 CommunicationListener* iface = communicationListeners.get( service ); 811 807 if( iface == NULL || iface == &CommunicationListener::DEFAULT ){ 812 logging_warn( "linkup event for service that has been registered with a NULL interface" ); 808 logging_warn( "linkup event for service that has been registered " 809 "with a NULL interface" ); 813 810 return true; 814 811 } … … 817 814 i->second.markused(); 818 815 819 //820 816 // ask the service whether it wants to accept this link 821 //822 823 817 if( iface->onLinkRequest(sourcenode) ){ 824 818 … … 838 832 } // else if( overlayMsg->isType(OverlayMsg::OverlayMessageTypeUpdate) ) 839 833 840 // 841 // bye messages to say goodbye 842 // 843 844 else if( overlayMsg->isType(OverlayMsg::OverlayMessageTypeBye)){ 845 846 logging_debug( "baseoverlay received message of type OverlayMessageTypeBye" ); 847 848 logging_debug( "received bye message from " << 834 /* ************************************************************************ 835 * handle bye messages 836 */ 837 else if( overlayMsg->isType(OverlayMsg::OverlayMessageTypeBye) ) { 838 839 logging_debug( "BaseOverlay received message of type OverlayMessageTypeBye" ); 840 logging_debug( "Received bye message from " << 849 841 overlayMsg->getSourceNode().toString() ); 850 842 851 // 852 // if we are the initiator and receive a bye from a node 853 // the node just left. if we are a node and receive a bye 854 // from the initiator, we have to close, too. 855 // 856 843 /* if we are the initiator and receive a bye from a node 844 * the node just left. if we are a node and receive a bye 845 * from the initiator, we have to close, too. 846 */ 857 847 if( overlayMsg->getSourceNode() == spovnetInitiator ){ 858 848 … … 869 859 870 860 } else { 871 872 // a node that said goodbye and we are the initiator 873 // don't have to do much here, as the node also 874 // will go out of the overlay structure 861 // a node that said goodbye and we are the initiator don't have to 862 // do much here, as the node also will go out of the overlay 863 // structure 875 864 logging_info( "node left " << overlayMsg->getSourceNode() ); 876 877 865 } 878 866 … … 881 869 } // else if( overlayMsg->isType(OverlayMsg::OverlayMessageTypeBye)) 882 870 883 // 884 // something wrong ... 885 // 886 871 /* ************************************************************************ 872 * handle link request forwarded through the overlay 873 */ 874 else if( overlayMsg->isType(OverlayMsg::OverlayMessageTypeLinkRequest)) { 875 LinkRequest* linkReq = overlayMsg->decapsulate<LinkRequest>(); 876 const ServiceID& service = overlayMsg->getService(); 877 if (linkReq->isReply()) { 878 879 // find link 880 PendingLinkMap::iterator i = pendingLinks.find( linkReq->getNonce() ); 881 if ( i == pendingLinks.end() ) { 882 logging_error( "Nonce not found in link request" ); 883 return true; 884 } 885 886 // debug message 887 logging_debug( "LinkRequest reply received. Establishing link " 888 << i->second << " to " << (linkReq->getEndpoint()->toString()) 889 << " for service " << service.toString() 890 << " with nonce " << linkReq->getNonce() 891 ); 892 893 // establishing link 894 bc->establishLink( *linkReq->getEndpoint(), i->second ); 895 } else { 896 OverlayMsg overlay_msg( OverlayMsg::OverlayMessageTypeLinkRequest, service, nodeId ); 897 LinkRequest link_request_msg( 898 linkReq->getNonce(), &bc->getEndpointDescriptor(), true ); 899 overlay_msg.encapsulate( &link_request_msg ); 900 901 // debug message 902 logging_debug( "Sending LinkRequest reply for link with nonce " << 903 linkReq->getNonce() ); 904 905 // route message back over overlay 906 overlayInterface->routeMessage( 907 overlayMsg->getSourceNode(), &overlay_msg 908 ); 909 } 910 } // if( overlayMsg->isType(OverlayMsg::OverlayMessageTypeLinkRequest)) 911 912 /* ************************************************************************ 913 * unknown message type ... error! 914 */ 887 915 else { 888 916 … … 1008 1036 } 1009 1037 1010 BOOST_FOREACH( const LinkID lnk, oldlinks ) {1038 BOOST_FOREACH( const LinkID lnk, oldlinks ) { 1011 1039 logging_debug( "auto-link " << lnk.toString() << " timed out and is getting dropped" ); 1012 1040 dropLink( lnk );
Note:
See TracChangeset
for help on using the changeset viewer.