datamodel

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package datamodel provides a comprehensive implementation of a stateful CPE (Customer Premises Equipment) data model. It includes functionalities for managing and manipulating parameter values, handling events, and simulating various states of the CPE. The package supports different versions of data models, such as TR-098 and TR-181, and provides mechanisms to detect and work with these versions. It also includes utilities for managing retry attempts, command keys, and simulated downtimes, ensuring robust and flexible handling of CPE operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadDataModel added in v0.2.1

func LoadDataModel(r io.Reader) (map[string]Parameter, error)

LoadDataModel reads the data model from the provided io.Reader and returns a map of parameters. It expects the data to be in CSV format with a header row. Each row should contain the path, object flag, writable flag, value, and type of the parameter. If there is an error reading or parsing the CSV data, it returns an error.

func LoadDataModelFile added in v0.2.9

func LoadDataModelFile(filePath string) (map[string]Parameter, error)

LoadDataModelFile loads the data model from the specified file path.

func NormalizeParameters added in v0.2.1

func NormalizeParameters(params map[string]Parameter)

NormalizeParameters will normalize all datamodel parameters.

Types

type DataModel

type DataModel struct {
	// contains filtered or unexported fields
}

DataModel describes a stateful CPE datamodel.

func New added in v0.2.1

func New(state *State) *DataModel

New creates a new DataModel instance with the given state.

func (*DataModel) AddEvent

func (dm *DataModel) AddEvent(evt string)

AddEvent adds a new event to be advertised during the next inform message.

func (*DataModel) AddObject

func (dm *DataModel) AddObject(name string) (int, error)

AddObject create a new object and returns the index if successful.

func (*DataModel) CanSetValue

func (dm *DataModel) CanSetValue(param Parameter) *rpc.FaultCode

CanSetValue returns a non-nil fault code if a value can't be set.

func (*DataModel) ClearEvents

func (dm *DataModel) ClearEvents()

ClearEvents removes all pending inform events.

func (*DataModel) CommandKey

func (dm *DataModel) CommandKey() string

CommandKey returns the current command key.

func (*DataModel) ConnectionRequestPassword added in v0.3.0

func (dm *DataModel) ConnectionRequestPassword() Parameter

ConnectionRequestPassword returns the connection request password.

func (*DataModel) ConnectionRequestURL

func (dm *DataModel) ConnectionRequestURL() Parameter

ConnectionRequestURL returns the connection request URL.

func (*DataModel) ConnectionRequestUsername added in v0.3.0

func (dm *DataModel) ConnectionRequestUsername() Parameter

ConnectionRequestUsername returns the connection request username.

func (*DataModel) DeleteObject

func (dm *DataModel) DeleteObject(name string)

DeleteObject deletes the given object.

func (*DataModel) DeviceID

func (dm *DataModel) DeviceID() DeviceID

DeviceID returns a DeviceID populated from the datamodel.

func (*DataModel) DownUntil

func (dm *DataModel) DownUntil() time.Time

DownUntil returns the time the CPE will stop pretending to be offline.

func (*DataModel) Each added in v0.3.1

func (dm *DataModel) Each(fn func(p Parameter) (cont bool))

Each iterates over all parameters in the DataModel. Iteration can be stopped by returning false from the callback function.

func (*DataModel) ForcedInformParameters added in v0.2.7

func (dm *DataModel) ForcedInformParameters() []string

ForcedInformParameters values that must be on every inform, according to the datamodel specifications.

TR-098: https://cwmp-data-models.broadband-forum.org/tr-098-1-2-0.html#forced-inform-parameters TR-181: https://cwmp-data-models.broadband-forum.org/tr-181-2-18-1-cwmp.html#forced-inform-parameters

func (*DataModel) GetAll

func (dm *DataModel) GetAll(path string) (params []Parameter, ok bool)

GetAll returns one or more parameters prefixed with the given path.

func (*DataModel) GetValue

func (dm *DataModel) GetValue(path string) (p Parameter, ok bool)

GetValue returns a parameter value with the given path and a boolean that is equal to true if a parameter exists.

func (*DataModel) GetValues added in v0.2.7

func (dm *DataModel) GetValues(paths ...string) (params []Parameter, ok bool)

GetValues returns all parameters in the given paths. If at least one requested parameter is missing ok will be set to false.

func (*DataModel) IncrRetryAttempts

func (dm *DataModel) IncrRetryAttempts()

IncrRetryAttempts increments the number of infrom attempts by one.

func (*DataModel) IsBootstrapped

func (dm *DataModel) IsBootstrapped() bool

IsBootstrapped returns true if CPE is had a successful bootstrap message exchange.

func (*DataModel) NotifyParams

func (dm *DataModel) NotifyParams() []string

NotifyParams returns a list of parameters that should be included in the next inform message. This will always include forced parameters.

func (*DataModel) ParameterNames

func (dm *DataModel) ParameterNames(path string, nextLevel bool) []Parameter

ParameterNames returns all subparameters in the given path. If nextLevel is set to true the list of parameters goes one level deeper.

func (*DataModel) PendingEvents

func (dm *DataModel) PendingEvents() []string

PendingEvents returns all events to be advertised during the next inform message.

func (*DataModel) PeriodicInformEnabled

func (dm *DataModel) PeriodicInformEnabled() bool

PeriodicInformEnabled returns true if periodic inform is enabled.

func (*DataModel) PeriodicInformInterval

func (dm *DataModel) PeriodicInformInterval() time.Duration

PeriodicInformInterval returns the value of periodic inform interval.

func (*DataModel) PeriodicInformTime

func (dm *DataModel) PeriodicInformTime() time.Time

PeriodicInformTime returns the value of periodic inform time.

func (*DataModel) Reset added in v0.2.1

func (dm *DataModel) Reset()

Reset clears the DataModel to its initial state.

func (*DataModel) ResetRetryAttempts

func (dm *DataModel) ResetRetryAttempts()

ResetRetryAttempts resets the number of infrom attempts to zero.

func (*DataModel) RetryAttempts

func (dm *DataModel) RetryAttempts() uint32

RetryAttempts returns the number of currently take attepts to inform.

func (*DataModel) SaveState

func (dm *DataModel) SaveState(stateFile string) error

SaveState saves the state to the given file.

func (*DataModel) SetBootstrapped

func (dm *DataModel) SetBootstrapped(b bool)

SetBootstrapped assigns the bootstrap flag to the given value.

func (*DataModel) SetCommandKey

func (dm *DataModel) SetCommandKey(ck string)

SetCommandKey sets the command key value.

func (*DataModel) SetConnectionRequestURL

func (dm *DataModel) SetConnectionRequestURL(val string)

SetConnectionRequestURL sets connection request URL to the given value.

func (*DataModel) SetDownUntil

func (dm *DataModel) SetDownUntil(du time.Time)

SetDownUntil sets the time until the CPE should pretend to be offline.

func (*DataModel) SetFirmwareVersion

func (dm *DataModel) SetFirmwareVersion(ver string)

SetFirmwareVersion sets the new firmware version value.

func (*DataModel) SetParameterAttribute

func (dm *DataModel) SetParameterAttribute(name string, notif int, notifChange bool, acl []string, aclChange bool)

SetParameterAttribute changes parameter value attributes.

func (*DataModel) SetParameterKey

func (dm *DataModel) SetParameterKey(val string)

SetParameterKey sets parameter key to the given value.

func (*DataModel) SetPeriodicInformInterval

func (dm *DataModel) SetPeriodicInformInterval(sec int64)

SetPeriodicInformInterval sets periodic inform interval to the given value.

func (*DataModel) SetPeriodicInformTime

func (dm *DataModel) SetPeriodicInformTime(ts time.Time)

SetPeriodicInformTime sets periodic inform time to the given value.

func (*DataModel) SetSerialNumber

func (dm *DataModel) SetSerialNumber(val string)

SetSerialNumber sets serial number to the given value.

func (*DataModel) SetUDPConnectionRequestAddress added in v0.3.0

func (dm *DataModel) SetUDPConnectionRequestAddress(val string)

SetUDPConnectionRequestAddress sets UDP connection request address to the given value.

func (*DataModel) SetUptime added in v0.2.0

func (dm *DataModel) SetUptime(dur time.Duration)

SetUptime sets the device uptime to the given duration.

func (*DataModel) SetValue

func (dm *DataModel) SetValue(path, val string)

SetValue sets the value of a given parameter.

func (*DataModel) SetValues

func (dm *DataModel) SetValues(params []Parameter)

SetValues saves multiple parameter values.

func (*DataModel) UDPConnectionRequestAddress added in v0.3.0

func (dm *DataModel) UDPConnectionRequestAddress() Parameter

UDPConnectionRequestAddress returns the UDP connection request address.

func (*DataModel) Version added in v0.2.9

func (dm *DataModel) Version() string

Version returns the current version of the DataModel.

type DeviceID

type DeviceID struct {
	Manufacturer string
	OUI          string
	ProductClass string
	SerialNumber string
}

DeviceID contains basic CPE info.

type Parameter

type Parameter struct {
	Path         string
	Object       bool
	Writable     bool
	Type         string
	Value        string
	Notification rpc.AttributeNotification
	ACL          []string
	// contains filtered or unexported fields
}

Parameter describes a datamodel paremeter.

func (*Parameter) Encode

func (p *Parameter) Encode() rpc.ParameterValueEncoder

Encode converts a parameter into RPC ParameterValue structure.

func (*Parameter) GetValue added in v0.3.0

func (p *Parameter) GetValue() string

GetValue returns a parameter value. If the parameter has a generator function it will be used to produce a value, otherwise the value from the parameter will be returned.

func (*Parameter) Name added in v0.3.1

func (p *Parameter) Name() string

Name returns parameter name.

func (*Parameter) Normalize added in v0.2.0

func (p *Parameter) Normalize()

Normalize attempts to normalize parameter type and value in order to make it fully compliant with SOAP data types spec.

type State added in v0.2.1

type State struct {
	Bootstrapped bool                 `json:"Bootstrapped"`
	Changes      map[string]Parameter `json:"Changes"`
	Deleted      map[string]struct{}  `json:"Deleted"`
	// contains filtered or unexported fields
}

State represents the state of parameters with support for tracking changes, deletions, and default values. It uses a read-write mutex to ensure thread- safe access and modifications.

func LoadState added in v0.2.1

func LoadState(filePath string) (*State, error)

LoadState loads the state from the specified file path. If the file path is empty or the file does not exist, it returns a new state. If there is an error reading or parsing the file, it returns an error.

func (*State) WithDefaults added in v0.2.1

func (s *State) WithDefaults(dm map[string]Parameter) *State

WithDefaults sets the default parameters for the state and returns the updated state. It allows chaining of state modifications.

Directories

Path Synopsis
Package noise provides algorithms to generate sequences of values that simulate sensor readings with various patterns, including random walk, piecewise linear, sine wave with noise, and Perlin noise.
Package noise provides algorithms to generate sequences of values that simulate sensor readings with various patterns, including random walk, piecewise linear, sine wave with noise, and Perlin noise.

Jump to

Keyboard shortcuts

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