]> git.proxmox.com Git - mirror_frr.git/blob - pathd/path_nb_state.c
Merge pull request #8252 from SaiGomathiN/8249
[mirror_frr.git] / pathd / path_nb_state.c
1 /*
2 * Copyright (C) 2020 NetDEF, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation; either version 2 of the License, or (at your option)
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; see the file COPYING; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <zebra.h>
20
21 #include "log.h"
22 #include "prefix.h"
23 #include "table.h"
24 #include "command.h"
25 #include "northbound.h"
26 #include "libfrr.h"
27
28 #include "pathd/pathd.h"
29 #include "pathd/path_nb.h"
30
31 /*
32 * XPath: /frr-pathd:pathd/srte/segment-list
33 */
34 const void *pathd_srte_segment_list_get_next(struct nb_cb_get_next_args *args)
35 {
36 struct srte_segment_list *segment_list =
37 (struct srte_segment_list *)args->list_entry;
38
39 if (args->list_entry == NULL)
40 segment_list =
41 RB_MIN(srte_segment_list_head, &srte_segment_lists);
42 else
43 segment_list = RB_NEXT(srte_segment_list_head, segment_list);
44
45 return segment_list;
46 }
47
48 int pathd_srte_segment_list_get_keys(struct nb_cb_get_keys_args *args)
49 {
50 const struct srte_segment_list *segment_list =
51 (struct srte_segment_list *)args->list_entry;
52
53 args->keys->num = 1;
54 snprintf(args->keys->key[0], sizeof(args->keys->key[0]), "%s",
55 segment_list->name);
56
57 return NB_OK;
58 }
59
60 const void *
61 pathd_srte_segment_list_lookup_entry(struct nb_cb_lookup_entry_args *args)
62 {
63 return srte_segment_list_find(args->keys->key[0]);
64 }
65
66 /*
67 * XPath: /frr-pathd:pathd/srte/policy
68 */
69 const void *pathd_srte_policy_get_next(struct nb_cb_get_next_args *args)
70 {
71 struct srte_policy *policy = (struct srte_policy *)args->list_entry;
72
73 if (args->list_entry == NULL)
74 policy = RB_MIN(srte_policy_head, &srte_policies);
75 else
76 policy = RB_NEXT(srte_policy_head, policy);
77
78 return policy;
79 }
80
81 int pathd_srte_policy_get_keys(struct nb_cb_get_keys_args *args)
82 {
83 const struct srte_policy *policy =
84 (struct srte_policy *)args->list_entry;
85
86 args->keys->num = 2;
87 snprintf(args->keys->key[0], sizeof(args->keys->key[0]), "%u",
88 policy->color);
89 ipaddr2str(&policy->endpoint, args->keys->key[1],
90 sizeof(args->keys->key[1]));
91
92 return NB_OK;
93 }
94
95 const void *pathd_srte_policy_lookup_entry(struct nb_cb_lookup_entry_args *args)
96 {
97 uint32_t color;
98 struct ipaddr endpoint;
99
100 color = yang_str2uint32(args->keys->key[0]);
101 yang_str2ip(args->keys->key[1], &endpoint);
102
103 return srte_policy_find(color, &endpoint);
104 }
105
106 /*
107 * XPath: /frr-pathd:pathd/srte/policy/is-operational
108 */
109 struct yang_data *
110 pathd_srte_policy_is_operational_get_elem(struct nb_cb_get_elem_args *args)
111 {
112 struct srte_policy *policy = (struct srte_policy *)args->list_entry;
113 bool is_operational = false;
114
115 if (policy->status == SRTE_POLICY_STATUS_UP)
116 is_operational = true;
117
118 return yang_data_new_bool(args->xpath, is_operational);
119 }
120
121 /*
122 * XPath: /frr-pathd:pathd/srte/policy/candidate-path
123 */
124 const void *
125 pathd_srte_policy_candidate_path_get_next(struct nb_cb_get_next_args *args)
126 {
127 struct srte_policy *policy =
128 (struct srte_policy *)args->parent_list_entry;
129 struct srte_candidate *candidate =
130 (struct srte_candidate *)args->list_entry;
131
132 if (args->list_entry == NULL)
133 candidate =
134 RB_MIN(srte_candidate_head, &policy->candidate_paths);
135 else
136 candidate = RB_NEXT(srte_candidate_head, candidate);
137
138 return candidate;
139 }
140
141 int pathd_srte_policy_candidate_path_get_keys(struct nb_cb_get_keys_args *args)
142 {
143 const struct srte_candidate *candidate =
144 (struct srte_candidate *)args->list_entry;
145
146 args->keys->num = 1;
147 snprintf(args->keys->key[0], sizeof(args->keys->key[0]), "%u",
148 candidate->preference);
149
150 return NB_OK;
151 }
152
153 const void *pathd_srte_policy_candidate_path_lookup_entry(
154 struct nb_cb_lookup_entry_args *args)
155 {
156 struct srte_policy *policy =
157 (struct srte_policy *)args->parent_list_entry;
158 uint32_t preference;
159
160 preference = yang_str2uint32(args->keys->key[0]);
161
162 return srte_candidate_find(policy, preference);
163 }
164
165 /*
166 * XPath: /frr-pathd:pathd/srte/policy/candidate_path/is-best-candidate-path
167 */
168 struct yang_data *
169 pathd_srte_policy_candidate_path_is_best_candidate_path_get_elem(
170 struct nb_cb_get_elem_args *args)
171 {
172 struct srte_candidate *candidate =
173 (struct srte_candidate *)args->list_entry;
174
175 return yang_data_new_bool(
176 args->xpath, CHECK_FLAG(candidate->flags, F_CANDIDATE_BEST));
177 }
178
179 /*
180 * XPath: /frr-pathd:pathd/srte/policy/candidate-path/discriminator
181 */
182 struct yang_data *pathd_srte_policy_candidate_path_discriminator_get_elem(
183 struct nb_cb_get_elem_args *args)
184 {
185 struct srte_candidate *candidate =
186 (struct srte_candidate *)args->list_entry;
187
188 return yang_data_new_uint32(args->xpath, candidate->discriminator);
189 }