00001 // [License] 00002 // The Ariba-Underlay Copyright 00003 // 00004 // Copyright (c) 2008-2009, Institute of Telematics, Universität Karlsruhe (TH) 00005 // 00006 // Institute of Telematics 00007 // Universität Karlsruhe (TH) 00008 // Zirkel 2, 76128 Karlsruhe 00009 // Germany 00010 // 00011 // Redistribution and use in source and binary forms, with or without 00012 // modification, are permitted provided that the following conditions are 00013 // met: 00014 // 00015 // 1. Redistributions of source code must retain the above copyright 00016 // notice, this list of conditions and the following disclaimer. 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // THIS SOFTWARE IS PROVIDED BY THE INSTITUTE OF TELEMATICS ``AS IS'' AND 00022 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00023 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00024 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OF TELEMATICS OR 00025 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00026 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00027 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00028 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00029 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00030 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00031 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 // 00033 // The views and conclusions contained in the software and documentation 00034 // are those of the authors and should not be interpreted as representing 00035 // official policies, either expressed or implied, of the Institute of 00036 // Telematics. 00037 // [License] 00038 00039 #ifndef NODE_H_ 00040 #define NODE_H_ 00041 00042 // forward declarations 00043 namespace ariba { 00044 class Node; 00045 namespace overlay { 00046 class BaseOverlay; 00047 } 00048 } 00049 00050 #include <vector> 00051 #include <iostream> 00052 #include <boost/foreach.hpp> 00053 #include "Module.h" 00054 #include "Identifiers.h" 00055 #include "SpoVNetProperties.h" 00056 #include "NodeListener.h" 00057 #include "Name.h" 00058 #include "AribaModule.h" 00059 #include "CommunicationListener.h" 00060 #include "DataMessage.h" 00061 #include "SideportListener.h" 00062 00063 using std::vector; 00064 using ariba::overlay::BaseOverlay; 00065 00066 namespace ariba { 00067 00074 class Node: public Module { 00075 public: 00085 Node(AribaModule& ariba_mod, const Name& node_name = Name::UNSPECIFIED); 00086 00095 virtual ~Node(); 00096 00097 //--- node control --- 00098 00106 void join(const Name& name); 00107 00115 void initiate(const Name& name, const SpoVNetProperties& parm = 00116 SpoVNetProperties::DEFAULT); 00117 00121 void leave(); 00122 00129 bool bind(NodeListener* listener); 00130 00137 bool unbind(NodeListener* listener); 00138 00139 //--- spovnet properties --- 00140 00146 const SpoVNetProperties& getSpoVNetProperties() const; 00147 00153 const SpoVNetID& getSpoVNetId() const; 00154 00160 bool isJoined() const; 00161 00162 //--- addressing --- 00163 00170 const NodeID& getNodeId(const LinkID& lid = LinkID::UNSPECIFIED) const; 00171 00178 NodeID generateNodeId(const Name& name) const; 00179 00187 const Name getNodeName(const LinkID& lid = LinkID::UNSPECIFIED) const; 00188 00197 vector<NodeID> getNeighborNodes() const; 00198 00199 //--- communication --- 00200 00211 LinkID establishLink(const NodeID& nid, const ServiceID& sid); 00212 00218 void dropLink(const LinkID& lnk); 00219 00220 // message sending 00221 00237 seqnum_t sendMessage(const DataMessage& msg, const NodeID& nid, const ServiceID& sid, 00238 const LinkProperties& req = LinkProperties::DEFAULT); 00239 00248 seqnum_t sendMessage(const DataMessage& msg, const LinkID& lnk); 00249 00258 void sendBroadcastMessage(const DataMessage& msg, const ServiceID& sid); 00259 00260 // --- communication listeners --- 00261 00271 bool bind(CommunicationListener* listener, const ServiceID& sid); 00272 00279 bool unbind(CommunicationListener* listener, const ServiceID& sid); 00280 00288 void put( const Data& key, const Data& value, uint16_t ttl, bool replace = false); 00289 00297 void get( const Data& key, const ServiceID& sid ); 00298 00299 00300 //------------------------------------------------------------------------- 00301 // 00302 // --- optimization proposal: allow direct endpoint descriptor exchange --- 00303 // main-idea: directly allow exchanging endpoint descriptors to establish 00304 // links. Depending on the overlay structure used in the base overlay, this 00305 // allows a node to directly establish links between two nodes when an 00306 // endpoint descriptor is known. 00307 // 00308 //const EndpointDescriptor& getEndpointDescriptor( const LinkID& lid ); 00309 //void sendMessage( EndpointDescriptor& epd, Message* msg ); 00310 //LinkID setupLink( const EndpointDescriptor& endpointDesc, 00311 // const LinkProperties& req = LinkProperties::UNSPECIFIED, 00312 // const Message* msg = NULL ); 00313 // 00314 //------------------------------------------------------------------------- 00315 00316 // --- module implementation --- 00317 // 00318 // main-idea: use module properties to configure nodeid, spovnetid etc. and 00319 // select start/stop procedures. This allows simulations to start a 00320 // node without manually calling join etc. 00321 00323 string getName() const; 00324 00325 protected: 00326 // friends 00327 friend class AribaModule; 00328 00329 // member variables 00330 Name name; //< node name 00331 AribaModule& ariba_mod; //< ariba module 00332 SpoVNetID spovnetId; //< current spovnet id 00333 NodeID nodeId; //< current node id 00334 overlay::BaseOverlay* base_overlay; //< the base overlay 00335 00336 }; 00337 00338 } // namespace ariba 00339 00340 #endif /* NODE_H_ */