[Linuxptp-devel] [v2] lstab: update expiration to 28 December 2021

2021-07-26 Thread Yangbo Lu
Bring the built in leap second table up to date through IERS Bulletin C62.
No new leap seconds have been scheduled for this year.

Signed-off-by: Yangbo Lu 
---
Changes for v2:
- Corrected to "C62" in commit message.
---
 lstab.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lstab.c b/lstab.c
index e6e7ad2..3bd920e 100644
--- a/lstab.c
+++ b/lstab.c
@@ -48,7 +48,7 @@ struct lstab {
int length;
 };
 
-static const uint64_t expiration_date_ntp = 3833827200ULL; /* 28 June 2021 */
+static const uint64_t expiration_date_ntp = 3849638400ULL; /* 28 December 2021 
*/
 
 static const uint64_t offset_table[N_LEAPS * 2] = {
2272060800ULL,  10, /* 1 Jan 1972 */
-- 
2.25.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH] lstab: update expiration to 28 December 2021

2021-06-28 Thread Yangbo Lu
Bring the built in leap second table up to date through IERS Bulletin C59.
No new leap seconds have been scheduled for this year.

Signed-off-by: Yangbo Lu 
---
 lstab.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lstab.c b/lstab.c
index e6e7ad2..3bd920e 100644
--- a/lstab.c
+++ b/lstab.c
@@ -48,7 +48,7 @@ struct lstab {
int length;
 };
 
-static const uint64_t expiration_date_ntp = 3833827200ULL; /* 28 June 2021 */
+static const uint64_t expiration_date_ntp = 3849638400ULL; /* 28 December 2021 
*/
 
 static const uint64_t offset_table[N_LEAPS * 2] = {
2272060800ULL,  10, /* 1 Jan 1972 */
-- 
2.25.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [v4] Bump to IEEE 1588-2019 version

2021-03-01 Thread Yangbo Lu
IEEE 1588-2019 specified new UInteger4 type minorVersionPTP field
in header, and minorVersionNumber data in portDS. It has the value
1 for IEEE 1588-2019, and has the value 0 for IEEE 1588-2008.
However missing minorVersionNumber definition in PORT_DATA_SET and
VERSION_NUMBER management TLVs was an oversight in this standard.

This patch is to bump to IEEE 1588-2019 version directly in message,
considering v2.1 and even future v2.x are all backward compatible.
For PORT_DATA_SET and VERSION_NUMBER TLVs, keep using only
versionNumber (major version) per current active IEEE 1588-2019
standard regardless.

Signed-off-by: Yangbo Lu 
---
Changes for v2:
- Made v2.1 as macros.
Changes for v3:
- Fixed pmc versionNumber printing issue.
Changes for v4:
- kept using only major version in TLVs per 2019 standard.
---
 msg.c  | 5 +
 msg.h  | 9 +++--
 pmc.c  | 7 ---
 port.c | 2 +-
 port_private.h | 2 +-
 5 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/msg.c b/msg.c
index d1619d4..c4516ad 100644
--- a/msg.c
+++ b/msg.c
@@ -27,9 +27,6 @@
 #include "print.h"
 #include "tlv.h"
 
-#define VERSION_MASK 0x0f
-#define VERSION  0x02
-
 int assume_two_step = 0;
 
 /*
@@ -80,7 +77,7 @@ static void announce_post_recv(struct announce_msg *m)
 
 static int hdr_post_recv(struct ptp_header *m)
 {
-   if ((m->ver & VERSION_MASK) != VERSION)
+   if ((m->ver & MAJOR_VERSION_MASK) != PTP_MAJOR_VERSION)
return -EPROTO;
m->messageLength = ntohs(m->messageLength);
m->correction = net2host64(m->correction);
diff --git a/msg.h b/msg.h
index a71df16..b7423ee 100644
--- a/msg.h
+++ b/msg.h
@@ -30,7 +30,12 @@
 #include "tlv.h"
 #include "tmv.h"
 
-#define PTP_VERSION 2
+/* Version definition for IEEE 1588-2019 */
+#define PTP_MAJOR_VERSION  2
+#define PTP_MINOR_VERSION  1
+#define PTP_VERSION(PTP_MINOR_VERSION << 4 | PTP_MAJOR_VERSION)
+
+#define MAJOR_VERSION_MASK 0x0f
 
 /* Values for the messageType field */
 #define SYNC  0x0
@@ -89,7 +94,7 @@ enum controlField {
 
 struct ptp_header {
uint8_t tsmt; /* transportSpecific | messageType */
-   uint8_t ver;  /* reserved  | versionPTP  */
+   uint8_t ver;  /* minorVersionPTP   | versionPTP  */
UInteger16  messageLength;
UInteger8   domainNumber;
Octet   reserved1;
diff --git a/pmc.c b/pmc.c
index 3678800..1e569b5 100644
--- a/pmc.c
+++ b/pmc.c
@@ -413,12 +413,13 @@ static void pmc_show(struct ptp_message *msg, FILE *fp)
IFMT "logSyncInterval %hhd"
IFMT "delayMechanism  %hhu"
IFMT "logMinPdelayReqInterval %hhd"
-   IFMT "versionNumber   %hhu",
+   IFMT "versionNumber   %u",
pid2str(>portIdentity), ps_str[p->portState],
p->logMinDelayReqInterval, p->peerMeanPathDelay >> 16,
p->logAnnounceInterval, p->announceReceiptTimeout,
p->logSyncInterval, p->delayMechanism,
-   p->logMinPdelayReqInterval, p->versionNumber);
+   p->logMinPdelayReqInterval,
+   p->versionNumber & MAJOR_VERSION_MASK);
break;
case TLV_PORT_DATA_SET_NP:
pnp = (struct port_ds_np *) mgt->data;
@@ -507,7 +508,7 @@ static void pmc_show(struct ptp_message *msg, FILE *fp)
case TLV_VERSION_NUMBER:
mtd = (struct management_tlv_datum *) mgt->data;
fprintf(fp, "VERSION_NUMBER "
-   IFMT "versionNumber %hhu", mtd->val);
+   IFMT "versionNumber %hhu", mtd->val & 
MAJOR_VERSION_MASK);
break;
case TLV_DELAY_MECHANISM:
mtd = (struct management_tlv_datum *) mgt->data;
diff --git a/port.c b/port.c
index eb3b319..25479a1 100644
--- a/port.c
+++ b/port.c
@@ -3132,7 +3132,7 @@ struct port *port_open(const char *phc_device,
p->portIdentity.portNumber = number;
p->state = PS_INITIALIZING;
p->delayMechanism = config_get_int(cfg, p->name, "delay_mechanism");
-   p->versionNumber = PTP_VERSION;
+   p->versionNumber = PTP_MAJOR_VERSION;
p->slave_event_monitor = clock_slave_monitor(clock);
 
if (!port_is_uds(p) && unicast_client_initialize(p)) {
diff --git a/port_private.h b/port_private.h
index 842ee06..2a98ef4 100644
--- a/port_private.h
+++ b/port_private.h
@@ -142,7 +142,7 @@ struct port {
enum link_state link_status

[Linuxptp-devel] [v3] Bump to IEEE 1588-2019 version

2021-02-28 Thread Yangbo Lu
IEEE 1588-2019 specified new UInteger4 type minorVersionPTP field
in header, and minorVersionNumber data in portDS. It has the value
1 for IEEE 1588-2019, and has the value 0 for IEEE 1588-2008.

This patch is to bump to IEEE 1588-2019 version directly in message,
considering v2.1 and even future v2.x are all backward compatible.

Signed-off-by: Yangbo Lu 
---
 msg.c | 5 +
 msg.h | 9 +++--
 pmc.c | 6 --
 3 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/msg.c b/msg.c
index d1619d4..c4516ad 100644
--- a/msg.c
+++ b/msg.c
@@ -27,9 +27,6 @@
 #include "print.h"
 #include "tlv.h"
 
-#define VERSION_MASK 0x0f
-#define VERSION  0x02
-
 int assume_two_step = 0;
 
 /*
@@ -80,7 +77,7 @@ static void announce_post_recv(struct announce_msg *m)
 
 static int hdr_post_recv(struct ptp_header *m)
 {
-   if ((m->ver & VERSION_MASK) != VERSION)
+   if ((m->ver & MAJOR_VERSION_MASK) != PTP_MAJOR_VERSION)
return -EPROTO;
m->messageLength = ntohs(m->messageLength);
m->correction = net2host64(m->correction);
diff --git a/msg.h b/msg.h
index a71df16..b7423ee 100644
--- a/msg.h
+++ b/msg.h
@@ -30,7 +30,12 @@
 #include "tlv.h"
 #include "tmv.h"
 
-#define PTP_VERSION 2
+/* Version definition for IEEE 1588-2019 */
+#define PTP_MAJOR_VERSION  2
+#define PTP_MINOR_VERSION  1
+#define PTP_VERSION(PTP_MINOR_VERSION << 4 | PTP_MAJOR_VERSION)
+
+#define MAJOR_VERSION_MASK 0x0f
 
 /* Values for the messageType field */
 #define SYNC  0x0
@@ -89,7 +94,7 @@ enum controlField {
 
 struct ptp_header {
uint8_t tsmt; /* transportSpecific | messageType */
-   uint8_t ver;  /* reserved  | versionPTP  */
+   uint8_t ver;  /* minorVersionPTP   | versionPTP  */
UInteger16  messageLength;
UInteger8   domainNumber;
Octet   reserved1;
diff --git a/pmc.c b/pmc.c
index 3678800..ea2af3f 100644
--- a/pmc.c
+++ b/pmc.c
@@ -413,12 +413,14 @@ static void pmc_show(struct ptp_message *msg, FILE *fp)
IFMT "logSyncInterval %hhd"
IFMT "delayMechanism  %hhu"
IFMT "logMinPdelayReqInterval %hhd"
-   IFMT "versionNumber   %hhu",
+   IFMT "versionNumber   %u.%u",
pid2str(>portIdentity), ps_str[p->portState],
p->logMinDelayReqInterval, p->peerMeanPathDelay >> 16,
p->logAnnounceInterval, p->announceReceiptTimeout,
p->logSyncInterval, p->delayMechanism,
-   p->logMinPdelayReqInterval, p->versionNumber);
+   p->logMinPdelayReqInterval,
+   p->versionNumber & MAJOR_VERSION_MASK,
+   p->versionNumber >> 4);
break;
case TLV_PORT_DATA_SET_NP:
pnp = (struct port_ds_np *) mgt->data;
-- 
2.25.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [v2] msg: bump to IEEE 1588-2019 version

2021-02-24 Thread Yangbo Lu
IEEE 1588-2019 specified new UInteger4 type minorVersionPTP field
in header, and minorVersionNumber data in portDS. It has the value
1 for IEEE 1588-2019, and has the value 0 for IEEE 1588-2008.

This patch is to bump to IEEE 1588-2019 version directly in message,
considering v2.1 and even future v2.x are all backward compatible.

Signed-off-by: Yangbo Lu 
---
Changes for v2:
- Made v2.1 as macros.
---
 msg.c | 5 +
 msg.h | 9 +++--
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/msg.c b/msg.c
index d1619d4..c4516ad 100644
--- a/msg.c
+++ b/msg.c
@@ -27,9 +27,6 @@
 #include "print.h"
 #include "tlv.h"
 
-#define VERSION_MASK 0x0f
-#define VERSION  0x02
-
 int assume_two_step = 0;
 
 /*
@@ -80,7 +77,7 @@ static void announce_post_recv(struct announce_msg *m)
 
 static int hdr_post_recv(struct ptp_header *m)
 {
-   if ((m->ver & VERSION_MASK) != VERSION)
+   if ((m->ver & MAJOR_VERSION_MASK) != PTP_MAJOR_VERSION)
return -EPROTO;
m->messageLength = ntohs(m->messageLength);
m->correction = net2host64(m->correction);
diff --git a/msg.h b/msg.h
index a71df16..b7423ee 100644
--- a/msg.h
+++ b/msg.h
@@ -30,7 +30,12 @@
 #include "tlv.h"
 #include "tmv.h"
 
-#define PTP_VERSION 2
+/* Version definition for IEEE 1588-2019 */
+#define PTP_MAJOR_VERSION  2
+#define PTP_MINOR_VERSION  1
+#define PTP_VERSION(PTP_MINOR_VERSION << 4 | PTP_MAJOR_VERSION)
+
+#define MAJOR_VERSION_MASK 0x0f
 
 /* Values for the messageType field */
 #define SYNC  0x0
@@ -89,7 +94,7 @@ enum controlField {
 
 struct ptp_header {
uint8_t tsmt; /* transportSpecific | messageType */
-   uint8_t ver;  /* reserved  | versionPTP  */
+   uint8_t ver;  /* minorVersionPTP   | versionPTP  */
UInteger16  messageLength;
UInteger8   domainNumber;
Octet   reserved1;
-- 
2.25.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH] ptp4l: version preparation for IEEE 1588-2019

2021-02-19 Thread Yangbo Lu
IEEE 1588-2019 specified new UInteger4 type minorVersionPTP field in header,
and minorVersionNumber data in portDS. It has the value 1 for IEEE 1588-2019,
and has the value 0 for IEEE 1588-2008.

This patch is to make versionNumber and minorVersionNumber configurable, rather
than using hard-coded IEEE 1588-2008 version, for PTP packets.
This is just preparation for future features support and profiles support based
on IEEE 1588-2019.

It seems IEEE 1588-2019 specified minorVersionNumber in portDS, but not in
PORT_DATA_SET management TLV data field. It's confusing. So this patch hasn't
added the minorVersionNumber in portDS making this as a TODO thing.

Signed-off-by: Yangbo Lu 
---
 config.c|  2 ++
 configs/default.cfg |  2 ++
 msg.c   |  5 +
 msg.h   |  5 +++--
 port.c  | 23 +--
 port_private.h  |  3 ++-
 port_signaling.c|  2 +-
 ptp4l.8 |  8 
 8 files changed, 32 insertions(+), 18 deletions(-)

diff --git a/config.c b/config.c
index 341f887..69cfb10 100644
--- a/config.c
+++ b/config.c
@@ -273,6 +273,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_STR("manufacturerIdentity", "00:00:00"),
GLOB_ITEM_INT("max_frequency", 9, 0, INT_MAX),
PORT_ITEM_INT("min_neighbor_prop_delay", -2000, INT_MIN, -1),
+   PORT_ITEM_INT("minorVersionNumber", 0, 0, 1),
PORT_ITEM_INT("msg_interval_request", 0, 0, 1),
PORT_ITEM_INT("neighborPropDelayThresh", 2000, 0, INT_MAX),
PORT_ITEM_INT("net_sync_monitor", 0, 0, 1),
@@ -332,6 +333,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_STR("userDescription", ""),
GLOB_ITEM_INT("utc_offset", CURRENT_UTC_OFFSET, 0, INT_MAX),
GLOB_ITEM_INT("verbose", 0, 0, 1),
+   PORT_ITEM_INT("versionNumber", 2, 2, 2),
GLOB_ITEM_INT("write_phase_mode", 0, 0, 1),
 };
 
diff --git a/configs/default.cfg b/configs/default.cfg
index 9604219..139ace0 100644
--- a/configs/default.cfg
+++ b/configs/default.cfg
@@ -40,6 +40,8 @@ BMCAptp
 inhibit_announce0
 inhibit_delay_req   0
 ignore_source_id0
+versionNumber   2
+minorVersionNumber  0
 #
 # Run time options
 #
diff --git a/msg.c b/msg.c
index d1619d4..a2f0567 100644
--- a/msg.c
+++ b/msg.c
@@ -27,9 +27,6 @@
 #include "print.h"
 #include "tlv.h"
 
-#define VERSION_MASK 0x0f
-#define VERSION  0x02
-
 int assume_two_step = 0;
 
 /*
@@ -80,7 +77,7 @@ static void announce_post_recv(struct announce_msg *m)
 
 static int hdr_post_recv(struct ptp_header *m)
 {
-   if ((m->ver & VERSION_MASK) != VERSION)
+   if ((m->ver & VERSION_MASK) != PTP_VERSION)
return -EPROTO;
m->messageLength = ntohs(m->messageLength);
m->correction = net2host64(m->correction);
diff --git a/msg.h b/msg.h
index a71df16..469f2ac 100644
--- a/msg.h
+++ b/msg.h
@@ -30,7 +30,8 @@
 #include "tlv.h"
 #include "tmv.h"
 
-#define PTP_VERSION 2
+#define PTP_VERSION2   /* This is major revision */
+#define VERSION_MASK   0x0f
 
 /* Values for the messageType field */
 #define SYNC  0x0
@@ -89,7 +90,7 @@ enum controlField {
 
 struct ptp_header {
uint8_t tsmt; /* transportSpecific | messageType */
-   uint8_t ver;  /* reserved  | versionPTP  */
+   uint8_t ver;  /* minorVersionPTP | versionPTP */
UInteger16  messageLength;
UInteger8   domainNumber;
Octet   reserved1;
diff --git a/port.c b/port.c
index 2bb974c..6423484 100644
--- a/port.c
+++ b/port.c
@@ -1353,7 +1353,7 @@ static int port_pdelay_request(struct port *p)
msg->hwts.type = p->timestamping;
 
msg->header.tsmt   = PDELAY_REQ | p->transportSpecific;
-   msg->header.ver= PTP_VERSION;
+   msg->header.ver= p->minorVersionNumber << 4 | 
p->versionNumber;
msg->header.messageLength  = sizeof(struct pdelay_req_msg);
msg->header.domainNumber   = clock_domain_number(p->clock);
msg->header.correction = -p->asymmetry;
@@ -1417,7 +1417,7 @@ int port_delay_request(struct port *p)
msg->hwts.type = p->timestamping;
 
msg->header.tsmt   = DELAY_REQ | p->transportSpecific;
-   msg->header.ver= PTP_VERSION;
+   msg->header.ver= p->minorVersionNumber << 4 | 
p->versionNumber;
msg->header.messageLength  = sizeof(struct delay_req_msg);
msg->header.domainNumber   = clock_domain_number(p->clock);
msg->header.correction

[Linuxptp-devel] [RFC V3, 2/4] Add BMCA support for IEEE 802.1AS-2011

2020-03-23 Thread Yangbo Lu
According to IEEE 802.1AS-2011, the BMCA used in gPTP is the same
as that used in IEEE 1588 with the following exceptions:

(1) Announce messages received on a slave port that were not sent
by the receiving time-aware system are used immediately,
i.e., there is no foreign-master qualification.

(2) A port that the BMCA determines should be a master port enters
the master state immediately, i.e., there is no pre-master state.

(3) The uncalibrated state is not needed and, therefore, not used.

(4) All time-aware systems are required to participate in best master
selection (even if it is not grandmaster capable).

This patch is to support (1) by using a specific FOREIGN_MASTER_THRESHOLD
case. (Treat FOREIGN_MASTER_THRESHOLD as 1.)
To support (2) and (3), reuse ptp_fsm and drop pre-master/uncalibrated
states. The (4) item is supported since IEEE 802.1AS reuses OC/BC.

Signed-off-by: Erik Hons 
Signed-off-by: Rodney Greenstreet 
Signed-off-by: Yangbo Lu 
---
Changes for v3:
- Added this patch.
---
 fsm.c  | 13 +
 fsm.h  | 10 ++
 port.c | 57 +++--
 3 files changed, 62 insertions(+), 18 deletions(-)

diff --git a/fsm.c b/fsm.c
index ce6efad..917dcae 100644
--- a/fsm.c
+++ b/fsm.c
@@ -335,3 +335,16 @@ enum port_state ptp_slave_fsm(enum port_state state, enum 
fsm_event event,
 
return next;
 }
+
+enum port_state ieee8021as_fsm(enum port_state state, enum fsm_event event,
+  int mdiff)
+{
+   enum port_state next = ptp_fsm(state, event, mdiff);
+
+   if (next == PS_UNCALIBRATED)
+   return PS_SLAVE;
+   if (next == PS_PRE_MASTER)
+   return PS_MASTER;
+
+   return next;
+}
diff --git a/fsm.h b/fsm.h
index 857af05..7f22dc1 100644
--- a/fsm.h
+++ b/fsm.h
@@ -79,4 +79,14 @@ enum port_state ptp_fsm(enum port_state state, enum 
fsm_event event, int mdiff);
 enum port_state ptp_slave_fsm(enum port_state state, enum fsm_event event,
  int mdiff);
 
+/**
+ * Run the state machine for a ieee8021as port.
+ * @param state  The current state of the port.
+ * @param event  The event to be processed.
+ * @param mdiff  Whether a new master has been selected.
+ * @return   The new state for the port.
+ */
+enum port_state ieee8021as_fsm(enum port_state state, enum fsm_event event,
+  int mdiff);
+
 #endif
diff --git a/port.c b/port.c
index 539fe3d..c625b01 100644
--- a/port.c
+++ b/port.c
@@ -278,12 +278,16 @@ void fc_clear(struct foreign_clock *fc)
 
 static void fc_prune(struct foreign_clock *fc)
 {
+   int threshold = FOREIGN_MASTER_THRESHOLD;
struct timespec now;
struct ptp_message *m;
 
clock_gettime(CLOCK_MONOTONIC, );
 
-   while (fc->n_messages > FOREIGN_MASTER_THRESHOLD) {
+   if (port_is_ieee8021as(fc->port))
+   threshold = 1;
+
+   while (fc->n_messages > threshold) {
m = TAILQ_LAST(>messages, messages);
TAILQ_REMOVE(>messages, m, list);
fc->n_messages--;
@@ -339,6 +343,7 @@ void ts_add(tmv_t *ts, Integer64 correction)
  */
 static int add_foreign_master(struct port *p, struct ptp_message *m)
 {
+   int threshold = FOREIGN_MASTER_THRESHOLD;
struct foreign_clock *fc;
struct ptp_message *tmp;
int broke_threshold = 0, diff = 0;
@@ -362,15 +367,20 @@ static int add_foreign_master(struct port *p, struct 
ptp_message *m)
LIST_INSERT_HEAD(>foreign_masters, fc, list);
fc->port = p;
fc->dataset.sender = m->header.sourcePortIdentity;
-   /* We do not count this first message, see 9.5.3(b) */
-   return 0;
+   /* For 1588, we do not count this first message, see 9.5.3(b) */
+   if (!port_is_ieee8021as(fc->port))
+   return 0;
}
 
/*
 * If this message breaks the threshold, that is an important change.
 */
fc_prune(fc);
-   if (FOREIGN_MASTER_THRESHOLD - 1 == fc->n_messages) {
+
+   if (port_is_ieee8021as(fc->port))
+   threshold = 1;
+
+   if (threshold - 1 == fc->n_messages) {
broke_threshold = 1;
}
 
@@ -2396,6 +2406,7 @@ void port_close(struct port *p)
 struct foreign_clock *port_compute_best(struct port *p)
 {
int (*dscmp)(struct dataset *a, struct dataset *b);
+   int threshold = FOREIGN_MASTER_THRESHOLD;
struct foreign_clock *fc;
struct ptp_message *tmp;
 
@@ -2414,7 +2425,10 @@ struct foreign_clock *port_compute_best(struct port *p)
 
fc_prune(fc);
 
-   if (fc->n_messages < FOREIGN_MASTER_THRESHOLD)
+   if (port_is_ieee8021as(fc->port))
+   threshold = 1;
+
+   if (fc->n_messages < threshold)
  

[Linuxptp-devel] [RFC V3, 3/4] port: drop erroneous neighbor rate ratio

2020-03-23 Thread Yangbo Lu
From: Rodney Greenstreet 

When a connected peer introduces a time discontinuities in between
consecutive peer-delay measurements (i.e. a jump in time in
consecutive PDelay response), an erroneous neighbor rate ratio is
calculated. This change disqualifies any neighbor rate ratio that
exceeds +/- 100 ppm, as required by IEEE 802.1AS-2011 Anex B.1.1.

This patch is to check and drop erroneous neighbor rate ratio to
ensure IEEE 802.1AS-2011 Anex B.1.1.

Signed-off-by: Rodney Greenstreet 
Signed-off-by: Yangbo Lu 
---
Changes for v3:
- Added this patch.
---
 port.c | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/port.c b/port.c
index c625b01..5c887b6 100644
--- a/port.c
+++ b/port.c
@@ -47,6 +47,7 @@
 
 #define ALLOWED_LOST_RESPONSES 3
 #define ANNOUNCE_SPAN 1
+#define MAX_NEIGHBOR_FREQ_OFFSET 0.0002
 
 enum syfu_event {
SYNC_MISMATCH,
@@ -1024,6 +1025,7 @@ static int port_management_set(struct port *target,
 static void port_nrate_calculate(struct port *p, tmv_t origin, tmv_t ingress)
 {
struct nrate_estimator *n = >nrate;
+   double ratio;
 
/*
 * We experienced a successful exchanges of peer delay request
@@ -1044,9 +1046,18 @@ static void port_nrate_calculate(struct port *p, tmv_t 
origin, tmv_t ingress)
pr_warning("bad timestamps in nrate calculation");
return;
}
-   n->ratio =
+
+   ratio =
tmv_dbl(tmv_sub(origin, n->origin1)) /
tmv_dbl(tmv_sub(ingress, n->ingress1));
+
+   if ((ratio <= (1.0 + MAX_NEIGHBOR_FREQ_OFFSET)) &&
+   (ratio >= (1.0 - MAX_NEIGHBOR_FREQ_OFFSET)))
+   n->ratio = ratio;
+   else
+   pr_debug("port %hu: drop erroneous nratio %lf, max offset %lf",
+portnum(p), ratio, MAX_NEIGHBOR_FREQ_OFFSET);
+
n->ingress1 = ingress;
n->origin1 = origin;
n->count = 0;
-- 
2.7.4



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [RFC V3, 4/4] clock: redecide state if get EV_FAULT_DETECTED event

2020-03-23 Thread Yangbo Lu
From: Rodney Greenstreet 

IEEE 802.1AS-2011's methodology for faults is to avoid waiting
in that FAULTY state in hopes that management will notice.
Instead, move on to search for a valid non-faulty state. If
supported, the fault is logged so that management can notice
later, but that logging isn't a requirement.

This patch is to invoke BMCA to redecide state if get
EV_FAULT_DETECTED event.

Signed-off-by: Rodney Greenstreet 
Signed-off-by: Yangbo Lu 
---
Changes for v3:
- Added this patch.
---
 clock.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clock.c b/clock.c
index 8a67499..22dbcf4 100644
--- a/clock.c
+++ b/clock.c
@@ -1527,6 +1527,9 @@ int clock_poll(struct clock *c)
if (EV_ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES == 
event) {
c->sde = 1;
}
+   if (EV_FAULT_DETECTED == event) {
+   c->sde = 1;
+   }
port_dispatch(p, event, 0);
/* Clear any fault after a little while. */
if (PS_FAULTY == port_state(p)) {
-- 
2.7.4



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [RFC V3, 1/4] Add IEEE 802.1AS-2011 time-aware bridge support

2020-03-23 Thread Yangbo Lu
This patch is to add IEEE 802.1AS-2011 time-aware bridge support
based on current BC clock type. It implements only time information
relay, and BMCA was not touched. To run it, the profile gPTP.cfg could
be used with multiple interfaces specified using -i option.

The main code changes are,
- Create syfu_relay_info structure for time information relay.
- Implement port_syfu_relay_info_insert() to update follow_up (with TLV)
  message with time information for relay.

Signed-off-by: Yangbo Lu 
---
Changes for v2:
- Implemented based on BC instead of TC.
Changes for v3:
- Rebased.
- Used port_is_ieee8021as() instead of p->follow_up_info.
---
 clock.c | 43 -
 clock.h | 45 +++
 port.c  | 75 +
 3 files changed, 158 insertions(+), 5 deletions(-)

diff --git a/clock.c b/clock.c
index 1668383..8a67499 100644
--- a/clock.c
+++ b/clock.c
@@ -45,7 +45,6 @@
 #include "util.h"
 
 #define N_CLOCK_PFD (N_POLLFD + 1) /* one extra per port, for the fault timer 
*/
-#define POW2_41 ((double)(1ULL << 41))
 
 struct interface {
STAILQ_ENTRY(interface) list;
@@ -127,6 +126,7 @@ struct clock {
int stats_interval;
struct clockcheck *sanity_check;
struct interface *udsif;
+   struct syfu_relay_info syfu_relay;
LIST_HEAD(clock_subscribers_head, clock_subscriber) subscribers;
 };
 
@@ -1117,6 +1117,8 @@ struct clock *clock_create(enum clock_type type, struct 
config *config,
}
}
 
+   memset(>syfu_relay, 0, sizeof(struct syfu_relay_info));
+
/* Initialize the parentDS. */
clock_update_grandmaster(c);
c->dad.pds.parentStats   = 0;
@@ -1208,6 +1210,15 @@ void clock_follow_up_info(struct clock *c, struct 
follow_up_info_tlv *f)
   sizeof(c->status.lastGmPhaseChange));
 }
 
+static void clock_get_follow_up_info(struct clock *c, struct 
follow_up_info_tlv *f)
+{
+   f->cumulativeScaledRateOffset = c->status.cumulativeScaledRateOffset;
+   f->scaledLastGmPhaseChange = c->status.scaledLastGmPhaseChange;
+   f->gmTimeBaseIndicator = c->status.gmTimeBaseIndicator;
+   memcpy(>lastGmPhaseChange, >status.lastGmPhaseChange,
+  sizeof(f->lastGmPhaseChange));
+}
+
 int clock_free_running(struct clock *c)
 {
return c->free_running ? 1 : 0;
@@ -1583,6 +1594,16 @@ void clock_peer_delay(struct clock *c, tmv_t ppd, tmv_t 
req, tmv_t rx,
stats_add_value(c->stats.delay, tmv_dbl(ppd));
 }
 
+tmv_t clock_get_path_delay(struct clock *c)
+{
+   return c->path_delay;
+}
+
+double clock_get_nrr(struct clock *c)
+{
+   return c->nrr;
+}
+
 int clock_slave_only(struct clock *c)
 {
return c->dds.flags & DDS_SLAVE_ONLY;
@@ -1777,6 +1798,7 @@ static void handle_state_decision_event(struct clock *c)
c->master_local_rr = 1.0;
c->nrr = 1.0;
fresh_best = 1;
+   clock_disable_syfu_relay(c);
}
 
c->best = best;
@@ -1848,3 +1870,22 @@ enum servo_state clock_servo_state(struct clock *c)
 {
return c->servo_state;
 }
+
+void clock_prepare_syfu_relay(struct clock *c, struct ptp_message *sync,
+ struct ptp_message *fup)
+{
+   c->syfu_relay.precise_origin_ts = timestamp_to_tmv(fup->ts.pdu);
+   c->syfu_relay.correction = fup->header.correction;
+   clock_get_follow_up_info(c, >syfu_relay.fup_info_tlv);
+   c->syfu_relay.avail = 1;
+}
+
+void clock_disable_syfu_relay(struct clock *c)
+{
+   c->syfu_relay.avail = 0;
+}
+
+struct syfu_relay_info *clock_get_syfu_relay(struct clock *c)
+{
+   return >syfu_relay;
+}
diff --git a/clock.h b/clock.h
index 9d3133a..8ff1181 100644
--- a/clock.h
+++ b/clock.h
@@ -29,8 +29,18 @@
 #include "tmv.h"
 #include "transport.h"
 
+#define POW2_41 ((double)(1ULL << 41))
+
 struct ptp_message; /*forward declaration*/
 
+struct syfu_relay_info {
+   tmv_t precise_origin_ts;
+   Integer64 correction;
+   struct follow_up_info_tlv fup_info_tlv;
+   /* Auxiliary info */
+   int avail;
+};
+
 /** Opaque type. */
 struct clock;
 
@@ -240,6 +250,20 @@ void clock_peer_delay(struct clock *c, tmv_t ppd, tmv_t 
req, tmv_t rx,
  double nrr);
 
 /**
+ * Get the path delay as measured on a slave port.
+ * @param c   The clock instance.
+ * @returnThe path delay as measured on a slave port.
+ */
+tmv_t clock_get_path_delay(struct clock *c);
+
+/**
+ * Get the neighbor rate ratio as measured on a slave port.
+ * @param c   The clock instance.
+ * @returnThe neighbor rate ratio as measured on a slave port.
+ */
+double clock_get_nrr(struct clock *c);
+
+/**
  * Set

[Linuxptp-devel] [RFC V3, 0/4] Add IEEE 802.1AS-2011 time-aware bridge support

2020-03-23 Thread Yangbo Lu
This patch-set is to add IEEE 802.1AS-2011 time-aware bridge support.
The implementation is based on BC clock type. The main changes are,
- Support time information relay through follow_up_TLV.
- Support BMCA for IEEE 802.1AS-2011 time-aware bridge.
- Implement other difference of IEEE 802.1AS-2011 time-aware bridge.

---
Changes for v2:
- Implemented based on BC instead of TC.
Changes for v3:
- Rebased.
- Used port_is_ieee8021as() instead of p->follow_up_info.
- Added three patches for BMCA and others support of TAB.

Rodney Greenstreet (2):
  port: drop erroneous neighbor rate ratio
  clock: redecide state if get EV_FAULT_DETECTED event

Yangbo Lu (2):
  Add IEEE 802.1AS-2011 time-aware bridge support
  Add BMCA support for IEEE 802.1AS-2011

 clock.c |  46 +++-
 clock.h |  45 
 fsm.c   |  13 ++
 fsm.h   |  10 +
 port.c  | 145 ++--
 5 files changed, 235 insertions(+), 24 deletions(-)

-- 
2.7.4



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [RFC V2] Add IEEE 802.1AS-2011 time-aware bridge support

2019-10-14 Thread Yangbo Lu
This patch is to add IEEE 802.1AS-2011 time-aware bridge support
based on current BC clock type. It implements only time information
relay, and BMCA was not touched. To run it, the profile gPTP.cfg could
be used with multiple interfaces specified using -i option.

The main code changes are,
- Create syfu_relay_info structure for time information relay.
- Implement port_syfu_relay_info_insert() to update follow_up (with TLV)
  message with time information for relay.

Signed-off-by: Yangbo Lu 
---
Changes for v2:
- Implemented based on BC instead of TC.
---
 clock.c | 43 -
 clock.h | 45 +++
 port.c  | 75 +
 3 files changed, 158 insertions(+), 5 deletions(-)

diff --git a/clock.c b/clock.c
index 146576a..1865ecb 100644
--- a/clock.c
+++ b/clock.c
@@ -45,7 +45,6 @@
 #include "util.h"
 
 #define N_CLOCK_PFD (N_POLLFD + 1) /* one extra per port, for the fault timer 
*/
-#define POW2_41 ((double)(1ULL << 41))
 
 struct port {
LIST_ENTRY(port) list;
@@ -123,6 +122,7 @@ struct clock {
int stats_interval;
struct clockcheck *sanity_check;
struct interface uds_interface;
+   struct syfu_relay_info syfu_relay;
LIST_HEAD(clock_subscribers_head, clock_subscriber) subscribers;
 };
 
@@ -1117,6 +1117,8 @@ struct clock *clock_create(enum clock_type type, struct 
config *config,
}
}
 
+   memset(>syfu_relay, 0, sizeof(struct syfu_relay_info));
+
/* Initialize the parentDS. */
clock_update_grandmaster(c);
c->dad.pds.parentStats   = 0;
@@ -1208,6 +1210,15 @@ void clock_follow_up_info(struct clock *c, struct 
follow_up_info_tlv *f)
   sizeof(c->status.lastGmPhaseChange));
 }
 
+static void clock_get_follow_up_info(struct clock *c, struct 
follow_up_info_tlv *f)
+{
+   f->cumulativeScaledRateOffset = c->status.cumulativeScaledRateOffset;
+   f->scaledLastGmPhaseChange = c->status.scaledLastGmPhaseChange;
+   f->gmTimeBaseIndicator = c->status.gmTimeBaseIndicator;
+   memcpy(>lastGmPhaseChange, >status.lastGmPhaseChange,
+  sizeof(f->lastGmPhaseChange));
+}
+
 int clock_free_running(struct clock *c)
 {
return c->free_running ? 1 : 0;
@@ -1583,6 +1594,16 @@ void clock_peer_delay(struct clock *c, tmv_t ppd, tmv_t 
req, tmv_t rx,
stats_add_value(c->stats.delay, tmv_dbl(ppd));
 }
 
+tmv_t clock_get_path_delay(struct clock *c)
+{
+   return c->path_delay;
+}
+
+double clock_get_nrr(struct clock *c)
+{
+   return c->nrr;
+}
+
 int clock_slave_only(struct clock *c)
 {
return c->dds.flags & DDS_SLAVE_ONLY;
@@ -1776,6 +1797,7 @@ static void handle_state_decision_event(struct clock *c)
c->path_delay = c->initial_delay;
c->nrr = 1.0;
fresh_best = 1;
+   clock_disable_syfu_relay(c);
}
 
c->best = best;
@@ -1847,3 +1869,22 @@ enum servo_state clock_servo_state(struct clock *c)
 {
return c->servo_state;
 }
+
+void clock_prepare_syfu_relay(struct clock *c, struct ptp_message *sync,
+ struct ptp_message *fup)
+{
+   c->syfu_relay.precise_origin_ts = timestamp_to_tmv(fup->ts.pdu);
+   c->syfu_relay.correction = fup->header.correction;
+   clock_get_follow_up_info(c, >syfu_relay.fup_info_tlv);
+   c->syfu_relay.avail = 1;
+}
+
+void clock_disable_syfu_relay(struct clock *c)
+{
+   c->syfu_relay.avail = 0;
+}
+
+struct syfu_relay_info *clock_get_syfu_relay(struct clock *c)
+{
+   return >syfu_relay;
+}
diff --git a/clock.h b/clock.h
index 9d3133a..8ff1181 100644
--- a/clock.h
+++ b/clock.h
@@ -29,8 +29,18 @@
 #include "tmv.h"
 #include "transport.h"
 
+#define POW2_41 ((double)(1ULL << 41))
+
 struct ptp_message; /*forward declaration*/
 
+struct syfu_relay_info {
+   tmv_t precise_origin_ts;
+   Integer64 correction;
+   struct follow_up_info_tlv fup_info_tlv;
+   /* Auxiliary info */
+   int avail;
+};
+
 /** Opaque type. */
 struct clock;
 
@@ -240,6 +250,20 @@ void clock_peer_delay(struct clock *c, tmv_t ppd, tmv_t 
req, tmv_t rx,
  double nrr);
 
 /**
+ * Get the path delay as measured on a slave port.
+ * @param c   The clock instance.
+ * @returnThe path delay as measured on a slave port.
+ */
+tmv_t clock_get_path_delay(struct clock *c);
+
+/**
+ * Get the neighbor rate ratio as measured on a slave port.
+ * @param c   The clock instance.
+ * @returnThe neighbor rate ratio as measured on a slave port.
+ */
+double clock_get_nrr(struct clock *c);
+
+/**
  * Set clock sde
  * @param c A pointer to a clock instance obtained with clock_create().
  * @

[Linuxptp-devel] [RFC] Add 802.1AS-2011 time-aware bridge support

2019-10-10 Thread Yangbo Lu
This is an immature implementation of non-GM 802.1AS-2011 time-aware bridge
which is based on P2P TC.
- Add BRIDGE clock type.
- Create bridge.c which is a copy of p2p_tc.c.
- Implement tc_fwd_folup_tlv() for bridge instead of tc_fwd_folup()
  used for p2p_tc.
- Create time-aware-bridge.cfg.

Signed-off-by: Yangbo Lu 
---
 bridge.c  | 231 ++
 clock.c   |   1 +
 clock.h   |   1 +
 config.c  |   1 +
 configs/time-aware-bridge.cfg |  38 +++
 makefile  |   2 +-
 msg.c |   7 +-
 port.c|   6 +-
 port.h|   1 +
 port_private.h|   3 +
 tc.c  | 108 
 tc.h  |   2 +
 12 files changed, 398 insertions(+), 3 deletions(-)
 create mode 100644 bridge.c
 create mode 100644 configs/time-aware-bridge.cfg

diff --git a/bridge.c b/bridge.c
new file mode 100644
index 000..89be2b9
--- /dev/null
+++ b/bridge.c
@@ -0,0 +1,231 @@
+/**
+ * @file bridge.c
+ * @note Copyright (C) 2018 Richard Cochran 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA.
+ */
+#include 
+
+#include "port.h"
+#include "port_private.h"
+#include "print.h"
+#include "rtnl.h"
+#include "tc.h"
+
+static int bridge_delay_request(struct port *p)
+{
+   switch (p->state) {
+   case PS_INITIALIZING:
+   case PS_FAULTY:
+   case PS_DISABLED:
+   return 0;
+   case PS_LISTENING:
+   case PS_PRE_MASTER:
+   case PS_MASTER:
+   case PS_PASSIVE:
+   case PS_UNCALIBRATED:
+   case PS_SLAVE:
+   case PS_GRAND_MASTER:
+   break;
+   }
+   return port_delay_request(p);
+}
+
+void bridge_dispatch(struct port *p, enum fsm_event event, int mdiff)
+{
+   if (!port_state_update(p, event, mdiff)) {
+   return;
+   }
+   if (!portnum(p)) {
+   /* UDS needs no timers. */
+   return;
+   }
+
+   port_clr_tmo(p->fda.fd[FD_ANNOUNCE_TIMER]);
+   port_clr_tmo(p->fda.fd[FD_SYNC_RX_TIMER]);
+   /* Leave FD_DELAY_TIMER running. */
+   port_clr_tmo(p->fda.fd[FD_QUALIFICATION_TIMER]);
+   port_clr_tmo(p->fda.fd[FD_MANNO_TIMER]);
+   port_clr_tmo(p->fda.fd[FD_SYNC_TX_TIMER]);
+
+   /*
+* Handle the side effects of the state transition.
+*/
+   switch (p->state) {
+   case PS_INITIALIZING:
+   break;
+   case PS_FAULTY:
+   case PS_DISABLED:
+   port_disable(p);
+   break;
+   case PS_LISTENING:
+   port_set_announce_tmo(p);
+   port_set_delay_tmo(p);
+   break;
+   case PS_PRE_MASTER:
+   port_set_qualification_tmo(p);
+   break;
+   case PS_MASTER:
+   case PS_GRAND_MASTER:
+   break;
+   case PS_PASSIVE:
+   port_set_announce_tmo(p);
+   break;
+   case PS_UNCALIBRATED:
+   case PS_SLAVE:
+   port_set_announce_tmo(p);
+   break;
+   };
+}
+
+enum fsm_event bridge_event(struct port *p, int fd_index)
+{
+   int cnt, fd = p->fda.fd[fd_index];
+   enum fsm_event event = EV_NONE;
+   struct ptp_message *msg, *dup;
+
+   switch (fd_index) {
+   case FD_ANNOUNCE_TIMER:
+   case FD_SYNC_RX_TIMER:
+   pr_debug("port %hu: %s timeout", portnum(p),
+fd_index == FD_SYNC_RX_TIMER ? "rx sync" : "announce");
+   if (p->best) {
+   fc_clear(p->best);
+   }
+   port_set_announce_tmo(p);
+   return EV_ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES;
+
+   case FD_DELAY_TIMER:
+   pr_debug("port %hu: delay timeout", portnum(p));
+   port_set_delay_tmo(p);
+   tc_prune(p);
+   return bridge_delay_request(p) ? EV_FAULT_DETECTED : EV_NONE;
+
+   case FD_QUALIFICATION_TIMER:
+   pr_debug("port %hu: qualification timeout", portnum(p));
+   return EV_QUALIFICAT