Changeset 7532 for source/ariba


Ignore:
Timestamp:
Feb 4, 2010, 5:29:37 PM (14 years ago)
Author:
Christoph Mayer
Message:

-von außen konfigurierbare bootstrap module, -periodicbroadcast crash fix

Location:
source/ariba
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • source/ariba/AribaModule.cpp

    r7468 r7532  
    4343#include <boost/regex.hpp>
    4444#include <boost/foreach.hpp>
     45#include <boost/algorithm/string.hpp>
    4546
    4647// ariba includes
     
    5859
    5960use_logging_cpp(AribaModule);
     61const string AribaModule::BootstrapMechanismNames[5] = {"invalid", "static", "broadcast", "mdns", "sdp"};
    6062
    6163AribaModule::AribaModule()
     
    6971string AribaModule::getBootstrapHints(const Name& spoVNetName) const {
    7072        std::ostringstream o;
     73        int i=0;
    7174        BOOST_FOREACH( const BootstrapInfo& info, bootstrapNodes ) {
    7275                o << info.spovnetName.toString() << "{";
    73                 int i=0;
     76                if (i!=0) o << ",";
     77
    7478                BOOST_FOREACH( const BootstrapNode& node, info.nodes ) {
    75                         if (i!=0) o << ",";
    76                         if( node.desc != NULL ) o << node.desc->toString();
    77                         i++;
     79                        if( node.desc != NULL )
     80                                o << node.desc->toString();
     81                        else if(node.mechanism == BootstrapMechanismBroadcast
     82                                        || node.mechanism == BootstrapMechanismMulticastDNS
     83                                        || node.mechanism == BootstrapMechanismSDP){
     84                                o << BootstrapMechanismNames[node.mechanism];
     85                                if( !node.info.empty() ) o << "{" << node.info << "}";
     86                                o << ";";
     87                        }
    7888                }
    7989                o << "}";
     90                i++;
    8091        }
    8192        return o.str();
     
    8798        using namespace ariba::utility::Helper;
    8899        using namespace std;
     100
     101        boost::erase_all(boot_info, " ");
     102        boost::erase_all(boot_info, "\t");
     103        boost::erase_all(boot_info, "\n");
     104        boost::erase_all(boot_info, "\r");
    89105
    90106        smatch match;
     
    96112                        data = data.substr(1, data.size() - 2);
    97113                        Name name(type);
     114
     115                        // find static bootstrap info --> BootstrapMechanismStatic
    98116                        EndpointDescriptor* desc = EndpointDescriptor::fromString(data);
    99                         logging_debug("Added bootstap info for " << type << ": " << desc->toString() );
    100                         addBootstrapNode(name, desc);
    101                 }
    102         }
     117                        addBootstrapNode(name, desc, "", BootstrapMechanismStatic);
     118
     119                        // find automatic bootstrap info --> {BootstrapMechanismBroadcast,
     120                        //                                      BootstrapMechanismMulticastDNS,BootstrapMechanismSDP}
     121                        typedef vector< string > split_vector_type;
     122                        split_vector_type splitvec;
     123                        boost::split( splitvec, data, boost::is_any_of(";") );
     124                        for(unsigned int i=0; i<splitvec.size(); i++){
     125                                string x = splitvec[i];
     126                                split_vector_type innervec;
     127
     128                                boost::split( innervec, x, boost::is_any_of("{}") );
     129                                BootstrapNode node;
     130                                if(innervec.size() < 1) continue;
     131
     132                                if(innervec[0] == BootstrapMechanismNames[BootstrapMechanismBroadcast])
     133                                        node.mechanism = BootstrapMechanismBroadcast;
     134                                else if(innervec[0] == BootstrapMechanismNames[BootstrapMechanismMulticastDNS])
     135                                        node.mechanism = BootstrapMechanismMulticastDNS;
     136                                else if(innervec[0] == BootstrapMechanismNames[BootstrapMechanismSDP])
     137                                        node.mechanism = BootstrapMechanismSDP;
     138                                else
     139                                        continue;
     140
     141                                if(innervec.size() > 1)
     142                                        node.info = innervec[1];
     143
     144                                this->addBootstrapNode(name, node);
     145                        }
     146                }
     147        }
     148
     149        logging_info( "Added bootstrap hints: " << getBootstrapHints() );
    103150}
    104151
    105152void AribaModule::addBootstrapNode(const Name& spovnet,
    106                 communication::EndpointDescriptor* desc) {
    107 
    108         // set bootstrap node
    109         BootstrapNode node;
    110         node.timestamp = 0;
    111         node.desc = desc;
     153                communication::EndpointDescriptor* desc, const string& info,
     154                const BootstrapMechanism& mechanism) {
     155        BootstrapNode node(0, desc, mechanism, info);
     156        addBootstrapNode(spovnet, node);
     157}
     158
     159void AribaModule::addBootstrapNode(const Name& spovnet, const BootstrapNode& node){
    112160        bool added = false;
    113161
     
    128176                bootstrapNodes.push_back(info);
    129177        }
    130 
    131         logging_debug( "Added bootstrap info: " << getBootstrapHints() );
    132178}
    133179
    134180const communication::EndpointDescriptor* AribaModule::getBootstrapNode(
    135                 const Name& spovnet) const {
     181                const Name& spovnet, const BootstrapMechanism mechanism) const {
    136182        BOOST_FOREACH( const BootstrapInfo& info, bootstrapNodes ) {
    137183                if( info.spovnetName == spovnet ) {
    138184                        BOOST_FOREACH( const BootstrapNode& node, info.nodes ) {
    139                                 if( node.desc != NULL ) return node.desc;
     185                                if( node.mechanism == mechanism && node.desc != NULL )
     186                                        return node.desc;
    140187                        }
    141188                }
    142189        }
    143190        return NULL;
     191}
     192
     193string AribaModule::getBootstrapInfo(
     194                const Name& spovnet, const BootstrapMechanism mechanism) const {
     195        BOOST_FOREACH( const BootstrapInfo& info, bootstrapNodes ) {
     196                if( info.spovnetName == spovnet ) {
     197                        BOOST_FOREACH( const BootstrapNode& node, info.nodes ) {
     198                                if( node.mechanism == mechanism && node.desc != NULL )
     199                                        return node.info;
     200                        }
     201                }
     202        }
     203
     204        return string();
     205}
     206
     207vector<AribaModule::BootstrapMechanism> AribaModule::getBootstrapMechanisms(
     208                const Name& spovnet) const {
     209        vector<AribaModule::BootstrapMechanism> ret;
     210        BOOST_FOREACH( const BootstrapInfo& info, bootstrapNodes ) {
     211                if( info.spovnetName == spovnet ) {
     212                        BOOST_FOREACH( const BootstrapNode& node, info.nodes ) {
     213                                if(std::find(ret.begin(), ret.end(), node.mechanism) == ret.end())
     214                                        ret.push_back(node.mechanism);
     215                        }
     216                }
     217        }
     218        return ret;
    144219}
    145220
  • source/ariba/AribaModule.h

    r5767 r7532  
    4444#include <ctime>
    4545#include <cstdlib>
    46 #include "ariba/utility/logging/Logging.h"
     46#include <algorithm>
    4747
    4848using std::vector;
     
    156156
    157157private:
     158
     159        // bootstrap mechanisms
     160        enum BootstrapMechanism {
     161                BootstrapMechanismInvalid = 0,
     162                BootstrapMechanismStatic = 1,
     163                BootstrapMechanismBroadcast = 2,
     164                BootstrapMechanismMulticastDNS = 3,
     165                BootstrapMechanismSDP = 4,
     166        };
     167        static const string BootstrapMechanismNames[5];
     168
    158169        // bootstrap node
    159170        class BootstrapNode {
    160171        public:
    161172                inline BootstrapNode() :
    162                         timestamp(0), desc(NULL) {
     173                        timestamp(0), desc(NULL), mechanism(BootstrapMechanismInvalid), info("") {
    163174
    164175                }
    165176                inline BootstrapNode(const BootstrapNode& copy) :
    166                         timestamp(copy.timestamp), desc(copy.desc) {
    167                 }
    168                 inline BootstrapNode(uint32_t timestamp,
    169                                 communication::EndpointDescriptor* desc) :
    170                         timestamp(timestamp), desc(desc) {
     177                        timestamp(copy.timestamp), desc(copy.desc), mechanism(copy.mechanism), info(copy.info) {
     178                }
     179                inline BootstrapNode(
     180                                uint32_t timestamp,
     181                                communication::EndpointDescriptor* desc,
     182                                BootstrapMechanism mechanism, string info) :
     183                        timestamp(timestamp), desc(desc), mechanism(mechanism), info(info) {
    171184                }
    172185                uint32_t timestamp;
    173186                communication::EndpointDescriptor* desc;
     187                BootstrapMechanism mechanism;
     188                string info;
    174189        };
    175190
     
    192207protected:
    193208        // members
    194         string bootstrapFile; //< file with bootstrap information
    195         string endpoints;
     209        string endpoints; //< local endpoints the ariba module is bound to
    196210        bool started; //< flag, if module has been started
    197211
    198212        // bootstrap node management
    199         void addBootstrapNode(const Name& spovnet,
    200                         communication::EndpointDescriptor* desc);
     213        void addBootstrapNode(
     214                        const Name& spovnet,
     215                        communication::EndpointDescriptor* desc,
     216                        const string& info,
     217                        const BootstrapMechanism& mechanism
     218                        );
     219        void addBootstrapNode(
     220                        const Name& spovnet,
     221                        const BootstrapNode& node
     222                        );
     223
     224        vector<AribaModule::BootstrapMechanism> getBootstrapMechanisms(
     225                        const Name& spovnet
     226                        ) const;
     227
    201228        const communication::EndpointDescriptor* getBootstrapNode(
    202                         const Name& spovnet) const;
     229                        const Name& spovnet,
     230                        const BootstrapMechanism mechanism
     231                        ) const;
     232
     233        string getBootstrapInfo(
     234                        const Name& spovnet,
     235                        const BootstrapMechanism mechanism
     236                        ) const;
    203237
    204238        communication::BaseCommunication* base_comm;
  • source/ariba/Node.cpp

    r7469 r7532  
    6161        nodeId = generateNodeId(name);
    6262
    63         const communication::EndpointDescriptor* ep =
    64                         ariba_mod.getBootstrapNode(vnetname);
    65 
    6663        // start base comm if not started
    6764        if( !ariba_mod.base_comm->isStarted() )
     
    7471        base_overlay->joinSpoVNet( spovnetId );
    7572
    76         // join against further nodes
    77         if( ep != NULL && ep->isUnspecified() == false )
    78                 base_overlay->joinSpoVNet( spovnetId, *ep);
     73        // join against static bootstrap points and
     74        // start automatic bootstrapping modules
     75        vector<AribaModule::BootstrapMechanism> mechanisms
     76                = ariba_mod.getBootstrapMechanisms(vnetname);
     77
     78        vector<pair<BootstrapManager::BootstrapType,string> > internalmodules;
     79
     80        BOOST_FOREACH(AribaModule::BootstrapMechanism m, mechanisms){
     81                switch(m){
     82                        case AribaModule::BootstrapMechanismStatic:
     83                        {
     84                                const communication::EndpointDescriptor* ep =
     85                                                        ariba_mod.getBootstrapNode(vnetname, m);
     86                                        if( ep != NULL && ep->isUnspecified() == false )
     87                                                base_overlay->joinSpoVNet( spovnetId, *ep);
     88                                break;
     89                        }
     90                        case AribaModule::BootstrapMechanismBroadcast:
     91                                internalmodules.push_back(make_pair(
     92                                                BootstrapManager::BootstrapTypePeriodicBroadcast,
     93                                                ariba_mod.getBootstrapInfo(vnetname, m)));
     94                                break;
     95                        case AribaModule::BootstrapMechanismMulticastDNS:
     96                                internalmodules.push_back(make_pair(
     97                                                BootstrapManager::BootstrapTypeMulticastDns,
     98                                                ariba_mod.getBootstrapInfo(vnetname, m)));
     99                                break;
     100                        case AribaModule::BootstrapMechanismSDP:
     101                                internalmodules.push_back(make_pair(
     102                                                BootstrapManager::BootstrapTypeBluetoothSdp,
     103                                                ariba_mod.getBootstrapInfo(vnetname, m)));
     104                                break;
     105                        default:
     106                                break;
     107                }
     108        }
     109
     110        // start automatic overlay bootstrapping modules
     111        base_overlay->startBootstrapModules(internalmodules);
     112
     113        // done
    79114}
    80115
     
    101136
    102137void Node::leave() {
     138        base_overlay->stopBootstrapModules();
    103139        base_overlay->leaveSpoVNet();
    104140        ariba_mod.base_comm->stop();
  • source/ariba/Node.h

    r7469 r7532  
    5050#include <vector>
    5151#include <iostream>
     52#include <boost/foreach.hpp>
    5253#include "Module.h"
    5354#include "Identifiers.h"
  • source/ariba/overlay/BaseOverlay.cpp

    r7018 r7532  
    824824        }
    825825
    826 
    827826        //ovl.visShowNodeBubble ( ovlId, nodeId, "joining..." );
    828827        logging_info( "Starting to join spovnet " << id.toString() <<
     
    830829
    831830        if(bootstrapEp.isUnspecified() && state == BaseOverlayStateInvalid){
     831
     832                //** FIRST STEP - MANDATORY */
    832833
    833834                // bootstrap against ourselfs
     
    842843                //ovl.visChangeNodeColor( ovlId, nodeId, OvlVis::NODE_COLORS_GREEN );
    843844
    844                 logging_debug("starting overlay bootstrap module");
    845                 overlayBootstrap.start(this, spovnetId, nodeId);
    846                 overlayBootstrap.publish(bc->getEndpointDescriptor());
    847 
    848845        } else {
     846
     847                //** SECOND STEP - OPTIONAL */
    849848
    850849                // bootstrap against another node
     
    857856}
    858857
    859 void BaseOverlay::leaveSpoVNet() {
    860 
    861         logging_info( "Leaving spovnet " << spovnetId );
    862         bool ret = ( state != this->BaseOverlayStateInvalid );
    863 
     858
     859void BaseOverlay::startBootstrapModules(vector<pair<BootstrapManager::BootstrapType,string> > modules){
     860        logging_debug("starting overlay bootstrap module");
     861        overlayBootstrap.start(this, spovnetId, nodeId, modules);
     862        overlayBootstrap.publish(bc->getEndpointDescriptor());
     863}
     864
     865void BaseOverlay::stopBootstrapModules(){
    864866        logging_debug("stopping overlay bootstrap module");
    865867        overlayBootstrap.stop();
    866868        overlayBootstrap.revoke();
     869}
     870
     871void BaseOverlay::leaveSpoVNet() {
     872
     873        logging_info( "Leaving spovnet " << spovnetId );
     874        bool ret = ( state != this->BaseOverlayStateInvalid );
    867875
    868876        logging_debug( "Dropping all auto-links" );
  • source/ariba/overlay/BaseOverlay.h

    r6961 r7532  
    274274
    275275        /**
     276         * Start the bootstrap modules
     277         */
     278        void startBootstrapModules(vector<pair<BootstrapManager::BootstrapType,string> > modules);
     279
     280        /**
     281         * Stop the bootstrap modules
     282         */
     283        void stopBootstrapModules();
     284
     285        /**
    276286         * Let the node leave the SpoVNet.
    277287         */
  • source/ariba/overlay/OverlayBootstrap.cpp

    r7491 r7532  
    6666}
    6767
    68 void OverlayBootstrap::start(BaseOverlay* _overlay, const SpoVNetID& _spovnetid, const NodeID& _nodeid){
     68void OverlayBootstrap::start(BaseOverlay* _overlay,
     69                const SpoVNetID& _spovnetid, const NodeID& _nodeid,
     70                vector<pair<BootstrapManager::BootstrapType,string> > modules){
    6971        overlay = _overlay;
    7072        spovnetid = _spovnetid;
     
    7476
    7577        manager.registerCallback( this );
    76         manager.registerModule( BootstrapManager::BootstrapTypePeriodicBroadcast );
    77         //manager.registerModule( BootstrapManager::BootstrapTypeBluetoothSdp );
    78         //manager.registerModule( BootstrapManager::BootstrapTypeMulticastDns );
     78
     79        typedef pair<BootstrapManager::BootstrapType,string> X;
     80        BOOST_FOREACH( X i, modules){
     81                manager.registerModule( i.first, i.second );
     82        }
    7983
    8084        watchtimer.startWatchdog();
     
    8993
    9094        manager.unregisterCallback( this );
    91         manager.unregisterModule( BootstrapManager::BootstrapTypePeriodicBroadcast );
    92         //manager.unregisterModule( BootstrapManager::BootstrapTypeBluetoothSdp );
    93         //manager.unregisterModule( BootstrapManager::BootstrapTypeMulticastDns );
     95        manager.unregisterAllModules();
    9496
    9597        watchtimer.stopWatchdog();
  • source/ariba/overlay/OverlayBootstrap.h

    r6919 r7532  
    4444#include <ctime>
    4545#include <deque>
     46#include <vector>
    4647#include <algorithm>
    4748#include <boost/thread/mutex.hpp>
     49#include <boost/foreach.hpp>
    4850#include "ariba/utility/logging/Logging.h"
    4951#include "ariba/utility/types.h"
     
    6062using std::deque;
    6163using std::string;
     64using std::vector;
     65using std::pair;
    6266using std::ostringstream;
    6367using ariba::utility::SpoVNetID;
     
    8387        virtual ~OverlayBootstrap();
    8488
    85         void start(BaseOverlay* _overlay, const SpoVNetID& _spovnetid, const NodeID& _nodeid);
     89        void start(
     90                        BaseOverlay* _overlay,
     91                        const SpoVNetID& _spovnetid,
     92                        const NodeID& _nodeid,
     93                        vector<pair<BootstrapManager::BootstrapType,string> > modules
     94                        );
    8695        void stop();
    8796
  • source/ariba/utility/bootstrap/BootstrapManager.cpp

    r5953 r7532  
    5454}
    5555
    56 BootstrapManager::RegistrationResult BootstrapManager::registerModule(BootstrapManager::BootstrapType type){
     56BootstrapManager::RegistrationResult BootstrapManager::registerModule(
     57                BootstrapManager::BootstrapType type, string info){
    5758
    5859        boost::mutex::scoped_lock lock( modulesMutex );
     
    6869        switch(type){
    6970        case BootstrapTypeMulticastDns:
    70                 module = new MulticastDns(this);
     71                module = new MulticastDns(this, info);
    7172                break;
    7273        case BootstrapTypePeriodicBroadcast:
    73                 module = new PeriodicBroadcast(this);
     74                module = new PeriodicBroadcast(this, info);
    7475                break;
    7576        case BootstrapTypeBluetoothSdp:
    76                 module = new BluetoothSdp(this);
     77                module = new BluetoothSdp(this, info);
    7778                break;
    7879        }
  • source/ariba/utility/bootstrap/BootstrapManager.h

    r5953 r7532  
    8585
    8686        RegistrationResult registerAllModules();
    87         RegistrationResult registerModule(BootstrapType type);
     87        RegistrationResult registerModule(BootstrapType type, string info=string(""));
    8888        RegistrationResult unregisterAllModules();
    8989        RegistrationResult unregisterModule(BootstrapType type);
  • source/ariba/utility/bootstrap/modules/bluetoothsdp/BluetoothSdp.cpp

    r7043 r7532  
    7272OverlayBootstrap* BluetoothSdp::CONNECTION_CHECKER = NULL;
    7373
    74 BluetoothSdp::BluetoothSdp(BootstrapInformationCallback* _callback) :
    75         BootstrapModule(_callback), scan_timer_(io_service_) {
     74BluetoothSdp::BluetoothSdp(BootstrapInformationCallback* _callback, string info)
     75        : BootstrapModule(_callback), scan_timer_(io_service_) {
    7676        srand( time(NULL) );
    7777#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
     
    8080        // of the info strings (as an attribute)
    8181        channel_ = 1;
    82 
    8382#endif // HAVE_BLUETOOTH_BLUETOOTH_H
    8483}
  • source/ariba/utility/bootstrap/modules/bluetoothsdp/BluetoothSdp.h

    r5967 r7532  
    8080        static OverlayBootstrap* CONNECTION_CHECKER;
    8181
    82         BluetoothSdp(BootstrapInformationCallback* _callback);
     82        BluetoothSdp(BootstrapInformationCallback* _callback, string info);
    8383        virtual ~BluetoothSdp();
    8484
  • source/ariba/utility/bootstrap/modules/multicastdns/MulticastDns.cpp

    r5284 r7532  
    4646use_logging_cpp(MulticastDns);
    4747
    48 MulticastDns::MulticastDns(BootstrapInformationCallback* _callback) : BootstrapModule(_callback) {
     48MulticastDns::MulticastDns(BootstrapInformationCallback* _callback, string info)
     49        : BootstrapModule(_callback) {
    4950  #ifdef HAVE_AVAHI_CLIENT_CLIENT_H
    5051        avahiclient = NULL;
  • source/ariba/utility/bootstrap/modules/multicastdns/MulticastDns.h

    r4836 r7532  
    7171        use_logging_h(MulticastDns);
    7272public:
    73         MulticastDns(BootstrapInformationCallback* _callback);
     73        MulticastDns(BootstrapInformationCallback* _callback, string info);
    7474        virtual ~MulticastDns();
    7575
  • source/ariba/utility/bootstrap/modules/periodicbroadcast/PeriodicBroadcast.cpp

    r5838 r7532  
    6363const unsigned int PeriodicBroadcast::serverport_v6 = 5636;
    6464
    65 PeriodicBroadcast::PeriodicBroadcast(BootstrapInformationCallback* _callback)
     65PeriodicBroadcast::PeriodicBroadcast(BootstrapInformationCallback* _callback, string info)
    6666        : BootstrapModule(_callback),
    6767        server(io_service, &newRemoteServices, &newRemoteServicesMutex) {
     
    108108
    109109        boost::mutex::scoped_lock lock( localServicesMutex );
     110        if(name.empty()) return;
     111
    110112        localServices.insert( std::make_pair(name, service) );
    111113}
     
    113115void PeriodicBroadcast::revokeService(string name){
    114116        boost::mutex::scoped_lock lock( localServicesMutex );
     117        if(name.empty()) return;
    115118
    116119        ServiceList::iterator i = localServices.find( name );
  • source/ariba/utility/bootstrap/modules/periodicbroadcast/PeriodicBroadcast.h

    r6919 r7532  
    6666        use_logging_h(PeriodicBroadcast);
    6767public:
    68         PeriodicBroadcast(BootstrapInformationCallback* _callback);
     68        PeriodicBroadcast(BootstrapInformationCallback* _callback, string info);
    6969        virtual ~PeriodicBroadcast();
    7070
     
    275275
    276276                        PeriodicBroadcastMessage msg;
     277                        if(service.getName().empty()) return;
    277278
    278279                        msg.setName( service.getName() );
     
    351352                                { // insert new found service
    352353                                        boost::mutex::scoped_lock lock( *servicesmutex );
     354                                        if(msg.getName().empty()) return;
    353355
    354356                                        ServiceList::iterator it = services->find( msg.getName() );
Note: See TracChangeset for help on using the changeset viewer.