Skip to content

Commit

Permalink
zebra: Convert label processing to Meta-Q
Browse files Browse the repository at this point in the history
Convert label processing that comes from zapi messages
into being handled by the meta-Q.  This is because early
route processing is going to be moved to the meta-Q as
well and we will have a chicken and egg problem without
moving this code to be processed by the meta-Q.

Ordering of messages from ospf as an example:
2022/08/09 08:55:52.740 ZEBRA: [YXG8K-BCYMV] zebra message[ZEBRA_ROUTE_ADD:0:48] comes from socket [36]
2022/08/09 08:55:52.740 ZEBRA: [YXG8K-BCYMV] zebra message[ZEBRA_ROUTE_ADD:0:48] comes from socket [36]
2022/08/09 08:55:52.740 ZEBRA: [YXG8K-BCYMV] zebra message[ZEBRA_ROUTE_ADD:0:48] comes from socket [36]
2022/08/09 08:55:52.740 ZEBRA: [YXG8K-BCYMV] zebra message[ZEBRA_ROUTE_ADD:0:48] comes from socket [36]
2022/08/09 08:55:52.740 ZEBRA: [YXG8K-BCYMV] zebra message[ZEBRA_ROUTE_ADD:0:62] comes from socket [36]
2022/08/09 08:55:52.740 ZEBRA: [YXG8K-BCYMV] zebra message[ZEBRA_ROUTE_ADD:0:43] comes from socket [36]
2022/08/09 08:55:52.740 ZEBRA: [YXG8K-BCYMV] zebra message[ZEBRA_ROUTE_ADD:0:47] comes from socket [36]
2022/08/09 08:55:52.740 ZEBRA: [YXG8K-BCYMV] zebra message[ZEBRA_ROUTE_ADD:0:47] comes from socket [36]
2022/08/09 08:55:52.740 ZEBRA: [YXG8K-BCYMV] zebra message[ZEBRA_ROUTE_ADD:0:47] comes from socket [36]
2022/08/09 08:55:52.740 ZEBRA: [YXG8K-BCYMV] zebra message[ZEBRA_ROUTE_ADD:0:47] comes from socket [36]
2022/08/09 08:55:52.740 ZEBRA: [YXG8K-BCYMV] zebra message[ZEBRA_ROUTE_ADD:0:61] comes from socket [36]
2022/08/09 08:55:52.740 ZEBRA: [YXG8K-BCYMV] zebra message[ZEBRA_ROUTE_ADD:0:47] comes from socket [36]
2022/08/09 08:55:52.740 ZEBRA: [YXG8K-BCYMV] zebra message[ZEBRA_ROUTE_ADD:0:47] comes from socket [36]
2022/08/09 08:55:52.740 ZEBRA: [YXG8K-BCYMV] zebra message[ZEBRA_MPLS_LABELS_REPLACE:0:47] comes from socket [36]
2022/08/09 08:55:52.740 ZEBRA: [YXG8K-BCYMV] zebra message[ZEBRA_MPLS_LABELS_REPLACE:0:66] comes from socket [36]
2022/08/09 08:55:52.740 ZEBRA: [YXG8K-BCYMV] zebra message[ZEBRA_MPLS_LABELS_REPLACE:0:47] comes from socket [36]
2022/08/09 08:55:52.740 ZEBRA: [YXG8K-BCYMV] zebra message[ZEBRA_MPLS_LABELS_REPLACE:0:47] comes from socket [36]
2022/08/09 08:55:52.740 ZEBRA: [YXG8K-BCYMV] zebra message[ZEBRA_MPLS_LABELS_REPLACE:0:47] comes from socket [36]

The ZEBRA_MPLS_LABELS_REPLACE immediately turn around and attempt to replace nexthop labels on routes that
were added.  If the route add is placed on the metaQ, it will not exist yet and as such the label replace
will fail.

Modify the zebra code to take the label operations and place them on the metaQ as well.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
  • Loading branch information
donaldsharp committed Aug 17, 2022
1 parent c8e1ce6 commit 53216df
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 8 deletions.
3 changes: 2 additions & 1 deletion zebra/rib.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ struct route_entry {
/* meta-queue structure:
* sub-queue 0: nexthop group objects
* sub-queue 1: EVPN/VxLAN objects
* sub-queue 2: Early Label Processing
* sub-queue 2: connected
* sub-queue 3: kernel
* sub-queue 4: static
Expand All @@ -186,7 +187,7 @@ struct route_entry {
* sub-queue 7: any other origin (if any) typically those that
* don't generate routes
*/
#define MQ_SIZE 8
#define MQ_SIZE 9
struct meta_queue {
struct list *subq[MQ_SIZE];
uint32_t size; /* sum of lengths of all subqueues */
Expand Down
10 changes: 5 additions & 5 deletions zebra/zebra_mpls.c
Original file line number Diff line number Diff line change
Expand Up @@ -2747,9 +2747,9 @@ static bool ftn_update_nexthop(bool add_p, struct nexthop *nexthop,
return true;
}

void mpls_ftn_uninstall(struct zebra_vrf *zvrf, enum lsp_types_t type,
struct prefix *prefix, uint8_t route_type,
unsigned short route_instance)
void zebra_mpls_ftn_uninstall(struct zebra_vrf *zvrf, enum lsp_types_t type,
struct prefix *prefix, uint8_t route_type,
uint8_t route_instance)
{
struct route_table *table;
struct route_node *rn;
Expand Down Expand Up @@ -2882,8 +2882,8 @@ static bool ftn_update_znh(bool add_p, enum lsp_types_t type,
* There are several changes that need to be made, in several zebra
* data structures, so we want to do all the work required at once.
*/
void mpls_zapi_labels_process(bool add_p, struct zebra_vrf *zvrf,
const struct zapi_labels *zl)
void zebra_mpls_zapi_labels_process(bool add_p, struct zebra_vrf *zvrf,
const struct zapi_labels *zl)
{
int i, counter, ret = 0;
char buf[NEXTHOP_STRLEN];
Expand Down
17 changes: 15 additions & 2 deletions zebra/zebra_mpls.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,17 +260,30 @@ void zebra_mpls_print_fec(struct vty *vty, struct zebra_vrf *zvrf,
/*
* Handle zapi request to install/uninstall LSP and
* (optionally) FEC-To-NHLFE (FTN) bindings.
*
* mpls_zapi_labels_process -> Installs for future processing
* in the meta-q
* zebra_mpls_labels_process -> called by the meta-q
*/
void mpls_zapi_labels_process(bool add_p, struct zebra_vrf *zvrf,
const struct zapi_labels *zl);
void zebra_mpls_zapi_labels_process(bool add_p, struct zebra_vrf *zvrf,
const struct zapi_labels *zl);

/*
* Uninstall all NHLFEs bound to a single FEC.
*
* mpls_ftn_uninstall -> Called to enqueue into early label processing
* via the metaq
* zebra_mpls_ftn_uninstall -> Called when we process the meta q
* for this item
*/
void mpls_ftn_uninstall(struct zebra_vrf *zvrf, enum lsp_types_t type,
struct prefix *prefix, uint8_t route_type,
unsigned short route_instance);

uint8_t route_instance);
void zebra_mpls_ftn_uninstall(struct zebra_vrf *zvrf, enum lsp_types_t type,
struct prefix *prefix, uint8_t route_type,
uint8_t route_instance);
/*
* Install/update a NHLFE for an LSP in the forwarding table. This may be
* a new LSP entry or a new NHLFE for an existing in-label or an update of
Expand Down
124 changes: 124 additions & 0 deletions zebra/zebra_rib.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ DEFINE_HOOK(rib_update, (struct route_node * rn, const char *reason),
enum meta_queue_indexes {
META_QUEUE_NHG,
META_QUEUE_EVPN,
META_QUEUE_EARLY_LABEL,
META_QUEUE_CONNECTED,
META_QUEUE_KERNEL,
META_QUEUE_STATIC,
Expand Down Expand Up @@ -173,6 +174,26 @@ struct wq_evpn_wrapper {
#define WQ_EVPN_WRAPPER_TYPE_REM_MACIP 0x03
#define WQ_EVPN_WRAPPER_TYPE_REM_VTEP 0x04

enum wq_label_types {
WQ_LABEL_FTN_UNINSTALL,
WQ_LABEL_LABELS_PROCESS,
};

struct wq_label_wrapper {
enum wq_label_types type;
vrf_id_t vrf_id;

struct prefix p;
enum lsp_types_t ltype;
uint8_t route_type;
uint8_t route_instance;

bool add_p;
struct zapi_labels zl;

int afi;
};

/* %pRN is already a printer for route_nodes that just prints the prefix */
#ifdef _FRR_ATTRIBUTE_PRINTFRR
#pragma FRR printfrr_ext "%pZN" (struct route_node *)
Expand All @@ -185,6 +206,8 @@ static const char *subqueue2str(enum meta_queue_indexes index)
return "NHG Objects";
case META_QUEUE_EVPN:
return "EVPN/VxLan Objects";
case META_QUEUE_EARLY_LABEL:
return "Early Label Handling";
case META_QUEUE_CONNECTED:
return "Connected Routes";
case META_QUEUE_KERNEL:
Expand Down Expand Up @@ -2468,6 +2491,33 @@ static void process_subq_nhg(struct listnode *lnode)
XFREE(MTYPE_WQ_WRAPPER, w);
}

static void process_subq_early_label(struct listnode *lnode)
{
struct wq_label_wrapper *w = listgetdata(lnode);
struct zebra_vrf *zvrf;

if (!w)
return;

zvrf = vrf_info_lookup(w->vrf_id);
if (!zvrf) {
XFREE(MTYPE_WQ_WRAPPER, w);
return;
}

switch (w->type) {
case WQ_LABEL_FTN_UNINSTALL:
zebra_mpls_ftn_uninstall(zvrf, w->ltype, &w->p, w->route_type,
w->route_instance);
break;
case WQ_LABEL_LABELS_PROCESS:
zebra_mpls_zapi_labels_process(w->add_p, zvrf, &w->zl);
break;
}

XFREE(MTYPE_WQ_WRAPPER, w);
}

static void process_subq_route(struct listnode *lnode, uint8_t qindex)
{
struct route_node *rnode = NULL;
Expand Down Expand Up @@ -2525,6 +2575,9 @@ static unsigned int process_subq(struct list *subq,
case META_QUEUE_NHG:
process_subq_nhg(lnode);
break;
case META_QUEUE_EARLY_LABEL:
process_subq_early_label(lnode);
break;
case META_QUEUE_CONNECTED:
case META_QUEUE_KERNEL:
case META_QUEUE_STATIC:
Expand Down Expand Up @@ -2635,6 +2688,13 @@ static int rib_meta_queue_add(struct meta_queue *mq, void *data)
return 0;
}

static int early_label_meta_queue_add(struct meta_queue *mq, void *data)
{
listnode_add(mq->subq[META_QUEUE_EARLY_LABEL], data);
mq->size++;
return 0;
}

static int rib_meta_queue_nhg_ctx_add(struct meta_queue *mq, void *data)
{
struct nhg_ctx *ctx = NULL;
Expand Down Expand Up @@ -2718,6 +2778,44 @@ static int mq_add_handler(void *data,
return mq_add_func(zrouter.mq, data);
}

void mpls_ftn_uninstall(struct zebra_vrf *zvrf, enum lsp_types_t type,
struct prefix *prefix, uint8_t route_type,
uint8_t route_instance)
{
struct wq_label_wrapper *w;

w = XCALLOC(MTYPE_WQ_WRAPPER, sizeof(struct wq_label_wrapper));

w->type = WQ_LABEL_FTN_UNINSTALL;
w->vrf_id = zvrf->vrf->vrf_id;
w->p = *prefix;
w->ltype = type;
w->route_type = route_type;
w->route_instance = route_instance;

if (IS_ZEBRA_DEBUG_RIB_DETAILED)
zlog_debug("Early Label Handling for %pFX", prefix);

mq_add_handler(w, early_label_meta_queue_add);
}

void mpls_zapi_labels_process(bool add_p, struct zebra_vrf *zvrf,
const struct zapi_labels *zl)
{
struct wq_label_wrapper *w;

w = XCALLOC(MTYPE_WQ_WRAPPER, sizeof(struct wq_label_wrapper));
w->type = WQ_LABEL_LABELS_PROCESS;
w->vrf_id = zvrf->vrf->vrf_id;
w->add_p = add_p;
w->zl = *zl;

if (IS_ZEBRA_DEBUG_RIB_DETAILED)
zlog_debug("Early Label Handling: Labels Process");

mq_add_handler(w, early_label_meta_queue_add);
}

/* Add route_node to work queue and schedule processing */
int rib_queue_add(struct route_node *rn)
{
Expand Down Expand Up @@ -3034,6 +3132,29 @@ static void nhg_meta_queue_free(struct meta_queue *mq, struct list *l,
}
}

static void early_label_meta_queue_free(struct meta_queue *mq, struct list *l,
struct zebra_vrf *zvrf)
{
struct wq_label_wrapper *w;
struct listnode *node, *nnode;

for (ALL_LIST_ELEMENTS(l, node, nnode, w)) {
if (zvrf && zvrf->vrf->vrf_id != w->vrf_id)
continue;

switch (w->type) {
case WQ_LABEL_FTN_UNINSTALL:
case WQ_LABEL_LABELS_PROCESS:
break;
}

node->data = NULL;
XFREE(MTYPE_WQ_WRAPPER, w);
list_delete_node(l, node);
mq->size--;
}
}

static void rib_meta_queue_free(struct meta_queue *mq, struct list *l,
struct zebra_vrf *zvrf)
{
Expand Down Expand Up @@ -3067,6 +3188,9 @@ void meta_queue_free(struct meta_queue *mq, struct zebra_vrf *zvrf)
case META_QUEUE_EVPN:
evpn_meta_queue_free(mq, mq->subq[i], zvrf);
break;
case META_QUEUE_EARLY_LABEL:
early_label_meta_queue_free(mq, mq->subq[i], zvrf);
break;
case META_QUEUE_CONNECTED:
case META_QUEUE_KERNEL:
case META_QUEUE_STATIC:
Expand Down

0 comments on commit 53216df

Please sign in to comment.