source: source/ariba/Node.cpp@ 2482

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

-added missing port and ip parameters to join

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 ariba_mod.ip_addr, ariba_mod.tcp_port);
145}
146
147//TODO: Implement error handling: no bootstrap node available
148void 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
165void Node::leave() {
166 ariba_mod.underlay_abs->leaveSpoVNet( context );
167 context = NULL;
168}
169
170const SpoVNetProperties& Node::getSpoVNetProperties() const {
171 return SpoVNetProperties::DEFAULT;
172}
173
174const SpoVNetID& Node::getSpoVNetId() const {
175 return spovnetId;
176}
177
178const NodeID& Node::getNodeId(const LinkID& lid) const {
179 return nodeId;
180}
181
182NodeID Node::generateNodeId(const Name& name) const {
183 if (name == Name::UNSPECIFIED) return Name::random().toNodeId();
184 else return name.toNodeId();
185}
186
187LinkID Node::establishLink(const NodeID& nid, const ServiceID& sid,
188 const LinkProperties& req, const DataMessage& msg) {
189 return context->getOverlay().establishLink(nid, sid);
190}
191
192void Node::dropLink(const LinkID& lnk) {
193 context->getOverlay().dropLink(lnk);
194}
195
196seqnum_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
201seqnum_t Node::sendMessage(const DataMessage& msg, const LinkID& lnk) {
202 return context->getOverlay().sendMessage((Message*) msg, lnk);
203}
204
205void Node::sendBroadcastMessage(const DataMessage& msg, const ServiceID& sid) {
206 return context->getOverlay().broadcastMessage((Message*)msg, sid);
207}
208
209void Node::bind(NodeListener* listener) {
210 context->getOverlay().bind(new ServiceInterfaceWrapper(listener),
211 Node::anonymousService);
212}
213
214void Node::unbind(NodeListener* listener) {
215 delete context->getOverlay().unbind(Node::anonymousService);
216}
217
218void Node::bind(CommunicationListener* listener, const ServiceID& sid) {
219 context->getOverlay().bind(new ServiceInterfaceWrapper(listener), sid);
220}
221
222void 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
237void Node::initialize() {
238
239}
240
241// @see Module.h
242void Node::start() {
243
244}
245
246// @see Module.h
247void Node::stop() {
248
249}
250
251// @see Module.h
252string Node::getName() const {
253
254}
255
256// @see Module.h
257void Node::setProperty(string key, string value) {
258
259}
260
261// @see Module.h
262const string Node::getProperty(string key) const {
263
264}
265
266// @see Module.h
267const vector<string> Node::getProperties() const {
268
269}
270
271} // namespace ariba
Note: See TracBrowser for help on using the repository browser.