core

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: Apache-2.0 Imports: 26 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"
	Scheduled = "scheduled"
	Destroyed = "destroyed"
	Revoked   = "revoked"
)
View Source
const (
	ProcessAttack     = "process"
	NetworkAttack     = "network"
	StressAttack      = "stress"
	DiskAttack        = "disk"
	DiskServerAttack  = "disk-server"
	ClockAttack       = "clock"
	HostAttack        = "host"
	JVMAttack         = "jvm"
	KafkaAttack       = "kafka"
	RedisAttack       = "redis"
	FileAttack        = "file"
	HTTPAttack        = "http"
	VMAttack          = "vm"
	UserDefinedAttack = "userDefined"
)
View Source
const (
	ServerMode  = "svr"
	CommandMode = "cmd"
)
View Source
const (
	RunStarted   = "started"
	RunFailed    = "failed"
	RunSuccess   = "success"
	RunRecovered = "recovered"
)
View Source
const (
	FileCreateAction          = "create"
	FileModifyPrivilegeAction = "modify"
	FileDeleteAction          = "delete"
	FileRenameAction          = "rename"
	FileAppendAction          = "append"
	FileReplaceAction         = "replace"
)
View Source
const (
	HostShutdownAction = "shutdown"
	HostRebootAction   = "reboot"
)
View Source
const (
	TargetRequest  tproxyconfig.PodHttpChaosTarget = "Request"
	TargetResponse tproxyconfig.PodHttpChaosTarget = "Response"
)
View Source
const (
	HTTPAbortAction   = "abort"
	HTTPDelayAction   = "delay"
	HTTPConfigAction  = "config"
	HTTPRequestAction = "request"
)
View Source
const (
	// jvm action
	JVMLatencyAction   = "latency"
	JVMExceptionAction = "exception"
	JVMReturnAction    = "return"
	JVMStressAction    = "stress"
	JVMGCAction        = "gc"
	JVMRuleFileAction  = "rule-file"
	JVMRuleDataAction  = "rule-data"
	JVMMySQLAction     = "mysql"

	// for action 'mysql', 'gc' and 'stress'
	SQLHelper    = "org.chaos_mesh.byteman.helper.SQLHelper"
	GCHelper     = "org.chaos_mesh.byteman.helper.GCHelper"
	StressHelper = "org.chaos_mesh.byteman.helper.StressHelper"

	// the trigger point for 'gc' and 'stress'
	TriggerClass  = "org.chaos_mesh.chaos_agent.TriggerThread"
	TriggerMethod = "triggerFunc"

	MySQL5InjectClass  = "com.mysql.jdbc.MysqlIO"
	MySQL5InjectMethod = "sqlQueryDirect"
	MySQL5Exception    = "java.sql.SQLException(\"%s\")"

	MySQL8InjectClass  = "com.mysql.cj.NativeSession"
	MySQL8InjectMethod = "execSQL"
	MySQL8Exception    = "com.mysql.cj.exceptions.CJException(\"%s\")"
)
View Source
const (
	SimpleRuleTemplate = `
RULE {{.Name}}
CLASS {{.Class}}
METHOD {{.Method}}
AT ENTRY
IF true
DO
	{{.Do}};
ENDRULE
`

	CompleteRuleTemplate = `` /* 135-byte string literal not displayed */

)

byteman rule template

View Source
const (
	// Kafka actions
	KafkaFillAction  KafkaAttackAction = "fill"
	KafkaFloodAction                   = "flood"
	KafkaIOAction                      = "io"
)
View Source
const (
	SaslPlain          KafkaAuthMechanism = "sasl/plain"
	SaslScream256                         = "sasl/scram-sha-256"
	SaslScram512                          = "sasl/scram-sha-512"
	AuthMechanismEmpty                    = ""
)
View Source
const (
	NetworkDelayAction        = "delay"
	NetworkLossAction         = "loss"
	NetworkCorruptAction      = "corrupt"
	NetworkDuplicateAction    = "duplicate"
	NetworkDNSAction          = "dns"
	NetworkPartitionAction    = "partition"
	NetworkBandwidthAction    = "bandwidth"
	NetworkPortOccupiedAction = "occupied"
	NetworkNICDownAction      = "down"
	NetworkFloodAction        = "flood"

	NetIPSet = "hash:net"
)
View Source
const (
	ProcessKillAction = "kill"
	ProcessStopAction = "stop"
)
View Source
const (
	RedisSentinelRestartAction  = "restart"
	RedisSentinelStopAction     = "stop"
	RedisCachePenetrationAction = "penetration"
	RedisCacheLimitAction       = "cacheLimit"
	RedisCacheExpirationAction  = "expiration"
)
View Source
const (
	StressCPUAction = "cpu"
	StressMemAction = "mem"
)
View Source
const (
	ClockAction = "clock"
)
View Source
const (
	VMAction = "vm"
)

Variables

View Source
var (
	ErrNs                     = errorx.NewNamespace("error.core")
	ErrAttackConfigValidation = ErrNs.NewType("attack_config_validation_error")
	ErrNonRecoverableAttack   = ErrNs.NewType("non_recoverable_attack")
)
View Source
var DdCommand = utils.Command{Name: "dd"}
View Source
var FAllocateCommand = utils.Command{Name: "fallocate"}
View Source
var (
	ValidOptions = map[string]bool{"XX": true, "NX": true, "GT": true, "LT": true}
)

Functions

This section is empty.

Types

type AttackConfig added in v1.0.0

type AttackConfig interface {
	Validate() error
	Cron() string
	ScheduleDuration() (*time.Duration, error)
	// String is replacement of .Action
	String() string
	// RecoverData is replacement of earlier .String()
	RecoverData() string

	// AttackKind returns the kind of attack
	AttackKind() string

	// CompleteDefaults is used to fill flags with default values
	CompleteDefaults()

	// GetUID returns the experiment's ID
	GetUID() string
}

func GetAttackByKind added in v1.0.2

func GetAttackByKind(kind string) *AttackConfig

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 BytemanTemplateSpec added in v1.2.0

type BytemanTemplateSpec struct {
	Name      string
	Class     string
	Method    string
	Helper    string
	Bind      string
	Condition string
	Do        string

	// below is only used for stress template
	StressType      string
	StressValueName string
	StressValue     string
}

type ChainDirection

type ChainDirection string

ChainDirection represents the direction of chain

type Cidr

type Cidr struct {
	gorm.Model
	Cidr string
}

type ClockFuncStore added in v1.1.0

type ClockFuncStore struct {
	CodeOfGetClockFunc []byte
	OriginAddress      uint64
}

type ClockOption added in v1.1.0

type ClockOption struct {
	CommonAttackConfig

	Pid int `json:"pid,omitempty"`

	TimeOffset string `json:"time-offset,omitempty"`
	SecDelta   int64
	NsecDelta  int64

	ClockIdsSlice string `json:"clock-ids-slice,omitempty"`

	Store ClockFuncStore

	ClockIdsMask uint64
}

func NewClockOption added in v1.1.0

func NewClockOption() *ClockOption

func (*ClockOption) CompleteDefaults added in v1.1.0

func (opt *ClockOption) CompleteDefaults()

func (*ClockOption) PreProcess added in v1.1.0

func (opt *ClockOption) PreProcess() error

func (ClockOption) RecoverData added in v1.1.0

func (opt ClockOption) RecoverData() string

type CommonAttackConfig added in v1.0.0

type CommonAttackConfig struct {
	SchedulerConfig

	Action string `json:"action"`
	Kind   string `json:"kind"`
	UID    string `json:"uid"`
}

func (CommonAttackConfig) AttackKind added in v1.0.0

func (config CommonAttackConfig) AttackKind() string

func (*CommonAttackConfig) CompleteDefaults added in v1.0.0

func (config *CommonAttackConfig) CompleteDefaults()

CompleteDefaults no-op implementation

func (*CommonAttackConfig) GetUID added in v1.0.2

func (config *CommonAttackConfig) GetUID() string

func (CommonAttackConfig) String added in v1.0.0

func (config CommonAttackConfig) String() string

func (*CommonAttackConfig) Validate added in v1.0.0

func (config *CommonAttackConfig) Validate() error

Validate does a basic validation of common parameters

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 DdOption added in v1.0.2

type DdOption struct {
	ReadPath  string `dd:"if"`
	WritePath string `dd:"of"`
	BlockSize string `dd:"bs"`
	Count     string `dd:"count"`
	Iflag     string `dd:"iflag"`
	Oflag     string `dd:"oflag"`
	Conv      string `dd:"conv"`
}

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 DiskAttackConfig added in v1.0.2

type DiskAttackConfig struct {
	CommonAttackConfig
	DdOptions       *[]DdOption
	FAllocateOption *FAllocateOption
	Path            string
}

func (DiskAttackConfig) RecoverData added in v1.0.2

func (d DiskAttackConfig) RecoverData() string

type DiskOption added in v1.0.0

type DiskOption struct {
	CommonAttackConfig

	Size              string `json:"size,omitempty"`
	Path              string `json:"path,omitempty"`
	Percent           string `json:"percent,omitempty"`
	PayloadProcessNum uint8  `json:"payload-process-num,omitempty"`

	FillByFallocate bool `json:"fallocate,omitempty"`
}

func NewDiskOption added in v1.0.0

func NewDiskOption() *DiskOption

func NewDiskOptionForServer added in v1.4.0

func NewDiskOptionForServer() *DiskOption

func (*DiskOption) PreProcess added in v1.0.2

func (opt *DiskOption) PreProcess() (*DiskAttackConfig, 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"`
	LaunchMode     string `json:"launch_mode"`
	// contains filtered or unexported fields
}

Experiment represents an experiment instance.

func (*Experiment) GetRequestCommand added in v1.0.0

func (exp *Experiment) GetRequestCommand() (AttackConfig, error)

func (Experiment) NewRun added in v1.0.0

func (exp Experiment) NewRun() *ExperimentRun

type ExperimentRun added in v1.0.0

type ExperimentRun struct {
	ID           uint      `gorm:"primary_key" json:"id"`
	UID          string    `gorm:"index:uid" json:"uid"`
	StartAt      time.Time `gorm:"autoCreateTime" json:"start_at"`
	FinishedAt   time.Time `json:"finished_at"`
	Status       string    `json:"status"`
	Message      string    `json:"error"`
	ExperimentID uint
	Experiment   Experiment `gorm:"foreignKey:ExperimentID" json:"experiment"`
}

ExperimentRun represents a run of an experiment

type ExperimentRunStore added in v1.0.0

type ExperimentRunStore interface {
	ListByExperimentID(ctx context.Context, id uint) ([]*ExperimentRun, error)
	ListByExperimentUID(ctx context.Context, uid string) ([]*ExperimentRun, error)
	LatestRun(ctx context.Context, id uint) (*ExperimentRun, error)

	NewRun(ctx context.Context, expRun *ExperimentRun) error
	Update(ctx context.Context, runUid string, status string, message string) error
}

ExperimentRunStore defines operations for working with experiment runs

type ExperimentStore

type ExperimentStore interface {
	List(ctx context.Context) ([]*Experiment, error)
	ListByLaunchMode(ctx context.Context, mode string) ([]*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 FAllocateOption added in v1.0.2

type FAllocateOption struct {
	LengthOpt string `fallocate:"-"`
	Length    string `fallocate:"-"`
	FileName  string `fallocate:"-"`
}

type FileCommand added in v1.2.0

type FileCommand struct {
	CommonAttackConfig

	//	FileName is the name of the file to be created, modified, deleted, renamed, or appended.
	FileName string `json:"file-name,omitempty"`
	// DirName is the directory name to create or delete.
	DirName string `json:"dir-name,omitempty"`
	// Privilege is the file privilege to be set.
	Privilege uint32 `json:"privilege,omitempty"`
	// SourceFile is the name need to be renamed.
	SourceFile string `json:"source-file,omitempty"`
	// DestFile is the name to be renamed.
	DestFile string `json:"dest-file,omitempty"`
	// Data is the data for append.
	Data string `json:"data,omitempty"`
	// Count is the number of times to append the data.
	Count int `json:"count,omitempty"`
	// OriginPrivilege used to save the file's origin privilege.
	OriginPrivilege int `json:"origin-privilege,omitempty"`

	// OriginStr is the origin string of the file.
	OriginStr string `json:"origin-string,omitempty"`
	// DestStr is the destination string of the file.
	DestStr string `json:"dest-string,omitempty"`
	// Line is the line number of the file to be replaced.
	Line int `json:"line,omitempty"`
}

func NewFileCommand added in v1.2.0

func NewFileCommand() *FileCommand

func (*FileCommand) CompleteDefaults added in v1.2.0

func (n *FileCommand) CompleteDefaults()

func (FileCommand) RecoverData added in v1.2.0

func (n FileCommand) RecoverData() string

func (*FileCommand) Validate added in v1.2.0

func (n *FileCommand) Validate() error

type HTTPAttackConfig added in v1.2.1

type HTTPAttackConfig struct {
	CommonAttackConfig
	Config   tproxyconfig.Config
	ProxyPID int

	Logger logr.Logger

	HTTPRequestConfig
}

func (HTTPAttackConfig) RecoverData added in v1.2.1

func (c HTTPAttackConfig) RecoverData() string

type HTTPAttackOption added in v1.2.1

type HTTPAttackOption struct {
	CommonAttackConfig

	ProxyPorts []uint `json:"proxy_ports"`
	Target     string `json:"target"`
	Port       int32  `json:"port,omitempty"`
	Path       string `json:"path,omitempty"`
	Method     string `json:"method,omitempty"`
	Code       string `json:"code,omitempty"`
	Abort      bool   `json:"abort"`
	Delay      string `json:"delay"`

	FilePath string `json:"file_path,omitempty"`

	HTTPRequestConfig `json:",inline"`
}

func NewHTTPAttackOption added in v1.2.1

func NewHTTPAttackOption() *HTTPAttackOption

func (*HTTPAttackOption) PreProcess added in v1.2.1

func (o *HTTPAttackOption) PreProcess() (*HTTPAttackConfig, error)

type HTTPRequestConfig added in v1.2.1

type HTTPRequestConfig struct {
	// used for HTTP request, now only support GET
	URL            string `json:"url,omitempty"`
	EnableConnPool bool   `json:"enable-conn-pool,omitempty"`
	Count          int    `json:"count,omitempty"`
}

type HostCommand

type HostCommand struct {
	CommonAttackConfig
}

func NewHostCommand added in v1.0.0

func NewHostCommand() *HostCommand

func (HostCommand) RecoverData added in v1.0.0

func (h HostCommand) RecoverData() 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"`

	Protocol string `json:"protocol"`
}

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 JVMClassMethodSpec added in v1.2.0

type JVMClassMethodSpec struct {
	// Java class
	Class string `json:"class,omitempty"`

	// the method in Java class
	Method string `json:"method,omitempty"`
}

type JVMCommand added in v1.0.0

type JVMCommand struct {
	CommonAttackConfig

	JVMCommonSpec

	JVMClassMethodSpec

	JVMStressSpec

	JVMMySQLSpec

	// rule name, should be unique, and will generate by chaosd automatically
	Name string `json:"name,omitempty"`

	// fault action, values can be latency, exception, return, stress, gc, rule-file, rule-data, mysql
	Action string `json:"action,omitempty"`

	// the return value for action 'return'
	ReturnValue string `json:"value,omitempty"`

	// the exception which needs to throw for action `exception`
	// or the exception message needs to throw in action `mysql`
	ThrowException string `json:"exception,omitempty"`

	// the latency duration for action 'latency'
	// or the latency duration in action `mysql`
	LatencyDuration int `json:"latency,omitempty"`

	// btm rule file path for action 'rule-file'
	RuleFile string `json:"rule-file,omitempty"`

	// RuleData used to save the rule file's data, will use it when recover, for action 'rule-data'
	RuleData string `json:"rule-data,omitempty"`
}

func NewJVMCommand added in v1.0.0

func NewJVMCommand() *JVMCommand

func (*JVMCommand) CompleteDefaults added in v1.0.0

func (j *JVMCommand) CompleteDefaults()

func (*JVMCommand) RecoverData added in v1.0.0

func (j *JVMCommand) RecoverData() string

func (*JVMCommand) Validate added in v1.0.0

func (j *JVMCommand) Validate() error

type JVMCommonSpec added in v1.2.0

type JVMCommonSpec struct {
	// the port of agent server
	Port int `json:"port,omitempty"`

	// the pid of Java process which need to attach
	Pid int `json:"pid,omitempty"`
}

type JVMMySQLSpec added in v1.2.0

type JVMMySQLSpec struct {
	// the version of mysql-connector-java, only support 5.X.X(set to 5) and 8.X.X(set to 8) now
	MySQLConnectorVersion string `json:"mysql-connector-version,omitempty"`

	// the match database
	// default value is "", means match all database
	Database string `json:"database,omitempty"`

	// the match table
	// default value is "", means match all table
	Table string `json:"table,omitempty"`

	// the match sql type
	// default value is "", means match all SQL type
	SQLType string `json:"sql-type,omitempty"`
}

JVMMySQLSpec is the specification of MySQL fault injection in JVM only when SQL match the Database, Table and SQLType, chaosd will inject fault for example:

SQL is "select * from test.t1",
only when ((Database == "test" || Database == "") && (Table == "t1" || Table == "") && (SQLType == "select" || SQLType == "")) is true, chaosd will inject fault

type JVMStressSpec added in v1.2.0

type JVMStressSpec struct {
	// the CPU core number need to use, only set it when action is stress
	CPUCount int `json:"cpu-count,omitempty"`

	// the memory type need to locate, only set it when action is stress, the value can be 'stack' or 'heap'
	MemoryType string `json:"mem-type,omitempty"`
}

type KafkaAttackAction added in v1.2.1

type KafkaAttackAction string

type KafkaAuthMechanism added in v1.4.0

type KafkaAuthMechanism string

type KafkaCommand added in v1.2.1

type KafkaCommand struct {
	CommonAttackConfig

	// global options
	Action KafkaAttackAction
	Topic  string `json:"topic,omitempty"`

	// options for fill and flood attack
	Host          string `json:"host,omitempty"`
	Port          uint16 `json:"port,omitempty"`
	Username      string `json:"username,omitempty"`
	Password      string `json:"password,omitempty"`
	AuthMechanism string `json:"authMechanism,omitempty"`
	MessageSize   uint   `json:"messageSize,omitempty"`
	MaxBytes      uint64 `json:"maxBytes,omitempty"`

	// options for fill attack
	ReloadCommand string `json:"reloadCommand,omitempty"`

	// options for flood attack
	Threads uint `json:"threads,omitempty"`

	// options for fill and io attack
	ConfigFile string `json:"configFile,omitempty"`

	// options for io attack
	NonReadable bool `json:"nonReadable,omitempty"`
	NonWritable bool `json:"nonWritable,omitempty"`

	// recover data for io attack
	OriginModeOfFiles map[string]uint32 `json:"originModeOfFiles,omitempty"`
	OriginConfig      string            `json:"originConfig,omitempty"`
}

func NewKafkaCommand added in v1.2.1

func NewKafkaCommand() *KafkaCommand

func (*KafkaCommand) CompleteDefaults added in v1.2.1

func (c *KafkaCommand) CompleteDefaults()

func (*KafkaCommand) RecoverData added in v1.2.1

func (c *KafkaCommand) RecoverData() string

func (*KafkaCommand) Validate added in v1.2.1

func (c *KafkaCommand) Validate() 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 {
	CommonAttackConfig

	Latency     string `json:"latency,omitempty"`
	Jitter      string `json:"jitter,omitempty"`
	Correlation string `json:"correlation,omitempty"`
	Percent     string `json:"percent,omitempty"`
	Device      string `json:"device,omitempty"`
	SourcePort  string `json:"source-port,omitempty"`
	EgressPort  string `json:"egress-port,omitempty"`
	IPAddress   string `json:"ip-address,omitempty"`
	IPProtocol  string `json:"ip-protocol,omitempty"`
	Hostname    string `json:"hostname,omitempty"`

	Direction string `json:"direction,omitempty"`

	// used for DNS attack
	DNSServer     string `json:"dns-server,omitempty"`
	DNSIp         string `json:"dns-ip,omitempty"`
	DNSDomainName string `json:"dns-domain-name,omitempty"`

	// used for port occupied or flood
	Port    string `json:"port,omitempty"`
	PortPid int32  `json:"port-pid,omitempty"`

	*BandwidthSpec `json:",inline"`
	// only the packet which match the tcp flag can be accepted, others will be dropped.
	// only set when the IPProtocol is tcp, used for partition.
	AcceptTCPFlags string `json:"accept-tcp-flags,omitempty"`

	// used for flood
	// number of iperf parallel client threads to run
	Parallel int32 `json:"parallel,omitempty"`

	// used for flood
	// the pid of iperf
	IperfPid int32 `json:"iperf-pid,omitempty"`
}

func NewNetworkCommand added in v1.0.0

func NewNetworkCommand() *NetworkCommand

func (*NetworkCommand) AdditionalChain added in v1.2.1

func (n *NetworkCommand) AdditionalChain(ipset string, uid string) ([]*pb.Chain, error)

func (*NetworkCommand) CompleteDefaults added in v1.0.0

func (n *NetworkCommand) CompleteDefaults()

func (*NetworkCommand) NeedAdditionalChains added in v1.2.1

func (n *NetworkCommand) NeedAdditionalChains() bool

func (*NetworkCommand) NeedApplyDNSServer added in v1.0.0

func (n *NetworkCommand) NeedApplyDNSServer() bool

func (*NetworkCommand) NeedApplyEtcHosts added in v1.0.0

func (n *NetworkCommand) NeedApplyEtcHosts() bool

func (*NetworkCommand) NeedApplyIPSet

func (n *NetworkCommand) NeedApplyIPSet() bool

func (*NetworkCommand) NeedApplyTC

func (n *NetworkCommand) NeedApplyTC() bool

func (NetworkCommand) RecoverData added in v1.0.0

func (n NetworkCommand) RecoverData() string

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 {
	CommonAttackConfig

	// Process defines the process name or the process ID.
	Process    string `json:"process,omitempty"`
	Signal     int    `json:"signal,omitempty"`
	PIDs       []int
	RecoverCmd string `json:"recoverCmd,omitempty"`
}

func NewProcessCommand added in v1.0.0

func NewProcessCommand() *ProcessCommand

func (ProcessCommand) RecoverData added in v1.0.0

func (p ProcessCommand) RecoverData() string

func (*ProcessCommand) Validate

func (p *ProcessCommand) Validate() error

type RedisCommand added in v1.2.1

type RedisCommand struct {
	CommonAttackConfig

	Addr        string `json:"addr,omitempty"`
	Password    string `json:"password,omitempty"`
	Conf        string `json:"conf,omitempty"`
	FlushConfig bool   `json:"flushConfig,omitempty"`
	RedisPath   string `json:"redisPath,omitempty"`
	RequestNum  int    `json:"requestNum,omitempty"`
	CacheSize   string `json:"cacheSize,omitempty"`
	Percent     string `json:"percent,omitempty"`
	Key         string `json:"key,omitempty"`
	Expiration  string `json:"expiration,omitempty"`
	Option      string `json:"option,omitempty"`

	OriginCacheSize string `json:"originCacheSize,omitempty"`
}

func NewRedisCommand added in v1.2.1

func NewRedisCommand() *RedisCommand

func (RedisCommand) RecoverData added in v1.2.1

func (r RedisCommand) RecoverData() string

func (*RedisCommand) Validate added in v1.2.1

func (r *RedisCommand) 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 SchedulerConfig added in v1.0.0

type SchedulerConfig struct {
	Schedule string `json:"schedule"`
	Duration string `json:"duration"`
}

func (SchedulerConfig) Cron added in v1.0.0

func (config SchedulerConfig) Cron() string

func (SchedulerConfig) ScheduleDuration added in v1.0.0

func (config SchedulerConfig) ScheduleDuration() (*time.Duration, error)

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 {
	CommonAttackConfig

	Load        int      `json:"load,omitempty"`
	Workers     int      `json:"workers,omitempty"`
	Size        string   `json:"size,omitempty"`
	Options     []string `json:"options,omitempty"`
	StressngPid int32    `json:"stress-ng-pid,omitempty"`
}

func NewStressCommand added in v1.0.0

func NewStressCommand() *StressCommand

func (*StressCommand) CompleteDefaults added in v1.0.2

func (s *StressCommand) CompleteDefaults()

func (StressCommand) RecoverData added in v1.0.0

func (s StressCommand) RecoverData() 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

type UserDefinedOption added in v1.2.1

type UserDefinedOption struct {
	CommonAttackConfig

	AttackCmd  string `json:"attackCmd,omitempty"`
	RecoverCmd string `json:"recoverCmd,omitempty"`
}

func NewUserDefinedOption added in v1.2.1

func NewUserDefinedOption() *UserDefinedOption

func (*UserDefinedOption) RecoverData added in v1.2.1

func (u *UserDefinedOption) RecoverData() string

func (*UserDefinedOption) Validate added in v1.2.1

func (u *UserDefinedOption) Validate() error

type VMOption added in v1.2.1

type VMOption struct {
	CommonAttackConfig

	VMName string `json:"vm-name,omitempty"`
}

func NewVMOption added in v1.2.1

func NewVMOption() *VMOption

func (*VMOption) CompleteDefaults added in v1.2.1

func (opt *VMOption) CompleteDefaults()

func (VMOption) RecoverData added in v1.2.1

func (opt VMOption) RecoverData() string

Jump to

Keyboard shortcuts

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