]> git.proxmox.com Git - mirror_frr.git/blob - sharpd/sharp_vty.c
Merge pull request #1464 from chiragshah6/mdev
[mirror_frr.git] / sharpd / sharp_vty.c
1 /*
2 * SHARP - vty code
3 * Copyright (C) Cumulus Networks, Inc.
4 * Donald Sharp
5 *
6 * This file is part of FRR.
7 *
8 * FRR is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
11 * later version.
12 *
13 * FRR is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; see the file COPYING; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22 #include <zebra.h>
23
24 #include "vty.h"
25 #include "command.h"
26 #include "prefix.h"
27 #include "nexthop.h"
28 #include "log.h"
29
30 #include "sharpd/sharp_zebra.h"
31 #include "sharpd/sharp_vty.h"
32 #include "sharpd/sharp_vty_clippy.c"
33
34 extern uint32_t total_routes;
35 extern uint32_t installed_routes;
36 extern uint32_t removed_routes;
37
38 DEFPY (install_routes,
39 install_routes_cmd,
40 "install routes A.B.C.D$start nexthop A.B.C.D$nexthop (1-1000000)$routes",
41 "install some routes\n"
42 "Routes to install\n"
43 "Address to start /32 generation at\n"
44 "Nexthop to use\n"
45 "Nexthop address\n"
46 "How many to create\n")
47 {
48 int i;
49 struct prefix p;
50 struct nexthop nhop;
51 uint32_t temp;
52
53 total_routes = routes;
54 installed_routes = 0;
55
56 memset(&p, 0, sizeof(p));
57 memset(&nhop, 0, sizeof(nhop));
58
59 p.family = AF_INET;
60 p.prefixlen = 32;
61 p.u.prefix4 = start;
62
63 nhop.gate.ipv4 = nexthop;
64 nhop.type = NEXTHOP_TYPE_IPV4;
65
66 zlog_debug("Inserting %ld routes", routes);
67
68 temp = ntohl(p.u.prefix4.s_addr);
69 for (i = 0 ; i < routes ; i++) {
70 route_add(&p, &nhop);
71 p.u.prefix4.s_addr = htonl(++temp);
72 }
73
74 return CMD_SUCCESS;
75 }
76
77 DEFPY (remove_routes,
78 remove_routes_cmd,
79 "remove routes A.B.C.D$start (1-1000000)$routes",
80 "Remove some routes\n"
81 "Routes to remove\n"
82 "Starting spot\n"
83 "Routes to uniinstall\n")
84 {
85 int i;
86 struct prefix p;
87 uint32_t temp;
88
89 total_routes = routes;
90 removed_routes = 0;
91
92 memset(&p, 0, sizeof(p));
93
94 p.family = AF_INET;
95 p.prefixlen = 32;
96 p.u.prefix4 = start;
97
98 zlog_debug("Removing %ld routes", routes);
99
100 temp = ntohl(p.u.prefix4.s_addr);
101 for (i = 0; i < routes ; i++) {
102 route_delete(&p);
103 p.u.prefix4.s_addr = htonl(++temp);
104 }
105
106 return CMD_SUCCESS;
107 }
108
109 void sharp_vty_init(void)
110 {
111 install_element(ENABLE_NODE, &install_routes_cmd);
112 install_element(ENABLE_NODE, &remove_routes_cmd);
113 return;
114 }