MAP: Use explicit address/prefix types in API
[vpp.git] / test / bfd.py
index 09a7681..d99bbf6 100644 (file)
@@ -6,7 +6,7 @@ from scapy.all import bind_layers
 from scapy.layers.inet import UDP
 from scapy.packet import Packet
 from scapy.fields import BitField, BitEnumField, XByteField, FlagsField,\
-        ConditionalField, StrField
+    ConditionalField, StrField
 from vpp_object import VppObject
 from util import NumericConstant
 
@@ -35,9 +35,6 @@ class BFDDiagCode(NumericConstant):
         reverse_concatenated_path_down: "Reverse Concatenated Path Down",
     }
 
-    def __init__(self, value):
-        NumericConstant.__init__(self, value)
-
 
 class BFDState(NumericConstant):
     """ BFD State """
@@ -53,9 +50,6 @@ class BFDState(NumericConstant):
         up: "Up",
     }
 
-    def __init__(self, value):
-        NumericConstant.__init__(self, value)
-
 
 class BFDAuthType(NumericConstant):
     """ BFD Authentication Type """
@@ -75,9 +69,6 @@ class BFDAuthType(NumericConstant):
         meticulous_keyed_sha1: "Meticulous Keyed SHA1",
     }
 
-    def __init__(self, value):
-        NumericConstant.__init__(self, value)
-
 
 def bfd_is_auth_used(pkt):
     """ is packet authenticated? """
@@ -110,6 +101,7 @@ class BFD(Packet):
     """ BFD protocol layer for scapy """
 
     udp_dport = 3784  #: BFD destination port per RFC 5881
+    udp_dport_echo = 3785  # : BFD destination port for ECHO per RFC 5881
     udp_sport_min = 49152  #: BFD source port min value per RFC 5881
     udp_sport_max = 65535  #: BFD source port max value per RFC 5881
     bfd_pkt_len = 24  # : length of BFD pkt without authentication section
@@ -147,10 +139,33 @@ class BFD(Packet):
         return self.sprintf("BFD(my_disc=%BFD.my_discriminator%,"
                             "your_disc=%BFD.your_discriminator%)")
 
+
 # glue the BFD packet class to scapy parser
 bind_layers(UDP, BFD, dport=BFD.udp_dport)
 
 
+class BFD_vpp_echo(Packet):
+    """ BFD echo packet as used by VPP (non-rfc, as rfc doesn't define one) """
+
+    udp_dport = 3785  #: BFD echo destination port per RFC 5881
+    name = "BFD_VPP_ECHO"
+
+    fields_desc = [
+        BitField("discriminator", 0, 32),
+        BitField("expire_time_clocks", 0, 64),
+        BitField("checksum", 0, 64)
+    ]
+
+    def mysummary(self):
+        return self.sprintf(
+            "BFD_VPP_ECHO(disc=%BFD_VPP_ECHO.discriminator%,"
+            "expire_time_clocks=%BFD_VPP_ECHO.expire_time_clocks%)")
+
+
+# glue the BFD echo packet class to scapy parser
+bind_layers(UDP, BFD_vpp_echo, dport=BFD_vpp_echo.udp_dport)
+
+
 class VppBFDAuthKey(VppObject):
     """ Represents BFD authentication key in VPP """
 
@@ -176,6 +191,10 @@ class VppBFDAuthKey(VppObject):
         """ key data """
         return self._key
 
+    @key.setter
+    def key(self, value):
+        self._key = value
+
     @property
     def conf_key_id(self):
         """ configuration key ID """
@@ -211,7 +230,7 @@ class VppBFDUDPSession(VppObject):
     """ Represents BFD UDP session in VPP """
 
     def __init__(self, test, interface, peer_addr, local_addr=None, af=AF_INET,
-                 desired_min_tx=100000, required_min_rx=100000, detect_mult=3,
+                 desired_min_tx=300000, required_min_rx=300000, detect_mult=3,
                  sha1_key=None, bfd_key_id=None):
         self._test = test
         self._interface = interface
@@ -227,7 +246,10 @@ class VppBFDUDPSession(VppObject):
         self._required_min_rx = required_min_rx
         self._detect_mult = detect_mult
         self._sha1_key = sha1_key
-        self._bfd_key_id = bfd_key_id if bfd_key_id else randint(0, 255)
+        if bfd_key_id is not None:
+            self._bfd_key_id = bfd_key_id
+        else:
+            self._bfd_key_id = randint(0, 255)
 
     @property
     def test(self):
@@ -419,3 +441,12 @@ class VppBFDUDPSession(VppObject):
                                                  self.local_addr_n,
                                                  self.peer_addr_n,
                                                  is_ipv6=is_ipv6)
+
+    def admin_down(self):
+        """ set bfd session admin-down """
+        is_ipv6 = 1 if AF_INET6 == self._af else 0
+        self.test.vapi.bfd_udp_session_set_flags(0,
+                                                 self._interface.sw_if_index,
+                                                 self.local_addr_n,
+                                                 self.peer_addr_n,
+                                                 is_ipv6=is_ipv6)