diff options
Diffstat (limited to 'sharpd/sharp_vty.c')
| -rw-r--r-- | sharpd/sharp_vty.c | 97 |
1 files changed, 58 insertions, 39 deletions
diff --git a/sharpd/sharp_vty.c b/sharpd/sharp_vty.c index 797e336c2d..d0a34c0f93 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,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> (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" @@ -89,40 +98,57 @@ DEFPY (install_routes, "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)); - - p.family = AF_INET; - p.prefixlen = 32; - p.u.prefix4 = start; + if (rpt >= 2) + repeat = rpt * 2; + else + repeat = 0; - if (nexthop4.s_addr != INADDR_ANY) { - nhop.gate.ipv4 = nexthop4; - nhop.type = NEXTHOP_TYPE_IPV4; + 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); + 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 { - memcpy(&nhop.gate.ipv6, &nexthop6, IPV6_MAX_BYTELEN); - nhop.type = NEXTHOP_TYPE_IPV6; + 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; } - 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); - } + inst = instance; + rts = routes; + sharp_install_routes_helper(&prefix, inst, &nhop_group, rts); return CMD_SUCCESS; } @@ -168,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; + prefix.family = AF_INET; + prefix.prefixlen = 32; + prefix.u.prefix4 = start; - zlog_debug("Removing %ld routes", routes); - - 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; } |
