diff options
author | imarom <imarom@cisco.com> | 2017-01-24 18:20:01 +0200 |
---|---|---|
committer | imarom <imarom@cisco.com> | 2017-01-24 18:20:37 +0200 |
commit | 5681d70e593d29be7ec8a8d963f8fb34c4f86390 (patch) | |
tree | 920479cf32a96d7cba32a84ced02d33e7a2cd910 /src/stateless/cp | |
parent | 2155c64b103391cc5693ee849ad73d9b35f79903 (diff) |
fix floating point calculation precision at L1 rate (GUI 100% issue)
Signed-off-by: imarom <imarom@cisco.com>
Diffstat (limited to 'src/stateless/cp')
-rw-r--r-- | src/stateless/cp/trex_stateless_port.cpp | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/stateless/cp/trex_stateless_port.cpp b/src/stateless/cp/trex_stateless_port.cpp index 7d331c6e..443f0df7 100644 --- a/src/stateless/cp/trex_stateless_port.cpp +++ b/src/stateless/cp/trex_stateless_port.cpp @@ -695,12 +695,6 @@ TrexStatelessPort::calculate_effective_factor(const TrexPortMultiplier &mul, boo /* did we exceeded the max L1 line rate ? */ double expected_l1_rate = m_graph_obj->get_max_bps_l1(factor); - /* 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()); - } /* L1 BW must be positive */ if (expected_l1_rate <= 0){ @@ -716,7 +710,23 @@ TrexStatelessPort::calculate_effective_factor(const TrexPortMultiplier &mul, boo throw TrexException(ss.str()); } - return factor; + /* if force simply return the value */ + if (force) { + return factor; + } else { + + /* due to float calculations we allow 0.1% roundup */ + if ( (expected_l1_rate / get_port_speed_bps()) > 1.0001 ) { + 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()); + } + + /* in any case, without force, do not return any value higher than the max factor */ + double max_factor = m_graph_obj->get_factor_bps_l1(get_port_speed_bps()); + return std::min(max_factor, factor); + } + } double |