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 | #ifndef ARIBAMODULE_H_
|
---|
40 | #define ARIBAMODULE_H_
|
---|
41 |
|
---|
42 | #include <string>
|
---|
43 | #include <vector>
|
---|
44 | #include <ctime>
|
---|
45 | #include <cstdlib>
|
---|
46 | #include <algorithm>
|
---|
47 |
|
---|
48 | using std::vector;
|
---|
49 | using std::string;
|
---|
50 |
|
---|
51 | // forward declaration
|
---|
52 | namespace ariba {
|
---|
53 | class AribaModule;
|
---|
54 | class SideportListener;
|
---|
55 | }
|
---|
56 |
|
---|
57 | // local includes
|
---|
58 | #include "Name.h"
|
---|
59 | #include "Module.h"
|
---|
60 |
|
---|
61 | namespace ariba {
|
---|
62 |
|
---|
63 | // forward declaration
|
---|
64 | namespace communication {
|
---|
65 | class EndpointDescriptor;
|
---|
66 | class BaseCommunication;
|
---|
67 | }
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * This class implements a container class for ariba base services. Each node
|
---|
71 | * is a running using this base-module. It also manages Bootstrap information
|
---|
72 | * in a abstract simple way.
|
---|
73 | *
|
---|
74 | * +---+ +---+
|
---|
75 | * |N1 | |N2 |
|
---|
76 | * +--| |---| |--+
|
---|
77 | * | +---+ +---+ |
|
---|
78 | * | |
|
---|
79 | * | AribaModule |
|
---|
80 | * +-----------------+
|
---|
81 | *
|
---|
82 | * N1, N2 are nodes.
|
---|
83 | *
|
---|
84 | * @author Sebastian Mies <mies@tm.uka.de>
|
---|
85 | * @author Christoph Mayer <mayer@tm.uka.de>
|
---|
86 | */
|
---|
87 | class AribaModule: public Module {
|
---|
88 | friend class Node;
|
---|
89 | use_logging_h(AribaModule);
|
---|
90 | public:
|
---|
91 | /**
|
---|
92 | * Constructor of the ariba underlay module
|
---|
93 | */
|
---|
94 | AribaModule();
|
---|
95 |
|
---|
96 | /**
|
---|
97 | * Destructor of the ariba underlay module
|
---|
98 | */
|
---|
99 | virtual ~AribaModule();
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * Returns all known bootstrap endpoints to this ariba module in
|
---|
103 | * a human-readable string. This information can be used by other
|
---|
104 | * nodes for bootstraping. It may also be used to publish this info
|
---|
105 | * to other nodes via the web, for example.
|
---|
106 | *
|
---|
107 | * @param The name of the spovnet
|
---|
108 | * @return A human-readable string containing all known bootstrap
|
---|
109 | * information known to this module.
|
---|
110 | */
|
---|
111 | string getBootstrapHints(const Name& spoVNetName = Name::UNSPECIFIED) const;
|
---|
112 |
|
---|
113 | /**
|
---|
114 | * Adds bootstrap hints to the local database. The format of the string
|
---|
115 | * must is the same as returned by <code>getBootstrapInfo</code>.
|
---|
116 | *
|
---|
117 | * @param bootinfo A string containing bootstrap information.
|
---|
118 | */
|
---|
119 | void addBootstrapHints(string bootinfo);
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * Register a sideport for sniffing on communication events
|
---|
123 | * and get advanced information. The sniffer is attached to
|
---|
124 | * every node that is created on the module. Only one such
|
---|
125 | * sniffer can be active system-wide, a new call to this
|
---|
126 | * register function will only attach the sniffer to nodes
|
---|
127 | * created after the registration call.
|
---|
128 | *
|
---|
129 | * @param sideport The SideportListener to integrate
|
---|
130 | */
|
---|
131 | void registerSideportListener(SideportListener* sideport);
|
---|
132 |
|
---|
133 | // --- module implementation ---
|
---|
134 |
|
---|
135 | /**
|
---|
136 | * Module Property information:
|
---|
137 | *
|
---|
138 | * ip.addr = preferred ip address (otherwise bind to all)
|
---|
139 | * tcp.port = preferred tcp port (or use default value)
|
---|
140 | * udp.port = preferred udp port (or use default value)
|
---|
141 | * bootstrap.hints = used bootstrap hints
|
---|
142 | * bootstrap.file = used file for bootstrap information
|
---|
143 | */
|
---|
144 | void initialize(); ///< @see Module.h
|
---|
145 | void start(); ///< @see Module.h
|
---|
146 | void stop(); ///< @see Module.h
|
---|
147 | string getName() const; ///< @see Module.h
|
---|
148 | void setProperty(string key, string value); ///< @see Module.h
|
---|
149 | const string getProperty(string key) const; ///< @see Module.h
|
---|
150 | const vector<string> getProperties() const; ///< @see Module.h
|
---|
151 |
|
---|
152 | /**
|
---|
153 | * Get the local endpoint information
|
---|
154 | */
|
---|
155 | const string getLocalEndpoints();
|
---|
156 |
|
---|
157 | private:
|
---|
158 |
|
---|
159 | // bootstrap mechanisms
|
---|
160 | enum BootstrapMechanism {
|
---|
161 | BootstrapMechanismInvalid = 0,
|
---|
162 | BootstrapMechanismStatic = 1,
|
---|
163 | BootstrapMechanismBroadcast = 2,
|
---|
164 | BootstrapMechanismMulticastDNS = 3,
|
---|
165 | BootstrapMechanismSDP = 4,
|
---|
166 | };
|
---|
167 | static const string BootstrapMechanismNames[5];
|
---|
168 |
|
---|
169 | // bootstrap node
|
---|
170 | class BootstrapNode {
|
---|
171 | public:
|
---|
172 | inline BootstrapNode() :
|
---|
173 | timestamp(0), desc(NULL), mechanism(BootstrapMechanismInvalid), info("") {
|
---|
174 |
|
---|
175 | }
|
---|
176 | inline BootstrapNode(const BootstrapNode& copy) :
|
---|
177 | timestamp(copy.timestamp), desc(copy.desc), mechanism(copy.mechanism), info(copy.info) {
|
---|
178 | }
|
---|
179 | inline BootstrapNode(
|
---|
180 | uint32_t timestamp,
|
---|
181 | communication::EndpointDescriptor* desc,
|
---|
182 | BootstrapMechanism mechanism, string info) :
|
---|
183 | timestamp(timestamp), desc(desc), mechanism(mechanism), info(info) {
|
---|
184 | }
|
---|
185 | uint32_t timestamp;
|
---|
186 | communication::EndpointDescriptor* desc;
|
---|
187 | BootstrapMechanism mechanism;
|
---|
188 | string info;
|
---|
189 | };
|
---|
190 |
|
---|
191 | // bootstrap info
|
---|
192 | class BootstrapInfo {
|
---|
193 | public:
|
---|
194 | BootstrapInfo() :
|
---|
195 | spovnetName(), nodes() {
|
---|
196 | }
|
---|
197 |
|
---|
198 | BootstrapInfo(const BootstrapInfo& copy) :
|
---|
199 | spovnetName(copy.spovnetName), nodes(copy.nodes) {
|
---|
200 | }
|
---|
201 |
|
---|
202 | Name spovnetName;
|
---|
203 | vector<BootstrapNode> nodes;
|
---|
204 | };
|
---|
205 | vector<BootstrapInfo> bootstrapNodes;
|
---|
206 |
|
---|
207 | protected:
|
---|
208 | // members
|
---|
209 | string endpoints; //< local endpoints the ariba module is bound to
|
---|
210 | bool started; //< flag, if module has been started
|
---|
211 |
|
---|
212 | // bootstrap node management
|
---|
213 | void addBootstrapNode(
|
---|
214 | const Name& spovnet,
|
---|
215 | communication::EndpointDescriptor* desc,
|
---|
216 | const string& info,
|
---|
217 | const BootstrapMechanism& mechanism
|
---|
218 | );
|
---|
219 | void addBootstrapNode(
|
---|
220 | const Name& spovnet,
|
---|
221 | const BootstrapNode& node
|
---|
222 | );
|
---|
223 |
|
---|
224 | vector<AribaModule::BootstrapMechanism> getBootstrapMechanisms(
|
---|
225 | const Name& spovnet
|
---|
226 | ) const;
|
---|
227 |
|
---|
228 | const communication::EndpointDescriptor* getBootstrapNode(
|
---|
229 | const Name& spovnet,
|
---|
230 | const BootstrapMechanism mechanism
|
---|
231 | ) const;
|
---|
232 |
|
---|
233 | string getBootstrapInfo(
|
---|
234 | const Name& spovnet,
|
---|
235 | const BootstrapMechanism mechanism
|
---|
236 | ) const;
|
---|
237 |
|
---|
238 | communication::BaseCommunication* base_comm;
|
---|
239 | SideportListener* sideport_sniffer;
|
---|
240 | };
|
---|
241 |
|
---|
242 | } // namespace ariba
|
---|
243 |
|
---|
244 | #endif /* ENVIRONMENT_H_ */
|
---|