From 3dd5810b597f573ab3ea307913d0064bc8ef401e Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Mon, 28 Aug 2023 19:27:52 +0200 Subject: [PATCH] test/case: new test, verify SSDP can be disabled/enabled This test use NETCONF to enable/disable SSDP, it then verifies that the DUT responds to, or does not respond to, SSDP discover messages. Signed-off-by: Joachim Wiberg --- test/case/all.yaml | 3 + test/case/infix_services/all.yaml | 2 + test/case/infix_services/services_basic.py | 85 ++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 test/case/infix_services/all.yaml create mode 100755 test/case/infix_services/services_basic.py diff --git a/test/case/all.yaml b/test/case/all.yaml index 72eecf2e..a024a416 100644 --- a/test/case/all.yaml +++ b/test/case/all.yaml @@ -9,3 +9,6 @@ - name: infix-interfaces suite: infix_interfaces/all.yaml + +- name: infix-services + suite: infix_services/all.yaml diff --git a/test/case/infix_services/all.yaml b/test/case/infix_services/all.yaml new file mode 100644 index 00000000..6c38f301 --- /dev/null +++ b/test/case/infix_services/all.yaml @@ -0,0 +1,2 @@ +--- +- case: services_basic.py diff --git a/test/case/infix_services/services_basic.py b/test/case/infix_services/services_basic.py new file mode 100755 index 00000000..446702fe --- /dev/null +++ b/test/case/infix_services/services_basic.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python3 +# +# Verify that basic services like SSDP, mDNS and LLDP can be enabled and +# disabled. We verify operation and non-operation by using tcpdump. +# + +import time +import infamy +from infamy.ssdp import SsdpClient + +def verify(enabled, sec): + """Verify SSDP traffic, or no traffic in case not enabled""" + _, hport = env.ltop.xlate("host", "data") + + with infamy.IsolatedMacVlan(hport) as netns: + snif = infamy.Sniffer(netns, "port 1900") + ssdp = SsdpClient(netns, retries=sec) + + netns.addip("10.0.0.1") + netns.addroute("0.0.0.0/0", "10.0.0.1") + + with snif: + target.put_config_dict("infix-services", { + "ssdp": { + "enabled": enabled + } + }) + running = target.get_config_dict("/infix-services:ssdp") + assert running["ssdp"]["enabled"] == enabled + + ssdp.start() + time.sleep(sec) + ssdp.stop() + + return snif.output() + +with infamy.Test() as test: + with test.step("Initialize"): + env = infamy.Env(infamy.std_topology("1x2")) + target = env.attach("target", "mgmt") + + with test.step("Enable IPv4 address and disable service SSDP"): + _, tport = env.ltop.xlate("target", "data") + + target.put_config_dict("ietf-interfaces", { + "interfaces": { + "interface": [ + { + "name": tport, + "type": "infix-if-type:ethernet", + "enabled": True, + "ipv4": { + "address": [ + { + "ip": "10.0.0.10", + "prefix-length": 24 + } + ] + } + } + ] + } + }) + target.put_config_dict("infix-services", { + "ssdp": { + "enabled": False + } + }) + cfg = target.get_config_dict("/infix-services:ssdp") + assert not cfg["ssdp"]["enabled"] + + with test.step("Start SSDP sniffer and enable SSDP on target ..."): + rc = verify(True, 3) + print(rc.stdout) + # breakpoint() + if "10.0.0.10.1900 > 10.0.0.1" not in rc.stdout: + test.fail() + + with test.step("Disable SSDP on target and start SSDP sniffer again ..."): + rc = verify(False, 3) + print(rc.stdout) + if "10.0.0.10.1900 > 10.0.0.1" in rc.stdout: + test.fail() + + test.succeed()