Traffic shaping
In Testground, a test instance can configure its own network (IP address, jitter, latency, bandwidth, etc.) using a network client. See the network package of the Go SDK for more information.
Imports
For this example, you'll need the following packages:
Pre-check and preparation
First, check to make sure the sidecar is available. At the moment, it's only available on docker-based runners. If it's not available, just skip any networking config code and return.
Network initialization
Wait for the sidecar to initialize the network for this test plan instance. See the Networking section for more details.
If you don't want to customize the network (set IP addresses, latency, etc.), you can stop here.
Configure traffic shaping
Once the network is ready, you'll need to actually configure your network. To "shape" traffic, set the Default
LinkShape
. You can use this to set latency, bandwidth, jitter, etc.
?> This sets egress (outbound) properties on the link. These settings must be symmetric (applied on both sides of the connection) to work properly (unless asymmetric bandwidth/latency/etc. is desired).
?> Per-subnet traffic shaping is a desired but unimplemented feature. The sidecar will reject configs with per-subnet rules set in network.Config.Rules
(Optional) Changing your IP address
If you don't specify an IPv4 address when configuring your network, your test instance will keep the default assignment. However, if desired, a test instance can change its IP address at any time.
First, you'll need some kind of unique sequence number to ensure you don't pick conflicting IP addresses. If you don't already have some form of unique sequence number at this point in your tests, use the sync service to get one:
Once you have a sequence number, you can set your IP address from one of the available subnets:
You cannot currently set an IPv6 address.
Apply the configuration
Applying the network configuration will post the configuration to the sync service, from where the appropriate instance of sidecar will consume it to apply the rules via Netlink. Once it is done, it will signal back on the CallbackState
.
?> The network API will, by default, wait for runenv.TestInstanceCount
instances to have signalled on the CallbackState
. If you want to wait for a different number of instances, such as if only a subset of instances actually apply traffic shaping rules, you can set the CallbackTarget
value in the configuration.
Appendix: What the sidecar does
The sidecar reads the network configuration from the sync service.
The sidecar applies network configurations requested by test plan instances.
The sidecar signals the configured
CallbackState
when done.
Last updated