Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions osism/tasks/conductor/sonic/config_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,17 @@ def generate_sonic_config(device, hwsku, device_as_mapping=None):
transfer_ips,
)

# Add BFD configuration for BGP neighbors
_add_bfd_configurations(
config,
connected_interfaces,
connected_portchannels,
portchannel_info,
interface_ips,
netbox_interfaces,
transfer_ips,
)

# Add NTP server configuration (device-specific)
_add_ntp_configuration(config, device)

Expand Down Expand Up @@ -922,6 +933,58 @@ def _determine_peer_type(local_device, connected_device, device_as_mapping=None)
return "external" # Default to external on error


def _add_bfd_configurations(
config,
connected_interfaces,
connected_portchannels,
portchannel_info,
interface_ips,
netbox_interfaces,
transfer_ips,
):
"""Add BFD configuration for all BGP neighbors.

This function iterates through all BGP_NEIGHBOR entries and creates
corresponding BFD_PEER_SINGLE_HOP configuration for each neighbor.

Args:
config: The configuration dictionary to update
connected_interfaces: Set of connected interface names
connected_portchannels: Set of connected port channel names
portchannel_info: Dictionary with port channel information
interface_ips: Dict mapping NetBox interface names to IPv4 addresses
netbox_interfaces: Dict mapping SONiC names to NetBox interface info
transfer_ips: Dict of IPv4 addresses from transfer role prefixes
"""
if "BFD_PEER_SINGLE_HOP" not in config:
config["BFD_PEER_SINGLE_HOP"] = {}

# Iterate through all BGP_NEIGHBOR entries
for neighbor_key in config.get("BGP_NEIGHBOR", {}):
# neighbor_key format is "default|interface_name" (e.g., "default|Ethernet0")
parts = neighbor_key.split("|")
if len(parts) == 2:
vrf = parts[0] # Usually "default"
interface_name = parts[1]

# Create BFD peer configuration key
# BFD peer key format: "default|interface_name|null"
bfd_key = f"{vrf}|{interface_name}|null"

# Add BFD configuration for this neighbor
config["BFD_PEER_SINGLE_HOP"][bfd_key] = {
"local_addr": interface_name,
"transmit_interval": "300",
"receive_interval": "300",
"detect_multiplier": "3",
"echo": "true",
}

logger.debug(
f"Added BFD configuration for BGP neighbor on interface {interface_name}"
)


def _get_metalbox_ip_for_device(device):
"""Get Metalbox IP for a SONiC device based on OOB connection.

Expand Down