summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/stateless/cp/trex_stateless_port.cpp53
-rw-r--r--src/stateless/cp/trex_stateless_port.h77
-rw-r--r--src/stateless/messaging/trex_stateless_messaging.cpp37
-rw-r--r--src/stateless/messaging/trex_stateless_messaging.h38
-rw-r--r--src/stateless/rx/trex_stateless_rx_port_mngr.h11
5 files changed, 137 insertions, 79 deletions
diff --git a/src/stateless/cp/trex_stateless_port.cpp b/src/stateless/cp/trex_stateless_port.cpp
index 9cf048b0..bfc7dce4 100644
--- a/src/stateless/cp/trex_stateless_port.cpp
+++ b/src/stateless/cp/trex_stateless_port.cpp
@@ -162,13 +162,14 @@ private:
* trex stateless port
*
**************************/
-TrexStatelessPort::TrexStatelessPort(uint8_t port_id, const TrexPlatformApi *api) : m_dp_events(this), m_service_mode(port_id, api) {
+TrexStatelessPort::TrexStatelessPort(uint8_t port_id, const TrexPlatformApi *api) : m_dp_events(this) {
std::vector<std::pair<uint8_t, uint8_t>> core_pair_list;
- m_port_id = port_id;
- m_port_state = PORT_STATE_IDLE;
- m_platform_api = api;
-
+ m_port_id = port_id;
+ m_port_state = PORT_STATE_IDLE;
+ m_platform_api = api;
+ m_is_service_mode_on = false;
+
/* get the platform specific data */
api->get_interface_info(port_id, m_api_info);
@@ -948,6 +949,44 @@ TrexStatelessPort::remove_and_delete_all_streams() {
}
}
+/**
+ * enable/disable service mode
+ * sends a query to the RX core
+ *
+ */
+void
+TrexStatelessPort::set_service_mode(bool enabled) {
+ static MsgReply<TrexStatelessRxQuery::query_rc_e> reply;
+ reply.reset();
+
+ TrexStatelessRxQuery::query_type_e query_type = (enabled ? TrexStatelessRxQuery::SERVICE_MODE_ON : TrexStatelessRxQuery::SERVICE_MODE_OFF);
+
+ TrexStatelessRxQuery *msg = new TrexStatelessRxQuery(m_port_id, query_type, reply);
+ send_message_to_rx( (TrexStatelessCpToRxMsgBase *)msg );
+
+ TrexStatelessRxQuery::query_rc_e rc = reply.wait_for_reply();
+
+ switch (rc) {
+ case TrexStatelessRxQuery::RC_OK:
+ if (enabled) {
+ getPortAttrObj()->set_rx_filter_mode(RX_FILTER_MODE_ALL);
+ } else {
+ getPortAttrObj()->set_rx_filter_mode(RX_FILTER_MODE_HW);
+ }
+ m_is_service_mode_on = enabled;
+ return;
+
+ case TrexStatelessRxQuery::RC_FAIL_RX_QUEUE_ACTIVE:
+ throw TrexException("unable to disable service mode - please remove RX queue");
+
+ case TrexStatelessRxQuery::RC_FAIL_CAPTURE_ACTIVE:
+ throw TrexException("unable to disable service mode - an active capture on port " + std::to_string(m_port_id) + " exists");
+
+ default:
+ assert(0);
+ }
+}
+
void
TrexStatelessPort::start_rx_queue(uint64_t size) {
@@ -962,16 +1001,12 @@ 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();
}
diff --git a/src/stateless/cp/trex_stateless_port.h b/src/stateless/cp/trex_stateless_port.h
index 0ef8ae60..4b8ea3d9 100644
--- a/src/stateless/cp/trex_stateless_port.h
+++ b/src/stateless/cp/trex_stateless_port.h
@@ -115,57 +115,6 @@ 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;
/**
@@ -287,20 +236,20 @@ public:
double duration,
bool is_dual);
- /**
- * moves port to / out service mode
+
+ /**
+ * sets service mode
+ *
+ * @author imarom (1/22/2017)
+ *
+ * @param enabled
*/
- void set_service_mode(bool enabled) {
- if (enabled) {
- m_service_mode.enable();
- } else {
- m_service_mode.disable();
- }
- }
+ void set_service_mode(bool enabled);
+
bool is_service_mode_on() const {
- return m_service_mode.is_enabled();
+ return m_is_service_mode_on;
}
-
+
/**
* get the port state
*
@@ -578,8 +527,8 @@ private:
int m_pending_async_stop_event;
- TrexServiceMode m_service_mode;
-
+ bool m_is_service_mode_on;
+
static const uint32_t MAX_STREAMS = 20000;
};
diff --git a/src/stateless/messaging/trex_stateless_messaging.cpp b/src/stateless/messaging/trex_stateless_messaging.cpp
index 2452487c..21fe7a13 100644
--- a/src/stateless/messaging/trex_stateless_messaging.cpp
+++ b/src/stateless/messaging/trex_stateless_messaging.cpp
@@ -381,3 +381,40 @@ TrexStatelessRxSetL3Mode::handle(CRxCoreStateless *rx_core) {
return true;
}
+bool
+TrexStatelessRxQuery::handle(CRxCoreStateless *rx_core) {
+
+ query_rc_e rc = RC_OK;
+
+ switch (m_query_type) {
+
+ case SERVICE_MODE_ON:
+ /* for service mode on - always allow this */
+ rc = RC_OK;
+ break;
+
+ case SERVICE_MODE_OFF:
+ /* cannot leave service mode when RX queue is active */
+ if (rx_core->get_rx_port_mngr(m_port_id).is_feature_set(RXPortManager::QUEUE)) {
+ rc = RC_FAIL_RX_QUEUE_ACTIVE;
+ break;
+ }
+
+ /* cannot leave service mode if PCAP capturing is active */
+ if (TrexStatelessCaptureMngr::getInstance().is_active(m_port_id)) {
+ rc = RC_FAIL_CAPTURE_ACTIVE;
+ break;
+ }
+
+ break;
+
+ default:
+ assert(0);
+ break;
+
+ }
+
+ m_reply.set_reply(rc);
+
+ return true;
+}
diff --git a/src/stateless/messaging/trex_stateless_messaging.h b/src/stateless/messaging/trex_stateless_messaging.h
index 3535ad4f..ed14b100 100644
--- a/src/stateless/messaging/trex_stateless_messaging.h
+++ b/src/stateless/messaging/trex_stateless_messaging.h
@@ -677,4 +677,42 @@ private:
MsgReply<Json::Value> &m_reply;
};
+
+class TrexStatelessRxQuery : public TrexStatelessCpToRxMsgBase {
+public:
+
+ /**
+ * query type to request
+ */
+ enum query_type_e {
+ SERVICE_MODE_ON,
+ SERVICE_MODE_OFF,
+ };
+
+ /**
+ * RC types for queries
+ */
+ enum query_rc_e {
+ RC_OK,
+ RC_FAIL_RX_QUEUE_ACTIVE,
+ RC_FAIL_CAPTURE_ACTIVE,
+ };
+
+ TrexStatelessRxQuery(uint8_t port_id, query_type_e query_type, MsgReply<query_rc_e> &reply) : m_reply(reply) {
+ m_port_id = port_id;
+ m_query_type = query_type;
+ }
+
+ /**
+ * virtual function to handle a message
+ *
+ */
+ virtual bool handle(CRxCoreStateless *rx_core);
+
+private:
+ uint8_t m_port_id;
+ query_type_e m_query_type;
+ MsgReply<query_rc_e> &m_reply;
+};
+
#endif /* __TREX_STATELESS_MESSAGING_H__ */
diff --git a/src/stateless/rx/trex_stateless_rx_port_mngr.h b/src/stateless/rx/trex_stateless_rx_port_mngr.h
index 0cc60716..b318d973 100644
--- a/src/stateless/rx/trex_stateless_rx_port_mngr.h
+++ b/src/stateless/rx/trex_stateless_rx_port_mngr.h
@@ -305,11 +305,14 @@ public:
return (m_features != NO_FEATURES);
}
-
bool no_features_set() {
return (!has_features_set());
}
+ bool is_feature_set(feature_t feature) const {
+ return ( (m_features & feature) == feature );
+ }
+
/**
* returns ignored set of stats
* (grat ARP, PING response and etc.)
@@ -334,11 +337,7 @@ private:
void unset_feature(feature_t feature) {
m_features &= (~feature);
}
-
- bool is_feature_set(feature_t feature) const {
- return ( (m_features & feature) == feature );
- }
-
+
uint32_t m_features;
uint8_t m_port_id;
RXLatency m_latency;