core

package
v0.0.0-...-3bc59d9 Latest Latest
Warning

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

Go to latest
Published: May 31, 2019 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPort         = "53"
	DefaultRandomLength = 0
	DefaultQPS          = 100
	DefaultMaxQuery     = 0
	DefaultProtocol     = "udp"
)

Default value for benchmark

View Source
const (
	StatusStart    uint32 = 1
	StatusRunning  uint32 = 2
	StatusStopping uint32 = 3
	StatusStopped  uint32 = 4
)

Status define the current dns loader running status

Variables

View Source
var StatusToString = map[uint32]string{
	StatusStart:    "start",
	StatusRunning:  "running",
	StatusStopping: "stopping",
	StatusStopped:  "stopped",
}

StatusToString store the status code to string info

Functions

func Assert

func Assert(t *testing.T, condition bool, msg string, v ...interface{})

Assert fails the test if the condition is false.

func Equals

func Equals(t *testing.T, exp, act interface{})

Equals fails the test if exp is not equal to act.

func GenRandomDomain

func GenRandomDomain(length int, domain string) string

GenRandomDomain will generate the random domain name with the fix length

func GenTrafficFromConfig

func GenTrafficFromConfig(appController *AppController) error

GenTrafficFromConfig function will do traffic generate job from configuration

func NewDatabaseConnectionFromFile

func NewDatabaseConnectionFromFile(dbfile string) error

NewDatabaseConnectionFromFile create database from file

func OK

func OK(t *testing.T, err error)

OK fails the test if an err is not nil.

func RemoveStringInSlice

func RemoveStringInSlice(a string, list []string) []string

RemoveStringInSlice find if string type object and remove it

func StringInSlice

func StringInSlice(a string, list []string) bool

StringInSlice find if string type object a in a string list

Types

type Agent

type Agent struct {
	gorm.Model
	UUID   string `json:"uuid"`
	IP     string `json:"ip"`
	Port   string `json:"port"`
	Live   bool   `json:"live"`
	Enable bool   `json:"enable"`
}

Agent save all agent information in sqlite table

func (Agent) IPAddrWithPort

func (agent Agent) IPAddrWithPort() string

IPAddrWithPort return connect ip and port combination

type AppConfig

type AppConfig struct {
	User              string
	Password          string
	AppSecrect        string
	HTTPServer        string
	ConfigFileName    string
	ConfigFileHandler *ini.File
}

AppConfig hold the configration from ini file

func NewAppConfigFromFile

func NewAppConfigFromFile(filename string) (*AppConfig, error)

NewAppConfigFromFile read a appConfig.ini file from local file system and return the AppConfig object

type AppController

type AppController struct {
	sync.RWMutex
	*JobConfig
	*AppConfig
	LoadManager
	LoadCaller
	Status   uint32
	IsMaster bool
}

AppController hold all infomation and control interface for this app

func GetGlobalAppController

func GetGlobalAppController() *AppController

GetGlobalAppController return current appAppController

func NewAppControllerFromFile

func NewAppControllerFromFile(file string) (*AppController, error)

NewAppControllerFromFile load the AppController and save to global variable

func (*AppController) GetCurrentJobStatus

func (config *AppController) GetCurrentJobStatus() uint32

GetCurrentJobStatus return current task running status

func (*AppController) GetCurrentJobStatusString

func (config *AppController) GetCurrentJobStatusString() string

GetCurrentJobStatusString return the readable string

func (*AppController) SetCurrentJobStatus

func (config *AppController) SetCurrentJobStatus(status uint32) error

SetCurrentJobStatus change the status of current task

type DBHandler

type DBHandler struct {
	*gorm.DB
}

DBHandler db manager

func GetDBHandler

func GetDBHandler() *DBHandler

GetDBHandler return global db manager

func (*DBHandler) CreateDNSQueryHistory

func (dbHander *DBHandler) CreateDNSQueryHistory(appController *AppController) error

CreateDNSQueryHistory save a new dns query info

func (*DBHandler) GetDNSQueryHistory

func (dbHander *DBHandler) GetDNSQueryHistory(start, length int, search string) ([]DNSQuery, error)

GetDNSQueryHistory return DNSQuery for datatables

type DNSClient

type DNSClient struct {
	Conn    []net.Conn
	NumConn int
	Offset  int
	// contains filtered or unexported fields
}

DNSClient hold the loader configuration setting and connection

func NewDNSClient

func NewDNSClient(app *AppController) (dnsclient *DNSClient, err error)

NewDNSClient create a new DNSClient instance

func (*DNSClient) BuildReq

func (client *DNSClient) BuildReq(job *JobConfig) []byte

BuildReq build new dns request for use later

func (*DNSClient) Call

func (client *DNSClient) Call(req []byte)

Call func will be called by schedual each time

func (*DNSClient) InitPacket

func (client *DNSClient) InitPacket(job *JobConfig) error

InitPacket init a packet for dns query data

type DNSQuery

type DNSQuery struct {
	gorm.Model
	JobConfig
}

DNSQuery save all query history

type Event

type Event uint8

Event define the event send to all node

const (
	// Ready usually for listening status
	Ready Event = iota
	// Start and send the new config
	Start
	// Status the status
	Status
	// Running status with some message
	Running
	// Kill the load
	Kill
	// Error Status
	Error
	// Stop the load in normal way
	Stop
)

type JobConfig

type JobConfig struct {
	JobID              string `json:"job_id" valid:"uuid,optional"`
	Duration           string `json:"duration" valid:"-"`
	Protocol           string `json:"protocol" valid:"in(tcp|udp),optional"`
	QPS                uint32 `json:"qps" valid:"-"`
	ClientNumber       int    `json:"client_number" valid:"-"`
	MaxQuery           uint64 `json:"max_query" valid:"-"`
	Server             string `json:"server" valid:"ip,optional"`
	Port               string `json:"port" valid:"port,optional"`
	Domain             string `json:"domain" valid:"-"`
	EnableEDNS         string `json:"edns_enable" valid:"-"`
	EnableDNSSEC       string `json:"dnssec_enable" valid:"-"`
	DomainRandomLength int    `json:"domain_random_length" valid:"-"`
	QueryType          string `json:"query_type" valid:"-"`
}

JobConfig hold the job appAppController

func NewDefaultJobConfig

func NewDefaultJobConfig() *JobConfig

NewDefaultJobConfig create a init job for appConfigration

func (*JobConfig) ValidateJob

func (jobConfig *JobConfig) ValidateJob() error

ValidateJob validate the job config

type LoadCaller

type LoadCaller interface {
	BuildReq(job *JobConfig) []byte
	Call(req []byte)
}

LoadCaller define the behavior of call processor

type LoadManager

type LoadManager interface {
	Start() bool
	Stop() bool
	Status() uint32
	CallCount() uint64
}

LoadManager define the behavior of dns benchmark loader

func NewDNSLoaderGenerator

func NewDNSLoaderGenerator(param LoadParams) (LoadManager, error)

NewDNSLoaderGenerator will return a new instance of generator using param from GeneratorParam

type LoadParams

type LoadParams struct {
	Caller       LoadCaller
	Timeout      time.Duration
	QPS          uint32
	Max          uint64
	ClientNumber int
	Protocol     string
	Duration     time.Duration
}

LoadParams will be used to new a loader instance with this param

func (*LoadParams) Info

func (param *LoadParams) Info() string

Info return the basic info of lodaer params

func (*LoadParams) ValidCheck

func (param *LoadParams) ValidCheck() error

ValidCheck function

type NodeInfo

type NodeInfo struct {
	Agent
	JobID  string `json:"job_id" valid:"-"`
	Status string `json:"status" valid:"-"`
	Error  string `json:"error" valid:"-"`
}

NodeInfo hold current Node baisc info and job info

type NodeManager

type NodeManager struct {
	DB        *gorm.DB
	NodeInfos map[string]NodeInfo
	// contains filtered or unexported fields
}

NodeManager define the node list when new config generated the manager will call the nodes one by one

func GetNodeManager

func GetNodeManager() *NodeManager

GetNodeManager global manager interface

func NewNodeManager

func NewNodeManager() *NodeManager

NewNodeManager will create a new node manager

func (*NodeManager) AddNode

func (manager *NodeManager) AddNode(ip string, port string) error

AddNode append a new ip to this node list

func (*NodeManager) Agents

func (manager *NodeManager) Agents() (agents []Agent)

Agents get all agents info

func (*NodeManager) Call

func (manager *NodeManager) Call(event Event, data interface{}) error

Call function will send data to all agents

func (*NodeManager) GetEnabledStatusAgent

func (manager *NodeManager) GetEnabledStatusAgent() ([]Agent, error)

GetEnabledStatusAgent get all enabled status

func (*NodeManager) RemoveNode

func (manager *NodeManager) RemoveNode(ip string, port string) error

RemoveNode will remove the ip from current list

func (*NodeManager) SyncDBForAgents

func (manager *NodeManager) SyncDBForAgents() error

SyncDBForAgents sync db to current list

func (*NodeManager) UpdateEnableStatusAgent

func (manager *NodeManager) UpdateEnableStatusAgent(ip string, port string, enable bool) error

UpdateEnableStatusAgent will enable or disable one agent when using benchmark

func (*NodeManager) UpdateLiveStatusAgent

func (manager *NodeManager) UpdateLiveStatusAgent(agent Agent, live bool) error

UpdateLiveStatusAgent will set live or dead status on one agent when using benchmark

Jump to

Keyboard shortcuts

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