]> git.proxmox.com Git - mirror_frr.git/blame - sharpd/sharp_vty.c
zebra, lib: fix the ZEBRA_INTERFACE_VRF_UPDATE zapi message
[mirror_frr.git] / sharpd / sharp_vty.c
CommitLineData
8a71d93d
DS
1/*
2 * SHARP - vty code
3 * Copyright (C) Cumulus Networks, Inc.
4 * Donald Sharp
5 *
6 * This file is part of FRR.
7 *
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
11 * later version.
12 *
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.
17 *
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
21 */
22#include <zebra.h>
23
24#include "vty.h"
25#include "command.h"
26#include "prefix.h"
27#include "nexthop.h"
28#include "log.h"
ab18a495
DS
29#include "vrf.h"
30#include "zclient.h"
8a71d93d
DS
31
32#include "sharpd/sharp_zebra.h"
33#include "sharpd/sharp_vty.h"
2e4c2296 34#ifndef VTYSH_EXTRACT_PL
8a71d93d 35#include "sharpd/sharp_vty_clippy.c"
2e4c2296 36#endif
8a71d93d
DS
37
38extern uint32_t total_routes;
39extern uint32_t installed_routes;
40extern uint32_t removed_routes;
41
0ae8130d
DS
42DEFPY(watch_nexthop_v6, watch_nexthop_v6_cmd,
43 "sharp watch nexthop X:X::X:X$nhop",
44 "Sharp routing Protocol\n"
45 "Watch for changes\n"
46 "Watch for nexthop changes\n"
47 "The v6 nexthop to signal for watching\n")
48{
49 struct prefix p;
50
51 memset(&p, 0, sizeof(p));
52
53 p.prefixlen = 128;
54 memcpy(&p.u.prefix6, &nhop, 16);
55 p.family = AF_INET6;
56
57 sharp_zebra_nexthop_watch(&p, true);
58
59 return CMD_SUCCESS;
60}
61
62DEFPY(watch_nexthop_v4, watch_nexthop_v4_cmd,
63 "sharp watch nexthop A.B.C.D$nhop",
64 "Sharp routing Protocol\n"
65 "Watch for changes\n"
66 "Watch for nexthop changes\n"
67 "The v4 nexthop to signal for watching\n")
68{
69 struct prefix p;
70
71 memset(&p, 0, sizeof(p));
72
73 p.prefixlen = 32;
74 p.u.prefix4 = nhop;
75 p.family = AF_INET;
76
77 sharp_zebra_nexthop_watch(&p, true);
78
79 return CMD_SUCCESS;
80}
81
8a71d93d
DS
82DEFPY (install_routes,
83 install_routes_cmd,
ba041bea 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]",
75239f4f 85 "Sharp routing Protocol\n"
8a71d93d
DS
86 "install some routes\n"
87 "Routes to install\n"
88 "Address to start /32 generation at\n"
ba041bea
DS
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"
ae252c02
DS
92 "How many to create\n"
93 "Instance to use\n"
94 "Instance\n")
8a71d93d
DS
95{
96 int i;
97 struct prefix p;
98 struct nexthop nhop;
99 uint32_t temp;
100
101 total_routes = routes;
102 installed_routes = 0;
103
104 memset(&p, 0, sizeof(p));
105 memset(&nhop, 0, sizeof(nhop));
106
107 p.family = AF_INET;
108 p.prefixlen = 32;
109 p.u.prefix4 = start;
110
ba041bea
DS
111 if (nexthop4.s_addr != INADDR_ANY) {
112 nhop.gate.ipv4 = nexthop4;
113 nhop.type = NEXTHOP_TYPE_IPV4;
114 } else {
115 memcpy(&nhop.gate.ipv6, &nexthop6, IPV6_MAX_BYTELEN);
116 nhop.type = NEXTHOP_TYPE_IPV6;
117 }
8a71d93d
DS
118
119 zlog_debug("Inserting %ld routes", routes);
120
121 temp = ntohl(p.u.prefix4.s_addr);
996c9314 122 for (i = 0; i < routes; i++) {
ae252c02 123 route_add(&p, (uint8_t)instance, &nhop);
8a71d93d
DS
124 p.u.prefix4.s_addr = htonl(++temp);
125 }
126
127 return CMD_SUCCESS;
128}
129
42567e00 130DEFPY(vrf_label, vrf_label_cmd,
7d061b3c 131 "sharp label <ip$ipv4|ipv6$ipv6> vrf NAME$name label (0-100000)$label",
75239f4f 132 "Sharp Routing Protocol\n"
ab18a495 133 "Give a vrf a label\n"
7d061b3c
DS
134 "Pop and forward for IPv4\n"
135 "Pop and forward for IPv6\n"
ab18a495 136 VRF_CMD_HELP_STR
42567e00 137 "The label to use, 0 specifies remove the label installed from previous\n"
ab18a495
DS
138 "Specified range to use\n")
139{
140 struct vrf *vrf;
7d061b3c 141 afi_t afi = (ipv4) ? AFI_IP : AFI_IP6;
ab18a495
DS
142
143 if (strcmp(name, "default") == 0)
144 vrf = vrf_lookup_by_id(VRF_DEFAULT);
145 else
146 vrf = vrf_lookup_by_name(name);
147
148 if (!vrf) {
149 vty_out(vty, "Unable to find vrf you silly head");
150 return CMD_WARNING_CONFIG_FAILED;
151 }
152
42567e00
DS
153 if (label == 0)
154 label = MPLS_LABEL_NONE;
155
7d061b3c 156 vrf_label_add(vrf->vrf_id, afi, label);
ab18a495
DS
157 return CMD_SUCCESS;
158}
159
8a71d93d
DS
160DEFPY (remove_routes,
161 remove_routes_cmd,
ae252c02 162 "sharp remove routes A.B.C.D$start (1-1000000)$routes [instance (0-255)$instance]",
75239f4f 163 "Sharp Routing Protocol\n"
8a71d93d
DS
164 "Remove some routes\n"
165 "Routes to remove\n"
166 "Starting spot\n"
ae252c02
DS
167 "Routes to uniinstall\n"
168 "instance to use\n"
169 "Value of instance\n")
8a71d93d
DS
170{
171 int i;
172 struct prefix p;
173 uint32_t temp;
8a71d93d
DS
174 total_routes = routes;
175 removed_routes = 0;
176
177 memset(&p, 0, sizeof(p));
178
179 p.family = AF_INET;
180 p.prefixlen = 32;
181 p.u.prefix4 = start;
182
183 zlog_debug("Removing %ld routes", routes);
184
185 temp = ntohl(p.u.prefix4.s_addr);
996c9314 186 for (i = 0; i < routes; i++) {
ae252c02 187 route_delete(&p, (uint8_t)instance);
8a71d93d
DS
188 p.u.prefix4.s_addr = htonl(++temp);
189 }
190
191 return CMD_SUCCESS;
192}
193
aaf8c96f
DS
194DEFUN_NOSH (show_debugging_sharpd,
195 show_debugging_sharpd_cmd,
196 "show debugging [sharp]",
197 SHOW_STR
198 DEBUG_STR
199 "Sharp Information\n")
200{
201 vty_out(vty, "Sharp debugging status\n");
202
203 return CMD_SUCCESS;
204}
205
8a71d93d
DS
206void sharp_vty_init(void)
207{
208 install_element(ENABLE_NODE, &install_routes_cmd);
209 install_element(ENABLE_NODE, &remove_routes_cmd);
ab18a495 210 install_element(ENABLE_NODE, &vrf_label_cmd);
0ae8130d
DS
211 install_element(ENABLE_NODE, &watch_nexthop_v6_cmd);
212 install_element(ENABLE_NODE, &watch_nexthop_v4_cmd);
aaf8c96f
DS
213
214 install_element(VIEW_NODE, &show_debugging_sharpd_cmd);
215
8a71d93d
DS
216 return;
217}