sharpd: support 'update lsp' zapi testing

Add 'update' support so that sharpd can exercise add,
update, and delete zapi exchanges for LSPs.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
This commit is contained in:
Mark Stapp 2020-08-04 09:34:37 -04:00
parent 774daaed3f
commit faa75dfa6c
4 changed files with 43 additions and 30 deletions

View File

@ -88,13 +88,13 @@ keyword. At present, no sharp commands will be preserved in the config.
may have been turned on. may have been turned on.
.. index:: sharp lsp .. index:: sharp lsp
.. clicmd:: sharp lsp (0-100000) nexthop-group NAME [prefix A.B.C.D/M TYPE [instance (0-255)]] .. clicmd:: sharp lsp [update] (0-100000) nexthop-group NAME [prefix A.B.C.D/M TYPE [instance (0-255)]]
Install an LSP using the specified in-label, with nexthops as Install an LSP using the specified in-label, with nexthops as
listed in nexthop-group ``NAME``. The LSP is installed as type listed in nexthop-group ``NAME``. If ``update`` is included, the
ZEBRA_LSP_SHARP. If ``prefix`` is specified, an existing route with update path is used. The LSP is installed as type ZEBRA_LSP_SHARP.
type ``TYPE`` (and optional ``instance`` id) will be updated to use If ``prefix`` is specified, an existing route with type ``TYPE``
the LSP. (and optional ``instance`` id) will be updated to use the LSP.
.. index:: sharp remove lsp .. index:: sharp remove lsp
.. clicmd:: sharp remove lsp (0-100000) nexthop-group NAME [prefix A.B.C.D/M TYPE [instance (0-255)]] .. clicmd:: sharp remove lsp (0-100000) nexthop-group NAME [prefix A.B.C.D/M TYPE [instance (0-255)]]

View File

@ -394,13 +394,14 @@ DEFUN_NOSH (show_debugging_sharpd,
return CMD_SUCCESS; return CMD_SUCCESS;
} }
DEFPY(sharp_lsp_prefix_v4, sharp_lsp_prefix_v4_cmd, DEFPY (sharp_lsp_prefix_v4, sharp_lsp_prefix_v4_cmd,
"sharp lsp (0-100000)$inlabel\ "sharp lsp [update]$update (0-100000)$inlabel\
nexthop-group NHGNAME$nhgname\ nexthop-group NHGNAME$nhgname\
[prefix A.B.C.D/M$pfx\ [prefix A.B.C.D/M$pfx\
" FRR_IP_REDIST_STR_ZEBRA "$type_str [instance (0-255)$instance]]", " FRR_IP_REDIST_STR_ZEBRA "$type_str [instance (0-255)$instance]]",
"Sharp Routing Protocol\n" "Sharp Routing Protocol\n"
"Add an LSP\n" "Add an LSP\n"
"Update an LSP\n"
"The ingress label to use\n" "The ingress label to use\n"
"Use nexthops from a nexthop-group\n" "Use nexthops from a nexthop-group\n"
"The nexthop-group name\n" "The nexthop-group name\n"
@ -415,6 +416,9 @@ DEFPY(sharp_lsp_prefix_v4, sharp_lsp_prefix_v4_cmd,
struct nexthop_group *backup_nhg = NULL; struct nexthop_group *backup_nhg = NULL;
struct prefix p = {}; struct prefix p = {};
int type = 0; int type = 0;
bool update_p;
update_p = (update != NULL);
/* We're offered a v4 prefix */ /* We're offered a v4 prefix */
if (pfx->family > 0 && type_str) { if (pfx->family > 0 && type_str) {
@ -458,7 +462,8 @@ DEFPY(sharp_lsp_prefix_v4, sharp_lsp_prefix_v4_cmd,
backup_nhg = &(backup_nhgc->nhg); backup_nhg = &(backup_nhgc->nhg);
} }
if (sharp_install_lsps_helper(true, pfx->family > 0 ? &p : NULL, if (sharp_install_lsps_helper(true /*install*/, update_p,
pfx->family > 0 ? &p : NULL,
type, instance, inlabel, type, instance, inlabel,
&(nhgc->nhg), backup_nhg) == 0) &(nhgc->nhg), backup_nhg) == 0)
return CMD_SUCCESS; return CMD_SUCCESS;
@ -523,7 +528,8 @@ DEFPY(sharp_remove_lsp_prefix_v4, sharp_remove_lsp_prefix_v4_cmd,
nhg = &(nhgc->nhg); nhg = &(nhgc->nhg);
} }
if (sharp_install_lsps_helper(false, pfx->family > 0 ? &p : NULL, if (sharp_install_lsps_helper(false /*!install*/, false,
pfx->family > 0 ? &p : NULL,
type, instance, inlabel, nhg, NULL) == 0) type, instance, inlabel, nhg, NULL) == 0)
return CMD_SUCCESS; return CMD_SUCCESS;
else { else {

View File

@ -114,15 +114,16 @@ static int sharp_ifp_down(struct interface *ifp)
return 0; return 0;
} }
int sharp_install_lsps_helper(bool install_p, const struct prefix *p, int sharp_install_lsps_helper(bool install_p, bool update_p,
uint8_t type, int instance, uint32_t in_label, const struct prefix *p, uint8_t type,
int instance, uint32_t in_label,
const struct nexthop_group *nhg, const struct nexthop_group *nhg,
const struct nexthop_group *backup_nhg) const struct nexthop_group *backup_nhg)
{ {
struct zapi_labels zl = {}; struct zapi_labels zl = {};
struct zapi_nexthop *znh; struct zapi_nexthop *znh;
const struct nexthop *nh; const struct nexthop *nh;
int i, ret; int i, cmd, ret;
zl.type = ZEBRA_LSP_SHARP; zl.type = ZEBRA_LSP_SHARP;
zl.local_label = in_label; zl.local_label = in_label;
@ -200,12 +201,17 @@ int sharp_install_lsps_helper(bool install_p, const struct prefix *p,
zl.backup_nexthop_num = i; zl.backup_nexthop_num = i;
} }
if (install_p)
ret = zebra_send_mpls_labels(zclient, ZEBRA_MPLS_LABELS_ADD, if (install_p) {
&zl); if (update_p)
cmd = ZEBRA_MPLS_LABELS_REPLACE;
else else
ret = zebra_send_mpls_labels(zclient, ZEBRA_MPLS_LABELS_DELETE, cmd = ZEBRA_MPLS_LABELS_ADD;
&zl); } else {
cmd = ZEBRA_MPLS_LABELS_DELETE;
}
ret = zebra_send_mpls_labels(zclient, cmd, &zl);
return ret; return ret;
} }

View File

@ -44,8 +44,9 @@ extern void sharp_install_routes_helper(struct prefix *p, vrf_id_t vrf_id,
extern void sharp_remove_routes_helper(struct prefix *p, vrf_id_t vrf_id, extern void sharp_remove_routes_helper(struct prefix *p, vrf_id_t vrf_id,
uint8_t instance, uint32_t routes); uint8_t instance, uint32_t routes);
int sharp_install_lsps_helper(bool install_p, const struct prefix *p, int sharp_install_lsps_helper(bool install_p, bool update_p,
uint8_t type, int instance, uint32_t in_label, const struct prefix *p, uint8_t type,
int instance, uint32_t in_label,
const struct nexthop_group *nhg, const struct nexthop_group *nhg,
const struct nexthop_group *backup_nhg); const struct nexthop_group *backup_nhg);