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