VOM: interface event struct
[vpp.git] / extras / vom / vom / interface_cmds.cpp
index e78ed46..c4fd661 100644 (file)
@@ -37,7 +37,7 @@ loopback_create_cmd::issue(connection& con)
 
   VAPI_CALL(req.execute());
 
-  m_hw_item = wait();
+  wait();
 
   if (m_hw_item.rc() == rc_t::OK) {
     insert_interface();
@@ -74,7 +74,7 @@ af_packet_create_cmd::issue(connection& con)
 
   VAPI_CALL(req.execute());
 
-  m_hw_item = wait();
+  wait();
 
   if (m_hw_item.rc() == rc_t::OK) {
     insert_interface();
@@ -120,7 +120,7 @@ vhost_create_cmd::issue(connection& con)
 
   VAPI_CALL(req.execute());
 
-  m_hw_item = wait();
+  wait();
 
   if (m_hw_item.rc() == rc_t::OK) {
     insert_interface();
@@ -257,9 +257,7 @@ state_change_cmd::issue(connection& con)
 
   VAPI_CALL(req.execute());
 
-  m_hw_item.set(wait());
-
-  return rc_t::OK;
+  return (wait());
 }
 
 std::string
@@ -299,9 +297,7 @@ set_table_cmd::issue(connection& con)
 
   VAPI_CALL(req.execute());
 
-  m_hw_item.set(wait());
-
-  return (rc_t::OK);
+  return (wait());
 }
 
 std::string
@@ -338,9 +334,7 @@ set_mac_cmd::issue(connection& con)
 
   VAPI_CALL(req.execute());
 
-  m_hw_item.set(wait());
-
-  return (rc_t::OK);
+  return (wait());
 }
 
 std::string
@@ -380,9 +374,7 @@ collect_detail_stats_change_cmd::issue(connection& con)
 
   VAPI_CALL(req.execute());
 
-  m_hw_item.set(wait());
-
-  return (rc_t::OK);
+  return (wait());
 }
 
 std::string
@@ -449,7 +441,30 @@ events_cmd::retire(connection& con)
 void
 events_cmd::notify()
 {
-  m_listener.handle_interface_event(this);
+  std::lock_guard<interface_cmds::events_cmd> lg(*this);
+  std::vector<interface::event> events;
+
+  for (auto& msg : *this) {
+    auto& payload = msg.get_payload();
+
+    handle_t handle(payload.sw_if_index);
+    std::shared_ptr<interface> sp = interface::find(handle);
+
+    if (sp) {
+      interface::oper_state_t oper_state =
+        interface::oper_state_t::from_int(payload.link_up_down);
+
+      VOM_LOG(log_level_t::DEBUG) << "Interface Event: " << sp->to_string()
+                                  << " state: " << oper_state.to_string();
+
+      sp->set(oper_state);
+      events.push_back({ *sp, oper_state });
+    }
+  }
+
+  flush();
+
+  m_listener.handle_interface_event(events);
 }
 
 std::string
@@ -691,9 +706,7 @@ set_tag::issue(connection& con)
 
   VAPI_CALL(req.execute());
 
-  wait();
-
-  return rc_t::OK;
+  return (wait());
 }
 std::string
 set_tag::to_string() const