示例#1
0
    def test__get_samples(self):
        mock_setup_helper = mock.Mock()
        trex_rh = tg_trex.TrexResourceHelper(mock_setup_helper)
        trex_rh.vnfd_helper.interfaces = [{
            'name': 'interface1'
        }, {
            'name': 'interface2'
        }]
        stats = {
            10: {
                'rx_pps': 5,
                'ipackets': 200
            },
            20: {
                'rx_pps': 10,
                'ipackets': 300
            },
            'latency': {
                1: {
                    'latency': 'latency_port_10_pg_id_1'
                },
                2: {
                    'latency': 'latency_port_10_pg_id_2'
                },
                3: {
                    'latency': 'latency_port_20_pg_id_3'
                },
                4: {
                    'latency': 'latency_port_20_pg_id_4'
                }
            }
        }
        port_pg_id = rfc2544.PortPgIDMap()
        port_pg_id.add_port(10)
        port_pg_id.increase_pg_id()
        port_pg_id.increase_pg_id()
        port_pg_id.add_port(20)
        port_pg_id.increase_pg_id()
        port_pg_id.increase_pg_id()

        with mock.patch.object(trex_rh, 'get_stats') as mock_get_stats, \
                mock.patch.object(trex_rh.vnfd_helper, 'port_num') as \
                mock_port_num:
            mock_get_stats.return_value = stats
            mock_port_num.side_effect = [10, 20]
            output = trex_rh._get_samples([10, 20], port_pg_id=port_pg_id)

        interface = output['interface1']
        self.assertEqual(5.0, interface['rx_throughput_fps'])
        self.assertEqual(200, interface['in_packets'])
        self.assertEqual('latency_port_10_pg_id_1', interface['latency'][1])
        self.assertEqual('latency_port_10_pg_id_2', interface['latency'][2])

        interface = output['interface2']
        self.assertEqual(10.0, interface['rx_throughput_fps'])
        self.assertEqual(300, interface['in_packets'])
        self.assertEqual('latency_port_20_pg_id_3', interface['latency'][3])
        self.assertEqual('latency_port_20_pg_id_4', interface['latency'][4])
示例#2
0
 def test_get_pg_ids(self):
     port_pg_id_map = rfc2544.PortPgIDMap()
     port_pg_id_map.add_port(10)
     port_pg_id_map.increase_pg_id()
     port_pg_id_map.increase_pg_id()
     port_pg_id_map.add_port(20)
     port_pg_id_map.increase_pg_id()
     self.assertEqual([1, 2], port_pg_id_map.get_pg_ids(10))
     self.assertEqual([3], port_pg_id_map.get_pg_ids(20))
     self.assertEqual([], port_pg_id_map.get_pg_ids(30))
示例#3
0
 def test_send_traffic_on_tg_error(self):
     mock_setup_helper = mock.Mock()
     vpp_rfc = tg_trex_vpp.TrexVppResourceHelper(mock_setup_helper)
     vpp_rfc.vnfd_helper = base.VnfdHelper(TestTrexTrafficGenVpp.VNFD_0)
     vpp_rfc.client = mock.Mock()
     vpp_rfc.client.get_warnings.return_value = 'get_warnings'
     vpp_rfc.client.get_stats.side_effect = STLError('get_stats')
     vpp_rfc.client.wait_on_traffic.side_effect = STLError(
         'wait_on_traffic')
     port_pg_id = rfc2544.PortPgIDMap()
     port_pg_id.add_port(1)
     port_pg_id.increase_pg_id()
     port_pg_id.add_port(0)
     port_pg_id.increase_pg_id()
     # with self.assertRaises(RuntimeError) as raised:
     vpp_rfc.send_traffic_on_tg([0, 1], port_pg_id, 30, 10000, True)
示例#4
0
 def test__create_streams(self, mock_stream, mock_txcont, mock_latency):
     imix_data = {'64': 25, '512': 75}
     rate = 35
     port_pg_id = rfc2544.PortPgIDMap()
     port_pg_id.add_port(10)
     mock_stream.side_effect = ['stream1', 'stream2']
     mock_txcont.side_effect = ['txcont1', 'txcont2']
     mock_latency.side_effect = ['latency1', 'latency2']
     rfc2544_profile = rfc2544.RFC2544Profile(self.TRAFFIC_PROFILE)
     with mock.patch.object(rfc2544_profile, '_create_single_packet'):
         output = rfc2544_profile._create_streams(imix_data, rate,
                                                  port_pg_id, True)
     self.assertEqual(['stream1', 'stream2'], output)
     mock_latency.assert_has_calls([
         mock.call(pg_id=1), mock.call(pg_id=2)])
     mock_txcont.assert_has_calls([
         mock.call(percentage=float(25 * 35) / 100),
         mock.call(percentage=float(75 * 35) / 100)], any_order=True)
示例#5
0
 def test__create_single_stream_mlr_search(self, mock_stream, mock_txcont,
                                           mock_latency):
     imix_data = {'64': 25, '512': 75}
     mock_stream.side_effect = ['stream1', 'stream2', 'stream3', 'stream4']
     mock_txcont.side_effect = ['txcont1', 'txcont2', 'txcont3', 'txcont4']
     mock_latency.side_effect = ['latency1', 'latency2']
     vpp_rfc2544_profile = vpp_rfc2544.VppRFC2544Profile(
         self.TRAFFIC_PROFILE)
     vpp_rfc2544_profile.max_rate = 14880000
     vpp_rfc2544_profile.port_pg_id = rfc2544.PortPgIDMap()
     vpp_rfc2544_profile.port_pg_id.add_port(10)
     with mock.patch.object(vpp_rfc2544_profile, '_create_single_packet') as \
             mock_create_single_packet:
         mock_create_single_packet.return_value = 64, 100
         output = vpp_rfc2544_profile._create_single_stream(
             10, imix_data, 100, 0.0)
     self.assertEqual(['stream1', 'stream2', 'stream3', 'stream4'], output)
     mock_latency.assert_has_calls([mock.call(pg_id=1), mock.call(pg_id=2)])
     mock_txcont.assert_has_calls(
         [mock.call(pps=25 * 100 / 100),
          mock.call(pps=75 * 100 / 100)],
         any_order=True)
示例#6
0
 def test_increase_pg_id_last_port(self):
     port_pg_id_map = rfc2544.PortPgIDMap()
     port_pg_id_map.add_port(10)
     self.assertEqual(1, port_pg_id_map.increase_pg_id())
     self.assertEqual([1], port_pg_id_map.get_pg_ids(10))
     self.assertEqual(10, port_pg_id_map._last_port)
示例#7
0
 def test_increase_pg_id_no_port(self):
     port_pg_id_map = rfc2544.PortPgIDMap()
     self.assertIsNone(port_pg_id_map.increase_pg_id())
示例#8
0
 def test_add_port(self):
     port_pg_id_map = rfc2544.PortPgIDMap()
     port_pg_id_map.add_port(10)
     self.assertEqual(10, port_pg_id_map._last_port)
     self.assertEqual([], port_pg_id_map._port_pg_id_map[10])
示例#9
0
 def test_send_traffic_on_tg(self):
     stats = {
         0: {
             "ibytes": 55549120,
             "ierrors": 0,
             "ipackets": 867955,
             "obytes": 55549696,
             "oerrors": 0,
             "opackets": 867964,
             "rx_bps": 104339032.0,
             "rx_bps_L1": 136944984.0,
             "rx_pps": 203787.2,
             "rx_util": 1.36944984,
             "tx_bps": 134126008.0,
             "tx_bps_L1": 176040392.0,
             "tx_pps": 261964.9,
             "tx_util": 1.7604039200000001
         },
         1: {
             "ibytes": 55549696,
             "ierrors": 0,
             "ipackets": 867964,
             "obytes": 55549120,
             "oerrors": 0,
             "opackets": 867955,
             "rx_bps": 134119648.0,
             "rx_bps_L1": 176032032.0,
             "rx_pps": 261952.4,
             "rx_util": 1.76032032,
             "tx_bps": 104338192.0,
             "tx_bps_L1": 136943872.0,
             "tx_pps": 203785.5,
             "tx_util": 1.36943872
         },
         "flow_stats": {
             1: {
                 "rx_bps": {
                     "0": 0,
                     "1": 0,
                     "total": 0
                 },
                 "rx_bps_l1": {
                     "0": 0.0,
                     "1": 0.0,
                     "total": 0.0
                 },
                 "rx_bytes": {
                     "0": 6400,
                     "1": 0,
                     "total": 6400
                 },
                 "rx_pkts": {
                     "0": 100,
                     "1": 0,
                     "total": 100
                 },
                 "rx_pps": {
                     "0": 0,
                     "1": 0,
                     "total": 0
                 },
                 "tx_bps": {
                     "0": 0,
                     "1": 0,
                     "total": 0
                 },
                 "tx_bps_l1": {
                     "0": 0.0,
                     "1": 0.0,
                     "total": 0.0
                 },
                 "tx_bytes": {
                     "0": 0,
                     "1": 6400,
                     "total": 6400
                 },
                 "tx_pkts": {
                     "0": 0,
                     "1": 100,
                     "total": 100
                 },
                 "tx_pps": {
                     "0": 0,
                     "1": 0,
                     "total": 0
                 }
             },
             2: {
                 "rx_bps": {
                     "0": 0,
                     "1": 0,
                     "total": 0
                 },
                 "rx_bps_l1": {
                     "0": 0.0,
                     "1": 0.0,
                     "total": 0.0
                 },
                 "rx_bytes": {
                     "0": 0,
                     "1": 6464,
                     "total": 6464
                 },
                 "rx_pkts": {
                     "0": 0,
                     "1": 101,
                     "total": 101
                 },
                 "rx_pps": {
                     "0": 0,
                     "1": 0,
                     "total": 0
                 },
                 "tx_bps": {
                     "0": 0,
                     "1": 0,
                     "total": 0
                 },
                 "tx_bps_l1": {
                     "0": 0.0,
                     "1": 0.0,
                     "total": 0.0
                 },
                 "tx_bytes": {
                     "0": 6464,
                     "1": 0,
                     "total": 6464
                 },
                 "tx_pkts": {
                     "0": 101,
                     "1": 0,
                     "total": 101
                 },
                 "tx_pps": {
                     "0": 0,
                     "1": 0,
                     "total": 0
                 }
             },
             "global": {
                 "rx_err": {
                     "0": 0,
                     "1": 0
                 },
                 "tx_err": {
                     "0": 0,
                     "1": 0
                 }
             }
         },
         "global": {
             "bw_per_core": 45.6,
             "cpu_util": 0.1494,
             "queue_full": 0,
             "rx_bps": 238458672.0,
             "rx_cpu_util": 4.751e-05,
             "rx_drop_bps": 0.0,
             "rx_pps": 465739.6,
             "tx_bps": 238464208.0,
             "tx_pps": 465750.4
         },
         "latency": {
             1: {
                 "err_cntrs": {
                     "dropped": 0,
                     "dup": 0,
                     "out_of_order": 0,
                     "seq_too_high": 0,
                     "seq_too_low": 0
                 },
                 "latency": {
                     "average": 63.375,
                     "histogram": {
                         "20": 1,
                         "30": 18,
                         "40": 12,
                         "50": 10,
                         "60": 12,
                         "70": 11,
                         "80": 6,
                         "90": 10,
                         "100": 20
                     },
                     "jitter": 23,
                     "last_max": 122,
                     "total_max": 123,
                     "total_min": 20
                 }
             },
             2: {
                 "err_cntrs": {
                     "dropped": 0,
                     "dup": 0,
                     "out_of_order": 0,
                     "seq_too_high": 0,
                     "seq_too_low": 0
                 },
                 "latency": {
                     "average": 74,
                     "histogram": {
                         "60": 20,
                         "70": 10,
                         "80": 3,
                         "90": 4,
                         "100": 64
                     },
                     "jitter": 6,
                     "last_max": 83,
                     "total_max": 135,
                     "total_min": 60
                 }
             },
             "global": {
                 "bad_hdr": 0,
                 "old_flow": 0
             }
         },
         "total": {
             "ibytes": 111098816,
             "ierrors": 0,
             "ipackets": 1735919,
             "obytes": 111098816,
             "oerrors": 0,
             "opackets": 1735919,
             "rx_bps": 238458680.0,
             "rx_bps_L1": 312977016.0,
             "rx_pps": 465739.6,
             "rx_util": 3.1297701599999996,
             "tx_bps": 238464200.0,
             "tx_bps_L1": 312984264.0,
             "tx_pps": 465750.4,
             "tx_util": 3.12984264
         }
     }
     mock_setup_helper = mock.Mock()
     vpp_rfc = tg_trex_vpp.TrexVppResourceHelper(mock_setup_helper)
     vpp_rfc.vnfd_helper = base.VnfdHelper(TestTrexTrafficGenVpp.VNFD_0)
     vpp_rfc.client = mock.Mock()
     vpp_rfc.client.get_warnings.return_value = 'get_warnings'
     vpp_rfc.client.get_stats.return_value = stats
     port_pg_id = rfc2544.PortPgIDMap()
     port_pg_id.add_port(1)
     port_pg_id.increase_pg_id()
     port_pg_id.add_port(0)
     port_pg_id.increase_pg_id()
     self.assertEqual(
         stats,
         vpp_rfc.send_traffic_on_tg([0, 1], port_pg_id, 30, 10000, True))
示例#10
0
 def test_generate_samples_error(self):
     stats = {
         0: {
             "ibytes": 55549120,
             "ierrors": 0,
             "ipackets": 867955,
             "obytes": 55549696,
             "oerrors": 0,
             "opackets": 867964,
             "rx_bps": 104339032.0,
             "rx_bps_L1": 136944984.0,
             "rx_pps": 203787.2,
             "rx_util": 1.36944984,
             "tx_bps": 134126008.0,
             "tx_bps_L1": 176040392.0,
             "tx_pps": 261964.9,
             "tx_util": 1.7604039200000001
         },
         1: {
             "ibytes": 55549696,
             "ierrors": 0,
             "ipackets": 867964,
             "obytes": 55549120,
             "oerrors": 0,
             "opackets": 867955,
             "rx_bps": 134119648.0,
             "rx_bps_L1": 176032032.0,
             "rx_pps": 261952.4,
             "rx_util": 1.76032032,
             "tx_bps": 104338192.0,
             "tx_bps_L1": 136943872.0,
             "tx_pps": 203785.5,
             "tx_util": 1.36943872
         },
         "flow_stats": {
             1: {
                 "rx_bps": {
                     "0": 0,
                     "1": 0,
                     "total": 0
                 },
                 "rx_bps_l1": {
                     "0": 0.0,
                     "1": 0.0,
                     "total": 0.0
                 },
                 "rx_bytes": {
                     "0": 6400,
                     "1": 0,
                     "total": 6400
                 },
                 "rx_pkts": {
                     "0": 100,
                     "1": 0,
                     "total": 100
                 },
                 "rx_pps": {
                     "0": 0,
                     "1": 0,
                     "total": 0
                 },
                 "tx_bps": {
                     "0": 0,
                     "1": 0,
                     "total": 0
                 },
                 "tx_bps_l1": {
                     "0": 0.0,
                     "1": 0.0,
                     "total": 0.0
                 },
                 "tx_bytes": {
                     "0": 0,
                     "1": 6400,
                     "total": 6400
                 },
                 "tx_pkts": {
                     "0": 0,
                     "1": 100,
                     "total": 100
                 },
                 "tx_pps": {
                     "0": 0,
                     "1": 0,
                     "total": 0
                 }
             },
             2: {
                 "rx_bps": {
                     "0": 0,
                     "1": 0,
                     "total": 0
                 },
                 "rx_bps_l1": {
                     "0": 0.0,
                     "1": 0.0,
                     "total": 0.0
                 },
                 "rx_bytes": {
                     "0": 0,
                     "1": 6464,
                     "total": 6464
                 },
                 "rx_pkts": {
                     "0": 0,
                     "1": 101,
                     "total": 101
                 },
                 "rx_pps": {
                     "0": 0,
                     "1": 0,
                     "total": 0
                 },
                 "tx_bps": {
                     "0": 0,
                     "1": 0,
                     "total": 0
                 },
                 "tx_bps_l1": {
                     "0": 0.0,
                     "1": 0.0,
                     "total": 0.0
                 },
                 "tx_bytes": {
                     "0": 6464,
                     "1": 0,
                     "total": 6464
                 },
                 "tx_pkts": {
                     "0": 101,
                     "1": 0,
                     "total": 101
                 },
                 "tx_pps": {
                     "0": 0,
                     "1": 0,
                     "total": 0
                 }
             },
             "global": {
                 "rx_err": {
                     "0": 0,
                     "1": 0
                 },
                 "tx_err": {
                     "0": 0,
                     "1": 0
                 }
             }
         },
         "global": {
             "bw_per_core": 45.6,
             "cpu_util": 0.1494,
             "queue_full": 0,
             "rx_bps": 238458672.0,
             "rx_cpu_util": 4.751e-05,
             "rx_drop_bps": 0.0,
             "rx_pps": 465739.6,
             "tx_bps": 238464208.0,
             "tx_pps": 465750.4
         },
         "latency": {
             1: {
                 "err_cntrs": {
                     "dropped": 0,
                     "dup": 0,
                     "out_of_order": 0,
                     "seq_too_high": 0,
                     "seq_too_low": 0
                 },
                 "latency": {
                     "average": "err",
                     "histogram": {
                         "20": 1,
                         "30": 18,
                         "40": 12,
                         "50": 10,
                         "60": 12,
                         "70": 11,
                         "80": 6,
                         "90": 10,
                         "100": 20
                     },
                     "jitter": 23,
                     "last_max": 122,
                     "total_max": "err",
                     "total_min": "err"
                 }
             },
             2: {
                 "err_cntrs": {
                     "dropped": 0,
                     "dup": 0,
                     "out_of_order": 0,
                     "seq_too_high": 0,
                     "seq_too_low": 0
                 },
                 "latency": {
                     "average": 74,
                     "histogram": {
                         "60": 20,
                         "70": 10,
                         "80": 3,
                         "90": 4,
                         "100": 64
                     },
                     "jitter": 6,
                     "last_max": 83,
                     "total_max": 135,
                     "total_min": 60
                 }
             },
             "global": {
                 "bad_hdr": 0,
                 "old_flow": 0
             }
         },
         "total": {
             "ibytes": 111098816,
             "ierrors": 0,
             "ipackets": 1735919,
             "obytes": 111098816,
             "oerrors": 0,
             "opackets": 1735919,
             "rx_bps": 238458680.0,
             "rx_bps_L1": 312977016.0,
             "rx_pps": 465739.6,
             "rx_util": 3.1297701599999996,
             "tx_bps": 238464200.0,
             "tx_bps_L1": 312984264.0,
             "tx_pps": 465750.4,
             "tx_util": 3.12984264
         }
     }
     expected = {
         'xe0': {
             'in_packets': 867955,
             'latency': {
                 2: {
                     'avg_latency': 74.0,
                     'max_latency': 135.0,
                     'min_latency': 60.0
                 }
             },
             'out_packets': 867964,
             'rx_throughput_bps': 104339032.0,
             'rx_throughput_fps': 203787.2,
             'tx_throughput_bps': 134126008.0,
             'tx_throughput_fps': 261964.9
         },
         'xe1': {
             'in_packets': 867964,
             'latency': {
                 1: {
                     'avg_latency': -1.0,
                     'max_latency': -1.0,
                     'min_latency': -1.0
                 }
             },
             'out_packets': 867955,
             'rx_throughput_bps': 134119648.0,
             'rx_throughput_fps': 261952.4,
             'tx_throughput_bps': 104338192.0,
             'tx_throughput_fps': 203785.5
         }
     }
     mock_setup_helper = mock.Mock()
     vpp_rfc = tg_trex_vpp.TrexVppResourceHelper(mock_setup_helper)
     vpp_rfc.vnfd_helper = base.VnfdHelper(TestTrexTrafficGenVpp.VNFD_0)
     vpp_rfc.get_stats = mock.Mock()
     vpp_rfc.get_stats.return_value = stats
     port_pg_id = rfc2544.PortPgIDMap()
     port_pg_id.add_port(1)
     port_pg_id.increase_pg_id()
     port_pg_id.add_port(0)
     port_pg_id.increase_pg_id()
     self.assertEqual(
         expected,
         vpp_rfc.generate_samples(stats=None,
                                  ports=[0, 1],
                                  port_pg_id=port_pg_id,
                                  latency=True))