diff options
author | imarom <imarom@cisco.com> | 2016-02-22 11:25:48 -0500 |
---|---|---|
committer | imarom <imarom@cisco.com> | 2016-02-23 03:09:25 -0500 |
commit | eb899885b5e4c551550275e8aa46061aefd6b37e (patch) | |
tree | 41af73da0621ab3219940e2bfaa04bc98f6d1acf /src/stateless | |
parent | d1360da9fbdda884f43400b98c022bbfccf523f4 (diff) |
some mods to the rate
Diffstat (limited to 'src/stateless')
-rw-r--r-- | src/stateless/cp/trex_stateless_port.cpp | 12 | ||||
-rw-r--r-- | src/stateless/cp/trex_stateless_port.h | 7 | ||||
-rw-r--r-- | src/stateless/cp/trex_stream.cpp | 35 | ||||
-rw-r--r-- | src/stateless/cp/trex_stream.h | 174 |
4 files changed, 130 insertions, 98 deletions
diff --git a/src/stateless/cp/trex_stateless_port.cpp b/src/stateless/cp/trex_stateless_port.cpp index 8ee46d29..75f77cf7 100644 --- a/src/stateless/cp/trex_stateless_port.cpp +++ b/src/stateless/cp/trex_stateless_port.cpp @@ -631,7 +631,10 @@ TrexStatelessPort::validate(void) { void -TrexStatelessPort::get_port_effective_rate(uint64_t &bps, uint64_t &pps) { +TrexStatelessPort::get_port_effective_rate(double &pps, + double &bps_L1, + double &bps_L2, + double &percentage) { if (get_stream_count() == 0) { return; @@ -641,8 +644,11 @@ TrexStatelessPort::get_port_effective_rate(uint64_t &bps, uint64_t &pps) { generate_streams_graph(); } - bps = m_graph_obj->get_max_bps_l2() * m_factor; - pps = m_graph_obj->get_max_pps() * m_factor; + pps = m_graph_obj->get_max_pps() * m_factor; + bps_L1 = m_graph_obj->get_max_bps_l1() * m_factor; + bps_L2 = m_graph_obj->get_max_bps_l2() * m_factor; + percentage = (bps_L1 / get_port_speed_bps()) * 100.0; + } /************* Trex Port Owner **************/ diff --git a/src/stateless/cp/trex_stateless_port.h b/src/stateless/cp/trex_stateless_port.h index b0b0ddf3..a101cef0 100644 --- a/src/stateless/cp/trex_stateless_port.h +++ b/src/stateless/cp/trex_stateless_port.h @@ -316,10 +316,11 @@ public: * * @author imarom (07-Jan-16) * - * @param bps - * @param pps */ - void get_port_effective_rate(uint64_t &bps, uint64_t &pps); + void get_port_effective_rate(double &pps, + double &bps_L1, + double &bps_L2, + double &percentage); private: diff --git a/src/stateless/cp/trex_stream.cpp b/src/stateless/cp/trex_stream.cpp index f4a8e800..357a2885 100644 --- a/src/stateless/cp/trex_stream.cpp +++ b/src/stateless/cp/trex_stream.cpp @@ -106,16 +106,16 @@ void TrexStream::Dump(FILE *fd){ fprintf(fd," rate :\n\n"); - fprintf(fd," pps : %f\n", get_rate().get_pps()); - fprintf(fd," bps L1 : %f\n", get_rate().get_bps_L1()); - fprintf(fd," bps L2 : %f\n", get_rate().get_bps_L2()); - fprintf(fd," percentage : %f\n", get_rate().get_percentage()); + fprintf(fd," pps : %f\n", m_rate.get_pps()); + fprintf(fd," bps L1 : %f\n", m_rate.get_bps_L1()); + fprintf(fd," bps L2 : %f\n", m_rate.get_bps_L2()); + fprintf(fd," percentage : %f\n", m_rate.get_percentage()); } TrexStream::TrexStream(uint8_t type, - uint8_t port_id, uint32_t stream_id) : m_port_id(port_id), m_stream_id(stream_id) { + uint8_t port_id, uint32_t stream_id) : m_port_id(port_id), m_stream_id(stream_id) , m_rate(*this) { /* default values */ m_type = type; @@ -160,18 +160,6 @@ TrexStream::get_stream_json() { return m_stream_json; } -TrexStreamRate & -TrexStream::get_rate() { - - /* lazy calculation of the rate */ - if (!m_rate.is_calculated()) { - TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(m_port_id); - double pkt_size = get_pkt_size(); - m_rate.calculate(pkt_size, port->get_port_speed_bps()); - } - - return m_rate; -} /************************************** * stream table @@ -253,3 +241,16 @@ int TrexStreamTable::size() { } +/************************************** + * TrexStreamRate + *************************************/ +uint64_t +TrexStreamRate::get_line_speed_bps() { + TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(m_stream.m_port_id); + return port->get_port_speed_bps(); +} + +double +TrexStreamRate::get_pkt_size() { + return m_stream.get_pkt_size(); +} diff --git a/src/stateless/cp/trex_stream.h b/src/stateless/cp/trex_stream.h index f4739569..66f05b16 100644 --- a/src/stateless/cp/trex_stream.h +++ b/src/stateless/cp/trex_stream.h @@ -103,6 +103,8 @@ public: } }; +class TrexStream; + /** * describes a stream rate * @@ -121,9 +123,21 @@ public: RATE_PERCENTAGE }; - TrexStreamRate() { - m_base_rate_type = RATE_INVALID; - m_is_calculated = false; + TrexStreamRate(TrexStream &stream) : m_stream(stream) { + m_pps = 0; + m_bps_L1 = 0; + m_bps_L2 = 0; + m_percentage = 0; + } + + + TrexStreamRate& operator=(const TrexStreamRate& other) { + m_pps = other.m_pps; + m_bps_L1 = other.m_bps_L1; + m_bps_L2 = other.m_bps_L2; + m_percentage = other.m_percentage; + + return (*this); } /** @@ -132,121 +146,133 @@ public: * */ void set_base_rate(rate_type_e type, double value) { - m_base_rate_type = type; - m_value = value; - m_is_calculated = false; - } - + m_pps = 0; + m_bps_L1 = 0; + m_bps_L2 = 0; + m_percentage = 0; - /** - * calculates all the rates from the base rate - * - */ - void calculate(uint16_t pkt_size, uint64_t line_bps) { + assert(value > 0); - switch (m_base_rate_type) { - + switch (type) { case RATE_PPS: - calculate_from_pps(m_value, pkt_size, line_bps); + m_pps = value; break; - case RATE_BPS_L1: - calculate_from_bps_L1(m_value, pkt_size, line_bps); + m_bps_L1 = value; break; - case RATE_BPS_L2: - calculate_from_bps_L2(m_value, pkt_size, line_bps); + m_bps_L2 = value; break; - case RATE_PERCENTAGE: - calculate_from_percentage(m_value, pkt_size, line_bps); + m_percentage = value; break; default: assert(0); + } - - m_is_calculated = true; - } - - - bool is_calculated() const { - return m_is_calculated; - } - - - /* update the rate by a factor */ - void update_factor(double factor) { - assert(m_is_calculated); - - m_pps *= factor; - m_bps_L1 *= factor; - m_bps_L2 *= factor; - m_percentage *= factor; } double get_pps() { - assert(m_is_calculated); + if (m_pps == 0) { + calculate(); + } return (m_pps); } double get_bps_L1() { - assert(m_is_calculated); + if (m_bps_L1 == 0) { + calculate(); + } return (m_bps_L1); } double get_bps_L2() { - assert(m_is_calculated); + if (m_bps_L2 == 0) { + calculate(); + } return m_bps_L2; } double get_percentage() { - assert(m_is_calculated); + if (m_percentage == 0) { + calculate(); + } return m_percentage; } + + + /* update the rate by a factor */ + void update_factor(double factor) { + /* if all are non zero - it works, if only one (base) is also works */ + m_pps *= factor; + m_bps_L1 *= factor; + m_bps_L2 *= factor; + m_percentage *= factor; + } + + + private: - void calculate_from_pps(double pps, uint16_t pkt_size, uint64_t line_bps) { - m_pps = pps; - m_bps_L1 = m_pps * (pkt_size + 24) * 8; - m_bps_L2 = m_pps * (pkt_size + 4) * 8; - m_percentage = (m_bps_L1 / line_bps) * 100.0; + /** + * calculates all the rates from the base rate + * + */ + void calculate() { + + if (m_pps != 0) { + calculate_from_pps(); + } else if (m_bps_L1 != 0) { + calculate_from_bps_L1(); + } else if (m_bps_L2 != 0) { + calculate_from_bps_L2(); + } else if (m_percentage != 0) { + calculate_from_percentage(); + } else { + assert(0); + } } - void calculate_from_bps_L1(double bps_L1, uint16_t pkt_size, uint64_t line_bps) { - m_bps_L1 = bps_L1; - m_bps_L2 = m_bps_L1 * ( (pkt_size + 4.0) / (pkt_size + 24.0) ); - m_pps = m_bps_L2 / (8 * (pkt_size + 4)); - m_percentage = (m_bps_L1 / line_bps) * 100.0; + uint64_t get_line_speed_bps(); + double get_pkt_size(); + + void calculate_from_pps() { + m_bps_L1 = m_pps * (get_pkt_size() + 24) * 8; + m_bps_L2 = m_pps * (get_pkt_size() + 4) * 8; + m_percentage = (m_bps_L1 / get_line_speed_bps()) * 100.0; } - void calculate_from_bps_L2(double bps_L2, uint16_t pkt_size, uint64_t line_bps) { - m_bps_L2 = bps_L2; - m_bps_L1 = m_bps_L2 * ( (pkt_size + 24.0) / (pkt_size + 4.0)); - m_pps = m_bps_L2 / (8 * (pkt_size + 4)); - m_percentage = (m_bps_L1 / line_bps) * 100.0; + void calculate_from_bps_L1() { + m_bps_L2 = m_bps_L1 * ( (get_pkt_size() + 4.0) / (get_pkt_size() + 24.0) ); + m_pps = m_bps_L2 / (8 * (get_pkt_size() + 4)); + m_percentage = (m_bps_L1 / get_line_speed_bps()) * 100.0; } - void calculate_from_percentage(double percentage, uint16_t pkt_size, uint64_t line_bps) { - m_percentage = percentage; - m_bps_L1 = (m_percentage / 100.0) * line_bps; - m_bps_L2 = m_bps_L1 * ( (pkt_size + 4.0) / (pkt_size + 24.0) ); - m_pps = m_bps_L2 / (8 * (pkt_size + 4)); + void calculate_from_bps_L2() { + m_bps_L1 = m_bps_L2 * ( (get_pkt_size() + 24.0) / (get_pkt_size() + 4.0)); + m_pps = m_bps_L2 / (8 * (get_pkt_size() + 4)); + m_percentage = (m_bps_L1 / get_line_speed_bps()) * 100.0; } - rate_type_e m_base_rate_type; - double m_value; + void calculate_from_percentage() { + m_bps_L1 = (m_percentage / 100.0) * get_line_speed_bps(); + m_bps_L2 = m_bps_L1 * ( (get_pkt_size() + 4.0) / (get_pkt_size() + 24.0) ); + m_pps = m_bps_L2 / (8 * (get_pkt_size() + 4)); + + } - bool m_is_calculated; double m_pps; double m_bps_L1; double m_bps_L2; double m_percentage; + /* reference to the owner class */ + TrexStream &m_stream; }; /** @@ -254,6 +280,7 @@ private: * */ class TrexStream { +friend class TrexStreamRate; public: enum STREAM_TYPE { @@ -298,19 +325,19 @@ public: double get_pps() { - return get_rate().get_pps(); + return m_rate.get_pps(); } double get_bps_L1() { - return get_rate().get_bps_L1(); + return m_rate.get_bps_L1(); } double get_bps_L2() { - return get_rate().get_bps_L2(); + return m_rate.get_bps_L2(); } double get_bw_percentage() { - return get_rate().get_percentage(); + return m_rate.get_percentage(); } void set_rate(TrexStreamRate::rate_type_e type, double value) { @@ -318,7 +345,7 @@ public: } void update_rate_factor(double factor) { - get_rate().update_factor(factor); + m_rate.update_factor(factor); } void set_type(uint8_t type){ @@ -502,9 +529,6 @@ private: } - /* get (and calculate if need) the rate of the stream */ - TrexStreamRate & get_rate(); - /* no access to this without a lazy build method */ TrexStreamRate m_rate; }; |