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 "Module.h" 00053 #include "Identifiers.h" 00054 #include "SpoVNetProperties.h" 00055 #include "NodeListener.h" 00056 #include "Name.h" 00057 #include "AribaModule.h" 00058 #include "CommunicationListener.h" 00059 #include "DataMessage.h" 00060 #include "SideportListener.h" 00061 00062 using std::vector; 00063 using ariba::overlay::BaseOverlay; 00064 00065 namespace ariba { 00066 00073 class Node: public Module { 00074 public: 00084 Node(AribaModule& ariba_mod, const Name& node_name = Name::UNSPECIFIED); 00085 00094 ~Node(); 00095 00096 //--- node control --- 00097 00105 void join(const Name& name); 00106 00114 void initiate(const Name& name, const SpoVNetProperties& parm = 00115 SpoVNetProperties::DEFAULT); 00116 00120 void leave(); 00121 00128 bool bind(NodeListener* listener); 00129 00136 bool unbind(NodeListener* listener); 00137 00138 //--- spovnet properties --- 00139 00145 const SpoVNetProperties& getSpoVNetProperties() const; 00146 00152 const SpoVNetID& getSpoVNetId() const; 00153 00159 bool isJoined() const; 00160 00161 //--- addressing --- 00162 00169 const NodeID& getNodeId(const LinkID& lid = LinkID::UNSPECIFIED) const; 00170 00177 NodeID generateNodeId(const Name& name) const; 00178 00188 const Name getNodeName(const LinkID& lid = LinkID::UNSPECIFIED) const; 00189 00198 vector<NodeID> getNeighborNodes() const; 00199 00200 //--- communication --- 00201 00212 LinkID establishLink(const NodeID& nid, const ServiceID& sid, 00213 const LinkProperties& req = LinkProperties::DEFAULT, 00214 const DataMessage& msg = DataMessage::UNSPECIFIED); 00215 00221 void dropLink(const LinkID& lnk); 00222 00223 // message sending 00224 00240 seqnum_t sendMessage(const DataMessage& msg, const NodeID& nid, const ServiceID& sid, 00241 const LinkProperties& req = LinkProperties::DEFAULT); 00242 00251 seqnum_t sendMessage(const DataMessage& msg, const LinkID& lnk); 00252 00261 void sendBroadcastMessage(const DataMessage& msg, const ServiceID& sid); 00262 00263 // --- communication listeners --- 00264 00274 bool bind(CommunicationListener* listener, const ServiceID& sid); 00275 00282 bool unbind(CommunicationListener* listener, const ServiceID& sid); 00283 00284 // --- extension proposal: service directory -- 00285 // main-idea: use this methods to register groups/rendevous points inside 00286 // the base overlay via a distributed storage service. 00287 // 00288 //void put(const KeyID& key, Message* value); 00289 //void get(const KeyID& key); 00290 //------------------------------------------------------------------------- 00291 // 00292 // --- optimization proposal: allow direct endpoint descriptor exchange --- 00293 // main-idea: directly allow exchanging endpoint descriptors to establish 00294 // links. Depending on the overlay structure used in the base overlay, this 00295 // allows a node to directly establish links between two nodes when an 00296 // endpoint descriptor is known. 00297 // 00298 //const EndpointDescriptor& getEndpointDescriptor( const LinkID& lid ); 00299 //void sendMessage( EndpointDescriptor& epd, Message* msg ); 00300 //LinkID setupLink( const EndpointDescriptor& endpointDesc, 00301 // const LinkProperties& req = LinkProperties::UNSPECIFIED, 00302 // const Message* msg = NULL ); 00303 // 00304 //------------------------------------------------------------------------- 00305 00306 // --- module implementation --- 00307 // 00308 // main-idea: use module properties to configure nodeid, spovnetid etc. and 00309 // select start/stop procedures. This allows simulations to start a 00310 // node without manually calling join etc. 00311 00313 void initialize(); 00314 00316 void start(); 00317 00319 void stop(); 00320 00322 string getName() const; 00323 00325 void setProperty(string key, string value); 00326 00328 const string getProperty(string key) const; 00329 00331 const vector<string> getProperties() const; 00332 00333 protected: 00334 // friends 00335 friend class AribaModule; 00336 00337 // member variables 00338 Name name; //< node name 00339 AribaModule& ariba_mod; //< ariba module 00340 SpoVNetID spovnetId; //< current spovnet id 00341 NodeID nodeId; //< current node id 00342 overlay::BaseOverlay* base_overlay; //< the base overlay 00343 }; 00344 00345 } // namespace ariba 00346 00347 #endif /* NODE_H_ */