|
2 | 2 | from swsscommon.swsscommon import CounterTable, MacsecCounter
|
3 | 3 | import conftest
|
4 | 4 |
|
| 5 | +import time |
5 | 6 | import functools
|
6 | 7 | import typing
|
7 | 8 | import re
|
@@ -89,6 +90,12 @@ def convert_key(self, key: str):
|
89 | 90 | StateDBTable.SEPARATOR))
|
90 | 91 |
|
91 | 92 |
|
| 93 | +class ConfigTable(Table): |
| 94 | + |
| 95 | + def __init__(self, dvs: conftest.DockerVirtualSwitch, table_name: str): |
| 96 | + super(ConfigTable, self).__init__(dvs.get_config_db(), table_name) |
| 97 | + |
| 98 | + |
92 | 99 | def gen_sci(macsec_system_identifier: str, macsec_port_identifier: int) -> str:
|
93 | 100 | macsec_system_identifier = macsec_system_identifier.translate(
|
94 | 101 | str.maketrans("", "", ":.-"))
|
@@ -808,6 +815,87 @@ def test_macsec_attribute_change(self, dvs: conftest.DockerVirtualSwitch, testlo
|
808 | 815 | macsec_port_identifier,
|
809 | 816 | 0)
|
810 | 817 |
|
| 818 | + def test_macsec_with_portchannel(self, dvs: conftest.DockerVirtualSwitch, testlog): |
| 819 | + |
| 820 | + # Set MACsec enabled on Ethernet0 |
| 821 | + ConfigTable(dvs, "PORT")["Ethernet0"] = {"macsec" : "test"} |
| 822 | + StateDBTable(dvs, "FEATURE")["macsec"] = {"state": "enabled"} |
| 823 | + |
| 824 | + # Setup Port-channel |
| 825 | + ConfigTable(dvs, "PORTCHANNEL")["PortChannel001"] = {"admin": "up", "mtu": "9100", "oper_status": "up"} |
| 826 | + time.sleep(1) |
| 827 | + |
| 828 | + # create port channel member |
| 829 | + ConfigTable(dvs, "PORTCHANNEL_MEMBER")["PortChannel001|Ethernet0"] = {"NULL": "NULL"} |
| 830 | + ConfigTable(dvs, "PORTCHANNEL_INTERFACE")["PortChannel001"] = {"NULL": "NULL"} |
| 831 | + ConfigTable(dvs, "PORTCHANNEL_INTERFACE")["PortChannel001|40.0.0.0/31"] = {"NULL": "NULL"} |
| 832 | + time.sleep(3) |
| 833 | + |
| 834 | + # Check Portchannel member in ASIC db that shouldn't been created before MACsec enabled |
| 835 | + lagmtbl = swsscommon.Table(swsscommon.DBConnector(1, dvs.redis_sock, 0), "ASIC_STATE:SAI_OBJECT_TYPE_LAG_MEMBER") |
| 836 | + lagms = lagmtbl.getKeys() |
| 837 | + assert len(lagms) == 0 |
| 838 | + |
| 839 | + # Create MACsec session |
| 840 | + port_name = "Ethernet0" |
| 841 | + local_mac_address = "00-15-5D-78-FF-C1" |
| 842 | + peer_mac_address = "00-15-5D-78-FF-C2" |
| 843 | + macsec_port_identifier = 1 |
| 844 | + macsec_port = "macsec_eth1" |
| 845 | + sak = "0" * 32 |
| 846 | + auth_key = "0" * 32 |
| 847 | + packet_number = 1 |
| 848 | + ssci = 1 |
| 849 | + salt = "0" * 24 |
| 850 | + |
| 851 | + wpa = WPASupplicantMock(dvs) |
| 852 | + inspector = MACsecInspector(dvs) |
| 853 | + |
| 854 | + self.init_macsec( |
| 855 | + wpa, |
| 856 | + port_name, |
| 857 | + local_mac_address, |
| 858 | + macsec_port_identifier) |
| 859 | + self.establish_macsec( |
| 860 | + wpa, |
| 861 | + port_name, |
| 862 | + local_mac_address, |
| 863 | + peer_mac_address, |
| 864 | + macsec_port_identifier, |
| 865 | + 0, |
| 866 | + sak, |
| 867 | + packet_number, |
| 868 | + auth_key, |
| 869 | + ssci, |
| 870 | + salt) |
| 871 | + time.sleep(3) |
| 872 | + |
| 873 | + # Check Portchannel member in ASIC db that should been created after MACsec enabled |
| 874 | + lagmtbl = swsscommon.Table(swsscommon.DBConnector(1, dvs.redis_sock, 0), "ASIC_STATE:SAI_OBJECT_TYPE_LAG_MEMBER") |
| 875 | + lagms = lagmtbl.getKeys() |
| 876 | + assert len(lagms) == 1 |
| 877 | + |
| 878 | + self.deinit_macsec( |
| 879 | + wpa, |
| 880 | + inspector, |
| 881 | + port_name, |
| 882 | + macsec_port, |
| 883 | + local_mac_address, |
| 884 | + peer_mac_address, |
| 885 | + macsec_port_identifier, |
| 886 | + 0) |
| 887 | + |
| 888 | + # remove port channel member |
| 889 | + del ConfigTable(dvs, "PORTCHANNEL_INTERFACE")["PortChannel001"] |
| 890 | + del ConfigTable(dvs, "PORTCHANNEL_INTERFACE")["PortChannel001|40.0.0.0/31"] |
| 891 | + del ConfigTable(dvs, "PORTCHANNEL_MEMBER")["PortChannel001|Ethernet0"] |
| 892 | + |
| 893 | + # remove port channel |
| 894 | + del ConfigTable(dvs, "PORTCHANNEL")["PortChannel001"] |
| 895 | + |
| 896 | + # Clear MACsec enabled on Ethernet0 |
| 897 | + ConfigTable(dvs, "PORT")["Ethernet0"] = {"macsec" : ""} |
| 898 | + |
811 | 899 |
|
812 | 900 | # Add Dummy always-pass test at end as workaroud
|
813 | 901 | # for issue when Flaky fail on final test it invokes module tear-down
|
|
0 commit comments