]>
Commit | Line | Data |
---|---|---|
9e6b5cf2 | 1 | import pytest |
2063390b VB |
2 | import socket |
3 | import struct | |
4 | ||
5 | ||
6 | def send_pcap(location, interface): | |
7 | """Send a PCAP file to the given interface. It is assumed that all | |
8 | pcap files are little-endian.""" | |
9 | with open(location, 'rb') as f: | |
10 | hdr = f.read(24) | |
11 | magic, major, minor, _, _, _, network = struct.unpack("<IHHiIII", | |
12 | hdr) | |
13 | assert(magic == 0xa1b2c3d4) | |
14 | assert(major == 2) | |
15 | assert(minor == 4) | |
16 | assert(network == 1) | |
17 | hdr = f.read(16) | |
18 | _, _, ilen, olen = struct.unpack("<IIII", hdr) | |
19 | assert(ilen == olen) | |
20 | content = f.read(ilen) | |
21 | s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW) | |
22 | s.bind((interface, 0)) | |
23 | s.send(content) | |
24 | ||
25 | ||
26 | class TestPcapCaptures(object): | |
27 | ||
f6bbc43b | 28 | def test_cisco_sg200(self, request, lldpd1, lldpcli, namespaces): |
2063390b VB |
29 | with namespaces(2): |
30 | send_pcap('data/sg200.pcap', 'eth1') | |
31 | with namespaces(1): | |
32 | out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") | |
33 | assert out['lldp.eth0.age'].startswith('0 day, 00:00:') | |
34 | del out['lldp.eth0.age'] | |
9e6b5cf2 | 35 | expected = { |
2063390b VB |
36 | "lldp.eth0.via": "LLDP", |
37 | "lldp.eth0.rid": "1", | |
38 | "lldp.eth0.chassis.mac": "00:35:35:35:35:35", | |
78346c89 | 39 | "lldp.eth0.port.ttl": "120", |
2063390b | 40 | "lldp.eth0.port.ifname": "g1", |
9e6b5cf2 | 41 | } |
f6bbc43b | 42 | if 'Dot3' in request.config.lldpd.features: |
f729e885 VB |
43 | expected.update({ |
44 | "lldp.eth0.port.auto-negotiation.supported": "yes", | |
45 | "lldp.eth0.port.auto-negotiation.enabled": "yes", | |
46 | "lldp.eth0.port.auto-negotiation.1000Base-T.hd": "no", | |
47 | "lldp.eth0.port.auto-negotiation.1000Base-T.fd": "yes", | |
48 | "lldp.eth0.port.auto-negotiation.current": "unknown", | |
49 | }) | |
f6bbc43b | 50 | if 'LLDP-MED' in request.config.lldpd.features: |
9e6b5cf2 VB |
51 | expected.update({ |
52 | "lldp.eth0.lldp-med.device-type": | |
53 | "Network Connectivity Device", | |
54 | "lldp.eth0.lldp-med.Capabilities.available": "yes", | |
55 | "lldp.eth0.lldp-med.Policy.available": "yes", | |
56 | "lldp.eth0.lldp-med.Location.available": "yes", | |
57 | "lldp.eth0.lldp-med.MDI/PSE.available": "yes", | |
58 | "lldp.eth0.lldp-med.Inventory.available": "yes", | |
59 | "lldp.eth0.lldp-med.Civic address.country": "DE", | |
60 | "lldp.eth0.lldp-med.Civic address.city": "Berlin", | |
61 | "lldp.eth0.lldp-med.Civic address.street": | |
62 | "Karl-Liebknecht-Strase", | |
63 | "lldp.eth0.lldp-med.Civic address.building": "42", | |
64 | "lldp.eth0.lldp-med.inventory.hardware": "V02", | |
65 | "lldp.eth0.lldp-med.inventory.software": "1.0.8.3", | |
66 | "lldp.eth0.lldp-med.inventory.firmware": "1.0.8.3", | |
67 | "lldp.eth0.lldp-med.inventory.serial": "XXX11111ZZZ", | |
68 | "lldp.eth0.lldp-med.inventory.manufacturer": "0xbc00", | |
69 | "lldp.eth0.lldp-med.inventory.model": "SG 200-08P", | |
70 | "lldp.eth0.lldp-med.inventory.asset": "1" | |
71 | }) | |
72 | assert out == expected |