diff options
author | 2016-01-24 11:35:41 -0500 | |
---|---|---|
committer | 2016-01-24 11:35:41 -0500 | |
commit | b87ac8e2af727598b3120510b221244c9c499e56 (patch) | |
tree | 425d9cb46b9fa49eb13a0e2773a3e68591182c6c /src/stateless/cp | |
parent | 7294d7f162e19e0ccd3a37eafbafe22cf63df6a4 (diff) |
added support for L1 B/W check
both start/update now enforce this and it can
be bypassed by providing 'force'
Diffstat (limited to 'src/stateless/cp')
-rw-r--r-- | src/stateless/cp/trex_stateless_port.cpp | 39 | ||||
-rw-r--r-- | src/stateless/cp/trex_stateless_port.h | 8 |
2 files changed, 35 insertions, 12 deletions
diff --git a/src/stateless/cp/trex_stateless_port.cpp b/src/stateless/cp/trex_stateless_port.cpp index f14cc84c..d47802ec 100644 --- a/src/stateless/cp/trex_stateless_port.cpp +++ b/src/stateless/cp/trex_stateless_port.cpp @@ -132,7 +132,7 @@ TrexStatelessPort::release(void) { * */ void -TrexStatelessPort::start_traffic(const TrexPortMultiplier &mul, double duration) { +TrexStatelessPort::start_traffic(const TrexPortMultiplier &mul, double duration, bool force) { /* command allowed only on state stream */ verify_state(PORT_STATE_STREAMS); @@ -143,7 +143,8 @@ TrexStatelessPort::start_traffic(const TrexPortMultiplier &mul, double duration) /* on start - we can only provide absolute values */ assert(mul.m_op == TrexPortMultiplier::OP_ABS); - double factor = calculate_effective_factor(mul); + /* caclulate the effective factor for DP */ + double factor = calculate_effective_factor(mul, force); /* fetch all the streams from the table */ vector<TrexStream *> streams; @@ -274,14 +275,14 @@ TrexStatelessPort::resume_traffic(void) { } void -TrexStatelessPort::update_traffic(const TrexPortMultiplier &mul) { +TrexStatelessPort::update_traffic(const TrexPortMultiplier &mul, bool force) { double factor; verify_state(PORT_STATE_TX | PORT_STATE_PAUSE); /* generate a message to all the relevant DP cores to start transmitting */ - double new_factor = calculate_effective_factor(mul); + double new_factor = calculate_effective_factor(mul, force); switch (mul.m_op) { case TrexPortMultiplier::OP_ABS: @@ -446,20 +447,42 @@ TrexStatelessPort::get_port_speed_bps() const { } } +static inline double +bps_to_gbps(double bps) { + return (bps / (1000.0 * 1000 * 1000)); +} + double -TrexStatelessPort::calculate_effective_factor(const TrexPortMultiplier &mul) { +TrexStatelessPort::calculate_effective_factor(const TrexPortMultiplier &mul, bool force) { - /* for a simple factor request */ - if (mul.m_type == TrexPortMultiplier::MUL_FACTOR) { - return (mul.m_value); + double factor = calculate_effective_factor_internal(mul); + + /* did we exceeded the max L1 line rate ? */ + double expected_l1_rate = factor * m_graph_obj->get_max_bps_l1(); + + /* if not force and exceeded - throw exception */ + if ( (!force) && (expected_l1_rate > get_port_speed_bps()) ) { + stringstream ss; + ss << "Expected L1 B/W: '" << bps_to_gbps(expected_l1_rate) << " Gbps' exceeds port line rate: '" << bps_to_gbps(get_port_speed_bps()) << " Gbps'"; + throw TrexException(ss.str()); } + return factor; +} + +double +TrexStatelessPort::calculate_effective_factor_internal(const TrexPortMultiplier &mul) { + /* we now need the graph - generate it if we don't have it (happens once) */ if (!m_graph_obj) { generate_streams_graph(); } switch (mul.m_type) { + + case TrexPortMultiplier::MUL_FACTOR: + return (mul.m_value); + case TrexPortMultiplier::MUL_BPS: return (mul.m_value / m_graph_obj->get_max_bps_l2()); diff --git a/src/stateless/cp/trex_stateless_port.h b/src/stateless/cp/trex_stateless_port.h index c3785b0c..64cf73a4 100644 --- a/src/stateless/cp/trex_stateless_port.h +++ b/src/stateless/cp/trex_stateless_port.h @@ -162,7 +162,7 @@ public: * start traffic * throws TrexException in case of an error */ - void start_traffic(const TrexPortMultiplier &mul, double duration); + void start_traffic(const TrexPortMultiplier &mul, double duration, bool force = false); /** * stop traffic @@ -186,7 +186,7 @@ public: * update current traffic on port * */ - void update_traffic(const TrexPortMultiplier &mul); + void update_traffic(const TrexPortMultiplier &mul, bool force); /** * get the port state @@ -351,8 +351,8 @@ private: * calculate effective M per core * */ - double calculate_effective_factor(const TrexPortMultiplier &mul); - + double calculate_effective_factor(const TrexPortMultiplier &mul, bool force = false); + double calculate_effective_factor_internal(const TrexPortMultiplier &mul); /** |