source: source/ariba/communication/BaseCommunication.h@ 5860

Last change on this file since 5860 was 5767, checked in by Christoph Mayer, 15 years ago

major gui update

File size: 9.6 KB
Line 
1// [License]
2// The Ariba-Underlay Copyright
3//
4// Copyright (c) 2008-2009, Institute of Telematics, UniversitÀt Karlsruhe (TH)
5//
6// Institute of Telematics
7// UniversitÀt Karlsruhe (TH)
8// Zirkel 2, 76128 Karlsruhe
9// Germany
10//
11// Redistribution and use in source and binary forms, with or without
12// modification, are permitted provided that the following conditions are
13// met:
14//
15// 1. Redistributions of source code must retain the above copyright
16// notice, this list of conditions and the following disclaimer.
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// THIS SOFTWARE IS PROVIDED BY THE INSTITUTE OF TELEMATICS ``AS IS'' AND
22// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ARIBA PROJECT OR
25// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32//
33// The views and conclusions contained in the software and documentation
34// are those of the authors and should not be interpreted as representing
35// official policies, either expressed or implied, of the Institute of
36// Telematics.
37// [License]
38
39#ifndef BASECOMMUNICATION_H_
40#define BASECOMMUNICATION_H_
41
42// boost & std includes
43#include <ext/hash_map>
44#include <ext/hash_set>
45#include <map>
46#include <set>
47#include <vector>
48#include <iostream>
49#include <algorithm>
50#include <boost/foreach.hpp>
51
52// utilities
53#include "ariba/utility/types.h"
54#include "ariba/utility/messages.h"
55#include "ariba/utility/logging/Logging.h"
56#include "ariba/utility/misc/Demultiplexer.hpp"
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
64#include "ariba/communication/CommunicationEvents.h"
65#include "ariba/communication/EndpointDescriptor.h"
66#include "ariba/communication/messages/AribaBaseMsg.h"
67
68// network changes
69#include "ariba/communication/networkinfo/NetworkChangeInterface.h"
70#include "ariba/communication/networkinfo/NetworkChangeDetection.h"
71#include "ariba/communication/networkinfo/NetworkInformation.h"
72#include "ariba/communication/networkinfo/AddressInformation.h"
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
95
96namespace ariba {
97 class SideportListener;
98}
99
100namespace ariba {
101namespace communication {
102
103using namespace std;
104using namespace ariba::addressing;
105using namespace ariba::transport;
106using namespace ariba::utility;
107
108// use base ariba types (clarifies multiple definitions)
109using ariba::utility::Message;
110using ariba::utility::seqnum_t;
111
112/**
113 * This class implements the Ariba Base Communication<br />
114 *
115 * Its primary task is to provide an abstraction to existing
116 * protocols and addressing schemes.
117 *
118 * @author Sebastian Mies, Christoph Mayer
119 */
120class BaseCommunication:
121 public NetworkChangeInterface,
122 public SystemEventListener,
123 public transport_listener {
124
125 use_logging_h(BaseCommunication);
126 friend class ariba::SideportListener;
127
128public:
129 /// Default ctor that just creates an non-functional base communication
130 BaseCommunication();
131
132 /// Default dtor that does nothing
133 virtual ~BaseCommunication();
134
135 /// Startup the base communication, start modules etc.
136 void start();
137
138 /// Stops the base communication, stop modules etc.
139 void stop();
140
141 /// Sets the endpoints
142 void setEndpoints( string& endpoints );
143
144 /// Check whether the base communication has been started up
145 bool isStarted();
146
147 /// Establishes a link to another end-point.
148 const LinkID establishLink(const EndpointDescriptor& descriptor,
149 const LinkID& linkid = LinkID::UNSPECIFIED, const QoSParameterSet& qos =
150 QoSParameterSet::DEFAULT, const SecurityParameterSet& sec =
151 SecurityParameterSet::DEFAULT);
152
153 /// Drops a link
154 void dropLink(const LinkID link);
155
156 /**
157 * Sends a message though an existing link to an end-point.
158 *
159 * @param lid The link identifier
160 * @param message The message to be sent
161 * @return A sequence number for this message
162 */
163 seqnum_t sendMessage(const LinkID lid, const Message* message);
164
165 /**
166 * Returns the end-point descriptor
167 *
168 * @param link the link id of the requested end-point
169 * @return The end-point descriptor of the link's end-point
170 */
171 const EndpointDescriptor& getEndpointDescriptor(const LinkID link =
172 LinkID::UNSPECIFIED) const;
173
174 /**
175 * Get local links to the given endpoint of all local link
176 * using the default parameter EndpointDescriptor::UNSPECIFIED
177 * @param ep The remote endpoint to get all links to.
178 * @return List of LinkID
179 */
180 LinkIDs getLocalLinks(const address_v* addr) const;
181
182 /**
183 * Registers a receiver.
184 *
185 * @param _receiver The receiving side
186 */
187 void registerMessageReceiver(MessageReceiver* receiver) {
188 messageReceiver = receiver;
189 }
190
191 /**
192 * Unregister a receiver.
193 *
194 * @param _receiver The receiving side
195 */
196 void unregisterMessageReceiver(MessageReceiver* receiver) {
197 messageReceiver = NULL;
198 }
199
200 void registerEventListener(CommunicationEvents* _events);
201
202 void unregisterEventListener(CommunicationEvents* _events);
203
204 /// called when a system event is emitted by system queue
205 virtual void handleSystemEvent(const SystemEvent& event);
206
207 /// called when a message is received form transport_peer
208 virtual void receive_message(transport_protocol* transport,
209 const address_vf local, const address_vf remote, const uint8_t* data,
210 size_t size);
211
212protected:
213
214 /// handle received message from a transport module
215 void receiveMessage(const Message* message,
216 const address_v* local, const address_v* remote );
217
218 /// called when a network interface change happens
219 virtual void onNetworkChange(
220 const NetworkChangeInterface::NetworkChangeInfo& info);
221
222private:
223 /**
224 * A link descriptor consisting of the end-point descriptor and currently
225 * used underlay address.
226 */
227 class LinkDescriptor {
228 public:
229
230 /// default constructor
231 LinkDescriptor() :
232 localLink(LinkID::UNSPECIFIED), localLocator(NULL),
233 remoteLink(LinkID::UNSPECIFIED), remoteLocator(NULL),
234 up(false) {
235 }
236
237 ~LinkDescriptor() {
238 if (localLocator!=NULL) delete localLocator;
239 if (remoteLocator!=NULL) delete remoteLocator;
240 }
241
242 bool isUnspecified() const {
243 return (this == &UNSPECIFIED());
244 }
245
246 static LinkDescriptor& UNSPECIFIED(){
247 static LinkDescriptor* unspec = NULL;
248 if(unspec == NULL) unspec = new LinkDescriptor();
249 return *unspec;
250 }
251
252 bool unspecified;
253
254 /// link identifiers
255 LinkID localLink;
256 LinkID remoteLink;
257
258 /// used underlay addresses for the link
259 const address_v* localLocator;
260 const address_v* remoteLocator;
261
262 /// the remote end-point descriptor
263 EndpointDescriptor remoteEndpoint;
264
265 /// flag, whether this link is up
266 bool up;
267 };
268
269 /// Link management: list of links
270 typedef vector<LinkDescriptor*> LinkSet;
271
272 /// Link management: the set of currently managed links
273 LinkSet linkSet;
274
275 /// Link management: add a link
276 void addLink( LinkDescriptor* link );
277
278 /// Link management: remove a link
279 void removeLink(const LinkID& localLink);
280
281 /// Link management: get link information using the local link
282 LinkDescriptor& queryLocalLink(const LinkID& localLink) const;
283
284 /// Link management: get link information using the remote link
285 LinkDescriptor& queryRemoteLink(const LinkID& remoteLink) const;
286
287 /// The local end-point descriptor
288 EndpointDescriptor localDescriptor;
289
290#ifndef UNDERLAY_OMNET
291 /// network change detector
292 NetworkChangeDetection networkMonitor;
293#endif
294 /// list of all remote addresses of links to end-points
295 class endpoint_reference {
296 public:
297 int count; ///< the number of open links to this end-point
298 const address_v* endpoint; ///< the end-point itself
299 };
300 vector<endpoint_reference> remote_endpoints;
301
302 /// adds an end-point to the list
303 void add_endpoint( const address_v* endpoint );
304
305 /// removes an end-point from the list
306 void remove_endpoint( const address_v* endpoint );
307
308 /// event listener
309 typedef set<CommunicationEvents*> EventListenerSet;
310 EventListenerSet eventListener;
311
312 /// sequence numbers
313 seqnum_t currentSeqnum;
314
315 /// transport peer
316 transport_peer* transport;
317
318 /// the base overlay message receiver
319 MessageReceiver* messageReceiver;
320
321 /// convenience: send message to peer
322 void send( Message* message, const EndpointDescriptor& endpoint );
323 void send( Message* message, const LinkDescriptor& descriptor );
324
325
326
327 /// state of the base communication
328 bool started;
329
330};
331
332}} // namespace ariba, communication
333
334#endif /* BASECOMMUNICATION_H_ */
Note: See TracBrowser for help on using the repository browser.