xorp

xrl_fib_client_manager.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 
00003 // Copyright (c) 2001-2012 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 
00021 #ifndef __FEA_XRL_FIB_CLIENT_MANAGER_HH__
00022 #define __FEA_XRL_FIB_CLIENT_MANAGER_HH__
00023 
00024 #include "libxipc/xrl_router.hh"
00025 
00026 #include "xrl/interfaces/fea_fib_client_xif.hh"
00027 
00028 #include "fibconfig_transaction.hh"
00029 #include "fte.hh"
00030 
00031 
00035 class XrlFibClientManager : public FibTableObserverBase {
00036 public:
00042     XrlFibClientManager(FibConfig&  fibconfig,
00043             XrlRouter&  xrl_router)
00044     : _fibconfig(fibconfig),
00045       _xrl_fea_fib_client(&xrl_router) {
00046     _fibconfig.add_fib_table_observer(this);
00047     }
00048 
00049     virtual ~XrlFibClientManager() {
00050     _fibconfig.delete_fib_table_observer(this);
00051     }
00052 
00058     EventLoop& eventloop() { return _fibconfig.eventloop(); }
00059 
00067     void process_fib_changes(const list<Fte4>& fte_list);
00068 
00077     XrlCmdError add_fib_client4(const string& client_target_name,
00078                 const bool send_updates,
00079                 const bool send_resolves);
00080 
00087     XrlCmdError delete_fib_client4(const string& client_target_name);
00088 
00097     int send_fib_client_add_route(const string& target_name,
00098                   const Fte4& fte);
00099 
00108     int send_fib_client_delete_route(const string& target_name,
00109                      const Fte4& fte);
00110 
00119     int send_fib_client_resolve_route(const string& target_name,
00120                      const Fte4& fte);
00121 
00122 
00123 #ifdef HAVE_IPV6
00124 
00132     void process_fib_changes(const list<Fte6>& fte_list);
00133 
00142     XrlCmdError add_fib_client6(const string& client_target_name,
00143                 const bool send_updates,
00144                 const bool send_resolves);
00145 
00152     XrlCmdError delete_fib_client6(const string& client_target_name);
00153 
00162     int send_fib_client_add_route(const string& target_name,
00163                   const Fte6& fte);
00164 
00165 
00174     int send_fib_client_delete_route(const string& target_name,
00175                      const Fte6& fte);
00176 
00185     int send_fib_client_resolve_route(const string& target_name,
00186                      const Fte6& fte);
00187 
00188 #endif
00189 
00190 protected:
00191     FibConfig&      _fibconfig;
00192 
00193 private:
00194 
00195     void send_fib_client_add_route4_cb(const XrlError& xrl_error,
00196                        string target_name);
00197     void send_fib_client_delete_route4_cb(const XrlError& xrl_error,
00198                       string target_name);
00199     void send_fib_client_resolve_route4_cb(const XrlError& xrl_error,
00200                       string target_name);
00201 #ifdef HAVE_IPV6
00202     void send_fib_client_delete_route6_cb(const XrlError& xrl_error,
00203                       string target_name);
00204     void send_fib_client_add_route6_cb(const XrlError& xrl_error,
00205                        string target_name);
00206     void send_fib_client_resolve_route6_cb(const XrlError& xrl_error,
00207                       string target_name);
00208 #endif
00209 
00213     template<class F>
00214     class FibClient {
00215     public:
00216     FibClient(const string& target_name, XrlFibClientManager& xfcm)
00217         : _target_name(target_name), _xfcm(&xfcm),
00218           _send_updates(false), _send_resolves(false) {}
00219 
00220     FibClient() { _xfcm = NULL; }
00221     FibClient& operator=(const FibClient& rhs) {
00222         if (this != &rhs) {
00223         _inform_fib_client_queue = rhs._inform_fib_client_queue;
00224         _inform_fib_client_queue_timer = rhs._inform_fib_client_queue_timer;
00225         _target_name = rhs._target_name;
00226         _send_updates = rhs._send_updates;
00227         _send_resolves = rhs._send_resolves;
00228         }
00229         return *this;
00230     }
00231 
00232     void    activate(const list<F>& fte_list);
00233     void    send_fib_client_route_change_cb(const XrlError& xrl_error);
00234 
00235     bool get_send_updates() const { return _send_updates; }
00236     bool get_send_resolves() const { return _send_resolves; }
00237     void set_send_updates(const bool sendit) { _send_updates = sendit; }
00238     void set_send_resolves(const bool sendit) { _send_resolves = sendit; }
00239 
00240     private:
00241     EventLoop& eventloop() { return _xfcm->eventloop(); }
00242     void    send_fib_client_route_change();
00243 
00244     list<F>         _inform_fib_client_queue;
00245     XorpTimer       _inform_fib_client_queue_timer;
00246 
00247     string          _target_name;   // Target name of the client
00248     XrlFibClientManager*    _xfcm;
00249 
00250     bool            _send_updates;  // Event filters
00251     bool            _send_resolves;
00252     };
00253 
00254     typedef FibClient<Fte4> FibClient4;
00255     map<string, FibClient4> _fib_clients4;
00256 
00257 #ifdef HAVE_IPV6
00258     typedef FibClient<Fte6> FibClient6;
00259     map<string, FibClient6> _fib_clients6;
00260 #endif
00261 
00262     XrlFeaFibClientV0p1Client   _xrl_fea_fib_client;
00263 };
00264 
00265 #endif // __FEA_XRL_FIB_CLIENT_MANAGER_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations