Skip to content

Commit

Permalink
bgpd:bgp l3vpn over SRv6-TE policy
Browse files Browse the repository at this point in the history
config:

segment-routing
 traffic-eng
  segment-list a
   index 10 ipv6-address 100:1::100
   index 20 ipv6-address 200:1::200
  exit
  policy color 100 endpoint 1::1
   candidate-path preference 1 name a explicit segment-list a
  exit
 exit
exit
!
end

show:
router2# show sr-te policy detail

Endpoint: 1::1  Color: 100  Name:   BSID: -  Status: Active Type: SRV6
  * Preference: 1  Name: a  Type: explicit  Segment-List: a  Protocol-Origin: Local

router2# show bgp ipv4 vpn
BGP table version is 2, local router ID is 2.2.2.2, vrf id 0
Default local pref 100, local AS 2
Status codes:  s suppressed, d damped, h history, u unsorted, * valid, > best, = multipath,
               i internal, r RIB-failure, S Stale, R Removed
Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self
Origin codes:  i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found

     Network          Next Hop            Metric LocPrf Weight Path
Route Distinguisher: 1:1
 *>  192.168.11.0/24  1::1                     0             0 1 ?
    UN=1::1 EC{1:1 Color:01:100} label=16 sid=2001:db8:1:1:: sid_structure=[40,24,16,0] type=bgp, subtype=0
 *>  192.168.15.0/24  1::1                     0             0 1 ?
    UN=1::1 EC{1:1 Color:01:100} label=16 sid=2001:db8:1:1:: sid_structure=[40,24,16,0] type=bgp, subtype=0

Displayed 2 routes and 2 total paths
router2# show bgp ipv4 vpn 192.168.11.0
BGP routing table entry for 1:1:192.168.11.0/24, version 1
not allocated
Paths: (1 available, best #1)
  Advertised to non peer-group peers:
  1::1
  1
    0.0.0.0 (metric 1024) from 1::1 (1.1.1.1)
      Origin incomplete, metric 0, valid, external, best (First path received)
      Relay-Nexthop(ip): gate 3fff:172:20:20::1, if eth0,
      Relay-Nexthop(tunnel): srv6-tunnel:1::1|100(endpoint|color),
      Extended Community: RT:1:1 Color:01:100
      Remote label: 16
      Remote SID: 2001:db8:1:1::
      Last update: Sat Dec  7 04:27:16 2024
router2# show ip route vrf Vrf1 192.168.11.0
Routing entry for 192.168.11.0/24
  Known via "bgp", distance 20, metric 0, vrf Vrf1, best
  Last update 00:01:31 ago
    1::1(vrf default) (recursive), label 16, seg6 100:1::100,200:1::200, srv6(endpoint|color):1::1|100, weight 1
  *   fe80::a8c1:abff:fe5c:7e19, via eth3(vrf default), label 16, seg6 100:1::100,200:1::200, srv6(endpoint|color):fe80::a8c1:abff:fe5c:7e19|0, weight 1
  *   fe80::a8c1:abff:feb5:6de9, via eth4(vrf default), label 16, seg6 100:1::100,200:1::200, srv6(endpoint|color):fe80::a8c1:abff:feb5:6de9|0, weight 1

frr@router2:/$ ip route show vrf Vrf1
192.168.11.0/24 nhid 74 proto bgp metric 20
        nexthop  encap seg6 mode encap segs 2 [ 100:1::100 200:1::200 ] via inet6 fe80::a8c1:abff:fe5c:7e19 dev eth3 weight 1
        nexthop  encap seg6 mode encap segs 2 [ 100:1::100 200:1::200 ] via inet6 fe80::a8c1:abff:feb5:6de9 dev eth4 weight 1
192.168.15.0/24 nhid 74 proto bgp metric 20
        nexthop  encap seg6 mode encap segs 2 [ 100:1::100 200:1::200 ] via inet6 fe80::a8c1:abff:fe5c:7e19 dev eth3 weight 1
        nexthop  encap seg6 mode encap segs 2 [ 100:1::100 200:1::200 ] via inet6 fe80::a8c1:abff:feb5:6de9 dev eth4 weight 1
192.168.23.0/24 dev eth1 proto kernel scope link src 192.168.23.1
192.168.25.0/24 dev eth5 proto kernel scope link src 192.168.25.1
frr@router2:/$

Signed-off-by: guozhongfeng.gzf <[email protected]>
  • Loading branch information
guoguojia2021 committed Dec 19, 2024
1 parent bed448b commit 1ea9f3b
Show file tree
Hide file tree
Showing 22 changed files with 1,190 additions and 342 deletions.
17 changes: 13 additions & 4 deletions bgpd/bgp_mplsvpn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1246,10 +1246,14 @@ leak_update(struct bgp *to_bgp, struct bgp_dest *bn,

if (leak_update_nexthop_valid(to_bgp, bn, new_attr, afi, safi,
source_bpi, bpi, bgp_orig, p,
debug))
debug)) {
bgp_path_info_set_flag(bn, bpi, BGP_PATH_VALID);
else
if (CHECK_FLAG(bpi->flags, BGP_PATH_SRV6_TE))
SET_FLAG(bpi->flags, BGP_PATH_SRV6_TE_VALID);
} else {
bgp_path_info_unset_flag(bn, bpi, BGP_PATH_VALID);
UNSET_FLAG(bpi->flags, BGP_PATH_SRV6_TE_VALID);
}

/* Process change. */
bgp_aggregate_increment(to_bgp, p, bpi, afi, safi);
Expand Down Expand Up @@ -1307,10 +1311,14 @@ leak_update(struct bgp *to_bgp, struct bgp_dest *bn,
new->extra->vrfleak->nexthop_orig = *nexthop_orig;

if (leak_update_nexthop_valid(to_bgp, bn, new_attr, afi, safi,
source_bpi, new, bgp_orig, p, debug))
source_bpi, new, bgp_orig, p, debug)) {
bgp_path_info_set_flag(bn, new, BGP_PATH_VALID);
else
if (CHECK_FLAG(new->flags, BGP_PATH_SRV6_TE))
SET_FLAG(new->flags, BGP_PATH_SRV6_TE_VALID);
} else {
bgp_path_info_unset_flag(bn, new, BGP_PATH_VALID);
UNSET_FLAG(new->flags, BGP_PATH_SRV6_TE_VALID);
}

bgp_aggregate_increment(to_bgp, p, new, afi, safi);
bgp_path_info_add(bn, new);
Expand Down Expand Up @@ -2691,6 +2699,7 @@ void vpn_leak_no_retain(struct bgp *to_bgp, struct bgp *vpn_from, afi_t afi)
continue;

bgp_unlink_nexthop(bpi);
bgp_unlink_te_nexthop(bpi);
bgp_rib_remove(bn, bpi, bpi->peer, afi, safi);
}
}
Expand Down
123 changes: 84 additions & 39 deletions bgpd/bgp_nexthop.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ bool bnc_existing_for_prefix(struct bgp_nexthop_cache *bnc)
frr_each (bgp_nexthop_cache, bnc->tree, bnc_tmp) {
if (bnc_tmp == bnc)
continue;
if (prefix_cmp(&bnc->prefix, &bnc_tmp->prefix) == 0)
if (prefix_cmp(&bnc->prefix, &bnc_tmp->prefix) == 0
&& (bnc->srte_color == bnc_tmp->srte_color))
return true;
}
return false;
Expand Down Expand Up @@ -125,6 +126,7 @@ static void bgp_nexthop_cache_reset(struct bgp_nexthop_cache_head *tree)
bgp_mplsvpn_path_nh_label_bind_unlink(path);

path_nh_map(path, bnc, false);
path_tenh_map(path, bnc, false);
}

bnc_free(bnc);
Expand Down Expand Up @@ -797,45 +799,86 @@ static void bgp_show_nexthop_paths(struct vty *vty, struct bgp *bgp,
paths = json_object_new_array();
else
vty_out(vty, " Paths:\n");
LIST_FOREACH (path, &(bnc->paths), nh_thread) {
dest = path->net;
assert(dest && bgp_dest_table(dest));
afi = family2afi(bgp_dest_get_prefix(dest)->family);
table = bgp_dest_table(dest);
safi = table->safi;
bgp_path = table->bgp;


if (json) {
json_path = json_object_new_object();
json_object_string_add(json_path, "afi", afi2str(afi));
json_object_string_add(json_path, "safi",
safi2str(safi));
json_object_string_addf(json_path, "prefix", "%pBD",
dest);
if (dest->pdest)
json_object_string_addf(
json_path, "rd",
BGP_RD_AS_FORMAT(bgp->asnotation),
if (bnc->srte_color) {
LIST_FOREACH (path, &(bnc->paths), te_nh_thread) {
dest = path->net;
assert(dest && bgp_dest_table(dest));
afi = family2afi(bgp_dest_get_prefix(dest)->family);
table = bgp_dest_table(dest);
safi = table->safi;
bgp_path = table->bgp;

if (json) {
json_path = json_object_new_object();
json_object_string_add(json_path, "afi", afi2str(afi));
json_object_string_add(json_path, "safi",
safi2str(safi));
json_object_string_addf(json_path, "prefix", "%pBD",
dest);
if (dest->pdest)
json_object_string_addf(
json_path, "rd",
BGP_RD_AS_FORMAT(bgp->asnotation),
(struct prefix_rd *)bgp_dest_get_prefix(
dest->pdest));
json_object_string_add(
json_path, "vrf",
vrf_id_to_name(bgp_path->vrf_id));
bgp_show_bgp_path_info_flags(path->flags, json_path);
json_object_array_add(paths, json_path);
continue;
}
if (dest->pdest) {
vty_out(vty, " %d/%d %pBD RD ", afi, safi, dest);
vty_out(vty, BGP_RD_AS_FORMAT(bgp->asnotation),
(struct prefix_rd *)bgp_dest_get_prefix(
dest->pdest));
json_object_string_add(
json_path, "vrf",
vrf_id_to_name(bgp_path->vrf_id));
bgp_show_bgp_path_info_flags(path->flags, json_path);
json_object_array_add(paths, json_path);
continue;
vty_out(vty, " %s flags 0x%x\n", bgp_path->name_pretty,
path->flags);
} else
vty_out(vty, " %d/%d %pBD %s flags 0x%x\n",
afi, safi, dest, bgp_path->name_pretty, path->flags);
}
} else {
LIST_FOREACH (path, &(bnc->paths), nh_thread) {
dest = path->net;
assert(dest && bgp_dest_table(dest));
afi = family2afi(bgp_dest_get_prefix(dest)->family);
table = bgp_dest_table(dest);
safi = table->safi;
bgp_path = table->bgp;

if (json) {
json_path = json_object_new_object();
json_object_string_add(json_path, "afi", afi2str(afi));
json_object_string_add(json_path, "safi",
safi2str(safi));
json_object_string_addf(json_path, "prefix", "%pBD",
dest);
if (dest->pdest)
json_object_string_addf(
json_path, "rd",
BGP_RD_AS_FORMAT(bgp->asnotation),
(struct prefix_rd *)bgp_dest_get_prefix(
dest->pdest));
json_object_string_add(
json_path, "vrf",
vrf_id_to_name(bgp_path->vrf_id));
bgp_show_bgp_path_info_flags(path->flags, json_path);
json_object_array_add(paths, json_path);
continue;
}
if (dest->pdest) {
vty_out(vty, " %d/%d %pBD RD ", afi, safi, dest);
vty_out(vty, BGP_RD_AS_FORMAT(bgp->asnotation),
(struct prefix_rd *)bgp_dest_get_prefix(
dest->pdest));
vty_out(vty, " %s flags 0x%x\n", bgp_path->name_pretty,
path->flags);
} else
vty_out(vty, " %d/%d %pBD %s flags 0x%x\n",
afi, safi, dest, bgp_path->name_pretty, path->flags);
}
if (dest->pdest) {
vty_out(vty, " %d/%d %pBD RD ", afi, safi, dest);
vty_out(vty, BGP_RD_AS_FORMAT(bgp->asnotation),
(struct prefix_rd *)bgp_dest_get_prefix(
dest->pdest));
vty_out(vty, " %s flags 0x%x\n", bgp_path->name_pretty,
path->flags);
} else
vty_out(vty, " %d/%d %pBD %s flags 0x%x\n",
afi, safi, dest, bgp_path->name_pretty, path->flags);
}
if (json)
json_object_object_add(json, "paths", paths);
Expand Down Expand Up @@ -1358,7 +1401,7 @@ char *bgp_nexthop_dump_bnc_flags(struct bgp_nexthop_cache *bnc, char *buf,
return buf;
}

snprintfrr(buf, len, "%s%s%s%s%s%s%s",
snprintfrr(buf, len, "%s%s%s%s%s%s%s%s",
CHECK_FLAG(bnc->flags, BGP_NEXTHOP_VALID) ? "Valid " : "",
CHECK_FLAG(bnc->flags, BGP_NEXTHOP_REGISTERED) ? "Reg " : "",
CHECK_FLAG(bnc->flags, BGP_NEXTHOP_CONNECTED) ? "Conn " : "",
Expand All @@ -1370,8 +1413,10 @@ char *bgp_nexthop_dump_bnc_flags(struct bgp_nexthop_cache *bnc, char *buf,
: "",
CHECK_FLAG(bnc->flags, BGP_NEXTHOP_LABELED_VALID)
? "Label Valid "
: "",
CHECK_FLAG(bnc->flags, BGP_NEXTHOP_SRV6TE_VALID)
? "SRv6 TE Valid "
: "");

return buf;
}

Expand Down
1 change: 1 addition & 0 deletions bgpd/bgp_nexthop.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ struct bgp_nexthop_cache {
#define BGP_STATIC_ROUTE_EXACT_MATCH (1 << 5)
#define BGP_NEXTHOP_LABELED_VALID (1 << 6)
#define BGP_NEXTHOP_ULTIMATE (1 << 7)
#define BGP_NEXTHOP_SRV6TE_VALID (1 << 8)

/*
* This flag is added for EVPN gateway IP nexthops.
Expand Down
Loading

0 comments on commit 1ea9f3b

Please sign in to comment.