Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_bfd.py

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # Copyright 2025 Dell Inc. or its subsidiaries. All Rights Reserved.
4 # GNU General Public License v3.0+
5 # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 """
8 The module file for sonic_bfd
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14 DOCUMENTATION = """
15 ---
16 module: sonic_bfd
17 version_added: "2.1.0"
18 notes:
19 - Tested against Enterprise SONiC Distribution by Dell Technologies.
20 - Supports C(check_mode).
21 short_description: Manage BFD configuration on SONiC
22 description:
23 - This module provides configuration management of BFD for devices running SONiC
24 author: "S. Talabi (@stalabi1)"
25 options:
26 config:
27 description:
28 - Specifies BFD configurations
29 type: dict
30 suboptions:
31 profiles:
32 description:
33 - List of preconfiguration profiles
34 type: list
35 elements: dict
36 suboptions:
37 profile_name:
38 description:
39 - BFD profile name
40 type: str
41 required: True
42 enabled:
43 description:
44 - Enables BFD session when set to true
45 type: bool
46 default: True
47 transmit_interval:
48 description:
49 - Specifies peer transmit interval
50 type: int
51 default: 300
52 receive_interval:
53 description:
54 - Specifies peer receive interval
55 type: int
56 default: 300
57 detect_multiplier:
58 description:
59 - Number of missed packets to bring down a BFD session
60 type: int
61 default: 3
62 passive_mode:
63 description:
64 - Specifies BFD peer as passive when set to true
65 type: bool
66 default: false
67 min_ttl:
68 description:
69 - Minimum expected TTL on received packets
70 type: int
71 default: 254
72 echo_interval:
73 description:
74 - Specifies echo interval
75 type: int
76 default: 300
77 echo_mode:
78 description:
79 - Echo mode is enabled when set to true
80 type: bool
81 default: false
82 single_hops:
83 description:
84 - List of single-hop sessions
85 type: list
86 elements: dict
87 suboptions:
88 remote_address:
89 description:
90 - IP address used by the remote system for the BFD session
91 type: str
92 required: True
93 vrf:
94 description:
95 - Name of the configured VRF on the device
96 type: str
97 required: True
98 interface:
99 description:
100 - Interface to use to contact peer
101 type: str
102 required: True
103 local_address:
104 description:
105 - Source IP address to be used for BFD sessions over the interface
106 type: str
107 required: True
108 enabled:
109 description:
110 - Enables BFD session when set to true
111 type: bool
112 default: True
113 transmit_interval:
114 description:
115 - Specifies peer transmit interval
116 type: int
117 default: 300
118 receive_interval:
119 description:
120 - Specifies peer receive interval
121 type: int
122 default: 300
123 detect_multiplier:
124 description:
125 - Number of missed packets to bring down a BFD session
126 type: int
127 default: 3
128 passive_mode:
129 description:
130 - Specifies BFD peer as passive when set to true
131 type: bool
132 default: false
133 echo_interval:
134 description:
135 - Specifies echo interval
136 type: int
137 default: 300
138 echo_mode:
139 description:
140 - Echo mode is enabled when set to true
141 type: bool
142 default: false
143 profile_name:
144 description:
145 - BFD profile name
146 type: str
147 multi_hops:
148 description:
149 - List of multi-hop sessions
150 type: list
151 elements: dict
152 suboptions:
153 remote_address:
154 description:
155 - IP address used by the remote system for the BFD session
156 type: str
157 required: True
158 vrf:
159 description:
160 - Name of the configured VRF on the device
161 type: str
162 required: True
163 local_address:
164 description:
165 - Source IP address to be used for BFD sessions over the interface
166 type: str
167 required: True
168 enabled:
169 description:
170 - Enables BFD session when set to true
171 type: bool
172 default: True
173 transmit_interval:
174 description:
175 - Specifies peer transmit interval
176 type: int
177 default: 300
178 receive_interval:
179 description:
180 - Specifies peer receive interval
181 type: int
182 default: 300
183 detect_multiplier:
184 description:
185 - Number of missed packets to bring down a BFD session
186 type: int
187 default: 3
188 passive_mode:
189 description:
190 - Specifies BFD peer as passive when set to true
191 type: bool
192 default: false
193 min_ttl:
194 description:
195 - Minimum expected TTL on received packets
196 type: int
197 default: 254
198 profile_name:
199 description:
200 - BFD profile name
201 type: str
202 state:
203 description:
204 - The state of the configuration after module completion.
205 type: str
206 choices: ['merged', 'deleted', 'replaced', 'overridden']
207 default: merged
208 """
209
210 EXAMPLES = """
211 # Using "merged" state
212 #
213 # Before state:
214 # -------------
215 #
216 # sonic# show bfd profile
217 # (No "bfd profile" configuration present)
218 # sonic# show bfd peers
219 # (No "bfd peers" configuration present)
220
221 - name: Merge BFD configuration
222 dellemc.enterprise_sonic.sonic_bfd:
223 config:
224 profiles:
225 - profile_name: 'p1'
226 enabled: true
227 transmit_interval: 120
228 receive_interval: 200
229 detect_multiplier: 2
230 passive_mode: true
231 min_ttl: 140
232 echo_interval: 150
233 echo_mode: true
234 single_hops:
235 - remote_address: '196.88.6.1'
236 vrf: 'default'
237 interface: 'Ethernet20'
238 local_address: '1.1.1.1'
239 enabled: true
240 transmit_interval: 50
241 receive_interval: 80
242 detect_multiplier: 4
243 passive_mode: true
244 echo_interval: 110
245 echo_mode: true
246 profile_name: 'p1'
247 multi_hops:
248 - remote_address: '192.40.1.3'
249 vrf: 'default'
250 local_address: '3.3.3.3'
251 enabled: true
252 transmit_interval: 75
253 receive_interval: 100
254 detect_multiplier: 3
255 passive_mode: true
256 min_ttl: 125
257 profile_name: 'p1'
258 state: merged
259
260 # After state:
261 # ------------
262 #
263 # sonic# show bfd profile
264 # BFD Profile:
265 # Profile-name: p1
266 # Enabled: True
267 # Echo-mode: Enabled
268 # Passive-mode: Enabled
269 # Minimum-Ttl: 140
270 # Detect-multiplier: 2
271 # Receive interval: 200ms
272 # Transmission interval: 120ms
273 # Echo transmission interval: 150ms
274 # sonic# show bfd peers
275 # BFD Peers:
276 #
277 # peer 192.40.1.3 multihop local-address 3.3.3.3 vrf default
278 # ID: 989720421
279 # Remote ID: 0
280 # Passive mode: Enabled
281 # Profile: p1
282 # Minimum TTL: 125
283 # Status: down
284 # Downtime: 0 day(s), 0 hour(s), 1 min(s), 46 sec(s)
285 # Diagnostics: ok
286 # Remote diagnostics: ok
287 # Peer Type: configured
288 # Local timers:
289 # Detect-multiplier: 2
290 # Receive interval: 100ms
291 # Transmission interval: 75ms
292 # Echo transmission interval: ms
293 # Remote timers:
294 # Detect-multiplier: 3
295 # Receive interval: 1000ms
296 # Transmission interval: 1000ms
297 # Echo transmission interval: 0ms
298 #
299 # peer 196.88.6.1 local-address 1.1.1.1 vrf default interface Ethernet20
300 # ID: 1134635660
301 # Remote ID: 0
302 # Passive mode: Enabled
303 # Profile: p1
304 # Status: down
305 # Downtime: 0 day(s), 1 hour(s), 50 min(s), 48 sec(s)
306 # Diagnostics: ok
307 # Remote diagnostics: ok
308 # Peer Type: configured
309 # Local timers:
310 # Detect-multiplier: 4
311 # Receive interval: 80ms
312 # Transmission interval: 50ms
313 # Echo transmission interval: 110ms
314 # Remote timers:
315 # Detect-multiplier: 3
316 # Receive interval: 1000ms
317 # Transmission interval: 1000ms
318 # Echo transmission interval: 0ms
319 #
320 #
321 # Using "replaced" state
322 #
323 # Before state:
324 # -------------
325 #
326 # sonic# show bfd profile
327 # BFD Profile:
328 # Profile-name: p1
329 # Enabled: True
330 # Echo-mode: Enabled
331 # Passive-mode: Enabled
332 # Minimum-Ttl: 140
333 # Detect-multiplier: 2
334 # Receive interval: 200ms
335 # Transmission interval: 120ms
336 # Echo transmission interval: 150ms
337 # Profile-name: p2
338 # Enabled: True
339 # Echo-mode: Disabled
340 # Passive-mode: Disabled
341 # Minimum-Ttl: 254
342 # Detect-multiplier: 3
343 # Receive interval: 300ms
344 # Transmission interval: 300ms
345 # Echo transmission interval: 300ms
346
347 - name: Replace BFD configuration
348 dellemc.enterprise_sonic.sonic_bfd:
349 config:
350 profiles:
351 - profile_name: 'p1'
352 transmit_interval: 144
353 - profile_name: 'p2'
354 enabled: false
355 transmit_interval: 110
356 receive_interval: 235
357 detect_multiplier: 5
358 passive_mode: true
359 min_ttl: 155
360 echo_interval: 163
361 echo_mode: true
362 state: replaced
363
364 # After state:
365 # ------------
366 #
367 # sonic# show bfd profile
368 # BFD Profile:
369 # Profile-name: p1
370 # Enabled: True
371 # Echo-mode: Enabled
372 # Passive-mode: Enabled
373 # Minimum-Ttl: 140
374 # Detect-multiplier: 2
375 # Receive interval: 200ms
376 # Transmission interval: 144ms
377 # Echo transmission interval: 150ms
378 # Profile-name: p2
379 # Enabled: False
380 # Echo-mode: Enabled
381 # Passive-mode: Enabled
382 # Minimum-Ttl: 155
383 # Detect-multiplier: 5
384 # Receive interval: 235ms
385 # Transmission interval: 110ms
386 # Echo transmission interval: 163ms
387 #
388 #
389 # Using "overridden" state
390 #
391 # Before state:
392 # -------------
393 #
394 # sonic# show bfd peers
395 # BFD Peers:
396 #
397 # peer 192.40.1.3 multihop local-address 3.3.3.3 vrf default
398 # ID: 989720421
399 # Remote ID: 0
400 # Passive mode: Enabled
401 # Profile: p1
402 # Minimum TTL: 125
403 # Status: down
404 # Downtime: 0 day(s), 0 hour(s), 1 min(s), 46 sec(s)
405 # Diagnostics: ok
406 # Remote diagnostics: ok
407 # Peer Type: configured
408 # Local timers:
409 # Detect-multiplier: 2
410 # Receive interval: 100ms
411 # Transmission interval: 75ms
412 # Echo transmission interval: ms
413 # Remote timers:
414 # Detect-multiplier: 3
415 # Receive interval: 1000ms
416 # Transmission interval: 1000ms
417 # Echo transmission interval: 0ms
418 #
419 # peer 196.88.6.1 local-address 1.1.1.1 vrf default interface Ethernet20
420 # ID: 1134635660
421 # Remote ID: 0
422 # Passive mode: Enabled
423 # Profile: p1
424 # Status: down
425 # Downtime: 0 day(s), 1 hour(s), 50 min(s), 48 sec(s)
426 # Diagnostics: ok
427 # Remote diagnostics: ok
428 # Peer Type: configured
429 # Local timers:
430 # Detect-multiplier: 4
431 # Receive interval: 80ms
432 # Transmission interval: 50ms
433 # Echo transmission interval: 110ms
434 # Remote timers:
435 # Detect-multiplier: 3
436 # Receive interval: 1000ms
437 # Transmission interval: 1000ms
438 # Echo transmission interval: 0ms
439
440 - name: Override BFD configuration
441 dellemc.enterprise_sonic.sonic_bfd:
442 config:
443 single_hops:
444 - remote_address: '172.68.2.1'
445 vrf: 'default'
446 interface: 'Ethernet16'
447 local_address: '2.2.2.2'
448 enabled: true
449 transmit_interval: 60
450 receive_interval: 88
451 detect_multiplier: 6
452 passive_mode: true
453 echo_interval: 112
454 echo_mode: true
455 profile_name: 'p3'
456 multi_hops:
457 - remote_address: '186.42.1.2'
458 vrf: 'default'
459 local_address: '1.1.1.1'
460 enabled: false
461 transmit_interval: 85
462 receive_interval: 122
463 detect_multiplier: 4
464 passive_mode: false
465 min_ttl: 120
466 profile_name: 'p3'
467 state: overridden
468
469 # After state:
470 # ------------
471 #
472 # sonic# show bfd peers
473 # BFD Peers:
474 #
475 # peer 186.42.1.2 multihop local-address 1.1.1.1 vrf default
476 # ID: 989720421
477 # Remote ID: 0
478 # Passive mode: Disabled
479 # Profile: p3
480 # Minimum TTL: 120
481 # Status: down
482 # Downtime: 0 day(s), 0 hour(s), 1 min(s), 46 sec(s)
483 # Diagnostics: ok
484 # Remote diagnostics: ok
485 # Peer Type: configured
486 # Local timers:
487 # Detect-multiplier: 4
488 # Receive interval: 122ms
489 # Transmission interval: 85ms
490 # Echo transmission interval: ms
491 # Remote timers:
492 # Detect-multiplier: 3
493 # Receive interval: 1000ms
494 # Transmission interval: 1000ms
495 # Echo transmission interval: 0ms
496 #
497 # peer 172.68.2.1 local-address 2.2.2.2 vrf default interface Ethernet16
498 # ID: 1134635660
499 # Remote ID: 0
500 # Passive mode: Enabled
501 # Profile: p3
502 # Status: down
503 # Downtime: 0 day(s), 1 hour(s), 50 min(s), 48 sec(s)
504 # Diagnostics: ok
505 # Remote diagnostics: ok
506 # Peer Type: configured
507 # Local timers:
508 # Detect-multiplier: 6
509 # Receive interval: 88ms
510 # Transmission interval: 60ms
511 # Echo transmission interval: 112ms
512 # Remote timers:
513 # Detect-multiplier: 3
514 # Receive interval: 1000ms
515 # Transmission interval: 1000ms
516 # Echo transmission interval: 0ms
517 #
518 #
519 # Using "deleted" state
520 #
521 # Before state:
522 # -------------
523 #
524 # sonic# show bfd profile
525 # BFD Profile:
526 # Profile-name: p1
527 # Enabled: True
528 # Echo-mode: Enabled
529 # Passive-mode: Enabled
530 # Minimum-Ttl: 140
531 # Detect-multiplier: 2
532 # Receive interval: 200ms
533 # Transmission interval: 120ms
534 # Echo transmission interval: 150ms
535 # sonic# show bfd peers
536 # BFD Peers:
537 #
538 # peer 192.40.1.3 multihop local-address 3.3.3.3 vrf default
539 # ID: 989720421
540 # Remote ID: 0
541 # Passive mode: Enabled
542 # Profile: p1
543 # Minimum TTL: 125
544 # Status: down
545 # Downtime: 0 day(s), 0 hour(s), 1 min(s), 46 sec(s)
546 # Diagnostics: ok
547 # Remote diagnostics: ok
548 # Peer Type: configured
549 # Local timers:
550 # Detect-multiplier: 2
551 # Receive interval: 100ms
552 # Transmission interval: 75ms
553 # Echo transmission interval: ms
554 # Remote timers:
555 # Detect-multiplier: 3
556 # Receive interval: 1000ms
557 # Transmission interval: 1000ms
558 # Echo transmission interval: 0ms
559 #
560 # peer 196.88.6.1 local-address 1.1.1.1 vrf default interface Ethernet20
561 # ID: 1134635660
562 # Remote ID: 0
563 # Passive mode: Enabled
564 # Profile: p1
565 # Status: down
566 # Downtime: 0 day(s), 1 hour(s), 50 min(s), 48 sec(s)
567 # Diagnostics: ok
568 # Remote diagnostics: ok
569 # Peer Type: configured
570 # Local timers:
571 # Detect-multiplier: 4
572 # Receive interval: 80ms
573 # Transmission interval: 50ms
574 # Echo transmission interval: 110ms
575 # Remote timers:
576 # Detect-multiplier: 3
577 # Receive interval: 1000ms
578 # Transmission interval: 1000ms
579 # Echo transmission interval: 0ms
580
581 - name: Delete BFD configuration
582 dellemc.enterprise_sonic.sonic_bfd:
583 config:
584 profiles:
585 - profile_name: 'p1'
586 enabled: true
587 transmit_interval: 120
588 receive_interval: 200
589 detect_multiplier: 2
590 passive_mode: true
591 min_ttl: 140
592 echo_interval: 150
593 echo_mode: true
594 single_hops:
595 - remote_address: '196.88.6.1'
596 vrf: 'default'
597 interface: 'Ethernet20'
598 local_address: '1.1.1.1'
599 multi_hops:
600 - remote_address: '192.40.1.3'
601 vrf: 'default'
602 local_address: '3.3.3.3'
603 state: deleted
604
605 # After state
606 # -----------
607 #
608 # sonic# show bfd profile
609 # BFD Profile:
610 # Profile-name: p1
611 # Enabled: True
612 # Echo-mode: Disabled
613 # Passive-mode: Disabled
614 # Minimum-Ttl: 254
615 # Detect-multiplier: 3
616 # Receive interval: 300ms
617 # Transmission interval: 300ms
618 # Echo transmission interval: 300ms
619 # sonic# show bfd peers
620 # (No "bfd peers" configuration present)
621 """
622
623 RETURN = """
624 before:
625 description: The configuration prior to the module invocation.
626 returned: always
627 type: list
628 sample: >
629 The configuration returned will always be in the same format
630 as the parameters above.
631 after:
632 description: The resulting configuration module invocation.
633 returned: when changed
634 type: list
635 sample: >
636 The configuration returned will always be in the same format
637 as the parameters above.
638 after_generated:
639 description: The generated configuration module invocation.
640 returned: when C(check_mode)
641 type: list
642 sample: >
643 The configuration returned will always be in the same format
644 as the parameters above.
645 commands:
646 description: The set of commands pushed to the remote device.
647 returned: always
648 type: list
649 sample: ['command 1', 'command 2', 'command 3']
650 """
651
652
653 from ansible.module_utils.basic import AnsibleModule
654 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.bfd.bfd import BfdArgs
655 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.bfd.bfd import Bfd
656
657
658 def main():
659 """
660 Main entry point for module execution
661
662 :returns: the result form module invocation
663 """
664 module = AnsibleModule(argument_spec=BfdArgs.argument_spec,
665 supports_check_mode=True)
666
667 result = Bfd(module).execute_module()
668 module.exit_json(**result)
669
670
671 if __name__ == '__main__':
672 main()