3 * Copyright (C) Cumulus Networks, Inc.
6 * This file is part of FRR.
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
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.
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
31 #include "nexthop_group.h"
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"
41 DEFPY(watch_nexthop_v6
, watch_nexthop_v6_cmd
,
42 "sharp watch [vrf NAME$name] <nexthop$n|import$import> X:X::X:X$nhop [connected$connected]",
43 "Sharp routing Protocol\n"
45 "The vrf we would like to watch if non-default\n"
46 "The NAME of the vrf\n"
47 "Watch for nexthop changes\n"
48 "Watch for import check changes\n"
49 "The v6 nexthop to signal for watching\n"
50 "Should the route be connected\n")
57 name
= VRF_DEFAULT_NAME
;
58 vrf
= vrf_lookup_by_name(name
);
60 vty_out(vty
, "The vrf NAME specified: %s does not exist\n",
70 memset(&p
, 0, sizeof(p
));
73 memcpy(&p
.u
.prefix6
, &nhop
, 16);
76 sharp_nh_tracker_get(&p
);
77 sharp_zebra_nexthop_watch(&p
, vrf
->vrf_id
, type_import
,
83 DEFPY(watch_nexthop_v4
, watch_nexthop_v4_cmd
,
84 "sharp watch [vrf NAME$name] <nexthop$n|import$import> A.B.C.D$nhop [connected$connected]",
85 "Sharp routing Protocol\n"
87 "The vrf we would like to watch if non-default\n"
88 "The NAME of the vrf\n"
89 "Watch for nexthop changes\n"
90 "Watch for import check changes\n"
91 "The v4 nexthop to signal for watching\n"
92 "Should the route be connected\n")
99 name
= VRF_DEFAULT_NAME
;
100 vrf
= vrf_lookup_by_name(name
);
102 vty_out(vty
, "The vrf NAME specified: %s does not exist\n",
107 memset(&p
, 0, sizeof(p
));
118 sharp_nh_tracker_get(&p
);
119 sharp_zebra_nexthop_watch(&p
, vrf
->vrf_id
, type_import
,
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"
132 sharp_nh_tracker_dump(vty
);
137 DEFPY (install_routes_data_dump
,
138 install_routes_data_dump_cmd
,
140 "Sharp routing Protocol\n"
141 "Data about what is going on\n"
142 "Route Install/Removal Information\n")
144 char buf
[PREFIX_STRLEN
];
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
)),
151 sg
.r
.installed_routes
,
153 r
.tv_sec
, (long int)r
.tv_usec
);
158 DEFPY (install_routes
,
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]",
161 "Sharp routing Protocol\n"
162 "install some routes\n"
163 "Routes to install\n"
164 "The vrf we would like to install into if non-default\n"
165 "The NAME of the vrf\n"
166 "v4 Address to start /32 generation at\n"
167 "v6 Address to start /32 generation at\n"
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"
171 "Nexthop-Group to use\n"
172 "The Name of the nexthop-group\n"
173 "How many to create\n"
176 "Should we repeat this command\n"
177 "How many times to repeat this command\n")
180 struct prefix prefix
;
183 sg
.r
.total_routes
= routes
;
184 sg
.r
.installed_routes
= 0;
187 sg
.r
.repeat
= rpt
* 2;
191 memset(&prefix
, 0, sizeof(prefix
));
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
));
196 if (start4
.s_addr
!= 0) {
197 prefix
.family
= AF_INET
;
198 prefix
.prefixlen
= 32;
199 prefix
.u
.prefix4
= start4
;
201 prefix
.family
= AF_INET6
;
202 prefix
.prefixlen
= 128;
203 prefix
.u
.prefix6
= start6
;
205 sg
.r
.orig_prefix
= prefix
;
208 name
= VRF_DEFAULT_NAME
;
210 vrf
= vrf_lookup_by_name(name
);
212 vty_out(vty
, "The vrf NAME specified: %s does not exist\n",
218 struct nexthop_group_cmd
*nhgc
= nhgc_find(nexthop_group
);
221 "Specified Nexthop Group: %s does not exist\n",
226 sg
.r
.nhop_group
.nexthop
= nhgc
->nhg
.nexthop
;
228 if (nexthop4
.s_addr
!= INADDR_ANY
) {
229 sg
.r
.nhop
.gate
.ipv4
= nexthop4
;
230 sg
.r
.nhop
.type
= NEXTHOP_TYPE_IPV4
;
232 sg
.r
.nhop
.gate
.ipv6
= nexthop6
;
233 sg
.r
.nhop
.type
= NEXTHOP_TYPE_IPV6
;
236 sg
.r
.nhop
.vrf_id
= vrf
->vrf_id
;
237 sg
.r
.nhop_group
.nexthop
= &sg
.r
.nhop
;
240 sg
.r
.inst
= instance
;
241 sg
.r
.vrf_id
= vrf
->vrf_id
;
243 sharp_install_routes_helper(&prefix
, sg
.r
.vrf_id
,
244 sg
.r
.inst
, &sg
.r
.nhop_group
, rts
);
249 DEFPY(vrf_label
, vrf_label_cmd
,
250 "sharp label <ip$ipv4|ipv6$ipv6> vrf NAME$name label (0-100000)$label",
251 "Sharp Routing Protocol\n"
252 "Give a vrf a label\n"
253 "Pop and forward for IPv4\n"
254 "Pop and forward for IPv6\n"
256 "The label to use, 0 specifies remove the label installed from previous\n"
257 "Specified range to use\n")
260 afi_t afi
= (ipv4
) ? AFI_IP
: AFI_IP6
;
262 if (strcmp(name
, "default") == 0)
263 vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
265 vrf
= vrf_lookup_by_name(name
);
268 vty_out(vty
, "Unable to find vrf you silly head");
269 return CMD_WARNING_CONFIG_FAILED
;
273 label
= MPLS_LABEL_NONE
;
275 vrf_label_add(vrf
->vrf_id
, afi
, label
);
279 DEFPY (remove_routes
,
281 "sharp remove routes [vrf NAME$name] <A.B.C.D$start4|X:X::X:X$start6> (1-1000000)$routes [instance (0-255)$instance]",
282 "Sharp Routing Protocol\n"
283 "Remove some routes\n"
285 "The vrf we would like to remove from if non-default\n"
286 "The NAME of the vrf\n"
289 "Routes to uninstall\n"
291 "Value of instance\n")
294 struct prefix prefix
;
296 sg
.r
.total_routes
= routes
;
297 sg
.r
.removed_routes
= 0;
300 memset(&prefix
, 0, sizeof(prefix
));
302 if (start4
.s_addr
!= 0) {
303 prefix
.family
= AF_INET
;
304 prefix
.prefixlen
= 32;
305 prefix
.u
.prefix4
= start4
;
307 prefix
.family
= AF_INET6
;
308 prefix
.prefixlen
= 128;
309 prefix
.u
.prefix6
= start6
;
312 vrf
= vrf_lookup_by_name(name
? name
: VRF_DEFAULT_NAME
);
314 vty_out(vty
, "The vrf NAME specified: %s does not exist\n",
315 name
? name
: VRF_DEFAULT_NAME
);
319 sg
.r
.inst
= instance
;
320 sg
.r
.vrf_id
= vrf
->vrf_id
;
322 sharp_remove_routes_helper(&prefix
, sg
.r
.vrf_id
,
328 DEFUN_NOSH (show_debugging_sharpd
,
329 show_debugging_sharpd_cmd
,
330 "show debugging [sharp]",
333 "Sharp Information\n")
335 vty_out(vty
, "Sharp debugging status\n");
340 void sharp_vty_init(void)
342 install_element(ENABLE_NODE
, &install_routes_data_dump_cmd
);
343 install_element(ENABLE_NODE
, &install_routes_cmd
);
344 install_element(ENABLE_NODE
, &remove_routes_cmd
);
345 install_element(ENABLE_NODE
, &vrf_label_cmd
);
346 install_element(ENABLE_NODE
, &sharp_nht_data_dump_cmd
);
347 install_element(ENABLE_NODE
, &watch_nexthop_v6_cmd
);
348 install_element(ENABLE_NODE
, &watch_nexthop_v4_cmd
);
350 install_element(VIEW_NODE
, &show_debugging_sharpd_cmd
);