Skip to content

Commit

Permalink
pbrd: convert pbr_send_pbr_map to use pbrms
Browse files Browse the repository at this point in the history
Signed-off-by: Don Slice <dslice@cumulusnetworks.com>
  • Loading branch information
dslicenc authored and donaldsharp committed Mar 15, 2018
1 parent 225584d commit 763ddb7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 50 deletions.
38 changes: 17 additions & 21 deletions pbrd/pbr_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,21 +176,13 @@ extern void pbr_map_delete(const char *name, uint32_t seqno)
struct pbr_map *pbrm;
struct pbr_map_sequence *pbrms;
struct listnode *node, *nnode;
bool uninstall = false;

pbrm = pbrm_find(name);

for (ALL_LIST_ELEMENTS(pbrm->seqnumbers, node, nnode, pbrms)) {
if (pbrms->reason & PBR_MAP_DEL_SEQUENCE_NUMBER) {
uninstall = true;
break;
}
}

if (uninstall)
pbr_send_pbr_map(pbrm, 0);
if (pbrms->reason & PBR_MAP_DEL_SEQUENCE_NUMBER)
pbr_send_pbr_map(pbrms, 0);

for (ALL_LIST_ELEMENTS(pbrm->seqnumbers, node, nnode, pbrms)) {
if (!(pbrms->reason & PBR_MAP_DEL_SEQUENCE_NUMBER))
continue;

Expand Down Expand Up @@ -410,26 +402,22 @@ void pbr_map_policy_install(const char *name)
struct pbr_map_sequence *pbrms;
struct pbr_map *pbrm;
struct listnode *node;
bool install;

DEBUGD(&pbr_dbg_map, "%s: for %s", __PRETTY_FUNCTION__, name);
pbrm = pbrm_find(name);
if (!pbrm)
return;

install = true;
for (ALL_LIST_ELEMENTS_RO(pbrm->seqnumbers, node, pbrms)) {
DEBUGD(&pbr_dbg_map,
"%s: Looking at what to install %s(%u) %d %d",
__PRETTY_FUNCTION__, name, pbrms->seqno, pbrm->valid,
pbrms->nhs_installed);
if (!pbrm->valid || !pbrms->nhs_installed)
install = false;
}

if (install && pbrm->incoming->count) {
DEBUGD(&pbr_dbg_map, "\tInstalling");
pbr_send_pbr_map(pbrm, true);
if (pbrm->valid && pbrms->nhs_installed && pbrm->incoming->count) {
DEBUGD(&pbr_dbg_map, "\tInstalling");
pbr_send_pbr_map(pbrms, true);
}
}
}

Expand All @@ -438,6 +426,7 @@ void pbr_map_policy_delete(const char *ifname)
struct listnode *node, *nnode;
struct pbr_map_interface *pmi;
struct pbr_map *pbrm;
struct pbr_map_sequence *pbrms;

RB_FOREACH (pbrm, pbr_map_entry_head, &pbr_maps) {
for (ALL_LIST_ELEMENTS(pbrm->incoming, node, nnode, pmi)) {
Expand All @@ -446,7 +435,9 @@ void pbr_map_policy_delete(const char *ifname)
if (strcmp(ifname, pmi->ifp->name) != 0)
continue;

pbr_send_pbr_map(pbrm, false);
for (ALL_LIST_ELEMENTS_RO(pbrm->seqnumbers, node, pbrms))
pbr_send_pbr_map(pbrms, false);

listnode_delete(pbrm->incoming, pmi);
pmi->pbrm = NULL;
XFREE(MTYPE_PBR_MAP_INTERFACE, pmi);
Expand Down Expand Up @@ -544,16 +535,21 @@ void pbr_map_check(struct pbr_map_sequence *pbrms)
"%s: Removing %s(%u) reason: %" PRIu64,
__PRETTY_FUNCTION__, pbrm->name,
pbrms->seqno, pbrms->reason);
pbr_send_pbr_map(pbrm, false);
pbr_send_pbr_map(pbrms, false);
}
}

void pbr_map_install(struct pbr_map *pbrm)
{
struct listnode *node;
struct pbr_map_sequence *pbrms;

if (!pbrm->incoming->count)
return;

pbr_send_pbr_map(pbrm, true);
for (ALL_LIST_ELEMENTS_RO(pbrm->seqnumbers, node, pbrms))
pbr_send_pbr_map(pbrms, true);

pbrm->installed = true;
}

Expand Down
48 changes: 20 additions & 28 deletions pbrd/pbr_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,13 +504,14 @@ static void pbr_encode_pbr_map_sequence(struct stream *s,
stream_putl(s, ifp->ifindex);
}

void pbr_send_pbr_map(struct pbr_map *pbrm, bool install)
void pbr_send_pbr_map(struct pbr_map_sequence *pbrms, bool install)
{
struct listnode *inode, *snode;
struct pbr_map_sequence *pbrms;
struct pbr_map *pbrm = pbrms->parent;
struct pbr_map_interface *pmi;
struct stream *s;
uint32_t total;
bool encode = true;
ssize_t tspot;

DEBUGD(&pbr_dbg_zebra, "%s: for %s %d", __PRETTY_FUNCTION__, pbrm->name,
Expand All @@ -533,38 +534,29 @@ void pbr_send_pbr_map(struct pbr_map *pbrm, bool install)
pbrm->name, install, pmi->ifp->name, pmi->delete);

if (!install && pmi->delete) {
for (ALL_LIST_ELEMENTS_RO(pbrm->seqnumbers, snode,
pbrms)) {
pbr_encode_pbr_map_sequence(s,
pbrms, pmi->ifp);
total++;
}
continue;
pbr_encode_pbr_map_sequence(s, pbrms, pmi->ifp);
total++;
}

for (ALL_LIST_ELEMENTS_RO(pbrm->seqnumbers, snode, pbrms)) {

DEBUGD(&pbr_dbg_zebra, "%s: \tSeqno: %u %" PRIu64 " valid %u",
__PRETTY_FUNCTION__, pbrms->seqno, pbrms->reason,
pbrm->valid);
DEBUGD(&pbr_dbg_zebra, "%s: \tSeqno: %u %" PRIu64 " valid %u",
__PRETTY_FUNCTION__, pbrms->seqno, pbrms->reason,
pbrm->valid);

if (!install &&
!(pbrms->reason & PBR_MAP_DEL_SEQUENCE_NUMBER))
continue;
if (!install &&
!(pbrms->reason & PBR_MAP_DEL_SEQUENCE_NUMBER))
encode = false;
if (!install && !pbrms->installed)
encode = false;

if (!install && !pbrms->installed)
continue;
if (install && pbrms->installed)
encode = false;

if (install && pbrms->installed)
continue;
DEBUGD(&pbr_dbg_zebra, "%s: \t Seq: %u ifp %s",
__PRETTY_FUNCTION__, pbrms->seqno,
pmi->ifp->name);

DEBUGD(&pbr_dbg_zebra, "%s: \t Seq: %u ifp %s",
__PRETTY_FUNCTION__, pbrms->seqno,
pmi->ifp->name);

pbr_encode_pbr_map_sequence(s, pbrms, pmi->ifp);
total++;
}
pbr_encode_pbr_map_sequence(s, pbrms, pmi->ifp);
total++;
}

DEBUGD(&pbr_dbg_zebra, "%s: Putting %u at %zu ", __PRETTY_FUNCTION__,
Expand Down
2 changes: 1 addition & 1 deletion pbrd/pbr_zebra.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ extern void route_delete(struct pbr_nexthop_group_cache *pnhgc,

extern void pbr_send_rnh(struct nexthop *nhop, bool reg);

extern void pbr_send_pbr_map(struct pbr_map *pbrm, bool install);
extern void pbr_send_pbr_map(struct pbr_map_sequence *pbrms, bool install);
#endif

0 comments on commit 763ddb7

Please sign in to comment.