An Overlay-based
Virtual Network Substrate
SpoVNet

source: source/ariba/AribaModule.cpp @ 3374

Last change on this file since 3374 was 3374, checked in by Christoph Mayer, 15 years ago

-Integration of Branch 20090424-mayer-sideport

File size: 6.1 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
45// ariba includes
46#include "ariba/SideportListener.h"
47#include "ariba/utility/misc/Helper.h"
48#include "ariba/utility/misc/StringFormat.h"
49#include "ariba/communication/BaseCommunication.h"
50#include "ariba/communication/EndpointDescriptor.h"
51#include "ariba/communication/modules/network/NetworkLocator.h"
52
53using namespace ariba::utility::Helper;
54using ariba::communication::BaseCommunication;
55using ariba::communication::EndpointDescriptor;
56
57namespace ariba {
58
59AribaModule::AribaModule()
60        : base_comm(NULL), sideport_sniffer(NULL),
61                ip_addr(NULL), started(false) {
62
63        // init with default values
64
65        this->tcp_port = 41402;
66        this->udp_port = 41402;
67}
68
69AribaModule::~AribaModule() {
70}
71
72string AribaModule::getBootstrapHints(const Name& spoVNetName) const {
73        std::ostringstream o;
74        BOOST_FOREACH( const BootstrapInfo& info, bootstrapNodes ) {
75                o << info.spovnetName.toString() << "{";
76                int i=0;
77                BOOST_FOREACH( const BootstrapNode& node, info.nodes ) {
78                        if (i!=0) o << ",";
79                        if( node.desc != NULL ) o << node.desc->toString();
80                        i++;
81                }
82                o << "}";
83        }
84        return o.str();
85}
86
87void AribaModule::addBootstrapHints(string boot_info) {
88        using namespace boost::xpressive;
89        using namespace ariba::utility::string_format;
90        using namespace ariba::utility::Helper;
91        using namespace std;
92
93        smatch match;
94        if (regex_search(boot_info, match, robjects)) {
95                regex_nav nav = match;
96                for (int i = 0; i < nav.size(); i++) {
97                        string type = nav[i][robject_id].str();
98                        string data = nav[i][robject_data].str();
99                        data = data.substr(1, data.size() - 2);
100                        Name name(type);
101                        EndpointDescriptor* desc = EndpointDescriptor::fromString(data);
102                        addBootstrapNode(name, desc);
103                }
104        }
105}
106
107void AribaModule::addBootstrapNode(const Name& spovnet,
108                communication::EndpointDescriptor* desc) {
109
110        // set bootstrap node
111        BootstrapNode node;
112        node.timestamp = 0;
113        node.desc = desc;
114        bool added = false;
115
116        // add node to existing bootstrap list
117        BOOST_FOREACH( BootstrapInfo& info, bootstrapNodes ){
118                if (info.spovnetName == spovnet) {
119                        info.nodes.push_back(node);
120                        added = true;
121                        break;
122                }
123        }
124
125        // create new entry
126        if (!added) {
127                BootstrapInfo info;
128                info.spovnetName = spovnet;
129                info.nodes.push_back(node);
130                bootstrapNodes.push_back(info);
131        }
132
133        //logging_debug( "added bootstrap info: " << getBootstrapHints() );
134}
135
136const communication::EndpointDescriptor* AribaModule::getBootstrapNode(
137                const Name& spovnet) const {
138        BOOST_FOREACH( const BootstrapInfo& info, bootstrapNodes ) {
139                if( info.spovnetName == spovnet ) {
140                        BOOST_FOREACH( const BootstrapNode& node, info.nodes ) {
141                                if( node.desc != NULL ) return node.desc;
142                        }
143                }
144        }
145        return NULL;
146}
147
148void AribaModule::registerSideportListener(SideportListener* sideport){
149        sideport_sniffer = sideport;
150}
151
152// @see Module.h
153void AribaModule::initialize() {
154
155        // preconditions
156        assert(!started);
157
158        // init variables
159        base_comm = NULL;
160}
161
162// @see Module.h
163void AribaModule::start() {
164
165        // preconditions
166        assert(base_comm == NULL);
167        assert(!started);
168
169        // create the base communication component
170        started = true;
171        base_comm = new BaseCommunication();
172}
173
174// @see Module.h
175void AribaModule::stop() {
176
177        // preconditions
178        assert(base_comm != NULL);
179        assert(started);
180
181        // delete base communication component
182        started = false;
183        delete base_comm;
184}
185
186// @see Module.h
187string AribaModule::getName() const {
188        return "ariba";
189}
190
191// @see Module.h
192void AribaModule::setProperty(string key, string value) {
193        if (key == "ip.addr") {
194                if (ip_addr != NULL) delete ip_addr;
195                communication::IPv4Locator* loc = new communication::IPv4Locator();
196                *loc = communication::IPv4Locator::fromString(value);
197                ip_addr = loc;
198        }
199        else if (key == "tcp.port") tcp_port = stoi(value);
200        else if (key == "udp.port") udp_port = stoi(value);
201        else if (key == "bootstrap.hints") addBootstrapHints(value);
202}
203
204// @see Module.h
205const string AribaModule::getProperty(string key) const {
206        if (key == "ip.addr") return ip_addr->toString();
207        else if (key == "tcp.port") return ultos(tcp_port);
208        else if (key == "udp.port") return ultos(udp_port);
209        else if (key == "bootstrap.hints") return getBootstrapHints();
210}
211
212// @see Module.h
213const vector<string> AribaModule::getProperties() const {
214        vector<string> properties;
215        properties.push_back("ip.addr");
216        properties.push_back("tcp.port");
217        properties.push_back("udp.port");
218        properties.push_back("hints");
219        return properties;
220}
221
222} // namespace ariba
Note: See TracBrowser for help on using the repository browser.