xorp

fibconfig.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_FIBCONFIG_HH__
00022 #define __FEA_FIBCONFIG_HH__
00023 
00024 #include "libxorp/xorp.h"
00025 #include "libxorp/ipv4.hh"
00026 #include "libxorp/ipv6.hh"
00027 #include "libxorp/ipv4net.hh"
00028 #include "libxorp/ipv6net.hh"
00029 #include "libxorp/status_codes.h"
00030 #include "libxorp/transaction.hh"
00031 #include "libxorp/trie.hh"
00032 
00033 #include "fte.hh"
00034 #include "fibconfig_forwarding.hh"
00035 #include "fibconfig_entry_get.hh"
00036 #include "fibconfig_entry_set.hh"
00037 #include "fibconfig_entry_observer.hh"
00038 #include "fibconfig_table_get.hh"
00039 #include "fibconfig_table_set.hh"
00040 #include "fibconfig_table_observer.hh"
00041 
00042 class EventLoop;
00043 class FeaNode;
00044 class FibConfigTransactionManager;
00045 class FibTableObserverBase;
00046 class IfTree;
00047 class NexthopPortMapper;
00048 #ifndef XORP_DISABLE_PROFILE
00049 class Profile;
00050 #endif
00051 
00052 typedef Trie<IPv4, Fte4> Trie4;
00053 typedef Trie<IPv6, Fte6> Trie6;
00054 
00060 class FibConfig {
00061 public:
00071     FibConfig(FeaNode& fea_node, const IfTree& system_config_iftree,
00072           const IfTree& merged_config_iftree);
00073 
00077     virtual ~FibConfig();
00078 
00084     EventLoop& eventloop() { return _eventloop; }
00085 
00091     NexthopPortMapper& nexthop_port_mapper() { return _nexthop_port_mapper; }
00092 
00098     const IfTree& system_config_iftree() const { return _system_config_iftree; }
00099 
00105     const IfTree& merged_config_iftree() const { return _merged_config_iftree; }
00106 
00113     ProcessStatus status(string& reason) const;
00114 
00122     int start_transaction(uint32_t& tid, string& error_msg);
00123 
00131     int commit_transaction(uint32_t tid, string& error_msg);
00132 
00140     int abort_transaction(uint32_t tid, string& error_msg);
00141 
00150     int add_transaction_operation(uint32_t tid,
00151                   const TransactionManager::Operation& op,
00152                   string& error_msg);
00153 
00162     int register_fibconfig_forwarding(FibConfigForwarding* fibconfig_forwarding,
00163                       bool is_exclusive);
00164 
00171     int unregister_fibconfig_forwarding(FibConfigForwarding* fibconfig_forwarding);
00172 
00181     int register_fibconfig_entry_get(FibConfigEntryGet* fibconfig_entry_get,
00182                      bool is_exclusive);
00183 
00190     int unregister_fibconfig_entry_get(FibConfigEntryGet* fibconfig_entry_get);
00191 
00200     int register_fibconfig_entry_set(FibConfigEntrySet* fibconfig_entry_set,
00201                      bool is_exclusive);
00202 
00209     int unregister_fibconfig_entry_set(FibConfigEntrySet* fibconfig_entry_set);
00210 
00219     int register_fibconfig_entry_observer(FibConfigEntryObserver* fibconfig_entry_observer,
00220                       bool is_exclusive);
00221 
00228     int unregister_fibconfig_entry_observer(FibConfigEntryObserver* fibconfig_entry_observer);
00229 
00238     int register_fibconfig_table_get(FibConfigTableGet* fibconfig_table_get,
00239                      bool is_exclusive);
00240 
00247     int unregister_fibconfig_table_get(FibConfigTableGet* fibconfig_table_get);
00248 
00257     int register_fibconfig_table_set(FibConfigTableSet* fibconfig_table_set,
00258                      bool is_exclusive);
00259 
00266     int unregister_fibconfig_table_set(FibConfigTableSet* fibconfig_table_set);
00267 
00276     int register_fibconfig_table_observer(FibConfigTableObserver* fibconfig_table_observer,
00277                       bool is_exclusive);
00278 
00285     int unregister_fibconfig_table_observer(FibConfigTableObserver* fibconfig_table_observer);
00286     
00293     int start(string& error_msg);
00294     
00301     int stop(string& error_msg);
00302 
00311     int start_configuration(string& error_msg);
00312     
00319     int end_configuration(string& error_msg);
00320 
00328     bool unicast_forwarding_entries_retain_on_startup4() const {
00329     return (_unicast_forwarding_entries_retain_on_startup4);
00330     }
00331 
00339     bool unicast_forwarding_entries_retain_on_shutdown4() const {
00340     return (_unicast_forwarding_entries_retain_on_shutdown4);
00341     }
00342 
00350     bool unicast_forwarding_entries_retain_on_startup6() const {
00351     return (_unicast_forwarding_entries_retain_on_startup6);
00352     }
00353 
00361     bool unicast_forwarding_entries_retain_on_shutdown6() const {
00362     return (_unicast_forwarding_entries_retain_on_shutdown6);
00363     }
00364 
00374     int set_unicast_forwarding_entries_retain_on_startup4(bool retain,
00375                               string& error_msg);
00376 
00386     int set_unicast_forwarding_entries_retain_on_shutdown4(bool retain,
00387                                string& error_msg);
00388 
00398     int set_unicast_forwarding_entries_retain_on_startup6(bool retain,
00399                               string& error_msg);
00400 
00410     int set_unicast_forwarding_entries_retain_on_shutdown6(bool retain,
00411                                string& error_msg);
00412 
00421     bool unicast_forwarding_table_id_is_configured(int family) const;
00422 
00429     uint32_t unicast_forwarding_table_id(int family) const;
00430 
00437     bool unicast_forwarding_table_id4_is_configured() const {
00438     return (_unicast_forwarding_table_id4_is_configured);
00439     }
00440 
00446     uint32_t unicast_forwarding_table_id4() const {
00447     return (_unicast_forwarding_table_id4);
00448     }
00449 
00456     bool unicast_forwarding_table_id6_is_configured() const {
00457     return (_unicast_forwarding_table_id6_is_configured);
00458     }
00459 
00465     uint32_t unicast_forwarding_table_id6() const {
00466     return (_unicast_forwarding_table_id6);
00467     }
00468 
00473     uint32_t get_netlink_filter_table_id() const;
00474 
00475     void propagate_table_id_change();
00476 
00486     int set_unicast_forwarding_table_id4(bool is_configured,
00487                      uint32_t table_id,
00488                      string& error_msg);
00489 
00499     int set_unicast_forwarding_table_id6(bool is_configured,
00500                      uint32_t table_id,
00501                      string& error_msg);
00502 
00512     int unicast_forwarding_enabled4(bool& ret_value, string& error_msg) const;
00513 
00523     int unicast_forwarding_enabled6(bool& ret_value, string& error_msg) const;
00524     
00534     int accept_rtadv_enabled6(bool& ret_value, string& error_msg) const;
00535     
00545     int set_unicast_forwarding_enabled4(bool v, string& error_msg);
00546 
00556     int set_unicast_forwarding_enabled6(bool v, string& error_msg);
00557     
00568     int set_accept_rtadv_enabled6(bool v, string& error_msg);
00569 
00578     virtual int add_entry4(const Fte4& fte);
00579 
00588     virtual int delete_entry4(const Fte4& fte);
00589 
00597     virtual int set_table4(const list<Fte4>& fte_list);
00598 
00606     virtual int delete_all_entries4();
00607 
00615     virtual int lookup_route_by_dest4(const IPv4& dst, Fte4& fte);
00616 
00624     virtual int lookup_route_by_network4(const IPv4Net& dst, Fte4& fte);
00625 
00633     virtual int get_table4(list<Fte4>& fte_list);
00634 
00643     virtual int add_entry6(const Fte6& fte);
00644 
00652     virtual int set_table6(const list<Fte6>& fte_list);
00653 
00662     virtual int delete_entry6(const Fte6& fte);
00663 
00671     virtual int delete_all_entries6();
00672 
00680     virtual int lookup_route_by_dest6(const IPv6& dst, Fte6& fte);
00681 
00689     virtual int lookup_route_by_network6(const IPv6Net& dst, Fte6& fte);
00690 
00698     virtual int get_table6(list<Fte6>& fte_list);
00699 
00706     int add_fib_table_observer(FibTableObserverBase* fib_table_observer);
00707     
00714     int delete_fib_table_observer(FibTableObserverBase* fib_table_observer);
00715 
00722     void propagate_fib_changes(const list<FteX>& fte_list,
00723                    const FibConfigTableObserver* fibconfig_table_observer);
00724 
00730     Trie4& trie4() { return _trie4; }
00731 
00737     Trie6& trie6() { return _trie6; }
00738 
00739 protected:
00740     Trie4   _trie4;     // IPv4 trie (used for testing purpose)
00741     Trie6   _trie6;     // IPv6 trie (used for testing purpose)
00742     
00743 private:
00744     FeaNode&                _fea_node;
00745     EventLoop&              _eventloop;
00746 #ifndef XORP_DISABLE_PROFILE
00747     Profile&                _profile;
00748 #endif
00749     NexthopPortMapper&          _nexthop_port_mapper;
00750     const IfTree&           _system_config_iftree;
00751     const IfTree&           _merged_config_iftree;
00752 
00753     //
00754     // The FIB transaction manager
00755     //
00756     FibConfigTransactionManager*    _ftm;
00757 
00758     //
00759     // The registered plugins
00760     //
00761     list<FibConfigForwarding*>      _fibconfig_forwarding_plugins;
00762     list<FibConfigEntryGet*>        _fibconfig_entry_gets;
00763     list<FibConfigEntrySet*>        _fibconfig_entry_sets;
00764     list<FibConfigEntryObserver*>   _fibconfig_entry_observers;
00765     list<FibConfigTableGet*>        _fibconfig_table_gets;
00766     list<FibConfigTableSet*>        _fibconfig_table_sets;
00767     list<FibConfigTableObserver*>   _fibconfig_table_observers;
00768     
00769     //
00770     // Configured unicast forwarding entries properties
00771     //
00772     bool    _unicast_forwarding_entries_retain_on_startup4;
00773     bool    _unicast_forwarding_entries_retain_on_shutdown4;
00774     bool    _unicast_forwarding_entries_retain_on_startup6;
00775     bool    _unicast_forwarding_entries_retain_on_shutdown6;
00776     uint32_t    _unicast_forwarding_table_id4;
00777     bool    _unicast_forwarding_table_id4_is_configured;
00778     uint32_t    _unicast_forwarding_table_id6;
00779     bool    _unicast_forwarding_table_id6_is_configured;
00780 
00781     //
00782     // Misc other state
00783     //
00784     bool    _is_running;
00785     list<FibTableObserverBase*> _fib_table_observers;
00786 };
00787 
00792 class FibTableObserverBase {
00793 public:
00794     FibTableObserverBase() {}
00795     virtual ~FibTableObserverBase() {}
00796 
00804     virtual void process_fib_changes(const list<Fte4>& fte_list) = 0;
00805 
00806 #ifdef HAVE_IPV6
00807 
00814     virtual void process_fib_changes(const list<Fte6>& fte_list) = 0;
00815 #endif
00816 
00817 private:
00818 };
00819 
00820 #endif  // __FEA_FIBCONFIG_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations