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

Routemap nb #7419

Merged
merged 6 commits into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
ospfd: North-bound implementation for ospfd rmaps
This commit introduces the implementation for the north-bound
callbacks for the ospfd-specific route-map match and set clauses.

Signed-off-by: NaveenThanikachalam <nthanikachal@vmware.com>
Signed-off-by: Sarita Patra <saritap@vmware.com>
  • Loading branch information
patrasar authored and idryzhov committed Mar 30, 2021
commit a623b52619466dc977e37f78a6d0afb69cb0e2b6
2 changes: 2 additions & 0 deletions ospfd/ospf_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "ospfd/ospf_bfd.h"
#include "ospfd/ospf_errors.h"
#include "ospfd/ospf_ldp_sync.h"
#include "ospfd/ospf_routemap_nb.h"

/* ospfd privileges */
zebra_capabilities_t _caps_p[] = {ZCAP_NET_RAW, ZCAP_BIND, ZCAP_NET_ADMIN,
Expand Down Expand Up @@ -134,6 +135,7 @@ static const struct frr_yang_module_info *const ospfd_yang_modules[] = {
&frr_interface_info,
&frr_route_map_info,
&frr_vrf_info,
&frr_ospf_route_map_info,
};

FRR_DAEMON_INFO(ospfd, OSPF, .vty_port = OSPF_VTY_PORT,
Expand Down
25 changes: 18 additions & 7 deletions ospfd/ospf_routemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "plist.h"
#include "vrf.h"
#include "frrstr.h"
#include "northbound_cli.h"

#include "ospfd/ospfd.h"
#include "ospfd/ospf_asbr.h"
Expand Down Expand Up @@ -534,7 +535,7 @@ static const struct route_map_rule_cmd route_set_tag_cmd = {
route_map_rule_tag_free,
};

DEFUN (set_metric_type,
DEFUN_YANG (set_metric_type,
set_metric_type_cmd,
"set metric-type <type-1|type-2>",
SET_STR
Expand All @@ -543,11 +544,19 @@ DEFUN (set_metric_type,
"OSPF[6] external type 2 metric\n")
{
char *ext = argv[2]->text;
return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index),
"metric-type", ext);

const char *xpath =
"./set-action[action='frr-ospf-route-map:metric-type']";
char xpath_value[XPATH_MAXLEN];

nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
snprintf(xpath_value, sizeof(xpath_value),
"%s/rmap-set-action/frr-ospf-route-map:metric-type", xpath);
nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, ext);
return nb_cli_apply_changes(vty, NULL);
}

DEFUN (no_set_metric_type,
DEFUN_YANG (no_set_metric_type,
no_set_metric_type_cmd,
"no set metric-type [<type-1|type-2>]",
NO_STR
Expand All @@ -556,9 +565,11 @@ DEFUN (no_set_metric_type,
"OSPF[6] external type 1 metric\n"
"OSPF[6] external type 2 metric\n")
{
char *ext = (argc == 4) ? argv[3]->text : NULL;
return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index),
"metric-type", ext);
const char *xpath =
"./set-action[action='frr-ospf-route-map:metric-type']";

nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
return nb_cli_apply_changes(vty, NULL);
}

/* Route-map init */
Expand Down
39 changes: 39 additions & 0 deletions ospfd/ospf_routemap_nb.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2020 Vmware
* Sarita Patra
*
* 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 "lib/northbound.h"
#include "lib/routemap.h"
#include "ospf_routemap_nb.h"

/* clang-format off */
const struct frr_yang_module_info frr_ospf_route_map_info = {
.name = "frr-ospf-route-map",
.nodes = {
{
.xpath = "/frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-ospf-route-map:metric-type",
.cbs = {
.modify = lib_route_map_entry_set_action_rmap_set_action_metric_type_modify,
.destroy = lib_route_map_entry_set_action_rmap_set_action_metric_type_destroy,
}
},
{
.xpath = NULL,
},
}
};
37 changes: 37 additions & 0 deletions ospfd/ospf_routemap_nb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2020 Vmware
* Sarita Patra
*
* 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
*/

#ifndef _FRR_OSPF_ROUTEMAP_NB_H_
#define _FRR_OSPF_ROUTEMAP_NB_H_

#ifdef __cplusplus
extern "C" {
#endif

extern const struct frr_yang_module_info frr_ospf_route_map_info;

/* prototypes */
int lib_route_map_entry_set_action_rmap_set_action_metric_type_modify(struct nb_cb_modify_args *args);
int lib_route_map_entry_set_action_rmap_set_action_metric_type_destroy(struct nb_cb_destroy_args *args);

#ifdef __cplusplus
}
#endif

#endif
63 changes: 63 additions & 0 deletions ospfd/ospf_routemap_nb_config.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (C) 2020 Vmware
* Sarita Patra
*
* 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 "lib/command.h"
#include "lib/log.h"
#include "lib/northbound.h"
#include "lib/routemap.h"
#include "ospf_routemap_nb.h"

/*
* XPath:
* /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-ospf-route-map:metric-type
*/
int lib_route_map_entry_set_action_rmap_set_action_metric_type_modify(
struct nb_cb_modify_args *args)
{
struct routemap_hook_context *rhc;
const char *type;
int rv;

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

/* Add configuration. */
rhc = nb_running_get_entry(args->dnode, NULL, true);
type = yang_dnode_get_string(args->dnode, NULL);

/* Set destroy information. */
rhc->rhc_shook = generic_set_delete;
rhc->rhc_rule = "metric-type";
rhc->rhc_event = RMAP_EVENT_SET_DELETED;

rv = generic_set_add(rhc->rhc_rmi, "metric-type", type,
args->errmsg, args->errmsg_len);
if (rv != CMD_SUCCESS) {
rhc->rhc_mhook = NULL;
return NB_ERR_INCONSISTENCY;
}

return NB_OK;
}

int lib_route_map_entry_set_action_rmap_set_action_metric_type_destroy(
struct nb_cb_destroy_args *args)
{
return lib_route_map_entry_set_destroy(args);
}
1 change: 1 addition & 0 deletions ospfd/ospfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -732,4 +732,5 @@ extern int p_spaces_compare_func(const struct p_space *a,
const struct p_space *b);
extern int q_spaces_compare_func(const struct q_space *a,
const struct q_space *b);

#endif /* _ZEBRA_OSPFD_H */
7 changes: 7 additions & 0 deletions ospfd/subdir.am
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ ospfd_libfrrospf_a_SOURCES = \
ospfd/ospf_ri.c \
ospfd/ospf_route.c \
ospfd/ospf_routemap.c \
ospfd/ospf_routemap_nb.c \
ospfd/ospf_routemap_nb_config.c \
ospfd/ospf_spf.c \
ospfd/ospf_ti_lfa.c \
ospfd/ospf_sr.c \
Expand Down Expand Up @@ -100,6 +102,7 @@ noinst_HEADERS += \
ospfd/ospf_packet.h \
ospfd/ospf_ri.h \
ospfd/ospf_route.h \
ospfd/ospf_routemap_nb.h \
ospfd/ospf_spf.h \
ospfd/ospf_ti_lfa.h \
ospfd/ospf_sr.h \
Expand All @@ -120,3 +123,7 @@ ospfd_ospfd_snmp_la_LIBADD = lib/libfrrsnmp.la
EXTRA_DIST += \
ospfd/ChangeLog.opaque.txt \
# end

nodist_ospfd_ospfd_SOURCES = \
yang/frr-ospf-route-map.yang.c \
# end