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

Last change on this file since 6185 was 5902, checked in by mies, 15 years ago
File size: 8.5 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/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 // topology signaling
92 typeSignalingStart = 0x80, ///< start of the signaling types
93 typeSignalingEnd = 0xFF ///< end of the signaling types
94 };
95
96 /// default constructor
97 OverlayMsg(
98 uint8_t type = typeInvalid,
99 const ServiceID& _service = ServiceID::UNSPECIFIED,
100 const NodeID& _sourceNode = NodeID::UNSPECIFIED,
101 const NodeID& _destinationNode = NodeID::UNSPECIFIED,
102 const LinkID& _sourceLink = LinkID::UNSPECIFIED,
103 const LinkID& _destinationLink = LinkID::UNSPECIFIED )
104 : type(type), flags(0), hops(0), ttl(10),
105 service(_service),
106 sourceNode(_sourceNode), destinationNode(_destinationNode),
107 sourceLink(_sourceLink), destinationLink(_destinationLink),
108 routeRecord() {
109 if (!_sourceLink.isUnspecified() || !_destinationLink.isUnspecified())
110 setLinkMessage(true);
111 }
112
113 // copy constructor
114 OverlayMsg(const OverlayMsg& rhs)
115 : type(rhs.type), flags(rhs.flags), hops(rhs.hops), ttl(rhs.ttl),
116 service(rhs.service),
117 sourceNode(rhs.sourceNode), destinationNode(rhs.destinationNode),
118 sourceLink(rhs.sourceLink), destinationLink(rhs.destinationLink),
119 routeRecord(rhs.routeRecord) {
120 }
121
122 /// destructor
123 ~OverlayMsg();
124
125 /// type -------------------------------------------------------------------
126
127 type_ getType() const {
128 return (type_) type;
129 }
130
131 void setType( type_ type ) {
132 this->type = type;
133 }
134
135 bool hasTypeMask( type_ mask ) const {
136 return (type & (uint8_t)mask) == (uint8_t)mask;
137 }
138
139 /// flags ------------------------------------------------------------------
140
141 bool isRelayed() const {
142 return (flags & 0x01)!=0;
143 }
144
145 void setRelayed( bool relayed = true ) {
146 if (relayed) flags |= 1; else flags &= ~1;
147 }
148
149 bool isRegisterRelay() const {
150 return (flags & 0x02)!=0;
151 }
152
153 void setRegisterRelay( bool relayed = true ) {
154 if (relayed) flags |= 0x02; else flags &= ~0x02;
155 }
156
157 bool isRouteRecord() const {
158 return (flags & 0x04)!=0;
159 }
160
161 void setRouteRecord( bool route_record = true ) {
162 if (route_record) flags |= 0x04; else flags &= ~0x04;
163 }
164
165 bool isAutoLink() const {
166 return (flags & 0x80) == 0x80;
167 }
168
169 void setAutoLink(bool auto_link = true ) {
170 if (auto_link) flags |= 0x80; else flags &= ~0x80;
171 }
172
173 bool isLinkMessage() const {
174 return (flags & 0x40)!=0;
175 }
176
177 void setLinkMessage(bool link_info = true ) {
178 if (link_info) flags |= 0x40; else flags &= ~0x40;
179 }
180
181
182 bool containsSourceEndpoint() const {
183 return (flags & 0x20)!=0;
184 }
185
186 void setContainsSourceEndpoint(bool contains_endpoint) {
187 if (contains_endpoint) flags |= 0x20; else flags &= ~0x20;
188 }
189
190 /// number of hops and time to live ----------------------------------------
191
192 uint8_t getNumHops() const {
193 return hops;
194 }
195
196 void setNumHops( uint8_t hops ) {
197 this->hops = hops;
198 }
199
200 uint8_t increaseNumHops() {
201 hops++;
202 }
203
204 uint8_t getTimeToLive() const {
205 return ttl;
206 }
207
208 void setTimeToLive( uint8_t ttl ) {
209 this->ttl = ttl;
210 }
211
212 /// addresses and links ----------------------------------------------------
213
214 const ServiceID& getService() const {
215 return service;
216 }
217
218 void setService( const ServiceID& service ) {
219 this->service = service;
220 }
221
222 const NodeID& getSourceNode() const {
223 return sourceNode;
224 }
225
226 void setSourceNode( const NodeID& node ) {
227 this->sourceNode = node;
228 }
229
230 const NodeID& getDestinationNode() const {
231 return destinationNode;
232 }
233
234 void setDestinationNode( const NodeID& node ) {
235 this->destinationNode = node;
236 }
237
238 const LinkID& getSourceLink() const {
239 return sourceLink;
240 }
241
242 void setSourceLink( const LinkID& link ) {
243 this->sourceLink = link;
244 setLinkMessage();
245 }
246
247 const LinkID& getDestinationLink() const {
248 return destinationLink;
249 }
250
251 void setDestinationLink( const LinkID& link ) {
252 this->destinationLink = link;
253 setLinkMessage();
254 }
255
256 void setSourceEndpoint( const EndpointDescriptor& endpoint ) {
257 sourceEndpoint = endpoint;
258 setContainsSourceEndpoint(true);
259 }
260
261 const EndpointDescriptor& getSourceEndpoint() const {
262 return sourceEndpoint;
263 }
264
265 /// swaps source and destination
266 void swapRoles() {
267 NodeID dummyNode = sourceNode;
268 sourceNode = destinationNode;
269 destinationNode = dummyNode;
270 LinkID dummyLink = sourceLink;
271 sourceLink = destinationLink;
272 destinationLink = dummyLink;
273 hops = 0;
274 }
275
276 const vector<NodeID> getRouteRecord() const {
277 return routeRecord;
278 }
279
280 void addRouteRecord( const NodeID& node ) {
281 if (isRouteRecord())
282 routeRecord.push_back(node);
283 }
284
285private:
286 uint8_t type, flags, hops, ttl;
287 ServiceID service;
288 NodeID sourceNode;
289 NodeID destinationNode;
290 LinkID sourceLink;
291 LinkID destinationLink;
292 EndpointDescriptor sourceEndpoint;
293 vector<NodeID> routeRecord;
294};
295
296}} // ariba::overlay
297
298/// serialization
299sznBeginDefault( ariba::overlay::OverlayMsg, X ){
300 // header
301 X && type && flags && hops && ttl;
302
303 // addresses
304 X && &service && &sourceNode && &destinationNode;
305
306 // message is associated with a end-to-end link
307 if (isLinkMessage())
308 X && &sourceLink && &destinationLink;
309
310 // message is associated with a source end-point
311 if (containsSourceEndpoint())
312 X && sourceEndpoint;
313
314 // message should record its route
315 if (isRouteRecord()) {
316 uint8_t size = routeRecord.size();
317 X && size;
318 if (X.isDeserializer()) routeRecord.resize(size);
319 for (uint8_t i=0;i<size; i++) X && &routeRecord[i];
320 }
321
322 // payload
323 X && Payload();
324} sznEnd();
325
326#endif // OVERLAY_MSG_H__
Note: See TracBrowser for help on using the repository browser.