Merge pull request #5494 from opensourcerouting/mlag-module

zebra: create zebra_cumulus_mlag module
This commit is contained in:
Donald Sharp 2019-12-11 13:14:02 -05:00 committed by GitHub
commit 37f4c2fb02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 60 additions and 77 deletions

View File

@ -1061,6 +1061,8 @@ FRR_INCLUDES
dnl V6 headers are checked below, after we check for v6 dnl V6 headers are checked below, after we check for v6
is_linux=false
AC_MSG_CHECKING([which operating system interface to use]) AC_MSG_CHECKING([which operating system interface to use])
case "$host_os" in case "$host_os" in
sunos* | solaris2*) sunos* | solaris2*)
@ -1089,6 +1091,8 @@ case "$host_os" in
dnl how to fix it but no real progress on implementation dnl how to fix it but no real progress on implementation
dnl when they fix it, remove this dnl when they fix it, remove this
AC_DEFINE([IPV6_MINHOPCOUNT], [73], [Linux ipv6 Min Hop Count]) AC_DEFINE([IPV6_MINHOPCOUNT], [73], [Linux ipv6 Min Hop Count])
is_linux=true
;; ;;
openbsd*) openbsd*)
AC_MSG_RESULT([OpenBSD]) AC_MSG_RESULT([OpenBSD])
@ -1116,6 +1120,7 @@ case "$host_os" in
;; ;;
esac esac
AM_CONDITIONAL([SOLARIS], [test "${SOLARIS}" = "solaris"]) AM_CONDITIONAL([SOLARIS], [test "${SOLARIS}" = "solaris"])
AM_CONDITIONAL([LINUX], [${is_linux}])
AC_SYS_LARGEFILE AC_SYS_LARGEFILE

1
debian/frr.install vendored
View File

@ -8,6 +8,7 @@ usr/lib/frr/*.sh
usr/lib/frr/*d usr/lib/frr/*d
usr/lib/frr/watchfrr usr/lib/frr/watchfrr
usr/lib/frr/zebra usr/lib/frr/zebra
usr/lib/*/frr/modules/zebra_cumulus_mlag.so
usr/lib/*/frr/modules/zebra_irdp.so usr/lib/*/frr/modules/zebra_irdp.so
usr/lib/*/frr/modules/zebra_fpm.so usr/lib/*/frr/modules/zebra_fpm.so
usr/lib/*/frr/modules/bgpd_bmp.so usr/lib/*/frr/modules/bgpd_bmp.so

View File

@ -633,6 +633,7 @@ fi
%if %{with_rpki} %if %{with_rpki}
%{_libdir}/frr/modules/bgpd_rpki.so %{_libdir}/frr/modules/bgpd_rpki.so
%endif %endif
%{_libdir}/frr/modules/zebra_cumulus_mlag.so
%{_libdir}/frr/modules/zebra_irdp.so %{_libdir}/frr/modules/zebra_irdp.so
%{_libdir}/frr/modules/bgpd_bmp.so %{_libdir}/frr/modules/bgpd_bmp.so
%{_bindir}/* %{_bindir}/*

View File

@ -32,6 +32,9 @@ endif
if FPM if FPM
module_LTLIBRARIES += zebra/zebra_fpm.la module_LTLIBRARIES += zebra/zebra_fpm.la
endif endif
if LINUX
module_LTLIBRARIES += zebra/zebra_cumulus_mlag.la
endif
man8 += $(MANBUILD)/zebra.8 man8 += $(MANBUILD)/zebra.8
## endif ZEBRA ## endif ZEBRA
@ -69,7 +72,6 @@ zebra_zebra_SOURCES = \
zebra/rule_netlink.c \ zebra/rule_netlink.c \
zebra/rule_socket.c \ zebra/rule_socket.c \
zebra/zebra_mlag.c \ zebra/zebra_mlag.c \
zebra/zebra_mlag_private.c \
zebra/zebra_l2.c \ zebra/zebra_l2.c \
zebra/zebra_memory.c \ zebra/zebra_memory.c \
zebra/zebra_dplane.c \ zebra/zebra_dplane.c \
@ -134,7 +136,6 @@ noinst_HEADERS += \
zebra/rtadv.h \ zebra/rtadv.h \
zebra/rule_netlink.h \ zebra/rule_netlink.h \
zebra/zebra_mlag.h \ zebra/zebra_mlag.h \
zebra/zebra_mlag_private.h \
zebra/zebra_fpm_private.h \ zebra/zebra_fpm_private.h \
zebra/zebra_l2.h \ zebra/zebra_l2.h \
zebra/zebra_dplane.h \ zebra/zebra_dplane.h \
@ -185,3 +186,6 @@ if DEV_BUILD
zebra_zebra_fpm_la_SOURCES += zebra/zebra_fpm_dt.c zebra_zebra_fpm_la_SOURCES += zebra/zebra_fpm_dt.c
endif endif
endif endif
zebra_zebra_cumulus_mlag_la_SOURCES = zebra/zebra_mlag_private.c
zebra_zebra_cumulus_mlag_la_LDFLAGS = -avoid-version -module -shared -export-dynamic

View File

@ -27,7 +27,6 @@
#include "mlag.h" #include "mlag.h"
#include "zebra/zebra_mlag.h" #include "zebra/zebra_mlag.h"
#include "zebra/zebra_mlag_private.h"
#include "zebra/zebra_router.h" #include "zebra/zebra_router.h"
#include "zebra/zebra_memory.h" #include "zebra/zebra_memory.h"
#include "zebra/zapi_msg.h" #include "zebra/zapi_msg.h"
@ -37,6 +36,13 @@
#include "zebra/zebra_mlag_clippy.c" #include "zebra/zebra_mlag_clippy.c"
#endif #endif
DEFINE_HOOK(zebra_mlag_private_write_data,
(uint8_t *data, uint32_t len), (data, len))
DEFINE_HOOK(zebra_mlag_private_monitor_state, (), ())
DEFINE_HOOK(zebra_mlag_private_open_channel, (), ())
DEFINE_HOOK(zebra_mlag_private_close_channel, (), ())
DEFINE_HOOK(zebra_mlag_private_cleanup_data, (), ())
#define ZEBRA_MLAG_METADATA_LEN 4 #define ZEBRA_MLAG_METADATA_LEN 4
#define ZEBRA_MLAG_MSG_BCAST 0xFFFFFFFF #define ZEBRA_MLAG_MSG_BCAST 0xFFFFFFFF
@ -175,7 +181,8 @@ static int zebra_mlag_client_msg_handler(struct thread *event)
* write to MCLAGD * write to MCLAGD
*/ */
if (len > 0) { if (len > 0) {
zebra_mlag_private_write_data(mlag_wr_buffer, len); hook_call(zebra_mlag_private_write_data,
mlag_wr_buffer, len);
/* /*
* If message type is De-register, send a signal to main * If message type is De-register, send a signal to main
@ -220,7 +227,7 @@ void zebra_mlag_handle_process_state(enum zebra_mlag_state state)
} else if (state == MLAG_DOWN) { } else if (state == MLAG_DOWN) {
zrouter.mlag_info.connected = false; zrouter.mlag_info.connected = false;
zebra_mlag_publish_process_state(NULL, ZEBRA_MLAG_PROCESS_DOWN); zebra_mlag_publish_process_state(NULL, ZEBRA_MLAG_PROCESS_DOWN);
zebra_mlag_private_monitor_state(); hook_call(zebra_mlag_private_monitor_state);
} }
} }
@ -412,7 +419,7 @@ static int zebra_mlag_terminate_pthread(struct thread *event)
/* /*
* Send Notification to clean private data * Send Notification to clean private data
*/ */
zebra_mlag_private_cleanup_data(); hook_call(zebra_mlag_private_cleanup_data);
return 0; return 0;
} }
@ -470,7 +477,7 @@ void zebra_mlag_client_register(ZAPI_HANDLER_ARGS)
"First client, opening the channel with MLAG"); "First client, opening the channel with MLAG");
zebra_mlag_spawn_pthread(); zebra_mlag_spawn_pthread();
rc = zebra_mlag_private_open_channel(); rc = hook_call(zebra_mlag_private_open_channel);
if (rc < 0) { if (rc < 0) {
/* /*
* For some reason, zebra not able to open the * For some reason, zebra not able to open the
@ -530,7 +537,7 @@ void zebra_mlag_client_unregister(ZAPI_HANDLER_ARGS)
* signal back to main thread to do the thread cleanup * signal back to main thread to do the thread cleanup
* this was mainly to make sure De-register is posted to MCLAGD. * this was mainly to make sure De-register is posted to MCLAGD.
*/ */
zebra_mlag_private_close_channel(); hook_call(zebra_mlag_private_close_channel);
} }
if (IS_ZEBRA_DEBUG_MLAG) if (IS_ZEBRA_DEBUG_MLAG)
@ -627,13 +634,13 @@ DEFPY_HIDDEN(test_mlag, test_mlag_cmd,
zebra_mlag_spawn_pthread(); zebra_mlag_spawn_pthread();
zrouter.mlag_info.clients_interested_cnt++; zrouter.mlag_info.clients_interested_cnt++;
test_mlag_in_progress = true; test_mlag_in_progress = true;
zebra_mlag_private_open_channel(); hook_call(zebra_mlag_private_open_channel);
} }
} else { } else {
if (test_mlag_in_progress == true) { if (test_mlag_in_progress == true) {
test_mlag_in_progress = false; test_mlag_in_progress = false;
zrouter.mlag_info.clients_interested_cnt--; zrouter.mlag_info.clients_interested_cnt--;
zebra_mlag_private_close_channel(); hook_call(zebra_mlag_private_close_channel);
} }
} }
} }

View File

@ -33,6 +33,13 @@
#define ZEBRA_MLAG_BUF_LIMIT 2048 #define ZEBRA_MLAG_BUF_LIMIT 2048
#define ZEBRA_MLAG_LEN_SIZE 4 #define ZEBRA_MLAG_LEN_SIZE 4
DECLARE_HOOK(zebra_mlag_private_write_data,
(uint8_t *data, uint32_t len), (data, len))
DECLARE_HOOK(zebra_mlag_private_monitor_state, (), ())
DECLARE_HOOK(zebra_mlag_private_open_channel, (), ())
DECLARE_HOOK(zebra_mlag_private_close_channel, (), ())
DECLARE_HOOK(zebra_mlag_private_cleanup_data, (), ())
extern uint8_t mlag_wr_buffer[ZEBRA_MLAG_BUF_LIMIT]; extern uint8_t mlag_wr_buffer[ZEBRA_MLAG_BUF_LIMIT];
extern uint8_t mlag_rd_buffer[ZEBRA_MLAG_BUF_LIMIT]; extern uint8_t mlag_rd_buffer[ZEBRA_MLAG_BUF_LIMIT];
extern uint32_t mlag_rd_buf_offset; extern uint32_t mlag_rd_buf_offset;

View File

@ -36,7 +36,6 @@
#include "zebra/debug.h" #include "zebra/debug.h"
#include "zebra/zebra_router.h" #include "zebra/zebra_router.h"
#include "zebra/zebra_mlag.h" #include "zebra/zebra_mlag.h"
#include "zebra/zebra_mlag_private.h"
#include <sys/un.h> #include <sys/un.h>
@ -46,8 +45,6 @@
* *
*/ */
#ifdef HAVE_CUMULUS
static struct thread_master *zmlag_master; static struct thread_master *zmlag_master;
static int mlag_socket; static int mlag_socket;
@ -57,7 +54,7 @@ static int zebra_mlag_read(struct thread *thread);
/* /*
* Write the data to MLAGD * Write the data to MLAGD
*/ */
int zebra_mlag_private_write_data(uint8_t *data, uint32_t len) static int zebra_mlag_private_write_data(uint8_t *data, uint32_t len)
{ {
int rc = 0; int rc = 0;
@ -103,7 +100,7 @@ static int zebra_mlag_read(struct thread *thread)
return -1; return -1;
} }
mlag_rd_buf_offset += data_len; mlag_rd_buf_offset += data_len;
if (data_len != (ssize_t)ZEBRA_MLAG_LEN_SIZE - curr_len) { if (data_len != (ssize_t)(ZEBRA_MLAG_LEN_SIZE - curr_len)) {
/* Try again later */ /* Try again later */
zebra_mlag_sched_read(); zebra_mlag_sched_read();
return 0; return 0;
@ -132,7 +129,7 @@ static int zebra_mlag_read(struct thread *thread)
return -1; return -1;
} }
mlag_rd_buf_offset += data_len; mlag_rd_buf_offset += data_len;
if (data_len != (ssize_t)tot_len - curr_len) { if (data_len != (ssize_t)(tot_len - curr_len)) {
/* Try again later */ /* Try again later */
zebra_mlag_sched_read(); zebra_mlag_sched_read();
return 0; return 0;
@ -207,13 +204,14 @@ static int zebra_mlag_connect(struct thread *thread)
/* /*
* Currently we are doing polling later we will look for better options * Currently we are doing polling later we will look for better options
*/ */
void zebra_mlag_private_monitor_state(void) static int zebra_mlag_private_monitor_state(void)
{ {
thread_add_event(zmlag_master, zebra_mlag_connect, NULL, 0, thread_add_event(zmlag_master, zebra_mlag_connect, NULL, 0,
&zrouter.mlag_info.t_read); &zrouter.mlag_info.t_read);
return 0;
} }
int zebra_mlag_private_open_channel(void) static int zebra_mlag_private_open_channel(void)
{ {
zmlag_master = zrouter.mlag_info.th_master; zmlag_master = zrouter.mlag_info.th_master;
@ -242,7 +240,7 @@ int zebra_mlag_private_open_channel(void)
return 0; return 0;
} }
int zebra_mlag_private_close_channel(void) static int zebra_mlag_private_close_channel(void)
{ {
if (zmlag_master == NULL) if (zmlag_master == NULL)
return -1; return -1;
@ -263,37 +261,34 @@ int zebra_mlag_private_close_channel(void)
return 0; return 0;
} }
void zebra_mlag_private_cleanup_data(void) static int zebra_mlag_private_cleanup_data(void)
{ {
zmlag_master = NULL; zmlag_master = NULL;
zrouter.mlag_info.connected = false; zrouter.mlag_info.connected = false;
zrouter.mlag_info.timer_running = false; zrouter.mlag_info.timer_running = false;
close(mlag_socket); close(mlag_socket);
}
#else /*HAVE_CUMULUS */
int zebra_mlag_private_write_data(uint8_t *data, uint32_t len)
{
return 0; return 0;
} }
void zebra_mlag_private_monitor_state(void) static int zebra_mlag_module_init(void)
{
}
int zebra_mlag_private_open_channel(void)
{ {
hook_register(zebra_mlag_private_write_data,
zebra_mlag_private_write_data);
hook_register(zebra_mlag_private_monitor_state,
zebra_mlag_private_monitor_state);
hook_register(zebra_mlag_private_open_channel,
zebra_mlag_private_open_channel);
hook_register(zebra_mlag_private_close_channel,
zebra_mlag_private_close_channel);
hook_register(zebra_mlag_private_cleanup_data,
zebra_mlag_private_cleanup_data);
return 0; return 0;
} }
int zebra_mlag_private_close_channel(void) FRR_MODULE_SETUP(
{ .name = "zebra_cumulus_mlag",
return 0; .version = FRR_VERSION,
} .description = "zebra Cumulus MLAG interface",
.init = zebra_mlag_module_init,
void zebra_mlag_private_cleanup_data(void) )
{
}
#endif /*HAVE_CUMULUS*/

View File

@ -1,37 +0,0 @@
/*
* This is an implementation of MLAG Functionality
*
* Module name: Zebra MLAG
*
* Author: sathesh Kumar karra <sathk@cumulusnetworks.com>
*
* Copyright (C) 2019 Cumulus Networks http://www.cumulusnetworks.com
*
* 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 __ZEBRA_MLAG_PRIVATE_H__
#define __ZEBRA_MLAG_PRIVATE_H__
/*
* all the platform specific API's
*/
int zebra_mlag_private_open_channel(void);
int zebra_mlag_private_close_channel(void);
void zebra_mlag_private_monitor_state(void);
int zebra_mlag_private_write_data(uint8_t *data, uint32_t len);
void zebra_mlag_private_cleanup_data(void);
#endif