–
– import “lorhammer/src/lorhammer/command”
func ApplyCmd(command model.CMD, mqtt tools.Mqtt, hostname string, lorhammerAddedChan chan bool, prometheus metrics.Prometheus)
ApplyCmd take a model.CMD and execute it
func Start(mqtt tools.Mqtt, hostname string, maxWaitOrchestratorTime time.Duration) chan bool
Start send model.NEWLORHAMMER command every second until orchestrator has respond model.LORHAMMERADDED command
– import “lorhammer/src/lorhammer/lora”
func GetPushDataPayload(node *model.Node, fcnt uint32) ([]byte, int64, error)
GetPushDataPayload return the nextbyte arraypush data
type LorhammerGateway struct {
Nodes []*model.Node
NsAddress string
MacAddress lorawan.EUI64
RxpkDate int64
PayloadsReplayMaxLaps int
AllLapsCompleted bool
ReceiveTimeoutTime time.Duration
}
LorhammerGateway : internal gateway for pointer receiver usage
func NewGateway(nbNode int, init model.Init) *LorhammerGateway
NewGateway return a new gateway with node configured
func (gateway LorhammerGateway) ConvertToGateway() model.Gateway
ConvertToGateway : convert internal gateway to model gateway
func (gateway *LorhammerGateway) Join(prometheus metrics.Prometheus, withJoin bool) error
Join send first pull datata to be discovered by network server Then send a
JoinRequest packet if withJoin
is set in scenario file
func (gateway *LorhammerGateway) Start(prometheus metrics.Prometheus, fcnt uint32) error
Start send push data packet and listen for ack
– import “lorhammer/src/lorhammer/metrics”
type Prometheus interface {
StartPushAckTimer() func()
StartPullRespTimer() func()
AddGateway(nb int)
SubGateway(nb int)
AddNodes(nb int)
SubNodes(nb int)
AddPushAckLongRequest(nb int)
AddPullRespLongRequest(nb int)
}
Prometheus export prometheus metrics
func NewPrometheus() Prometheus
NewPrometheus return a Prometheus instance
– import “lorhammer/src/lorhammer/scenario”
type Scenario struct {
UUID string
Gateways []*lora.LorhammerGateway
ScenarioSleepTime [2]time.Duration
GatewaySleepTime [2]time.Duration
NbScenarioReplayLaps int
RxpkDate uint64
WithJoin bool
MessageFcnt uint32
AppsKey string
Nwskey string
Payloads []model.Payload
}
Scenario struc define scenari with metadata
func NewScenario(init model.Init) (*Scenario, error)
NewScenario provide new Scenario with param defined in model.Init
func (p *Scenario) Cron(prometheus metrics.Prometheus) context.Context
Cron start scenario in go routine and start gateway every
scenario.ScenarioSleepTime
func (p *Scenario) Join(prometheus metrics.Prometheus)
Join launch all gateways join method
func (p *Scenario) Stop(prometheus metrics.Prometheus)
Stop stop scenario launched in Start
– import “lorhammer/src/model”
const (
NEWLORHAMMER = "newLorhammer" // prevent orchestrator new lorhammer is here LORHAMMER -> ORCHESTRATOR
LORHAMMERADDED = "lorhammerAdded" // orchestrator has received lorhammer infos ORCHESTRATOR -> LORHAMME
INIT = "init" // send init (lorawan info) ORCHESTRATOR -> LORHAMMER
REGISTER = "register" // send lorawan sensors to provision LORHAMMER -> ORCHESTRATOR
START = "start" // send start after sensors provisioning ORCHESTRATOR -> LORHAMMER
STOP = "stop" // send stop to finish test ORCHESTRATOR -> LORHAMMER
SHUTDOWN = "shutdown" // kill lorhammers ORCHESTRATOR -> LORHAMMER
)
All commands for communication between orchestrator and lorhammer
type CMD struct {
CmdName CommandName `json:"cmd"`
Payload json.RawMessage `json:"payload"`
}
CMD is the stuct for communication between orchestrator and lorhammer
type CommandName string
CommandName is a type to be sure command are send (and not all string possible)
type Gateway struct {
Nodes []*Node
NsAddress string
MacAddress lorawan.EUI64
RxpkDate int64
PayloadsReplayMaxLaps int
AllLapsCompleted bool
ReceiveTimeoutTime time.Duration
}
Gateway represent a lorawan gateway
type Init struct {
NsAddress string `json:"nsAddress"`
NbGateway int `json:"nbGatewayPerLorhammer"`
NbNode [2]int `json:"nbNodePerGateway"`
NbScenarioReplayLaps int `json:"nbScenarioReplayLaps"`
ScenarioSleepTime [2]string `json:"scenarioSleepTime"`
GatewaySleepTime [2]string `json:"gatewaySleepTime"`
AppsKey string `json:"appskey"`
Nwskey string `json:"nwskey"`
WithJoin bool `json:"withJoin"`
Payloads []Payload `json:"payloads"`
RxpkDate int64 `json:"rxpkDate"`
ReceiveTimeoutTime string `json:"receiveTimeoutTime"`
Description string `json:"description"`
RandomPayloads bool `json:"randomPayloads"`
}
Init is the struc send by orchestrator to lorhammer
type NewLorhammer struct {
CallbackTopic string
}
NewLorhammer is the struct used by lorhammer to prevent orchestrator
type Node struct {
DevAddr lorawan.DevAddr
DevEUI lorawan.EUI64
AppEUI lorawan.EUI64
AppKey lorawan.AES128Key
AppSKey lorawan.AES128Key
NwSKey lorawan.AES128Key
JoinedNetwork bool
Payloads []Payload
NextPayload int
PayloadsReplayLap int
RandomPayloads bool
Description string
}
Node represent a lorawan sensor
type Payload struct {
Value string `json:"value"`
Date int64 `json:"date"`
}
Payload struct define a payload with timestamp date attached { “value”: “a
string”, “date”: Register struct is the command send by lorhammer to orchestrator for register
gateway and sensors to network-server Start is the command send by orchestrator to lorhammer because all gateway and
sensor have been registered – –
import “lorhammer/src/orchestrator/checker” Checker check if data is correct depending on implementation Get return a checker if the Model is an implementation of Checker Error is the interface fo details error depending on implementation Model is the structure loaded from json file Success is the interface fo details success depending on implementation Type is a type to define a checker –
import “lorhammer/src/orchestrator/cli” Start launch the cli mode and ask to user to select actions –
import “lorhammer/src/orchestrator/command” ApplyCmd launch a model.CMD received from a lorhammer LaunchScenario emit a model.INIT command for lorhammers over mqtt NbLorhammer return the current number of lorhammer listening for init scenario NewLorhammer add a new lorhammer topic to be able to init scenario ShutdownLorhammers emit a model.SHUTDOWN command for lorhammers over mqtt StopScenario emit a model.STOP command for lorhammers over mqtt –
import “lorhammer/src/orchestrator/deploy” Start launch a deployement Model represent a deployer in config file UnmarshalJSON permit to json to object a depoyer Type is type to define a deployer –
import “lorhammer/src/orchestrator/metrics” Prometheus export prometheus metrics NewPrometheus return a Prometheus instance –
import “lorhammer/src/orchestrator/prometheus” APIClient permit communication with prometheus rest api NewAPIClient return an APIClient of prometheus –
import “lorhammer/src/orchestrator/provisioning” DeProvision delete all references of a previous Provision() Provision start a provisioner Model is the representation of provisioner in json config file Type represent provioner type from json –
import “lorhammer/src/orchestrator/testsuite” TestReport is a struct which encapsulate all information about a test WriteFile write the report in json into the file located at pathReportFile TestSuite describe a test to execute scenarios FromFile build []testSuite from a json file LaunchTest manage life cycle of a test (start, stop, check, report…) –
import “lorhammer/src/orchestrator/testtype” Start launch a test Test is the representation of a test in config file UnmarshalJSON permit to load a Test from a json Type represent a testType –
import “lorhammer/src/tools” Channels mqtt to use FreeTCPPort return free tcp port on host Hostname return unique hostname_ip:port string Random generate random int between min and max Deprecated: use Random64 instead Random16Bytes generate random [16]byte Random2Bytes generate random [2]byte Random4Bytes generate random [4]byte Random64 generate random int64 between min and max Random8Bytes generate random [8]byte RandomBytes generate random int64 between min and max RandomDuration generate random time.Duration between min and max Mqtt is responsible of communication with the mqtt server NewMqtt return a Mqtt based on mqttAddr (protocol://ip:port) and set clientID
with hostname NewMqttBasic return a Mqtt clienttype Register
type Register struct {
ScenarioUUID string `json:"scenarioid"`
Gateways []Gateway `json:"gateways"`
CallBackTopic string `json:"callBackTopic"`
}
type Start
type Start struct {
ScenarioUUID string `json:"scenarioid"`
}
orchestrator
checker
Usage
type Checker
type Checker interface {
Start() error
Check() ([]Success, []Error)
}
func Get
func Get(checker Model, prometheus metrics.Prometheus) (Checker, error)
type Error
type Error interface {
Details() map[string]interface{}
}
type Model
type Model struct {
Type Type `json:"type"`
Config json.RawMessage `json:"config"`
}
type Success
type Success interface {
Details() map[string]interface{}
}
type Type
type Type string
cli
Usage
func Start
func Start(mqttClient tools.Mqtt)
command
Usage
func ApplyCmd
func ApplyCmd(command model.CMD, mqtt tools.Mqtt, provision func(model.Register) error, newLorhammer func(model.NewLorhammer) error) error
func LaunchScenario
func LaunchScenario(mqttClient tools.Mqtt, inits []model.Init) error
func NbLorhammer
func NbLorhammer() int
func NewLorhammer
func NewLorhammer(newLorhammer model.NewLorhammer) error
func ShutdownLorhammers
func ShutdownLorhammers(mqttClient tools.Mqtt)
func StopScenario
func StopScenario(mqttClient tools.Mqtt)
deploy
Usage
func Start
func Start(model Model, mqttClient tools.Mqtt) error
type Model
type Model struct {
Type Type
Config json.RawMessage
}
func (*Model) UnmarshalJSON
func (m *Model) UnmarshalJSON(b []byte) error
type Type
type Type string
metrics
Usage
type Prometheus
type Prometheus interface {
AddMQTTMessageOK()
AddMQTTMessageFailed()
}
func NewPrometheus
func NewPrometheus() Prometheus
prometheus
Usage
type APIClient
type APIClient interface {
ExecQuery(query string) (float64, error)
}
func NewAPIClient
func NewAPIClient(address string) (APIClient, error)
provisioning
Usage
func DeProvision
func DeProvision(uuid string) error
func Provision
func Provision(uuid string, provisioning Model, sensorsToRegister model.Register) error
type Model
type Model struct {
Type Type `json:"type"`
Config json.RawMessage `json:"config"`
}
type Type
type Type string
testsuite
Usage
type TestReport
type TestReport struct {
StartDate time.Time `json:"startDate"`
EndDate time.Time `json:"endDate"`
Input *TestSuite `json:"input"`
ChecksSuccess []checker.Success `json:"checksSuccess"`
ChecksError []checker.Error `json:"checksError"`
}
func (*TestReport) WriteFile
func (testReport *TestReport) WriteFile(pathReportFile string) error
type TestSuite
type TestSuite struct {
UUID string `json:"uuid"`
Test testtype.Test `json:"test"`
StopAllLorhammerTime time.Duration `json:"stopAllLorhammerTime"`
SleepBeforeCheckTime time.Duration `json:"sleepBeforeCheckTime"`
ShutdownAllLorhammerTime time.Duration `json:"shutdownAllLorhammerTime"`
SleepAtEndTime time.Duration `json:"sleepAtEndTime"`
RequieredLorhammer int `json:"requieredLorhammer"`
MaxWaitLorhammerTime time.Duration `json:"maxWaitLorhammerTime"`
Init []model.Init `json:"init"`
Check checker.Model `json:"check"`
Provisioning provisioning.Model `json:"provisioning"`
Deploy deploy.Model `json:"deploy"`
}
func FromFile
func FromFile(configFile []byte) ([]TestSuite, error)
func (*TestSuite) LaunchTest
func (test *TestSuite) LaunchTest(mqttClient tools.Mqtt, prometheus metrics.Prometheus) (*TestReport, error)
testtype
Usage
func Start
func Start(test Test, init []model.Init, mqttClient tools.Mqtt) error
type Test
type Test struct {
}
func (*Test) UnmarshalJSON
func (test *Test) UnmarshalJSON(b []byte) error
type Type
type Type string
tools
Usage
const (
MqttLorhammerTopic = "/lorhammer"
MqttOrchestratorTopic = "/lorhammer/orchestrator"
)
func FreeTCPPort
func FreeTCPPort() (int, error)
func Hostname
func Hostname(port int) (string, error)
func Random
func Random(min, max int) int
func Random16Bytes
func Random16Bytes() [16]byte
func Random2Bytes
func Random2Bytes() [2]byte
func Random4Bytes
func Random4Bytes() [4]byte
func Random64
func Random64(min, max int64) int64
func Random8Bytes
func Random8Bytes() [8]byte
func RandomBytes
func RandomBytes(nb int) []byte
func RandomDuration
func RandomDuration(min, max time.Duration) time.Duration
type Mqtt
type Mqtt interface {
Connect() error
Disconnect()
GetAddress() string
Handle(topics []string, handle func(message []byte)) error
HandleCmd(topics []string, handle func(cmd model.CMD)) error
PublishCmd(topic string, cmdName model.CommandName) error
PublishSubCmd(topic string, cmdName model.CommandName, subCmd interface{}) error
}
func NewMqtt
func NewMqtt(hostname string, mqttAddr string) (Mqtt, error)
func NewMqttBasic
func NewMqttBasic(url string, clientID string) (Mqtt, error)