diff options
Diffstat (limited to 'src/stateless/cp')
-rw-r--r-- | src/stateless/cp/trex_stateless.cpp | 56 | ||||
-rw-r--r-- | src/stateless/cp/trex_stateless.h | 28 | ||||
-rw-r--r-- | src/stateless/cp/trex_stateless_port.cpp | 28 | ||||
-rw-r--r-- | src/stateless/cp/trex_stateless_port.h | 100 |
4 files changed, 102 insertions, 110 deletions
diff --git a/src/stateless/cp/trex_stateless.cpp b/src/stateless/cp/trex_stateless.cpp index c31ba0a5..6ab9b417 100644 --- a/src/stateless/cp/trex_stateless.cpp +++ b/src/stateless/cp/trex_stateless.cpp @@ -18,13 +18,14 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -#include <trex_stateless.h> -#include <trex_stateless_port.h> -#include <sched.h> #include <iostream> #include <unistd.h> +#include "trex_stateless.h" +#include "trex_stateless_port.h" +#include "trex_stateless_messaging.h" + using namespace std; /*********************************************************** @@ -141,53 +142,10 @@ TrexStateless::get_dp_core_count() { } void -TrexStateless::encode_stats(Json::Value &global) { - - TrexPlatformGlobalStats stats; - m_platform_api->get_global_stats(stats); - - global["cpu_util"] = stats.m_stats.m_cpu_util; - global["rx_cpu_util"] = stats.m_stats.m_rx_cpu_util; - - global["tx_bps"] = stats.m_stats.m_tx_bps; - global["rx_bps"] = stats.m_stats.m_rx_bps; - - global["tx_pps"] = stats.m_stats.m_tx_pps; - global["rx_pps"] = stats.m_stats.m_rx_pps; - - global["total_tx_pkts"] = Json::Value::UInt64(stats.m_stats.m_total_tx_pkts); - global["total_rx_pkts"] = Json::Value::UInt64(stats.m_stats.m_total_rx_pkts); - - global["total_tx_bytes"] = Json::Value::UInt64(stats.m_stats.m_total_tx_bytes); - global["total_rx_bytes"] = Json::Value::UInt64(stats.m_stats.m_total_rx_bytes); - - global["tx_rx_errors"] = Json::Value::UInt64(stats.m_stats.m_tx_rx_errors); - - for (uint8_t i = 0; i < m_port_count; i++) { - std::stringstream ss; - - ss << "port " << i; - Json::Value &port_section = global[ss.str()]; +TrexStateless::send_msg_to_rx(TrexStatelessCpToRxMsgBase *msg) const { - m_ports[i]->encode_stats(port_section); - } + CNodeRing *ring = CMsgIns::Ins()->getCpRx()->getRingCpToDp(0); + ring->Enqueue((CGenNode *)msg); } -/** - * generate a snapshot for publish (async publish) - * - */ -void -TrexStateless::generate_publish_snapshot(std::string &snapshot) { - Json::FastWriter writer; - Json::Value root; - - root["name"] = "trex-stateless-info"; - root["type"] = 0; - - /* stateless specific info goes here */ - root["data"] = Json::nullValue; - - snapshot = writer.write(root); -} diff --git a/src/stateless/cp/trex_stateless.h b/src/stateless/cp/trex_stateless.h index 3a1a2c24..87d227f6 100644 --- a/src/stateless/cp/trex_stateless.h +++ b/src/stateless/cp/trex_stateless.h @@ -132,32 +132,14 @@ public: /** - * shutdown the server + * send a message to the RX core */ - void shutdown(); - + void send_msg_to_rx(TrexStatelessCpToRxMsgBase *msg) const; + /** - * fetch xstats names (keys of dict) - * - */ - void encode_xstats_names(Json::Value &global); - - /** - * fetch xstats values - * - */ - void encode_xstats_values(Json::Value &global); - - /** - * fetch all the stats - * - */ - void encode_stats(Json::Value &global); - - /** - * generate a snapshot for publish + * shutdown the server */ - void generate_publish_snapshot(std::string &snapshot); + void shutdown(); const TrexPlatformApi * get_platform_api() { return (m_platform_api); diff --git a/src/stateless/cp/trex_stateless_port.cpp b/src/stateless/cp/trex_stateless_port.cpp index 7d331c6e..9cf048b0 100644 --- a/src/stateless/cp/trex_stateless_port.cpp +++ b/src/stateless/cp/trex_stateless_port.cpp @@ -162,7 +162,7 @@ private: * trex stateless port * **************************/ -TrexStatelessPort::TrexStatelessPort(uint8_t port_id, const TrexPlatformApi *api) : m_dp_events(this) { +TrexStatelessPort::TrexStatelessPort(uint8_t port_id, const TrexPlatformApi *api) : m_dp_events(this), m_service_mode(port_id, api) { std::vector<std::pair<uint8_t, uint8_t>> core_pair_list; m_port_id = port_id; @@ -948,24 +948,6 @@ TrexStatelessPort::remove_and_delete_all_streams() { } } -void -TrexStatelessPort::start_rx_capture(const std::string &pcap_filename, uint64_t limit) { - static MsgReply<bool> reply; - - reply.reset(); - - TrexStatelessRxStartCapture *msg = new TrexStatelessRxStartCapture(m_port_id, pcap_filename, limit, reply); - send_message_to_rx((TrexStatelessCpToRxMsgBase *)msg); - - /* as below, must wait for ACK from RX core before returning ACK */ - reply.wait_for_reply(); -} - -void -TrexStatelessPort::stop_rx_capture() { - TrexStatelessCpToRxMsgBase *msg = new TrexStatelessRxStopCapture(m_port_id); - send_message_to_rx(msg); -} void TrexStatelessPort::start_rx_queue(uint64_t size) { @@ -980,18 +962,22 @@ TrexStatelessPort::start_rx_queue(uint64_t size) { this might cause the user to lose some packets from the queue */ reply.wait_for_reply(); + + m_service_mode.set_rx_queue(); } void TrexStatelessPort::stop_rx_queue() { TrexStatelessCpToRxMsgBase *msg = new TrexStatelessRxStopQueue(m_port_id); send_message_to_rx(msg); + + m_service_mode.unset_rx_queue(); } -const RXPacketBuffer * +const TrexPktBuffer * TrexStatelessPort::get_rx_queue_pkts() { - static MsgReply<const RXPacketBuffer *> reply; + static MsgReply<const TrexPktBuffer *> reply; reply.reset(); diff --git a/src/stateless/cp/trex_stateless_port.h b/src/stateless/cp/trex_stateless_port.h index d4ac4018..0ef8ae60 100644 --- a/src/stateless/cp/trex_stateless_port.h +++ b/src/stateless/cp/trex_stateless_port.h @@ -26,12 +26,14 @@ limitations under the License. #include "trex_dp_port_events.h" #include "trex_stateless_rx_defs.h" #include "trex_stream.h" +#include "trex_exception.h" +#include "trex_stateless_capture.h" class TrexStatelessCpToDpMsgBase; class TrexStatelessCpToRxMsgBase; class TrexStreamsGraphObj; class TrexPortMultiplier; -class RXPacketBuffer; +class TrexPktBuffer; /** @@ -113,6 +115,56 @@ private: static const std::string g_unowned_handler; }; +/** + * enforces in/out from service mode + * + * @author imarom (1/4/2017) + */ +class TrexServiceMode { +public: + TrexServiceMode(uint8_t port_id, const TrexPlatformApi *api) { + m_is_enabled = false; + m_has_rx_queue = false; + m_port_id = port_id; + m_port_attr = api->getPortAttrObj(port_id); + } + + void enable() { + m_port_attr->set_rx_filter_mode(RX_FILTER_MODE_ALL); + m_is_enabled = true; + } + + void disable() { + if (m_has_rx_queue) { + throw TrexException("unable to disable service mode - please remove RX queue"); + } + + if (TrexStatelessCaptureMngr::getInstance().is_active(m_port_id)) { + throw TrexException("unable to disable service mode - an active capture on port " + std::to_string(m_port_id) + " exists"); + } + + m_port_attr->set_rx_filter_mode(RX_FILTER_MODE_HW); + m_is_enabled = false; + } + + bool is_enabled() const { + return m_is_enabled; + } + + void set_rx_queue() { + m_has_rx_queue = true; + } + + void unset_rx_queue() { + m_has_rx_queue = false; + } + +private: + bool m_is_enabled; + bool m_has_rx_queue; + TRexPortAttr *m_port_attr; + uint8_t m_port_id; +}; class AsyncStopEvent; @@ -150,7 +202,15 @@ public: RC_ERR_FAILED_TO_COMPILE_STREAMS }; - + /** + * port capture mode + */ + enum capture_mode_e { + PORT_CAPTURE_NONE = 0, + PORT_CAPTURE_RX, + PORT_CAPTURE_ALL + }; + TrexStatelessPort(uint8_t port_id, const TrexPlatformApi *api); ~TrexStatelessPort(); @@ -227,6 +287,20 @@ public: double duration, bool is_dual); + /** + * moves port to / out service mode + */ + void set_service_mode(bool enabled) { + if (enabled) { + m_service_mode.enable(); + } else { + m_service_mode.disable(); + } + } + bool is_service_mode_on() const { + return m_service_mode.is_enabled(); + } + /** * get the port state * @@ -365,19 +439,6 @@ public: void get_pci_info(std::string &pci_addr, int &numa_node); - - /** - * enable RX capture on port - * - */ - void start_rx_capture(const std::string &pcap_filename, uint64_t limit); - - /** - * disable RX capture if on - * - */ - void stop_rx_capture(); - /** * start RX queueing of packets * @@ -398,7 +459,7 @@ public: * fetch the RX queue packets from the queue * */ - const RXPacketBuffer *get_rx_queue_pkts(); + const TrexPktBuffer *get_rx_queue_pkts(); /** * configures port for L2 mode @@ -429,7 +490,9 @@ public: } private: - + void set_service_mode_on(); + void set_service_mode_off(); + bool is_core_active(int core_id); const std::vector<uint8_t> get_core_id_list () { @@ -514,6 +577,9 @@ private: TrexPortOwner m_owner; int m_pending_async_stop_event; + + TrexServiceMode m_service_mode; + static const uint32_t MAX_STREAMS = 20000; }; |