]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
tests: use a PCAP file to do some integration tests
authorVincent Bernat <vincent@bernat.im>
Fri, 25 Nov 2016 20:09:15 +0000 (21:09 +0100)
committerVincent Bernat <vincent@bernat.im>
Fri, 25 Nov 2016 20:09:55 +0000 (21:09 +0100)
tests/ci/install.sh
tests/integration/data/sg200.pcap [new file with mode: 0644]
tests/integration/fixtures/programs.py
tests/integration/test_pcap.py [new file with mode: 0644]

index 070ef5f0c5b479ef043f3045e39b40d1ba07f0b3..f6f9cf8ba16f4a7a87213a957fdd873fce33483e 100755 (executable)
@@ -19,7 +19,8 @@ case "$(uname -s)" in
             automake autoconf libtool pkg-config \
             libsnmp-dev libxml2-dev libjansson-dev libjson-c-dev \
             libevent-dev libreadline-dev libbsd-dev \
-            check libc6-dbg libevent-dbg libseccomp-dev
+            check libc6-dbg libevent-dbg libseccomp-dev \
+            libpcap-dev
         [ $CC != gcc ] || \
             sudo apt-get -qqy install gcc-5
         # For integration tests
diff --git a/tests/integration/data/sg200.pcap b/tests/integration/data/sg200.pcap
new file mode 100644 (file)
index 0000000..619150d
Binary files /dev/null and b/tests/integration/data/sg200.pcap differ
index d49fdbcbc30a55a02727cc822186495954633710..8f91db5825b523fbed1f8729fced0cb346c949e1 100644 (file)
@@ -78,6 +78,7 @@ def most_recent(*args):
     assert len(candidates) > 0
     return candidates[0]
 
+
 libtool_location = most_recent('../../libtool',
                                '../../*/libtool')
 lldpcli_location = most_recent('../../src/client/lldpcli',
diff --git a/tests/integration/test_pcap.py b/tests/integration/test_pcap.py
new file mode 100644 (file)
index 0000000..1bab143
--- /dev/null
@@ -0,0 +1,63 @@
+import socket
+import struct
+
+
+def send_pcap(location, interface):
+    """Send a PCAP file to the given interface. It is assumed that all
+    pcap files are little-endian."""
+    with open(location, 'rb') as f:
+        hdr = f.read(24)
+        magic, major, minor, _, _, _, network = struct.unpack("<IHHiIII",
+                                                              hdr)
+        assert(magic == 0xa1b2c3d4)
+        assert(major == 2)
+        assert(minor == 4)
+        assert(network == 1)
+        hdr = f.read(16)
+        _, _, ilen, olen = struct.unpack("<IIII", hdr)
+        assert(ilen == olen)
+        content = f.read(ilen)
+        s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW)
+        s.bind((interface, 0))
+        s.send(content)
+
+
+class TestPcapCaptures(object):
+
+    def test_cisco_sg200(self, lldpd1, lldpcli, namespaces):
+        with namespaces(2):
+            send_pcap('data/sg200.pcap', 'eth1')
+        with namespaces(1):
+            out = lldpcli("-f", "keyvalue", "show", "neighbors", "details")
+            assert out['lldp.eth0.age'].startswith('0 day, 00:00:')
+            del out['lldp.eth0.age']
+            assert out == {
+                "lldp.eth0.via": "LLDP",
+                "lldp.eth0.rid": "1",
+                "lldp.eth0.chassis.mac": "00:35:35:35:35:35",
+                "lldp.eth0.chassis.ttl": "120",
+                "lldp.eth0.port.ifname": "g1",
+                "lldp.eth0.port.auto-negotiation.supported": "yes",
+                "lldp.eth0.port.auto-negotiation.enabled": "yes",
+                "lldp.eth0.port.auto-negotiation.1000Base-T.hd": "no",
+                "lldp.eth0.port.auto-negotiation.1000Base-T.fd": "yes",
+                "lldp.eth0.port.auto-negotiation.current": "unknown",
+                "lldp.eth0.lldp-med.device-type":
+                "Network Connectivity Device",
+                "lldp.eth0.lldp-med.Capabilities.available": "yes",
+                "lldp.eth0.lldp-med.Policy.available": "yes",
+                "lldp.eth0.lldp-med.Location.available": "yes",
+                "lldp.eth0.lldp-med.MDI/PSE.available": "yes",
+                "lldp.eth0.lldp-med.Inventory.available": "yes",
+                "lldp.eth0.lldp-med.Civic address.country": "DE",
+                "lldp.eth0.lldp-med.Civic address.city": "Berlin",
+                "lldp.eth0.lldp-med.Civic address.street":
+                "Karl-Liebknecht-Strase",
+                "lldp.eth0.lldp-med.Civic address.building": "42",
+                "lldp.eth0.lldp-med.inventory.hardware": "V02",
+                "lldp.eth0.lldp-med.inventory.software": "1.0.8.3",
+                "lldp.eth0.lldp-med.inventory.firmware": "1.0.8.3",
+                "lldp.eth0.lldp-med.inventory.serial": "XXX11111ZZZ",
+                "lldp.eth0.lldp-med.inventory.manufacturer": "0xbc00",
+                "lldp.eth0.lldp-med.inventory.model": "SG 200-08P",
+                "lldp.eth0.lldp-med.inventory.asset": "1"}