]>
Commit | Line | Data |
---|---|---|
8a71d93d DS |
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" | |
ab18a495 DS |
29 | #include "vrf.h" |
30 | #include "zclient.h" | |
694b242f | 31 | #include "nexthop_group.h" |
8a71d93d | 32 | |
547dc642 | 33 | #include "sharpd/sharp_globals.h" |
8a71d93d | 34 | #include "sharpd/sharp_zebra.h" |
86da53ab | 35 | #include "sharpd/sharp_nht.h" |
8a71d93d | 36 | #include "sharpd/sharp_vty.h" |
2e4c2296 | 37 | #ifndef VTYSH_EXTRACT_PL |
8a71d93d | 38 | #include "sharpd/sharp_vty_clippy.c" |
2e4c2296 | 39 | #endif |
8a71d93d | 40 | |
0ae8130d | 41 | DEFPY(watch_nexthop_v6, watch_nexthop_v6_cmd, |
e429a2a0 | 42 | "sharp watch [vrf NAME$vrf_name] <nexthop$n X:X::X:X$nhop|import$import X:X::X:X/M$inhop> [connected$connected]", |
0ae8130d DS |
43 | "Sharp routing Protocol\n" |
44 | "Watch for changes\n" | |
a3b6aa82 DS |
45 | "The vrf we would like to watch if non-default\n" |
46 | "The NAME of the vrf\n" | |
0ae8130d | 47 | "Watch for nexthop changes\n" |
a60ffbc9 | 48 | "The v6 nexthop to signal for watching\n" |
1be0815d DS |
49 | "Watch for import check changes\n" |
50 | "The v6 prefix to signal for watching\n" | |
a60ffbc9 | 51 | "Should the route be connected\n") |
0ae8130d | 52 | { |
a3b6aa82 | 53 | struct vrf *vrf; |
0ae8130d | 54 | struct prefix p; |
80d5ff33 DS |
55 | bool type_import; |
56 | ||
e429a2a0 IR |
57 | if (!vrf_name) |
58 | vrf_name = VRF_DEFAULT_NAME; | |
59 | vrf = vrf_lookup_by_name(vrf_name); | |
a3b6aa82 DS |
60 | if (!vrf) { |
61 | vty_out(vty, "The vrf NAME specified: %s does not exist\n", | |
e429a2a0 | 62 | vrf_name); |
a3b6aa82 DS |
63 | return CMD_WARNING; |
64 | } | |
80d5ff33 | 65 | |
0ae8130d DS |
66 | memset(&p, 0, sizeof(p)); |
67 | ||
1be0815d DS |
68 | if (n) { |
69 | type_import = false; | |
70 | p.prefixlen = 128; | |
71 | memcpy(&p.u.prefix6, &nhop, 16); | |
72 | p.family = AF_INET6; | |
73 | } else { | |
74 | type_import = true; | |
75 | p = *(const struct prefix *)inhop; | |
76 | } | |
0ae8130d | 77 | |
86da53ab | 78 | sharp_nh_tracker_get(&p); |
a3b6aa82 | 79 | sharp_zebra_nexthop_watch(&p, vrf->vrf_id, type_import, |
91529dc8 | 80 | true, !!connected); |
0ae8130d DS |
81 | |
82 | return CMD_SUCCESS; | |
83 | } | |
84 | ||
85 | DEFPY(watch_nexthop_v4, watch_nexthop_v4_cmd, | |
e429a2a0 | 86 | "sharp watch [vrf NAME$vrf_name] <nexthop$n A.B.C.D$nhop|import$import A.B.C.D/M$inhop> [connected$connected]", |
0ae8130d DS |
87 | "Sharp routing Protocol\n" |
88 | "Watch for changes\n" | |
a3b6aa82 DS |
89 | "The vrf we would like to watch if non-default\n" |
90 | "The NAME of the vrf\n" | |
0ae8130d | 91 | "Watch for nexthop changes\n" |
1be0815d | 92 | "The v4 address to signal for watching\n" |
80d5ff33 | 93 | "Watch for import check changes\n" |
1be0815d | 94 | "The v4 prefix for import check to watch\n" |
a60ffbc9 | 95 | "Should the route be connected\n") |
0ae8130d | 96 | { |
a3b6aa82 | 97 | struct vrf *vrf; |
0ae8130d | 98 | struct prefix p; |
80d5ff33 | 99 | bool type_import; |
0ae8130d | 100 | |
e429a2a0 IR |
101 | if (!vrf_name) |
102 | vrf_name = VRF_DEFAULT_NAME; | |
103 | vrf = vrf_lookup_by_name(vrf_name); | |
a3b6aa82 DS |
104 | if (!vrf) { |
105 | vty_out(vty, "The vrf NAME specified: %s does not exist\n", | |
e429a2a0 | 106 | vrf_name); |
a3b6aa82 DS |
107 | return CMD_WARNING; |
108 | } | |
109 | ||
0ae8130d DS |
110 | memset(&p, 0, sizeof(p)); |
111 | ||
1be0815d | 112 | if (n) { |
80d5ff33 | 113 | type_import = false; |
1be0815d DS |
114 | p.prefixlen = 32; |
115 | p.u.prefix4 = nhop; | |
116 | p.family = AF_INET; | |
117 | } | |
118 | else { | |
80d5ff33 | 119 | type_import = true; |
1be0815d DS |
120 | p = *(const struct prefix *)inhop; |
121 | } | |
0ae8130d | 122 | |
86da53ab | 123 | sharp_nh_tracker_get(&p); |
a3b6aa82 | 124 | sharp_zebra_nexthop_watch(&p, vrf->vrf_id, type_import, |
91529dc8 | 125 | true, !!connected); |
0ae8130d DS |
126 | |
127 | return CMD_SUCCESS; | |
128 | } | |
129 | ||
86da53ab DS |
130 | DEFPY(sharp_nht_data_dump, |
131 | sharp_nht_data_dump_cmd, | |
132 | "sharp data nexthop", | |
133 | "Sharp routing Protocol\n" | |
134 | "Nexthop information\n" | |
135 | "Data Dump\n") | |
136 | { | |
137 | sharp_nh_tracker_dump(vty); | |
138 | ||
139 | return CMD_SUCCESS; | |
140 | } | |
141 | ||
f59e6418 DS |
142 | DEFPY (install_routes_data_dump, |
143 | install_routes_data_dump_cmd, | |
144 | "sharp data route", | |
145 | "Sharp routing Protocol\n" | |
146 | "Data about what is going on\n" | |
147 | "Route Install/Removal Information\n") | |
148 | { | |
149 | char buf[PREFIX_STRLEN]; | |
150 | struct timeval r; | |
151 | ||
152 | timersub(&sg.r.t_end, &sg.r.t_start, &r); | |
051a0be4 | 153 | vty_out(vty, "Prefix: %s Total: %u %u %u Time: %jd.%ld\n", |
f59e6418 DS |
154 | prefix2str(&sg.r.orig_prefix, buf, sizeof(buf)), |
155 | sg.r.total_routes, | |
156 | sg.r.installed_routes, | |
157 | sg.r.removed_routes, | |
051a0be4 | 158 | (intmax_t)r.tv_sec, (long)r.tv_usec); |
f59e6418 DS |
159 | |
160 | return CMD_SUCCESS; | |
161 | } | |
162 | ||
8a71d93d DS |
163 | DEFPY (install_routes, |
164 | install_routes_cmd, | |
1df3b1dc MS |
165 | "sharp install routes [vrf NAME$vrf_name]\ |
166 | <A.B.C.D$start4|X:X::X:X$start6>\ | |
167 | <nexthop <A.B.C.D$nexthop4|X:X::X:X$nexthop6>|\ | |
168 | nexthop-group NHGNAME$nexthop_group>\ | |
169 | [backup$backup <A.B.C.D$backup_nexthop4|X:X::X:X$backup_nexthop6>] \ | |
170 | (1-1000000)$routes [instance (0-255)$instance] [repeat (2-1000)$rpt]", | |
75239f4f | 171 | "Sharp routing Protocol\n" |
8a71d93d DS |
172 | "install some routes\n" |
173 | "Routes to install\n" | |
4a7d4737 DS |
174 | "The vrf we would like to install into if non-default\n" |
175 | "The NAME of the vrf\n" | |
dbc1bf46 DS |
176 | "v4 Address to start /32 generation at\n" |
177 | "v6 Address to start /32 generation at\n" | |
ba041bea DS |
178 | "Nexthop to use(Can be an IPv4 or IPv6 address)\n" |
179 | "V4 Nexthop address to use\n" | |
180 | "V6 Nexthop address to use\n" | |
d4101c0a DS |
181 | "Nexthop-Group to use\n" |
182 | "The Name of the nexthop-group\n" | |
1df3b1dc MS |
183 | "Backup nexthop to use(Can be an IPv4 or IPv6 address)\n" |
184 | "Backup V4 Nexthop address to use\n" | |
185 | "Backup V6 Nexthop address to use\n" | |
ae252c02 DS |
186 | "How many to create\n" |
187 | "Instance to use\n" | |
b939f6ff DS |
188 | "Instance\n" |
189 | "Should we repeat this command\n" | |
190 | "How many times to repeat this command\n") | |
8a71d93d | 191 | { |
4a7d4737 | 192 | struct vrf *vrf; |
547dc642 DS |
193 | struct prefix prefix; |
194 | uint32_t rts; | |
195 | ||
196 | sg.r.total_routes = routes; | |
197 | sg.r.installed_routes = 0; | |
8a71d93d | 198 | |
b939f6ff | 199 | if (rpt >= 2) |
547dc642 | 200 | sg.r.repeat = rpt * 2; |
b939f6ff | 201 | else |
547dc642 | 202 | sg.r.repeat = 0; |
b939f6ff DS |
203 | |
204 | memset(&prefix, 0, sizeof(prefix)); | |
547dc642 DS |
205 | memset(&sg.r.orig_prefix, 0, sizeof(sg.r.orig_prefix)); |
206 | memset(&sg.r.nhop, 0, sizeof(sg.r.nhop)); | |
207 | memset(&sg.r.nhop_group, 0, sizeof(sg.r.nhop_group)); | |
1df3b1dc MS |
208 | memset(&sg.r.backup_nhop, 0, sizeof(sg.r.nhop)); |
209 | memset(&sg.r.backup_nhop_group, 0, sizeof(sg.r.nhop_group)); | |
8a71d93d | 210 | |
dbc1bf46 DS |
211 | if (start4.s_addr != 0) { |
212 | prefix.family = AF_INET; | |
213 | prefix.prefixlen = 32; | |
214 | prefix.u.prefix4 = start4; | |
215 | } else { | |
216 | prefix.family = AF_INET6; | |
217 | prefix.prefixlen = 128; | |
218 | prefix.u.prefix6 = start6; | |
219 | } | |
547dc642 | 220 | sg.r.orig_prefix = prefix; |
8a71d93d | 221 | |
e429a2a0 IR |
222 | if (!vrf_name) |
223 | vrf_name = VRF_DEFAULT_NAME; | |
a3b6aa82 | 224 | |
e429a2a0 | 225 | vrf = vrf_lookup_by_name(vrf_name); |
4a7d4737 DS |
226 | if (!vrf) { |
227 | vty_out(vty, "The vrf NAME specified: %s does not exist\n", | |
e429a2a0 | 228 | vrf_name); |
4a7d4737 DS |
229 | return CMD_WARNING; |
230 | } | |
231 | ||
1df3b1dc MS |
232 | /* Explicit backup not available with named nexthop-group */ |
233 | if (backup && nexthop_group) { | |
234 | vty_out(vty, "%% Invalid: cannot specify both nexthop-group and backup\n"); | |
235 | return CMD_WARNING; | |
236 | } | |
237 | ||
d4101c0a DS |
238 | if (nexthop_group) { |
239 | struct nexthop_group_cmd *nhgc = nhgc_find(nexthop_group); | |
240 | if (!nhgc) { | |
241 | vty_out(vty, | |
242 | "Specified Nexthop Group: %s does not exist\n", | |
243 | nexthop_group); | |
244 | return CMD_WARNING; | |
245 | } | |
246 | ||
547dc642 | 247 | sg.r.nhop_group.nexthop = nhgc->nhg.nexthop; |
1df3b1dc MS |
248 | |
249 | /* Use group's backup nexthop info if present */ | |
250 | if (nhgc->backup_list_name[0]) { | |
251 | struct nexthop_group_cmd *bnhgc = | |
252 | nhgc_find(nhgc->backup_list_name); | |
253 | ||
254 | if (!bnhgc) { | |
255 | vty_out(vty, "%% Backup group %s not found for group %s\n", | |
256 | nhgc->backup_list_name, | |
257 | nhgc->name); | |
258 | return CMD_WARNING; | |
259 | } | |
260 | ||
261 | sg.r.backup_nhop.vrf_id = vrf->vrf_id; | |
262 | sg.r.backup_nhop_group.nexthop = bnhgc->nhg.nexthop; | |
263 | } | |
ba041bea | 264 | } else { |
d4101c0a | 265 | if (nexthop4.s_addr != INADDR_ANY) { |
547dc642 DS |
266 | sg.r.nhop.gate.ipv4 = nexthop4; |
267 | sg.r.nhop.type = NEXTHOP_TYPE_IPV4; | |
d4101c0a | 268 | } else { |
547dc642 DS |
269 | sg.r.nhop.gate.ipv6 = nexthop6; |
270 | sg.r.nhop.type = NEXTHOP_TYPE_IPV6; | |
d4101c0a DS |
271 | } |
272 | ||
4a7d4737 | 273 | sg.r.nhop.vrf_id = vrf->vrf_id; |
547dc642 | 274 | sg.r.nhop_group.nexthop = &sg.r.nhop; |
ba041bea | 275 | } |
8a71d93d | 276 | |
1df3b1dc MS |
277 | /* Use single backup nexthop if specified */ |
278 | if (backup) { | |
279 | /* Set flag and index in primary nexthop */ | |
280 | SET_FLAG(sg.r.nhop.flags, NEXTHOP_FLAG_HAS_BACKUP); | |
281 | sg.r.nhop.backup_idx = 0; | |
282 | ||
283 | if (backup_nexthop4.s_addr != INADDR_ANY) { | |
284 | sg.r.backup_nhop.gate.ipv4 = backup_nexthop4; | |
285 | sg.r.backup_nhop.type = NEXTHOP_TYPE_IPV4; | |
286 | } else { | |
287 | sg.r.backup_nhop.gate.ipv6 = backup_nexthop6; | |
288 | sg.r.backup_nhop.type = NEXTHOP_TYPE_IPV6; | |
289 | } | |
290 | ||
291 | sg.r.backup_nhop.vrf_id = vrf->vrf_id; | |
292 | sg.r.backup_nhop_group.nexthop = &sg.r.backup_nhop; | |
293 | } | |
294 | ||
547dc642 | 295 | sg.r.inst = instance; |
4a7d4737 | 296 | sg.r.vrf_id = vrf->vrf_id; |
b939f6ff | 297 | rts = routes; |
1df3b1dc MS |
298 | sharp_install_routes_helper(&prefix, sg.r.vrf_id, sg.r.inst, |
299 | &sg.r.nhop_group, &sg.r.backup_nhop_group, | |
300 | rts); | |
8a71d93d DS |
301 | |
302 | return CMD_SUCCESS; | |
303 | } | |
304 | ||
42567e00 | 305 | DEFPY(vrf_label, vrf_label_cmd, |
e429a2a0 | 306 | "sharp label <ip$ipv4|ipv6$ipv6> vrf NAME$vrf_name label (0-100000)$label", |
75239f4f | 307 | "Sharp Routing Protocol\n" |
ab18a495 | 308 | "Give a vrf a label\n" |
7d061b3c DS |
309 | "Pop and forward for IPv4\n" |
310 | "Pop and forward for IPv6\n" | |
ab18a495 | 311 | VRF_CMD_HELP_STR |
42567e00 | 312 | "The label to use, 0 specifies remove the label installed from previous\n" |
ab18a495 DS |
313 | "Specified range to use\n") |
314 | { | |
315 | struct vrf *vrf; | |
7d061b3c | 316 | afi_t afi = (ipv4) ? AFI_IP : AFI_IP6; |
ab18a495 | 317 | |
e429a2a0 | 318 | if (strcmp(vrf_name, "default") == 0) |
ab18a495 DS |
319 | vrf = vrf_lookup_by_id(VRF_DEFAULT); |
320 | else | |
e429a2a0 | 321 | vrf = vrf_lookup_by_name(vrf_name); |
ab18a495 DS |
322 | |
323 | if (!vrf) { | |
324 | vty_out(vty, "Unable to find vrf you silly head"); | |
325 | return CMD_WARNING_CONFIG_FAILED; | |
326 | } | |
327 | ||
42567e00 DS |
328 | if (label == 0) |
329 | label = MPLS_LABEL_NONE; | |
330 | ||
7d061b3c | 331 | vrf_label_add(vrf->vrf_id, afi, label); |
ab18a495 DS |
332 | return CMD_SUCCESS; |
333 | } | |
334 | ||
8a71d93d DS |
335 | DEFPY (remove_routes, |
336 | remove_routes_cmd, | |
e429a2a0 | 337 | "sharp remove routes [vrf NAME$vrf_name] <A.B.C.D$start4|X:X::X:X$start6> (1-1000000)$routes [instance (0-255)$instance]", |
75239f4f | 338 | "Sharp Routing Protocol\n" |
8a71d93d DS |
339 | "Remove some routes\n" |
340 | "Routes to remove\n" | |
4a7d4737 DS |
341 | "The vrf we would like to remove from if non-default\n" |
342 | "The NAME of the vrf\n" | |
e310fc19 DS |
343 | "v4 Starting spot\n" |
344 | "v6 Starting spot\n" | |
345 | "Routes to uninstall\n" | |
ae252c02 DS |
346 | "instance to use\n" |
347 | "Value of instance\n") | |
8a71d93d | 348 | { |
4a7d4737 | 349 | struct vrf *vrf; |
547dc642 DS |
350 | struct prefix prefix; |
351 | ||
352 | sg.r.total_routes = routes; | |
353 | sg.r.removed_routes = 0; | |
354 | uint32_t rts; | |
8a71d93d | 355 | |
b939f6ff | 356 | memset(&prefix, 0, sizeof(prefix)); |
8a71d93d | 357 | |
dbc1bf46 DS |
358 | if (start4.s_addr != 0) { |
359 | prefix.family = AF_INET; | |
360 | prefix.prefixlen = 32; | |
361 | prefix.u.prefix4 = start4; | |
362 | } else { | |
363 | prefix.family = AF_INET6; | |
364 | prefix.prefixlen = 128; | |
365 | prefix.u.prefix6 = start6; | |
366 | } | |
8a71d93d | 367 | |
e429a2a0 | 368 | vrf = vrf_lookup_by_name(vrf_name ? vrf_name : VRF_DEFAULT_NAME); |
4a7d4737 DS |
369 | if (!vrf) { |
370 | vty_out(vty, "The vrf NAME specified: %s does not exist\n", | |
e429a2a0 | 371 | vrf_name ? vrf_name : VRF_DEFAULT_NAME); |
4a7d4737 DS |
372 | return CMD_WARNING; |
373 | } | |
374 | ||
547dc642 | 375 | sg.r.inst = instance; |
4a7d4737 | 376 | sg.r.vrf_id = vrf->vrf_id; |
b939f6ff | 377 | rts = routes; |
0cf08685 DS |
378 | sharp_remove_routes_helper(&prefix, sg.r.vrf_id, |
379 | sg.r.inst, rts); | |
8a71d93d DS |
380 | |
381 | return CMD_SUCCESS; | |
382 | } | |
383 | ||
aaf8c96f DS |
384 | DEFUN_NOSH (show_debugging_sharpd, |
385 | show_debugging_sharpd_cmd, | |
386 | "show debugging [sharp]", | |
387 | SHOW_STR | |
388 | DEBUG_STR | |
389 | "Sharp Information\n") | |
390 | { | |
c9e5adba | 391 | vty_out(vty, "Sharp debugging status:\n"); |
aaf8c96f DS |
392 | |
393 | return CMD_SUCCESS; | |
394 | } | |
395 | ||
c9e5adba MS |
396 | DEFPY(sharp_lsp_prefix_v4, sharp_lsp_prefix_v4_cmd, |
397 | "sharp lsp (0-100000)$inlabel\ | |
398 | nexthop-group NHGNAME$nhgname\ | |
399 | [prefix A.B.C.D/M$pfx\ | |
4b0f6237 | 400 | " FRR_IP_REDIST_STR_ZEBRA "$type_str [instance (0-255)$instance]]", |
c9e5adba MS |
401 | "Sharp Routing Protocol\n" |
402 | "Add an LSP\n" | |
403 | "The ingress label to use\n" | |
404 | "Use nexthops from a nexthop-group\n" | |
405 | "The nexthop-group name\n" | |
406 | "Label a prefix\n" | |
407 | "The v4 prefix to label\n" | |
4b0f6237 | 408 | FRR_IP_REDIST_HELP_STR_ZEBRA |
c9e5adba MS |
409 | "Instance to use\n" |
410 | "Instance\n") | |
411 | { | |
412 | struct nexthop_group_cmd *nhgc = NULL; | |
665edffd MS |
413 | struct nexthop_group_cmd *backup_nhgc = NULL; |
414 | struct nexthop_group *backup_nhg = NULL; | |
c9e5adba MS |
415 | struct prefix p = {}; |
416 | int type = 0; | |
417 | ||
418 | /* We're offered a v4 prefix */ | |
419 | if (pfx->family > 0 && type_str) { | |
420 | p.family = pfx->family; | |
421 | p.prefixlen = pfx->prefixlen; | |
422 | p.u.prefix4 = pfx->prefix; | |
423 | ||
424 | type = proto_redistnum(AFI_IP, type_str); | |
425 | if (type < 0) { | |
426 | vty_out(vty, "%% Unknown route type '%s'\n", type_str); | |
427 | return CMD_WARNING; | |
428 | } | |
429 | } else if (pfx->family > 0 || type_str) { | |
430 | vty_out(vty, "%% Must supply both prefix and type\n"); | |
431 | return CMD_WARNING; | |
432 | } | |
433 | ||
434 | nhgc = nhgc_find(nhgname); | |
435 | if (!nhgc) { | |
436 | vty_out(vty, "%% Nexthop-group '%s' does not exist\n", | |
437 | nhgname); | |
438 | return CMD_WARNING; | |
439 | } | |
440 | ||
441 | if (nhgc->nhg.nexthop == NULL) { | |
442 | vty_out(vty, "%% Nexthop-group '%s' is empty\n", nhgname); | |
443 | return CMD_WARNING; | |
444 | } | |
445 | ||
665edffd MS |
446 | /* Use group's backup nexthop info if present */ |
447 | if (nhgc->backup_list_name[0]) { | |
448 | backup_nhgc = nhgc_find(nhgc->backup_list_name); | |
449 | ||
450 | if (!backup_nhgc) { | |
451 | vty_out(vty, | |
452 | "%% Backup group %s not found for group %s\n", | |
453 | nhgc->backup_list_name, | |
454 | nhgname); | |
455 | return CMD_WARNING; | |
456 | } | |
457 | backup_nhg = &(backup_nhgc->nhg); | |
458 | } | |
459 | ||
c9e5adba MS |
460 | if (sharp_install_lsps_helper(true, pfx->family > 0 ? &p : NULL, |
461 | type, instance, inlabel, | |
665edffd | 462 | &(nhgc->nhg), backup_nhg) == 0) |
c9e5adba MS |
463 | return CMD_SUCCESS; |
464 | else { | |
465 | vty_out(vty, "%% LSP install failed!\n"); | |
466 | return CMD_WARNING; | |
467 | } | |
468 | } | |
469 | ||
470 | DEFPY(sharp_remove_lsp_prefix_v4, sharp_remove_lsp_prefix_v4_cmd, | |
471 | "sharp remove lsp \ | |
472 | (0-100000)$inlabel\ | |
665edffd | 473 | [nexthop-group NHGNAME$nhgname] \ |
c9e5adba MS |
474 | [prefix A.B.C.D/M$pfx\ |
475 | " FRR_IP_REDIST_STR_SHARPD "$type_str [instance (0-255)$instance]]", | |
476 | "Sharp Routing Protocol\n" | |
477 | "Remove data\n" | |
478 | "Remove an LSP\n" | |
479 | "The ingress label\n" | |
480 | "Use nexthops from a nexthop-group\n" | |
481 | "The nexthop-group name\n" | |
482 | "Specify a v4 prefix\n" | |
483 | "The v4 prefix to label\n" | |
484 | FRR_IP_REDIST_HELP_STR_SHARPD | |
485 | "Routing instance\n" | |
486 | "Instance to use\n") | |
487 | { | |
488 | struct nexthop_group_cmd *nhgc = NULL; | |
489 | struct prefix p = {}; | |
490 | int type = 0; | |
665edffd | 491 | struct nexthop_group *nhg = NULL; |
c9e5adba MS |
492 | |
493 | /* We're offered a v4 prefix */ | |
494 | if (pfx->family > 0 && type_str) { | |
495 | p.family = pfx->family; | |
496 | p.prefixlen = pfx->prefixlen; | |
497 | p.u.prefix4 = pfx->prefix; | |
498 | ||
499 | type = proto_redistnum(AFI_IP, type_str); | |
500 | if (type < 0) { | |
501 | vty_out(vty, "%% Unknown route type '%s'\n", type_str); | |
502 | return CMD_WARNING; | |
503 | } | |
504 | } else if (pfx->family > 0 || type_str) { | |
505 | vty_out(vty, "%% Must supply both prefix and type\n"); | |
506 | return CMD_WARNING; | |
507 | } | |
508 | ||
665edffd MS |
509 | if (nhgname) { |
510 | nhgc = nhgc_find(nhgname); | |
511 | if (!nhgc) { | |
512 | vty_out(vty, "%% Nexthop-group '%s' does not exist\n", | |
513 | nhgname); | |
514 | return CMD_WARNING; | |
515 | } | |
c9e5adba | 516 | |
665edffd MS |
517 | if (nhgc->nhg.nexthop == NULL) { |
518 | vty_out(vty, "%% Nexthop-group '%s' is empty\n", | |
519 | nhgname); | |
520 | return CMD_WARNING; | |
521 | } | |
522 | nhg = &(nhgc->nhg); | |
c9e5adba MS |
523 | } |
524 | ||
525 | if (sharp_install_lsps_helper(false, pfx->family > 0 ? &p : NULL, | |
665edffd | 526 | type, instance, inlabel, nhg, NULL) == 0) |
c9e5adba MS |
527 | return CMD_SUCCESS; |
528 | else { | |
529 | vty_out(vty, "%% LSP remove failed!\n"); | |
530 | return CMD_WARNING; | |
531 | } | |
532 | } | |
533 | ||
aef4a13f DL |
534 | DEFPY (logpump, |
535 | logpump_cmd, | |
536 | "sharp logpump duration (1-60) frequency (1-1000000) burst (1-1000)", | |
537 | "Sharp Routing Protocol\n" | |
538 | "Generate bulk log messages for testing\n" | |
539 | "Duration of run (s)\n" | |
540 | "Duration of run (s)\n" | |
541 | "Frequency of bursts (s^-1)\n" | |
542 | "Frequency of bursts (s^-1)\n" | |
543 | "Number of log messages per each burst\n" | |
544 | "Number of log messages per each burst\n") | |
545 | { | |
546 | sharp_logpump_run(vty, duration, frequency, burst); | |
547 | return CMD_SUCCESS; | |
548 | } | |
549 | ||
2ac6c90d MS |
550 | DEFPY (send_opaque, |
551 | send_opaque_cmd, | |
552 | "sharp send opaque type (1-255) (1-1000)$count", | |
553 | "Sharp Routing Protocol\n" | |
554 | "Send messages for testing\n" | |
555 | "Send opaque messages\n" | |
556 | "Type code to send\n" | |
557 | "Type code to send\n" | |
558 | "Number of messages to send\n") | |
559 | { | |
560 | sharp_opaque_send(type, count); | |
561 | return CMD_SUCCESS; | |
562 | } | |
563 | ||
8a71d93d DS |
564 | void sharp_vty_init(void) |
565 | { | |
f59e6418 | 566 | install_element(ENABLE_NODE, &install_routes_data_dump_cmd); |
8a71d93d DS |
567 | install_element(ENABLE_NODE, &install_routes_cmd); |
568 | install_element(ENABLE_NODE, &remove_routes_cmd); | |
ab18a495 | 569 | install_element(ENABLE_NODE, &vrf_label_cmd); |
86da53ab | 570 | install_element(ENABLE_NODE, &sharp_nht_data_dump_cmd); |
0ae8130d DS |
571 | install_element(ENABLE_NODE, &watch_nexthop_v6_cmd); |
572 | install_element(ENABLE_NODE, &watch_nexthop_v4_cmd); | |
c9e5adba MS |
573 | install_element(ENABLE_NODE, &sharp_lsp_prefix_v4_cmd); |
574 | install_element(ENABLE_NODE, &sharp_remove_lsp_prefix_v4_cmd); | |
aef4a13f | 575 | install_element(ENABLE_NODE, &logpump_cmd); |
2ac6c90d | 576 | install_element(ENABLE_NODE, &send_opaque_cmd); |
aaf8c96f DS |
577 | |
578 | install_element(VIEW_NODE, &show_debugging_sharpd_cmd); | |
579 | ||
8a71d93d DS |
580 | return; |
581 | } |