close Warning: Can't use blame annotator:
No changeset 2293 in the repository

source: source/ariba/Node.cpp@ 3995

Last change on this file since 3995 was 3718, checked in by Christoph Mayer, 16 years ago

-dynamische wahl des overlays durch den initiator, nodes kriegen bei join mitgeteilt welche overlay struktur zu verwenden ist

File size: 5.7 KB
RevLine 
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
45using ariba::communication::EndpointDescriptor;
46
47namespace ariba {
48
49Node::Node(AribaModule& ariba_mod, const Name& node_name) :
50 ariba_mod(ariba_mod), name(node_name) {
51 base_overlay = new BaseOverlay();
52}
53
54Node::~Node() {
55 delete base_overlay;
56 base_overlay = NULL;
57}
58
59void 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 if( ep == NULL ) {
66 std::cout << "no bootstrap node defined" << std::endl;
67 return;
68 }
69 ariba_mod.base_comm->start(ariba_mod.ip_addr, ariba_mod.tcp_port);
70 base_overlay->start( *ariba_mod.base_comm, nodeId );
71 base_overlay->joinSpoVNet( spovnetId, *ep);
72}
73
74void Node::initiate(const Name& vnetname, const SpoVNetProperties& parm) {
75 utility::OverlayParameterSet ovrpset;
76 ovrpset.setOverlayStructure(
77 (utility::OverlayParameterSet::_OverlayStructure)
78 parm.getBaseOverlayType()
79 );
80
81 spovnetId = vnetname.toSpoVNetId();
82 nodeId = generateNodeId(name);
83
84 ariba_mod.base_comm->start(ariba_mod.ip_addr, ariba_mod.tcp_port);
85
86 base_overlay->start( *ariba_mod.base_comm, nodeId );
87 base_overlay->createSpoVNet( spovnetId, ovrpset );
88
89 ariba_mod.addBootstrapNode(vnetname,
90 new EndpointDescriptor(ariba_mod.base_comm->getEndpointDescriptor()));
91}
92
93void Node::leave() {
94 base_overlay->leaveSpoVNet();
95 ariba_mod.base_comm->stop();
96 base_overlay->stop();
97}
98
99const SpoVNetProperties& Node::getSpoVNetProperties() const {
100 return SpoVNetProperties::DEFAULT;
101}
102
103const SpoVNetID& Node::getSpoVNetId() const {
104 return spovnetId;
105}
106
107const NodeID& Node::getNodeId(const LinkID& lid) const {
108 if( lid == LinkID::UNSPECIFIED ) return nodeId;
109 else return base_overlay->getNodeID( lid );
110}
111
112NodeID Node::generateNodeId(const Name& name) const {
113 if (name == Name::UNSPECIFIED) return Name::random().toNodeId();
114 else return name.toNodeId();
115}
116
117vector<NodeID> Node::getNeighborNodes() const {
118 return base_overlay->getOverlayNeighbors();
119}
120
121LinkID Node::establishLink(const NodeID& nid, const ServiceID& sid,
122 const LinkProperties& req, const DataMessage& msg) {
123 return base_overlay->establishLink(nid, sid);
124}
125
126void Node::dropLink(const LinkID& lnk) {
127 base_overlay->dropLink(lnk);
128}
129
130seqnum_t Node::sendMessage(const DataMessage& msg, const NodeID& nid,
131 const ServiceID& sid, const LinkProperties& req) {
132 return base_overlay->sendMessage((Message*) msg, nid, sid);
133}
134
135seqnum_t Node::sendMessage(const DataMessage& msg, const LinkID& lnk) {
136 return base_overlay->sendMessage((Message*) msg, lnk);
137}
138
139void Node::sendBroadcastMessage(const DataMessage& msg, const ServiceID& sid) {
140 return base_overlay->broadcastMessage((Message*)msg, sid);
141}
142
143bool Node::bind(NodeListener* listener) {
144 return base_overlay->bind(listener);
145}
146
147bool Node::unbind(NodeListener* listener) {
148 return base_overlay->unbind(listener);
149}
150
151bool Node::bind(CommunicationListener* listener, const ServiceID& sid) {
152 // bind the listener
153 bool ret = base_overlay->bind(listener, sid);
154
155 // now that we have a listener, we can ask if sniffing is ok
156 if( ariba_mod.sideport_sniffer != NULL ){
157 bool allow = listener->onEnableSideportListener();
158 base_overlay->registerSidePort(ariba_mod.sideport_sniffer);
159 }
160
161 return ret;
162}
163
164bool Node::unbind(CommunicationListener* listener, const ServiceID& sid) {
165 return base_overlay->unbind(listener, sid);
166}
167
168// service directory
169/*
170 void Node::put(const Identifier<>& key, Message* value) {
171 }
172
173 void Node::get(const Identifier<>& key) {
174
175 }
176 */
177
178// @see Module.h
179void Node::initialize() {
180
181}
182
183// @see Module.h
184void Node::start() {
185
186}
187
188// @see Module.h
189void Node::stop() {
190
191}
192
193// @see Module.h
194string Node::getName() const {
195
196}
197
198// @see Module.h
199void Node::setProperty(string key, string value) {
200
201}
202
203// @see Module.h
204const string Node::getProperty(string key) const {
205
206}
207
208// @see Module.h
209const vector<string> Node::getProperties() const {
210
211}
212
213} // namespace ariba
Note: See TracBrowser for help on using the repository browser.