GBP V2
[vpp.git] / src / vpp-api / vom / interface.cpp
index f323727..6faf349 100644 (file)
@@ -22,6 +22,7 @@
 #include "vom/l3_binding_cmds.hpp"
 #include "vom/logger.hpp"
 #include "vom/prefix.hpp"
+#include "vom/singular_db_funcs.hpp"
 
 namespace VOM {
 /**
@@ -49,6 +50,7 @@ interface::interface(const std::string& name,
   , m_state(itf_state)
   , m_table_id(route::DEFAULT_TABLE)
   , m_l2_address(l2_address_t::ZERO, rc_t::UNSET)
+  , m_stats_type(stats_type_t::NORMAL)
   , m_oper(oper_state_t::DOWN)
   , m_tag(tag)
 {
@@ -66,6 +68,7 @@ interface::interface(const std::string& name,
   , m_state(itf_state)
   , m_table_id(m_rd->table_id())
   , m_l2_address(l2_address_t::ZERO, rc_t::UNSET)
+  , m_stats_type(stats_type_t::NORMAL)
   , m_oper(oper_state_t::DOWN)
   , m_tag(tag)
 {
@@ -79,6 +82,7 @@ interface::interface(const interface& o)
   , m_state(o.m_state)
   , m_table_id(o.m_table_id)
   , m_l2_address(o.m_l2_address)
+  , m_stats_type(o.m_stats_type)
   , m_oper(o.m_oper)
   , m_tag(o.m_tag)
 {
@@ -145,13 +149,13 @@ interface::l2_address() const
 interface::const_iterator_t
 interface::cbegin()
 {
-  return m_db.cbegin();
+  return m_db.begin();
 }
 
 interface::const_iterator_t
 interface::cend()
 {
-  return m_db.cend();
+  return m_db.end();
 }
 
 void
@@ -166,6 +170,10 @@ interface::sweep()
   }
 
   if (m_stats) {
+    if (stats_type_t::DETAILED == m_stats_type) {
+      HW::enqueue(new interface_cmds::collect_detail_stats_change_cmd(
+        m_stats_type, handle_i(), false));
+    }
     HW::enqueue(new interface_cmds::stats_disable_cmd(m_hdl.data()));
     m_stats.reset();
   }
@@ -195,6 +203,18 @@ interface::replay()
     HW::enqueue(new interface_cmds::state_change_cmd(m_state, m_hdl));
   }
 
+  if (m_stats) {
+    if (stats_type_t::DETAILED == m_stats_type) {
+      m_stats_type.set(rc_t::NOOP);
+      HW::enqueue(new interface_cmds::collect_detail_stats_change_cmd(
+        m_stats_type, handle_i(), true));
+    }
+    stat_listener& listener = m_stats->listener();
+    listener.status().set(rc_t::NOOP);
+    m_stats.reset(new interface_cmds::stats_enable_cmd(listener, handle_i()));
+    HW::enqueue(m_stats);
+  }
+
   if (m_table_id && (m_table_id.data() != route::DEFAULT_TABLE)) {
     HW::enqueue(
       new interface_cmds::set_table_cmd(m_table_id, l3_proto_t::IPV4, m_hdl));
@@ -255,9 +275,7 @@ interface::key() const
 std::queue<cmd*>&
 interface::mk_create_cmd(std::queue<cmd*>& q)
 {
-  if (type_t::LOOPBACK == m_type) {
-    q.push(new interface_cmds::loopback_create_cmd(m_hdl, m_name));
-  } else if (type_t::BVI == m_type) {
+  if ((type_t::LOOPBACK == m_type) || (type_t::BVI == m_type)) {
     q.push(new interface_cmds::loopback_create_cmd(m_hdl, m_name));
     q.push(new interface_cmds::set_tag(m_hdl, m_name));
     /*
@@ -403,9 +421,14 @@ interface::set(const std::string& tag)
 }
 
 void
-interface::enable_stats_i(interface::stat_listener& el)
+interface::enable_stats_i(interface::stat_listener& el, const stats_type_t& st)
 {
   if (!m_stats) {
+    if (stats_type_t::DETAILED == st) {
+      m_stats_type = st;
+      HW::enqueue(new interface_cmds::collect_detail_stats_change_cmd(
+        m_stats_type, handle_i(), true));
+    }
     m_stats.reset(new interface_cmds::stats_enable_cmd(el, handle_i()));
     HW::enqueue(m_stats);
     HW::write();
@@ -413,9 +436,9 @@ interface::enable_stats_i(interface::stat_listener& el)
 }
 
 void
-interface::enable_stats(interface::stat_listener& el)
+interface::enable_stats(interface::stat_listener& el, const stats_type_t& st)
 {
-  singular()->enable_stats_i(el);
+  singular()->enable_stats_i(el, st);
 }
 
 std::shared_ptr<interface>
@@ -461,7 +484,7 @@ interface::remove(const HW::item<handle_t>& item)
 void
 interface::dump(std::ostream& os)
 {
-  m_db.dump(os);
+  db_dump(m_db, os);
 }
 
 void
@@ -491,8 +514,12 @@ interface::event_handler::handle_populate(const client_db::key_t& key)
   HW::write();
 
   for (auto& itf_record : *cmd) {
-    std::shared_ptr<interface> itf =
-      interface_factory::new_interface(itf_record.get_payload());
+    auto payload = itf_record.get_payload();
+    VOM_LOG(log_level_t::DEBUG) << "dump: [" << payload.sw_if_index
+                                << " name:" << (char*)payload.interface_name
+                                << " tag:" << (char*)payload.tag << "]";
+
+    std::shared_ptr<interface> itf = interface_factory::new_interface(payload);
 
     if (itf && interface::type_t::LOCAL != itf->type()) {
       VOM_LOG(log_level_t::DEBUG) << "dump: " << itf->to_string();
@@ -602,7 +629,7 @@ interface::event_handler::order() const
 void
 interface::event_handler::show(std::ostream& os)
 {
-  m_db.dump(os);
+  db_dump(m_db, os);
 }
 
 } // namespace VOM