From b103e6a8544d727ea155ec2c2bc71dbf91a36219 Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Thu, 16 Aug 2018 12:20:10 +0100 Subject: Improvie TRex RFC2544 throughput calculation Improve TRex RFC2544 throughput calculation by using the in/out packets instead of using the throughput samples. JIRA: YARDSTICK-1387 Change-Id: I877e901c3226d31c6435a877a2924bb95deb1cf0 Signed-off-by: Rodolfo Alonso Hernandez --- .../network_services/traffic_profile/rfc2544.py | 23 +++++------- .../network_services/vnf_generic/vnf/tg_trex.py | 4 +- .../traffic_profile/test_rfc2544.py | 43 ++++++++++++---------- 3 files changed, 37 insertions(+), 33 deletions(-) diff --git a/yardstick/network_services/traffic_profile/rfc2544.py b/yardstick/network_services/traffic_profile/rfc2544.py index b54fc575f..898315671 100644 --- a/yardstick/network_services/traffic_profile/rfc2544.py +++ b/yardstick/network_services/traffic_profile/rfc2544.py @@ -247,19 +247,16 @@ class RFC2544Profile(trex_traffic_profile.TrexProfile): correlated_traffic): """Calculate the drop percentage and run the traffic""" completed = False - tx_rate_fps = 0 - rx_rate_fps = 0 - for sample in samples: - tx_rate_fps += sum( - port['tx_throughput_fps'] for port in sample.values()) - rx_rate_fps += sum( - port['rx_throughput_fps'] for port in sample.values()) - tx_rate_fps = round(float(tx_rate_fps) / len(samples), 2) - rx_rate_fps = round(float(rx_rate_fps) / len(samples), 2) - - # TODO(esm): RFC2544 doesn't tolerate packet loss, why do we? - out_packets = sum(port['out_packets'] for port in samples[-1].values()) - in_packets = sum(port['in_packets'] for port in samples[-1].values()) + out_pkt_end = sum(port['out_packets'] for port in samples[-1].values()) + in_pkt_end = sum(port['in_packets'] for port in samples[-1].values()) + out_pkt_ini = sum(port['out_packets'] for port in samples[0].values()) + in_pkt_ini = sum(port['in_packets'] for port in samples[0].values()) + time_diff = (list(samples[-1].values())[0]['timestamp'] - + list(samples[0].values())[0]['timestamp']).total_seconds() + out_packets = out_pkt_end - out_pkt_ini + in_packets = in_pkt_end - in_pkt_ini + tx_rate_fps = float(out_packets) / time_diff + rx_rate_fps = float(in_packets) / time_diff drop_percent = 100.0 # https://tools.ietf.org/html/rfc2544#section-26.3 diff --git a/yardstick/network_services/vnf_generic/vnf/tg_trex.py b/yardstick/network_services/vnf_generic/vnf/tg_trex.py index 58b73488b..4296da84c 100644 --- a/yardstick/network_services/vnf_generic/vnf/tg_trex.py +++ b/yardstick/network_services/vnf_generic/vnf/tg_trex.py @@ -11,8 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -""" Trex acts as traffic generation and vnf definitions based on IETS Spec """ +import datetime import logging import os @@ -167,6 +167,7 @@ class TrexResourceHelper(ClientResourceHelper): def _get_samples(self, ports, port_pg_id=None): stats = self.get_stats(ports) + timestamp = datetime.datetime.now() samples = {} for pname in (intf['name'] for intf in self.vnfd_helper.interfaces): port_num = self.vnfd_helper.port_num(pname) @@ -178,6 +179,7 @@ class TrexResourceHelper(ClientResourceHelper): 'tx_throughput_bps': float(port_stats.get('tx_bps', 0.0)), 'in_packets': int(port_stats.get('ipackets', 0)), 'out_packets': int(port_stats.get('opackets', 0)), + 'timestamp': timestamp } pg_id_list = port_pg_id.get_pg_ids(port_num) diff --git a/yardstick/tests/unit/network_services/traffic_profile/test_rfc2544.py b/yardstick/tests/unit/network_services/traffic_profile/test_rfc2544.py index 2e0331e8e..d0ad77110 100644 --- a/yardstick/tests/unit/network_services/traffic_profile/test_rfc2544.py +++ b/yardstick/tests/unit/network_services/traffic_profile/test_rfc2544.py @@ -12,8 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -import mock +import datetime +import mock from trex_stl_lib import api as Pkt from trex_stl_lib import trex_stl_client from trex_stl_lib import trex_stl_packet_builder_scapy @@ -219,34 +220,38 @@ class TestRFC2544Profile(base.BaseUnitTestCase): def test_get_drop_percentage(self): rfc2544_profile = rfc2544.RFC2544Profile(self.TRAFFIC_PROFILE) samples = [ - {'xe1': {'tx_throughput_fps': 100, + {'xe1': {'tx_throughput_fps': 110, 'rx_throughput_fps': 101, - 'out_packets': 2000, - 'in_packets': 2010}, - 'xe2': {'tx_throughput_fps': 200, + 'out_packets': 2100, + 'in_packets': 2010, + 'timestamp': datetime.datetime(2000, 1, 1, 1, 1, 1, 1)}, + 'xe2': {'tx_throughput_fps': 210, 'rx_throughput_fps': 201, - 'out_packets': 4000, - 'in_packets': 4010}}, - {'xe1': {'tx_throughput_fps': 106, + 'out_packets': 4100, + 'in_packets': 4010, + 'timestamp': datetime.datetime(2000, 1, 1, 1, 1, 1, 1)}}, + {'xe1': {'tx_throughput_fps': 156, 'rx_throughput_fps': 108, - 'out_packets': 2031, + 'out_packets': 2110, 'in_packets': 2040, - 'latency': 'Latency1'}, - 'xe2': {'tx_throughput_fps': 203, + 'latency': 'Latency1', + 'timestamp': datetime.datetime(2000, 1, 1, 1, 1, 1, 31)}, + 'xe2': {'tx_throughput_fps': 253, 'rx_throughput_fps': 215, - 'out_packets': 4025, - 'in_packets': 4040, - 'latency': 'Latency2'}} + 'out_packets': 4150, + 'in_packets': 4010, + 'latency': 'Latency2', + 'timestamp': datetime.datetime(2000, 1, 1, 1, 1, 1, 31)}} ] completed, output = rfc2544_profile.get_drop_percentage( samples, 0, 0, False) - expected = {'DropPercentage': 0.3963, + expected = {'DropPercentage': 50.0, 'Latency': {'xe1': 'Latency1', 'xe2': 'Latency2'}, - 'RxThroughput': 312.5, - 'TxThroughput': 304.5, - 'CurrentDropPercentage': 0.3963, + 'RxThroughput': 1000000.0, + 'TxThroughput': 2000000.0, + 'CurrentDropPercentage': 50.0, 'Rate': 100.0, - 'Throughput': 312.5} + 'Throughput': 1000000.0} self.assertEqual(expected, output) self.assertFalse(completed) -- cgit 1.2.3-korg