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
00043 #include <ext/hash_map>
00044 #include <ext/hash_set>
00045 #include <map>
00046 #include <set>
00047 #include <vector>
00048 #include <iostream>
00049 #include <algorithm>
00050 #include <boost/foreach.hpp>
00051
00052
00053 #include "ariba/utility/types.h"
00054 #include "ariba/utility/messages.h"
00055 #include "ariba/utility/logging/Logging.h"
00056 #include "ariba/utility/misc/Demultiplexer.hpp"
00057 #include "ariba/utility/system/SystemEventListener.h"
00058
00059
00060 #include "ariba/utility/addressing/addressing.hpp"
00061 #include "ariba/utility/transport/transport.hpp"
00062
00063
00064 #include "ariba/communication/CommunicationEvents.h"
00065 #include "ariba/communication/EndpointDescriptor.h"
00066 #include "ariba/communication/messages/AribaBaseMsg.h"
00067
00068
00069 #include "ariba/communication/networkinfo/NetworkChangeInterface.h"
00070 #include "ariba/communication/networkinfo/NetworkChangeDetection.h"
00071 #include "ariba/communication/networkinfo/NetworkInformation.h"
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 namespace ariba {
00082 class SideportListener;
00083 }
00084
00085 namespace ariba {
00086 namespace communication {
00087
00088 using namespace std;
00089 using namespace ariba::addressing;
00090 using namespace ariba::transport;
00091 using namespace ariba::utility;
00092
00093
00094 using ariba::utility::Message;
00095 using ariba::utility::seqnum_t;
00096
00105 class BaseCommunication:
00106 public NetworkChangeInterface,
00107 public SystemEventListener,
00108 public transport_listener {
00109
00110 use_logging_h(BaseCommunication);
00111 friend class ariba::SideportListener;
00112
00113 public:
00115 BaseCommunication();
00116
00118 virtual ~BaseCommunication();
00119
00121 void start();
00122
00124 void stop();
00125
00127 void setEndpoints( string& endpoints );
00128
00130 bool isStarted();
00131
00133 const LinkID establishLink(const EndpointDescriptor& descriptor,
00134 const LinkID& linkid = LinkID::UNSPECIFIED, const QoSParameterSet& qos =
00135 QoSParameterSet::DEFAULT, const SecurityParameterSet& sec =
00136 SecurityParameterSet::DEFAULT);
00137
00139 void dropLink(const LinkID link);
00140
00148 seqnum_t sendMessage(const LinkID lid, const Message* message);
00149
00156 const EndpointDescriptor& getEndpointDescriptor(const LinkID link =
00157 LinkID::UNSPECIFIED) const;
00158
00165 LinkIDs getLocalLinks(const address_v* addr) const;
00166
00172 void registerMessageReceiver(MessageReceiver* receiver) {
00173 messageReceiver = receiver;
00174 }
00175
00181 void unregisterMessageReceiver(MessageReceiver* receiver) {
00182 messageReceiver = NULL;
00183 }
00184
00185 void registerEventListener(CommunicationEvents* _events);
00186
00187 void unregisterEventListener(CommunicationEvents* _events);
00188
00190 virtual void handleSystemEvent(const SystemEvent& event);
00191
00193 virtual void receive_message(transport_protocol* transport,
00194 const address_vf local, const address_vf remote, const uint8_t* data,
00195 size_t size);
00196
00197 protected:
00198
00200 void receiveMessage(const Message* message,
00201 const address_v* local, const address_v* remote );
00202
00204 virtual void onNetworkChange(
00205 const NetworkChangeInterface::NetworkChangeInfo& info);
00206
00207 private:
00212 class LinkDescriptor {
00213 public:
00214
00216 LinkDescriptor() :
00217 localLink(LinkID::UNSPECIFIED), localLocator(NULL),
00218 remoteLink(LinkID::UNSPECIFIED), remoteLocator(NULL),
00219 up(false) {
00220 }
00221
00222 ~LinkDescriptor() {
00223 if (localLocator!=NULL) delete localLocator;
00224 if (remoteLocator!=NULL) delete remoteLocator;
00225 }
00226
00227 bool isUnspecified() const {
00228 return (this == &UNSPECIFIED());
00229 }
00230
00231 static LinkDescriptor& UNSPECIFIED(){
00232 static LinkDescriptor* unspec = NULL;
00233 if(unspec == NULL) unspec = new LinkDescriptor();
00234 return *unspec;
00235 }
00236
00237 bool unspecified;
00238
00240 LinkID localLink;
00241 LinkID remoteLink;
00242
00244 const address_v* localLocator;
00245 const address_v* remoteLocator;
00246
00248 EndpointDescriptor remoteEndpoint;
00249
00251 bool up;
00252 };
00253
00255 typedef vector<LinkDescriptor*> LinkSet;
00256
00258 LinkSet linkSet;
00259
00261 void addLink( LinkDescriptor* link );
00262
00264 void removeLink(const LinkID& localLink);
00265
00267 LinkDescriptor& queryLocalLink(const LinkID& localLink) const;
00268
00270 LinkDescriptor& queryRemoteLink(const LinkID& remoteLink) const;
00271
00273 EndpointDescriptor localDescriptor;
00274
00275 #ifndef UNDERLAY_OMNET
00277 NetworkChangeDetection networkMonitor;
00278 #endif
00280 class endpoint_reference {
00281 public:
00282 int count;
00283 const address_v* endpoint;
00284 };
00285 vector<endpoint_reference> remote_endpoints;
00286
00288 void add_endpoint( const address_v* endpoint );
00289
00291 void remove_endpoint( const address_v* endpoint );
00292
00294 typedef set<CommunicationEvents*> EventListenerSet;
00295 EventListenerSet eventListener;
00296
00298 seqnum_t currentSeqnum;
00299
00301 transport_peer* transport;
00302
00304 MessageReceiver* messageReceiver;
00305
00307 void send( Message* message, const EndpointDescriptor& endpoint );
00308 void send( Message* message, const LinkDescriptor& descriptor );
00309
00310
00311
00313 bool started;
00314
00315 };
00316
00317 }}
00318
00319 #endif