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

source: source/ariba/overlay/messages/OverlayMsg.h@ 6880

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

added basic DHT functionality (untested)

File size: 8.9 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 ARIBA PROJECT 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 OVERLAY_MSG_H__
40#define OVERLAY_MSG_H__
41
42#include <boost/cstdint.hpp>
43
44#include "ariba/utility/messages.h"
45#include "ariba/utility/serialization.h"
46#include "ariba/utility/types/ServiceID.h"
47#include "ariba/utility/types/NodeID.h"
48#include "ariba/utility/types/LinkID.h"
49#include "ariba/communication/EndpointDescriptor.h"
50
51
52namespace ariba {
53namespace overlay {
54
55using ariba::utility::LinkID;
56using ariba::utility::NodeID;
57using ariba::utility::ServiceID;
58using ariba::utility::Message;
59using ariba::communication::EndpointDescriptor;
60using_serialization;
61
62/**
63 * A general purpose overlay message that is used to exchange messages
64 * between nodes.
65 *
66 * @author Sebastian Mies <mies@tm.uka.de>
67 */
68class OverlayMsg: public Message { VSERIALIZEABLE;
69public:
70 /// message types, is: uint8_t
71 enum type_ { // is: uint8_t
72 typeInvalid = 0x00, ///< invalid, unspecified type
73
74 // data transfer
75 maskTransfer = 0x10, ///< bit mask for transfer messages
76 typeData = 0x11, ///< message contains data for higher layers
77
78 // join signaling
79 maskJoin = 0x20, ///< bit mask for join messages
80 typeJoinRequest = 0x21, ///< join request
81 typeJoinReply = 0x22, ///< join reply
82
83 // link messages
84 maskLink = 0x30, ///< bit mask for link messages
85 typeLinkRequest = 0x31, ///< request a new link
86 typeLinkReply = 0x32, ///< link request reply
87 typeLinkUpdate = 0x33, ///< update message for link association
88 typeLinkDirect = 0x34, ///< direct connection has been established
89 typeLinkAlive = 0x35, ///< keep-alive message
90
91 // DHT routed messages
92 maskDHT = 0x40, ///< bit mask for dht messages
93 typeDHTPut = 0x41, ///< DHT put operation
94 typeDHTGet = 0x42, ///< DHT get operation
95 typeDHTRemove = 0x43, ///< DHT remove operation
96
97 /// DHT response messages
98 maskDHTResponse = 0x50, ///< bit mask for dht responses
99 typeDHTData = 0x51, ///< DHT get data
100
101 // topology signaling
102 typeSignalingStart = 0x80, ///< start of the signaling types
103 typeSignalingEnd = 0xFF ///< end of the signaling types
104 };
105
106 /// default constructor
107 OverlayMsg(
108 uint8_t type = typeInvalid,
109 const ServiceID& _service = ServiceID::UNSPECIFIED,
110 const NodeID& _sourceNode = NodeID::UNSPECIFIED,
111 const NodeID& _destinationNode = NodeID::UNSPECIFIED,
112 const LinkID& _sourceLink = LinkID::UNSPECIFIED,
113 const LinkID& _destinationLink = LinkID::UNSPECIFIED )
114 : type(type), flags(0), hops(0), ttl(10),
115 service(_service),
116 sourceNode(_sourceNode), destinationNode(_destinationNode),
117 sourceLink(_sourceLink), destinationLink(_destinationLink),
118 routeRecord() {
119 if (!_sourceLink.isUnspecified() || !_destinationLink.isUnspecified())
120 setLinkMessage(true);
121 }
122
123 // copy constructor
124 OverlayMsg(const OverlayMsg& rhs)
125 : type(rhs.type), flags(rhs.flags), hops(rhs.hops), ttl(rhs.ttl),
126 service(rhs.service),
127 sourceNode(rhs.sourceNode), destinationNode(rhs.destinationNode),
128 sourceLink(rhs.sourceLink), destinationLink(rhs.destinationLink),
129 routeRecord(rhs.routeRecord) {
130 }
131
132 /// destructor
133 ~OverlayMsg();
134
135 /// type -------------------------------------------------------------------
136
137 type_ getType() const {
138 return (type_) type;
139 }
140
141 void setType( type_ type ) {
142 this->type = type;
143 }
144
145 bool hasTypeMask( type_ mask ) const {
146 return (type & (uint8_t)mask) == (uint8_t)mask;
147 }
148
149 /// flags ------------------------------------------------------------------
150
151 bool isRelayed() const {
152 return (flags & 0x01)!=0;
153 }
154
155 void setRelayed( bool relayed = true ) {
156 if (relayed) flags |= 1; else flags &= ~1;
157 }
158
159 bool isRegisterRelay() const {
160 return (flags & 0x02)!=0;
161 }
162
163 void setRegisterRelay( bool relayed = true ) {
164 if (relayed) flags |= 0x02; else flags &= ~0x02;
165 }
166
167 bool isRouteRecord() const {
168 return (flags & 0x04)!=0;
169 }
170
171 void setRouteRecord( bool route_record = true ) {
172 if (route_record) flags |= 0x04; else flags &= ~0x04;
173 }
174
175 bool isAutoLink() const {
176 return (flags & 0x80) == 0x80;
177 }
178
179 void setAutoLink(bool auto_link = true ) {
180 if (auto_link) flags |= 0x80; else flags &= ~0x80;
181 }
182
183 bool isLinkMessage() const {
184 return (flags & 0x40)!=0;
185 }
186
187 void setLinkMessage(bool link_info = true ) {
188 if (link_info) flags |= 0x40; else flags &= ~0x40;
189 }
190
191 bool containsSourceEndpoint() const {
192 return (flags & 0x20)!=0;
193 }
194
195 void setContainsSourceEndpoint(bool contains_endpoint) {
196 if (contains_endpoint) flags |= 0x20; else flags &= ~0x20;
197 }
198
199 bool isDHTMessage() const {
200 return hasTypeMask(maskDHT);
201 }
202
203 /// number of hops and time to live ----------------------------------------
204
205 uint8_t getNumHops() const {
206 return hops;
207 }
208
209 void setNumHops( uint8_t hops ) {
210 this->hops = hops;
211 }
212
213 uint8_t increaseNumHops() {
214 hops++;
215 }
216
217 uint8_t getTimeToLive() const {
218 return ttl;
219 }
220
221 void setTimeToLive( uint8_t ttl ) {
222 this->ttl = ttl;
223 }
224
225 /// addresses and links ----------------------------------------------------
226
227 const ServiceID& getService() const {
228 return service;
229 }
230
231 void setService( const ServiceID& service ) {
232 this->service = service;
233 }
234
235 const NodeID& getSourceNode() const {
236 return sourceNode;
237 }
238
239 void setSourceNode( const NodeID& node ) {
240 this->sourceNode = node;
241 }
242
243 const NodeID& getDestinationNode() const {
244 return destinationNode;
245 }
246
247 void setDestinationNode( const NodeID& node ) {
248 this->destinationNode = node;
249 }
250
251 const LinkID& getSourceLink() const {
252 return sourceLink;
253 }
254
255 void setSourceLink( const LinkID& link ) {
256 this->sourceLink = link;
257 setLinkMessage();
258 }
259
260 const LinkID& getDestinationLink() const {
261 return destinationLink;
262 }
263
264 void setDestinationLink( const LinkID& link ) {
265 this->destinationLink = link;
266 setLinkMessage();
267 }
268
269 void setSourceEndpoint( const EndpointDescriptor& endpoint ) {
270 sourceEndpoint = endpoint;
271 setContainsSourceEndpoint(true);
272 }
273
274 const EndpointDescriptor& getSourceEndpoint() const {
275 return sourceEndpoint;
276 }
277
278 /// swaps source and destination
279 void swapRoles() {
280 NodeID dummyNode = sourceNode;
281 sourceNode = destinationNode;
282 destinationNode = dummyNode;
283 LinkID dummyLink = sourceLink;
284 sourceLink = destinationLink;
285 destinationLink = dummyLink;
286 hops = 0;
287 }
288
289 const vector<NodeID> getRouteRecord() const {
290 return routeRecord;
291 }
292
293 void addRouteRecord( const NodeID& node ) {
294 if (isRouteRecord())
295 routeRecord.push_back(node);
296 }
297
298private:
299 uint8_t type, flags, hops, ttl;
300 ServiceID service;
301 NodeID sourceNode;
302 NodeID destinationNode;
303 LinkID sourceLink;
304 LinkID destinationLink;
305 EndpointDescriptor sourceEndpoint;
306 vector<NodeID> routeRecord;
307};
308
309}} // ariba::overlay
310
311/// serialization
312sznBeginDefault( ariba::overlay::OverlayMsg, X ){
313 // header
314 X && type && flags && hops && ttl;
315
316 // addresses
317 X && &service && &sourceNode && &destinationNode;
318
319 // message is associated with a end-to-end link
320 if (isLinkMessage())
321 X && &sourceLink && &destinationLink;
322
323 // message is associated with a source end-point
324 if (containsSourceEndpoint())
325 X && sourceEndpoint;
326
327 // message should record its route
328 if (isRouteRecord()) {
329 uint8_t size = routeRecord.size();
330 X && size;
331 if (X.isDeserializer()) routeRecord.resize(size);
332 for (uint8_t i=0;i<size; i++) X && &routeRecord[i];
333 }
334
335 // payload
336 X && Payload();
337} sznEnd();
338
339#endif // OVERLAY_MSG_H__
Note: See TracBrowser for help on using the repository browser.