Blame test/simulation/clknetsim/README

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