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

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

-some further fixed in the protocols and cleaning the interfaces for stuff we have no functionality yet

File size: 10.8 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 bool bind(CommunicationListener* listener, const ServiceID& sid);
205
206 /**
207 * TODO
208 */
209 bool unbind(CommunicationListener* listener, const ServiceID& sid);
210
211 /**
212 * TODO
213 */
214 bool bind(NodeListener* listener);
215
216 /**
217 * TODO
218 */
219 bool 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 * @see ariba::communication::CommunicationEvents.h
253 */
254 virtual void onLinkUp( const LinkID& id, const NetworkLocator* local, const NetworkLocator* remote );
255
256 /**
257 * @see ariba::communication::CommunicationEvents.h
258 */
259 virtual void onLinkDown( const LinkID& id, const NetworkLocator* local, const NetworkLocator* remote );
260
261 /**
262 * @see ariba::communication::CommunicationEvents.h
263 */
264 virtual void onLinkChanged( const LinkID& id, const NetworkLocator* oldlocal, const NetworkLocator* newlocal, const NetworkLocator* oldremote, const NetworkLocator* newremote );
265
266 /**
267 * @see ariba::communication::CommunicationEvents.h
268 */
269 virtual void onLinkFail( const LinkID& id, const NetworkLocator* local, const NetworkLocator* remote );
270
271 /**
272 * @see ariba::communication::CommunicationEvents.h
273 */
274 virtual void onLinkQoSChanged( const LinkID& id, const NetworkLocator* local, const NetworkLocator* remote, const QoSParameterSet& qos );
275
276 /**
277 * @see ariba::communication::CommunicationEvents.h
278 */
279 virtual bool onLinkRequest( const LinkID& id, const NetworkLocator* local, const NetworkLocator* remote );
280
281 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
282 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
283 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
284
285 /**
286 * TODO
287 */
288 virtual bool receiveMessage( const Message* message, const LinkID& link, const NodeID& ); // nodeid is not valid in this case!
289
290 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
291 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
292 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
293
294 /**
295 * see OverlayStructureEvents.h, called from specific OverlayInterface class
296 */
297 virtual void incomingRouteMessage( Message* msg );
298
299 /**
300 * see OverlayStructureEvents.h, called from specific OverlayInterface class
301 */
302 virtual void onNodeJoin( const NodeID& node );
303
304
305 /**
306 * TODO, for timer events
307 */
308 virtual void eventFunction();
309
310private:
311 /**
312 * The BaseCommunication the BaseOverlay
313 * communicates over
314 */
315 BaseCommunication* bc;
316
317 /**
318 * The nodeid of this BaseOverlay instance.
319 */
320 NodeID nodeId;
321
322 /**
323 * The SpoVNetID that we are joined to
324 * or that we have created.
325 */
326 SpoVNetID spovnetId;
327
328 /**
329 * TODO
330 */
331 Demultiplexer<CommunicationListener*, ServiceID> communicationListeners;
332
333 /**
334 * TODO
335 */
336 typedef vector<NodeListener*> NodeListenerVector;
337
338 /**
339 * TODO
340 */
341 NodeListenerVector nodeListeners;
342
343 /**
344 * The abstract overlay interface that implements
345 * the overlay specific functionality.
346 */
347 OverlayInterface* overlayInterface;
348
349 /**
350 * The special link to the Initiator of the SpoVNet
351 * or LinkID::UNDEFINED if we are the Initiator
352 */
353 LinkID initiatorLink;
354
355 /**
356 * The state of the BaseOverlay
357 */
358 typedef enum _BaseOverlayState {
359 BaseOverlayStateInvalid = 0,
360 BaseOverlayStateInitiator = 1,
361 BaseOverlayStateJoinInitiated = 2,
362 BaseOverlayStateCompleted = 3,
363 } BaseOverlayState;
364
365 /**
366 * TODO
367 */
368 BaseOverlayState state;
369
370 /**
371 * The initiator node
372 */
373 NodeID spovnetInitiator;
374
375 /**
376 * OvlVis
377 */
378 NodeID min, max;
379 NodeID succ, pred;
380 void updateOvlVis( const NodeID& node );
381
382 /**
383 * Link management
384 */
385 class LinkItem {
386 public:
387 static const LinkItem UNSPECIFIED;
388
389 LinkItem( const LinkID& _link, const NodeID& _node,
390 const ServiceID& _service, CommunicationListener* _interface )
391 : link( _link ), node( _node ), service( _service ), interface( _interface ),
392 autolink( false ), lastuse( time(NULL) ) {
393 }
394
395 // general information about the link
396
397 const LinkID link;
398 NodeID node;
399 ServiceID service;
400 CommunicationListener* interface;
401
402 // information needed for auto links
403
404 void markused(){
405 lastuse = time(NULL);
406 }
407
408 bool autolink;
409 time_t lastuse;
410 };
411
412 typedef map<const LinkID, LinkItem> LinkMapping;
413 typedef pair<const LinkID,LinkItem> LinkPair;
414 LinkMapping linkMapping;
415
416
417 /**
418 * nodes with pending joines. TODO: should be cleaned every
419 * some seconds, add timestamps to each, and check on occasion
420 */
421 typedef vector<NodeID> JoiningNodes;
422 JoiningNodes joiningNodes;
423
424};
425
426}} // namespace ariba, overlay
427
428#endif /*BASEOVERLAY_H_*/
Note: See TracBrowser for help on using the repository browser.