1 from framework import VppTestCase, VppTestRunner
3 from config import config
4 from scapy.layers.l2 import Ether
5 from scapy.contrib.lldp import (
14 @unittest.skipIf("lldp" in config.excluded_plugins, "Exclude lldp plugin tests")
15 class TestLldpCli(VppTestCase):
16 """LLDP plugin tests [CLI]"""
20 super(TestLldpCli, cls).setUpClass()
22 cls.create_pg_interfaces(range(2))
23 for i in cls.pg_interfaces:
33 def tearDownClass(cls):
34 for i in cls.pg_interfaces:
38 super(TestLldpCli, cls).tearDownClass()
40 def create_frame(self, src_if):
41 if src_if == self.pg0:
42 chassis_id = "01:02:03:04:05:06"
43 port_id = "07:08:09:0a:0b:0c"
45 chassis_id = "11:12:13:14:15:16"
46 port_id = "17:18:19:1a:1b:1c"
49 Ether(src=src_if.remote_mac, dst="01:80:C2:00:00:03")
51 / LLDPDUChassisID(subtype=4, id=chassis_id)
52 / LLDPDUPortID(subtype=3, id=port_id)
53 / LLDPDUTimeToLive(ttl=120)
59 def test_lldp_cli(self):
60 """Enable, send frames, show, disable, verify"""
62 packets = self.create_frame(self.pg0)
63 self.pg0.add_stream(packets)
64 packets = self.create_frame(self.pg1)
65 self.pg1.add_stream(packets)
67 self.vapi.cli("set lldp system-name VPP tx-hold 4 tx-interval 10")
68 # configure everything to increase coverage
70 f"set interface lldp pg0 port-desc vtf:pg0 mgmt-ip4"
71 f" {self.pg0.local_ip4} mgmt-ip6 {self.pg0.local_ip6} mgmt-oid '1234'"
73 self.vapi.cli("set interface lldp pg1 port-desc vtf:pg1")
77 reply = self.vapi.cli("show lldp")
84 for entry in expected:
85 self.assertIn(entry, reply)
87 # only checking for an output
88 reply = self.vapi.cli("show lldp detail")
89 self.assertIn("Local Interface name: pg0", reply)
90 self.assertIn("Local Interface name: pg1", reply)
92 # disable LLDP on an interface and verify
93 self.vapi.cli("set interface lldp pg0 disable")
94 reply = self.vapi.cli("show lldp")
95 self.assertNotIn("pg0", reply)
98 class TestLldpVapi(VppTestCase):
99 """LLDP plugin test [VAPI]"""
103 super(TestLldpVapi, cls).setUpClass()
105 cls.create_pg_interfaces(range(2))
106 for i in cls.pg_interfaces:
116 def tearDownClass(cls):
117 for i in cls.pg_interfaces:
121 super(TestLldpVapi, cls).tearDownClass()
123 def test_lldp_vapi(self):
124 """Enable, show, disable, verify"""
125 self.vapi.lldp_config(tx_hold=4, tx_interval=1, system_name="VAPI")
126 self.vapi.sw_interface_set_lldp(
128 mgmt_ip4=self.pg0.local_ip4,
131 self.vapi.sw_interface_set_lldp(
133 mgmt_ip4=self.pg1.local_ip4,
135 mgmt_ip6=self.pg1.local_ip6,
139 # only check if LLDP gets enabled, functionality is tested in CLI class
140 reply = self.vapi.cli("show lldp")
141 self.assertIn("pg1", reply)
143 self.vapi.sw_interface_set_lldp(sw_if_index=2, enable=False)
144 reply = self.vapi.cli("show lldp")
145 self.assertNotIn("pg1", reply)
148 if __name__ == "__main__":
149 unittest.main(testRunner=VppTestRunner)