[Linuxptp-devel] [PATCH v2 3/6] Introduce the Common Mean Link Delay Information TLV.
PTP IEEE 1588 stack for Linux
Brought to you by:
rcochran
|
From: Richard C. <ric...@gm...> - 2023-12-02 22:25:19
|
Add a new TLV to convey link delay measurements by the Common Mean
Link Delay Service (CMLDS) (as specified in IEEE 1588/16.6.3) over the
management interface.
Co-authored-by: Andrew Zaborowski <and...@in...>
Signed-off-by: Kishen Maloor <kis...@in...>
Signed-off-by: Richard Cochran <ric...@gm...>
---
clock.c | 1 -
pmc.c | 11 +++++++++++
pmc_common.c | 1 +
port.c | 9 +++++++++
port.h | 2 ++
tlv.c | 16 ++++++++++++++++
tlv.h | 7 +++++++
7 files changed, 46 insertions(+), 1 deletion(-)
diff --git a/clock.c b/clock.c
index 6f7722c..c999c83 100644
--- a/clock.c
+++ b/clock.c
@@ -47,7 +47,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;
diff --git a/pmc.c b/pmc.c
index d18fea0..12a6109 100644
--- a/pmc.c
+++ b/pmc.c
@@ -169,6 +169,7 @@ static void pmc_show(struct ptp_message *msg, FILE *fp)
struct subscribe_events_np *sen;
struct port_properties_np *ppn;
struct port_hwclock_np *phn;
+ struct cmlds_info_np *cmlds;
struct timePropertiesDS *tp;
struct management_tlv *mgt;
struct time_status_np *tsn;
@@ -623,6 +624,16 @@ static void pmc_show(struct ptp_message *msg, FILE *fp)
pwr->networkTimeInaccuracy,
pwr->totalTimeInaccuracy);
break;
+ case MID_CMLDS_INFO_NP:
+ cmlds = (struct cmlds_info_np *) mgt->data;
+ fprintf(fp, "CMLDS_INFO_NP "
+ IFMT "meanLinkDelay %" PRId64
+ IFMT "scaledNeighborRateRatio %" PRId32
+ IFMT "as_capable %" PRIu32,
+ cmlds->meanLinkDelay >> 16,
+ cmlds->scaledNeighborRateRatio,
+ cmlds->as_capable);
+ break;
case MID_LOG_ANNOUNCE_INTERVAL:
mtd = (struct management_tlv_datum *) mgt->data;
fprintf(fp, "LOG_ANNOUNCE_INTERVAL "
diff --git a/pmc_common.c b/pmc_common.c
index fca16c6..1d537f2 100644
--- a/pmc_common.c
+++ b/pmc_common.c
@@ -156,6 +156,7 @@ struct management_id idtab[] = {
{ "UNICAST_MASTER_TABLE_NP", MID_UNICAST_MASTER_TABLE_NP, do_get_action },
{ "PORT_HWCLOCK_NP", MID_PORT_HWCLOCK_NP, do_get_action },
{ "POWER_PROFILE_SETTINGS_NP", MID_POWER_PROFILE_SETTINGS_NP, do_set_action },
+ { "CMLDS_INFO_NP", MID_CMLDS_INFO_NP, do_get_action },
};
static void do_get_action(struct pmc *pmc, int action, int index, char *str)
diff --git a/port.c b/port.c
index b7fbfb1..2eca876 100644
--- a/port.c
+++ b/port.c
@@ -883,6 +883,7 @@ static int port_management_fill_response(struct port *target,
struct clock_description *desc;
struct port_properties_np *ppn;
struct port_hwclock_np *phn;
+ struct cmlds_info_np *cmlds;
struct management_tlv *tlv;
struct port_stats_np *psn;
struct foreign_clock *fc;
@@ -1125,6 +1126,14 @@ static int port_management_fill_response(struct port *target,
memcpy(pwr, &target->pwr, sizeof(*pwr));
datalen = sizeof(*pwr);
break;
+ case MID_CMLDS_INFO_NP:
+ cmlds = (struct cmlds_info_np *)tlv->data;
+ cmlds->meanLinkDelay = target->peerMeanPathDelay;
+ cmlds->scaledNeighborRateRatio =
+ (Integer32) (target->nrate.ratio * POW2_41 - POW2_41);
+ cmlds->as_capable = target->asCapable;
+ datalen = sizeof(*cmlds);
+ break;
default:
/* The caller should *not* respond to this message. */
tlv_extra_recycle(extra);
diff --git a/port.h b/port.h
index 57c8c2f..cc03859 100644
--- a/port.h
+++ b/port.h
@@ -26,6 +26,8 @@
#include "notification.h"
#include "transport.h"
+#define POW2_41 ((double)(1ULL << 41))
+
/* forward declarations */
struct interface;
struct clock;
diff --git a/tlv.c b/tlv.c
index 9b82bd9..7cbd84d 100644
--- a/tlv.c
+++ b/tlv.c
@@ -176,6 +176,7 @@ static int mgt_post_recv(struct management_tlv *m, uint16_t data_len,
struct port_properties_np *ppn;
struct port_hwclock_np *phn;
struct timePropertiesDS *tp;
+ struct cmlds_info_np *cmlds;
struct time_status_np *tsn;
struct port_stats_np *psn;
int extra_len = 0, i, len;
@@ -481,6 +482,14 @@ static int mgt_post_recv(struct management_tlv *m, uint16_t data_len,
NTOHL(pwr->networkTimeInaccuracy);
NTOHL(pwr->totalTimeInaccuracy);
break;
+ case MID_CMLDS_INFO_NP:
+ if (data_len < sizeof(struct cmlds_info_np))
+ goto bad_length;
+ cmlds = (struct cmlds_info_np *)m->data;
+ net2host64_unaligned(&cmlds->meanLinkDelay);
+ NTOHL(cmlds->scaledNeighborRateRatio);
+ NTOHL(cmlds->as_capable);
+ break;
case MID_SAVE_IN_NON_VOLATILE_STORAGE:
case MID_RESET_NON_VOLATILE_STORAGE:
case MID_INITIALIZE:
@@ -514,6 +523,7 @@ static void mgt_pre_send(struct management_tlv *m, struct tlv_extra *extra)
struct subscribe_events_np *sen;
struct port_properties_np *ppn;
struct port_hwclock_np *phn;
+ struct cmlds_info_np *cmlds;
struct timePropertiesDS *tp;
struct time_status_np *tsn;
struct port_stats_np *psn;
@@ -672,6 +682,12 @@ static void mgt_pre_send(struct management_tlv *m, struct tlv_extra *extra)
HTONL(pwr->networkTimeInaccuracy);
HTONL(pwr->totalTimeInaccuracy);
break;
+ case MID_CMLDS_INFO_NP:
+ cmlds = (struct cmlds_info_np *)m->data;
+ host2net64_unaligned(&cmlds->meanLinkDelay);
+ HTONL(cmlds->scaledNeighborRateRatio);
+ HTONL(cmlds->as_capable);
+ break;
}
}
diff --git a/tlv.h b/tlv.h
index 8b51ffd..d8875b3 100644
--- a/tlv.h
+++ b/tlv.h
@@ -129,6 +129,7 @@ enum management_action {
#define MID_UNICAST_MASTER_TABLE_NP 0xC008
#define MID_PORT_HWCLOCK_NP 0xC009
#define MID_POWER_PROFILE_SETTINGS_NP 0xC00A
+#define MID_CMLDS_INFO_NP 0xC00B
/* Management error ID values */
#define MID_RESPONSE_TOO_BIG 0x0001
@@ -323,6 +324,12 @@ typedef struct Integer96 {
uint16_t fractional_nanoseconds;
} PACKED ScaledNs;
+struct cmlds_info_np {
+ TimeInterval meanLinkDelay;
+ Integer32 scaledNeighborRateRatio;
+ uint32_t as_capable;
+} PACKED;
+
struct follow_up_info_tlv {
Enumeration16 type;
UInteger16 length;
--
2.39.2
|