Signed-off-by: Anders Selhammer <anders.selham...@est.tech>
---
 bmc.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 bmc.h | 10 ++++++++++
 2 files changed, 73 insertions(+)

diff --git a/bmc.c b/bmc.c
index fd80f99..7a8bca1 100644
--- a/bmc.c
+++ b/bmc.c
@@ -139,6 +139,69 @@ int dscmp_ieee1588(struct dataset *a, struct dataset *b)
        return diff < 0 ? A_BETTER : B_BETTER;
 }
 
+int dscmp_G8275(struct dataset *a, struct dataset *b)
+{
+       int diff;
+
+       if (a == b) {
+               return 0;
+       }
+       if (a && !b) {
+               return A_BETTER;
+       }
+       if (b && !a) {
+               return B_BETTER;
+       }
+
+       if (a->quality.clockClass < b->quality.clockClass) {
+               return A_BETTER;
+       }
+       if (a->quality.clockClass > b->quality.clockClass) {
+               return B_BETTER;
+       }
+
+       if (a->quality.clockAccuracy < b->quality.clockAccuracy) {
+               return A_BETTER;
+       }
+       if (a->quality.clockAccuracy > b->quality.clockAccuracy) {
+               return B_BETTER;
+       }
+
+       if (a->quality.offsetScaledLogVariance <
+           b->quality.offsetScaledLogVariance) {
+               return A_BETTER;
+       }
+       if (a->quality.offsetScaledLogVariance >
+           b->quality.offsetScaledLogVariance) {
+               return B_BETTER;
+       }
+
+       if (a->priority2 < b->priority2) {
+               return A_BETTER;
+       }
+       if (a->priority2 > b->priority2) {
+               return B_BETTER;
+       }
+
+       if (a->localPriority < b->localPriority) {
+               return A_BETTER;
+       }
+       if (a->localPriority > b->localPriority) {
+               return B_BETTER;
+       }
+
+       if (a->quality.clockClass <= 127) {
+               return dscmp2(a, b);
+       }
+
+       diff = memcmp(&a->identity, &b->identity, sizeof(a->identity));
+       if (!diff) {
+               return dscmp2(a, b);
+       }
+
+       return diff < 0 ? A_BETTER : B_BETTER;
+}
+
 enum port_state bmc_state_decision(struct clock *c, struct port *r,
                                   int (*compare)(struct dataset *a, struct 
dataset *b))
 {
diff --git a/bmc.h b/bmc.h
index d09a605..b8f3561 100644
--- a/bmc.h
+++ b/bmc.h
@@ -54,6 +54,16 @@ enum port_state bmc_state_decision(struct clock *c, struct 
port *r,
 int dscmp_ieee1588(struct dataset *a, struct dataset *b);
 
 /**
+ * Compare two data sets using the algorithm defined in ITU-T G.8275.1.
+ * @param a A dataset to compare.
+ * @param b A dataset to compare.
+ * @return An integer less than, equal to, or greater than zero
+ *         if the dataset @a a is found, respectively, to be
+ *         less than, to match, or be greater than @a b.
+ */
+int dscmp_G8275(struct dataset *a, struct dataset *b);
+
+/**
  * Second part of the data set comparison algorithm, not for general
  * public use.
  */
-- 
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

Reply via email to