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

source: source/ariba/Node.h@ 2483

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

-einige fixes im ablauf des neuen interface
-einige fehlende funktionalität implementiert

File size: 10.0 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#ifndef NODE_H_
40#define NODE_H_
41
42// forward declarations
43namespace ariba {
44class Node;
45}
46
47#include "Module.h"
48#include "Identifiers.h"
49#include "SpoVNetProperties.h"
50#include "NodeListener.h"
51#include "Name.h"
52#include "AribaModule.h"
53#include "CommunicationListener.h"
54#include "DataMessage.h"
55
56namespace ariba {
57
58// forward declaration
59namespace interface {
60class AribaContext;
61class ServiceInterface;
62}
63
64/**
65 * This class should implement all ariba node functionality.
66 *
67 * @author Sebastian Mies <mies@tm.uka.de>
68 */
69class Node: public Module {
70public:
71 /**
72 * Constructs a new node using a given ariba module
73 *
74 * @param ariba_mod The ariba module
75 * @param name The canonical node name of the new node. When NULL a
76 * randomly chosen name is created.
77 * @param len The length of the canonical node name or -1, if the name
78 * is a zero-terminated char-string.
79 */
80 Node(AribaModule& ariba_mod, const Name& node_name = Name::UNSPECIFIED);
81
82 /**
83 * Destroys the node. Before destruction some pre-conditions
84 * must be met:<br />
85 *
86 * 1. The node is not part of any SpoVNet <br />
87 * 2. All listeners must be unbound from this node <br />
88 * 3. The module has been stopped<br />
89 */
90 ~Node();
91
92 //--- node control ---
93
94 /**
95 * This method instructs the node to join a particular spovnet.
96 * Callees may bind with a NodeListener to receive events, when
97 * a node has been successfully joined.
98 *
99 * @param vnetId The SpoVNet name
100 */
101 void join(const Name& name);
102
103 /**
104 * This method initiates a new SpoVNet with the given SpoVNetID and
105 * parameters.
106 *
107 * @param name The SpoVNet name
108 * @param param The SpoVNet properties
109 */
110 void initiate(const Name& name, const SpoVNetProperties& parm =
111 SpoVNetProperties::DEFAULT);
112
113 /**
114 * This method initiates the leave procedure of this node.
115 */
116 void leave();
117
118 /**
119 * This method is used to bind a node listener to this node.
120 *
121 * @param listener The node listener
122 */
123 void bind(NodeListener* listener);
124
125 /**
126 * This method is used to unbind a node listener to this node.
127 *
128 * @param listener The node listener
129 */
130 void unbind(NodeListener* listener);
131
132 //--- spovnet properties ---
133
134 /**
135 * Returns the properties of the spovnet the node has joined.
136 *
137 * @return The properties of the spovnet the node has joined
138 */
139 const SpoVNetProperties& getSpoVNetProperties() const;
140
141 /**
142 * Returns the spovnet identifier
143 *
144 * @return The spovnet idenfifier
145 */
146 const SpoVNetID& getSpoVNetId() const;
147
148 /**
149 * Returns true, if the node is part of a spovnet.
150 *
151 * @return True, if the node is part of a spovnet
152 */
153 bool isJoined() const;
154
155 //--- addressing ---
156
157 /**
158 * Returns the node id of this node if the link id is unspecified or
159 * the node id of the remote node.
160 *
161 * @return The local or the remote node identifier
162 */
163 const NodeID& getNodeId(const LinkID& lid = LinkID::UNSPECIFIED) const;
164
165 /**
166 * Returns the node id to a node name according to the currently joined
167 * spovnet (usually derives a node identifier by hashing the name).
168 *
169 * @return The node identifier to the given name
170 */
171 NodeID generateNodeId(const Name& name) const;
172
173 /**
174 * Returns the name of this node if the link id is unspecified or
175 * the node name of the remote node, if known -- otherwise it returns
176 * an unspecified name.
177 *
178 * TODO: RFE -- send request to remote node and inform service.
179 *
180 * @return A node's name or an unspecified name, if unknown
181 */
182 const Name getNodeName(const LinkID& lid = LinkID::UNSPECIFIED) const;
183
184 //--- communication ---
185
186 /**
187 * Establishes a new link to another node and service with the given
188 * link properties. An optional message could be sent with the request.
189 *
190 * @param nid The remote node identifier
191 * @param sid The remote service identifier
192 * @param req The required link properties
193 * @param msg An optional message that is sent with the request
194 * @return A new link id
195 */
196 LinkID establishLink(const NodeID& nid, const ServiceID& sid,
197 const LinkProperties& req = LinkProperties::DEFAULT,
198 const DataMessage& msg = DataMessage::UNSPECIFIED);
199
200 /**
201 * This method drops an established link.
202 *
203 * @param lnk The link identifier of an active link
204 */
205 void dropLink(const LinkID& lnk);
206
207 // message sending
208
209 /**
210 * Sends a one-shot message to a service. If link properties are specified,
211 * the node tries to fulfill those requirements. This may cause the node
212 * to first establish a temporary link, second sending the message and last
213 * dropping the link. This would result in a small amount of extra latency
214 * until the message is delivered. If reliable transport was selected,
215 * the method returns a sequence number and a communication event is
216 * triggered on message delivery or loss.
217 *
218 * @param msg The message to be sent
219 * @param nid The remote node identifier
220 * @param sid The remote service identifier
221 * @param req The requirements associated with the message
222 * @return A sequence number
223 */
224 seqnum_t sendMessage(const DataMessage& msg, const NodeID& nid, const ServiceID& sid,
225 const LinkProperties& req = LinkProperties::DEFAULT);
226
227 /**
228 * Sends a message via an established link. If reliable transport was
229 * selected, the method returns a sequence number and a communication event
230 * is triggered on message delivery or loss.
231 *
232 * @param msg The message to be sent
233 * @param lnk The link to be used for sending the message
234 */
235 seqnum_t sendMessage(const DataMessage& msg, const LinkID& lnk);
236
237 /**
238 * Sends a message to all known hosts in the overlay structure
239 * the nodes that are reached here depend on the overlay structure.
240 *
241 * @param msg The message to be send
242 * @param sid The id of the service that should receive the message
243 */
244 void sendBroadcastMessage(const DataMessage& msg, const ServiceID& sid);
245
246 // --- communication listeners ---
247
248 /**
249 * Binds a listener to a specifed service identifier.
250 * Whenever a link is established/dropped or messages are received the
251 * events inside the interface are called.
252 *
253 * @param listener The listener to be registered
254 * @param sid The service identifier
255 */
256 void bind(CommunicationListener* listener, const ServiceID& sid);
257
258 /**
259 * Un-binds a listener from this node.
260 *
261 * @param The listener to be unbound
262 */
263 void unbind(CommunicationListener* listener, const ServiceID& sid);
264
265 // --- extension proposal: service directory -- TODO
266 // main-idea: use this methods to register groups/rendevous points inside
267 // the base overlay via a distributed storage service.
268 //
269 //void put(const KeyID& key, Message* value);
270 //void get(const KeyID& key);
271 //-------------------------------------------------------------------------
272 //
273 // --- optimization proposal: allow direct endpoint descriptor exchange ---
274 // main-idea: directly allow exchanging endpoint descriptors to establish
275 // links. Depending on the overlay structure used in the base overlay, this
276 // allows a node to directly establish links between two nodes when an
277 // endpoint descriptor is known.
278 //
279 //const EndpointDescriptor& getEndpointDescriptor( const LinkID& lid );
280 //void sendMessage( EndpointDescriptor& epd, Message* msg );
281 //LinkID setupLink( const EndpointDescriptor& endpointDesc,
282 // const LinkProperties& req = LinkProperties::UNSPECIFIED,
283 // const Message* msg = NULL );
284 //
285 //-------------------------------------------------------------------------
286
287 // --- module implementation ---
288 //
289 // main-idea: use module properties to configure nodeid, spovnetid etc. and
290 // select start/stop procedures. This allows simulations to start a
291 // node without manually calling join etc.
292
293 /** @see Module.h */
294 void initialize();
295
296 /** @see Module.h */
297 void start();
298
299 /** @see Module.h */
300 void stop();
301
302 /** @see Module.h */
303 string getName() const;
304
305 /** @see Module.h */
306 void setProperty(string key, string value);
307
308 /** @see Module.h */
309 const string getProperty(string key) const;
310
311 /** @see Module.h */
312 const vector<string> getProperties() const;
313
314protected:
315 // friends
316 friend class AribaModule;
317
318 // member variables
319 Name name; //< node name
320 AribaModule& ariba_mod; //< ariba module
321 SpoVNetID spovnetId; //< current spovnet id
322 NodeID nodeId; //< current node id
323
324 // delegates
325 interface::AribaContext* context;
326 static ServiceID anonymousService;
327};
328
329} // namespace ariba
330
331#endif /* NODE_H_ */
Note: See TracBrowser for help on using the repository browser.