An Overlay-based
Virtual Network Substrate
SpoVNet

source: source/ariba/Node.cpp @ 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: 7.4 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 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
48using ariba::communication::EndpointDescriptor;
49using ariba::interface::UnderlayAbstraction;
50
51namespace ariba {
52
53class ServiceInterfaceWrapper: public interface::ServiceInterface {
54private:
55        NodeListener* nodeListener;
56        CommunicationListener* commListener;
57public:
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
70protected:
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
130ServiceID Node::anonymousService = ServiceID(0xFF00);
131
132Node::Node(AribaModule& ariba_mod, const Name& node_name) :
133        ariba_mod(ariba_mod), name(node_name), context(NULL) {
134}
135
136Node::~Node() {
137}
138
139void 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}
145
146//TODO: Implement error handling: no bootstrap node available
147void Node::initiate(const Name& vnetname, const SpoVNetProperties& parm) {
148        utility::OverlayParameterSet ovrpset =
149                        (utility::OverlayParameterSet::_OverlayStructure) parm.getBaseOverlayType();
150
151        spovnetId = vnetname.toSpoVNetId();
152        nodeId = generateNodeId(name);
153
154        this->context = ariba_mod.underlay_abs->createSpoVNet(spovnetId, nodeId,
155                                                        ariba_mod.ip_addr, ariba_mod.tcp_port);
156        ariba_mod.addBootstrapNode(vnetname,
157                new EndpointDescriptor(this->context->getBaseCommunication().getEndpointDescriptor()));
158}
159
160void Node::leave() {
161        ariba_mod.underlay_abs->leaveSpoVNet( context );
162        context = NULL;
163}
164
165const SpoVNetProperties& Node::getSpoVNetProperties() const {
166        return SpoVNetProperties::DEFAULT;
167}
168
169const SpoVNetID& Node::getSpoVNetId() const {
170        return spovnetId;
171}
172
173const NodeID& Node::getNodeId(const LinkID& lid) const {
174        return nodeId;
175}
176
177NodeID Node::generateNodeId(const Name& name) const {
178        if (name == Name::UNSPECIFIED) return Name::random().toNodeId();
179        else return name.toNodeId();
180}
181
182LinkID Node::establishLink(const NodeID& nid, const ServiceID& sid,
183                const LinkProperties& req, const DataMessage& msg) {
184        return context->getOverlay().establishLink(nid, sid);
185}
186
187void Node::dropLink(const LinkID& lnk) {
188        context->getOverlay().dropLink(lnk);
189}
190
191seqnum_t Node::sendMessage(const DataMessage& msg, const NodeID& nid,
192                const ServiceID& sid, const LinkProperties& req) {
193        return context->getOverlay().sendMessage((Message*) msg, nid, sid);
194}
195
196seqnum_t Node::sendMessage(const DataMessage& msg, const LinkID& lnk) {
197        return context->getOverlay().sendMessage((Message*) msg, lnk);
198}
199
200void Node::sendBroadcastMessage(const DataMessage& msg, const ServiceID& sid) {
201        return context->getOverlay().broadcastMessage((Message*)msg, sid);
202}
203
204void Node::bind(NodeListener* listener) {
205        context->getOverlay().bind(new ServiceInterfaceWrapper(listener),
206                        Node::anonymousService);
207}
208
209void Node::unbind(NodeListener* listener) {
210        delete context->getOverlay().unbind(Node::anonymousService);
211}
212
213void Node::bind(CommunicationListener* listener, const ServiceID& sid) {
214        context->getOverlay().bind(new ServiceInterfaceWrapper(listener), sid);
215}
216
217void Node::unbind(CommunicationListener* listener, const ServiceID& sid) {
218        delete context->getOverlay().unbind(sid);
219}
220
221// service directory
222/*
223 void Node::put(const Identifier<>& key, Message* value) {
224 }
225
226 void Node::get(const Identifier<>& key) {
227
228 }
229 */
230
231// @see Module.h
232void Node::initialize() {
233
234}
235
236// @see Module.h
237void Node::start() {
238
239}
240
241// @see Module.h
242void Node::stop() {
243
244}
245
246// @see Module.h
247string Node::getName() const {
248
249}
250
251// @see Module.h
252void Node::setProperty(string key, string value) {
253
254}
255
256// @see Module.h
257const string Node::getProperty(string key) const {
258
259}
260
261// @see Module.h
262const vector<string> Node::getProperties() const {
263
264}
265
266} // namespace ariba
Note: See TracBrowser for help on using the repository browser.