xorp

xrl_rtrmgr_interface.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/rtrmgr/xrl_rtrmgr_interface.hh,v 1.33 2008/10/02 21:58:27 bms Exp $
00021 
00022 #ifndef __RTRMGR_XRL_RTRMGR_INTERFACE_HH__
00023 #define __RTRMGR_XRL_RTRMGR_INTERFACE_HH__
00024 
00025 
00026 #include "libxorp/timer.hh"
00027 
00028 #include "xrl/targets/rtrmgr_base.hh"
00029 #include "xrl/interfaces/rtrmgr_client_xif.hh"
00030 #include "xrl/interfaces/finder_event_notifier_xif.hh"
00031 
00032 #include "generic_module_manager.hh"
00033 
00034 
00035 #define CNAMELEN 40
00036 
00037 
00038 class MasterConfigTree;
00039 class RandomGen;
00040 class User;
00041 class UserDB;
00042 class UserInstance;
00043 class Rtrmgr;
00044 
00045 class XrlRtrmgrInterface : public XrlRtrmgrTargetBase {
00046     typedef XorpCallback2<void, bool, string>::RefPtr CallBack;
00047     typedef XorpCallback4<void, bool, string, string, string>::RefPtr ConfigChangeCallBack;
00048     typedef XorpCallback2<void, bool, string>::RefPtr ConfigSaveCallBack;
00049     typedef XorpCallback4<void, bool, string, string, string>::RefPtr ConfigLoadCallBack;
00050 
00051 public:
00052     XrlRtrmgrInterface(XrlRouter& r, UserDB& db, EventLoop& eventloop,
00053                RandomGen& randgen, Rtrmgr& rtrmgr);
00054     ~XrlRtrmgrInterface();
00055 
00056     void set_master_config_tree(MasterConfigTree* v) { _master_config_tree = v; }
00057 
00058     XrlCmdError common_0_1_get_target_name(// Output values,
00059                        string& name);
00060 
00061     XrlCmdError common_0_1_get_version(// Output values, 
00062                        string& version);
00063 
00067     XrlCmdError common_0_1_get_status(// Output values,
00068                       uint32_t& status,
00069                       string& reason);
00070 
00074     XrlCmdError common_0_1_shutdown();
00075 
00076     XrlCmdError common_0_1_startup() { return XrlCmdError::OKAY(); }
00077 
00078     XrlCmdError rtrmgr_0_1_get_pid(
00079         // Output values, 
00080     uint32_t& pid);
00081 
00082     XrlCmdError rtrmgr_0_1_register_client(
00083     // Input values, 
00084     const uint32_t& user_id, 
00085     const string& clientname, 
00086     // Output values, 
00087     string& filename,
00088     uint32_t& pid,
00089     uint32_t& clientid);
00090 
00091     XrlCmdError rtrmgr_0_1_unregister_client(
00092         // Input values
00093     const string& token);
00094 
00095     XrlCmdError rtrmgr_0_1_authenticate_client(
00096     // Input values, 
00097     const uint32_t& user_id, 
00098     const string& clientname, 
00099     const string& token);
00100 
00101     XrlCmdError rtrmgr_0_1_enter_config_mode(
00102     // Input values, 
00103     const string&   token, 
00104     const bool& exclusive);
00105 
00106     XrlCmdError rtrmgr_0_1_leave_config_mode(
00107     // Input values, 
00108     const string&   token);
00109 
00110     XrlCmdError rtrmgr_0_1_get_config_users(
00111     // Input values, 
00112     const string& token, 
00113     // Output values, 
00114     XrlAtomList& users);
00115 
00116     XrlCmdError rtrmgr_0_1_get_running_config(
00117     // Input values, 
00118     const string& token, 
00119     // Output values, 
00120     bool& ready,
00121     string& config);
00122 
00123     XrlCmdError rtrmgr_0_1_apply_config_change(
00124     // Input values, 
00125     const string& token, 
00126     const string& target, 
00127     const string& deltas,
00128     const string& deletions);
00129 
00130     void apply_config_change_done(bool success, string error_msg,
00131                   string deltas, string deletions,
00132                   uid_t user_id, string target);
00133 
00134     void config_saved_done_cb(const XrlError&);
00135     void apply_config_change_done_cb(const XrlError&);
00136     void client_updated(const XrlError& e, uid_t user_id, UserInstance* user);
00137 
00138     void module_status_changed(const string& modname,
00139                    GenericModule::ModuleStatus status);
00140 
00141     XrlCmdError rtrmgr_0_1_lock_config(
00142     // Input values, 
00143     const string& token, 
00144     const uint32_t& timeout, 
00145     // Output values, 
00146     bool& success, 
00147     uint32_t& holder);
00148 
00149     XrlCmdError rtrmgr_0_1_unlock_config(
00150     // Input values, 
00151     const string& token);
00152 
00153     XrlCmdError rtrmgr_0_1_lock_node(
00154     // Input values, 
00155     const string& token, 
00156     const string& node, 
00157     const uint32_t& timeout, 
00158     // Output values, 
00159     bool& success, 
00160     uint32_t& holder);
00161 
00162     XrlCmdError rtrmgr_0_1_unlock_node(
00163     // Input values, 
00164     const string& token, 
00165     const string& node);
00166 
00167     XrlCmdError rtrmgr_0_1_save_config(
00168     // Input values, 
00169     const string& token, 
00170     const string& target, 
00171     const string& filename);
00172 
00173     XrlCmdError rtrmgr_0_1_load_config(
00174     // Input values, 
00175     const string& token, 
00176     const string& target, 
00177     const string& filename);
00178 
00185     XrlCmdError rtrmgr_0_1_set_config_directory(
00186     // Input values,
00187     const string&   config_directory);
00188 
00189     XrlCmdError finder_event_observer_0_1_xrl_target_birth(
00190     // Input values,
00191     const string&   target_class,
00192     const string&   target_instance);
00193 
00194     XrlCmdError finder_event_observer_0_1_xrl_target_death(
00195     // Input values,
00196     const string&   target_class,
00197     const string&   target_instance);
00198 
00199     void finder_register_done(const XrlError& e, string clientname);
00200 
00201 private:
00202     typedef XorpCallback1<void, const XrlError&>::RefPtr GENERIC_CALLBACK;
00203 
00204     void save_config_done(bool success, string error_msg, string filename,
00205               uid_t user_id, string target);
00206     void load_config_done(bool success, string error_msg, string deltas,
00207               string deletions, string filename, uid_t user_id,
00208               string target);
00209     UserInstance* find_user_instance(uid_t user_id, const string& clientname);
00210     string generate_auth_token(uid_t user_id, const string& clientname);
00211     bool verify_token(const string& token) const;
00212     uid_t get_user_id_from_token(const string& token) const;
00213     void lock_timeout();
00214     void initialize_client_state(uid_t user_id, UserInstance *user);
00215     void send_client_state(uid_t user_id, string clientname);
00216     uint32_t allocate_clientid();
00217     void deallocate_clientid(uint32_t clientid);
00218 
00219     XrlRouter& _xrl_router;
00220     XrlRtrmgrClientV0p2Client       _client_interface;
00221     XrlFinderEventNotifierV0p1Client    _finder_notifier_interface;
00222     multimap<uid_t, UserInstance*>  _users;
00223     multimap<uid_t, UserInstance*>  _config_users;
00224     set<uint32_t>   _clientids;
00225     UserDB&     _userdb;
00226     MasterConfigTree*   _master_config_tree;
00227     EventLoop&      _eventloop;
00228     RandomGen&      _randgen;
00229     Rtrmgr&             _rtrmgr;
00230 
00231     bool    _exclusive;  // Indicates only one user allowed in config mode
00232     string  _exclusive_username;    // The current exclusive user name
00233 
00234     // Variables to implement global lock on config changes
00235     bool    _config_locked;
00236     string  _lock_holder_token;
00237     XorpTimer   _lock_timer;
00238 
00239     // generic place to store background task callback timers
00240     list <XorpTimer> _background_tasks;
00241 
00242     bool    _verbose;   //  Set to true if output is verbose
00243 };
00244 
00245 #endif // __RTRMGR_XRL_RTRMGR_INTERFACE_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations