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$start <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 "Address to start /32 generation at\n"
98 "Nexthop to use(Can be an IPv4 or IPv6 address)\n"
99 "V4 Nexthop address to use\n"
100 "V6 Nexthop address to use\n"
101 "Nexthop-Group to use\n"
102 "The Name of the nexthop-group\n"
103 "How many to create\n"
106 "Should we repeat this command\n"
107 "How many times to repeat this command\n")
109 total_routes
= routes
;
110 installed_routes
= 0;
117 memset(&prefix
, 0, sizeof(prefix
));
118 memset(&orig_prefix
, 0, sizeof(orig_prefix
));
119 memset(&nhop
, 0, sizeof(nhop
));
120 memset(&nhop_group
, 0, sizeof(nhop_group
));
122 prefix
.family
= AF_INET
;
123 prefix
.prefixlen
= 32;
124 prefix
.u
.prefix4
= start
;
125 orig_prefix
= prefix
;
128 struct nexthop_group_cmd
*nhgc
= nhgc_find(nexthop_group
);
131 "Specified Nexthop Group: %s does not exist\n",
136 nhop_group
.nexthop
= nhgc
->nhg
.nexthop
;
138 if (nexthop4
.s_addr
!= INADDR_ANY
) {
139 nhop
.gate
.ipv4
= nexthop4
;
140 nhop
.type
= NEXTHOP_TYPE_IPV4
;
142 nhop
.gate
.ipv6
= nexthop6
;
143 nhop
.type
= NEXTHOP_TYPE_IPV6
;
146 nhop_group
.nexthop
= &nhop
;
151 sharp_install_routes_helper(&prefix
, inst
, &nhop_group
, rts
);
156 DEFPY(vrf_label
, vrf_label_cmd
,
157 "sharp label <ip$ipv4|ipv6$ipv6> vrf NAME$name label (0-100000)$label",
158 "Sharp Routing Protocol\n"
159 "Give a vrf a label\n"
160 "Pop and forward for IPv4\n"
161 "Pop and forward for IPv6\n"
163 "The label to use, 0 specifies remove the label installed from previous\n"
164 "Specified range to use\n")
167 afi_t afi
= (ipv4
) ? AFI_IP
: AFI_IP6
;
169 if (strcmp(name
, "default") == 0)
170 vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
172 vrf
= vrf_lookup_by_name(name
);
175 vty_out(vty
, "Unable to find vrf you silly head");
176 return CMD_WARNING_CONFIG_FAILED
;
180 label
= MPLS_LABEL_NONE
;
182 vrf_label_add(vrf
->vrf_id
, afi
, label
);
186 DEFPY (remove_routes
,
188 "sharp remove routes A.B.C.D$start (1-1000000)$routes [instance (0-255)$instance]",
189 "Sharp Routing Protocol\n"
190 "Remove some routes\n"
193 "Routes to uniinstall\n"
195 "Value of instance\n")
197 total_routes
= routes
;
200 memset(&prefix
, 0, sizeof(prefix
));
202 prefix
.family
= AF_INET
;
203 prefix
.prefixlen
= 32;
204 prefix
.u
.prefix4
= start
;
208 sharp_remove_routes_helper(&prefix
, inst
, rts
);
213 DEFUN_NOSH (show_debugging_sharpd
,
214 show_debugging_sharpd_cmd
,
215 "show debugging [sharp]",
218 "Sharp Information\n")
220 vty_out(vty
, "Sharp debugging status\n");
225 void sharp_vty_init(void)
227 install_element(ENABLE_NODE
, &install_routes_cmd
);
228 install_element(ENABLE_NODE
, &remove_routes_cmd
);
229 install_element(ENABLE_NODE
, &vrf_label_cmd
);
230 install_element(ENABLE_NODE
, &watch_nexthop_v6_cmd
);
231 install_element(ENABLE_NODE
, &watch_nexthop_v4_cmd
);
233 install_element(VIEW_NODE
, &show_debugging_sharpd_cmd
);