Skip to main content
Version: 2.6.7

Simulate Time Faults

This document describes how to use Chaosd to simulate a time offset scenario. You can create experiments either in command-line mode or service mode.

Parameters for simulating time faults​

Configuration itemAbbreviationService mode fieldDescriptionTypeValue
time-offset—time-offsetSpecifies the length of time offset.stringstring type, such as -5m. Required.
clock-ids-slice—clock-ids-sliceSpecifies the ID of the clock that will be offset. Multiple clock IDs should be separated by a comma. See the clock_gettime documentation for details.stringstring type. The default value is "CLOCK_REALTIME".
pid—pidThe identifier of the process.intint type. Required.

Simulate time faults using the command-line mode​

Before creating an experiment, you can run the following command to check the options of time faults:

chaosd attack clock -h

The result is as follows:

$ chaosd attack clock -h

clock skew

Usage:
chaosd attack clock attack [flags]

Flags:
-c, --clock-ids-slice string The identifier of the particular clock on which to act.More clock description in linux kernel can be found in man page of clock_getres, clock_gettime, clock_settime.Muti clock ids should be split with "," (default "CLOCK_REALTIME")
-h, --help help for clock
-p, --pid int Pid of target program.
-t, --time-offset string Specifies the length of time offset.

Global Flags:
--log-level string the log level of chaosd, the value can be 'debug', 'info', 'warn' and 'error'
--uid string the experiment ID

Quick Example​

Prepare test program:

cat > time.c << EOF
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <sys/types.h>

int main() {
printf("PID : %ld\n", (long)getpid());
struct timespec ts;
for(;;) {
clock_gettime(CLOCK_REALTIME, &ts);
printf("Time : %lld.%.9ld\n", (long long)ts.tv_sec, ts.tv_nsec);
sleep(10);
}
}
EOF

gcc -o get_time ./time.c

Then execute get_time and try to attack it. The following is an example:

chaosd attack clock -p $PID -t 11s

Simulate time faults using the service mode​

Run the test program in Quick Example, and then use the following command to create a time fault experiment:

curl -X POST 172.16.112.130:31767/api/attack/clock -H "Content-Type:application/json" -d '{"pid":123, "time-offset":"11s"}'