]>
Commit | Line | Data |
---|---|---|
707656ec RW |
1 | /* |
2 | * Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro <kunihiro@zebra.org> | |
3 | * Copyright (C) 2018 NetDEF, Inc. | |
4 | * Renato Westphal | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License as published by the Free | |
8 | * Software Foundation; either version 2 of the License, or (at your option) | |
9 | * any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
14 | * more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License along | |
17 | * with this program; see the file COPYING; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | */ | |
20 | ||
21 | #include <zebra.h> | |
22 | ||
23 | #include "if.h" | |
24 | #include "vrf.h" | |
25 | #include "log.h" | |
26 | #include "prefix.h" | |
27 | #include "command.h" | |
28 | #include "northbound_cli.h" | |
29 | #include "libfrr.h" | |
30 | ||
31 | #include "ripd/ripd.h" | |
32 | #include "ripd/rip_cli.h" | |
33 | #ifndef VTYSH_EXTRACT_PL | |
34 | #include "ripd/rip_cli_clippy.c" | |
35 | #endif | |
36 | ||
8c9226c2 RW |
37 | /* |
38 | * XPath: /frr-ripd:ripd/instance | |
39 | */ | |
40 | DEFPY_NOSH (router_rip, | |
41 | router_rip_cmd, | |
42 | "router rip", | |
43 | "Enable a routing process\n" | |
44 | "Routing Information Protocol (RIP)\n") | |
45 | { | |
46 | int ret; | |
47 | ||
48 | struct cli_config_change changes[] = { | |
49 | { | |
50 | .xpath = "/frr-ripd:ripd/instance", | |
51 | .operation = NB_OP_CREATE, | |
52 | .value = NULL, | |
53 | }, | |
54 | }; | |
55 | ||
56 | ret = nb_cli_cfg_change(vty, NULL, changes, array_size(changes)); | |
57 | if (ret == CMD_SUCCESS) | |
58 | VTY_PUSH_XPATH(RIP_NODE, changes[0].xpath); | |
59 | ||
60 | return ret; | |
61 | } | |
62 | ||
63 | DEFPY (no_router_rip, | |
64 | no_router_rip_cmd, | |
65 | "no router rip", | |
66 | NO_STR | |
67 | "Enable a routing process\n" | |
68 | "Routing Information Protocol (RIP)\n") | |
69 | { | |
70 | struct cli_config_change changes[] = { | |
71 | { | |
72 | .xpath = "/frr-ripd:ripd/instance", | |
73 | .operation = NB_OP_DELETE, | |
74 | .value = NULL, | |
75 | }, | |
76 | }; | |
77 | ||
78 | return nb_cli_cfg_change(vty, NULL, changes, array_size(changes)); | |
79 | } | |
80 | ||
81 | void cli_show_router_rip(struct vty *vty, struct lyd_node *dnode, | |
82 | bool show_defaults) | |
83 | { | |
84 | vty_out(vty, "!\n"); | |
85 | vty_out(vty, "router rip\n"); | |
86 | } | |
87 | ||
edbf59d2 RW |
88 | /* |
89 | * XPath: /frr-ripd:ripd/instance/allow-ecmp | |
90 | */ | |
91 | DEFPY (rip_allow_ecmp, | |
92 | rip_allow_ecmp_cmd, | |
93 | "[no] allow-ecmp", | |
94 | NO_STR | |
95 | "Allow Equal Cost MultiPath\n") | |
96 | { | |
97 | struct cli_config_change changes[] = { | |
98 | { | |
99 | .xpath = "./allow-ecmp", | |
100 | .operation = NB_OP_MODIFY, | |
101 | .value = no ? "false" : "true", | |
102 | }, | |
103 | }; | |
104 | ||
105 | return nb_cli_cfg_change(vty, NULL, changes, array_size(changes)); | |
106 | } | |
107 | ||
108 | void cli_show_rip_allow_ecmp(struct vty *vty, struct lyd_node *dnode, | |
109 | bool show_defaults) | |
110 | { | |
111 | if (!yang_dnode_get_bool(dnode, NULL)) | |
112 | vty_out(vty, " no"); | |
113 | ||
114 | vty_out(vty, " allow-ecmp\n"); | |
115 | } | |
116 | ||
0b0609ba RW |
117 | /* |
118 | * XPath: /frr-ripd:ripd/instance/default-information-originate | |
119 | */ | |
120 | DEFPY (rip_default_information_originate, | |
121 | rip_default_information_originate_cmd, | |
122 | "[no] default-information originate", | |
123 | NO_STR | |
124 | "Control distribution of default route\n" | |
125 | "Distribute a default route\n") | |
126 | { | |
127 | struct cli_config_change changes[] = { | |
128 | { | |
129 | .xpath = "./default-information-originate", | |
130 | .operation = NB_OP_MODIFY, | |
131 | .value = no ? "false" : "true", | |
132 | }, | |
133 | }; | |
134 | ||
135 | return nb_cli_cfg_change(vty, NULL, changes, array_size(changes)); | |
136 | } | |
137 | ||
138 | void cli_show_rip_default_information_originate(struct vty *vty, | |
139 | struct lyd_node *dnode, | |
140 | bool show_defaults) | |
141 | { | |
142 | if (!yang_dnode_get_bool(dnode, NULL)) | |
143 | vty_out(vty, " no"); | |
144 | ||
145 | vty_out(vty, " default-information originate\n"); | |
146 | } | |
147 | ||
282ae30c RW |
148 | /* |
149 | * XPath: /frr-ripd:ripd/instance/default-metric | |
150 | */ | |
151 | DEFPY (rip_default_metric, | |
152 | rip_default_metric_cmd, | |
153 | "default-metric (1-16)", | |
154 | "Set a metric of redistribute routes\n" | |
155 | "Default metric\n") | |
156 | { | |
157 | struct cli_config_change changes[] = { | |
158 | { | |
159 | .xpath = "./default-metric", | |
160 | .operation = NB_OP_MODIFY, | |
161 | .value = default_metric_str, | |
162 | }, | |
163 | }; | |
164 | ||
165 | return nb_cli_cfg_change(vty, NULL, changes, array_size(changes)); | |
166 | } | |
167 | ||
168 | DEFPY (no_rip_default_metric, | |
169 | no_rip_default_metric_cmd, | |
170 | "no default-metric [(1-16)]", | |
171 | NO_STR | |
172 | "Set a metric of redistribute routes\n" | |
173 | "Default metric\n") | |
174 | { | |
175 | struct cli_config_change changes[] = { | |
176 | { | |
177 | .xpath = "./default-metric", | |
178 | .operation = NB_OP_MODIFY, | |
179 | .value = NULL, | |
180 | }, | |
181 | }; | |
182 | ||
183 | return nb_cli_cfg_change(vty, NULL, changes, array_size(changes)); | |
184 | } | |
185 | ||
186 | void cli_show_rip_default_metric(struct vty *vty, struct lyd_node *dnode, | |
187 | bool show_defaults) | |
188 | { | |
189 | vty_out(vty, " default-metric %s\n", | |
190 | yang_dnode_get_string(dnode, NULL)); | |
191 | } | |
192 | ||
7f8a9cba RW |
193 | /* |
194 | * XPath: /frr-ripd:ripd/instance/distance/default | |
195 | */ | |
196 | DEFPY (rip_distance, | |
197 | rip_distance_cmd, | |
198 | "distance (1-255)", | |
199 | "Administrative distance\n" | |
200 | "Distance value\n") | |
201 | { | |
202 | struct cli_config_change changes[] = { | |
203 | { | |
204 | .xpath = "./distance/default", | |
205 | .operation = NB_OP_MODIFY, | |
206 | .value = distance_str, | |
207 | }, | |
208 | }; | |
209 | ||
210 | return nb_cli_cfg_change(vty, NULL, changes, array_size(changes)); | |
211 | } | |
212 | ||
213 | DEFPY (no_rip_distance, | |
214 | no_rip_distance_cmd, | |
215 | "no distance [(1-255)]", | |
216 | NO_STR | |
217 | "Administrative distance\n" | |
218 | "Distance value\n") | |
219 | { | |
220 | struct cli_config_change changes[] = { | |
221 | { | |
222 | .xpath = "./distance/default", | |
223 | .operation = NB_OP_MODIFY, | |
224 | .value = NULL, | |
225 | }, | |
226 | }; | |
227 | ||
228 | return nb_cli_cfg_change(vty, NULL, changes, array_size(changes)); | |
229 | } | |
230 | ||
231 | void cli_show_rip_distance(struct vty *vty, struct lyd_node *dnode, | |
232 | bool show_defaults) | |
233 | { | |
234 | vty_out(vty, " distance %s\n", yang_dnode_get_string(dnode, NULL)); | |
235 | } | |
236 | ||
707656ec RW |
237 | void rip_cli_init(void) |
238 | { | |
8c9226c2 RW |
239 | install_element(CONFIG_NODE, &router_rip_cmd); |
240 | install_element(CONFIG_NODE, &no_router_rip_cmd); | |
edbf59d2 RW |
241 | |
242 | install_element(RIP_NODE, &rip_allow_ecmp_cmd); | |
0b0609ba | 243 | install_element(RIP_NODE, &rip_default_information_originate_cmd); |
282ae30c RW |
244 | install_element(RIP_NODE, &rip_default_metric_cmd); |
245 | install_element(RIP_NODE, &no_rip_default_metric_cmd); | |
7f8a9cba RW |
246 | install_element(RIP_NODE, &rip_distance_cmd); |
247 | install_element(RIP_NODE, &no_rip_distance_cmd); | |
707656ec | 248 | } |