close Warning: Can't use blame annotator:
No changeset 2305 in the repository

source: source/ariba/AribaModule.cpp@ 2435

Last change on this file since 2435 was 2434, checked in by Christoph Mayer, 16 years ago

-getBootstrapNodes implementiert

File size: 4.8 KB
RevLine 
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/utility/misc/Helper.h"
47
48// hack includes
49#include "ariba/interface/UnderlayAbstraction.h"
50#include "ariba/communication/EndpointDescriptor.h"
51#include "ariba/communication/modules/network/NetworkLocator.h"
52
53using namespace ariba::utility::Helper;
54using ariba::interface::UnderlayAbstraction;
55
56namespace ariba {
57
58AribaModule::AribaModule() {
59
60 // init with default values
61 this->underlay_abs = NULL;
62 this->ip_addr = NULL;
63 this->tcp_port = 41402;
64 this->udp_port = 41402;
65 this->started = false;
66}
67
68AribaModule::~AribaModule() {
69}
70
71
72string AribaModule::getBootstrapHints(const Name& spoVNetName) const {
73
74}
75
76void 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
87void AribaModule::addBootstrapNode(const Name& spovnet, const Name& node,
88 communication::EndpointDescriptor* desc) {
89
90}
91
92const 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 ){
98 if( node.desc != NULL ) return node.desc;
99 }
100 }
101 }
102
103 return NULL;
104}
105
106// @see Module.h
107void AribaModule::initialize() {
108
109 // preconditions
110 assert(!started);
111
112 // init variables
113 underlay_abs = NULL;
114}
115
116// @see Module.h
117void AribaModule::start() {
118
119 // preconditions
120 assert(underlay_abs == NULL);
121 assert(!started);
122
123 // create the base communication component
124 started = true;
125 underlay_abs = new interface::UnderlayAbstraction();
126}
127
128// @see Module.h
129void AribaModule::stop() {
130
131 // preconditions
132 assert(underlay_abs != NULL);
133 assert(started);
134
135 // delete base communication component
136 started = false;
137 delete underlay_abs;
138}
139
140// @see Module.h
141string AribaModule::getName() const {
142 return "ariba";
143}
144
145// @see Module.h
146void AribaModule::setProperty(string key, string value) {
147 if (key == "ip.addr") {
148 if (ip_addr != NULL) delete ip_addr;
149 communication::IPv4Locator* loc = new communication::IPv4Locator();
150 *loc = communication::IPv4Locator::fromString(value);
151 ip_addr = loc;
152 } else if (key == "tcp.port") tcp_port = stoi(value);
153 else if (key == "udp.port") udp_port = stoi(value);
154 else if (key == "bootstrap.hints") addBootstrapHints(value);
155}
156
157// @see Module.h
158const string AribaModule::getProperty(string key) const {
159 if (key == "ip.addr") return ip_addr->toString();
160 else if (key == "tcp.port") return ultos(tcp_port);
161 else if (key == "udp.port") return ultos(udp_port);
162 else if (key == "bootstrap.hints") return getBootstrapHints();
163}
164
165// @see Module.h
166const vector<string> AribaModule::getProperties() const {
167 vector<string> properties;
168 properties.push_back("ip.addr");
169 properties.push_back("tcp.port");
170 properties.push_back("udp.port");
171 properties.push_back("hints");
172 return properties;
173}
174
175} // namespace ariba
Note: See TracBrowser for help on using the repository browser.