]> git.proxmox.com Git - mirror_frr.git/blob - pathd/path_nb_config.c
Merge pull request #9899 from Drumato/zebra-srv6-locator-detail-json-support
[mirror_frr.git] / pathd / path_nb_config.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 #include <lib_errors.h>
21
22 #include "northbound.h"
23 #include "libfrr.h"
24
25 #include "pathd/path_zebra.h"
26 #include "pathd/path_nb.h"
27
28 /*
29 * XPath: /frr-pathd:pathd
30 */
31 void pathd_apply_finish(struct nb_cb_apply_finish_args *args)
32 {
33 srte_apply_changes();
34 }
35
36 /*
37 * XPath: /frr-pathd:pathd/srte/segment-list
38 */
39 int pathd_srte_segment_list_create(struct nb_cb_create_args *args)
40 {
41 struct srte_segment_list *segment_list;
42 const char *name;
43
44 if (args->event != NB_EV_APPLY)
45 return NB_OK;
46
47 name = yang_dnode_get_string(args->dnode, "./name");
48 segment_list = srte_segment_list_add(name);
49 nb_running_set_entry(args->dnode, segment_list);
50 SET_FLAG(segment_list->flags, F_SEGMENT_LIST_NEW);
51
52 return NB_OK;
53 }
54
55 int pathd_srte_segment_list_destroy(struct nb_cb_destroy_args *args)
56 {
57 struct srte_segment_list *segment_list;
58
59 if (args->event != NB_EV_APPLY)
60 return NB_OK;
61
62 segment_list = nb_running_unset_entry(args->dnode);
63 SET_FLAG(segment_list->flags, F_SEGMENT_LIST_DELETED);
64
65 return NB_OK;
66 }
67
68 /*
69 * XPath: /frr-pathd:pathd/srte/segment-list/protocol-origin
70 */
71 int pathd_srte_segment_list_protocol_origin_modify(
72 struct nb_cb_modify_args *args)
73 {
74 struct srte_segment_list *segment_list;
75
76 if (args->event != NB_EV_APPLY)
77 return NB_OK;
78
79 segment_list = nb_running_get_entry(args->dnode, NULL, true);
80 segment_list->protocol_origin = yang_dnode_get_enum(args->dnode, NULL);
81 SET_FLAG(segment_list->flags, F_SEGMENT_LIST_MODIFIED);
82
83 return NB_OK;
84 }
85
86 /*
87 * XPath: /frr-pathd:pathd/srte/segment-list/originator
88 */
89 int pathd_srte_segment_list_originator_modify(struct nb_cb_modify_args *args)
90 {
91 struct srte_segment_list *segment_list;
92 const char *originator;
93
94 if (args->event != NB_EV_APPLY)
95 return NB_OK;
96
97 segment_list = nb_running_get_entry(args->dnode, NULL, true);
98 originator = yang_dnode_get_string(args->dnode, NULL);
99 strlcpy(segment_list->originator, originator,
100 sizeof(segment_list->originator));
101 SET_FLAG(segment_list->flags, F_SEGMENT_LIST_MODIFIED);
102
103 return NB_OK;
104 }
105
106
107 /*
108 * XPath: /frr-pathd:pathd/srte/segment-list/segment
109 */
110 int pathd_srte_segment_list_segment_create(struct nb_cb_create_args *args)
111 {
112 struct srte_segment_list *segment_list;
113 struct srte_segment_entry *segment;
114 uint32_t index;
115
116 if (args->event != NB_EV_APPLY)
117 return NB_OK;
118
119 segment_list = nb_running_get_entry(args->dnode, NULL, true);
120 index = yang_dnode_get_uint32(args->dnode, "./index");
121 segment = srte_segment_entry_add(segment_list, index);
122 nb_running_set_entry(args->dnode, segment);
123 SET_FLAG(segment_list->flags, F_SEGMENT_LIST_MODIFIED);
124
125 return NB_OK;
126 }
127
128 int pathd_srte_segment_list_segment_destroy(struct nb_cb_destroy_args *args)
129 {
130 struct srte_segment_entry *segment;
131
132 if (args->event != NB_EV_APPLY)
133 return NB_OK;
134
135 segment = nb_running_unset_entry(args->dnode);
136 SET_FLAG(segment->segment_list->flags, F_SEGMENT_LIST_MODIFIED);
137
138 srte_segment_entry_del(segment);
139
140 return NB_OK;
141 }
142
143 /*
144 * XPath: /frr-pathd:pathd/srte/segment-list/segment/sid-value
145 */
146 int pathd_srte_segment_list_segment_sid_value_modify(
147 struct nb_cb_modify_args *args)
148 {
149 mpls_label_t sid_value;
150 struct srte_segment_entry *segment;
151
152 if (args->event != NB_EV_APPLY)
153 return NB_OK;
154
155 segment = nb_running_get_entry(args->dnode, NULL, true);
156 sid_value = yang_dnode_get_uint32(args->dnode, NULL);
157 segment->sid_value = sid_value;
158 SET_FLAG(segment->segment_list->flags, F_SEGMENT_LIST_MODIFIED);
159
160 return NB_OK;
161 }
162
163 int pathd_srte_segment_list_segment_sid_value_destroy(
164 struct nb_cb_destroy_args *args)
165 {
166 struct srte_segment_entry *segment;
167
168 if (args->event != NB_EV_APPLY)
169 return NB_OK;
170
171 segment = nb_running_get_entry(args->dnode, NULL, true);
172 segment->sid_value = MPLS_LABEL_NONE;
173 SET_FLAG(segment->segment_list->flags, F_SEGMENT_LIST_MODIFIED);
174
175 return NB_OK;
176 }
177
178
179 int pathd_srte_segment_list_segment_nai_destroy(struct nb_cb_destroy_args *args)
180 {
181 struct srte_segment_entry *segment;
182
183 if (args->event != NB_EV_APPLY)
184 return NB_OK;
185
186 segment = nb_running_get_entry(args->dnode, NULL, true);
187 segment->nai_type = SRTE_SEGMENT_NAI_TYPE_NONE;
188 segment->nai_local_addr.ipa_type = IPADDR_NONE;
189 segment->nai_local_iface = 0;
190 segment->nai_remote_addr.ipa_type = IPADDR_NONE;
191 segment->nai_remote_iface = 0;
192
193 return NB_OK;
194 }
195
196 void pathd_srte_segment_list_segment_nai_apply_finish(
197 struct nb_cb_apply_finish_args *args)
198 {
199 struct srte_segment_entry *segment;
200 enum srte_segment_nai_type type;
201 struct ipaddr local_addr, remote_addr;
202 uint32_t local_iface = 0, remote_iface = 0;
203 uint8_t algo = 0, local_prefix_len = 0;
204 const char *algo_buf, *local_prefix_len_buf;
205
206 segment = nb_running_get_entry(args->dnode, NULL, true);
207 type = yang_dnode_get_enum(args->dnode, "./type");
208
209 yang_dnode_get_ip(&local_addr, args->dnode, "./local-address");
210
211 switch (type) {
212 case SRTE_SEGMENT_NAI_TYPE_IPV4_NODE:
213 case SRTE_SEGMENT_NAI_TYPE_IPV6_NODE:
214 break;
215 case SRTE_SEGMENT_NAI_TYPE_IPV4_ADJACENCY:
216 case SRTE_SEGMENT_NAI_TYPE_IPV6_ADJACENCY:
217 yang_dnode_get_ip(&remote_addr, args->dnode,
218 "./remote-address");
219 break;
220 case SRTE_SEGMENT_NAI_TYPE_IPV4_UNNUMBERED_ADJACENCY:
221 yang_dnode_get_ip(&remote_addr, args->dnode,
222 "./remote-address");
223 local_iface =
224 yang_dnode_get_uint32(args->dnode, "./local-interface");
225 remote_iface = yang_dnode_get_uint32(args->dnode,
226 "./remote-interface");
227 break;
228 case SRTE_SEGMENT_NAI_TYPE_IPV4_ALGORITHM:
229 algo_buf = yang_dnode_get_string(args->dnode, "./algorithm");
230 algo = atoi(algo_buf);
231 local_prefix_len_buf = yang_dnode_get_string(
232 args->dnode, "./local-prefix-len");
233 local_prefix_len = atoi(local_prefix_len_buf);
234 break;
235 case SRTE_SEGMENT_NAI_TYPE_IPV4_LOCAL_IFACE:
236 local_iface =
237 yang_dnode_get_uint32(args->dnode, "./local-interface");
238 local_prefix_len_buf = yang_dnode_get_string(
239 args->dnode, "./local-prefix-len");
240 local_prefix_len = atoi(local_prefix_len_buf);
241 break;
242 default:
243 break;
244 }
245
246 zlog_debug(" Segment list name (%d) index (%s) ", segment->index,
247 segment->segment_list->name);
248 if (srte_segment_entry_set_nai(segment, type, &local_addr, local_iface,
249 &remote_addr, remote_iface, algo,
250 local_prefix_len))
251 SET_FLAG(segment->segment_list->flags,
252 F_SEGMENT_LIST_SID_CONFLICT);
253 }
254
255 /*
256 * XPath: /frr-pathd:pathd/srte/policy
257 */
258 int pathd_srte_policy_create(struct nb_cb_create_args *args)
259 {
260 struct srte_policy *policy;
261 uint32_t color;
262 struct ipaddr endpoint;
263
264 if (args->event != NB_EV_APPLY)
265 return NB_OK;
266
267 color = yang_dnode_get_uint32(args->dnode, "./color");
268 yang_dnode_get_ip(&endpoint, args->dnode, "./endpoint");
269 policy = srte_policy_add(color, &endpoint, SRTE_ORIGIN_LOCAL, NULL);
270
271 nb_running_set_entry(args->dnode, policy);
272 SET_FLAG(policy->flags, F_POLICY_NEW);
273
274 return NB_OK;
275 }
276
277 int pathd_srte_policy_destroy(struct nb_cb_destroy_args *args)
278 {
279 struct srte_policy *policy;
280
281 if (args->event != NB_EV_APPLY)
282 return NB_OK;
283
284 policy = nb_running_unset_entry(args->dnode);
285 SET_FLAG(policy->flags, F_POLICY_DELETED);
286
287 return NB_OK;
288 }
289
290 /*
291 * XPath: /frr-pathd:pathd/srte/policy/name
292 */
293 int pathd_srte_policy_name_modify(struct nb_cb_modify_args *args)
294 {
295 struct srte_policy *policy;
296 const char *name;
297
298 if (args->event != NB_EV_APPLY && args->event != NB_EV_VALIDATE)
299 return NB_OK;
300
301 policy = nb_running_get_entry(args->dnode, NULL, true);
302
303 if (args->event == NB_EV_VALIDATE) {
304 /* the policy name is fixed after setting it once */
305 if (strlen(policy->name) > 0) {
306 flog_warn(EC_LIB_NB_CB_CONFIG_VALIDATE,
307 "The SR Policy name is fixed!");
308 return NB_ERR_RESOURCE;
309 } else
310 return NB_OK;
311 }
312
313 name = yang_dnode_get_string(args->dnode, NULL);
314 strlcpy(policy->name, name, sizeof(policy->name));
315 SET_FLAG(policy->flags, F_POLICY_MODIFIED);
316
317 return NB_OK;
318 }
319
320 int pathd_srte_policy_name_destroy(struct nb_cb_destroy_args *args)
321 {
322 struct srte_policy *policy;
323
324 if (args->event != NB_EV_APPLY)
325 return NB_OK;
326
327 policy = nb_running_get_entry(args->dnode, NULL, true);
328 policy->name[0] = '\0';
329 SET_FLAG(policy->flags, F_POLICY_MODIFIED);
330
331 return NB_OK;
332 }
333
334 /*
335 * XPath: /frr-pathd:pathd/srte/policy/binding-sid
336 */
337 int pathd_srte_policy_binding_sid_modify(struct nb_cb_modify_args *args)
338 {
339 struct srte_policy *policy;
340 mpls_label_t binding_sid;
341
342 binding_sid = yang_dnode_get_uint32(args->dnode, NULL);
343
344 switch (args->event) {
345 case NB_EV_VALIDATE:
346 break;
347 case NB_EV_PREPARE:
348 if (path_zebra_request_label(binding_sid) < 0)
349 return NB_ERR_RESOURCE;
350 break;
351 case NB_EV_ABORT:
352 break;
353 case NB_EV_APPLY:
354 policy = nb_running_get_entry(args->dnode, NULL, true);
355 srte_policy_update_binding_sid(policy, binding_sid);
356 SET_FLAG(policy->flags, F_POLICY_MODIFIED);
357 break;
358 }
359
360 return NB_OK;
361 }
362
363 int pathd_srte_policy_binding_sid_destroy(struct nb_cb_destroy_args *args)
364 {
365 struct srte_policy *policy;
366
367 if (args->event != NB_EV_APPLY)
368 return NB_OK;
369
370 policy = nb_running_get_entry(args->dnode, NULL, true);
371 srte_policy_update_binding_sid(policy, MPLS_LABEL_NONE);
372 SET_FLAG(policy->flags, F_POLICY_MODIFIED);
373
374 return NB_OK;
375 }
376
377 /*
378 * XPath: /frr-pathd:pathd/srte/policy/candidate-path
379 */
380 int pathd_srte_policy_candidate_path_create(struct nb_cb_create_args *args)
381 {
382 struct srte_policy *policy;
383 struct srte_candidate *candidate;
384 uint32_t preference;
385
386 if (args->event != NB_EV_APPLY)
387 return NB_OK;
388
389 policy = nb_running_get_entry(args->dnode, NULL, true);
390 preference = yang_dnode_get_uint32(args->dnode, "./preference");
391 candidate =
392 srte_candidate_add(policy, preference, SRTE_ORIGIN_LOCAL, NULL);
393 nb_running_set_entry(args->dnode, candidate);
394 SET_FLAG(candidate->flags, F_CANDIDATE_NEW);
395
396 return NB_OK;
397 }
398
399 int pathd_srte_policy_candidate_path_destroy(struct nb_cb_destroy_args *args)
400 {
401 struct srte_candidate *candidate;
402
403 if (args->event != NB_EV_APPLY)
404 return NB_OK;
405
406 candidate = nb_running_unset_entry(args->dnode);
407 SET_FLAG(candidate->flags, F_CANDIDATE_DELETED);
408
409 return NB_OK;
410 }
411
412 /*
413 * XPath: /frr-pathd:pathd/srte/policy/candidate-path/name
414 */
415 int pathd_srte_policy_candidate_path_name_modify(struct nb_cb_modify_args *args)
416 {
417 struct srte_candidate *candidate;
418 const char *name;
419 char xpath[XPATH_MAXLEN];
420 char xpath_buf[XPATH_MAXLEN - 3];
421
422 if (args->event != NB_EV_APPLY && args->event != NB_EV_VALIDATE)
423 return NB_OK;
424
425 /* the candidate name is fixed after setting it once, this is checked
426 * here */
427 if (args->event == NB_EV_VALIDATE) {
428 /* first get the precise path to the candidate path */
429 yang_dnode_get_path(args->dnode, xpath_buf, sizeof(xpath_buf));
430 snprintf(xpath, sizeof(xpath), "%s%s", xpath_buf, "/..");
431
432 candidate = nb_running_get_entry_non_rec(NULL, xpath, false);
433
434 /* then check if it exists and if the name was provided */
435 if (candidate && strlen(candidate->name) > 0) {
436 flog_warn(EC_LIB_NB_CB_CONFIG_VALIDATE,
437 "The candidate name is fixed!");
438 return NB_ERR_RESOURCE;
439 } else
440 return NB_OK;
441 }
442
443 candidate = nb_running_get_entry(args->dnode, NULL, true);
444
445 name = yang_dnode_get_string(args->dnode, NULL);
446 strlcpy(candidate->name, name, sizeof(candidate->name));
447 SET_FLAG(candidate->flags, F_CANDIDATE_MODIFIED);
448
449 return NB_OK;
450 }
451
452
453 static int affinity_filter_modify(struct nb_cb_modify_args *args,
454 enum affinity_filter_type type)
455 {
456 uint32_t filter;
457 struct srte_candidate *candidate;
458
459 if (args->event != NB_EV_APPLY)
460 return NB_OK;
461
462 assert(args->context != NULL);
463 candidate = nb_running_get_entry(args->dnode, NULL, true);
464 filter = yang_dnode_get_uint32(args->dnode, NULL);
465 srte_candidate_set_affinity_filter(candidate, type, filter);
466
467 return NB_OK;
468 }
469
470 static int affinity_filter_destroy(struct nb_cb_destroy_args *args,
471 enum affinity_filter_type type)
472 {
473 struct srte_candidate *candidate;
474
475 if (args->event != NB_EV_APPLY)
476 return NB_OK;
477
478 assert(args->context != NULL);
479 candidate = nb_running_get_entry(args->dnode, NULL, true);
480 srte_candidate_unset_affinity_filter(candidate, type);
481
482 return NB_OK;
483 }
484
485 /*
486 * XPath:
487 * /frr-pathd:pathd/srte/policy/candidate-path/constraints/affinity/exclude-any
488 */
489
490 int pathd_srte_policy_candidate_path_exclude_any_modify(
491 struct nb_cb_modify_args *args)
492 {
493 return affinity_filter_modify(args, AFFINITY_FILTER_EXCLUDE_ANY);
494 }
495
496 int pathd_srte_policy_candidate_path_exclude_any_destroy(
497 struct nb_cb_destroy_args *args)
498 {
499 return affinity_filter_destroy(args, AFFINITY_FILTER_EXCLUDE_ANY);
500 }
501
502
503 /*
504 * XPath:
505 * /frr-pathd:pathd/srte/policy/candidate-path/constraints/affinity/include-any
506 */
507 int pathd_srte_policy_candidate_path_include_any_modify(
508 struct nb_cb_modify_args *args)
509 {
510 return affinity_filter_modify(args, AFFINITY_FILTER_INCLUDE_ANY);
511 }
512
513 int pathd_srte_policy_candidate_path_include_any_destroy(
514 struct nb_cb_destroy_args *args)
515 {
516 return affinity_filter_destroy(args, AFFINITY_FILTER_INCLUDE_ANY);
517 }
518
519
520 /*
521 * XPath:
522 * /frr-pathd:pathd/srte/policy/candidate-path/constraints/affinity/include-all
523 */
524 int pathd_srte_policy_candidate_path_include_all_modify(
525 struct nb_cb_modify_args *args)
526 {
527 return affinity_filter_modify(args, AFFINITY_FILTER_INCLUDE_ALL);
528 }
529
530 int pathd_srte_policy_candidate_path_include_all_destroy(
531 struct nb_cb_destroy_args *args)
532 {
533 return affinity_filter_destroy(args, AFFINITY_FILTER_INCLUDE_ALL);
534 }
535
536
537 /*
538 * XPath: /frr-pathd:pathd/srte/policy/candidate-path/constraints/metrics
539 */
540 int pathd_srte_policy_candidate_path_metrics_destroy(
541 struct nb_cb_destroy_args *args)
542 {
543 struct srte_candidate *candidate;
544 enum srte_candidate_metric_type type;
545
546 if (args->event != NB_EV_APPLY)
547 return NB_OK;
548
549 assert(args->context != NULL);
550 candidate = nb_running_get_entry(args->dnode, NULL, true);
551
552 type = yang_dnode_get_enum(args->dnode, "./type");
553 srte_candidate_unset_metric(candidate, type);
554
555 return NB_OK;
556 }
557
558 void pathd_srte_policy_candidate_path_metrics_apply_finish(
559 struct nb_cb_apply_finish_args *args)
560 {
561 struct srte_candidate *candidate;
562 enum srte_candidate_metric_type type;
563 float value;
564 bool required, is_bound = false, is_computed = false;
565
566 assert(args->context != NULL);
567
568 candidate = nb_running_get_entry(args->dnode, NULL, true);
569
570 type = yang_dnode_get_enum(args->dnode, "./type");
571 value = (float)yang_dnode_get_dec64(args->dnode, "./value");
572 required = yang_dnode_get_bool(args->dnode, "./required");
573 if (yang_dnode_exists(args->dnode, "./is-bound"))
574 is_bound = yang_dnode_get_bool(args->dnode, "./is-bound");
575 if (yang_dnode_exists(args->dnode, "./is-computed"))
576 is_computed = yang_dnode_get_bool(args->dnode, "./is-computed");
577
578 srte_candidate_set_metric(candidate, type, value, required, is_bound,
579 is_computed);
580 }
581
582 /*
583 * XPath:
584 * /frr-pathd:pathd/srte/policy/candidate-path/constraints/objective-function
585 */
586 int pathd_srte_policy_candidate_path_objfun_destroy(
587 struct nb_cb_destroy_args *args)
588 {
589 struct srte_candidate *candidate;
590
591 if (args->event != NB_EV_APPLY)
592 return NB_OK;
593
594 assert(args->context != NULL);
595
596 candidate = nb_running_get_entry(args->dnode, NULL, true);
597 srte_candidate_unset_objfun(candidate);
598
599 return NB_OK;
600 }
601
602 void pathd_srte_policy_candidate_path_objfun_apply_finish(
603 struct nb_cb_apply_finish_args *args)
604 {
605 struct srte_candidate *candidate;
606 enum objfun_type type;
607 bool required;
608
609 candidate = nb_running_get_entry(args->dnode, NULL, true);
610 required = yang_dnode_get_bool(args->dnode, "./required");
611 type = yang_dnode_get_enum(args->dnode, "./type");
612 srte_candidate_set_objfun(candidate, required, type);
613 }
614
615 /*
616 * XPath: /frr-pathd:pathd/srte/policy/candidate-path/protocol-origin
617 */
618 int pathd_srte_policy_candidate_path_protocol_origin_modify(
619 struct nb_cb_modify_args *args)
620 {
621 struct srte_candidate *candidate;
622 enum srte_protocol_origin protocol_origin;
623
624 if (args->event != NB_EV_APPLY)
625 return NB_OK;
626
627 candidate = nb_running_get_entry(args->dnode, NULL, true);
628 protocol_origin = yang_dnode_get_enum(args->dnode, NULL);
629 candidate->protocol_origin = protocol_origin;
630 candidate->lsp->protocol_origin = protocol_origin;
631 SET_FLAG(candidate->flags, F_CANDIDATE_MODIFIED);
632
633 return NB_OK;
634 }
635
636 /*
637 * XPath: /frr-pathd:pathd/srte/policy/candidate-path/originator
638 */
639 int pathd_srte_policy_candidate_path_originator_modify(
640 struct nb_cb_modify_args *args)
641 {
642 struct srte_candidate *candidate;
643 const char *originator;
644
645 if (args->event != NB_EV_APPLY)
646 return NB_OK;
647
648 candidate = nb_running_get_entry(args->dnode, NULL, true);
649 originator = yang_dnode_get_string(args->dnode, NULL);
650 strlcpy(candidate->originator, originator,
651 sizeof(candidate->originator));
652 strlcpy(candidate->lsp->originator, originator,
653 sizeof(candidate->lsp->originator));
654 SET_FLAG(candidate->flags, F_CANDIDATE_MODIFIED);
655
656 return NB_OK;
657 }
658
659 /*
660 * XPath: /frr-pathd:pathd/srte/policy/candidate-path/type
661 */
662 int pathd_srte_policy_candidate_path_type_modify(struct nb_cb_modify_args *args)
663 {
664 struct srte_candidate *candidate;
665 enum srte_candidate_type type;
666 char xpath[XPATH_MAXLEN];
667 char xpath_buf[XPATH_MAXLEN - 3];
668
669 if (args->event != NB_EV_APPLY && args->event != NB_EV_VALIDATE)
670 return NB_OK;
671
672 /* the candidate type is fixed after setting it once, this is checked
673 * here */
674 if (args->event == NB_EV_VALIDATE) {
675 /* first get the precise path to the candidate path */
676 yang_dnode_get_path(args->dnode, xpath_buf, sizeof(xpath_buf));
677 snprintf(xpath, sizeof(xpath), "%s%s", xpath_buf, "/..");
678
679 candidate = nb_running_get_entry_non_rec(NULL, xpath, false);
680
681 /* then check if it exists and if the type was provided */
682 if (candidate
683 && candidate->type != SRTE_CANDIDATE_TYPE_UNDEFINED) {
684 flog_warn(EC_LIB_NB_CB_CONFIG_VALIDATE,
685 "The candidate type is fixed!");
686 return NB_ERR_RESOURCE;
687 } else
688 return NB_OK;
689 }
690
691 candidate = nb_running_get_entry(args->dnode, NULL, true);
692
693 type = yang_dnode_get_enum(args->dnode, NULL);
694 candidate->type = type;
695 SET_FLAG(candidate->flags, F_CANDIDATE_MODIFIED);
696
697 return NB_OK;
698 }
699
700 /*
701 * XPath: /frr-pathd:pathd/srte/policy/candidate-path/segment-list-name
702 */
703 int pathd_srte_policy_candidate_path_segment_list_name_modify(
704 struct nb_cb_modify_args *args)
705 {
706 struct srte_candidate *candidate;
707 const char *segment_list_name;
708
709 if (args->event != NB_EV_APPLY)
710 return NB_OK;
711
712 candidate = nb_running_get_entry(args->dnode, NULL, true);
713 segment_list_name = yang_dnode_get_string(args->dnode, NULL);
714
715 candidate->segment_list = srte_segment_list_find(segment_list_name);
716 candidate->lsp->segment_list = candidate->segment_list;
717 assert(candidate->segment_list);
718 SET_FLAG(candidate->flags, F_CANDIDATE_MODIFIED);
719
720 return NB_OK;
721 }
722
723 int pathd_srte_policy_candidate_path_segment_list_name_destroy(
724 struct nb_cb_destroy_args *args)
725 {
726 struct srte_candidate *candidate;
727
728 if (args->event != NB_EV_APPLY)
729 return NB_OK;
730
731 candidate = nb_running_get_entry(args->dnode, NULL, true);
732 candidate->segment_list = NULL;
733 candidate->lsp->segment_list = NULL;
734 SET_FLAG(candidate->flags, F_CANDIDATE_MODIFIED);
735
736 return NB_OK;
737 }
738
739 /*
740 * XPath: /frr-pathd:pathd/srte/policy/candidate-path/constraints/bandwidth
741 */
742 void pathd_srte_policy_candidate_path_bandwidth_apply_finish(
743 struct nb_cb_apply_finish_args *args)
744 {
745 struct srte_candidate *candidate;
746 float value;
747 bool required;
748
749 assert(args->context != NULL);
750
751 candidate = nb_running_get_entry(args->dnode, NULL, true);
752 value = (float)yang_dnode_get_dec64(args->dnode, "./value");
753 required = yang_dnode_get_bool(args->dnode, "./required");
754 srte_candidate_set_bandwidth(candidate, value, required);
755 }
756
757 int pathd_srte_policy_candidate_path_bandwidth_destroy(
758 struct nb_cb_destroy_args *args)
759 {
760 struct srte_candidate *candidate;
761
762 if (args->event != NB_EV_APPLY)
763 return NB_OK;
764
765 assert(args->context != NULL);
766 candidate = nb_running_get_entry(args->dnode, NULL, true);
767 srte_candidate_unset_bandwidth(candidate);
768 return NB_OK;
769 }