]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: Add support for SR-TE Policies in route-maps
authorSebastien Merle <sebastien@netdef.org>
Tue, 28 Jan 2020 11:59:57 +0000 (11:59 +0000)
committerGalaxyGorilla <sascha@netdef.org>
Mon, 31 Aug 2020 09:09:12 +0000 (09:09 +0000)
Example configuration:
    route-map SET_SR_POLICY permit 10
     set sr-te color 1
     !
    router bgp 1
     bgp router-id 1.1.1.1
     neighbor 2.2.2.2 remote-as 1
     neighbor 2.2.2.2 update-source lo
     address-family ipv4 unicast
      neighbor 2.2.2.2 next-hop-self
      neighbor 2.2.2.2 route-map SET_SR_POLICY in
     exit-address-family
     !
    !
Learned BGP routes from 2.2.2.2 are mapped to the SR-TE Policy
which is uniquely determined by the BGP nexthop (2.2.2.2 in this
case) and the SR-TE color in the route-map.

Co-authored-by: Renato Westphal <renato@opensourcerouting.org>
Co-authored-by: GalaxyGorilla <sascha@netdef.org>
Co-authored-by: Sebastien Merle <sebastien@netdef.org>
Signed-off-by: Sebastien Merle <sebastien@netdef.org>
bgpd/bgp_attr.c
bgpd/bgp_attr.h
bgpd/bgp_routemap.c
bgpd/bgp_zebra.c
bgpd/bgpd.h
doc/user/routemap.rst

index cac3ab1ca72747fe6053db2417c7b83ae52b0a3d..d8eaabfdf8a61afb0725f357d56cc2a3358a6cdc 100644 (file)
@@ -729,7 +729,8 @@ bool attrhash_cmp(const void *p1, const void *p2)
                    && attr1->nh_lla_ifindex == attr2->nh_lla_ifindex
                    && attr1->distance == attr2->distance
                    && srv6_l3vpn_same(attr1->srv6_l3vpn, attr2->srv6_l3vpn)
-                   && srv6_vpn_same(attr1->srv6_vpn, attr2->srv6_vpn))
+                   && srv6_vpn_same(attr1->srv6_vpn, attr2->srv6_vpn)
+                   && attr1->srte_color == attr2->srte_color)
                        return true;
        }
 
index c57cf8100773c62acb41008e3b1a6fc64b397ff3..e6e953364bebe5d0c0d199e55054622b601accd1 100644 (file)
@@ -24,6 +24,7 @@
 #include "mpls.h"
 #include "bgp_attr_evpn.h"
 #include "bgpd/bgp_encap_types.h"
+#include "srte.h"
 
 /* Simple bit mapping. */
 #define BITMAP_NBBY 8
@@ -290,6 +291,9 @@ struct attr {
 
        /* EVPN ES */
        esi_t esi;
+
+       /* SR-TE Color */
+       uint32_t srte_color;
 };
 
 /* rmap_change_flags definition */
index 6d81cfaab4cd5e908e89c0f2dbd39a8ae35bc13e..09cc775d479550aa4120babb731fc0b7fc79297e 100644 (file)
@@ -1668,6 +1668,45 @@ static const struct route_map_rule_cmd route_match_tag_cmd = {
        route_map_rule_tag_free,
 };
 
+static enum route_map_cmd_result_t
+route_set_srte_color(void *rule, const struct prefix *prefix,
+                    route_map_object_t type, void *object)
+{
+       uint32_t *srte_color = rule;
+       struct bgp_path_info *path;
+
+       if (type != RMAP_BGP)
+               return RMAP_OKAY;
+
+       path = object;
+
+       path->attr->srte_color = *srte_color;
+       path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_SRTE_COLOR);
+
+       return RMAP_OKAY;
+}
+
+/* Route map `sr-te color' compile function */
+static void *route_set_srte_color_compile(const char *arg)
+{
+       uint32_t *color;
+
+       color = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint32_t));
+       *color = atoi(arg);
+
+       return color;
+}
+
+/* Free route map's compiled `sr-te color' value. */
+static void route_set_srte_color_free(void *rule)
+{
+       XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
+}
+
+/* Route map commands for sr-te color set. */
+struct route_map_rule_cmd route_set_srte_color_cmd = {
+       "sr-te color", route_set_srte_color, route_set_srte_color_compile,
+       route_set_srte_color_free};
 
 /* Set nexthop to object.  ojbect must be pointer to struct attr. */
 struct rmap_ip_nexthop_set {
@@ -5686,6 +5725,9 @@ void bgp_route_map_init(void)
        route_map_match_tag_hook(generic_match_add);
        route_map_no_match_tag_hook(generic_match_delete);
 
+       route_map_set_srte_color_hook(generic_set_add);
+       route_map_no_set_srte_color_hook(generic_set_delete);
+
        route_map_set_ip_nexthop_hook(generic_set_add);
        route_map_no_set_ip_nexthop_hook(generic_set_delete);
 
@@ -5728,6 +5770,7 @@ void bgp_route_map_init(void)
        route_map_install_match(&route_match_vrl_source_vrf_cmd);
 
        route_map_install_set(&route_set_table_id_cmd);
+       route_map_install_set(&route_set_srte_color_cmd);
        route_map_install_set(&route_set_ip_nexthop_cmd);
        route_map_install_set(&route_set_local_pref_cmd);
        route_map_install_set(&route_set_weight_cmd);
index dba114f86a004562f3f709c4fb6d996571c0e314..15bd6d33b82efcbd0018554fe2501cdca07d446a 100644 (file)
@@ -1265,6 +1265,9 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p,
                api.tableid = info->attr->rmap_table_id;
        }
 
+       if (CHECK_FLAG(info->attr->flag, ATTR_FLAG_BIT(BGP_ATTR_SRTE_COLOR)))
+               SET_FLAG(api.message, ZAPI_MESSAGE_SRTE);
+
        /* Metric is currently based on the best-path only */
        metric = info->attr->med;
 
@@ -1303,6 +1306,11 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p,
                                continue;
                }
                api_nh = &api.nexthops[valid_nh_count];
+
+               if (CHECK_FLAG(info->attr->flag,
+                              ATTR_FLAG_BIT(BGP_ATTR_SRTE_COLOR)))
+                       api_nh->srte_color = info->attr->srte_color;
+
                if (nh_family == AF_INET) {
                        if (bgp_debug_zebra(&api.prefix)) {
                                if (mpinfo->extra) {
index 20a41987cae56bf5cb911b5eb8ee135885e9322a..6145d9305f9451158bd352480692da1841feb1e2 100644 (file)
@@ -1538,6 +1538,7 @@ struct bgp_nlri {
 #define BGP_ATTR_IPV6_EXT_COMMUNITIES           25
 #define BGP_ATTR_LARGE_COMMUNITIES              32
 #define BGP_ATTR_PREFIX_SID                     40
+#define BGP_ATTR_SRTE_COLOR                     51
 #ifdef ENABLE_BGP_VNC_ATTR
 #define BGP_ATTR_VNC                           255
 #endif
index f557cbe022b53449b49c85eac198f533c84c464c..fa5fc248a8cffc146b950b36a8af76b957cc7906 100644 (file)
@@ -329,6 +329,12 @@ Route Map Set Command
 
    Set the BGP table to a given table identifier
 
+.. index:: set sr-te color (1-4294967295)
+.. clicmd:: set sr-te color (1-4294967295)
+
+   Set the color of a SR-TE Policy to be applied to a learned route. The SR-TE
+   Policy is uniquely determined by the color and the BGP nexthop.
+
 .. _route-map-call-command:
 
 Route Map Call Command