]>
git.ipfire.org Git - thirdparty/lldpd.git/blob - tests/integration/test_basic.py
6 def test_one_neighbor(lldpd1
, lldpd
, lldpcli
, namespaces
):
10 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
11 assert out
['lldp.eth0.age'].startswith('0 day, 00:00:')
12 assert out
['lldp.eth0.chassis.descr'].startswith(
13 "Spectacular GNU/Linux 2016 Linux")
14 assert 'lldp.eth0.chassis.Router.enabled' in out
15 assert 'lldp.eth0.chassis.Station.enabled' in out
16 del out
['lldp.eth0.age']
17 del out
['lldp.eth0.chassis.descr']
18 del out
['lldp.eth0.chassis.Router.enabled']
19 del out
['lldp.eth0.chassis.Station.enabled']
20 assert out
== {"lldp.eth0.via": "LLDP",
22 "lldp.eth0.chassis.mac": "00:00:00:00:00:02",
23 "lldp.eth0.chassis.name": "ns-2.example.com",
24 "lldp.eth0.chassis.mgmt-ip": "fe80::200:ff:fe00:2",
25 "lldp.eth0.chassis.Bridge.enabled": "off",
26 "lldp.eth0.chassis.Wlan.enabled": "off",
27 "lldp.eth0.port.mac": "00:00:00:00:00:02",
28 "lldp.eth0.port.descr": "eth1",
29 "lldp.eth0.port.ttl": "120"}
32 @pytest.mark
.parametrize("neighbors", (5, 10, 20))
33 def test_several_neighbors(lldpd
, lldpcli
, links
, namespaces
, neighbors
):
34 for i
in range(2, neighbors
+ 1):
35 links(namespaces(1), namespaces(i
))
36 for i
in range(1, neighbors
+ 1):
38 lldpd(sleep
=(i
== 1 and 2 or 0),
42 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
43 for i
in range(2, neighbors
+ 1):
44 assert out
['lldp.eth{}.chassis.name'.format((i
- 2)*2)] == \
45 'ns-{}.example.com'.format(i
)
48 def test_one_interface(lldpd1
, lldpd
, lldpcli
, namespaces
):
52 out
= lldpcli("-f", "keyvalue", "show", "interfaces")
53 assert out
['lldp.eth0.chassis.descr'].startswith(
54 "Spectacular GNU/Linux 2016 Linux")
55 assert 'lldp.eth0.age' in out
56 assert 'lldp.eth0.chassis.Router.enabled' in out
57 assert 'lldp.eth0.chassis.Station.enabled' in out
58 del out
['lldp.eth0.age']
59 del out
['lldp.eth0.chassis.descr']
60 del out
['lldp.eth0.chassis.Router.enabled']
61 del out
['lldp.eth0.chassis.Station.enabled']
62 assert out
== {"lldp.eth0.via": "unknown",
63 "lldp.eth0.chassis.mac": "00:00:00:00:00:01",
64 "lldp.eth0.chassis.name": "ns-1.example.com",
65 "lldp.eth0.chassis.mgmt-ip": "fe80::200:ff:fe00:1",
66 "lldp.eth0.chassis.Bridge.enabled": "off",
67 "lldp.eth0.chassis.Wlan.enabled": "off",
68 "lldp.eth0.port.mac": "00:00:00:00:00:01",
69 "lldp.eth0.port.descr": "eth0",
70 "lldp.eth0.ttl.ttl": "120"}
72 @pytest.mark
.parametrize("interfaces", (5, 10, 20))
73 def test_several_interfaces(lldpd
, lldpcli
, links
, namespaces
, interfaces
):
74 for i
in range(2, interfaces
+ 1):
75 links(namespaces(1), namespaces(i
))
76 for i
in range(1, interfaces
+ 1):
80 out
= lldpcli("-f", "keyvalue", "show", "interfaces")
81 for i
in range(2, interfaces
+ 1):
82 assert out
['lldp.eth{}.chassis.mac'.format((i
- 2)*2)] == \
84 assert out
['lldp.eth{}.port.mac'.format((i
- 2)*2)] == \
85 '00:00:00:00:00:{num:02x}'.format(num
=(i
- 2)*2 + 1)
88 def test_overrided_description(lldpd1
, lldpd
, lldpcli
, namespaces
):
90 lldpd("-S", "Modified description")
92 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
93 assert out
['lldp.eth0.chassis.descr'] == "Modified description"
96 def test_overrided_description2(lldpd1
, lldpd
, lldpcli
, namespaces
):
99 lldpcli("configure", "system", "description", "Modified description")
103 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
104 assert out
['lldp.eth0.chassis.descr'] == "Modified description"
107 def test_overrided_chassisid(lldpd1
, lldpd
, lldpcli
, namespaces
):
110 lldpcli("configure", "system", "chassisid", "Modified chassis ID")
114 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
115 assert out
['lldp.eth0.chassis.local'] == "Modified chassis ID"
118 def test_overrided_chassisid_reverse(lldpd1
, lldpd
, lldpcli
, namespaces
):
121 lldpcli("configure", "system", "chassisid", "Modified chassis ID")
122 lldpcli("unconfigure", "system", "chassisid")
126 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
127 assert out
['lldp.eth0.chassis.mac'] == "00:00:00:00:00:02"
130 def test_hide_kernel(lldpd1
, lldpd
, lldpcli
, namespaces
):
134 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
135 assert out
["lldp.eth0.chassis.descr"] == \
136 "Spectacular GNU/Linux 2016"
139 def test_listen_only(lldpd1
, lldpd
, lldpcli
, namespaces
):
143 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
147 def test_forced_management_address(lldpd1
, lldpd
, lldpcli
, namespaces
):
149 lldpd("-m", "2001:db8::47")
151 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
152 assert out
["lldp.eth0.chassis.mgmt-ip"] == "2001:db8::47"
155 def test_management_address(lldpd1
, lldpd
, lldpcli
, links
, namespaces
):
157 ipr
= pyroute2
.IPRoute()
158 idx
= ipr
.link_lookup(ifname
="eth1")[0]
159 ipr
.addr('add', index
=idx
, address
="192.168.14.2", mask
=24)
160 ipr
.addr('add', index
=idx
, address
="172.25.21.47", mask
=24)
161 lldpd("-m", "172.25.*")
163 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
164 assert out
["lldp.eth0.chassis.mgmt-ip"] == "172.25.21.47"
167 def test_change_management_address(lldpd1
, lldpd
, lldpcli
, links
, namespaces
):
169 ipr
= pyroute2
.IPRoute()
170 idx
= ipr
.link_lookup(ifname
="eth1")[0]
171 ipr
.addr('add', index
=idx
, address
="192.168.14.2", mask
=24)
172 lldpd("-m", "192.168.*")
173 # We need a short TX interval as updating the IP address
174 # doesn't trigger a resend.
175 lldpcli("configure", "lldp", "tx-interval", "2")
177 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
178 assert out
["lldp.eth0.chassis.mgmt-ip"] == "192.168.14.2"
180 ipr
.addr('del', index
=idx
, address
="192.168.14.2", mask
=24)
181 ipr
.addr('add', index
=idx
, address
="192.168.14.5", mask
=24)
184 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
185 assert out
["lldp.eth0.chassis.mgmt-ip"] == "192.168.14.5"
188 def test_portid_subtype_ifname(lldpd1
, lldpd
, lldpcli
, namespaces
):
191 lldpcli("configure", "lldp", "portidsubtype", "ifname")
194 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
195 assert out
["lldp.eth0.port.ifname"] == "eth1"
196 assert out
["lldp.eth0.port.descr"] == "eth1"
199 def test_portid_subtype_with_alias(lldpd1
, lldpd
, lldpcli
, links
, namespaces
):
201 ipr
= pyroute2
.IPRoute()
202 idx
= ipr
.link_lookup(ifname
="eth1")[0]
203 ipr
.link('set', index
=idx
, ifalias
="alias of eth1")
206 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
207 assert out
["lldp.eth0.port.ifname"] == "eth1"
208 assert out
["lldp.eth0.port.descr"] == "alias of eth1"
211 def test_portid_subtype_macaddress(lldpd1
, lldpd
, lldpcli
, links
, namespaces
):
213 ipr
= pyroute2
.IPRoute()
214 idx
= ipr
.link_lookup(ifname
="eth1")[0]
215 ipr
.link('set', index
=idx
, ifalias
="alias of eth1")
217 lldpcli("configure", "lldp", "portidsubtype", "macaddress")
220 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
221 assert out
["lldp.eth0.port.mac"] == "00:00:00:00:00:02"
222 assert out
["lldp.eth0.port.descr"] == "eth1"
225 def test_portid_subtype_local(lldpd1
, lldpd
, lldpcli
, namespaces
):
228 lldpcli("configure", "lldp", "portidsubtype", "local", "localname")
231 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
232 assert out
["lldp.eth0.port.local"] == "localname"
233 assert out
["lldp.eth0.port.descr"] == "eth1"
236 def test_portid_subtype_local_with_description(lldpd1
, lldpd
, lldpcli
, namespaces
):
239 lldpcli("configure", "lldp", "portidsubtype", "local", "localname", "description", "localdescription")
242 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
243 assert out
["lldp.eth0.port.local"] == "localname"
244 assert out
["lldp.eth0.port.descr"] == "localdescription"
247 def test_portdescription(lldpd1
, lldpd
, lldpcli
, namespaces
):
250 lldpcli("configure", "lldp", "portdescription", "localdescription")
253 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
254 assert out
["lldp.eth0.port.descr"] == "localdescription"
257 def test_portid_subtype_local_with_alias(lldpd1
, lldpd
, lldpcli
, namespaces
):
259 ipr
= pyroute2
.IPRoute()
260 idx
= ipr
.link_lookup(ifname
="eth1")[0]
261 ipr
.link('set', index
=idx
, ifalias
="alias of eth1")
264 lldpcli("configure", "lldp", "portidsubtype", "local", "localname")
267 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
268 assert out
["lldp.eth0.port.local"] == "localname"
269 assert out
["lldp.eth0.port.descr"] == "alias of eth1"
272 def test_port_status_txonly(lldpd
, lldpcli
, namespaces
, links
):
273 links(namespaces(1), namespaces(2))
276 lldpcli("configure", "lldp", "status", "tx-only")
280 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
284 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
285 assert out
["lldp.eth1.chassis.mac"] == "00:00:00:00:00:01"
288 def test_port_status_rxonly(lldpd
, lldpcli
, namespaces
, links
):
289 links(namespaces(1), namespaces(2))
292 lldpcli("configure", "lldp", "status", "rx-only")
296 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
297 assert out
["lldp.eth0.chassis.mac"] == "00:00:00:00:00:02"
300 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
304 def test_port_status_rxandtx(lldpd
, lldpcli
, namespaces
, links
):
305 links(namespaces(1), namespaces(2))
308 lldpcli("configure", "lldp", "status", "rx-and-tx") # noop
312 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
313 assert out
["lldp.eth0.chassis.mac"] == "00:00:00:00:00:02"
316 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
317 assert out
["lldp.eth1.chassis.mac"] == "00:00:00:00:00:01"
320 def test_port_status_disabled(lldpd
, lldpcli
, namespaces
, links
):
321 links(namespaces(1), namespaces(2))
324 lldpcli("configure", "lldp", "status", "disabled")
328 out
= lldpcli("-f", "keyvalue", "show", "neighbors")
332 out
= lldpcli("-f", "keyvalue", "show", "neighbors")