Zebra: Fixing Review comments in Zebra_MLAG

Signed-off-by: Satheesh Kumar K <sathk@cumulusnetworks.com>
This commit is contained in:
Satheesh Kumar K 2019-09-24 02:29:15 -07:00
parent d516749633
commit 40e79e9411
8 changed files with 50 additions and 43 deletions

View file

@ -154,6 +154,10 @@ message ZebraMlagMrouteAdd {
string vrf_name = 1; string vrf_name = 1;
uint32 source_ip = 2; uint32 source_ip = 2;
uint32 group_ip = 3; uint32 group_ip = 3;
/*
* This is the IGP Cost to reach Configured RP in case of (*,G) or
* Cost to the source in case of (S,G) entry
*/
uint32 cost_to_rp = 4; uint32 cost_to_rp = 4;
uint32 owner_id = 5; uint32 owner_id = 5;
bool am_i_DR = 6; bool am_i_DR = 6;

View file

@ -1,5 +1,5 @@
/* PIM Mlag Code. /* PIM Mlag Code.
* Copyright (C) 2018 Cumulus Networks, Inc. * Copyright (C) 2019 Cumulus Networks, Inc.
* Donald Sharp * Donald Sharp
* *
* This file is part of FRR. * This file is part of FRR.

View file

@ -1,5 +1,5 @@
/* PIM mlag header. /* PIM mlag header.
* Copyright (C) 2018 Cumulus Networks, Inc. * Copyright (C) 2019 Cumulus Networks, Inc.
* Donald Sharp * Donald Sharp
* *
* This file is part of FRR. * This file is part of FRR.

View file

@ -1,5 +1,5 @@
/* Zebra Mlag Code. /* Zebra Mlag Code.
* Copyright (C) 2018 Cumulus Networks, Inc. * Copyright (C) 2019 Cumulus Networks, Inc.
* Donald Sharp * Donald Sharp
* *
* This file is part of FRR. * This file is part of FRR.
@ -39,6 +39,7 @@
#define ZEBRA_MLAG_METADATA_LEN 4 #define ZEBRA_MLAG_METADATA_LEN 4
#define ZEBRA_MLAG_MSG_BCAST 0xFFFFFFFF #define ZEBRA_MLAG_MSG_BCAST 0xFFFFFFFF
#define MAXCH_LEN 80
uint8_t mlag_wr_buffer[ZEBRA_MLAG_BUF_LIMIT]; uint8_t mlag_wr_buffer[ZEBRA_MLAG_BUF_LIMIT];
uint8_t mlag_rd_buffer[ZEBRA_MLAG_BUF_LIMIT]; uint8_t mlag_rd_buffer[ZEBRA_MLAG_BUF_LIMIT];
@ -153,6 +154,7 @@ static int zebra_mlag_thread_handler(struct thread *event)
struct stream *s; struct stream *s;
uint32_t wr_count = 0; uint32_t wr_count = 0;
uint32_t msg_type = 0; uint32_t msg_type = 0;
uint32_t max_count = 0;
int len = 0; int len = 0;
wr_count = stream_fifo_count_safe(zrouter.mlag_info.mlag_fifo); wr_count = stream_fifo_count_safe(zrouter.mlag_info.mlag_fifo);
@ -160,12 +162,13 @@ static int zebra_mlag_thread_handler(struct thread *event)
zlog_debug(":%s: Processing MLAG write, %d messages in queue", zlog_debug(":%s: Processing MLAG write, %d messages in queue",
__func__, wr_count); __func__, wr_count);
pthread_mutex_lock(&zrouter.mlag_info.mlag_th_mtx);
zrouter.mlag_info.t_write = NULL; zrouter.mlag_info.t_write = NULL;
for (wr_count = 0; wr_count < ZEBRA_MLAG_POST_LIMIT; wr_count++) { pthread_mutex_unlock(&zrouter.mlag_info.mlag_th_mtx);
/* FIFO is empty,wait for teh message to be add */
if (stream_fifo_count_safe(zrouter.mlag_info.mlag_fifo) == 0)
break;
max_count = MIN(wr_count, ZEBRA_MLAG_POST_LIMIT);
for (wr_count = 0; wr_count < max_count; wr_count++) {
s = stream_fifo_pop_safe(zrouter.mlag_info.mlag_fifo); s = stream_fifo_pop_safe(zrouter.mlag_info.mlag_fifo);
if (!s) { if (!s) {
zlog_debug(":%s: Got a NULL Messages, some thing wrong", zlog_debug(":%s: Got a NULL Messages, some thing wrong",
@ -173,7 +176,6 @@ static int zebra_mlag_thread_handler(struct thread *event)
break; break;
} }
zebra_mlag_reset_write_buffer();
/* /*
* Encode the data now * Encode the data now
*/ */
@ -182,17 +184,19 @@ static int zebra_mlag_thread_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); zebra_mlag_private_write_data(mlag_wr_buffer, len);
/* /*
* If mesasge type is De-register, send a signal to main thread, * If mesasge type is De-register, send a signal to main
* sothat necessary cleanup will be done by main thread. * thread, sothat necessary cleanup will be done by main
* thread.
*/ */
if (msg_type == MLAG_DEREGISTER) { if (msg_type == MLAG_DEREGISTER) {
thread_add_event(zrouter.master, thread_add_event(zrouter.master,
zebra_mlag_terminate_pthread, NULL, 0, zebra_mlag_terminate_pthread,
NULL); NULL, 0, NULL);
}
} }
stream_free(s); stream_free(s);
@ -246,6 +250,7 @@ void zebra_mlag_handle_process_state(enum zebra_mlag_state state)
*/ */
static int zebra_mlag_signal_write_thread(void) static int zebra_mlag_signal_write_thread(void)
{ {
pthread_mutex_lock(&zrouter.mlag_info.mlag_th_mtx);
if (zrouter.mlag_info.zebra_pth_mlag) { if (zrouter.mlag_info.zebra_pth_mlag) {
if (IS_ZEBRA_DEBUG_MLAG) if (IS_ZEBRA_DEBUG_MLAG)
zlog_debug(":%s: Scheduling MLAG write", __func__); zlog_debug(":%s: Scheduling MLAG write", __func__);
@ -253,6 +258,7 @@ static int zebra_mlag_signal_write_thread(void)
zebra_mlag_thread_handler, NULL, 0, zebra_mlag_thread_handler, NULL, 0,
&zrouter.mlag_info.t_write); &zrouter.mlag_info.t_write);
} }
pthread_mutex_unlock(&zrouter.mlag_info.mlag_th_mtx);
return 0; return 0;
} }
@ -588,7 +594,7 @@ DEFUN_HIDDEN (show_mlag,
ZEBRA_STR ZEBRA_STR
"The mlag role on this machine\n") "The mlag role on this machine\n")
{ {
char buf[80]; char buf[MAXCH_LEN];
vty_out(vty, "MLag is configured to: %s\n", vty_out(vty, "MLag is configured to: %s\n",
mlag_role2str(zrouter.mlag_info.role, buf, sizeof(buf))); mlag_role2str(zrouter.mlag_info.role, buf, sizeof(buf)));
@ -790,7 +796,7 @@ DEFPY(test_mlag, test_mlag_cmd,
"Mlag is setup to be the secondary\n") "Mlag is setup to be the secondary\n")
{ {
enum mlag_role orig = zrouter.mlag_info.role; enum mlag_role orig = zrouter.mlag_info.role;
char buf1[80], buf2[80]; char buf1[MAXCH_LEN], buf2[MAXCH_LEN];
if (none) if (none)
zrouter.mlag_info.role = MLAG_ROLE_NONE; zrouter.mlag_info.role = MLAG_ROLE_NONE;
@ -894,8 +900,8 @@ void zebra_mlag_init(void)
zrouter.mlag_info.t_read = NULL; zrouter.mlag_info.t_read = NULL;
zrouter.mlag_info.t_write = NULL; zrouter.mlag_info.t_write = NULL;
test_mlag_in_progress = false; test_mlag_in_progress = false;
zebra_mlag_reset_write_buffer();
zebra_mlag_reset_read_buffer(); zebra_mlag_reset_read_buffer();
pthread_mutex_init(&zrouter.mlag_info.mlag_th_mtx, NULL);
} }
void zebra_mlag_terminate(void) void zebra_mlag_terminate(void)
@ -920,7 +926,7 @@ int zebra_mlag_protobuf_encode_client_data(struct stream *s, uint32_t *msg_type)
int len = 0; int len = 0;
int n_len = 0; int n_len = 0;
int rc = 0; int rc = 0;
char buf[80]; char buf[MAXCH_LEN];
if (IS_ZEBRA_DEBUG_MLAG) if (IS_ZEBRA_DEBUG_MLAG)
zlog_debug("%s: Entering..", __func__); zlog_debug("%s: Entering..", __func__);
@ -933,12 +939,10 @@ int zebra_mlag_protobuf_encode_client_data(struct stream *s, uint32_t *msg_type)
zlog_debug("%s: Decoded msg length:%d..", __func__, zlog_debug("%s: Decoded msg length:%d..", __func__,
mlag_msg.data_len); mlag_msg.data_len);
memset(tmp_buf, 0, ZEBRA_MLAG_BUF_LIMIT);
if (IS_ZEBRA_DEBUG_MLAG) if (IS_ZEBRA_DEBUG_MLAG)
zlog_debug("%s: Mlag ProtoBuf encoding of message:%s", __func__, zlog_debug("%s: Mlag ProtoBuf encoding of message:%s", __func__,
zebra_mlag_lib_msgid_to_str(mlag_msg.msg_type, buf, zebra_mlag_lib_msgid_to_str(mlag_msg.msg_type, buf,
80)); sizeof(buf)));
*msg_type = mlag_msg.msg_type; *msg_type = mlag_msg.msg_type;
switch (mlag_msg.msg_type) { switch (mlag_msg.msg_type) {
case MLAG_MROUTE_ADD: { case MLAG_MROUTE_ADD: {
@ -1138,17 +1142,15 @@ int zebra_mlag_protobuf_encode_client_data(struct stream *s, uint32_t *msg_type)
} }
if (IS_ZEBRA_DEBUG_MLAG) if (IS_ZEBRA_DEBUG_MLAG)
zlog_debug( zlog_debug("%s: length of Mlag ProtoBuf encoded message:%s, %d",
"%s: length of Mlag ProtoBuf encoded message:%s, %d",
__func__, __func__,
zebra_mlag_lib_msgid_to_str(mlag_msg.msg_type, buf, 80), zebra_mlag_lib_msgid_to_str(mlag_msg.msg_type, buf,
sizeof(buf)),
len); len);
hdr.type = (ZebraMlagHeader__MessageType)mlag_msg.msg_type; hdr.type = (ZebraMlagHeader__MessageType)mlag_msg.msg_type;
if (len != 0) { if (len != 0) {
hdr.data.len = len; hdr.data.len = len;
hdr.data.data = XMALLOC(MTYPE_MLAG_PBUF, len); hdr.data.data = XMALLOC(MTYPE_MLAG_PBUF, len);
if (hdr.data.data == NULL)
return -1;
memcpy(hdr.data.data, tmp_buf, len); memcpy(hdr.data.data, tmp_buf, len);
} }
@ -1173,7 +1175,8 @@ int zebra_mlag_protobuf_encode_client_data(struct stream *s, uint32_t *msg_type)
zlog_debug( zlog_debug(
"%s: length of Mlag ProtoBuf message:%s with Header %d", "%s: length of Mlag ProtoBuf message:%s with Header %d",
__func__, __func__,
zebra_mlag_lib_msgid_to_str(mlag_msg.msg_type, buf, 80), zebra_mlag_lib_msgid_to_str(mlag_msg.msg_type, buf,
sizeof(buf)),
len); len);
if (hdr.data.data) if (hdr.data.data)
XFREE(MTYPE_MLAG_PBUF, hdr.data.data); XFREE(MTYPE_MLAG_PBUF, hdr.data.data);
@ -1188,7 +1191,7 @@ int zebra_mlag_protobuf_decode_message(struct stream **s, uint8_t *data,
{ {
uint32_t msg_type; uint32_t msg_type;
ZebraMlagHeader *hdr = NULL; ZebraMlagHeader *hdr = NULL;
char buf[80]; char buf[MAXCH_LEN];
if (IS_ZEBRA_DEBUG_MLAG) if (IS_ZEBRA_DEBUG_MLAG)
zlog_debug("%s: Entering..", __func__); zlog_debug("%s: Entering..", __func__);
@ -1205,7 +1208,8 @@ int zebra_mlag_protobuf_decode_message(struct stream **s, uint8_t *data,
if (IS_ZEBRA_DEBUG_MLAG) if (IS_ZEBRA_DEBUG_MLAG)
zlog_debug("%s: Mlag ProtoBuf decoding of message:%s", __func__, zlog_debug("%s: Mlag ProtoBuf decoding of message:%s", __func__,
zebra_mlag_lib_msgid_to_str(msg_type, buf, 80)); zebra_mlag_lib_msgid_to_str(msg_type, buf,
sizeof(buf)));
/* /*
* Internal MLAG Message-types & MLAG.proto message types should * Internal MLAG Message-types & MLAG.proto message types should

View file

@ -1,5 +1,5 @@
/* Zebra mlag header. /* Zebra mlag header.
* Copyright (C) 2018 Cumulus Networks, Inc. * Copyright (C) 2019 Cumulus Networks, Inc.
* Donald Sharp * Donald Sharp
* *
* This file is part of FRR. * This file is part of FRR.
@ -37,14 +37,8 @@ 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;
static inline void zebra_mlag_reset_write_buffer(void)
{
memset(mlag_wr_buffer, 0, ZEBRA_MLAG_BUF_LIMIT);
}
static inline void zebra_mlag_reset_read_buffer(void) static inline void zebra_mlag_reset_read_buffer(void)
{ {
memset(mlag_rd_buffer, 0, ZEBRA_MLAG_BUF_LIMIT);
mlag_rd_buf_offset = 0; mlag_rd_buf_offset = 0;
} }

View file

@ -1,5 +1,5 @@
/* Zebra Mlag Code. /* Zebra Mlag Code.
* Copyright (C) 2018 Cumulus Networks, Inc. * Copyright (C) 2019 Cumulus Networks, Inc.
* Donald Sharp * Donald Sharp
* *
* This file is part of FRR. * This file is part of FRR.
@ -68,8 +68,10 @@ int zebra_mlag_private_write_data(uint8_t *data, uint32_t len)
static void zebra_mlag_sched_read(void) static void zebra_mlag_sched_read(void)
{ {
pthread_mutex_lock(&zrouter.mlag_info.mlag_th_mtx);
thread_add_read(zmlag_master, zebra_mlag_read, NULL, mlag_socket, thread_add_read(zmlag_master, zebra_mlag_read, NULL, mlag_socket,
&zrouter.mlag_info.t_read); &zrouter.mlag_info.t_read);
pthread_mutex_unlock(&zrouter.mlag_info.mlag_th_mtx);
} }
static int zebra_mlag_read(struct thread *thread) static int zebra_mlag_read(struct thread *thread)
@ -78,7 +80,9 @@ static int zebra_mlag_read(struct thread *thread)
uint32_t h_msglen; uint32_t h_msglen;
uint32_t tot_len, curr_len = mlag_rd_buf_offset; uint32_t tot_len, curr_len = mlag_rd_buf_offset;
pthread_mutex_lock(&zrouter.mlag_info.mlag_th_mtx);
zrouter.mlag_info.t_read = NULL; zrouter.mlag_info.t_read = NULL;
pthread_mutex_unlock(&zrouter.mlag_info.mlag_th_mtx);
/* /*
* Received message in sock_stream looks like below * Received message in sock_stream looks like below

View file

@ -1,5 +1,5 @@
/* Zebra mlag header. /* Zebra mlag header.
* Copyright (C) 2018 Cumulus Networks, Inc. * Copyright (C) 2019 Cumulus Networks, Inc.
* Donald Sharp * Donald Sharp
* *
* This file is part of FRR. * This file is part of FRR.

View file

@ -100,6 +100,7 @@ struct zebra_mlag_info {
/* Threads for read/write. */ /* Threads for read/write. */
struct thread *t_read; struct thread *t_read;
struct thread *t_write; struct thread *t_write;
pthread_mutex_t mlag_th_mtx;
}; };
struct zebra_router { struct zebra_router {