Skip to content

Commit

Permalink
Add address scope to subnets in get_sync_data()
Browse files Browse the repository at this point in the history
With IPv6 we want to make sure that we know the address scope for each
subnet, so we can easily decide in the agent if a network is routable or
not. With IPv4 we normally only have one subnet per port (and I'm not
even sure we can have more than one), but with IPv6 subnets of the same
network are grouped on the same router port.
  • Loading branch information
sebageek committed Jan 7, 2025
1 parent a9812e1 commit f5324e1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
11 changes: 11 additions & 0 deletions asr1k_neutron_l3/plugins/db/asr1k_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,17 @@ def set_router_dynamic_nat_pool(self, context, router_id, dynamic_nat_pool):
ra = self.get_router_att(context, router_id)
ra.dynamic_nat_pool = dynamic_nat_pool

@db_api.CONTEXT_READER
def get_subnet_address_scope_map(self, context, subnet_ids):
query = context.session.query(models_v2.Subnet.id,
models_v2.SubnetPool.address_scope_id)
query = query.outerjoin(
models_v2.SubnetPool,
models_v2.Subnet.subnetpool_id == models_v2.SubnetPool.id)
query = query.filter(models_v2.Subnet.id.in_(subnet_ids))

return {entry[0]: entry[1] for entry in query}


class ExtraAttsDb(object):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,14 @@ def get_sync_data(self, context, router_ids=None, active=None, host=None):
if gw_info is not None:
gw_info['external_fixed_ips'] = gw_port['fixed_ips']

# add address scope to internal subnets
all_ports = router.get('_interfaces', []) + ([gw_port] if gw_port else [])
all_subnets = {sn['id'] for port in all_ports for sn in port.get('subnets', [])}
subnet_address_scope_map = self.db.get_subnet_address_scope_map(context, all_subnets)
for port in all_ports:
for subnet in port.get('subnets', []):
subnet['address_scope_id'] = subnet_address_scope_map.get(subnet['id'])

rt_import = []
rt_export = []
bgpvpns = self.db.get_bgpvpns_by_router_id(context, router['id'])
Expand All @@ -320,12 +328,9 @@ def get_sync_data(self, context, router_ids=None, active=None, host=None):
router["rt_export"] = list(set(rt_export))
router["rt_import"] = list(set(rt_import))

all_ports = [x["id"] for x in router.get("_interfaces", [])]
if gw_port:
all_ports.append(gw_port["id"])

if constants.FWAAS_SERVICE_PLUGIN in cfg.CONF.service_plugins:
router["fwaas_policies"] = self.get_fwaas_policies(context, all_ports)
all_port_ids = [port["id"] for port in all_ports]
router["fwaas_policies"] = self.get_fwaas_policies(context, all_port_ids)

return routers

Expand Down

0 comments on commit f5324e1

Please sign in to comment.