Ignore:
Timestamp:
May 26, 2009, 1:40:23 AM (15 years ago)
Author:
mies
Message:

Merged 20090512-mies-connectors changes r3472:r3689 into trunk.

Location:
source/ariba/overlay/modules
Files:
10 added
16 edited

Legend:

Unmodified
Added
Removed
  • source/ariba/overlay/modules/OverlayFactory.cpp

    r3689 r3690  
    1 // [Licence]
     1// [License]
    22// The Ariba-Underlay Copyright
    33//
     
    3535// official policies, either expressed or implied, of the Institute of
    3636// Telematics.
    37 // [Licence]
     37// [License]
    3838
    3939#include "OverlayFactory.h"
     40
     41// structured overlays
     42#include "chord/Chord.h"
     43#include "onehop/OneHop.h"
    4044
    4145namespace ariba {
     
    5357
    5458                case OverlayParameterSet::OverlayStructureChord:
    55                         return NULL;
     59                        return new Chord( baseoverlay, nodeid, routeReceiver );
    5660
    5761                case OverlayParameterSet::OverlayStructureKademlia:
  • source/ariba/overlay/modules/OverlayFactory.h

    r3689 r3690  
    1 // [Licence]
     1// [License]
    22// The Ariba-Underlay Copyright
    33//
     
    3535// official policies, either expressed or implied, of the Institute of
    3636// Telematics.
    37 // [Licence]
     37// [License]
    3838
    3939#ifndef __OVERLAY_FACTORY_H
     
    4141
    4242#include "ariba/utility/types/OverlayParameterSet.h"
    43 #include "ariba/overlay/modules/OverlayInterface.h"
    44 #include "ariba/overlay/modules/onehop/OneHop.h"
     43
     44#include "OverlayInterface.h"
    4545
    4646using ariba::utility::OverlayParameterSet;
    47 using ariba::overlay::OverlayInterface;
    48 using ariba::overlay::OneHop;
    4947
    5048namespace ariba {
  • source/ariba/overlay/modules/OverlayInterface.cpp

    r3057 r3690  
    1 // [Licence]
     1// [License]
    22// The Ariba-Underlay Copyright
    33//
     
    3535// official policies, either expressed or implied, of the Institute of
    3636// Telematics.
    37 // [Licence]
     37// [License]
    3838
    3939#include "OverlayInterface.h"
    4040#include "ariba/overlay/BaseOverlay.h"
    4141
     42// namespace ariba::overlay
    4243namespace ariba {
    4344namespace overlay {
    4445
    45 ServiceID OverlayInterface::OVERLAY_SERVICE_ID (0);
     46ServiceID OverlayInterface::OVERLAY_SERVICE_ID(0);
    4647
    47 OverlayInterface::OverlayInterface(
    48         BaseOverlay& _baseoverlay,
    49         const NodeID& _nodeid,
    50         OverlayStructureEvents* _eventsReceiver )
    51         :       baseoverlay( _baseoverlay ),
    52                 nodeid( _nodeid ),
    53                 eventsReceiver( _eventsReceiver ) {
     48OverlayInterface::OverlayInterface(BaseOverlay& _baseoverlay,
     49                const NodeID& _nodeid, OverlayStructureEvents* _eventsReceiver) :
     50        baseoverlay(_baseoverlay), nodeid(_nodeid), eventsReceiver(_eventsReceiver) {
    5451
    55         _baseoverlay.bind( this, OVERLAY_SERVICE_ID );
     52        _baseoverlay.bind(this, OVERLAY_SERVICE_ID);
    5653}
    5754
    58 OverlayInterface::~OverlayInterface(){
    59         baseoverlay.unbind( this, OVERLAY_SERVICE_ID );
     55OverlayInterface::~OverlayInterface() {
     56        baseoverlay.unbind(this, OVERLAY_SERVICE_ID);
    6057}
    6158
    62 void OverlayInterface::onLinkUp(const LinkID& lnk, const NodeID& remote){
     59void OverlayInterface::onLinkUp(const LinkID& lnk, const NodeID& remote) {
    6360}
    6461
    65 void OverlayInterface::onLinkDown(const LinkID& lnk, const NodeID& remote){
     62void OverlayInterface::onLinkDown(const LinkID& lnk, const NodeID& remote) {
    6663}
    6764
    68 void OverlayInterface::onLinkChanged(const LinkID& lnk, const NodeID& remote){
     65void OverlayInterface::onLinkChanged(const LinkID& lnk, const NodeID& remote) {
    6966}
    7067
    71 void OverlayInterface::onLinkFail(const LinkID& lnk, const NodeID& remote){
     68void OverlayInterface::onLinkFail(const LinkID& lnk, const NodeID& remote) {
    7269}
    7370
    74 void OverlayInterface::onLinkQoSChanged(const LinkID& lnk, const NodeID& remote, const LinkProperties& prop){
     71void OverlayInterface::onLinkQoSChanged(const LinkID& lnk,
     72                const NodeID& remote, const LinkProperties& prop) {
    7573}
    7674
    77 bool OverlayInterface::onLinkRequest(const NodeID& remote, const DataMessage& msg){
     75bool OverlayInterface::onLinkRequest(const NodeID& remote,
     76                const DataMessage& msg) {
    7877}
    7978
    80 void OverlayInterface::onMessage(const DataMessage& msg, const NodeID& remote, const LinkID& lnk){
     79void OverlayInterface::onMessage(const DataMessage& msg, const NodeID& remote,
     80                const LinkID& lnk) {
    8181}
    8282
  • source/ariba/overlay/modules/OverlayInterface.h

    r3067 r3690  
    1 // [Licence]
     1// [License]
    22// The Ariba-Underlay Copyright
    33//
     
    3535// official policies, either expressed or implied, of the Institute of
    3636// Telematics.
    37 // [Licence]
     37// [License]
    3838
    3939#ifndef __OVERLAY_INTERFACE_H
     
    5757class BaseOverlay;
    5858
    59 class OverlayInterface : public CommunicationListener {
     59/**
     60 * This class declares an interface for an structured overlay.
     61 */
     62class OverlayInterface: public CommunicationListener {
    6063        friend class BaseOverlay;
     64
    6165public:
     66        /**
     67         * A node list
     68         */
     69        typedef vector<NodeID> NodeList;
     70
     71        /**
     72         * Constructs a new overlay.
     73         */
    6274        OverlayInterface(
    63                 BaseOverlay& _baseoverlay,
    64                 const NodeID& _nodeid,
    65                 OverlayStructureEvents* _eventsReceiver
    66         );
     75                        BaseOverlay& _baseoverlay,
     76                        const NodeID& _nodeid,
     77                        OverlayStructureEvents* _eventsReceiver );
    6778
     79        /**
     80         * Destrcuts the overlay.
     81         */
    6882        virtual ~OverlayInterface();
    6983
    70         typedef vector<NodeID> NodeList;
     84        /**
     85         * Creates the overlay.
     86         */
     87        virtual void createOverlay() = 0;
    7188
    72         virtual void createOverlay() = 0;
     89        /**
     90         * Destroys the overlay.
     91         */
    7392        virtual void deleteOverlay() = 0;
    7493
    75         virtual void joinOverlay( const EndpointDescriptor& bootstrapEp = EndpointDescriptor::UNSPECIFIED) = 0;
     94        /**
     95         * Joins the overlay. Starts integration and stabilization of the overlay
     96         * Node.
     97         *
     98         * @param bootstrap The bootstrap end-point descriptor or the default
     99         *    end-point, if this node is the initiator
     100         */
     101        virtual void joinOverlay(const EndpointDescriptor& bootstrap =
     102                EndpointDescriptor::UNSPECIFIED ) = 0;
     103
     104        /**
     105         * Leaves the overlay gracefully.
     106         */
    76107        virtual void leaveOverlay() = 0;
    77108
    78         virtual const EndpointDescriptor& resolveNode( const NodeID& node ) = 0;
    79         virtual void routeMessage( const NodeID& destnode, Message* msg ) = 0;
     109        /**
     110         * Resolves a overlay neighbor.
     111         *
     112         * @param node The node to resolve
     113         * @return Endpoint descriptor of local neighbor or UNSPECIFIED
     114         */
     115        virtual const EndpointDescriptor& resolveNode(const NodeID& node) = 0;
    80116
     117        /**
     118         * Routes a message to a given node by using overlay routing.
     119         *
     120         * @param destnode The destination node.
     121         * @param msg The message to be routed.
     122         */
     123        virtual void routeMessage(const NodeID& destnode, Message* msg) = 0;
     124
     125        /**
     126         * Returns the nodes known to this overlay.
     127         *
     128         * Usually this are the direct neighbors in the overlay structure.
     129         * For instance, Chord would return his predecessor, successor and finger
     130         * nodes. On the other hand OneHop would likely return all participating
     131         * nodes in the overlay.
     132         *
     133         * @return The list of all known nodes
     134         */
    81135        virtual NodeList getKnownNodes() const = 0;
    82136
    83         // functions from CommunicationListener that we _can_ use as overlay
     137        //--- functions from CommunicationListener that we _can_ use as overlay ---
     138
     139        /// @see CommunicationListener
    84140        virtual void onLinkUp(const LinkID& lnk, const NodeID& remote);
     141        /// @see CommunicationListener
    85142        virtual void onLinkDown(const LinkID& lnk, const NodeID& remote);
     143        /// @see CommunicationListener
    86144        virtual void onLinkChanged(const LinkID& lnk, const NodeID& remote);
     145        /// @see CommunicationListener
    87146        virtual void onLinkFail(const LinkID& lnk, const NodeID& remote);
    88         virtual void onLinkQoSChanged(const LinkID& lnk, const NodeID& remote, const LinkProperties& prop);
     147        /// @see CommunicationListener
     148        virtual void onLinkQoSChanged(const LinkID& lnk, const NodeID& remote,
     149                        const LinkProperties& prop);
     150        /// @see CommunicationListener
    89151        virtual bool onLinkRequest(const NodeID& remote, const DataMessage& msg);
    90         virtual void onMessage(const DataMessage& msg, const NodeID& remote, const LinkID& lnk = LinkID::UNSPECIFIED);
     152        /// @see CommunicationListener
     153        virtual void onMessage(const DataMessage& msg, const NodeID& remote,
     154                        const LinkID& lnk = LinkID::UNSPECIFIED);
    91155
    92156protected:
     157
     158        /// Reference to an active base overlay
    93159        BaseOverlay& baseoverlay;
     160
     161        /// The node identifier to use with this overlay
    94162        const NodeID& nodeid;
     163
     164        /// The listener used to inform about overlay structure changes
    95165        OverlayStructureEvents* eventsReceiver;
     166
     167        /// The service identifer of this overlay
    96168        static ServiceID OVERLAY_SERVICE_ID;
    97169};
  • source/ariba/overlay/modules/OverlayStructureEvents.cpp

    r3689 r3690  
    1 // [Licence]
     1// [License]
    22// The Ariba-Underlay Copyright
    33//
     
    3535// official policies, either expressed or implied, of the Institute of
    3636// Telematics.
    37 // [Licence]
     37// [License]
    3838#include "OverlayStructureEvents.h"
    3939
  • source/ariba/overlay/modules/OverlayStructureEvents.h

    r3689 r3690  
    1 // [Licence]
     1// [License]
    22// The Ariba-Underlay Copyright
    33//
     
    3535// official policies, either expressed or implied, of the Institute of
    3636// Telematics.
    37 // [Licence]
     37// [License]
    3838
    3939#ifndef __OVERLAY_STRUCTURE_EVENTS_H
     
    5555        friend class ariba::overlay::OverlayInterface;
    5656        friend class ariba::overlay::OneHop;
     57
    5758public:
    5859        OverlayStructureEvents();
  • source/ariba/overlay/modules/chord/Chord.cpp

    r3689 r3690  
    1 // [Licence]
     1// [License]
    22// The Ariba-Underlay Copyright
    33//
     
    3535// official policies, either expressed or implied, of the Institute of
    3636// Telematics.
    37 // [Licence]
     37// [License]
     38
     39#include "ariba/overlay/BaseOverlay.h"
    3840
    3941#include "Chord.h"
     42#include "messages/ChordMessage.h"
     43#include "messages/Discovery.h"
     44
     45#include "detail/chord_routing_table.hpp"
    4046
    4147namespace ariba {
    4248namespace overlay {
    4349
    44 use_logging_cpp( OneHop );
     50typedef chord_routing_table::item route_item;
     51use_logging_cpp( Chord )
     52;
    4553
    4654Chord::Chord(BaseOverlay& _baseoverlay, const NodeID& _nodeid,
    4755                OverlayStructureEvents* _eventsReceiver) :
    48         OverlayInterface( _baseoverlay, _nodeid, _eventsReceiver ) {
     56        OverlayInterface(_baseoverlay, _nodeid, _eventsReceiver) {
     57
     58        // create routing table
     59        this->table = new chord_routing_table(_nodeid, 2);
     60        orphan_removal_counter = 0;
     61        stabilize_counter = 0;
     62        stabilize_finger = 0;
     63        bootstrapLink = LinkID::UNSPECIFIED;
    4964}
    5065
    5166Chord::~Chord() {
     67
     68        // delete routing table
     69        delete table;
     70}
     71
     72// helper: sets up a link using the base overlay
     73LinkID Chord::setup(const EndpointDescriptor& endp) {
     74
     75        logging_debug("request to setup link to " << endp.toString() );
     76        // establish link via base overlay
     77        return baseoverlay.establishLink(endp, OverlayInterface::OVERLAY_SERVICE_ID);
     78}
     79
     80// helper: sends a message using the "base overlay"
     81seqnum_t Chord::send(Message* msg, const LinkID& link) {
     82        return baseoverlay.sendMessage(msg, link);
     83}
     84
     85void Chord::send_discovery_to(const NodeID& destination, int ttl) {
     86        logging_debug("Initiating discovery of " << destination.toString() );
     87        Message msg;
     88        ChordMessage cmsg(ChordMessage::discovery, nodeid, destination);
     89        Discovery dmsg;
     90        dmsg.setSourceEndpoint(&baseoverlay.getEndpointDescriptor());
     91        dmsg.setFollowType(Discovery::normal);
     92        dmsg.setTTL((uint8_t) ttl);
     93        cmsg.encapsulate(&dmsg);
     94        msg.encapsulate(&cmsg);
     95        logging_debug("" << (int)cmsg.getType());
     96        this->onMessage(&msg, NodeID::UNSPECIFIED, LinkID::UNSPECIFIED);
    5297}
    5398
    5499void Chord::createOverlay() {
    55 
    56100}
    57101
     
    60104}
    61105
    62 void Chord::joinOverlay(
    63         const EndpointDescriptor& bootstrapEp = EndpointDescriptor::UNSPECIFIED
    64 ) {
    65 
     106void Chord::joinOverlay(const EndpointDescriptor& boot) {
     107        logging_info( "joining Chord overlay structure through end-point " <<
     108                        (boot == EndpointDescriptor::UNSPECIFIED ?
     109                                        "local" : boot.toString()) );
     110
     111        // initiator? no->setup first link
     112        if (!(boot == EndpointDescriptor::UNSPECIFIED)) bootstrapLink = setup(boot);
     113
     114        // timer for stabilization management
     115        Timer::setInterval(2500);
     116        Timer::start();
    66117}
    67118
    68119void Chord::leaveOverlay() {
    69 
    70 }
    71 
    72 const EndpointDescriptor& Chord::resolveNode( const NodeID& node ) {
    73 
    74 }
    75 
    76 void Chord::routeMessage( const NodeID& destnode, Message* msg ) {
    77 
    78 }
    79 
    80 NodeList Chord::getKnownNodes() const {
    81 
    82 }
    83 
    84 
    85 }} // namespace ariba, overlay
     120        Timer::stop();
     121        for (size_t i = 0; i < table->size(); i++) {
     122                route_item* it = (*table)[i];
     123                ChordMessage msg(ChordMessage::leave, nodeid, it->id);
     124                send(&msg,it->info);
     125        }
     126}
     127
     128const EndpointDescriptor& Chord::resolveNode(const NodeID& node) {
     129        const route_item* item = table->get(node);
     130        if (item == NULL || item->info.isUnspecified()) return EndpointDescriptor::UNSPECIFIED;
     131        return baseoverlay.getEndpointDescriptor(item->info);
     132}
     133
     134void Chord::routeMessage(const NodeID& destnode, Message* msg) {
     135        // get next hop
     136        const route_item* item = table->get_next_hop(destnode);
     137
     138        // message for this node? yes-> delegate to base overlay
     139        if (item->id == nodeid) baseoverlay.incomingRouteMessage(msg);
     140        else { // no-> send to next hop
     141                ChordMessage cmsg(ChordMessage::route, nodeid, destnode);
     142                cmsg.encapsulate(msg);
     143                send(&cmsg, item->info);
     144        }
     145}
     146
     147OverlayInterface::NodeList Chord::getKnownNodes() const {
     148        OverlayInterface::NodeList nodelist;
     149        for (size_t i = 0; i < table->size(); i++)
     150                if ((*table)[i]->ref_count != 0) nodelist.push_back((*table)[i]->id);
     151        return nodelist;
     152}
     153
     154/// @see CommunicationListener.h
     155/// @see OverlayInterface.h
     156void Chord::onLinkUp(const LinkID& lnk, const NodeID& remote) {
     157        logging_debug("link_up: link=" << lnk.toString() << " remote=" <<
     158                        remote.toString() );
     159        route_item* item = table->insert(remote);
     160
     161        if (!bootstrapLink.isUnspecified() && lnk == bootstrapLink) {
     162                send_discovery_to(nodeid);
     163                bootstrapLink = LinkID::UNSPECIFIED;
     164        }
     165
     166        // item added to routing table?
     167        if (item != NULL) { // yes-> add to routing table
     168                logging_debug("new routing neighbor: " << remote.toString() );
     169                item->info = lnk;
     170        } else { // no-> add orphan entry to routing table
     171                logging_debug("new orphan: " << remote.toString() );
     172                table->insert_orphan(remote)->info = lnk;
     173        }
     174}
     175
     176/// @see CommunicationListener.h or @see OverlayInterface.h
     177void Chord::onLinkDown(const LinkID& lnk, const NodeID& remote) {
     178        logging_debug("link_down: link=" << lnk.toString() << " remote=" <<
     179                        remote.toString() );
     180
     181        // remove link from routing table
     182        table->remove(remote);
     183}
     184
     185/// @see CommunicationListener.h
     186/// @see OverlayInterface.h
     187void Chord::onMessage(const DataMessage& msg, const NodeID& remote,
     188                const LinkID& link) {
     189
     190        // decode message
     191        typedef ChordMessage M;
     192        M* m = msg.getMessage()->convert<ChordMessage> ();
     193        if (m == NULL) return;
     194
     195        logging_debug("onMessage: type=" << (int)m->getType() );
     196
     197        // handle messages
     198        switch (m->getType()) {
     199
     200        // invalid message
     201        case M::invalid:
     202                break;
     203
     204                // route message with payload
     205        case M::route: {
     206                // find next hop
     207                const route_item* item = table->get_next_hop(m->getDestination());
     208
     209                // next hop == myself?
     210                if (m->getDestination() == nodeid) { // yes-> route to base overlay
     211                        logging_debug("send message to baseoverlay");
     212                        baseoverlay.incomingRouteMessage(m);
     213                }
     214                // no-> route to next hop
     215                else {
     216                        logging_debug("route chord message to " << item->id.toString() );
     217                        send(m, item->info);
     218                }
     219                break;
     220        }
     221
     222                // discovery request
     223        case M::discovery: {
     224                // decapsulate message
     225                Discovery* dmsg = m->decapsulate<Discovery> ();
     226                logging_debug("received discovery message with"
     227                                << " dest=" << m->getDestination().toString()
     228                                << " ttl=" << (int)dmsg->getTTL()
     229                                << " type=" << (int)dmsg->getFollowType()
     230                );
     231
     232                // check if source node can be added to routing table and setup link
     233                if (m->getSource() != nodeid && table->is_insertable(m->getSource())) setup(
     234                                *dmsg->getSourceEndpoint());
     235
     236                // delegate discovery message
     237                switch (dmsg->getFollowType()) {
     238
     239                // normal: route discovery message like every other message
     240                case Discovery::normal:
     241                        // closest node? yes-> split to follow successor and predecessor
     242                        if (table->is_closest_to(m->getDestination())) {
     243
     244                                if (table->get_successor() != NULL) {
     245                                        // send successor message
     246                                        ChordMessage cmsg_s(*m);
     247                                        Discovery dmsg_s(*dmsg);
     248                                        dmsg_s.setFollowType(Discovery::successor);
     249                                        cmsg_s.encapsulate(&dmsg_s);
     250                                        route_item* succ_item = table->get(*table->get_successor());
     251                                        logging_debug("split: routing discovery message to successor "
     252                                                        << succ_item->id.toString() );
     253                                        send(&cmsg_s, succ_item->info);
     254                                }
     255
     256                                // send predecessor message
     257                                if (table->get_predesessor() != NULL) {
     258                                        ChordMessage cmsg_p(*m);
     259                                        Discovery dmsg_p(*dmsg);
     260                                        dmsg_p.setFollowType(Discovery::predecessor);
     261                                        cmsg_p.encapsulate(&dmsg_p);
     262                                        route_item* pred_item = table->get(
     263                                                        *table->get_predesessor());
     264                                        logging_debug("split: routing discovery message to predecessor "
     265                                                        << pred_item->id.toString() );
     266                                        send(&cmsg_p, pred_item->info);
     267                                }
     268                        }
     269                        // no-> route message
     270                        else {
     271                                // find next hop
     272                                const route_item* item = table->get_next_hop(
     273                                                m->getDestination());
     274                                if (item->id == nodeid) break;
     275                                logging_debug("routing discovery message to " <<
     276                                                item->id.toString() );
     277                                send(m, item->info);
     278                        }
     279                        break;
     280
     281                        // successor mode: follow the successor until TTL is zero
     282                case Discovery::successor:
     283                case Discovery::predecessor: {
     284                        // time to live ended? yes-> stop routing
     285                        if (dmsg->getTTL() == 0) break;
     286
     287                        // decrease time-to-live
     288                        dmsg->setTTL(dmsg->getTTL() - 1);
     289
     290                        const route_item* item;
     291                        if (dmsg->getFollowType() == Discovery::successor) item
     292                                        = table->get(*table->get_successor());
     293                        else item = table->get(*table->get_predesessor());
     294                        logging_debug("routing discovery message to succ/pred "
     295                                        << item->id.toString() );
     296                        ChordMessage cmsg(*m);
     297                        cmsg.encapsulate(dmsg);
     298                        send(&cmsg, item->info);
     299                        break;
     300                }
     301                }
     302                break;
     303        }
     304
     305                // leave
     306        case M::leave: {
     307                baseoverlay.dropLink(link);
     308                break;
     309        }
     310        }
     311}
     312
     313void Chord::eventFunction() {
     314        stabilize_counter++;
     315        if (stabilize_counter == 3) {
     316                stabilize_counter = 0;
     317                stabilize_finger = ((stabilize_finger+1) % table->get_finger_table_size() );
     318                logging_debug("sending discovery message to my neighbors");
     319                send_discovery_to(nodeid);
     320                send_discovery_to(
     321                        table->get_finger_table(stabilize_finger).get_compare().get_center()
     322                );
     323                orphan_removal_counter++;
     324                if (orphan_removal_counter == 2) {
     325                        orphan_removal_counter = 0;
     326                        for (size_t i = 0; i < table->size(); i++) {
     327                                route_item* it = (*table)[i];
     328                                if (it->ref_count == 0) {
     329                                        baseoverlay.dropLink(it->info);
     330                                        logging_debug("dropping orphaned link " << it->info.toString() << " to " << it->id.toString());
     331                                }
     332                        }
     333                }
     334        }
     335        logging_debug("--- chord routing information ----------------------------------");
     336        logging_debug("predecessor: " << (table->get_predesessor()==NULL? "<none>" : table->get_predesessor()->toString()) );
     337        logging_debug("node_id    : " << nodeid.toString() );
     338        logging_debug("successor  : " << (table->get_successor()==NULL? "<none>" : table->get_successor()->toString()));
     339        logging_debug("----------------------------------------------------------------");
     340}
     341
     342}
     343} // namespace ariba, overlay
  • source/ariba/overlay/modules/chord/Chord.h

    r3689 r3690  
    1 // [Licence]
     1// [License]
    22// The Ariba-Underlay Copyright
    33//
     
    3535// official policies, either expressed or implied, of the Institute of
    3636// Telematics.
    37 // [Licence]
     37// [License]
    3838
    3939#ifndef CHORD_H_
    4040#define CHORD_H_
    4141
     42#include "ariba/utility/system/Timer.h"
    4243#include "ariba/utility/logging/Logging.h"
    4344#include "ariba/communication/EndpointDescriptor.h"
     45#include "../OverlayInterface.h"
     46#include <vector>
     47
     48class chord_routing_table;
    4449
    4550namespace ariba {
    4651namespace overlay {
    4752
    48 using ariba::overlay::OverlayInterface;
    4953using ariba::communication::EndpointDescriptor;
     54using ariba::utility::Timer;
    5055
    51 class Chord : public OverlayInterface {
     56using namespace std;
     57
     58/**
     59 * This class implements a structured overlay inspired by chord.
     60 * It differs to the original form of chord in the following manner:
     61 *
     62 * (1) The graph is bidirectional
     63 * (2) Stabilization is done in a reactive manner
     64 *
     65 * It therefore can be considered as a kind of Chorded-Kademlia :)
     66 *
     67 * The resulting overlay graph has a diameter of O(log N).
     68 *
     69 * @author Sebastian Mies <mies@tm.uka.de>
     70 */
     71class Chord : public OverlayInterface, protected Timer {
    5272        use_logging_h( Chord );
    5373private:
     74        chord_routing_table* table;
     75        int orphan_removal_counter;
     76        int stabilize_counter;
     77        int stabilize_finger;
     78        LinkID bootstrapLink;
     79
     80        // helper: sets up a link using the "base overlay"
     81        LinkID setup( const EndpointDescriptor& endp );
     82
     83        // helper: sends a message using the "base overlay"
     84        seqnum_t send( Message* msg, const LinkID& link );
     85
     86        // stabilization: sends a discovery message to the specified neighborhood
     87        void send_discovery_to( const NodeID& destination, int ttl = 4 );
    5488
    5589public:
    5690        Chord(BaseOverlay& _baseoverlay, const NodeID& _nodeid,
    5791                        OverlayStructureEvents* _eventsReceiver);
    58         ~Chord();
     92        virtual ~Chord();
    5993
    60         void createOverlay();
     94        /// @see OverlayInterface.h
     95        virtual void createOverlay();
    6196
    62         void deleteOverlay();
     97        /// @see OverlayInterface.h
     98        virtual void deleteOverlay();
    6399
    64         void joinOverlay(
    65                 const EndpointDescriptor& bootstrapEp = EndpointDescriptor::UNSPECIFIED
     100        /// @see OverlayInterface.h
     101        virtual void joinOverlay(
     102                const EndpointDescriptor& boot = EndpointDescriptor::UNSPECIFIED
    66103        );
    67104
    68         void leaveOverlay();
     105        /// @see OverlayInterface.h
     106        virtual void leaveOverlay();
    69107
    70         const EndpointDescriptor& resolveNode( const NodeID& node );
     108        /// @see OverlayInterface.h
     109        virtual const EndpointDescriptor& resolveNode( const NodeID& node );
    71110
    72         void routeMessage( const NodeID& destnode, Message* msg );
     111        /// @see OverlayInterface.h
     112        virtual void routeMessage( const NodeID& destnode, Message* msg );
    73113
    74         NodeList getKnownNodes() const;
     114        /// @see OverlayInterface.h
     115        virtual NodeList getKnownNodes() const;
     116
     117        /// @see CommunicationListener.h or @see OverlayInterface.h
     118        virtual void onLinkUp(const LinkID& lnk, const NodeID& remote);
     119
     120        /// @see CommunicationListener.h or @see OverlayInterface.h
     121        virtual void onLinkDown(const LinkID& lnk, const NodeID& remote);
     122
     123        /// @see CommunicationListener.h or @see OverlayInterface.h
     124        virtual void onMessage(const DataMessage& msg, const NodeID& remote,
     125                        const LinkID& lnk = LinkID::UNSPECIFIED);
     126
     127        /// @see Timer.h
     128        virtual void eventFunction();
    75129};
    76130
  • source/ariba/overlay/modules/onehop/OneHop.cpp

    r3067 r3690  
    1 // [Licence]
     1// [License]
    22// The Ariba-Underlay Copyright
    33//
     
    3535// official policies, either expressed or implied, of the Institute of
    3636// Telematics.
    37 // [Licence]
     37// [License]
    3838
    3939#include "OneHop.h"
    4040#include "ariba/overlay/BaseOverlay.h"
     41
     42#include "ariba/overlay/modules/onehop/messages/OneHopMessage.h"
     43#include "ariba/overlay/modules/onehop/messages/NodeListingRequest.h"
     44#include "ariba/overlay/modules/onehop/messages/NodeListingReply.h"
    4145
    4246namespace ariba {
     
    8488                return;
    8589        }
    86 
    87         baseoverlay.sendMessage( msg, i->second );
    88 }
    89 
    90 void OneHop::createOverlay(){
    91 
     90        OneHopMessage onehopRoute( OneHopMessage::OneHopMessageTypeRoute );
     91        onehopRoute.encapsulate(msg);
     92
     93        baseoverlay.sendMessage( &onehopRoute, i->second );
     94}
     95
     96void OneHop::createOverlay() {
    9297        // don't need to bootstrap against ourselfs.
    9398        // the create and join process is completed now.
    94 
    9599        logging_info( "creating onehop overlay structure" );
    96100        state = OneHopStateCompleted;
     
    119123void OneHop::joinOverlay(const EndpointDescriptor& bootstrapEp){
    120124
    121         logging_info( "joining onehop overlay structure through endpoint " <<
     125        logging_info( "joining onehop overlay structure through end-point " <<
    122126                        (bootstrapEp == EndpointDescriptor::UNSPECIFIED ?
    123127                                        "local" : bootstrapEp.toString()) );
     
    133137
    134138                state = OneHopStateCompleted;
    135 
    136 
    137139        } else {
    138 
    139140                bootstrapLink = baseoverlay.establishLink( bootstrapEp,
    140141                                        OverlayInterface::OVERLAY_SERVICE_ID );
     
    175176        if( state == OneHopStateInvalid ) return;
    176177
    177         //
    178178        // node went down, remove from overlay mapping
    179         //
    180 
    181179        logging_debug( "node " << remote.toString() << " left overlay structure" );
    182180
     
    223221        //
    224222
    225         if( onemsg->isType( OneHopMessage::OneHopMessageTypeListingRequest) ){
     223        if( onemsg->isType( OneHopMessage::OneHopMessageTypeListingRequest ) ){
    226224
    227225                NodeListingRequest* request = onemsg->decapsulate<NodeListingRequest>();
     
    316314        } // if( reply != NULL )
    317315
     316        if( onemsg->isType( OneHopMessage::OneHopMessageTypeRoute) ){
     317                logging_debug( "Route message arrived at destination node -> delegate to BaseOverlay" );
     318                baseoverlay.incomingRouteMessage( onemsg );
     319        }
     320
     321
    318322}
    319323
  • source/ariba/overlay/modules/onehop/OneHop.h

    r3057 r3690  
    1 // [Licence]
     1// [License]
    22// The Ariba-Underlay Copyright
    33//
     
    3535// official policies, either expressed or implied, of the Institute of
    3636// Telematics.
    37 // [Licence]
     37// [License]
    3838
    3939#ifndef _ONE_HOP_H
     
    4242#include <map>
    4343#include "ariba/overlay/modules/OverlayInterface.h"
    44 #include "ariba/overlay/modules/onehop/messages/OneHopMessage.h"
    45 #include "ariba/overlay/modules/onehop/messages/NodeListingRequest.h"
    46 #include "ariba/overlay/modules/onehop/messages/NodeListingReply.h"
    4744#include "ariba/utility/logging/Logging.h"
    4845
    4946using std::map;
    50 using ariba::overlay::OverlayInterface;
    51 using ariba::overlay::OneHopMessage;
    52 using ariba::overlay::NodeListingRequest;
    53 using ariba::overlay::NodeListingReply;
    5447
    5548namespace ariba {
    5649namespace overlay {
    5750
    58 class OneHop : public OverlayInterface {
     51class OneHop: public OverlayInterface {
    5952        use_logging_h( OneHop );
    6053public:
    61         OneHop(
    62                 BaseOverlay& _overlay,
    63                 const NodeID& _nodeid,
    64                 OverlayStructureEvents* _eventsReceiver
    65         );
     54        OneHop(BaseOverlay& _overlay, const NodeID& _nodeid,
     55                        OverlayStructureEvents* _eventsReceiver);
    6656
    6757        virtual ~OneHop();
    6858
    6959protected:
     60        /// @see OverlayInterface.h
     61        virtual void createOverlay();
    7062
    71         //
    72         // OverlayInterface.h
    73         //
    74 
    75         virtual void createOverlay();
     63        /// @see OverlayInterface.h
    7664        virtual void deleteOverlay();
    7765
    78         virtual void joinOverlay(const EndpointDescriptor& bootstrapEp = EndpointDescriptor::UNSPECIFIED);
     66        /// @see OverlayInterface.h
     67        virtual void joinOverlay(const EndpointDescriptor& boot =
     68                        EndpointDescriptor::UNSPECIFIED);
     69
     70        /// @see OverlayInterface.h
    7971        virtual void leaveOverlay();
    8072
    81         virtual const EndpointDescriptor& resolveNode( const NodeID& node );
    82         virtual void routeMessage( const NodeID& destnode, Message* msg );
     73        /// @see OverlayInterface.h
     74        virtual const EndpointDescriptor& resolveNode(const NodeID& node);
    8375
     76        /// @see OverlayInterface.h
     77        virtual void routeMessage(const NodeID& destnode, Message* msg);
     78
     79        /// @see OverlayInterface.h
    8480        virtual NodeList getKnownNodes() const;
    8581
    86         //
    87         // see CommunicationListener.h or OverlayInterface.h
    88         //
     82        /// @see CommunicationListener.h or @see OverlayInterface.h
     83        virtual void onLinkUp(const LinkID& lnk, const NodeID& remote);
    8984
    90         virtual void onLinkUp(const LinkID& lnk, const NodeID& remote);
     85        /// @see CommunicationListener.h or @see OverlayInterface.h
    9186        virtual void onLinkDown(const LinkID& lnk, const NodeID& remote);
    92         virtual void onMessage(const DataMessage& msg, const NodeID& remote, const LinkID& lnk = LinkID::UNSPECIFIED);
     87
     88        /// @see CommunicationListener.h or @see OverlayInterface.h
     89        virtual void onMessage(const DataMessage& msg, const NodeID& remote,
     90                        const LinkID& lnk = LinkID::UNSPECIFIED);
    9391
    9492private:
    95 
    96         /**
    97          * The other nodes in the overlay
    98          */
    99         typedef map<const NodeID,const LinkID> OverlayNodeMapping;
     93        /// The other nodes in the overlay
     94        typedef map<const NodeID, const LinkID> OverlayNodeMapping;
    10095        OverlayNodeMapping overlayNodes;
    10196
    102         /**
    103          * The current state of the overlay
    104          */
     97        /// The current state of the overlay
    10598        typedef enum _OneHopState {
    106                 OneHopStateInvalid                = 0,
    107                 OneHopStateJoinInitiated          = 1,
    108                 OneHopStateJoinListingRequested   = 2,
    109                 OneHopStateCompleted              = 3,
     99                OneHopStateInvalid = 0,
     100                OneHopStateJoinInitiated = 1,
     101                OneHopStateJoinListingRequested = 2,
     102                OneHopStateCompleted = 3,
    110103        } OneHopState;
    111104
    112105        OneHopState state;
    113 
    114106        uint16_t pendingLinks;
    115107        LinkID bootstrapLink;
    116 
    117108};
    118109
  • source/ariba/overlay/modules/onehop/messages/NodeListingReply.cpp

    r3689 r3690  
    1 // [Licence]
     1// [License]
    22// The Ariba-Underlay Copyright
    33//
     
    3535// official policies, either expressed or implied, of the Institute of
    3636// Telematics.
    37 // [Licence]
     37// [License]
    3838
    3939#include "NodeListingReply.h"
  • source/ariba/overlay/modules/onehop/messages/NodeListingReply.h

    r3689 r3690  
    1 // [Licence]
     1// [License]
    22// The Ariba-Underlay Copyright
    33//
     
    3535// official policies, either expressed or implied, of the Institute of
    3636// Telematics.
    37 // [Licence]
     37// [License]
    3838
    3939#ifndef NODE_LISTING_REPLY_H__
     
    7777
    7878sznBeginDefault( ariba::overlay::NodeListingReply, X ) {
    79         uint16_t len = X.isSerializer() ? descriptors.size() : 0;
     79        uint16_t len = descriptors.size();
    8080        X && len;
    81         if (X.isDeserializer()) {
    82                 descriptors.resize(len);
    83         }
    84         for (int i=0; i<len; i++) {
    85                 if (X.isDeserializer()) descriptors[i].second = new EndpointDescriptor();
    86                 X && &descriptors[i].first && reinterpret_cast<VSerializeable*>(descriptors[i].second);
    87         }
     81        if (X.isDeserializer()) descriptors.resize(len);
     82        for (int i=0; i<len; i++)
     83                X && &descriptors[i].first && VO(descriptors[i].second);
    8884} sznEnd();
    8985
  • source/ariba/overlay/modules/onehop/messages/NodeListingRequest.cpp

    r3689 r3690  
    1 // [Licence]
     1// [License]
    22// The Ariba-Underlay Copyright
    33//
     
    3535// official policies, either expressed or implied, of the Institute of
    3636// Telematics.
    37 // [Licence]
     37// [License]
    3838
    3939#include "NodeListingRequest.h"
  • source/ariba/overlay/modules/onehop/messages/NodeListingRequest.h

    r3689 r3690  
    1 // [Licence]
     1// [License]
    22// The Ariba-Underlay Copyright
    33//
     
    3535// official policies, either expressed or implied, of the Institute of
    3636// Telematics.
    37 // [Licence]
     37// [License]
    3838
    3939#ifndef NODE_LISTING_REQUEST_H__
  • source/ariba/overlay/modules/onehop/messages/OneHopMessage.cpp

    r3689 r3690  
    1 // [Licence]
     1// [License]
    22// The Ariba-Underlay Copyright
    33//
     
    3535// official policies, either expressed or implied, of the Institute of
    3636// Telematics.
    37 // [Licence]
     37// [License]
    3838
    3939#include "OneHopMessage.h"
  • source/ariba/overlay/modules/onehop/messages/OneHopMessage.h

    r3689 r3690  
    1 // [Licence]
     1// [License]
    22// The Ariba-Underlay Copyright
    33//
     
    3535// official policies, either expressed or implied, of the Institute of
    3636// Telematics.
    37 // [Licence]
     37// [License]
    3838
    3939#ifndef __ONE_HOP_MESSAGE_H
     
    5757                OneHopMessageTypeListingRequest = 1,
    5858                OneHopMessageTypeListingReply   = 2,
     59                OneHopMessageTypeRoute          = 3,
    5960        } OneHopMessageType;
    6061
Note: See TracChangeset for help on using the changeset viewer.