[Git][NTPsec/ntpsec][master] 10 commits: Improved instrumentation.

Eric S. Raymond gitlab at mg.gitlab.com
Wed Dec 7 03:07:33 UTC 2016


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
50995a61 by Eric S. Raymond at 2016-12-06T19:44:35-05:00
Improved instrumentation.

- - - - -
622f757e by Eric S. Raymond at 2016-12-06T19:44:35-05:00
More instrumentation for checking pyntpdig correctness.

- - - - -
d9629868 by Matt Selsky at 2016-12-06T19:44:35-05:00
Remove variables that were assigned but never used.

pyflakes reported this as:
1302: local variable 'last_older' is assigned to but never used
1303: local variable 'addr_older' is assigned to but never used
1304: local variable 'highwater' is assigned to but never used

- - - - -
31895e50 by Matt Selsky at 2016-12-06T19:44:35-05:00
Remove tracing added in "Fix function name in ntpsweep"

- - - - -
33759049 by Matt Selsky at 2016-12-06T19:44:35-05:00
Spelling

- - - - -
fac79639 by Matt Selsky at 2016-12-06T19:44:35-05:00
Fix update ntp.util.rfc3339 so that all tests pass

Treat the fractional seconds as a string so that we don't change the precision

- - - - -
9c10b9b3 by Matt Selsky at 2016-12-06T19:44:35-05:00
Fix import in ntpq to use updated module name

Import cleanup was missed in "Python namespace cleanup.  No actual code
changes."

- - - - -
8788cfa7 by Eric S. Raymond at 2016-12-06T19:44:35-05:00
Add tstofloat to the Python library.

- - - - -
9d91bf15 by Eric S. Raymond at 2016-12-06T19:44:35-05:00
Address GitLab issue #196 ntpq mrv with lo=hi shows same rv twice

- - - - -
c6addedd by Eric S. Raymond at 2016-12-06T22:06:03-05:00
Address GitKab issue #195: ntpq only shows mrv...

...after the association list is primed

- - - - -


8 changed files:

- docs/includes/ntpkeygen-body.txt
- libntp/pymodule.c
- ntpdig/main.c
- ntpdig/pyntpdig
- ntpq/ntpq
- pylib/packet.py
- pylib/util.py
- tests/pylib/test_util.py


Changes:

=====================================
docs/includes/ntpkeygen-body.txt
=====================================
--- a/docs/includes/ntpkeygen-body.txt
+++ b/docs/includes/ntpkeygen-body.txt
@@ -99,7 +99,7 @@ automated means on the other subnet hosts. This file is needed to
 authenticate some remote configuration commands used by the {ntpqman}
 utility.
 
-Comments may appear in the file, and are preceeded with the +#+
+Comments may appear in the file, and are preceded with the +#+
 character.  
 
 Following any headers the keys are entered one per line in the


=====================================
libntp/pymodule.c
=====================================
--- a/libntp/pymodule.c
+++ b/libntp/pymodule.c
@@ -104,6 +104,22 @@ ntpc_lfptofloat(PyObject *self, PyObject *args)
 }
 
 static PyObject *
+ntpc_tstofloat(PyObject *self, PyObject *args)
+{
+    int64_t ti;
+    l_fp ts;
+    struct timespec tt;
+ 
+    UNUSED_ARG(self);
+    if (!PyArg_ParseTuple(args, "i", &ti))
+	return NULL;
+    ts.l_ui = ti >> 32;
+    ts.l_uf = ti & 0xFFFFFFFFUL;
+    tt = lfp_stamp_to_tspec(ts, NULL);
+    return Py_BuildValue("d", tt.tv_sec + tt.tv_nsec * 1e-9);
+}
+
+static PyObject *
 ntpc_set_tod(PyObject *self, PyObject *args)
 {
     struct timespec ts;
@@ -153,6 +169,8 @@ static PyMethodDef ntpc_methods[] = {
      PyDoc_STR("Convert a time stamp to something readable.")},
     {"lfptofloat",     	ntpc_lfptofloat,  	METH_VARARGS,
      PyDoc_STR("NTP l_fp to Python-style float time.")},
+    {"tstofloat",     	ntpc_tstofloat,  	METH_VARARGS,
+     PyDoc_STR("NTP integral timestamp to Python-style float time.")},
     {"set_tod",     	ntpc_set_tod,   	METH_VARARGS,
      PyDoc_STR("Set time to nanosecond precision.")},
     {"adj_systime",    	ntpc_adj_systime,   	METH_VARARGS,


=====================================
ntpdig/main.c
=====================================
--- a/ntpdig/main.c
+++ b/ntpdig/main.c
@@ -14,6 +14,7 @@
 #include "log.h"
 #include "libntp.h"
 #include "ntp_intres.h"
+#include "timespecops.h"
 
 bool shutting_down;
 bool time_derived;
@@ -1510,17 +1511,26 @@ offset_calculation(
 #ifdef DEBUG
 	if (debug > 3) {
 		double ftime;
+		struct timespec ts_tmp;
 		pkt_output(rpkt, rpktl, stdout);
 		printf("ntpdig rootdelay: %f\n", FPTOD(p_rdly));
 		printf("ntpdig rootdisp: %f\n", FPTOD(p_rdsp));
 		printf("ntpdig syncdist: %f\n", *synch_distance);
-		printf("ntpdig offset_calculation: reftime: ");
+		ts_tmp = lfp_stamp_to_tspec(p_ref, NULL);
+		ftime = ts_tmp.tv_sec + ts_tmp.tv_nsec / 1000000.0;
+		printf("ntpdig offset_calculation: ref: %f ", ftime);
 		l_fp_output(&p_ref, stdout);
-		printf("ntpdig offset_calculation: org: ");
+		ts_tmp = lfp_stamp_to_tspec(p_org, NULL);
+		ftime = ts_tmp.tv_sec + ts_tmp.tv_nsec / 1000000.0;
+		printf("ntpdig offset_calculation: org: %f ", ftime);
 		l_fp_output(&p_org, stdout);
-		printf("ntpdig offset_calculation: rec: ");
+		ts_tmp = lfp_stamp_to_tspec(p_rec, NULL);
+		ftime = ts_tmp.tv_sec + ts_tmp.tv_nsec / 1000000.0;
+		printf("ntpdig offset_calculation: rec: %f ", ftime);
 		l_fp_output(&p_rec, stdout);
-		printf("ntpdig offset_calculation: xmt: ");
+		ts_tmp = lfp_stamp_to_tspec(p_xmt, NULL);
+		ftime = ts_tmp.tv_sec + ts_tmp.tv_nsec / 1000000.0;
+		printf("ntpdig offset_calculation: xmt: %f ", ftime);
 		l_fp_output(&p_xmt, stdout);
 		ftime = tv_dst->tv_sec + tv_dst->tv_usec / 1000.0;
 		printf("ntpdig dst %f\n", ftime);


=====================================
ntpdig/pyntpdig
=====================================
--- a/ntpdig/pyntpdig
+++ b/ntpdig/pyntpdig
@@ -359,12 +359,18 @@ if __name__ == '__main__':
         arguments = ["localhost"]
 
     if replay:
-        pkt = ntp.packet.SyncPacket(replay.decode("hex"))
-        print(repr(pkt))
+        (packet, dst) = replay.split(":")
+        pkt = ntp.packet.SyncPacket(packet.decode("hex"))
+        pkt.received = ntp.packet.SyncPacket.posix_to_ntp(float(dst))
+        #print(repr(pkt))
+        def hexstamp(n):
+            return "%08x.%08x" % (n >> 32, n & 0x00000000ffffffff)
+        print("org t1: %s rec t2: %s" % (hexstamp(pkt.t1()), hexstamp(pkt.t2())))
+        print("xmt t3: %s dst t4: %s" % (hexstamp(pkt.t3()), hexstamp(pkt.t4())))
         pkt.posixize()
+        print("org t1: %f rec t2: %f" % (pkt.t1(), pkt.t2()))
         print("xmt t3: %f dst t4: %f" % (pkt.t3(), pkt.t4()))
         print("rec-org t21: %f  xmt-dst t34: %f" % (pkt.t2() - pkt.t1(), pkt.t3() - pkt.t4()))
-        raise SystemExit(0)
 
     returned = []
     for server in concurrent_hosts:


=====================================
ntpq/ntpq
=====================================
--- a/ntpq/ntpq
+++ b/ntpq/ntpq
@@ -19,7 +19,7 @@ try:
     import ntp.util
     import ntp.ntpc
     import ntp.version
-    import ntp.ntp_control
+    import ntp.control
 except ImportError as e:
     sys.stderr.write("ntpq: can't find Python NTP library -- check PYTHONPATH.\n")
     sys.stderr.write("%s\n" % e)
@@ -348,8 +348,6 @@ usage: help [ command ]
         if not self.__dogetassoc():
             return
         if self.showhostnames:
-            print("HELLO")
-            print(ntp.util.termsize())
             termwidth = ntp.util.termsize().width
         else:
             termwidth = None	# Default width
@@ -406,7 +404,9 @@ usage: help [ command ]
                 return -1
             else:
                 return 0
-        elif line.startswith("&"):
+        if not self.peers:
+            self.__dogetassoc()
+        if line.startswith("&"):
             try:
                 idx = int(line[1:].split()[0])
             except:
@@ -441,7 +441,9 @@ usage: help [ command ]
         hi = self.__assoc_valid(tokens[1])
         if lo < 0 or hi < 0 or hi < lo: 
             return ()
-        return (lo, hi)
+        if lo == hi:
+            return(lo,)
+        return range(lo, hi+1)
 
     def printvars(self, variables, dtype, quiet):
         "Dump variables in raw (actually, semi-cooked) mode."
@@ -500,7 +502,7 @@ usage: help [ command ]
                         )
                         for (i, n) in enumerate(tstflagnames):
                             if (1 << i) & value:
-                                item += tstflagnames + " "
+                                item += tstflagnames[i] + " "
                         item = item[:-1]
                 else:
                     item += repr(value)


=====================================
pylib/packet.py
=====================================
--- a/pylib/packet.py
+++ b/pylib/packet.py
@@ -1299,9 +1299,6 @@ class ControlSession:
                     rawhook(variables)
 
                 # Analyze the contents of this response into a span structure
-                last_older = None
-                addr_older = None
-                highwater = len(span.entries)
                 for (tag, val) in variables.items():
                     if tag =="now":
                         span.now = ntp.ntpc.lfptofloat(val)


=====================================
pylib/util.py
=====================================
--- a/pylib/util.py
+++ b/pylib/util.py
@@ -22,10 +22,13 @@ def stdversion():
 
 def rfc3339(t):
     "RFC 3339 string from Unix time, including fractional second."
-    subsec = t - int(t)
-    t -= subsec
     rep = time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime(t))
-    rep += ("%f" % subsec)[1:] + "Z"
+    t = str(t)
+    if "." in t:
+        subsec = t.split(".", 1)[1]
+        if int(subsec) > 0:
+            rep += "." + subsec
+    rep += "Z"
     return rep
 
 def portsplit(hostname):


=====================================
tests/pylib/test_util.py
=====================================
--- a/tests/pylib/test_util.py
+++ b/tests/pylib/test_util.py
@@ -6,6 +6,7 @@ class TestPylibUtilMethods(unittest.TestCase):
     def test_rfc3339(self):
         self.assertEqual(ntp.util.rfc3339(1480999786), '2016-12-06T04:49:46Z')
         self.assertEqual(ntp.util.rfc3339(1480999786.5), '2016-12-06T04:49:46.5Z')
+        self.assertEqual(ntp.util.rfc3339(1480999786.025), '2016-12-06T04:49:46.025Z')
 
     def test_portsplit(self):
         self.assertEqual(ntp.util.portsplit("host.invalid"), ("host.invalid", ""))



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/58a58bec36be8485b72eeffe5c508e6629eff838...c6addedd79a967f190ccb839141b95e6bde34d6b
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20161207/7b65a261/attachment.html>


More information about the vc mailing list