VOM: stats: Associate stat obj to interface 10/9510/2
authorMohsin Kazmi <sykazmi@cisco.com>
Mon, 20 Nov 2017 09:23:47 +0000 (10:23 +0100)
committerNeale Ranns <nranns@cisco.com>
Wed, 22 Nov 2017 11:20:45 +0000 (11:20 +0000)
Change-Id: Id8b159dd72b92798538a32fe570fb0038d742ef2
Signed-off-by: Mohsin Kazmi <sykazmi@cisco.com>
src/vpp-api/vom/interface.cpp
src/vpp-api/vom/interface.hpp
src/vpp-api/vom/interface_cmds.cpp
src/vpp-api/vom/interface_cmds.hpp
src/vpp-api/vom/rpc_cmd.hpp

index 8f1023d..39ca074 100644 (file)
@@ -163,11 +163,15 @@ interface::sweep()
       new interface_cmds::set_table_cmd(m_table_id, l3_proto_t::IPV6, m_hdl));
   }
 
+  if (m_stats)
+    HW::dequeue(m_stats);
+
   // If the interface is up, bring it down
   if (m_state && interface::admin_state_t::UP == m_state.data()) {
     m_state.data() = interface::admin_state_t::DOWN;
     HW::enqueue(new interface_cmds::state_change_cmd(m_state, m_hdl));
   }
+
   if (m_hdl) {
     std::queue<cmd*> cmds;
     HW::enqueue(mk_delete_cmd(cmds));
@@ -356,6 +360,20 @@ interface::set(const oper_state_t& state)
   m_oper = state;
 }
 
+void
+interface::enable_stats_i(interface::stat_listener& el)
+{
+  m_stats.reset(new interface_cmds::stats_cmd(el, handle_i()));
+  HW::enqueue(m_stats);
+  HW::write();
+}
+
+void
+interface::enable_stats(interface::stat_listener& el)
+{
+  singular()->enable_stats_i(el);
+}
+
 std::shared_ptr<interface>
 interface::singular_i() const
 {
index 181e76d..76ecf8a 100644 (file)
@@ -421,6 +421,11 @@ public:
    */
   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
@@ -512,6 +517,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.
    */
@@ -549,6 +559,11 @@ private:
    */
   std::shared_ptr<route_domain> m_rd;
 
+  /**
+   * shared pointer to the stats object for this interface.
+   */
+  std::shared_ptr<interface_cmds::stats_cmd> m_stats;
+
   /**
    * The state of the interface
    */
index 4f6286f..750ad1f 100644 (file)
@@ -401,11 +401,10 @@ events_cmd::to_string() const
 /**
  * Interface statistics
  */
-stats_cmd::stats_cmd(interface::stat_listener& el,
-                     const std::vector<handle_t>& interfaces)
+stats_cmd::stats_cmd(interface::stat_listener& el, const handle_t& handle)
   : event_cmd(el.status())
   , m_listener(el)
-  , m_swifindex(interfaces)
+  , m_swifindex(handle)
 {
 }
 
@@ -419,29 +418,21 @@ rc_t
 stats_cmd::issue(connection& con)
 {
   /*
* First set the clal back to handle the interface stats
- */
  * First set the call back to handle the interface stats
  */
   m_reg.reset(new reg_t(con.ctx(), std::ref(*(static_cast<event_cmd*>(this)))));
-  // m_reg->execute();
 
   /*
- * then send the request to enable them
- */
-  msg_t req(con.ctx(), m_swifindex.size(),
-            std::ref(*(static_cast<rpc_cmd*>(this))));
+   * then send the request to enable them
+   */
+  msg_t req(con.ctx(), 1, std::ref(*(static_cast<rpc_cmd*>(this))));
 
   auto& payload = req.get_request().get_payload();
   payload.enable_disable = 1;
   payload.pid = getpid();
-  payload.num = m_swifindex.size();
-
-  auto it = m_swifindex.cbegin();
-  uint32_t ii = 0;
-  while (it != m_swifindex.cend()) {
-    payload.sw_ifs[ii] = it->value();
-    ++it;
-    ++ii;
-  }
+  payload.num = 1;
+
+  payload.sw_ifs[0] = m_swifindex.value();
 
   VAPI_CALL(req.execute());
 
@@ -453,6 +444,20 @@ stats_cmd::issue(connection& con)
 void
 stats_cmd::retire(connection& con)
 {
+  /*
+   * disable interface stats.
+   */
+  msg_t req(con.ctx(), 1, std::ref(*(static_cast<rpc_cmd*>(this))));
+
+  auto& payload = req.get_request().get_payload();
+  payload.enable_disable = 0;
+  payload.pid = getpid();
+  payload.num = 1;
+  payload.sw_ifs[0] = m_swifindex.value();
+
+  VAPI_CALL(req.execute());
+
+  wait();
 }
 
 void
index 4178be3..c86df92 100644 (file)
@@ -364,7 +364,7 @@ private:
   /**
    * The listeners to notify when data/events arrive
    */
-  interface::interface::event_listener& m_listener;
+  interface::event_listener& m_listener;
 };
 
 /**
@@ -377,8 +377,7 @@ public:
   /**
    * Constructor taking the listner to notify
    */
-  stats_cmd(interface::stat_listener& el,
-            const std::vector<handle_t>& interfaces);
+  stats_cmd(interface::stat_listener& el, const handle_t& handle);
 
   /**
    * Issue the command to VPP/HW
@@ -409,9 +408,9 @@ private:
   /**
    * The listeners to notify when data/stats arrive
    */
-  interface::interface::stat_listener& m_listener;
+  interface::stat_listener& m_listener;
 
-  std::vector<handle_t> m_swifindex;
+  handle_t m_swifindex;
 };
 
 /**
index 60dbd47..ae3c675 100644 (file)
@@ -71,7 +71,16 @@ public:
   /**
    * Fulfill the commands promise. Called from the RX thread
    */
-  void fulfill(const DATA& d) { m_promise.set_value(d); }
+  void fulfill(const DATA& d)
+  {
+    m_promise.set_value(d);
+
+    /*
+     * we reset the promise after setting the value to reuse it
+     * when we run the retire command from the same cmd object
+     */
+    m_promise = std::promise<DATA>();
+  }
 
   /**
    * Wait on the commands promise. i.e. block on the completion