]> git.proxmox.com Git - mirror_frr.git/blame - sharpd/sharp_vty.c
Merge pull request #3788 from AnuradhaKaruppiah/evpn-pmsi-fixes
[mirror_frr.git] / sharpd / sharp_vty.c
CommitLineData
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 41DEFPY(watch_nexthop_v6, watch_nexthop_v6_cmd,
80d5ff33 42 "sharp watch <nexthop$n|import$import> X:X::X:X$nhop [connected$connected]",
0ae8130d
DS
43 "Sharp routing Protocol\n"
44 "Watch for changes\n"
45 "Watch for nexthop changes\n"
80d5ff33 46 "Watch for import check changes\n"
a60ffbc9
DS
47 "The v6 nexthop to signal for watching\n"
48 "Should the route be connected\n")
0ae8130d
DS
49{
50 struct prefix p;
80d5ff33
DS
51 bool type_import;
52
53
54 if (n)
55 type_import = false;
56 else
57 type_import = true;
0ae8130d
DS
58
59 memset(&p, 0, sizeof(p));
60
61 p.prefixlen = 128;
62 memcpy(&p.u.prefix6, &nhop, 16);
63 p.family = AF_INET6;
64
86da53ab 65 sharp_nh_tracker_get(&p);
80d5ff33 66 sharp_zebra_nexthop_watch(&p, type_import, true, !!connected);
0ae8130d
DS
67
68 return CMD_SUCCESS;
69}
70
71DEFPY(watch_nexthop_v4, watch_nexthop_v4_cmd,
80d5ff33 72 "sharp watch <nexthop$n|import$import> A.B.C.D$nhop [connected$connected]",
0ae8130d
DS
73 "Sharp routing Protocol\n"
74 "Watch for changes\n"
75 "Watch for nexthop changes\n"
80d5ff33 76 "Watch for import check changes\n"
a60ffbc9
DS
77 "The v4 nexthop to signal for watching\n"
78 "Should the route be connected\n")
0ae8130d
DS
79{
80 struct prefix p;
80d5ff33 81 bool type_import;
0ae8130d
DS
82
83 memset(&p, 0, sizeof(p));
84
80d5ff33
DS
85 if (n)
86 type_import = false;
87 else
88 type_import = true;
89
0ae8130d
DS
90 p.prefixlen = 32;
91 p.u.prefix4 = nhop;
92 p.family = AF_INET;
93
86da53ab 94 sharp_nh_tracker_get(&p);
80d5ff33 95 sharp_zebra_nexthop_watch(&p, type_import, true, !!connected);
0ae8130d
DS
96
97 return CMD_SUCCESS;
98}
99
86da53ab
DS
100DEFPY(sharp_nht_data_dump,
101 sharp_nht_data_dump_cmd,
102 "sharp data nexthop",
103 "Sharp routing Protocol\n"
104 "Nexthop information\n"
105 "Data Dump\n")
106{
107 sharp_nh_tracker_dump(vty);
108
109 return CMD_SUCCESS;
110}
111
f59e6418
DS
112DEFPY (install_routes_data_dump,
113 install_routes_data_dump_cmd,
114 "sharp data route",
115 "Sharp routing Protocol\n"
116 "Data about what is going on\n"
117 "Route Install/Removal Information\n")
118{
119 char buf[PREFIX_STRLEN];
120 struct timeval r;
121
122 timersub(&sg.r.t_end, &sg.r.t_start, &r);
123 vty_out(vty, "Prefix: %s Total: %u %u %u Time: %ld.%ld\n",
124 prefix2str(&sg.r.orig_prefix, buf, sizeof(buf)),
125 sg.r.total_routes,
126 sg.r.installed_routes,
127 sg.r.removed_routes,
128 r.tv_sec, r.tv_usec);
129
130 return CMD_SUCCESS;
131}
132
8a71d93d
DS
133DEFPY (install_routes,
134 install_routes_cmd,
dbc1bf46 135 "sharp install routes <A.B.C.D$start4|X:X::X:X$start6> <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]",
75239f4f 136 "Sharp routing Protocol\n"
8a71d93d
DS
137 "install some routes\n"
138 "Routes to install\n"
dbc1bf46
DS
139 "v4 Address to start /32 generation at\n"
140 "v6 Address to start /32 generation at\n"
ba041bea
DS
141 "Nexthop to use(Can be an IPv4 or IPv6 address)\n"
142 "V4 Nexthop address to use\n"
143 "V6 Nexthop address to use\n"
d4101c0a
DS
144 "Nexthop-Group to use\n"
145 "The Name of the nexthop-group\n"
ae252c02
DS
146 "How many to create\n"
147 "Instance to use\n"
b939f6ff
DS
148 "Instance\n"
149 "Should we repeat this command\n"
150 "How many times to repeat this command\n")
8a71d93d 151{
547dc642
DS
152 struct prefix prefix;
153 uint32_t rts;
154
155 sg.r.total_routes = routes;
156 sg.r.installed_routes = 0;
8a71d93d 157
b939f6ff 158 if (rpt >= 2)
547dc642 159 sg.r.repeat = rpt * 2;
b939f6ff 160 else
547dc642 161 sg.r.repeat = 0;
b939f6ff
DS
162
163 memset(&prefix, 0, sizeof(prefix));
547dc642
DS
164 memset(&sg.r.orig_prefix, 0, sizeof(sg.r.orig_prefix));
165 memset(&sg.r.nhop, 0, sizeof(sg.r.nhop));
166 memset(&sg.r.nhop_group, 0, sizeof(sg.r.nhop_group));
8a71d93d 167
dbc1bf46
DS
168 if (start4.s_addr != 0) {
169 prefix.family = AF_INET;
170 prefix.prefixlen = 32;
171 prefix.u.prefix4 = start4;
172 } else {
173 prefix.family = AF_INET6;
174 prefix.prefixlen = 128;
175 prefix.u.prefix6 = start6;
176 }
547dc642 177 sg.r.orig_prefix = prefix;
8a71d93d 178
d4101c0a
DS
179 if (nexthop_group) {
180 struct nexthop_group_cmd *nhgc = nhgc_find(nexthop_group);
181 if (!nhgc) {
182 vty_out(vty,
183 "Specified Nexthop Group: %s does not exist\n",
184 nexthop_group);
185 return CMD_WARNING;
186 }
187
547dc642 188 sg.r.nhop_group.nexthop = nhgc->nhg.nexthop;
ba041bea 189 } else {
d4101c0a 190 if (nexthop4.s_addr != INADDR_ANY) {
547dc642
DS
191 sg.r.nhop.gate.ipv4 = nexthop4;
192 sg.r.nhop.type = NEXTHOP_TYPE_IPV4;
d4101c0a 193 } else {
547dc642
DS
194 sg.r.nhop.gate.ipv6 = nexthop6;
195 sg.r.nhop.type = NEXTHOP_TYPE_IPV6;
d4101c0a
DS
196 }
197
547dc642 198 sg.r.nhop_group.nexthop = &sg.r.nhop;
ba041bea 199 }
8a71d93d 200
547dc642 201 sg.r.inst = instance;
b939f6ff 202 rts = routes;
547dc642 203 sharp_install_routes_helper(&prefix, sg.r.inst, &sg.r.nhop_group, rts);
8a71d93d
DS
204
205 return CMD_SUCCESS;
206}
207
42567e00 208DEFPY(vrf_label, vrf_label_cmd,
7d061b3c 209 "sharp label <ip$ipv4|ipv6$ipv6> vrf NAME$name label (0-100000)$label",
75239f4f 210 "Sharp Routing Protocol\n"
ab18a495 211 "Give a vrf a label\n"
7d061b3c
DS
212 "Pop and forward for IPv4\n"
213 "Pop and forward for IPv6\n"
ab18a495 214 VRF_CMD_HELP_STR
42567e00 215 "The label to use, 0 specifies remove the label installed from previous\n"
ab18a495
DS
216 "Specified range to use\n")
217{
218 struct vrf *vrf;
7d061b3c 219 afi_t afi = (ipv4) ? AFI_IP : AFI_IP6;
ab18a495
DS
220
221 if (strcmp(name, "default") == 0)
222 vrf = vrf_lookup_by_id(VRF_DEFAULT);
223 else
224 vrf = vrf_lookup_by_name(name);
225
226 if (!vrf) {
227 vty_out(vty, "Unable to find vrf you silly head");
228 return CMD_WARNING_CONFIG_FAILED;
229 }
230
42567e00
DS
231 if (label == 0)
232 label = MPLS_LABEL_NONE;
233
7d061b3c 234 vrf_label_add(vrf->vrf_id, afi, label);
ab18a495
DS
235 return CMD_SUCCESS;
236}
237
8a71d93d
DS
238DEFPY (remove_routes,
239 remove_routes_cmd,
dbc1bf46 240 "sharp remove routes <A.B.C.D$start4|X:X::X:X$start6> (1-1000000)$routes [instance (0-255)$instance]",
75239f4f 241 "Sharp Routing Protocol\n"
8a71d93d
DS
242 "Remove some routes\n"
243 "Routes to remove\n"
e310fc19
DS
244 "v4 Starting spot\n"
245 "v6 Starting spot\n"
246 "Routes to uninstall\n"
ae252c02
DS
247 "instance to use\n"
248 "Value of instance\n")
8a71d93d 249{
547dc642
DS
250 struct prefix prefix;
251
252 sg.r.total_routes = routes;
253 sg.r.removed_routes = 0;
254 uint32_t rts;
8a71d93d 255
b939f6ff 256 memset(&prefix, 0, sizeof(prefix));
8a71d93d 257
dbc1bf46
DS
258 if (start4.s_addr != 0) {
259 prefix.family = AF_INET;
260 prefix.prefixlen = 32;
261 prefix.u.prefix4 = start4;
262 } else {
263 prefix.family = AF_INET6;
264 prefix.prefixlen = 128;
265 prefix.u.prefix6 = start6;
266 }
8a71d93d 267
547dc642 268 sg.r.inst = instance;
b939f6ff 269 rts = routes;
547dc642 270 sharp_remove_routes_helper(&prefix, sg.r.inst, rts);
8a71d93d
DS
271
272 return CMD_SUCCESS;
273}
274
aaf8c96f
DS
275DEFUN_NOSH (show_debugging_sharpd,
276 show_debugging_sharpd_cmd,
277 "show debugging [sharp]",
278 SHOW_STR
279 DEBUG_STR
280 "Sharp Information\n")
281{
282 vty_out(vty, "Sharp debugging status\n");
283
284 return CMD_SUCCESS;
285}
286
8a71d93d
DS
287void sharp_vty_init(void)
288{
f59e6418 289 install_element(ENABLE_NODE, &install_routes_data_dump_cmd);
8a71d93d
DS
290 install_element(ENABLE_NODE, &install_routes_cmd);
291 install_element(ENABLE_NODE, &remove_routes_cmd);
ab18a495 292 install_element(ENABLE_NODE, &vrf_label_cmd);
86da53ab 293 install_element(ENABLE_NODE, &sharp_nht_data_dump_cmd);
0ae8130d
DS
294 install_element(ENABLE_NODE, &watch_nexthop_v6_cmd);
295 install_element(ENABLE_NODE, &watch_nexthop_v4_cmd);
aaf8c96f
DS
296
297 install_element(VIEW_NODE, &show_debugging_sharpd_cmd);
298
8a71d93d
DS
299 return;
300}