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

Last change on this file since 12763 was 12060, checked in by hock@…, 11 years ago

Reintegrate branch: 20130111-hock-message_classes

improvements:

  • new message classes (reboost, zero-copy)
  • "fast path" for direct links (skip overlay layer)
  • link-properties accessible from the application
  • SystemQueue can call boost::bind functions
  • protlib compatibility removed (32bit overhead saved in every message)
  • addressing2
  • AddressDiscovery discoveres only addresses on which we're actually listening
  • ariba serialization usage reduced (sill used in OverlayMsg)
  • Node::connect, easier and cleaner interface to start-up ariba from the application
  • ariba configs via JSON, XML, etc (boost::property_tree)
  • keep-alive overhead greatly reduced
  • (relayed) overlay links can actually be closed now
  • lost messages are detected in most cases
  • notification to the application when link is transformed into direct-link
  • overlay routing: send message to second best hop if it would be dropped otherwise
  • SequenceNumbers (only mechanisms, so for: upward compatibility)
  • various small fixes


regressions:

  • bluetooth is not yet working again
  • bootstrap modules deactivated
  • liblog4xx is not working (use cout-logging)

This patch brings great performance and stability improvements at cost of backward compatibility.
Also bluetooth and the bootstrap modules have not been ported to the new interfaces, yet.

File size: 11.6 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 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/utility/misc/sha1.h>
50#include "ariba/overlay/SequenceNumber.h"
51
52namespace ariba {
53namespace overlay {
54
55using ariba::utility::LinkID;
56using ariba::utility::NodeID;
57using ariba::utility::ServiceID;
58using ariba::utility::Message;
59//using 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>, Mario Hock
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 typeMessageLost = 0x12, ///< message contains info about a dropped message
78
79 // join signaling
80 maskJoin = 0x20, ///< bit mask for join messages
81 typeJoinRequest = 0x21, ///< join request
82 typeJoinReply = 0x22, ///< join reply
83
84 // link messages
85 maskLink = 0x30, ///< bit mask for link messages
86 typeLinkRequest = 0x31, ///< request a new link
87 typeLinkReply = 0x32, ///< link request reply
88 typeLinkUpdate = 0x33, ///< update message for link association
89 typeLinkDirect = 0x34, ///< direct connection has been established
90 typeKeepAlive = 0x35, ///< keep-alive message
91 typeKeepAliveReply = 0x36, ///< keep-alive message (replay)
92 typeLinkClose = 0x37,
93
94 /// DHT routed messages
95 /// @deprecated because the DHT has been moved into a separate service
96 maskDHT = 0x40, ///< bit mask for dht messages
97 typeDHTPut = 0x41, ///< DHT put operation
98 typeDHTGet = 0x42, ///< DHT get operation
99 typeDHTRemove = 0x43, ///< DHT remove operation
100
101 /// DHT response messages
102 /// @deprecated because the DHT has been moved into a separate service
103 maskDHTResponse = 0x50, ///< bit mask for dht responses
104 typeDHTData = 0x51, ///< DHT get data
105
106 /// misc message types
107 typePing = 0x44,
108 typePong = 0x45,
109
110 // topology signaling
111 typeSignalingStart = 0x80, ///< start of the signaling types
112 typeSignalingEnd = 0xFF ///< end of the signaling types
113 };
114
115 /// message flags (uint8_t)
116 enum flags_
117 {
118 flagRelayed = 1 << 0,
119 flagRegisterRelay = 1 << 1,
120 flagRouteRecord = 1 << 2,
121 flagSeqNum1 = 1 << 3,
122 flagSeqNum2 = 1 << 4,
123 flagAutoLink = 1 << 5,
124 flagLinkMessage = 1 << 6,
125 flagHasMoreFlags = 1 << 7
126 };
127
128 /// default constructor
129 OverlayMsg(
130 uint8_t type = typeInvalid,
131 const ServiceID& _service = ServiceID::UNSPECIFIED,
132 const NodeID& _sourceNode = NodeID::UNSPECIFIED,
133 const NodeID& _destinationNode = NodeID::UNSPECIFIED,
134 const LinkID& _sourceLink = LinkID::UNSPECIFIED,
135 const LinkID& _destinationLink = LinkID::UNSPECIFIED )
136 : type(type), flags(0), extended_flags(0), hops(0), ttl(10), priority(0),
137 service(_service),
138 sourceNode(_sourceNode), destinationNode(_destinationNode),
139 sourceLink(_sourceLink), destinationLink(_destinationLink),
140 routeRecord() {
141 if (!_sourceLink.isUnspecified() || !_destinationLink.isUnspecified())
142 setLinkMessage(true);
143 }
144
145 // copy constructor
146 OverlayMsg(const OverlayMsg& rhs)
147 : type(rhs.type), flags(rhs.flags), extended_flags(rhs.extended_flags),
148 hops(rhs.hops), ttl(rhs.ttl),
149 priority(rhs.priority), service(rhs.service),
150 sourceNode(rhs.sourceNode), destinationNode(rhs.destinationNode),
151 sourceLink(rhs.sourceLink), destinationLink(rhs.destinationLink),
152 routeRecord(rhs.routeRecord) {
153 }
154
155 /// destructor
156 ~OverlayMsg();
157
158 /// type -------------------------------------------------------------------
159
160 type_ getType() const {
161 return (type_) type;
162 }
163
164 void setType( type_ type ) {
165 this->type = type;
166 }
167
168 bool hasTypeMask( type_ mask ) const {
169 return (type & (uint8_t)mask) == (uint8_t)mask;
170 }
171
172 /// priority ------------------------------------------------------------------
173
174 uint8_t getPriority() const {
175 return priority;
176 }
177
178 void setPriority(uint8_t priority) {
179 this->priority = priority;
180 }
181
182 /// flags ------------------------------------------------------------------
183
184 bool isRelayed() const {
185 return (flags & flagRelayed)!=0;
186 }
187
188 void setRelayed( bool relayed = true ) {
189 if (relayed) flags |= flagRelayed; else flags &= ~flagRelayed;
190 }
191
192 bool isRegisterRelay() const {
193 return (flags & flagRegisterRelay)!=0;
194 }
195
196 void setRegisterRelay( bool relayed = true ) {
197 if (relayed) flags |= flagRegisterRelay; else flags &= ~flagRegisterRelay;
198 }
199
200 bool isRouteRecord() const {
201 return (flags & flagRouteRecord)!=0;
202 }
203
204 void setRouteRecord( bool route_record = true ) {
205 if (route_record) flags |= flagRouteRecord; else flags &= ~flagRouteRecord;
206 }
207
208 bool isAutoLink() const {
209 return (flags & flagAutoLink) == flagAutoLink;
210 }
211
212 void setAutoLink(bool auto_link = true ) {
213 if (auto_link) flags |= flagAutoLink; else flags &= ~flagAutoLink;
214 }
215
216 bool isLinkMessage() const {
217 return (flags & flagLinkMessage)!=0;
218 }
219
220 void setLinkMessage(bool link_info = true ) {
221 if (link_info) flags |= flagLinkMessage; else flags &= ~flagLinkMessage;
222 }
223
224 bool hasExtendedFlags() const {
225 return (flags & flagHasMoreFlags) == flagHasMoreFlags;
226 }
227
228 /// number of hops and time to live ----------------------------------------
229
230 uint8_t getNumHops() const {
231 return hops;
232 }
233
234 void setNumHops( uint8_t hops ) {
235 this->hops = hops;
236 }
237
238 uint8_t increaseNumHops() {
239 hops++;
240 return hops;
241 }
242
243 uint8_t getTimeToLive() const {
244 return ttl;
245 }
246
247 void setTimeToLive( uint8_t ttl ) {
248 this->ttl = ttl;
249 }
250
251 /// addresses and links ----------------------------------------------------
252
253 const ServiceID& getService() const {
254 return service;
255 }
256
257 void setService( const ServiceID& service ) {
258 this->service = service;
259 }
260
261 const NodeID& getSourceNode() const {
262 return sourceNode;
263 }
264
265 void setSourceNode( const NodeID& node ) {
266 this->sourceNode = node;
267 }
268
269 const NodeID& getDestinationNode() const {
270 return destinationNode;
271 }
272
273 void setDestinationNode( const NodeID& node ) {
274 this->destinationNode = node;
275 }
276
277 const LinkID& getSourceLink() const {
278 return sourceLink;
279 }
280
281 void setSourceLink( const LinkID& link ) {
282 this->sourceLink = link;
283 setLinkMessage();
284 }
285
286 const LinkID& getDestinationLink() const {
287 return destinationLink;
288 }
289
290 void setDestinationLink( const LinkID& link ) {
291 this->destinationLink = link;
292 setLinkMessage();
293 }
294
295 /// swaps source and destination
296 void swapRoles() {
297 NodeID dummyNode = sourceNode;
298 sourceNode = destinationNode;
299 destinationNode = dummyNode;
300 LinkID dummyLink = sourceLink;
301 sourceLink = destinationLink;
302 destinationLink = dummyLink;
303 hops = 0;
304 routeRecord.clear();
305 }
306
307 const vector<NodeID> getRouteRecord() const {
308 return routeRecord;
309 }
310
311 void addRouteRecord( const NodeID& node ) {
312 if (isRouteRecord())
313 routeRecord.push_back(node);
314 }
315
316 /// sequence numbers
317 bool hasShortSeqNum() const
318 {
319 return (flags & (flagSeqNum1 | flagSeqNum2)) == flagSeqNum1;
320 }
321
322 bool hasLongSeqNum() const
323 {
324 return (flags & (flagSeqNum1 | flagSeqNum2)) == flagSeqNum2;
325 }
326
327 void setSeqNum(const SequenceNumber& sequence_number)
328 {
329 this->seqnum = sequence_number;
330
331 // short seqnum
332 if ( sequence_number.isShortSeqNum() )
333 {
334 flags |= flagSeqNum1;
335 flags &= ~flagSeqNum2;
336 }
337 // longseqnum
338 else if ( sequence_number.isShortSeqNum() )
339 {
340 flags &= ~flagSeqNum1;
341 flags |= flagSeqNum2;
342 }
343 // no seqnum
344 else
345 {
346 flags &= ~flagSeqNum1;
347 flags &= ~flagSeqNum2;
348 }
349 }
350
351 const SequenceNumber& getSeqNum() const
352 {
353 return seqnum;
354 }
355
356
357private:
358 uint8_t type, flags, extended_flags, hops, ttl, priority;
359 ServiceID service;
360 NodeID sourceNode;
361 NodeID destinationNode;
362 LinkID sourceLink;
363 LinkID destinationLink;
364// EndpointDescriptor sourceEndpoint;
365 vector<NodeID> routeRecord;
366 SequenceNumber seqnum;
367};
368
369}} // ariba::overlay
370
371/// serialization
372sznBeginDefault( ariba::overlay::OverlayMsg, X ){
373 // header
374 X && type && flags;
375
376 if ( hasExtendedFlags() )
377 X && extended_flags;
378
379 X && hops && ttl;
380
381 // addresses
382 X && &service && &sourceNode && &destinationNode;
383
384 // priority
385 X && priority;
386
387 // message is associated with a end-to-end link
388 if (isLinkMessage())
389 X && &sourceLink && &destinationLink;
390
391
392 /* seqnum */
393 // serialize
394 if ( X.isSerializer() )
395 {
396 if ( hasShortSeqNum() )
397 {
398 uint32_t short_seqnum;
399 short_seqnum = seqnum.getShortSeqNum();
400 X && short_seqnum;
401 }
402 if ( hasLongSeqNum() )
403 {
404 uint64_t long_seqnum;
405 long_seqnum = seqnum.getLongSeqNum();
406 X && long_seqnum;
407 }
408 }
409 // deserialize
410 else
411 {
412 if ( hasShortSeqNum() )
413 {
414 uint32_t short_seqnum;
415 X && short_seqnum;
416 seqnum = ariba::overlay::SequenceNumber(short_seqnum);
417 }
418 if ( hasLongSeqNum() )
419 {
420 uint64_t long_seqnum;
421 X && long_seqnum;
422 seqnum = ariba::overlay::SequenceNumber(long_seqnum);
423 }
424 }
425
426
427 // message should record its route
428 if (isRouteRecord()) {
429 uint8_t size = routeRecord.size();
430 X && size;
431 if (X.isDeserializer()) routeRecord.resize(size);
432 for (uint8_t i=0;i<size; i++) X && &routeRecord[i];
433 }
434
435 // payload
436// X && Payload();
437} sznEnd();
438
439#endif // OVERLAY_MSG_H__
Note: See TracBrowser for help on using the repository browser.