diff --git a/test/case/ietf_interfaces/Readme.adoc b/test/case/ietf_interfaces/Readme.adoc index 28307548..22ca7442 100644 --- a/test/case/ietf_interfaces/Readme.adoc +++ b/test/case/ietf_interfaces/Readme.adoc @@ -38,3 +38,5 @@ include::static_multicast_filters/Readme.adoc[] include::vlan_qos/Readme.adoc[] include::verify_all_interface_types/Readme.adoc[] + +include::iface_enable_disable/Readme.adoc[] diff --git a/test/case/ietf_interfaces/ietf_interfaces.yaml b/test/case/ietf_interfaces/ietf_interfaces.yaml index bb71d029..a512bc27 100644 --- a/test/case/ietf_interfaces/ietf_interfaces.yaml +++ b/test/case/ietf_interfaces/ietf_interfaces.yaml @@ -55,3 +55,6 @@ - name: verify_all_interface_types case: verify_all_interface_types/test.py + +- name: iface_enable_disable + case: iface_enable_disable/test.py diff --git a/test/case/ietf_interfaces/iface_enable_disable/Readme.adoc b/test/case/ietf_interfaces/iface_enable_disable/Readme.adoc new file mode 100644 index 00000000..f6d14d02 --- /dev/null +++ b/test/case/ietf_interfaces/iface_enable_disable/Readme.adoc @@ -0,0 +1,28 @@ +=== Interface status +==== Description +Verify that interface status works + +==== Topology +ifdef::topdoc[] +image::../../test/case/ietf_interfaces/iface_enable_disable/topology.png[Interface status topology] +endif::topdoc[] +ifndef::topdoc[] +ifdef::testgroup[] +image::iface_enable_disable/topology.png[Interface status topology] +endif::testgroup[] +ifndef::testgroup[] +image::topology.png[Interface status topology] +endif::testgroup[] +endif::topdoc[] +==== Test sequence +. Set up topology and attach to target DUTs +. Configure bridge and associated interfaces in target1 +. Disable interface in target2 +. Verify the interface is disabled +. Enable the interface and assign an IP address +. Verify the interface is enabled +. Verify it is possible to ping the interface + + +<<< + diff --git a/test/case/ietf_interfaces/iface_enable_disable/test.py b/test/case/ietf_interfaces/iface_enable_disable/test.py new file mode 100755 index 00000000..76e85d1d --- /dev/null +++ b/test/case/ietf_interfaces/iface_enable_disable/test.py @@ -0,0 +1,105 @@ +#!/usr/bin/env python3 +""" +Interface status + +Verify interface status properly propagate changes when an interface +is disabled and then re-enabled. + +Both admin-status and oper-status are verified. +""" + +import infamy +import infamy.iface as iface + +from infamy import until + +def print_error_message(iface, param, exp_val, act_val): + return f"'{param}' failure for interface '{iface}'. Expected '{exp_val}', Actual: '{act_val}'" + +def assert_param(target, interface, parameter, expected_value): + def check_param(): + actual_value = iface.get_param(target, interface, parameter) + if actual_value is None: + raise ValueError(f"Failed to retrieve '{parameter}' for interface '{interface}'") + return actual_value == expected_value + + until(check_param) + + actual_value = iface.get_param(target, interface, parameter) + assert (expected_value == actual_value), print_error_message( + iface=interface, + param = parameter, + exp_val = expected_value, + act_val = actual_value + ) + +def configure_interface(target, iface_name, iface_type=None, enabled=True, ip_address=None, bridge=None): + + interface_config = { + "name": iface_name, + "enabled": enabled + } + + if iface_type: + interface_config["type"] = iface_type + + if ip_address: + interface_config["ipv4"] = { + "address": [ + { + "ip": ip_address, + "prefix-length": 24 + }]} + + if bridge: + interface_config["infix-interfaces:bridge-port"] = { + "bridge": bridge + } + + target.put_config_dict( "ietf-interfaces", { + "interfaces": { + "interface": [ + interface_config + ]}}) + +with infamy.Test() as test: + with test.step("Set up topology and attach to target DUTs"): + env = infamy.Env() + target1 = env.attach("target1", "mgmt") + target2 = env.attach("target2", "mgmt") + + _, data1 = env.ltop.xlate("target1", "data") + _, link1 = env.ltop.xlate("target1", "link") + + _, iface_under_test = env.ltop.xlate("target2", "link") + _, host_send_iface = env.ltop.xlate("host", "data") + _bridge = "br_0" + + target_address = "10.10.10.2" + host_address = "10.10.10.1" + + with test.step("Configure bridge and associated interfaces in target1"): + configure_interface(target1, _bridge, enabled=True, iface_type="infix-if-type:bridge") + configure_interface(target1, data1, enabled=True, bridge=_bridge) + configure_interface(target1, link1, enabled=True, bridge=_bridge) + + with test.step("Disable interface in target2"): + configure_interface(target2, iface_under_test, enabled=False) + + with test.step("Verify the interface is disabled"): + assert_param(target2, iface_under_test, "admin-status", "down") + assert_param(target2, iface_under_test, "oper-status", "down") + + with test.step("Enable the interface and assign an IP address"): + configure_interface(target2, iface_under_test, enabled=True, ip_address=target_address) + + with test.step("Verify the interface is enabled"): + assert_param(target2, iface_under_test, "admin-status", "up") + assert_param(target2, iface_under_test, "oper-status", "up") + + with infamy.IsolatedMacVlan(host_send_iface) as send_ns: + with test.step("Verify it is possible to ping the interface"): + send_ns.addip(host_address) + send_ns.must_reach(target_address) + + test.succeed() \ No newline at end of file diff --git a/test/case/ietf_interfaces/iface_enable_disable/topology.dot b/test/case/ietf_interfaces/iface_enable_disable/topology.dot new file mode 100644 index 00000000..06dba991 --- /dev/null +++ b/test/case/ietf_interfaces/iface_enable_disable/topology.dot @@ -0,0 +1,35 @@ +graph "2x4" { + layout="neato"; + overlap="false"; + esep="+40"; + + node [shape=record, fontname="monospace"]; + edge [color="cornflowerblue", penwidth="2"]; + + host [ + label="host | { mgmt1 | data | mgmt2 }", + pos="0,15!", + kind="controller", + ]; + + target1 [ + label="{ mgmt | data | link } | { \n dut1 \n\n }", + pos="8,15!", + + kind="infix", + ]; + + target2 [ + label="{ link | mgmt } | { \n dut2 \n\n }", + pos="8,12!", + + kind="infix", + ]; + + host:mgmt1 -- target1:mgmt [kind=mgmt, color="lightgrey"] + host:data -- target1:data [color=black, fontcolor=black, taillabel="10.10.10.1/24"] + + host:mgmt2 -- target2:mgmt [kind=mgmt, color="lightgrey"] + + target1:link -- target2:link [color=black, fontcolor=black, headlabel="10.10.10.2/24"] +} \ No newline at end of file diff --git a/test/case/ietf_interfaces/iface_enable_disable/topology.png b/test/case/ietf_interfaces/iface_enable_disable/topology.png new file mode 100644 index 00000000..f2c67ca9 Binary files /dev/null and b/test/case/ietf_interfaces/iface_enable_disable/topology.png differ