/src/frr/lib/affinitymap_cli.c
Line | Count | Source |
1 | | /* |
2 | | * Affinity map northbound CLI implementation. |
3 | | * |
4 | | * Copyright 2022 Hiroki Shirokura, LINE Corporation |
5 | | * Copyright 2022 Masakazu Asama |
6 | | * Copyright 2022 6WIND S.A. |
7 | | * |
8 | | * |
9 | | * This file is part of Free Range Routing (FRR). |
10 | | * |
11 | | * FRR is free software; you can redistribute it and/or modify it |
12 | | * under the terms of the GNU General Public License as published by the |
13 | | * Free Software Foundation; either version 2, or (at your option) any |
14 | | * later version. |
15 | | * |
16 | | * FRR is distributed in the hope that it will be useful, but |
17 | | * WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
19 | | * General Public License for more details. |
20 | | * |
21 | | * You should have received a copy of the GNU General Public License along |
22 | | * with this program; see the file COPYING; if not, write to the Free Software |
23 | | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
24 | | */ |
25 | | |
26 | | #include <zebra.h> |
27 | | |
28 | | #include "lib/command.h" |
29 | | #include "lib/northbound_cli.h" |
30 | | #include "lib/affinitymap.h" |
31 | | #include "lib/affinitymap_cli_clippy.c" |
32 | | |
33 | | /* Route map node structure. */ |
34 | | static int affinity_map_config_write(struct vty *vty); |
35 | | static struct cmd_node affinitymap_node = { |
36 | | .name = "affinity-map", |
37 | | .node = AFFMAP_NODE, |
38 | | .prompt = "", |
39 | | .config_write = affinity_map_config_write, |
40 | | }; |
41 | | |
42 | | /* max value is EXT_ADMIN_GROUP_MAX_POSITIONS - 1 */ |
43 | | DEFPY_YANG_NOSH(affinity_map, affinity_map_cmd, |
44 | | "affinity-map NAME$name bit-position (0-1023)$position", |
45 | | "Affinity map configuration\n" |
46 | | "Affinity attribute name\n" |
47 | | "Bit position for affinity attribute value\n" |
48 | | "Bit position\n") |
49 | 0 | { |
50 | 0 | char xpathr[XPATH_MAXLEN]; |
51 | |
|
52 | 0 | snprintf( |
53 | 0 | xpathr, sizeof(xpathr), |
54 | 0 | "/frr-affinity-map:lib/affinity-maps/affinity-map[name='%s']/value", |
55 | 0 | name); |
56 | 0 | nb_cli_enqueue_change(vty, xpathr, NB_OP_MODIFY, position_str); |
57 | 0 | return nb_cli_apply_changes(vty, NULL); |
58 | 0 | } |
59 | | |
60 | | /* max value is EXT_ADMIN_GROUP_MAX_POSITIONS - 1 */ |
61 | | DEFPY_YANG_NOSH(no_affinity_map, no_affinity_map_cmd, |
62 | | "no affinity-map NAME$name [bit-position (0-1023)$position]", |
63 | | NO_STR |
64 | | "Affinity map configuration\n" |
65 | | "Affinity attribute name\n" |
66 | | "Bit position for affinity attribute value\n" |
67 | | "Bit position\n") |
68 | 0 | { |
69 | 0 | char xpathr[XPATH_MAXLEN]; |
70 | |
|
71 | 0 | snprintf(xpathr, sizeof(xpathr), |
72 | 0 | "/frr-affinity-map:lib/affinity-maps/affinity-map[name='%s']", |
73 | 0 | name); |
74 | 0 | nb_cli_enqueue_change(vty, xpathr, NB_OP_DESTROY, NULL); |
75 | 0 | return nb_cli_apply_changes(vty, NULL); |
76 | 0 | } |
77 | | |
78 | | static int affinity_map_config_write(struct vty *vty) |
79 | 0 | { |
80 | 0 | const struct lyd_node *dnode; |
81 | 0 | int written = 0; |
82 | |
|
83 | 0 | dnode = yang_dnode_get(running_config->dnode, "/frr-affinity-map:lib"); |
84 | 0 | if (dnode) { |
85 | 0 | nb_cli_show_dnode_cmds(vty, dnode, false); |
86 | 0 | written = 1; |
87 | 0 | } |
88 | |
|
89 | 0 | return written; |
90 | 0 | } |
91 | | |
92 | | void cli_show_affinity_map(struct vty *vty, const struct lyd_node *dnode, |
93 | | bool show_defaults __attribute__((__unused__))) |
94 | 0 | { |
95 | 0 | vty_out(vty, "affinity-map %s bit-position %u\n", |
96 | 0 | yang_dnode_get_string(dnode, "./name"), |
97 | 0 | yang_dnode_get_uint16(dnode, "./value")); |
98 | 0 | } |
99 | | |
100 | | /* Initialization of affinity map vector. */ |
101 | | void affinity_map_init(void) |
102 | 1 | { |
103 | | /* CLI commands. */ |
104 | 1 | install_node(&affinitymap_node); |
105 | 1 | install_element(CONFIG_NODE, &affinity_map_cmd); |
106 | 1 | install_element(CONFIG_NODE, &no_affinity_map_cmd); |
107 | 1 | } |