VOM: bond: Add support for LACP
[vpp.git] / src / vpp-api / vom / interface.hpp
index 8863bc9..0099bde 100644 (file)
@@ -16,9 +16,7 @@
 #ifndef __VOM_INTERFACE_H__
 #define __VOM_INTERFACE_H__
 
-#include "vom/dump_cmd.hpp"
 #include "vom/enum_base.hpp"
-#include "vom/event_cmd.hpp"
 #include "vom/hw.hpp"
 #include "vom/inspect.hpp"
 #include "vom/object_base.hpp"
 #include "vom/rpc_cmd.hpp"
 #include "vom/singular_db.hpp"
 
-#include <vapi/af_packet.api.vapi.hpp>
-#include <vapi/interface.api.vapi.hpp>
-#include <vapi/stats.api.vapi.hpp>
-#include <vapi/tap.api.vapi.hpp>
-#include <vapi/vapi.hpp>
-#include <vapi/vpe.api.vapi.hpp>
-
 namespace VOM {
+/**
+ * Forward declaration of the stats and events command
+ */
+namespace interface_cmds {
+class stats_enable_cmd;
+class events_cmd;
+};
+
 /**
  * A representation of an interface in VPP
  */
@@ -45,7 +44,7 @@ public:
   /**
    * The key for interface's key
    */
-  typedef std::string key_type;
+  typedef std::string key_t;
 
   /**
    * The iterator type
@@ -91,6 +90,16 @@ public:
      */
     const static type_t TAP;
 
+    /**
+     * vhost-user interface type
+     */
+    const static type_t VHOST;
+
+    /**
+     * bond interface type
+     */
+    const static type_t BOND;
+
     /**
      * Convert VPP's name of the interface to a type
      */
@@ -158,7 +167,10 @@ public:
   /**
    * Construct a new object matching the desried state
    */
-  interface(const std::string& name, type_t type, admin_state_t state);
+  interface(const std::string& name,
+            type_t type,
+            admin_state_t state,
+            const std::string& tag = "");
   /**
    * Construct a new object matching the desried state mapped
    * to a specific route_domain
@@ -166,7 +178,8 @@ public:
   interface(const std::string& name,
             type_t type,
             admin_state_t state,
-            const route_domain& rd);
+            const route_domain& rd,
+            const std::string& tag = "");
   /**
    * Destructor
    */
@@ -208,13 +221,18 @@ public:
   /**
    * Return the interface type
    */
-  const key_type& key() const;
+  const key_t& key() const;
 
   /**
    * Return the L2 Address
    */
   const l2_address_t& l2_address() const;
 
+  /**
+   * Set the admin state of the interface
+   */
+  void set(const admin_state_t& state);
+
   /**
    * Set the L2 Address
    */
@@ -225,6 +243,16 @@ public:
    */
   void set(const oper_state_t& state);
 
+  /**
+   * Set the tag to the interface
+   */
+  void set(const std::string& tag);
+
+  /**
+   * Comparison operator - only used for UT
+   */
+  virtual bool operator==(const interface& i) const;
+
   /**
    * A base class for interface Create commands
    */
@@ -260,6 +288,11 @@ public:
       interface::add(m_name, this->item());
     }
 
+    /**
+     * add the created interface to the DB
+     */
+    void insert_interface() { interface::add(m_name, this->item()); }
+
     virtual vapi_error_e operator()(MSG& reply)
     {
       int sw_if_index = reply.get_response().get_payload().sw_if_index;
@@ -288,75 +321,6 @@ public:
     const std::string& m_name;
   };
 
-  /**
-   * A command class to create Loopback interfaces in VPP
-   */
-  class loopback_create_cmd : public create_cmd<vapi::Create_loopback>
-  {
-  public:
-    /**
-     * Constructor taking the HW::item to update
-     * and the name of the interface to create
-     */
-    loopback_create_cmd(HW::item<handle_t>& item, const std::string& name);
-    ~loopback_create_cmd() = default;
-
-    /**
-     * Issue the command to VPP/HW
-     */
-    rc_t issue(connection& con);
-    /**
-     * convert to string format for debug purposes
-     */
-    std::string to_string() const;
-  };
-
-  /**
-   * A command class to create af_packet interfaces in VPP
-   */
-  class af_packet_create_cmd : public create_cmd<vapi::Af_packet_create>
-  {
-  public:
-    /**
-     * Constructor taking the HW::item to update
-     * and the name of the interface to create
-     */
-    af_packet_create_cmd(HW::item<handle_t>& item, const std::string& name);
-    ~af_packet_create_cmd() = default;
-    /**
-     * Issue the command to VPP/HW
-     */
-    rc_t issue(connection& con);
-    /**
-     * convert to string format for debug purposes
-     */
-    std::string to_string() const;
-  };
-
-  /**
-   * A command class to create TAP interfaces in VPP
-   */
-  class tap_create_cmd : public create_cmd<vapi::Tap_connect>
-  {
-  public:
-    /**
-     * Constructor taking the HW::item to update
-     * and the name of the interface to create
-     */
-    tap_create_cmd(HW::item<handle_t>& item, const std::string& name);
-    ~tap_create_cmd() = default;
-
-    /**
-     * Issue the command to VPP/HW
-     */
-    rc_t issue(connection& con);
-
-    /**
-     * convert to string format for debug purposes
-     */
-    std::string to_string() const;
-  };
-
   /**
    * Base class for intterface Delete commands
    */
@@ -394,230 +358,18 @@ public:
      */
     void succeeded() {}
 
-  protected:
     /**
-     * The name of the interface to be created
+     * remove the deleted interface from the DB
      */
-    const std::string m_name;
-  };
+    void remove_interface() { interface::remove(this->item()); }
 
-  /**
-   * A command class to delete loopback interfaces in VPP
-   */
-  class loopback_delete_cmd : public delete_cmd<vapi::Delete_loopback>
-  {
-  public:
-    /**
-     * Constructor taking the HW::item to update
-     */
-    loopback_delete_cmd(HW::item<handle_t>& item);
-
-    /**
-     * Issue the command to VPP/HW
-     */
-    rc_t issue(connection& con);
-    /**
-     * convert to string format for debug purposes
-     */
-    std::string to_string() const;
-  };
-
-  /**
-   * A command class to delete af-packet interfaces in VPP
-   */
-  class af_packet_delete_cmd : public delete_cmd<vapi::Af_packet_delete>
-  {
-  public:
-    /**
-     * Constructor taking the HW::item to update
-     * and the name of the interface to delete
-     */
-    af_packet_delete_cmd(HW::item<handle_t>& item, const std::string& name);
-
-    /**
-     * Issue the command to VPP/HW
-     */
-    rc_t issue(connection& con);
-    /**
-     * convert to string format for debug purposes
-     */
-    std::string to_string() const;
-  };
-
-  /**
-   * A command class to delete TAP interfaces in VPP
-   */
-  class tap_delete_cmd : public delete_cmd<vapi::Tap_delete>
-  {
-  public:
-    /**
-     * Constructor taking the HW::item to update
-     */
-    tap_delete_cmd(HW::item<handle_t>& item);
-
-    /**
-     * Issue the command to VPP/HW
-     */
-    rc_t issue(connection& con);
-    /**
-     * convert to string format for debug purposes
-     */
-    std::string to_string() const;
-  };
-
-  /**
-   * A command class to delete TAP interfaces in VPP
-   */
-  class set_tag
-    : public rpc_cmd<HW::item<handle_t>, rc_t, vapi::Sw_interface_tag_add_del>
-  {
-  public:
-    /**
-     * Constructor taking the HW::item to update
-     */
-    set_tag(HW::item<handle_t>& item, const std::string& name);
-
-    /**
-     * Issue the command to VPP/HW
-     */
-    rc_t issue(connection& con);
-
-    /**
-     * convert to string format for debug purposes
-     */
-    std::string to_string() const;
-
-    /**
-     * Comparison operator - only used for UT
-     */
-    bool operator==(const set_tag& i) const;
-
-  private:
+  protected:
     /**
-     * The tag to add
+     * The name of the interface to be created
      */
     const std::string m_name;
   };
 
-  /**
-   * A cmd class that changes the admin state
-   */
-  class state_change_cmd : public rpc_cmd<HW::item<admin_state_t>,
-                                          rc_t,
-                                          vapi::Sw_interface_set_flags>
-  {
-  public:
-    /**
-     * Constructor taking the HW::item to update
-     * and the name handle of the interface whose state is to change
-     */
-    state_change_cmd(HW::item<admin_state_t>& s, const HW::item<handle_t>& h);
-
-    /**
-     * Issue the command to VPP/HW
-     */
-    rc_t issue(connection& con);
-    /**
-     * convert to string format for debug purposes
-     */
-    std::string to_string() const;
-
-    /**
-     * Comparison operator - only used for UT
-     */
-    bool operator==(const state_change_cmd& i) const;
-
-  private:
-    /**
-     * the handle of the interface to update
-     */
-    const HW::item<handle_t>& m_hdl;
-  };
-
-  /**
-   * A command class that binds an interface to an L3 table
-   */
-  class set_table_cmd : public rpc_cmd<HW::item<route::table_id_t>,
-                                       rc_t,
-                                       vapi::Sw_interface_set_table>
-  {
-  public:
-    /**
-     * Constructor taking the HW::item to update
-     * and the name handle of the interface whose table is to change
-     */
-    set_table_cmd(HW::item<route::table_id_t>& item,
-                  const l3_proto_t& proto,
-                  const HW::item<handle_t>& h);
-
-    /**
-     * Issue the command to VPP/HW
-     */
-    rc_t issue(connection& con);
-
-    /**
-     * convert to string format for debug purposes
-     */
-    std::string to_string() const;
-
-    /**
-     * Comparison operator - only used for UT
-     */
-    bool operator==(const set_table_cmd& i) const;
-
-  private:
-    /**
-     * the handle of the interface to update
-     */
-    const HW::item<handle_t>& m_hdl;
-
-    /**
-     * The L3 protocol of the table
-     */
-    l3_proto_t m_proto;
-  };
-
-  /**
-   * A command class that binds an interface to an L3 table
-   */
-  class set_mac_cmd : public rpc_cmd<HW::item<l2_address_t>,
-                                     rc_t,
-                                     vapi::Sw_interface_set_mac_address>
-  {
-  public:
-    /**
-     * Constructor taking the HW::item to update
-     * and the handle of the interface
-     */
-    set_mac_cmd(HW::item<l2_address_t>& item, const HW::item<handle_t>& h);
-
-    /**
-     * Issue the command to VPP/HW
-     */
-    rc_t issue(connection& con);
-
-    /**
-     * convert to string format for debug purposes
-     */
-    std::string to_string() const;
-
-    /**
-     * Comparison operator - only used for UT
-     */
-    bool operator==(const set_mac_cmd& i) const;
-
-  private:
-    /**
-     * the handle of the interface to update
-     */
-    const HW::item<handle_t>& m_hdl;
-  };
-
-  /**
-   * Forward declaration of the Event command
-   */
-  class events_cmd;
-
   /**
    * A class that listens to interface Events
    */
@@ -633,7 +385,7 @@ public:
      * Virtual function called on the listener when the command has data
      * ready to process
      */
-    virtual void handle_interface_event(events_cmd* cmd) = 0;
+    virtual void handle_interface_event(interface_cmds::events_cmd* cmd) = 0;
 
     /**
      * Return the HW::item representing the status
@@ -647,55 +399,6 @@ public:
     HW::item<bool> m_status;
   };
 
-  /**
-   * A command class represents our desire to recieve interface events
-   */
-  class events_cmd
-    : public event_cmd<vapi::Want_interface_events, vapi::Sw_interface_event>
-  {
-  public:
-    /**
-     * Constructor taking the listner to notify
-     */
-    events_cmd(event_listener& el);
-
-    /**
-     * Issue the command to VPP/HW
-     */
-    rc_t issue(connection& con);
-
-    /**
-     * Retires the command - unsubscribe from the events.
-     */
-    void retire(connection& con);
-
-    /**
-     * convert to string format for debug purposes
-     */
-    std::string to_string() const;
-
-    /**
-     * Comparison operator - only used for UT
-     */
-    bool operator==(const events_cmd& i) const;
-
-    /**
-     * Called when it's time to poke the listeners
-     */
-    void notify();
-
-  private:
-    /**
-     * The listeners to notify when data/events arrive
-     */
-    event_listener& m_listener;
-  };
-
-  /**
-   * Forward declaration of the stat command
-   */
-  class stats_cmd;
-
   /**
    * A class that listens to interface Stats
    */
@@ -711,7 +414,8 @@ public:
      * Virtual function called on the listener when the command has data
      * ready to process
      */
-    virtual void handle_interface_stat(stats_cmd* cmd) = 0;
+    virtual void handle_interface_stat(
+      interface_cmds::stats_enable_cmd* cmd) = 0;
 
     /**
      * Return the HW::item representing the status
@@ -726,93 +430,14 @@ public:
   };
 
   /**
-   * A command class represents our desire to recieve interface stats
-   */
-  class stats_cmd : public event_cmd<vapi::Want_per_interface_combined_stats,
-                                     vapi::Vnet_per_interface_combined_counters>
-  {
-  public:
-    /**
-     * Constructor taking the listner to notify
-     */
-    stats_cmd(stat_listener& el, const std::vector<handle_t>& interfaces);
-
-    /**
-     * Issue the command to VPP/HW
-     */
-    rc_t issue(connection& con);
-
-    /**
-     * Retires the command - unsubscribe from the stats.
-     */
-    void retire(connection& con);
-
-    /**
-     * convert to string format for debug purposes
-     */
-    std::string to_string() const;
-
-    /**
-     * Comparison operator - only used for UT
-     */
-    bool operator==(const stats_cmd& i) const;
-
-    /**
-     * Called when it's time to poke the listeners
-     */
-    void notify();
-
-  private:
-    /**
-     * The listeners to notify when data/stats arrive
-     */
-    stat_listener& m_listener;
-
-    std::vector<handle_t> m_swifindex;
-  };
-
-  /**
-   * A cmd class that Dumps all the Vpp interfaces
-   */
-  class dump_cmd : public VOM::dump_cmd<vapi::Sw_interface_dump>
-  {
-  public:
-    /**
-     * Default Constructor
-     */
-    dump_cmd();
-
-    /**
-     * Issue the command to VPP/HW
-     */
-    rc_t issue(connection& con);
-    /**
-     * convert to string format for debug purposes
-     */
-    std::string to_string() const;
-
-    /**
-     * Comparison operator - only used for UT
-     */
-    bool operator==(const dump_cmd& i) const;
-  };
-
-  /**
-   * The the singular instance of the interface in the object_base-Model
-   */
-  static std::shared_ptr<interface> find(const interface& temp);
-
-  /**
-   * The the singular instance of the interface in the object_base-Model
-   * by handle
+   * The the singular instance of the interface in the DB by handle
    */
   static std::shared_ptr<interface> find(const handle_t& h);
 
   /**
-   * The the singular instance of the interface in the object_base-Model
-   * by name
+   * The the singular instance of the interface in the DB by key
    */
-  static std::shared_ptr<interface> find(const std::string& s);
+  static std::shared_ptr<interface> find(const key_t& k);
 
   /**
    * Dump all interfaces into the stream provided
@@ -820,20 +445,17 @@ public:
   static void dump(std::ostream& os);
 
   /**
-   * Factory method to construct a new interface from the VPP record
+   * Enable stats for this interface
    */
-  static std::unique_ptr<interface> new_interface(
-    const vapi_payload_sw_interface_details& vd);
+  void enable_stats(stat_listener& el);
 
 protected:
   /**
-   * Construct an interface object with a handle and a HW address
+   * Set the handle of an interface object. Only called by the interface
+   * factory during the populate
    */
-  interface(const handle_t& handle,
-            const l2_address_t& l2_address,
-            const std::string& name,
-            type_t type,
-            admin_state_t state);
+  void set(const handle_t& handle);
+  friend class interface_factory;
 
   /**
    * The SW interface handle VPP has asigned to the interface
@@ -870,12 +492,12 @@ protected:
   /**
    * A map of all interfaces key against the interface's name
    */
-  static singular_db<const std::string, interface> m_db;
+  static singular_db<key_t, interface> m_db;
 
   /**
    * Add an interface to the DB keyed on handle
    */
-  static void add(const std::string& name, const HW::item<handle_t>& item);
+  static void add(const key_t& name, const HW::item<handle_t>& item);
 
   /**
    * remove an interface from the DB keyed on handle
@@ -915,11 +537,21 @@ private:
 
   static event_handler m_evh;
 
+  /**
+   * enable the interface stats in the singular instance
+   */
+  void enable_stats_i(stat_listener& el);
+
   /**
    * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
    */
   void update(const interface& obj);
 
+  /*
+   * return the interface's handle in the singular instance
+   */
+  const handle_t& handle_i() const;
+
   /*
    * It's the OM class that calls singular()
    */
@@ -928,7 +560,7 @@ private:
   /**
    * It's the singular_db class that calls replay()
    */
-  friend class singular_db<const std::string, interface>;
+  friend class singular_db<key_t, interface>;
 
   /**
    * The interfaces name
@@ -943,9 +575,14 @@ private:
 
   /**
    * shared pointer to the routeDoamin the interface is in.
-   * NULL is not mapped  - i.e. in eht default table
+   * NULL is not mapped  - i.e. in the default table
    */
-  const std::shared_ptr<route_domain> m_rd;
+  std::shared_ptr<route_domain> m_rd;
+
+  /**
+   * shared pointer to the stats object for this interface.
+   */
+  std::shared_ptr<interface_cmds::stats_enable_cmd> m_stats;
 
   /**
    * The state of the interface
@@ -967,6 +604,11 @@ private:
    */
   oper_state_t m_oper;
 
+  /**
+   * tag of the interface
+   */
+  std::string m_tag;
+
   /**
    * A map of all interfaces keyed against VPP's handle
    */