summaryrefslogtreecommitdiffstats
path: root/src/stateless/cp/trex_stateless_port.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/stateless/cp/trex_stateless_port.cpp')
-rw-r--r--src/stateless/cp/trex_stateless_port.cpp179
1 files changed, 159 insertions, 20 deletions
diff --git a/src/stateless/cp/trex_stateless_port.cpp b/src/stateless/cp/trex_stateless_port.cpp
index 9bb20990..e9b3c6d4 100644
--- a/src/stateless/cp/trex_stateless_port.cpp
+++ b/src/stateless/cp/trex_stateless_port.cpp
@@ -25,6 +25,7 @@ limitations under the License.
#include <trex_streams_compiler.h>
#include <common/basic_utils.h>
#include <common/captureFile.h>
+#include "trex_stateless_rx_defs.h"
#include <string>
@@ -98,20 +99,26 @@ protected:
************************************/
class StreamsFeeder {
public:
+
StreamsFeeder(TrexStatelessPort *port) {
-
/* start pesimistic */
m_success = false;
-
+
+ m_port = port;
+ }
+
+ void feed() {
+
/* fetch the original streams */
- port->get_object_list(m_in_streams);
+ m_port->get_object_list(m_in_streams);
for (const TrexStream *in_stream : m_in_streams) {
TrexStream *out_stream = in_stream->clone(true);
- get_stateless_obj()->m_rx_flow_stat.start_stream(out_stream);
-
m_out_streams.push_back(out_stream);
+
+ get_stateless_obj()->m_rx_flow_stat.start_stream(out_stream);
+
}
}
@@ -146,6 +153,8 @@ private:
vector<TrexStream *> m_in_streams;
vector<TrexStream *> m_out_streams;
bool m_success;
+
+ TrexStatelessPort *m_port;
};
@@ -156,9 +165,9 @@ private:
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;
/* get the platform specific data */
api->get_interface_info(port_id, m_api_info);
@@ -262,6 +271,7 @@ TrexStatelessPort::start_traffic(const TrexPortMultiplier &mul, double duration,
double factor = calculate_effective_factor(mul, force);
StreamsFeeder feeder(this);
+ feeder.feed();
/* compiler it */
std::vector<TrexStreamsCompiledObj *> compiled_objs;
@@ -501,6 +511,7 @@ TrexStatelessPort::update_traffic(const TrexPortMultiplier &mul, bool force) {
void
TrexStatelessPort::push_remote(const std::string &pcap_filename,
double ipg_usec,
+ double min_ipg_sec,
double speedup,
uint32_t count,
double duration,
@@ -540,6 +551,7 @@ TrexStatelessPort::push_remote(const std::string &pcap_filename,
m_pending_async_stop_event,
pcap_filename,
ipg_usec,
+ min_ipg_sec,
speedup,
count,
duration,
@@ -584,10 +596,9 @@ TrexStatelessPort::get_max_stream_id() const {
}
void
-TrexStatelessPort::get_properties(std::string &driver, uint32_t &speed) {
+TrexStatelessPort::get_properties(std::string &driver) {
driver = m_api_info.driver_name;
- speed = m_platform_api->getPortAttrObj(m_port_id)->get_link_speed();
}
bool
@@ -888,16 +899,6 @@ TrexStatelessPort::get_port_effective_rate(double &pps,
}
void
-TrexStatelessPort::get_macaddr(std::string &hw_macaddr,
- std::string &src_macaddr,
- std::string &dst_macaddr) {
-
- utl_macaddr_to_str(m_api_info.mac_info.hw_macaddr, hw_macaddr);
- utl_macaddr_to_str(m_api_info.mac_info.src_macaddr, src_macaddr);
- utl_macaddr_to_str(m_api_info.mac_info.dst_macaddr, dst_macaddr);
-}
-
-void
TrexStatelessPort::get_pci_info(std::string &pci_addr, int &numa_node) {
pci_addr = m_api_info.pci_addr;
numa_node = m_api_info.numa_node;
@@ -908,6 +909,9 @@ TrexStatelessPort::add_stream(TrexStream *stream) {
verify_state(PORT_STATE_IDLE | PORT_STATE_STREAMS, "add_stream");
+ if (m_stream_table.size() >= MAX_STREAMS) {
+ throw TrexException("Reached limit of " + std::to_string(MAX_STREAMS) + " streams at the port.");
+ }
get_stateless_obj()->m_rx_flow_stat.add_stream(stream);
m_stream_table.add_stream(stream);
@@ -944,6 +948,141 @@ 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) {
+ static MsgReply<bool> reply;
+
+ reply.reset();
+
+ TrexStatelessRxStartQueue *msg = new TrexStatelessRxStartQueue(m_port_id, size, reply);
+ send_message_to_rx( (TrexStatelessCpToRxMsgBase *)msg );
+
+ /* we cannot return ACK to the user until the RX core has approved
+ this might cause the user to lose some packets from the queue
+ */
+ reply.wait_for_reply();
+}
+
+void
+TrexStatelessPort::stop_rx_queue() {
+ TrexStatelessCpToRxMsgBase *msg = new TrexStatelessRxStopQueue(m_port_id);
+ send_message_to_rx(msg);
+}
+
+
+const RXPacketBuffer *
+TrexStatelessPort::get_rx_queue_pkts() {
+ static MsgReply<const RXPacketBuffer *> reply;
+
+ reply.reset();
+
+ TrexStatelessRxQueueGetPkts *msg = new TrexStatelessRxQueueGetPkts(m_port_id, reply);
+ send_message_to_rx( (TrexStatelessCpToRxMsgBase *)msg );
+
+ return reply.wait_for_reply();
+}
+
+
+/**
+ * configures port in L2 mode
+ *
+ */
+void
+TrexStatelessPort::set_l2_mode(const uint8_t *dest_mac) {
+
+ /* not valid under traffic */
+ verify_state(PORT_STATE_IDLE | PORT_STATE_STREAMS, "set_l2_mode");
+
+ /* no IPv4 src */
+ getPortAttrObj()->set_src_ipv4(0);
+
+ /* set destination as MAC */
+ getPortAttrObj()->get_dest().set_dest(dest_mac);
+
+ TrexStatelessRxSetL2Mode *msg = new TrexStatelessRxSetL2Mode(m_port_id);
+ send_message_to_rx( (TrexStatelessCpToRxMsgBase *)msg );
+}
+
+/**
+ * configures port in L3 mode - unresolved
+ */
+void
+TrexStatelessPort::set_l3_mode(uint32_t src_ipv4, uint32_t dest_ipv4) {
+
+ /* not valid under traffic */
+ verify_state(PORT_STATE_IDLE | PORT_STATE_STREAMS, "set_l3_mode");
+
+ /* set src IPv4 */
+ getPortAttrObj()->set_src_ipv4(src_ipv4);
+
+ /* set dest IPv4 */
+ getPortAttrObj()->get_dest().set_dest(dest_ipv4);
+
+ /* send RX core the relevant info */
+ CManyIPInfo ip_info;
+ ip_info.insert(COneIPv4Info(src_ipv4, 0, getPortAttrObj()->get_src_mac()));
+
+ TrexStatelessRxSetL3Mode *msg = new TrexStatelessRxSetL3Mode(m_port_id, ip_info, false);
+ send_message_to_rx( (TrexStatelessCpToRxMsgBase *)msg );
+}
+
+/**
+ * configures port in L3 mode - resolved
+ *
+ */
+void
+TrexStatelessPort::set_l3_mode(uint32_t src_ipv4, uint32_t dest_ipv4, const uint8_t *resolved_mac) {
+
+ verify_state(PORT_STATE_IDLE | PORT_STATE_STREAMS, "set_l3_mode");
+
+ /* set src IPv4 */
+ getPortAttrObj()->set_src_ipv4(src_ipv4);
+
+ /* set dest IPv4 + resolved MAC */
+ getPortAttrObj()->get_dest().set_dest(dest_ipv4, resolved_mac);
+
+ /* send RX core the relevant info */
+ CManyIPInfo ip_info;
+ ip_info.insert(COneIPv4Info(src_ipv4, 0, getPortAttrObj()->get_src_mac()));
+
+ bool is_grat_arp_needed = !getPortAttrObj()->is_loopback();
+
+ TrexStatelessRxSetL3Mode *msg = new TrexStatelessRxSetL3Mode(m_port_id, ip_info, is_grat_arp_needed);
+ send_message_to_rx( (TrexStatelessCpToRxMsgBase *)msg );
+}
+
+
+Json::Value
+TrexStatelessPort::rx_features_to_json() {
+ static MsgReply<Json::Value> reply;
+
+ reply.reset();
+
+ TrexStatelessRxFeaturesToJson *msg = new TrexStatelessRxFeaturesToJson(m_port_id, reply);
+ send_message_to_rx( (TrexStatelessCpToRxMsgBase *)msg );
+
+ return reply.wait_for_reply();
+}
+
/************* Trex Port Owner **************/
TrexPortOwner::TrexPortOwner() {