| 1 | // [License]
|
---|
| 2 | // The Ariba-Underlay Copyright
|
---|
| 3 | //
|
---|
| 4 | // Copyright (c) 2008-2009, Institute of Telematics, UniversitÀt Karlsruhe (TH)
|
---|
| 5 | //
|
---|
| 6 | // Institute of Telematics
|
---|
| 7 | // UniversitÀt Karlsruhe (TH)
|
---|
| 8 | // Zirkel 2, 76128 Karlsruhe
|
---|
| 9 | // Germany
|
---|
| 10 | //
|
---|
| 11 | // Redistribution and use in source and binary forms, with or without
|
---|
| 12 | // modification, are permitted provided that the following conditions are
|
---|
| 13 | // met:
|
---|
| 14 | //
|
---|
| 15 | // 1. Redistributions of source code must retain the above copyright
|
---|
| 16 | // notice, this list of conditions and the following disclaimer.
|
---|
| 17 | // 2. Redistributions in binary form must reproduce the above copyright
|
---|
| 18 | // notice, this list of conditions and the following disclaimer in the
|
---|
| 19 | // documentation and/or other materials provided with the distribution.
|
---|
| 20 | //
|
---|
| 21 | // THIS SOFTWARE IS PROVIDED BY THE INSTITUTE OF TELEMATICS ``AS IS'' AND
|
---|
| 22 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
| 23 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
---|
| 24 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OF TELEMATICS OR
|
---|
| 25 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
---|
| 26 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
---|
| 27 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
---|
| 28 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
---|
| 29 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
---|
| 30 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
---|
| 31 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 32 | //
|
---|
| 33 | // The views and conclusions contained in the software and documentation
|
---|
| 34 | // are those of the authors and should not be interpreted as representing
|
---|
| 35 | // official policies, either expressed or implied, of the Institute of
|
---|
| 36 | // Telematics.
|
---|
| 37 | // [License]
|
---|
| 38 |
|
---|
| 39 | #include "Node.h"
|
---|
| 40 |
|
---|
| 41 | #include "ariba/overlay/BaseOverlay.h"
|
---|
| 42 | #include "ariba/utility/types/OverlayParameterSet.h"
|
---|
| 43 | #include "ariba/communication/EndpointDescriptor.h"
|
---|
| 44 |
|
---|
| 45 | using ariba::communication::EndpointDescriptor;
|
---|
| 46 |
|
---|
| 47 | namespace ariba {
|
---|
| 48 |
|
---|
| 49 | Node::Node(AribaModule& ariba_mod, const Name& node_name) :
|
---|
| 50 | name(node_name), ariba_mod(ariba_mod) {
|
---|
| 51 | base_overlay = new BaseOverlay();
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | Node::~Node() {
|
---|
| 55 | delete base_overlay;
|
---|
| 56 | base_overlay = NULL;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | void Node::join(const Name& vnetname) {
|
---|
| 60 | spovnetId = vnetname.toSpoVNetId();
|
---|
| 61 | nodeId = generateNodeId(name);
|
---|
| 62 |
|
---|
| 63 | // start base comm if not started
|
---|
| 64 | if( !ariba_mod.base_comm->isStarted() )
|
---|
| 65 | ariba_mod.base_comm->start();
|
---|
| 66 |
|
---|
| 67 | // start base overlay if not started
|
---|
| 68 | // join against ourselfs
|
---|
| 69 | if( !base_overlay->isStarted() )
|
---|
| 70 | base_overlay->start( *ariba_mod.base_comm, nodeId );
|
---|
| 71 | base_overlay->joinSpoVNet( spovnetId );
|
---|
| 72 |
|
---|
| 73 | // join against static bootstrap points and
|
---|
| 74 | // start automatic bootstrapping modules
|
---|
| 75 | vector<AribaModule::BootstrapMechanism> mechanisms
|
---|
| 76 | = ariba_mod.getBootstrapMechanisms(vnetname);
|
---|
| 77 |
|
---|
| 78 | vector<pair<BootstrapManager::BootstrapType,string> > internalmodules;
|
---|
| 79 |
|
---|
| 80 | BOOST_FOREACH(AribaModule::BootstrapMechanism m, mechanisms){
|
---|
| 81 | switch(m){
|
---|
| 82 | case AribaModule::BootstrapMechanismStatic:
|
---|
| 83 | {
|
---|
| 84 | const communication::EndpointDescriptor* ep =
|
---|
| 85 | ariba_mod.getBootstrapNode(vnetname, m);
|
---|
| 86 | if( ep != NULL && ep->isUnspecified() == false )
|
---|
| 87 | base_overlay->joinSpoVNet( spovnetId, *ep);
|
---|
| 88 | break;
|
---|
| 89 | }
|
---|
| 90 | case AribaModule::BootstrapMechanismBroadcast:
|
---|
| 91 | internalmodules.push_back(make_pair(
|
---|
| 92 | BootstrapManager::BootstrapTypePeriodicBroadcast,
|
---|
| 93 | ariba_mod.getBootstrapInfo(vnetname, m)));
|
---|
| 94 | break;
|
---|
| 95 | case AribaModule::BootstrapMechanismMulticastDNS:
|
---|
| 96 | internalmodules.push_back(make_pair(
|
---|
| 97 | BootstrapManager::BootstrapTypeMulticastDns,
|
---|
| 98 | ariba_mod.getBootstrapInfo(vnetname, m)));
|
---|
| 99 | break;
|
---|
| 100 | case AribaModule::BootstrapMechanismSDP:
|
---|
| 101 | internalmodules.push_back(make_pair(
|
---|
| 102 | BootstrapManager::BootstrapTypeBluetoothSdp,
|
---|
| 103 | ariba_mod.getBootstrapInfo(vnetname, m)));
|
---|
| 104 | break;
|
---|
| 105 | default:
|
---|
| 106 | break;
|
---|
| 107 | }
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | // start automatic overlay bootstrapping modules
|
---|
| 111 | base_overlay->startBootstrapModules(internalmodules);
|
---|
| 112 |
|
---|
| 113 | // done
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | void Node::initiate(const Name& vnetname, const SpoVNetProperties& parm) {
|
---|
| 117 | utility::OverlayParameterSet ovrpset;
|
---|
| 118 | ovrpset.setOverlayStructure(
|
---|
| 119 | (utility::OverlayParameterSet::_OverlayStructure)
|
---|
| 120 | parm.getBaseOverlayType()
|
---|
| 121 | );
|
---|
| 122 |
|
---|
| 123 | spovnetId = vnetname.toSpoVNetId();
|
---|
| 124 | nodeId = generateNodeId(name);
|
---|
| 125 |
|
---|
| 126 | // start base comm if not started
|
---|
| 127 | if( !ariba_mod.base_comm->isStarted() )
|
---|
| 128 | ariba_mod.base_comm->start();
|
---|
| 129 |
|
---|
| 130 | // start base overlay if not started
|
---|
| 131 | if( !base_overlay->isStarted() )
|
---|
| 132 | base_overlay->start( *ariba_mod.base_comm, nodeId );
|
---|
| 133 |
|
---|
| 134 | base_overlay->createSpoVNet( spovnetId, ovrpset );
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | void Node::leave() {
|
---|
| 138 | base_overlay->stopBootstrapModules();
|
---|
| 139 | base_overlay->leaveSpoVNet();
|
---|
| 140 | ariba_mod.base_comm->stop();
|
---|
| 141 | base_overlay->stop();
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | const SpoVNetProperties& Node::getSpoVNetProperties() const {
|
---|
| 145 | return SpoVNetProperties::DEFAULT;
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | const SpoVNetID& Node::getSpoVNetId() const {
|
---|
| 149 | return spovnetId;
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | const NodeID& Node::getNodeId(const LinkID& lid) const {
|
---|
| 153 | if( lid == LinkID::UNSPECIFIED ) return nodeId;
|
---|
| 154 | else return base_overlay->getNodeID( lid );
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | NodeID Node::generateNodeId(const Name& name) const {
|
---|
| 158 | if (name == Name::UNSPECIFIED) return Name::random().toNodeId();
|
---|
| 159 | else return name.toNodeId();
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | vector<NodeID> Node::getNeighborNodes() const {
|
---|
| 163 | return base_overlay->getOverlayNeighbors();
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | LinkID Node::establishLink(const NodeID& nid, const ServiceID& sid) {
|
---|
| 167 | return base_overlay->establishLink(nid, sid);
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | void Node::dropLink(const LinkID& lnk) {
|
---|
| 171 | base_overlay->dropLink(lnk);
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | seqnum_t Node::sendMessage(const DataMessage& msg, const NodeID& nid,
|
---|
| 175 | const ServiceID& sid, const LinkProperties& req) {
|
---|
| 176 | return base_overlay->sendMessage((Message*) msg, nid, sid);
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | NodeID Node::sendMessageCloserToNodeID(const DataMessage& msg, const NodeID& nid, const ServiceID& sid,
|
---|
| 180 | const LinkProperties& req) {
|
---|
| 181 |
|
---|
| 182 | return base_overlay->sendMessageCloserToNodeID((Message*) msg, nid, sid);
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 |
|
---|
| 186 | seqnum_t Node::sendMessage(const DataMessage& msg, const LinkID& lnk) {
|
---|
| 187 | return base_overlay->sendMessage((Message*) msg, lnk);
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | void Node::sendBroadcastMessage(const DataMessage& msg, const ServiceID& sid) {
|
---|
| 191 | return base_overlay->broadcastMessage((Message*)msg, sid);
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 | bool Node::bind(NodeListener* listener) {
|
---|
| 195 | return base_overlay->bind(listener);
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 | bool Node::unbind(NodeListener* listener) {
|
---|
| 199 | return base_overlay->unbind(listener);
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 | bool Node::bind(CommunicationListener* listener, const ServiceID& sid) {
|
---|
| 203 | // bind the listener
|
---|
| 204 | bool ret = base_overlay->bind(listener, sid);
|
---|
| 205 |
|
---|
| 206 | // now that we have a listener, we can ask if sniffing is ok
|
---|
| 207 | if( ariba_mod.sideport_sniffer != NULL ){
|
---|
| 208 | base_overlay->registerSidePort(ariba_mod.sideport_sniffer);
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | return ret;
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | bool Node::unbind(CommunicationListener* listener, const ServiceID& sid) {
|
---|
| 215 | return base_overlay->unbind(listener, sid);
|
---|
| 216 | }
|
---|
| 217 |
|
---|
| 218 | // @see Module.h
|
---|
| 219 | string Node::getName() const {
|
---|
| 220 | return name.toString();
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 | } // namespace ariba
|
---|