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

[testcase]MACsec basic test #3571

Merged
merged 35 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
d592c1d
Add check neighbors health for SONiC neighbor devices
Pterosaur May 14, 2021
1bd4fa8
Add MACsec test
Pterosaur May 23, 2021
e721812
Skip to move bp port to docker if neighbor devices are sonic
Pterosaur Jun 2, 2021
f9bb8f8
AddPolish code
Pterosaur Jun 2, 2021
6fa54e4
Add data plane server to neighbor
Pterosaur Jun 14, 2021
83ee15b
Polish dataplane test
Pterosaur Jun 16, 2021
fe24a15
Add ptf service in nSONiC eighbor devices
Pterosaur Jun 21, 2021
c7ae21f
Add MACsec pkt checking in neighbor devices
Pterosaur Jun 21, 2021
c90f1ec
polish ansible task name
Pterosaur Jun 21, 2021
ce8f061
[MACsec test]Add test neighbor to neighbor
Pterosaur Jun 21, 2021
53ad88c
Fix test
Pterosaur Aug 8, 2021
98a4607
Fix warning
Pterosaur Aug 9, 2021
e213382
Merge branch 'master' into macsec_test
Pterosaur Aug 19, 2021
e2e93ac
Merge branch 'master' of https://github.com/Azure/sonic-mgmt into mac…
Pterosaur Aug 26, 2021
b389a36
Merge branch 'master' into macsec_test
Pterosaur Nov 19, 2021
9d84568
Add macsec to azp
Pterosaur Nov 19, 2021
5fbdfc7
test
Pterosaur Nov 29, 2021
cfbf9ff
fixtest
Pterosaur Dec 7, 2021
5e2c6ff
fix test
Pterosaur Dec 26, 2021
dae9def
Different priority to peers
Pterosaur Feb 3, 2022
d934eb5
Merge branch 'master' into macsec_test
Pterosaur Feb 3, 2022
791fb8c
Add enable_macsec_feature before setup
Pterosaur Feb 3, 2022
1fca9dd
Polish test
Pterosaur Feb 14, 2022
f7a03e7
Add xpn and send_sci
Pterosaur Feb 17, 2022
1412b0e
remove unused import
Pterosaur Feb 17, 2022
cecd4dd
increase timeout in sonictest-sonic-t0
Pterosaur Feb 24, 2022
dd2fa36
Modify timeout
Pterosaur Feb 25, 2022
e907e0b
Remove useless function
Pterosaur Feb 26, 2022
0938857
Merge branch 'master' into macsec_test
Pterosaur Feb 28, 2022
197f466
Polish code
Pterosaur Feb 28, 2022
ac5cca3
Polish code
Pterosaur Feb 28, 2022
8d526b4
Merge branch 'macsec_test' into advanced_macsec_test
Pterosaur Feb 28, 2022
ab038ba
Add fault handling test
Pterosaur Feb 28, 2022
625d90b
decrease cpu count of neighbor devices
Pterosaur Mar 1, 2022
2bde3b8
Wait until mka session recovering from flap
Pterosaur Mar 1, 2022
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
2 changes: 1 addition & 1 deletion ansible/roles/vm_set/templates/sonic_vm.xml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<name>{{ vm_name }}</name>
<memory unit='GiB'>4</memory>
<currentMemory unit='GiB'>4</currentMemory>
<vcpu placement='static'>4</vcpu>
<vcpu placement='static'>2</vcpu>
<resource>
<partition>/machine</partition>
</resource>
Expand Down
4 changes: 3 additions & 1 deletion tests/kvmtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ test_t0_sonic() {
# Run tests_1vlan on vlab-01 virtual switch
# TODO: Use a marker to select these tests rather than providing a hard-coded list here.
tgname=t0-sonic
tests="bgp/test_bgp_fact.py"
tests="\
bgp/test_bgp_fact.py \
macsec/test_macsec.py"

pushd $SONIC_MGMT_DIR/tests
./run_tests.sh $RUNTEST_CLI_COMMON_OPTS -c "$tests" -p logs/$tgname -e "--neighbor_type=sonic"
Expand Down
174 changes: 174 additions & 0 deletions tests/macsec/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import pytest
import logging
import ipaddress
import collections
from multiprocessing.pool import ThreadPool

import natsort

from tests.common.utilities import wait_until

logger = logging.getLogger(__name__)


def pytest_configure(config):
config.addinivalue_line(
"markers", "macsec_required: mark test as MACsec required to run")


def pytest_collection_modifyitems(config, items):
if config.getoption("--neighbor_type") == "sonic":
return
skip_macsec = pytest.mark.skip(
reason="Neighbor devices don't support MACsec")
for item in items:
if "macsec_required" in item.keywords:
item.add_marker(skip_macsec)


def global_cmd(duthost, nbrhosts, cmd):
pool = ThreadPool(1 + len(nbrhosts))
pool.apply_async(duthost.command, args=(cmd,))
for nbr in nbrhosts.values():
pool.apply_async(nbr["host"].command, args=(cmd, ))
pool.close()
pool.join()


@pytest.fixture(scope="module")
def enable_macsec_feature(duthost, nbrhosts):
global_cmd(duthost, nbrhosts, "sudo config feature state macsec enabled")
def check_macsec_enabled():
for nbr in [n["host"] for n in nbrhosts.values()] + [duthost]:
if len(nbr.shell("docker ps | grep macsec | grep -v grep")["stdout_lines"]) != 1:
return False
if len(nbr.shell("ps -ef | grep macsecmgrd | grep -v grep")["stdout_lines"]) != 1:
return False
return True
assert wait_until(180, 1, 1, check_macsec_enabled)
logger.info("Enable MACsec feature")
yield
global_cmd(duthost, nbrhosts, "sudo config feature state macsec disable")


@pytest.fixture(scope="module")
def profile_name():
return "test"


@pytest.fixture(scope="module")
def default_priority():
return 64

@pytest.fixture(scope="module", params=["GCM-AES-128", "GCM-AES-256", "GCM-AES-XPN-128", "GCM-AES-XPN-256"])
def cipher_suite(request):
return request.param


@pytest.fixture(scope="module")
def primary_ckn():
cak = "6162636465666768696A6B6C6D6E6F707172737475767778797A303132333435"
return cak


@pytest.fixture(scope="module")
def primary_cak(cipher_suite):
ckn = "0123456789ABCDEF0123456789ABCDEF"
if "128" in cipher_suite:
ckn = ckn * 1
elif "256" in cipher_suite:
ckn = ckn * 2
else:
raise ValueError("Unknown cipher suite {}".format(cipher_suite))
return ckn


# Some platform cannot support "integrity_only" mode, skip this option
# @pytest.fixture(scope="module", params=["integrity_only", "security"])
@pytest.fixture(scope="module", params=["security"])
def policy(request):
return request.param


@pytest.fixture(scope="module", params=["true", "false"])
def send_sci(request):
return request.param


def find_links(duthost, tbinfo, filter):
mg_facts = duthost.get_extended_minigraph_facts(tbinfo)
for interface, neighbor in mg_facts["minigraph_neighbors"].items():
filter(interface, neighbor, mg_facts, tbinfo)


@pytest.fixture(scope="module")
def downstream_links(duthost, tbinfo, nbrhosts):
links = collections.defaultdict(dict)
def filter(interface, neighbor, mg_facts, tbinfo):
if tbinfo["topo"]["type"] == "t0" and "Server" in neighbor["name"]:
port = mg_facts["minigraph_neighbors"][interface]["port"]
links[interface] = {
"name": neighbor["name"],
"ptf_port_id": mg_facts["minigraph_ptf_indices"][interface],
"port": port
}
find_links(duthost, tbinfo, filter)
return links


@pytest.fixture(scope="module")
def upstream_links(duthost, tbinfo, nbrhosts):
links = collections.defaultdict(dict)
def filter(interface, neighbor, mg_facts, tbinfo):
if tbinfo["topo"]["type"] == "t0" and "T1" in neighbor["name"]:
for item in mg_facts["minigraph_bgp"]:
if item["name"] == neighbor["name"]:
if isinstance(ipaddress.ip_address(item["addr"]), ipaddress.IPv4Address):
ipv4_addr = item["addr"]
break
port = mg_facts["minigraph_neighbors"][interface]["port"]
links[interface] = {
"name": neighbor["name"],
"ptf_port_id": mg_facts["minigraph_ptf_indices"][interface],
"ipv4_addr": ipv4_addr,
"port": port
}
find_links(duthost, tbinfo, filter)
return links


def find_links_from_nbr(duthost, tbinfo, nbrhosts):
links = collections.defaultdict(dict)

def filter(interface, neighbor, mg_facts, tbinfo):
if neighbor["name"] not in nbrhosts.keys():
return
port = mg_facts["minigraph_neighbors"][interface]["port"]
links[interface] = {
"name": neighbor["name"],
"host": nbrhosts[neighbor["name"]]["host"],
"port": port
}
find_links(duthost, tbinfo, filter)
return links


@pytest.fixture(scope="module")
def ctrl_links(duthost, tbinfo, nbrhosts):
assert len(nbrhosts) > 1
ctrl_nbr_names = natsort.natsorted(nbrhosts.keys())[:2]
# ctrl_nbr_names = random.sample(nbrhosts.keys(), len(nbrhosts)//2)
logging.info("Controlled links {}".format(ctrl_nbr_names))
nbrhosts = {name: nbrhosts[name] for name in ctrl_nbr_names}
return find_links_from_nbr(duthost, tbinfo, nbrhosts)


@pytest.fixture(scope="module")
def unctrl_links(duthost, tbinfo, nbrhosts, ctrl_links):
unctrl_nbr_names = set(nbrhosts.keys())
for _, nbr in ctrl_links.items():
unctrl_nbr_names.remove(nbr["name"])
logging.info("Uncontrolled links {}".format(unctrl_nbr_names))
nbrhosts = {name: nbrhosts[name] for name in unctrl_nbr_names}
return find_links_from_nbr(duthost, tbinfo, nbrhosts)

Loading