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_zebra.h"
34 #include "sharpd/sharp_vty.h"
35 #ifndef VTYSH_EXTRACT_PL
36 #include "sharpd/sharp_vty_clippy.c"
39 extern uint32_t total_routes
;
40 extern uint32_t installed_routes
;
41 extern uint32_t removed_routes
;
45 struct prefix orig_prefix
;
47 struct nexthop_group nhop_group
;
51 DEFPY(watch_nexthop_v6
, watch_nexthop_v6_cmd
,
52 "sharp watch nexthop X:X::X:X$nhop",
53 "Sharp routing Protocol\n"
55 "Watch for nexthop changes\n"
56 "The v6 nexthop to signal for watching\n")
60 memset(&p
, 0, sizeof(p
));
63 memcpy(&p
.u
.prefix6
, &nhop
, 16);
66 sharp_zebra_nexthop_watch(&p
, true);
71 DEFPY(watch_nexthop_v4
, watch_nexthop_v4_cmd
,
72 "sharp watch nexthop A.B.C.D$nhop",
73 "Sharp routing Protocol\n"
75 "Watch for nexthop changes\n"
76 "The v4 nexthop to signal for watching\n")
80 memset(&p
, 0, sizeof(p
));
86 sharp_zebra_nexthop_watch(&p
, true);
91 DEFPY (install_routes
,
93 "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]",
94 "Sharp routing Protocol\n"
95 "install some routes\n"
97 "v4 Address to start /32 generation at\n"
98 "v6 Address to start /32 generation at\n"
99 "Nexthop to use(Can be an IPv4 or IPv6 address)\n"
100 "V4 Nexthop address to use\n"
101 "V6 Nexthop address to use\n"
102 "Nexthop-Group to use\n"
103 "The Name of the nexthop-group\n"
104 "How many to create\n"
107 "Should we repeat this command\n"
108 "How many times to repeat this command\n")
110 total_routes
= routes
;
111 installed_routes
= 0;
118 memset(&prefix
, 0, sizeof(prefix
));
119 memset(&orig_prefix
, 0, sizeof(orig_prefix
));
120 memset(&nhop
, 0, sizeof(nhop
));
121 memset(&nhop_group
, 0, sizeof(nhop_group
));
123 if (start4
.s_addr
!= 0) {
124 prefix
.family
= AF_INET
;
125 prefix
.prefixlen
= 32;
126 prefix
.u
.prefix4
= start4
;
128 prefix
.family
= AF_INET6
;
129 prefix
.prefixlen
= 128;
130 prefix
.u
.prefix6
= start6
;
132 orig_prefix
= prefix
;
135 struct nexthop_group_cmd
*nhgc
= nhgc_find(nexthop_group
);
138 "Specified Nexthop Group: %s does not exist\n",
143 nhop_group
.nexthop
= nhgc
->nhg
.nexthop
;
145 if (nexthop4
.s_addr
!= INADDR_ANY
) {
146 nhop
.gate
.ipv4
= nexthop4
;
147 nhop
.type
= NEXTHOP_TYPE_IPV4
;
149 nhop
.gate
.ipv6
= nexthop6
;
150 nhop
.type
= NEXTHOP_TYPE_IPV6
;
153 nhop_group
.nexthop
= &nhop
;
158 sharp_install_routes_helper(&prefix
, inst
, &nhop_group
, rts
);
163 DEFPY(vrf_label
, vrf_label_cmd
,
164 "sharp label <ip$ipv4|ipv6$ipv6> vrf NAME$name label (0-100000)$label",
165 "Sharp Routing Protocol\n"
166 "Give a vrf a label\n"
167 "Pop and forward for IPv4\n"
168 "Pop and forward for IPv6\n"
170 "The label to use, 0 specifies remove the label installed from previous\n"
171 "Specified range to use\n")
174 afi_t afi
= (ipv4
) ? AFI_IP
: AFI_IP6
;
176 if (strcmp(name
, "default") == 0)
177 vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
179 vrf
= vrf_lookup_by_name(name
);
182 vty_out(vty
, "Unable to find vrf you silly head");
183 return CMD_WARNING_CONFIG_FAILED
;
187 label
= MPLS_LABEL_NONE
;
189 vrf_label_add(vrf
->vrf_id
, afi
, label
);
193 DEFPY (remove_routes
,
195 "sharp remove routes <A.B.C.D$start4|X:X::X:X$start6> (1-1000000)$routes [instance (0-255)$instance]",
196 "Sharp Routing Protocol\n"
197 "Remove some routes\n"
201 "Routes to uninstall\n"
203 "Value of instance\n")
205 total_routes
= routes
;
208 memset(&prefix
, 0, sizeof(prefix
));
210 if (start4
.s_addr
!= 0) {
211 prefix
.family
= AF_INET
;
212 prefix
.prefixlen
= 32;
213 prefix
.u
.prefix4
= start4
;
215 prefix
.family
= AF_INET6
;
216 prefix
.prefixlen
= 128;
217 prefix
.u
.prefix6
= start6
;
222 sharp_remove_routes_helper(&prefix
, inst
, rts
);
227 DEFUN_NOSH (show_debugging_sharpd
,
228 show_debugging_sharpd_cmd
,
229 "show debugging [sharp]",
232 "Sharp Information\n")
234 vty_out(vty
, "Sharp debugging status\n");
239 void sharp_vty_init(void)
241 install_element(ENABLE_NODE
, &install_routes_cmd
);
242 install_element(ENABLE_NODE
, &remove_routes_cmd
);
243 install_element(ENABLE_NODE
, &vrf_label_cmd
);
244 install_element(ENABLE_NODE
, &watch_nexthop_v6_cmd
);
245 install_element(ENABLE_NODE
, &watch_nexthop_v4_cmd
);
247 install_element(VIEW_NODE
, &show_debugging_sharpd_cmd
);