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

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

-temporärer commit, sorry kompiliert nicht :( muss aber die änderungen auf die andere maschine kriegen, ist in ca1h gefixt.

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