sim

package
v0.3.11-0...-4fdaadb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2022 License: BSD-3-Clause Imports: 14 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// KB is 2³ bytes.
	KB = int64(1) << 10
	// MB is 2⁶ bytes.
	MB = KB << 10
	// GB is 2⁹ bytes.
	GB = MB << 10
	// TB is 2¹² bytes.
	TB = GB << 10
	// PB is 2¹⁶ bytes.
	PB = TB << 10
)
View Source
const (
	// TCP is the key for the TCP protocol.
	TCP = Protocol("TCP")
	// UDP is the key for the UDP protocol.
	UDP = Protocol("UDP")
)
View Source
const (
	// VpnConnectionTimeout is the maximum amount of time given to open the
	// VPN tunnel.
	VpnConnectionTimeout = 10 * time.Second

	// LogFileName is the name of the file written in the temporary folder
	// where the logs of the vpn are written.
	LogFileName = "vpn.log"
	// PIDFileName is the name of the file written in the temporary folder
	// containing the PID of the VPN process.
	PIDFileName = "running_pid"

	// MessageInitDone is the message to look for to assume the tunnel is
	// opened.
	MessageInitDone = "Initialization Sequence Completed"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Certificates

type Certificates struct {
	CA   string
	Key  string
	Cert string
}

Certificates holds the location of the different files.

type DefaultTunnel

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

DefaultTunnel is an implementation of the tunnel interface that is using OpenVPN.

func NewDefaultTunnel

func NewDefaultTunnel(output string) *DefaultTunnel

NewDefaultTunnel creates a new OpenVPN process.

func (*DefaultTunnel) Start

func (v *DefaultTunnel) Start(opts ...TunOption) error

Start runs the openvpn process and returns any error that could happen before the tunnel is setup.

func (*DefaultTunnel) Stop

func (v *DefaultTunnel) Stop() error

Stop closes the vpn tunnel.

type ExecOptions

type ExecOptions struct {
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
}

ExecOptions is the options to pass to a command execution.

type IO

type IO interface {
	// Tag allows to mark a point in time with a given tag. The moment the
	// function is called will be saved and it can be reported to the plot.
	Tag(name string)

	// Read reads a file on a simulation node at the given path. It returns a
	// stream through a reader, or an error if something bad happened.
	Read(node, path string) (io.ReadCloser, error)

	// Write writes a file on a simulation node at the given path. It will
	// write everything from the reader until it reaches EOF. It also returns
	// an error if something bad happened.
	Write(node, path string, content io.Reader) error

	// Exec executes a command on a simulation node and returns the output if
	// the command is successful, an error otherwise.
	Exec(node string, cmd []string, options ExecOptions) error

	// Disconnect provides an API to simulate a network failure between two
	// nodes.
	Disconnect(src string, targets ...string) error

	// Revert all the disconnection on the given node so that it will again be
	// able to contact all the nodes.
	Reconnect(node string) error

	// FetchStats gathers the statistics from the nodes and write into filename.
	FetchStats(from, to time.Time, filename string) error
}

IO provides an API to interact with the nodes.

type NodeInfo

type NodeInfo struct {
	Name    string
	Address string
}

NodeInfo is the element value of the array available in the execution context. Use `nodes := ctx.Value(NodesKey{}).([]NodeInfo)` to retrieve the data.

type Option

type Option func(opts *Options)

Option is a function that changes the global options.

func WithImage

func WithImage(image string, cmd, args []string, ports ...Port) Option

WithImage is an option for simulation engines to use this Docker image as the base application to run.

func WithOutput

func WithOutput(dir string) Option

WithOutput is an option to change the default directory that will be used to write data about the simulation.

func WithTmpFS

func WithTmpFS(destination string, size int64) Option

WithTmpFS is an option for simulation engines to mount a tmpfs at the given destination.

func WithTopology

func WithTopology(topo network.Topology) Option

WithTopology is an option for simulation engines to use the topology when deploying the nodes.

func WithVPN

func WithVPN(exec string) Option

WithVPN is an option to change the default vpn executable path.

type Options

type Options struct {
	OutputDir     string
	Topology      network.Topology
	Image         string
	Cmd           []string
	Args          []string
	Ports         []Port
	TmpFS         []TmpVolume
	VPNExecutable string
	Data          map[string]interface{}
}

Options contains the different options for a simulation execution.

func NewOptions

func NewOptions(opts []Option) *Options

NewOptions creates empty options.

type Port

type Port interface {
	Protocol() Protocol
	Value() int32
}

Port is a parameter for the container image to open a port with a given protocol. It can also be a range.

type Protocol

type Protocol string

Protocol is the type of the keys for the protocols.

func (Protocol) String

func (p Protocol) String() string

type Round

type Round interface {
	// Before is run once after deployment so that initialization can be
	// performed before the simulation is executed.
	Before(simio IO, nodes []NodeInfo) error

	// Execute is run during the execution step of the simulation, which is
	// after the nodes are deployed.
	Execute(simio IO, nodes []NodeInfo) error

	// After is run after each execution of the simulation to give a chance
	// to read files from simulation nodes.
	After(simio IO, nodes []NodeInfo) error
}

Round is executed during the simulation.

type Strategy

type Strategy interface {
	Option(Option)

	// Deploy takes care of deploying the application according to the
	// topology. The simulation should be able to run after it returns
	// with no error.
	Deploy(context.Context, Round) error

	// Execute takes the round provided to execute a round of the simulation.
	Execute(context.Context, Round) error

	// WriteStats reads the data writtent by the monitors on each node of the
	// simulation.
	WriteStats(ctx context.Context, filename string) error

	// Clean wipes off any resources that has been created for the simulation.
	Clean(context.Context) error
}

Strategy provides the primitives to run a simulation from the deployment, to the execution of the simulation round and finally the cleaning.

type TCPPort

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

TCPPort is a single TCPPort port.

func NewTCP

func NewTCP(port int32) TCPPort

NewTCP creates a new tcp port.

func (TCPPort) Protocol

func (p TCPPort) Protocol() Protocol

Protocol returns the protocol key for TCP.

func (TCPPort) Value

func (p TCPPort) Value() int32

Value returns the integer value of the port.

type TmpVolume

type TmpVolume struct {
	Destination string
	Size        int64
}

TmpVolume stores the information about a tmpfs mount.

type TunOption

type TunOption func(opts *TunOptions)

TunOption is a function that transforms the vpn options.

func WithCertificate

func WithCertificate(certs Certificates) TunOption

WithCertificate updates the options to include the certificate elements in the parameters used to start the vpn.

func WithCommand

func WithCommand(cmd string) TunOption

WithCommand updates the options to use a different executable.

func WithHost

func WithHost(host string) TunOption

WithHost updates the options to include the hostname of the distant vpn.

func WithPort

func WithPort(port int32) TunOption

WithPort updates the options to include the port of the distant vpn.

type TunOptions

type TunOptions struct {
	Cmd          string
	Host         string
	Port         int32
	Certificates Certificates
}

TunOptions contains the data that will be used to start the vpn.

type Tunnel

type Tunnel interface {
	Start(...TunOption) error
	Stop() error
}

Tunnel provides primitives to open and close a tunnel to a private network.

type UDPPort

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

UDPPort is a single udp port.

func NewUDP

func NewUDP(port int32) UDPPort

NewUDP creates a new udp port.

func (UDPPort) Protocol

func (p UDPPort) Protocol() Protocol

Protocol returns the protocol key for UDP.

func (UDPPort) Value

func (p UDPPort) Value() int32

Value returns the integer value of the port.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL