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

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

-autolinks impl. (funktioniert noch nicht komplett, macht aber im moment nichts schlechter)
-einige fixes im ablauf etc.

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