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
32 #include "sharpd/sharp_zebra.h"
33 #include "sharpd/sharp_vty.h"
34 #ifndef VTYSH_EXTRACT_PL
35 #include "sharpd/sharp_vty_clippy.c"
38 extern uint32_t total_routes
;
39 extern uint32_t installed_routes
;
40 extern uint32_t removed_routes
;
42 DEFPY(watch_nexthop_v6
, watch_nexthop_v6_cmd
,
43 "sharp watch nexthop X:X::X:X$nhop",
44 "Sharp routing Protocol\n"
46 "Watch for nexthop changes\n"
47 "The v6 nexthop to signal for watching\n")
51 memset(&p
, 0, sizeof(p
));
54 memcpy(&p
.u
.prefix6
, &nhop
, 16);
57 sharp_zebra_nexthop_watch(&p
, true);
62 DEFPY(watch_nexthop_v4
, watch_nexthop_v4_cmd
,
63 "sharp watch nexthop A.B.C.D$nhop",
64 "Sharp routing Protocol\n"
66 "Watch for nexthop changes\n"
67 "The v4 nexthop to signal for watching\n")
71 memset(&p
, 0, sizeof(p
));
77 sharp_zebra_nexthop_watch(&p
, true);
82 DEFPY (install_routes
,
84 "sharp install routes A.B.C.D$start nexthop <A.B.C.D$nexthop4|X:X::X:X$nexthop6> (1-1000000)$routes [instance (0-255)$instance]",
85 "Sharp routing Protocol\n"
86 "install some routes\n"
88 "Address to start /32 generation at\n"
89 "Nexthop to use(Can be an IPv4 or IPv6 address)\n"
90 "V4 Nexthop address to use\n"
91 "V6 Nexthop address to use\n"
92 "How many to create\n"
101 total_routes
= routes
;
102 installed_routes
= 0;
104 memset(&p
, 0, sizeof(p
));
105 memset(&nhop
, 0, sizeof(nhop
));
111 if (nexthop4
.s_addr
!= INADDR_ANY
) {
112 nhop
.gate
.ipv4
= nexthop4
;
113 nhop
.type
= NEXTHOP_TYPE_IPV4
;
115 memcpy(&nhop
.gate
.ipv6
, &nexthop6
, IPV6_MAX_BYTELEN
);
116 nhop
.type
= NEXTHOP_TYPE_IPV6
;
119 zlog_debug("Inserting %ld routes", routes
);
121 temp
= ntohl(p
.u
.prefix4
.s_addr
);
122 for (i
= 0; i
< routes
; i
++) {
123 route_add(&p
, (uint8_t)instance
, &nhop
);
124 p
.u
.prefix4
.s_addr
= htonl(++temp
);
130 DEFPY(vrf_label
, vrf_label_cmd
,
131 "sharp label <ip$ipv4|ipv6$ipv6> vrf NAME$name label (0-100000)$label",
132 "Sharp Routing Protocol\n"
133 "Give a vrf a label\n"
134 "Pop and forward for IPv4\n"
135 "Pop and forward for IPv6\n"
137 "The label to use, 0 specifies remove the label installed from previous\n"
138 "Specified range to use\n")
141 afi_t afi
= (ipv4
) ? AFI_IP
: AFI_IP6
;
143 if (strcmp(name
, "default") == 0)
144 vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
146 vrf
= vrf_lookup_by_name(name
);
149 vty_out(vty
, "Unable to find vrf you silly head");
150 return CMD_WARNING_CONFIG_FAILED
;
154 label
= MPLS_LABEL_NONE
;
156 vrf_label_add(vrf
->vrf_id
, afi
, label
);
160 DEFPY (remove_routes
,
162 "sharp remove routes A.B.C.D$start (1-1000000)$routes [instance (0-255)$instance]",
163 "Sharp Routing Protocol\n"
164 "Remove some routes\n"
167 "Routes to uniinstall\n"
169 "Value of instance\n")
174 total_routes
= routes
;
177 memset(&p
, 0, sizeof(p
));
183 zlog_debug("Removing %ld routes", routes
);
185 temp
= ntohl(p
.u
.prefix4
.s_addr
);
186 for (i
= 0; i
< routes
; i
++) {
187 route_delete(&p
, (uint8_t)instance
);
188 p
.u
.prefix4
.s_addr
= htonl(++temp
);
194 DEFUN_NOSH (show_debugging_sharpd
,
195 show_debugging_sharpd_cmd
,
196 "show debugging [sharp]",
199 "Sharp Information\n")
201 vty_out(vty
, "Sharp debugging status\n");
206 void sharp_vty_init(void)
208 install_element(ENABLE_NODE
, &install_routes_cmd
);
209 install_element(ENABLE_NODE
, &remove_routes_cmd
);
210 install_element(ENABLE_NODE
, &vrf_label_cmd
);
211 install_element(ENABLE_NODE
, &watch_nexthop_v6_cmd
);
212 install_element(ENABLE_NODE
, &watch_nexthop_v4_cmd
);
214 install_element(VIEW_NODE
, &show_debugging_sharpd_cmd
);