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
00066
00067 namespace ariba {
00068 class NodeListener;
00069 class CommunicationListener;
00070 class SideportListener;
00071 namespace utility {
00072 class OvlVis;
00073 }
00074 }
00075
00076 using std::vector;
00077 using std::list;
00078 using std::cout;
00079 using std::map;
00080 using std::make_pair;
00081 using std::pair;
00082 using std::find;
00083 using std::deque;
00084
00085 using ariba::NodeListener;
00086 using ariba::CommunicationListener;
00087
00088
00089 using ariba::communication::EndpointDescriptor;
00090 using ariba::communication::BaseCommunication;
00091 using ariba::communication::CommunicationEvents;
00092
00093
00094 using ariba::utility::NodeID;
00095 using ariba::utility::SpoVNetID;
00096 using ariba::utility::LinkID;
00097 using ariba::utility::Identifier;
00098 using ariba::utility::ServiceID;
00099 using ariba::utility::QoSParameterSet;
00100 using ariba::utility::SecurityParameterSet;
00101 using ariba::utility::Demultiplexer;
00102 using ariba::utility::MessageReceiver;
00103 using ariba::utility::MessageSender;
00104 using ariba::utility::seqnum_t;
00105 using ariba::utility::Timer;
00106 using ariba::utility::OvlVis;
00107
00108 #define ovl OvlVis::instance()
00109 #define ovlId OvlVis::NETWORK_ID_BASE_OVERLAY
00110
00111 namespace ariba {
00112 namespace overlay {
00113
00114 class BaseOverlay: public MessageReceiver, public CommunicationEvents,
00115 public OverlayStructureEvents, protected Timer {
00116
00117 private:
00118 friend class OneHop;
00119 friend class Chord;
00120
00121 use_logging_h( BaseOverlay );
00122
00123 public:
00124
00128 BaseOverlay();
00129
00133 virtual ~BaseOverlay();
00134
00138 void start(BaseCommunication& _basecomm, const NodeID& _nodeid);
00139
00143 void stop();
00144
00153 const LinkID establishLink(const NodeID& node, const ServiceID& service,
00154 const LinkID& linkid = LinkID::UNSPECIFIED);
00155
00161 const LinkID establishLink(const EndpointDescriptor& ep,
00162 const ServiceID& service, const LinkID& linkid =
00163 LinkID::UNSPECIFIED);
00164
00166 void dropLink(const LinkID& link);
00167
00169 seqnum_t sendMessage(const Message* message, const LinkID& link);
00170
00172 seqnum_t sendMessage(const Message* message, const NodeID& node,
00173 const ServiceID& service);
00174
00179 void broadcastMessage(Message* message, const ServiceID& service);
00180
00187 const EndpointDescriptor& getEndpointDescriptor(const LinkID& link =
00188 LinkID::UNSPECIFIED) const;
00189
00195 vector<NodeID> getOverlayNeighbors() const;
00196
00205 const EndpointDescriptor& getEndpointDescriptor(const NodeID& node) const;
00206
00207
00208 bool bind(CommunicationListener* listener, const ServiceID& sid);
00209
00210
00211 bool unbind(CommunicationListener* listener, const ServiceID& sid);
00212
00213
00214 bool bind(NodeListener* listener);
00215
00216
00217 bool unbind(NodeListener* listener);
00218
00219
00220 bool registerSidePort(SideportListener* _sideport);
00221
00222
00223 bool unregisterSidePort(SideportListener* _sideport);
00224
00231 const NodeID& getNodeID(const LinkID& lid = LinkID::UNSPECIFIED) const;
00232
00240 vector<LinkID> getLinkIDs(const NodeID& nid = NodeID::UNSPECIFIED) const;
00241
00248 void joinSpoVNet(const SpoVNetID& id, const EndpointDescriptor& boot );
00249
00256 void createSpoVNet(const SpoVNetID& id, const OverlayParameterSet& param =
00257 OverlayParameterSet::DEFAULT, const SecurityParameterSet& sec =
00258 SecurityParameterSet::DEFAULT, const QoSParameterSet& qos =
00259 QoSParameterSet::DEFAULT);
00260
00264 void leaveSpoVNet();
00265
00266 protected:
00267
00271 virtual void onLinkUp(const LinkID& id, const NetworkLocator* local,
00272 const NetworkLocator* remote);
00273
00277 virtual void onLinkDown(const LinkID& id, const NetworkLocator* local,
00278 const NetworkLocator* remote);
00279
00283 virtual void onLinkChanged(const LinkID& id,
00284 const NetworkLocator* oldlocal, const NetworkLocator* newlocal,
00285 const NetworkLocator* oldremote, const NetworkLocator* newremote);
00286
00290 virtual void onLinkFail(const LinkID& id, const NetworkLocator* local,
00291 const NetworkLocator* remote);
00292
00296 virtual void onLinkQoSChanged(const LinkID& id,
00297 const NetworkLocator* local, const NetworkLocator* remote,
00298 const QoSParameterSet& qos);
00299
00303 virtual bool onLinkRequest(const LinkID& id, const NetworkLocator* local,
00304 const NetworkLocator* remote);
00305
00306
00307
00314 virtual bool receiveMessage(
00315 const Message* message, const LinkID& link, const NodeID&);
00316
00317
00318
00325 virtual void incomingRouteMessage(Message* msg);
00326
00332 virtual void onNodeJoin(const NodeID& node);
00333
00337 virtual void eventFunction();
00338
00339 private:
00344 BaseCommunication* bc;
00345
00349 NodeID nodeId;
00350
00355 SpoVNetID spovnetId;
00356
00360 Demultiplexer<CommunicationListener*, ServiceID> communicationListeners;
00361
00365 typedef vector<NodeListener*> NodeListenerVector;
00366
00370 NodeListenerVector nodeListeners;
00371
00375 SideportListener* sideport;
00376
00381 OverlayInterface* overlayInterface;
00382
00387 LinkID initiatorLink;
00388
00392 typedef enum _BaseOverlayState {
00393 BaseOverlayStateInvalid = 0,
00394 BaseOverlayStateInitiator = 1,
00395 BaseOverlayStateJoinInitiated = 2,
00396 BaseOverlayStateCompleted = 3,
00397 } BaseOverlayState;
00398
00402 BaseOverlayState state;
00403
00407 NodeID spovnetInitiator;
00408
00412 NodeID min, max;
00413 NodeID succ, pred;
00414 void updateOvlVis(const NodeID& node);
00415
00419 class LinkItem {
00420 public:
00421 static const LinkItem UNSPECIFIED;
00422
00423 LinkItem() :
00424 link(LinkID::UNSPECIFIED),
00425 node(NodeID::UNSPECIFIED),
00426 service(ServiceID::UNSPECIFIED),
00427 interface(&CommunicationListener::DEFAULT),
00428 autolink(false),
00429 lastuse(0),
00430 linkup(false){
00431 }
00432
00433 LinkItem(const LinkID& _link, const NodeID& _node,
00434 const ServiceID& _service, CommunicationListener* _interface) :
00435 link(_link),
00436 node(_node),
00437 service(_service),
00438 interface(_interface),
00439 autolink(false),
00440 lastuse(time(NULL)),
00441 linkup(false){
00442
00443 assert( _interface != NULL );
00444 }
00445
00446 LinkItem(const LinkItem& rh) :
00447 link(rh.link),
00448 node(rh.node),
00449 service(rh.service),
00450 interface(rh.interface),
00451 autolink(rh.autolink),
00452 lastuse(rh.lastuse),
00453 linkup(rh.linkup){
00454
00455 BOOST_FOREACH( Message* msg, rh.waitingmsg ){
00456 waitingmsg.push_back( msg );
00457 }
00458 }
00459
00460 void deleteWaiting(){
00461 BOOST_FOREACH( Message* msg, waitingmsg ){
00462 delete msg;
00463 }
00464 waitingmsg.clear();
00465 }
00466
00467
00468 const LinkID link;
00469 NodeID node;
00470 ServiceID service;
00471 CommunicationListener* interface;
00472 bool linkup;
00473
00474
00475 void markused() {
00476 lastuse = time(NULL);
00477 }
00478
00479 bool autolink;
00480 time_t lastuse;
00481 deque<Message*> waitingmsg;
00482 };
00483
00484 typedef map<const LinkID, LinkItem> LinkMapping;
00485 typedef pair<const LinkID, LinkItem> LinkPair;
00486 LinkMapping linkMapping;
00487
00488
00489 typedef map<const uint32_t, LinkID> PendingLinkMap;
00490 PendingLinkMap pendingLinks;
00491
00496 typedef vector<NodeID> JoiningNodes;
00497 JoiningNodes joiningNodes;
00498
00499 };
00500
00501 }}
00502
00503 #endif