xorp

register_server.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 
00003 // Copyright (c) 2001-2011 XORP, Inc and Others
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License, Version 2, June
00007 // 1991 as published by the Free Software Foundation. Redistribution
00008 // and/or modification of this program under the terms of any other
00009 // version of the GNU General Public License is not permitted.
00010 // 
00011 // This program is distributed in the hope that it will be useful, but
00012 // WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
00014 // see the GNU General Public License, Version 2, a copy of which can be
00015 // found in the XORP LICENSE.gpl file.
00016 // 
00017 // XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
00018 // http://xorp.net
00019 
00020 // $XORP: xorp/rib/register_server.hh,v 1.17 2008/10/02 21:58:11 bms Exp $
00021 
00022 #ifndef __RIB_REGISTER_SERVER_HH__
00023 #define __RIB_REGISTER_SERVER_HH__
00024 
00025 
00026 
00027 
00028 #include "libxorp/xorp.h"
00029 #include "libxorp/ipv4.hh"
00030 #include "libxorp/ipv6.hh"
00031 #include "libxorp/ipnet.hh"
00032 
00033 #include "xrl/interfaces/rib_client_xif.hh"
00034 
00035 
00036 class XrlRouter;
00037 class NotifyQueueEntry;
00038 
00039 typedef XrlRibClientV0p1Client ResponseSender;
00040 
00050 class NotifyQueue {
00051 public:
00058     NotifyQueue(const string& module_name);
00059 
00065     void add_entry(NotifyQueueEntry* e);
00066 
00070     void send_next();
00071 
00080     void flush(ResponseSender* response_sender);
00081 
00088     void xrl_done(const XrlError& e);
00089 
00090     typedef XorpCallback1<void, const XrlError&>::RefPtr XrlCompleteCB;
00091 
00092 private:
00093     string      _module_name;
00094     list<NotifyQueueEntry* > _queue;
00095     bool        _active;
00096     ResponseSender* _response_sender;
00097 };
00098 
00102 class NotifyQueueEntry {
00103 public:
00111     typedef enum { CHANGED, INVALIDATE } EntryType;
00112 
00116     NotifyQueueEntry() {}
00117 
00121     virtual ~NotifyQueueEntry() {};
00122 
00126     virtual void send(ResponseSender* response_sender,
00127               const string& module_name,
00128               NotifyQueue::XrlCompleteCB& cb) = 0;
00129 
00134     virtual EntryType type() const = 0;
00135 
00136 private:
00137 };
00138 
00147 template <class A>
00148 class NotifyQueueChangedEntry : public NotifyQueueEntry {
00149  public:
00164     NotifyQueueChangedEntry(const IPNet<A>& net, const A& nexthop,
00165                 uint32_t metric, uint32_t admin_distance,
00166                 const string& protocol_origin, bool multicast)
00167     : _net(net), _nexthop(nexthop), _metric(metric),
00168       _admin_distance(admin_distance), _protocol_origin(protocol_origin),
00169       _multicast(multicast) {}
00170 
00175     EntryType type() const { return CHANGED; }
00176 
00187     void send(ResponseSender* response_sender,
00188           const string& module_name,
00189           NotifyQueue::XrlCompleteCB& cb);
00190 
00191  private:
00192     IPNet<A>    _net;   // The route's full subnet (not the valid_subnet)
00193     A       _nexthop;   // The new nexthop of the route
00194     uint32_t    _metric;    // The metric of the route
00195     uint32_t    _admin_distance; // The administratively defined distance of
00196                 // the routing protocol this routing entry
00197                 // was computed by
00198     string  _protocol_origin; // The name of the protocol that originated
00199                   // this route
00200     bool    _multicast; // If true, a change occured in multicast RIB,
00201                 // otherwise it occured in the unicast RIB
00202 };
00203 
00212 template <class A>
00213 class NotifyQueueInvalidateEntry : public NotifyQueueEntry {
00214 public:
00224     NotifyQueueInvalidateEntry(const IPNet<A>& net, bool multicast)
00225     : _net(net), _multicast(multicast) {}
00226 
00231     EntryType type() const { return INVALIDATE; }
00232 
00243     void send(ResponseSender* response_sender,
00244           const string& module_name,
00245           NotifyQueue::XrlCompleteCB& cb);
00246 
00247 private:
00248     IPNet<A>    _net;   // The valid_subnet from the RouteRegister
00249             // instance.  The other end already knows the
00250             // route's full subnet.
00251     bool    _multicast; // If true, a change occured in multicast RIB,
00252                 // otherwise it occured in the unicast RIB
00253 };
00254 
00266 class RegisterServer {
00267 public:
00274     RegisterServer(XrlRouter* xrl_router);
00275 
00279     virtual ~RegisterServer() {}
00280 
00297     virtual void send_route_changed(const string& module_name,
00298                     const IPv4Net& net,
00299                     const IPv4& nexthop,
00300                     uint32_t metric,
00301                     uint32_t admin_distance,
00302                     const string& protocol_origin,
00303                     bool multicast);
00304     virtual void send_invalidate(const string& module_name,
00305                  const IPv4Net& net,
00306                  bool multicast);
00307 
00308 #ifdef HAVE_IPV6
00309 
00325     virtual void send_route_changed(const string& module_name,
00326                     const IPv6Net& net,
00327                     const IPv6& nexthop,
00328                     uint32_t metric,
00329                     uint32_t admin_distance,
00330                     const string& protocol_origin,
00331                     bool multicast);
00332 
00347     virtual void send_invalidate(const string& module_name,
00348                  const IPv6Net& net,
00349                  bool multicast);
00350 #endif
00351 
00355     virtual void flush();
00356 
00357 protected:
00358     void add_entry_to_queue(const string& module_name, NotifyQueueEntry* e);
00359     map<string, NotifyQueue* > _queuemap;
00360     ResponseSender _response_sender;
00361 };
00362 
00363 #endif // __RIB_REGISTER_SERVER_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations