Skip to content

Commit

Permalink
IPv6 support for Route Maps
Browse files Browse the repository at this point in the history
Route Maps can now reference IPv6 prefix lists. We also did some
maintenance on the RouteMap class, like removing the unused enable_bgp
flag and making sure that specifying both prefix_list and access_list
don't override each other's match conditions (though this hasn't been
used so far).

As we don't know yet how we'll transport IPv6 prefixes from ACI/EVPN to
our routers we'll for now leave the RoutePrefix to be v4 only and don't
reference it for v6 addresses. Once we know how that part of the infra
is going to work we'll fill it with life!
  • Loading branch information
sebageek committed Nov 15, 2024
1 parent 8903fcc commit c7f8e1f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
21 changes: 14 additions & 7 deletions asr1k_neutron_l3/models/netconf_yang/route_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class RouteMapConstants(object):
ADDITIVE = 'additive'
MATCH = "match"
IP = "ip"
IPV6 = "ipv6"
FORCE = "force"
NEXT_HOP = "next-hop"
NEXT_HOP_ADDR = "next-hop-addr"
Expand Down Expand Up @@ -133,6 +134,7 @@ def __parameters__(cls):
{'key': 'force', 'yang-path': 'set/ip/next-hop/next-hop-addr', 'default': False,
'yang-type': YANG_TYPE.EMPTY},
{'key': 'prefix_list', 'yang-key': 'prefix-list', 'yang-path': 'match/ip/address'},
{'key': 'prefix_list_v6', 'yang-key': 'prefix-list', 'yang-path': 'match/ipv6/address'},
{'key': 'access_list', 'yang-key': 'access-list', 'yang-path': 'match/ip/address'},
{'key': 'ip_precedence', 'yang-path': 'set/ip/precedence', 'yang-key': 'precedence-fields'},
]
Expand All @@ -145,8 +147,6 @@ def __init__(self, **kwargs):
if self.asn is not None and not isinstance(self.asn, list):
self.asn = [self.asn]

self.enable_bgp = kwargs.get('enable_bgp', False)

@classmethod
def from_json(cls, json, context, *args, **kwargs):
nh = (json.get(RouteMapConstants.SET, {})
Expand Down Expand Up @@ -189,13 +189,20 @@ def to_dict(self, context):
seq[RouteMapConstants.SET][RouteMapConstants.IP][RouteMapConstants.NEXT_HOP][
RouteMapConstants.ADDRESS].append(RouteMapConstants.FORCE)

if self.prefix_list is not None:
seq[RouteMapConstants.MATCH] = {
RouteMapConstants.IP: {RouteMapConstants.ADDRESS: {RouteMapConstants.PREFIX_LIST: self.prefix_list}}}
if self.prefix_list or self.prefix_list_v6:
entry = seq.setdefault(RouteMapConstants.MATCH, {})
if self.prefix_list:
entry[RouteMapConstants.IP] = {
RouteMapConstants.ADDRESS: {RouteMapConstants.PREFIX_LIST: self.prefix_list}}
if self.prefix_list_v6:
entry[RouteMapConstants.IP] = {
RouteMapConstants.ADDRESS: {RouteMapConstants.PREFIX_LIST: self.prefix_list_v6}}

if self.access_list is not None:
seq[RouteMapConstants.MATCH] = {
RouteMapConstants.IP: {RouteMapConstants.ADDRESS: {RouteMapConstants.ACCESS_LIST: self.access_list}}}
entry = seq.setdefault(RouteMapConstants.MATCH, {})
entry = entry.setdefault(RouteMapConstants.IP, {})
entry[RouteMapConstants.ADDRESS] = {RouteMapConstants.ACCESS_LIST: self.access_list}

if self.ip_precedence:
if RouteMapConstants.SET not in seq:
seq[RouteMapConstants.SET] = {}
Expand Down
21 changes: 11 additions & 10 deletions asr1k_neutron_l3/models/neutron/l3/route_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


class RouteMap(base.Base):
def __init__(self, name, rt=None, routable_interface=False):
def __init__(self, name, rt=None, routable_interface=False, enable_ipv6=False):
super(RouteMap, self).__init__()
self.vrf = utils.uuid_to_vrf_id(name)
self.name = "exp-{}".format(self.vrf)
Expand All @@ -31,28 +31,29 @@ def __init__(self, name, rt=None, routable_interface=False):
self.secondary_rt = components[0] + ":" + str(int(components[1]) + 1000)

self.routable_interface = routable_interface
self.enable_bgp = False
if self.routable_interface:
self.enable_bgp = True

sequences = []

# ipv4
seq = 10
if self.routable_interface:
sequences.append(route_map.MapSequence(seq_no=seq,
operation='permit',
prefix_list='snat-{}'.format(self.vrf),
asn=[self.rt, 'additive'],
enable_bgp=self.enable_bgp))
asn=[self.rt, 'additive']))
seq += 10
if self.secondary_rt:
sequences.append(route_map.MapSequence(seq_no=seq,
operation='permit',
prefix_list='route-{}'.format(self.vrf),
asn=[self.secondary_rt, 'additive'],
enable_bgp=self.enable_bgp))
asn=[self.secondary_rt, 'additive']))
seq += 10

sequences.append(route_map.MapSequence(seq_no=seq, operation='deny', prefix_list='ext-{}'.format(self.vrf)))
sequences.append(route_map.MapSequence(seq_no=seq, operation='deny', prefix_list=f'ext-{self.vrf}'))

# ipv6
if enable_ipv6:
seq += 10
sequences.append(route_map.MapSequence(seq_no=seq, operation='deny', prefix_list_v6=f'ext-{self.vrf}'))

self._rest_definition = route_map.RouteMap(name=self.name, seq=sequences)

Expand Down
2 changes: 1 addition & 1 deletion asr1k_neutron_l3/models/neutron/l3/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def __init__(self, router_info):
self.nat_acl = self._build_nat_acl()

self.route_map = route_map.RouteMap(self.router_info.get('id'), rt=rt,
routable_interface=self.routable_interface)
routable_interface=self.routable_interface, enable_ipv6=self.enable_ipv6)

self.pbr_route_map = route_map.PBRRouteMap(self.router_info.get('id'), gateway_interface=self.gateway_interface)

Expand Down

0 comments on commit c7f8e1f

Please sign in to comment.