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

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

Last change on this file since 10573 was 6919, checked in by mies, 15 years ago

Fixed tons of warnings when using CXXFLAGS="-Wall"!

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 return hops;
216 }
217
218 uint8_t getTimeToLive() const {
219 return ttl;
220 }
221
222 void setTimeToLive( uint8_t ttl ) {
223 this->ttl = ttl;
224 }
225
226 /// addresses and links ----------------------------------------------------
227
228 const ServiceID& getService() const {
229 return service;
230 }
231
232 void setService( const ServiceID& service ) {
233 this->service = service;
234 }
235
236 const NodeID& getSourceNode() const {
237 return sourceNode;
238 }
239
240 void setSourceNode( const NodeID& node ) {
241 this->sourceNode = node;
242 }
243
244 const NodeID& getDestinationNode() const {
245 return destinationNode;
246 }
247
248 void setDestinationNode( const NodeID& node ) {
249 this->destinationNode = node;
250 }
251
252 const LinkID& getSourceLink() const {
253 return sourceLink;
254 }
255
256 void setSourceLink( const LinkID& link ) {
257 this->sourceLink = link;
258 setLinkMessage();
259 }
260
261 const LinkID& getDestinationLink() const {
262 return destinationLink;
263 }
264
265 void setDestinationLink( const LinkID& link ) {
266 this->destinationLink = link;
267 setLinkMessage();
268 }
269
270 void setSourceEndpoint( const EndpointDescriptor& endpoint ) {
271 sourceEndpoint = endpoint;
272 setContainsSourceEndpoint(true);
273 }
274
275 const EndpointDescriptor& getSourceEndpoint() const {
276 return sourceEndpoint;
277 }
278
279 /// swaps source and destination
280 void swapRoles() {
281 NodeID dummyNode = sourceNode;
282 sourceNode = destinationNode;
283 destinationNode = dummyNode;
284 LinkID dummyLink = sourceLink;
285 sourceLink = destinationLink;
286 destinationLink = dummyLink;
287 hops = 0;
288 }
289
290 const vector<NodeID> getRouteRecord() const {
291 return routeRecord;
292 }
293
294 void addRouteRecord( const NodeID& node ) {
295 if (isRouteRecord())
296 routeRecord.push_back(node);
297 }
298
299private:
300 uint8_t type, flags, hops, ttl;
301 ServiceID service;
302 NodeID sourceNode;
303 NodeID destinationNode;
304 LinkID sourceLink;
305 LinkID destinationLink;
306 EndpointDescriptor sourceEndpoint;
307 vector<NodeID> routeRecord;
308};
309
310}} // ariba::overlay
311
312/// serialization
313sznBeginDefault( ariba::overlay::OverlayMsg, X ){
314 // header
315 X && type && flags && hops && ttl;
316
317 // addresses
318 X && &service && &sourceNode && &destinationNode;
319
320 // message is associated with a end-to-end link
321 if (isLinkMessage())
322 X && &sourceLink && &destinationLink;
323
324 // message is associated with a source end-point
325 if (containsSourceEndpoint())
326 X && sourceEndpoint;
327
328 // message should record its route
329 if (isRouteRecord()) {
330 uint8_t size = routeRecord.size();
331 X && size;
332 if (X.isDeserializer()) routeRecord.resize(size);
333 for (uint8_t i=0;i<size; i++) X && &routeRecord[i];
334 }
335
336 // payload
337 X && Payload();
338} sznEnd();
339
340#endif // OVERLAY_MSG_H__
Note: See TracBrowser for help on using the repository browser.