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