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

Multi chunk trial #14180

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 112 additions & 27 deletions bgpd/bgp_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -10322,50 +10322,135 @@ 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;
struct srv6_locator_chunk *chunk;
struct bgp_srv6_function *func;
json_object *json = NULL;
json_object *json_chunk = 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)) {
vty_out(vty, "- %pFX\n", &chunk->prefix);
vty_out(vty, " block-length: %d\n", chunk->block_bits_length);
vty_out(vty, " node-length: %d\n", chunk->node_bits_length);
vty_out(vty, " func-length: %d\n",
chunk->function_bits_length);
vty_out(vty, " arg-length: %d\n", chunk->argument_bits_length);
}

vty_out(vty, "functions:\n");
for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
vty_out(vty, "- sid: %pI6\n", &func->sid);
vty_out(vty, " locator: %s\n", func->locator_name);
}
if (!uj) {
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)) {
vty_out(vty, "- %pFX\n", &chunk->prefix);
vty_out(vty, " block-length: %d\n",
chunk->block_bits_length);
vty_out(vty, " node-length: %d\n",
chunk->node_bits_length);
vty_out(vty, " func-length: %d\n",
chunk->function_bits_length);
vty_out(vty, " arg-length: %d\n",
chunk->argument_bits_length);
}

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");
vty_out(vty, "functions:\n");
for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
vty_out(vty, "- sid: %pI6\n", &func->sid);
vty_out(vty, " locator: %s\n", func->locator_name);
}

vty_out(vty, " vpn_policy[AFI_IP].tovpn_sid: %pI6\n",
bgp->vpn_policy[AFI_IP].tovpn_sid);
vty_out(vty, " vpn_policy[AFI_IP6].tovpn_sid: %pI6\n",
bgp->vpn_policy[AFI_IP6].tovpn_sid);
vty_out(vty, " per-vrf tovpn_sid: %pI6\n", bgp->tovpn_sid);

} else {
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)) {
json_chunk = json_object_new_object();
json_object_array_add(json_chunks, json_chunk);
json_object_string_addf(json_chunk, "chunk", "%pFX",
&chunk->prefix);
json_object_int_add(json_chunk, "block-length",
chunk->block_bits_length);
json_object_int_add(json_chunk, "node-bits-length",
chunk->node_bits_length);
json_object_int_add(json_chunk, "function-bits-length",
chunk->function_bits_length);
json_object_int_add(json_chunk, "arg-length",
chunk->argument_bits_length);
}

/* 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);
json_object_string_addf(json_function, "Sid", "%pI6",
&func->sid);
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);
if (bgp->vpn_policy[AFI_IP].tovpn_sid)
json_object_string_addf(json_vpn_policy_ip,
"toVpnSid", "%pI6",
bgp->vpn_policy[AFI_IP]
.tovpn_sid);
else
json_object_string_add(json_vpn_policy_ip,
"toVpnSid", "none");
if (bgp->vpn_policy[AFI_IP6].tovpn_sid)
json_object_string_addf(json_vpn_policy_ip6,
"toVpnSid", "%pI6",
bgp->vpn_policy[AFI_IP6]
.tovpn_sid);
else
json_object_string_add(json_vpn_policy_ip6,
"toVpnSid", "none");
}

vty_out(vty, "%s\n",
json_object_to_json_string_ext(json,
JSON_C_TO_STRING_PRETTY));
json_object_free(json);
}

return CMD_SUCCESS;
Expand Down
18 changes: 18 additions & 0 deletions lib/srv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,24 @@ 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)
{
json_object *jo_root = NULL;
Expand Down
2 changes: 2 additions & 0 deletions lib/srv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ struct srv6_locator {
uint64_t current;
bool status_up;
struct list *chunks;
uint8_t chunk_bits_length;

uint8_t flags;
#define SRV6_LOCATOR_USID (1 << 0) /* The SRv6 Locator is a uSID Locator */
Expand Down Expand Up @@ -195,6 +196,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);
json_object *srv6_locator_detailed_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 @@ -965,23 +965,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
12 changes: 6 additions & 6 deletions tests/topotests/srv6_locator/expected_chunks2.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[
{
"name": "loc1",
"chunks": [
"2001:db8:1:1::/64"
]
}
{
"name": "loc1",
"chunks": [
"2001:db8:1:1::/68"
]
}
]
40 changes: 16 additions & 24 deletions tests/topotests/srv6_locator/expected_locators1.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
{
"locators":[
{
"name": "loc1",
"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"
}
]
}
]
"locators": [
{
"name": "loc1",
"prefix": "2001:db8:1:1::/64",
"statusUp": true,
"chunks": [
]
},
{
"name": "loc2",
"prefix": "2001:db8:2:2::/64",
"statusUp": true,
"chunks": [
]
}
]
}
44 changes: 20 additions & 24 deletions tests/topotests/srv6_locator/expected_locators2.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
{
"locators":[
{
"name": "loc1",
"prefix": "2001:db8:1:1::/64",
"statusUp": true,
"chunks": [
{
"prefix": "2001:db8:1:1::/64",
"proto": "sharp"
}
]
},
{
"name": "loc2",
"prefix": "2001:db8:2:2::/64",
"statusUp": true,
"chunks": [
{
"prefix": "2001:db8:2:2::/64",
"proto": "system"
}
]
}
]
"locators": [
{
"name": "loc1",
"prefix": "2001:db8:1:1::/64",
"statusUp": true,
"chunks": [
{
"prefix": "2001:db8:1:1::/68",
"proto": "sharp"
}
]
},
{
"name": "loc2",
"prefix": "2001:db8:2:2::/64",
"statusUp": true,
"chunks": [
]
}
]
}
44 changes: 20 additions & 24 deletions tests/topotests/srv6_locator/expected_locators3.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
{
"locators":[
{
"name": "loc1",
"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"
}
]
}
]
"locators": [
{
"name": "loc1",
"prefix": "2001:db8:1:1::/64",
"statusUp": true,
"chunks": [
{
"prefix": "2001:db8:1:1::/68",
"proto": "system"
}
]
},
{
"name": "loc2",
"prefix": "2001:db8:2:2::/64",
"statusUp": true,
"chunks": [
]
}
]
}
Loading