Changeset 5284 for source/ariba/communication/BaseCommunication.h
- Timestamp:
- Jul 24, 2009, 3:23:11 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
source/ariba/communication/BaseCommunication.h
r4983 r5284 40 40 #define BASECOMMUNICATION_H_ 41 41 42 // boost & std includes 42 43 #include <ext/hash_map> 43 44 #include <ext/hash_set> … … 49 50 #include <boost/foreach.hpp> 50 51 52 // utilities 51 53 #include "ariba/utility/types.h" 52 54 #include "ariba/utility/messages.h" 53 55 #include "ariba/utility/logging/Logging.h" 54 56 #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 56 64 #include "ariba/communication/CommunicationEvents.h" 57 65 #include "ariba/communication/EndpointDescriptor.h" 66 #include "ariba/communication/messages/AribaBaseMsg.h" 67 68 // network changes 58 69 #include "ariba/communication/networkinfo/NetworkChangeInterface.h" 59 70 #include "ariba/communication/networkinfo/NetworkChangeDetection.h" 60 71 #include "ariba/communication/networkinfo/NetworkInformation.h" 61 72 #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 109 95 110 96 namespace ariba { 111 97 namespace communication { 98 99 using namespace std; 100 using namespace ariba::addressing; 101 using namespace ariba::transport; 102 using namespace ariba::utility; 103 104 // use base ariba types (clarifies multiple definitions) 105 using ariba::utility::Message; 106 using ariba::utility::seqnum_t; 112 107 113 108 /** … … 119 114 * @author Sebastian Mies, Christoph Mayer 120 115 */ 121 class BaseCommunication : public MessageReceiver, NetworkChangeInterface { 116 class BaseCommunication: public NetworkChangeInterface, 117 public SystemEventListener, public transport_listener { 122 118 use_logging_h(BaseCommunication); 119 123 120 public: 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 129 122 BaseCommunication(); 130 123 131 /** 132 * Default dtor that does nothing 133 */ 124 /// Default dtor that does nothing 134 125 virtual ~BaseCommunication(); 135 126 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. 144 131 void stop(); 145 132 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 149 137 bool isStarted(); 150 138 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 167 146 void dropLink(const LinkID link); 168 147 … … 182 161 * @return The end-point descriptor of the link's end-point 183 162 */ 184 const EndpointDescriptor& getEndpointDescriptor( const LinkID link = LinkID::UNSPECIFIED ) const; 163 const EndpointDescriptor& getEndpointDescriptor(const LinkID link = 164 LinkID::UNSPECIFIED) const; 185 165 186 166 /** … … 190 170 * @return List of LinkID 191 171 */ 192 LinkIDs getLocalLinks( const EndpointDescriptor& ep = EndpointDescriptor::UNSPECIFIED) const;172 LinkIDs getLocalLinks(const address_v* addr) const; 193 173 194 174 /** … … 197 177 * @param _receiver The receiving side 198 178 */ 199 void registerMessageReceiver( MessageReceiver* _receiver ); 179 void registerMessageReceiver(MessageReceiver* receiver) { 180 messageReceiver = receiver; 181 } 200 182 201 183 /** … … 204 186 * @param _receiver The receiving side 205 187 */ 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 196 public: 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); 210 205 211 206 protected: 212 207 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); 223 215 224 216 private: 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. 230 220 */ 231 221 class LinkDescriptor { … … 233 223 static const LinkDescriptor UNSPECIFIED; 234 224 225 /// default constructor 235 226 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) { 242 230 } 243 231 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; 253 235 } 254 236 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; 262 240 } 263 241 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; 275 255 }; 276 256 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 305 261 LinkSet linkSet; 306 262 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 315 276 EndpointDescriptor localDescriptor; 316 277 317 /**318 * Network information and protocol319 */320 NetworkProtocol* network;321 322 /**323 * Transport information and protocol324 */325 TransportProtocol* transport;326 327 278 #ifndef UNDERLAY_OMNET 328 /** 329 * Detect changes in the routing/interface, etc. 330 * stuff needed for mobility detection 331 */ 279 /// network change detector 332 280 NetworkChangeDetection networkMonitor; 333 281 #endif 334 335 /** 336 * The local listen port 337 */ 338 uint16_t listenport; 339 282 /// event listener 340 283 typedef set<CommunicationEvents*> EventListenerSet; 341 284 EventListenerSet eventListener; 342 285 286 /// sequence numbers 343 287 seqnum_t currentSeqnum; 344 288 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; 349 301 350 302 }; … … 352 304 }} // namespace ariba, communication 353 305 354 #endif /* BASECOMMUNICATION_H_*/306 #endif /* BASECOMMUNICATION_H_ */
Note:
See TracChangeset
for help on using the changeset viewer.