From: Karen Schoener Date: Wed, 22 Jul 2020 16:41:57 +0000 (-0400) Subject: lib: adding support for LDP IGP Sync feature X-Git-Tag: base_7.6~571^2~2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=24e7c5c8975630d93f619b333dbdf417b316fd0c;p=mirror%2Ffrr.git lib: adding support for LDP IGP Sync feature Signed-off-by: Lynne Morrison Signed-off-by: Karen Schoener --- diff --git a/lib/command.h b/lib/command.h index e20bfe3318..d828989118 100644 --- a/lib/command.h +++ b/lib/command.h @@ -421,6 +421,11 @@ struct cmd_node { #define CMD_VNI_RANGE "(1-16777215)" #define CONF_BACKUP_EXT ".sav" +#define MPLS_LDP_SYNC_STR "Enable MPLS LDP-SYNC\n" +#define NO_MPLS_LDP_SYNC_STR "Disable MPLS LDP-SYNC\n" +#define MPLS_LDP_SYNC_HOLDDOWN_STR \ + "Time to wait for LDP-SYNC to occur before restoring if cost\n" +#define NO_MPLS_LDP_SYNC_HOLDDOWN_STR "holddown timer disable\n" /* Command warnings. */ #define NO_PASSWD_CMD_WARNING \ diff --git a/lib/ldp_sync.c b/lib/ldp_sync.c new file mode 100644 index 0000000000..5dd045d88d --- /dev/null +++ b/lib/ldp_sync.c @@ -0,0 +1,93 @@ +/* + * ldp_sync.c: LDP-SYNC handling routines + * Copyright (C) 2020 Volta Networks, 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 + +#include "command.h" +#include "memory.h" +#include "prefix.h" +#include "log.h" +#include "thread.h" +#include "stream.h" +#include "zclient.h" +#include "table.h" +#include "vty.h" +#include "ldp_sync.h" + +/* Library code */ +DEFINE_MTYPE_STATIC(LIB, LDP_SYNC_INFO, "LDP SYNC info") + +/* + * ldp_sync_info_create - Allocate the LDP_SYNC information + */ +struct ldp_sync_info *ldp_sync_info_create(void) +{ + struct ldp_sync_info *ldp_sync_info; + + ldp_sync_info = XCALLOC(MTYPE_LDP_SYNC_INFO, + sizeof(struct ldp_sync_info)); + assert(ldp_sync_info); + + ldp_sync_info->flags = 0; + ldp_sync_info->enabled = LDP_IGP_SYNC_DEFAULT; + ldp_sync_info->state = LDP_IGP_SYNC_STATE_NOT_REQUIRED; + ldp_sync_info->holddown = LDP_IGP_SYNC_HOLDDOWN_DEFAULT; + ldp_sync_info->t_holddown = NULL; + return ldp_sync_info; +} + +/* + * ldp_sync_info_free - Free the LDP_SYNC information. + */ +void ldp_sync_info_free(struct ldp_sync_info **ldp_sync_info) +{ + if (*ldp_sync_info) + XFREE(MTYPE_LDP_SYNC_INFO, *ldp_sync_info); +} + +bool ldp_sync_if_is_enabled(struct ldp_sync_info *ldp_sync_info) +{ + /* return true if LDP-SYNC is configured on this interface */ + if (ldp_sync_info && + ldp_sync_info->enabled == LDP_IGP_SYNC_ENABLED && + ldp_sync_info->state == LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP) + return true; + + return false; +} + +bool ldp_sync_if_down(struct ldp_sync_info *ldp_sync_info) +{ + /* Stop LDP-SYNC on this interface: + * if holddown timer is running stop it + * update state + */ + if (ldp_sync_info && ldp_sync_info->enabled == LDP_IGP_SYNC_ENABLED) { + if (ldp_sync_info->t_holddown != NULL) { + THREAD_TIMER_OFF(ldp_sync_info->t_holddown); + ldp_sync_info->t_holddown = NULL; + } + if (ldp_sync_info->state == LDP_IGP_SYNC_STATE_REQUIRED_UP) + ldp_sync_info->state = + LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP; + return true; + } + + return false; +} diff --git a/lib/ldp_sync.h b/lib/ldp_sync.h new file mode 100644 index 0000000000..daede566f0 --- /dev/null +++ b/lib/ldp_sync.h @@ -0,0 +1,91 @@ +/* + * Defines and structures common to LDP-Sync for OSPFv2 and OSPFv3 and ISIS + * Copyright (C) 2020 Volta Networks, 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 + */ + +#ifndef _LIBLDPSYNC_H +#define _LIBLDPSYNC_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* LDP-IGP Sync values */ +#define LDP_SYNC_FLAG_ENABLE (1 << 0) /* LDP-SYNC enabled */ +#define LDP_SYNC_FLAG_HOLDDOWN (1 << 1) /* Holddown timer enabled */ +#define LDP_SYNC_FLAG_IF_CONFIG (1 << 2) /* LDP-SYNC enabled on interface */ +#define LDP_SYNC_FLAG_SET_METRIC (1 << 3) /* Metric has been set on ISIS intf */ + +#define LDP_IGP_SYNC_DEFAULT 0 +#define LDP_IGP_SYNC_ENABLED 1 + +#define LDP_IGP_SYNC_STATE_NOT_REQUIRED 0 +#define LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP 1 +#define LDP_IGP_SYNC_STATE_REQUIRED_UP 2 + +#define LDP_IGP_SYNC_HOLDDOWN_DEFAULT 0 + +#define LDP_IGP_SYNC_HELLO_TIMEOUT 1 + +/* LDP-IGP Sync structures */ +struct ldp_sync_info_cmd { + uint16_t flags; + uint16_t holddown; /* timer value */ + uint32_t sequence; /* hello sequence number */ + struct thread *t_hello; /* hello timer for detecting LDP going down */ +}; + +struct ldp_sync_info { + uint16_t flags; /* indicate if set on interface or globally */ + uint8_t enabled; /* enabled */ + uint8_t state; /* running state */ + uint16_t holddown; /* timer value */ + struct thread *t_holddown; /* holddown timer*/ + uint32_t metric[2]; /* isis interface metric */ +}; + +/* Prototypes. */ +extern struct ldp_sync_info *ldp_sync_info_create(void); +extern bool ldp_sync_if_is_enabled(struct ldp_sync_info *ldp_sync_info); +extern bool ldp_sync_if_down(struct ldp_sync_info *ldp_sync_info); +extern void ldp_sync_info_free(struct ldp_sync_info **ldp_sync_info); + +struct ldp_igp_sync_announce { + int proto; +}; + +struct ldp_igp_sync_if_state { + ifindex_t ifindex; + bool sync_start; +}; + +struct ldp_igp_sync_if_state_req { + int proto; + ifindex_t ifindex; + char name[INTERFACE_NAMSIZ]; +}; + +struct ldp_igp_sync_hello { + int proto; + unsigned int sequence; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* _LIBLDPSYNC_H */ diff --git a/lib/subdir.am b/lib/subdir.am index 1feaa56d13..b8bcee139b 100644 --- a/lib/subdir.am +++ b/lib/subdir.am @@ -42,6 +42,7 @@ lib_libfrr_la_SOURCES = \ lib/jhash.c \ lib/json.c \ lib/keychain.c \ + lib/ldp_sync.c \ lib/lib_errors.c \ lib/lib_vty.c \ lib/libfrr.c \ @@ -198,6 +199,7 @@ pkginclude_HEADERS += \ lib/jhash.h \ lib/json.h \ lib/keychain.h \ + lib/ldp_sync.h \ lib/lib_errors.h \ lib/lib_vty.h \ lib/libfrr.h \