VOM: interface event struct
[vpp.git] / extras / vom / vom / interface.hpp
index f6708b3..42dfa67 100644 (file)
@@ -94,10 +94,11 @@ public:
      * Local interface type (specific to VPP)
      */
     const static type_t LOCAL;
+
     /**
-     * TAP interface type
+     * TAPv2 interface type
      */
-    const static type_t TAP;
+    const static type_t TAPV2;
 
     /**
      * vhost-user interface type
@@ -109,6 +110,16 @@ public:
      */
     const static type_t BOND;
 
+    /**
+     * pipe-parent type
+     */
+    const static type_t PIPE;
+
+    /**
+     * pipe-end type
+     */
+    const static type_t PIPE_END;
+
     /**
      * Convert VPP's name of the interface to a type
      */
@@ -266,11 +277,11 @@ public:
    * A base class for interface Create commands
    */
   template <typename MSG>
-  class create_cmd : public rpc_cmd<HW::item<handle_t>, HW::item<handle_t>, MSG>
+  class create_cmd : public rpc_cmd<HW::item<handle_t>, MSG>
   {
   public:
     create_cmd(HW::item<handle_t>& item, const std::string& name)
-      : rpc_cmd<HW::item<handle_t>, HW::item<handle_t>, MSG>(item)
+      : rpc_cmd<HW::item<handle_t>, MSG>(item)
       , m_name(name)
     {
     }
@@ -293,7 +304,7 @@ public:
      */
     void succeeded()
     {
-      rpc_cmd<HW::item<handle_t>, HW::item<handle_t>, MSG>::succeeded();
+      rpc_cmd<HW::item<handle_t>, MSG>::succeeded();
       interface::add(m_name, this->item());
     }
 
@@ -307,7 +318,8 @@ public:
       int sw_if_index = reply.get_response().get_payload().sw_if_index;
       int retval = reply.get_response().get_payload().retval;
 
-      VOM_LOG(log_level_t::DEBUG) << this->to_string() << " " << retval;
+      VOM_LOG(log_level_t::DEBUG) << this->to_string() << " res:" << retval
+                                  << " sw-if-index:" << sw_if_index;
 
       rc_t rc = rc_t::from_vpp_retval(retval);
       handle_t handle = handle_t::INVALID;
@@ -316,9 +328,7 @@ public:
         handle = sw_if_index;
       }
 
-      HW::item<handle_t> res(handle, rc);
-
-      this->fulfill(res);
+      this->fulfill(HW::item<handle_t>(handle, rc));
 
       return (VAPI_OK);
     }
@@ -334,17 +344,17 @@ public:
    * Base class for intterface Delete commands
    */
   template <typename MSG>
-  class delete_cmd : public rpc_cmd<HW::item<handle_t>, HW::item<handle_t>, MSG>
+  class delete_cmd : public rpc_cmd<HW::item<handle_t>, MSG>
   {
   public:
     delete_cmd(HW::item<handle_t>& item, const std::string& name)
-      : rpc_cmd<HW::item<handle_t>, HW::item<handle_t>, MSG>(item)
+      : rpc_cmd<HW::item<handle_t>, MSG>(item)
       , m_name(name)
     {
     }
 
     delete_cmd(HW::item<handle_t>& item)
-      : rpc_cmd<HW::item<handle_t>, HW::item<handle_t>, MSG>(item)
+      : rpc_cmd<HW::item<handle_t>, MSG>(item)
       , m_name()
     {
     }
@@ -379,6 +389,18 @@ public:
     const std::string m_name;
   };
 
+  struct event
+  {
+    event(const interface& itf, const interface::oper_state_t& state)
+      : itf(itf)
+      , state(state)
+    {
+    }
+
+    const interface& itf;
+    interface::oper_state_t state;
+  };
+
   /**
    * A class that listens to interface Events
    */
@@ -394,7 +416,7 @@ public:
      * Virtual function called on the listener when the command has data
      * ready to process
      */
-    virtual void handle_interface_event(interface_cmds::events_cmd* cmd) = 0;
+    virtual void handle_interface_event(std::vector<event> es) = 0;
 
     /**
      * Return the HW::item representing the status
@@ -459,6 +481,16 @@ public:
   void enable_stats(stat_listener& el,
                     const stats_type_t& st = stats_type_t::NORMAL);
 
+  /**
+   * Enable the reception of events of all interfaces
+   */
+  static void enable_events(interface::event_listener& el);
+
+  /**
+   * disable the reception of events of all interfaces
+   */
+  static void disable_events();
+
 protected:
   /**
    * Set the handle of an interface object. Only called by the interface
@@ -466,6 +498,7 @@ protected:
    */
   void set(const handle_t& handle);
   friend class interface_factory;
+  friend class pipe;
 
   /**
    * The SW interface handle VPP has asigned to the interface
@@ -647,6 +680,8 @@ private:
    */
   template <typename MSG>
   friend class delete_cmd;
+
+  static std::shared_ptr<interface_cmds::events_cmd> m_events_cmd;
 };
 };
 /*