00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef BASEOVERLAY_H_
00040 #define BASEOVERLAY_H_
00041
00042 #include <map>
00043 #include <iostream>
00044 #include <algorithm>
00045 #include <ctime>
00046 #include <list>
00047 #include <vector>
00048 #include <deque>
00049 #include <boost/foreach.hpp>
00050
00051 #include "ariba/utility/messages.h"
00052 #include "ariba/utility/types.h"
00053 #include "ariba/utility/misc/Helper.h"
00054 #include "ariba/utility/misc/Demultiplexer.hpp"
00055 #include "ariba/utility/logging/Logging.h"
00056 #include "ariba/utility/system/Timer.h"
00057
00058 #include "ariba/communication/EndpointDescriptor.h"
00059 #include "ariba/communication/BaseCommunication.h"
00060 #include "ariba/communication/CommunicationEvents.h"
00061
00062 #include "ariba/overlay/modules/OverlayInterface.h"
00063 #include "ariba/overlay/modules/OverlayFactory.h"
00064 #include "ariba/overlay/modules/OverlayStructureEvents.h"
00065 #include "ariba/overlay/OverlayBootstrap.h"
00066
00067
00068 namespace ariba {
00069 class NodeListener;
00070 class CommunicationListener;
00071 class SideportListener;
00072 namespace utility {
00073 class OvlVis;
00074 }
00075 }
00076
00077 using std::vector;
00078 using std::list;
00079 using std::cout;
00080 using std::map;
00081 using std::make_pair;
00082 using std::pair;
00083 using std::find;
00084 using std::deque;
00085
00086
00087 using ariba::NodeListener;
00088 using ariba::SideportListener;
00089 using ariba::CommunicationListener;
00090
00091
00092 using ariba::overlay::OverlayBootstrap;
00093
00094
00095 using ariba::communication::EndpointDescriptor;
00096 using ariba::communication::BaseCommunication;
00097 using ariba::communication::CommunicationEvents;
00098
00099
00100 using ariba::utility::NodeID;
00101 using ariba::utility::SpoVNetID;
00102 using ariba::utility::LinkID;
00103 using ariba::utility::Identifier;
00104 using ariba::utility::ServiceID;
00105 using ariba::utility::QoSParameterSet;
00106 using ariba::utility::SecurityParameterSet;
00107 using ariba::utility::Demultiplexer;
00108 using ariba::utility::MessageReceiver;
00109 using ariba::utility::MessageSender;
00110 using ariba::utility::seqnum_t;
00111 using ariba::utility::Timer;
00112 using ariba::utility::OvlVis;
00113
00114
00115
00116
00117 namespace ariba {
00118 namespace overlay {
00119
00120 using namespace ariba::addressing;
00121
00122 class LinkDescriptor;
00123 class OverlayMsg;
00124
00125 class BaseOverlay: public MessageReceiver,
00126 public CommunicationEvents,
00127 public OverlayStructureEvents,
00128 protected Timer {
00129
00130 friend class OneHop;
00131 friend class Chord;
00132 friend class ariba::SideportListener;
00133
00134 use_logging_h( BaseOverlay );
00135
00136 public:
00137
00141 BaseOverlay();
00142
00146 virtual ~BaseOverlay();
00147
00151 void start(BaseCommunication& _basecomm, const NodeID& _nodeid);
00152
00156 void stop();
00157
00161 bool isStarted();
00162
00164 const LinkID establishLink( const EndpointDescriptor& ep,
00165 const NodeID& node, const ServiceID& service );
00166
00175 const LinkID establishLink( const NodeID& remote,
00176 const ServiceID& service = OverlayInterface::OVERLAY_SERVICE_ID );
00177
00182 const LinkID establishDirectLink( const EndpointDescriptor& endpoint,
00183 const ServiceID& service = OverlayInterface::OVERLAY_SERVICE_ID );
00184
00186 void dropLink( const LinkID& link );
00187
00189 seqnum_t sendMessage(const Message* message, const LinkID& link );
00190
00192 seqnum_t sendMessage(const Message* message, const NodeID& remote,
00193 const ServiceID& service = OverlayInterface::OVERLAY_SERVICE_ID);
00194
00199 void broadcastMessage(Message* message, const ServiceID& service);
00200
00207 const EndpointDescriptor& getEndpointDescriptor(
00208 const LinkID& link = LinkID::UNSPECIFIED) const;
00209
00215 vector<NodeID> getOverlayNeighbors(bool deep = true) const;
00216
00225 const EndpointDescriptor& getEndpointDescriptor(const NodeID& node) const;
00226
00227
00228 bool bind(CommunicationListener* listener, const ServiceID& sid);
00229
00230
00231 bool unbind(CommunicationListener* listener, const ServiceID& sid);
00232
00233
00234 bool bind(NodeListener* listener);
00235
00236
00237 bool unbind(NodeListener* listener);
00238
00239
00240 bool registerSidePort(SideportListener* _sideport);
00241
00242
00243 bool unregisterSidePort(SideportListener* _sideport);
00244
00251 const NodeID& getNodeID(const LinkID& lid = LinkID::UNSPECIFIED) const;
00252
00260 vector<LinkID> getLinkIDs(const NodeID& nid = NodeID::UNSPECIFIED) const;
00261
00268 void joinSpoVNet(const SpoVNetID& id, const EndpointDescriptor& boot = EndpointDescriptor::UNSPECIFIED());
00269
00276 void createSpoVNet(const SpoVNetID& id, const OverlayParameterSet& param =
00277 OverlayParameterSet::DEFAULT, const SecurityParameterSet& sec =
00278 SecurityParameterSet::DEFAULT, const QoSParameterSet& qos =
00279 QoSParameterSet::DEFAULT);
00280
00284 void leaveSpoVNet();
00285
00286 protected:
00287
00291 virtual void onLinkUp(const LinkID& id, const address_v* local,
00292 const address_v* remote);
00293
00297 virtual void onLinkDown(const LinkID& id, const address_v* local,
00298 const address_v* remote);
00299
00303 virtual void onLinkChanged(const LinkID& id,
00304 const address_v* oldlocal, const address_v* newlocal,
00305 const address_v* oldremote, const address_v* newremote);
00306
00310 virtual void onLinkFail(const LinkID& id, const address_v* local,
00311 const address_v* remote);
00312
00316 virtual void onLinkQoSChanged(const LinkID& id,
00317 const address_v* local, const address_v* remote,
00318 const QoSParameterSet& qos);
00319
00323 virtual bool onLinkRequest(const LinkID& id, const address_v* local,
00324 const address_v* remote);
00325
00332 virtual bool receiveMessage( const Message* message, const LinkID& link,
00333 const NodeID& );
00334
00340 virtual void onNodeJoin(const NodeID& node);
00341
00345 virtual void eventFunction();
00346
00347
00348
00349 std::string getLinkHTMLInfo();
00350
00351 private:
00353 bool started;
00354
00356 typedef enum _BaseOverlayState {
00357 BaseOverlayStateInvalid = 0,
00358 BaseOverlayStateCompleted = 1,
00359 } BaseOverlayState;
00360
00361 BaseOverlayState state;
00362 BaseCommunication* bc;
00363 NodeID nodeId;
00364 SpoVNetID spovnetId;
00365 vector<LinkID> bootstrapLinks;
00366 NodeID spovnetInitiator;
00367
00369 Demultiplexer<CommunicationListener*, ServiceID> communicationListeners;
00370 CommunicationListener* getListener( const ServiceID& id );
00371
00373 typedef vector<NodeListener*> NodeListenerVector;
00374 NodeListenerVector nodeListeners;
00375
00377 SideportListener* sideport;
00378
00380 OverlayInterface* overlayInterface;
00381
00383 OverlayBootstrap overlayBootstrap;
00384
00385
00386
00388 bool handleMessage( const Message* message, LinkDescriptor* ld,
00389 const LinkID bcLink = LinkID::UNSPECIFIED );
00390
00391
00392 bool handleData( OverlayMsg* msg, LinkDescriptor* ld );
00393 bool handleSignaling( OverlayMsg* msg, LinkDescriptor* ld );
00394
00395
00396 bool handleJoinRequest( OverlayMsg* msg, const LinkID& bcLink );
00397 bool handleJoinReply( OverlayMsg* msg, const LinkID& bcLink );
00398
00399
00400 bool handleLinkRequest( OverlayMsg* msg, LinkDescriptor* ld );
00401 bool handleLinkReply( OverlayMsg* msg, LinkDescriptor* ld );
00402 bool handleLinkUpdate( OverlayMsg* msg, LinkDescriptor* ld );
00403 bool handleLinkDirect( OverlayMsg* msg, LinkDescriptor* ld );
00404 bool handleLinkAlive( OverlayMsg* msg, LinkDescriptor* ld );
00405
00406
00407
00409 int counter;
00410
00412 vector<LinkDescriptor*> links;
00413
00415 void eraseDescriptor(const LinkID& link, bool communication = false);
00416
00418 LinkDescriptor* getDescriptor(const LinkID& link,
00419 bool communication = false);
00420
00422 const LinkDescriptor* getDescriptor(const LinkID& link,
00423 bool communication = false) const;
00424
00426 LinkDescriptor* getAutoDescriptor(const NodeID& node, const ServiceID& service);
00427
00429 LinkDescriptor* addDescriptor(const LinkID& link = LinkID::UNSPECIFIED);
00430
00432 void stabilizeLinks();
00433
00435 void showLinks();
00436
00438 int compare( const LinkID& lhs, const LinkID& rhs );
00439
00440
00441
00443 class relay_route {
00444 public:
00445 NodeID node;
00446 LinkID link;
00447 uint8_t hops;
00448 time_t used;
00449 };
00450 vector<relay_route> relay_routes;
00451
00453 void stabilizeRelays();
00454
00456 void refreshRelayInformation( const OverlayMsg* message, LinkDescriptor* ld );
00457
00459 LinkDescriptor* getRelayLinkTo( const NodeID& remote );
00460
00462 void removeRelayLink( const LinkID& link );
00463
00465 void removeRelayNode( const NodeID& link );
00466
00467
00468
00470 void route( OverlayMsg* message );
00471
00473 seqnum_t send( OverlayMsg* message, const NodeID& destination );
00474
00476 seqnum_t send( OverlayMsg* message, LinkDescriptor* ld,
00477 bool ignore_down = false );
00478
00481 seqnum_t send_node( OverlayMsg* message, const NodeID& remote,
00482 const ServiceID& service = OverlayInterface::OVERLAY_SERVICE_ID);
00483
00486 seqnum_t send_link( OverlayMsg* message, const LinkID& link,
00487 bool ignore_down = false );
00488
00489
00490
00495 typedef vector<NodeID> JoiningNodes;
00496 JoiningNodes joiningNodes;
00497 };
00498
00499 }}
00500
00501 #endif