source: source/ariba/SideportListener.cpp@ 7041

Last change on this file since 7041 was 6944, checked in by mies, 15 years ago
File size: 5.7 KB
Line 
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 "SideportListener.h"
40
41#include "ariba/overlay/BaseOverlay.h"
42#include "ariba/overlay/LinkDescriptor.h"
43#include "ariba/utility/addressing/endpoint_set.hpp"
44
45using ariba::overlay::LinkDescriptor;
46
47namespace ariba {
48
49SideportListener SideportListener::DEFAULT;
50
51SideportListener::SideportListener() : overlay(NULL) {
52}
53
54SideportListener::~SideportListener(){
55}
56
57string SideportListener::getEndpointDescription( const LinkID& link ) const {
58 if( overlay == NULL ) {
59 std::cerr << "Sideport: No overlay found." << std::endl;
60 return "";
61 }
62 std::cerr << "WTF!!!" << std::endl;
63 return overlay->getEndpointDescriptor(link).toString();
64}
65
66string SideportListener::getEndpointDescription( const NodeID& node ) const {
67 if( overlay == NULL ) {
68 std::cerr << "Sideport: No overlay found." << std::endl;
69 return "";
70 }
71 return overlay->getEndpointDescriptor(node).toString();
72}
73
74const NodeID& SideportListener::getNodeID( const LinkID& link ) const {
75 if( overlay == NULL ) return NodeID::UNSPECIFIED;
76 return overlay->getNodeID(link);
77}
78
79vector<LinkID> SideportListener::getLinkIDs( const NodeID& node ) const {
80 if( overlay == NULL ) return vector<LinkID>();
81 return overlay->getLinkIDs( node );
82}
83
84string SideportListener::getHtmlLinks(){
85 return overlay->getLinkHTMLInfo();
86}
87
88vector<NodeID> SideportListener::getOverlayNeighbors(bool deep){
89 vector<NodeID> nodes;
90 if( overlay == NULL ) return nodes;
91
92 nodes = overlay->getOverlayNeighbors(deep);
93 return nodes;
94}
95
96bool SideportListener::isRelayedNode(const NodeID& node){
97 if( overlay == NULL ) return false;
98
99 bool relay = false;
100
101 BOOST_FOREACH( LinkDescriptor* link, overlay->links ){
102
103 // is we find a direct connection this is not a relayed node
104 if(link->relayed == false && link->remoteNode == node && link->up)
105 return false;
106
107 // if we find a relay connection this can be a relayed node
108 // but only if we find no direct connection as above
109 if( link->relayed && link->remoteNode == node && link->up)
110 relay = true;
111 }
112
113 return relay;
114}
115
116bool SideportListener::isRelayingNode(const NodeID& node){
117 if( overlay == NULL ) return false;
118
119 vector<NodeID> directnodes;
120 BOOST_FOREACH( LinkDescriptor* link, overlay->links ){
121 if(link == NULL) continue;
122
123 BOOST_FOREACH(NodeID route, link->routeRecord){
124 if(route == node) return true;
125 }
126 }
127
128 return false;
129}
130
131SideportListener::Protocol SideportListener::getReachabilityProtocol(const NodeID& node){
132 int ret = SideportListener::undefined;
133 if( overlay == NULL ) return (Protocol)ret;
134
135 using namespace ariba::addressing;
136
137 LinkDescriptor* link = NULL;
138 BOOST_FOREACH( LinkDescriptor* lnk, overlay->links ){
139 if(lnk->up && lnk->remoteNode == node && !lnk->relayed && lnk->communicationUp){
140 link = lnk;
141 break;
142 }
143 }
144
145 if (link == NULL) return (Protocol)ret;
146
147 BaseCommunication::LinkDescriptor& bclink =
148 overlay->bc->queryLocalLink(link->communicationId);
149
150 if(bclink.isUnspecified() || bclink.remoteLocator == NULL) return (Protocol)ret;
151
152 const address_v* locator = bclink.remoteLocator;
153
154 if( locator->instanceof<tcpip_endpoint>() ){
155 tcpip_endpoint tcpip = *locator;
156
157 if( tcpip.address().is_v4() || tcpip.address().is_v4_mapped() ){
158 ret = SideportListener::ipv4;
159 }else if( tcpip.address().is_v6() ){
160 ret = SideportListener::ipv6;
161 }
162
163 }else if( locator->instanceof<rfcomm_endpoint>() ){
164 ret = SideportListener::rfcomm;
165 }
166
167 return (Protocol)ret;
168}
169
170void SideportListener::configure( overlay::BaseOverlay* _overlay ) {
171 overlay = _overlay;
172}
173
174void SideportListener::onLinkUp(const LinkID& lnk, const NodeID& local, const NodeID& remote, const SpoVNetID& spovnet){
175}
176
177void SideportListener::onLinkDown(const LinkID& lnk, const NodeID& local, const NodeID& remote, const SpoVNetID& spovnet){
178}
179
180void SideportListener::onLinkChanged(const LinkID& lnk, const NodeID& local, const NodeID& remote, const SpoVNetID& spovnet){
181}
182
183void SideportListener::onLinkFail(const LinkID& lnk, const NodeID& local, const NodeID& remote, const SpoVNetID& spovnet){
184}
185
186} // namespace ariba
Note: See TracBrowser for help on using the repository browser.