An Overlay-based
Virtual Network Substrate
SpoVNet

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

Last change on this file since 5284 was 5284, checked in by mies, 14 years ago

+ added new transport modules and adapted ariba to them
+ exchange endpoint descriptors an link establishment
+ clean up of base communication
+ link establishment with in the presence of multiple endpoints
+ local discovery for ipv6, ipv4 and bluetooth mac addresses

File size: 13.0 KB
Line 
1// [License]
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// [License]
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 <deque>
49#include <boost/foreach.hpp>
50
51#include "ariba/utility/messages.h"
52#include "ariba/utility/types.h"
53#include "ariba/utility/misc/Helper.h"
54#include "ariba/utility/misc/Demultiplexer.hpp"
55#include "ariba/utility/logging/Logging.h"
56#include "ariba/utility/system/Timer.h"
57
58#include "ariba/communication/EndpointDescriptor.h"
59#include "ariba/communication/BaseCommunication.h"
60#include "ariba/communication/CommunicationEvents.h"
61
62#include "ariba/overlay/modules/OverlayInterface.h"
63#include "ariba/overlay/modules/OverlayFactory.h"
64#include "ariba/overlay/modules/OverlayStructureEvents.h"
65#include "ariba/overlay/OverlayBootstrap.h"
66
67// forward declarations
68namespace ariba {
69  class NodeListener;
70  class CommunicationListener;
71  class SideportListener;
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;
84using std::deque;
85
86// ariba interface
87using ariba::NodeListener;
88using ariba::SideportListener;
89using ariba::CommunicationListener;
90
91// overlay
92using ariba::overlay::OverlayBootstrap;
93
94// communication
95using ariba::communication::EndpointDescriptor;
96using ariba::communication::BaseCommunication;
97using ariba::communication::CommunicationEvents;
98
99// utilities
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
120using namespace ariba::addressing;
121
122class LinkDescriptor;
123
124class BaseOverlay: public MessageReceiver,
125                public CommunicationEvents,
126                public OverlayStructureEvents,
127                protected Timer {
128
129        friend class OneHop;
130        friend class Chord;
131        friend class ariba::SideportListener;
132
133        use_logging_h( BaseOverlay );
134
135public:
136
137        /**
138         * Constructs an empty non-functional base overlay instance
139         */
140        BaseOverlay();
141
142        /**
143         * Destructs a base overlay instance
144         */
145        virtual ~BaseOverlay();
146
147        /**
148         * Starts the Base Overlay instance
149         */
150        void start(BaseCommunication& _basecomm, const NodeID& _nodeid);
151
152        /**
153         * Stops the Base Overlay instance
154         */
155        void stop();
156
157        /**
158         * Starts a link establishment procedure to the specfied node
159         * for the service with id service
160         *
161         * @param node Destination node id
162         * @param service Service to connect to
163         * @param linkid Link identifier to be used with this link
164         */
165        const LinkID establishLink(const NodeID& node, const ServiceID& service,
166                const LinkID& linkid = LinkID::UNSPECIFIED);
167
168        /**
169         * Starts a link establishment procedure to the specified
170         * endpoint and to the specified service. Concurrently it tries to
171         * establish a relay link over the overlay using the nodeid
172         */
173        const LinkID establishLink(const EndpointDescriptor& ep, const NodeID& nodeid,
174                const ServiceID& service, const LinkID& linkid = LinkID::UNSPECIFIED);
175
176        /**
177         * Starts a link establishment procedure to the specified
178         * endpoint and to the specified service
179         */
180        const LinkID establishLink(const EndpointDescriptor& ep,
181                const ServiceID& service, const LinkID& linkid = LinkID::UNSPECIFIED);
182
183        /// drops a link
184        void dropLink(const LinkID& link);
185
186        /// sends a message over an existing link
187        seqnum_t sendMessage(const Message* message, const LinkID& link);
188
189        /// sends a message to a node and a specific service
190        seqnum_t sendMessage(const Message* message, const NodeID& node,
191                const ServiceID& service);
192
193        /**
194         * Send out a message to all nodes that are known in the overlay structure.
195         * Depending on the structure of the overlay, this can be very different.
196         */
197        void broadcastMessage(Message* message, const ServiceID& service);
198
199        /**
200         * Returns the end-point descriptor of a link.
201         *
202         * @param link the link id of the requested end-point
203         * @return The end-point descriptor of the link's end-point
204         */
205        const EndpointDescriptor& getEndpointDescriptor(const LinkID& link =
206                        LinkID::UNSPECIFIED) const;
207
208        /**
209         * Get a list of overlay neighbors.
210         *
211         * @return A list of overlay neighbors.
212         */
213        vector<NodeID> getOverlayNeighbors() const;
214
215        /**
216         * Returns a end-endpoint descriptor of a overlay neighbor.
217         * If the node is not known -- an unspecified endpoint descriptor is
218         * returned.
219         *
220         * @param node The node identifer of a overlay neighbor.
221         * @return The end-point descriptor of the node or unspecified.
222         */
223        const EndpointDescriptor& getEndpointDescriptor(const NodeID& node) const;
224
225        // TODO: Doc
226        bool bind(CommunicationListener* listener, const ServiceID& sid);
227
228        // TODO: Doc
229        bool unbind(CommunicationListener* listener, const ServiceID& sid);
230
231        // TODO: Doc
232        bool bind(NodeListener* listener);
233
234        // TODO: Doc
235        bool unbind(NodeListener* listener);
236
237        // TODO: Doc
238        bool registerSidePort(SideportListener* _sideport);
239
240        // TODO: Doc
241        bool unregisterSidePort(SideportListener* _sideport);
242
243        /**
244         * Returns the own nodeID or the NodeID of the specified link
245         *
246         * @param lid The link identifier
247         * @return The NodeID of the link
248         */
249        const NodeID& getNodeID(const LinkID& lid = LinkID::UNSPECIFIED) const;
250
251        /**
252         * Return all Links for the specified remote nodeid, or all links when
253         * the node id given is set to unspecified
254         *
255         * @param nid The node id to request links for, or unspecified for all links
256         * @return a vector that contains all the link ids requested
257         */
258        vector<LinkID> getLinkIDs(const NodeID& nid = NodeID::UNSPECIFIED) const;
259
260        /**
261         * Join a existing sponaneous virtual network (spovnet).
262         *
263         * @param id A spovnet identifier
264         * @param boot A bootstrap node
265         */
266        void joinSpoVNet(const SpoVNetID& id, const EndpointDescriptor& boot);
267
268        /**
269         * Initiates a new spontaneous virtual network.
270         * This makes this BaseOverlay to the SpoVNet-Initiator.
271         *
272         * @param id The spovnet identifier
273         */
274        void createSpoVNet(const SpoVNetID& id, const OverlayParameterSet& param =
275                        OverlayParameterSet::DEFAULT, const SecurityParameterSet& sec =
276                        SecurityParameterSet::DEFAULT, const QoSParameterSet& qos =
277                        QoSParameterSet::DEFAULT);
278
279        /**
280         * Let the node leave the SpoVNet.
281         */
282        void leaveSpoVNet();
283
284protected:
285
286        /**
287         * @see ariba::communication::CommunicationEvents.h
288         */
289        virtual void onLinkUp(const LinkID& id, const address_v* local,
290                const address_v* remote);
291
292        /**
293         * @see ariba::communication::CommunicationEvents.h
294         */
295        virtual void onLinkDown(const LinkID& id, const address_v* local,
296                const address_v* remote);
297
298        /**
299         * @see ariba::communication::CommunicationEvents.h
300         */
301        virtual void onLinkChanged(const LinkID& id,
302                const address_v* oldlocal, const address_v* newlocal,
303                const address_v* oldremote, const address_v* newremote);
304
305        /**
306         * @see ariba::communication::CommunicationEvents.h
307         */
308        virtual void onLinkFail(const LinkID& id, const address_v* local,
309                const address_v* remote);
310
311        /**
312         * @see ariba::communication::CommunicationEvents.h
313         */
314        virtual void onLinkQoSChanged(const LinkID& id,
315                const address_v* local, const address_v* remote,
316                const QoSParameterSet& qos);
317
318        /**
319         * @see ariba::communication::CommunicationEvents.h
320         */
321        virtual bool onLinkRequest(const LinkID& id, const address_v* local,
322                const address_v* remote);
323
324        /**
325         * Processes a received message from BaseCommunication
326         *
327         * In case of a message routed by the overlay the source identifies
328         * the node the message came from!
329         */
330        virtual bool receiveMessage(const Message* message, const LinkID& link,
331                const NodeID& source = NodeID::UNSPECIFIED);
332
333        //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
334
335        /// handles an incoming message with link descriptor
336        bool handleMessage(const Message* message,
337                const LinkID& boLink, const LinkID& bcLink, const NodeID& remoteNode );
338
339        //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
340        /**
341         * This method is called, when a routed message arrives from the
342         * overlay.
343         *
344         * @see OverlayStructureEvents.h
345         */
346        virtual void incomingRouteMessage(Message* msg,
347                const LinkID& link = LinkID::UNSPECIFIED,
348                const NodeID& source = NodeID::UNSPECIFIED);
349
350        /**
351         * This method is called, when a new node joined the network
352         *
353         * @see OverlayStructureEvents.h
354         */
355        virtual void onNodeJoin(const NodeID& node);
356
357        /**
358         * Timer Event method
359         */
360        virtual void eventFunction();
361
362private:
363
364        /// The state of the BaseOverlay
365        typedef enum _BaseOverlayState {
366                BaseOverlayStateInvalid = 0,
367                BaseOverlayStateInitiator = 1,
368                BaseOverlayStateJoinInitiated = 2,
369                BaseOverlayStateCompleted = 3,
370        } BaseOverlayState;
371
372        BaseOverlayState state; ///< Current Base-Overlay state
373        BaseCommunication* bc;  ///< reference to the base communication
374        NodeID nodeId;          ///< the node id of this node
375        SpoVNetID spovnetId;    ///< the spovnet id of the currently joined overlay
376        LinkID initiatorLink;   ///< the link id of the link to the initiator node
377        NodeID spovnetInitiator;///< The initiator node
378
379        /// the service id communication listeners
380        Demultiplexer<CommunicationListener*, ServiceID> communicationListeners;
381
382        /// the node listeners
383        typedef vector<NodeListener*> NodeListenerVector;
384        NodeListenerVector nodeListeners;
385
386        /// the sideport listener
387        SideportListener* sideport;
388
389        /// the used overlay structure
390        OverlayInterface* overlayInterface;
391
392        /// The link mapping of the node
393        vector<LinkDescriptor*> links;
394        void eraseDescriptor(const LinkID& link, bool communication = false);
395
396        /// returns a link descriptor for the given id
397        LinkDescriptor* getDescriptor(const LinkID& link,
398                        bool communication = false);
399
400        /// returns a link descriptor for the given id
401        const LinkDescriptor* getDescriptor(const LinkID& link,
402                        bool communication = false) const;
403
404        /// returns a auto-link descriptor for the given node and service id
405        LinkDescriptor* getAutoDescriptor(const NodeID& node, const ServiceID& service);
406
407        /// adds a new link descriptor or uses an existing one
408        LinkDescriptor* addDescriptor(const LinkID& link = LinkID::UNSPECIFIED);
409
410        /// returns a direct link relay descriptor to the given relay node
411        LinkDescriptor* getRelayDescriptor( const NodeID& relayNode );
412
413        /// find a proper relay node that is directly connected to this node
414        const NodeID findRelayNode( const NodeID& id );
415
416        /// forwards a message over relays/overlay/directly using link descriptor
417        seqnum_t sendMessage( Message* message, const LinkDescriptor* ld );
418
419        /// creates a link descriptor, applys relay semantics if possible
420        LinkDescriptor* createLinkDescriptor(
421                const NodeID& remoteNode, const ServiceID& service, const LinkID& link_id );
422
423        // map of a link request map a nonce to a LinkID
424        typedef map<const uint32_t, LinkID> PendingLinkMap;
425        PendingLinkMap pendingLinks;
426
427        void showLinkState();
428
429        /**
430         * nodes with pending joines. TODO: should be cleaned every
431         * some seconds, add timestamps to each, and check on occasion
432         */
433        typedef vector<NodeID> JoiningNodes;
434        JoiningNodes joiningNodes;
435
436        int counter;
437
438        /**
439         * Bootstrapper for our spovnet
440         */
441        OverlayBootstrap overlayBootstrap;
442};
443
444}} // namespace ariba, overlay
445
446#endif /*BASEOVERLAY_H_*/
Note: See TracBrowser for help on using the repository browser.