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

Last change on this file since 9684 was 9684, checked in by mies, 13 years ago

almost forgot to commit: doxygen modules :)

File size: 8.5 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 <boost/unordered_map.hpp>
44#include <boost/unordered_set.hpp>
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
73// disabled
74//#ifndef UNDERLAY_OMNET
75// #include "ariba/communication/modules/transport/tcp/TCPTransport.h"
76// #include "ariba/communication/modules/network/ip/IPv4NetworkProtocol.h"
77// using ariba::communication::IPv4NetworkProtocol;
78// using ariba::communication::TCPTransport;
79//#endif
80
81namespace ariba {
82 class SideportListener;
83}
84
85namespace ariba {
86namespace communication {
87
88using namespace std;
89using namespace ariba::addressing;
90using namespace ariba::transport;
91using namespace ariba::utility;
92
93// use base ariba types (clarifies multiple definitions)
94using ariba::utility::Message;
95using ariba::utility::seqnum_t;
96
97/**
98 * This class implements the Ariba Base Communication<br />
99 *
100 * Its primary task is to provide an abstraction to existing
101 * protocols and addressing schemes.
102 *
103 * @author Sebastian Mies, Christoph Mayer
104 */
105class BaseCommunication:
106 public NetworkChangeInterface,
107 public SystemEventListener,
108 public transport_listener {
109
110 use_logging_h(BaseCommunication);
111 friend class ariba::SideportListener;
112
113public:
114 /// Default ctor that just creates an non-functional base communication
115 BaseCommunication();
116
117 /// Default dtor that does nothing
118 virtual ~BaseCommunication();
119
120 /// Startup the base communication, start modules etc.
121 void start();
122
123 /// Stops the base communication, stop modules etc.
124 void stop();
125
126 /// Sets the endpoints
127 void setEndpoints( string& endpoints );
128
129 /// Check whether the base communication has been started up
130 bool isStarted();
131
132 /// Establishes a link to another end-point.
133 const LinkID establishLink(const EndpointDescriptor& descriptor );
134
135 /// Drops a link
136 void dropLink( LinkID link );
137
138 /**
139 * Sends a message though an existing link to an end-point.
140 *
141 * @param lid The link identifier
142 * @param message The message to be sent
143 * @return A sequence number for this message
144 */
145 seqnum_t sendMessage( LinkID lid, const Message* message );
146
147 /**
148 * Returns the end-point descriptor
149 *
150 * @param link the link id of the requested end-point
151 * @return The end-point descriptor of the link's end-point
152 */
153 const EndpointDescriptor& getEndpointDescriptor(
154 LinkID link = LinkID::UNSPECIFIED) const;
155
156 /**
157 * Get local links to the given endpoint of all local link
158 * using the default parameter EndpointDescriptor::UNSPECIFIED
159 * @param ep The remote endpoint to get all links to.
160 * @return List of LinkID
161 */
162 LinkIDs getLocalLinks(const address_v* addr) const;
163
164 /**
165 * Registers a receiver.
166 *
167 * @param _receiver The receiving side
168 */
169 void registerMessageReceiver(MessageReceiver* receiver) {
170 messageReceiver = receiver;
171 }
172
173 /**
174 * Unregister a receiver.
175 *
176 * @param _receiver The receiving side
177 */
178 void unregisterMessageReceiver(MessageReceiver* receiver) {
179 messageReceiver = NULL;
180 }
181
182 void registerEventListener(CommunicationEvents* _events);
183
184 void unregisterEventListener(CommunicationEvents* _events);
185
186 /// called when a system event is emitted by system queue
187 virtual void handleSystemEvent(const SystemEvent& event);
188
189 /// called when a message is received form transport_peer
190 virtual void receive_message(transport_protocol* transport,
191 const address_vf local, const address_vf remote, const uint8_t* data,
192 size_t size);
193
194protected:
195
196 /// handle received message from a transport module
197 void receiveMessage(const Message* message,
198 const address_v* local, const address_v* remote );
199
200 /// called when a network interface change happens
201 virtual void onNetworkChange(
202 const NetworkChangeInterface::NetworkChangeInfo& info);
203
204private:
205 /**
206 * A link descriptor consisting of the end-point descriptor and currently
207 * used underlay address.
208 */
209 class LinkDescriptor {
210 public:
211 /// default constructor
212 LinkDescriptor() : up(false), id(), localLocator(NULL), remoteLocator(NULL) {}
213
214 ~LinkDescriptor() {
215 if (localLocator!=NULL) delete localLocator;
216 if (remoteLocator!=NULL) delete remoteLocator;
217 }
218
219 bool isUnspecified() const {
220 return id.isUnspecified();
221 }
222
223 /// flag, whether this link is up
224 bool up;
225
226 /// link identifier
227 LinkID id;
228
229 /// locators
230 const address_v* localLocator;
231 const address_v* remoteLocator;
232
233 /// the remote end-point descriptor
234 EndpointDescriptor remoteEndpoint;
235 };
236
237 /// Link management: list of links
238 typedef vector<LinkDescriptor*> LinkSet;
239
240 /// Link management: the set of currently managed links
241 LinkSet linkSet;
242
243 /// Link management: add a link
244 LinkDescriptor& addLink( LinkID link );
245
246 /// Link management: remove a link
247 void removeLink( LinkID link);
248
249 /// Link management: get link information using the local link
250 LinkDescriptor& queryLink( LinkID link) const;
251
252 /// The local end-point descriptor
253 EndpointDescriptor localDescriptor;
254
255#ifndef UNDERLAY_OMNET
256 /// network change detector
257 NetworkChangeDetection networkMonitor;
258#endif
259
260 /// list of all remote addresses of links to end-points
261 class endpoint_reference {
262 public:
263 int count; ///< the number of open links to this end-point
264 const address_v* endpoint; ///< the end-point itself
265 };
266 vector<endpoint_reference> remote_endpoints;
267
268 /// adds an end-point to the list
269 void add_endpoint( const address_v* endpoint );
270
271 /// removes an end-point from the list
272 void remove_endpoint( const address_v* endpoint );
273
274 /// event listener
275 typedef set<CommunicationEvents*> EventListenerSet;
276 EventListenerSet eventListener;
277
278 /// sequence numbers
279 seqnum_t currentSeqnum;
280
281 /// transport peer
282 transport_peer* transport;
283
284 /// the base overlay message receiver
285 MessageReceiver* messageReceiver;
286
287 /// convenience: send message to peer
288 void send( Message* message, const EndpointDescriptor& endpoint );
289
290 void send( Message* message, const LinkDescriptor& descriptor );
291
292 /// state of the base communication
293 bool started;
294};
295
296}} // namespace ariba, communication
297
298#endif /* BASECOMMUNICATION_H_ */
Note: See TracBrowser for help on using the repository browser.