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

[MCLAG] Improve performance and fix some bugs #7769

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions src/iccpd/include/iccp_ifm.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,8 @@ int do_one_neigh_request(struct nlmsghdr *n);
void iccp_from_netlink_port_state_handler( char * ifname, int state);

void iccp_parse_if_vlan_info_from_netlink(struct nlmsghdr *n);

void iccp_get_if_vlan_info_from_netlink();

#endif // LACP_IFM_H

2 changes: 1 addition & 1 deletion src/iccpd/include/mlacp_link_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void peerlink_port_isolate_cleanup(struct CSM* csm);
void update_peerlink_isolate_from_all_csm_lif(struct CSM* csm);

void del_mac_from_chip(struct MACMsg *mac_msg);
void add_mac_to_chip(struct MACMsg *mac_msg, uint8_t mac_type);
void add_mac_to_chip(struct CSM *csm, struct MACMsg *mac_msg, uint8_t mac_type);
uint8_t set_mac_local_age_flag(struct CSM *csm, struct MACMsg *mac_msg, uint8_t set);
void iccp_get_fdb_change_from_syncd(void);

Expand Down
11 changes: 7 additions & 4 deletions src/iccpd/include/mlacp_tlv.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#define MLACP_SYSCONF_NODEID_NODEID_MASK 0x70
#define MLACP_SYSCONF_NODEID_FREE_MASK 0x0F

#define NEIGH_SYNC_TIME 240
/*
* RFC 7275
* 7.2.3. mLACP System Config TLV
Expand Down Expand Up @@ -369,17 +370,19 @@ struct mLACPMACInfoTLV
struct ARPMsg
{
uint8_t op_type;
char ifname[MAX_L_PORT_NAME];
char ifname[MAX_L_PORT_NAME];
uint32_t ipv4_addr;
uint8_t mac_addr[ETHER_ADDR_LEN];
time_t sync_time;
};

struct NDISCMsg
{
uint8_t op_type;
char ifname[MAX_L_PORT_NAME];
uint8_t op_type;
char ifname[MAX_L_PORT_NAME];
uint32_t ipv6_addr[4];
uint8_t mac_addr[ETHER_ADDR_LEN];
uint8_t mac_addr[ETHER_ADDR_LEN];
time_t sync_time;
};

/*
Expand Down
571 changes: 571 additions & 0 deletions src/iccpd/include/openbsd_tree.h

Large diffs are not rendered by default.

43 changes: 33 additions & 10 deletions src/iccpd/include/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@
#include <time.h>
#include <sys/queue.h>

#include "../include/openbsd_tree.h"

#define ETHER_ADDR_LEN 6
#define ETHER_ADDR_STR_LEN 18

/*
* RFC 7275
* 7.2.4. mLACP Port Config TLV
Expand All @@ -47,9 +50,10 @@
#define IF_T_UNKNOW -1
#define IF_T_PORT 0
#define IF_T_PORT_CHANNEL 1
#define IF_T_VLAN 2
#define IF_T_VXLAN 3
#define IF_T_BRIDGE 4
#define IF_T_VLAN 2
#define IF_T_VXLAN 3
#define IF_T_BRIDGE 4

typedef struct
{
char *ifname;
Expand All @@ -67,9 +71,19 @@ struct VLAN_ID
uint16_t vid;
uint16_t vlan_removed;
struct LocalInterface* vlan_itf; /* loacl vlan interface */
LIST_ENTRY(VLAN_ID) port_next;
RB_ENTRY(VLAN_ID) vlan_entry;
};

RB_HEAD(vlan_rb_tree, VLAN_ID);
RB_PROTOTYPE(vlan_rb_tree, VLAN_ID, vlan_entry, vlan_node_compare);

#define VLAN_RB_REMOVE(name, head, elm) do { \
RB_REMOVE(name, head, elm); \
(elm)->vlan_entry.rbt_parent = NULL; \
(elm)->vlan_entry.rbt_left = NULL; \
(elm)->vlan_entry.rbt_right = NULL; \
} while (0)

struct PeerInterface
{
int ifindex;
Expand All @@ -88,7 +102,13 @@ struct PeerInterface
struct CSM* csm;

LIST_ENTRY(PeerInterface) mlacp_next;
LIST_HEAD(peer_vlan_list, VLAN_ID) vlan_list;
struct vlan_rb_tree vlan_tree;
};

struct PortChannel_member
{
char name[MAX_L_PORT_NAME];
LIST_ENTRY(PortChannel_member) member_next;
};

struct LocalInterface
Expand All @@ -108,7 +128,6 @@ struct LocalInterface
uint8_t l3_mode;
uint8_t l3_mac_addr[ETHER_ADDR_LEN];
uint8_t is_peer_link;
char portchannel_member_buf[512];
uint8_t is_arp_accept;
int po_id; /* Port Channel ID */
uint8_t po_active; /* Port Channel is in active status? */
Expand All @@ -120,9 +139,12 @@ struct LocalInterface
uint8_t changed;
uint8_t port_config_sync;

LIST_HEAD(local_vlan_list, VLAN_ID) vlan_list;
struct vlan_rb_tree vlan_tree;

LIST_HEAD(member_list, PortChannel_member) member_list;
int portchannel_member_count;

LIST_ENTRY(LocalInterface) system_next;
RB_ENTRY(LocalInterface) lif_entry;
LIST_ENTRY(LocalInterface) system_purge_next;
LIST_ENTRY(LocalInterface) mlacp_next;
LIST_ENTRY(LocalInterface) mlacp_purge_next;
Expand All @@ -131,9 +153,9 @@ struct LocalInterface
struct LocalInterface* local_if_create(int ifindex, char* ifname, int type);
struct LocalInterface* local_if_find_by_name(const char* ifname);
struct LocalInterface* local_if_find_by_ifindex(int ifindex);
struct LocalInterface* local_if_find_by_po_id(int po_id);
/*struct LocalInterface* local_if_find_by_po_id(int po_id);*/

void local_if_destroy(char *ifname);
void local_if_destroy(struct LocalInterface *lif);
void local_if_change_flag_clear(void);
void local_if_purge_clear(void);
int local_if_is_l3_mode(struct LocalInterface* local_if);
Expand All @@ -152,6 +174,7 @@ int peer_if_clean_unused_vlan(struct PeerInterface* peer_if);
int local_if_add_vlan(struct LocalInterface* local_if, uint16_t vid);
void local_if_del_vlan(struct LocalInterface* local_if, uint16_t vid);
void local_if_del_all_vlan(struct LocalInterface* lif);
void local_if_del_all_portchannel_member(struct LocalInterface* lif);

/* ARP manipulation */
int set_sys_arp_accept_flag(char* ifname, int flag);
Expand Down
12 changes: 11 additions & 1 deletion src/iccpd/include/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ struct CSM;
#define MAX_BUFSIZE 4096
#endif

RB_HEAD(lif_rb_tree, LocalInterface);
RB_PROTOTYPE(lif_rb_tree, LocalInterface, lif_entry, lif_node_compare);

#define LIF_RB_REMOVE(name, head, elm) do { \
RB_REMOVE(name, head, elm); \
(elm)->lif_entry.rbt_parent = NULL; \
(elm)->lif_entry.rbt_left = NULL; \
(elm)->lif_entry.rbt_right = NULL; \
} while (0)

struct System
{
int server_fd;/* Peer-Link Socket*/
Expand All @@ -76,7 +86,7 @@ struct System

/* Info List*/
LIST_HEAD(csm_list, CSM) csm_list;
LIST_HEAD(lif_all_list, LocalInterface) lif_list;
struct lif_rb_tree lif_tree;
LIST_HEAD(lif_purge_all_list, LocalInterface) lif_purge_list;

/* Settings */
Expand Down
3 changes: 2 additions & 1 deletion src/iccpd/src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ iccpd_SOURCES = \
mlacp_link_handler.c \
mlacp_sync_prepare.c mlacp_sync_update.c\
mlacp_fsm.c \
iccp_netlink.c
iccp_netlink.c \
openbsd_tree.c
iccpd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON)
iccpd_LDADD = -lnl-genl-3 -lnl-route-3 -lnl-3 -lpthread
6 changes: 3 additions & 3 deletions src/iccpd/src/app_csm.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,13 @@ int mlacp_bind_local_if(struct CSM* csm, struct LocalInterface* lif)
{
if (lif_po->type == IF_T_PORT_CHANNEL && lif_po->po_id == lif->po_id)
{
/*if join a po member, may swss restart, reset portchannel ip mac to mclagsyncd*/
/*if join a po member, may swss restart, reset portchannel ip mac to mclagsyncd*/
update_if_ipmac_on_standby(lif_po);
return 0;
}
}

if (lif_po == NULL)
/*if (lif_po == NULL)
{
lif_po = local_if_find_by_po_id(lif->po_id);
if (lif_po == NULL)
Expand All @@ -257,7 +257,7 @@ int mlacp_bind_local_if(struct CSM* csm, struct LocalInterface* lif)
LIST_INSERT_HEAD(&(MLACP(csm).lif_list), lif_po, mlacp_next);
lif_po->port_config_sync = 1;
ICCPD_LOG_INFO(__FUNCTION__, "Add port_channel %d into local_if_list in CSM %p.", lif->po_id, csm);
}
}*/

return 0;
}
Expand Down
7 changes: 3 additions & 4 deletions src/iccpd/src/iccp_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "../include/iccp_cmd_show.h"
#include "../include/iccp_cli.h"
#include "../include/logger.h"
#include "mclagdctl/mclagdctl.h"

int set_mc_lag_by_id(uint16_t mid)
{
Expand All @@ -55,8 +56,6 @@ int set_mc_lag_by_id(uint16_t mid)
return ret;
}

#define CONFIG_LINE_LEN 512

int iccp_config_from_command(char * line)
{
char *cp, *start;
Expand Down Expand Up @@ -150,13 +149,13 @@ int
iccp_config_from_file(char *config_default_dir)
{
FILE *confp = NULL;
char command_buf[CONFIG_LINE_LEN];
char command_buf[CONFIG_MCLAG_ENABLE_INTF_LEN];

confp = fopen(config_default_dir, "r");
if (confp == NULL)
return (1);

while (fgets(command_buf, CONFIG_LINE_LEN, confp))
while (fgets(command_buf, CONFIG_MCLAG_ENABLE_INTF_LEN, confp))
{
iccp_config_from_command(command_buf);
}
Expand Down
44 changes: 21 additions & 23 deletions src/iccpd/src/iccp_cmd_show.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int iccp_mclag_config_dump(char * *buf, int *num, int mclag_id)
continue;
}

peer_link_if = local_if_find_by_name(csm->peer_itf_name);
peer_link_if = csm->peer_link_if;

if (csm->mlag_id <= 0)
state_info.mclag_id = -1;
Expand All @@ -98,7 +98,7 @@ int iccp_mclag_config_dump(char * *buf, int *num, int mclag_id)

state_info.role = csm->role_type;

str_size = MCLAGDCTL_PORT_MEMBER_BUF_LEN;
str_size = CONFIG_MCLAG_ENABLE_INTF_LEN;
len = 0;

LIST_FOREACH(lif_po, &(MLACP(csm).lif_list), mlacp_next)
Expand Down Expand Up @@ -339,20 +339,18 @@ int iccp_mac_dump(char * *buf, int *num, int mclag_id)
return EXEC_TYPE_SUCCESS;
}

int iccp_local_if_dump(char * *buf, int *num, int mclag_id)
int iccp_local_if_dump(char * *buf, int *data_len, int mclag_id)
{
struct System *sys = NULL;
struct CSM *csm = NULL;
struct LocalInterface *lif_po = NULL;
struct mclagd_local_if mclagd_lif;
struct VLAN_ID* vlan_id = NULL;
char * str_buf = NULL;
int str_size = MCLAGDCTL_PARA3_LEN - 1;
int len = 0;
int lif_num = 0;
int id_exist = 0;
int lif_buf_size = MCLAGDCTL_CMD_SIZE;
int lif_buf_base = MCLAGD_REPLY_INFO_HDR;
char * lif_buf = NULL;
struct PortChannel_member *member = NULL;

if (!(sys = system_get_instance()))
{
Expand Down Expand Up @@ -405,7 +403,7 @@ int iccp_local_if_dump(char * *buf, int *num, int mclag_id)

mclagd_lif.is_peer_link = lif_po->is_peer_link;

memcpy(mclagd_lif.portchannel_member_buf, lif_po->portchannel_member_buf, 512);
mclagd_lif.portchannel_member_count = lif_po->portchannel_member_count;

mclagd_lif.po_id = lif_po->po_id;
mclagd_lif.po_active = lif_po->po_active;
Expand All @@ -423,36 +421,36 @@ int iccp_local_if_dump(char * *buf, int *num, int mclag_id)

mclagd_lif.isolate_to_peer_link = lif_po->isolate_to_peer_link;

str_buf = mclagd_lif.vlanlist;

len = 0;
LIST_FOREACH(vlan_id, &(lif_po->vlan_list), port_next)
RB_FOREACH (vlan_id, vlan_rb_tree, &(lif_po->vlan_tree))
{
if (vlan_id != NULL )
if (vlan_id == NULL )
{
if (str_size - len < 4)
break;
len += snprintf(str_buf + len, str_size - len, "%d ", vlan_id->vid);
continue;
}
BMAP_ADD(mclagd_lif.vlan_map, vlan_id->vid);
}

memcpy(lif_buf + MCLAGD_REPLY_INFO_HDR + lif_num * sizeof(struct mclagd_local_if),
&mclagd_lif, sizeof(struct mclagd_local_if));

lif_num++;

if ((lif_num + 1) * sizeof(struct mclagd_local_if) > (lif_buf_size - MCLAGD_REPLY_INFO_HDR))
if ((lif_buf_base + sizeof(struct mclagd_local_if) + lif_po->portchannel_member_count*MAX_L_PORT_NAME) > lif_buf_size)
{
lif_buf_size += MCLAGDCTL_CMD_SIZE;
lif_buf = (char*)realloc(lif_buf, lif_buf_size);
if (!lif_buf)
return EXEC_TYPE_FAILED;
}

memcpy(lif_buf + lif_buf_base, &mclagd_lif, sizeof(struct mclagd_local_if));
lif_buf_base += sizeof(struct mclagd_local_if);

LIST_FOREACH(member, &(lif_po->member_list), member_next)
{
memcpy(lif_buf + lif_buf_base, &member->name, MAX_L_PORT_NAME);
lif_buf_base += MAX_L_PORT_NAME;
}
}
}

*buf = lif_buf;
*num = lif_num;
*data_len = lif_buf_base;

if (mclag_id > 0 && !id_exist)
return EXEC_TYPE_NO_EXIST_MCLAGID;
Expand Down
17 changes: 4 additions & 13 deletions src/iccpd/src/iccp_consistency_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,28 +112,19 @@ static int iccp_check_interface_vlan(char* ifname)
if (peer_if == NULL)
return -4;

LIST_FOREACH(local_vlan, &(local_if->vlan_list), port_next)
RB_FOREACH (local_vlan, vlan_rb_tree, &(local_if->vlan_tree))
{
LIST_FOREACH(peer_vlan, &(peer_if->vlan_list), port_next)
{
if (peer_vlan->vid == local_vlan->vid)
break;
}
peer_vlan = RB_FIND(vlan_rb_tree, &(peer_if->vlan_tree), local_vlan);

if (peer_vlan == NULL)
{
return -5;
}
}

LIST_FOREACH(peer_vlan, &(peer_if->vlan_list), port_next)
RB_FOREACH (peer_vlan, vlan_rb_tree, &(peer_if->vlan_tree))
{

LIST_FOREACH(local_vlan, &(local_if->vlan_list), port_next)
{
if (peer_vlan->vid == local_vlan->vid)
break;
}
local_vlan = RB_FIND(vlan_rb_tree, &(local_if->vlan_tree), peer_vlan);

if (local_vlan == NULL)
{
Expand Down
Loading