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 }
00073
00074 using std::vector;
00075 using std::list;
00076 using std::cout;
00077 using std::map;
00078 using std::make_pair;
00079 using std::pair;
00080 using std::find;
00081 using std::deque;
00082
00083
00084 using ariba::NodeListener;
00085 using ariba::SideportListener;
00086 using ariba::CommunicationListener;
00087
00088
00089 using ariba::overlay::OverlayBootstrap;
00090
00091
00092 using ariba::communication::EndpointDescriptor;
00093 using ariba::communication::BaseCommunication;
00094 using ariba::communication::CommunicationEvents;
00095
00096
00097 using ariba::utility::NodeID;
00098 using ariba::utility::SpoVNetID;
00099 using ariba::utility::LinkID;
00100 using ariba::utility::Identifier;
00101 using ariba::utility::ServiceID;
00102 using ariba::utility::QoSParameterSet;
00103 using ariba::utility::SecurityParameterSet;
00104 using ariba::utility::Demultiplexer;
00105 using ariba::utility::MessageReceiver;
00106 using ariba::utility::MessageSender;
00107 using ariba::utility::seqnum_t;
00108 using ariba::utility::Timer;
00109
00110 namespace ariba {
00111 namespace overlay {
00112
00113 using namespace ariba::addressing;
00114
00115 class LinkDescriptor;
00116 class OverlayMsg;
00117 class DHT;
00118
00119 class BaseOverlay: public MessageReceiver,
00120 public CommunicationEvents,
00121 public OverlayStructureEvents,
00122 protected Timer {
00123
00124 friend class OneHop;
00125 friend class Chord;
00126 friend class ariba::SideportListener;
00127
00128 use_logging_h( BaseOverlay );
00129
00130 public:
00131
00135 BaseOverlay();
00136
00140 virtual ~BaseOverlay();
00141
00145 void start(BaseCommunication& _basecomm, const NodeID& _nodeid);
00146
00150 void stop();
00151
00155 bool isStarted();
00156
00158 const LinkID establishLink( const EndpointDescriptor& ep,
00159 const NodeID& node, const ServiceID& service );
00160
00169 const LinkID establishLink( const NodeID& remote,
00170 const ServiceID& service = OverlayInterface::OVERLAY_SERVICE_ID );
00171
00176 const LinkID establishDirectLink( const EndpointDescriptor& endpoint,
00177 const ServiceID& service = OverlayInterface::OVERLAY_SERVICE_ID );
00178
00180 void dropLink( const LinkID& link );
00181
00183 seqnum_t sendMessage(const Message* message, const LinkID& link );
00184
00186 seqnum_t sendMessage(const Message* message, const NodeID& remote,
00187 const ServiceID& service = OverlayInterface::OVERLAY_SERVICE_ID);
00188
00193 void broadcastMessage(Message* message, const ServiceID& service);
00194
00201 const EndpointDescriptor& getEndpointDescriptor(
00202 const LinkID& link = LinkID::UNSPECIFIED) const;
00203
00209 vector<NodeID> getOverlayNeighbors(bool deep = true) const;
00210
00219 const EndpointDescriptor& getEndpointDescriptor(const NodeID& node) const;
00220
00221
00222 bool bind(CommunicationListener* listener, const ServiceID& sid);
00223
00224
00225 bool unbind(CommunicationListener* listener, const ServiceID& sid);
00226
00227
00228 bool bind(NodeListener* listener);
00229
00230
00231 bool unbind(NodeListener* listener);
00232
00233
00234 bool registerSidePort(SideportListener* _sideport);
00235
00236
00237 bool unregisterSidePort(SideportListener* _sideport);
00238
00245 const NodeID& getNodeID(const LinkID& lid = LinkID::UNSPECIFIED) const;
00246
00254 vector<LinkID> getLinkIDs(const NodeID& nid = NodeID::UNSPECIFIED) const;
00255
00262 void joinSpoVNet(const SpoVNetID& id, const EndpointDescriptor& boot = EndpointDescriptor::UNSPECIFIED());
00263
00270 void createSpoVNet(const SpoVNetID& id, const OverlayParameterSet& param =
00271 OverlayParameterSet::DEFAULT, const SecurityParameterSet& sec =
00272 SecurityParameterSet::DEFAULT, const QoSParameterSet& qos =
00273 QoSParameterSet::DEFAULT);
00274
00278 void startBootstrapModules(vector<pair<BootstrapManager::BootstrapType,string> > modules);
00279
00283 void stopBootstrapModules();
00284
00288 void leaveSpoVNet();
00289
00291 void dhtPut( const Data& key, const Data& value, int ttl = 0, bool replace = false, bool no_local_refresh = false);
00292
00294 void dhtRemove( const Data& key, const Data& value );
00295
00297 void dhtRemove( const Data& key );
00298
00300 void dhtGet( const Data& key, const ServiceID& service );
00301
00302 protected:
00306 virtual void onLinkUp(const LinkID& id, const address_v* local,
00307 const address_v* remote);
00308
00312 virtual void onLinkDown(const LinkID& id, const address_v* local,
00313 const address_v* remote);
00314
00318 virtual void onLinkChanged(const LinkID& id,
00319 const address_v* oldlocal, const address_v* newlocal,
00320 const address_v* oldremote, const address_v* newremote);
00321
00325 virtual void onLinkFail(const LinkID& id, const address_v* local,
00326 const address_v* remote);
00327
00331 virtual void onLinkQoSChanged(const LinkID& id,
00332 const address_v* local, const address_v* remote,
00333 const QoSParameterSet& qos);
00334
00338 virtual bool onLinkRequest(const LinkID& id, const address_v* local,
00339 const address_v* remote);
00340
00347 virtual bool receiveMessage( const Message* message, const LinkID& link,
00348 const NodeID& );
00349
00355 virtual void onNodeJoin(const NodeID& node);
00356
00360 virtual void eventFunction();
00361
00362
00363
00364 std::string getLinkHTMLInfo();
00365
00366 private:
00368 bool started;
00369
00371 typedef enum _BaseOverlayState {
00372 BaseOverlayStateInvalid = 0,
00373 BaseOverlayStateCompleted = 1,
00374 } BaseOverlayState;
00375
00376 BaseOverlayState state;
00377 BaseCommunication* bc;
00378 NodeID nodeId;
00379 SpoVNetID spovnetId;
00380 vector<LinkID> bootstrapLinks;
00381 NodeID spovnetInitiator;
00382
00384 Demultiplexer<CommunicationListener*, ServiceID> communicationListeners;
00385 CommunicationListener* getListener( const ServiceID& id );
00386
00388 typedef vector<NodeListener*> NodeListenerVector;
00389 NodeListenerVector nodeListeners;
00390
00392 SideportListener* sideport;
00393
00395 OverlayInterface* overlayInterface;
00396
00398 OverlayBootstrap overlayBootstrap;
00399
00400
00401
00403 bool handleMessage( const Message* message, LinkDescriptor* ld,
00404 const LinkID bcLink = LinkID::UNSPECIFIED );
00405
00406
00407 bool handleData( OverlayMsg* msg, LinkDescriptor* ld );
00408 bool handleSignaling( OverlayMsg* msg, LinkDescriptor* ld );
00409
00410
00411 bool handleJoinRequest( OverlayMsg* msg, const LinkID& bcLink );
00412 bool handleJoinReply( OverlayMsg* msg, const LinkID& bcLink );
00413
00414
00415 bool handleDHTMessage( OverlayMsg* msg );
00416
00417
00418 bool handleLinkRequest( OverlayMsg* msg, LinkDescriptor* ld );
00419 bool handleLinkReply( OverlayMsg* msg, LinkDescriptor* ld );
00420 bool handleLinkUpdate( OverlayMsg* msg, LinkDescriptor* ld );
00421 bool handleLinkDirect( OverlayMsg* msg, LinkDescriptor* ld );
00422 bool handleLinkAlive( OverlayMsg* msg, LinkDescriptor* ld );
00423
00424
00425
00426
00428 int counter;
00429
00431 vector<LinkDescriptor*> links;
00432
00434 void eraseDescriptor(const LinkID& link, bool communication = false);
00435
00437 LinkDescriptor* getDescriptor(const LinkID& link,
00438 bool communication = false);
00439
00441 const LinkDescriptor* getDescriptor(const LinkID& link,
00442 bool communication = false) const;
00443
00445 LinkDescriptor* getAutoDescriptor(const NodeID& node, const ServiceID& service);
00446
00448 LinkDescriptor* addDescriptor(const LinkID& link = LinkID::UNSPECIFIED);
00449
00451 void stabilizeLinks();
00452
00454 void showLinks();
00455
00457 int compare( const LinkID& lhs, const LinkID& rhs );
00458
00459
00460
00462 class relay_route {
00463 public:
00464 NodeID node;
00465 LinkID link;
00466 uint8_t hops;
00467 time_t used;
00468 };
00469 vector<relay_route> relay_routes;
00470
00472 void stabilizeRelays();
00473
00475 void refreshRelayInformation( const OverlayMsg* message, LinkDescriptor* ld );
00476
00478 LinkDescriptor* getRelayLinkTo( const NodeID& remote );
00479
00481 void removeRelayLink( const LinkID& link );
00482
00484 void removeRelayNode( const NodeID& link );
00485
00486
00487
00489 void route( OverlayMsg* message );
00490
00492 seqnum_t send( OverlayMsg* message, const NodeID& destination );
00493
00495 seqnum_t send( OverlayMsg* message, LinkDescriptor* ld,
00496 bool ignore_down = false );
00497
00500 seqnum_t send_node( OverlayMsg* message, const NodeID& remote,
00501 const ServiceID& service = OverlayInterface::OVERLAY_SERVICE_ID);
00502
00505 seqnum_t send_link( OverlayMsg* message, const LinkID& link,
00506 bool ignore_down = false );
00507
00508
00509
00510 DHT* dht;
00511 DHT* localDHT;
00512 int republishCounter;
00513
00514 void initDHT();
00515 void destroyDHT();
00516 void stabilizeDHT();
00517 void dhtSend( OverlayMsg* msg, const NodeID& dest );
00518
00519
00520
00521 std::string debugInformation();
00522
00527 typedef vector<NodeID> JoiningNodes;
00528 JoiningNodes joiningNodes;
00529
00530 void updateVisual();
00531 };
00532
00533 }}
00534
00535 #endif