forked from Mirror/frr
sharpd: Add code to allow install/uninstall repeatedly
Add a bit of test code to allow the tester to install/uninstall the routes via: sharp install routes A.B.C.D nexthop Y.Z.M.D 1000000 repeat 100 This will install 1000000 routes wait for them to be finished then uninstall them then start installation over 100 times. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com.
This commit is contained in:
parent
6b98d34fdf
commit
b939f6ff51
|
@ -40,6 +40,14 @@ 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",
|
||||
"Sharp routing Protocol\n"
|
||||
|
@ -80,11 +88,9 @@ DEFPY(watch_nexthop_v4, watch_nexthop_v4_cmd,
|
|||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
DEFPY (install_routes,
|
||||
install_routes_cmd,
|
||||
"sharp install routes A.B.C.D$start <nexthop <A.B.C.D$nexthop4|X:X::X:X$nexthop6>|nexthop-group NAME$nexthop_group> (1-1000000)$routes [instance (0-255)$instance]",
|
||||
"sharp install routes A.B.C.D$start <nexthop <A.B.C.D$nexthop4|X:X::X:X$nexthop6>|nexthop-group NAME$nexthop_group> (1-1000000)$routes [instance (0-255)$instance] [repeat (2-1000)$rpt]",
|
||||
"Sharp routing Protocol\n"
|
||||
"install some routes\n"
|
||||
"Routes to install\n"
|
||||
|
@ -96,22 +102,27 @@ DEFPY (install_routes,
|
|||
"The Name of the nexthop-group\n"
|
||||
"How many to create\n"
|
||||
"Instance to use\n"
|
||||
"Instance\n")
|
||||
"Instance\n"
|
||||
"Should we repeat this command\n"
|
||||
"How many times to repeat this command\n")
|
||||
{
|
||||
struct prefix p;
|
||||
struct nexthop nhop;
|
||||
struct nexthop_group nhg;
|
||||
|
||||
total_routes = routes;
|
||||
installed_routes = 0;
|
||||
|
||||
memset(&p, 0, sizeof(p));
|
||||
memset(&nhop, 0, sizeof(nhop));
|
||||
memset(&nhg, 0, sizeof(nhg));
|
||||
if (rpt >= 2)
|
||||
repeat = rpt * 2;
|
||||
else
|
||||
repeat = 0;
|
||||
|
||||
p.family = AF_INET;
|
||||
p.prefixlen = 32;
|
||||
p.u.prefix4 = start;
|
||||
memset(&prefix, 0, sizeof(prefix));
|
||||
memset(&orig_prefix, 0, sizeof(orig_prefix));
|
||||
memset(&nhop, 0, sizeof(nhop));
|
||||
memset(&nhop_group, 0, sizeof(nhop_group));
|
||||
|
||||
prefix.family = AF_INET;
|
||||
prefix.prefixlen = 32;
|
||||
prefix.u.prefix4 = start;
|
||||
orig_prefix = prefix;
|
||||
|
||||
if (nexthop_group) {
|
||||
struct nexthop_group_cmd *nhgc = nhgc_find(nexthop_group);
|
||||
|
@ -122,7 +133,7 @@ DEFPY (install_routes,
|
|||
return CMD_WARNING;
|
||||
}
|
||||
|
||||
nhg.nexthop = nhgc->nhg.nexthop;
|
||||
nhop_group.nexthop = nhgc->nhg.nexthop;
|
||||
} else {
|
||||
if (nexthop4.s_addr != INADDR_ANY) {
|
||||
nhop.gate.ipv4 = nexthop4;
|
||||
|
@ -132,10 +143,12 @@ DEFPY (install_routes,
|
|||
nhop.type = NEXTHOP_TYPE_IPV6;
|
||||
}
|
||||
|
||||
nhg.nexthop = &nhop;
|
||||
nhop_group.nexthop = &nhop;
|
||||
}
|
||||
|
||||
sharp_install_routes_helper(&p, instance, &nhg, routes);
|
||||
inst = instance;
|
||||
rts = routes;
|
||||
sharp_install_routes_helper(&prefix, inst, &nhop_group, rts);
|
||||
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
@ -181,17 +194,18 @@ DEFPY (remove_routes,
|
|||
"instance to use\n"
|
||||
"Value of instance\n")
|
||||
{
|
||||
struct prefix p;
|
||||
total_routes = routes;
|
||||
removed_routes = 0;
|
||||
|
||||
memset(&p, 0, sizeof(p));
|
||||
memset(&prefix, 0, sizeof(prefix));
|
||||
|
||||
p.family = AF_INET;
|
||||
p.prefixlen = 32;
|
||||
p.u.prefix4 = start;
|
||||
prefix.family = AF_INET;
|
||||
prefix.prefixlen = 32;
|
||||
prefix.u.prefix4 = start;
|
||||
|
||||
sharp_remove_routes_helper(&p, instance, routes);
|
||||
inst = instance;
|
||||
rts = routes;
|
||||
sharp_remove_routes_helper(&prefix, inst, rts);
|
||||
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -132,6 +132,10 @@ static int interface_state_down(int command, struct zclient *zclient,
|
|||
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,
|
||||
|
@ -162,8 +166,9 @@ void sharp_remove_routes_helper(struct prefix *p, uint8_t instance,
|
|||
}
|
||||
}
|
||||
|
||||
static int handle_repeated(bool installed)
|
||||
static void handle_repeated(bool installed)
|
||||
{
|
||||
struct prefix p = orig_prefix;
|
||||
repeat--;
|
||||
|
||||
if (repeat <= 0)
|
||||
|
@ -171,12 +176,13 @@ static int handle_repeated(bool installed)
|
|||
|
||||
if (installed) {
|
||||
removed_routes = 0;
|
||||
sharp_remove_routes_helper(&prefix, inst, total_routes);
|
||||
sharp_remove_routes_helper(&p, inst, total_routes);
|
||||
}
|
||||
|
||||
if (!installed) {
|
||||
installed_routes = 0;
|
||||
sharp_remove_routes
|
||||
sharp_install_routes_helper(&p, inst, &nhop_group,
|
||||
total_routes);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue