blob: 4189983b4305dd9ebc964436c3fe1527d39544e0 [file] [log] [blame]
Klement Sekerad3ba5152017-02-14 03:09:17 +01001""" BFD protocol implementation """
2
Klement Sekerab17dd962017-01-09 07:43:48 +01003from random import randint
Klement Sekerad3ba5152017-02-14 03:09:17 +01004from socket import AF_INET, AF_INET6, inet_pton
5from scapy.all import bind_layers
6from scapy.layers.inet import UDP
7from scapy.packet import Packet
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02008from scapy.fields import (
9 BitField,
10 BitEnumField,
11 XByteField,
12 FlagsField,
13 ConditionalField,
14 StrField,
15)
Klement Sekerad3ba5152017-02-14 03:09:17 +010016from vpp_object import VppObject
Klement Sekera0e3c0de2016-09-29 14:43:44 +020017from util import NumericConstant
Jakub Grajciar4682feb2019-09-02 13:28:52 +020018from vpp_papi import VppEnum
Klement Sekera0e3c0de2016-09-29 14:43:44 +020019
20
21class BFDDiagCode(NumericConstant):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020022 """BFD Diagnostic Code"""
23
Klement Sekera0e3c0de2016-09-29 14:43:44 +020024 no_diagnostic = 0
25 control_detection_time_expired = 1
26 echo_function_failed = 2
27 neighbor_signaled_session_down = 3
28 forwarding_plane_reset = 4
29 path_down = 5
30 concatenated_path_down = 6
31 administratively_down = 7
32 reverse_concatenated_path_down = 8
33
34 desc_dict = {
35 no_diagnostic: "No diagnostic",
36 control_detection_time_expired: "Control Detection Time Expired",
37 echo_function_failed: "Echo Function Failed",
38 neighbor_signaled_session_down: "Neighbor Signaled Session Down",
39 forwarding_plane_reset: "Forwarding Plane Reset",
40 path_down: "Path Down",
41 concatenated_path_down: "Concatenated Path Down",
42 administratively_down: "Administratively Down",
43 reverse_concatenated_path_down: "Reverse Concatenated Path Down",
44 }
45
Klement Sekera0e3c0de2016-09-29 14:43:44 +020046
47class BFDState(NumericConstant):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020048 """BFD State"""
49
Klement Sekera0e3c0de2016-09-29 14:43:44 +020050 admin_down = 0
51 down = 1
52 init = 2
53 up = 3
54
55 desc_dict = {
56 admin_down: "AdminDown",
57 down: "Down",
58 init: "Init",
59 up: "Up",
60 }
61
Klement Sekera0e3c0de2016-09-29 14:43:44 +020062
Klement Sekerab17dd962017-01-09 07:43:48 +010063class BFDAuthType(NumericConstant):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020064 """BFD Authentication Type"""
65
Klement Sekerab17dd962017-01-09 07:43:48 +010066 no_auth = 0
67 simple_pwd = 1
68 keyed_md5 = 2
69 meticulous_keyed_md5 = 3
70 keyed_sha1 = 4
71 meticulous_keyed_sha1 = 5
72
73 desc_dict = {
74 no_auth: "No authentication",
75 simple_pwd: "Simple Password",
76 keyed_md5: "Keyed MD5",
77 meticulous_keyed_md5: "Meticulous Keyed MD5",
78 keyed_sha1: "Keyed SHA1",
79 meticulous_keyed_sha1: "Meticulous Keyed SHA1",
80 }
81
Klement Sekerab17dd962017-01-09 07:43:48 +010082
83def bfd_is_auth_used(pkt):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020084 """is packet authenticated?"""
Klement Sekerab17dd962017-01-09 07:43:48 +010085 return "A" in pkt.sprintf("%BFD.flags%")
86
87
88def bfd_is_simple_pwd_used(pkt):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020089 """is simple password authentication used?"""
Klement Sekerab17dd962017-01-09 07:43:48 +010090 return bfd_is_auth_used(pkt) and pkt.auth_type == BFDAuthType.simple_pwd
91
92
93def bfd_is_sha1_used(pkt):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020094 """is sha1 authentication used?"""
95 return bfd_is_auth_used(pkt) and pkt.auth_type in (
96 BFDAuthType.keyed_sha1,
97 BFDAuthType.meticulous_keyed_sha1,
98 )
Klement Sekerab17dd962017-01-09 07:43:48 +010099
100
101def bfd_is_md5_used(pkt):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200102 """is md5 authentication used?"""
103 return bfd_is_auth_used(pkt) and pkt.auth_type in (
104 BFDAuthType.keyed_md5,
105 BFDAuthType.meticulous_keyed_md5,
106 )
Klement Sekerab17dd962017-01-09 07:43:48 +0100107
108
109def bfd_is_md5_or_sha1_used(pkt):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200110 """is md5 or sha1 used?"""
Klement Sekerab17dd962017-01-09 07:43:48 +0100111 return bfd_is_md5_used(pkt) or bfd_is_sha1_used(pkt)
112
113
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200114class BFD(Packet):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200115 """BFD protocol layer for scapy"""
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200116
117 udp_dport = 3784 #: BFD destination port per RFC 5881
Klement Sekeraaeeac3b2017-02-14 07:11:52 +0100118 udp_dport_echo = 3785 # : BFD destination port for ECHO per RFC 5881
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200119 udp_sport_min = 49152 #: BFD source port min value per RFC 5881
120 udp_sport_max = 65535 #: BFD source port max value per RFC 5881
Klement Sekerab17dd962017-01-09 07:43:48 +0100121 bfd_pkt_len = 24 # : length of BFD pkt without authentication section
122 sha1_auth_len = 28 # : length of authentication section if SHA1 used
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200123
124 name = "BFD"
125
126 fields_desc = [
127 BitField("version", 1, 3),
128 BitEnumField("diag", 0, 5, BFDDiagCode.desc_dict),
129 BitEnumField("state", 0, 2, BFDState.desc_dict),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200130 FlagsField("flags", 0, 6, ["M", "D", "A", "C", "F", "P"]),
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200131 XByteField("detect_mult", 0),
Klement Sekerab17dd962017-01-09 07:43:48 +0100132 BitField("length", bfd_pkt_len, 8),
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200133 BitField("my_discriminator", 0, 32),
134 BitField("your_discriminator", 0, 32),
135 BitField("desired_min_tx_interval", 0, 32),
136 BitField("required_min_rx_interval", 0, 32),
Klement Sekerab17dd962017-01-09 07:43:48 +0100137 BitField("required_min_echo_rx_interval", 0, 32),
138 ConditionalField(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200139 BitEnumField("auth_type", 0, 8, BFDAuthType.desc_dict), bfd_is_auth_used
140 ),
Klement Sekerab17dd962017-01-09 07:43:48 +0100141 ConditionalField(BitField("auth_len", 0, 8), bfd_is_auth_used),
142 ConditionalField(BitField("auth_key_id", 0, 8), bfd_is_auth_used),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200143 ConditionalField(BitField("auth_reserved", 0, 8), bfd_is_md5_or_sha1_used),
144 ConditionalField(BitField("auth_seq_num", 0, 32), bfd_is_md5_or_sha1_used),
Klement Sekerab17dd962017-01-09 07:43:48 +0100145 ConditionalField(StrField("auth_key_hash", "0" * 16), bfd_is_md5_used),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200146 ConditionalField(StrField("auth_key_hash", "0" * 20), bfd_is_sha1_used),
Klement Sekerab17dd962017-01-09 07:43:48 +0100147 ]
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200148
149 def mysummary(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200150 return self.sprintf(
151 "BFD(my_disc=%BFD.my_discriminator%, your_disc=%BFD.your_discriminator%)"
152 )
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200153
Klement Sekera31da2e32018-06-24 22:49:55 +0200154
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200155# glue the BFD packet class to scapy parser
156bind_layers(UDP, BFD, dport=BFD.udp_dport)
157
158
Klement Sekera239790f2017-02-16 10:53:53 +0100159class BFD_vpp_echo(Packet):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200160 """BFD echo packet as used by VPP (non-rfc, as rfc doesn't define one)"""
Klement Sekera239790f2017-02-16 10:53:53 +0100161
162 udp_dport = 3785 #: BFD echo destination port per RFC 5881
163 name = "BFD_VPP_ECHO"
164
165 fields_desc = [
166 BitField("discriminator", 0, 32),
167 BitField("expire_time_clocks", 0, 64),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200168 BitField("checksum", 0, 64),
Klement Sekera239790f2017-02-16 10:53:53 +0100169 ]
170
171 def mysummary(self):
172 return self.sprintf(
173 "BFD_VPP_ECHO(disc=%BFD_VPP_ECHO.discriminator%,"
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200174 "expire_time_clocks=%BFD_VPP_ECHO.expire_time_clocks%)"
175 )
Klement Sekera239790f2017-02-16 10:53:53 +0100176
Klement Sekera31da2e32018-06-24 22:49:55 +0200177
Klement Sekera239790f2017-02-16 10:53:53 +0100178# glue the BFD echo packet class to scapy parser
179bind_layers(UDP, BFD_vpp_echo, dport=BFD_vpp_echo.udp_dport)
180
181
Klement Sekerab17dd962017-01-09 07:43:48 +0100182class VppBFDAuthKey(VppObject):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200183 """Represents BFD authentication key in VPP"""
Klement Sekerab17dd962017-01-09 07:43:48 +0100184
185 def __init__(self, test, conf_key_id, auth_type, key):
186 self._test = test
187 self._key = key
188 self._auth_type = auth_type
189 test.assertIn(auth_type, BFDAuthType.desc_dict)
190 self._conf_key_id = conf_key_id
191
192 @property
193 def test(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200194 """Test which created this key"""
Klement Sekerab17dd962017-01-09 07:43:48 +0100195 return self._test
196
197 @property
198 def auth_type(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200199 """Authentication type for this key"""
Klement Sekerab17dd962017-01-09 07:43:48 +0100200 return self._auth_type
201
202 @property
203 def key(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200204 """key data"""
Klement Sekerab17dd962017-01-09 07:43:48 +0100205 return self._key
206
Klement Sekera73884482017-02-23 09:26:30 +0100207 @key.setter
208 def key(self, value):
209 self._key = value
210
Klement Sekerab17dd962017-01-09 07:43:48 +0100211 @property
212 def conf_key_id(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200213 """configuration key ID"""
Klement Sekerab17dd962017-01-09 07:43:48 +0100214 return self._conf_key_id
215
216 def add_vpp_config(self):
217 self.test.vapi.bfd_auth_set_key(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200218 conf_key_id=self._conf_key_id,
219 auth_type=self._auth_type,
220 key=self._key,
221 key_len=len(self._key),
222 )
Klement Sekerab17dd962017-01-09 07:43:48 +0100223 self._test.registry.register(self, self.test.logger)
224
225 def get_bfd_auth_keys_dump_entry(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200226 """get the entry in the auth keys dump corresponding to this key"""
Klement Sekerab17dd962017-01-09 07:43:48 +0100227 result = self.test.vapi.bfd_auth_keys_dump()
228 for k in result:
229 if k.conf_key_id == self._conf_key_id:
230 return k
231 return None
232
233 def query_vpp_config(self):
234 return self.get_bfd_auth_keys_dump_entry() is not None
235
236 def remove_vpp_config(self):
Jakub Grajciar4682feb2019-09-02 13:28:52 +0200237 self.test.vapi.bfd_auth_del_key(conf_key_id=self._conf_key_id)
Klement Sekerab17dd962017-01-09 07:43:48 +0100238
239 def object_id(self):
240 return "bfd-auth-key-%s" % self._conf_key_id
241
Klement Sekerab17dd962017-01-09 07:43:48 +0100242
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200243class VppBFDUDPSession(VppObject):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200244 """Represents BFD UDP session in VPP"""
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200245
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200246 def __init__(
247 self,
248 test,
249 interface,
250 peer_addr,
251 local_addr=None,
252 af=AF_INET,
253 desired_min_tx=300000,
254 required_min_rx=300000,
255 detect_mult=3,
256 sha1_key=None,
257 bfd_key_id=None,
258 is_tunnel=False,
259 ):
Klement Sekerab17dd962017-01-09 07:43:48 +0100260 self._test = test
261 self._interface = interface
262 self._af = af
Jakub Grajciar4682feb2019-09-02 13:28:52 +0200263 if local_addr:
Neale Rannsefd7bc22019-11-11 08:32:34 +0000264 self._local_addr = local_addr
Klement Sekerad3ba5152017-02-14 03:09:17 +0100265 else:
Jakub Grajciar4682feb2019-09-02 13:28:52 +0200266 self._local_addr = None
Neale Rannsefd7bc22019-11-11 08:32:34 +0000267 self._peer_addr = peer_addr
Klement Sekerab17dd962017-01-09 07:43:48 +0100268 self._desired_min_tx = desired_min_tx
269 self._required_min_rx = required_min_rx
270 self._detect_mult = detect_mult
271 self._sha1_key = sha1_key
Klement Sekera73884482017-02-23 09:26:30 +0100272 if bfd_key_id is not None:
273 self._bfd_key_id = bfd_key_id
274 else:
275 self._bfd_key_id = randint(0, 255)
Neale Ranns52cd4962019-06-05 10:28:17 +0000276 self._is_tunnel = is_tunnel
Klement Sekerab17dd962017-01-09 07:43:48 +0100277
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200278 @property
279 def test(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200280 """Test which created this session"""
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200281 return self._test
282
283 @property
284 def interface(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200285 """Interface on which this session lives"""
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200286 return self._interface
287
288 @property
289 def af(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200290 """Address family - AF_INET or AF_INET6"""
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200291 return self._af
292
293 @property
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200294 def local_addr(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200295 """BFD session local address (VPP address)"""
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200296 if self._local_addr is None:
Klement Sekera46a87ad2017-01-02 08:22:23 +0100297 if self.af == AF_INET:
298 return self._interface.local_ip4
299 elif self.af == AF_INET6:
300 return self._interface.local_ip6
301 else:
Klement Sekerad3ba5152017-02-14 03:09:17 +0100302 raise Exception("Unexpected af '%s'" % self.af)
Neale Rannsefd7bc22019-11-11 08:32:34 +0000303 return self._local_addr
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200304
305 @property
306 def peer_addr(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200307 """BFD session peer address"""
Neale Rannsefd7bc22019-11-11 08:32:34 +0000308 return self._peer_addr
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200309
Klement Sekerab17dd962017-01-09 07:43:48 +0100310 def get_bfd_udp_session_dump_entry(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200311 """get the namedtuple entry from bfd udp session dump"""
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200312 result = self.test.vapi.bfd_udp_session_dump()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200313 for s in result:
Klement Sekerab17dd962017-01-09 07:43:48 +0100314 self.test.logger.debug("session entry: %s" % str(s))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200315 if s.sw_if_index == self.interface.sw_if_index:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200316 if (
317 self.af == AF_INET
318 and self.interface.local_ip4 == str(s.local_addr)
319 and self.interface.remote_ip4 == str(s.peer_addr)
320 ):
Klement Sekerab17dd962017-01-09 07:43:48 +0100321 return s
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200322 if (
323 self.af == AF_INET6
324 and self.interface.local_ip6 == str(s.local_addr)
325 and self.interface.remote_ip6 == str(s.peer_addr)
326 ):
Klement Sekerab17dd962017-01-09 07:43:48 +0100327 return s
328 return None
329
330 @property
331 def state(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200332 """BFD session state"""
Klement Sekerab17dd962017-01-09 07:43:48 +0100333 session = self.get_bfd_udp_session_dump_entry()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200334 if session is None:
Klement Sekerad3ba5152017-02-14 03:09:17 +0100335 raise Exception("Could not find BFD session in VPP response")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200336 return session.state
337
338 @property
339 def desired_min_tx(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200340 """desired minimum tx interval"""
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200341 return self._desired_min_tx
342
343 @property
344 def required_min_rx(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200345 """required minimum rx interval"""
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200346 return self._required_min_rx
347
348 @property
349 def detect_mult(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200350 """detect multiplier"""
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200351 return self._detect_mult
352
Klement Sekerab17dd962017-01-09 07:43:48 +0100353 @property
354 def sha1_key(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200355 """sha1 key"""
Klement Sekerab17dd962017-01-09 07:43:48 +0100356 return self._sha1_key
357
358 @property
359 def bfd_key_id(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200360 """bfd key id in use"""
Klement Sekerab17dd962017-01-09 07:43:48 +0100361 return self._bfd_key_id
362
Neale Ranns52cd4962019-06-05 10:28:17 +0000363 @property
364 def is_tunnel(self):
365 return self._is_tunnel
366
Klement Sekerab17dd962017-01-09 07:43:48 +0100367 def activate_auth(self, key, bfd_key_id=None, delayed=False):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200368 """activate authentication for this session"""
Klement Sekerab17dd962017-01-09 07:43:48 +0100369 self._bfd_key_id = bfd_key_id if bfd_key_id else randint(0, 255)
370 self._sha1_key = key
Klement Sekerab17dd962017-01-09 07:43:48 +0100371 conf_key_id = self._sha1_key.conf_key_id
372 is_delayed = 1 if delayed else 0
Jakub Grajciar4682feb2019-09-02 13:28:52 +0200373 self.test.vapi.bfd_udp_auth_activate(
374 sw_if_index=self._interface.sw_if_index,
Neale Rannsefd7bc22019-11-11 08:32:34 +0000375 local_addr=self.local_addr,
376 peer_addr=self.peer_addr,
Jakub Grajciar4682feb2019-09-02 13:28:52 +0200377 bfd_key_id=self._bfd_key_id,
378 conf_key_id=conf_key_id,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200379 is_delayed=is_delayed,
380 )
Klement Sekerab17dd962017-01-09 07:43:48 +0100381
382 def deactivate_auth(self, delayed=False):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200383 """deactivate authentication"""
Klement Sekerab17dd962017-01-09 07:43:48 +0100384 self._bfd_key_id = None
385 self._sha1_key = None
386 is_delayed = 1 if delayed else 0
Jakub Grajciar4682feb2019-09-02 13:28:52 +0200387 self.test.vapi.bfd_udp_auth_deactivate(
388 sw_if_index=self._interface.sw_if_index,
Neale Rannsefd7bc22019-11-11 08:32:34 +0000389 local_addr=self.local_addr,
390 peer_addr=self.peer_addr,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200391 is_delayed=is_delayed,
392 )
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200393
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200394 def modify_parameters(
395 self, detect_mult=None, desired_min_tx=None, required_min_rx=None
396 ):
397 """modify session parameters"""
Klement Sekeraa57a9702017-02-02 06:58:07 +0100398 if detect_mult:
399 self._detect_mult = detect_mult
400 if desired_min_tx:
401 self._desired_min_tx = desired_min_tx
402 if required_min_rx:
403 self._required_min_rx = required_min_rx
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200404 self.test.vapi.bfd_udp_mod(
405 sw_if_index=self._interface.sw_if_index,
406 desired_min_tx=self.desired_min_tx,
407 required_min_rx=self.required_min_rx,
408 detect_mult=self.detect_mult,
409 local_addr=self.local_addr,
410 peer_addr=self.peer_addr,
411 )
Klement Sekeraa57a9702017-02-02 06:58:07 +0100412
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200413 def add_vpp_config(self):
Klement Sekerab17dd962017-01-09 07:43:48 +0100414 bfd_key_id = self._bfd_key_id if self._sha1_key else None
415 conf_key_id = self._sha1_key.conf_key_id if self._sha1_key else None
Jakub Grajciar4682feb2019-09-02 13:28:52 +0200416 is_authenticated = True if self._sha1_key else False
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200417 self.test.vapi.bfd_udp_add(
418 sw_if_index=self._interface.sw_if_index,
419 desired_min_tx=self.desired_min_tx,
420 required_min_rx=self.required_min_rx,
421 detect_mult=self.detect_mult,
422 local_addr=self.local_addr,
423 peer_addr=self.peer_addr,
424 bfd_key_id=bfd_key_id,
425 conf_key_id=conf_key_id,
426 is_authenticated=is_authenticated,
427 )
Klement Sekera10db26f2017-01-11 08:16:53 +0100428 self._test.registry.register(self, self.test.logger)
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200429
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200430 def upd_vpp_config(
431 self, detect_mult=None, desired_min_tx=None, required_min_rx=None
432 ):
Neale Ranns63f2c7d2022-02-09 13:47:29 +0000433 if desired_min_tx:
434 self._desired_min_tx = desired_min_tx
435 if required_min_rx:
436 self._required_min_rx = required_min_rx
437 if detect_mult:
438 self._detect_mult = detect_mult
439 bfd_key_id = self._bfd_key_id if self._sha1_key else None
440 conf_key_id = self._sha1_key.conf_key_id if self._sha1_key else None
441 is_authenticated = True if self._sha1_key else False
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200442 self.test.vapi.bfd_udp_upd(
443 sw_if_index=self._interface.sw_if_index,
444 desired_min_tx=self.desired_min_tx,
445 required_min_rx=self.required_min_rx,
446 detect_mult=self.detect_mult,
447 local_addr=self.local_addr,
448 peer_addr=self.peer_addr,
449 bfd_key_id=bfd_key_id,
450 conf_key_id=conf_key_id,
451 is_authenticated=is_authenticated,
452 )
Neale Ranns63f2c7d2022-02-09 13:47:29 +0000453 self._test.registry.register(self, self.test.logger)
454
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200455 def query_vpp_config(self):
Klement Sekerab17dd962017-01-09 07:43:48 +0100456 session = self.get_bfd_udp_session_dump_entry()
457 return session is not None
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200458
459 def remove_vpp_config(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200460 self.test.vapi.bfd_udp_del(
461 self._interface.sw_if_index,
462 local_addr=self.local_addr,
463 peer_addr=self.peer_addr,
464 )
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200465
466 def object_id(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200467 return "bfd-udp-%s-%s-%s-%s" % (
468 self._interface.sw_if_index,
469 self.local_addr,
470 self.peer_addr,
471 self.af,
472 )
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200473
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200474 def admin_up(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200475 """set bfd session admin-up"""
Jakub Grajciar4682feb2019-09-02 13:28:52 +0200476 self.test.vapi.bfd_udp_session_set_flags(
477 flags=VppEnum.vl_api_if_status_flags_t.IF_STATUS_API_FLAG_ADMIN_UP,
478 sw_if_index=self._interface.sw_if_index,
Neale Rannsefd7bc22019-11-11 08:32:34 +0000479 local_addr=self.local_addr,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200480 peer_addr=self.peer_addr,
481 )
Klement Sekerac48829b2017-02-14 07:55:57 +0100482
483 def admin_down(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200484 """set bfd session admin-down"""
Jakub Grajciar4682feb2019-09-02 13:28:52 +0200485 self.test.vapi.bfd_udp_session_set_flags(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200486 flags=0,
487 sw_if_index=self._interface.sw_if_index,
Neale Rannsefd7bc22019-11-11 08:32:34 +0000488 local_addr=self.local_addr,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200489 peer_addr=self.peer_addr,
490 )