source: source/ariba/Node.cpp@ 2410

Last change on this file since 2410 was 2409, checked in by mies, 16 years ago

moved tidy & pingpong

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