X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=extras%2Fvom%2Fvom%2Finterface.hpp;h=05642f0cdf723a2ae6a0ed546d77c509b8a678d2;hb=d8cf40b8bb5e00eb8b668f7d762e8eb5267a228a;hp=f6708b301760f7e23c499e780a20da45a65e9779;hpb=164e5f8c63652028ecb9c3570e1ea8618b163071;p=vpp.git diff --git a/extras/vom/vom/interface.hpp b/extras/vom/vom/interface.hpp index f6708b30176..05642f0cdf7 100644 --- a/extras/vom/vom/interface.hpp +++ b/extras/vom/vom/interface.hpp @@ -31,9 +31,9 @@ namespace VOM { * Forward declaration of the stats and events command */ namespace interface_cmds { -class stats_enable_cmd; class events_cmd; }; +class stat_reader; /** * A representation of an interface in VPP @@ -94,10 +94,11 @@ public: * Local interface type (specific to VPP) */ const static type_t LOCAL; + /** - * TAP interface type + * TAPv2 interface type */ - const static type_t TAP; + const static type_t TAPV2; /** * vhost-user interface type @@ -109,6 +110,16 @@ public: */ const static type_t BOND; + /** + * pipe-parent type + */ + const static type_t PIPE; + + /** + * pipe-end type + */ + const static type_t PIPE_END; + /** * Convert VPP's name of the interface to a type */ @@ -173,6 +184,22 @@ public: oper_state_t(int v, const std::string& s); }; + /** + * stats_t: + */ + struct stats_t + { + counter_t m_rx; + counter_t m_tx; + counter_t m_rx_unicast; + counter_t m_tx_unicast; + counter_t m_rx_multicast; + counter_t m_tx_multicast; + counter_t m_rx_broadcast; + counter_t m_tx_broadcast; + counter_t m_drop; + }; + /** * Construct a new object matching the desried state */ @@ -257,6 +284,11 @@ public: */ void set(const std::string& tag); + /** + * Get the interface stats + */ + const stats_t& get_stats(void) const; + /** * Comparison operator - only used for UT */ @@ -266,11 +298,11 @@ public: * A base class for interface Create commands */ template - class create_cmd : public rpc_cmd, HW::item, MSG> + class create_cmd : public rpc_cmd, MSG> { public: create_cmd(HW::item& item, const std::string& name) - : rpc_cmd, HW::item, MSG>(item) + : rpc_cmd, MSG>(item) , m_name(name) { } @@ -293,7 +325,7 @@ public: */ void succeeded() { - rpc_cmd, HW::item, MSG>::succeeded(); + rpc_cmd, MSG>::succeeded(); interface::add(m_name, this->item()); } @@ -307,7 +339,8 @@ public: int sw_if_index = reply.get_response().get_payload().sw_if_index; int retval = reply.get_response().get_payload().retval; - VOM_LOG(log_level_t::DEBUG) << this->to_string() << " " << retval; + VOM_LOG(log_level_t::DEBUG) << this->to_string() << " res:" << retval + << " sw-if-index:" << sw_if_index; rc_t rc = rc_t::from_vpp_retval(retval); handle_t handle = handle_t::INVALID; @@ -316,9 +349,7 @@ public: handle = sw_if_index; } - HW::item res(handle, rc); - - this->fulfill(res); + this->fulfill(HW::item(handle, rc)); return (VAPI_OK); } @@ -334,17 +365,17 @@ public: * Base class for intterface Delete commands */ template - class delete_cmd : public rpc_cmd, HW::item, MSG> + class delete_cmd : public rpc_cmd, MSG> { public: delete_cmd(HW::item& item, const std::string& name) - : rpc_cmd, HW::item, MSG>(item) + : rpc_cmd, MSG>(item) , m_name(name) { } delete_cmd(HW::item& item) - : rpc_cmd, HW::item, MSG>(item) + : rpc_cmd, MSG>(item) , m_name() { } @@ -379,6 +410,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 */ @@ -394,7 +437,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 @@ -419,12 +462,13 @@ public: */ stat_listener(); + virtual ~stat_listener() = default; + /** * Virtual function called on the listener when the command has data * ready to process */ - virtual void handle_interface_stat( - interface_cmds::stats_enable_cmd* cmd) = 0; + virtual void handle_interface_stat(const interface&) = 0; /** * Return the HW::item representing the status @@ -456,9 +500,24 @@ public: /** * Enable stats for this interface */ - void enable_stats(stat_listener& el, + void enable_stats(stat_listener* el, const stats_type_t& st = stats_type_t::NORMAL); + /** + * Disable stats for this interface + */ + void disable_stats(); + + /** + * 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 @@ -466,7 +525,7 @@ protected: */ void set(const handle_t& handle); friend class interface_factory; - + friend class pipe; /** * The SW interface handle VPP has asigned to the interface */ @@ -547,10 +606,30 @@ private: static event_handler m_evh; + /** + * friend with stat_reader + */ + friend stat_reader; + + /** + * publish stats + */ + void publish_stats(); + + /** + * Set the interface stat + */ + void set(const counter_t& count, const std::string& stat_type); + /** * enable the interface stats in the singular instance */ - void enable_stats_i(stat_listener& el, const stats_type_t& st); + void enable_stats_i(stat_listener* el, const stats_type_t& st); + + /** + * disable the interface stats in the singular instance + */ + void disable_stats_i(); /** * Commit the acculmulated changes into VPP. i.e. to a 'HW" write. @@ -589,11 +668,6 @@ private: */ std::shared_ptr m_rd; - /** - * shared pointer to the stats object for this interface. - */ - std::shared_ptr m_stats; - /** * The state of the interface */ @@ -614,6 +688,16 @@ private: */ HW::item m_stats_type; + /** + * Interface stats + */ + stats_t m_stats; + + /** + * reference to stat listener + */ + stat_listener* m_listener; + /** * Operational state of the interface */ @@ -647,7 +731,14 @@ private: */ template friend class delete_cmd; + + static std::shared_ptr m_events_cmd; }; + +/** + * stream insertion operator for interface stats + */ +std::ostream& operator<<(std::ostream& os, const interface::stats_t& stats); }; /* * fd.io coding-style-patch-verification: ON