| 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 __OVERLAY_INTERFACE_H | 
|---|
| 40 | #define __OVERLAY_INTERFACE_H | 
|---|
| 41 |  | 
|---|
| 42 | #include "ariba/CommunicationListener.h" | 
|---|
| 43 | #include "ariba/communication/EndpointDescriptor.h" | 
|---|
| 44 | #include "ariba/overlay/modules/OverlayStructureEvents.h" | 
|---|
| 45 | #include "ariba/utility/types/NodeID.h" | 
|---|
| 46 | #include "ariba/utility/types/ServiceID.h" | 
|---|
| 47 | #include "ariba/utility/types/OverlayParameterSet.h" | 
|---|
| 48 |  | 
|---|
| 49 | using ariba::CommunicationListener; | 
|---|
| 50 | using ariba::communication::EndpointDescriptor; | 
|---|
| 51 | using ariba::overlay::OverlayStructureEvents; | 
|---|
| 52 | using ariba::utility::NodeID; | 
|---|
| 53 | using ariba::utility::ServiceID; | 
|---|
| 54 | using ariba::utility::OverlayParameterSet; | 
|---|
| 55 |  | 
|---|
| 56 | namespace ariba { | 
|---|
| 57 | namespace overlay { | 
|---|
| 58 |  | 
|---|
| 59 | class BaseOverlay; | 
|---|
| 60 |  | 
|---|
| 61 | /** | 
|---|
| 62 | * This class declares an interface for an structured overlay. | 
|---|
| 63 | */ | 
|---|
| 64 | class OverlayInterface: public CommunicationListener { | 
|---|
| 65 | friend class BaseOverlay; | 
|---|
| 66 |  | 
|---|
| 67 | public: | 
|---|
| 68 | /** | 
|---|
| 69 | * A node list | 
|---|
| 70 | */ | 
|---|
| 71 | typedef vector<NodeID> NodeList; | 
|---|
| 72 |  | 
|---|
| 73 | /** | 
|---|
| 74 | * Constructs a new overlay. | 
|---|
| 75 | */ | 
|---|
| 76 | OverlayInterface( | 
|---|
| 77 | BaseOverlay& _baseoverlay, | 
|---|
| 78 | const NodeID& _nodeid, | 
|---|
| 79 | OverlayStructureEvents* _eventsReceiver, | 
|---|
| 80 | OverlayParameterSet _parameters | 
|---|
| 81 | ); | 
|---|
| 82 |  | 
|---|
| 83 | /** | 
|---|
| 84 | * Destrcuts the overlay. | 
|---|
| 85 | */ | 
|---|
| 86 | virtual ~OverlayInterface(); | 
|---|
| 87 |  | 
|---|
| 88 | /** | 
|---|
| 89 | * Creates the overlay. | 
|---|
| 90 | */ | 
|---|
| 91 | virtual void createOverlay() = 0; | 
|---|
| 92 |  | 
|---|
| 93 | /** | 
|---|
| 94 | * Destroys the overlay. | 
|---|
| 95 | */ | 
|---|
| 96 | virtual void deleteOverlay() = 0; | 
|---|
| 97 |  | 
|---|
| 98 | /** | 
|---|
| 99 | * Joins the overlay. Starts integration and stabilization of the overlay | 
|---|
| 100 | * Node. | 
|---|
| 101 | * | 
|---|
| 102 | * @param bootstrap The bootstrap end-point descriptor or the default | 
|---|
| 103 | *    end-point, if this node is the initiator | 
|---|
| 104 | */ | 
|---|
| 105 | virtual void joinOverlay(const EndpointDescriptor& bootstrap = | 
|---|
| 106 | EndpointDescriptor::UNSPECIFIED ) = 0; | 
|---|
| 107 |  | 
|---|
| 108 | /** | 
|---|
| 109 | * Leaves the overlay gracefully. | 
|---|
| 110 | */ | 
|---|
| 111 | virtual void leaveOverlay() = 0; | 
|---|
| 112 |  | 
|---|
| 113 | /** | 
|---|
| 114 | * Resolves a overlay neighbor. | 
|---|
| 115 | * | 
|---|
| 116 | * @param node The node to resolve | 
|---|
| 117 | * @return Endpoint descriptor of local neighbor or UNSPECIFIED | 
|---|
| 118 | */ | 
|---|
| 119 | virtual const EndpointDescriptor& resolveNode(const NodeID& node) = 0; | 
|---|
| 120 |  | 
|---|
| 121 | /** | 
|---|
| 122 | * Routes a message to a given node by using overlay routing. | 
|---|
| 123 | * | 
|---|
| 124 | * @param destnode The destination node. | 
|---|
| 125 | * @param msg The message to be routed. | 
|---|
| 126 | */ | 
|---|
| 127 | virtual void routeMessage(const NodeID& destnode, Message* msg) = 0; | 
|---|
| 128 |  | 
|---|
| 129 | /** | 
|---|
| 130 | * Returns the nodes known to this overlay. | 
|---|
| 131 | * | 
|---|
| 132 | * Usually this are the direct neighbors in the overlay structure. | 
|---|
| 133 | * For instance, Chord would return his predecessor, successor and finger | 
|---|
| 134 | * nodes. On the other hand OneHop would likely return all participating | 
|---|
| 135 | * nodes in the overlay. | 
|---|
| 136 | * | 
|---|
| 137 | * @return The list of all known nodes | 
|---|
| 138 | */ | 
|---|
| 139 | virtual NodeList getKnownNodes() const = 0; | 
|---|
| 140 |  | 
|---|
| 141 | //--- functions from CommunicationListener that we _can_ use as overlay --- | 
|---|
| 142 |  | 
|---|
| 143 | /// @see CommunicationListener | 
|---|
| 144 | virtual void onLinkUp(const LinkID& lnk, const NodeID& remote); | 
|---|
| 145 | /// @see CommunicationListener | 
|---|
| 146 | virtual void onLinkDown(const LinkID& lnk, const NodeID& remote); | 
|---|
| 147 | /// @see CommunicationListener | 
|---|
| 148 | virtual void onLinkChanged(const LinkID& lnk, const NodeID& remote); | 
|---|
| 149 | /// @see CommunicationListener | 
|---|
| 150 | virtual void onLinkFail(const LinkID& lnk, const NodeID& remote); | 
|---|
| 151 | /// @see CommunicationListener | 
|---|
| 152 | virtual void onLinkQoSChanged(const LinkID& lnk, const NodeID& remote, | 
|---|
| 153 | const LinkProperties& prop); | 
|---|
| 154 | /// @see CommunicationListener | 
|---|
| 155 | virtual bool onLinkRequest(const NodeID& remote, const DataMessage& msg); | 
|---|
| 156 | /// @see CommunicationListener | 
|---|
| 157 | virtual void onMessage(const DataMessage& msg, const NodeID& remote, | 
|---|
| 158 | const LinkID& lnk = LinkID::UNSPECIFIED); | 
|---|
| 159 |  | 
|---|
| 160 |  | 
|---|
| 161 | const OverlayParameterSet& getParameters() const; | 
|---|
| 162 |  | 
|---|
| 163 | protected: | 
|---|
| 164 |  | 
|---|
| 165 | /// Reference to an active base overlay | 
|---|
| 166 | BaseOverlay& baseoverlay; | 
|---|
| 167 |  | 
|---|
| 168 | /// The parameters of the overlay structure | 
|---|
| 169 | OverlayParameterSet parameters; | 
|---|
| 170 |  | 
|---|
| 171 | /// The node identifier to use with this overlay | 
|---|
| 172 | const NodeID& nodeid; | 
|---|
| 173 |  | 
|---|
| 174 | /// The listener used to inform about overlay structure changes | 
|---|
| 175 | OverlayStructureEvents* eventsReceiver; | 
|---|
| 176 |  | 
|---|
| 177 | /// The service identifer of this overlay | 
|---|
| 178 | static ServiceID OVERLAY_SERVICE_ID; | 
|---|
| 179 | }; | 
|---|
| 180 |  | 
|---|
| 181 | }} // namespace ariba, overlay | 
|---|
| 182 |  | 
|---|
| 183 | #endif // __OVERLAY_INTERFACE_H | 
|---|