From 783fd4cd6283fc873e989d7de1e56c13a46fc31a Mon Sep 17 00:00:00 2001 From: Dipendu Ghosh Date: Thu, 26 Sep 2024 14:56:50 +0530 Subject: [PATCH] removing e2e tag from custom and ipv6_imix. add ipsec_imix and tcp_imix tests --- tests/imix/test_custom_imix_e2e.py | 20 ++--- tests/imix/test_ipsec_imix_predefined_e2e.py | 86 +++++++++++++++++++ tests/imix/test_ipv6_imix_predefined_e2e.py | 16 ++-- tests/imix/test_tcp_imix_predefined_e2e.py | 88 ++++++++++++++++++++ 4 files changed, 192 insertions(+), 18 deletions(-) create mode 100644 tests/imix/test_ipsec_imix_predefined_e2e.py create mode 100644 tests/imix/test_tcp_imix_predefined_e2e.py diff --git a/tests/imix/test_custom_imix_e2e.py b/tests/imix/test_custom_imix_e2e.py index ed3da5673..2865b397c 100644 --- a/tests/imix/test_custom_imix_e2e.py +++ b/tests/imix/test_custom_imix_e2e.py @@ -2,12 +2,11 @@ import time -@pytest.mark.e2e def test_stats_filter_e2e(api, b2b_raw_config, utils): """ configure flows with ipv4 imix - Send ipv4 imix predefined traffic - + Validation: 1) Get port statistics based on port name & column names and assert @@ -20,17 +19,17 @@ def test_stats_filter_e2e(api, b2b_raw_config, utils): b2b_raw_config.flows.clear() config = b2b_raw_config - + d1, d2 = config.devices.device(name="d1").device(name="d2") eth1 = d1.ethernets.add() eth1.name = "eth1" - eth1.port_name = config.ports[0].name + eth1.connection.port_name = config.ports[0].name eth1.mac = "00:ad:aa:13:11:01" eth2 = d2.ethernets.add() eth2.name = "eth2" - eth2.port_name = config.ports[1].name + eth2.connection.port_name = config.ports[1].name eth2.mac = "00:ad:aa:13:11:02" ip1 = eth1.ipv4_addresses.add() @@ -69,7 +68,9 @@ def test_stats_filter_e2e(api, b2b_raw_config, utils): timeout_seconds=20, ) utils.stop_traffic(api, b2b_raw_config) - captures_ok(api, b2b_raw_config, utils, no_of_packets, config.ports[1].name ) + captures_ok( + api, b2b_raw_config, utils, no_of_packets, config.ports[1].name + ) def results_ok(api, utils, packets): @@ -83,9 +84,9 @@ def results_ok(api, utils, packets): print("Checking byte count") flow_rx = sum([f.bytes_rx for f in flow_results]) bytes_ok = 300000 <= flow_rx <= 500000 - - print ("fraemes ok {}" .format(frames_ok)) - print ("bytes ok {}".format(bytes_ok)) + + print("fraemes ok {}".format(frames_ok)) + print("bytes ok {}".format(bytes_ok)) return frames_ok and bytes_ok @@ -99,4 +100,3 @@ def captures_ok(api, cfg, utils, packets, name): assert len(buf) in [92, 560, 600] pkt_count += 1 assert pkt_count == packets - diff --git a/tests/imix/test_ipsec_imix_predefined_e2e.py b/tests/imix/test_ipsec_imix_predefined_e2e.py new file mode 100644 index 000000000..aa71995f3 --- /dev/null +++ b/tests/imix/test_ipsec_imix_predefined_e2e.py @@ -0,0 +1,86 @@ +import pytest +import time + + +def test_stats_filter_e2e(api, b2b_raw_config, utils): + """ + configure flows with ipv4 imix + - Send ipv4 imix predefined traffic + + + Validation: + 1) Get port statistics based on port name & column names and assert + each port & column has returned the values and assert + 2) Get flow statistics based on flow name & column names and assert + each flow & column has returned the values and assert + """ + + no_of_packets = 1000 + + b2b_raw_config.flows.clear() + config = b2b_raw_config + + d1, d2 = config.devices.device(name="d1").device(name="d2") + + eth1 = d1.ethernets.add() + eth1.name = "eth1" + eth1.connection.port_name = config.ports[0].name + eth1.mac = "00:ad:aa:13:11:01" + + eth2 = d2.ethernets.add() + eth2.name = "eth2" + eth2.connection.port_name = config.ports[1].name + eth2.mac = "00:ad:aa:13:11:02" + + ip1 = eth1.ipv4_addresses.add() + ip1.name = "ipv41" + ip1.address = "10.1.1.1" + ip1.gateway = "10.1.1.2" + + ip2 = eth2.ipv4_addresses.add() + ip2.name = "ipv42" + ip2.address = "10.1.1.2" + ip2.gateway = "10.1.1.1" + + f1 = config.flows.flow(name="f1")[-1] + f1.tx_rx.device.tx_names = [ip1.name] + f1.tx_rx.device.rx_names = [ip2.name] + f1.size.weight_pairs.predefined = "imix" + f1.rate.pps = 1000 + f1.duration.fixed_packets.packets = no_of_packets + f1.metrics.enable = True + eth, ip = f1.packet.ethernet().ipv4() + api.set_config(config) + + utils.start_traffic(api, b2b_raw_config) + + utils.wait_for( + lambda: results_ok(api, utils, no_of_packets), + "stats to be as expected", + timeout_seconds=20, + ) + utils.stop_traffic(api, b2b_raw_config) + captures_ok(api, b2b_raw_config, utils, no_of_packets, config.ports[1].name ) + + +def results_ok(api, utils, packets): + """ + Returns true if stats are as expected, false otherwise. + """ + port_results, flow_results = utils.get_all_stats(api) + frames_ok = utils.total_frames_ok(port_results, flow_results, packets) + flow_rx = sum([f.bytes_rx for f in flow_results]) + bytes_ok = 300000 <= flow_rx <= 500000 + return frames_ok and bytes_ok + +def captures_ok(api, cfg, utils, packets, name): + """ + Returns normally if patterns in captured packets are as expected. + """ + pkt_count = 0 + cap_dict = utils.get_all_captures(api, cfg) + for buf in cap_dict[name]: + assert len(buf) in [64, 570, 1518] + pkt_count += 1 + assert pkt_count == packets + diff --git a/tests/imix/test_ipv6_imix_predefined_e2e.py b/tests/imix/test_ipv6_imix_predefined_e2e.py index c55dab172..6f2bed6f0 100644 --- a/tests/imix/test_ipv6_imix_predefined_e2e.py +++ b/tests/imix/test_ipv6_imix_predefined_e2e.py @@ -2,12 +2,11 @@ import time -@pytest.mark.e2e def test_stats_filter_e2e(api, b2b_raw_config, utils): """ configure flows with ipv4 imix - Send ipv4 imix predefined traffic - + Validation: 1) Get port statistics based on port name & column names and assert @@ -20,7 +19,7 @@ def test_stats_filter_e2e(api, b2b_raw_config, utils): b2b_raw_config.flows.clear() config = b2b_raw_config - + d1, d2 = config.devices.device(name="d1").device(name="d2") eth1 = d1.ethernets.add() @@ -61,7 +60,9 @@ def test_stats_filter_e2e(api, b2b_raw_config, utils): timeout_seconds=20, ) utils.stop_traffic(api, b2b_raw_config) - captures_ok(api, b2b_raw_config, utils, no_of_packets, config.ports[1].name ) + captures_ok( + api, b2b_raw_config, utils, no_of_packets, config.ports[1].name + ) def results_ok(api, utils, packets): @@ -75,9 +76,9 @@ def results_ok(api, utils, packets): print("Checking byte count") flow_rx = sum([f.bytes_rx for f in flow_results]) bytes_ok = 300000 <= flow_rx <= 500000 - - print ("fraemes ok {}" .format(frames_ok)) - print ("bytes ok {}".format(bytes_ok)) + + print("fraemes ok {}".format(frames_ok)) + print("bytes ok {}".format(bytes_ok)) return frames_ok and bytes_ok @@ -91,4 +92,3 @@ def captures_ok(api, cfg, utils, packets, name): assert len(buf) in [60, 496, 594, 1518] pkt_count += 1 assert pkt_count == packets - diff --git a/tests/imix/test_tcp_imix_predefined_e2e.py b/tests/imix/test_tcp_imix_predefined_e2e.py new file mode 100644 index 000000000..b3449cd8b --- /dev/null +++ b/tests/imix/test_tcp_imix_predefined_e2e.py @@ -0,0 +1,88 @@ +import pytest +import time + + +def test_stats_filter_e2e(api, b2b_raw_config, utils): + """ + configure flows with ipv4 imix + - Send ipv4 imix predefined traffic + + + Validation: + 1) Get port statistics based on port name & column names and assert + each port & column has returned the values and assert + 2) Get flow statistics based on flow name & column names and assert + each flow & column has returned the values and assert + """ + + no_of_packets = 1000 + + b2b_raw_config.flows.clear() + config = b2b_raw_config + + d1, d2 = config.devices.device(name="d1").device(name="d2") + + eth1 = d1.ethernets.add() + eth1.name = "eth1" + eth1.connection.port_name = config.ports[0].name + eth1.mac = "00:ad:aa:13:11:01" + + eth2 = d2.ethernets.add() + eth2.name = "eth2" + eth2.connection.port_name = config.ports[1].name + eth2.mac = "00:ad:aa:13:11:02" + + ip1 = eth1.ipv4_addresses.add() + ip1.name = "ipv41" + ip1.address = "10.1.1.1" + ip1.gateway = "10.1.1.2" + + ip2 = eth2.ipv4_addresses.add() + ip2.name = "ipv42" + ip2.address = "10.1.1.2" + ip2.gateway = "10.1.1.1" + + f1 = config.flows.flow(name="f1")[-1] + f1.tx_rx.device.tx_names = [ip1.name] + f1.tx_rx.device.rx_names = [ip2.name] + f1.size.weight_pairs.predefined = "tcp_imix" + f1.rate.pps = 1000 + f1.duration.fixed_packets.packets = no_of_packets + f1.metrics.enable = True + eth, ip = f1.packet.ethernet().ipv4() + api.set_config(config) + + utils.start_traffic(api, b2b_raw_config) + + utils.wait_for( + lambda: results_ok(api, utils, no_of_packets), + "stats to be as expected", + timeout_seconds=20, + ) + utils.stop_traffic(api, b2b_raw_config) + captures_ok( + api, b2b_raw_config, utils, no_of_packets, config.ports[1].name + ) + + +def results_ok(api, utils, packets): + """ + Returns true if stats are as expected, false otherwise. + """ + port_results, flow_results = utils.get_all_stats(api) + frames_ok = utils.total_frames_ok(port_results, flow_results, packets) + flow_rx = sum([f.bytes_rx for f in flow_results]) + bytes_ok = 300000 <= flow_rx <= 500000 + return frames_ok and bytes_ok + + +def captures_ok(api, cfg, utils, packets, name): + """ + Returns normally if patterns in captured packets are as expected. + """ + pkt_count = 0 + cap_dict = utils.get_all_captures(api, cfg) + for buf in cap_dict[name]: + assert len(buf) in [64, 570, 1518] + pkt_count += 1 + assert pkt_count == packets