Ignore:
Timestamp:
Jul 24, 2009, 3:23:11 PM (15 years ago)
Author:
mies
Message:

+ added new transport modules and adapted ariba to them
+ exchange endpoint descriptors an link establishment
+ clean up of base communication
+ link establishment with in the presence of multiple endpoints
+ local discovery for ipv6, ipv4 and bluetooth mac addresses

File:
1 edited

Legend:

Unmodified
Added
Removed
  • source/ariba/communication/BaseCommunication.h

    r4983 r5284  
    4040#define BASECOMMUNICATION_H_
    4141
     42// boost & std includes
    4243#include <ext/hash_map>
    4344#include <ext/hash_set>
     
    4950#include <boost/foreach.hpp>
    5051
     52// utilities
    5153#include "ariba/utility/types.h"
    5254#include "ariba/utility/messages.h"
    5355#include "ariba/utility/logging/Logging.h"
    5456#include "ariba/utility/misc/Demultiplexer.hpp"
    55 
     57#include "ariba/utility/system/SystemEventListener.h"
     58
     59// new transport and addressing
     60#include "ariba/utility/addressing/addressing.hpp"
     61#include "ariba/utility/transport/transport.hpp"
     62
     63// communication
    5664#include "ariba/communication/CommunicationEvents.h"
    5765#include "ariba/communication/EndpointDescriptor.h"
     66#include "ariba/communication/messages/AribaBaseMsg.h"
     67
     68// network changes
    5869#include "ariba/communication/networkinfo/NetworkChangeInterface.h"
    5970#include "ariba/communication/networkinfo/NetworkChangeDetection.h"
    6071#include "ariba/communication/networkinfo/NetworkInformation.h"
    6172#include "ariba/communication/networkinfo/AddressInformation.h"
    62 #include "ariba/communication/messages/AribaBaseMsg.h"
    63 #include "ariba/communication/modules/transport/TransportProtocol.h"
    64 #include "ariba/communication/modules/network/NetworkProtocol.h"
    65 #include "ariba/communication/modules/network/NetworkLocator.h"
    66 
    67 #ifndef UNDERLAY_OMNET
    68   #include "ariba/communication/modules/transport/tcp/TCPTransport.h"
    69   #include "ariba/communication/modules/network/ip/IPv4NetworkProtocol.h"
    70 #endif
    71 
    72 using __gnu_cxx::hash_set;
    73 using __gnu_cxx::hash_map;
    74 
    75 using std::cout;
    76 using std::set;
    77 using std::map;
    78 using std::vector;
    79 using std::pair;
    80 using std::make_pair;
    81 using std::find;
    82 
    83 using ariba::communication::NetworkChangeDetection;
    84 using ariba::communication::NetworkChangeInterface;
    85 using ariba::communication::NetworkInterfaceList;
    86 using ariba::communication::NetworkInformation;
    87 using ariba::communication::AddressInformation;
    88 using ariba::communication::AddressList;
    89 using ariba::communication::AribaBaseMsg;
    90 using ariba::communication::CommunicationEvents;
    91 
    92 using ariba::utility::Demultiplexer;
    93 using ariba::utility::QoSParameterSet;
    94 using ariba::utility::SecurityParameterSet;
    95 using ariba::utility::Address;
    96 using ariba::utility::LinkID;
    97 using ariba::utility::LinkIDs;
    98 using ariba::utility::Message;
    99 using ariba::utility::MessageReceiver;
    100 using ariba::utility::seqnum_t;
    101 
    102 using ariba::communication::TransportProtocol;
    103 using ariba::communication::NetworkProtocol;
    104 using ariba::communication::NetworkLocator;
    105 #ifndef UNDERLAY_OMNET
    106   using ariba::communication::IPv4NetworkProtocol;
    107   using ariba::communication::TCPTransport;
    108 #endif
     73
     74// deprecated
     75//#include "ariba/communication/modules/transport/TransportProtocol.h"
     76//#include "ariba/communication/modules/network/NetworkProtocol.h"
     77//#include "ariba/communication/modules/network/NetworkLocator.h"
     78
     79// disabled
     80//#ifndef UNDERLAY_OMNET
     81//  #include "ariba/communication/modules/transport/tcp/TCPTransport.h"
     82//  #include "ariba/communication/modules/network/ip/IPv4NetworkProtocol.h"
     83//#endif
     84
     85// deprecated
     86//using ariba::communication::TransportProtocol;
     87//using ariba::communication::NetworkProtocol;
     88//using ariba::communication::NetworkLocator;
     89
     90// disabled
     91//#ifndef UNDERLAY_OMNET
     92//  using ariba::communication::IPv4NetworkProtocol;
     93//  using ariba::communication::TCPTransport;
     94//#endif
    10995
    11096namespace ariba {
    11197namespace communication {
     98
     99using namespace std;
     100using namespace ariba::addressing;
     101using namespace ariba::transport;
     102using namespace ariba::utility;
     103
     104// use base ariba types (clarifies multiple definitions)
     105using ariba::utility::Message;
     106using ariba::utility::seqnum_t;
    112107
    113108/**
     
    119114 * @author Sebastian Mies, Christoph Mayer
    120115 */
    121 class BaseCommunication : public MessageReceiver, NetworkChangeInterface {
     116class BaseCommunication: public NetworkChangeInterface,
     117        public SystemEventListener, public transport_listener {
    122118        use_logging_h(BaseCommunication);
     119
    123120public:
    124 
    125         /**
    126          * Default ctor that just creates an empty
    127          * non functional base communication
    128          */
     121        /// Default ctor that just creates an non-functional base communication
    129122        BaseCommunication();
    130123
    131         /**
    132          * Default dtor that does nothing
    133          */
     124        /// Default dtor that does nothing
    134125        virtual ~BaseCommunication();
    135126
    136         /**
    137          * Startup the base communication, start modules etc.
    138          */
    139         void start(const NetworkLocator* _locallocator, const uint16_t _listenport);
    140 
    141         /**
    142          * stop the base communication, stop modules etc.
    143          */
     127        /// Startup the base communication, start modules etc.
     128        void start();
     129
     130        /// Stops the base communication, stop modules etc.
    144131        void stop();
    145132
    146         /*
    147          * Check whether the base communication has been started up
    148          */
     133        /// Sets the endpoints
     134        void setEndpoints( string& endpoints );
     135
     136        /// Check whether the base communication has been started up
    149137        bool isStarted();
    150138
    151 
    152         /**
    153          * Establishes a link to another end-point.
    154          */
    155         const LinkID establishLink(
    156                 const EndpointDescriptor& descriptor,
    157                 const LinkID& linkid = LinkID::UNSPECIFIED,
    158                 const QoSParameterSet& qos = QoSParameterSet::DEFAULT,
    159                 const SecurityParameterSet& sec = SecurityParameterSet::DEFAULT
    160         );
    161 
    162         /**
    163          * Drops a link.
    164          *
    165          * @param The link id of the link that should be dropped
    166          */
     139        /// Establishes a link to another end-point.
     140        const LinkID establishLink(const EndpointDescriptor& descriptor,
     141                const LinkID& linkid = LinkID::UNSPECIFIED, const QoSParameterSet& qos =
     142                                QoSParameterSet::DEFAULT, const SecurityParameterSet& sec =
     143                                SecurityParameterSet::DEFAULT);
     144
     145        /// Drops a link
    167146        void dropLink(const LinkID link);
    168147
     
    182161         * @return The end-point descriptor of the link's end-point
    183162         */
    184         const EndpointDescriptor& getEndpointDescriptor( const LinkID link = LinkID::UNSPECIFIED ) const;
     163        const EndpointDescriptor& getEndpointDescriptor(const LinkID link =
     164                        LinkID::UNSPECIFIED) const;
    185165
    186166        /**
     
    190170         * @return List of LinkID
    191171         */
    192         LinkIDs getLocalLinks( const EndpointDescriptor& ep = EndpointDescriptor::UNSPECIFIED ) const;
     172        LinkIDs getLocalLinks(const address_v* addr) const;
    193173
    194174        /**
     
    197177         * @param _receiver The receiving side
    198178         */
    199         void registerMessageReceiver( MessageReceiver* _receiver );
     179        void registerMessageReceiver(MessageReceiver* receiver) {
     180                messageReceiver = receiver;
     181        }
    200182
    201183        /**
     
    204186         * @param _receiver The receiving side
    205187         */
    206         void unregisterMessageReceiver( MessageReceiver* _receiver );
    207 
    208         void registerEventListener( CommunicationEvents* _events );
    209         void unregisterEventListener( CommunicationEvents* _events );
     188        void unregisterMessageReceiver(MessageReceiver* receiver) {
     189                messageReceiver = NULL;
     190        }
     191
     192        void registerEventListener(CommunicationEvents* _events);
     193
     194        void unregisterEventListener(CommunicationEvents* _events);
     195
     196public:
     197
     198        /// called when a system event is emitted by system queue
     199        virtual void handleSystemEvent(const SystemEvent& event);
     200
     201        /// called when a message is received form transport_peer
     202        virtual void receive_message(transport_protocol* transport,
     203                const address_vf local, const address_vf remote, const uint8_t* data,
     204                size_t size);
    210205
    211206protected:
    212207
    213         /**
    214          * Called from the Transport when async items
    215          * from the SystemQueue are delivered
    216          */
    217         virtual bool receiveMessage( const Message* message, const LinkID& link, const NodeID& node );
    218 
    219         /**
    220          * Called when a network interface change happens
    221          */
    222         virtual void onNetworkChange( const NetworkChangeInterface::NetworkChangeInfo& info );
     208        /// handle received message from a transport module
     209        void receiveMessage(const Message* message,
     210                const address_v* local, const address_v* remote );
     211
     212        /// called when a network interface change happens
     213        virtual void onNetworkChange(
     214                const NetworkChangeInterface::NetworkChangeInfo& info);
    223215
    224216private:
    225 
    226         /**
    227          * A link descriptor consisting of the
    228          * end-point descriptor and currently used locator and
    229          * message receiver
     217        /**
     218         * A link descriptor consisting of the end-point descriptor and currently
     219         * used underlay address.
    230220         */
    231221        class LinkDescriptor {
     
    233223                static const LinkDescriptor UNSPECIFIED;
    234224
     225                /// default constructor
    235226                LinkDescriptor() :
    236                         localLink(LinkID::UNSPECIFIED),
    237                         localLocator(NULL),
    238                         remoteLink(LinkID::UNSPECIFIED),
    239                         remoteLocator(NULL),
    240                         remoteEndpoint(EndpointDescriptor::UNSPECIFIED),
    241                         linkup(false) {
     227                        localLink(LinkID::UNSPECIFIED), localLocator(NULL),
     228                        remoteLink(LinkID::UNSPECIFIED), remoteLocator(NULL),
     229                        remoteEndpoint(EndpointDescriptor::UNSPECIFIED), up(false) {
    242230                }
    243231
    244                 LinkDescriptor(const LinkID& _localLink, const NetworkLocator*& _localLocator,
    245                                 const LinkID& _remoteLink, const NetworkLocator*& _remoteLocator,
    246                                 const EndpointDescriptor& _remoteEndpoint, bool _linkup ) :
    247                         localLink(_localLink),
    248                         localLocator(_localLocator),
    249                         remoteLink(_remoteLink),
    250                         remoteLocator(_remoteLocator),
    251                         remoteEndpoint(_remoteEndpoint),
    252                         linkup(_linkup) {
     232                ~LinkDescriptor() {
     233                        if (localLocator!=NULL)  delete localLocator;
     234                        if (remoteLocator!=NULL) delete remoteLocator;
    253235                }
    254236
    255                 LinkDescriptor( const LinkDescriptor& desc ) :
    256                         localLink(desc.localLink),
    257                         localLocator(desc.localLocator),
    258                         remoteLink(desc.remoteLink),
    259                         remoteLocator(desc.remoteLocator),
    260                         remoteEndpoint(desc.remoteEndpoint),
    261                         linkup(desc.linkup) {
     237                /// returns true if this is the UNSPECIFIED object
     238                bool isUnspecified() const {
     239                        return this == &UNSPECIFIED;
    262240                }
    263241
    264                 bool isUnspecified() const {
    265                         return (this == &UNSPECIFIED);
    266                 }
    267 
    268                 LinkID                                  localLink;
    269                 const NetworkLocator*   localLocator;
    270                 LinkID                                  remoteLink;
    271                 const NetworkLocator*   remoteLocator;
    272                 EndpointDescriptor              remoteEndpoint;
    273 
    274                 bool                                    linkup;
     242                /// link identifiers
     243                LinkID localLink;
     244                LinkID remoteLink;
     245
     246                /// used underlay addresses for the link
     247                const address_v* localLocator;
     248                const address_v* remoteLocator;
     249
     250                /// the remote end-point descriptor
     251                EndpointDescriptor remoteEndpoint;
     252
     253                /// flag, whether this link is up
     254                bool up;
    275255        };
    276256
    277         /**
    278          * Link management: add a link
    279          */
    280         void addLink( const LinkDescriptor& link );
    281 
    282         /**
    283          * Link management: remove alink
    284          */
    285         void removeLink( const LinkID& localLink );
    286 
    287         /**
    288          * Link management: get link information using the local link
    289          */
    290         LinkDescriptor& queryLocalLink( const LinkID& localLink ) const;
    291 
    292         /**
    293          * Link management: get link information using the remote link
    294          */
    295         LinkDescriptor& queryRemoteLink( const LinkID& remoteLink ) const;
    296 
    297         /**
    298          * Link management: list of links
    299          */
    300         typedef vector<LinkDescriptor> LinkSet;
    301 
    302         /**
    303          * Link management: the set of currently managed links
    304          */
     257        /// Link management: list of links
     258        typedef vector<LinkDescriptor*> LinkSet;
     259
     260        /// Link management: the set of currently managed links
    305261        LinkSet linkSet;
    306262
    307         /**
    308          * The message receiver
    309          */
    310         MessageReceiver* messageReceiver;
    311 
    312         /**
    313          * The local end-point descriptor
    314          */
     263        /// Link management: add a link
     264        void addLink( LinkDescriptor* link );
     265
     266        /// Link management: remove a link
     267        void removeLink(const LinkID& localLink);
     268
     269        /// Link management: get link information using the local link
     270        LinkDescriptor& queryLocalLink(const LinkID& localLink) const;
     271
     272        /// Link management: get link information using the remote link
     273        LinkDescriptor& queryRemoteLink(const LinkID& remoteLink) const;
     274
     275        /// The local end-point descriptor
    315276        EndpointDescriptor localDescriptor;
    316277
    317         /**
    318          * Network information and protocol
    319          */
    320         NetworkProtocol* network;
    321 
    322         /**
    323          * Transport information and protocol
    324          */
    325         TransportProtocol* transport;
    326 
    327278#ifndef UNDERLAY_OMNET
    328         /**
    329          * Detect changes in the routing/interface, etc.
    330          * stuff needed for mobility detection
    331          */
     279        /// network change detector
    332280        NetworkChangeDetection networkMonitor;
    333281#endif
    334 
    335         /**
    336          * The local listen port
    337          */
    338         uint16_t listenport;
    339 
     282        /// event listener
    340283        typedef set<CommunicationEvents*> EventListenerSet;
    341284        EventListenerSet eventListener;
    342285
     286        /// sequence numbers
    343287        seqnum_t currentSeqnum;
    344288
    345         /**
    346          * state of the base communication
    347          */
    348         bool basecommStarted;
     289        /// transport peer
     290        transport_peer* transport;
     291
     292        /// the base overlay message receiver
     293        MessageReceiver* messageReceiver;
     294
     295        /// convenience: send message to peer
     296        void send( Message* message, const EndpointDescriptor& endpoint );
     297        void send( Message* message, const LinkDescriptor& descriptor );
     298
     299        /// state of the base communication
     300        bool started;
    349301
    350302};
     
    352304}} // namespace ariba, communication
    353305
    354 #endif /*BASECOMMUNICATION_H_*/
     306#endif /* BASECOMMUNICATION_H_ */
Note: See TracChangeset for help on using the changeset viewer.