Changeset 2452
- Timestamp:
- Feb 18, 2009, 11:39:30 AM (16 years ago)
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
etc/pingpong/settings_initiator.cnf
r2419 r2452 4 4 ariba.tcp.port = 5002 5 5 #ariba.udp.port = 6 #ariba.bootstrap.hints = 6 ariba.bootstrap.hints=pingpong{ip{127.0.0.1},tcp(ip,5002)} -
etc/pingpong/settings_node1.cnf
r2419 r2452 4 4 ariba.tcp.port = 5003 5 5 #ariba.udp.port = 6 ariba.bootstrap.hints = <spovnet>pingpong<ip>127.0.0.1<port>50026 ariba.bootstrap.hints=pingpong{ip{127.0.0.1},tcp(ip,5002)} -
etc/pingpong/settings_node2.cnf
r2419 r2452 4 4 ariba.tcp.port = 5010 5 5 #ariba.udp.port = 6 ariba.bootstrap.hints = <spovnet>pingpong<ip>127.0.0.1<port>50026 ariba.bootstrap.hints=pingpong{ip{127.0.0.1},tcp(ip,5002)} -
source/ariba/AribaModule.cpp
r2434 r2452 45 45 // ariba includes 46 46 #include "ariba/utility/misc/Helper.h" 47 #include "ariba/utility/misc/StringFormat.h" 47 48 48 49 // hack includes … … 53 54 using namespace ariba::utility::Helper; 54 55 using ariba::interface::UnderlayAbstraction; 56 using ariba::communication::EndpointDescriptor; 55 57 56 58 namespace ariba { 59 60 AribaModule::BootstrapNode::~BootstrapNode() { 61 if (desc!=NULL) delete desc; 62 } 57 63 58 64 AribaModule::AribaModule() { … … 69 75 } 70 76 71 72 77 string AribaModule::getBootstrapHints(const Name& spoVNetName) const { 73 78 std::ostringstream o; 79 BOOST_FOREACH( const BootstrapInfo& info, bootstrapNodes ) { 80 o << info.spovnetName.toString() << "{"; 81 int i=0; 82 BOOST_FOREACH( const BootstrapNode& node, info.nodes ) { 83 if (i!=0) o << ","; 84 if( node.desc != NULL ) o << node.desc->toString(); 85 i++; 86 } 87 } 88 return o.str(); 74 89 } 75 90 76 91 void AribaModule::addBootstrapHints(string boot_info) { 77 string str = boot_info; 78 static ::boost::regex boot_expr("<([^>:]+)[:]?([0-9]+)?>([^<]+)(.*)"); 79 ::boost::smatch what; 80 while (::boost::regex_match(str, what, boot_expr)) { 81 std::cout << what[1].str() << ":" << what[2].str() << "=" << what[3] 82 << std::endl; 83 str = what[4].str(); 84 } 85 } 86 87 void AribaModule::addBootstrapNode(const Name& spovnet, const Name& node, 92 using namespace boost::xpressive; 93 using namespace ariba::utility::string_format; 94 using namespace ariba::utility::Helper; 95 using namespace std; 96 97 smatch match; 98 if (regex_search(boot_info, match, robjects)) { 99 regex_nav nav = match; 100 for (int i = 0; i < nav.size(); i++) { 101 string type = nav[i][robject_id].str(); 102 string data = nav[i][robject_data].str(); 103 data = data.substr(1, data.size() - 2); 104 Name name = type; 105 EndpointDescriptor* desc = EndpointDescriptor::fromString(data); 106 addBootstrapNode(name, desc); 107 } 108 } 109 } 110 111 void AribaModule::addBootstrapNode(const Name& spovnet, 88 112 communication::EndpointDescriptor* desc) { 89 113 114 // set bootstrap node 115 BootstrapNode node; 116 node.timestamp = 0; 117 node.desc = desc; 118 bool added = false; 119 120 // add node to existing bootstrap list 121 BOOST_FOREACH( BootstrapInfo& info, bootstrapNodes ){ 122 if (info.spovnetName == spovnet) { 123 info.nodes.push_back(node); 124 added = true; 125 break; 126 } 127 } 128 129 // create new entry 130 if (!added) { 131 BootstrapInfo info; 132 info.spovnetName = spovnet; 133 info.nodes.push_back(node); 134 bootstrapNodes.push_back(info); 135 } 136 137 std::cout << "added bootstrap info: " << getBootstrapHints() << std::endl; 90 138 } 91 139 92 140 const communication::EndpointDescriptor* AribaModule::getBootstrapNode( 93 const Name& spovnet) { 94 95 BOOST_FOREACH( BootstrapInfo info, bootstrapNodes ){ 96 if( info.spovnetName == spovnet ){ 97 BOOST_FOREACH( BootstrapNode node, info.desc ){ 141 const Name& spovnet) const { 142 BOOST_FOREACH( const BootstrapInfo& info, bootstrapNodes ) { 143 if( info.spovnetName == spovnet ) { 144 BOOST_FOREACH( const BootstrapNode& node, info.nodes ) { 98 145 if( node.desc != NULL ) return node.desc; 99 146 } 100 147 } 101 148 } 102 103 149 return NULL; 104 150 } … … 150 196 *loc = communication::IPv4Locator::fromString(value); 151 197 ip_addr = loc; 152 } else if (key == "tcp.port") tcp_port = stoi(value); 198 } 199 else if (key == "tcp.port") tcp_port = stoi(value); 153 200 else if (key == "udp.port") udp_port = stoi(value); 154 201 else if (key == "bootstrap.hints") addBootstrapHints(value); -
source/ariba/AribaModule.h
r2434 r2452 141 141 class BootstrapNode { 142 142 public: 143 inline BootstrapNode() : timestamp(0), desc(NULL) { 144 145 } 146 inline BootstrapNode(uint32_t timestamp, 147 communication::EndpointDescriptor* desc) : 148 timestamp(timestamp), desc(desc) { 149 150 } 151 ~BootstrapNode(); 143 152 uint32_t timestamp; 144 153 communication::EndpointDescriptor* desc; … … 149 158 public: 150 159 Name spovnetName; 151 vector<BootstrapNode> desc;160 vector<BootstrapNode> nodes; 152 161 }; 153 162 vector<BootstrapInfo> bootstrapNodes; … … 155 164 protected: 156 165 // members 157 string bootstrapFile; 158 bool started; 166 string bootstrapFile; //< file with bootstrap information 167 bool started; //< flag, if module has been started 159 168 160 169 // bootstrap node management 161 void addBootstrapNode(const Name& spovnet, const Name& node,170 void addBootstrapNode(const Name& spovnet, 162 171 communication::EndpointDescriptor* desc); 163 172 const communication::EndpointDescriptor* getBootstrapNode( 164 const Name& spovnet) ;173 const Name& spovnet) const; 165 174 166 175 // TODO: merge with old interface -
source/ariba/communication/EndpointDescriptor.cpp
r2451 r2452 38 38 39 39 #include "EndpointDescriptor.h" 40 #include "ariba/utility/misc/StringFormat.h" 41 #include "ariba/utility/misc/Helper.h" 40 42 41 43 namespace ariba { … … 68 70 string EndpointDescriptor::toString() const { 69 71 if( locator == NULL ) return "<undefined locator>"; 70 else return locator->toString(); 72 std::ostringstream o; 73 o << "ip{" << locator->getIP() << "}"; 74 o << ","; 75 o << "tcp(ip,{" << locator->getPort() << "})"; 76 return o.str(); 71 77 } 72 78 73 79 EndpointDescriptor* EndpointDescriptor::fromString( string str ) { 74 EndpointDescriptor* ep = new EndpointDescriptor(); 75 ep->locator->fromString(str); 76 ep->isUnspec = false; 80 using namespace boost::xpressive; 81 using namespace ariba::utility::string_format; 82 using namespace ariba::utility::Helper; 83 using namespace std; 84 85 EndpointDescriptor* ep = NULL; 86 smatch match; 87 if (regex_search(str, match, robjects)) { 88 regex_nav nav = match; 89 for (int i=0; i<nav.size(); i++) { 90 string type = nav[i][robject_id].str(); 91 if (type=="ip") { 92 string ip = nav[i][robject_data].str(); 93 ip = ip.substr(1,ip.size()-2); 94 cout << "ep-ip = " <<ip << endl; 95 ep = new EndpointDescriptor(); 96 ep->locator = new IPv4Locator(); 97 ep->locator->setIP(ip); 98 ep->isUnspec = false; 99 } else 100 if (type=="tcp") { 101 string port = nav[i][robject_data][rfields][1].str(); 102 port = port.substr(1,port.size()-2); 103 cout << "ep-tcp-port = " << port << endl; 104 ep->locator->setPort(stoi(port)); 105 } 106 } 107 } 77 108 return ep; 78 109 } -
source/ariba/communication/modules/network/ip/IPv4Locator.h
r2451 r2452 77 77 virtual string toString() const; 78 78 79 void setIP( string ip ) { 80 ipv4Address = boost::asio::ip::address_v4::from_string( ip ); 81 } 82 79 83 string getIP() const { 80 84 return ipv4Address.to_string(); … … 91 95 boost::asio::ip::address_v4 ipv4Address; 92 96 uint16_t port; 93 94 97 }; 95 98 -
source/ariba/utility/misc/StringFormat.cpp
r2444 r2452 4 4 #include "boost/xpressive/xpressive.hpp" 5 5 6 namespace ariba { 7 namespace utility { 8 namespace string_format { 9 6 10 using namespace boost::xpressive; 7 11 8 12 // regex: string 9 const sregex StringFormat::rstring = '"' >> keep(*~(boost::xpressive::set = '"'))13 const sregex rstring = '"' >> keep(*~(boost::xpressive::set = '"')) 10 14 >> '"'; 11 15 12 16 // regex: base64 encoding 13 const sregex StringFormat::rbase64 = '!' >> +(range('a', 'z') | range('A', 'Z')17 const sregex rbase64 = '!' >> +(range('a', 'z') | range('A', 'Z') 14 18 | range('0', '9') | '/' | '+') >> *(boost::xpressive::set = '='); 15 19 16 20 // regex: raw alphabet 17 const sregex StringFormat::rchars = +(range('a', 'z') | range('A', 'Z'));21 const sregex rchars = +(range('a', 'z') | range('A', 'Z')); 18 22 19 23 // regex: integer 20 const sregex StringFormat::rint = '0' | (range('1', '9') >> !(range('0', '9')));24 const sregex rint = '0' | (range('1', '9') >> !(range('0', '9'))); 21 25 22 26 // regex: binary label 23 const sregex StringFormat::rlabel = rchars | rstring | rbase64;27 const sregex rlabel = rchars | rstring | rbase64; 24 28 25 29 // regex: dot separated identifier 26 const sregex StringFormat::rid = rlabel >> *('.' >> rlabel) >> *('.' >> rint);30 const sregex rid = rlabel >> *('.' >> rlabel) >> *('.' >> rint); 27 31 28 32 // regex: "leaf" data 29 const sregex StringFormat::rdata = !(boost::xpressive::set = '!') >> '{'33 const sregex rdata = !(boost::xpressive::set = '!') >> '{' 30 34 >> *(keep(+~(boost::xpressive::set = '{', '}')) | by_ref(rdata)) 31 35 >> '}'; 32 36 33 37 // regex: fields 34 const sregex StringFormat::rfield_label = rlabel >> '=';35 const sregex StringFormat::rfield = !rfield_label >> (rid | rdata);36 const sregex StringFormat::rfields = '(' >> rfield >> *(',' >> rfield) >> ')';38 const sregex rfield_label = rlabel >> '='; 39 const sregex rfield = !rfield_label >> (rid | rdata); 40 const sregex rfields = '(' >> rfield >> *(',' >> rfield) >> ')'; 37 41 38 // regex: objects 39 const sregex StringFormat::robject_data = (rdata | rfields); 40 const sregex StringFormat::robject = rid >> robject_data; 41 const sregex StringFormat::robjects = robject >> *(',' >> robject); 42 // regex objects 43 const sregex robject_data = (rdata | rfields); 44 const sregex robject_id = rid; 45 const sregex robject = robject_id >> robject_data; 46 const sregex robjects = robject >> *(',' >> robject); 47 48 }}} -
source/ariba/utility/misc/StringFormat.h
r2444 r2452 5 5 #include "boost/xpressive/xpressive.hpp" 6 6 7 namespace ariba { 8 namespace utility { 9 namespace string_format { 10 7 11 using boost::xpressive::sregex; 8 12 9 /** 10 * This class defines some regular expressions ... 11 * 12 * @author Sebastian Mies 13 */ 14 class StringFormat { 13 class regex_nav { 14 private: 15 typedef boost::xpressive::smatch _match; 16 typedef _match::nested_results_type nested_results; 17 typedef nested_results::const_iterator nested_iterator; 18 const _match& match; 19 15 20 public: 16 // regex: string 17 static const sregex rstring; 21 regex_nav(const _match& match) : 22 match(match) { 23 } 18 24 19 // regex: base64 encoding 20 static const sregex rbase64; 25 regex_nav() : 26 match(*((const _match*) NULL)) { 27 } 21 28 22 // regex: raw alphabet 23 static const sregex rchars; 29 bool matched() const { 30 return &match != NULL; 31 } 24 32 25 // regex: integer 26 static const sregex rint; 33 regex_nav operator[] (const sregex& type) const { 34 const nested_results& nr = match.nested_results(); 35 for (nested_iterator i = nr.begin(); i != nr.end(); i++) { 36 if (i->regex_id() == type.regex_id()) return regex_nav(*i); 37 } 38 return regex_nav(); 39 } 27 40 28 // regex: binary label 29 static const sregex rlabel; 41 regex_nav operator[](int index) const { 42 const nested_results& nr = match.nested_results(); 43 for (nested_iterator i = nr.begin(); i != nr.end() && index >= 0; i++) { 44 if (index == 0) return regex_nav(*i); 45 index--; 46 } 47 return regex_nav(); 48 } 30 49 31 // regex: dot separated identifier 32 static const sregex rid; 50 int size() const { 51 return match.nested_results().size(); 52 } 33 53 34 // regex: "leaf" data 35 static const sregex rdata; 36 37 // regex: fields 38 static const sregex rfield_label; 39 static const sregex rfield; 40 static const sregex rfields; 41 42 // regex: objects 43 static const sregex robject_data; 44 static const sregex robject; 45 static const sregex robjects; 54 std::string str() const { 55 if (!matched()) return std::string("<no match>"); 56 return match[0].str(); 57 } 46 58 }; 47 59 60 // regex: string 61 extern const sregex rstring; 62 63 // regex: base64 encoding 64 extern const sregex rbase64; 65 66 // regex: raw alphabet 67 extern const sregex rchars; 68 69 // regex: integer 70 extern const sregex rint; 71 72 // regex: binary label 73 extern const sregex rlabel; 74 75 // regex: dot separated identifier 76 extern const sregex rid; 77 78 // regex: "leaf" data 79 extern const sregex rdata; 80 81 // regex: fields 82 extern const sregex rfield_label; 83 extern const sregex rfield; 84 extern const sregex rfields; 85 86 // regex: objects 87 extern const sregex robject_data; 88 extern const sregex robject_id; 89 extern const sregex robject; 90 extern const sregex robjects; 91 92 }}} 93 48 94 #endif /* STRINGFORMAT_H_ */
Note:
See TracChangeset
for help on using the changeset viewer.