| 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 INSTITUTE OF TELEMATICS 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 | #include "Node.h"
|
---|
| 40 |
|
---|
| 41 | #include "ariba/overlay/BaseOverlay.h"
|
---|
| 42 | #include "ariba/utility/types/OverlayParameterSet.h"
|
---|
| 43 | #include "ariba/interface/AribaContext.h"
|
---|
| 44 | #include "ariba/interface/ServiceInterface.h"
|
---|
| 45 | #include "ariba/interface/UnderlayAbstraction.h"
|
---|
| 46 | #include "ariba/communication/EndpointDescriptor.h"
|
---|
| 47 |
|
---|
| 48 | using ariba::communication::EndpointDescriptor;
|
---|
| 49 | using ariba::interface::UnderlayAbstraction;
|
---|
| 50 |
|
---|
| 51 | namespace ariba {
|
---|
| 52 |
|
---|
| 53 | class ServiceInterfaceWrapper: public interface::ServiceInterface {
|
---|
| 54 | private:
|
---|
| 55 | NodeListener* nodeListener;
|
---|
| 56 | CommunicationListener* commListener;
|
---|
| 57 | public:
|
---|
| 58 | ServiceInterfaceWrapper(NodeListener* listener) :
|
---|
| 59 | nodeListener(listener), commListener(NULL) {
|
---|
| 60 |
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | ServiceInterfaceWrapper(CommunicationListener* listener) :
|
---|
| 64 | nodeListener(NULL), commListener(listener) {
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | ~ServiceInterfaceWrapper() {
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | protected:
|
---|
| 71 | void onOverlayCreate(const SpoVNetID& id) {
|
---|
| 72 |
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | void onOverlayDestroy(const SpoVNetID& id) {
|
---|
| 76 |
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | bool isJoinAllowed(const NodeID& nodeid, const SpoVNetID& spovnetid) {
|
---|
| 80 | return true;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | void onNodeJoin(const NodeID& nodeid, const SpoVNetID& spovnetid) {
|
---|
| 84 | // not handled
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | void onNodeLeave(const NodeID& id, const SpoVNetID& spovnetid) {
|
---|
| 88 | // not handled
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | void onJoinSuccess(const SpoVNetID& spovnetid) {
|
---|
| 92 | if (nodeListener != NULL) nodeListener->onJoinCompleted(spovnetid);
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | void onJoinFail(const SpoVNetID& spovnetid) {
|
---|
| 96 | if (nodeListener != NULL) nodeListener->onJoinFailed(spovnetid);
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | void onLinkUp(const LinkID& link, const NodeID& local, const NodeID& remote) {
|
---|
| 100 | if (commListener != NULL) commListener->onLinkUp(link, remote);
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | void onLinkDown(const LinkID& link, const NodeID& local,
|
---|
| 104 | const NodeID& remote) {
|
---|
| 105 | if (commListener != NULL) commListener->onLinkDown(link, remote);
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | void onLinkChanged(const LinkID& link, const NodeID& local,
|
---|
| 109 | const NodeID& remote) {
|
---|
| 110 | if (commListener != NULL) commListener->onLinkChanged(link, remote);
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | void onLinkFail(const LinkID& id, const NodeID& local, const NodeID& remote) {
|
---|
| 114 | if (commListener != NULL) commListener->onLinkFail(id, remote);
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | void onLinkQoSChanged(const LinkID& id, const NodeID& local,
|
---|
| 118 | const NodeID& remote, const QoSParameterSet& qos) {
|
---|
| 119 | if (commListener != NULL) commListener->onLinkQoSChanged(id, remote,
|
---|
| 120 | LinkProperties::DEFAULT);
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | bool receiveMessage(const Message* message, const LinkID& link,
|
---|
| 124 | const NodeID& node) {
|
---|
| 125 | if (commListener != NULL) commListener->onMessage(
|
---|
| 126 | const_cast<Message*>(message), node, link);
|
---|
| 127 | }
|
---|
| 128 | };
|
---|
| 129 |
|
---|
| 130 | ServiceID Node::anonymousService = ServiceID(0xFF00);
|
---|
| 131 |
|
---|
| 132 | Node::Node(AribaModule& ariba_mod, const Name& node_name) :
|
---|
| 133 | ariba_mod(ariba_mod), name(node_name), context(NULL) {
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | Node::~Node() {
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | void Node::join(const Name& vnetname) {
|
---|
| 140 | spovnetId = vnetname.toSpoVNetId();
|
---|
| 141 | nodeId = generateNodeId(name);
|
---|
| 142 | this->context = ariba_mod.underlay_abs->joinSpoVNet(spovnetId,
|
---|
| 143 | *ariba_mod.getBootstrapNode(vnetname), nodeId,
|
---|
| 144 | ariba_mod.ip_addr, ariba_mod.tcp_port);
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | //TODO: Implement error handling: no bootstrap node available
|
---|
| 148 | void Node::initiate(const Name& vnetname, const SpoVNetProperties& parm) {
|
---|
| 149 | utility::OverlayParameterSet ovrpset =
|
---|
| 150 | (utility::OverlayParameterSet::_OverlayStructure)
|
---|
| 151 | parm.getBaseOverlayType();
|
---|
| 152 |
|
---|
| 153 | spovnetId = vnetname.toSpoVNetId();
|
---|
| 154 | nodeId = generateNodeId(name);
|
---|
| 155 |
|
---|
| 156 | this->context = ariba_mod.underlay_abs->createSpoVNet(
|
---|
| 157 | spovnetId, nodeId, ariba_mod.ip_addr,
|
---|
| 158 | ariba_mod.tcp_port);
|
---|
| 159 |
|
---|
| 160 | ariba_mod.addBootstrapNode(vnetname,
|
---|
| 161 | new EndpointDescriptor(this->context->
|
---|
| 162 | getBaseCommunication().getEndpointDescriptor()));
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | void Node::leave() {
|
---|
| 166 | ariba_mod.underlay_abs->leaveSpoVNet( context );
|
---|
| 167 | context = NULL;
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | const SpoVNetProperties& Node::getSpoVNetProperties() const {
|
---|
| 171 | return SpoVNetProperties::DEFAULT;
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | const SpoVNetID& Node::getSpoVNetId() const {
|
---|
| 175 | return spovnetId;
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | const NodeID& Node::getNodeId(const LinkID& lid) const {
|
---|
| 179 | return nodeId;
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | NodeID Node::generateNodeId(const Name& name) const {
|
---|
| 183 | if (name == Name::UNSPECIFIED) return Name::random().toNodeId();
|
---|
| 184 | else return name.toNodeId();
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | LinkID Node::establishLink(const NodeID& nid, const ServiceID& sid,
|
---|
| 188 | const LinkProperties& req, const DataMessage& msg) {
|
---|
| 189 | return context->getOverlay().establishLink(nid, sid);
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | void Node::dropLink(const LinkID& lnk) {
|
---|
| 193 | context->getOverlay().dropLink(lnk);
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 | seqnum_t Node::sendMessage(const DataMessage& msg, const NodeID& nid,
|
---|
| 197 | const ServiceID& sid, const LinkProperties& req) {
|
---|
| 198 | return context->getOverlay().sendMessage((Message*) msg, nid, sid);
|
---|
| 199 | }
|
---|
| 200 |
|
---|
| 201 | seqnum_t Node::sendMessage(const DataMessage& msg, const LinkID& lnk) {
|
---|
| 202 | return context->getOverlay().sendMessage((Message*) msg, lnk);
|
---|
| 203 | }
|
---|
| 204 |
|
---|
| 205 | void Node::sendBroadcastMessage(const DataMessage& msg, const ServiceID& sid) {
|
---|
| 206 | return context->getOverlay().broadcastMessage((Message*)msg, sid);
|
---|
| 207 | }
|
---|
| 208 |
|
---|
| 209 | void Node::bind(NodeListener* listener) {
|
---|
| 210 | context->getOverlay().bind(new ServiceInterfaceWrapper(listener),
|
---|
| 211 | Node::anonymousService);
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | void Node::unbind(NodeListener* listener) {
|
---|
| 215 | delete context->getOverlay().unbind(Node::anonymousService);
|
---|
| 216 | }
|
---|
| 217 |
|
---|
| 218 | void Node::bind(CommunicationListener* listener, const ServiceID& sid) {
|
---|
| 219 | context->getOverlay().bind(new ServiceInterfaceWrapper(listener), sid);
|
---|
| 220 | }
|
---|
| 221 |
|
---|
| 222 | void Node::unbind(CommunicationListener* listener, const ServiceID& sid) {
|
---|
| 223 | delete context->getOverlay().unbind(sid);
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 | // service directory
|
---|
| 227 | /*
|
---|
| 228 | void Node::put(const Identifier<>& key, Message* value) {
|
---|
| 229 | }
|
---|
| 230 |
|
---|
| 231 | void Node::get(const Identifier<>& key) {
|
---|
| 232 |
|
---|
| 233 | }
|
---|
| 234 | */
|
---|
| 235 |
|
---|
| 236 | // @see Module.h
|
---|
| 237 | void Node::initialize() {
|
---|
| 238 |
|
---|
| 239 | }
|
---|
| 240 |
|
---|
| 241 | // @see Module.h
|
---|
| 242 | void Node::start() {
|
---|
| 243 |
|
---|
| 244 | }
|
---|
| 245 |
|
---|
| 246 | // @see Module.h
|
---|
| 247 | void Node::stop() {
|
---|
| 248 |
|
---|
| 249 | }
|
---|
| 250 |
|
---|
| 251 | // @see Module.h
|
---|
| 252 | string Node::getName() const {
|
---|
| 253 |
|
---|
| 254 | }
|
---|
| 255 |
|
---|
| 256 | // @see Module.h
|
---|
| 257 | void Node::setProperty(string key, string value) {
|
---|
| 258 |
|
---|
| 259 | }
|
---|
| 260 |
|
---|
| 261 | // @see Module.h
|
---|
| 262 | const string Node::getProperty(string key) const {
|
---|
| 263 |
|
---|
| 264 | }
|
---|
| 265 |
|
---|
| 266 | // @see Module.h
|
---|
| 267 | const vector<string> Node::getProperties() const {
|
---|
| 268 |
|
---|
| 269 | }
|
---|
| 270 |
|
---|
| 271 | } // namespace ariba
|
---|