Signed-off-by: Anders Selhammer <anders.selham...@est.tech> --- bmc.c | 78 ++++++++++++++++++++++++++++++++++++++++++++----------------------- bmc.h | 3 ++- 2 files changed, 53 insertions(+), 28 deletions(-)
diff --git a/bmc.c b/bmc.c index 3c3db82..857d22c 100644 --- a/bmc.c +++ b/bmc.c @@ -26,45 +26,55 @@ int dscmp2(struct dataset *a, struct dataset *b) int diff; unsigned int A = a->stepsRemoved, B = b->stepsRemoved; - if (A + 1 < B) + if (A + 1 < B) { return A_BETTER; - if (B + 1 < A) + } + if (B + 1 < A) { return B_BETTER; + } /* * We ignore the "error-1" conditions mentioned in the * standard, since there is nothing we can do about it anyway. */ if (A < B) { diff = memcmp(&b->receiver, &b->sender, sizeof(b->receiver)); - if (diff < 0) + if (diff < 0) { return A_BETTER; - if (diff > 0) + } + 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) + if (diff < 0) { return B_BETTER; - if (diff > 0) + } + if (diff > 0) { return B_BETTER_TOPO; + } /* error-1 */ return 0; } diff = memcmp(&a->sender, &b->sender, sizeof(a->sender)); - if (diff < 0) + if (diff < 0) { return A_BETTER_TOPO; - if (diff > 0) + } + if (diff > 0) { return B_BETTER_TOPO; + } - if (a->receiver.portNumber < b->receiver.portNumber) + if (a->receiver.portNumber < b->receiver.portNumber) { return A_BETTER_TOPO; - if (a->receiver.portNumber > b->receiver.portNumber) + } + if (a->receiver.portNumber > b->receiver.portNumber) { return B_BETTER_TOPO; + } /* - * If we got this far, it means "error-2" has occured. + * If we got this far, it means "error-2" has occurred. */ return 0; } @@ -73,44 +83,57 @@ int dscmp(struct dataset *a, struct dataset *b) { int diff; - if (a == b) + if (a == b) { return 0; - if (a && !b) + } + if (a && !b) { return A_BETTER; - if (b && !a) + } + if (b && !a) { return B_BETTER; + } diff = memcmp(&a->identity, &b->identity, sizeof(a->identity)); - - if (!diff) + if (!diff) { return dscmp2(a, b); + } - if (a->priority1 < b->priority1) + if (a->priority1 < b->priority1) { return A_BETTER; - if (a->priority1 > b->priority1) + } + if (a->priority1 > b->priority1) { return B_BETTER; + } - if (a->quality.clockClass < b->quality.clockClass) + if (a->quality.clockClass < b->quality.clockClass) { return A_BETTER; - if (a->quality.clockClass > b->quality.clockClass) + } + if (a->quality.clockClass > b->quality.clockClass) { return B_BETTER; + } - if (a->quality.clockAccuracy < b->quality.clockAccuracy) + if (a->quality.clockAccuracy < b->quality.clockAccuracy) { return A_BETTER; - if (a->quality.clockAccuracy > b->quality.clockAccuracy) + } + if (a->quality.clockAccuracy > b->quality.clockAccuracy) { return B_BETTER; + } if (a->quality.offsetScaledLogVariance < - b->quality.offsetScaledLogVariance) + b->quality.offsetScaledLogVariance) { return A_BETTER; + } if (a->quality.offsetScaledLogVariance > - b->quality.offsetScaledLogVariance) + b->quality.offsetScaledLogVariance) { return B_BETTER; + } - if (a->priority2 < b->priority2) + if (a->priority2 < b->priority2) { return A_BETTER; - if (a->priority2 > b->priority2) + } + if (a->priority2 > b->priority2) { return B_BETTER; + } return diff < 0 ? A_BETTER : B_BETTER; } @@ -126,8 +149,9 @@ enum port_state bmc_state_decision(struct clock *c, struct port *r, port_best = port_best_foreign(r); ps = port_state(r); - if (!port_best && PS_LISTENING == ps) + if (!port_best && PS_LISTENING == ps) { return ps; + } if (clock_class(c) <= 127) { if (compare(clock_ds, port_best) > 0) { diff --git a/bmc.h b/bmc.h index 30fd443..e2fbf3b 100644 --- a/bmc.h +++ b/bmc.h @@ -37,7 +37,8 @@ * @return A @ref port_state value as the recommended state. */ enum port_state bmc_state_decision(struct clock *c, struct port *r, - int (*comapre)(struct dataset *a, struct dataset *b)); + int (*compare)(struct dataset *a, + struct dataset *b)); /** * Compare two data sets using the algorithm defined in IEEE 1588. -- 1.8.3.1 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel