xorp

master_conf_tree.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 
00021 #ifndef __RTRMGR_MASTER_CONF_TREE_HH__
00022 #define __RTRMGR_MASTER_CONF_TREE_HH__
00023 
00024 
00025 #include "conf_tree.hh"
00026 #include "master_conf_tree_node.hh"
00027 #include "rtrmgr_error.hh"
00028 #include "task.hh"
00029 
00030 
00031 class CommandTree;
00032 class ConfTemplate;
00033 class RouterCLI;
00034 class MasterTemplateTree;
00035 
00036 class MasterConfigTree : public ConfigTree {
00037     typedef XorpCallback0<void>::RefPtr CallBack0;
00038     typedef XorpCallback2<void, bool, string>::RefPtr CallBack;
00039     typedef XorpCallback4<void, bool, string, string, string>::RefPtr ConfigChangeCallBack;
00040     typedef XorpCallback2<void, bool, string>::RefPtr ConfigSaveCallBack;
00041     typedef XorpCallback4<void, bool, string, string, string>::RefPtr ConfigLoadCallBack;
00042 
00043 public:
00044     MasterConfigTree(const string& config_file, MasterTemplateTree* tt,
00045              ModuleManager& mmgr, XorpClient& xclient,
00046              bool global_do_exec, bool verbose) throw (InitError);
00047     MasterConfigTree(TemplateTree* tt, bool verbose);
00048     MasterConfigTree& operator=(const MasterConfigTree& orig_tree);
00049     ~MasterConfigTree();
00050     
00051 
00052     bool read_file(string& configuration, const string& config_file,
00053            string& errmsg);
00054     bool parse(const string& configuration, const string& config_file,
00055            string& errmsg);
00056     void execute();
00057     void config_done(bool success, string errmsg);
00058 
00059     virtual ConfigTreeNode* create_node(const string& segment, 
00060                     const string& path,
00061                     const TemplateTreeNode* ttn, 
00062                     ConfigTreeNode* parent_node, 
00063                     const ConfigNodeId& node_id,
00064                     uid_t user_id, bool verbose);
00065     virtual ConfigTree* create_tree(TemplateTree *tt, bool verbose);
00066 
00067     void commit_changes_pass1(CallBack cb);
00068     void commit_pass1_done(bool success, string errmsg);
00069     void commit_changes_pass2();
00070     void commit_pass2_done(bool success, string errmsg);
00071 
00072     bool commit_in_progress() const { return _commit_in_progress; }
00073     bool config_failed() const { return _config_failed; }
00074     const string& config_failed_msg() const { return _config_failed_msg; }
00075     bool check_commit_status(string& response);
00076     string discard_changes();
00077     string mark_subtree_for_deletion(const list<string>& path_segments, 
00078                      uid_t user_id);
00079     void delete_entire_config();
00080     bool lock_node(const string& node, uid_t user_id, uint32_t timeout, 
00081            uint32_t& holder);
00082     bool unlock_node(const string& node, uid_t user_id);
00083 
00084     bool change_config(uid_t user_id, CallBack cb, string& errmsg);
00085     bool apply_config_change(uid_t user_id, string& errmsg,
00086                  const string& deltas,
00087                  const string& deletions,
00088                  ConfigChangeCallBack cb);
00089     bool save_config(const string& filename, uid_t user_id,
00090              string& errmsg, ConfigSaveCallBack cb);
00091     bool load_config(const string& filename, uid_t user_id, string& errmsg,
00092              ConfigLoadCallBack cb);
00093 
00094     void set_config_directory(const string& config_directory);
00095 
00096     ModuleManager& module_manager() const {
00097     return _task_manager->module_manager();
00098     }
00099 
00100     virtual ConfigTreeNode& root_node() {
00101     return _root_node;
00102     }
00103     virtual const ConfigTreeNode& const_root_node() const {
00104     return _root_node;
00105     }
00106 
00107     MasterConfigTreeNode& master_root_node() {
00108     return (MasterConfigTreeNode&)_root_node;
00109     }
00110     const MasterConfigTreeNode& const_master_root_node() const {
00111     return (const MasterConfigTreeNode&)_root_node;
00112     }
00113 
00114     MasterConfigTreeNode* find_node(const list<string>& path) {
00115     return (MasterConfigTreeNode*)(ConfigTree::find_node(path));
00116     }
00117     MasterConfigTreeNode* find_config_module(const string& module_name) {
00118     return (MasterConfigTreeNode*)(ConfigTree::find_config_module(module_name));
00119     }
00120     
00124     void set_task_completed(CallBack0 task_completed_cb) {
00125     _task_completed_cb = task_completed_cb;
00126     }
00127 
00128 private:
00129     string config_full_filename(const string& filename) const;
00130 
00131     void remove_tmp_config_file();
00132     bool set_config_file_permissions(FILE* fp, uid_t user_id, string& errmsg);
00133 
00134     void apply_config_commit_changes_cb(bool success, string errmsg,
00135                     ConfigChangeCallBack cb);
00136     void save_config_file_sent_cb(bool success, string errmsg,
00137                   string filename, uid_t user_id,
00138                   ConfigSaveCallBack cb);
00139     void save_config_file_cleanup_cb(bool success, string errmsg,
00140                      bool orig_success, string orig_errmsg,
00141                      string filename, uid_t user_id,
00142                      ConfigSaveCallBack cb);
00143     void save_config_done_cb(bool success, string errmsg,
00144                  ConfigSaveCallBack cb);
00145     bool save_to_file(const string& filename, uid_t user_id, string& errmsg);
00146 
00147     void load_config_file_received_cb(bool success, string errmsg,
00148                       string filename, uid_t user_id,
00149                       ConfigLoadCallBack cb);
00150     void load_config_file_cleanup_cb(bool success, string errmsg,
00151                      bool orig_success, string orig_errmsg,
00152                      string rtrmgr_config_value,
00153                      string filename, uid_t user_id,
00154                      ConfigLoadCallBack cb);
00155     void load_config_commit_changes_cb(bool success, string errmsg,
00156                        string deltas, string deletions,
00157                        ConfigLoadCallBack cb);
00158     bool load_from_file(const string& filename, uid_t user_id, string& errmsg,
00159             string& deltas, string& deletions);
00160 
00161     void diff_configs(const MasterConfigTree& new_tree, 
00162               MasterConfigTree& delta_tree,
00163               MasterConfigTree& deletion_tree);
00164     list<string> find_changed_modules() const;
00165     list<string> find_active_modules() const;
00166     list<string> find_inactive_modules() const;
00167     void order_module_list(const set<string>& module_set,
00168                list<string>& ordered_modules) const;
00169     bool module_config_start(const string& module_name, string& error_msg);
00170     bool module_shutdown(const string& module_name, string& error_msg);
00171 
00172     bool do_exec() const { return _task_manager->do_exec(); }
00173     bool verbose() const { return _task_manager->verbose(); }
00174 
00175     XorpClient& xorp_client() const { return _task_manager->xorp_client(); }
00176 
00177     MasterConfigTreeNode _root_node;
00178     TaskManager*        _task_manager;
00179     CallBack0       _task_completed_cb;
00180     CallBack        _commit_cb;
00181     bool        _commit_in_progress;
00182     bool        _config_failed;
00183     string      _config_failed_msg;
00184     bool        _rtrmgr_config_node_found;
00185     XorpTimer       _save_config_completed_timer;
00186     string      _tmp_config_filename;
00187     string      _config_directory;
00188 
00189     gid_t       _xorp_gid;
00190     bool        _is_xorp_gid_set;
00191     RunCommand::ExecId  _exec_id;
00192     bool        _enable_program_exec_id;
00193 
00194     MasterConfigTree*   _config_tree_copy;
00195 };
00196 
00197 #endif // __RTRMGR_MASTER_CONF_TREE_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations