Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zebra: SRv6 manager multi chunks support #9932

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
156 changes: 117 additions & 39 deletions bgpd/bgp_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -9243,13 +9243,11 @@ DEFPY (no_bgp_srv6_locator,
return CMD_SUCCESS;
}

DEFPY (show_bgp_srv6,
show_bgp_srv6_cmd,
"show bgp segment-routing srv6",
SHOW_STR
BGP_STR
"BGP Segment Routing\n"
"BGP Segment Routing SRv6\n")
DEFPY(show_bgp_srv6, show_bgp_srv6_cmd,
"show bgp segment-routing srv6 [json]",
SHOW_STR BGP_STR
"BGP Segment Routing\n"
"BGP Segment Routing SRv6\n" JSON_STR)
{
struct bgp *bgp;
struct listnode *node;
Expand All @@ -9260,43 +9258,123 @@ DEFPY (show_bgp_srv6,
char buf[256];
char buf_tovpn4_sid[256];
char buf_tovpn6_sid[256];
json_object *json = NULL;
json_object *json_chunks = NULL;
json_object *json_function = NULL;
json_object *json_functions = NULL;
json_object *json_bgp = NULL;
json_object *json_bgps = NULL;
json_object *json_vpn_policy = NULL;
json_object *json_vpn_policy_ip = NULL;
json_object *json_vpn_policy_ip6 = NULL;
bool uj = use_json(argc, argv);

bgp = bgp_get_default();
if (!bgp)
return CMD_SUCCESS;

vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
vty_out(vty, "locator_chunks:\n");
for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
prefix2str(chunk, buf, sizeof(buf));
vty_out(vty, "- %s\n", buf);
}

vty_out(vty, "functions:\n");
for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
vty_out(vty, "- sid: %s\n", buf);
vty_out(vty, " locator: %s\n", func->locator_name);
}

vty_out(vty, "bgps:\n");
for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
vty_out(vty, "- name: %s\n",
bgp->name ? bgp->name : "default");

tovpn4_sid = bgp->vpn_policy[AFI_IP].tovpn_sid;
tovpn6_sid = bgp->vpn_policy[AFI_IP6].tovpn_sid;
if (tovpn4_sid)
inet_ntop(AF_INET6, tovpn4_sid, buf_tovpn4_sid,
sizeof(buf_tovpn4_sid));
if (tovpn6_sid)
inet_ntop(AF_INET6, tovpn6_sid, buf_tovpn6_sid,
sizeof(buf_tovpn6_sid));

vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %s\n",
tovpn4_sid ? buf_tovpn4_sid : "none");
vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %s\n",
tovpn6_sid ? buf_tovpn6_sid : "none");
if (uj) {
json = json_object_new_object();
json_chunks = json_object_new_array();
json_functions = json_object_new_array();
json_bgps = json_object_new_array();
json_object_string_add(json, "locatorName",
bgp->srv6_locator_name);
json_object_object_add(json, "locatorChunks", json_chunks);
json_object_object_add(json, "functions", json_functions);
json_object_object_add(json, "bgps", json_bgps);

/* collect all chunk to json array*/
for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node,
chunk)) {
prefix2str(chunk, buf, sizeof(buf));
json_array_string_add(json_chunks, buf);
}

/* collect all function to json array*/
for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
json_function = json_object_new_object();
json_object_array_add(json_functions, json_function);
inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
json_object_string_add(json_function, "Sid", buf);
json_object_string_add(json_function, "locator",
func->locator_name);
}

/* collect all bgp instance to json array*/
for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
json_bgp = json_object_new_object();
json_object_array_add(json_bgps, json_bgp);
json_object_string_add(json_bgp, "name",
bgp->name ? bgp->name
: "default");

json_vpn_policy = json_object_new_object();
json_vpn_policy_ip = json_object_new_object();
json_vpn_policy_ip6 = json_object_new_object();
json_object_object_add(json_bgp, "vpnPolicy",
json_vpn_policy);
json_object_object_add(json_vpn_policy, "ip",
json_vpn_policy_ip);
json_object_object_add(json_vpn_policy, "ip6",
json_vpn_policy_ip6);

tovpn4_sid = bgp->vpn_policy[AFI_IP].tovpn_sid;
tovpn6_sid = bgp->vpn_policy[AFI_IP6].tovpn_sid;
if (tovpn4_sid)
inet_ntop(AF_INET6, tovpn4_sid, buf_tovpn4_sid,
sizeof(buf_tovpn4_sid));
if (tovpn6_sid)
inet_ntop(AF_INET6, tovpn6_sid, buf_tovpn6_sid,
sizeof(buf_tovpn6_sid));

json_object_string_add(json_vpn_policy_ip, "toVpnSid",
tovpn4_sid ? buf_tovpn4_sid
: "none");
json_object_string_add(json_vpn_policy_ip6, "toVpnSid",
tovpn6_sid ? buf_tovpn6_sid
: "none");
}

vty_out(vty, "%s\n",
json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
} else {
vty_out(vty, "locator_name: %s\n", bgp->srv6_locator_name);
vty_out(vty, "locator_chunks:\n");
for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node,
chunk)) {
prefix2str(chunk, buf, sizeof(buf));
vty_out(vty, "- %s\n", buf);
}

vty_out(vty, "functions:\n");
for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
vty_out(vty, "- sid: %s\n", buf);
vty_out(vty, " locator: %s\n", func->locator_name);
}

vty_out(vty, "bgps:\n");
for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) {
vty_out(vty, "- name: %s\n",
bgp->name ? bgp->name : "default");

tovpn4_sid = bgp->vpn_policy[AFI_IP].tovpn_sid;
tovpn6_sid = bgp->vpn_policy[AFI_IP6].tovpn_sid;
if (tovpn4_sid)
inet_ntop(AF_INET6, tovpn4_sid, buf_tovpn4_sid,
sizeof(buf_tovpn4_sid));
if (tovpn6_sid)
inet_ntop(AF_INET6, tovpn6_sid, buf_tovpn6_sid,
sizeof(buf_tovpn6_sid));

vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %s\n",
tovpn4_sid ? buf_tovpn4_sid : "none");
vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %s\n",
tovpn6_sid ? buf_tovpn6_sid : "none");
}
}

return CMD_SUCCESS;
Expand Down
19 changes: 19 additions & 0 deletions lib/srv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,25 @@ void srv6_locator_chunk_free(struct srv6_locator_chunk *chunk)
XFREE(MTYPE_SRV6_LOCATOR_CHUNK, chunk);
}

/**
* check all chunk in the locator are used by clients
*
* @param loc SRv6 locator
* @return true if all chunks are used.
*/
bool srv6_locator_chunks_exhausted(const struct srv6_locator *loc)
{
struct listnode *node;
struct srv6_locator_chunk *chunk;

for (ALL_LIST_ELEMENTS_RO(loc->chunks, node, chunk))
if (chunk->proto == 0 && chunk->instance == 0
&& chunk->session_id == 0 && chunk->keep == 0)
return false;

return true;
}

json_object *srv6_locator_chunk_json(const struct srv6_locator_chunk *chunk)
{
char str[256];
Expand Down
2 changes: 2 additions & 0 deletions lib/srv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ struct srv6_locator {
uint64_t current;
bool status_up;
struct list *chunks;
uint8_t chunk_bits_length;

QOBJ_FIELDS;
};
Expand Down Expand Up @@ -187,6 +188,7 @@ extern struct srv6_locator *srv6_locator_alloc(const char *name);
extern struct srv6_locator_chunk *srv6_locator_chunk_alloc(void);
extern void srv6_locator_free(struct srv6_locator *locator);
extern void srv6_locator_chunk_free(struct srv6_locator_chunk *chunk);
extern bool srv6_locator_chunks_exhausted(const struct srv6_locator *loc);
json_object *srv6_locator_chunk_json(const struct srv6_locator_chunk *chunk);
json_object *srv6_locator_json(const struct srv6_locator *loc);

Expand Down
14 changes: 4 additions & 10 deletions sharpd/sharp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -942,23 +942,17 @@ static int sharp_zebra_process_srv6_locator_chunk(ZAPI_CALLBACK_ARGS)
zapi_srv6_locator_chunk_decode(s, &s6c);

for (ALL_LIST_ELEMENTS(sg.srv6_locators, node, nnode, loc)) {
struct prefix_ipv6 *chunk = NULL;
struct listnode *chunk_node;
struct prefix_ipv6 *c;
struct prefix_ipv6 *chunk_prefix = NULL;

if (strcmp(loc->name, s6c.locator_name) != 0) {
zlog_err("%s: Locator name unmatch %s:%s", __func__,
loc->name, s6c.locator_name);
continue;
}

for (ALL_LIST_ELEMENTS_RO(loc->chunks, chunk_node, c))
if (!prefix_cmp(c, &s6c.prefix))
return 0;

chunk = prefix_ipv6_new();
*chunk = s6c.prefix;
listnode_add(loc->chunks, chunk);
chunk_prefix = prefix_ipv6_new();
*chunk_prefix = s6c.prefix;
listnode_add(loc->chunks, chunk_prefix);
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/topotests/srv6_locator/expected_chunks2.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"name": "loc1",
"chunks": [
"2001:db8:1:1::/64"
"2001:db8:1:1::/68"
]
}
]
8 changes: 0 additions & 8 deletions tests/topotests/srv6_locator/expected_locators1.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,13 @@
"prefix": "2001:db8:1:1::/64",
"statusUp": true,
"chunks": [
{
"prefix": "2001:db8:1:1::/64",
"proto": "system"
}
]
},
{
"name": "loc2",
"prefix": "2001:db8:2:2::/64",
"statusUp": true,
"chunks": [
{
"prefix": "2001:db8:2:2::/64",
"proto": "system"
}
]
}
]
Expand Down
6 changes: 1 addition & 5 deletions tests/topotests/srv6_locator/expected_locators2.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"statusUp": true,
"chunks": [
{
"prefix": "2001:db8:1:1::/64",
"prefix": "2001:db8:1:1::/68",
"proto": "sharp"
}
]
Expand All @@ -16,10 +16,6 @@
"prefix": "2001:db8:2:2::/64",
"statusUp": true,
"chunks": [
{
"prefix": "2001:db8:2:2::/64",
"proto": "system"
}
]
}
]
Expand Down
6 changes: 1 addition & 5 deletions tests/topotests/srv6_locator/expected_locators3.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"statusUp": true,
"chunks": [
{
"prefix": "2001:db8:1:1::/64",
"prefix": "2001:db8:1:1::/68",
"proto": "system"
}
]
Expand All @@ -16,10 +16,6 @@
"prefix": "2001:db8:2:2::/64",
"statusUp": true,
"chunks": [
{
"prefix": "2001:db8:2:2::/64",
"proto": "system"
}
]
}
]
Expand Down
10 changes: 1 addition & 9 deletions tests/topotests/srv6_locator/expected_locators4.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"statusUp": true,
"chunks": [
{
"prefix": "2001:db8:1:1::/64",
"prefix": "2001:db8:1:1::/68",
"proto": "system"
}
]
Expand All @@ -16,21 +16,13 @@
"prefix": "2001:db8:2:2::/64",
"statusUp": true,
"chunks": [
{
"prefix": "2001:db8:2:2::/64",
"proto": "system"
}
]
},
{
"name": "loc3",
"prefix": "2001:db8:3:3::/64",
"statusUp": true,
"chunks": [
{
"prefix": "2001:db8:3:3::/64",
"proto": "system"
}
]
}
]
Expand Down
8 changes: 0 additions & 8 deletions tests/topotests/srv6_locator/expected_locators5.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,13 @@
"prefix": "2001:db8:2:2::/64",
"statusUp": true,
"chunks": [
{
"prefix": "2001:db8:2:2::/64",
"proto": "system"
}
]
},
{
"name": "loc3",
"prefix": "2001:db8:3:3::/64",
"statusUp": true,
"chunks":[
{
"prefix": "2001:db8:3:3::/64",
"proto": "system"
}
]
}
]
Expand Down
Empty file.
3 changes: 3 additions & 0 deletions tests/topotests/srv6_locator_chunks/r1/bgpd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
router bgp 100
bgp router-id 1.1.1.1
!
2 changes: 2 additions & 0 deletions tests/topotests/srv6_locator_chunks/r1/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ip link add dummy0 type dummy
ip link set dummy0 up
7 changes: 7 additions & 0 deletions tests/topotests/srv6_locator_chunks/r1/sharpd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
hostname r1
!
log stdout notifications
log monitor notifications
log commands
log file sharpd.log debugging
!
Loading