From 4e0a7355c22cf06e4d1fb2e2b6a398055944ad13 Mon Sep 17 00:00:00 2001 From: Chirag Shah Date: Wed, 19 Feb 2020 13:26:41 -0800 Subject: [PATCH] lib: add interface operational northbound callback Signed-off-by: Chirag Shah --- lib/if.c | 138 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/if.h | 18 ++++++++ 2 files changed, 156 insertions(+) diff --git a/lib/if.c b/lib/if.c index cc964106d0..f557d7a1dd 100644 --- a/lib/if.c +++ b/lib/if.c @@ -1667,6 +1667,96 @@ static int lib_interface_description_destroy(enum nb_event event, return NB_OK; } +/* + * XPath: /frr-interface:lib/interface/state/if-index + */ +struct yang_data *lib_interface_state_if_index_get_elem(const char *xpath, + const void *list_entry) +{ + const struct interface *ifp = list_entry; + + return yang_data_new_int32(xpath, ifp->ifindex); +} + +/* + * XPath: /frr-interface:lib/interface/state/mtu + */ +struct yang_data *lib_interface_state_mtu_get_elem(const char *xpath, + const void *list_entry) +{ + const struct interface *ifp = list_entry; + + return yang_data_new_uint16(xpath, ifp->mtu); +} + +/* + * XPath: /frr-interface:lib/interface/state/mtu6 + */ +struct yang_data *lib_interface_state_mtu6_get_elem(const char *xpath, + const void *list_entry) +{ + const struct interface *ifp = list_entry; + + return yang_data_new_uint32(xpath, ifp->mtu6); +} + +/* + * XPath: /frr-interface:lib/interface/state/speed + */ +struct yang_data *lib_interface_state_speed_get_elem(const char *xpath, + const void *list_entry) +{ + const struct interface *ifp = list_entry; + + return yang_data_new_uint32(xpath, ifp->speed); +} + +/* + * XPath: /frr-interface:lib/interface/state/metric + */ +struct yang_data *lib_interface_state_metric_get_elem(const char *xpath, + const void *list_entry) +{ + const struct interface *ifp = list_entry; + + return yang_data_new_uint32(xpath, ifp->metric); +} + +/* + * XPath: /frr-interface:lib/interface/state/flags + */ +struct yang_data *lib_interface_state_flags_get_elem(const char *xpath, + const void *list_entry) +{ + /* TODO: implement me. */ + return NULL; +} + +/* + * XPath: /frr-interface:lib/interface/state/type + */ +struct yang_data *lib_interface_state_type_get_elem(const char *xpath, + const void *list_entry) +{ + /* TODO: implement me. */ + return NULL; +} + +/* + * XPath: /frr-interface:lib/interface/state/phy-address + */ +struct yang_data * +lib_interface_state_phy_address_get_elem(const char *xpath, + const void *list_entry) +{ + const struct interface *ifp = list_entry; + struct ethaddr macaddr; + + memcpy(&macaddr.octet, ifp->hw_addr, ETH_ALEN); + + return yang_data_new_mac(xpath, &macaddr); +} + /* clang-format off */ const struct frr_yang_module_info frr_interface_info = { @@ -1691,6 +1781,54 @@ const struct frr_yang_module_info frr_interface_info = { .cli_show = cli_show_interface_desc, }, }, + { + .xpath = "/frr-interface:lib/interface/state/if-index", + .cbs = { + .get_elem = lib_interface_state_if_index_get_elem, + } + }, + { + .xpath = "/frr-interface:lib/interface/state/mtu", + .cbs = { + .get_elem = lib_interface_state_mtu_get_elem, + } + }, + { + .xpath = "/frr-interface:lib/interface/state/mtu6", + .cbs = { + .get_elem = lib_interface_state_mtu6_get_elem, + } + }, + { + .xpath = "/frr-interface:lib/interface/state/speed", + .cbs = { + .get_elem = lib_interface_state_speed_get_elem, + } + }, + { + .xpath = "/frr-interface:lib/interface/state/metric", + .cbs = { + .get_elem = lib_interface_state_metric_get_elem, + } + }, + { + .xpath = "/frr-interface:lib/interface/state/flags", + .cbs = { + .get_elem = lib_interface_state_flags_get_elem, + } + }, + { + .xpath = "/frr-interface:lib/interface/state/type", + .cbs = { + .get_elem = lib_interface_state_type_get_elem, + } + }, + { + .xpath = "/frr-interface:lib/interface/state/phy-address", + .cbs = { + .get_elem = lib_interface_state_phy_address_get_elem, + } + }, { .xpath = NULL, }, diff --git a/lib/if.h b/lib/if.h index ac8d8e70ba..9afbb5acc8 100644 --- a/lib/if.h +++ b/lib/if.h @@ -602,6 +602,24 @@ extern void if_destroy_via_zapi(struct interface *ifp); extern const struct frr_yang_module_info frr_interface_info; +struct yang_data *lib_interface_state_if_index_get_elem(const char *xpath, + const void *list_entry); +struct yang_data *lib_interface_state_mtu_get_elem(const char *xpath, + const void *list_entry); +struct yang_data *lib_interface_state_mtu6_get_elem(const char *xpath, + const void *list_entry); +struct yang_data *lib_interface_state_speed_get_elem(const char *xpath, + const void *list_entry); +struct yang_data *lib_interface_state_metric_get_elem(const char *xpath, + const void *list_entry); +struct yang_data *lib_interface_state_flags_get_elem(const char *xpath, + const void *list_entry); +struct yang_data *lib_interface_state_type_get_elem(const char *xpath, + const void *list_entry); +struct yang_data * +lib_interface_state_phy_address_get_elem(const char *xpath, + const void *list_entry); + #ifdef __cplusplus } #endif -- 2.39.5