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

Last change on this file since 3690 was 3690, checked in by mies, 16 years ago

Merged 20090512-mies-connectors changes r3472:r3689 into trunk.

File size: 9.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#include <ext/hash_map>
43#include <ext/hash_set>
44#include <map>
45#include <set>
46#include <vector>
47#include <iostream>
48#include <deque>
49#include <algorithm>
50#include <boost/foreach.hpp>
51
52#include "ariba/utility/types.h"
53#include "ariba/utility/messages.h"
54#include "ariba/utility/logging/Logging.h"
55#include "ariba/utility/misc/Demultiplexer.hpp"
56
57#include "ariba/communication/CommunicationEvents.h"
58#include "ariba/communication/EndpointDescriptor.h"
59#include "ariba/communication/networkinfo/NetworkChangeInterface.h"
60#include "ariba/communication/networkinfo/NetworkChangeDetection.h"
61#include "ariba/communication/networkinfo/NetworkInformation.h"
62#include "ariba/communication/networkinfo/AddressInformation.h"
63#include "ariba/communication/messages/AribaBaseMsg.h"
64#include "ariba/communication/modules/transport/TransportProtocol.h"
65#include "ariba/communication/modules/network/NetworkProtocol.h"
66#include "ariba/communication/modules/network/NetworkLocator.h"
67
68#ifndef UNDERLAY_OMNET
69 #include "ariba/communication/modules/transport/tcp/TCPTransport.h"
70 #include "ariba/communication/modules/network/ip/IPv4NetworkProtocol.h"
71#endif
72
73using __gnu_cxx::hash_set;
74using __gnu_cxx::hash_map;
75
76using std::cout;
77using std::set;
78using std::map;
79using std::vector;
80using std::deque;
81using std::pair;
82using std::make_pair;
83using std::find;
84
85using ariba::communication::NetworkChangeDetection;
86using ariba::communication::NetworkChangeInterface;
87using ariba::communication::NetworkInterfaceList;
88using ariba::communication::NetworkInformation;
89using ariba::communication::AddressInformation;
90using ariba::communication::AddressList;
91using ariba::communication::AribaBaseMsg;
92using ariba::communication::CommunicationEvents;
93
94using ariba::utility::Demultiplexer;
95using ariba::utility::QoSParameterSet;
96using ariba::utility::SecurityParameterSet;
97using ariba::utility::Address;
98using ariba::utility::LinkID;
99using ariba::utility::LinkIDs;
100using ariba::utility::Message;
101using ariba::utility::MessageReceiver;
102using ariba::utility::seqnum_t;
103
104using ariba::communication::TransportProtocol;
105using ariba::communication::NetworkProtocol;
106using ariba::communication::NetworkLocator;
107#ifndef UNDERLAY_OMNET
108 using ariba::communication::IPv4NetworkProtocol;
109 using ariba::communication::TCPTransport;
110#endif
111
112namespace ariba {
113namespace communication {
114
115/**
116 * This class implements the Ariba Base Communication<br />
117 *
118 * Its primary task is to provide an abstraction to existing
119 * protocols and addressing schemes.
120 *
121 * @author Sebastian Mies, Christoph Mayer
122 */
123class BaseCommunication : public MessageReceiver, NetworkChangeInterface {
124 use_logging_h(BaseCommunication);
125public:
126
127 /**
128 * Default ctor that just creates an empty
129 * non functional base communication
130 */
131 BaseCommunication();
132
133 /**
134 * Default dtor that does nothing
135 */
136 virtual ~BaseCommunication();
137
138 /**
139 * Startup the base communication, start modules etc.
140 */
141 void start(const NetworkLocator* _locallocator, const uint16_t _listenport);
142
143 /**
144 * stop the base communication, stop modules etc.
145 */
146 void stop();
147
148 /**
149 * Establishes a link to another end-point.
150 */
151 const LinkID establishLink(
152 const EndpointDescriptor& descriptor,
153 const LinkID& linkid = LinkID::UNSPECIFIED,
154 const QoSParameterSet& qos = QoSParameterSet::DEFAULT,
155 const SecurityParameterSet& sec = SecurityParameterSet::DEFAULT
156 );
157
158 /**
159 * Drops a link.
160 *
161 * @param The link id of the link that should be dropped
162 */
163 void dropLink(const LinkID link);
164
165 /**
166 * Sends a message though an existing link to an end-point.
167 *
168 * @param lid The link identifier
169 * @param message The message to be sent
170 * @return A sequence number for this message
171 */
172 seqnum_t sendMessage(const LinkID lid, const Message* message);
173
174 /**
175 * Returns the end-point descriptor
176 *
177 * @param link the link id of the requested end-point
178 * @return The end-point descriptor of the link's end-point
179 */
180 const EndpointDescriptor& getEndpointDescriptor( const LinkID link = LinkID::UNSPECIFIED ) const;
181
182 /**
183 * Get local links to the given endpoint of all local link
184 * using the default parameter EndpointDescriptor::UNSPECIFIED
185 * @param ep The remote endpoint to get all links to.
186 * @return List of LinkID
187 */
188 LinkIDs getLocalLinks( const EndpointDescriptor& ep = EndpointDescriptor::UNSPECIFIED ) const;
189
190 /**
191 * Registers a receiver.
192 *
193 * @param _receiver The receiving side
194 */
195 void registerMessageReceiver( MessageReceiver* _receiver );
196
197 /**
198 * Unregister a receiver.
199 *
200 * @param _receiver The receiving side
201 */
202 void unregisterMessageReceiver( MessageReceiver* _receiver );
203
204 void registerEventListener( CommunicationEvents* _events );
205 void unregisterEventListener( CommunicationEvents* _events );
206
207protected:
208
209 /**
210 * Called from the Transport when async items
211 * from the SystemQueue are delivered
212 */
213 virtual bool receiveMessage( const Message* message, const LinkID& link, const NodeID& node );
214
215 /**
216 * Called when a network interface change happens
217 */
218 virtual void onNetworkChange( const NetworkChangeInterface::NetworkChangeInfo& info );
219
220private:
221
222 /**
223 * A link descriptor consisting of the
224 * end-point descriptor and currently used locator and
225 * message receiver
226 */
227 class LinkDescriptor {
228 public:
229 static const LinkDescriptor UNSPECIFIED;
230
231 LinkDescriptor() :
232 localLink(),
233 localLocator(NULL),
234 remoteLink(),
235 remoteLocator(NULL),
236 remoteEndpoint(EndpointDescriptor::UNSPECIFIED),
237 linkup(false) {
238 }
239
240 LinkDescriptor(const LinkID& _localLink, const NetworkLocator*& _localLocator,
241 const LinkID& _remoteLink, const NetworkLocator*& _remoteLocator,
242 const EndpointDescriptor& _remoteEndpoint, bool _linkup ) :
243 localLink(_localLink),
244 localLocator(_localLocator),
245 remoteLink(_remoteLink),
246 remoteLocator(_remoteLocator),
247 remoteEndpoint(_remoteEndpoint),
248 linkup(_linkup) {
249 }
250
251 LinkDescriptor( const LinkDescriptor& desc ) :
252 localLink(desc.localLink),
253 localLocator(desc.localLocator),
254 remoteLink(desc.remoteLink),
255 remoteLocator(desc.remoteLocator),
256 remoteEndpoint(desc.remoteEndpoint),
257 linkup(desc.linkup) {
258
259 BOOST_FOREACH( Message* msg, desc.waitingmsg ){
260 waitingmsg.push_back( msg );
261 }
262 }
263
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;
275 deque<Message*> waitingmsg;
276 };
277
278 /**
279 * Link management: add a link
280 */
281 void addLink( const LinkDescriptor& link );
282
283 /**
284 * Link management: remove alink
285 */
286 void removeLink( const LinkID& localLink );
287
288 /**
289 * Link management: get link information using the local link
290 */
291 LinkDescriptor& queryLocalLink( const LinkID& localLink ) const;
292
293 /**
294 * Link management: get link information using the remote link
295 */
296 LinkDescriptor& queryRemoteLink( const LinkID& remoteLink ) const;
297
298 /**
299 * Link management: list of links
300 */
301 typedef vector<LinkDescriptor> LinkSet;
302
303 /**
304 * Link management: the set of currently managed links
305 */
306 LinkSet linkSet;
307
308 /**
309 * The message receiver
310 */
311 MessageReceiver* messageReceiver;
312
313 /**
314 * The local end-point descriptor
315 */
316 EndpointDescriptor localDescriptor;
317
318 /**
319 * Network information and protocol
320 */
321 NetworkProtocol* network;
322
323 /**
324 * Transport information and protocol
325 */
326 TransportProtocol* transport;
327
328#ifndef UNDERLAY_OMNET
329 /**
330 * Detect changes in the routing/interface, etc.
331 * stuff needed for mobility detection
332 */
333 NetworkChangeDetection networkMonitor;
334#endif
335
336 /**
337 * The local listen port
338 */
339 uint16_t listenport;
340
341 typedef set<CommunicationEvents*> EventListenerSet;
342 EventListenerSet eventListener;
343
344 seqnum_t currentSeqnum;
345};
346
347}} // namespace ariba, communication
348
349#endif /*BASECOMMUNICATION_H_*/
Note: See TracBrowser for help on using the repository browser.