]> git.ipfire.org Git - thirdparty/lldpd.git/blame - tests/integration/test_basic.py
build: bump cross-platform-actions/action from 0.27.0 to 0.28.0
[thirdparty/lldpd.git] / tests / integration / test_basic.py
CommitLineData
e0a84778
VB
1import time
2import pytest
3import pyroute2
a9fe956f
VB
4import scapy.all
5import scapy.contrib.lldp
e0a84778 6
8b549648 7
e0a84778
VB
8def test_one_neighbor(lldpd1, lldpd, lldpcli, namespaces):
9 with namespaces(2):
10 lldpd()
11 with namespaces(1):
12 out = lldpcli("-f", "keyvalue", "show", "neighbors")
8b549648
VB
13 assert out["lldp.eth0.age"].startswith("0 day, 00:00:")
14 assert out["lldp.eth0.chassis.descr"].startswith(
15 "Spectacular GNU/Linux 2016 Linux"
16 )
17 assert "lldp.eth0.chassis.Router.enabled" in out
18 assert "lldp.eth0.chassis.Station.enabled" in out
19 del out["lldp.eth0.age"]
20 del out["lldp.eth0.chassis.descr"]
21 del out["lldp.eth0.chassis.Router.enabled"]
22 del out["lldp.eth0.chassis.Station.enabled"]
23 assert out == {
24 "lldp.eth0.via": "LLDP",
25 "lldp.eth0.rid": "1",
26 "lldp.eth0.chassis.mac": "00:00:00:00:00:02",
27 "lldp.eth0.chassis.name": "ns-2.example.com",
28 "lldp.eth0.chassis.mgmt-ip": "fe80::200:ff:fe00:2",
29 "lldp.eth0.chassis.mgmt-iface": "2",
30 "lldp.eth0.chassis.Bridge.enabled": "off",
31 "lldp.eth0.chassis.Wlan.enabled": "off",
32 "lldp.eth0.port.mac": "00:00:00:00:00:02",
33 "lldp.eth0.port.descr": "eth1",
34 "lldp.eth0.port.ttl": "120",
35 }
e0a84778
VB
36
37
dd0d1674 38@pytest.mark.parametrize("neighbors", (5, 10, 20))
e0a84778
VB
39def test_several_neighbors(lldpd, lldpcli, links, namespaces, neighbors):
40 for i in range(2, neighbors + 1):
41 links(namespaces(1), namespaces(i))
42 for i in range(1, neighbors + 1):
43 with namespaces(i):
8b549648 44 lldpd(sleep=(i == 1 and 2 or 0), silent=True)
f9452218 45 time.sleep(10)
e0a84778
VB
46 with namespaces(1):
47 out = lldpcli("-f", "keyvalue", "show", "neighbors")
48 for i in range(2, neighbors + 1):
8b549648
VB
49 assert out[
50 "lldp.eth{}.chassis.name".format((i - 2) * 2)
51 ] == "ns-{}.example.com".format(i)
e0a84778
VB
52
53
a54f6012
SW
54def test_one_interface(lldpd1, lldpd, lldpcli, namespaces):
55 with namespaces(2):
56 lldpd()
57 with namespaces(1):
58 out = lldpcli("-f", "keyvalue", "show", "interfaces")
8b549648
VB
59 assert out["lldp.eth0.chassis.descr"].startswith(
60 "Spectacular GNU/Linux 2016 Linux"
61 )
62 assert "lldp.eth0.chassis.Router.enabled" in out
63 assert "lldp.eth0.chassis.Station.enabled" in out
64 del out["lldp.eth0.chassis.descr"]
65 del out["lldp.eth0.chassis.Router.enabled"]
66 del out["lldp.eth0.chassis.Station.enabled"]
67 assert out == {
68 "lldp.eth0.status": "RX and TX",
69 "lldp.eth0.chassis.mac": "00:00:00:00:00:01",
70 "lldp.eth0.chassis.name": "ns-1.example.com",
71 "lldp.eth0.chassis.mgmt-ip": "fe80::200:ff:fe00:1",
72 "lldp.eth0.chassis.mgmt-iface": "3",
73 "lldp.eth0.chassis.Bridge.enabled": "off",
74 "lldp.eth0.chassis.Wlan.enabled": "off",
75 "lldp.eth0.port.mac": "00:00:00:00:00:01",
76 "lldp.eth0.port.descr": "eth0",
77 "lldp.eth0.ttl.ttl": "120",
78 }
a54f6012 79
69362215 80
a54f6012
SW
81@pytest.mark.parametrize("interfaces", (5, 10, 20))
82def test_several_interfaces(lldpd, lldpcli, links, namespaces, interfaces):
83 for i in range(2, interfaces + 1):
84 links(namespaces(1), namespaces(i))
85 for i in range(1, interfaces + 1):
86 with namespaces(i):
87 lldpd()
88 with namespaces(1):
89 out = lldpcli("-f", "keyvalue", "show", "interfaces")
90 for i in range(2, interfaces + 1):
8b549648
VB
91 assert (
92 out["lldp.eth{}.chassis.mac".format((i - 2) * 2)] == "00:00:00:00:00:01"
93 )
94 assert out[
95 "lldp.eth{}.port.mac".format((i - 2) * 2)
96 ] == "00:00:00:00:00:{num:02x}".format(num=(i - 2) * 2 + 1)
a54f6012
SW
97
98
69362215
VB
99def test_different_mtu(lldpd, lldpcli, links, namespaces):
100 links(namespaces(1), namespaces(2), mtu=1500)
101 links(namespaces(1), namespaces(2), mtu=9000)
102 with namespaces(1):
103 lldpd()
104 with namespaces(2):
105 lldpd()
106 with namespaces(1):
107 out = lldpcli("-f", "keyvalue", "show", "interfaces")
8b549648
VB
108 assert out["lldp.eth0.chassis.mac"] == "00:00:00:00:00:01"
109 assert out["lldp.eth2.chassis.mac"] == "00:00:00:00:00:01"
69362215
VB
110
111
e0a84778
VB
112def test_overrided_description(lldpd1, lldpd, lldpcli, namespaces):
113 with namespaces(2):
114 lldpd("-S", "Modified description")
115 with namespaces(1):
116 out = lldpcli("-f", "keyvalue", "show", "neighbors")
8b549648 117 assert out["lldp.eth0.chassis.descr"] == "Modified description"
e0a84778
VB
118
119
e6f64ed9
VB
120def test_overrided_description2(lldpd1, lldpd, lldpcli, namespaces):
121 with namespaces(2):
122 lldpd()
123 lldpcli("configure", "system", "description", "Modified description")
124 lldpcli("update")
125 time.sleep(1)
126 with namespaces(1):
127 out = lldpcli("-f", "keyvalue", "show", "neighbors")
8b549648 128 assert out["lldp.eth0.chassis.descr"] == "Modified description"
e6f64ed9
VB
129
130
8481f490
VB
131def test_overrided_chassisid(lldpd1, lldpd, lldpcli, namespaces):
132 with namespaces(2):
133 lldpd()
134 lldpcli("configure", "system", "chassisid", "Modified chassis ID")
135 lldpcli("update")
136 time.sleep(1)
137 with namespaces(1):
138 out = lldpcli("-f", "keyvalue", "show", "neighbors")
8b549648 139 assert out["lldp.eth0.chassis.local"] == "Modified chassis ID"
8481f490
VB
140
141
d7afa6a1
VB
142def test_overrided_chassisid_kept(lldpd1, lldpd, lldpcli, namespaces, links):
143 with namespaces(2):
144 lldpd()
145 lldpcli("configure", "system", "chassisid", "Modified chassis ID")
146 links.down("eth1")
147 time.sleep(1)
148 links.up("eth1")
149 time.sleep(1)
150 lldpcli("update")
151 time.sleep(1)
152 with namespaces(1):
153 out = lldpcli("-f", "keyvalue", "show", "neighbors")
8b549648 154 assert out["lldp.eth0.chassis.local"] == "Modified chassis ID"
d7afa6a1
VB
155
156
8481f490
VB
157def test_overrided_chassisid_reverse(lldpd1, lldpd, lldpcli, namespaces):
158 with namespaces(2):
159 lldpd()
160 lldpcli("configure", "system", "chassisid", "Modified chassis ID")
161 lldpcli("unconfigure", "system", "chassisid")
162 lldpcli("update")
163 time.sleep(1)
164 with namespaces(1):
165 out = lldpcli("-f", "keyvalue", "show", "neighbors")
8b549648 166 assert out["lldp.eth0.chassis.mac"] == "00:00:00:00:00:02"
8481f490
VB
167
168
e0a84778
VB
169def test_hide_kernel(lldpd1, lldpd, lldpcli, namespaces):
170 with namespaces(2):
171 lldpd("-k")
172 with namespaces(1):
173 out = lldpcli("-f", "keyvalue", "show", "neighbors")
8b549648 174 assert out["lldp.eth0.chassis.descr"] == "Spectacular GNU/Linux 2016"
e0a84778
VB
175
176
177def test_listen_only(lldpd1, lldpd, lldpcli, namespaces):
178 with namespaces(2):
179 lldpd("-r")
180 with namespaces(1):
181 out = lldpcli("-f", "keyvalue", "show", "neighbors")
182 assert out == {}
183
184
b7b7dc34 185def test_forced_unknown_management_address(lldpd1, lldpd, lldpcli, namespaces):
e0a84778
VB
186 with namespaces(2):
187 lldpd("-m", "2001:db8::47")
188 with namespaces(1):
189 out = lldpcli("-f", "keyvalue", "show", "neighbors")
190 assert out["lldp.eth0.chassis.mgmt-ip"] == "2001:db8::47"
30fca74b 191 assert "lldp.eth0.chassis.mgmt-iface" not in out
e0a84778
VB
192
193
b7b7dc34
VB
194def test_forced_known_management_address(lldpd1, lldpd, lldpcli, namespaces):
195 with namespaces(2):
12e81bd1
VB
196 with pyroute2.IPRoute() as ipr:
197 idx = ipr.link_lookup(ifname="eth1")[0]
16a1a7e6 198 ipr.addr("add", index=idx, address="192.168.14.2", prefixlen=24)
b7b7dc34
VB
199 lldpd("-m", "192.168.14.2")
200 with namespaces(1):
201 out = lldpcli("-f", "keyvalue", "show", "neighbors")
202 assert out["lldp.eth0.chassis.mgmt-ip"] == "192.168.14.2"
203 assert out["lldp.eth0.chassis.mgmt-iface"] == "2"
204
205
e0a84778
VB
206def test_management_address(lldpd1, lldpd, lldpcli, links, namespaces):
207 with namespaces(2):
12e81bd1
VB
208 with pyroute2.IPRoute() as ipr:
209 idx = ipr.link_lookup(ifname="eth1")[0]
16a1a7e6
VB
210 ipr.addr("add", index=idx, address="192.168.14.2", prefixlen=24)
211 ipr.addr("add", index=idx, address="172.25.21.47", prefixlen=24)
e0a84778
VB
212 lldpd("-m", "172.25.*")
213 with namespaces(1):
214 out = lldpcli("-f", "keyvalue", "show", "neighbors")
215 assert out["lldp.eth0.chassis.mgmt-ip"] == "172.25.21.47"
d319b0de 216 assert out["lldp.eth0.chassis.mgmt-iface"] == "2"
e1717397
VB
217
218
68bc4a4d
VB
219def test_management_interface(lldpd1, lldpd, lldpcli, links, namespaces):
220 links(namespaces(1), namespaces(2), 4)
221 with namespaces(2):
12e81bd1
VB
222 with pyroute2.IPRoute() as ipr:
223 idx = ipr.link_lookup(ifname="eth1")[0]
16a1a7e6 224 ipr.addr("add", index=idx, address="192.168.14.2", prefixlen=24)
12e81bd1 225 idx = ipr.link_lookup(ifname="eth3")[0]
16a1a7e6 226 ipr.addr("add", index=idx, address="172.25.21.47", prefixlen=24)
68bc4a4d
VB
227 lldpd("-m", "eth3")
228 with namespaces(1):
229 out = lldpcli("-f", "keyvalue", "show", "neighbors")
8b549648
VB
230 assert out["lldp.eth0.chassis.mgmt-ip"] == [
231 "172.25.21.47",
232 "fe80::200:ff:fe00:4",
233 ]
68bc4a4d
VB
234 assert out["lldp.eth0.chassis.mgmt-iface"] == ["4", "4"]
235
236
878441b2
VB
237def test_change_management_address(lldpd1, lldpd, lldpcli, links, namespaces):
238 with namespaces(2):
12e81bd1
VB
239 with pyroute2.IPRoute() as ipr:
240 idx = ipr.link_lookup(ifname="eth1")[0]
16a1a7e6 241 ipr.addr("add", index=idx, address="192.168.14.2", prefixlen=24)
878441b2
VB
242 lldpd("-m", "192.168.*")
243 # We need a short TX interval as updating the IP address
244 # doesn't trigger a resend.
245 lldpcli("configure", "lldp", "tx-interval", "2")
246 with namespaces(1):
247 out = lldpcli("-f", "keyvalue", "show", "neighbors")
248 assert out["lldp.eth0.chassis.mgmt-ip"] == "192.168.14.2"
d319b0de 249 assert out["lldp.eth0.chassis.mgmt-iface"] == "2"
878441b2 250 with namespaces(2):
12e81bd1 251 with pyroute2.IPRoute() as ipr:
16a1a7e6
VB
252 ipr.addr("del", index=idx, address="192.168.14.2", prefixlen=24)
253 ipr.addr("add", index=idx, address="192.168.14.5", prefixlen=24)
878441b2
VB
254 time.sleep(5)
255 with namespaces(1):
256 out = lldpcli("-f", "keyvalue", "show", "neighbors")
257 assert out["lldp.eth0.chassis.mgmt-ip"] == "192.168.14.5"
d319b0de 258 assert out["lldp.eth0.chassis.mgmt-iface"] == "2"
878441b2
VB
259
260
e1717397
VB
261def test_portid_subtype_ifname(lldpd1, lldpd, lldpcli, namespaces):
262 with namespaces(2):
263 lldpd()
8fe53e87 264 lldpcli("configure", "lldp", "portidsubtype", "ifname")
e1717397
VB
265 time.sleep(3)
266 with namespaces(1):
267 out = lldpcli("-f", "keyvalue", "show", "neighbors")
268 assert out["lldp.eth0.port.ifname"] == "eth1"
269 assert out["lldp.eth0.port.descr"] == "eth1"
270
271
272def test_portid_subtype_with_alias(lldpd1, lldpd, lldpcli, links, namespaces):
273 with namespaces(2):
12e81bd1
VB
274 with pyroute2.IPRoute() as ipr:
275 idx = ipr.link_lookup(ifname="eth1")[0]
8b549648 276 ipr.link("set", index=idx, ifalias="alias of eth1")
e1717397
VB
277 lldpd()
278 with namespaces(1):
279 out = lldpcli("-f", "keyvalue", "show", "neighbors")
280 assert out["lldp.eth0.port.ifname"] == "eth1"
281 assert out["lldp.eth0.port.descr"] == "alias of eth1"
282
283
284def test_portid_subtype_macaddress(lldpd1, lldpd, lldpcli, links, namespaces):
285 with namespaces(2):
12e81bd1
VB
286 with pyroute2.IPRoute() as ipr:
287 idx = ipr.link_lookup(ifname="eth1")[0]
8b549648 288 ipr.link("set", index=idx, ifalias="alias of eth1")
e1717397 289 lldpd()
8fe53e87 290 lldpcli("configure", "lldp", "portidsubtype", "macaddress")
e1717397
VB
291 time.sleep(3)
292 with namespaces(1):
293 out = lldpcli("-f", "keyvalue", "show", "neighbors")
294 assert out["lldp.eth0.port.mac"] == "00:00:00:00:00:02"
295 assert out["lldp.eth0.port.descr"] == "eth1"
296
297
298def test_portid_subtype_local(lldpd1, lldpd, lldpcli, namespaces):
299 with namespaces(2):
300 lldpd()
8fe53e87 301 lldpcli("configure", "lldp", "portidsubtype", "local", "localname")
e1717397
VB
302 time.sleep(3)
303 with namespaces(1):
304 out = lldpcli("-f", "keyvalue", "show", "neighbors")
305 assert out["lldp.eth0.port.local"] == "localname"
306 assert out["lldp.eth0.port.descr"] == "eth1"
307
308
309def test_portid_subtype_local_with_description(lldpd1, lldpd, lldpcli, namespaces):
310 with namespaces(2):
311 lldpd()
8b549648
VB
312 lldpcli(
313 "configure",
314 "lldp",
315 "portidsubtype",
316 "local",
317 "localname",
318 "description",
319 "localdescription",
320 )
e1717397
VB
321 time.sleep(3)
322 with namespaces(1):
323 out = lldpcli("-f", "keyvalue", "show", "neighbors")
324 assert out["lldp.eth0.port.local"] == "localname"
325 assert out["lldp.eth0.port.descr"] == "localdescription"
326
327
5dd953f4
VB
328def test_portdescription(lldpd1, lldpd, lldpcli, namespaces):
329 with namespaces(2):
330 lldpd()
331 lldpcli("configure", "lldp", "portdescription", "localdescription")
332 time.sleep(3)
333 with namespaces(1):
334 out = lldpcli("-f", "keyvalue", "show", "neighbors")
335 assert out["lldp.eth0.port.descr"] == "localdescription"
336
337
e1717397
VB
338def test_portid_subtype_local_with_alias(lldpd1, lldpd, lldpcli, namespaces):
339 with namespaces(2):
12e81bd1
VB
340 with pyroute2.IPRoute() as ipr:
341 idx = ipr.link_lookup(ifname="eth1")[0]
8b549648 342 ipr.link("set", index=idx, ifalias="alias of eth1")
e1717397 343 lldpd()
8fe53e87 344 lldpcli("configure", "lldp", "portidsubtype", "local", "localname")
e1717397
VB
345 time.sleep(3)
346 with namespaces(1):
347 out = lldpcli("-f", "keyvalue", "show", "neighbors")
348 assert out["lldp.eth0.port.local"] == "localname"
349 assert out["lldp.eth0.port.descr"] == "alias of eth1"
6934b73d
VB
350
351
352def test_port_status_txonly(lldpd, lldpcli, namespaces, links):
353 links(namespaces(1), namespaces(2))
354 with namespaces(1):
355 lldpd()
356 lldpcli("configure", "lldp", "status", "tx-only")
357 with namespaces(2):
358 lldpd()
359 with namespaces(1):
360 out = lldpcli("-f", "keyvalue", "show", "neighbors")
361 assert out == {}
362 lldpcli("update")
363 with namespaces(2):
364 out = lldpcli("-f", "keyvalue", "show", "neighbors")
365 assert out["lldp.eth1.chassis.mac"] == "00:00:00:00:00:01"
366
367
368def test_port_status_rxonly(lldpd, lldpcli, namespaces, links):
369 links(namespaces(1), namespaces(2))
370 with namespaces(1):
371 lldpd()
372 lldpcli("configure", "lldp", "status", "rx-only")
373 with namespaces(2):
374 lldpd()
375 with namespaces(1):
376 out = lldpcli("-f", "keyvalue", "show", "neighbors")
377 assert out["lldp.eth0.chassis.mac"] == "00:00:00:00:00:02"
378 lldpcli("update")
379 with namespaces(2):
380 out = lldpcli("-f", "keyvalue", "show", "neighbors")
381 assert out == {}
382
383
384def test_port_status_rxandtx(lldpd, lldpcli, namespaces, links):
385 links(namespaces(1), namespaces(2))
386 with namespaces(1):
387 lldpd()
388 lldpcli("configure", "lldp", "status", "rx-and-tx") # noop
389 with namespaces(2):
390 lldpd()
391 with namespaces(1):
392 out = lldpcli("-f", "keyvalue", "show", "neighbors")
393 assert out["lldp.eth0.chassis.mac"] == "00:00:00:00:00:02"
394 lldpcli("update")
395 with namespaces(2):
396 out = lldpcli("-f", "keyvalue", "show", "neighbors")
397 assert out["lldp.eth1.chassis.mac"] == "00:00:00:00:00:01"
398
399
400def test_port_status_disabled(lldpd, lldpcli, namespaces, links):
401 links(namespaces(1), namespaces(2))
402 with namespaces(1):
403 lldpd()
404 lldpcli("configure", "lldp", "status", "disabled")
405 with namespaces(2):
406 lldpd()
407 with namespaces(1):
408 out = lldpcli("-f", "keyvalue", "show", "neighbors")
409 assert out == {}
410 lldpcli("update")
411 with namespaces(2):
412 out = lldpcli("-f", "keyvalue", "show", "neighbors")
413 assert out == {}
414
415
1e85286a
MW
416def test_port_vlan_tx(lldpd1, lldpd, lldpcli, namespaces):
417 with namespaces(1):
418 lldpd()
8b549648
VB
419 lldpcli(
420 "configure",
421 "ports",
422 "eth0",
423 "lldp",
424 "vlan-tx",
425 "100",
426 "priority",
427 "5",
428 "dei",
429 "1",
430 )
1e85286a 431 out = lldpcli("-f", "keyvalue", "show", "interfaces", "ports", "eth0")
8b549648
VB
432 assert out["lldp.eth0.port.vlanTX.id"] == "100"
433 assert out["lldp.eth0.port.vlanTX.prio"] == "5"
434 assert out["lldp.eth0.port.vlanTX.dei"] == "1"
1e85286a
MW
435 # unconfigure VLAN TX
436 lldpcli("unconfigure", "ports", "eth0", "lldp", "vlan-tx")
437 out = lldpcli("-f", "keyvalue", "show", "interfaces", "ports", "eth0")
12e81bd1
VB
438 assert "lldp.eth0.port.vlanTX.id" not in out
439 assert "lldp.eth0.port.vlanTX.prio" not in out
440 assert "lldp.eth0.port.vlanTX.dei" not in out
1e85286a
MW
441
442
08e05799
VB
443def test_set_interface_alias(lldpd1, lldpd, lldpcli, namespaces):
444 with namespaces(1):
445 lldpcli("configure", "system", "interface", "description")
446 with namespaces(2):
447 lldpd()
448 with namespaces(1):
12e81bd1 449 with pyroute2.IPRoute() as ipr:
8b549648
VB
450 link = ipr.link("get", ifname="eth0")[0]
451 assert (
452 link.get_attr("IFLA_IFALIAS") == "lldpd: connected to ns-2.example.com"
453 )
a9fe956f
VB
454
455
456def test_lldpdu_shutdown(lldpd, lldpcli, namespaces, links):
457 links(namespaces(1), namespaces(2))
458 links(namespaces(1), namespaces(2))
459 with namespaces(1):
460 lldpd()
fae9dd45 461 # From https://github.com/lldpd/lldpd/issues/348
8b549648
VB
462 frm_fa01 = (
463 scapy.all.Ether(
464 src="04:fe:7f:00:00:01", dst=scapy.contrib.lldp.LLDP_NEAREST_BRIDGE_MAC
465 )
466 / scapy.contrib.lldp.LLDPDUChassisID(
a9fe956f 467 subtype=scapy.contrib.lldp.LLDPDUChassisID.SUBTYPE_MAC_ADDRESS,
8b549648
VB
468 id=b"\x04\xfe\x7f\x00\x00\x00",
469 )
470 / scapy.contrib.lldp.LLDPDUPortID(
471 subtype=scapy.contrib.lldp.LLDPDUPortID.SUBTYPE_INTERFACE_NAME, id="Fa0/1"
472 )
473 / scapy.contrib.lldp.LLDPDUTimeToLive(ttl=65535)
474 / scapy.contrib.lldp.LLDPDUSystemName(
475 system_name="this info should not disappear"
476 )
477 / scapy.contrib.lldp.LLDPDUEndOfLLDPDU()
478 )
a9fe956f
VB
479 frm_fa01 = frm_fa01.build()
480 frm_fa01 = scapy.all.Ether(frm_fa01)
481
8b549648
VB
482 frm_fa02 = (
483 scapy.all.Ether(
484 src="04:fe:7f:00:00:02", dst=scapy.contrib.lldp.LLDP_NEAREST_BRIDGE_MAC
485 )
486 / scapy.contrib.lldp.LLDPDUChassisID(
a9fe956f 487 subtype=scapy.contrib.lldp.LLDPDUChassisID.SUBTYPE_MAC_ADDRESS,
8b549648
VB
488 id=b"\x04\xfe\x7f\x00\x00\x00",
489 )
490 / scapy.contrib.lldp.LLDPDUPortID(
491 subtype=scapy.contrib.lldp.LLDPDUPortID.SUBTYPE_INTERFACE_NAME, id="Fa0/2"
492 )
493 / scapy.contrib.lldp.LLDPDUTimeToLive(ttl=65535)
494 / scapy.contrib.lldp.LLDPDUSystemName(
495 system_name="this info should not disappear"
496 )
497 / scapy.contrib.lldp.LLDPDUEndOfLLDPDU()
498 )
a9fe956f
VB
499 frm_fa02 = frm_fa02.build()
500 frm_fa02 = scapy.all.Ether(frm_fa02)
501
8b549648
VB
502 frm_shut_fa01 = (
503 scapy.all.Ether(
504 src="04:fe:7f:00:00:01", dst=scapy.contrib.lldp.LLDP_NEAREST_BRIDGE_MAC
505 )
506 / scapy.contrib.lldp.LLDPDUChassisID(
a9fe956f 507 subtype=scapy.contrib.lldp.LLDPDUChassisID.SUBTYPE_MAC_ADDRESS,
8b549648
VB
508 id=b"\x04\xfe\x7f\x00\x00\x00",
509 )
510 / scapy.contrib.lldp.LLDPDUPortID(
511 subtype=scapy.contrib.lldp.LLDPDUPortID.SUBTYPE_INTERFACE_NAME, id="Fa0/1"
512 )
513 / scapy.contrib.lldp.LLDPDUTimeToLive(ttl=0)
514 / scapy.contrib.lldp.LLDPDUEndOfLLDPDU()
515 )
a9fe956f
VB
516 frm_shut_fa01 = frm_shut_fa01.build()
517 frm_shut_fa01 = scapy.all.Ether(frm_shut_fa01)
518
519 with namespaces(2):
8b549648
VB
520 scapy.all.sendp(frm_fa01, iface="eth1")
521 scapy.all.sendp(frm_fa02, iface="eth3")
a9fe956f
VB
522 time.sleep(2)
523 with namespaces(1):
524 out = lldpcli("-f", "keyvalue", "show", "neighbors")
8b549648
VB
525 del out["lldp.eth0.age"]
526 del out["lldp.eth2.age"]
a9fe956f
VB
527 assert out == {
528 "lldp.eth0.via": "LLDP",
529 "lldp.eth0.rid": "1",
530 "lldp.eth0.chassis.mac": "04:fe:7f:00:00:00",
531 "lldp.eth0.chassis.name": "this info should not disappear",
532 "lldp.eth0.port.ifname": "Fa0/1",
533 "lldp.eth0.port.ttl": "65535",
534 "lldp.eth2.via": "LLDP",
535 "lldp.eth2.rid": "1",
536 "lldp.eth2.chassis.mac": "04:fe:7f:00:00:00",
537 "lldp.eth2.chassis.name": "this info should not disappear",
538 "lldp.eth2.port.ifname": "Fa0/2",
8b549648
VB
539 "lldp.eth2.port.ttl": "65535",
540 }
a9fe956f 541 with namespaces(2):
8b549648 542 scapy.all.sendp(frm_shut_fa01, iface="eth1")
a9fe956f
VB
543 time.sleep(2)
544 with namespaces(1):
545 out = lldpcli("-f", "keyvalue", "show", "neighbors")
8b549648 546 del out["lldp.eth2.age"]
a9fe956f
VB
547 assert out == {
548 "lldp.eth2.via": "LLDP",
549 "lldp.eth2.rid": "1",
550 "lldp.eth2.chassis.mac": "04:fe:7f:00:00:00",
551 "lldp.eth2.chassis.name": "this info should not disappear",
552 "lldp.eth2.port.ifname": "Fa0/2",
8b549648
VB
553 "lldp.eth2.port.ttl": "65535",
554 }