xorp

ifconfig_set_click.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/data_plane/ifconfig/ifconfig_set_click.hh,v 1.13 2008/10/02 21:57:07 bms Exp $
00021 
00022 #ifndef __FEA_DATA_PLANE_IFCONFIG_IFCONFIG_SET_CLICK_HH__
00023 #define __FEA_DATA_PLANE_IFCONFIG_IFCONFIG_SET_CLICK_HH__
00024 
00025 #include <xorp_config.h>
00026 #ifdef XORP_USE_CLICK
00027 
00028 
00029 #include "fea/ifconfig_set.hh"
00030 #include "fea/data_plane/control_socket/click_socket.hh"
00031 
00032 class RunCommand;
00033 
00034 
00035 class IfConfigSetClick : public IfConfigSet,
00036              public ClickSocket {
00037 private:
00038     class ClickConfigGenerator;
00039 
00040 public:
00047     IfConfigSetClick(FeaDataPlaneManager& fea_data_plane_manager);
00048 
00052     virtual ~IfConfigSetClick();
00053 
00060     virtual int start(string& error_msg);
00061 
00068     virtual int stop(string& error_msg);
00069 
00075     const IfTree& iftree() const { return _iftree; }
00076 
00087     void click_config_generator_done(
00088     IfConfigSetClick::ClickConfigGenerator* click_config_generator,
00089     bool success,
00090     const string& error_msg);
00091 
00092 private:
00100     virtual bool is_discard_emulated(const IfTreeInterface& i) const;
00101 
00109     virtual bool is_unreachable_emulated(const IfTreeInterface& i) const;
00110 
00117     virtual int config_begin(string& error_msg);
00118 
00125     virtual int config_end(string& error_msg);
00126 
00137     virtual int config_interface_begin(const IfTreeInterface* pulled_ifp,
00138                        IfTreeInterface& config_iface,
00139                        string& error_msg);
00140 
00151     virtual int config_interface_end(const IfTreeInterface* pulled_ifp,
00152                      const IfTreeInterface& config_iface,
00153                      string& error_msg);
00154 
00169     virtual int config_vif_begin(const IfTreeInterface* pulled_ifp,
00170                  const IfTreeVif* pulled_vifp,
00171                  const IfTreeInterface& config_iface,
00172                  const IfTreeVif& config_vif,
00173                  string& error_msg);
00174 
00189     virtual int config_vif_end(const IfTreeInterface* pulled_ifp,
00190                    const IfTreeVif* pulled_vifp,
00191                    const IfTreeInterface& config_iface,
00192                    const IfTreeVif& config_vif,
00193                    string& error_msg);
00194 
00216     virtual int config_add_address(const IfTreeInterface* pulled_ifp,
00217                    const IfTreeVif* pulled_vifp,
00218                    const IfTreeAddr4* pulled_addrp,
00219                    const IfTreeInterface& config_iface,
00220                    const IfTreeVif& config_vif,
00221                    const IfTreeAddr4& config_addr,
00222                    string& error_msg);
00223 
00242     virtual int config_delete_address(const IfTreeInterface* pulled_ifp,
00243                       const IfTreeVif* pulled_vifp,
00244                       const IfTreeAddr4* pulled_addrp,
00245                       const IfTreeInterface& config_iface,
00246                       const IfTreeVif& config_vif,
00247                       const IfTreeAddr4& config_addr,
00248                       string& error_msg);
00249 
00271     virtual int config_add_address(const IfTreeInterface* pulled_ifp,
00272                    const IfTreeVif* pulled_vifp,
00273                    const IfTreeAddr6* pulled_addrp,
00274                    const IfTreeInterface& config_iface,
00275                    const IfTreeVif& config_vif,
00276                    const IfTreeAddr6& config_addr,
00277                    string& error_msg);
00278 
00297     virtual int config_delete_address(const IfTreeInterface* pulled_ifp,
00298                       const IfTreeVif* pulled_vifp,
00299                       const IfTreeAddr6* pulled_addrp,
00300                       const IfTreeInterface& config_iface,
00301                       const IfTreeVif& config_vif,
00302                       const IfTreeAddr6& config_addr,
00303                       string& error_msg);
00304 
00305     int execute_click_config_generator(string& error_msg);
00306     void terminate_click_config_generator();
00307     int write_generated_config(bool is_kernel_click,
00308                    const string& kernel_config,
00309                    bool is_user_click,
00310                    const string& user_config,
00311                    string& error_msg);
00312     string regenerate_xorp_iftree_config() const;
00313     string regenerate_xorp_fea_click_config() const;
00314 
00320     int generate_nexthop_to_port_mapping();
00321 
00322     ClickSocketReader   _cs_reader;
00323     IfTree      _iftree;
00324 
00325     class ClickConfigGenerator {
00326     public:
00327     ClickConfigGenerator(IfConfigSetClick& ifconfig_set_click,
00328                  const string& command_name);
00329     ~ClickConfigGenerator();
00330     int execute(const string& xorp_config, string& error_msg);
00331 
00332     const string& command_name() const { return _command_name; }
00333     const string& command_stdout() const { return _command_stdout; }
00334 
00335     private:
00336     void stdout_cb(RunCommand* run_command, const string& output);
00337     void stderr_cb(RunCommand* run_command, const string& output);
00338     void done_cb(RunCommand* run_command, bool success,
00339              const string& error_msg);
00340 
00341     IfConfigSetClick& _ifconfig_set_click;
00342     EventLoop&  _eventloop;
00343     string      _command_name;
00344     list<string>    _command_argument_list;
00345     RunCommand* _run_command;
00346     string      _command_stdout;
00347     string      _tmp_filename;
00348     };
00349 
00350     ClickConfigGenerator*   _kernel_click_config_generator;
00351     ClickConfigGenerator*   _user_click_config_generator;
00352     bool            _has_kernel_click_config;
00353     bool            _has_user_click_config;
00354     string          _generated_kernel_click_config;
00355     string          _generated_user_click_config;
00356 };
00357 
00358 #endif
00359 #endif // __FEA_DATA_PLANE_IFCONFIG_IFCONFIG_SET_CLICK_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations