]>
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, | |
e429a2a0 | 165 | "sharp install routes [vrf NAME$vrf_name] <A.B.C.D$start4|X:X::X:X$start6> <nexthop <A.B.C.D$nexthop4|X:X::X:X$nexthop6>|nexthop-group NHGNAME$nexthop_group> (1-1000000)$routes [instance (0-255)$instance] [repeat (2-1000)$rpt]", |
75239f4f | 166 | "Sharp routing Protocol\n" |
8a71d93d DS |
167 | "install some routes\n" |
168 | "Routes to install\n" | |
4a7d4737 DS |
169 | "The vrf we would like to install into if non-default\n" |
170 | "The NAME of the vrf\n" | |
dbc1bf46 DS |
171 | "v4 Address to start /32 generation at\n" |
172 | "v6 Address to start /32 generation at\n" | |
ba041bea DS |
173 | "Nexthop to use(Can be an IPv4 or IPv6 address)\n" |
174 | "V4 Nexthop address to use\n" | |
175 | "V6 Nexthop address to use\n" | |
d4101c0a DS |
176 | "Nexthop-Group to use\n" |
177 | "The Name of the nexthop-group\n" | |
ae252c02 DS |
178 | "How many to create\n" |
179 | "Instance to use\n" | |
b939f6ff DS |
180 | "Instance\n" |
181 | "Should we repeat this command\n" | |
182 | "How many times to repeat this command\n") | |
8a71d93d | 183 | { |
4a7d4737 | 184 | struct vrf *vrf; |
547dc642 DS |
185 | struct prefix prefix; |
186 | uint32_t rts; | |
187 | ||
188 | sg.r.total_routes = routes; | |
189 | sg.r.installed_routes = 0; | |
8a71d93d | 190 | |
b939f6ff | 191 | if (rpt >= 2) |
547dc642 | 192 | sg.r.repeat = rpt * 2; |
b939f6ff | 193 | else |
547dc642 | 194 | sg.r.repeat = 0; |
b939f6ff DS |
195 | |
196 | memset(&prefix, 0, sizeof(prefix)); | |
547dc642 DS |
197 | memset(&sg.r.orig_prefix, 0, sizeof(sg.r.orig_prefix)); |
198 | memset(&sg.r.nhop, 0, sizeof(sg.r.nhop)); | |
199 | memset(&sg.r.nhop_group, 0, sizeof(sg.r.nhop_group)); | |
8a71d93d | 200 | |
dbc1bf46 DS |
201 | if (start4.s_addr != 0) { |
202 | prefix.family = AF_INET; | |
203 | prefix.prefixlen = 32; | |
204 | prefix.u.prefix4 = start4; | |
205 | } else { | |
206 | prefix.family = AF_INET6; | |
207 | prefix.prefixlen = 128; | |
208 | prefix.u.prefix6 = start6; | |
209 | } | |
547dc642 | 210 | sg.r.orig_prefix = prefix; |
8a71d93d | 211 | |
e429a2a0 IR |
212 | if (!vrf_name) |
213 | vrf_name = VRF_DEFAULT_NAME; | |
a3b6aa82 | 214 | |
e429a2a0 | 215 | vrf = vrf_lookup_by_name(vrf_name); |
4a7d4737 DS |
216 | if (!vrf) { |
217 | vty_out(vty, "The vrf NAME specified: %s does not exist\n", | |
e429a2a0 | 218 | vrf_name); |
4a7d4737 DS |
219 | return CMD_WARNING; |
220 | } | |
221 | ||
d4101c0a DS |
222 | if (nexthop_group) { |
223 | struct nexthop_group_cmd *nhgc = nhgc_find(nexthop_group); | |
224 | if (!nhgc) { | |
225 | vty_out(vty, | |
226 | "Specified Nexthop Group: %s does not exist\n", | |
227 | nexthop_group); | |
228 | return CMD_WARNING; | |
229 | } | |
230 | ||
547dc642 | 231 | sg.r.nhop_group.nexthop = nhgc->nhg.nexthop; |
ba041bea | 232 | } else { |
d4101c0a | 233 | if (nexthop4.s_addr != INADDR_ANY) { |
547dc642 DS |
234 | sg.r.nhop.gate.ipv4 = nexthop4; |
235 | sg.r.nhop.type = NEXTHOP_TYPE_IPV4; | |
d4101c0a | 236 | } else { |
547dc642 DS |
237 | sg.r.nhop.gate.ipv6 = nexthop6; |
238 | sg.r.nhop.type = NEXTHOP_TYPE_IPV6; | |
d4101c0a DS |
239 | } |
240 | ||
4a7d4737 | 241 | sg.r.nhop.vrf_id = vrf->vrf_id; |
547dc642 | 242 | sg.r.nhop_group.nexthop = &sg.r.nhop; |
ba041bea | 243 | } |
8a71d93d | 244 | |
547dc642 | 245 | sg.r.inst = instance; |
4a7d4737 | 246 | sg.r.vrf_id = vrf->vrf_id; |
b939f6ff | 247 | rts = routes; |
0cf08685 DS |
248 | sharp_install_routes_helper(&prefix, sg.r.vrf_id, |
249 | sg.r.inst, &sg.r.nhop_group, rts); | |
8a71d93d DS |
250 | |
251 | return CMD_SUCCESS; | |
252 | } | |
253 | ||
42567e00 | 254 | DEFPY(vrf_label, vrf_label_cmd, |
e429a2a0 | 255 | "sharp label <ip$ipv4|ipv6$ipv6> vrf NAME$vrf_name label (0-100000)$label", |
75239f4f | 256 | "Sharp Routing Protocol\n" |
ab18a495 | 257 | "Give a vrf a label\n" |
7d061b3c DS |
258 | "Pop and forward for IPv4\n" |
259 | "Pop and forward for IPv6\n" | |
ab18a495 | 260 | VRF_CMD_HELP_STR |
42567e00 | 261 | "The label to use, 0 specifies remove the label installed from previous\n" |
ab18a495 DS |
262 | "Specified range to use\n") |
263 | { | |
264 | struct vrf *vrf; | |
7d061b3c | 265 | afi_t afi = (ipv4) ? AFI_IP : AFI_IP6; |
ab18a495 | 266 | |
e429a2a0 | 267 | if (strcmp(vrf_name, "default") == 0) |
ab18a495 DS |
268 | vrf = vrf_lookup_by_id(VRF_DEFAULT); |
269 | else | |
e429a2a0 | 270 | vrf = vrf_lookup_by_name(vrf_name); |
ab18a495 DS |
271 | |
272 | if (!vrf) { | |
273 | vty_out(vty, "Unable to find vrf you silly head"); | |
274 | return CMD_WARNING_CONFIG_FAILED; | |
275 | } | |
276 | ||
42567e00 DS |
277 | if (label == 0) |
278 | label = MPLS_LABEL_NONE; | |
279 | ||
7d061b3c | 280 | vrf_label_add(vrf->vrf_id, afi, label); |
ab18a495 DS |
281 | return CMD_SUCCESS; |
282 | } | |
283 | ||
8a71d93d DS |
284 | DEFPY (remove_routes, |
285 | remove_routes_cmd, | |
e429a2a0 | 286 | "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 | 287 | "Sharp Routing Protocol\n" |
8a71d93d DS |
288 | "Remove some routes\n" |
289 | "Routes to remove\n" | |
4a7d4737 DS |
290 | "The vrf we would like to remove from if non-default\n" |
291 | "The NAME of the vrf\n" | |
e310fc19 DS |
292 | "v4 Starting spot\n" |
293 | "v6 Starting spot\n" | |
294 | "Routes to uninstall\n" | |
ae252c02 DS |
295 | "instance to use\n" |
296 | "Value of instance\n") | |
8a71d93d | 297 | { |
4a7d4737 | 298 | struct vrf *vrf; |
547dc642 DS |
299 | struct prefix prefix; |
300 | ||
301 | sg.r.total_routes = routes; | |
302 | sg.r.removed_routes = 0; | |
303 | uint32_t rts; | |
8a71d93d | 304 | |
b939f6ff | 305 | memset(&prefix, 0, sizeof(prefix)); |
8a71d93d | 306 | |
dbc1bf46 DS |
307 | if (start4.s_addr != 0) { |
308 | prefix.family = AF_INET; | |
309 | prefix.prefixlen = 32; | |
310 | prefix.u.prefix4 = start4; | |
311 | } else { | |
312 | prefix.family = AF_INET6; | |
313 | prefix.prefixlen = 128; | |
314 | prefix.u.prefix6 = start6; | |
315 | } | |
8a71d93d | 316 | |
e429a2a0 | 317 | vrf = vrf_lookup_by_name(vrf_name ? vrf_name : VRF_DEFAULT_NAME); |
4a7d4737 DS |
318 | if (!vrf) { |
319 | vty_out(vty, "The vrf NAME specified: %s does not exist\n", | |
e429a2a0 | 320 | vrf_name ? vrf_name : VRF_DEFAULT_NAME); |
4a7d4737 DS |
321 | return CMD_WARNING; |
322 | } | |
323 | ||
547dc642 | 324 | sg.r.inst = instance; |
4a7d4737 | 325 | sg.r.vrf_id = vrf->vrf_id; |
b939f6ff | 326 | rts = routes; |
0cf08685 DS |
327 | sharp_remove_routes_helper(&prefix, sg.r.vrf_id, |
328 | sg.r.inst, rts); | |
8a71d93d DS |
329 | |
330 | return CMD_SUCCESS; | |
331 | } | |
332 | ||
aaf8c96f DS |
333 | DEFUN_NOSH (show_debugging_sharpd, |
334 | show_debugging_sharpd_cmd, | |
335 | "show debugging [sharp]", | |
336 | SHOW_STR | |
337 | DEBUG_STR | |
338 | "Sharp Information\n") | |
339 | { | |
340 | vty_out(vty, "Sharp debugging status\n"); | |
341 | ||
342 | return CMD_SUCCESS; | |
343 | } | |
344 | ||
8a71d93d DS |
345 | void sharp_vty_init(void) |
346 | { | |
f59e6418 | 347 | install_element(ENABLE_NODE, &install_routes_data_dump_cmd); |
8a71d93d DS |
348 | install_element(ENABLE_NODE, &install_routes_cmd); |
349 | install_element(ENABLE_NODE, &remove_routes_cmd); | |
ab18a495 | 350 | install_element(ENABLE_NODE, &vrf_label_cmd); |
86da53ab | 351 | install_element(ENABLE_NODE, &sharp_nht_data_dump_cmd); |
0ae8130d DS |
352 | install_element(ENABLE_NODE, &watch_nexthop_v6_cmd); |
353 | install_element(ENABLE_NODE, &watch_nexthop_v4_cmd); | |
aaf8c96f DS |
354 | |
355 | install_element(VIEW_NODE, &show_debugging_sharpd_cmd); | |
356 | ||
8a71d93d DS |
357 | return; |
358 | } |