00001 #ifndef __LINK_DESCRIPTOR_H 00002 #define __LINK_DESCRIPTOR_H 00003 00004 #include <iostream> 00005 #include <sstream> 00006 #include <ctime> 00007 #include <deque> 00008 #include <boost/foreach.hpp> 00009 00010 #include "ariba/utility/messages.h" 00011 #include "ariba/utility/types.h" 00012 #include "ariba/communication/EndpointDescriptor.h" 00013 #include "ariba/CommunicationListener.h" 00014 00015 namespace ariba { 00016 class CommunicationListener; 00017 } 00018 00019 using std::deque; 00020 using ariba::utility::Message; 00021 using ariba::utility::NodeID; 00022 using ariba::utility::SpoVNetID; 00023 using ariba::utility::ServiceID; 00024 using ariba::utility::LinkID; 00025 using ariba::CommunicationListener; 00026 using ariba::communication::EndpointDescriptor; 00027 00028 namespace ariba { 00029 namespace overlay { 00030 00031 class LinkDescriptor; 00032 00033 std::ostream& operator<<(std::ostream& s, const LinkDescriptor* ld ); 00034 std::ostream& operator<<(std::ostream& s, const LinkDescriptor& ld ); 00035 00037 class LinkDescriptor { 00038 public: 00039 // ctor 00040 LinkDescriptor() { 00041 // default values 00042 this->up = false; 00043 this->fromRemote = false; 00044 this->remoteNode = NodeID::UNSPECIFIED; 00045 this->overlayId = LinkID::create(); 00046 this->communicationUp = false; 00047 this->communicationId = LinkID::UNSPECIFIED; 00048 this->keepAliveTime = time(NULL); 00049 this->keepAliveMissed = 0; 00050 this->relaying = false; 00051 this->timeRelaying = time(NULL); 00052 this->dropAfterRelaying = false; 00053 this->service = ServiceID::UNSPECIFIED; 00054 this->listener = &CommunicationListener::DEFAULT; 00055 this->relayed = false; 00056 this->remoteLink = LinkID::UNSPECIFIED; 00057 this->autolink = false; 00058 this->lastuse = time(NULL); 00059 this->retryCounter = 0; 00060 } 00061 00062 // dtor 00063 ~LinkDescriptor() { 00064 flushQueue(); 00065 } 00066 00067 // general information about the link -------------------------------------- 00068 bool up; 00069 bool fromRemote; 00070 NodeID remoteNode; 00071 bool isVital() { 00072 return up && keepAliveMissed == 0; 00073 } 00074 bool isDirectVital() { 00075 return isVital() && communicationUp && !relayed; 00076 } 00077 00078 00079 // link identifiers -------------------------------------------------------- 00080 LinkID overlayId; 00081 LinkID communicationId; 00082 bool communicationUp; 00083 00084 // direct link retries ----------------------------------------------------- 00085 EndpointDescriptor endpoint; 00086 int retryCounter; 00087 00088 // link alive information -------------------------------------------------- 00089 time_t keepAliveTime; 00090 int keepAliveMissed; 00091 void setAlive() { 00092 keepAliveMissed = 0; 00093 keepAliveTime = time(NULL); 00094 } 00095 00096 // relay information ------------------------------------------------------- 00097 bool relayed; 00098 LinkID remoteLink; 00099 vector<NodeID> routeRecord; 00100 00101 // relay state ------------------------------------------------------------- 00102 bool relaying; 00103 bool dropAfterRelaying; 00104 time_t timeRelaying; 00105 void setRelaying() { 00106 relaying = true; 00107 timeRelaying = time(NULL); 00108 } 00109 00110 // owner ------------------------------------------------------------------- 00111 ServiceID service; 00112 CommunicationListener* listener; 00113 00114 // auto links -------------------------------------------------------------- 00115 bool autolink; 00116 time_t lastuse; 00117 deque<Message*> messageQueue; 00118 void setAutoUsed() { 00119 if (autolink) lastuse = time(NULL); 00120 } 00122 void flushQueue() { 00123 BOOST_FOREACH( Message* msg, messageQueue ) delete msg; 00124 messageQueue.clear(); 00125 } 00126 00127 // string representation --------------------------------------------------- 00128 std::string to_string() const { 00129 std::ostringstream s; 00130 s << "up=" << up << " "; 00131 s << "init=" << !fromRemote << " "; 00132 s << "id=" << overlayId.toString().substr(0,4) << " "; 00133 s << "serv=" << service.toString() << " "; 00134 s << "node=" << remoteNode.toString().substr(0,4) << " "; 00135 s << "relaying=" << relaying << " "; 00136 s << "miss=" << keepAliveMissed << " "; 00137 s << "auto=" << autolink << " "; 00138 if ( relayed ) { 00139 s << "| Relayed: "; 00140 s << "remote link=" << remoteLink.toString().substr(0,4) << " "; 00141 if (routeRecord.size()>0) { 00142 s << "route record="; 00143 for (size_t i=0; i<routeRecord.size(); i++) 00144 s << routeRecord[i].toString().substr(0,4) << " "; 00145 } 00146 } else { 00147 s << "| Direct: "; 00148 s << "using id=" << communicationId.toString().substr(0,4) << " "; 00149 s << "(up=" << communicationUp << ") "; 00150 } 00151 return s.str(); 00152 } 00153 }; 00154 00155 }} // namespace ariba, overlay 00156 00157 #endif // __LINK_DESCRIPTOR_H 00158