xorp

ifconfig.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/fea/ifconfig.hh,v 1.81 2008/10/02 21:56:47 bms Exp $
00021 
00022 #ifndef __FEA_IFCONFIG_HH__
00023 #define __FEA_IFCONFIG_HH__
00024 
00025 #include "libxorp/status_codes.h"
00026 #include "libxorp/transaction.hh"
00027 
00028 #include "ifconfig_property.hh"
00029 #include "ifconfig_get.hh"
00030 #include "ifconfig_set.hh"
00031 #include "ifconfig_observer.hh"
00032 #include "ifconfig_vlan_get.hh"
00033 #include "ifconfig_vlan_set.hh"
00034 #include "ifconfig_reporter.hh"
00035 #include "iftree.hh"
00036 
00037 class EventLoop;
00038 class FeaNode;
00039 class IfConfigErrorReporterBase;
00040 class IfConfigTransactionManager;
00041 class IfConfigUpdateReporterBase;
00042 class NexthopPortMapper;
00043 
00044 
00049 class IfConfig {
00050 public:
00056     IfConfig(FeaNode& fea_node);
00057 
00061     virtual ~IfConfig();
00062 
00068     EventLoop& eventloop() { return _eventloop; }
00069 
00076     ProcessStatus status(string& reason) const;
00077 
00085     int start_transaction(uint32_t& tid, string& error_msg);
00086 
00094     int commit_transaction(uint32_t tid, string& error_msg);
00095 
00103     int abort_transaction(uint32_t tid, string& error_msg);
00104 
00113     int add_transaction_operation(uint32_t tid,
00114                   const TransactionManager::Operation& op,
00115                   string& error_msg);
00116 
00120     int add_interface(const char* ifname);
00121     int add_interface(const string& ifname) { return add_interface(ifname.c_str()); }
00122     int remove_interface(const char* ifname);
00123     int remove_interface(const string& ifname) { return remove_interface(ifname.c_str()); }
00124     int update_interface(const IfTreeInterface& iface);
00125 
00131     NexthopPortMapper& nexthop_port_mapper() { return (_nexthop_port_mapper); }
00132 
00139     IfConfigUpdateReplicator& ifconfig_update_replicator() {
00140     return (_ifconfig_update_replicator);
00141     }
00142 
00148     IfConfigErrorReporterBase& ifconfig_error_reporter() {
00149     return (_ifconfig_error_reporter);
00150     }
00151 
00157     IfTree& system_config() { return (_system_config); }
00158 
00164     void set_system_config(const IfTree& iftree) { _system_config = iftree; }
00165 
00171     IfTree& user_config()       { return (_user_config); }
00172 
00178     void set_user_config(const IfTree& iftree) { _user_config = iftree; }
00179 
00185     IfTree& merged_config()     { return (_merged_config); }
00186 
00192     void set_merged_config(const IfTree& iftree) { _merged_config = iftree; }
00193 
00199     const IfTree& original_config() { return (_original_config); }
00200 
00207     bool restore_original_config_on_shutdown() const {
00208     return (_restore_original_config_on_shutdown);
00209     }
00210 
00218     void set_restore_original_config_on_shutdown(bool v) {
00219     _restore_original_config_on_shutdown = v;
00220     }
00221 
00230     int register_ifconfig_property(IfConfigProperty* ifconfig_property,
00231                    bool is_exclusive);
00232 
00239     int unregister_ifconfig_property(IfConfigProperty* ifconfig_property);
00240 
00249     int register_ifconfig_get(IfConfigGet* ifconfig_get, bool is_exclusive);
00250 
00257     int unregister_ifconfig_get(IfConfigGet* ifconfig_get);
00258 
00267     int register_ifconfig_set(IfConfigSet* ifconfig_set, bool is_exclusive);
00268 
00275     int unregister_ifconfig_set(IfConfigSet* ifconfig_set);
00276 
00285     int register_ifconfig_observer(IfConfigObserver* ifconfig_observer,
00286                    bool is_exclusive);
00287 
00294     int unregister_ifconfig_observer(IfConfigObserver* ifconfig_observer);
00295 
00304     int register_ifconfig_vlan_get(IfConfigVlanGet* ifconfig_vlan_get,
00305                    bool is_exclusive);
00306 
00313     int unregister_ifconfig_vlan_get(IfConfigVlanGet* ifconfig_vlan_get);
00314 
00323     int register_ifconfig_vlan_set(IfConfigVlanSet* ifconfig_vlan_set,
00324                    bool is_exclusive);
00325 
00332     int unregister_ifconfig_vlan_set(IfConfigVlanSet* ifconfig_vlan_set);
00333 
00340     int start(string& error_msg);
00341 
00348     int stop(string& error_msg);
00349 
00360     int push_config(const IfTree& iftree);
00361 
00367     const string& push_error() const;
00368 
00377     const IfTree& pull_config(const char* ifname, int if_index);
00378 
00379 
00387     const IfTree& full_pulled_config();
00388 
00395     bool report_update(const IfTreeInterface& fi);
00396 
00404     bool report_update(const IfTreeInterface& fi, const IfTreeVif& fv);
00405 
00414     bool report_update(const IfTreeInterface&   fi,
00415                const IfTreeVif&     fv,
00416                const IfTreeAddr4&   fa);
00417 
00418 #ifdef HAVE_IPV6
00419 
00427     bool report_update(const IfTreeInterface&   fi,
00428                const IfTreeVif&     fv,
00429                const IfTreeAddr6&   fa);
00430 #endif
00431 
00435     void report_updates_completed();
00436 
00443     void report_updates(IfTree& iftree);
00444 
00445 private:
00454     int restore_config(const IfTree& old_user_config,
00455                const IfTree& old_system_config,
00456                string& error_msg);
00457 
00458     FeaNode&            _fea_node;
00459     EventLoop&          _eventloop;
00460     NexthopPortMapper&      _nexthop_port_mapper;
00461     IfConfigTransactionManager* _itm;   // The interface transaction manager
00462 
00463     IfTree      _user_config;   // The IfTree with the user config
00464     IfTree      _system_config; /* The IfTree with the system config.
00465                      * This usually only holds info for devices in _user_config */
00466     IfTree      _merged_config; // The merged system-user config
00467     IfTree      _original_config; // The IfTree on startup
00468     bool        _restore_original_config_on_shutdown; // If true, then
00469                 //  restore the original config on shutdown
00470 
00471     IfConfigUpdateReplicator    _ifconfig_update_replicator;
00472     IfConfigErrorReporter   _ifconfig_error_reporter;
00473 
00474     //
00475     // The registered plugins
00476     //
00477     list<IfConfigProperty*> _ifconfig_property_plugins;
00478     list<IfConfigGet*>      _ifconfig_gets;
00479     list<IfConfigSet*>      _ifconfig_sets;
00480     list<IfConfigObserver*> _ifconfig_observers;
00481     list<IfConfigVlanGet*>  _ifconfig_vlan_gets;
00482     list<IfConfigVlanSet*>  _ifconfig_vlan_sets;
00483 
00484     //
00485     // Misc other state
00486     //
00487     bool    _is_running;
00488 };
00489 
00490 #endif // __FEA_IFCONFIG_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations