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

Last change on this file since 2390 was 2390, checked in by mies, 16 years ago
File size: 9.1 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 <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
123 use_logging_h(BaseCommunication);
124
125public:
126 /**
127 * Constructs a Base Communication instance.
128 * Listens default on port number 41402
129 */
130 BaseCommunication(const NetworkLocator* _locallocator, const uint16_t _listenport);
131
132 /**
133 * Destructs a Base Communication instance
134 */
135 virtual ~BaseCommunication();
136
137 /**
138 * Establishes a link to another end-point
139 */
140 const LinkID establishLink(
141 const EndpointDescriptor& descriptor,
142 const QoSParameterSet& qos = QoSParameterSet::DEFAULT,
143 const SecurityParameterSet& sec = SecurityParameterSet::DEFAULT
144 );
145
146 /**
147 * Drops a link
148 *
149 * @param The link id of the link that should be dropped
150 */
151 void dropLink(const LinkID link);
152
153 /**
154 * Sends a message though an existing link to an end-point.
155 *
156 * @param lid The link identifier
157 * @param message The message to be sent
158 * @return A sequence number for this message
159 */
160 seqnum_t sendMessage(const LinkID lid, const Message* message);
161
162 /**
163 * Returns the end-point descriptor
164 *
165 * @param link the link id of the requested end-point
166 * @return The end-point descriptor of the link's end-point
167 */
168 const EndpointDescriptor& getEndpointDescriptor( const LinkID link = LinkID::UNSPECIFIED ) const;
169
170 /**
171 * Get local links to the given endpoint of all local link
172 * using the default parameter EndpointDescriptor::UNSPECIFIED
173 * @param ep The remote endpoint to get all links to.
174 * @return List of LinkID
175 */
176 LinkIDs getLocalLinks( const EndpointDescriptor& ep = EndpointDescriptor::UNSPECIFIED ) const;
177
178 /**
179 * Registers a receiver.
180 *
181 * @param _receiver The receiving side
182 */
183 void registerMessageReceiver( MessageReceiver* _receiver );
184
185 /**
186 * Unregister a receiver.
187 *
188 * @param _receiver The receiving side
189 */
190 void unregisterMessageReceiver( MessageReceiver* _receiver );
191
192 void registerEventListener( CommunicationEvents* _events );
193 void unregisterEventListener( CommunicationEvents* _events );
194
195protected:
196
197 /**
198 * Called from the Transport when async items
199 * from the SystemQueue are delivered
200 */
201 virtual bool receiveMessage( const Message* message, const LinkID& link, const NodeID& node );
202
203 /**
204 * Called when a network interface change happens
205 */
206 virtual void onNetworkChange( const NetworkChangeInterface::NetworkChangeInfo& info );
207
208private:
209
210 /**
211 * A link descriptor consisting of the
212 * end-point descriptor and currently used locator and
213 * message receiver
214 */
215 class LinkDescriptor {
216 public:
217 static const LinkDescriptor UNSPECIFIED;
218
219 LinkDescriptor() :
220 localLink(),
221 localLocator(NULL),
222 remoteLink(),
223 remoteLocator(NULL),
224 remoteEndpoint(EndpointDescriptor::UNSPECIFIED){
225 }
226
227 LinkDescriptor(const LinkID& _localLink, const NetworkLocator*& _localLocator,
228 const LinkID& _remoteLink, const NetworkLocator*& _remoteLocator,
229 const EndpointDescriptor& _remoteEndpoint ) :
230 localLink(_localLink),
231 localLocator(_localLocator),
232 remoteLink(_remoteLink),
233 remoteLocator(_remoteLocator),
234 remoteEndpoint(_remoteEndpoint){
235 }
236
237 LinkDescriptor( const LinkDescriptor& desc ) :
238 localLink(desc.localLink),
239 localLocator(desc.localLocator),
240 remoteLink(desc.remoteLink),
241 remoteLocator(desc.remoteLocator),
242 remoteEndpoint(desc.remoteEndpoint){
243 }
244
245 bool isUnspecified() const {
246 return (this == &UNSPECIFIED);
247 }
248
249 LinkID localLink;
250 const NetworkLocator* localLocator;
251 LinkID remoteLink;
252 const NetworkLocator* remoteLocator;
253 EndpointDescriptor remoteEndpoint;
254 };
255
256 /**
257 * Link management: add a link
258 */
259 void addLink( const LinkDescriptor& link );
260
261 /**
262 * Link management: remove alink
263 */
264 void removeLink( const LinkID& localLink );
265
266 /**
267 * Link management: get link information using the local link
268 */
269 LinkDescriptor& queryLocalLink( const LinkID& localLink ) const;
270
271 /**
272 * Link management: get link information using the remote link
273 */
274 LinkDescriptor& queryRemoteLink( const LinkID& remoteLink ) const;
275
276 /**
277 * Link management: list of links
278 */
279 typedef vector<LinkDescriptor> LinkSet;
280
281 /**
282 * Link management: the set of currently managed links
283 */
284 LinkSet linkSet;
285
286 /**
287 * The message receiver
288 */
289 MessageReceiver* messageReceiver;
290
291 /**
292 * The local end-point descriptor
293 */
294 EndpointDescriptor localDescriptor;
295
296 /**
297 * Network information and protocol
298 */
299 NetworkProtocol* network;
300
301 /**
302 * Transport information and protocol
303 */
304 TransportProtocol* transport;
305
306#ifndef UNDERLAY_OMNET
307 /**
308 * Detect changes in the routing/interface, etc.
309 * stuff needed for mobility detection
310 */
311 NetworkChangeDetection networkMonitor;
312#endif
313
314 /**
315 * The local listen port
316 */
317 uint16_t listenport;
318
319 typedef set<CommunicationEvents*> EventListenerSet;
320 EventListenerSet eventListener;
321
322 seqnum_t currentSeqnum;
323};
324
325}} // namespace ariba, communication
326
327#endif /*BASECOMMUNICATION_H_*/
Note: See TracBrowser for help on using the repository browser.