模拟时间故障
非官方测试版翻译
本页面由 PageTurner AI 翻译(测试版)。未经项目官方认可。 发现错误? 报告问题 →
本文档介绍如何使用 Chaosd 模拟时间偏移场景。您可以通过命令行模式或服务模式创建实验。
使用命令行模式创建实验
本节介绍如何通过命令创建时间故障实验。
在创建实验前,您可以运行以下命令查看时间故障的选项:
chaosd attack clock -h
结果如下:
$ 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
快速示例
准备测试程序:
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
然后执行 get_time 并尝试攻击它。示例如下:
chaosd attack clock -p $PID -t 11s
模拟时间故障的配置
| Parameter | Type | Note | Default value | Required | Example |
|---|---|---|---|---|---|
| timeOffset | string | Specifies the length of time offset. | None | Yes | -5m |
| clockIds | []string | Specifies the ID of clock that will be offset. See the clock_gettime documentation for details. | ["CLOCK_REALTIME"] | No | ["CLOCK_REALTIME", "CLOCK_MONOTONIC"] |
| pid | string | The identifier of the process. | None | Yes | 1 |
使用服务模式创建实验
(持续更新中)