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

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.