| 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 <iostream>
 | 
|---|
| 45 | #include <boost/foreach.hpp>
 | 
|---|
| 46 | #include "Identifiers.h"
 | 
|---|
| 47 | #include "CommunicationListener.h"
 | 
|---|
| 48 | 
 | 
|---|
| 49 | using std::cout;
 | 
|---|
| 50 | using std::map;
 | 
|---|
| 51 | using std::vector;
 | 
|---|
| 52 | 
 | 
|---|
| 53 | namespace ariba {
 | 
|---|
| 54 | 
 | 
|---|
| 55 | // forward declarations
 | 
|---|
| 56 | class Node;
 | 
|---|
| 57 | class AribaModule;
 | 
|---|
| 58 | namespace overlay {
 | 
|---|
| 59 |         class BaseOverlay;
 | 
|---|
| 60 | }
 | 
|---|
| 61 | 
 | 
|---|
| 62 | /**
 | 
|---|
| 63 |  * \addtogroup public
 | 
|---|
| 64 |  * @{
 | 
|---|
| 65 |  *
 | 
|---|
| 66 |  * A sideport class to gather advanced information about nodes, links,
 | 
|---|
| 67 |  * their endpoints and get information about all link activity on a node.
 | 
|---|
| 68 |  *
 | 
|---|
| 69 |  * @author Christoph Mayer <mayer@tm.uka.de>
 | 
|---|
| 70 |  */
 | 
|---|
| 71 | class SideportListener {
 | 
|---|
| 72 | 
 | 
|---|
| 73 |         friend class Node;
 | 
|---|
| 74 |         friend class AribaModule;
 | 
|---|
| 75 |         friend class overlay::BaseOverlay;
 | 
|---|
| 76 | 
 | 
|---|
| 77 | public:
 | 
|---|
| 78 | 
 | 
|---|
| 79 |         /**
 | 
|---|
| 80 |          * A default object of the SideportListener that has empty
 | 
|---|
| 81 |          * event functions and will return invalid information.
 | 
|---|
| 82 |          */
 | 
|---|
| 83 |         static SideportListener DEFAULT;
 | 
|---|
| 84 | 
 | 
|---|
| 85 |         /**
 | 
|---|
| 86 |          * Constructor of the SideportListener.
 | 
|---|
| 87 |          */
 | 
|---|
| 88 |         SideportListener();
 | 
|---|
| 89 | 
 | 
|---|
| 90 |         /**
 | 
|---|
| 91 |          * Virtual Desctructor for the SideportListener.
 | 
|---|
| 92 |          */
 | 
|---|
| 93 |         virtual ~SideportListener();
 | 
|---|
| 94 | 
 | 
|---|
| 95 |         /**
 | 
|---|
| 96 |          * Get a descriptive string that identifies
 | 
|---|
| 97 |          * the remote endpoint for the given link.
 | 
|---|
| 98 |          *
 | 
|---|
| 99 |          *  @param link The link to query endpoint information for.
 | 
|---|
| 100 |          *  @return A descriptive endpoint information.
 | 
|---|
| 101 |          */
 | 
|---|
| 102 |         string getEndpointDescription(
 | 
|---|
| 103 |                         const LinkID& link
 | 
|---|
| 104 |                         ) const;
 | 
|---|
| 105 | 
 | 
|---|
| 106 |         /**
 | 
|---|
| 107 |          * Get a descriprive string that identifiers the remote node.
 | 
|---|
| 108 |          *
 | 
|---|
| 109 |          * @param node The node id to query endpoint information.
 | 
|---|
| 110 |          * @return A descriptive endpoint information.
 | 
|---|
| 111 |          */
 | 
|---|
| 112 |         string getEndpointDescription(
 | 
|---|
| 113 |                         const NodeID& node = NodeID::UNSPECIFIED
 | 
|---|
| 114 |                         ) const;
 | 
|---|
| 115 | 
 | 
|---|
| 116 |         /**
 | 
|---|
| 117 |          * Get the remote endpoint node id for the given string,
 | 
|---|
| 118 |          * or the local nodeid for an unspecified link.
 | 
|---|
| 119 |          *
 | 
|---|
| 120 |          * @param link The link to get the remote node.
 | 
|---|
| 121 |          * @return The nodeid of the remote end of the link
 | 
|---|
| 122 |          *                      or the local nodeid for an unspecified link.
 | 
|---|
| 123 |          */
 | 
|---|
| 124 |         const NodeID& getNodeID(
 | 
|---|
| 125 |                         const LinkID& link = LinkID::UNSPECIFIED
 | 
|---|
| 126 |                         ) const;
 | 
|---|
| 127 | 
 | 
|---|
| 128 |         /**
 | 
|---|
| 129 |          * Get all links that end at the specified node id.
 | 
|---|
| 130 |          * Or all links from the local node when the node id
 | 
|---|
| 131 |          * is set to unspecified.
 | 
|---|
| 132 |          *
 | 
|---|
| 133 |          * @param node The remote node to query all links or unspecified
 | 
|---|
| 134 |          *                      for all local starting links
 | 
|---|
| 135 |          * @return A vector of link ids.
 | 
|---|
| 136 |          */
 | 
|---|
| 137 |         vector<LinkID> getLinkIDs(
 | 
|---|
| 138 |                         const NodeID& node = NodeID::UNSPECIFIED
 | 
|---|
| 139 |                         ) const;
 | 
|---|
| 140 | 
 | 
|---|
| 141 |         /**
 | 
|---|
| 142 |          * Get html presentation of the links.
 | 
|---|
| 143 |          * @return html of links
 | 
|---|
| 144 |          */
 | 
|---|
| 145 |         string getHtmlLinks();
 | 
|---|
| 146 | 
 | 
|---|
| 147 |         /**
 | 
|---|
| 148 |          * Get the neighbots in the overlay structure
 | 
|---|
| 149 |          * @return A vector of NodeIDs of the neighbors
 | 
|---|
| 150 |          */
 | 
|---|
| 151 |         vector<NodeID> getOverlayNeighbors(bool deep = true);
 | 
|---|
| 152 | 
 | 
|---|
| 153 |         /**
 | 
|---|
| 154 |          * Is this node acting as a relay for us
 | 
|---|
| 155 |          *
 | 
|---|
| 156 |          * @param node The node in question
 | 
|---|
| 157 |          * @return true, if this node is relaying for us
 | 
|---|
| 158 |          */
 | 
|---|
| 159 |         bool isRelayingNode(const NodeID& node);
 | 
|---|
| 160 | 
 | 
|---|
| 161 |         /**
 | 
|---|
| 162 |          * Is this node only reachable for us through a relay?
 | 
|---|
| 163 |          *
 | 
|---|
| 164 |          * @param node The node in question
 | 
|---|
| 165 |          * @return true, if we reach this node only over a relay
 | 
|---|
| 166 |          */
 | 
|---|
| 167 |         bool isRelayedNode(const NodeID& node);
 | 
|---|
| 168 | 
 | 
|---|
| 169 |         /**
 | 
|---|
| 170 |          * Protocols for some layer, can be combined
 | 
|---|
| 171 |          */
 | 
|---|
| 172 |         enum Protocol {
 | 
|---|
| 173 |                 undefined = 0x0,
 | 
|---|
| 174 |                 rfcomm = 0x1,
 | 
|---|
| 175 |                 ipv4 = 0x2,
 | 
|---|
| 176 |                 ipv6 = 0x3
 | 
|---|
| 177 |         };
 | 
|---|
| 178 | 
 | 
|---|
| 179 |         /**
 | 
|---|
| 180 |          * Through which protocol is a node reachable.
 | 
|---|
| 181 |          *
 | 
|---|
| 182 |          * @param node The node for which to return protocol reachability
 | 
|---|
| 183 |          * @return Combination of protocols
 | 
|---|
| 184 |          */
 | 
|---|
| 185 |         Protocol getReachabilityProtocol(const NodeID& node);
 | 
|---|
| 186 | 
 | 
|---|
| 187 | protected:
 | 
|---|
| 188 | 
 | 
|---|
| 189 |         /**
 | 
|---|
| 190 |          * Notification function when a link has gone up.
 | 
|---|
| 191 |          *
 | 
|---|
| 192 |          * @param lnk The corresponding link id.
 | 
|---|
| 193 |          * @param local The local node id.
 | 
|---|
| 194 |          * @param remote The remote node id.
 | 
|---|
| 195 |          * @param spovnet The SpoVNet ID.
 | 
|---|
| 196 |          */
 | 
|---|
| 197 |         virtual void onLinkUp(
 | 
|---|
| 198 |                         const LinkID& lnk,
 | 
|---|
| 199 |                         const NodeID& local,
 | 
|---|
| 200 |                         const NodeID& remote,
 | 
|---|
| 201 |                         const SpoVNetID& spovnet
 | 
|---|
| 202 |                         );
 | 
|---|
| 203 | 
 | 
|---|
| 204 |         /**
 | 
|---|
| 205 |          * Notification function when a link has gone down.
 | 
|---|
| 206 |          *
 | 
|---|
| 207 |          * @param lnk The corresponding link id.
 | 
|---|
| 208 |          * @param local The local node id.
 | 
|---|
| 209 |          * @param remote The remote node id.
 | 
|---|
| 210 |          * @param spovnet The SpoVNet ID.
 | 
|---|
| 211 |          */
 | 
|---|
| 212 |         virtual void onLinkDown(
 | 
|---|
| 213 |                         const LinkID& lnk,
 | 
|---|
| 214 |                         const NodeID& local,
 | 
|---|
| 215 |                         const NodeID& remote,
 | 
|---|
| 216 |                         const SpoVNetID& spovnet
 | 
|---|
| 217 |                         );
 | 
|---|
| 218 | 
 | 
|---|
| 219 |         /**
 | 
|---|
| 220 |          * Notification function when a link has changed
 | 
|---|
| 221 |          *
 | 
|---|
| 222 |          * @param lnk The corresponding link id.
 | 
|---|
| 223 |          * @param local The local node id.
 | 
|---|
| 224 |          * @param remote The remote node id.
 | 
|---|
| 225 |          * @param spovnet The SpoVNet ID.
 | 
|---|
| 226 |          */
 | 
|---|
| 227 |         virtual void onLinkChanged(
 | 
|---|
| 228 |                         const LinkID& lnk,
 | 
|---|
| 229 |                         const NodeID& local,
 | 
|---|
| 230 |                         const NodeID& remote,
 | 
|---|
| 231 |                         const SpoVNetID& spovnet
 | 
|---|
| 232 |                         );
 | 
|---|
| 233 | 
 | 
|---|
| 234 |         /**
 | 
|---|
| 235 |          * Notification function when a link has failed
 | 
|---|
| 236 |          *
 | 
|---|
| 237 |          * @param lnk The corresponding link id.
 | 
|---|
| 238 |          * @param local The local node id.
 | 
|---|
| 239 |          * @param remote The remote node id.
 | 
|---|
| 240 |          * @param spovnet The SpoVNet ID.
 | 
|---|
| 241 |          */
 | 
|---|
| 242 |         virtual void onLinkFail(
 | 
|---|
| 243 |                         const LinkID& lnk,
 | 
|---|
| 244 |                         const NodeID& local,
 | 
|---|
| 245 |                         const NodeID& remote,
 | 
|---|
| 246 |                         const SpoVNetID& spovnet
 | 
|---|
| 247 |                         );
 | 
|---|
| 248 | 
 | 
|---|
| 249 | private:
 | 
|---|
| 250 | 
 | 
|---|
| 251 |         /**
 | 
|---|
| 252 |          * Configure the sideport with the correct base overlay.
 | 
|---|
| 253 |          *
 | 
|---|
| 254 |          * @param _overlay The BaseOverlay where to attach the sideport.
 | 
|---|
| 255 |          */
 | 
|---|
| 256 |         void configure(
 | 
|---|
| 257 |                         overlay::BaseOverlay* _overlay
 | 
|---|
| 258 |                         );
 | 
|---|
| 259 | 
 | 
|---|
| 260 |         /**
 | 
|---|
| 261 |          * The configured BaseOverlay where
 | 
|---|
| 262 |          * the sideport is attached to.
 | 
|---|
| 263 |          */
 | 
|---|
| 264 |         overlay::BaseOverlay* overlay;
 | 
|---|
| 265 | 
 | 
|---|
| 266 | };
 | 
|---|
| 267 | 
 | 
|---|
| 268 | } // namespace ariba
 | 
|---|
| 269 | 
 | 
|---|
| 270 | /** @} */
 | 
|---|
| 271 | 
 | 
|---|
| 272 | #endif // SIDEPORTLISTENER_H_
 | 
|---|