PageRenderTime 63ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 0ms

/xorp/rib/register_server.hh

https://github.com/schintan/xorp
C++ Header | 363 lines | 102 code | 40 blank | 221 comment | 0 complexity | 7ee937ff27b0f6c1eeb9c31ec3f3c571 MD5 | raw file
  1. // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
  2. // Copyright (c) 2001-2011 XORP, Inc and Others
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License, Version 2, June
  6. // 1991 as published by the Free Software Foundation. Redistribution
  7. // and/or modification of this program under the terms of any other
  8. // version of the GNU General Public License is not permitted.
  9. //
  10. // This program is distributed in the hope that it will be useful, but
  11. // WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
  13. // see the GNU General Public License, Version 2, a copy of which can be
  14. // found in the XORP LICENSE.gpl file.
  15. //
  16. // XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
  17. // http://xorp.net
  18. // $XORP: xorp/rib/register_server.hh,v 1.17 2008/10/02 21:58:11 bms Exp $
  19. #ifndef __RIB_REGISTER_SERVER_HH__
  20. #define __RIB_REGISTER_SERVER_HH__
  21. #include "libxorp/xorp.h"
  22. #include "libxorp/ipv4.hh"
  23. #include "libxorp/ipv6.hh"
  24. #include "libxorp/ipnet.hh"
  25. #include "xrl/interfaces/rib_client_xif.hh"
  26. class XrlRouter;
  27. class NotifyQueueEntry;
  28. typedef XrlRibClientV0p1Client ResponseSender;
  29. /**
  30. * @short Queue of route event notifications
  31. *
  32. * A NotfiyQueue holds a queue of route event notifications waiting
  33. * transmission to the XORP process that registered interest in route
  34. * changes that affected one or more routes. When a lot of routes
  35. * change, we need to queue the changes because we may generate them
  36. * faster than the recipient can handle being told about them.
  37. */
  38. class NotifyQueue {
  39. public:
  40. /**
  41. * NotifyQueue constructor
  42. *
  43. * @param module_name the XRL module target name for the process that
  44. * this queue holds notifications for.
  45. */
  46. NotifyQueue(const string& module_name);
  47. /**
  48. * Add an notification entry to the queue.
  49. *
  50. * @param e the notification entry to be queued.
  51. */
  52. void add_entry(NotifyQueueEntry* e);
  53. /**
  54. * Send the next entry in the queue to this queue's XRL target.
  55. */
  56. void send_next();
  57. /**
  58. * Flush is an indication to the queue that the changes since the
  59. * last flush can be checked for consolidation. Several add_entry
  60. * events might occur in rapid succession affecting the same
  61. * route. A flush indicates that it is OK to start sending this
  62. * batch of changes (and to consolidate those changes to avoid
  63. * thrashing, but we don't currently do this).
  64. */
  65. void flush(ResponseSender* response_sender);
  66. /**
  67. * XRL transmit complete callback. We use this to cause the next
  68. * item in the queue to be sent.
  69. *
  70. * @param e the XRL completion status code.
  71. */
  72. void xrl_done(const XrlError& e);
  73. typedef XorpCallback1<void, const XrlError&>::RefPtr XrlCompleteCB;
  74. private:
  75. string _module_name;
  76. list<NotifyQueueEntry* > _queue;
  77. bool _active;
  78. ResponseSender* _response_sender;
  79. };
  80. /**
  81. * Base class for a queue entry to be held in a @ref NotifyQueue.
  82. */
  83. class NotifyQueueEntry {
  84. public:
  85. /**
  86. * The type of notifcation: either the data (nexthop, metric,
  87. * admin_distance) associated with the registered route changed,
  88. * or the data has changed enough that the registration has been
  89. * invalidated and the client needs to register again to find out
  90. * what happened.
  91. */
  92. typedef enum { CHANGED, INVALIDATE } EntryType;
  93. /**
  94. * NotifyQueueEntry constructor
  95. */
  96. NotifyQueueEntry() {}
  97. /**
  98. * NotifyQueueEntry destructor
  99. */
  100. virtual ~NotifyQueueEntry() {};
  101. /**
  102. * Send the queue entry (pure virtual)
  103. */
  104. virtual void send(ResponseSender* response_sender,
  105. const string& module_name,
  106. NotifyQueue::XrlCompleteCB& cb) = 0;
  107. /**
  108. * @return The type of queue entry
  109. * @see NotifyQueueEntry::EntryType
  110. */
  111. virtual EntryType type() const = 0;
  112. private:
  113. };
  114. /**
  115. * Notification Queue entry indicating that a change occured to the
  116. * metric, admin_distance or nexthop of a route in which interest was
  117. * registered.
  118. *
  119. * The template class A is the address family: either the IPv4 class
  120. * or the IPv6 class.
  121. */
  122. template <class A>
  123. class NotifyQueueChangedEntry : public NotifyQueueEntry {
  124. public:
  125. /**
  126. * NotifyQueueChangedEntry Constructor
  127. *
  128. * @param net the destination subnet of the route that changed.
  129. * @param nexthop the new nexthop of the route that changed.
  130. * @param metric the new routing protocol metric of the route that changed.
  131. * @param admin_distance the adminstratively defined distance of the
  132. * routing protocol this routing entry was computed by.
  133. * @param protocol_origin the name of the protocol that originated this
  134. * route.
  135. * @param multicast true indicates that the change occured in the
  136. * multicast RIB, false indicates that it occured in the unicast
  137. * RIB.
  138. */
  139. NotifyQueueChangedEntry(const IPNet<A>& net, const A& nexthop,
  140. uint32_t metric, uint32_t admin_distance,
  141. const string& protocol_origin, bool multicast)
  142. : _net(net), _nexthop(nexthop), _metric(metric),
  143. _admin_distance(admin_distance), _protocol_origin(protocol_origin),
  144. _multicast(multicast) {}
  145. /**
  146. * @return CHANGED
  147. * @see NotifyQueueEntry::EntryType
  148. */
  149. EntryType type() const { return CHANGED; }
  150. /**
  151. * Actually send the XRL that communicates this change to the
  152. * registered process.
  153. *
  154. * @param response_sender the auto-generated stub class instance
  155. * that will do the parameter marchalling.
  156. * @param module_name the XRL module target name to send this
  157. * information to.
  158. * @param cb the method to call back when this XRL completes.
  159. */
  160. void send(ResponseSender* response_sender,
  161. const string& module_name,
  162. NotifyQueue::XrlCompleteCB& cb);
  163. private:
  164. IPNet<A> _net; // The route's full subnet (not the valid_subnet)
  165. A _nexthop; // The new nexthop of the route
  166. uint32_t _metric; // The metric of the route
  167. uint32_t _admin_distance; // The administratively defined distance of
  168. // the routing protocol this routing entry
  169. // was computed by
  170. string _protocol_origin; // The name of the protocol that originated
  171. // this route
  172. bool _multicast; // If true, a change occured in multicast RIB,
  173. // otherwise it occured in the unicast RIB
  174. };
  175. /**
  176. * Notification Queue entry indicating that a change occured which has
  177. * caused a route registration to become invalid. The client must
  178. * re-register to find out what actually happened.
  179. *
  180. * The template class A is the address family: either the IPv4 class
  181. * or the IPv6 class.
  182. */
  183. template <class A>
  184. class NotifyQueueInvalidateEntry : public NotifyQueueEntry {
  185. public:
  186. /**
  187. * NotifyQueueInvalidateEntry Constructor
  188. *
  189. * @param net the valid_subnet of the route registration that is
  190. * now invalid.
  191. * @param multicast true indicates that the change occured in the
  192. * multicast RIB, false indicates that it occured in the unicast
  193. * RIB.
  194. */
  195. NotifyQueueInvalidateEntry(const IPNet<A>& net, bool multicast)
  196. : _net(net), _multicast(multicast) {}
  197. /**
  198. * @return INVALIDATE
  199. * @see NotifyQueueEntry::EntryType
  200. */
  201. EntryType type() const { return INVALIDATE; }
  202. /**
  203. * Actually send the XRL that communicates this change to the
  204. * registered process.
  205. *
  206. * @param response_sender the auto-generated stub class instance
  207. * that will do the parameter marchalling.
  208. * @param module_name the XRL module target name to send this
  209. * information to.
  210. * @param cb the method to call back when this XRL completes.
  211. */
  212. void send(ResponseSender* response_sender,
  213. const string& module_name,
  214. NotifyQueue::XrlCompleteCB& cb);
  215. private:
  216. IPNet<A> _net; // The valid_subnet from the RouteRegister
  217. // instance. The other end already knows the
  218. // route's full subnet.
  219. bool _multicast; // If true, a change occured in multicast RIB,
  220. // otherwise it occured in the unicast RIB
  221. };
  222. /**
  223. * @short RegisterServer handles communication of notifications to the
  224. * clients that registered interest in changes affecting specific
  225. * routes.
  226. *
  227. * RegisterServer handles communication of notifications to the
  228. * clients that registered interest in changes affecting specific
  229. * routes. As these notifications can sometimes be generated faster
  230. * than the recipient can handle them, the notifications can be queued
  231. * here.
  232. */
  233. class RegisterServer {
  234. public:
  235. /**
  236. * RegisterServer constructor
  237. *
  238. * @param xrl_router the XRL router instance used to send and
  239. * receive XRLs in this process.
  240. */
  241. RegisterServer(XrlRouter* xrl_router);
  242. /**
  243. * RegisterServer destructor
  244. */
  245. virtual ~RegisterServer() {}
  246. /**
  247. * send_route_changed is called to communicate to another XRL
  248. * module that routing information in which it had registered an
  249. * interest has changed its nexthop, metric, or admin distance.
  250. *
  251. * @param module_name the XRL target name of the module to notify.
  252. * @param net the destination subnet of the route that changed.
  253. * @param nexthop the new nexthop of the route that changed.
  254. * @param metric the new routing protocol metric of the route that changed.
  255. * @param admin_distance the new admin distance of the route that changed.
  256. * @param protocol_origin the name of the protocol that originated this
  257. * route.
  258. * @param multicast true indicates that the change occured in the
  259. * multicast RIB, false indicates that it occured in the unicast
  260. * RIB.
  261. */
  262. virtual void send_route_changed(const string& module_name,
  263. const IPv4Net& net,
  264. const IPv4& nexthop,
  265. uint32_t metric,
  266. uint32_t admin_distance,
  267. const string& protocol_origin,
  268. bool multicast);
  269. virtual void send_invalidate(const string& module_name,
  270. const IPv4Net& net,
  271. bool multicast);
  272. #ifdef HAVE_IPV6
  273. /**
  274. * send_route_changed is called to communicate to another XRL
  275. * module that routing information in which it had registered an
  276. * interest has changed its nexthop, metric, or admin distance.
  277. *
  278. * @param module_name the XRL target name of the module to notify.
  279. * @param net the destination subnet of the route that changed.
  280. * @param nexthop the new nexthop of the route that changed.
  281. * @param metric the new routing protocol metric of the route that changed.
  282. * @param admin_distance the new admin distance of the route that changed.
  283. * @param protocol_origin the name of the protocol that originated this
  284. * route.
  285. * @param multicast true indicates that the change occured in the
  286. * multicast RIB, false indicates that it occured in the unicast
  287. * RIB.
  288. */
  289. virtual void send_route_changed(const string& module_name,
  290. const IPv6Net& net,
  291. const IPv6& nexthop,
  292. uint32_t metric,
  293. uint32_t admin_distance,
  294. const string& protocol_origin,
  295. bool multicast);
  296. /**
  297. * send_invalidate is called to communicate to another XRL module
  298. * that routing information in which it had registered an interest
  299. * has changed in some unspecified way that has caused the
  300. * registration to become invalid. The client must re-register to
  301. * find out what really happened.
  302. *
  303. * @param module_name the XRL target name of the module to notify.
  304. * @param net the valid_subnet of the route registration that is
  305. * now invalid.
  306. * @param multicast true indicates that the change occured in the
  307. * multicast RIB, false indicates that it occured in the unicast
  308. * RIB.
  309. */
  310. virtual void send_invalidate(const string& module_name,
  311. const IPv6Net& net,
  312. bool multicast);
  313. #endif
  314. /**
  315. * @see NotifyQueue::flush
  316. */
  317. virtual void flush();
  318. protected:
  319. void add_entry_to_queue(const string& module_name, NotifyQueueEntry* e);
  320. map<string, NotifyQueue* > _queuemap;
  321. ResponseSender _response_sender;
  322. };
  323. #endif // __RIB_REGISTER_SERVER_HH__