summaryrefslogtreecommitdiff
path: root/sharpd/sharp_vty.c
diff options
context:
space:
mode:
Diffstat (limited to 'sharpd/sharp_vty.c')
-rw-r--r--sharpd/sharp_vty.c71
1 files changed, 36 insertions, 35 deletions
diff --git a/sharpd/sharp_vty.c b/sharpd/sharp_vty.c
index 3aed8eb123..d0a34c0f93 100644
--- a/sharpd/sharp_vty.c
+++ b/sharpd/sharp_vty.c
@@ -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"
@@ -82,7 +90,7 @@ DEFPY(watch_nexthop_v4, watch_nexthop_v4_cmd,
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"
@@ -94,24 +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")
{
- int i;
- struct prefix p;
- struct nexthop nhop;
- struct nexthop_group nhg;
- uint32_t temp;
-
total_routes = routes;
installed_routes = 0;
- memset(&p, 0, sizeof(p));
+ if (rpt >= 2)
+ repeat = rpt * 2;
+ else
+ repeat = 0;
+
+ memset(&prefix, 0, sizeof(prefix));
+ memset(&orig_prefix, 0, sizeof(orig_prefix));
memset(&nhop, 0, sizeof(nhop));
- memset(&nhg, 0, sizeof(nhg));
+ memset(&nhop_group, 0, sizeof(nhop_group));
- p.family = AF_INET;
- p.prefixlen = 32;
- p.u.prefix4 = start;
+ 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,15 +143,12 @@ DEFPY (install_routes,
nhop.type = NEXTHOP_TYPE_IPV6;
}
- nhg.nexthop = &nhop;
+ nhop_group.nexthop = &nhop;
}
- zlog_debug("Inserting %ld routes", routes);
- temp = ntohl(p.u.prefix4.s_addr);
- for (i = 0; i < routes; i++) {
- route_add(&p, (uint8_t)instance, &nhg);
- p.u.prefix4.s_addr = htonl(++temp);
- }
+ inst = instance;
+ rts = routes;
+ sharp_install_routes_helper(&prefix, inst, &nhop_group, rts);
return CMD_SUCCESS;
}
@@ -186,25 +194,18 @@ DEFPY (remove_routes,
"instance to use\n"
"Value of instance\n")
{
- int i;
- struct prefix p;
- uint32_t temp;
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;
-
- zlog_debug("Removing %ld routes", routes);
+ prefix.family = AF_INET;
+ prefix.prefixlen = 32;
+ prefix.u.prefix4 = start;
- temp = ntohl(p.u.prefix4.s_addr);
- for (i = 0; i < routes; i++) {
- route_delete(&p, (uint8_t)instance);
- p.u.prefix4.s_addr = htonl(++temp);
- }
+ inst = instance;
+ rts = routes;
+ sharp_remove_routes_helper(&prefix, inst, rts);
return CMD_SUCCESS;
}