Changeset 5743 for source


Ignore:
Timestamp:
Aug 6, 2009, 2:32:48 PM (15 years ago)
Author:
mies
Message:
 
Location:
source/ariba/overlay
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • source/ariba/overlay/BaseOverlay.cpp

    r5738 r5743  
    7474}
    7575
     76/// erases a link descriptor
     77void 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
     89LinkDescriptor* 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
    76100LinkDescriptor* BaseOverlay::getAutoDescriptor( const NodeID& node, const ServiceID& service ) {
    77101        BOOST_FOREACH( LinkDescriptor* lp, links )
     
    84108}
    85109
    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
     111LinkDescriptor* BaseOverlay::getRelayDescriptor( const NodeID& id ) {
     112
     113        // get used next hop towards node
    120114        LinkDescriptor* rld = NULL;
    121115        NodeID relayNode = NodeID::UNSPECIFIED;
    122 
    123         // get used next hop towards node
    124116        LinkID rlid = overlayInterface->getNextLinkId(id);
    125         while ( relayNode.isUnspecified() && !rlid.isUnspecified() && rld == NULL ) {
    126 
     117        if ( relayNode.isUnspecified() && !rlid.isUnspecified() && rld == NULL ) {
    127118                // get descriptor of first hop
    128119                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;
    134123
    135124                // no-> a proper relay node has been found
     
    150139        }
    151140
    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
    207156LinkDescriptor* BaseOverlay::getSendDescriptor( const NodeID& nodeid, bool follow ) {
    208157        for (size_t i=0; i<links.size(); i++)
     
    221170}
    222171
     172NodeID BaseOverlay::getRelayNode( const NodeID& remoteNode ) {
     173        LinkDescriptor* rld = getRelayDescriptor(remoteNode);
     174        return rld!=NULL ? rld->remoteNode : NodeID::UNSPECIFIED;
     175}
     176
    223177/// 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 ) {
     178seqnum_t BaseOverlay::sendOverlay( Message* message, const NodeID& nodeid, const NodeID& remoteRelay  ) {
     179        /// send message directly to a neighbor
    225180        for (size_t i=0; i<links.size(); i++)
    226181                if ( !links[i]->relay &&
     
    230185                        links[i]->remoteNode == nodeid &&
    231186                        links[i]->service == OverlayInterface::OVERLAY_SERVICE_ID) {
     187
     188                        // mark as relay and send message
    232189                        links[i]->markAsRelay();
    233190                        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
    236217        overlayInterface->routeMessage(nodeid, message);
    237218        return 0;
     219}
     220
     221/// forwards a message over relays/directly using link descriptor
     222seqnum_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;
    238257}
    239258
     
    258277
    259278        // create relay link descriptor
    260         NodeID relayNode = findRelayNode(remoteNode);
     279        LinkDescriptor* rld = getRelayDescriptor(remoteNode);
     280        NodeID relayNode = rld != NULL ? rld->remoteNode : NodeID::UNSPECIFIED;
    261281
    262282        // add descriptor
     
    454474const LinkID BaseOverlay::establishLink(
    455475        const EndpointDescriptor& ep, const NodeID& nodeid,
    456         const ServiceID& service, const LinkID& linkid ) {
     476        const ServiceID& service, const NodeID& remoteRelay, const LinkID& linkid ) {
    457477
    458478        LinkID link_id = linkid;
     
    460480        // establish link via overlay
    461481        if (!nodeid.isUnspecified())
    462                 link_id = establishLink( nodeid, service, link_id );
     482                link_id = establishLink( nodeid, service, remoteRelay, link_id );
    463483
    464484        // establish link directly if only ep is known
    465 //      if (nodeid.isUnspecified())
    466                 establishLink( ep, service, link_id );
     485        if (nodeid.isUnspecified())
     486                establishDirectLink( ep, service, link_id );
    467487
    468488        return link_id;
     
    470490
    471491/// call base communication's establish link and add link mapping
    472 const LinkID BaseOverlay::establishLink( const EndpointDescriptor& ep,
     492const LinkID BaseOverlay::establishDirectLink( const EndpointDescriptor& ep,
    473493                const ServiceID& service, const LinkID& linkid ) {
    474494
     
    502522/// establishes a link between two arbitrary nodes
    503523const 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 ) {
    505525
    506526        // do not establish a link to myself!
     
    509529        // create a link descriptor
    510530        LinkDescriptor* ld = createLinkDescriptor( node, service, link_id );
     531        ld->remoteRelay = remoteRelay;
    511532
    512533        // create link request message with own link id
     
    809830
    810831                // if link is a relayed link ->convert to direct link
    811                 if (ld->relay) {
     832                if (ld->relay && !ld->remoteLinkId.isUnspecified() ) {
    812833                        logging_info( "Converting to direct link: " << ld );
    813834                        ld->up = true;
     
    10251046
    10261047                                // drop initiator link
    1027 
    10281048                                if(bcLink != LinkID::UNSPECIFIED){
    10291049                                        bc->dropLink( bcLink );
  • source/ariba/overlay/BaseOverlay.h

    r5624 r5743  
    160160        bool isStarted();
    161161
     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
    162168        /**
    163169         * Starts a link establishment procedure to the specfied node
     
    169175         */
    170176        const LinkID establishLink(const NodeID& node, const ServiceID& service,
     177                const NodeID& remoteRelay = NodeID::UNSPECIFIED,
    171178                const LinkID& linkid = LinkID::UNSPECIFIED);
    172 
    173         /**
    174          * Starts a link establishment procedure to the specified
    175          * endpoint and to the specified service. Concurrently it tries to
    176          * establish a relay link over the overlay using the nodeid
    177          */
    178         const LinkID establishLink(const EndpointDescriptor& ep, const NodeID& nodeid,
    179                 const ServiceID& service, const LinkID& linkid = LinkID::UNSPECIFIED);
    180179
    181180        /**
     
    183182         * endpoint and to the specified service
    184183         */
    185         const LinkID establishLink(const EndpointDescriptor& ep,
     184        const LinkID establishDirectLink(const EndpointDescriptor& ep,
    186185                const ServiceID& service, const LinkID& linkid = LinkID::UNSPECIFIED);
    187186
     
    412411
    413412        /// 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 );
    418424
    419425        /// forwards a message over relays/overlay/directly using link descriptor
    420426        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 open
    425         seqnum_t sendOverlay( Message* message, const NodeID& nodeid );
    426427
    427428        /// creates a link descriptor, applys relay semantics if possible
  • source/ariba/overlay/modules/chord/Chord.cpp

    r5736 r5743  
    5757
    5858        // create routing table
    59         this->table = new chord_routing_table(_nodeid, 2);
     59        this->table = new chord_routing_table(_nodeid, 4);
    6060        orphan_removal_counter = 0;
    6161        discovery_count = 0;
     
    7171
    7272/// helper: sets up a link using the base overlay
    73 LinkID Chord::setup(const EndpointDescriptor& endp, const NodeID& node) {
     73LinkID Chord::setup(const EndpointDescriptor& endp, const NodeID& node, const NodeID& remoteRelay ) {
    7474        logging_debug("Request to setup link to " << endp.toString() );
    7575
     76        // check if we already have a connection
    7677        for (int i=0; i<table->size(); i++)
    7778                if ((*table)[i]->id == node && !((*table)[i]->info.isUnspecified()))
     
    8990
    9091        // 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 );
    9293}
    9394
     
    105106        Discovery dmsg;
    106107        dmsg.setSourceEndpoint(&baseoverlay.getEndpointDescriptor());
     108        dmsg.setSourceRelay(baseoverlay.getRelayNode(destination));
    107109        dmsg.setFollowType(Discovery::normal);
    108110        dmsg.setTTL((uint8_t) ttl);
     
    120122                Discovery dmsg;
    121123                dmsg.setSourceEndpoint(&baseoverlay.getEndpointDescriptor());
     124                dmsg.setSourceRelay(baseoverlay.getRelayNode(nodeid));
    122125                dmsg.setFollowType(Discovery::successor);
    123126                dmsg.setTTL((uint8_t)3);
     
    130133                Discovery dmsg;
    131134                dmsg.setSourceEndpoint(&baseoverlay.getEndpointDescriptor());
     135                dmsg.setSourceRelay(baseoverlay.getRelayNode(nodeid));
    132136                dmsg.setFollowType(Discovery::predecessor);
    133137                dmsg.setTTL((uint8_t)3);
     
    332336                // check if source node can be added to routing table and setup link
    333337                if (m->getSource() != nodeid && table->is_insertable(m->getSource()))
    334                         setup(*dmsg->getSourceEndpoint(), m->getSource() );
     338                        setup(*dmsg->getSourceEndpoint(), m->getSource(), dmsg->getSourceRelay() );
    335339
    336340                // delegate discovery message
  • source/ariba/overlay/modules/chord/Chord.h

    r5668 r5743  
    8181
    8282        // 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 );
    8486
    8587        // helper: sends a message using the "base overlay"
  • source/ariba/overlay/modules/chord/messages/Discovery.h

    r5681 r5743  
    7070                this->follow_type = msg.follow_type;
    7171                this->ttl = msg.ttl;
     72                this->source_relay = msg.source_relay;
    7273                this->source_endpoint = msg.source_endpoint;
    7374        }
     
    99100        }
    100101
     102        inline void setSourceRelay( const NodeID& relay ) {
     103                source_relay = relay;
     104        }
     105
     106        inline const NodeID& getSourceRelay() const {
     107                return source_relay;
     108        }
    101109private:
    102110        uint8_t follow_type;
    103111        uint8_t ttl;
    104112        EndpointDescriptor source_endpoint;
     113        NodeID source_relay;
    105114};
    106115
     
    112121
    113122        // serialize end-point
    114         X && source_endpoint;
     123        X && source_relay && source_endpoint;
    115124} sznEnd();
    116125
  • source/ariba/overlay/modules/onehop/OneHop.cpp

    r5624 r5743  
    154154        } else {
    155155                bootstrapLinks.push_back(
    156                                 baseoverlay.establishLink( bootstrapEp,
     156                                baseoverlay.establishDirectLink( bootstrapEp,
    157157                                        OverlayInterface::OVERLAY_SERVICE_ID )
    158158                                        );
     
    314314
    315315                        logging_debug( "building up link to node in overlay " << node.toString() );
    316                         const LinkID link = baseoverlay.establishLink( *((*i).second),
     316                        const LinkID link = baseoverlay.establishDirectLink( *((*i).second),
    317317                                                        OverlayInterface::OVERLAY_SERVICE_ID );
    318318
Note: See TracChangeset for help on using the changeset viewer.