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

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

-mehrere Fixes, Tickets #25 (bind listeners earlier), #21 (better pingpong), #40 (systemqueue misbehavior)

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/interface/ServiceInterface.h"
62
63#include "ariba/overlay/modules/OverlayInterface.h"
64#include "ariba/overlay/modules/OverlayFactory.h"
65#include "ariba/overlay/modules/OverlayStructureEvents.h"
66#include "ariba/overlay/messages/OverlayMsg.h"
67#include "ariba/overlay/messages/JoinRequest.h"
68#include "ariba/overlay/messages/JoinReply.h"
69
70using std::vector;
71using std::list;
72using std::cout;
73using std::map;
74using std::make_pair;
75using std::pair;
76using std::find;
77
78using ariba::communication::EndpointDescriptor;
79using ariba::communication::BaseCommunication;
80using ariba::communication::CommunicationEvents;
81
82using ariba::interface::ServiceInterface;
83
84using ariba::overlay::OverlayMsg;
85using ariba::overlay::JoinRequest;
86using ariba::overlay::JoinReply;
87using ariba::overlay::OverlayInterface;
88using ariba::overlay::OverlayFactory;
89using ariba::overlay::OverlayStructureEvents;
90
91using ariba::utility::NodeID;
92using ariba::utility::SpoVNetID;
93using ariba::utility::LinkID;
94using ariba::utility::Identifier;
95using ariba::utility::ServiceID;
96using ariba::utility::QoSParameterSet;
97using ariba::utility::SecurityParameterSet;
98using ariba::utility::Demultiplexer;
99using ariba::utility::MessageReceiver;
100using ariba::utility::MessageSender;
101using ariba::utility::seqnum_t;
102using ariba::utility::Timer;
103
104#define ovl OvlVis::instance()
105#define ovlId OvlVis::NETWORK_ID_BASE_OVERLAY
106
107// needed for friend decleration
108// in different namespace
109namespace ariba {
110 class Node;
111}
112
113namespace ariba {
114namespace overlay {
115
116class BaseOverlay :
117 public MessageReceiver,
118 public CommunicationEvents,
119 public OverlayStructureEvents,
120 protected Timer {
121
122 use_logging_h( BaseOverlay );
123 friend class ariba::Node;
124
125public:
126
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 *
150 * @param node The node id
151 */
152 const LinkID establishLink( const NodeID& node, const ServiceID& service );
153
154 /**
155 * TODO
156 */
157 const LinkID establishLink( const EndpointDescriptor& ep, const ServiceID& service );
158
159 /**
160 * TODO
161 */
162 void dropLink( const LinkID& link );
163
164 /**
165 * TODO
166 */
167 seqnum_t sendMessage( const Message* message, const LinkID& link );
168
169 /**
170 * TODO
171 */
172 seqnum_t sendMessage( const Message* message, const NodeID& node, const ServiceID& service );
173
174 /**
175 * Send out a message to all nodes that are known in the overlay structure.
176 * Depending on the structure of the overlay, this can be very different.
177 */
178 void broadcastMessage(
179 Message* message,
180 const ServiceID& service
181 );
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 * Registers a receiver.
203 *
204 * @param receiver An implementation of the receiver interface
205 */
206 bool bind( ServiceInterface* service, const ServiceID& sid );
207
208 /**
209 * Unregister a receiver.
210 *
211 * @param sid The service id to unregister
212 */
213 ServiceInterface* unbind( const ServiceID& sid );
214
215 /**
216 * Returns the own nodeID or the NodeID of the specified link
217 *
218 * @param lid The link identifier
219 * @return The NodeID of the link
220 */
221 const NodeID& getNodeID( const LinkID& lid = LinkID::UNSPECIFIED ) const ;
222
223protected:
224
225 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
226 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
227 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
228
229 void joinSpoVNet(
230 const SpoVNetID& id,
231 const EndpointDescriptor& bootstrapEp
232 );
233
234 void createSpoVNet(
235 const SpoVNetID& id,
236 const OverlayParameterSet& param = OverlayParameterSet::DEFAULT,
237 const SecurityParameterSet& sec = SecurityParameterSet::DEFAULT,
238 const QoSParameterSet& qos = QoSParameterSet::DEFAULT
239 );
240
241 void leaveSpoVNet(
242 );
243
244 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
245 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
246 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
247
248 virtual void onLinkUp( const LinkID& id, const NetworkLocator* local, const NetworkLocator* remote );
249
250 virtual void onLinkDown( const LinkID& id, const NetworkLocator* local, const NetworkLocator* remote );
251
252 virtual void onLinkChanged( const LinkID& id, const NetworkLocator* oldlocal, const NetworkLocator* newlocal, const NetworkLocator* oldremote, const NetworkLocator* newremote );
253
254 virtual void onLinkFail( const LinkID& id, const NetworkLocator* local, const NetworkLocator* remote );
255
256 virtual void onLinkQoSChanged( const LinkID& id, const NetworkLocator* local, const NetworkLocator* remote, const QoSParameterSet& qos );
257
258 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
259 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
260 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
261
262 virtual bool receiveMessage( const Message* message, const LinkID& link, const NodeID& ); // nodeid is not valid in this case!
263
264 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
265 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
266 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
267
268 /**
269 * see OverlayStructureEvents.h, called from specific OverlayInterface class
270 */
271 virtual void incomingRouteMessage( Message* msg );
272 virtual void onNodeJoin( const NodeID& node );
273
274 // for timer events
275 virtual void eventFunction();
276
277private:
278
279 /**
280 * The BaseCommunication the BaseOverlay
281 * communicates over
282 */
283 BaseCommunication* bc;
284
285 /**
286 * The nodeid of this BaseOverlay instance.
287 */
288 NodeID nodeId;
289
290 /**
291 * The SpoVNetID that we are joined to
292 * or that we have created.
293 */
294 SpoVNetID spovnetId;
295
296 /**
297 * A demultiplexer that maps listeners to service ids
298 * to deliver upcoming messages to the correct service.
299 */
300 Demultiplexer<ServiceInterface*, ServiceID> listenerMux;
301
302 /**
303 * The abstract overlay interface that implements
304 * the overlay specific functionality.
305 */
306 OverlayInterface* overlayInterface;
307
308 /**
309 * The special link to the Initiator of the SpoVNet
310 * or LinkID::UNDEFINED if we are the Initiator
311 */
312 LinkID initiatorLink;
313
314 /**
315 * The state of the BaseOverlay
316 */
317 typedef enum _BaseOverlayState {
318 BaseOverlayStateInvalid = 0,
319 BaseOverlayStateInitiator = 1,
320 BaseOverlayStateJoinInitiated = 2,
321 BaseOverlayStateCompleted = 3,
322 } BaseOverlayState;
323
324 BaseOverlayState state;
325
326 /**
327 * The initiator node
328 */
329 NodeID spovnetInitiator;
330
331 /**
332 * OvlVis
333 */
334 NodeID min, max;
335 NodeID succ, pred;
336 void updateOvlVis( const NodeID& node );
337
338 /**
339 * Link management
340 */
341 class LinkItem {
342 public:
343 static const LinkItem UNSPECIFIED;
344
345 LinkItem( const LinkID& _link, const NodeID& _node,
346 const ServiceID& _service, ServiceInterface* _interface )
347 : link( _link ), node( _node ), service( _service ), interface( _interface ),
348 autolink( false ), lastuse( time(NULL) ) {
349 }
350
351 // general information about the link
352
353 const LinkID link;
354 NodeID node;
355 ServiceID service;
356 ServiceInterface* interface;
357
358 // information needed for auto links
359
360 void markused(){
361 lastuse = time(NULL);
362 }
363
364 bool autolink;
365 time_t lastuse;
366 };
367
368 typedef map<const LinkID, LinkItem> LinkMapping;
369 typedef pair<const LinkID,LinkItem> LinkPair;
370 LinkMapping linkMapping;
371
372 // nodes with pending joines. TODO: should be cleaned every some seconds
373 // add timestamps to each, and check on occasion
374 typedef vector<NodeID> JoiningNodes;
375 JoiningNodes joiningNodes;
376
377};
378
379}} // namespace ariba, overlay
380
381#endif /*BASEOVERLAY_H_*/
Note: See TracBrowser for help on using the repository browser.