]>
Commit | Line | Data |
---|---|---|
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 | |
38 | extern uint32_t total_routes; | |
39 | extern uint32_t installed_routes; | |
40 | extern uint32_t removed_routes; | |
41 | ||
42 | DEFPY (install_routes, | |
43 | install_routes_cmd, | |
75239f4f DS |
44 | "sharp install routes A.B.C.D$start nexthop A.B.C.D$nexthop (1-1000000)$routes", |
45 | "Sharp routing Protocol\n" | |
8a71d93d DS |
46 | "install some routes\n" |
47 | "Routes to install\n" | |
48 | "Address to start /32 generation at\n" | |
49 | "Nexthop to use\n" | |
50 | "Nexthop address\n" | |
51 | "How many to create\n") | |
52 | { | |
53 | int i; | |
54 | struct prefix p; | |
55 | struct nexthop nhop; | |
56 | uint32_t temp; | |
57 | ||
58 | total_routes = routes; | |
59 | installed_routes = 0; | |
60 | ||
61 | memset(&p, 0, sizeof(p)); | |
62 | memset(&nhop, 0, sizeof(nhop)); | |
63 | ||
64 | p.family = AF_INET; | |
65 | p.prefixlen = 32; | |
66 | p.u.prefix4 = start; | |
67 | ||
68 | nhop.gate.ipv4 = nexthop; | |
69 | nhop.type = NEXTHOP_TYPE_IPV4; | |
70 | ||
71 | zlog_debug("Inserting %ld routes", routes); | |
72 | ||
73 | temp = ntohl(p.u.prefix4.s_addr); | |
996c9314 | 74 | for (i = 0; i < routes; i++) { |
8a71d93d DS |
75 | route_add(&p, &nhop); |
76 | p.u.prefix4.s_addr = htonl(++temp); | |
77 | } | |
78 | ||
79 | return CMD_SUCCESS; | |
80 | } | |
81 | ||
42567e00 | 82 | DEFPY(vrf_label, vrf_label_cmd, |
7d061b3c | 83 | "sharp label <ip$ipv4|ipv6$ipv6> vrf NAME$name label (0-100000)$label", |
75239f4f | 84 | "Sharp Routing Protocol\n" |
ab18a495 | 85 | "Give a vrf a label\n" |
7d061b3c DS |
86 | "Pop and forward for IPv4\n" |
87 | "Pop and forward for IPv6\n" | |
ab18a495 | 88 | VRF_CMD_HELP_STR |
42567e00 | 89 | "The label to use, 0 specifies remove the label installed from previous\n" |
ab18a495 DS |
90 | "Specified range to use\n") |
91 | { | |
92 | struct vrf *vrf; | |
7d061b3c | 93 | afi_t afi = (ipv4) ? AFI_IP : AFI_IP6; |
ab18a495 DS |
94 | |
95 | if (strcmp(name, "default") == 0) | |
96 | vrf = vrf_lookup_by_id(VRF_DEFAULT); | |
97 | else | |
98 | vrf = vrf_lookup_by_name(name); | |
99 | ||
100 | if (!vrf) { | |
101 | vty_out(vty, "Unable to find vrf you silly head"); | |
102 | return CMD_WARNING_CONFIG_FAILED; | |
103 | } | |
104 | ||
42567e00 DS |
105 | if (label == 0) |
106 | label = MPLS_LABEL_NONE; | |
107 | ||
7d061b3c | 108 | vrf_label_add(vrf->vrf_id, afi, label); |
ab18a495 DS |
109 | return CMD_SUCCESS; |
110 | } | |
111 | ||
8a71d93d DS |
112 | DEFPY (remove_routes, |
113 | remove_routes_cmd, | |
75239f4f DS |
114 | "sharp remove routes A.B.C.D$start (1-1000000)$routes", |
115 | "Sharp Routing Protocol\n" | |
8a71d93d DS |
116 | "Remove some routes\n" |
117 | "Routes to remove\n" | |
118 | "Starting spot\n" | |
119 | "Routes to uniinstall\n") | |
120 | { | |
121 | int i; | |
122 | struct prefix p; | |
123 | uint32_t temp; | |
124 | ||
125 | total_routes = routes; | |
126 | removed_routes = 0; | |
127 | ||
128 | memset(&p, 0, sizeof(p)); | |
129 | ||
130 | p.family = AF_INET; | |
131 | p.prefixlen = 32; | |
132 | p.u.prefix4 = start; | |
133 | ||
134 | zlog_debug("Removing %ld routes", routes); | |
135 | ||
136 | temp = ntohl(p.u.prefix4.s_addr); | |
996c9314 | 137 | for (i = 0; i < routes; i++) { |
8a71d93d DS |
138 | route_delete(&p); |
139 | p.u.prefix4.s_addr = htonl(++temp); | |
140 | } | |
141 | ||
142 | return CMD_SUCCESS; | |
143 | } | |
144 | ||
145 | void sharp_vty_init(void) | |
146 | { | |
147 | install_element(ENABLE_NODE, &install_routes_cmd); | |
148 | install_element(ENABLE_NODE, &remove_routes_cmd); | |
ab18a495 | 149 | install_element(ENABLE_NODE, &vrf_label_cmd); |
8a71d93d DS |
150 | return; |
151 | } |