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 BASECOMMUNICATION_H_
00040 #define BASECOMMUNICATION_H_
00041
00042 #include <ext/hash_map>
00043 #include <ext/hash_set>
00044 #include <map>
00045 #include <set>
00046 #include <vector>
00047 #include <iostream>
00048 #include <algorithm>
00049 #include <boost/foreach.hpp>
00050
00051 #include "ariba/utility/types.h"
00052 #include "ariba/utility/messages.h"
00053 #include "ariba/utility/logging/Logging.h"
00054 #include "ariba/utility/misc/Demultiplexer.hpp"
00055
00056 #include "ariba/communication/CommunicationEvents.h"
00057 #include "ariba/communication/EndpointDescriptor.h"
00058 #include "ariba/communication/networkinfo/NetworkChangeInterface.h"
00059 #include "ariba/communication/networkinfo/NetworkChangeDetection.h"
00060 #include "ariba/communication/networkinfo/NetworkInformation.h"
00061 #include "ariba/communication/networkinfo/AddressInformation.h"
00062 #include "ariba/communication/messages/AribaBaseMsg.h"
00063 #include "ariba/communication/modules/transport/TransportProtocol.h"
00064 #include "ariba/communication/modules/network/NetworkProtocol.h"
00065 #include "ariba/communication/modules/network/NetworkLocator.h"
00066
00067 #ifndef UNDERLAY_OMNET
00068 #include "ariba/communication/modules/transport/tcp/TCPTransport.h"
00069 #include "ariba/communication/modules/network/ip/IPv4NetworkProtocol.h"
00070 #endif
00071
00072 using __gnu_cxx::hash_set;
00073 using __gnu_cxx::hash_map;
00074
00075 using std::cout;
00076 using std::set;
00077 using std::map;
00078 using std::vector;
00079 using std::pair;
00080 using std::make_pair;
00081 using std::find;
00082
00083 using ariba::communication::NetworkChangeDetection;
00084 using ariba::communication::NetworkChangeInterface;
00085 using ariba::communication::NetworkInterfaceList;
00086 using ariba::communication::NetworkInformation;
00087 using ariba::communication::AddressInformation;
00088 using ariba::communication::AddressList;
00089 using ariba::communication::AribaBaseMsg;
00090 using ariba::communication::CommunicationEvents;
00091
00092 using ariba::utility::Demultiplexer;
00093 using ariba::utility::QoSParameterSet;
00094 using ariba::utility::SecurityParameterSet;
00095 using ariba::utility::Address;
00096 using ariba::utility::LinkID;
00097 using ariba::utility::LinkIDs;
00098 using ariba::utility::Message;
00099 using ariba::utility::MessageReceiver;
00100 using ariba::utility::seqnum_t;
00101
00102 using ariba::communication::TransportProtocol;
00103 using ariba::communication::NetworkProtocol;
00104 using ariba::communication::NetworkLocator;
00105 #ifndef UNDERLAY_OMNET
00106 using ariba::communication::IPv4NetworkProtocol;
00107 using ariba::communication::TCPTransport;
00108 #endif
00109
00110 namespace ariba {
00111 namespace communication {
00112
00121 class BaseCommunication : public MessageReceiver, NetworkChangeInterface {
00122 use_logging_h(BaseCommunication);
00123 public:
00124
00129 BaseCommunication();
00130
00134 virtual ~BaseCommunication();
00135
00139 void start(const NetworkLocator* _locallocator, const uint16_t _listenport);
00140
00144 void stop();
00145
00149 const LinkID establishLink(
00150 const EndpointDescriptor& descriptor,
00151 const LinkID& linkid = LinkID::UNSPECIFIED,
00152 const QoSParameterSet& qos = QoSParameterSet::DEFAULT,
00153 const SecurityParameterSet& sec = SecurityParameterSet::DEFAULT
00154 );
00155
00161 void dropLink(const LinkID link);
00162
00170 seqnum_t sendMessage(const LinkID lid, const Message* message);
00171
00178 const EndpointDescriptor& getEndpointDescriptor( const LinkID link = LinkID::UNSPECIFIED ) const;
00179
00186 LinkIDs getLocalLinks( const EndpointDescriptor& ep = EndpointDescriptor::UNSPECIFIED ) const;
00187
00193 void registerMessageReceiver( MessageReceiver* _receiver );
00194
00200 void unregisterMessageReceiver( MessageReceiver* _receiver );
00201
00202 void registerEventListener( CommunicationEvents* _events );
00203 void unregisterEventListener( CommunicationEvents* _events );
00204
00205 protected:
00206
00211 virtual bool receiveMessage( const Message* message, const LinkID& link, const NodeID& node );
00212
00216 virtual void onNetworkChange( const NetworkChangeInterface::NetworkChangeInfo& info );
00217
00218 private:
00219
00225 class LinkDescriptor {
00226 public:
00227 static const LinkDescriptor UNSPECIFIED;
00228
00229 LinkDescriptor() :
00230 localLink(),
00231 localLocator(NULL),
00232 remoteLink(),
00233 remoteLocator(NULL),
00234 remoteEndpoint(EndpointDescriptor::UNSPECIFIED),
00235 linkup(false) {
00236 }
00237
00238 LinkDescriptor(const LinkID& _localLink, const NetworkLocator*& _localLocator,
00239 const LinkID& _remoteLink, const NetworkLocator*& _remoteLocator,
00240 const EndpointDescriptor& _remoteEndpoint, bool _linkup ) :
00241 localLink(_localLink),
00242 localLocator(_localLocator),
00243 remoteLink(_remoteLink),
00244 remoteLocator(_remoteLocator),
00245 remoteEndpoint(_remoteEndpoint),
00246 linkup(_linkup) {
00247 }
00248
00249 LinkDescriptor( const LinkDescriptor& desc ) :
00250 localLink(desc.localLink),
00251 localLocator(desc.localLocator),
00252 remoteLink(desc.remoteLink),
00253 remoteLocator(desc.remoteLocator),
00254 remoteEndpoint(desc.remoteEndpoint),
00255 linkup(desc.linkup) {
00256 }
00257
00258 bool isUnspecified() const {
00259 return (this == &UNSPECIFIED);
00260 }
00261
00262 LinkID localLink;
00263 const NetworkLocator* localLocator;
00264 LinkID remoteLink;
00265 const NetworkLocator* remoteLocator;
00266 EndpointDescriptor remoteEndpoint;
00267
00268 bool linkup;
00269 };
00270
00274 void addLink( const LinkDescriptor& link );
00275
00279 void removeLink( const LinkID& localLink );
00280
00284 LinkDescriptor& queryLocalLink( const LinkID& localLink ) const;
00285
00289 LinkDescriptor& queryRemoteLink( const LinkID& remoteLink ) const;
00290
00294 typedef vector<LinkDescriptor> LinkSet;
00295
00299 LinkSet linkSet;
00300
00304 MessageReceiver* messageReceiver;
00305
00309 EndpointDescriptor localDescriptor;
00310
00314 NetworkProtocol* network;
00315
00319 TransportProtocol* transport;
00320
00321 #ifndef UNDERLAY_OMNET
00322
00326 NetworkChangeDetection networkMonitor;
00327 #endif
00328
00332 uint16_t listenport;
00333
00334 typedef set<CommunicationEvents*> EventListenerSet;
00335 EventListenerSet eventListener;
00336
00337 seqnum_t currentSeqnum;
00338 };
00339
00340 }}
00341
00342 #endif