Blame clknetsim-3f5ef9eb72d2182fab4ea06ad42f6f3e9dc802f5/README

Packit Service 623930
Clock and Network Simulator (clknetsim)
Packit Service 623930
=======================================
Packit Service 623930
Packit Service 623930
clknetsim is a tool designed to test programs which synchronize the system
Packit Service 623930
clock, either over network or from a hardware reference clock. It simulates a
Packit Service 623930
system or a number of systems connected to each other in a network and the
Packit Service 623930
tested programs discipline the simulated system clocks. It can be used to
Packit Service 623930
quickly test how well the programs control the system clocks in various
Packit Service 623930
conditions or to test the network protocols.
Packit Service 623930
Packit Service 623930
The tested programs are not modified in order to be included in the simulation,
Packit Service 623930
but they have some system calls redirected by a clknetsim library, which is
Packit Service 623930
loaded by the LD_PRELOAD feature of the dynamic linker, to a clknetsim server,
Packit Service 623930
which runs the simulation and collects several statistics about each client.
Packit Service 623930
The server and the clients run on a single host, they communicate via a UNIX
Packit Service 623930
domain socket. The simulation runs as fast as the host system is capable of,
Packit Service 623930
with two simulated systems it is usually three or four orders of magnitude
Packit Service 623930
faster than real time.
Packit Service 623930
Packit Service 623930
Supported programs:
Packit Service 623930
- chronyd and chronyc from chrony (http://chrony.tuxfamily.org/)
Packit Service 623930
- ntpd, ntpdate, sntp and ntpq from ntp (http://www.ntp.org/)
Packit Service 623930
- ntpd from busybox (http://www.busybox.net/)
Packit Service 623930
- ptp4l, phc2sys, pmc and nsm from linuxptp (http://linuxptp.sourceforge.net/)
Packit Service 623930
Packit Service 623930
Limitations:
Packit Service 623930
- only Linux is supported
Packit Service 623930
- the fake system calls implement only a minimal functionality required to
Packit Service 623930
  keep the supported clients working
Packit Service 623930
- the simulated system clock advances only on select(), poll() or usleep()
Packit Service 623930
  calls, this means the client sees the CPU as infinitely fast
Packit Service 623930
- adjtimex() frequency and tick changes happen immediately, the kernel has
Packit Service 623930
  infinite HZ
Packit Service 623930
- adjtime() and PLL updates happen in one second intervals in the simulated
Packit Service 623930
  time instead of the uncorrected simulated system time, all clocks are updated
Packit Service 623930
  at the same time
Packit Service 623930
Packit Service 623930
Packit Service 623930
Usage
Packit Service 623930
-----
Packit Service 623930
Packit Service 623930
The clknetsim server is started with two required arguments, the first one is
Packit Service 623930
path to a configuration file describing the network and clocks and the second
Packit Service 623930
argument is the number of simulated nodes. The simulation is started when all
Packit Service 623930
clients are connected.
Packit Service 623930
Packit Service 623930
The clients are started under a non-root user, with preloaded clknetsim.so and
Packit Service 623930
the environment variable CLKNETSIM_NODE set to the number of the client.
Packit Service 623930
Optionally, the environment variable CLKNETSIM_SOCKET can be set to the path of
Packit Service 623930
the UNIX domain socket which is used to connect to the server, clknetsim.sock
Packit Service 623930
in current directory is used by default. The CLKNETSIM_START_DATE variable can
Packit Service 623930
be used to specify in seconds since 1970 when should the simulated time start,
Packit Service 623930
1262304000 by default (2010-01-01 0:00 UTC). The CLKNETSIM_CONNECT_TIMEOUT
Packit Service 623930
variable sets the server connection timeout, 10 seconds by default.
Packit Service 623930
Packit Service 623930
The simulated network is available to the clients as one or more Ethernet
Packit Service 623930
networks with IPv4 addressing. All nodes have interfaces to all networks.
Packit Service 623930
Their addresses are 192.168.122+s.n, where n is the number of the node
Packit Service 623930
(starting at 1) and s is the number of the network (starting at 1). The
Packit Service 623930
broadcast addresses are 192.168.122+s.255.
Packit Service 623930
Packit Service 623930
At the end of the simulation clock and network statistics are printed.
Packit Service 623930
clknetsim has options which can be used to control for how long the
Packit Service 623930
simulation should run, or if the frequency, offset or network log should be
Packit Service 623930
written. clknetsim -h prints a complete list of available options.
Packit Service 623930
Packit Service 623930
A minimal example how to start a simulation:
Packit Service 623930
Packit Service 623930
$ LD_PRELOAD=./clknetsim.so CLKNETSIM_NODE=1 chronyd -d -f chrony.conf &
Packit Service 623930
$ LD_PRELOAD=./clknetsim.so CLKNETSIM_NODE=2 ntpd -n -c ntp.conf &
Packit Service 623930
$ ./clknetsim -o log.offset -l 100000 clknetsim.conf 2
Packit Service 623930
Packit Service 623930
clknetsim.conf:
Packit Service 623930
node2_freq = (sum (* 1e-8 (normal)))
Packit Service 623930
node1_delay2 = (+ 1e-1 (* 1e-3 (exponential)))
Packit Service 623930
node2_delay1 = (+ 1e-1 (* 1e-3 (exponential)))
Packit Service 623930
Packit Service 623930
chrony.conf:
Packit Service 623930
pidfile chronyd.pid
Packit Service 623930
local stratum 1
Packit Service 623930
allow
Packit Service 623930
Packit Service 623930
ntp.conf:
Packit Service 623930
pidfile ntpd.pid
Packit Service 623930
server 192.168.123.1
Packit Service 623930
Packit Service 623930
The clknetsim.bash file contains bash functions which can create the
Packit Service 623930
configuration in several network settings, start the simulation, stop the
Packit Service 623930
clients and process the results. The examples subdirectory contains an example
Packit Service 623930
script for each supported client. The above example can be written in a bash
Packit Service 623930
script as:
Packit Service 623930
Packit Service 623930
CLKNETSIM_PATH=.
Packit Service 623930
. ./clknetsim.bash
Packit Service 623930
Packit Service 623930
generate_config1 2 0.0 "(sum (* 1e-8 (normal)))" "(+ 1e-1 (* 1e-3 (exponential)))"
Packit Service 623930
start_client 1 chrony "local stratum 1"
Packit Service 623930
start_client 2 ntp "server 192.168.123.1"
Packit Service 623930
start_server 2 -o log.offset -l 100000
Packit Service 623930
Packit Service 623930
cat tmp/stats
Packit Service 623930
Packit Service 623930
Packit Service 623930
Configuration file
Packit Service 623930
------------------
Packit Service 623930
Packit Service 623930
The configuration file is a text file containing a list of assignments, each
Packit Service 623930
specified on a separate line, and comments using # as delimiter. Each node has
Packit Service 623930
several variables, which configure the system clock, the reference clock and
Packit Service 623930
the network delays to other nodes in the network. They can be set either to an
Packit Service 623930
integer value, a floating-point value or a number generating expression written
Packit Service 623930
in a Lisp-style syntax.
Packit Service 623930
Packit Service 623930
Variables:
Packit Service 623930
- nodeX_freq = float | expr
Packit Service 623930
  the system clock frequency error in terms of gained seconds per second of
Packit Service 623930
  simulated time, if an expression is specified, the expression is evaluated and
Packit Service 623930
  frequency updated once per simulated second (or at the rate specified with
Packit Service 623930
  the -R option), the allowed range is (-0.2, 0.2), the default is 0
Packit Service 623930
- nodeX_delayY = expr
Packit Service 623930
  the network delay for packets sent from node X to node Y in seconds, the
Packit Service 623930
  expression is evaluated for each sent packet, a negative value means the
Packit Service 623930
  packet will be dropped, there is no default (packets are dropped)
Packit Service 623930
- nodeX_offset = float
Packit Service 623930
  the initial time error of the system clock in seconds, the default is 0
Packit Service 623930
- nodeX_start = float
Packit Service 623930
  the time in seconds when will be the node started, the default is 0
Packit Service 623930
- nodeX_refclock = expr
Packit Service 623930
  the reference clock time error in seconds, the clock can be accessed by the
Packit Service 623930
  client via shared memory (NTP SHM protocol) or as a PTP hardware clock (PHC)
Packit Service 623930
  via the clock_gettime() function, there is no default (the clock is disabled)
Packit Service 623930
- nodeX_step = expr
Packit Service 623930
  the extra time step applied once per second (or at the rate specified with
Packit Service 623930
  the -R option) in seconds, there is no default (no extra steps are applied)
Packit Service 623930
- nodeX_shift_pll = integer
Packit Service 623930
  kernel PLL parameter, the default is 2
Packit Service 623930
- nodeX_pll_clamp = 1 | 0
Packit Service 623930
  kernel PLL parameter, the default is 0
Packit Service 623930
- nodeX_fll_mode2 = 1 | 0
Packit Service 623930
  kernel FLL parameter, the default is 0
Packit Service 623930
Packit Service 623930
Functions and their parameters supported in the expressions:
Packit Service 623930
  (* [expr | float] ...) - multiplication
Packit Service 623930
  (+ [expr | float] ...) - addition
Packit Service 623930
  (% [expr | float] ...) - modulo
Packit Service 623930
  (sum [expr | float] ...)
Packit Service 623930
                         - summation over consecutive evaluation of parameters
Packit Service 623930
  (uniform)              - random number generator with standard uniform
Packit Service 623930
                           distribution
Packit Service 623930
  (normal)               - random number generator with standard normal
Packit Service 623930
                           distribution
Packit Service 623930
  (exponential)          - random number generator with exponential distribution
Packit Service 623930
                           (lambda = 1)
Packit Service 623930
  (poisson lambda)       - random number generator with poisson distribution
Packit Service 623930
  (file "datafile")      - number generator reading floating-point values from
Packit Service 623930
                           the specified file in an inifinite loop
Packit Service 623930
  (pulse high low)       - pulse wave generator
Packit Service 623930
  (sine period)          - sine wave generator
Packit Service 623930
  (cosine period)        - cosine wave generator
Packit Service 623930
  (triangle period)      - triangle wave generator
Packit Service 623930
  (equal epsilon [expr | float] ...)
Packit Service 623930
                         - returns 1.0 if the values of all parameters are
Packit Service 623930
                           equal within epsilon, 0.0 otherwise
Packit Service 623930
  (max [expr | float] ...)
Packit Service 623930
                         - returns maximum value
Packit Service 623930
  (min [expr | float] ...)
Packit Service 623930
                         - returns minimum value
Packit Service 623930
Packit Service 623930
Variables available in network delay expressions:
Packit Service 623930
  time                   - current network time
Packit Service 623930
  from                   - number of the sending node
Packit Service 623930
  to                     - number of the receiving node
Packit Service 623930
  port                   - receiving port number
Packit Service 623930
  length                 - length of the packet
Packit Service 623930
  subnet                 - number of the Ethernet network in which
Packit Service 623930
                           the packet was sent
Packit Service 623930
Packit Service 623930
An example:
Packit Service 623930
Packit Service 623930
# node1 is an NTP server, it has an accurate and absolutely stable clock 
Packit Service 623930
node1_offset = 0
Packit Service 623930
node1_freq = 0
Packit Service 623930
Packit Service 623930
# node2 is an NTP client, it starts with 0.1s offset and has
Packit Service 623930
# 0.01ppm/s frequency wander
Packit Service 623930
node2_offset = 0.1
Packit Service 623930
node2_freq = (sum (* 1e-8 (normal)))
Packit Service 623930
Packit Service 623930
# network delays between the two nodes have 10ms mean and 100us
Packit Service 623930
# jitter in both directions
Packit Service 623930
node1_delay2 = (+ 9.9e-3 (* 100e-6 (exponential)))
Packit Service 623930
node2_delay1 = (+ 9.9e-3 (* 100e-6 (exponential)))
Packit Service 623930
Packit Service 623930
Packit Service 623930
Author
Packit Service 623930
------
Packit Service 623930
Packit Service 623930
Miroslav Lichvar <mlichvar@redhat.com>
Packit Service 623930
Packit Service 623930
Packit Service 623930
License
Packit Service 623930
-------
Packit Service 623930
Packit Service 623930
Copyright (C) 2010, 2011, 2012  Miroslav Lichvar <mlichvar@redhat.com>
Packit Service 623930
Packit Service 623930
This program is free software; you can redistribute it and/or modify
Packit Service 623930
it under the terms of the GNU General Public License as published by
Packit Service 623930
the Free Software Foundation; either version 2 of the License, or
Packit Service 623930
(at your option) any later version.
Packit Service 623930
Packit Service 623930
This program is distributed in the hope that it will be useful,
Packit Service 623930
but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 623930
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 623930
GNU General Public License for more details.
Packit Service 623930
Packit Service 623930
You should have received a copy of the GNU General Public License
Packit Service 623930
along with this program.  If not, see <http://www.gnu.org/licenses/>.