00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include "SideportListener.h"
00040
00041 #include "ariba/overlay/BaseOverlay.h"
00042 #include "ariba/overlay/LinkDescriptor.h"
00043 #include "ariba/utility/addressing/endpoint_set.hpp"
00044
00045 using ariba::overlay::LinkDescriptor;
00046
00047 namespace ariba {
00048
00049 SideportListener SideportListener::DEFAULT;
00050
00051 SideportListener::SideportListener() : overlay(NULL) {
00052 }
00053
00054 SideportListener::~SideportListener(){
00055 }
00056
00057 string SideportListener::getEndpointDescription( const LinkID& link ) const {
00058 if( overlay == NULL ) return "";
00059 return overlay->getEndpointDescriptor(link).toString();
00060 }
00061
00062 string SideportListener::getEndpointDescription( const NodeID& node ) const {
00063 if( overlay == NULL ) return "";
00064 return overlay->getEndpointDescriptor(node).toString();
00065 }
00066
00067 const NodeID& SideportListener::getNodeID( const LinkID& link ) const {
00068 if( overlay == NULL ) return NodeID::UNSPECIFIED;
00069 return overlay->getNodeID(link);
00070 }
00071
00072 vector<LinkID> SideportListener::getLinkIDs( const NodeID& node ) const {
00073 if( overlay == NULL ) return vector<LinkID>();
00074 return overlay->getLinkIDs( node );
00075 }
00076
00077 string SideportListener::getHtmlLinks(){
00078 return overlay->getLinkHTMLInfo();
00079 }
00080
00081 vector<NodeID> SideportListener::getOverlayNeighbors(bool deep){
00082 vector<NodeID> nodes;
00083 if( overlay == NULL ) return nodes;
00084
00085 nodes = overlay->getOverlayNeighbors(deep);
00086 return nodes;
00087 }
00088
00089 bool SideportListener::isRelayedNode(const NodeID& node){
00090 if( overlay == NULL ) return false;
00091
00092 bool relay = false;
00093
00094 BOOST_FOREACH( LinkDescriptor* link, overlay->links ){
00095
00096
00097 if(link->relayed == false && link->remoteNode == node && link->up)
00098 return false;
00099
00100
00101
00102 if( link->relayed && link->remoteNode == node && link->up)
00103 relay = true;
00104 }
00105
00106 return relay;
00107 }
00108
00109 bool SideportListener::isRelayingNode(const NodeID& node){
00110 if( overlay == NULL ) return false;
00111
00112 vector<NodeID> directnodes;
00113 BOOST_FOREACH( LinkDescriptor* link, overlay->links ){
00114 if(link == NULL) continue;
00115
00116 BOOST_FOREACH(NodeID route, link->routeRecord){
00117 if(route == node) return true;
00118 }
00119 }
00120
00121 return false;
00122 }
00123
00124 SideportListener::Protocol SideportListener::getReachabilityProtocol(const NodeID& node){
00125 int ret = SideportListener::undefined;
00126 if( overlay == NULL ) return (Protocol)ret;
00127
00128 using namespace ariba::addressing;
00129
00130 LinkDescriptor* link = NULL;
00131 BOOST_FOREACH( LinkDescriptor* lnk, overlay->links ){
00132 if(lnk->up && lnk->remoteNode == node && !lnk->relayed && lnk->communicationUp){
00133 link = lnk;
00134 break;
00135 }
00136 }
00137
00138 if (link == NULL) return (Protocol)ret;
00139
00140 BaseCommunication::LinkDescriptor& bclink =
00141 overlay->bc->queryLocalLink(link->communicationId);
00142
00143 if(bclink.isUnspecified() || bclink.remoteLocator == NULL) return (Protocol)ret;
00144
00145 const address_v* locator = bclink.remoteLocator;
00146
00147 if( locator->instanceof<tcpip_endpoint>() ){
00148 tcpip_endpoint tcpip = *locator;
00149
00150 if( tcpip.address().is_v4() || tcpip.address().is_v4_mapped() ){
00151 ret = SideportListener::ipv4;
00152 }else if( tcpip.address().is_v6() ){
00153 ret = SideportListener::ipv6;
00154 }
00155
00156 }else if( locator->instanceof<rfcomm_endpoint>() ){
00157 ret = SideportListener::rfcomm;
00158 }
00159
00160 return (Protocol)ret;
00161 }
00162
00163 void SideportListener::configure( overlay::BaseOverlay* _overlay ) {
00164 overlay = _overlay;
00165 }
00166
00167 void SideportListener::onLinkUp(const LinkID& lnk, const NodeID& local, const NodeID& remote, const SpoVNetID& spovnet){
00168 }
00169
00170 void SideportListener::onLinkDown(const LinkID& lnk, const NodeID& local, const NodeID& remote, const SpoVNetID& spovnet){
00171 }
00172
00173 void SideportListener::onLinkChanged(const LinkID& lnk, const NodeID& local, const NodeID& remote, const SpoVNetID& spovnet){
00174 }
00175
00176 void SideportListener::onLinkFail(const LinkID& lnk, const NodeID& local, const NodeID& remote, const SpoVNetID& spovnet){
00177 }
00178
00179 }