close Warning: Can't use blame annotator:
No changeset 2293 in the repository

source: source/ariba/Node.cpp@ 2455

Last change on this file since 2455 was 2455, checked in by mies, 15 years ago

fixed bugs concerning bootstrap

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