VOM: bond: Add support for LACP
[vpp.git] / src / vpp-api / vom / interface.hpp
index 181e76d..0099bde 100644 (file)
@@ -31,7 +31,7 @@ namespace VOM {
  * Forward declaration of the stats and events command
  */
 namespace interface_cmds {
-class stats_cmd;
+class stats_enable_cmd;
 class events_cmd;
 };
 
@@ -44,7 +44,7 @@ public:
   /**
    * The key for interface's key
    */
-  typedef std::string key_type;
+  typedef std::string key_t;
 
   /**
    * The iterator type
@@ -90,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
      */
@@ -157,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
@@ -165,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
    */
@@ -207,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
    */
@@ -224,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
    */
@@ -330,7 +359,7 @@ public:
     void succeeded() {}
 
     /**
-     * add the created interface to the DB
+     * remove the deleted interface from the DB
      */
     void remove_interface() { interface::remove(this->item()); }
 
@@ -385,7 +414,8 @@ public:
      * Virtual function called on the listener when the command has data
      * ready to process
      */
-    virtual void handle_interface_stat(interface_cmds::stats_cmd* cmd) = 0;
+    virtual void handle_interface_stat(
+      interface_cmds::stats_enable_cmd* cmd) = 0;
 
     /**
      * Return the HW::item representing the status
@@ -400,36 +430,31 @@ public:
   };
 
   /**
-   * 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
    */
   static void dump(std::ostream& os);
 
+  /**
+   * Enable stats for this interface
+   */
+  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;
 
   /**
@@ -467,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
@@ -512,6 +537,11 @@ 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.
    */
@@ -530,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
@@ -549,6 +579,11 @@ private:
    */
   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
    */
@@ -569,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
    */