Signed-off-by: Anders Selhammer <anders.selham...@est.tech>
---
 bmc.c | 48 +++++++++++++++++++++++++++++++++++++++---------
 bmc.h | 15 +++++++++++++++
 2 files changed, 54 insertions(+), 9 deletions(-)

diff --git a/bmc.c b/bmc.c
index d346397..a86148d 100644
--- a/bmc.c
+++ b/bmc.c
@@ -81,7 +81,7 @@ int dscmp2(struct dataset *a, struct dataset *b)
        return 0;
 }
 
-int dscmp_ieee1588(struct dataset *a, struct dataset *b)
+static int dscmp(struct dataset *a, struct dataset *b, enum bmca_type type)
 {
        int diff;
 
@@ -96,15 +96,18 @@ int dscmp_ieee1588(struct dataset *a, struct dataset *b)
        }
 
        diff = memcmp(&a->identity, &b->identity, sizeof(a->identity));
-       if (!diff) {
-               return dscmp2(a, b);
-       }
 
-       if (a->priority1 < b->priority1) {
-               return A_BETTER;
-       }
-       if (a->priority1 > b->priority1) {
-               return B_BETTER;
+       if (IEEE1588_BMCA == type) {
+               if (!diff) {
+                       return dscmp2(a, b);
+               }
+
+               if (a->priority1 < b->priority1) {
+                       return A_BETTER;
+               }
+               if (a->priority1 > b->priority1) {
+                       return B_BETTER;
+               }
        }
 
        if (a->quality.clockClass < b->quality.clockClass) {
@@ -137,9 +140,36 @@ int dscmp_ieee1588(struct dataset *a, struct dataset *b)
                return B_BETTER;
        }
 
+       if (ALTERNATE_BMCA == type) {
+               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);
+               }
+
+               if (!diff) {
+                       return dscmp2(a, b);
+               }
+       }
+
        return diff < 0 ? A_BETTER : B_BETTER;
 }
 
+int dscmp_ieee1588(struct dataset *a, struct dataset *b)
+{
+       return dscmp(a, b, IEEE1588_BMCA);
+}
+
+int dscmp_alternate(struct dataset *a, struct dataset *b)
+{
+       return dscmp(a, b, ALTERNATE_BMCA);
+}
+
 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..96b7b88 100644
--- a/bmc.h
+++ b/bmc.h
@@ -32,6 +32,11 @@ typedef int (*dscmp_type)(struct dataset*, struct dataset*);
 struct clock; /*forward declaration*/
 struct port; /*forward declaration*/
 
+enum bmca_type {
+       IEEE1588_BMCA,
+       ALTERNATE_BMCA,
+};
+
 /**
  * BMC state decision algorithm.
  * @param c  The local clock.
@@ -54,6 +59,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_alternate(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