summaryrefslogtreecommitdiff
path: root/sharpd
diff options
context:
space:
mode:
Diffstat (limited to 'sharpd')
-rw-r--r--sharpd/sharp_main.c4
-rw-r--r--sharpd/sharp_vty.c115
-rw-r--r--sharpd/sharp_zebra.c64
3 files changed, 141 insertions, 42 deletions
diff --git a/sharpd/sharp_main.c b/sharpd/sharp_main.c
index a646c313e4..d7783b6fc7 100644
--- a/sharpd/sharp_main.c
+++ b/sharpd/sharp_main.c
@@ -94,7 +94,7 @@ static void sigusr1(void)
zlog_rotate();
}
-struct quagga_signal_t sharp_signals[] = {
+struct frr_signal_t sharp_signals[] = {
{
.signal = SIGHUP,
.handler = &sighup,
@@ -181,7 +181,7 @@ int main(int argc, char **argv, char **envp)
sharp_global_init();
sharp_nhgroup_init();
- vrf_init(NULL, NULL, NULL, NULL, NULL);
+ vrf_init(NULL, NULL, NULL, NULL);
sharp_zebra_init();
diff --git a/sharpd/sharp_vty.c b/sharpd/sharp_vty.c
index 34629b929f..ceed9cf739 100644
--- a/sharpd/sharp_vty.c
+++ b/sharpd/sharp_vty.c
@@ -29,7 +29,9 @@
#include "vrf.h"
#include "zclient.h"
#include "nexthop_group.h"
+#include "linklist.h"
#include "link_state.h"
+#include "cspf.h"
#include "sharpd/sharp_globals.h"
#include "sharpd/sharp_zebra.h"
@@ -1071,12 +1073,8 @@ DEFUN (show_sharp_ted,
ls_show_ted(sg.ted, vty, json, verbose);
}
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- }
+ if (uj)
+ vty_json(vty, json);
return CMD_SUCCESS;
}
@@ -1143,9 +1141,7 @@ DEFPY (show_sharp_segment_routing_srv6,
}
}
- vty_out(vty, "%s\n", json_object_to_json_string_ext(
- jo_locs, JSON_C_TO_STRING_PRETTY));
- json_object_free(jo_locs);
+ vty_json(vty, jo_locs);
} else {
for (ALL_LIST_ELEMENTS_RO(sg.srv6_locators, loc_node, loc)) {
vty_out(vty, "Locator %s has %d prefix chunks\n",
@@ -1162,6 +1158,106 @@ DEFPY (show_sharp_segment_routing_srv6,
return CMD_SUCCESS;
}
+DEFPY (show_sharp_cspf,
+ show_sharp_cspf_cmd,
+ "show sharp cspf source <A.B.C.D$src4|X:X::X:X$src6> \
+ destination <A.B.C.D$dst4|X:X::X:X$dst6> \
+ <metric|te-metric|delay> (0-16777215)$cost \
+ [rsv-bw (0-7)$cos BANDWIDTH$bw]",
+ SHOW_STR
+ SHARP_STR
+ "Constraint Shortest Path First path computation\n"
+ "Source of the path\n"
+ "IPv4 Source address in dot decimal A.B.C.D\n"
+ "IPv6 Source address as X:X:X:X\n"
+ "Destination of the path\n"
+ "IPv4 Destination address in dot decimal A.B.C.D\n"
+ "IPv6 Destination address as X:X:X:X\n"
+ "Maximum Metric\n"
+ "Maximum TE Metric\n"
+ "Maxim Delay\n"
+ "Value of Maximum cost\n"
+ "Reserved Bandwidth of this path\n"
+ "Class of Service or Priority level\n"
+ "Bytes/second (IEEE floating point format)\n")
+{
+
+ struct cspf *algo;
+ struct constraints csts;
+ struct c_path *path;
+ struct listnode *node;
+ struct ls_edge *edge;
+ int idx;
+
+ if (sg.ted == NULL) {
+ vty_out(vty, "MPLS-TE import is not enabled\n");
+ return CMD_WARNING;
+ }
+
+ if ((src4.s_addr != INADDR_ANY && dst4.s_addr == INADDR_ANY) ||
+ (src4.s_addr == INADDR_ANY && dst4.s_addr != INADDR_ANY)) {
+ vty_out(vty, "Don't mix IPv4 and IPv6 addresses\n");
+ return CMD_WARNING;
+ }
+
+ idx = 6;
+ memset(&csts, 0, sizeof(struct constraints));
+ if (argv_find(argv, argc, "metric", &idx)) {
+ csts.ctype = CSPF_METRIC;
+ csts.cost = cost;
+ }
+ idx = 6;
+ if (argv_find(argv, argc, "te-metric", &idx)) {
+ csts.ctype = CSPF_TE_METRIC;
+ csts.cost = cost;
+ }
+ idx = 6;
+ if (argv_find(argv, argc, "delay", &idx)) {
+ csts.ctype = CSPF_DELAY;
+ csts.cost = cost;
+ }
+ if (argc > 9) {
+ if (sscanf(bw, "%g", &csts.bw) != 1) {
+ vty_out(vty, "Bandwidth constraints: fscanf: %s\n",
+ safe_strerror(errno));
+ return CMD_WARNING_CONFIG_FAILED;
+ }
+ csts.cos = cos;
+ }
+
+ /* Initialize and call point-to-point Path computation */
+ if (src4.s_addr != INADDR_ANY)
+ algo = cspf_init_v4(NULL, sg.ted, src4, dst4, &csts);
+ else
+ algo = cspf_init_v6(NULL, sg.ted, src6, dst6, &csts);
+ path = compute_p2p_path(algo, sg.ted);
+ cspf_del(algo);
+
+ if (!path) {
+ vty_out(vty, "Path computation failed without error\n");
+ return CMD_SUCCESS;
+ }
+ if (path->status != SUCCESS) {
+ vty_out(vty, "Path computation failed: %d\n", path->status);
+ return CMD_SUCCESS;
+ }
+
+ vty_out(vty, "Path computation success\n");
+ vty_out(vty, "\tCost: %d\n", path->weight);
+ vty_out(vty, "\tEdges:");
+ for (ALL_LIST_ELEMENTS_RO(path->edges, node, edge)) {
+ if (src4.s_addr != INADDR_ANY)
+ vty_out(vty, " %pI4",
+ &edge->attributes->standard.remote);
+ else
+ vty_out(vty, " %pI6",
+ &edge->attributes->standard.remote6);
+ }
+ vty_out(vty, "\n");
+
+ return CMD_SUCCESS;
+}
+
void sharp_vty_init(void)
{
install_element(ENABLE_NODE, &install_routes_data_dump_cmd);
@@ -1187,6 +1283,7 @@ void sharp_vty_init(void)
install_element(ENABLE_NODE, &show_debugging_sharpd_cmd);
install_element(ENABLE_NODE, &show_sharp_ted_cmd);
+ install_element(ENABLE_NODE, &show_sharp_cspf_cmd);
install_element(ENABLE_NODE, &sharp_srv6_manager_get_locator_chunk_cmd);
install_element(ENABLE_NODE,
diff --git a/sharpd/sharp_zebra.c b/sharpd/sharp_zebra.c
index 2575475dd2..313febd9bb 100644
--- a/sharpd/sharp_zebra.c
+++ b/sharpd/sharp_zebra.c
@@ -626,19 +626,12 @@ void sharp_zebra_nexthop_watch(struct prefix *p, vrf_id_t vrf_id, bool import,
{
int command;
- if (!import) {
- command = ZEBRA_NEXTHOP_REGISTER;
+ command = ZEBRA_NEXTHOP_REGISTER;
- if (!watch)
- command = ZEBRA_NEXTHOP_UNREGISTER;
- } else {
- command = ZEBRA_IMPORT_ROUTE_REGISTER;
-
- if (!watch)
- command = ZEBRA_IMPORT_ROUTE_UNREGISTER;
- }
+ if (!watch)
+ command = ZEBRA_NEXTHOP_UNREGISTER;
- if (zclient_send_rnh(zclient, command, p, connected, vrf_id)
+ if (zclient_send_rnh(zclient, command, p, connected, false, vrf_id)
== ZCLIENT_SEND_FAILURE)
zlog_warn("%s: Failure to send nexthop to zebra", __func__);
}
@@ -727,6 +720,10 @@ void sharp_redistribute_vrf(struct vrf *vrf, int type)
0, vrf->vrf_id);
}
+static zclient_handler *const sharp_opaque_handlers[] = {
+ [ZEBRA_OPAQUE_MESSAGE] = sharp_opaque_handler,
+};
+
/* Add a zclient with a specified session id, for testing. */
int sharp_zclient_create(uint32_t session_id)
{
@@ -739,15 +736,14 @@ int sharp_zclient_create(uint32_t session_id)
return -1;
}
- client = zclient_new(master, &zclient_options_default);
+ client = zclient_new(master, &zclient_options_default,
+ sharp_opaque_handlers,
+ array_size(sharp_opaque_handlers));
client->sock = -1;
client->session_id = session_id;
zclient_init(client, ZEBRA_ROUTE_SHARP, 0, &sharp_privs);
- /* Register handlers for messages we expect this session to see */
- client->opaque_msg_handler = sharp_opaque_handler;
-
/* Enqueue on the list of test clients */
add_zclient(client);
@@ -803,10 +799,12 @@ static int sharp_opaque_handler(ZAPI_CALLBACK_ARGS)
if (info.type == LINK_STATE_UPDATE) {
lse = ls_stream2ted(sg.ted, s, false);
- if (lse)
+ if (lse) {
zlog_debug(" |- Got %s %s from Link State Database",
status2txt[lse->status],
type2txt[lse->type]);
+ lse->status = SYNC;
+ }
else
zlog_debug(
"%s: Error to convert Stream into Link State",
@@ -935,7 +933,7 @@ int sharp_zebra_srv6_manager_release_locator_chunk(const char *locator_name)
return srv6_manager_release_locator_chunk(zclient, locator_name);
}
-static void sharp_zebra_process_srv6_locator_chunk(ZAPI_CALLBACK_ARGS)
+static int sharp_zebra_process_srv6_locator_chunk(ZAPI_CALLBACK_ARGS)
{
struct stream *s = NULL;
struct srv6_locator_chunk s6c = {};
@@ -958,17 +956,31 @@ static void sharp_zebra_process_srv6_locator_chunk(ZAPI_CALLBACK_ARGS)
for (ALL_LIST_ELEMENTS_RO(loc->chunks, chunk_node, c))
if (!prefix_cmp(c, &s6c.prefix))
- return;
+ return 0;
chunk = prefix_ipv6_new();
*chunk = s6c.prefix;
listnode_add(loc->chunks, chunk);
- return;
+ return 0;
}
zlog_err("%s: can't get locator_chunk!!", __func__);
+ return 0;
}
+static zclient_handler *const sharp_handlers[] = {
+ [ZEBRA_INTERFACE_ADDRESS_ADD] = interface_address_add,
+ [ZEBRA_INTERFACE_ADDRESS_DELETE] = interface_address_delete,
+ [ZEBRA_ROUTE_NOTIFY_OWNER] = route_notify_owner,
+ [ZEBRA_NEXTHOP_UPDATE] = sharp_nexthop_update,
+ [ZEBRA_NHG_NOTIFY_OWNER] = nhg_notify_owner,
+ [ZEBRA_REDISTRIBUTE_ROUTE_ADD] = sharp_redistribute_route,
+ [ZEBRA_REDISTRIBUTE_ROUTE_DEL] = sharp_redistribute_route,
+ [ZEBRA_OPAQUE_MESSAGE] = sharp_opaque_handler,
+ [ZEBRA_SRV6_MANAGER_GET_LOCATOR_CHUNK] =
+ sharp_zebra_process_srv6_locator_chunk,
+};
+
void sharp_zebra_init(void)
{
struct zclient_options opt = {.receive_notify = true};
@@ -976,20 +988,10 @@ void sharp_zebra_init(void)
if_zapi_callbacks(sharp_ifp_create, sharp_ifp_up,
sharp_ifp_down, sharp_ifp_destroy);
- zclient = zclient_new(master, &opt);
+ zclient = zclient_new(master, &opt, sharp_handlers,
+ array_size(sharp_handlers));
zclient_init(zclient, ZEBRA_ROUTE_SHARP, 0, &sharp_privs);
zclient->zebra_connected = zebra_connected;
- zclient->interface_address_add = interface_address_add;
- zclient->interface_address_delete = interface_address_delete;
- zclient->route_notify_owner = route_notify_owner;
- zclient->nexthop_update = sharp_nexthop_update;
- zclient->import_check_update = sharp_nexthop_update;
- zclient->nhg_notify_owner = nhg_notify_owner;
zclient->zebra_buffer_write_ready = sharp_zclient_buffer_ready;
- zclient->redistribute_route_add = sharp_redistribute_route;
- zclient->redistribute_route_del = sharp_redistribute_route;
- zclient->opaque_msg_handler = sharp_opaque_handler;
- zclient->process_srv6_locator_chunk =
- sharp_zebra_process_srv6_locator_chunk;
}