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 maskDHT = 0x40,
00093 typeDHTPut = 0x41,
00094 typeDHTGet = 0x42,
00095 typeDHTRemove = 0x43,
00096
00098 maskDHTResponse = 0x50,
00099 typeDHTData = 0x51,
00100
00101
00102 typeSignalingStart = 0x80,
00103 typeSignalingEnd = 0xFF
00104 };
00105
00107 OverlayMsg(
00108 uint8_t type = typeInvalid,
00109 const ServiceID& _service = ServiceID::UNSPECIFIED,
00110 const NodeID& _sourceNode = NodeID::UNSPECIFIED,
00111 const NodeID& _destinationNode = NodeID::UNSPECIFIED,
00112 const LinkID& _sourceLink = LinkID::UNSPECIFIED,
00113 const LinkID& _destinationLink = LinkID::UNSPECIFIED )
00114 : type(type), flags(0), hops(0), ttl(10),
00115 service(_service),
00116 sourceNode(_sourceNode), destinationNode(_destinationNode),
00117 sourceLink(_sourceLink), destinationLink(_destinationLink),
00118 routeRecord() {
00119 if (!_sourceLink.isUnspecified() || !_destinationLink.isUnspecified())
00120 setLinkMessage(true);
00121 }
00122
00123
00124 OverlayMsg(const OverlayMsg& rhs)
00125 : type(rhs.type), flags(rhs.flags), hops(rhs.hops), ttl(rhs.ttl),
00126 service(rhs.service),
00127 sourceNode(rhs.sourceNode), destinationNode(rhs.destinationNode),
00128 sourceLink(rhs.sourceLink), destinationLink(rhs.destinationLink),
00129 routeRecord(rhs.routeRecord) {
00130 }
00131
00133 ~OverlayMsg();
00134
00136
00137 type_ getType() const {
00138 return (type_) type;
00139 }
00140
00141 void setType( type_ type ) {
00142 this->type = type;
00143 }
00144
00145 bool hasTypeMask( type_ mask ) const {
00146 return (type & (uint8_t)mask) == (uint8_t)mask;
00147 }
00148
00150
00151 bool isRelayed() const {
00152 return (flags & 0x01)!=0;
00153 }
00154
00155 void setRelayed( bool relayed = true ) {
00156 if (relayed) flags |= 1; else flags &= ~1;
00157 }
00158
00159 bool isRegisterRelay() const {
00160 return (flags & 0x02)!=0;
00161 }
00162
00163 void setRegisterRelay( bool relayed = true ) {
00164 if (relayed) flags |= 0x02; else flags &= ~0x02;
00165 }
00166
00167 bool isRouteRecord() const {
00168 return (flags & 0x04)!=0;
00169 }
00170
00171 void setRouteRecord( bool route_record = true ) {
00172 if (route_record) flags |= 0x04; else flags &= ~0x04;
00173 }
00174
00175 bool isAutoLink() const {
00176 return (flags & 0x80) == 0x80;
00177 }
00178
00179 void setAutoLink(bool auto_link = true ) {
00180 if (auto_link) flags |= 0x80; else flags &= ~0x80;
00181 }
00182
00183 bool isLinkMessage() const {
00184 return (flags & 0x40)!=0;
00185 }
00186
00187 void setLinkMessage(bool link_info = true ) {
00188 if (link_info) flags |= 0x40; else flags &= ~0x40;
00189 }
00190
00191 bool containsSourceEndpoint() const {
00192 return (flags & 0x20)!=0;
00193 }
00194
00195 void setContainsSourceEndpoint(bool contains_endpoint) {
00196 if (contains_endpoint) flags |= 0x20; else flags &= ~0x20;
00197 }
00198
00199 bool isDHTMessage() const {
00200 return hasTypeMask(maskDHT);
00201 }
00202
00204
00205 uint8_t getNumHops() const {
00206 return hops;
00207 }
00208
00209 void setNumHops( uint8_t hops ) {
00210 this->hops = hops;
00211 }
00212
00213 uint8_t increaseNumHops() {
00214 hops++;
00215 return hops;
00216 }
00217
00218 uint8_t getTimeToLive() const {
00219 return ttl;
00220 }
00221
00222 void setTimeToLive( uint8_t ttl ) {
00223 this->ttl = ttl;
00224 }
00225
00227
00228 const ServiceID& getService() const {
00229 return service;
00230 }
00231
00232 void setService( const ServiceID& service ) {
00233 this->service = service;
00234 }
00235
00236 const NodeID& getSourceNode() const {
00237 return sourceNode;
00238 }
00239
00240 void setSourceNode( const NodeID& node ) {
00241 this->sourceNode = node;
00242 }
00243
00244 const NodeID& getDestinationNode() const {
00245 return destinationNode;
00246 }
00247
00248 void setDestinationNode( const NodeID& node ) {
00249 this->destinationNode = node;
00250 }
00251
00252 const LinkID& getSourceLink() const {
00253 return sourceLink;
00254 }
00255
00256 void setSourceLink( const LinkID& link ) {
00257 this->sourceLink = link;
00258 setLinkMessage();
00259 }
00260
00261 const LinkID& getDestinationLink() const {
00262 return destinationLink;
00263 }
00264
00265 void setDestinationLink( const LinkID& link ) {
00266 this->destinationLink = link;
00267 setLinkMessage();
00268 }
00269
00270 void setSourceEndpoint( const EndpointDescriptor& endpoint ) {
00271 sourceEndpoint = endpoint;
00272 setContainsSourceEndpoint(true);
00273 }
00274
00275 const EndpointDescriptor& getSourceEndpoint() const {
00276 return sourceEndpoint;
00277 }
00278
00280 void swapRoles() {
00281 NodeID dummyNode = sourceNode;
00282 sourceNode = destinationNode;
00283 destinationNode = dummyNode;
00284 LinkID dummyLink = sourceLink;
00285 sourceLink = destinationLink;
00286 destinationLink = dummyLink;
00287 hops = 0;
00288 }
00289
00290 const vector<NodeID> getRouteRecord() const {
00291 return routeRecord;
00292 }
00293
00294 void addRouteRecord( const NodeID& node ) {
00295 if (isRouteRecord())
00296 routeRecord.push_back(node);
00297 }
00298
00299 private:
00300 uint8_t type, flags, hops, ttl;
00301 ServiceID service;
00302 NodeID sourceNode;
00303 NodeID destinationNode;
00304 LinkID sourceLink;
00305 LinkID destinationLink;
00306 EndpointDescriptor sourceEndpoint;
00307 vector<NodeID> routeRecord;
00308 };
00309
00310 }}
00311
00313 sznBeginDefault( ariba::overlay::OverlayMsg, X ){
00314
00315 X && type && flags && hops && ttl;
00316
00317
00318 X && &service && &sourceNode && &destinationNode;
00319
00320
00321 if (isLinkMessage())
00322 X && &sourceLink && &destinationLink;
00323
00324
00325 if (containsSourceEndpoint())
00326 X && sourceEndpoint;
00327
00328
00329 if (isRouteRecord()) {
00330 uint8_t size = routeRecord.size();
00331 X && size;
00332 if (X.isDeserializer()) routeRecord.resize(size);
00333 for (uint8_t i=0;i<size; i++) X && &routeRecord[i];
00334 }
00335
00336
00337 X && Payload();
00338 } sznEnd();
00339
00340 #endif // OVERLAY_MSG_H__