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

Last change on this file since 5876 was 5873, checked in by mies, 15 years ago
File size: 4.4 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
69 // link identifiers --------------------------------------------------------
70 LinkID overlayId; ///< the base overlay link id
71 LinkID communicationId; ///< the communication id
72 bool communicationUp; ///< flag, whether the communication is up
73
74 // link alive information --------------------------------------------------
75 time_t keepAliveTime; ///< the last time a keep-alive message was received
76 int keepAliveMissed; ///< the number of missed keep-alive messages
77 void setAlive() {
78 keepAliveMissed = 0;
79 keepAliveTime = time(NULL);
80 }
81
82 // relay information -------------------------------------------------------
83 bool relayed; ///< flag whether this link is a relayed link
84 LinkID remoteLink; ///< the remote link id
85 vector<NodeID> routeRecord;
86
87 // relay state -------------------------------------------------------------
88 bool relaying; ///< flag, wheter this link has been used as relay
89 bool dropAfterRelaying;
90 time_t timeRelaying; ///< last time the link has been used as relay
91 void setRelaying() {
92 relaying = true;
93 timeRelaying = time(NULL);
94 }
95
96 // owner -------------------------------------------------------------------
97 ServiceID service; ///< service using this link
98 CommunicationListener* listener; ///< the listener using this node
99
100 // auto links --------------------------------------------------------------
101 bool autolink; ///< flag, whether this link is a auto-link
102 time_t lastuse; ///< time, when the link was last used
103 deque<Message*> messageQueue; ///< waiting messages to be delivered
104 void setAutoUsed() {
105 if (autolink) lastuse = time(NULL);
106 }
107 /// drops waiting auto-link messages
108 void flushQueue() {
109 BOOST_FOREACH( Message* msg, messageQueue ) delete msg;
110 messageQueue.clear();
111 }
112
113 // string representation ---------------------------------------------------
114 std::string to_string() const {
115 std::ostringstream s;
116 s << "up=" << up << " ";
117 s << "init=" << !fromRemote << " ";
118 s << "id=" << overlayId.toString().substr(0,4) << " ";
119 s << "serv=" << service.toString() << " ";
120 s << "node=" << remoteNode.toString().substr(0,4) << " ";
121 s << "relaying=" << relaying << " ";
122 s << "miss=" << keepAliveMissed << " ";
123 s << "auto=" << autolink << " ";
124 if ( relayed ) {
125 s << "| Relayed: ";
126 s << "remote link=" << remoteLink.toString().substr(0,4) << " ";
127 if (routeRecord.size()>0) {
128 s << "route record=";
129 for (size_t i=0; i<routeRecord.size(); i++)
130 s << routeRecord[i].toString().substr(0,4) << " ";
131 }
132 } else {
133 s << "| Direct: ";
134 s << "using id=" << communicationId.toString().substr(0,4) << " ";
135 s << "(up=" << communicationUp << ") ";
136 }
137 return s.str();
138 }
139};
140
141}} // namespace ariba, overlay
142
143#endif // __LINK_DESCRIPTOR_H
144
Note: See TracBrowser for help on using the repository browser.