vpp/test/test_lldp.py
Dave Wallace 8800f732f8 tests: refactor asf framework code
- Make framework.py classes a subset of asfframework.py classes
- Remove all packet related code from asfframework.py
- Add test class and test case set up debug output to log
- Repatriate packet tests from asf to test directory
- Remove non-packet related code from framework.py and
  inherit them from asfframework.py classes
- Clean up unused import variables
- Re-enable BFD tests on Ubuntu 22.04 and fix
  intermittent test failures in echo_looped_back
  testcases (where # control packets verified but
  not guaranteed to be received during test)
- Re-enable Wireguard tests on Ubuntu 22.04 and fix
  intermittent test failures in handshake ratelimiting
  testcases and event testcase
- Run Wiregard testcase suites solo
- Improve debug output in log.txt
- Increase VCL/LDP post sleep timeout to allow iperf server
  to finish cleanly.
- Fix pcap history files to be sorted by suite and testcase
  and ensure order/timestamp is correct based on creation
  in the testcase.
- Decode pcap files for each suite and testcase for all
  errors or if configured via comandline option / env var
- Improve vpp corefile detection to allow complete corefile
  generation
- Disable vm vpp interfaces testcases on debian11
- Clean up failed unittest dir when retrying failed testcases
  and unify testname directory and failed linknames into
  framwork functions

Type: test

Change-Id: I0764f79ea5bb639d278bf635ed2408d4d5220e1e
Signed-off-by: Dave Wallace <dwallacelf@gmail.com>
2023-11-03 05:06:43 +00:00

151 lines
4.4 KiB
Python

from asfframework import VppTestRunner
from framework import VppTestCase
import unittest
from config import config
from scapy.layers.l2 import Ether
from scapy.contrib.lldp import (
LLDPDUChassisID,
LLDPDUPortID,
LLDPDUTimeToLive,
LLDPDUEndOfLLDPDU,
LLDPDU,
)
@unittest.skipIf("lldp" in config.excluded_plugins, "Exclude lldp plugin tests")
class TestLldpCli(VppTestCase):
"""LLDP plugin tests [CLI]"""
@classmethod
def setUpClass(cls):
super(TestLldpCli, cls).setUpClass()
try:
cls.create_pg_interfaces(range(2))
for i in cls.pg_interfaces:
i.config_ip4()
i.config_ip6()
i.resolve_arp()
i.admin_up()
except Exception:
cls.tearDownClass()
raise
@classmethod
def tearDownClass(cls):
for i in cls.pg_interfaces:
i.unconfig_ip4()
i.unconfig_ip6()
i.admin_down()
super(TestLldpCli, cls).tearDownClass()
def create_frame(self, src_if):
if src_if == self.pg0:
chassis_id = "01:02:03:04:05:06"
port_id = "07:08:09:0a:0b:0c"
else:
chassis_id = "11:12:13:14:15:16"
port_id = "17:18:19:1a:1b:1c"
lldp_frame = (
Ether(src=src_if.remote_mac, dst="01:80:C2:00:00:03")
/ LLDPDU()
/ LLDPDUChassisID(subtype=4, id=chassis_id)
/ LLDPDUPortID(subtype=3, id=port_id)
/ LLDPDUTimeToLive(ttl=120)
/ LLDPDUEndOfLLDPDU()
)
return lldp_frame
def test_lldp_cli(self):
"""Enable, send frames, show, disable, verify"""
packets = self.create_frame(self.pg0)
self.pg0.add_stream(packets)
packets = self.create_frame(self.pg1)
self.pg1.add_stream(packets)
self.vapi.cli("set lldp system-name VPP tx-hold 4 tx-interval 10")
# configure everything to increase coverage
self.vapi.cli(
f"set interface lldp pg0 port-desc vtf:pg0 mgmt-ip4"
f" {self.pg0.local_ip4} mgmt-ip6 {self.pg0.local_ip6} mgmt-oid '1234'"
)
self.vapi.cli("set interface lldp pg1 port-desc vtf:pg1")
self.pg_start()
reply = self.vapi.cli("show lldp")
expected = [
"01:02:03:04:05:06",
"07:08:09:0a:0b:0c",
"11:12:13:14:15:16",
"17:18:19:1a:1b:1c",
]
for entry in expected:
self.assertIn(entry, reply)
# only checking for an output
reply = self.vapi.cli("show lldp detail")
self.assertIn("Local Interface name: pg0", reply)
self.assertIn("Local Interface name: pg1", reply)
# disable LLDP on an interface and verify
self.vapi.cli("set interface lldp pg0 disable")
reply = self.vapi.cli("show lldp")
self.assertNotIn("pg0", reply)
class TestLldpVapi(VppTestCase):
"""LLDP plugin test [VAPI]"""
@classmethod
def setUpClass(cls):
super(TestLldpVapi, cls).setUpClass()
try:
cls.create_pg_interfaces(range(2))
for i in cls.pg_interfaces:
i.config_ip4()
i.config_ip6()
i.resolve_arp()
i.admin_up()
except Exception:
cls.tearDownClass()
raise
@classmethod
def tearDownClass(cls):
for i in cls.pg_interfaces:
i.unconfig_ip4()
i.unconfig_ip6()
i.admin_down()
super(TestLldpVapi, cls).tearDownClass()
def test_lldp_vapi(self):
"""Enable, show, disable, verify"""
self.vapi.lldp_config(tx_hold=4, tx_interval=1, system_name="VAPI")
self.vapi.sw_interface_set_lldp(
sw_if_index=1,
mgmt_ip4=self.pg0.local_ip4,
port_desc="vtf:pg0",
)
self.vapi.sw_interface_set_lldp(
sw_if_index=2,
mgmt_ip4=self.pg1.local_ip4,
port_desc="vtf:pg1",
mgmt_ip6=self.pg1.local_ip6,
mgmt_oid=b"1",
)
# only check if LLDP gets enabled, functionality is tested in CLI class
reply = self.vapi.cli("show lldp")
self.assertIn("pg1", reply)
self.vapi.sw_interface_set_lldp(sw_if_index=2, enable=False)
reply = self.vapi.cli("show lldp")
self.assertNotIn("pg1", reply)
if __name__ == "__main__":
unittest.main(testRunner=VppTestRunner)