source: source/ariba/Node.cpp@ 2454

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

fixed some bugs

File size: 7.1 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
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(name), nodeId);
140}
141
142void Node::initiate(const Name& vnetname, const SpoVNetProperties& parm) {
143 utility::OverlayParameterSet
144 ovrpset =
145 (utility::OverlayParameterSet::_OverlayStructure) parm.getBaseOverlayType();
146 spovnetId = vnetname.toSpoVNetId();
147 nodeId = generateNodeId(name);
148 this->context = ariba_mod.underlay_abs->createSpoVNet(spovnetId, nodeId,
149 ariba_mod.ip_addr, ariba_mod.tcp_port);
150 ariba_mod.addBootstrapNode(vnetname,
151 new EndpointDescriptor(this->context->getBaseCommunication().getEndpointDescriptor()));
152}
153
154void Node::leave() {
155 // not implemeted yet.
156}
157
158void Node::bind(NodeListener* listener) {
159 this->context->getOverlay().bind(new ServiceInterfaceWrapper(listener),
160 Node::anonymousService);
161}
162
163void Node::unbind(NodeListener* listener) {
164 // TODO: allow unbinding
165}
166
167const SpoVNetProperties& Node::getSpoVNetProperties() const {
168 return SpoVNetProperties::DEFAULT;
169}
170
171const SpoVNetID& Node::getSpoVNetId() const {
172 return SpoVNetID::UNSPECIFIED;
173}
174
175const NodeID& Node::getNodeId(const LinkID& lid) const {
176 return NodeID::UNSPECIFIED;
177}
178
179NodeID Node::generateNodeId(const Name& name) const {
180 if (name == Name::UNSPECIFIED) return Name::random().toNodeId();
181 else return name.toNodeId();
182}
183
184LinkID Node::establishLink(const NodeID& nid, const ServiceID& sid,
185 const LinkProperties& req, const DataMessage& msg) {
186 return context->getOverlay().establishLink(nid, sid);
187}
188
189void Node::dropLink(const LinkID& lnk) {
190 context->getOverlay().dropLink(lnk);
191}
192
193seqnum_t Node::sendMessage(const DataMessage& msg, const NodeID& nid,
194 const ServiceID& sid, const LinkProperties& req) {
195 return context->getOverlay().sendMessage((Message*) msg, nid, sid);
196}
197
198seqnum_t Node::sendMessage(const DataMessage& msg, const LinkID& lnk) {
199 return context->getOverlay().sendMessage((Message*) msg, lnk);
200}
201
202void Node::bind(CommunicationListener* listener, const ServiceID& sid) {
203 this->context->getOverlay().bind(new ServiceInterfaceWrapper(listener), sid);
204}
205
206void Node::unbind(CommunicationListener* listener, const ServiceID& sid) {
207 // TODO
208}
209
210// service directory
211/*
212 void Node::put(const Identifier<>& key, Message* value) {
213 }
214
215 void Node::get(const Identifier<>& key) {
216
217 }
218 */
219
220// @see Module.h
221void Node::initialize() {
222
223}
224
225// @see Module.h
226void Node::start() {
227
228}
229
230// @see Module.h
231void Node::stop() {
232
233}
234
235// @see Module.h
236string Node::getName() const {
237
238}
239
240// @see Module.h
241void Node::setProperty(string key, string value) {
242
243}
244
245// @see Module.h
246const string Node::getProperty(string key) const {
247
248}
249
250// @see Module.h
251const vector<string> Node::getProperties() const {
252
253}
254
255} // namespace ariba
Note: See TracBrowser for help on using the repository browser.