Ignore:
Timestamp:
Aug 11, 2009, 4:11:02 PM (15 years ago)
Author:
Christoph Mayer
Message:

merge noch nicht fertig

File:
1 edited

Legend:

Unmodified
Added
Removed
  • source/ariba/overlay/messages/OverlayMsg.h

    r5316 r5870  
    4141
    4242#include <boost/cstdint.hpp>
     43
    4344#include "ariba/utility/messages.h"
    4445#include "ariba/utility/serialization.h"
     
    4647#include "ariba/utility/types/NodeID.h"
    4748#include "ariba/utility/types/LinkID.h"
     49#include "ariba/communication/EndpointDescriptor.h"
     50
     51
     52namespace ariba {
     53namespace overlay {
    4854
    4955using ariba::utility::LinkID;
     
    5157using ariba::utility::ServiceID;
    5258using ariba::utility::Message;
    53 
    54 namespace ariba {
    55 namespace overlay {
    56 
    57 using_serialization
    58 ;
    59 
    60 class OverlayMsg: public Message {
    61 VSERIALIZEABLE
    62         ;
     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;
    6369public:
    64 
    65         /// (payload-) message types
    66         enum type_ {
    67                 typeInvalid = 0, ///< invalid type (no encapsulated messages)
    68                 typeData = 1, ///< message contains data for higher layers
    69                 typeJoinRequest = 2, ///< join request
    70                 typeJoinReply = 3, ///< join reply
    71                 typeUpdate = 4, ///< update message for link association
    72                 typeLinkRequest = 5, ///< link request (sent over the overlay)
    73                 typeRelay = 6, ///< relay message
    74                 typeKeepAlive = 7, ///< a keep-alive message
    75                 typeDirectLink = 8,
    76         ///< a direct connection has been established
     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
    7794        };
    7895
    7996        /// default constructor
    80         OverlayMsg(type_ type = typeInvalid, const ServiceID _service =
    81                         ServiceID::UNSPECIFIED, const NodeID _sourceNode =
    82                         NodeID::UNSPECIFIED) :
    83                 type((uint8_t) type), service(_service), sourceNode(_sourceNode),
    84                                 relayLink(LinkID::UNSPECIFIED), autoLink(false) {
    85         }
    86 
    87         OverlayMsg(const OverlayMsg& rhs) :
    88                 type(rhs.type), service(rhs.service), sourceNode(rhs.sourceNode),
    89                                 relayLink(rhs.relayLink), autoLink(rhs.autoLink) {
    90         }
    91 
    92         /// type and source node constructor
    93         OverlayMsg(type_ type, const NodeID _sourceNode) :
    94                 type((uint8_t) type), service(ServiceID::UNSPECIFIED), sourceNode(
    95                                 _sourceNode), relayLink(LinkID::UNSPECIFIED), autoLink(false) {
     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(25),
     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) {
    96120        }
    97121
     
    99123        ~OverlayMsg();
    100124
     125        /// type -------------------------------------------------------------------
     126
    101127        type_ getType() const {
    102128                return (type_) type;
    103129        }
    104130
     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 isRouteRecord() const {
     150                return (flags & 0x02)!=0;
     151        }
     152
     153        void setRouteRecord( bool route_record = true ) {
     154                if (route_record) flags |= 0x02; else flags &= ~0x02;
     155        }
     156
     157        bool isAutoLink() const {
     158                return (flags & 0x80) == 0x80;
     159        }
     160
     161        void setAutoLink(bool auto_link = true ) {
     162                if (auto_link) flags |= 0x80; else flags &= ~0x80;
     163        }
     164
     165        bool isLinkMessage() const {
     166                return (flags & 0x40)!=0;
     167        }
     168
     169        void setLinkMessage(bool link_info = true ) {
     170                if (link_info) flags |= 0x40; else flags &= ~0x40;
     171        }
     172
     173
     174        bool containsSourceEndpoint() const {
     175                return (flags & 0x20)!=0;
     176        }
     177
     178        void setContainsSourceEndpoint(bool contains_endpoint) {
     179                if (contains_endpoint) flags |= 0x20; else flags &= ~0x20;
     180        }
     181
     182        /// number of hops and time to live ----------------------------------------
     183
     184        uint8_t getNumHops() const {
     185                return hops;
     186        }
     187
     188        void setNumHops( uint8_t hops ) {
     189                this->hops = hops;
     190        }
     191
     192        uint8_t increaseNumHops() {
     193                hops++;
     194        }
     195
     196        uint8_t getTimeToLive() const {
     197                return ttl;
     198        }
     199
     200        void setTimeToLive( uint8_t ttl ) {
     201                this->ttl = ttl;
     202        }
     203
     204        /// addresses and links ----------------------------------------------------
     205
    105206        const ServiceID& getService() const {
    106207                return service;
    107208        }
    108209
     210        void setService( const ServiceID& service ) {
     211                this->service = service;
     212        }
     213
    109214        const NodeID& getSourceNode() const {
    110215                return sourceNode;
    111216        }
    112217
    113         const LinkID& getRelayLink() const {
    114                 return relayLink;
    115         }
    116 
    117         void setRelayLink(const LinkID& relayLink) {
    118                 this->relayLink = relayLink;
    119         }
    120 
    121         const bool isAutoLink() const {
    122                 return autoLink;
    123         }
    124 
    125         void setAutoLink(bool autoLink) {
    126                 this->autoLink = autoLink;
    127         }
     218        void setSourceNode( const NodeID& node ) {
     219                this->sourceNode = node;
     220        }
     221
     222        const NodeID& getDestinationNode() const {
     223                return destinationNode;
     224        }
     225
     226        void setDestinationNode( const NodeID& node ) {
     227                this->destinationNode = node;
     228        }
     229
     230        const LinkID& getSourceLink() const {
     231                return sourceLink;
     232        }
     233
     234        void setSourceLink( const LinkID& link ) {
     235                this->sourceLink = link;
     236                setLinkMessage();
     237        }
     238
     239        const LinkID& getDestinationLink() const {
     240                return destinationLink;
     241        }
     242
     243        void setDestinationLink( const LinkID& link ) {
     244                this->destinationLink = link;
     245                setLinkMessage();
     246        }
     247
     248        void setSourceEndpoint( const EndpointDescriptor& endpoint ) {
     249                sourceEndpoint = endpoint;
     250                setContainsSourceEndpoint(true);
     251        }
     252
     253        const EndpointDescriptor& getSourceEndpoint() const {
     254                return sourceEndpoint;
     255        }
     256
     257        /// swaps source and destination
     258        void swapRoles() {
     259                NodeID dummyNode = sourceNode;
     260                sourceNode = destinationNode;
     261                destinationNode = dummyNode;
     262                LinkID dummyLink = sourceLink;
     263                sourceLink = destinationLink;
     264                destinationLink = dummyLink;
     265                hops = 0;
     266        }
     267
     268        const vector<NodeID> getRouteRecord() const {
     269                return routeRecord;
     270        }
     271
     272        void addRouteRecord( const NodeID& node ) {
     273                if (isRouteRecord())
     274                        routeRecord.push_back(node);
     275        }
     276
    128277private:
    129         uint8_t type;
     278        uint8_t type, flags, hops, ttl;
    130279        ServiceID service;
    131280        NodeID sourceNode;
    132         LinkID relayLink;
    133         uint8_t autoLink;
     281        NodeID destinationNode;
     282        LinkID sourceLink;
     283        LinkID destinationLink;
     284        EndpointDescriptor sourceEndpoint;
     285        vector<NodeID> routeRecord;
    134286};
    135287
    136 }
    137 } // ariba::overlay
    138 
     288}} // ariba::overlay
     289
     290/// serialization
    139291sznBeginDefault( ariba::overlay::OverlayMsg, X ){
    140 X && type && &service && &sourceNode;
    141 if (type == typeDirectLink) X && &relayLink;
    142 if (type == typeUpdate) X && autoLink;
    143 X && Payload();
    144 }sznEnd();
     292        // header
     293        X && type && flags && hops && ttl;
     294
     295        // addresses
     296        X && &service && &sourceNode && &destinationNode;
     297
     298        // message is associated with a end-to-end link
     299        if (isLinkMessage())
     300                X && &sourceLink && &destinationLink;
     301
     302        // message is associated with a source end-point
     303        if (containsSourceEndpoint())
     304                X && sourceEndpoint;
     305
     306        // message should record its route
     307        if (isRouteRecord()) {
     308                uint8_t size = routeRecord.size();
     309                X && size;
     310                if (X.isDeserializer()) routeRecord.resize(size);
     311                for (uint8_t i=0;i<size; i++) X && &routeRecord[i];
     312        }
     313
     314        // payload
     315        X && Payload();
     316} sznEnd();
    145317
    146318#endif // OVERLAY_MSG_H__
Note: See TracChangeset for help on using the changeset viewer.