diff options
Diffstat (limited to 'sharpd/sharp_vty.c')
| -rw-r--r-- | sharpd/sharp_vty.c | 117 |
1 files changed, 75 insertions, 42 deletions
diff --git a/sharpd/sharp_vty.c b/sharpd/sharp_vty.c index 797e336c2d..86c8bfe1c2 100644 --- a/sharpd/sharp_vty.c +++ b/sharpd/sharp_vty.c @@ -28,6 +28,7 @@ #include "log.h" #include "vrf.h" #include "zclient.h" +#include "nexthop_group.h" #include "sharpd/sharp_zebra.h" #include "sharpd/sharp_vty.h" @@ -39,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" @@ -81,49 +90,73 @@ 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> (1-1000000)$routes [instance (0-255)$instance]", + "sharp install routes <A.B.C.D$start4|X:X::X:X$start6> <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" - "Address to start /32 generation at\n" + "v4 Address to start /32 generation at\n" + "v6 Address to start /32 generation at\n" "Nexthop to use(Can be an IPv4 or IPv6 address)\n" "V4 Nexthop address to use\n" "V6 Nexthop address to use\n" + "Nexthop-Group to use\n" + "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; - uint32_t temp; - total_routes = routes; installed_routes = 0; - memset(&p, 0, sizeof(p)); - memset(&nhop, 0, sizeof(nhop)); + 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)); - if (nexthop4.s_addr != INADDR_ANY) { - nhop.gate.ipv4 = nexthop4; - nhop.type = NEXTHOP_TYPE_IPV4; + if (start4.s_addr != 0) { + prefix.family = AF_INET; + prefix.prefixlen = 32; + prefix.u.prefix4 = start4; } else { - memcpy(&nhop.gate.ipv6, &nexthop6, IPV6_MAX_BYTELEN); - nhop.type = NEXTHOP_TYPE_IPV6; + prefix.family = AF_INET6; + prefix.prefixlen = 128; + prefix.u.prefix6 = start6; } - - 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, &nhop); - p.u.prefix4.s_addr = htonl(++temp); + orig_prefix = prefix; + + if (nexthop_group) { + struct nexthop_group_cmd *nhgc = nhgc_find(nexthop_group); + if (!nhgc) { + vty_out(vty, + "Specified Nexthop Group: %s does not exist\n", + nexthop_group); + return CMD_WARNING; + } + + nhop_group.nexthop = nhgc->nhg.nexthop; + } else { + if (nexthop4.s_addr != INADDR_ANY) { + nhop.gate.ipv4 = nexthop4; + nhop.type = NEXTHOP_TYPE_IPV4; + } else { + nhop.gate.ipv6 = nexthop6; + nhop.type = NEXTHOP_TYPE_IPV6; + } + + nhop_group.nexthop = &nhop; } + inst = instance; + rts = routes; + sharp_install_routes_helper(&prefix, inst, &nhop_group, rts); + return CMD_SUCCESS; } @@ -159,35 +192,35 @@ DEFPY(vrf_label, vrf_label_cmd, DEFPY (remove_routes, remove_routes_cmd, - "sharp remove routes A.B.C.D$start (1-1000000)$routes [instance (0-255)$instance]", + "sharp remove routes <A.B.C.D$start4|X:X::X:X$start6> (1-1000000)$routes [instance (0-255)$instance]", "Sharp Routing Protocol\n" "Remove some routes\n" "Routes to remove\n" - "Starting spot\n" - "Routes to uniinstall\n" + "v4 Starting spot\n" + "v6 Starting spot\n" + "Routes to uninstall\n" "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)); - - p.family = AF_INET; - p.prefixlen = 32; - p.u.prefix4 = start; - - zlog_debug("Removing %ld routes", routes); + memset(&prefix, 0, sizeof(prefix)); - 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); + if (start4.s_addr != 0) { + prefix.family = AF_INET; + prefix.prefixlen = 32; + prefix.u.prefix4 = start4; + } else { + prefix.family = AF_INET6; + prefix.prefixlen = 128; + prefix.u.prefix6 = start6; } + inst = instance; + rts = routes; + sharp_remove_routes_helper(&prefix, inst, rts); + return CMD_SUCCESS; } |
