source: source/ariba/AribaModule.cpp@ 5286

Last change on this file since 5286 was 5284, checked in by mies, 15 years ago

+ added new transport modules and adapted ariba to them
+ exchange endpoint descriptors an link establishment
+ clean up of base communication
+ link establishment with in the presence of multiple endpoints
+ local discovery for ipv6, ipv4 and bluetooth mac addresses

File size: 5.7 KB
Line 
1// [License]
2// The Ariba-Underlay Copyright
3//
4// Copyright (c) 2008-2009, Institute of Telematics, UniversitÀt Karlsruhe (TH)
5//
6// Institute of Telematics
7// UniversitÀt Karlsruhe (TH)
8// Zirkel 2, 76128 Karlsruhe
9// Germany
10//
11// Redistribution and use in source and binary forms, with or without
12// modification, are permitted provided that the following conditions are
13// met:
14//
15// 1. Redistributions of source code must retain the above copyright
16// notice, this list of conditions and the following disclaimer.
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// THIS SOFTWARE IS PROVIDED BY THE INSTITUTE OF TELEMATICS ``AS IS'' AND
22// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ARIBA PROJECT OR
25// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32//
33// The views and conclusions contained in the software and documentation
34// are those of the authors and should not be interpreted as representing
35// official policies, either expressed or implied, of the Institute of
36// Telematics.
37// [License]
38
39#include "AribaModule.h"
40
41// boost/std includes
42#include <assert.h>
43#include <boost/regex.hpp>
44#include <boost/foreach.hpp>
45
46// ariba includes
47#include "ariba/SideportListener.h"
48#include "ariba/utility/misc/Helper.h"
49#include "ariba/utility/misc/StringFormat.h"
50#include "ariba/communication/BaseCommunication.h"
51#include "ariba/communication/EndpointDescriptor.h"
52
53using namespace ariba::utility::Helper;
54using ariba::communication::BaseCommunication;
55using ariba::communication::EndpointDescriptor;
56
57namespace ariba {
58
59use_logging_cpp(AribaModule);
60
61AribaModule::AribaModule()
62 : base_comm(NULL), sideport_sniffer(NULL), started(false) {
63}
64
65AribaModule::~AribaModule() {
66}
67
68string AribaModule::getBootstrapHints(const Name& spoVNetName) const {
69 std::ostringstream o;
70 BOOST_FOREACH( const BootstrapInfo& info, bootstrapNodes ) {
71 o << info.spovnetName.toString() << "{";
72 int i=0;
73 BOOST_FOREACH( const BootstrapNode& node, info.nodes ) {
74 if (i!=0) o << ",";
75 if( node.desc != NULL ) o << node.desc->toString();
76 i++;
77 }
78 o << "}";
79 }
80 return o.str();
81}
82
83void AribaModule::addBootstrapHints(string boot_info) {
84 using namespace boost::xpressive;
85 using namespace ariba::utility::string_format;
86 using namespace ariba::utility::Helper;
87 using namespace std;
88
89 smatch match;
90 if (regex_search(boot_info, match, robjects)) {
91 regex_nav nav = match;
92 for (int i = 0; i < nav.size(); i++) {
93 string type = nav[i][robject_id].str();
94 string data = nav[i][robject_data].str();
95 data = data.substr(1, data.size() - 2);
96 Name name(type);
97 EndpointDescriptor* desc = EndpointDescriptor::fromString(data);
98 logging_debug("Added bootstap info for " << type << ": " << desc->toString() );
99 addBootstrapNode(name, desc);
100 }
101 }
102}
103
104void AribaModule::addBootstrapNode(const Name& spovnet,
105 communication::EndpointDescriptor* desc) {
106
107 // set bootstrap node
108 BootstrapNode node;
109 node.timestamp = 0;
110 node.desc = desc;
111 bool added = false;
112
113 // add node to existing bootstrap list
114 BOOST_FOREACH( BootstrapInfo& info, bootstrapNodes ){
115 if (info.spovnetName == spovnet) {
116 info.nodes.push_back(node);
117 added = true;
118 break;
119 }
120 }
121
122 // create new entry
123 if (!added) {
124 BootstrapInfo info;
125 info.spovnetName = spovnet;
126 info.nodes.push_back(node);
127 bootstrapNodes.push_back(info);
128 }
129
130 logging_debug( "Added bootstrap info: " << getBootstrapHints() );
131}
132
133const communication::EndpointDescriptor* AribaModule::getBootstrapNode(
134 const Name& spovnet) const {
135 BOOST_FOREACH( const BootstrapInfo& info, bootstrapNodes ) {
136 if( info.spovnetName == spovnet ) {
137 BOOST_FOREACH( const BootstrapNode& node, info.nodes ) {
138 if( node.desc != NULL ) return node.desc;
139 }
140 }
141 }
142 return NULL;
143}
144
145void AribaModule::registerSideportListener(SideportListener* sideport){
146 sideport_sniffer = sideport;
147}
148
149// @see Module.h
150void AribaModule::initialize() {
151
152 // preconditions
153 assert(!started);
154
155 // init variables
156 base_comm = NULL;
157}
158
159// @see Module.h
160void AribaModule::start() {
161
162 // preconditions
163 assert(base_comm == NULL);
164 assert(!started);
165
166 // create the base communication component
167 started = true;
168 base_comm = new BaseCommunication();
169 base_comm->setEndpoints(endpoints);
170}
171
172// @see Module.h
173void AribaModule::stop() {
174
175 // preconditions
176 assert(base_comm != NULL);
177 assert(started);
178
179 // delete base communication component
180 started = false;
181 delete base_comm;
182}
183
184// @see Module.h
185string AribaModule::getName() const {
186 return "ariba";
187}
188
189// @see Module.h
190void AribaModule::setProperty(string key, string value) {
191 if (key == "endpoints") endpoints = value;
192 else if (key == "bootstrap.hints") addBootstrapHints(value);
193}
194
195// @see Module.h
196const string AribaModule::getProperty(string key) const {
197 if (key == "endpoints") return endpoints; // TODO: return local endpoints
198 else if (key == "bootstrap.hints") return getBootstrapHints();
199}
200
201// @see Module.h
202const vector<string> AribaModule::getProperties() const {
203 vector<string> properties;
204 properties.push_back("endpoints");
205 properties.push_back("bootstrap.hints");
206 return properties;
207}
208
209} // namespace ariba
Note: See TracBrowser for help on using the repository browser.