[Linuxptp-devel] [PATCH] Log the selected grandmaster's clock quality.

2018-06-18 Thread Cliff Spradlin via Linuxptp-devel
It can be useful to see the quality of the grandmaster's clock,
especially as it changes over time (such as during GPS holdover).

This patch also collapses two redundant if statements into one.

Signed-off-by: Cliff Spradlin 
---
 clock.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/clock.c b/clock.c
index 1edbb37..1db28e2 100644
--- a/clock.c
+++ b/clock.c
@@ -1731,16 +1731,16 @@ static void handle_state_decision_event(struct clock *c)
 
if (best) {
best_id = best->dataset.identity;
+   pr_notice("selected best master clock %s",
+ cid2str(_id));
+   pr_info("class %hhu accuracy 0x%02hhx variance 0x%04hx",
+   best->dataset.quality.clockClass,
+   best->dataset.quality.clockAccuracy,
+   best->dataset.quality.offsetScaledLogVariance);
} else {
best_id = c->dds.clockIdentity;
-   }
-
-   if (cid_eq(_id, >dds.clockIdentity)) {
pr_notice("selected local clock %s as best master",
  cid2str(_id));
-   } else {
-   pr_notice("selected best master clock %s",
- cid2str(_id));
}
 
if (!cid_eq(_id, >best_id)) {
-- 
2.18.0.rc1.244.gcf134e6275-goog


--
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


[Linuxptp-devel] [PATCH_SNMP_v3 1/5] pmc: Move new common funtionality into pmc_common

2018-06-18 Thread Anders Selhammer
Code from pmc.c will be reused by new snmpd.c in later commit.

Signed-off-by: Anders Selhammer 
---
 pmc.c| 299 +--
 pmc_common.c | 294 ++
 pmc_common.h |   9 ++
 3 files changed, 305 insertions(+), 297 deletions(-)

diff --git a/pmc.c b/pmc.c
index 6f23167..35b1d96 100644
--- a/pmc.c
+++ b/pmc.c
@@ -35,88 +35,8 @@
 #include "util.h"
 #include "version.h"
 
-#define BAD_ACTION   -1
-#define BAD_ID   -1
-#define AMBIGUOUS_ID -2
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#define P41 ((double)(1ULL << 41))
-
 static struct pmc *pmc;
 
-static void do_get_action(int action, int index, char *str);
-static void do_set_action(int action, int index, char *str);
-static void not_supported(int action, int index, char *str);
-static void null_management(int action, int index, char *str);
-
-struct management_id {
-   char name[64];
-   int code;
-   void (*func)(int action, int index, char *str);
-};
-
-struct management_id idtab[] = {
-/* Clock management ID values */
-   { "USER_DESCRIPTION", TLV_USER_DESCRIPTION, do_get_action },
-   { "SAVE_IN_NON_VOLATILE_STORAGE", TLV_SAVE_IN_NON_VOLATILE_STORAGE, 
not_supported },
-   { "RESET_NON_VOLATILE_STORAGE", TLV_RESET_NON_VOLATILE_STORAGE, 
not_supported },
-   { "INITIALIZE", TLV_INITIALIZE, not_supported },
-   { "FAULT_LOG", TLV_FAULT_LOG, not_supported },
-   { "FAULT_LOG_RESET", TLV_FAULT_LOG_RESET, not_supported },
-   { "DEFAULT_DATA_SET", TLV_DEFAULT_DATA_SET, do_get_action },
-   { "CURRENT_DATA_SET", TLV_CURRENT_DATA_SET, do_get_action },
-   { "PARENT_DATA_SET", TLV_PARENT_DATA_SET, do_get_action },
-   { "TIME_PROPERTIES_DATA_SET", TLV_TIME_PROPERTIES_DATA_SET, 
do_get_action },
-   { "PRIORITY1", TLV_PRIORITY1, do_set_action },
-   { "PRIORITY2", TLV_PRIORITY2, do_set_action },
-   { "DOMAIN", TLV_DOMAIN, do_get_action },
-   { "SLAVE_ONLY", TLV_SLAVE_ONLY, do_get_action },
-   { "TIME", TLV_TIME, not_supported },
-   { "CLOCK_ACCURACY", TLV_CLOCK_ACCURACY, do_get_action },
-   { "UTC_PROPERTIES", TLV_UTC_PROPERTIES, not_supported },
-   { "TRACEABILITY_PROPERTIES", TLV_TRACEABILITY_PROPERTIES, do_get_action 
},
-   { "TIMESCALE_PROPERTIES", TLV_TIMESCALE_PROPERTIES, do_get_action },
-   { "PATH_TRACE_LIST", TLV_PATH_TRACE_LIST, not_supported },
-   { "PATH_TRACE_ENABLE", TLV_PATH_TRACE_ENABLE, not_supported },
-   { "GRANDMASTER_CLUSTER_TABLE", TLV_GRANDMASTER_CLUSTER_TABLE, 
not_supported },
-   { "ACCEPTABLE_MASTER_TABLE", TLV_ACCEPTABLE_MASTER_TABLE, not_supported 
},
-   { "ACCEPTABLE_MASTER_MAX_TABLE_SIZE", 
TLV_ACCEPTABLE_MASTER_MAX_TABLE_SIZE, not_supported },
-   { "ALTERNATE_TIME_OFFSET_ENABLE", TLV_ALTERNATE_TIME_OFFSET_ENABLE, 
not_supported },
-   { "ALTERNATE_TIME_OFFSET_NAME", TLV_ALTERNATE_TIME_OFFSET_NAME, 
not_supported },
-   { "ALTERNATE_TIME_OFFSET_MAX_KEY", TLV_ALTERNATE_TIME_OFFSET_MAX_KEY, 
not_supported },
-   { "ALTERNATE_TIME_OFFSET_PROPERTIES", 
TLV_ALTERNATE_TIME_OFFSET_PROPERTIES, not_supported },
-   { "TRANSPARENT_CLOCK_DEFAULT_DATA_SET", 
TLV_TRANSPARENT_CLOCK_DEFAULT_DATA_SET, not_supported },
-   { "PRIMARY_DOMAIN", TLV_PRIMARY_DOMAIN, not_supported },
-   { "TIME_STATUS_NP", TLV_TIME_STATUS_NP, do_get_action },
-   { "GRANDMASTER_SETTINGS_NP", TLV_GRANDMASTER_SETTINGS_NP, do_set_action 
},
-/* Port management ID values */
-   { "NULL_MANAGEMENT", TLV_NULL_MANAGEMENT, null_management },
-   { "CLOCK_DESCRIPTION", TLV_CLOCK_DESCRIPTION, do_get_action },
-   { "PORT_DATA_SET", TLV_PORT_DATA_SET, do_get_action },
-   { "LOG_ANNOUNCE_INTERVAL", TLV_LOG_ANNOUNCE_INTERVAL, do_get_action },
-   { "ANNOUNCE_RECEIPT_TIMEOUT", TLV_ANNOUNCE_RECEIPT_TIMEOUT, 
do_get_action },
-   { "LOG_SYNC_INTERVAL", TLV_LOG_SYNC_INTERVAL, do_get_action },
-   { "VERSION_NUMBER", TLV_VERSION_NUMBER, do_get_action },
-   { "ENABLE_PORT", TLV_ENABLE_PORT, not_supported },
-   { "DISABLE_PORT", TLV_DISABLE_PORT, not_supported },
-   { "UNICAST_NEGOTIATION_ENABLE", TLV_UNICAST_NEGOTIATION_ENABLE, 
not_supported },
-   { "UNICAST_MASTER_TABLE", TLV_UNICAST_MASTER_TABLE, not_supported },
-   { "UNICAST_MASTER_MAX_TABLE_SIZE", TLV_UNICAST_MASTER_MAX_TABLE_SIZE, 
not_supported },
-   { "ACCEPTABLE_MASTER_TABLE_ENABLED", 
TLV_ACCEPTABLE_MASTER_TABLE_ENABLED, not_supported },
-   { "ALTERNATE_MASTER", TLV_ALTERNATE_MASTER, not_supported },
-   { "TRANSPARENT_CLOCK_PORT_DATA_SET", 
TLV_TRANSPARENT_CLOCK_PORT_DATA_SET, not_supported },
-   { "DELAY_MECHANISM", TLV_DELAY_MECHANISM, do_get_action },
-   { "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 },
-};
-
-static const char *action_string[] = {
-   "GET",
-   

[Linuxptp-devel] [PATCH_SNMP_v3 0/5] Add support of snmp

2018-06-18 Thread Anders Selhammer
Add of the first step of supporting SNMP communication to linuxptp.
This patchset only adds the basics for SNMP. The support of published
MIBs will be added later on.
Support of cross compilation will also be included later on.

Anders Selhammer (5):
  pmc: Move new common funtionality into pmc_common
  pdt: Added check if already defined
  snmpd: Add snmp sub agent
  snmpd: Added communication to ptp4l via the UDS port.
  snmpd: Add snmpd_run_pmc for data collection from ptp4l program.

 configs/snmpd.conf |  26 +
 incdefs.sh |  16 ++-
 ldlibs.sh  |  44 
 makefile   |  12 ++-
 optprg.sh  |  44 
 pdt.h  |   7 +-
 pmc.c  | 299 +
 pmc_common.c   | 294 
 pmc_common.h   |   9 ++
 snmpd.c| 192 ++
 snmpd_mib.h|  30 ++
 11 files changed, 671 insertions(+), 302 deletions(-)
 create mode 100644 configs/snmpd.conf
 create mode 100755 ldlibs.sh
 create mode 100755 optprg.sh
 create mode 100644 snmpd.c
 create mode 100644 snmpd_mib.h

-- 
1.8.3.1


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus


--
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


[Linuxptp-devel] [PATCH_SNMP_v3 4/5] snmpd: Added communication to ptp4l via the UDS port.

2018-06-18 Thread Anders Selhammer
UDS transport is configured using pmc_common functions.

Signed-off-by: Anders Selhammer 
---
 makefile |   3 +-
 snmpd.c  | 102 +--
 2 files changed, 102 insertions(+), 3 deletions(-)

diff --git a/makefile b/makefile
index ed5c554..fdf3747 100644
--- a/makefile
+++ b/makefile
@@ -52,7 +52,8 @@ ptp4l: $(OBJ)
 nsm: config.o filter.o hash.o mave.o mmedian.o msg.o nsm.o print.o raw.o \
  rtnl.o sk.o transport.o tlv.o tsproc.o udp.o udp6.o uds.o util.o version.o
 
-snmpd: print.o sk.o snmpd.o util.o
+snmpd: config.o hash.o msg.o pmc_common.o print.o raw.o sk.o \
+ snmpd.o tlv.o transport.o udp.o udp6.o uds.o util.o
 
 pmc: config.o hash.o msg.o pmc.o pmc_common.o print.o raw.o sk.o tlv.o \
  transport.o udp.o udp6.o uds.o util.o version.o
diff --git a/snmpd.c b/snmpd.c
index 32237a5..1718b07 100644
--- a/snmpd.c
+++ b/snmpd.c
@@ -21,8 +21,26 @@
 #include 
 #include 
 
+#include "config.h"
+#include "pmc_common.h"
+#include "print.h"
 #include "util.h"
 
+static struct pmc *pmc;
+
+static int open_pmc(struct config *cfg)
+{
+   char uds_local[MAX_IFNAME_SIZE + 1];
+   snprintf(uds_local, sizeof(uds_local), "/var/run/snmpd.%d", getpid());
+
+   pmc = pmc_create(cfg, TRANS_UDS, uds_local, 0,
+config_get_int(cfg, NULL, "domainNumber"),
+config_get_int(cfg, NULL, "transportSpecific") << 4,
+1);
+
+   return pmc ? 0 : -1;
+}
+
 static int open_snmp()
 {
snmp_enable_calllog();
@@ -35,23 +53,103 @@ static int open_snmp()
return 0;
 }
 
+static void usage(char *progname)
+{
+   fprintf(stderr,
+   "\nusage: %s [options]\n\n"
+   " -f [file] read configuration from 'file'\n"
+   " -hprints this message and exits\n"
+   " -mprint messages to stdout\n"
+   " -qdo not print messages to the syslog\n"
+   "\n",
+   progname);
+}
+
 int main(int argc, char *argv[])
 {
-   int err = 0;
+   char *config = NULL, *progname;
+   int c, err = 0, index;
+   struct option *opts;
+   struct config *cfg;
 
if (handle_term_signals()) {
return -1;
}
 
-   if (open_snmp()) {
+   cfg = config_create();
+   if (!cfg) {
return -1;
}
 
+   opts = config_long_options(cfg);
+   print_set_verbose(1);
+   print_set_syslog(0);
+
+   /* Process the command line arguments. */
+   progname = strrchr(argv[0], '/');
+   progname = progname ? 1+progname : argv[0];
+   while (EOF != (c = getopt_long(argc, argv, "f:hmq", opts, ))) {
+   switch (c) {
+   case 0:
+   if (config_parse_option(cfg, opts[index].name, optarg)) 
{
+   config_destroy(cfg);
+   return -1;
+   }
+   break;
+   case 'f':
+   config = optarg;
+   break;
+   case 'h':
+   usage(progname);
+   err = -1;
+   goto out;
+   case 'm':
+   config_set_int(cfg, "verbose", 1);
+   break;
+   case 'q':
+   config_set_int(cfg, "use_syslog", 0);
+   break;
+   case '?':
+   default:
+   usage(progname);
+   err = -1;
+   goto out;
+   }
+   }
+
+   if (config && (err = config_read(config, cfg))) {
+   err = -1;
+   goto out;
+   }
+
+   print_set_progname(progname);
+   print_set_tag(config_get_string(cfg, NULL, "message_tag"));
+   print_set_verbose(config_get_int(cfg, NULL, "verbose"));
+   print_set_syslog(config_get_int(cfg, NULL, "use_syslog"));
+   print_set_level(config_get_int(cfg, NULL, "logging_level"));
+
+
+   if (open_pmc(cfg)) {
+   err = -1;
+   goto pmc_out;
+   }
+
+   if (open_snmp()) {
+   err = -1;
+   goto snmp_out;
+   }
+
while (is_running()) {
agent_check_and_process(1);
}
 
snmp_shutdown("linuxptpAgent");
 
+snmp_out:
+   pmc_destroy(pmc);
+   msg_cleanup();
+pmc_out:
+out:
+   config_destroy(cfg);
return err;
 }
-- 
1.8.3.1


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus


--
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

[Linuxptp-devel] [PATCH_SNMP_v3 2/5] pdt: Added check if already defined

2018-06-18 Thread Anders Selhammer
TRUE and FALSE is also defined in net-snmp library. Without this check,
compilation and includes must be made in a certain order.

Signed-off-by: Anders Selhammer 
---
 pdt.h | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/pdt.h b/pdt.h
index 29ffbb5..e46b218 100644
--- a/pdt.h
+++ b/pdt.h
@@ -22,7 +22,12 @@
 
 #include 
 
-enum {FALSE, TRUE};
+#ifndef FALSE
+#define FALSE  0
+#endif
+#ifndef TRUE
+#define TRUE   1
+#endif
 
 typedefint   Boolean;
 typedef uint8_t   Enumeration8;
-- 
1.8.3.1


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus


--
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


Re: [Linuxptp-devel] [PATCH_SNMPD_v2 4/6] snmpd: Add snmp sub agent

2018-06-18 Thread Anders Selhammer
Friday, June 15, 2018 4:36 PM

> This won't work.  The 'dirs' are only the built in include paths from
> gcc, and the sysroot containing net-snmp-config will be somewhere
> else.

> Let's try something else:

> If CROSS_COMPILE is empty, just test `which net-snmp-config`, and if
> it doesn't fail, then use the output of net-snmp-config.

> If CROSS_COMPILE is non-empty, then check that `which net-snmp-config`
> is not /usr/bin/net-snmp-config.  If so, then use its output.

> If the user puts the sysroot's /usr/bin first in the PATH the we will
> have the correct net-snmp-config program.  That net-snmp-config is a
> shell script, and so it will run on the build machine in a cross
> environment.

I add this check is CROSS_COMPILE is unset, then I look for the h-files. 
If not found, snmpd will not be included. This will work in normal case but 
if you are in a cross compile environment it will just not be included. You 
can still compile. 


>I really want this series to go forward.  If you do the rest, I'll
>take care of the cross compilation issues.

Note that there are two libs that needs to be installed.
net-snmp and net-snmp-devel. 
If you only install the main lib, you will get access to the script but the libs
needed for the subagent will not be in place. This means that the script will 
probably provide the correct path but it will not find the libs when you try 
to link them in. So you need to really verify that they are in place.


Then since snmpd is a subagent, you need to start the master agent provided 
By the lib inorder to get the agent up and running properly.
The snmpd.conf needs to be replaced if you want access to the new 
implemented OIDs.


I will send in a v3 with updates for your other comments and this CROSS_COMPILE
unset check during the day.

/Anders


--
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


[Linuxptp-devel] [PATCH_SNMP_v3 3/5] snmpd: Add snmp sub agent

2018-06-18 Thread Anders Selhammer
The sub agent use net-snmp library and AgentX protocol for the
communication towards the snmp master agent.
snmpd.c should only include general setup needed for handling snmp.
Supported MIBs should be implemented in separate files.
Makefile will include snmpd if libsnmp is available during compilation.
configs/snmpd.conf should be placed in /etc/snmp/

Signed-off-by: Anders Selhammer 
---
 configs/snmpd.conf | 26 +
 incdefs.sh | 16 ++-
 ldlibs.sh  | 44 +
 makefile   | 11 ---
 optprg.sh  | 44 +
 snmpd.c| 57 ++
 6 files changed, 194 insertions(+), 4 deletions(-)
 create mode 100644 configs/snmpd.conf
 create mode 100755 ldlibs.sh
 create mode 100755 optprg.sh
 create mode 100644 snmpd.c

diff --git a/configs/snmpd.conf b/configs/snmpd.conf
new file mode 100644
index 000..8a0d929
--- /dev/null
+++ b/configs/snmpd.conf
@@ -0,0 +1,26 @@
+# Map 'linuxptp' community to the 'LinuxPtpUser'
+# Map 'public' community to the 'AllUser'
+#   sec.namesource  community
+com2sec LinuxPtpUserdefault linuxptp
+com2sec AllUser default public
+
+# Map 'LinuxPtpUser' to 'LinuxPtpGroup' for SNMP Version 2c
+# Map 'AllUser' to 'AllGroup' for SNMP Version 2c
+#   sec.model   sec.name
+group   LinuxPtpGroup   v2c LinuxPtpUser
+group   AllGroupv2c AllUser
+
+# Define 'SystemView', which includes everything under .1.3.6.1.2.1.241
+# Define 'AllView', which includes everything under .1
+#   incl/excl   subtree
+viewSystemView  included.1.3.6.1.2.1.241
+viewAllView included.1
+
+# Give 'ConfigGroup' read access to objects in the view 'SystemView'
+# Give 'AllGroup' read access to objects in the view 'AllView'
+#   context model   level   prefix  readwrite  
 notify
+access  LinuxPtpGroup   ""  any noauth  exact   SystemView  none   
 none
+access  AllGroup""  any noauth  exact   AllView none   
 none
+
+# turn on the AgentX master agent support
+master agentx
diff --git a/incdefs.sh b/incdefs.sh
index 19e620e..7f86b94 100755
--- a/incdefs.sh
+++ b/incdefs.sh
@@ -19,7 +19,8 @@
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 #
-# Look for functional prototypes in the C library.
+# Look for functional prototypes in the C library
+# Look for libsnmp presence.
 #
 user_flags()
 {
@@ -50,6 +51,19 @@ user_flags()
fi
done
done
+
+   # Look for libsnmp presence
+   if test -z ${CROSS_COMPILE}; then
+   for d in $dirs; do
+   files=$(find $d -type f -name net-snmp-agent-includes.h)
+   for f in $files; do
+   if grep -q NET_SNMP_AGENT_INCLUDES_H $f; then
+   printf " -I. `net-snmp-config --cflags`"
+   break 2
+   fi
+   done
+   done
+   fi
 }
 
 #
diff --git a/ldlibs.sh b/ldlibs.sh
new file mode 100755
index 000..c3b6625
--- /dev/null
+++ b/ldlibs.sh
@@ -0,0 +1,44 @@
+#!/bin/sh
+#
+# Discover the LDLIBS to use during compilation.
+#
+# Copyright (C) 2018 Anders Selhammer 
+#
+# 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-1301 USA.
+
+#
+# Look for libsnmp presence.
+#
+user_libs()
+{
+   # Get list of directories searched for header files.
+   dirs=$(echo "" | ${CROSS_COMPILE}cpp -Wp,-v 2>&1 >/dev/null | grep ^" 
/")
+
+   # Look for libsnmp presence
+   if test -z ${CROSS_COMPILE}; then
+   for d in $dirs; do
+   files=$(find $d -type f -name net-snmp-agent-includes.h)
+   for f in $files; do
+   if grep -q NET_SNMP_AGENT_INCLUDES_H $f; then
+   printf " `net-snmp-config --agent-libs`"
+   break 2
+   fi
+   done
+   done
+   fi
+}