/* The nexthop info we are using for installation */
struct nexthop nhop;
struct nexthop backup_nhop;
+ uint32_t nhgid;
struct nexthop_group nhop_group;
struct nexthop_group backup_nhop_group;
#include "sharp_zebra.h"
#include "sharp_vty.h"
#include "sharp_globals.h"
+#include "sharp_nht.h"
DEFINE_MGROUP(SHARPD, "sharpd")
sharp_global_init();
- nexthop_group_init(NULL, NULL, NULL, NULL);
+ sharp_nhgroup_init();
vrf_init(NULL, NULL, NULL, NULL, NULL);
sharp_zebra_init();
#include "nexthop.h"
#include "nexthop_group.h"
#include "vty.h"
+#include "typesafe.h"
+#include "zclient.h"
#include "sharp_nht.h"
#include "sharp_globals.h"
+#include "sharp_zebra.h"
DEFINE_MTYPE_STATIC(SHARPD, NH_TRACKER, "Nexthop Tracker")
+DEFINE_MTYPE_STATIC(SHARPD, NHG, "Nexthop Group")
struct sharp_nh_tracker *sharp_nh_tracker_get(struct prefix *p)
{
nht->updates);
}
}
+
+PREDECL_RBTREE_UNIQ(sharp_nhg_rb);
+
+struct sharp_nhg {
+ struct sharp_nhg_rb_item mylistitem;
+
+ uint32_t id;
+
+ char name[256];
+};
+
+static uint32_t nhg_id;
+
+static uint32_t sharp_get_next_nhid(void)
+{
+ zlog_debug("Id assigned: %u", nhg_id + 1);
+ return nhg_id++;
+}
+
+struct sharp_nhg_rb_head nhg_head;
+
+static int sharp_nhg_compare_func(const struct sharp_nhg *a,
+ const struct sharp_nhg *b)
+{
+ return strncmp(a->name, b->name, strlen(a->name));
+}
+
+DECLARE_RBTREE_UNIQ(sharp_nhg_rb, struct sharp_nhg, mylistitem,
+ sharp_nhg_compare_func);
+
+static void sharp_nhgroup_add_cb(const char *name)
+{
+ struct sharp_nhg *snhg;
+
+ snhg = XCALLOC(MTYPE_NHG, sizeof(*snhg));
+ snhg->id = sharp_get_next_nhid();
+ strncpy(snhg->name, name, sizeof(snhg->name));
+
+ sharp_nhg_rb_add(&nhg_head, snhg);
+ return;
+}
+
+static void sharp_nhgroup_add_nexthop_cb(const struct nexthop_group_cmd *nhgc,
+ const struct nexthop *nhop)
+{
+ struct sharp_nhg lookup;
+ struct sharp_nhg *snhg;
+
+ strncpy(lookup.name, nhgc->name, sizeof(lookup.name));
+ snhg = sharp_nhg_rb_find(&nhg_head, &lookup);
+
+ nhg_add(snhg->id, &nhgc->nhg);
+ return;
+}
+
+static void sharp_nhgroup_del_nexthop_cb(const struct nexthop_group_cmd *nhgc,
+ const struct nexthop *nhop)
+{
+ struct sharp_nhg lookup;
+ struct sharp_nhg *snhg;
+
+ strncpy(lookup.name, nhgc->name, sizeof(lookup.name));
+ snhg = sharp_nhg_rb_find(&nhg_head, &lookup);
+
+ nhg_add(snhg->id, &nhgc->nhg);
+ return;
+}
+
+static void sharp_nhgroup_delete_cb(const char *name)
+{
+ struct sharp_nhg lookup;
+ struct sharp_nhg *snhg;
+
+ strncpy(lookup.name, name, sizeof(lookup.name));
+ snhg = sharp_nhg_rb_find(&nhg_head, &lookup);
+ if (!snhg)
+ return;
+
+ nhg_del(snhg->id);
+ sharp_nhg_rb_del(&nhg_head, snhg);
+ XFREE(MTYPE_NHG, snhg);
+ return;
+}
+
+uint32_t sharp_nhgroup_get_id(const char *name)
+{
+ struct sharp_nhg lookup;
+ struct sharp_nhg *snhg;
+
+ strncpy(lookup.name, name, sizeof(lookup.name));
+ snhg = sharp_nhg_rb_find(&nhg_head, &lookup);
+ if (!snhg)
+ return 0;
+
+ return snhg->id;
+}
+
+void sharp_nhgroup_init(void)
+{
+ sharp_nhg_rb_init(&nhg_head);
+ nhg_id = zclient_get_nhg_start(ZEBRA_ROUTE_SHARP);
+
+ nexthop_group_init(sharp_nhgroup_add_cb, sharp_nhgroup_add_nexthop_cb,
+ sharp_nhgroup_del_nexthop_cb,
+ sharp_nhgroup_delete_cb);
+}
extern struct sharp_nh_tracker *sharp_nh_tracker_get(struct prefix *p);
extern void sharp_nh_tracker_dump(struct vty *vty);
+
+extern uint32_t sharp_nhgroup_get_id(const char *name);
+extern void sharp_nhgroup_init(void);
#endif
struct vrf *vrf;
struct prefix prefix;
uint32_t rts;
+ uint32_t nhgid = 0;
sg.r.total_routes = routes;
sg.r.installed_routes = 0;
return CMD_WARNING;
}
+ nhgid = sharp_nhgroup_get_id(nexthop_group);
+ sg.r.nhgid = nhgid;
sg.r.nhop_group.nexthop = nhgc->nhg.nexthop;
/* Use group's backup nexthop info if present */
sg.r.vrf_id = vrf->vrf_id;
rts = routes;
sharp_install_routes_helper(&prefix, sg.r.vrf_id, sg.r.inst,
- &sg.r.nhop_group, &sg.r.backup_nhop_group,
- rts);
+ nhgid, &sg.r.nhop_group,
+ &sg.r.backup_nhop_group, rts);
return CMD_SUCCESS;
}
}
void sharp_install_routes_helper(struct prefix *p, vrf_id_t vrf_id,
- uint8_t instance,
+ uint8_t instance, uint32_t nhgid,
const struct nexthop_group *nhg,
const struct nexthop_group *backup_nhg,
uint32_t routes)
monotime(&sg.r.t_start);
for (i = 0; i < routes; i++) {
- route_add(p, vrf_id, (uint8_t)instance, nhg, backup_nhg);
+ route_add(p, vrf_id, (uint8_t)instance, nhgid, nhg, backup_nhg);
if (v4)
p->u.prefix4.s_addr = htonl(++temp);
else
if (!installed) {
sg.r.installed_routes = 0;
sharp_install_routes_helper(&p, sg.r.vrf_id, sg.r.inst,
+ sg.r.nhgid,
&sg.r.nhop_group,
&sg.r.backup_nhop_group,
sg.r.total_routes);
zclient_send_vrf_label(zclient, vrf_id, afi, label, ZEBRA_LSP_SHARP);
}
+void nhg_add(uint32_t id, const struct nexthop_group *nhg)
+{
+ struct zapi_nexthop nh_array[MULTIPATH_NUM];
+ struct zapi_nexthop *api_nh;
+ uint16_t nexthop_num = 0;
+ struct nexthop *nh;
+
+ for (ALL_NEXTHOPS_PTR(nhg, nh)) {
+ api_nh = &nh_array[nexthop_num];
+
+ zapi_nexthop_from_nexthop(api_nh, nh);
+ nexthop_num++;
+ }
+
+ zclient_nhg_add(zclient, id, nexthop_num, nh_array);
+
+ zclient_send_message(zclient);
+}
+
+void nhg_del(uint32_t id)
+{
+ zclient_nhg_del(zclient, id);
+ zclient_send_message(zclient);
+}
+
void route_add(const struct prefix *p, vrf_id_t vrf_id,
- uint8_t instance, const struct nexthop_group *nhg,
+ uint8_t instance, uint32_t nhgid,
+ const struct nexthop_group *nhg,
const struct nexthop_group *backup_nhg)
{
struct zapi_route api;
SET_FLAG(api.flags, ZEBRA_FLAG_ALLOW_RECURSION);
SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP);
- for (ALL_NEXTHOPS_PTR(nhg, nh)) {
- api_nh = &api.nexthops[i];
+ if (nhgid) {
+ SET_FLAG(api.message, ZAPI_MESSAGE_NHG);
+ api.nhgid = nhgid;
+ } else {
+ for (ALL_NEXTHOPS_PTR(nhg, nh)) {
+ api_nh = &api.nexthops[i];
- zapi_nexthop_from_nexthop(api_nh, nh);
+ zapi_nexthop_from_nexthop(api_nh, nh);
- i++;
+ i++;
+ }
+ api.nexthop_num = i;
}
- api.nexthop_num = i;
/* Include backup nexthops, if present */
if (backup_nhg && backup_nhg->nexthop) {
int sharp_zclient_delete(uint32_t session_id);
extern void vrf_label_add(vrf_id_t vrf_id, afi_t afi, mpls_label_t label);
+extern void nhg_add(uint32_t id, const struct nexthop_group *nhg);
+extern void nhg_del(uint32_t id);
extern void route_add(const struct prefix *p, vrf_id_t, uint8_t instance,
- const struct nexthop_group *nhg,
+ uint32_t nhgid, const struct nexthop_group *nhg,
const struct nexthop_group *backup_nhg);
extern void route_delete(struct prefix *p, vrf_id_t vrf_id, uint8_t instance);
extern void sharp_zebra_nexthop_watch(struct prefix *p, vrf_id_t vrf_id,
bool import, bool watch, bool connected);
extern void sharp_install_routes_helper(struct prefix *p, vrf_id_t vrf_id,
- uint8_t instance,
+ uint8_t instance, uint32_t nhgid,
const struct nexthop_group *nhg,
const struct nexthop_group *backup_nhg,
uint32_t routes);