Skip to content

Commit

Permalink
MCLAG enhacements ICCPd initial code commit (sonic-net#4819)
Browse files Browse the repository at this point in the history
* MCLAG enhacements ICCPd initial code commit
* Resolving the merge conflicts with orighin
* L3 MCLAG Enhancements and Unique IP Changes.
* Addressed review comments

Co-authored-by: Tapash Das <tapash.das@broadcom.com>
  • Loading branch information
2 people authored and Carl Keene committed Aug 7, 2021
1 parent a93cb97 commit 915e590
Show file tree
Hide file tree
Showing 38 changed files with 8,501 additions and 1,389 deletions.
27 changes: 15 additions & 12 deletions src/iccpd/include/iccp_cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ typedef enum

typedef struct cli_param_queue
{
char ifname[16];
char ifname[16];
cli_queue_type_et type;
int param;
int itf_add;
int param;
int itf_add;
LIST_ENTRY(cli_param_queue) cli_queue_next;
} cli_param_queue_st;

Expand All @@ -50,18 +50,21 @@ typedef struct cli_param_queue
#define MCLAG_INTF_STR "mclag_interface"
#define SYSTEM_MAC_STR "system_mac"

int set_mc_lag_id(struct CSM* csm, uint16_t domain);
int set_peer_link(int mid, const char* ifname);
int set_local_address(int mid, const char* addr);
int set_peer_address(int mid, const char* addr);
int unset_mc_lag_id(struct CSM* csm, uint16_t domain);
int set_mc_lag_id(struct CSM *csm, uint16_t domain);
int set_peer_link(int mid, const char *ifname);
int set_local_address(int mid, const char *addr);
int set_peer_address(int mid, const char *addr);
int unset_mc_lag_id(struct CSM *csm, uint16_t domain);
int unset_peer_link(int mid);
int unset_local_address(int mid);
int unset_peer_address(int mid);

int iccp_cli_attach_mclag_domain_to_port_channel(int domain, const char* ifname);
int iccp_cli_detach_mclag_domain_to_port_channel(const char* ifname);
int set_local_system_id(const char* mac);
int unset_local_system_id( );
int iccp_cli_attach_mclag_domain_to_port_channel(int domain, const char *ifname);
int iccp_cli_detach_mclag_domain_to_port_channel(const char *ifname);
int set_local_system_id(const char *mac);
int unset_local_system_id();

int set_keepalive_time(int mid, int keepalive_time);
int set_session_timeout(int mid, int session_timeout_val);

#endif
3 changes: 3 additions & 0 deletions src/iccpd/include/iccp_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@

int iccp_config_from_file(char *config_default_dir);

int set_mc_lag_by_id(uint16_t mid);
int unset_mc_lag_by_id(uint16_t mid);

#endif /* ICCP_CMD_H_ */
2 changes: 2 additions & 0 deletions src/iccpd/include/iccp_cmd_show.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ extern int iccp_ndisc_dump(char * *buf, int *num, int mclag_id);
extern int iccp_mac_dump(char * *buf, int *num, int mclag_id);
extern int iccp_local_if_dump(char * *buf, int *num, int mclag_id);
extern int iccp_peer_if_dump(char * *buf, int *num, int mclag_id);
extern int iccp_cmd_dbg_counter_dump(char * *buf, int *data_len, int mclag_id);
extern int iccp_unique_ip_if_dump(char * *buf, int *num, int mclag_id);
#endif
11 changes: 8 additions & 3 deletions src/iccpd/include/iccp_csm.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@

#ifndef INET_ADDRSTRLEN
#define INET_ADDRSTRLEN 16
#endif /* INET_ADDRSTRLEN */
#endif /* INET_ADDRSTRLEN */
#ifndef INET6_ADDRSTRLEN
#define INET6_ADDRSTRLEN 46
#endif /* INET6_ADDRSTRLEN */
#endif /* INET6_ADDRSTRLEN */
/* For socket binding */
#define ICCP_TCP_PORT 8888
#define MAX_ACCEPT_CONNETIONS 20
Expand Down Expand Up @@ -113,10 +113,15 @@ struct CSM
time_t peer_warm_reboot_time;
time_t warm_reboot_disconn_time;
char peer_itf_name[IFNAMSIZ];
time_t peer_link_learning_retry_time;
char peer_ip[INET_ADDRSTRLEN];
char sender_ip[INET_ADDRSTRLEN];
void* sock_read_event_ptr;

int keepalive_time;
int session_timeout;
int peer_link_learning_enable;

/* Msg queue */
TAILQ_HEAD(msg_list, Msg) msg_list;

Expand Down Expand Up @@ -164,5 +169,5 @@ void iccp_csm_correspond_from_rg_connect_msg(struct CSM*, struct Msg*);
void iccp_csm_correspond_from_rg_disconnect_msg(struct CSM*, struct Msg*);

int mlacp_bind_port_channel_to_csm(struct CSM* csm, const char *ifname);

int iccp_csm_init_mac_msg(struct MACMsg **mac_msg, char* data, int len);
#endif /* ICCP_CSM_H_ */
4 changes: 3 additions & 1 deletion src/iccpd/include/iccp_ifm.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,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 vlan_mbrship_change_handler(unsigned int vlan_id, char *mbr_if_name, int add_flag);
void del_all_pending_vlan_mbr_ifs(struct System *sys);
void move_pending_vlan_mbr_to_lif(struct System *sys, struct LocalInterface* lif);
#endif // LACP_IFM_H

16 changes: 9 additions & 7 deletions src/iccpd/include/iccp_netlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
#include <stdarg.h>
#include <unistd.h>
#include <netlink/netlink.h>

#include <linux/types.h>

#include "../include/system.h"
#include "../include/port.h"
#include <netinet/icmp6.h>
Expand All @@ -37,6 +35,7 @@
#define NDISC_NEIGHBOUR_ADVERTISEMENT 136
#define ND_OPT_TARGET_LL_ADDR 2
#define NEXTHDR_ICMP 58
#define ICCP_NLE_SEQ_MISMATCH -16

struct nd_msg
{
Expand All @@ -51,17 +50,20 @@ struct in6_pktinfo
unsigned int ipi6_ifindex; /* send/recv interface index */
};

int iccp_get_port_member_list(struct LocalInterface* lif);
int iccp_get_port_member_list(struct LocalInterface *lif);
void iccp_event_handler_obj_input_newlink(struct nl_object *obj, void *arg);
void iccp_event_handler_obj_input_dellink(struct nl_object *obj, void *arg);
int iccp_system_init_netlink_socket();
void iccp_system_dinit_netlink_socket();
int iccp_init_netlink_event_fd(struct System *sys);
int iccp_handle_events(struct System * sys);
void update_if_ipmac_on_standby(struct LocalInterface* lif_po);
int iccp_handle_events(struct System *sys);
void update_if_ipmac_on_standby(struct LocalInterface *lif_po, int dir);
int iccp_sys_local_if_list_get_addr();
int iccp_netlink_neighbor_request(int family, uint8_t *addr, int add, uint8_t *mac, char *portname);
int iccp_netlink_neighbor_request(int family, uint8_t *addr, int add, uint8_t *mac, char *portname, int permanent, int dir);
int iccp_check_if_addr_from_netlink(int family, uint8_t *addr, struct LocalInterface *lif);

void recover_if_ipmac_on_standby(struct LocalInterface* lif_po, int dir);
void update_vlan_if_mac_on_standby(struct LocalInterface* lif_vlan, int dir);
void recover_vlan_if_mac_on_standby(struct LocalInterface* lif_vlan, int dir, uint8_t *remote_system_mac);
void update_vlan_if_mac_on_iccp_up(struct LocalInterface* lif_peer, int is_up, uint8_t *remote_system_mac);
#endif

2 changes: 1 addition & 1 deletion src/iccpd/include/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
typedef enum _iccpd_log_level_t
{
CRITICAL_LOG_LEVEL = 0,
ERR_LOG_LEVEL = 1,
ERR_LOG_LEVEL = 1,
WARN_LOG_LEVEL = 2,
NOTICE_LOG_LEVEL = 3,
INFO_LOG_LEVEL = 4,
Expand Down
96 changes: 93 additions & 3 deletions src/iccpd/include/mlacp_fsm.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@
#define _MLACP_FSM_H

#include "../include/port.h"
#include "../include/mlacp_tlv.h"

#define MLCAP_SYNC_PHY_DEV_SEC 1 /*every 1 sec*/

#define MLACP_LOCAL_IF_DOWN_TIMER 600 // 600 seconds.

#define MLACP(csm_ptr) (csm_ptr->app_csm.mlacp)

struct CSM;
Expand All @@ -47,7 +50,7 @@ typedef enum MLACP_APP_STATE MLACP_APP_STATE_E;
/* for sender only*/
enum MLACP_SYNC_STATE
{
MLACP_SYNC_SYSCONF=0,
MLACP_SYNC_SYSCONF = 0,
MLACP_SYNC_AGGCONF,
MLACP_SYNC_AGGSTATE,
MLACP_SYNC_AGGINFO,
Expand All @@ -66,6 +69,85 @@ struct Remote_System
uint32_t node_id;
};

/****************************************************************
* Debug counters to track message sent and received between
* MC-LAG peers over ICCP
***************************************************************/
typedef uint8_t ICCP_DBG_CNTR_DIR_e;
enum ICCP_DBG_CNTR_DIR_e
{
ICCP_DBG_CNTR_DIR_TX = 0,
ICCP_DBG_CNTR_DIR_RX = 1,
ICCP_DBG_CNTR_DIR_MAX
};

typedef uint8_t ICCP_DBG_CNTR_STS_e;
enum ICCP_DBG_CNTR_STS_e
{
ICCP_DBG_CNTR_STS_OK = 0,
ICCP_DBG_CNTR_STS_ERR = 1, /* Send error or receive processing error*/
ICCP_DBG_CNTR_STS_MAX
};

/* Change MCLAGDCTL_MAX_DBG_COUNTERS if ICCP_DBG_CNTR_MSG_MAX is more than 32 */
enum ICCP_DBG_CNTR_MSG
{
ICCP_DBG_CNTR_MSG_SYS_CONFIG = 0,
ICCP_DBG_CNTR_MSG_AGGR_CONFIG = 1,
ICCP_DBG_CNTR_MSG_AGGR_STATE = 2,
ICCP_DBG_CNTR_MSG_MAC_INFO = 3,
ICCP_DBG_CNTR_MSG_ARP_INFO = 4,
ICCP_DBG_CNTR_MSG_L2MC_INFO = 5,
ICCP_DBG_CNTR_MSG_PORTCHANNEL_INFO = 6,
ICCP_DBG_CNTR_MSG_PEER_LINK_INFO = 7,
ICCP_DBG_CNTR_MSG_HEART_BEAT = 8,
ICCP_DBG_CNTR_MSG_NAK = 9,
ICCP_DBG_CNTR_MSG_SYNC_DATA = 10,
ICCP_DBG_CNTR_MSG_SYNC_REQ = 11,
ICCP_DBG_CNTR_MSG_WARM_BOOT = 12,
ICCP_DBG_CNTR_MSG_IF_UP_ACK = 13,
ICCP_DBG_CNTR_MSG_STP_CONNECT = 14,
ICCP_DBG_CNTR_MSG_STP_DISCONNECT = 15,
ICCP_DBG_CNTR_MSG_STP_SYSTEM_CONFIG = 16,
ICCP_DBG_CNTR_MSG_STP_REGION_NAME = 17,
ICCP_DBG_CNTR_MSG_STP_REVISION_LEVEL = 18,
ICCP_DBG_CNTR_MSG_STP_INSTANCE_PRIORITY = 19,
ICCP_DBG_CNTR_MSG_STP_CONFIGURATION_DIGEST = 20,
ICCP_DBG_CNTR_MSG_STP_TC_INSTANCES = 21,
ICCP_DBG_CNTR_MSG_STP_ROOT_TIME_PARAM = 22,
ICCP_DBG_CNTR_MSG_STP_MIST_ROOT_TIME_PARAM = 23,
ICCP_DBG_CNTR_MSG_STP_SYNC_REQ = 24,
ICCP_DBG_CNTR_MSG_STP_SYNC_DATA = 25,
ICCP_DBG_CNTR_MSG_STP_PO_PORT_MAP = 26,
ICCP_DBG_CNTR_MSG_STP_AGE_OUT = 27,
ICCP_DBG_CNTR_MSG_STP_COMMON_MSG = 28,
ICCP_DBG_CNTR_MSG_MAX
};
typedef enum ICCP_DBG_CNTR_MSG ICCP_DBG_CNTR_MSG_e;

/* Count messages sent to MCLAG peer */
#define MLACP_SET_ICCP_TX_DBG_COUNTER(csm, tlv_type, status)\
do{\
ICCP_DBG_CNTR_MSG_e dbg_type;\
dbg_type = mlacp_fsm_iccp_to_dbg_msg_type(tlv_type);\
if (csm && ((dbg_type) < ICCP_DBG_CNTR_MSG_MAX) && ((status) < ICCP_DBG_CNTR_STS_MAX))\
++MLACP(csm).dbg_counters.iccp_counters[dbg_type][ICCP_DBG_CNTR_DIR_TX][status];\
}while(0);

/* Count messages received from MCLAG peer */
#define MLACP_SET_ICCP_RX_DBG_COUNTER(csm, tlv_type, status)\
do{\
ICCP_DBG_CNTR_MSG_e dbg_type;\
dbg_type = mlacp_fsm_iccp_to_dbg_msg_type(tlv_type);\
if (csm && ((dbg_type) < ICCP_DBG_CNTR_MSG_MAX) && ((status) < ICCP_DBG_CNTR_STS_MAX))\
++MLACP(csm).dbg_counters.iccp_counters[dbg_type][ICCP_DBG_CNTR_DIR_RX][status];\
}while(0);

typedef struct mlacp_dbg_counter_info
{
uint64_t iccp_counters[ICCP_DBG_CNTR_MSG_MAX][ICCP_DBG_CNTR_DIR_MAX][ICCP_DBG_CNTR_STS_MAX];
}mlacp_dbg_counter_info_t;

struct mLACP
{
int id;
Expand All @@ -88,22 +170,30 @@ struct mLACP
TAILQ_HEAD(arp_info_list, Msg) arp_list;
TAILQ_HEAD(ndisc_msg_list, Msg) ndisc_msg_list;
TAILQ_HEAD(ndisc_info_list, Msg) ndisc_list;
TAILQ_HEAD(mac_msg_list, Msg) mac_msg_list;
TAILQ_HEAD(mac_info_list, Msg) mac_list;
TAILQ_HEAD(mac_msg_list, MACMsg) mac_msg_list;

struct mac_rb_tree mac_rb;

LIST_HEAD(lif_list, LocalInterface) lif_list;
LIST_HEAD(lif_purge_list, LocalInterface) lif_purge_list;
LIST_HEAD(pif_list, PeerInterface) pif_list;

/* ICCP message tx/rx debug counters */
mlacp_dbg_counter_info_t dbg_counters;
};

void mlacp_init(struct CSM* csm, int all);
void mlacp_finalize(struct CSM* csm);
void mlacp_fsm_transit(struct CSM* csm);
void mlacp_enqueue_msg(struct CSM*, struct Msg*);
struct Msg* mlacp_dequeue_msg(struct CSM*);
char* mlacp_state(struct CSM* csm);

/* from app_csm*/
extern int mlacp_bind_local_if(struct CSM* csm, struct LocalInterface* local_if);
extern int mlacp_unbind_local_if(struct LocalInterface* local_if);

/* Debug counter API */
ICCP_DBG_CNTR_MSG_e mlacp_fsm_iccp_to_dbg_msg_type(uint32_t tlv_type);

#endif /* _MLACP_HANDLER_H */
45 changes: 41 additions & 4 deletions src/iccpd/include/mlacp_link_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,16 @@
#ifndef __MLACP_LINK_HANDLER__
#define __MLACP_LINK_HANDLER__

#include <stdbool.h>
#include "../include/iccp_csm.h"
#include "../include/mlacp_tlv.h"

#define MCLAG_MAX_MSG_LEN 4096
#define ICCP_MLAGSYNCD_SEND_MSG_BUFFER_SIZE MCLAG_MAX_MSG_LEN
#define ICCP_MLAGSYNCD_RECV_MSG_BUFFER_SIZE (MCLAG_MAX_MSG_LEN * 256)

extern char g_iccp_recv_buf[];

/*****************************************
* Link Handler
*
Expand All @@ -43,18 +50,48 @@ void set_peerlink_mlag_port_learn(struct LocalInterface *lif, int enable);
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);
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);
ssize_t iccp_send_to_mclagsyncd(uint8_t msg_type, char *send_buff, uint16_t send_len);

void del_mac_from_chip(struct MACMsg* mac_msg);
void add_mac_to_chip(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, uint8_t update_peer);

extern int mclagd_ctl_sock_create();
extern int mclagd_ctl_sock_accept(int fd);
extern int mclagd_ctl_interactive_process(int client_fd);
extern int parseMacString(const char *str_mac, uint8_t *bin_mac);

char *show_ip_str(uint32_t ipv4_addr);
char *show_ipv6_str(char *ipv6_addr);

void syncd_info_close();
int iccp_connect_syncd();

void mlacp_link_disable_traffic_distribution(struct LocalInterface *lif);
void mlacp_link_enable_traffic_distribution(struct LocalInterface *lif);
int mlacp_link_set_iccp_state(int mlag_id, bool is_oper_up);
int mlacp_link_set_iccp_role(int mlag_id, bool is_active_role, uint8_t *system_id);
int mlacp_link_set_iccp_system_id(int mlag_id, uint8_t *system_id);
int mlacp_link_del_iccp_info(int mlag_id);
int mlacp_link_set_remote_if_state(int mlag_id, char *po_name, bool is_oper_up);
int mlacp_link_del_remote_if_info(int mlag_id, char *po_name);
int mlacp_link_set_peerlink_port_isolation(int mlag_id, char *po_name, bool is_isolation_enable);

void mlacp_mlag_intf_detach_handler(struct CSM* csm, struct LocalInterface* local_if);
void mlacp_peer_mlag_intf_delete_handler(struct CSM* csm, char *mlag_if_name);

int iccp_mclagsyncd_msg_handler(struct System *sys);
int syn_local_neigh_mac_info_to_peer(struct LocalInterface *local_if, int sync_add,
int is_v4, int is_v6, int sync_mac, int ack, int is_ipv6_ll, int dir);
int syn_local_mac_info_to_peer(struct CSM* csm, struct LocalInterface *local_if, int sync_add, int is_sag);
int syn_local_arp_info_to_peer(struct CSM* csm, struct LocalInterface *local_if, int sync_add, int ack);
int syn_local_nd_info_to_peer(struct CSM* csm, struct LocalInterface *local_if, int sync_add, int ack, int is_ipv6_ll, int dir);
int syn_ack_local_neigh_mac_info_to_peer(char *ifname, int is_ipv6_ll);
int is_unique_ip_configured(char *ifname);
void set_peerlink_learn_kernel(struct CSM* csm, int enable, int dir);
void set_peer_mac_in_kernel(char *mac, int vlan, int add);
void mlacp_fix_bridge_mac(struct CSM* csm);
void update_orphan_port_mac(struct CSM *csm, struct LocalInterface *lif, int state);
void mlacp_convert_remote_mac_to_local(struct CSM *csm, char *po_name);
int sync_unique_ip();
#endif
13 changes: 10 additions & 3 deletions src/iccpd/include/mlacp_sync_prepare.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,19 @@ int mlacp_prepare_for_sync_request_tlv(struct CSM* csm, char* buf, size_t max_bu
int mlacp_prepare_for_sync_data_tlv(struct CSM* csm, char* buf, size_t max_buf_size, int end);
int mlacp_prepare_for_sys_config(struct CSM* csm, char* buf, size_t max_buf_size);
int mlacp_prepare_for_mac_info_to_peer(struct CSM* csm, char* buf, size_t max_buf_size, struct MACMsg* mac_msg, int count);
int mlacp_prepare_for_arp_info(struct CSM* csm, char* buf, size_t max_buf_size, struct ARPMsg* arp_msg, int count);
int mlacp_prepare_for_ndisc_info(struct CSM *csm, char *buf, size_t max_buf_size, struct NDISCMsg *ndisc_msg, int count);
int mlacp_prepare_for_arp_info(struct CSM* csm, char* buf, size_t max_buf_size, struct ARPMsg* arp_msg, int count, int dir);
int mlacp_prepare_for_ndisc_info(struct CSM *csm, char *buf, size_t max_buf_size, struct NDISCMsg *ndisc_msg, int count, int dir);
int mlacp_prepare_for_heartbeat(struct CSM* csm, char* buf, size_t max_buf_size);
int mlacp_prepare_for_Aggport_state(struct CSM* csm, char* buf, size_t max_buf_size, struct LocalInterface* local_if);
int mlacp_prepare_for_Aggport_config(struct CSM* csm, char* buf, size_t max_buf_size, struct LocalInterface* lif, int purge_flag);
int mlacp_prepare_for_port_channel_info(struct CSM* csm, char* buf, size_t max_buf_size, struct LocalInterface* port_channel);
int mlacp_prepare_for_port_peerlink_info(struct CSM* csm, char* buf, size_t max_buf_size, struct LocalInterface* peerlink_port);
int iccp_netlink_if_hwaddr_set(uint32_t ifindex, uint8_t *addr, unsigned int addr_len);
#endif
int mlacp_prepare_for_if_up_ack(
struct CSM *csm,
char *buf,
size_t max_buf_size,
uint8_t if_type,
uint16_t if_id,
uint8_t port_isolation_enable);
#endif
Loading

0 comments on commit 915e590

Please sign in to comment.