From: Neale Ranns Date: Wed, 5 Dec 2018 12:34:27 +0000 (-0800) Subject: VOM: interface event struct X-Git-Tag: v19.04-rc0~234 X-Git-Url: https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commitdiff_plain;h=7e9affb696fcfd8f22cdce0caf46b1e2f25c5799 VOM: interface event struct Change-Id: If133829ba4db2da1c9c20bfbbdfc6df6276efa10 Signed-off-by: Neale Ranns --- diff --git a/extras/vom/vom/arp_proxy_binding_cmds.hpp b/extras/vom/vom/arp_proxy_binding_cmds.hpp index cafc1420f87..9389896c009 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 +#include namespace VOM { namespace arp_proxy_binding_cmds { diff --git a/extras/vom/vom/interface.cpp b/extras/vom/vom/interface.cpp index 371682333c7..c1894c2fbdf 100644 --- a/extras/vom/vom/interface.cpp +++ b/extras/vom/vom/interface.cpp @@ -38,6 +38,11 @@ std::map> interface::m_hdl_db; interface::event_handler interface::m_evh; +/** + * the event enable command. + */ +std::shared_ptr 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(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 1096bcb332c..42dfa67e03d 100644 --- a/extras/vom/vom/interface.hpp +++ b/extras/vom/vom/interface.hpp @@ -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 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 friend class delete_cmd; + + static std::shared_ptr m_events_cmd; }; }; /* diff --git a/extras/vom/vom/interface_cmds.cpp b/extras/vom/vom/interface_cmds.cpp index 9e2772584c0..c4fd6613a0e 100644 --- a/extras/vom/vom/interface_cmds.cpp +++ b/extras/vom/vom/interface_cmds.cpp @@ -441,7 +441,30 @@ events_cmd::retire(connection& con) void events_cmd::notify() { - m_listener.handle_interface_event(this); + std::lock_guard lg(*this); + std::vector events; + + for (auto& msg : *this) { + auto& payload = msg.get_payload(); + + handle_t handle(payload.sw_if_index); + std::shared_ptr 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 fdd00520404..436b0c72130 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 +#include namespace VOM { namespace ip_unnumbered_cmds { diff --git a/extras/vom/vom/route_domain.hpp b/extras/vom/vom/route_domain.hpp index 19a3c18dddc..96e46ce575b 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 - 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 1996f4b3fbe..ccb41abbd2d 100644 --- a/extras/vom/vom/rpc_cmd.hpp +++ b/extras/vom/vom/rpc_cmd.hpp @@ -18,6 +18,8 @@ #include +#include + #include "vom/cmd.hpp" #include "vom/logger.hpp"