]> git.proxmox.com Git - mirror_frr.git/blob - pathd/path_nb_state.c
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / pathd / path_nb_state.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2020 NetDEF, Inc.
4 */
5
6 #include <zebra.h>
7
8 #include "log.h"
9 #include "prefix.h"
10 #include "table.h"
11 #include "command.h"
12 #include "northbound.h"
13 #include "libfrr.h"
14
15 #include "pathd/pathd.h"
16 #include "pathd/path_nb.h"
17
18 /*
19 * XPath: /frr-pathd:pathd/srte/segment-list
20 */
21 const void *pathd_srte_segment_list_get_next(struct nb_cb_get_next_args *args)
22 {
23 struct srte_segment_list *segment_list =
24 (struct srte_segment_list *)args->list_entry;
25
26 if (args->list_entry == NULL)
27 segment_list =
28 RB_MIN(srte_segment_list_head, &srte_segment_lists);
29 else
30 segment_list = RB_NEXT(srte_segment_list_head, segment_list);
31
32 return segment_list;
33 }
34
35 int pathd_srte_segment_list_get_keys(struct nb_cb_get_keys_args *args)
36 {
37 const struct srte_segment_list *segment_list =
38 (struct srte_segment_list *)args->list_entry;
39
40 args->keys->num = 1;
41 snprintf(args->keys->key[0], sizeof(args->keys->key[0]), "%s",
42 segment_list->name);
43
44 return NB_OK;
45 }
46
47 const void *
48 pathd_srte_segment_list_lookup_entry(struct nb_cb_lookup_entry_args *args)
49 {
50 return srte_segment_list_find(args->keys->key[0]);
51 }
52
53 /*
54 * XPath: /frr-pathd:pathd/srte/policy
55 */
56 const void *pathd_srte_policy_get_next(struct nb_cb_get_next_args *args)
57 {
58 struct srte_policy *policy = (struct srte_policy *)args->list_entry;
59
60 if (args->list_entry == NULL)
61 policy = RB_MIN(srte_policy_head, &srte_policies);
62 else
63 policy = RB_NEXT(srte_policy_head, policy);
64
65 return policy;
66 }
67
68 int pathd_srte_policy_get_keys(struct nb_cb_get_keys_args *args)
69 {
70 const struct srte_policy *policy =
71 (struct srte_policy *)args->list_entry;
72
73 args->keys->num = 2;
74 snprintf(args->keys->key[0], sizeof(args->keys->key[0]), "%u",
75 policy->color);
76 ipaddr2str(&policy->endpoint, args->keys->key[1],
77 sizeof(args->keys->key[1]));
78
79 return NB_OK;
80 }
81
82 const void *pathd_srte_policy_lookup_entry(struct nb_cb_lookup_entry_args *args)
83 {
84 uint32_t color;
85 struct ipaddr endpoint;
86
87 color = yang_str2uint32(args->keys->key[0]);
88 yang_str2ip(args->keys->key[1], &endpoint);
89
90 return srte_policy_find(color, &endpoint);
91 }
92
93 /*
94 * XPath: /frr-pathd:pathd/srte/policy/is-operational
95 */
96 struct yang_data *
97 pathd_srte_policy_is_operational_get_elem(struct nb_cb_get_elem_args *args)
98 {
99 struct srte_policy *policy = (struct srte_policy *)args->list_entry;
100 bool is_operational = false;
101
102 if (policy->status == SRTE_POLICY_STATUS_UP)
103 is_operational = true;
104
105 return yang_data_new_bool(args->xpath, is_operational);
106 }
107
108 /*
109 * XPath: /frr-pathd:pathd/srte/policy/candidate-path
110 */
111 const void *
112 pathd_srte_policy_candidate_path_get_next(struct nb_cb_get_next_args *args)
113 {
114 struct srte_policy *policy =
115 (struct srte_policy *)args->parent_list_entry;
116 struct srte_candidate *candidate =
117 (struct srte_candidate *)args->list_entry;
118
119 if (args->list_entry == NULL)
120 candidate =
121 RB_MIN(srte_candidate_head, &policy->candidate_paths);
122 else
123 candidate = RB_NEXT(srte_candidate_head, candidate);
124
125 return candidate;
126 }
127
128 int pathd_srte_policy_candidate_path_get_keys(struct nb_cb_get_keys_args *args)
129 {
130 const struct srte_candidate *candidate =
131 (struct srte_candidate *)args->list_entry;
132
133 args->keys->num = 1;
134 snprintf(args->keys->key[0], sizeof(args->keys->key[0]), "%u",
135 candidate->preference);
136
137 return NB_OK;
138 }
139
140 const void *pathd_srte_policy_candidate_path_lookup_entry(
141 struct nb_cb_lookup_entry_args *args)
142 {
143 struct srte_policy *policy =
144 (struct srte_policy *)args->parent_list_entry;
145 uint32_t preference;
146
147 preference = yang_str2uint32(args->keys->key[0]);
148
149 return srte_candidate_find(policy, preference);
150 }
151
152 /*
153 * XPath: /frr-pathd:pathd/srte/policy/candidate_path/is-best-candidate-path
154 */
155 struct yang_data *
156 pathd_srte_policy_candidate_path_is_best_candidate_path_get_elem(
157 struct nb_cb_get_elem_args *args)
158 {
159 struct srte_candidate *candidate =
160 (struct srte_candidate *)args->list_entry;
161
162 return yang_data_new_bool(
163 args->xpath, CHECK_FLAG(candidate->flags, F_CANDIDATE_BEST));
164 }
165
166 /*
167 * XPath: /frr-pathd:pathd/srte/policy/candidate-path/discriminator
168 */
169 struct yang_data *pathd_srte_policy_candidate_path_discriminator_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_uint32(args->xpath, candidate->discriminator);
176 }