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 ) {
00059 return "";
00060 }
00061 return overlay->getEndpointDescriptor(link).toString();
00062 }
00063
00064 string SideportListener::getEndpointDescription( const NodeID& node ) const {
00065 if( overlay == NULL ) {
00066 return "";
00067 }
00068 return overlay->getEndpointDescriptor(node).toString();
00069 }
00070
00071 const NodeID& SideportListener::getNodeID( const LinkID& link ) const {
00072 if( overlay == NULL ) return NodeID::UNSPECIFIED;
00073 return overlay->getNodeID(link);
00074 }
00075
00076 vector<LinkID> SideportListener::getLinkIDs( const NodeID& node ) const {
00077 if( overlay == NULL ) return vector<LinkID>();
00078 return overlay->getLinkIDs( node );
00079 }
00080
00081 string SideportListener::getHtmlLinks(){
00082 return overlay->getLinkHTMLInfo();
00083 }
00084
00085 vector<NodeID> SideportListener::getOverlayNeighbors(bool deep){
00086 vector<NodeID> nodes;
00087 if( overlay == NULL ) return nodes;
00088
00089 nodes = overlay->getOverlayNeighbors(deep);
00090 return nodes;
00091 }
00092
00093 bool SideportListener::isRelayedNode(const NodeID& node){
00094 if( overlay == NULL ) return false;
00095
00096 bool relay = false;
00097
00098 BOOST_FOREACH( LinkDescriptor* link, overlay->links ){
00099
00100
00101 if(link->relayed == false && link->remoteNode == node && link->up)
00102 return false;
00103
00104
00105
00106 if( link->relayed && link->remoteNode == node && link->up)
00107 relay = true;
00108 }
00109
00110 return relay;
00111 }
00112
00113 bool SideportListener::isRelayingNode(const NodeID& node){
00114 if( overlay == NULL ) return false;
00115
00116 vector<NodeID> directnodes;
00117 BOOST_FOREACH( LinkDescriptor* link, overlay->links ){
00118 if(link == NULL) continue;
00119
00120 BOOST_FOREACH(NodeID route, link->routeRecord){
00121 if(route == node) return true;
00122 }
00123 }
00124
00125 return false;
00126 }
00127
00128 SideportListener::Protocol SideportListener::getReachabilityProtocol(const NodeID& node){
00129 int ret = SideportListener::undefined;
00130 if( overlay == NULL ) return (Protocol)ret;
00131
00132 using namespace ariba::addressing;
00133
00134 LinkDescriptor* link = NULL;
00135 BOOST_FOREACH( LinkDescriptor* lnk, overlay->links ){
00136 if(lnk->up && lnk->remoteNode == node && !lnk->relayed && lnk->communicationUp){
00137 link = lnk;
00138 break;
00139 }
00140 }
00141
00142 if (link == NULL) return (Protocol)ret;
00143
00144 BaseCommunication::LinkDescriptor& bclink =
00145 overlay->bc->queryLocalLink(link->communicationId);
00146
00147 if(bclink.isUnspecified() || bclink.remoteLocator == NULL) return (Protocol)ret;
00148
00149 const address_v* locator = bclink.remoteLocator;
00150
00151 if( locator->instanceof<tcpip_endpoint>() ){
00152 tcpip_endpoint tcpip = *locator;
00153
00154 if( tcpip.address().is_v4() || tcpip.address().is_v4_mapped() ){
00155 ret = SideportListener::ipv4;
00156 }else if( tcpip.address().is_v6() ){
00157 ret = SideportListener::ipv6;
00158 }
00159
00160 }else if( locator->instanceof<rfcomm_endpoint>() ){
00161 ret = SideportListener::rfcomm;
00162 }
00163
00164 return (Protocol)ret;
00165 }
00166
00167 void SideportListener::configure( overlay::BaseOverlay* _overlay ) {
00168 overlay = _overlay;
00169 }
00170
00171 void SideportListener::onLinkUp(const LinkID& lnk, const NodeID& local, const NodeID& remote, const SpoVNetID& spovnet){
00172 }
00173
00174 void SideportListener::onLinkDown(const LinkID& lnk, const NodeID& local, const NodeID& remote, const SpoVNetID& spovnet){
00175 }
00176
00177 void SideportListener::onLinkChanged(const LinkID& lnk, const NodeID& local, const NodeID& remote, const SpoVNetID& spovnet){
00178 }
00179
00180 void SideportListener::onLinkFail(const LinkID& lnk, const NodeID& local, const NodeID& remote, const SpoVNetID& spovnet){
00181 }
00182
00183 }