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

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