sonic: Generate the entries of the default VRF#2516
Merged
Conversation
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The DEFAULT_VRF_* policy dictionaries are mutable module-level globals; consider wrapping them in immutable structures (e.g. MappingProxyType or dataclasses with frozen=True) to prevent accidental in-place modification elsewhere in the codebase.
- The default VRF emission logic added to generate_sonic_config() is fairly substantial; factoring it into a small helper (e.g. _add_default_vrf_configuration(config, device)) would keep the main generator function easier to scan and isolate the default-VRF behavior.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The DEFAULT_VRF_* policy dictionaries are mutable module-level globals; consider wrapping them in immutable structures (e.g. MappingProxyType or dataclasses with frozen=True) to prevent accidental in-place modification elsewhere in the codebase.
- The default VRF emission logic added to generate_sonic_config() is fairly substantial; factoring it into a small helper (e.g. _add_default_vrf_configuration(config, device)) would keep the main generator function easier to scan and isolate the default-VRF behavior.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
VRF, BGP_GLOBALS, BGP_GLOBALS_AF, BGP_GLOBALS_ROUTE_ADVERTISE and ROUTE_REDISTRIBUTE are owned tables, so their base content is dropped up front and rebuilt from NetBox data and hardcoded policy. The default-VRF entries, however, only ever shipped in the image-provided config_db.json and were never regenerated: the generator writes these tables only for the VRFs NetBox carries, and it replaced BGP_GLOBALS|default wholesale with router_id and local_asn. As a result every regen left BGP_GLOBALS|default without its global BGP attributes and dropped VRF|default as well as the connected-route redistribution of the default VRF; on switches without VNI VRFs BGP_GLOBALS_AF and BGP_GLOBALS_ROUTE_ADVERTISE came back empty. The default VRF then stopped advertising its IPv4/IPv6 unicast routes into L2VPN EVPN, so traffic between subnets attached to different leaves was dropped. VRFs with a VNI inherited the attribute loss as well, because their BGP_GLOBALS entry is copied from the default one. Emit the default-VRF entries from the new _add_default_vrf_configuration as hardcoded SONiC policy, with the values the base config used to carry, and drop them from files/sonic/config_db.json. router_id and local_asn are merged into the generated entry instead of replacing it. The policy lives in read-only module constants that are copied per device, so it cannot be rewritten process-wide by an in-place edit. All five tables are co-owned by _add_default_vrf_configuration and _add_vrf_configuration from now on, so they are listed in MULTI_OWNER_OWNED_TABLE_KEYS to keep both writers on the per-key merge pattern. Closes #2515 Assisted-by: Claude:claude-opus-5 Signed-off-by: Christian Berendt <berendt@osism.tech>
berendt
force-pushed
the
fix/2515-default-vrf-bgp-globals
branch
from
July 24, 2026 20:17
b60f215 to
38599bf
Compare
ideaship
approved these changes
Jul 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2515
Since the table-ownership enforcement,
generate_sonic_config()drops the content of every owned table up front and rebuilds it. The default-VRF entries that the baseconfig_db.jsonshipped (#1937) were never regenerated, because the generator only writes these tables for the VRFs NetBox carries.Change
The generator now owns the default-VRF entries as hardcoded SONiC policy, with the values the base config used to carry:
VRF|defaultBGP_GLOBALS|defaultattributes (network_import_check,ebgp_requires_policy,holdtime/keepalive, …), withrouter_id/local_asnmerged into the entry instead of replacing itBGP_GLOBALS_AFdefault|ipv4_unicast,default|ipv6_unicast,default|l2vpn_evpnBGP_GLOBALS_ROUTE_ADVERTISEdefault|L2VPN_EVPN|IPV4_UNICASTand…|IPV6_UNICASTROUTE_REDISTRIBUTEdefault|connected|bgp|ipv4anddefault|connected|bgp|ipv6The entries are dropped from
files/sonic/config_db.json. Since VRFs with a VNI copy theirBGP_GLOBALSentry from the default VRF, they pick up the full attribute set again as well.All five tables are now written by both the orchestrator (default VRF) and
_add_vrf_configuration(per-VRF entries), so they joinMULTI_OWNER_OWNED_TABLE_KEYS; the existing static guard keeps both writers on the per-key merge pattern._add_vrf_configurationcreatesROUTE_REDISTRIBUTEviasetdefaultinstead of rebinding it.Beyond the three
BGP_GLOBALS*tables named in the issue,VRF|defaultand the default-VRFROUTE_REDISTRIBUTEentries were lost in exactly the same way, so they are covered here too. The only other owned table with base content isSNMP_SERVER|SYSTEM, which_add_snmp_configurationalready regenerates.Tests
BGP_GLOBALS_AF|default|ipv4_unicastfrom the base config is overwritten by the generated policy, and a device without a primary IP now gets the policy withoutrouter_id/local_asn