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.

Create experiments using command-line mode

This section describes how to create time fault experiments using commands.

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

  1. chaosd attack clock -h

The result is as follows:

  1. $ chaosd attack clock -h
  2. clock skew
  3. Usage:
  4. chaosd attack clock attack [flags]
  5. Flags:
  6. -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")
  7. -h, --help help for clock
  8. -p, --pid int Pid of target program.
  9. -t, --time-offset string Specifies the length of time offset.
  10. Global Flags:
  11. --log-level string the log level of chaosd, the value can be 'debug', 'info', 'warn' and 'error'
  12. --uid string the experiment ID

Quick Example

Prepare test program:

  1. cat > time.c << EOF
  2. #include <stdio.h>
  3. #include <time.h>
  4. #include <unistd.h>
  5. #include <sys/types.h>
  6. int main() {
  7. printf("PID : %ld\n", (long)getpid());
  8. struct timespec ts;
  9. for(;;) {
  10. clock_gettime(CLOCK_REALTIME, &ts);
  11. printf("Time : %lld.%.9ld\n", (long long)ts.tv_sec, ts.tv_nsec);
  12. sleep(10);
  13. }
  14. }
  15. EOF
  16. gcc -o get_time ./time.c

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

  1. chaosd attack clock -p $PID -t 11s

Configurations of simulating time faults

ParameterTypeNoteDefault valueRequiredExample
timeOffsetstringSpecifies the length of time offset.NoneYes-5m
clockIds[]stringSpecifies the ID of clock that will be offset. See the clock_gettime documentation for details.[“CLOCK_REALTIME”]No[“CLOCK_REALTIME”, “CLOCK_MONOTONIC”]
pidstringThe identifier of the process.NoneYes1

Create experiments using service mode

(ongoing update)