From 234779fd32e747f4ac918f3c39e59618dde0f2d7 Mon Sep 17 00:00:00 2001 From: imarom Date: Thu, 3 Nov 2016 16:33:52 +0200 Subject: moved RX filter feature to port attr Signed-off-by: imarom --- src/stateless/rx/trex_stateless_rx_core.cpp | 61 +++++++++++++++++------- src/stateless/rx/trex_stateless_rx_core.h | 45 ++++++++++------- src/stateless/rx/trex_stateless_rx_port_mngr.cpp | 4 +- src/stateless/rx/trex_stateless_rx_port_mngr.h | 55 +++++++++++++++------ 4 files changed, 115 insertions(+), 50 deletions(-) (limited to 'src/stateless/rx') diff --git a/src/stateless/rx/trex_stateless_rx_core.cpp b/src/stateless/rx/trex_stateless_rx_core.cpp index ca39b8a0..ee9c64c4 100644 --- a/src/stateless/rx/trex_stateless_rx_core.cpp +++ b/src/stateless/rx/trex_stateless_rx_core.cpp @@ -121,10 +121,29 @@ bool CRxCoreStateless::periodic_check_for_cp_messages() { handle_cp_msg(msg); } + recalculate_next_state(); return true; } +void CRxCoreStateless::recalculate_next_state() { + if (m_state == STATE_QUIT) { + return; + } + + /* next state is determine by the question are there any ports with active features ? */ + m_state = (are_any_features_active() ? STATE_WORKING : STATE_IDLE); +} + +bool CRxCoreStateless::are_any_features_active() { + for (int i = 0; i < m_max_ports; i++) { + if (m_rx_port_mngr[i].has_features_set()) { + return true; + } + } + + return false; +} void CRxCoreStateless::idle_state_loop() { const int SHORT_DELAY_MS = 2; @@ -260,12 +279,12 @@ void CRxCoreStateless::try_rx_queues() { int CRxCoreStateless::process_all_pending_pkts(bool flush_rx) { - int total_pkts = 0; - for (int i = 0; i < m_max_ports; i++) { - total_pkts += m_rx_port_mngr[i].process_all_pending_pkts(flush_rx); - } + int total_pkts = 0; + for (int i = 0; i < m_max_ports; i++) { + total_pkts += m_rx_port_mngr[i].process_all_pending_pkts(flush_rx); + } - return total_pkts; + return total_pkts; } @@ -336,17 +355,27 @@ double CRxCoreStateless::get_cpu_util() { } -/** - * configure RX filtering mode (HW or software) - * - * @author imarom (11/1/2016) - * - * @param port_id - * @param filter_mode - */ void -CRxCoreStateless::set_rx_filter_mode(uint8_t port_id, rx_filter_mode_e filter_mode) { - const TrexPlatformApi *api = get_stateless_obj()->get_platform_api(); - api->set_rx_filter_mode(port_id, filter_mode); +CRxCoreStateless::start_capture(uint8_t port_id, const std::string &pcap_filename, uint64_t limit) { + m_rx_port_mngr[port_id].start_capture(pcap_filename, limit); +} + +void +CRxCoreStateless::stop_capture(uint8_t port_id) { + m_rx_port_mngr[port_id].stop_capture(); +} + +void +CRxCoreStateless::enable_latency() { + for (int i = 0; i < m_max_ports; i++) { + m_rx_port_mngr[i].enable_latency(); + } +} + +void +CRxCoreStateless::disable_latency() { + for (int i = 0; i < m_max_ports; i++) { + m_rx_port_mngr[i].disable_latency(); + } } diff --git a/src/stateless/rx/trex_stateless_rx_core.h b/src/stateless/rx/trex_stateless_rx_core.h index 2a59862b..425c15ae 100644 --- a/src/stateless/rx/trex_stateless_rx_core.h +++ b/src/stateless/rx/trex_stateless_rx_core.h @@ -103,11 +103,8 @@ class CRxCoreStateless { , TrexPlatformApi::driver_stat_cap_e type); int get_rfc2544_info(rfc2544_info_t *rfc2544_info, int min, int max, bool reset); int get_rx_err_cntrs(CRxCoreErrCntrs *rx_err); - void work() { - m_state = STATE_WORKING; - m_err_cntrs.reset(); // When starting to work, reset global counters - } - void idle() {m_state = STATE_IDLE;} + + void quit() {m_state = STATE_QUIT;} bool is_working() const {return (m_ack_start_work_msg == true);} void set_working_msg_ack(bool val); @@ -119,19 +116,33 @@ class CRxCoreStateless { } /** - * sets the port filter mode + * start capturing of RX packets on a specific port * - * @author imarom (10/31/2016) + * @author imarom (11/2/2016) * - * @param filter_mode + * @param port_id + * @param pcap_filename + * @param limit + */ + void start_capture(uint8_t port_id, const std::string &pcap_filename, uint64_t limit); + void stop_capture(uint8_t port_id); + + /** + * enable latency feature for RX packets + * will be apply to all ports */ - void set_rx_filter_mode(uint8_t port_id, rx_filter_mode_e filter_mode); + void enable_latency(); + void disable_latency(); private: void handle_cp_msg(TrexStatelessCpToRxMsgBase *msg); bool periodic_check_for_cp_messages(); void tickle(); void idle_state_loop(); + + void recalculate_next_state(); + bool are_any_features_active(); + void capture_pkt(rte_mbuf_t *m); void handle_rx_queue_msgs(uint8_t thread_id, CNodeRing * r); void handle_work_stage(bool do_try_rx_queue); @@ -145,14 +156,14 @@ class CRxCoreStateless { void try_rx_queues(); private: - TrexMonitor m_monitor; - uint32_t m_max_ports; - bool m_capture; - state_e m_state; - CNodeRing *m_ring_from_cp; - CNodeRing *m_ring_to_cp; - CCpuUtlDp m_cpu_dp_u; - CCpuUtlCp m_cpu_cp_u; + TrexMonitor m_monitor; + uint32_t m_max_ports; + bool m_capture; + state_e m_state; + CNodeRing *m_ring_from_cp; + CNodeRing *m_ring_to_cp; + CCpuUtlDp m_cpu_dp_u; + CCpuUtlCp m_cpu_cp_u; // Used for acking "work" (go out of idle) messages from cp volatile bool m_ack_start_work_msg __rte_cache_aligned; diff --git a/src/stateless/rx/trex_stateless_rx_port_mngr.cpp b/src/stateless/rx/trex_stateless_rx_port_mngr.cpp index 5b10eebf..35d331cf 100644 --- a/src/stateless/rx/trex_stateless_rx_port_mngr.cpp +++ b/src/stateless/rx/trex_stateless_rx_port_mngr.cpp @@ -148,7 +148,7 @@ RXPacketRecorder::~RXPacketRecorder() { } void -RXPacketRecorder::start(const std::string &pcap, uint32_t limit) { +RXPacketRecorder::start(const std::string &pcap, uint64_t limit) { m_writer = CCapWriterFactory::CreateWriter(LIBPCAP, (char *)pcap.c_str()); if (m_writer == NULL) { std::stringstream ss; @@ -206,7 +206,7 @@ void RXPortManager::handle_pkt(const rte_mbuf_t *m) { m_latency.handle_pkt(m); } - if (is_feature_set(RECORD)) { + if (is_feature_set(CAPTURE)) { m_recorder.handle_pkt(m); } diff --git a/src/stateless/rx/trex_stateless_rx_port_mngr.h b/src/stateless/rx/trex_stateless_rx_port_mngr.h index d197c423..7cc527d8 100644 --- a/src/stateless/rx/trex_stateless_rx_port_mngr.h +++ b/src/stateless/rx/trex_stateless_rx_port_mngr.h @@ -212,7 +212,7 @@ class RXPacketRecorder { public: RXPacketRecorder(); ~RXPacketRecorder(); - void start(const std::string &pcap, uint32_t limit); + void start(const std::string &pcap, uint64_t limit); void stop(); void handle_pkt(const rte_mbuf_t *m); @@ -235,16 +235,15 @@ class RXPortManager { public: enum features_t { LATENCY = 0x1, - RECORD = 0x2, + CAPTURE = 0x2, QUEUE = 0x4 }; RXPortManager() { - m_features = 0; - m_pkt_buffer = NULL; - m_io = NULL; - m_cpu_dp_u = NULL; - set_feature(LATENCY); + m_features = 0; + m_pkt_buffer = NULL; + m_io = NULL; + m_cpu_dp_u = NULL; } void create(CPortLatencyHWBase *io, @@ -264,16 +263,36 @@ public: return m_latency; } - void start_recorder(const std::string &pcap, uint32_t limit_pkts) { + void enable_latency() { + set_feature(LATENCY); + } + + void disable_latency() { + unset_feature(LATENCY); + } + + /** + * capturing of RX packets + * + * @author imarom (11/2/2016) + * + * @param pcap + * @param limit_pkts + */ + void start_capture(const std::string &pcap, uint64_t limit_pkts) { m_recorder.start(pcap, limit_pkts); - set_feature(RECORD); + set_feature(CAPTURE); } - void stop_recorder() { + void stop_capture() { m_recorder.stop(); - unset_feature(RECORD); + unset_feature(CAPTURE); } + /** + * queueing packets + * + */ void start_queue(uint32_t limit) { if (m_pkt_buffer) { delete m_pkt_buffer; @@ -329,6 +348,16 @@ public: */ void handle_pkt(const rte_mbuf_t *m); + + bool has_features_set() { + return (m_features != 0); + } + + + bool no_features_set() { + return (!has_features_set()); + } + private: @@ -344,10 +373,6 @@ private: return ( (m_features & feature) == feature ); } - bool no_features_set() { - return (m_features == 0); - } - uint32_t m_features; RXPacketRecorder m_recorder; RXLatency m_latency; -- cgit 1.2.3-korg