diff options
Diffstat (limited to 'src/stateless/cp/trex_stateless_port.cpp')
-rw-r--r-- | src/stateless/cp/trex_stateless_port.cpp | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/src/stateless/cp/trex_stateless_port.cpp b/src/stateless/cp/trex_stateless_port.cpp index 58410fea..9bb20990 100644 --- a/src/stateless/cp/trex_stateless_port.cpp +++ b/src/stateless/cp/trex_stateless_port.cpp @@ -158,6 +158,7 @@ TrexStatelessPort::TrexStatelessPort(uint8_t port_id, const TrexPlatformApi *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); @@ -252,6 +253,11 @@ TrexStatelessPort::start_traffic(const TrexPortMultiplier &mul, double duration, /* on start - we can only provide absolute values */ assert(mul.m_op == TrexPortMultiplier::OP_ABS); + /* check link state */ + if ( !m_platform_api->getPortAttrObj(m_port_id)->is_link_up() && !force ) { + throw TrexException("Link state is DOWN."); + } + /* caclulate the effective factor for DP */ double factor = calculate_effective_factor(mul, force); @@ -278,7 +284,7 @@ TrexStatelessPort::start_traffic(const TrexPortMultiplier &mul, double duration, feeder.set_status(true); - /* generate a message to all the relevant DP cores to start transmitting */ + /* generate a message to all the relevant DP cores to stop transmitting */ assert(m_pending_async_stop_event == TrexDpPortEvents::INVALID_ID); m_pending_async_stop_event = m_dp_events.create_event(new AsyncStopEvent()); @@ -581,7 +587,7 @@ void TrexStatelessPort::get_properties(std::string &driver, uint32_t &speed) { driver = m_api_info.driver_name; - speed = m_api_info.speed; + speed = m_platform_api->getPortAttrObj(m_port_id)->get_link_speed(); } bool @@ -609,10 +615,8 @@ TrexStatelessPort::change_state(port_state_e new_state) { void TrexStatelessPort::encode_stats(Json::Value &port) { - const TrexPlatformApi *api = get_stateless_obj()->get_platform_api(); - TrexPlatformInterfaceStats stats; - api->get_interface_stats(m_port_id, stats); + m_platform_api->get_interface_stats(m_port_id, stats); port["tx_bps"] = stats.m_stats.m_tx_bps; port["rx_bps"] = stats.m_stats.m_rx_bps; @@ -664,7 +668,7 @@ TrexStatelessPort::send_message_to_rx(TrexStatelessCpToRxMsgBase *msg) { uint64_t TrexStatelessPort::get_port_speed_bps() const { - return (uint64_t) m_api_info.speed * 1000 * 1000; + return (uint64_t) m_platform_api->getPortAttrObj(m_port_id)->get_link_speed() * 1000 * 1000; } static inline double @@ -687,6 +691,20 @@ TrexStatelessPort::calculate_effective_factor(const TrexPortMultiplier &mul, boo throw TrexException(ss.str()); } + /* L1 BW must be positive */ + if (expected_l1_rate <= 0){ + stringstream ss; + ss << "Effective bandwidth must be positive, got: " << expected_l1_rate; + throw TrexException(ss.str()); + } + + /* factor must be positive */ + if (factor <= 0) { + stringstream ss; + ss << "Factor must be positive, got: " << factor; + throw TrexException(ss.str()); + } + return factor; } @@ -869,18 +887,6 @@ TrexStatelessPort::get_port_effective_rate(double &pps, } - -void -TrexStatelessPort::set_promiscuous(bool enabled) { - get_stateless_obj()->get_platform_api()->set_promiscuous(m_port_id, enabled); -} - -bool -TrexStatelessPort::get_promiscuous() { - return get_stateless_obj()->get_platform_api()->get_promiscuous(m_port_id); -} - - void TrexStatelessPort::get_macaddr(std::string &hw_macaddr, std::string &src_macaddr, |