[Linuxptp-devel] [PATCH 2/2] pmc: Support querying TLV_PORT_PROPERTIES_NP

2019-09-12 Thread Petr Machata
TLV_PORT_PROPERTIES_NP messages serve for querying of port properties, such
as timestamp type and, prominently, netdevice name associated with the
port. pmc however does not support this query, which makes it difficult to
access this information e.g. from scripts. Add this support to pmc.

Signed-off-by: Mykola Zhuravel 
Signed-off-by: Petr Machata 
---
 pmc.8|  2 ++
 pmc.c| 16 
 pmc_common.c |  1 +
 3 files changed, 19 insertions(+)

diff --git a/pmc.8 b/pmc.8
index acf2d90..e0ab5ac 100644
--- a/pmc.8
+++ b/pmc.8
@@ -193,6 +193,8 @@ The MAC address to which PTP management messages should be 
sent. Relevant only w
 .TP
 .B PORT_DATA_SET_NP
 .TP
+.B PORT_PROPERTIES_NP
+.TP
 .B PORT_STATS_NP
 .TP
 .B PRIORITY1
diff --git a/pmc.c b/pmc.c
index 868fc2a..4e6043b 100644
--- a/pmc.c
+++ b/pmc.c
@@ -69,6 +69,7 @@ static void pmc_show(struct ptp_message *msg, FILE *fp)
struct tlv_extra *extra;
struct portDS *p;
struct port_ds_np *pnp;
+   struct port_properties_np *ppn;
struct port_stats_np *pcp;
 
if (msg_type(msg) != MANAGEMENT) {
@@ -323,6 +324,21 @@ static void pmc_show(struct ptp_message *msg, FILE *fp)
pnp->neighborPropDelayThresh,
pnp->asCapable ? 1 : 0);
break;
+   case TLV_PORT_PROPERTIES_NP:
+   ppn = (struct port_properties_np *) mgt->data;
+   if (ppn->port_state > PS_SLAVE) {
+   ppn->port_state = 0;
+   }
+   fprintf(fp, "PORT_PROPERTIES_NP "
+   IFMT "portIdentity%s"
+   IFMT "portState   %s"
+   IFMT "timestamping%s"
+   IFMT "interface   %s",
+   pid2str(&ppn->portIdentity),
+   ps_str[ppn->port_state],
+   ts_str(ppn->timestamping),
+   text2str(&ppn->interface));
+   break;
case TLV_PORT_STATS_NP:
pcp = (struct port_stats_np *) mgt->data;
fprintf(fp, "PORT_STATS_NP "
diff --git a/pmc_common.c b/pmc_common.c
index 592cc93..46aac30 100644
--- a/pmc_common.c
+++ b/pmc_common.c
@@ -121,6 +121,7 @@ struct management_id idtab[] = {
{ "LOG_MIN_PDELAY_REQ_INTERVAL", TLV_LOG_MIN_PDELAY_REQ_INTERVAL, 
do_get_action },
{ "PORT_DATA_SET_NP", TLV_PORT_DATA_SET_NP, do_set_action },
{ "PORT_STATS_NP", TLV_PORT_STATS_NP, do_get_action },
+   { "PORT_PROPERTIES_NP", TLV_PORT_PROPERTIES_NP, do_get_action },
 };
 
 static void do_get_action(struct pmc *pmc, int action, int index, char *str)
-- 
2.20.1



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


[Linuxptp-devel] [PATCH 0/2] pmc: Support querying TLV_PORT_PROPERTIES_NP

2019-09-12 Thread Petr Machata
In commit 424bbde8fcca ("Custom management TLV PORT_PROPERTIES_NP"), a new
TLV was added that allows introspection into PTP ports, and in particular
translation from PTP port identifiers to system netdevice names. The TLV
was added for phc2sys, and correspondingly pmc support was not added.

However, translating from port IDs to netdevices is as useful to phc2sys as
to end users. Besides just visually correlating what's what also for ad-hoc
scripting and writing automated tests.

This patchset therefore extends pmc to understand this TLV. In patch #1, a
new helper is added that allows human-readable rendering of timestamping
type, which is one of the reported properties. Patch #2 then extends pmc.

Petr Machata (2):
  util: Add a function to render timestamp type
  pmc: Support querying TLV_PORT_PROPERTIES_NP

 pmc.8|  2 ++
 pmc.c| 16 
 pmc_common.c |  1 +
 util.c   | 18 ++
 util.h   |  7 +++
 5 files changed, 44 insertions(+)

-- 
2.20.1



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


[Linuxptp-devel] [PATCH 1/2] util: Add a function to render timestamp type

2019-09-12 Thread Petr Machata
TLV_PORT_PROPERTIES_NP carries, among other attributes, a timestamp type
used for that port. In order to make it possible to format the value for
user consumption, introduce a new function ts_str().

Signed-off-by: Petr Machata 
---
 util.c | 18 ++
 util.h |  7 +++
 2 files changed, 25 insertions(+)

diff --git a/util.c b/util.c
index 833f1a5..e64a93d 100644
--- a/util.c
+++ b/util.c
@@ -70,6 +70,24 @@ const char *ev_str[] = {
"RS_PASSIVE",
 };
 
+const char *ts_str(enum timestamp_type ts)
+{
+   switch (ts) {
+   case TS_SOFTWARE:
+   return "SOFTWARE";
+   case TS_HARDWARE:
+   return "HARDWARE";
+   case TS_LEGACY_HW:
+   return "LEGACY_HW";
+   case TS_ONESTEP:
+   return "ONESTEP";
+   case TS_P2P1STEP:
+   return "P2P1STEP";
+   }
+
+   return "???";
+}
+
 int addreq(enum transport_type type, struct address *a, struct address *b)
 {
void *bufa, *bufb;
diff --git a/util.h b/util.h
index 9d3f227..60d28ac 100644
--- a/util.h
+++ b/util.h
@@ -41,6 +41,13 @@ extern const char *ps_str[];
  */
 extern const char *ev_str[];
 
+/**
+ * Gets a human-readable string for a given timestamp type.
+ * @param tsTimestamp type.
+ * @return  Human-readable rendering if TS is valid, otherwise "???".
+ */
+const char *ts_str(enum timestamp_type ts);
+
 /**
  * Compares two binary addresses for equality.
  * @param type  One of the enumerated transport types.
-- 
2.20.1



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