Skip to content

Commit

Permalink
Fix the BMC state decision algorithm.
Browse files Browse the repository at this point in the history
We failed to make the distinction between plain old "better" and
"better by topology," but the BMC algorithm really counts on this.

Signed-off-by: Richard Cochran <[email protected]>
  • Loading branch information
richardcochran committed Jan 7, 2012
1 parent 807ec32 commit c2fad7b
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions bmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
#include "bmc.h"
#include "ds.h"

#define A_BETTER 1
#define B_BETTER -1
#define A_BETTER_TOPO 2
#define A_BETTER 1
#define B_BETTER -1
#define B_BETTER_TOPO -2

static int dscmp2(struct dataset *a, struct dataset *b)
{
Expand All @@ -37,21 +39,35 @@ static int dscmp2(struct dataset *a, struct dataset *b)
* We ignore the "error-1" conditions mentioned in the
* standard, since there is nothing we can do about it anyway.
*/
if (A < B)
return A_BETTER;
if (A > B)
return B_BETTER;
if (A < B) {
diff = memcmp(&b->receiver, &b->sender, sizeof(b->receiver));
if (diff < 0)
return A_BETTER;
if (diff > 0)
return A_BETTER_TOPO;
/* error-1 */
return 0;
}
if (A > B) {
diff = memcmp(&a->receiver, &a->sender, sizeof(a->receiver));
if (diff < 0)
return B_BETTER;
if (diff > 0)
return B_BETTER_TOPO;
/* error-1 */
return 0;
}

diff = memcmp(&a->sender, &b->sender, sizeof(a->sender));
if (diff < 0)
return A_BETTER;
return A_BETTER_TOPO;
if (diff > 0)
return B_BETTER;
return B_BETTER_TOPO;

if (a->receiver.portNumber < b->receiver.portNumber)
return A_BETTER;
return A_BETTER_TOPO;
if (a->receiver.portNumber > b->receiver.portNumber)
return B_BETTER;
return B_BETTER_TOPO;
/*
* If we got this far, it means "error-2" has occured.
*/
Expand Down Expand Up @@ -136,7 +152,7 @@ enum port_state bmc_state_decision(struct clock *c, struct port *r)
return PS_SLAVE; /*S1*/
}

if (dscmp(clock_best, port_best) > 0) {
if (dscmp(clock_best, port_best) == A_BETTER_TOPO) {
return PS_PASSIVE; /*P2*/
} else {
return PS_MASTER; /*M3*/
Expand Down

0 comments on commit c2fad7b

Please sign in to comment.