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