source: source/ariba/overlay/BaseOverlay.h@ 3056

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

-fixed all compile errors, but now the overlay functionality is messed up somewhere

File size: 10.4 KB
Line 
1// [Licence]
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// [Licence]
38
39#ifndef BASEOVERLAY_H_
40#define BASEOVERLAY_H_
41
42#include <map>
43#include <iostream>
44#include <algorithm>
45#include <ctime>
46#include <list>
47#include <vector>
48#include <boost/foreach.hpp>
49
50#include "ariba/utility/messages.h"
51#include "ariba/utility/types.h"
52#include "ariba/utility/misc/Helper.h"
53#include "ariba/utility/misc/Demultiplexer.hpp"
54#include "ariba/utility/logging/Logging.h"
55#include "ariba/utility/system/Timer.h"
56
57#include "ariba/communication/EndpointDescriptor.h"
58#include "ariba/communication/BaseCommunication.h"
59#include "ariba/communication/CommunicationEvents.h"
60
61#include "ariba/overlay/modules/OverlayInterface.h"
62#include "ariba/overlay/modules/OverlayFactory.h"
63#include "ariba/overlay/modules/OverlayStructureEvents.h"
64#include "ariba/overlay/messages/OverlayMsg.h"
65#include "ariba/overlay/messages/JoinRequest.h"
66#include "ariba/overlay/messages/JoinReply.h"
67
68// forward declerations
69namespace ariba {
70 class NodeListener;
71 class CommunicationListener;
72 namespace utility {
73 class OvlVis;
74 }
75}
76
77using std::vector;
78using std::list;
79using std::cout;
80using std::map;
81using std::make_pair;
82using std::pair;
83using std::find;
84
85using ariba::NodeListener;
86using ariba::CommunicationListener;
87
88using ariba::communication::EndpointDescriptor;
89using ariba::communication::BaseCommunication;
90using ariba::communication::CommunicationEvents;
91
92using ariba::overlay::OverlayMsg;
93using ariba::overlay::JoinRequest;
94using ariba::overlay::JoinReply;
95using ariba::overlay::OverlayInterface;
96using ariba::overlay::OverlayFactory;
97using ariba::overlay::OverlayStructureEvents;
98
99using ariba::utility::NodeID;
100using ariba::utility::SpoVNetID;
101using ariba::utility::LinkID;
102using ariba::utility::Identifier;
103using ariba::utility::ServiceID;
104using ariba::utility::QoSParameterSet;
105using ariba::utility::SecurityParameterSet;
106using ariba::utility::Demultiplexer;
107using ariba::utility::MessageReceiver;
108using ariba::utility::MessageSender;
109using ariba::utility::seqnum_t;
110using ariba::utility::Timer;
111using ariba::utility::OvlVis;
112
113#define ovl OvlVis::instance()
114#define ovlId OvlVis::NETWORK_ID_BASE_OVERLAY
115
116namespace ariba {
117namespace overlay {
118
119class BaseOverlay :
120 public MessageReceiver,
121 public CommunicationEvents,
122 public OverlayStructureEvents,
123 protected Timer {
124
125 use_logging_h( BaseOverlay );
126public:
127 /**
128 * Constructs an empty non-functional base overlay instance
129 */
130 BaseOverlay();
131
132 /**
133 * Destructs a base overlay instance
134 */
135 virtual ~BaseOverlay();
136
137 /**
138 * Starts the Base Overlay instance
139 */
140 void start( BaseCommunication& _basecomm, const NodeID& _nodeid );
141
142 /**
143 * Stops the Base Overlay instance
144 */
145 void stop();
146
147 /**
148 * Starts a link establishment procedure to the specfied node
149 * for the service with id service
150 *
151 * @param node Destination node id
152 * @param service Service to connect to
153 */
154 const LinkID establishLink( const NodeID& node, const ServiceID& service );
155
156 /**
157 * Starts a link establishment procedure to the specified
158 * endpoint and to the specified service
159 */
160 const LinkID establishLink( const EndpointDescriptor& ep, const ServiceID& service );
161
162 /**
163 * TODO
164 */
165 void dropLink( const LinkID& link );
166
167 /**
168 * TODO
169 */
170 seqnum_t sendMessage( const Message* message, const LinkID& link );
171
172 /**
173 * TODO
174 */
175 seqnum_t sendMessage( const Message* message, const NodeID& node, const ServiceID& service );
176
177 /**
178 * Send out a message to all nodes that are known in the overlay structure.
179 * Depending on the structure of the overlay, this can be very different.
180 */
181 void broadcastMessage( Message* message, const ServiceID& service );
182
183 /**
184 * Get a list of overlay neighboring nodes.
185 */
186 vector<NodeID> getOverlayNeighbors() const;
187
188 /**
189 * Returns the end-point descriptor of a link.
190 *
191 * @param link the link id of the requested end-point
192 * @return The end-point descriptor of the link's end-point
193 */
194 const EndpointDescriptor& getEndpointDescriptor( const LinkID& link = LinkID::UNSPECIFIED ) const;
195
196 /**
197 * TODO
198 */
199 const EndpointDescriptor& getEndpointDescriptor( const NodeID& node ) const;
200
201 /**
202 * TODO
203 */
204 void bind(CommunicationListener* listener, const ServiceID& sid);
205
206 /**
207 * TODO
208 */
209 void unbind(CommunicationListener* listener, const ServiceID& sid);
210
211 /**
212 * TODO
213 */
214 void bind(NodeListener* listener);
215
216 /**
217 * TODO
218 */
219 void unbind(NodeListener* listener);
220
221 /**
222 * Returns the own nodeID or the NodeID of the specified link
223 *
224 * @param lid The link identifier
225 * @return The NodeID of the link
226 */
227 const NodeID& getNodeID( const LinkID& lid = LinkID::UNSPECIFIED ) const ;
228
229 /**
230 * TODO
231 */
232 void joinSpoVNet( const SpoVNetID& id, const EndpointDescriptor& bootstrapEp );
233
234 /**
235 * TODO
236 */
237 void createSpoVNet(
238 const SpoVNetID& id,
239 const OverlayParameterSet& param = OverlayParameterSet::DEFAULT,
240 const SecurityParameterSet& sec = SecurityParameterSet::DEFAULT,
241 const QoSParameterSet& qos = QoSParameterSet::DEFAULT
242 );
243
244 /**
245 * TODO
246 */
247 void leaveSpoVNet();
248
249protected:
250
251 /**
252 * TODO
253 */
254 virtual void onLinkUp( const LinkID& id, const NetworkLocator* local, const NetworkLocator* remote );
255
256 /**
257 * TODO
258 */
259 virtual void onLinkDown( const LinkID& id, const NetworkLocator* local, const NetworkLocator* remote );
260
261 virtual void onLinkChanged( const LinkID& id, const NetworkLocator* oldlocal, const NetworkLocator* newlocal, const NetworkLocator* oldremote, const NetworkLocator* newremote );
262
263 /**
264 * TODO
265 */
266 virtual void onLinkFail( const LinkID& id, const NetworkLocator* local, const NetworkLocator* remote );
267
268 /**
269 * TODO
270 */
271 virtual void onLinkQoSChanged( const LinkID& id, const NetworkLocator* local, const NetworkLocator* remote, const QoSParameterSet& qos );
272
273 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
274 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
275 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
276
277 /**
278 * TODO
279 */
280 virtual bool receiveMessage( const Message* message, const LinkID& link, const NodeID& ); // nodeid is not valid in this case!
281
282 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
283 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
284 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
285
286 /**
287 * see OverlayStructureEvents.h, called from specific OverlayInterface class
288 */
289 virtual void incomingRouteMessage( Message* msg );
290
291 /**
292 * see OverlayStructureEvents.h, called from specific OverlayInterface class
293 */
294 virtual void onNodeJoin( const NodeID& node );
295
296
297 /**
298 * TODO, for timer events
299 */
300 virtual void eventFunction();
301
302private:
303 /**
304 * The BaseCommunication the BaseOverlay
305 * communicates over
306 */
307 BaseCommunication* bc;
308
309 /**
310 * The nodeid of this BaseOverlay instance.
311 */
312 NodeID nodeId;
313
314 /**
315 * The SpoVNetID that we are joined to
316 * or that we have created.
317 */
318 SpoVNetID spovnetId;
319
320 /**
321 * TODO
322 */
323 Demultiplexer<CommunicationListener*, ServiceID> communicationListeners;
324
325 /**
326 * TODO
327 */
328 typedef vector<NodeListener*> NodeListenerVector;
329
330 /**
331 * TODO
332 */
333 NodeListenerVector nodeListeners;
334
335 /**
336 * The abstract overlay interface that implements
337 * the overlay specific functionality.
338 */
339 OverlayInterface* overlayInterface;
340
341 /**
342 * The special link to the Initiator of the SpoVNet
343 * or LinkID::UNDEFINED if we are the Initiator
344 */
345 LinkID initiatorLink;
346
347 /**
348 * The state of the BaseOverlay
349 */
350 typedef enum _BaseOverlayState {
351 BaseOverlayStateInvalid = 0,
352 BaseOverlayStateInitiator = 1,
353 BaseOverlayStateJoinInitiated = 2,
354 BaseOverlayStateCompleted = 3,
355 } BaseOverlayState;
356
357 /**
358 * TODO
359 */
360 BaseOverlayState state;
361
362 /**
363 * The initiator node
364 */
365 NodeID spovnetInitiator;
366
367 /**
368 * OvlVis
369 */
370 NodeID min, max;
371 NodeID succ, pred;
372 void updateOvlVis( const NodeID& node );
373
374 /**
375 * Link management
376 */
377 class LinkItem {
378 public:
379 static const LinkItem UNSPECIFIED;
380
381 LinkItem( const LinkID& _link, const NodeID& _node,
382 const ServiceID& _service, CommunicationListener* _interface )
383 : link( _link ), node( _node ), service( _service ), interface( _interface ),
384 autolink( false ), lastuse( time(NULL) ) {
385 }
386
387 // general information about the link
388
389 const LinkID link;
390 NodeID node;
391 ServiceID service;
392 CommunicationListener* interface;
393
394 // information needed for auto links
395
396 void markused(){
397 lastuse = time(NULL);
398 }
399
400 bool autolink;
401 time_t lastuse;
402 };
403
404 typedef map<const LinkID, LinkItem> LinkMapping;
405 typedef pair<const LinkID,LinkItem> LinkPair;
406 LinkMapping linkMapping;
407
408
409 /**
410 * nodes with pending joines. TODO: should be cleaned every
411 * some seconds, add timestamps to each, and check on occasion
412 */
413 typedef vector<NodeID> JoiningNodes;
414 JoiningNodes joiningNodes;
415
416};
417
418}} // namespace ariba, overlay
419
420#endif /*BASEOVERLAY_H_*/
Note: See TracBrowser for help on using the repository browser.