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 | const communication::EndpointDescriptor* ep =
|
---|
64 | ariba_mod.getBootstrapNode(vnetname);
|
---|
65 |
|
---|
66 | // start base comm if not started
|
---|
67 | if( !ariba_mod.base_comm->isStarted() )
|
---|
68 | ariba_mod.base_comm->start();
|
---|
69 |
|
---|
70 | // start base overlay if not started
|
---|
71 | // join against ourselfs
|
---|
72 | if( !base_overlay->isStarted() )
|
---|
73 | base_overlay->start( *ariba_mod.base_comm, nodeId );
|
---|
74 | base_overlay->joinSpoVNet( spovnetId );
|
---|
75 |
|
---|
76 | // join against further nodes
|
---|
77 | if( ep != NULL && ep->isUnspecified() == false )
|
---|
78 | base_overlay->joinSpoVNet( spovnetId, *ep);
|
---|
79 | }
|
---|
80 |
|
---|
81 | void Node::initiate(const Name& vnetname, const SpoVNetProperties& parm) {
|
---|
82 | utility::OverlayParameterSet ovrpset;
|
---|
83 | ovrpset.setOverlayStructure(
|
---|
84 | (utility::OverlayParameterSet::_OverlayStructure)
|
---|
85 | parm.getBaseOverlayType()
|
---|
86 | );
|
---|
87 |
|
---|
88 | spovnetId = vnetname.toSpoVNetId();
|
---|
89 | nodeId = generateNodeId(name);
|
---|
90 |
|
---|
91 | // start base comm if not started
|
---|
92 | if( !ariba_mod.base_comm->isStarted() )
|
---|
93 | ariba_mod.base_comm->start();
|
---|
94 |
|
---|
95 | // start base overlay if not started
|
---|
96 | if( !base_overlay->isStarted() )
|
---|
97 | base_overlay->start( *ariba_mod.base_comm, nodeId );
|
---|
98 |
|
---|
99 | base_overlay->createSpoVNet( spovnetId, ovrpset );
|
---|
100 | }
|
---|
101 |
|
---|
102 | void Node::leave() {
|
---|
103 | base_overlay->leaveSpoVNet();
|
---|
104 | ariba_mod.base_comm->stop();
|
---|
105 | base_overlay->stop();
|
---|
106 | }
|
---|
107 |
|
---|
108 | const SpoVNetProperties& Node::getSpoVNetProperties() const {
|
---|
109 | return SpoVNetProperties::DEFAULT;
|
---|
110 | }
|
---|
111 |
|
---|
112 | const SpoVNetID& Node::getSpoVNetId() const {
|
---|
113 | return spovnetId;
|
---|
114 | }
|
---|
115 |
|
---|
116 | const NodeID& Node::getNodeId(const LinkID& lid) const {
|
---|
117 | if( lid == LinkID::UNSPECIFIED ) return nodeId;
|
---|
118 | else return base_overlay->getNodeID( lid );
|
---|
119 | }
|
---|
120 |
|
---|
121 | NodeID Node::generateNodeId(const Name& name) const {
|
---|
122 | if (name == Name::UNSPECIFIED) return Name::random().toNodeId();
|
---|
123 | else return name.toNodeId();
|
---|
124 | }
|
---|
125 |
|
---|
126 | vector<NodeID> Node::getNeighborNodes() const {
|
---|
127 | return base_overlay->getOverlayNeighbors();
|
---|
128 | }
|
---|
129 |
|
---|
130 | LinkID Node::establishLink(const NodeID& nid, const ServiceID& sid) {
|
---|
131 | return base_overlay->establishLink(nid, sid);
|
---|
132 | }
|
---|
133 |
|
---|
134 | void Node::dropLink(const LinkID& lnk) {
|
---|
135 | base_overlay->dropLink(lnk);
|
---|
136 | }
|
---|
137 |
|
---|
138 | seqnum_t Node::sendMessage(const DataMessage& msg, const NodeID& nid,
|
---|
139 | const ServiceID& sid, const LinkProperties& req) {
|
---|
140 | return base_overlay->sendMessage((Message*) msg, nid, sid);
|
---|
141 | }
|
---|
142 |
|
---|
143 | seqnum_t Node::sendMessage(const DataMessage& msg, const LinkID& lnk) {
|
---|
144 | return base_overlay->sendMessage((Message*) msg, lnk);
|
---|
145 | }
|
---|
146 |
|
---|
147 | void Node::sendBroadcastMessage(const DataMessage& msg, const ServiceID& sid) {
|
---|
148 | return base_overlay->broadcastMessage((Message*)msg, sid);
|
---|
149 | }
|
---|
150 |
|
---|
151 | bool Node::bind(NodeListener* listener) {
|
---|
152 | return base_overlay->bind(listener);
|
---|
153 | }
|
---|
154 |
|
---|
155 | bool Node::unbind(NodeListener* listener) {
|
---|
156 | return base_overlay->unbind(listener);
|
---|
157 | }
|
---|
158 |
|
---|
159 | bool Node::bind(CommunicationListener* listener, const ServiceID& sid) {
|
---|
160 | // bind the listener
|
---|
161 | bool ret = base_overlay->bind(listener, sid);
|
---|
162 |
|
---|
163 | // now that we have a listener, we can ask if sniffing is ok
|
---|
164 | if( ariba_mod.sideport_sniffer != NULL ){
|
---|
165 | base_overlay->registerSidePort(ariba_mod.sideport_sniffer);
|
---|
166 | }
|
---|
167 |
|
---|
168 | return ret;
|
---|
169 | }
|
---|
170 |
|
---|
171 | bool Node::unbind(CommunicationListener* listener, const ServiceID& sid) {
|
---|
172 | return base_overlay->unbind(listener, sid);
|
---|
173 | }
|
---|
174 |
|
---|
175 | // service directory
|
---|
176 |
|
---|
177 | void Node::put( const Data& key, const Data& value, uint16_t ttl, bool replace ) {
|
---|
178 | base_overlay->dhtPut(key,value,ttl,replace);
|
---|
179 | }
|
---|
180 |
|
---|
181 | void Node::get( const Data& key, const ServiceID& sid ) {
|
---|
182 | base_overlay->dhtGet(key,sid);
|
---|
183 | }
|
---|
184 |
|
---|
185 | // @see Module.h
|
---|
186 | string Node::getName() const {
|
---|
187 | return name.toString();
|
---|
188 | }
|
---|
189 |
|
---|
190 | } // namespace ariba
|
---|