]> git.proxmox.com Git - mirror_frr.git/blob - sharpd/sharp_vty.c
sharpd: Add code to allow install/uninstall repeatedly
[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 #include "vrf.h"
30 #include "zclient.h"
31 #include "nexthop_group.h"
32
33 #include "sharpd/sharp_zebra.h"
34 #include "sharpd/sharp_vty.h"
35 #ifndef VTYSH_EXTRACT_PL
36 #include "sharpd/sharp_vty_clippy.c"
37 #endif
38
39 extern uint32_t total_routes;
40 extern uint32_t installed_routes;
41 extern uint32_t removed_routes;
42
43 uint8_t inst;
44 struct prefix prefix;
45 struct prefix orig_prefix;
46 struct nexthop nhop;
47 struct nexthop_group nhop_group;
48 uint32_t rts;
49 int32_t repeat;
50
51 DEFPY(watch_nexthop_v6, watch_nexthop_v6_cmd,
52 "sharp watch nexthop X:X::X:X$nhop",
53 "Sharp routing Protocol\n"
54 "Watch for changes\n"
55 "Watch for nexthop changes\n"
56 "The v6 nexthop to signal for watching\n")
57 {
58 struct prefix p;
59
60 memset(&p, 0, sizeof(p));
61
62 p.prefixlen = 128;
63 memcpy(&p.u.prefix6, &nhop, 16);
64 p.family = AF_INET6;
65
66 sharp_zebra_nexthop_watch(&p, true);
67
68 return CMD_SUCCESS;
69 }
70
71 DEFPY(watch_nexthop_v4, watch_nexthop_v4_cmd,
72 "sharp watch nexthop A.B.C.D$nhop",
73 "Sharp routing Protocol\n"
74 "Watch for changes\n"
75 "Watch for nexthop changes\n"
76 "The v4 nexthop to signal for watching\n")
77 {
78 struct prefix p;
79
80 memset(&p, 0, sizeof(p));
81
82 p.prefixlen = 32;
83 p.u.prefix4 = nhop;
84 p.family = AF_INET;
85
86 sharp_zebra_nexthop_watch(&p, true);
87
88 return CMD_SUCCESS;
89 }
90
91 DEFPY (install_routes,
92 install_routes_cmd,
93 "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]",
94 "Sharp routing Protocol\n"
95 "install some routes\n"
96 "Routes to install\n"
97 "Address to start /32 generation at\n"
98 "Nexthop to use(Can be an IPv4 or IPv6 address)\n"
99 "V4 Nexthop address to use\n"
100 "V6 Nexthop address to use\n"
101 "Nexthop-Group to use\n"
102 "The Name of the nexthop-group\n"
103 "How many to create\n"
104 "Instance to use\n"
105 "Instance\n"
106 "Should we repeat this command\n"
107 "How many times to repeat this command\n")
108 {
109 total_routes = routes;
110 installed_routes = 0;
111
112 if (rpt >= 2)
113 repeat = rpt * 2;
114 else
115 repeat = 0;
116
117 memset(&prefix, 0, sizeof(prefix));
118 memset(&orig_prefix, 0, sizeof(orig_prefix));
119 memset(&nhop, 0, sizeof(nhop));
120 memset(&nhop_group, 0, sizeof(nhop_group));
121
122 prefix.family = AF_INET;
123 prefix.prefixlen = 32;
124 prefix.u.prefix4 = start;
125 orig_prefix = prefix;
126
127 if (nexthop_group) {
128 struct nexthop_group_cmd *nhgc = nhgc_find(nexthop_group);
129 if (!nhgc) {
130 vty_out(vty,
131 "Specified Nexthop Group: %s does not exist\n",
132 nexthop_group);
133 return CMD_WARNING;
134 }
135
136 nhop_group.nexthop = nhgc->nhg.nexthop;
137 } else {
138 if (nexthop4.s_addr != INADDR_ANY) {
139 nhop.gate.ipv4 = nexthop4;
140 nhop.type = NEXTHOP_TYPE_IPV4;
141 } else {
142 nhop.gate.ipv6 = nexthop6;
143 nhop.type = NEXTHOP_TYPE_IPV6;
144 }
145
146 nhop_group.nexthop = &nhop;
147 }
148
149 inst = instance;
150 rts = routes;
151 sharp_install_routes_helper(&prefix, inst, &nhop_group, rts);
152
153 return CMD_SUCCESS;
154 }
155
156 DEFPY(vrf_label, vrf_label_cmd,
157 "sharp label <ip$ipv4|ipv6$ipv6> vrf NAME$name label (0-100000)$label",
158 "Sharp Routing Protocol\n"
159 "Give a vrf a label\n"
160 "Pop and forward for IPv4\n"
161 "Pop and forward for IPv6\n"
162 VRF_CMD_HELP_STR
163 "The label to use, 0 specifies remove the label installed from previous\n"
164 "Specified range to use\n")
165 {
166 struct vrf *vrf;
167 afi_t afi = (ipv4) ? AFI_IP : AFI_IP6;
168
169 if (strcmp(name, "default") == 0)
170 vrf = vrf_lookup_by_id(VRF_DEFAULT);
171 else
172 vrf = vrf_lookup_by_name(name);
173
174 if (!vrf) {
175 vty_out(vty, "Unable to find vrf you silly head");
176 return CMD_WARNING_CONFIG_FAILED;
177 }
178
179 if (label == 0)
180 label = MPLS_LABEL_NONE;
181
182 vrf_label_add(vrf->vrf_id, afi, label);
183 return CMD_SUCCESS;
184 }
185
186 DEFPY (remove_routes,
187 remove_routes_cmd,
188 "sharp remove routes A.B.C.D$start (1-1000000)$routes [instance (0-255)$instance]",
189 "Sharp Routing Protocol\n"
190 "Remove some routes\n"
191 "Routes to remove\n"
192 "Starting spot\n"
193 "Routes to uniinstall\n"
194 "instance to use\n"
195 "Value of instance\n")
196 {
197 total_routes = routes;
198 removed_routes = 0;
199
200 memset(&prefix, 0, sizeof(prefix));
201
202 prefix.family = AF_INET;
203 prefix.prefixlen = 32;
204 prefix.u.prefix4 = start;
205
206 inst = instance;
207 rts = routes;
208 sharp_remove_routes_helper(&prefix, inst, rts);
209
210 return CMD_SUCCESS;
211 }
212
213 DEFUN_NOSH (show_debugging_sharpd,
214 show_debugging_sharpd_cmd,
215 "show debugging [sharp]",
216 SHOW_STR
217 DEBUG_STR
218 "Sharp Information\n")
219 {
220 vty_out(vty, "Sharp debugging status\n");
221
222 return CMD_SUCCESS;
223 }
224
225 void sharp_vty_init(void)
226 {
227 install_element(ENABLE_NODE, &install_routes_cmd);
228 install_element(ENABLE_NODE, &remove_routes_cmd);
229 install_element(ENABLE_NODE, &vrf_label_cmd);
230 install_element(ENABLE_NODE, &watch_nexthop_v6_cmd);
231 install_element(ENABLE_NODE, &watch_nexthop_v4_cmd);
232
233 install_element(VIEW_NODE, &show_debugging_sharpd_cmd);
234
235 return;
236 }