mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-13 21:10:28 +00:00
sharpd: Move route global variables into the global data structure
Clean up the route global variables into a global data structure. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
This commit is contained in:
parent
d21f1a930f
commit
547dc6429c
@ -22,7 +22,28 @@
|
||||
#ifndef __SHARP_GLOBAL_H__
|
||||
#define __SHARP_GLOBAL_H__
|
||||
|
||||
struct sharp_global {
|
||||
struct sharp_routes {
|
||||
/* The original prefix for route installation */
|
||||
struct prefix orig_prefix;
|
||||
|
||||
/* The nexthop group we are using for installation */
|
||||
struct nexthop nhop;
|
||||
struct nexthop_group nhop_group;
|
||||
|
||||
uint32_t total_routes;
|
||||
uint32_t installed_routes;
|
||||
uint32_t removed_routes;
|
||||
int32_t repeat;
|
||||
|
||||
uint8_t inst;
|
||||
|
||||
struct timeval t_start;
|
||||
struct timeval t_end;
|
||||
};
|
||||
|
||||
struct sharp_global {
|
||||
struct sharp_routes r;
|
||||
};
|
||||
|
||||
extern struct sharp_global sg;
|
||||
#endif
|
||||
|
@ -48,10 +48,6 @@
|
||||
#include "sharp_vty.h"
|
||||
#include "sharp_globals.h"
|
||||
|
||||
uint32_t total_routes = 0;
|
||||
uint32_t installed_routes = 0;
|
||||
uint32_t removed_routes = 0;
|
||||
|
||||
zebra_capabilities_t _caps_p[] = {
|
||||
};
|
||||
|
||||
|
@ -30,24 +30,13 @@
|
||||
#include "zclient.h"
|
||||
#include "nexthop_group.h"
|
||||
|
||||
#include "sharpd/sharp_globals.h"
|
||||
#include "sharpd/sharp_zebra.h"
|
||||
#include "sharpd/sharp_vty.h"
|
||||
#ifndef VTYSH_EXTRACT_PL
|
||||
#include "sharpd/sharp_vty_clippy.c"
|
||||
#endif
|
||||
|
||||
extern uint32_t total_routes;
|
||||
extern uint32_t installed_routes;
|
||||
extern uint32_t removed_routes;
|
||||
|
||||
uint8_t inst;
|
||||
struct prefix prefix;
|
||||
struct prefix orig_prefix;
|
||||
struct nexthop nhop;
|
||||
struct nexthop_group nhop_group;
|
||||
uint32_t rts;
|
||||
int32_t repeat;
|
||||
|
||||
DEFPY(watch_nexthop_v6, watch_nexthop_v6_cmd,
|
||||
"sharp watch nexthop X:X::X:X$nhop [connected$connected]",
|
||||
"Sharp routing Protocol\n"
|
||||
@ -109,18 +98,21 @@ DEFPY (install_routes,
|
||||
"Should we repeat this command\n"
|
||||
"How many times to repeat this command\n")
|
||||
{
|
||||
total_routes = routes;
|
||||
installed_routes = 0;
|
||||
struct prefix prefix;
|
||||
uint32_t rts;
|
||||
|
||||
sg.r.total_routes = routes;
|
||||
sg.r.installed_routes = 0;
|
||||
|
||||
if (rpt >= 2)
|
||||
repeat = rpt * 2;
|
||||
sg.r.repeat = rpt * 2;
|
||||
else
|
||||
repeat = 0;
|
||||
sg.r.repeat = 0;
|
||||
|
||||
memset(&prefix, 0, sizeof(prefix));
|
||||
memset(&orig_prefix, 0, sizeof(orig_prefix));
|
||||
memset(&nhop, 0, sizeof(nhop));
|
||||
memset(&nhop_group, 0, sizeof(nhop_group));
|
||||
memset(&sg.r.orig_prefix, 0, sizeof(sg.r.orig_prefix));
|
||||
memset(&sg.r.nhop, 0, sizeof(sg.r.nhop));
|
||||
memset(&sg.r.nhop_group, 0, sizeof(sg.r.nhop_group));
|
||||
|
||||
if (start4.s_addr != 0) {
|
||||
prefix.family = AF_INET;
|
||||
@ -131,7 +123,7 @@ DEFPY (install_routes,
|
||||
prefix.prefixlen = 128;
|
||||
prefix.u.prefix6 = start6;
|
||||
}
|
||||
orig_prefix = prefix;
|
||||
sg.r.orig_prefix = prefix;
|
||||
|
||||
if (nexthop_group) {
|
||||
struct nexthop_group_cmd *nhgc = nhgc_find(nexthop_group);
|
||||
@ -142,22 +134,22 @@ DEFPY (install_routes,
|
||||
return CMD_WARNING;
|
||||
}
|
||||
|
||||
nhop_group.nexthop = nhgc->nhg.nexthop;
|
||||
sg.r.nhop_group.nexthop = nhgc->nhg.nexthop;
|
||||
} else {
|
||||
if (nexthop4.s_addr != INADDR_ANY) {
|
||||
nhop.gate.ipv4 = nexthop4;
|
||||
nhop.type = NEXTHOP_TYPE_IPV4;
|
||||
sg.r.nhop.gate.ipv4 = nexthop4;
|
||||
sg.r.nhop.type = NEXTHOP_TYPE_IPV4;
|
||||
} else {
|
||||
nhop.gate.ipv6 = nexthop6;
|
||||
nhop.type = NEXTHOP_TYPE_IPV6;
|
||||
sg.r.nhop.gate.ipv6 = nexthop6;
|
||||
sg.r.nhop.type = NEXTHOP_TYPE_IPV6;
|
||||
}
|
||||
|
||||
nhop_group.nexthop = &nhop;
|
||||
sg.r.nhop_group.nexthop = &sg.r.nhop;
|
||||
}
|
||||
|
||||
inst = instance;
|
||||
sg.r.inst = instance;
|
||||
rts = routes;
|
||||
sharp_install_routes_helper(&prefix, inst, &nhop_group, rts);
|
||||
sharp_install_routes_helper(&prefix, sg.r.inst, &sg.r.nhop_group, rts);
|
||||
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
@ -204,8 +196,11 @@ DEFPY (remove_routes,
|
||||
"instance to use\n"
|
||||
"Value of instance\n")
|
||||
{
|
||||
total_routes = routes;
|
||||
removed_routes = 0;
|
||||
struct prefix prefix;
|
||||
|
||||
sg.r.total_routes = routes;
|
||||
sg.r.removed_routes = 0;
|
||||
uint32_t rts;
|
||||
|
||||
memset(&prefix, 0, sizeof(prefix));
|
||||
|
||||
@ -219,9 +214,9 @@ DEFPY (remove_routes,
|
||||
prefix.u.prefix6 = start6;
|
||||
}
|
||||
|
||||
inst = instance;
|
||||
sg.r.inst = instance;
|
||||
rts = routes;
|
||||
sharp_remove_routes_helper(&prefix, inst, rts);
|
||||
sharp_remove_routes_helper(&prefix, sg.r.inst, rts);
|
||||
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "nexthop.h"
|
||||
#include "nexthop_group.h"
|
||||
|
||||
#include "sharp_globals.h"
|
||||
#include "sharp_zebra.h"
|
||||
|
||||
/* Zebra structure to hold current status. */
|
||||
@ -129,16 +130,6 @@ static int interface_state_down(int command, struct zclient *zclient,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct timeval t_start;
|
||||
static struct timeval t_end;
|
||||
extern uint32_t total_routes;
|
||||
extern uint32_t installed_routes;
|
||||
extern uint32_t removed_routes;
|
||||
extern int32_t repeat;
|
||||
extern struct prefix orig_prefix;
|
||||
extern struct nexthop_group nhop_group;
|
||||
extern uint8_t inst;
|
||||
|
||||
void sharp_install_routes_helper(struct prefix *p, uint8_t instance,
|
||||
struct nexthop_group *nhg,
|
||||
uint32_t routes)
|
||||
@ -154,7 +145,7 @@ void sharp_install_routes_helper(struct prefix *p, uint8_t instance,
|
||||
} else
|
||||
temp = ntohl(p->u.val32[3]);
|
||||
|
||||
monotime(&t_start);
|
||||
monotime(&sg.r.t_start);
|
||||
for (i = 0; i < routes; i++) {
|
||||
route_add(p, (uint8_t)instance, nhg);
|
||||
if (v4)
|
||||
@ -178,7 +169,7 @@ void sharp_remove_routes_helper(struct prefix *p, uint8_t instance,
|
||||
} else
|
||||
temp = ntohl(p->u.val32[3]);
|
||||
|
||||
monotime(&t_start);
|
||||
monotime(&sg.r.t_start);
|
||||
for (i = 0; i < routes; i++) {
|
||||
route_delete(p, (uint8_t)instance);
|
||||
if (v4)
|
||||
@ -190,21 +181,21 @@ void sharp_remove_routes_helper(struct prefix *p, uint8_t instance,
|
||||
|
||||
static void handle_repeated(bool installed)
|
||||
{
|
||||
struct prefix p = orig_prefix;
|
||||
repeat--;
|
||||
struct prefix p = sg.r.orig_prefix;
|
||||
sg.r.repeat--;
|
||||
|
||||
if (repeat <= 0)
|
||||
if (sg.r.repeat <= 0)
|
||||
return;
|
||||
|
||||
if (installed) {
|
||||
removed_routes = 0;
|
||||
sharp_remove_routes_helper(&p, inst, total_routes);
|
||||
sg.r.removed_routes = 0;
|
||||
sharp_remove_routes_helper(&p, sg.r.inst, sg.r.total_routes);
|
||||
}
|
||||
|
||||
if (!installed) {
|
||||
installed_routes = 0;
|
||||
sharp_install_routes_helper(&p, inst, &nhop_group,
|
||||
total_routes);
|
||||
if (installed) {
|
||||
sg.r.installed_routes = 0;
|
||||
sharp_install_routes_helper(&p, sg.r.inst, &sg.r.nhop_group,
|
||||
sg.r.total_routes);
|
||||
}
|
||||
}
|
||||
|
||||
@ -221,10 +212,10 @@ static int route_notify_owner(int command, struct zclient *zclient,
|
||||
|
||||
switch (note) {
|
||||
case ZAPI_ROUTE_INSTALLED:
|
||||
installed_routes++;
|
||||
if (total_routes == installed_routes) {
|
||||
monotime(&t_end);
|
||||
timersub(&t_end, &t_start, &r);
|
||||
sg.r.installed_routes++;
|
||||
if (sg.r.total_routes == sg.r.installed_routes) {
|
||||
monotime(&sg.r.t_end);
|
||||
timersub(&sg.r.t_end, &sg.r.t_start, &r);
|
||||
zlog_debug("Installed All Items %ld.%ld", r.tv_sec,
|
||||
r.tv_usec);
|
||||
handle_repeated(true);
|
||||
@ -237,10 +228,10 @@ static int route_notify_owner(int command, struct zclient *zclient,
|
||||
zlog_debug("Better Admin Distance won over us");
|
||||
break;
|
||||
case ZAPI_ROUTE_REMOVED:
|
||||
removed_routes++;
|
||||
if (total_routes == removed_routes) {
|
||||
monotime(&t_end);
|
||||
timersub(&t_end, &t_start, &r);
|
||||
sg.r.removed_routes++;
|
||||
if (sg.r.total_routes == sg.r.removed_routes) {
|
||||
monotime(&sg.r.t_end);
|
||||
timersub(&sg.r.t_end, &sg.r.t_start, &r);
|
||||
zlog_debug("Removed all Items %ld.%ld", r.tv_sec,
|
||||
r.tv_usec);
|
||||
handle_repeated(false);
|
||||
|
Loading…
Reference in New Issue
Block a user