]> git.proxmox.com Git - mirror_frr.git/blob - sharpd/sharp_vty.c
*: make clippy usage more consistent
[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 #ifndef VTYSH_EXTRACT_PL
33 #include "sharpd/sharp_vty_clippy.c"
34 #endif
35
36 extern uint32_t total_routes;
37 extern uint32_t installed_routes;
38 extern uint32_t removed_routes;
39
40 DEFPY (install_routes,
41 install_routes_cmd,
42 "install routes A.B.C.D$start nexthop A.B.C.D$nexthop (1-1000000)$routes",
43 "install some routes\n"
44 "Routes to install\n"
45 "Address to start /32 generation at\n"
46 "Nexthop to use\n"
47 "Nexthop address\n"
48 "How many to create\n")
49 {
50 int i;
51 struct prefix p;
52 struct nexthop nhop;
53 uint32_t temp;
54
55 total_routes = routes;
56 installed_routes = 0;
57
58 memset(&p, 0, sizeof(p));
59 memset(&nhop, 0, sizeof(nhop));
60
61 p.family = AF_INET;
62 p.prefixlen = 32;
63 p.u.prefix4 = start;
64
65 nhop.gate.ipv4 = nexthop;
66 nhop.type = NEXTHOP_TYPE_IPV4;
67
68 zlog_debug("Inserting %ld routes", routes);
69
70 temp = ntohl(p.u.prefix4.s_addr);
71 for (i = 0 ; i < routes ; i++) {
72 route_add(&p, &nhop);
73 p.u.prefix4.s_addr = htonl(++temp);
74 }
75
76 return CMD_SUCCESS;
77 }
78
79 DEFPY (remove_routes,
80 remove_routes_cmd,
81 "remove routes A.B.C.D$start (1-1000000)$routes",
82 "Remove some routes\n"
83 "Routes to remove\n"
84 "Starting spot\n"
85 "Routes to uniinstall\n")
86 {
87 int i;
88 struct prefix p;
89 uint32_t temp;
90
91 total_routes = routes;
92 removed_routes = 0;
93
94 memset(&p, 0, sizeof(p));
95
96 p.family = AF_INET;
97 p.prefixlen = 32;
98 p.u.prefix4 = start;
99
100 zlog_debug("Removing %ld routes", routes);
101
102 temp = ntohl(p.u.prefix4.s_addr);
103 for (i = 0; i < routes ; i++) {
104 route_delete(&p);
105 p.u.prefix4.s_addr = htonl(++temp);
106 }
107
108 return CMD_SUCCESS;
109 }
110
111 void sharp_vty_init(void)
112 {
113 install_element(ENABLE_NODE, &install_routes_cmd);
114 install_element(ENABLE_NODE, &remove_routes_cmd);
115 return;
116 }