Lorhammer

lorhammer

command

– import “lorhammer/src/lorhammer/command”

Usage

func ApplyCmd

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

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

lora

– import “lorhammer/src/lorhammer/lora”

Usage

func GetPushDataPayload

func GetPushDataPayload(node *model.Node, fcnt uint32) ([]byte, int64, error)

GetPushDataPayload return the nextbyte arraypush data

type LorhammerGateway

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

func NewGateway(nbNode int, init model.Init) *LorhammerGateway

NewGateway return a new gateway with node configured

func (LorhammerGateway) ConvertToGateway

func (gateway LorhammerGateway) ConvertToGateway() model.Gateway

ConvertToGateway : convert internal gateway to model gateway

func (*LorhammerGateway) Join

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 (*LorhammerGateway) Start

func (gateway *LorhammerGateway) Start(prometheus metrics.Prometheus, fcnt uint32) error

Start send push data packet and listen for ack

metrics

– import “lorhammer/src/lorhammer/metrics”

Usage

type Prometheus

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

func NewPrometheus() Prometheus

NewPrometheus return a Prometheus instance

scenario

– import “lorhammer/src/lorhammer/scenario”

Usage

type 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

func NewScenario(init model.Init) (*Scenario, error)

NewScenario provide new Scenario with param defined in model.Init

func (*Scenario) Cron

func (p *Scenario) Cron(prometheus metrics.Prometheus) context.Context

Cron start scenario in go routine and start gateway every scenario.ScenarioSleepTime

func (*Scenario) Join

func (p *Scenario) Join(prometheus metrics.Prometheus)

Join launch all gateways join method

func (*Scenario) Stop

func (p *Scenario) Stop(prometheus metrics.Prometheus)

Stop stop scenario launched in Start

model

– import “lorhammer/src/model”

Usage

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

type CMD struct {
	CmdName CommandName     `json:"cmd"`
	Payload json.RawMessage `json:"payload"`
}

CMD is the stuct for communication between orchestrator and lorhammer

type CommandName

type CommandName string

CommandName is a type to be sure command are send (and not all string possible)

type Gateway

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

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

type NewLorhammer struct {
	CallbackTopic string
}

NewLorhammer is the struct used by lorhammer to prevent orchestrator

type Node

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

type Payload struct {
	Value string `json:"value"`
	Date  int64  `json:"date"`
}

Payload struct define a payload with timestamp date attached { “value”: “a string”, “date”: }

type Register

type Register struct {
	ScenarioUUID  string    `json:"scenarioid"`
	Gateways      []Gateway `json:"gateways"`
	CallBackTopic string    `json:"callBackTopic"`
}

Register struct is the command send by lorhammer to orchestrator for register gateway and sensors to network-server

type Start

type Start struct {
	ScenarioUUID string `json:"scenarioid"`
}

Start is the command send by orchestrator to lorhammer because all gateway and sensor have been registered

orchestrator

checker

– import “lorhammer/src/orchestrator/checker”

Usage

type Checker

type Checker interface {
	Start() error
	Check() ([]Success, []Error)
}

Checker check if data is correct depending on implementation

func Get

func Get(checker Model, prometheus metrics.Prometheus) (Checker, error)

Get return a checker if the Model is an implementation of Checker

type Error

type Error interface {
	Details() map[string]interface{}
}

Error is the interface fo details error depending on implementation

type Model

type Model struct {
	Type   Type            `json:"type"`
	Config json.RawMessage `json:"config"`
}

Model is the structure loaded from json file

type Success

type Success interface {
	Details() map[string]interface{}
}

Success is the interface fo details success depending on implementation

type Type

type Type string

Type is a type to define a checker

cli

– import “lorhammer/src/orchestrator/cli”

Usage

func Start

func Start(mqttClient tools.Mqtt)

Start launch the cli mode and ask to user to select actions

command

– import “lorhammer/src/orchestrator/command”

Usage

func ApplyCmd

func ApplyCmd(command model.CMD, mqtt tools.Mqtt, provision func(model.Register) error, newLorhammer func(model.NewLorhammer) error) error

ApplyCmd launch a model.CMD received from a lorhammer

func LaunchScenario

func LaunchScenario(mqttClient tools.Mqtt, inits []model.Init) error

LaunchScenario emit a model.INIT command for lorhammers over mqtt

func NbLorhammer

func NbLorhammer() int

NbLorhammer return the current number of lorhammer listening for init scenario

func NewLorhammer

func NewLorhammer(newLorhammer model.NewLorhammer) error

NewLorhammer add a new lorhammer topic to be able to init scenario

func ShutdownLorhammers

func ShutdownLorhammers(mqttClient tools.Mqtt)

ShutdownLorhammers emit a model.SHUTDOWN command for lorhammers over mqtt

func StopScenario

func StopScenario(mqttClient tools.Mqtt)

StopScenario emit a model.STOP command for lorhammers over mqtt

deploy

– import “lorhammer/src/orchestrator/deploy”

Usage

func Start

func Start(model Model, mqttClient tools.Mqtt) error

Start launch a deployement

type Model

type Model struct {
	Type   Type
	Config json.RawMessage
}

Model represent a deployer in config file

func (*Model) UnmarshalJSON

func (m *Model) UnmarshalJSON(b []byte) error

UnmarshalJSON permit to json to object a depoyer

type Type

type Type string

Type is type to define a deployer

metrics

– import “lorhammer/src/orchestrator/metrics”

Usage

type Prometheus

type Prometheus interface {
	AddMQTTMessageOK()
	AddMQTTMessageFailed()
}

Prometheus export prometheus metrics

func NewPrometheus

func NewPrometheus() Prometheus

NewPrometheus return a Prometheus instance

prometheus

– import “lorhammer/src/orchestrator/prometheus”

Usage

type APIClient

type APIClient interface {
	ExecQuery(query string) (float64, error)
}

APIClient permit communication with prometheus rest api

func NewAPIClient

func NewAPIClient(address string) (APIClient, error)

NewAPIClient return an APIClient of prometheus

provisioning

– import “lorhammer/src/orchestrator/provisioning”

Usage

func DeProvision

func DeProvision(uuid string) error

DeProvision delete all references of a previous Provision()

func Provision

func Provision(uuid string, provisioning Model, sensorsToRegister model.Register) error

Provision start a provisioner

type Model

type Model struct {
	Type   Type            `json:"type"`
	Config json.RawMessage `json:"config"`
}

Model is the representation of provisioner in json config file

type Type

type Type string

Type represent provioner type from json

testsuite

– import “lorhammer/src/orchestrator/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"`
}

TestReport is a struct which encapsulate all information about a test

func (*TestReport) WriteFile

func (testReport *TestReport) WriteFile(pathReportFile string) error

WriteFile write the report in json into the file located at pathReportFile

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"`
}

TestSuite describe a test to execute scenarios

func FromFile

func FromFile(configFile []byte) ([]TestSuite, error)

FromFile build []testSuite from a json file

func (*TestSuite) LaunchTest

func (test *TestSuite) LaunchTest(mqttClient tools.Mqtt, prometheus metrics.Prometheus) (*TestReport, error)

LaunchTest manage life cycle of a test (start, stop, check, report…)

testtype

– import “lorhammer/src/orchestrator/testtype”

Usage

func Start

func Start(test Test, init []model.Init, mqttClient tools.Mqtt) error

Start launch a test

type Test

type Test struct {
}

Test is the representation of a test in config file

func (*Test) UnmarshalJSON

func (test *Test) UnmarshalJSON(b []byte) error

UnmarshalJSON permit to load a Test from a json

type Type

type Type string

Type represent a testType

tools

– import “lorhammer/src/tools”

Usage

const (
	MqttLorhammerTopic    = "/lorhammer"
	MqttOrchestratorTopic = "/lorhammer/orchestrator"
)

Channels mqtt to use

func FreeTCPPort

func FreeTCPPort() (int, error)

FreeTCPPort return free tcp port on host

func Hostname

func Hostname(port int) (string, error)

Hostname return unique hostname_ip:port string

func Random

func Random(min, max int) int

Random generate random int between min and max Deprecated: use Random64 instead

func Random16Bytes

func Random16Bytes() [16]byte

Random16Bytes generate random [16]byte

func Random2Bytes

func Random2Bytes() [2]byte

Random2Bytes generate random [2]byte

func Random4Bytes

func Random4Bytes() [4]byte

Random4Bytes generate random [4]byte

func Random64

func Random64(min, max int64) int64

Random64 generate random int64 between min and max

func Random8Bytes

func Random8Bytes() [8]byte

Random8Bytes generate random [8]byte

func RandomBytes

func RandomBytes(nb int) []byte

RandomBytes generate random int64 between min and max

func RandomDuration

func RandomDuration(min, max time.Duration) time.Duration

RandomDuration generate random time.Duration between min and max

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
}

Mqtt is responsible of communication with the mqtt server

func NewMqtt

func NewMqtt(hostname string, mqttAddr string) (Mqtt, error)

NewMqtt return a Mqtt based on mqttAddr (protocol://ip:port) and set clientID with hostname

func NewMqttBasic

func NewMqttBasic(url string, clientID string) (Mqtt, error)

NewMqttBasic return a Mqtt client