Changeset 7532 for source/ariba/AribaModule.cpp
- Timestamp:
- Feb 4, 2010, 5:29:37 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
source/ariba/AribaModule.cpp
r7468 r7532 43 43 #include <boost/regex.hpp> 44 44 #include <boost/foreach.hpp> 45 #include <boost/algorithm/string.hpp> 45 46 46 47 // ariba includes … … 58 59 59 60 use_logging_cpp(AribaModule); 61 const string AribaModule::BootstrapMechanismNames[5] = {"invalid", "static", "broadcast", "mdns", "sdp"}; 60 62 61 63 AribaModule::AribaModule() … … 69 71 string AribaModule::getBootstrapHints(const Name& spoVNetName) const { 70 72 std::ostringstream o; 73 int i=0; 71 74 BOOST_FOREACH( const BootstrapInfo& info, bootstrapNodes ) { 72 75 o << info.spovnetName.toString() << "{"; 73 int i=0; 76 if (i!=0) o << ","; 77 74 78 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 } 78 88 } 79 89 o << "}"; 90 i++; 80 91 } 81 92 return o.str(); … … 87 98 using namespace ariba::utility::Helper; 88 99 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"); 89 105 90 106 smatch match; … … 96 112 data = data.substr(1, data.size() - 2); 97 113 Name name(type); 114 115 // find static bootstrap info --> BootstrapMechanismStatic 98 116 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() ); 103 150 } 104 151 105 152 void 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 159 void AribaModule::addBootstrapNode(const Name& spovnet, const BootstrapNode& node){ 112 160 bool added = false; 113 161 … … 128 176 bootstrapNodes.push_back(info); 129 177 } 130 131 logging_debug( "Added bootstrap info: " << getBootstrapHints() );132 178 } 133 179 134 180 const communication::EndpointDescriptor* AribaModule::getBootstrapNode( 135 const Name& spovnet ) const {181 const Name& spovnet, const BootstrapMechanism mechanism) const { 136 182 BOOST_FOREACH( const BootstrapInfo& info, bootstrapNodes ) { 137 183 if( info.spovnetName == spovnet ) { 138 184 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; 140 187 } 141 188 } 142 189 } 143 190 return NULL; 191 } 192 193 string 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 207 vector<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; 144 219 } 145 220
Note:
See TracChangeset
for help on using the changeset viewer.