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 nexthop X:X::X:X$nhop [connected$connected]",
43 "Sharp routing Protocol\n"
45 "Watch for nexthop changes\n"
46 "The v6 nexthop to signal for watching\n"
47 "Should the route be connected\n")
51 memset(&p
, 0, sizeof(p
));
54 memcpy(&p
.u
.prefix6
, &nhop
, 16);
57 sharp_nh_tracker_get(&p
);
58 sharp_zebra_nexthop_watch(&p
, true, !!connected
);
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"
67 "Watch for nexthop changes\n"
68 "The v4 nexthop to signal for watching\n"
69 "Should the route be connected\n")
73 memset(&p
, 0, sizeof(p
));
79 sharp_nh_tracker_get(&p
);
80 sharp_zebra_nexthop_watch(&p
, true, !!connected
);
85 DEFPY(sharp_nht_data_dump
,
86 sharp_nht_data_dump_cmd
,
88 "Sharp routing Protocol\n"
89 "Nexthop information\n"
92 sharp_nh_tracker_dump(vty
);
97 DEFPY (install_routes_data_dump
,
98 install_routes_data_dump_cmd
,
100 "Sharp routing Protocol\n"
101 "Data about what is going on\n"
102 "Route Install/Removal Information\n")
104 char buf
[PREFIX_STRLEN
];
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
)),
111 sg
.r
.installed_routes
,
113 r
.tv_sec
, r
.tv_usec
);
118 DEFPY (install_routes
,
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"
134 "Should we repeat this command\n"
135 "How many times to repeat this command\n")
137 struct prefix prefix
;
140 sg
.r
.total_routes
= routes
;
141 sg
.r
.installed_routes
= 0;
144 sg
.r
.repeat
= rpt
* 2;
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
));
153 if (start4
.s_addr
!= 0) {
154 prefix
.family
= AF_INET
;
155 prefix
.prefixlen
= 32;
156 prefix
.u
.prefix4
= start4
;
158 prefix
.family
= AF_INET6
;
159 prefix
.prefixlen
= 128;
160 prefix
.u
.prefix6
= start6
;
162 sg
.r
.orig_prefix
= prefix
;
165 struct nexthop_group_cmd
*nhgc
= nhgc_find(nexthop_group
);
168 "Specified Nexthop Group: %s does not exist\n",
173 sg
.r
.nhop_group
.nexthop
= nhgc
->nhg
.nexthop
;
175 if (nexthop4
.s_addr
!= INADDR_ANY
) {
176 sg
.r
.nhop
.gate
.ipv4
= nexthop4
;
177 sg
.r
.nhop
.type
= NEXTHOP_TYPE_IPV4
;
179 sg
.r
.nhop
.gate
.ipv6
= nexthop6
;
180 sg
.r
.nhop
.type
= NEXTHOP_TYPE_IPV6
;
183 sg
.r
.nhop_group
.nexthop
= &sg
.r
.nhop
;
186 sg
.r
.inst
= instance
;
188 sharp_install_routes_helper(&prefix
, sg
.r
.inst
, &sg
.r
.nhop_group
, rts
);
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"
200 "The label to use, 0 specifies remove the label installed from previous\n"
201 "Specified range to use\n")
204 afi_t afi
= (ipv4
) ? AFI_IP
: AFI_IP6
;
206 if (strcmp(name
, "default") == 0)
207 vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
209 vrf
= vrf_lookup_by_name(name
);
212 vty_out(vty
, "Unable to find vrf you silly head");
213 return CMD_WARNING_CONFIG_FAILED
;
217 label
= MPLS_LABEL_NONE
;
219 vrf_label_add(vrf
->vrf_id
, afi
, label
);
223 DEFPY (remove_routes
,
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"
231 "Routes to uninstall\n"
233 "Value of instance\n")
235 struct prefix prefix
;
237 sg
.r
.total_routes
= routes
;
238 sg
.r
.removed_routes
= 0;
241 memset(&prefix
, 0, sizeof(prefix
));
243 if (start4
.s_addr
!= 0) {
244 prefix
.family
= AF_INET
;
245 prefix
.prefixlen
= 32;
246 prefix
.u
.prefix4
= start4
;
248 prefix
.family
= AF_INET6
;
249 prefix
.prefixlen
= 128;
250 prefix
.u
.prefix6
= start6
;
253 sg
.r
.inst
= instance
;
255 sharp_remove_routes_helper(&prefix
, sg
.r
.inst
, rts
);
260 DEFUN_NOSH (show_debugging_sharpd
,
261 show_debugging_sharpd_cmd
,
262 "show debugging [sharp]",
265 "Sharp Information\n")
267 vty_out(vty
, "Sharp debugging status\n");
272 void sharp_vty_init(void)
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
);
282 install_element(VIEW_NODE
, &show_debugging_sharpd_cmd
);