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

source: source/ariba/overlay/LinkDescriptor.h@ 7468

Last change on this file since 7468 was 6961, checked in by mies, 14 years ago
File size: 4.8 KB
RevLine 
1#ifndef __LINK_DESCRIPTOR_H
2#define __LINK_DESCRIPTOR_H
3
4#include <iostream>
5#include <sstream>
6#include <ctime>
7#include <deque>
8#include <boost/foreach.hpp>
9
10#include "ariba/utility/messages.h"
11#include "ariba/utility/types.h"
12#include "ariba/communication/EndpointDescriptor.h"
13#include "ariba/CommunicationListener.h"
14
15namespace ariba {
16 class CommunicationListener;
17}
18
19using std::deque;
20using ariba::utility::Message;
21using ariba::utility::NodeID;
22using ariba::utility::SpoVNetID;
23using ariba::utility::ServiceID;
24using ariba::utility::LinkID;
25using ariba::CommunicationListener;
26using ariba::communication::EndpointDescriptor;
27
28namespace ariba {
29namespace overlay {
30
31class LinkDescriptor;
32
33std::ostream& operator<<(std::ostream& s, const LinkDescriptor* ld );
34std::ostream& operator<<(std::ostream& s, const LinkDescriptor& ld );
35
36/// LinkDescriptor
37class LinkDescriptor {
38public:
39 // ctor
40 LinkDescriptor() {
41 // default values
42 this->up = false;
43 this->fromRemote = false;
44 this->remoteNode = NodeID::UNSPECIFIED;
45 this->overlayId = LinkID::create();
46 this->communicationUp = false;
47 this->communicationId = LinkID::UNSPECIFIED;
48 this->keepAliveTime = time(NULL);
49 this->keepAliveMissed = 0;
50 this->relaying = false;
51 this->timeRelaying = time(NULL);
52 this->dropAfterRelaying = false;
53 this->service = ServiceID::UNSPECIFIED;
54 this->listener = &CommunicationListener::DEFAULT;
55 this->relayed = false;
56 this->remoteLink = LinkID::UNSPECIFIED;
57 this->autolink = false;
58 this->lastuse = time(NULL);
59 this->retryCounter = 0;
60 }
61
62 // dtor
63 ~LinkDescriptor() {
64 flushQueue();
65 }
66
67 // general information about the link --------------------------------------
68 bool up; ///< flag whether this link is up and running
69 bool fromRemote; ///< flag, whether this link was requested from remote
70 NodeID remoteNode; ///< remote end-point node
71 bool isVital() {
72 return up && keepAliveMissed == 0;
73 }
74 bool isDirectVital() {
75 return isVital() && communicationUp && !relayed;
76 }
77
78
79 // link identifiers --------------------------------------------------------
80 LinkID overlayId; ///< the base overlay link id
81 LinkID communicationId; ///< the communication id
82 bool communicationUp; ///< flag, whether the communication is up
83
84 // direct link retries -----------------------------------------------------
85 EndpointDescriptor endpoint;
86 int retryCounter;
87
88 // link alive information --------------------------------------------------
89 time_t keepAliveTime; ///< the last time a keep-alive message was received
90 int keepAliveMissed; ///< the number of missed keep-alive messages
91 void setAlive() {
92 keepAliveMissed = 0;
93 keepAliveTime = time(NULL);
94 }
95
96 // relay information -------------------------------------------------------
97 bool relayed; ///< flag whether this link is a relayed link
98 LinkID remoteLink; ///< the remote link id
99 vector<NodeID> routeRecord;
100
101 // relay state -------------------------------------------------------------
102 bool relaying; ///< flag, wheter this link has been used as relay
103 bool dropAfterRelaying;
104 time_t timeRelaying; ///< last time the link has been used as relay
105 void setRelaying() {
106 relaying = true;
107 timeRelaying = time(NULL);
108 }
109
110 // owner -------------------------------------------------------------------
111 ServiceID service; ///< service using this link
112 CommunicationListener* listener; ///< the listener using this node
113
114 // auto links --------------------------------------------------------------
115 bool autolink; ///< flag, whether this link is a auto-link
116 time_t lastuse; ///< time, when the link was last used
117 deque<Message*> messageQueue; ///< waiting messages to be delivered
118 void setAutoUsed() {
119 if (autolink) lastuse = time(NULL);
120 }
121 /// drops waiting auto-link messages
122 void flushQueue() {
123 BOOST_FOREACH( Message* msg, messageQueue ) delete msg;
124 messageQueue.clear();
125 }
126
127 // string representation ---------------------------------------------------
128 std::string to_string() const {
129 std::ostringstream s;
130 s << "up=" << up << " ";
131 s << "init=" << !fromRemote << " ";
132 s << "id=" << overlayId.toString().substr(0,4) << " ";
133 s << "serv=" << service.toString() << " ";
134 s << "node=" << remoteNode.toString().substr(0,4) << " ";
135 s << "relaying=" << relaying << " ";
136 s << "miss=" << keepAliveMissed << " ";
137 s << "auto=" << autolink << " ";
138 if ( relayed ) {
139 s << "| Relayed: ";
140 s << "remote link=" << remoteLink.toString().substr(0,4) << " ";
141 if (routeRecord.size()>0) {
142 s << "route record=";
143 for (size_t i=0; i<routeRecord.size(); i++)
144 s << routeRecord[i].toString().substr(0,4) << " ";
145 }
146 } else {
147 s << "| Direct: ";
148 s << "using id=" << communicationId.toString().substr(0,4) << " ";
149 s << "(up=" << communicationUp << ") ";
150 }
151 return s.str();
152 }
153};
154
155}} // namespace ariba, overlay
156
157#endif // __LINK_DESCRIPTOR_H
158
Note: See TracBrowser for help on using the repository browser.