core

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DiskFillAction         = "fill"
	DiskWritePayloadAction = "write-payload"
	DiskReadPayloadAction  = "read-payload"
)
View Source
const (
	Created   = "created"
	Success   = "success"
	Error     = "error"
	Destroyed = "destroyed"
	Revoked   = "revoked"
)
View Source
const (
	ProcessAttack = "process"
	NetworkAttack = "network"
	StressAttack  = "stress"
	DiskAttack    = "disk"
	HostAttack    = "host"
)
View Source
const (
	NetworkDelayAction     = "delay"
	NetworkLossAction      = "loss"
	NetworkCorruptAction   = "corrupt"
	NetworkDuplicateAction = "duplicate"
)
View Source
const (
	ProcessKillAction = "kill"
	ProcessStopAction = "stop"
)
View Source
const (
	StressCPUAction = "cpu"
	StressMemAction = "mem"
)
View Source
const (
	HostShutdownAction = "shutdown"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BandwidthSpec

type BandwidthSpec struct {
	// Rate is the speed knob. Allows bps, kbps, mbps, gbps, tbps unit. bps means bytes per second.
	Rate string `json:"rate"`
	// Limit is the number of bytes that can be queued waiting for tokens to become available.
	Limit uint32 `json:"limit"`
	// Buffer is the maximum amount of bytes that tokens can be available for instantaneously.
	Buffer uint32 `json:"buffer"`
	// Peakrate is the maximum depletion rate of the bucket.
	// The peakrate does not need to be set, it is only necessary
	// if perfect millisecond timescale shaping is required.
	Peakrate *uint64 `json:"peakrate,omitempty"`
	// Minburst specifies the size of the peakrate bucket. For perfect
	// accuracy, should be set to the MTU of the interface.  If a
	// peakrate is needed, but some burstiness is acceptable, this
	// size can be raised. A 3000 byte minburst allows around 3mbit/s
	// of peakrate, given 1000 byte packets.
	Minburst *uint32 `json:"minburst,omitempty"`
}

BandwidthSpec defines detail of bandwidth limit.

func (*BandwidthSpec) ToTbf

func (in *BandwidthSpec) ToTbf() (*pb.Tbf, error)

ToTbf converts BandwidthSpec to *chaosdaemonpb.Tbf Bandwidth action use TBF under the hood. TBF stands for Token Bucket Filter, is a classful queueing discipline available for traffic control with the tc command. http://man7.org/linux/man-pages/man8/tc-tbf.8.html

type ChainDirection

type ChainDirection string

ChainDirection represents the direction of chain

type Cidr

type Cidr struct {
	gorm.Model
	Cidr string
}

type CorruptSpec

type CorruptSpec struct {
	Corrupt     string `json:"corrupt"`
	Correlation string `json:"correlation"`
}

CorruptSpec defines detail of a corrupt action

func (*CorruptSpec) ToNetem

func (in *CorruptSpec) ToNetem() (*pb.Netem, error)

ToNetem implements Netem interface.

type DelaySpec

type DelaySpec struct {
	Latency     string       `json:"latency"`
	Correlation string       `json:"correlation,omitempty"`
	Jitter      string       `json:"jitter,omitempty"`
	Reorder     *ReorderSpec `json:"reorder,omitempty"`
}

DelaySpec defines detail of a delay action

func (*DelaySpec) ToNetem

func (in *DelaySpec) ToNetem() (*pb.Netem, error)

ToNetem implements Netem interface.

type DiskCommand

type DiskCommand struct {
	Action          string `json:"action"`
	Size            uint64 `json:"size"`
	Path            string `json:"path"`
	FillByFallocate bool   `json:"fill_by_fallocate"`
}

func (*DiskCommand) String

func (d *DiskCommand) String() string

func (*DiskCommand) Validate

func (d *DiskCommand) Validate() error

type DuplicateSpec

type DuplicateSpec struct {
	Duplicate   string `json:"duplicate"`
	Correlation string `json:"correlation"`
}

DuplicateSpec defines detail of a duplicate action

func (*DuplicateSpec) ToNetem

func (in *DuplicateSpec) ToNetem() (*pb.Netem, error)

ToNetem implements Netem interface.

type Experiment

type Experiment struct {
	ID        uint      `gorm:"primary_key" json:"id"`
	Uid       string    `gorm:"index:uid" json:"uid"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	Status    string    `json:"status"`
	Message   string    `json:"error"`
	// TODO: need to improve
	Kind           string `json:"kind"`
	Action         string `json:"action"`
	RecoverCommand string `json:"recover_command"`
}

Experiment represents an experiment instance.

type ExperimentStore

type ExperimentStore interface {
	List(ctx context.Context) ([]*Experiment, error)
	ListByConditions(ctx context.Context, conds *SearchCommand) ([]*Experiment, error)
	ListByStatus(ctx context.Context, status string) ([]*Experiment, error)
	FindByUid(ctx context.Context, uid string) (*Experiment, error)
	Set(ctx context.Context, exp *Experiment) error
	Update(ctx context.Context, uid, status, msg string, command string) error
}

ExperimentStore defines operations for working with experiments

type HostCommand

type HostCommand struct {
	Action string
}

func (*HostCommand) String

func (h *HostCommand) String() string

func (*HostCommand) Validate

func (h *HostCommand) Validate() error

type IPSetRule

type IPSetRule struct {
	gorm.Model
	// The name of ipset
	Name string `gorm:"index:name" json:"name"`
	// The contents of ipset
	Cidrs string `json:"cidrs"`
	// Experiment represents the experiment which the rule belong to.
	Experiment string `gorm:"index:experiment" json:"experiment"`
}

type IPSetRuleStore

type IPSetRuleStore interface {
	List(ctx context.Context) ([]*IPSetRule, error)
	Set(ctx context.Context, rule *IPSetRule) error
	FindByExperiment(ctx context.Context, experiment string) ([]*IPSetRule, error)
	DeleteByExperiment(ctx context.Context, experiment string) error
}

type IptablesRule

type IptablesRule struct {
	gorm.Model
	// The name of iptables chain
	Name string `gorm:"index:name" json:"name"`
	// The name of related ipset
	IPSets string `json:"ipsets"`
	// The block direction of this iptables rule
	Direction string `json:"direction"`
	// Experiment represents the experiment which the rule belong to.
	Experiment string `gorm:"index:experiment" json:"experiment"`
}

func (*IptablesRule) ToChain

func (i *IptablesRule) ToChain() *pb.Chain

type IptablesRuleList

type IptablesRuleList []*IptablesRule

func (IptablesRuleList) ToChains

func (l IptablesRuleList) ToChains() []*pb.Chain

type IptablesRuleStore

type IptablesRuleStore interface {
	List(ctx context.Context) ([]*IptablesRule, error)
	Set(ctx context.Context, rule *IptablesRule) error
	FindByExperiment(ctx context.Context, experiment string) ([]*IptablesRule, error)
	DeleteByExperiment(ctx context.Context, experiment string) error
}

type LossSpec

type LossSpec struct {
	Loss        string `json:"loss"`
	Correlation string `json:"correlation"`
}

LossSpec defines detail of a loss action

func (*LossSpec) ToNetem

func (in *LossSpec) ToNetem() (*pb.Netem, error)

ToNetem implements Netem interface.

type NetemSpec

type NetemSpec interface {
	ToNetem() (*pb.Netem, error)
}

NetemSpec defines the interface to convert to a Netem protobuf

type NetworkCommand

type NetworkCommand struct {
	Action      string
	Latency     string
	Jitter      string
	Correlation string
	Percent     string
	Device      string
	SourcePort  string
	EgressPort  string
	IPAddress   string
	IPProtocol  string
	Hostname    string
}

func (*NetworkCommand) NeedApplyIPSet

func (n *NetworkCommand) NeedApplyIPSet() bool

func (*NetworkCommand) NeedApplyIptables

func (n *NetworkCommand) NeedApplyIptables() bool

func (*NetworkCommand) NeedApplyTC

func (n *NetworkCommand) NeedApplyTC() bool

func (*NetworkCommand) SetDefaultForNetworkDelay

func (n *NetworkCommand) SetDefaultForNetworkDelay()

func (*NetworkCommand) SetDefaultForNetworkLoss

func (n *NetworkCommand) SetDefaultForNetworkLoss()

func (*NetworkCommand) String

func (n *NetworkCommand) String() string

func (*NetworkCommand) ToChain

func (n *NetworkCommand) ToChain() (*pb.Chain, error)

func (*NetworkCommand) ToCorruptNetem

func (n *NetworkCommand) ToCorruptNetem() (*pb.Netem, error)

func (*NetworkCommand) ToDelayNetem

func (n *NetworkCommand) ToDelayNetem() (*pb.Netem, error)

func (*NetworkCommand) ToDuplicateNetem

func (n *NetworkCommand) ToDuplicateNetem() (*pb.Netem, error)

func (*NetworkCommand) ToIPSet

func (n *NetworkCommand) ToIPSet(name string) (*pb.IPSet, error)

func (*NetworkCommand) ToLossNetem

func (n *NetworkCommand) ToLossNetem() (*pb.Netem, error)

func (*NetworkCommand) ToTC

func (n *NetworkCommand) ToTC(ipset string) (*pb.Tc, error)

func (*NetworkCommand) Validate

func (n *NetworkCommand) Validate() error

type ProcessCommand

type ProcessCommand struct {
	Action string
	// Process defines the process name or the process ID.
	Process string
	Signal  int
	PIDs    []int
}

func (*ProcessCommand) String

func (p *ProcessCommand) String() string

func (*ProcessCommand) Validate

func (p *ProcessCommand) Validate() error

type ReorderSpec

type ReorderSpec struct {
	Reorder     string `json:"reorder"`
	Correlation string `json:"correlation"`
	Gap         int    `json:"gap"`
}

ReorderSpec defines details of packet reorder.

type SearchCommand

type SearchCommand struct {
	Asc    bool
	All    bool
	Status string
	Kind   string
	Limit  uint32
	Offset uint32
	UID    string
}

func (*SearchCommand) Validate

func (s *SearchCommand) Validate() error

type StressCommand

type StressCommand struct {
	Action string

	Load int

	Workers int

	Options []string

	Duration time.Duration

	StressngPid int32
}

func (*StressCommand) String

func (s *StressCommand) String() string

func (*StressCommand) Validate

func (s *StressCommand) Validate() error

type TCRule

type TCRule struct {
	gorm.Model
	Device string `json:"device"`
	// The type of traffic control
	Type string `json:"type"`
	TC   string `json:"tc"`
	// The name of target ipset
	IPSet string `json:"ipset,omitempty"`
	// Experiment represents the experiment which the rule belong to.
	Experiment string `gorm:"index:experiment" json:"experiment"`

	Protocal   string
	SourcePort string
	EgressPort string
}

func (*TCRule) ToTC

func (t *TCRule) ToTC() (*pb.Tc, error)

type TCRuleList

type TCRuleList []*TCRule

func (TCRuleList) ToTCs

func (t TCRuleList) ToTCs() ([]*pb.Tc, error)

type TCRuleStore

type TCRuleStore interface {
	List(ctx context.Context) ([]*TCRule, error)
	ListGroupDevice(ctx context.Context) (map[string][]*TCRule, error)
	Set(ctx context.Context, rule *TCRule) error
	FindByDevice(ctx context.Context, experiment string) ([]*TCRule, error)
	FindByExperiment(ctx context.Context, experiment string) ([]*TCRule, error)
	DeleteByExperiment(ctx context.Context, experiment string) error
}

type TcParameter

type TcParameter struct {
	Device string
	// Delay represents the detail about delay action
	Delay *DelaySpec `json:"delay,omitempty"`
	// Loss represents the detail about loss action
	Loss *LossSpec `json:"loss,omitempty"`
	// DuplicateSpec represents the detail about loss action
	Duplicate *DuplicateSpec `json:"duplicate,omitempty"`
	// Corrupt represents the detail about corrupt action
	Corrupt *CorruptSpec `json:"corrupt,omitempty"`
	// Bandwidth represents the detail about bandwidth control action
	Bandwidth *BandwidthSpec `json:"bandwidth,omitempty"`
}

TcParameter represents the parameters for a traffic control chaos

Jump to

Keyboard shortcuts

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