session: optimize ct fifo segment allocations
[vpp.git] / test / test_cdp.py
index ac42bf0..46751e8 100644 (file)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 """ CDP tests """
 
 from scapy.packet import Packet
@@ -13,6 +13,8 @@ from re import compile
 from time import sleep
 from util import ppp
 import platform
+import sys
+import unittest
 
 
 """ TestCDP is a subclass of  VPPTestCase classes.
@@ -71,24 +73,29 @@ class TestCDP(VppTestCase):
             super(TestCDP, cls).tearDownClass()
             raise
 
+    @classmethod
+    def tearDownClass(cls):
+        super(TestCDP, cls).tearDownClass()
+
     def test_enable_cdp(self):
-        self.logger.info(self.vapi.cli("cdp enable"))
+        self.logger.info(self.vapi.cdp_enable_disable(enable_disable=1))
         ret = self.vapi.cli("show cdp")
         self.logger.info(ret)
         not_enabled = self.nen_ptr.search(ret)
         self.assertFalse(not_enabled, "CDP isn't enabled")
 
     def test_send_cdp_packet(self):
-        self.logger.info(self.vapi.cli("cdp enable"))
+        self.logger.info(self.vapi.cdp_enable_disable(enable_disable=1))
         self.send_packet(self.create_packet())
 
         neighbors = list(self.show_cdp())
         self.assertTrue(neighbors, "CDP didn't register neighbor")
 
         port, system = neighbors[0]
+        length = min(len(system), len(self.device_id))
 
         self.assert_equal(port, self.port_id, "CDP received invalid port id")
-        self.assert_equal(system, self.device_id,
+        self.assert_equal(system[:length], self.device_id[:length],
                           "CDP received invalid device id")
 
     def test_cdp_underflow_tlv(self):
@@ -98,21 +105,12 @@ class TestCDP(VppTestCase):
         self.send_bad_packet(8, ".")
 
     def send_bad_packet(self, l, v):
-        self.logger.info(self.vapi.cli("cdp enable"))
+        self.logger.info(self.vapi.cdp_enable_disable(enable_disable=1))
         self.send_packet(self.create_bad_packet(l, v))
 
-        errors = list(self.show_errors())
-        self.assertTrue(errors)
-
-        expected_errors = False
-        for count, node, reason in errors:
-            if (node == u'cdp-input' and
-                    reason == u'cdp packets with bad TLVs' and
-                    int(count) >= 1):
-
-                expected_errors = True
-                break
-        self.assertTrue(expected_errors, "CDP didn't drop bad packet")
+        err = self.statistics.get_err_counter(
+            '/err/cdp-input/cdp packets with bad TLVs')
+        self.assertTrue(err >= 1, "CDP didn't drop bad packet")
 
     def send_packet(self, packet):
         self.logger.debug(ppp("Sending packet:", packet))
@@ -155,12 +153,3 @@ class TestCDP(VppTestCase):
                 pass
             else:
                 yield port, system
-
-    def show_errors(self):
-        for pack in self.process_cli("show errors", self.err_ptr):
-            try:
-                count, node, reason = pack
-            except ValueError:
-                pass
-            else:
-                yield count, node, reason