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

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

-is started function

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#include <ext/hash_map>
43#include <ext/hash_set>
44#include <map>
45#include <set>
46#include <vector>
47#include <iostream>
48#include <algorithm>
49#include <boost/foreach.hpp>
50
51#include "ariba/utility/types.h"
52#include "ariba/utility/messages.h"
53#include "ariba/utility/logging/Logging.h"
54#include "ariba/utility/misc/Demultiplexer.hpp"
55
56#include "ariba/communication/CommunicationEvents.h"
57#include "ariba/communication/EndpointDescriptor.h"
58#include "ariba/communication/networkinfo/NetworkChangeInterface.h"
59#include "ariba/communication/networkinfo/NetworkChangeDetection.h"
60#include "ariba/communication/networkinfo/NetworkInformation.h"
61#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
72using __gnu_cxx::hash_set;
73using __gnu_cxx::hash_map;
74
75using std::cout;
76using std::set;
77using std::map;
78using std::vector;
79using std::pair;
80using std::make_pair;
81using std::find;
82
83using ariba::communication::NetworkChangeDetection;
84using ariba::communication::NetworkChangeInterface;
85using ariba::communication::NetworkInterfaceList;
86using ariba::communication::NetworkInformation;
87using ariba::communication::AddressInformation;
88using ariba::communication::AddressList;
89using ariba::communication::AribaBaseMsg;
90using ariba::communication::CommunicationEvents;
91
92using ariba::utility::Demultiplexer;
93using ariba::utility::QoSParameterSet;
94using ariba::utility::SecurityParameterSet;
95using ariba::utility::Address;
96using ariba::utility::LinkID;
97using ariba::utility::LinkIDs;
98using ariba::utility::Message;
99using ariba::utility::MessageReceiver;
100using ariba::utility::seqnum_t;
101
102using ariba::communication::TransportProtocol;
103using ariba::communication::NetworkProtocol;
104using ariba::communication::NetworkLocator;
105#ifndef UNDERLAY_OMNET
106 using ariba::communication::IPv4NetworkProtocol;
107 using ariba::communication::TCPTransport;
108#endif
109
110namespace ariba {
111namespace communication {
112
113/**
114 * This class implements the Ariba Base Communication<br />
115 *
116 * Its primary task is to provide an abstraction to existing
117 * protocols and addressing schemes.
118 *
119 * @author Sebastian Mies, Christoph Mayer
120 */
121class BaseCommunication : public MessageReceiver, NetworkChangeInterface {
122 use_logging_h(BaseCommunication);
123public:
124
125 /**
126 * Default ctor that just creates an empty
127 * non functional base communication
128 */
129 BaseCommunication();
130
131 /**
132 * Default dtor that does nothing
133 */
134 virtual ~BaseCommunication();
135
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 */
144 void stop();
145
146 /*
147 * Check whether the base communication has been started up
148 */
149 bool isStarted();
150
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 */
167 void dropLink(const LinkID link);
168
169 /**
170 * Sends a message though an existing link to an end-point.
171 *
172 * @param lid The link identifier
173 * @param message The message to be sent
174 * @return A sequence number for this message
175 */
176 seqnum_t sendMessage(const LinkID lid, const Message* message);
177
178 /**
179 * Returns the end-point descriptor
180 *
181 * @param link the link id of the requested end-point
182 * @return The end-point descriptor of the link's end-point
183 */
184 const EndpointDescriptor& getEndpointDescriptor( const LinkID link = LinkID::UNSPECIFIED ) const;
185
186 /**
187 * Get local links to the given endpoint of all local link
188 * using the default parameter EndpointDescriptor::UNSPECIFIED
189 * @param ep The remote endpoint to get all links to.
190 * @return List of LinkID
191 */
192 LinkIDs getLocalLinks( const EndpointDescriptor& ep = EndpointDescriptor::UNSPECIFIED ) const;
193
194 /**
195 * Registers a receiver.
196 *
197 * @param _receiver The receiving side
198 */
199 void registerMessageReceiver( MessageReceiver* _receiver );
200
201 /**
202 * Unregister a receiver.
203 *
204 * @param _receiver The receiving side
205 */
206 void unregisterMessageReceiver( MessageReceiver* _receiver );
207
208 void registerEventListener( CommunicationEvents* _events );
209 void unregisterEventListener( CommunicationEvents* _events );
210
211protected:
212
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 );
223
224private:
225
226 /**
227 * A link descriptor consisting of the
228 * end-point descriptor and currently used locator and
229 * message receiver
230 */
231 class LinkDescriptor {
232 public:
233 static const LinkDescriptor UNSPECIFIED;
234
235 LinkDescriptor() :
236 localLink(LinkID::UNSPECIFIED),
237 localLocator(NULL),
238 remoteLink(LinkID::UNSPECIFIED),
239 remoteLocator(NULL),
240 remoteEndpoint(EndpointDescriptor::UNSPECIFIED),
241 linkup(false) {
242 }
243
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) {
253 }
254
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) {
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 };
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 * state of the base communication
347 */
348 bool basecommStarted;
349
350};
351
352}} // namespace ariba, communication
353
354#endif /*BASECOMMUNICATION_H_*/
Note: See TracBrowser for help on using the repository browser.