1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
|
/*
* Copyright (C) 2001,2002 Sampo Saaristo
* Tampere University of Technology
* Institute of Communications Engineering
* Copyright (C) 2018 Volta Networks
* Emanuele Di Pascale
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; see the file COPYING; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include "if.h"
#include "vrf.h"
#include "log.h"
#include "prefix.h"
#include "command.h"
#include "northbound_cli.h"
#include "libfrr.h"
#include "yang.h"
#include "lib/linklist.h"
#include "isisd/isisd.h"
#include "isisd/isis_cli.h"
#include "isisd/isis_misc.h"
#include "isisd/isis_circuit.h"
#include "isisd/isis_csm.h"
#ifndef VTYSH_EXTRACT_PL
#include "isisd/isis_cli_clippy.c"
#endif
#ifndef FABRICD
/*
* XPath: /frr-isisd:isis/instance
*/
DEFPY_NOSH(router_isis, router_isis_cmd, "router isis WORD$tag",
ROUTER_STR
"ISO IS-IS\n"
"ISO Routing area tag\n")
{
int ret;
char base_xpath[XPATH_MAXLEN];
snprintf(base_xpath, XPATH_MAXLEN,
"/frr-isisd:isis/instance[area-tag='%s']", tag);
nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
/* default value in yang for is-type is level-1, but in FRR
* the first instance is assigned is-type level-1-2. We
* need to make sure to set it in the yang model so that it
* is consistent with what FRR sees.
*/
if (listcount(isis->area_list) == 0)
nb_cli_enqueue_change(vty, "./is-type", NB_OP_MODIFY,
"level-1-2");
ret = nb_cli_apply_changes(vty, base_xpath);
if (ret == CMD_SUCCESS)
VTY_PUSH_XPATH(ISIS_NODE, base_xpath);
return ret;
}
DEFPY(no_router_isis, no_router_isis_cmd, "no router isis WORD$tag",
NO_STR ROUTER_STR
"ISO IS-IS\n"
"ISO Routing area tag\n")
{
char temp_xpath[XPATH_MAXLEN];
struct listnode *node, *nnode;
struct isis_circuit *circuit = NULL;
struct isis_area *area = NULL;
area = isis_area_lookup(tag);
if (!area) {
vty_out(vty, "ISIS area %s not found.\n", tag);
return CMD_ERR_NOTHING_TODO;
}
nb_cli_enqueue_change(vty, ".", NB_OP_DELETE, NULL);
if (area->circuit_list && listcount(area->circuit_list)) {
for (ALL_LIST_ELEMENTS(area->circuit_list, node, nnode,
circuit)) {
/* add callbacks to delete each of the circuits listed
*/
const char *vrf_name =
vrf_lookup_by_id(circuit->interface->vrf_id)
->name;
snprintf(
temp_xpath, XPATH_MAXLEN,
"/frr-interface:lib/interface[name='%s'][vrf='%s']/frr-isisd:isis",
circuit->interface->name, vrf_name);
nb_cli_enqueue_change(vty, temp_xpath, NB_OP_DELETE,
NULL);
}
}
return nb_cli_apply_changes(
vty, "/frr-isisd:isis/instance[area-tag='%s']", tag);
}
void cli_show_router_isis(struct vty *vty, struct lyd_node *dnode,
bool show_defaults)
{
vty_out(vty, "!\n");
vty_out(vty, "router isis %s\n",
yang_dnode_get_string(dnode, "./area-tag"));
}
/*
* XPath: /frr-interface:lib/interface/frr-isisd:isis/
* XPath: /frr-interface:lib/interface/frr-isisd:isis/ipv4-routing
* XPath: /frr-interface:lib/interface/frr-isisd:isis/ipv6-routing
* XPath: /frr-isisd:isis/instance
*/
DEFPY(ip_router_isis, ip_router_isis_cmd, "ip router isis WORD$tag",
"Interface Internet Protocol config commands\n"
"IP router interface commands\n"
"IS-IS routing protocol\n"
"Routing process tag\n")
{
char temp_xpath[XPATH_MAXLEN];
const char *circ_type;
struct isis_area *area;
/* area will be created if it is not present. make sure the yang model
* is synced with FRR and call the appropriate NB cb.
*/
area = isis_area_lookup(tag);
if (!area) {
snprintf(temp_xpath, XPATH_MAXLEN,
"/frr-isisd:isis/instance[area-tag='%s']", tag);
nb_cli_enqueue_change(vty, temp_xpath, NB_OP_CREATE, tag);
snprintf(temp_xpath, XPATH_MAXLEN,
"/frr-isisd:isis/instance[area-tag='%s']/is-type",
tag);
nb_cli_enqueue_change(
vty, temp_xpath, NB_OP_MODIFY,
listcount(isis->area_list) == 0 ? "level-1-2" : NULL);
nb_cli_enqueue_change(vty, "./frr-isisd:isis", NB_OP_CREATE,
NULL);
nb_cli_enqueue_change(vty, "./frr-isisd:isis/area-tag",
NB_OP_MODIFY, tag);
nb_cli_enqueue_change(vty, "./frr-isisd:isis/ipv4-routing",
NB_OP_CREATE, NULL);
nb_cli_enqueue_change(
vty, "./frr-isisd:isis/circuit-type", NB_OP_MODIFY,
listcount(isis->area_list) == 0 ? "level-1-2"
: "level-1");
} else {
/* area exists, circuit type defaults to its area's is_type */
switch (area->is_type) {
case IS_LEVEL_1:
circ_type = "level-1";
break;
case IS_LEVEL_2:
circ_type = "level-2";
break;
case IS_LEVEL_1_AND_2:
circ_type = "level-1-2";
break;
}
nb_cli_enqueue_change(vty, "./frr-isisd:isis", NB_OP_CREATE,
NULL);
nb_cli_enqueue_change(vty, "./frr-isisd:isis/area-tag",
NB_OP_MODIFY, tag);
nb_cli_enqueue_change(vty, "./frr-isisd:isis/ipv4-routing",
NB_OP_CREATE, NULL);
nb_cli_enqueue_change(vty, "./frr-isisd:isis/circuit-type",
NB_OP_MODIFY, circ_type);
}
return nb_cli_apply_changes(vty, NULL);
}
DEFPY(ip6_router_isis, ip6_router_isis_cmd, "ipv6 router isis WORD$tag",
"Interface Internet Protocol config commands\n"
"IP router interface commands\n"
"IS-IS routing protocol\n"
"Routing process tag\n")
{
char temp_xpath[XPATH_MAXLEN];
const char *circ_type;
struct isis_area *area;
/* area will be created if it is not present. make sure the yang model
* is synced with FRR and call the appropriate NB cb.
*/
area = isis_area_lookup(tag);
if (!area) {
snprintf(temp_xpath, XPATH_MAXLEN,
"/frr-isisd:isis/instance[area-tag='%s']", tag);
nb_cli_enqueue_change(vty, temp_xpath, NB_OP_CREATE, tag);
snprintf(temp_xpath, XPATH_MAXLEN,
"/frr-isisd:isis/instance[area-tag='%s']/is-type",
tag);
nb_cli_enqueue_change(
vty, temp_xpath, NB_OP_MODIFY,
listcount(isis->area_list) == 0 ? "level-1-2" : NULL);
nb_cli_enqueue_change(vty, "./frr-isisd:isis", NB_OP_CREATE,
NULL);
nb_cli_enqueue_change(vty, "./frr-isisd:isis/area-tag",
NB_OP_MODIFY, tag);
nb_cli_enqueue_change(vty, "./frr-isisd:isis/ipv6-routing",
NB_OP_CREATE, NULL);
nb_cli_enqueue_change(
vty, "./frr-isisd:isis/circuit-type", NB_OP_MODIFY,
listcount(isis->area_list) == 0 ? "level-1-2"
: "level-1");
} else {
/* area exists, circuit type defaults to its area's is_type */
switch (area->is_type) {
case IS_LEVEL_1:
circ_type = "level-1";
break;
case IS_LEVEL_2:
circ_type = "level-2";
break;
case IS_LEVEL_1_AND_2:
circ_type = "level-1-2";
break;
}
nb_cli_enqueue_change(vty, "./frr-isisd:isis", NB_OP_CREATE,
NULL);
nb_cli_enqueue_change(vty, "./frr-isisd:isis/area-tag",
NB_OP_MODIFY, tag);
nb_cli_enqueue_change(vty, "./frr-isisd:isis/ipv6-routing",
NB_OP_CREATE, NULL);
nb_cli_enqueue_change(vty, "./frr-isisd:isis/circuit-type",
NB_OP_MODIFY, circ_type);
}
return nb_cli_apply_changes(vty, NULL);
}
DEFPY(no_ip_router_isis, no_ip_router_isis_cmd,
"no <ip|ipv6>$ip router isis [WORD]$tag",
NO_STR
"Interface Internet Protocol config commands\n"
"IP router interface commands\n"
"IP router interface commands\n"
"IS-IS routing protocol\n"
"Routing process tag\n")
{
const struct lyd_node *dnode =
yang_dnode_get(running_config->dnode, VTY_CURR_XPATH);
struct interface *ifp;
struct isis_circuit *circuit = NULL;
/* check for the existance of a circuit */
if (dnode) {
ifp = yang_dnode_get_entry(dnode, false);
if (ifp)
circuit = circuit_scan_by_ifp(ifp);
}
/* if both ipv4 and ipv6 are off delete the interface isis container too
*/
if (!strncmp(ip, "ipv6", strlen("ipv6"))) {
if (circuit && !circuit->ip_router)
nb_cli_enqueue_change(vty, "./frr-isisd:isis",
NB_OP_DELETE, NULL);
else
nb_cli_enqueue_change(vty,
"./frr-isisd:isis/ipv6-routing",
NB_OP_DELETE, NULL);
} else { /* no ipv4 */
if (circuit && !circuit->ipv6_router)
nb_cli_enqueue_change(vty, "./frr-isisd:isis",
NB_OP_DELETE, NULL);
else
nb_cli_enqueue_change(vty,
"./frr-isisd:isis/ipv4-routing",
NB_OP_DELETE, NULL);
}
return nb_cli_apply_changes(vty, NULL);
}
void cli_show_ip_isis_ipv4(struct vty *vty, struct lyd_node *dnode,
bool show_defaults)
{
vty_out(vty, " ip router isis %s\n",
yang_dnode_get_string(dnode, "../area-tag"));
}
void cli_show_ip_isis_ipv6(struct vty *vty, struct lyd_node *dnode,
bool show_defaults)
{
vty_out(vty, " ipv6 router isis %s\n",
yang_dnode_get_string(dnode, "../area-tag"));
}
/*
* XPath: /frr-isisd:isis/instance/area-address
*/
DEFPY(net, net_cmd, "[no] net WORD",
"Remove an existing Network Entity Title for this process\n"
"A Network Entity Title for this process (OSI only)\n"
"XX.XXXX. ... .XXX.XX Network entity title (NET)\n")
{
nb_cli_enqueue_change(vty, "./area-address",
no ? NB_OP_DELETE : NB_OP_CREATE, net);
return nb_cli_apply_changes(vty, NULL);
}
void cli_show_isis_area_address(struct vty *vty, struct lyd_node *dnode,
bool show_defaults)
{
vty_out(vty, " net %s\n", yang_dnode_get_string(dnode, NULL));
}
/*
* XPath: /frr-isisd:isis/instance/is-type
*/
DEFPY(is_type, is_type_cmd, "is-type <level-1|level-1-2|level-2-only>$level",
"IS Level for this routing process (OSI only)\n"
"Act as a station router only\n"
"Act as both a station router and an area router\n"
"Act as an area router only\n")
{
nb_cli_enqueue_change(vty, "./is-type", NB_OP_MODIFY,
strmatch(level, "level-2-only") ? "level-2"
: level);
return nb_cli_apply_changes(vty, NULL);
}
DEFPY(no_is_type, no_is_type_cmd,
"no is-type [<level-1|level-1-2|level-2-only>]",
NO_STR
"IS Level for this routing process (OSI only)\n"
"Act as a station router only\n"
"Act as both a station router and an area router\n"
"Act as an area router only\n")
{
const char *value = NULL;
const struct lyd_node *dnode =
yang_dnode_get(running_config->dnode, VTY_CURR_XPATH);
struct isis_area *area = yang_dnode_get_entry(dnode, false);
/*
* Put the is-type back to defaults:
* - level-1-2 on first area
* - level-1 for the rest
*/
if (area && listgetdata(listhead(isis->area_list)) == area)
value = "level-1-2";
else
value = NULL;
nb_cli_enqueue_change(vty, "./is-type", NB_OP_MODIFY, value);
return nb_cli_apply_changes(vty, NULL);
}
void cli_show_isis_is_type(struct vty *vty, struct lyd_node *dnode,
bool show_defaults)
{
int is_type = yang_dnode_get_enum(dnode, NULL);
switch (is_type) {
case IS_LEVEL_1:
vty_out(vty, " is-type level-1\n");
break;
case IS_LEVEL_2:
vty_out(vty, " is-type level-2-only\n");
break;
case IS_LEVEL_1_AND_2:
vty_out(vty, " is-type level-1-2\n");
break;
}
}
/*
* XPath: /frr-isisd:isis/instance/dynamic-hostname
*/
DEFPY(dynamic_hostname, dynamic_hostname_cmd, "[no] hostname dynamic",
NO_STR
"Dynamic hostname for IS-IS\n"
"Dynamic hostname\n")
{
nb_cli_enqueue_change(vty, "./dynamic-hostname", NB_OP_MODIFY,
no ? "false" : "true");
return nb_cli_apply_changes(vty, NULL);
}
void cli_show_isis_dynamic_hostname(struct vty *vty, struct lyd_node *dnode,
bool show_defaults)
{
if (!yang_dnode_get_bool(dnode, NULL))
vty_out(vty, " no");
vty_out(vty, " hostname dynamic\n");
}
void isis_cli_init(void)
{
install_element(CONFIG_NODE, &router_isis_cmd);
install_element(CONFIG_NODE, &no_router_isis_cmd);
install_element(INTERFACE_NODE, &ip_router_isis_cmd);
install_element(INTERFACE_NODE, &ip6_router_isis_cmd);
install_element(INTERFACE_NODE, &no_ip_router_isis_cmd);
install_element(ISIS_NODE, &net_cmd);
install_element(ISIS_NODE, &is_type_cmd);
install_element(ISIS_NODE, &no_is_type_cmd);
install_element(ISIS_NODE, &dynamic_hostname_cmd);
}
#endif /* ifndef FABRICD */
|