Zebra: Handle RMAC add/delete operation and add fpm_mac_info_t

- Define a hook "zebra_mac_update" which can be registered by multiple
  data plane components (e.g. FPM, dplane).

DEFINE_HOOK(zebra_rmac_update, (zebra_mac_t *rmac, zebra_l3vni_t *zl3vni, bool
	    delete, const char *reason), (rmac, zl3vni, delete, reason))

- While performing RMAC add/delete for an L3VNI, call "zebra_mac_update" hook.

- This hook call triggers "zfpm_trigger_rmac_update". In this function, we do a
  lookup for the RMAC in fpm_mac_info_table. If already present, this node is
  updated with the latest RMAC info. Else, a new fpm_mac_info_t node is created
  and inserted in the queue and hash data structures.

Signed-off-by: Ameya Dharkar <adharkar@vmware.com>
This commit is contained in:
Ameya Dharkar 2019-05-16 14:43:41 -07:00
parent e5218ec873
commit a780a73896
3 changed files with 147 additions and 4 deletions

View File

@ -42,6 +42,7 @@
#include "fpm/fpm.h"
#include "zebra_fpm_private.h"
#include "zebra/zebra_router.h"
#include "zebra_vxlan_private.h"
DEFINE_MTYPE_STATIC(ZEBRA, FPM_MAC_INFO, "FPM_MAC_INFO");
@ -283,6 +284,7 @@ static int zfpm_write_cb(struct thread *thread);
static void zfpm_set_state(zfpm_state_t state, const char *reason);
static void zfpm_start_connect_timer(const char *reason);
static void zfpm_start_stats_timer(void);
static void zfpm_mac_info_del(struct fpm_mac_info_t *fpm_mac);
/*
* zfpm_thread_should_yield
@ -615,9 +617,17 @@ static int zfpm_conn_down_thread_cb(struct thread *thread)
struct route_node *rnode;
zfpm_rnodes_iter_t *iter;
rib_dest_t *dest;
struct fpm_mac_info_t *mac = NULL;
assert(zfpm_g->state == ZFPM_STATE_IDLE);
/*
* Delink and free all fpm_mac_info_t nodes
* in the mac_q and fpm_mac_info_hash
*/
while ((mac = TAILQ_FIRST(&zfpm_g->mac_q)) != NULL)
zfpm_mac_info_del(mac);
zfpm_g->t_conn_down = NULL;
iter = &zfpm_g->t_conn_down_state.iter;
@ -1369,6 +1379,119 @@ static void zfpm_mac_info_del(struct fpm_mac_info_t *fpm_mac)
XFREE(MTYPE_FPM_MAC_INFO, fpm_mac);
}
/*
* zfpm_trigger_rmac_update
*
* Zebra code invokes this function to indicate that we should
* send an update to FPM for given MAC entry.
*
* This function checks if we already have enqueued an update for this RMAC,
* If yes, update the same fpm_mac_info_t. Else, create and enqueue an update.
*/
static int zfpm_trigger_rmac_update(zebra_mac_t *rmac, zebra_l3vni_t *zl3vni,
bool delete, const char *reason)
{
char buf[ETHER_ADDR_STRLEN];
struct fpm_mac_info_t *fpm_mac, key;
struct interface *vxlan_if, *svi_if;
/*
* Ignore if the connection is down. We will update the FPM about
* all destinations once the connection comes up.
*/
if (!zfpm_conn_is_up())
return 0;
if (reason) {
zfpm_debug("triggering update to FPM - Reason: %s - %s",
reason,
prefix_mac2str(&rmac->macaddr, buf, sizeof(buf)));
}
vxlan_if = zl3vni_map_to_vxlan_if(zl3vni);
svi_if = zl3vni_map_to_svi_if(zl3vni);
memset(&key, 0, sizeof(struct fpm_mac_info_t));
memcpy(&key.macaddr, &rmac->macaddr, ETH_ALEN);
key.r_vtep_ip.s_addr = rmac->fwd_info.r_vtep_ip.s_addr;
key.vni = zl3vni->vni;
/* Check if this MAC is already present in the queue. */
fpm_mac = zfpm_mac_info_lookup(&key);
if (fpm_mac) {
if (!!CHECK_FLAG(fpm_mac->fpm_flags, ZEBRA_MAC_DELETE_FPM)
== delete) {
/*
* MAC is already present in the queue
* with the same op as this one. Do nothing
*/
zfpm_g->stats.redundant_triggers++;
return 0;
}
/*
* A new op for an already existing fpm_mac_info_t node.
* Update the existing node for the new op.
*/
if (!delete) {
/*
* New op is "add". Previous op is "delete".
* Update the fpm_mac_info_t for the new add.
*/
fpm_mac->zebra_flags = rmac->flags;
fpm_mac->vxlan_if = vxlan_if ? vxlan_if->ifindex : 0;
fpm_mac->svi_if = svi_if ? svi_if->ifindex : 0;
UNSET_FLAG(fpm_mac->fpm_flags, ZEBRA_MAC_DELETE_FPM);
SET_FLAG(fpm_mac->fpm_flags, ZEBRA_MAC_UPDATE_FPM);
} else {
/*
* New op is "delete". Previous op is "add".
* Thus, no-op. Unset ZEBRA_MAC_UPDATE_FPM flag.
*/
SET_FLAG(fpm_mac->fpm_flags, ZEBRA_MAC_DELETE_FPM);
UNSET_FLAG(fpm_mac->fpm_flags, ZEBRA_MAC_UPDATE_FPM);
}
return 0;
}
fpm_mac = hash_get(zfpm_g->fpm_mac_info_table, &key,
zfpm_mac_info_alloc);
if (!fpm_mac)
return 0;
memcpy(&fpm_mac->zebra_flags, &rmac->flags, sizeof(uint32_t));
fpm_mac->vxlan_if = vxlan_if ? vxlan_if->ifindex : 0;
fpm_mac->svi_if = svi_if ? svi_if->ifindex : 0;
SET_FLAG(fpm_mac->fpm_flags, ZEBRA_MAC_UPDATE_FPM);
if (delete)
SET_FLAG(fpm_mac->fpm_flags, ZEBRA_MAC_DELETE_FPM);
TAILQ_INSERT_TAIL(&zfpm_g->mac_q, fpm_mac, fpm_mac_q_entries);
zfpm_g->stats.updates_triggered++;
/*
* For now, since we do not have mac_q processing code which takes care
* of delinkng and deleting fpm_mac, delete fpm_mac anyway.
* Remove this delete when that code is added in the subsequent commit.
*/
zfpm_mac_info_del(fpm_mac);
/* If writes are already enabled, return. */
if (zfpm_g->t_write)
return 0;
zfpm_write_on();
return 0;
}
/*
* zfpm_stats_timer_cb
*/
@ -1731,6 +1854,7 @@ static int zfpm_init(struct thread_master *master)
static int zebra_fpm_module_init(void)
{
hook_register(rib_update, zfpm_trigger_update);
hook_register(zebra_rmac_update, zfpm_trigger_rmac_update);
hook_register(frr_late_init, zfpm_init);
return 0;
}

View File

@ -60,6 +60,9 @@ DEFINE_MTYPE_STATIC(ZEBRA, MAC, "VNI MAC");
DEFINE_MTYPE_STATIC(ZEBRA, NEIGH, "VNI Neighbor");
DEFINE_MTYPE_STATIC(ZEBRA, ZVXLAN_SG, "zebra VxLAN multicast group");
DEFINE_HOOK(zebra_rmac_update, (zebra_mac_t *rmac, zebra_l3vni_t *zl3vni,
bool delete, const char *reason), (rmac, zl3vni, delete, reason))
/* definitions */
/* PMSI strings. */
#define VXLAN_FLOOD_STR_NO_INFO "-"
@ -143,8 +146,6 @@ static zebra_l3vni_t *zl3vni_lookup(vni_t vni);
static void *zl3vni_alloc(void *p);
static zebra_l3vni_t *zl3vni_add(vni_t vni, vrf_id_t vrf_id);
static int zl3vni_del(zebra_l3vni_t *zl3vni);
static struct interface *zl3vni_map_to_svi_if(zebra_l3vni_t *zl3vni);
static struct interface *zl3vni_map_to_vxlan_if(zebra_l3vni_t *zl3vni);
static void zebra_vxlan_process_l3vni_oper_up(zebra_l3vni_t *zl3vni);
static void zebra_vxlan_process_l3vni_oper_down(zebra_l3vni_t *zl3vni);
@ -4459,6 +4460,10 @@ static int zl3vni_remote_rmac_add(zebra_l3vni_t *zl3vni, struct ethaddr *rmac,
memset(&zrmac->fwd_info, 0, sizeof(zrmac->fwd_info));
zrmac->fwd_info.r_vtep_ip = vtep_ip->ipaddr_v4;
/* Send RMAC for FPM processing */
hook_call(zebra_rmac_update, zrmac, zl3vni, false,
"new RMAC added");
/* install rmac in kernel */
zl3vni_rmac_install(zl3vni, zrmac);
}
@ -4479,6 +4484,10 @@ static void zl3vni_remote_rmac_del(zebra_l3vni_t *zl3vni, zebra_mac_t *zrmac,
/* uninstall from kernel */
zl3vni_rmac_uninstall(zl3vni, zrmac);
/* Send RMAC for FPM processing */
hook_call(zebra_rmac_update, zrmac, zl3vni, true,
"RMAC deleted");
/* del the rmac entry */
zl3vni_rmac_del(zl3vni, zrmac);
}
@ -4790,7 +4799,7 @@ static int zl3vni_del(zebra_l3vni_t *zl3vni)
return 0;
}
static struct interface *zl3vni_map_to_vxlan_if(zebra_l3vni_t *zl3vni)
struct interface *zl3vni_map_to_vxlan_if(zebra_l3vni_t *zl3vni)
{
struct zebra_ns *zns = NULL;
struct route_node *rn = NULL;
@ -4821,7 +4830,7 @@ static struct interface *zl3vni_map_to_vxlan_if(zebra_l3vni_t *zl3vni)
return NULL;
}
static struct interface *zl3vni_map_to_svi_if(zebra_l3vni_t *zl3vni)
struct interface *zl3vni_map_to_svi_if(zebra_l3vni_t *zl3vni)
{
struct zebra_if *zif = NULL; /* zebra_if for vxlan_if */
struct zebra_l2info_vxlan *vxl = NULL; /* l2 info for vxlan_if */
@ -5089,6 +5098,10 @@ static void zl3vni_del_rmac_hash_entry(struct hash_bucket *bucket, void *ctx)
zrmac = (zebra_mac_t *)bucket->data;
zl3vni = (zebra_l3vni_t *)ctx;
zl3vni_rmac_uninstall(zl3vni, zrmac);
/* Send RMAC for FPM processing */
hook_call(zebra_rmac_update, zrmac, zl3vni, true, "RMAC deleted");
zl3vni_rmac_del(zl3vni, zrmac);
}

View File

@ -431,6 +431,12 @@ struct nh_walk_ctx {
};
extern zebra_l3vni_t *zl3vni_from_vrf(vrf_id_t vrf_id);
extern struct interface *zl3vni_map_to_vxlan_if(zebra_l3vni_t *zl3vni);
extern struct interface *zl3vni_map_to_svi_if(zebra_l3vni_t *zl3vni);
DECLARE_HOOK(zebra_rmac_update, (zebra_mac_t *rmac, zebra_l3vni_t *zl3vni,
bool delete, const char *reason), (rmac, zl3vni, delete, reason))
#ifdef __cplusplus
}