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

Last change on this file since 3038 was 3037, checked in by Christoph Mayer, 16 years ago

-jede Menge fixes und Umstellungen
-angefangen ariba/interface los zu werden, erste dateien sind weg

File size: 9.5 KB
Line 
1// [Licence]
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// [Licence]
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 QoSParameterSet& qos = QoSParameterSet::DEFAULT,
154 const SecurityParameterSet& sec = SecurityParameterSet::DEFAULT
155 );
156
157 /**
158 * Drops a link
159 *
160 * @param The link id of the link that should be dropped
161 */
162 void dropLink(const LinkID link);
163
164 /**
165 * Sends a message though an existing link to an end-point.
166 *
167 * @param lid The link identifier
168 * @param message The message to be sent
169 * @return A sequence number for this message
170 */
171 seqnum_t sendMessage(const LinkID lid, const Message* message);
172
173 /**
174 * Returns the end-point descriptor
175 *
176 * @param link the link id of the requested end-point
177 * @return The end-point descriptor of the link's end-point
178 */
179 const EndpointDescriptor& getEndpointDescriptor( const LinkID link = LinkID::UNSPECIFIED ) const;
180
181 /**
182 * Get local links to the given endpoint of all local link
183 * using the default parameter EndpointDescriptor::UNSPECIFIED
184 * @param ep The remote endpoint to get all links to.
185 * @return List of LinkID
186 */
187 LinkIDs getLocalLinks( const EndpointDescriptor& ep = EndpointDescriptor::UNSPECIFIED ) const;
188
189 /**
190 * Registers a receiver.
191 *
192 * @param _receiver The receiving side
193 */
194 void registerMessageReceiver( MessageReceiver* _receiver );
195
196 /**
197 * Unregister a receiver.
198 *
199 * @param _receiver The receiving side
200 */
201 void unregisterMessageReceiver( MessageReceiver* _receiver );
202
203 void registerEventListener( CommunicationEvents* _events );
204 void unregisterEventListener( CommunicationEvents* _events );
205
206protected:
207
208 /**
209 * Called from the Transport when async items
210 * from the SystemQueue are delivered
211 */
212 virtual bool receiveMessage( const Message* message, const LinkID& link, const NodeID& node );
213
214 /**
215 * Called when a network interface change happens
216 */
217 virtual void onNetworkChange( const NetworkChangeInterface::NetworkChangeInfo& info );
218
219private:
220
221 /**
222 * A link descriptor consisting of the
223 * end-point descriptor and currently used locator and
224 * message receiver
225 */
226 class LinkDescriptor {
227 public:
228 static const LinkDescriptor UNSPECIFIED;
229
230 LinkDescriptor() :
231 localLink(),
232 localLocator(NULL),
233 remoteLink(),
234 remoteLocator(NULL),
235 remoteEndpoint(EndpointDescriptor::UNSPECIFIED),
236 linkup(false) {
237 }
238
239 LinkDescriptor(const LinkID& _localLink, const NetworkLocator*& _localLocator,
240 const LinkID& _remoteLink, const NetworkLocator*& _remoteLocator,
241 const EndpointDescriptor& _remoteEndpoint, bool _linkup ) :
242 localLink(_localLink),
243 localLocator(_localLocator),
244 remoteLink(_remoteLink),
245 remoteLocator(_remoteLocator),
246 remoteEndpoint(_remoteEndpoint),
247 linkup(_linkup) {
248 }
249
250 LinkDescriptor( const LinkDescriptor& desc ) :
251 localLink(desc.localLink),
252 localLocator(desc.localLocator),
253 remoteLink(desc.remoteLink),
254 remoteLocator(desc.remoteLocator),
255 remoteEndpoint(desc.remoteEndpoint),
256 linkup(desc.linkup) {
257
258 BOOST_FOREACH( Message* msg, desc.waitingmsg ){
259 waitingmsg.push_back( msg );
260 }
261 }
262
263 bool isUnspecified() const {
264 return (this == &UNSPECIFIED);
265 }
266
267 LinkID localLink;
268 const NetworkLocator* localLocator;
269 LinkID remoteLink;
270 const NetworkLocator* remoteLocator;
271 EndpointDescriptor remoteEndpoint;
272
273 bool linkup;
274 deque<Message*> waitingmsg;
275 };
276
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 */
305 LinkSet linkSet;
306
307 /**
308 * The message receiver
309 */
310 MessageReceiver* messageReceiver;
311
312 /**
313 * The local end-point descriptor
314 */
315 EndpointDescriptor localDescriptor;
316
317 /**
318 * Network information and protocol
319 */
320 NetworkProtocol* network;
321
322 /**
323 * Transport information and protocol
324 */
325 TransportProtocol* transport;
326
327#ifndef UNDERLAY_OMNET
328 /**
329 * Detect changes in the routing/interface, etc.
330 * stuff needed for mobility detection
331 */
332 NetworkChangeDetection networkMonitor;
333#endif
334
335 /**
336 * The local listen port
337 */
338 uint16_t listenport;
339
340 typedef set<CommunicationEvents*> EventListenerSet;
341 EventListenerSet eventListener;
342
343 seqnum_t currentSeqnum;
344};
345
346}} // namespace ariba, communication
347
348#endif /*BASECOMMUNICATION_H_*/
Note: See TracBrowser for help on using the repository browser.