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

source: source/ariba/Node.cpp@ 2445

Last change on this file since 2445 was 2439, checked in by Christoph Mayer, 16 years ago

-NodeID Generierung bei UNSPECIFIED gefixt

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