VOM: interface event struct 51/16351/2
authorNeale Ranns <nranns@cisco.com>
Wed, 5 Dec 2018 12:34:27 +0000 (04:34 -0800)
committerNeale Ranns <nranns@cisco.com>
Wed, 5 Dec 2018 14:30:02 +0000 (14:30 +0000)
Change-Id: If133829ba4db2da1c9c20bfbbdfc6df6276efa10
Signed-off-by: Neale Ranns <nranns@cisco.com>
extras/vom/vom/arp_proxy_binding_cmds.hpp
extras/vom/vom/interface.cpp
extras/vom/vom/interface.hpp
extras/vom/vom/interface_cmds.cpp
extras/vom/vom/ip_unnumbered_cmds.hpp
extras/vom/vom/route_domain.hpp
extras/vom/vom/rpc_cmd.hpp

index cafc142..9389896 100644 (file)
@@ -19,7 +19,7 @@
 #include "vom/arp_proxy_binding.hpp"
 #include "vom/dump_cmd.hpp"
 
-#include <vapi/vpe.api.vapi.hpp>
+#include <vapi/ip.api.vapi.hpp>
 
 namespace VOM {
 namespace arp_proxy_binding_cmds {
index 3716823..c1894c2 100644 (file)
@@ -38,6 +38,11 @@ std::map<handle_t, std::weak_ptr<interface>> interface::m_hdl_db;
 
 interface::event_handler interface::m_evh;
 
+/**
+ * the event enable command.
+ */
+std::shared_ptr<interface_cmds::events_cmd> interface::m_events_cmd;
+
 /**
  * Construct a new object matching the desried state
  */
@@ -485,6 +490,20 @@ interface::dump(std::ostream& os)
   db_dump(m_db, os);
 }
 
+void
+interface::enable_events(interface::event_listener& el)
+{
+  m_events_cmd = std::make_shared<interface_cmds::events_cmd>(el);
+  HW::enqueue(m_events_cmd);
+  HW::write();
+}
+
+void
+interface::disable_events()
+{
+  m_events_cmd.reset();
+}
+
 void
 interface::event_handler::handle_populate(const client_db::key_t& key)
 {
index 1096bcb..42dfa67 100644 (file)
@@ -389,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
    */
@@ -404,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
@@ -469,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
@@ -658,6 +680,8 @@ private:
    */
   template <typename MSG>
   friend class delete_cmd;
+
+  static std::shared_ptr<interface_cmds::events_cmd> m_events_cmd;
 };
 };
 /*
index 9e27725..c4fd661 100644 (file)
@@ -441,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
index fdd0052..436b0c7 100644 (file)
@@ -21,6 +21,7 @@
 #include "vom/rpc_cmd.hpp"
 
 #include <vapi/interface.api.vapi.hpp>
+#include <vapi/ip.api.vapi.hpp>
 
 namespace VOM {
 namespace ip_unnumbered_cmds {
index 19a3c18..96e46ce 100644 (file)
@@ -22,8 +22,6 @@
 #include "vom/prefix.hpp"
 #include "vom/singular_db.hpp"
 
-#include <vapi/ip.api.vapi.hpp>
-
 namespace VOM {
 /**
  * A route-domain is a VRF.
index 1996f4b..ccb41ab 100644 (file)
@@ -18,6 +18,8 @@
 
 #include <future>
 
+#include <vapi/vapi.hpp>
+
 #include "vom/cmd.hpp"
 #include "vom/logger.hpp"