Back to godoc.org

Package network

v0.2.0
Latest Go to latest

The latest major version is .

Published: Apr 30, 2020 | Licenses: Apache-2.0 , MIT | Module: github.com/testground/sdk-go

Index

Constants

const (
	// magic values that we monitor on the Testground runner side to detect when Testground
	// testplan instances are initialised and at the stage of actually running a test
	// check cluster_k8s.go for more information
	InitialisationSuccessful = "network initialisation successful"
	InitialisationFailed     = "network initialisation failed"
)

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(client *sync.Client, runenv *runtime.RunEnv) *Client

NewClient returns a new network client. Use this client to request network changes, such as setting latencies, jitter, packet loss, connectedness, etc.

func (*Client) ConfigureNetwork

func (c *Client) ConfigureNetwork(ctx context.Context, config *Config) (err error)

ConfigureNetwork asks the sidecar to configure the network, and returns either when the sidecar signals back to us, or when the context expires.

func (*Client) MustConfigureNetwork

func (c *Client) MustConfigureNetwork(ctx context.Context, config *Config)

MustConfigureNetwork calls ConfigureNetwork, and panics if it errors. It is suitable to use with runner.Invoke/InvokeMap, as long as this method is called from the main goroutine of the test plan.

func (*Client) MustWaitNetworkInitialized

func (c *Client) MustWaitNetworkInitialized(ctx context.Context)

MustWaitNetworkInitialized calls WaitNetworkInitialized, and panics if it errors. It is suitable to use with runner.Invoke/InvokeMap, as long as this method is called from the main goroutine of the test plan.

func (*Client) WaitNetworkInitialized

func (c *Client) WaitNetworkInitialized(ctx context.Context) error

WaitNetworkInitialized waits for the sidecar to initialize the network, if the sidecar is enabled. If not, it returns immediately.

type Config

type Config struct {
	// Network is the name of the network to configure
	Network string

	// IPv4 and IPv6 set the IP addresses of this network device. If
	// unspecified, the sidecar will leave them alone.
	//
	// Your test-case will be assigned a B block in the range
	// 16.0.0.1-32.0.0.0. X.Y.0.1 will always be reserved for the gateway
	// and shouldn't be used by the test.
	//
	// TODO: IPv6 is currently not supported.
	IPv4, IPv6 *net.IPNet

	// Enable enables this network device.
	Enable bool

	// Default is the default link shaping rule.
	Default LinkShape

	// Rules defines how traffic should be shaped to different subnets.
	//
	// TODO: This is not implemented.
	Rules []LinkRule

	// CallbackState will be signalled when the link changes are applied.
	//
	// Nodes can use the same state to wait for _all_ or a subset of nodes to
	// enter the desired network state. See CallbackTarget.
	CallbackState sync.State `json:"State"`

	// CallbackTarget is the amount of instances that will have needed to signal
	// on the Callback state to consider the configuration operation a success.
	//
	// A zero value falls back to runenv.TestInstanceCount (i.e. all instances
	// participating in the test run).
	CallbackTarget int `json:"-"`
}

NetworkConfig specifies how a node's network should be configured.

type FilterAction

type FilterAction int
const (
	Accept FilterAction = iota
	Reject
	Drop
)

type LinkRule

type LinkRule struct {
	LinkShape
	Subnet net.IPNet
}

LinkRule applies a LinkShape to a subnet.

type LinkShape

type LinkShape struct {
	// Latency is the egress latency
	Latency time.Duration

	// Jitter is the egress jitter
	Jitter time.Duration

	// Bandwidth is egress bytes per second
	Bandwidth uint64

	// Drop all inbound traffic.
	// TODO: Not implemented
	Filter FilterAction

	// Loss is the egress packet loss (%)
	Loss float32

	// Corrupt is the egress packet corruption probability (%)
	Corrupt float32

	// Corrupt is the egress packet corruption correlation (%)
	CorruptCorr float32

	// Reorder is the probability that an egress packet will be reordered (%)
	//
	// Reordered packets will skip the latency delay and be sent
	// immediately. You must specify a non-zero Latency for this option to
	// make sense.
	Reorder float32

	// ReorderCorr is the egress packet reordering correlation (%)
	ReorderCorr float32

	// Duplicate is the percentage of packets that are duplicated (%)
	Duplicate float32

	// DuplicateCorr is the correlation between egress packet duplication (%)
	DuplicateCorr float32
}

LinkShape defines how traffic should be shaped.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier