1 | // [License] |
---|
2 | // The Ariba-Underlay Copyright |
---|
3 | // |
---|
4 | // Copyright (c) 2008-2009, Institute of Telematics, UniversitÀt Karlsruhe (TH) |
---|
5 | // |
---|
6 | // Institute of Telematics |
---|
7 | // UniversitÀt Karlsruhe (TH) |
---|
8 | // Zirkel 2, 76128 Karlsruhe |
---|
9 | // Germany |
---|
10 | // |
---|
11 | // Redistribution and use in source and binary forms, with or without |
---|
12 | // modification, are permitted provided that the following conditions are |
---|
13 | // met: |
---|
14 | // |
---|
15 | // 1. Redistributions of source code must retain the above copyright |
---|
16 | // notice, this list of conditions and the following disclaimer. |
---|
17 | // 2. Redistributions in binary form must reproduce the above copyright |
---|
18 | // notice, this list of conditions and the following disclaimer in the |
---|
19 | // documentation and/or other materials provided with the distribution. |
---|
20 | // |
---|
21 | // THIS SOFTWARE IS PROVIDED BY THE INSTITUTE OF TELEMATICS ``AS IS'' AND |
---|
22 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
23 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
---|
24 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OF TELEMATICS OR |
---|
25 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
26 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
27 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
28 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
29 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
30 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
31 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | // |
---|
33 | // The views and conclusions contained in the software and documentation |
---|
34 | // are those of the authors and should not be interpreted as representing |
---|
35 | // official policies, either expressed or implied, of the Institute of |
---|
36 | // Telematics. |
---|
37 | // [License] |
---|
38 | |
---|
39 | #ifndef SIDEPORTLISTENER_H_ |
---|
40 | #define SIDEPORTLISTENER_H_ |
---|
41 | |
---|
42 | #include <vector> |
---|
43 | #include <map> |
---|
44 | #include <boost/foreach.hpp> |
---|
45 | #include "Identifiers.h" |
---|
46 | #include "CommunicationListener.h" |
---|
47 | |
---|
48 | using std::map; |
---|
49 | using std::vector; |
---|
50 | |
---|
51 | namespace ariba { |
---|
52 | |
---|
53 | // forward declerations |
---|
54 | class Node; |
---|
55 | class AribaModule; |
---|
56 | namespace overlay { |
---|
57 | class BaseOverlay; |
---|
58 | } |
---|
59 | |
---|
60 | /** |
---|
61 | * A sideport class to gather advanced information about nodes, links, |
---|
62 | * their endpoints and get information about all link activity on a node. |
---|
63 | * |
---|
64 | * @author Christoph Mayer <mayer@tm.uka.de> |
---|
65 | */ |
---|
66 | class SideportListener { |
---|
67 | |
---|
68 | friend class Node; |
---|
69 | friend class AribaModule; |
---|
70 | friend class overlay::BaseOverlay; |
---|
71 | |
---|
72 | public: |
---|
73 | |
---|
74 | /** |
---|
75 | * A default object of the SideportListener that has empty |
---|
76 | * event functions and will return invalid information. |
---|
77 | */ |
---|
78 | static SideportListener DEFAULT; |
---|
79 | |
---|
80 | /** |
---|
81 | * Constructor of the SideportListener. |
---|
82 | */ |
---|
83 | SideportListener(); |
---|
84 | |
---|
85 | /** |
---|
86 | * Virtual Desctructor for the SideportListener. |
---|
87 | */ |
---|
88 | virtual ~SideportListener(); |
---|
89 | |
---|
90 | /** |
---|
91 | * Get a descriptive string that identifies |
---|
92 | * the remote endpoint for the given link. |
---|
93 | * |
---|
94 | * @param link The link to query endpoint information for. |
---|
95 | * @return A descriptive endpoint information. |
---|
96 | */ |
---|
97 | string getEndpointDescription( |
---|
98 | const LinkID& link |
---|
99 | ) const; |
---|
100 | |
---|
101 | /** |
---|
102 | * Get a descriprive string that identifiers the remote node. |
---|
103 | * |
---|
104 | * @param node The node id to query endpoint information. |
---|
105 | * @return A descriptive endpoint information. |
---|
106 | */ |
---|
107 | string getEndpointDescription( |
---|
108 | const NodeID& node = NodeID::UNSPECIFIED |
---|
109 | ) const; |
---|
110 | |
---|
111 | /** |
---|
112 | * Get the remote endpoint node id for the given string, |
---|
113 | * or the local nodeid for an unspecified link. |
---|
114 | * |
---|
115 | * @param link The link to get the remote node. |
---|
116 | * @return The nodeid of the remote end of the link |
---|
117 | * or the local nodeid for an unspecified link. |
---|
118 | */ |
---|
119 | const NodeID& getNodeID( |
---|
120 | const LinkID& link = LinkID::UNSPECIFIED |
---|
121 | ) const; |
---|
122 | |
---|
123 | /** |
---|
124 | * Get all links that end at the specified node id. |
---|
125 | * Or all links from the local node when the node id |
---|
126 | * is set to unspecified. |
---|
127 | * |
---|
128 | * @param node The remote node to query all links or unspecified |
---|
129 | * for all local starting links |
---|
130 | * @return A vector of link ids. |
---|
131 | */ |
---|
132 | vector<LinkID> getLinkIDs( |
---|
133 | const NodeID& node = NodeID::UNSPECIFIED |
---|
134 | ) const; |
---|
135 | |
---|
136 | /** |
---|
137 | * Is this node acting as a relay for us |
---|
138 | * |
---|
139 | * @param node The node in question |
---|
140 | * @return true, if this node is relaying for us |
---|
141 | */ |
---|
142 | bool isRelayingNode(const NodeID& node); |
---|
143 | |
---|
144 | /** |
---|
145 | * Is this node only reachable for us through a relay? |
---|
146 | * |
---|
147 | * @param node The node in question |
---|
148 | * @return true, if we reach this node only over a relay |
---|
149 | */ |
---|
150 | bool isRelayedNode(const NodeID& node); |
---|
151 | |
---|
152 | |
---|
153 | /** |
---|
154 | * Protocols for some layer, can be combined |
---|
155 | */ |
---|
156 | enum Protocol { |
---|
157 | undefined = 0x0, |
---|
158 | rfcomm = 0x1, |
---|
159 | ipv4 = 0x2, |
---|
160 | ipv6 = 0x4, |
---|
161 | udp = 0x8, |
---|
162 | tcp = 0x16, |
---|
163 | }; |
---|
164 | |
---|
165 | /** |
---|
166 | * Through which protocol is a node reachable. |
---|
167 | * |
---|
168 | * @param node The node for which to return protocol reachability |
---|
169 | * @return Combination of protocols |
---|
170 | */ |
---|
171 | Protocol getReachabilityProtocol(const NodeID& node); |
---|
172 | |
---|
173 | protected: |
---|
174 | |
---|
175 | /** |
---|
176 | * Notification function when a link has gone up. |
---|
177 | * |
---|
178 | * @param lnk The corresponding link id. |
---|
179 | * @param local The local node id. |
---|
180 | * @param remote The remote node id. |
---|
181 | * @param spovnet The SpoVNet ID. |
---|
182 | */ |
---|
183 | virtual void onLinkUp( |
---|
184 | const LinkID& lnk, |
---|
185 | const NodeID& local, |
---|
186 | const NodeID& remote, |
---|
187 | const SpoVNetID& spovnet |
---|
188 | ); |
---|
189 | |
---|
190 | /** |
---|
191 | * Notification function when a link has gone down. |
---|
192 | * |
---|
193 | * @param lnk The corresponding link id. |
---|
194 | * @param local The local node id. |
---|
195 | * @param remote The remote node id. |
---|
196 | * @param spovnet The SpoVNet ID. |
---|
197 | */ |
---|
198 | virtual void onLinkDown( |
---|
199 | const LinkID& lnk, |
---|
200 | const NodeID& local, |
---|
201 | const NodeID& remote, |
---|
202 | const SpoVNetID& spovnet |
---|
203 | ); |
---|
204 | |
---|
205 | /** |
---|
206 | * Notification function when a link has changed |
---|
207 | * |
---|
208 | * @param lnk The corresponding link id. |
---|
209 | * @param local The local node id. |
---|
210 | * @param remote The remote node id. |
---|
211 | * @param spovnet The SpoVNet ID. |
---|
212 | */ |
---|
213 | virtual void onLinkChanged( |
---|
214 | const LinkID& lnk, |
---|
215 | const NodeID& local, |
---|
216 | const NodeID& remote, |
---|
217 | const SpoVNetID& spovnet |
---|
218 | ); |
---|
219 | |
---|
220 | /** |
---|
221 | * Notification function when a link has failed |
---|
222 | * |
---|
223 | * @param lnk The corresponding link id. |
---|
224 | * @param local The local node id. |
---|
225 | * @param remote The remote node id. |
---|
226 | * @param spovnet The SpoVNet ID. |
---|
227 | */ |
---|
228 | virtual void onLinkFail( |
---|
229 | const LinkID& lnk, |
---|
230 | const NodeID& local, |
---|
231 | const NodeID& remote, |
---|
232 | const SpoVNetID& spovnet |
---|
233 | ); |
---|
234 | |
---|
235 | private: |
---|
236 | |
---|
237 | /** |
---|
238 | * Configure the sideport with the correct base overlay. |
---|
239 | * |
---|
240 | * @param _overlay The BaseOverlay where to attach the sideport. |
---|
241 | */ |
---|
242 | void configure( |
---|
243 | overlay::BaseOverlay* _overlay |
---|
244 | ); |
---|
245 | |
---|
246 | /** |
---|
247 | * The configured BaseOverlay where |
---|
248 | * the sideport is attached to. |
---|
249 | */ |
---|
250 | overlay::BaseOverlay* overlay; |
---|
251 | |
---|
252 | }; |
---|
253 | |
---|
254 | } // namespace ariba |
---|
255 | |
---|
256 | #endif // SIDEPORTLISTENER_H_ |
---|