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