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

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

-einige fixes im ablauf des neuen interface
-einige fehlende funktionalität implementiert

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