Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor storm_control tests #321

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import math

from dent_os_testbed.lib.devlink.devlink_port import DevlinkPort
from dent_os_testbed.lib.tc.tc_filter import TcFilter

Expand All @@ -16,6 +18,25 @@ async def devlink_rate_value(dev, name, value, cmode=False, device_host_name=Tru
assert kbyte_value == value, f"Verify that storm control rate configured is '{value}' kbps.\n"


async def verify_expected_rx_rate(kbyte_value, stats, rx_ports, deviation=0.10):
"""
Verify expected rx_rate in bytes on ports
Args:
kbyte_value (int): Kbyte per sec rate
stats (stats_object): Output of tgen_utils_get_traffic_stats
rx_ports (list): list of Rx ports which rate should be verified
deviation (int): Permissible deviation percentage
"""
collected = {row['Port Name']:
{'tx_rate': row['Bytes Tx. Rate'], 'rx_rate': row['Bytes Rx. Rate']} for row in stats.Rows}
exp_rate = kbyte_value*1000
for port in rx_ports:
rx_name = port.split('_')[0]
res = math.isclose(exp_rate, float(collected[rx_name]['rx_rate']), rel_tol=deviation)
assert res, f"The rate is not limited by storm control, \
actual rate {float(collected[rx_name]['rx_rate'])} istead of {exp_rate}."


async def tc_filter_add(dev, vlan_id, src_mac, dst_mac, rate, burst, device_host_name=True):
out = await TcFilter.add(
input_data=[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import pytest
import random
import asyncio

from dent_os_testbed.test.test_suite.functional.storm_control.storm_control_utils import verify_expected_rx_rate
from dent_os_testbed.test.test_suite.functional.storm_control.storm_control_utils import devlink_rate_value
from dent_os_testbed.utils.test_utils.cleanup_utils import cleanup_kbyte_per_sec_rate_value
from dent_os_testbed.lib.bridge.bridge_vlan import BridgeVlan
from dent_os_testbed.lib.ip.ip_link import IpLink
from random import randrange

from dent_os_testbed.utils.test_utils.tgen_utils import (
tgen_utils_get_dent_devices_with_tgen,
Expand All @@ -14,7 +15,7 @@
tgen_utils_get_traffic_stats,
tgen_utils_setup_streams,
tgen_utils_start_traffic,
tgen_utils_get_loss
tgen_utils_stop_traffic
)

pytestmark = [
Expand All @@ -38,10 +39,11 @@ async def test_storm_control_br_and_mc_lag_and_vlan_membership(testbed):
5. Set bridge br0 admin state UP.
6. Set ports swp2, swp4 master br0.
7. Set bonds bond1, bond2 master br0.
8. Set up the following streams:
8. Set storm control rate limit rule for all TG port.
9. Set up the following streams:
- Ixia port 2: broadcast and multicast streams with random generated size of packet.
9. Transmit continues traffic by TG.
10. Verify the RX rate on the RX port is as expected - the rate is limited by storm control.
10. Transmit continues traffic by TG.
11. Verify the RX rate on the RX port is as expected - the rate is limited by storm control.
"""

bridge = 'br0'
Expand All @@ -52,8 +54,9 @@ async def test_storm_control_br_and_mc_lag_and_vlan_membership(testbed):
device_host_name = dent_dev.host_name
tg_ports = tgen_dev.links_dict[device_host_name][0]
ports = tgen_dev.links_dict[device_host_name][1]
kbyte_value_mc = 42099
kbyte_value_bc = 12010
traffic_duration = 15
pps_value = 1000

for x in range(2):
out = await IpLink.add(
Expand Down Expand Up @@ -117,27 +120,19 @@ async def test_storm_control_br_and_mc_lag_and_vlan_membership(testbed):
for x in range(2)]}])
assert out[0][device_host_name]['rc'] == 0, f"Verify that entities added to vid '1' and '2'.\n{out}"

await devlink_rate_value(dev=f'pci/0000:01:00.0/{ports[0].replace("swp","")}',
name='unk_uc_kbyte_per_sec_rate', value=94404,
cmode='runtime', device_host_name=device_host_name, set=True, verify=True)
await devlink_rate_value(dev=f'pci/0000:01:00.0/{ports[1].replace("swp","")}',
name='bc_kbyte_per_sec_rate', value=1210,
cmode='runtime', device_host_name=device_host_name, set=True, verify=True)
await devlink_rate_value(dev=f'pci/0000:01:00.0/{ports[1].replace("swp","")}',
name='unreg_mc_kbyte_per_sec_rate', value=35099,
cmode='runtime', device_host_name=device_host_name, set=True, verify=True)
await devlink_rate_value(dev=f'pci/0000:01:00.0/{ports[1].replace("swp","")}',
name='unk_uc_kbyte_per_sec_rate', value=37519,
cmode='runtime', device_host_name=device_host_name, set=True, verify=True)
await devlink_rate_value(dev=f'pci/0000:01:00.0/{ports[2].replace("swp","")}',
name='bc_kbyte_per_sec_rate', value=32678,
cmode='runtime', device_host_name=device_host_name, set=True, verify=True)
await devlink_rate_value(dev=f'pci/0000:01:00.0/{ports[2].replace("swp","")}',
name='unk_uc_kbyte_per_sec_rate', value=36309,
cmode='runtime', device_host_name=device_host_name, set=True, verify=True)
await devlink_rate_value(dev=f'pci/0000:01:00.0/{ports[3].replace("swp","")}',
name='unreg_mc_kbyte_per_sec_rate', value=83511,
cmode='runtime', device_host_name=device_host_name, set=True, verify=True)
params = [
{'port': ports[0], 'name': 'unk_uc_kbyte_per_sec_rate', 'value': 94404},
{'port': ports[1], 'name': 'bc_kbyte_per_sec_rate', 'value': kbyte_value_bc},
{'port': ports[1], 'name': 'unreg_mc_kbyte_per_sec_rate', 'value': kbyte_value_mc},
{'port': ports[1], 'name': 'unk_uc_kbyte_per_sec_rate', 'value': 37519},
{'port': ports[2], 'name': 'bc_kbyte_per_sec_rate', 'value': 32678},
{'port': ports[2], 'name': 'unk_uc_kbyte_per_sec_rate', 'value': 36309},
{'port': ports[3], 'name': 'unreg_mc_kbyte_per_sec_rate', 'value': 83511}
]
for value in params:
await devlink_rate_value(dev=f'pci/0000:01:00.0/{value["port"].replace("swp","")}',
name=value['name'], value=value['value'],
cmode='runtime', device_host_name=device_host_name, set=True, verify=True)

try:
address_map = (
Expand Down Expand Up @@ -167,8 +162,9 @@ async def test_storm_control_br_and_mc_lag_and_vlan_membership(testbed):
'ip_destination': dev_groups[tg_ports[0]][0]['name'],
'srcMac': 'b4:87:2a:9f:73:d5',
'dstMac': 'ff:ff:ff:ff:ff:ff',
'frameSize': random.randint(128, 1000),
'rate': pps_value,
'frameSize': randrange(100, 1500),
'frame_rate_type': 'line_rate',
'rate': 30,
'protocol': '0x0800',
'type': 'raw'
},
Expand All @@ -179,8 +175,9 @@ async def test_storm_control_br_and_mc_lag_and_vlan_membership(testbed):
'dstIp': '227.82.186.172',
'srcMac': 'da:db:ce:9c:11:6f',
'dstMac': '01:00:5E:51:ba:ac',
'frameSize': random.randint(128, 1000),
'rate': pps_value,
'frameSize': randrange(100, 1500),
'frame_rate_type': 'line_rate',
'rate': 30,
'protocol': '0x0800',
'type': 'raw'
},
Expand All @@ -191,8 +188,9 @@ async def test_storm_control_br_and_mc_lag_and_vlan_membership(testbed):
'dstIp': '227.83.186.172',
'srcMac': 'da:db:ce:9c:12:6f',
'dstMac': '01:00:5E:53:ba:ac',
'frameSize': random.randint(128, 1000),
'rate': pps_value,
'frameSize': randrange(100, 1500),
'frame_rate_type': 'line_rate',
'rate': 30,
'protocol': '0x0800',
'type': 'raw'
},
Expand All @@ -203,8 +201,9 @@ async def test_storm_control_br_and_mc_lag_and_vlan_membership(testbed):
'dstIp': '227.84.186.172',
'srcMac': 'da:db:ce:9c:13:6f',
'dstMac': '01:00:5E:55:ba:ac',
'frameSize': random.randint(128, 1000),
'rate': pps_value,
'frameSize': randrange(100, 1500),
'frame_rate_type': 'line_rate',
'rate': 30,
'protocol': '0x0800',
'type': 'raw'
}
Expand All @@ -215,15 +214,10 @@ async def test_storm_control_br_and_mc_lag_and_vlan_membership(testbed):
await asyncio.sleep(traffic_duration)

# check the traffic stats
stats = await tgen_utils_get_traffic_stats(tgen_dev, 'Flow Statistics')
expected_loss = {
'stream_br': 0,
'stream_1_mc': 0,
'stream_2_mc': 100,
'stream_3_mc': 100
}
for row in stats.Rows:
assert tgen_utils_get_loss(row) == expected_loss[row['Traffic Item']], \
'Verify that traffic forwarded/not forwarded in accordance.'
stats = await tgen_utils_get_traffic_stats(tgen_dev, 'Port Statistics')
kbyte_value = kbyte_value_bc+kbyte_value_mc
await verify_expected_rx_rate(kbyte_value, stats, rx_ports=[streams['stream_br']['ip_destination']],
deviation=0.10)
finally:
await cleanup_kbyte_per_sec_rate_value(dent_dev, all_values=True)
await tgen_utils_stop_traffic(tgen_dev)
await cleanup_kbyte_per_sec_rate_value(dent_dev, tgen_dev, all_values=True)
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import pytest
import random
import asyncio

from dent_os_testbed.test.test_suite.functional.storm_control.storm_control_utils import verify_expected_rx_rate
from dent_os_testbed.test.test_suite.functional.storm_control.storm_control_utils import devlink_rate_value
from dent_os_testbed.utils.test_utils.cleanup_utils import cleanup_kbyte_per_sec_rate_value
from dent_os_testbed.lib.bridge.bridge_vlan import BridgeVlan
from dent_os_testbed.lib.ip.ip_link import IpLink
from random import randrange

from dent_os_testbed.utils.test_utils.tgen_utils import (
tgen_utils_get_dent_devices_with_tgen,
Expand All @@ -14,7 +15,7 @@
tgen_utils_get_traffic_stats,
tgen_utils_setup_streams,
tgen_utils_start_traffic,
tgen_utils_get_loss
tgen_utils_stop_traffic
)

pytestmark = [
Expand All @@ -38,10 +39,11 @@ async def test_storm_control_br_and_unk_un_and_vlan_membership(testbed):
5. Set bridge br0 admin state UP.
6. Set ports swp2, swp4 master br0.
7. Set bonds bond1, bond2 master br0.
8. Set up the following streams:
8. Set storm control rate limit rule for all TG port.
9. Set up the following streams:
- Ixia port 3: broadcast and unknown unicast streams with random generated size of packet.
9. Transmit continues traffic by TG.
10. Verify the RX rate on the RX port is as expected - the rate is limited by storm control.
10. Transmit continues traffic by TG.
11. Verify the RX rate on the RX port is as expected - the rate is limited by storm control.
"""

bridge = 'br0'
Expand All @@ -52,8 +54,9 @@ async def test_storm_control_br_and_unk_un_and_vlan_membership(testbed):
device_host_name = dent_dev.host_name
tg_ports = tgen_dev.links_dict[device_host_name][0]
ports = tgen_dev.links_dict[device_host_name][1]
kbyte_value_unk_uc = 20511
kbyte_value_bc = 32678
traffic_duration = 15
pps_value = 1000

for x in range(2):
out = await IpLink.add(
Expand Down Expand Up @@ -117,27 +120,19 @@ async def test_storm_control_br_and_unk_un_and_vlan_membership(testbed):
for x in range(2)]}])
assert out[0][device_host_name]['rc'] == 0, f"Verify that entities added to vid '1' and '2'.\n{out}"

await devlink_rate_value(dev=f'pci/0000:01:00.0/{ports[0].replace("swp","")}',
name='unk_uc_kbyte_per_sec_rate', value=94404,
cmode='runtime', device_host_name=device_host_name, set=True, verify=True)
await devlink_rate_value(dev=f'pci/0000:01:00.0/{ports[1].replace("swp","")}',
name='bc_kbyte_per_sec_rate', value=1210,
cmode='runtime', device_host_name=device_host_name, set=True, verify=True)
await devlink_rate_value(dev=f'pci/0000:01:00.0/{ports[1].replace("swp","")}',
name='unreg_mc_kbyte_per_sec_rate', value=35099,
cmode='runtime', device_host_name=device_host_name, set=True, verify=True)
await devlink_rate_value(dev=f'pci/0000:01:00.0/{ports[1].replace("swp","")}',
name='unk_uc_kbyte_per_sec_rate', value=37519,
cmode='runtime', device_host_name=device_host_name, set=True, verify=True)
await devlink_rate_value(dev=f'pci/0000:01:00.0/{ports[2].replace("swp","")}',
name='bc_kbyte_per_sec_rate', value=32678,
cmode='runtime', device_host_name=device_host_name, set=True, verify=True)
await devlink_rate_value(dev=f'pci/0000:01:00.0/{ports[2].replace("swp","")}',
name='unk_uc_kbyte_per_sec_rate', value=36309,
cmode='runtime', device_host_name=device_host_name, set=True, verify=True)
await devlink_rate_value(dev=f'pci/0000:01:00.0/{ports[3].replace("swp","")}',
name='unreg_mc_kbyte_per_sec_rate', value=83511,
cmode='runtime', device_host_name=device_host_name, set=True, verify=True)
params = [
{'port': ports[0], 'name': 'unk_uc_kbyte_per_sec_rate', 'value': 94404},
{'port': ports[1], 'name': 'bc_kbyte_per_sec_rate', 'value': 1210},
{'port': ports[1], 'name': 'unreg_mc_kbyte_per_sec_rate', 'value': 35099},
{'port': ports[1], 'name': 'unk_uc_kbyte_per_sec_rate', 'value': 37519},
{'port': ports[2], 'name': 'bc_kbyte_per_sec_rate', 'value': kbyte_value_bc},
{'port': ports[2], 'name': 'unk_uc_kbyte_per_sec_rate', 'value': kbyte_value_unk_uc},
{'port': ports[3], 'name': 'unreg_mc_kbyte_per_sec_rate', 'value': 83511}
]
for value in params:
await devlink_rate_value(dev=f'pci/0000:01:00.0/{value["port"].replace("swp","")}',
name=value['name'], value=value['value'],
cmode='runtime', device_host_name=device_host_name, set=True, verify=True)

try:
address_map = (
Expand All @@ -164,11 +159,12 @@ async def test_storm_control_br_and_unk_un_and_vlan_membership(testbed):
streams = {
'stream_br': {
'ip_source': dev_groups[tg_ports[2]][0]['name'],
'ip_destination': dev_groups[tg_ports[3]][0]['name'],
'ip_destination': dev_groups[tg_ports[0]][0]['name'],
'srcMac': 'b4:87:2a:9f:75:d5',
'dstMac': 'ff:ff:ff:ff:ff:ff',
'frameSize': random.randint(128, 1000),
'rate': pps_value,
'frameSize': randrange(100, 1500),
'frame_rate_type': 'line_rate',
'rate': 30,
'protocol': '0x0800',
'type': 'raw'
},
Expand All @@ -177,8 +173,9 @@ async def test_storm_control_br_and_unk_un_and_vlan_membership(testbed):
'ip_destination': dev_groups[tg_ports[0]][0]['name'],
'srcMac': '1c:30:27:a1:3c:bc',
'dstMac': '4a:4c:30:4e:9d:1e',
'frameSize': random.randint(128, 1000),
'rate': pps_value,
'frameSize': randrange(100, 1500),
'frame_rate_type': 'line_rate',
'rate': 30,
'protocol': '0x0800',
'type': 'raw'
},
Expand All @@ -189,8 +186,9 @@ async def test_storm_control_br_and_unk_un_and_vlan_membership(testbed):
'dstIp': '0.0.0.0',
'srcMac': '8:d4:6b:50:c9:f9',
'dstMac': 'b6:ee:e2:ef:d7:68',
'frameSize': random.randint(128, 1000),
'rate': pps_value,
'frameSize': randrange(100, 1500),
'frame_rate_type': 'line_rate',
'rate': 30,
'protocol': '0x0800',
'type': 'raw'
},
Expand All @@ -199,8 +197,9 @@ async def test_storm_control_br_and_unk_un_and_vlan_membership(testbed):
'ip_destination': dev_groups[tg_ports[3]][0]['name'],
'srcMac': 'ae:8a:1d:f3:1d:a5',
'dstMac': '6e:f8:5a:c0:66:84',
'frameSize': random.randint(128, 1000),
'rate': pps_value,
'frameSize': randrange(100, 1500),
'frame_rate_type': 'line_rate',
'rate': 30,
'protocol': '0x0800',
'type': 'raw'
}
Expand All @@ -211,15 +210,10 @@ async def test_storm_control_br_and_unk_un_and_vlan_membership(testbed):
await asyncio.sleep(traffic_duration)

# check the traffic stats
stats = await tgen_utils_get_traffic_stats(tgen_dev, 'Flow Statistics')
expected_loss = {
'stream_br': 0,
'stream_1_unk_un': 100,
'stream_2_unk_un': 100,
'stream_3_unk_un': 0
}
for row in stats.Rows:
assert tgen_utils_get_loss(row) == expected_loss[row['Traffic Item']], \
'Verify that traffic forwarded/not forwarded in accordance.'
stats = await tgen_utils_get_traffic_stats(tgen_dev, 'Port Statistics')
kbyte_value = kbyte_value_bc+kbyte_value_unk_uc
await verify_expected_rx_rate(kbyte_value, stats, rx_ports=[streams['stream_3_unk_un']['ip_destination']],
deviation=0.10)
finally:
await cleanup_kbyte_per_sec_rate_value(dent_dev, all_values=True)
await tgen_utils_stop_traffic(tgen_dev)
await cleanup_kbyte_per_sec_rate_value(dent_dev, tgen_dev, all_values=True)
Loading