Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pathd: refactor config processing #24

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 24 additions & 52 deletions pathd/path_cli.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 NetDEF, Inc.
* 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
Expand Down Expand Up @@ -138,6 +138,9 @@ DEFPY(show_srte_policy_detail, show_srte_policy_detail_cmd,

RB_FOREACH (candidate, srte_candidate_head,
&policy->candidate_paths) {
struct srte_segment_list *segment_list;

segment_list = candidate->lsp->segment_list;
vty_out(vty,
" %s Preference: %d Name: %s Type: %s Segment-List: %s Protocol-Origin: %s\n",
CHECK_FLAG(candidate->flags, F_CANDIDATE_BEST)
Expand All @@ -147,10 +150,13 @@ DEFPY(show_srte_policy_detail, show_srte_policy_detail_cmd,
candidate->type == SRTE_CANDIDATE_TYPE_EXPLICIT
? "explicit"
: "dynamic",
candidate->segment_list == NULL
segment_list == NULL
|| segment_list->protocol_origin
== SRTE_ORIGIN_PCEP
? "(undefined)"
: candidate->segment_list->name,
srte_origin2str(candidate->protocol_origin));
: candidate->lsp->segment_list->name,
srte_origin2str(
candidate->lsp->protocol_origin));
}

vty_out(vty, "\n");
Expand Down Expand Up @@ -211,11 +217,6 @@ DEFPY(no_te_path_segment_list, no_te_path_segment_list_cmd,
void cli_show_te_path_segment_list(struct vty *vty, struct lyd_node *dnode,
bool show_defaults)
{
enum srte_protocol_origin origin;
origin = yang_dnode_get_enum(dnode, "./protocol-origin");
if (origin != SRTE_ORIGIN_LOCAL)
return;

vty_out(vty, "segment-list %s\n",
yang_dnode_get_string(dnode, "./name"));
}
Expand Down Expand Up @@ -292,11 +293,6 @@ void cli_show_te_path_segment_list_segment(struct vty *vty,
struct lyd_node *dnode,
bool show_defaults)
{
enum srte_protocol_origin origin;
origin = yang_dnode_get_enum(dnode, "../protocol-origin");
if (origin != SRTE_ORIGIN_LOCAL)
return;

vty_out(vty, " index %s mpls label %s",
yang_dnode_get_string(dnode, "./index"),
yang_dnode_get_string(dnode, "./sid-value"));
Expand Down Expand Up @@ -599,23 +595,21 @@ static void config_write_metric(struct vty *vty,
config_write_float(vty, value);
}

/* FIXME: Enable this back when the candidate path are only containing
* configuration data */
// static int config_write_metric_cb(const struct lyd_node *dnode, void *arg)
// {
// struct vty *vty = arg;
// enum srte_candidate_metric_type type;
// bool is_bound = false;
// float value;
static int config_write_metric_cb(const struct lyd_node *dnode, void *arg)
{
struct vty *vty = arg;
enum srte_candidate_metric_type type;
bool is_bound = false;
float value;

// type = yang_dnode_get_enum(dnode, "./type");
// value = (float)yang_dnode_get_dec64(dnode, "./value");
// if (yang_dnode_exists(dnode, "./is-bound"))
// is_bound = yang_dnode_get_bool(dnode, "./is-bound");
type = yang_dnode_get_enum(dnode, "./type");
value = (float)yang_dnode_get_dec64(dnode, "./value");
if (yang_dnode_exists(dnode, "./is-bound"))
is_bound = yang_dnode_get_bool(dnode, "./is-bound");

// config_write_metric(vty, type, value, is_bound);
// return YANG_ITER_CONTINUE;
// }
config_write_metric(vty, type, value, is_bound);
return YANG_ITER_CONTINUE;
}

void cli_show_te_path_sr_policy_candidate_path(struct vty *vty,
struct lyd_node *dnode,
Expand All @@ -632,29 +626,7 @@ void cli_show_te_path_sr_policy_candidate_path(struct vty *vty,
if (yang_dnode_exists(dnode, "./metrics"))
vty_out(vty, " metrics");

/* FIXME: Candidate path contains both configuration and transient
* data. This is not what we want os until it is fixed we need to
* hack around it */
// yang_dnode_iterate(config_write_metric_cb, vty, dnode, "./metrics");
struct srte_candidate *candidate;
bool is_bound;
candidate = nb_running_get_entry(dnode, NULL, true);
if (CHECK_FLAG(candidate->flags, F_CANDIDATE_HAS_METRIC_ABC)) {
is_bound = CHECK_FLAG(candidate->flags,
F_CANDIDATE_METRIC_ABC_BOUND);
config_write_metric(vty, SRTE_CANDIDATE_METRIC_TYPE_ABC,
candidate->metric_abc, is_bound);
}
if (CHECK_FLAG(candidate->flags, F_CANDIDATE_HAS_METRIC_TE)) {
is_bound = CHECK_FLAG(candidate->flags,
F_CANDIDATE_METRIC_TE_BOUND);
config_write_metric(vty, SRTE_CANDIDATE_METRIC_TYPE_TE,
candidate->metric_te, is_bound);
}
if (CHECK_FLAG(candidate->flags, F_CANDIDATE_HAS_BANDWIDTH)) {
vty_out(vty, " bandwidth");
config_write_float(vty, candidate->bandwidth);
}
yang_dnode_iterate(config_write_metric_cb, vty, dnode, "./metrics");

vty_out(vty, "\n");
}
Expand Down
58 changes: 28 additions & 30 deletions pathd/path_nb_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,38 +181,37 @@ void pathd_te_segment_list_segment_nai_apply_finish(
{
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;

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:
segment->nai_type = type;
yang_dnode_get_ip(&segment->nai_local_addr, args->dnode,
"./local-address");
break;
case SRTE_SEGMENT_NAI_TYPE_IPV4_ADJACENCY:
case SRTE_SEGMENT_NAI_TYPE_IPV6_ADJACENCY:
segment->nai_type = type;
yang_dnode_get_ip(&segment->nai_local_addr, args->dnode,
"./local-address");
yang_dnode_get_ip(&segment->nai_remote_addr, args->dnode,
yang_dnode_get_ip(&remote_addr, args->dnode,
"./remote-address");
break;
case SRTE_SEGMENT_NAI_TYPE_IPV4_UNNUMBERED_ADJACENCY:
segment->nai_type = type;
yang_dnode_get_ip(&segment->nai_local_addr, args->dnode,
"./local-address");
segment->nai_local_iface =
yang_dnode_get_uint32(args->dnode, "./local-interface");
yang_dnode_get_ip(&segment->nai_remote_addr, args->dnode,
yang_dnode_get_ip(&remote_addr, args->dnode,
"./remote-address");
segment->nai_remote_iface =
yang_dnode_get_uint32(args->dnode, "./remote-interface");
local_iface =
yang_dnode_get_uint32(args->dnode, "./local-interface");
remote_iface = yang_dnode_get_uint32(args->dnode,
"./remote-interface");
break;
default:
segment->nai_type = SRTE_SEGMENT_NAI_TYPE_NONE;
return;
break;
}

srte_segment_entry_set_nai(segment, type, &local_addr, local_iface,
&remote_addr, remote_iface);
}

/*
Expand Down Expand Up @@ -420,17 +419,15 @@ int pathd_te_sr_policy_candidate_path_metrics_destroy(
{
struct srte_candidate *candidate;
enum srte_candidate_metric_type type;
bool is_config;

if (args->event != NB_EV_APPLY)
return NB_OK;

assert(args->context != NULL);
is_config = args->context->client == NB_CLIENT_CLI;
candidate = nb_running_get_entry(args->dnode, NULL, true);

type = yang_dnode_get_enum(args->dnode, "./type");
srte_candidate_unset_metric(candidate, type, is_config);
srte_candidate_unset_metric(candidate, type);

return NB_OK;
}
Expand All @@ -441,10 +438,9 @@ void pathd_te_sr_policy_candidate_path_metrics_apply_finish(
struct srte_candidate *candidate;
enum srte_candidate_metric_type type;
float value;
bool is_bound = false, is_computed = false, is_config;
bool is_bound = false, is_computed = false;

assert(args->context != NULL);
is_config = args->context->client == NB_CLIENT_CLI;

candidate = nb_running_get_entry(args->dnode, NULL, true);

Expand All @@ -455,8 +451,8 @@ void pathd_te_sr_policy_candidate_path_metrics_apply_finish(
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, is_bound, is_computed,
is_config);
srte_candidate_set_metric(candidate, type, value, is_bound,
is_computed);
}

/*
Expand All @@ -474,6 +470,7 @@ int pathd_te_sr_policy_candidate_path_protocol_origin_modify(
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;
Expand All @@ -495,6 +492,8 @@ int pathd_te_sr_policy_candidate_path_originator_modify(
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;
Expand All @@ -515,6 +514,7 @@ int pathd_te_sr_policy_candidate_path_discriminator_modify(
candidate = nb_running_get_entry(args->dnode, NULL, true);
discriminator = yang_dnode_get_uint32(args->dnode, NULL);
candidate->discriminator = discriminator;
candidate->lsp->discriminator = discriminator;
SET_FLAG(candidate->flags, F_CANDIDATE_MODIFIED);

return NB_OK;
Expand Down Expand Up @@ -578,6 +578,7 @@ int pathd_te_sr_policy_candidate_path_segment_list_name_modify(
return NB_OK;

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);

Expand All @@ -594,6 +595,7 @@ int pathd_te_sr_policy_candidate_path_segment_list_name_destroy(

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;
Expand All @@ -607,31 +609,27 @@ int pathd_te_sr_policy_candidate_path_bandwidth_modify(
{
struct srte_candidate *candidate;
float value;
bool is_config;

if (args->event != NB_EV_APPLY)
return NB_OK;

assert(args->context != NULL);
is_config = args->context->client == NB_CLIENT_CLI;
candidate = nb_running_get_entry(args->dnode, NULL, true);
value = (float)yang_dnode_get_dec64(args->dnode, NULL);
srte_candidate_set_bandwidth(candidate, value, is_config);
srte_candidate_set_bandwidth(candidate, value);
return NB_OK;
}

int pathd_te_sr_policy_candidate_path_bandwidth_destroy(
struct nb_cb_destroy_args *args)
{
struct srte_candidate *candidate;
bool is_config;

if (args->event != NB_EV_APPLY)
return NB_OK;

assert(args->context != NULL);
is_config = args->context->client == NB_CLIENT_CLI;
candidate = nb_running_get_entry(args->dnode, NULL, true);
srte_candidate_unset_bandwidth(candidate, is_config);
srte_candidate_unset_bandwidth(candidate);
return NB_OK;
}
8 changes: 4 additions & 4 deletions pathd/path_pcep.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include "pathd/path_pcep.h"
#include "pathd/path_pcep_controller.h"
#include "pathd/path_pcep_lib.h"
#include "pathd/path_pcep_nb.h"
#include "pathd/path_pcep_config.h"


/*
Expand Down Expand Up @@ -201,7 +201,7 @@ int pcep_main_event_handler(enum pcep_main_event_type type, int pcc_id,

int pcep_main_event_start_sync(int pcc_id)
{
path_nb_list_path(pcep_main_event_start_sync_cb, &pcc_id);
path_pcep_config_list_path(pcep_main_event_start_sync_cb, &pcc_id);
pcep_ctrl_sync_done(pcep_g->fpt, pcc_id);
return 0;
}
Expand All @@ -218,14 +218,14 @@ int pcep_main_event_update_candidate(struct path *path)
struct path *resp = NULL;
int ret = 0;

ret = path_nb_update_path(path);
ret = path_pcep_config_update_path(path);
if (ret != PATH_NB_ERR && path->srp_id != 0) {
/* ODL and Cisco requires the first reported
* LSP to have a DOWN status, the later status changes
* will be comunicated through hook calls.
*/
enum pcep_lsp_operational_status real_status;
if ((resp = path_nb_get_path(&path->nbkey))) {
if ((resp = path_pcep_config_get_path(&path->nbkey))) {
resp->srp_id = path->srp_id;
real_status = resp->status;
resp->status = PCEP_LSP_OPERATIONAL_DOWN;
Expand Down
Loading