1 from asfframework import VppTestRunner
2 from framework import VppTestCase
4 from config import config
5 from scapy.layers.l2 import Ether
6 from scapy.contrib.lldp import (
15 @unittest.skipIf("lldp" in config.excluded_plugins, "Exclude lldp plugin tests")
16 class TestLldpCli(VppTestCase):
17 """LLDP plugin tests [CLI]"""
21 super(TestLldpCli, cls).setUpClass()
23 cls.create_pg_interfaces(range(2))
24 for i in cls.pg_interfaces:
34 def tearDownClass(cls):
35 for i in cls.pg_interfaces:
39 super(TestLldpCli, cls).tearDownClass()
41 def create_frame(self, src_if):
42 if src_if == self.pg0:
43 chassis_id = "01:02:03:04:05:06"
44 port_id = "07:08:09:0a:0b:0c"
46 chassis_id = "11:12:13:14:15:16"
47 port_id = "17:18:19:1a:1b:1c"
50 Ether(src=src_if.remote_mac, dst="01:80:C2:00:00:03")
52 / LLDPDUChassisID(subtype=4, id=chassis_id)
53 / LLDPDUPortID(subtype=3, id=port_id)
54 / LLDPDUTimeToLive(ttl=120)
60 def test_lldp_cli(self):
61 """Enable, send frames, show, disable, verify"""
63 packets = self.create_frame(self.pg0)
64 self.pg0.add_stream(packets)
65 packets = self.create_frame(self.pg1)
66 self.pg1.add_stream(packets)
68 self.vapi.cli("set lldp system-name VPP tx-hold 4 tx-interval 10")
69 # configure everything to increase coverage
71 f"set interface lldp pg0 port-desc vtf:pg0 mgmt-ip4"
72 f" {self.pg0.local_ip4} mgmt-ip6 {self.pg0.local_ip6} mgmt-oid '1234'"
74 self.vapi.cli("set interface lldp pg1 port-desc vtf:pg1")
78 reply = self.vapi.cli("show lldp")
85 for entry in expected:
86 self.assertIn(entry, reply)
88 # only checking for an output
89 reply = self.vapi.cli("show lldp detail")
90 self.assertIn("Local Interface name: pg0", reply)
91 self.assertIn("Local Interface name: pg1", reply)
93 # disable LLDP on an interface and verify
94 self.vapi.cli("set interface lldp pg0 disable")
95 reply = self.vapi.cli("show lldp")
96 self.assertNotIn("pg0", reply)
99 class TestLldpVapi(VppTestCase):
100 """LLDP plugin test [VAPI]"""
104 super(TestLldpVapi, cls).setUpClass()
106 cls.create_pg_interfaces(range(2))
107 for i in cls.pg_interfaces:
117 def tearDownClass(cls):
118 for i in cls.pg_interfaces:
122 super(TestLldpVapi, cls).tearDownClass()
124 def test_lldp_vapi(self):
125 """Enable, show, disable, verify"""
126 self.vapi.lldp_config(tx_hold=4, tx_interval=1, system_name="VAPI")
127 self.vapi.sw_interface_set_lldp(
129 mgmt_ip4=self.pg0.local_ip4,
132 self.vapi.sw_interface_set_lldp(
134 mgmt_ip4=self.pg1.local_ip4,
136 mgmt_ip6=self.pg1.local_ip6,
140 # only check if LLDP gets enabled, functionality is tested in CLI class
141 reply = self.vapi.cli("show lldp")
142 self.assertIn("pg1", reply)
144 self.vapi.sw_interface_set_lldp(sw_if_index=2, enable=False)
145 reply = self.vapi.cli("show lldp")
146 self.assertNotIn("pg1", reply)
149 if __name__ == "__main__":
150 unittest.main(testRunner=VppTestRunner)