]>
git.proxmox.com Git - mirror_frr.git/blob - pathd/path_nb_state.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2020 NetDEF, Inc.
12 #include "northbound.h"
15 #include "pathd/pathd.h"
16 #include "pathd/path_nb.h"
19 * XPath: /frr-pathd:pathd/srte/segment-list
21 const void *pathd_srte_segment_list_get_next(struct nb_cb_get_next_args
*args
)
23 struct srte_segment_list
*segment_list
=
24 (struct srte_segment_list
*)args
->list_entry
;
26 if (args
->list_entry
== NULL
)
28 RB_MIN(srte_segment_list_head
, &srte_segment_lists
);
30 segment_list
= RB_NEXT(srte_segment_list_head
, segment_list
);
35 int pathd_srte_segment_list_get_keys(struct nb_cb_get_keys_args
*args
)
37 const struct srte_segment_list
*segment_list
=
38 (struct srte_segment_list
*)args
->list_entry
;
41 snprintf(args
->keys
->key
[0], sizeof(args
->keys
->key
[0]), "%s",
48 pathd_srte_segment_list_lookup_entry(struct nb_cb_lookup_entry_args
*args
)
50 return srte_segment_list_find(args
->keys
->key
[0]);
54 * XPath: /frr-pathd:pathd/srte/policy
56 const void *pathd_srte_policy_get_next(struct nb_cb_get_next_args
*args
)
58 struct srte_policy
*policy
= (struct srte_policy
*)args
->list_entry
;
60 if (args
->list_entry
== NULL
)
61 policy
= RB_MIN(srte_policy_head
, &srte_policies
);
63 policy
= RB_NEXT(srte_policy_head
, policy
);
68 int pathd_srte_policy_get_keys(struct nb_cb_get_keys_args
*args
)
70 const struct srte_policy
*policy
=
71 (struct srte_policy
*)args
->list_entry
;
74 snprintf(args
->keys
->key
[0], sizeof(args
->keys
->key
[0]), "%u",
76 ipaddr2str(&policy
->endpoint
, args
->keys
->key
[1],
77 sizeof(args
->keys
->key
[1]));
82 const void *pathd_srte_policy_lookup_entry(struct nb_cb_lookup_entry_args
*args
)
85 struct ipaddr endpoint
;
87 color
= yang_str2uint32(args
->keys
->key
[0]);
88 yang_str2ip(args
->keys
->key
[1], &endpoint
);
90 return srte_policy_find(color
, &endpoint
);
94 * XPath: /frr-pathd:pathd/srte/policy/is-operational
97 pathd_srte_policy_is_operational_get_elem(struct nb_cb_get_elem_args
*args
)
99 struct srte_policy
*policy
= (struct srte_policy
*)args
->list_entry
;
100 bool is_operational
= false;
102 if (policy
->status
== SRTE_POLICY_STATUS_UP
)
103 is_operational
= true;
105 return yang_data_new_bool(args
->xpath
, is_operational
);
109 * XPath: /frr-pathd:pathd/srte/policy/candidate-path
112 pathd_srte_policy_candidate_path_get_next(struct nb_cb_get_next_args
*args
)
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
;
119 if (args
->list_entry
== NULL
)
121 RB_MIN(srte_candidate_head
, &policy
->candidate_paths
);
123 candidate
= RB_NEXT(srte_candidate_head
, candidate
);
128 int pathd_srte_policy_candidate_path_get_keys(struct nb_cb_get_keys_args
*args
)
130 const struct srte_candidate
*candidate
=
131 (struct srte_candidate
*)args
->list_entry
;
134 snprintf(args
->keys
->key
[0], sizeof(args
->keys
->key
[0]), "%u",
135 candidate
->preference
);
140 const void *pathd_srte_policy_candidate_path_lookup_entry(
141 struct nb_cb_lookup_entry_args
*args
)
143 struct srte_policy
*policy
=
144 (struct srte_policy
*)args
->parent_list_entry
;
147 preference
= yang_str2uint32(args
->keys
->key
[0]);
149 return srte_candidate_find(policy
, preference
);
153 * XPath: /frr-pathd:pathd/srte/policy/candidate_path/is-best-candidate-path
156 pathd_srte_policy_candidate_path_is_best_candidate_path_get_elem(
157 struct nb_cb_get_elem_args
*args
)
159 struct srte_candidate
*candidate
=
160 (struct srte_candidate
*)args
->list_entry
;
162 return yang_data_new_bool(
163 args
->xpath
, CHECK_FLAG(candidate
->flags
, F_CANDIDATE_BEST
));
167 * XPath: /frr-pathd:pathd/srte/policy/candidate-path/discriminator
169 struct yang_data
*pathd_srte_policy_candidate_path_discriminator_get_elem(
170 struct nb_cb_get_elem_args
*args
)
172 struct srte_candidate
*candidate
=
173 (struct srte_candidate
*)args
->list_entry
;
175 return yang_data_new_uint32(args
->xpath
, candidate
->discriminator
);