Simulate Network Faults
This document introduces how to use Chaosd to simulate network faults. The simulations can be completed by modifying network routing and traffic flow control using iptables, ipsets, tc, etc.
note
Make sure the NET_SCH_NETEM module is installed in the Linux kernel. If you are using CentOS, you can install the module through the kernel-modules-extra package. Most other Linux distributions have installed it already by default.
This section introduces how to create network fault experiments using command-line mode.
Before creating an experiment, you can run the following command to check the types of network faults supported by Chaosd:
The output is as follows:
Usage:
chaosd attack network [command]
Available Commands:
corrupt corrupt network packet
delay delay network
duplicate duplicate network packet
loss loss network packet
Flags:
-h, --help help for network
Global Flags:
--log-level string the log level of chaosd, the value can be 'debug', 'info', 'warn' and 'error'
Use "chaosd attack network [command] --help" for more information about a command.
Currently, you can simulate four experimental scenarios using Chaosd: network corruption, network latency, network duplication, and network loss.
You can run the command below to see the configuration of simulated network corruption using Chaosd.
The command for network corruption
The command is as follows:
chaosd attack network corrupt --help
The output is as follows:
corrupt network packet
Usage:
chaosd attack network corrupt [flags]
Flags:
-c, --correlation string correlation is percentage (10 is 10%) (default "0")
-d, --device string the network interface to impact
-e, --egress-port string only impact egress traffic to these destination ports, use a ',' to separate or to indicate the range, such as 80, 8001:8010. It can only be used in conjunction with -p tcp or -p udp
-h, --help help for corrupt
-H, --hostname string only impact traffic to these hostnames
-i, --ip string only impact egress traffic to these IP addresses
--percent string percentage of packets to corrupt (10 is 10%) (default "1")
-p, --protocol string only impact traffic using this IP protocol, supported: tcp, udp, icmp, all
Global Flags:
--log-level string the log level of chaosd, the value can be 'debug', 'info', 'warn' and 'error'
Configuration items related to network corruption
An example of network corruption
Run the following command to simulate network corruption:
chaosd attack network corrupt -d eth0 -i 172.16.4.4 --percent 50
If the command runs successfully, the output is as follows:
Attack network successfully, uid: 4eab1e62-8d60-45cb-ac85-3c17b8ac4825
You can run the command below to see the configuration of simulated network latency using Chaosd.
The command for network latency
The command is as follows:
The output is as follows:
delay network
Usage:
chaosd attack network delay [flags]
Flags:
-c, --correlation string correlation is percentage (10 is 10%) (default "0")
-d, --device string the network interface to impact
-e, --egress-port string only impact egress traffic to these destination ports, use a ',' to separate or to indicate the range, such as 80, 8001:8010. It can only be used in conjunction with -p tcp or -p udp
-h, --help help for delay
-H, --hostname string only impact traffic to these hostnames
-i, --ip string only impact egress traffic to these IP addresses
-j, --jitter string jitter time, time units: ns, us (or µs), ms, s, m, h.
-l, --latency string delay egress time, time units: ns, us (or µs), ms, s, m, h.
-p, --protocol string only impact traffic using this IP protocol, supported: tcp, udp, icmp, all
-s, --source-port string only impact egress traffic from these source ports, use a ',' to separate or to indicate the range, such as 80, 8001:8010. It can only be used in conjunction with -p tcp or -p udp
Global Flags:
--log-level string the log level of chaosd, the value can be 'debug', 'info', 'warn' and 'error'
Configuration items related to network latency
The related configuration items are described as follows:
An example of network latency
Run the following command to simulate network latency:
chaosd attack network delay -d eth0 -i 172.16.4.4 -l 10ms
If the command runs successfully, the output is as follows:
Attack network successfully, uid: 4b23a0b5-e193-4b27-90a7-3e04235f32ab
You can run the command below to see the configuration of simulated network duplication using Chaosd:
The command for network duplication
The output is as follows:
duplicate network packet
Usage:
chaosd attack network duplicate [flags]
-c, --correlation string correlation is percentage (10 is 10%) (default "0")
-d, --device string the network interface to impact
-e, --egress-port string only impact egress traffic to these destination ports, use a ',' to separate or to indicate the range, such as 80, 8001:8010. It can only be used in conjunction with -p tcp or -p udp
-h, --help help for duplicate
-H, --hostname string only impact traffic to these hostnames
-i, --ip string only impact egress traffic to these IP addresses
--percent string percentage of packets to duplicate (10 is 10%) (default "1")
-p, --protocol string only impact traffic using this IP protocol, supported: tcp, udp, icmp, all
-s, --source-port string only impact egress traffic from these source ports, use a ',' to separate or to indicate the range, such as 80, 8001:8010. It can only be used in conjunction with -p tcp or -p udp
Global Flags:
--log-level string the log level of chaosd, the value can be 'debug', 'info', 'warn' and 'error'
Configuration items related to network duplication
The related configuration items are described as follows:
An example of network duplication
Run the following command to simulate network duplication:
If the command runs successfully, the output is as follows:
Attack network successfully, uid: 7bcb74ee-9101-4ae4-82f0-e44c8a7f113c
You can run the command below to see the configuration of simulated network loss using Chaosd:
The command for network loss
The command is as follows:
chaosd attack network loss --help
The output is as follows:
loss network packet
Usage:
chaosd attack network loss [flags]
Flags:
-c, --correlation string correlation is percentage (10 is 10%) (default "0")
-d, --device string the network interface to impact
-e, --egress-port string only impact egress traffic to these destination ports, use a ',' to separate or to indicate the range, such as 80, 8001:8010. It can only be used in conjunction with -p tcp or -p udp
-h, --help help for loss
-H, --hostname string only impact traffic to these hostnames
-i, --ip string only impact egress traffic to these IP addresses
--percent string percentage of packets to drop (10 is 10%) (default "1")
-p, --protocol string only impact traffic using this IP protocol, supported: tcp, udp, icmp, all
-s, --source-port string only impact egress traffic from these source ports, use a ',' to separate or to indicate the range, such as 80, 8001:8010. It can only be used in conjunction with -p tcp or -p udp
Global Flags:
--log-level string the log level of chaosd, the value can be 'debug', 'info', 'warn' and 'error'
Configuration items related to network loss
The related configuration items are described as follows:
An example of network loss
Run the following command to simulate network loss:
Create network fault experiments using service mode
(To be added)