VOM: interface event struct
Change-Id: If133829ba4db2da1c9c20bfbbdfc6df6276efa10
Signed-off-by: Neale Ranns <nranns@cisco.com>
diff --git a/extras/vom/vom/arp_proxy_binding_cmds.hpp b/extras/vom/vom/arp_proxy_binding_cmds.hpp
index cafc142..9389896 100644
--- a/extras/vom/vom/arp_proxy_binding_cmds.hpp
+++ b/extras/vom/vom/arp_proxy_binding_cmds.hpp
@@ -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 {
diff --git a/extras/vom/vom/interface.cpp b/extras/vom/vom/interface.cpp
index 3716823..c1894c2 100644
--- a/extras/vom/vom/interface.cpp
+++ b/extras/vom/vom/interface.cpp
@@ -39,6 +39,11 @@
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
*/
interface::interface(const std::string& name,
@@ -486,6 +491,20 @@
}
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)
{
/*
diff --git a/extras/vom/vom/interface.hpp b/extras/vom/vom/interface.hpp
index 1096bcb..42dfa67 100644
--- a/extras/vom/vom/interface.hpp
+++ b/extras/vom/vom/interface.hpp
@@ -389,6 +389,18 @@
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 @@
* 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 @@
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 @@
*/
template <typename MSG>
friend class delete_cmd;
+
+ static std::shared_ptr<interface_cmds::events_cmd> m_events_cmd;
};
};
/*
diff --git a/extras/vom/vom/interface_cmds.cpp b/extras/vom/vom/interface_cmds.cpp
index 9e27725..c4fd661 100644
--- a/extras/vom/vom/interface_cmds.cpp
+++ b/extras/vom/vom/interface_cmds.cpp
@@ -441,7 +441,30 @@
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
diff --git a/extras/vom/vom/ip_unnumbered_cmds.hpp b/extras/vom/vom/ip_unnumbered_cmds.hpp
index fdd0052..436b0c7 100644
--- a/extras/vom/vom/ip_unnumbered_cmds.hpp
+++ b/extras/vom/vom/ip_unnumbered_cmds.hpp
@@ -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 {
diff --git a/extras/vom/vom/route_domain.hpp b/extras/vom/vom/route_domain.hpp
index 19a3c18..96e46ce 100644
--- a/extras/vom/vom/route_domain.hpp
+++ b/extras/vom/vom/route_domain.hpp
@@ -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.
diff --git a/extras/vom/vom/rpc_cmd.hpp b/extras/vom/vom/rpc_cmd.hpp
index 1996f4b..ccb41ab 100644
--- a/extras/vom/vom/rpc_cmd.hpp
+++ b/extras/vom/vom/rpc_cmd.hpp
@@ -18,6 +18,8 @@
#include <future>
+#include <vapi/vapi.hpp>
+
#include "vom/cmd.hpp"
#include "vom/logger.hpp"