00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef OVERLAY_MSG_H__
00040 #define OVERLAY_MSG_H__
00041
00042 #include <boost/cstdint.hpp>
00043
00044 #include "ariba/utility/messages.h"
00045 #include "ariba/utility/serialization.h"
00046 #include "ariba/utility/types/ServiceID.h"
00047 #include "ariba/utility/types/NodeID.h"
00048 #include "ariba/utility/types/LinkID.h"
00049 #include "ariba/communication/EndpointDescriptor.h"
00050
00051
00052 namespace ariba {
00053 namespace overlay {
00054
00055 using ariba::utility::LinkID;
00056 using ariba::utility::NodeID;
00057 using ariba::utility::ServiceID;
00058 using ariba::utility::Message;
00059 using ariba::communication::EndpointDescriptor;
00060 using_serialization;
00061
00068 class OverlayMsg: public Message { VSERIALIZEABLE;
00069 public:
00071 enum type_ {
00072 typeInvalid = 0x00,
00073
00074
00075 maskTransfer = 0x10,
00076 typeData = 0x11,
00077
00078
00079 maskJoin = 0x20,
00080 typeJoinRequest = 0x21,
00081 typeJoinReply = 0x22,
00082
00083
00084 maskLink = 0x30,
00085 typeLinkRequest = 0x31,
00086 typeLinkReply = 0x32,
00087 typeLinkUpdate = 0x33,
00088 typeLinkDirect = 0x34,
00089 typeLinkAlive = 0x35,
00090
00091
00092 typeSignalingStart = 0x80,
00093 typeSignalingEnd = 0xFF
00094 };
00095
00097 OverlayMsg(
00098 uint8_t type = typeInvalid,
00099 const ServiceID& _service = ServiceID::UNSPECIFIED,
00100 const NodeID& _sourceNode = NodeID::UNSPECIFIED,
00101 const NodeID& _destinationNode = NodeID::UNSPECIFIED,
00102 const LinkID& _sourceLink = LinkID::UNSPECIFIED,
00103 const LinkID& _destinationLink = LinkID::UNSPECIFIED )
00104 : type(type), flags(0), hops(0), ttl(10),
00105 service(_service),
00106 sourceNode(_sourceNode), destinationNode(_destinationNode),
00107 sourceLink(_sourceLink), destinationLink(_destinationLink),
00108 routeRecord() {
00109 if (!_sourceLink.isUnspecified() || !_destinationLink.isUnspecified())
00110 setLinkMessage(true);
00111 }
00112
00113
00114 OverlayMsg(const OverlayMsg& rhs)
00115 : type(rhs.type), flags(rhs.flags), hops(rhs.hops), ttl(rhs.ttl),
00116 service(rhs.service),
00117 sourceNode(rhs.sourceNode), destinationNode(rhs.destinationNode),
00118 sourceLink(rhs.sourceLink), destinationLink(rhs.destinationLink),
00119 routeRecord(rhs.routeRecord) {
00120 }
00121
00123 ~OverlayMsg();
00124
00126
00127 type_ getType() const {
00128 return (type_) type;
00129 }
00130
00131 void setType( type_ type ) {
00132 this->type = type;
00133 }
00134
00135 bool hasTypeMask( type_ mask ) const {
00136 return (type & (uint8_t)mask) == (uint8_t)mask;
00137 }
00138
00140
00141 bool isRelayed() const {
00142 return (flags & 0x01)!=0;
00143 }
00144
00145 void setRelayed( bool relayed = true ) {
00146 if (relayed) flags |= 1; else flags &= ~1;
00147 }
00148
00149 bool isRegisterRelay() const {
00150 return (flags & 0x02)!=0;
00151 }
00152
00153 void setRegisterRelay( bool relayed = true ) {
00154 if (relayed) flags |= 0x02; else flags &= ~0x02;
00155 }
00156
00157 bool isRouteRecord() const {
00158 return (flags & 0x04)!=0;
00159 }
00160
00161 void setRouteRecord( bool route_record = true ) {
00162 if (route_record) flags |= 0x04; else flags &= ~0x04;
00163 }
00164
00165 bool isAutoLink() const {
00166 return (flags & 0x80) == 0x80;
00167 }
00168
00169 void setAutoLink(bool auto_link = true ) {
00170 if (auto_link) flags |= 0x80; else flags &= ~0x80;
00171 }
00172
00173 bool isLinkMessage() const {
00174 return (flags & 0x40)!=0;
00175 }
00176
00177 void setLinkMessage(bool link_info = true ) {
00178 if (link_info) flags |= 0x40; else flags &= ~0x40;
00179 }
00180
00181
00182 bool containsSourceEndpoint() const {
00183 return (flags & 0x20)!=0;
00184 }
00185
00186 void setContainsSourceEndpoint(bool contains_endpoint) {
00187 if (contains_endpoint) flags |= 0x20; else flags &= ~0x20;
00188 }
00189
00191
00192 uint8_t getNumHops() const {
00193 return hops;
00194 }
00195
00196 void setNumHops( uint8_t hops ) {
00197 this->hops = hops;
00198 }
00199
00200 uint8_t increaseNumHops() {
00201 hops++;
00202 }
00203
00204 uint8_t getTimeToLive() const {
00205 return ttl;
00206 }
00207
00208 void setTimeToLive( uint8_t ttl ) {
00209 this->ttl = ttl;
00210 }
00211
00213
00214 const ServiceID& getService() const {
00215 return service;
00216 }
00217
00218 void setService( const ServiceID& service ) {
00219 this->service = service;
00220 }
00221
00222 const NodeID& getSourceNode() const {
00223 return sourceNode;
00224 }
00225
00226 void setSourceNode( const NodeID& node ) {
00227 this->sourceNode = node;
00228 }
00229
00230 const NodeID& getDestinationNode() const {
00231 return destinationNode;
00232 }
00233
00234 void setDestinationNode( const NodeID& node ) {
00235 this->destinationNode = node;
00236 }
00237
00238 const LinkID& getSourceLink() const {
00239 return sourceLink;
00240 }
00241
00242 void setSourceLink( const LinkID& link ) {
00243 this->sourceLink = link;
00244 setLinkMessage();
00245 }
00246
00247 const LinkID& getDestinationLink() const {
00248 return destinationLink;
00249 }
00250
00251 void setDestinationLink( const LinkID& link ) {
00252 this->destinationLink = link;
00253 setLinkMessage();
00254 }
00255
00256 void setSourceEndpoint( const EndpointDescriptor& endpoint ) {
00257 sourceEndpoint = endpoint;
00258 setContainsSourceEndpoint(true);
00259 }
00260
00261 const EndpointDescriptor& getSourceEndpoint() const {
00262 return sourceEndpoint;
00263 }
00264
00266 void swapRoles() {
00267 NodeID dummyNode = sourceNode;
00268 sourceNode = destinationNode;
00269 destinationNode = dummyNode;
00270 LinkID dummyLink = sourceLink;
00271 sourceLink = destinationLink;
00272 destinationLink = dummyLink;
00273 hops = 0;
00274 }
00275
00276 const vector<NodeID> getRouteRecord() const {
00277 return routeRecord;
00278 }
00279
00280 void addRouteRecord( const NodeID& node ) {
00281 if (isRouteRecord())
00282 routeRecord.push_back(node);
00283 }
00284
00285 private:
00286 uint8_t type, flags, hops, ttl;
00287 ServiceID service;
00288 NodeID sourceNode;
00289 NodeID destinationNode;
00290 LinkID sourceLink;
00291 LinkID destinationLink;
00292 EndpointDescriptor sourceEndpoint;
00293 vector<NodeID> routeRecord;
00294 };
00295
00296 }}
00297
00299 sznBeginDefault( ariba::overlay::OverlayMsg, X ){
00300
00301 X && type && flags && hops && ttl;
00302
00303
00304 X && &service && &sourceNode && &destinationNode;
00305
00306
00307 if (isLinkMessage())
00308 X && &sourceLink && &destinationLink;
00309
00310
00311 if (containsSourceEndpoint())
00312 X && sourceEndpoint;
00313
00314
00315 if (isRouteRecord()) {
00316 uint8_t size = routeRecord.size();
00317 X && size;
00318 if (X.isDeserializer()) routeRecord.resize(size);
00319 for (uint8_t i=0;i<size; i++) X && &routeRecord[i];
00320 }
00321
00322
00323 X && Payload();
00324 } sznEnd();
00325
00326 #endif // OVERLAY_MSG_H__