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 ¶
- func LoadDataModel(r io.Reader) (map[string]Parameter, error)
- func LoadDataModelFile(filePath string) (map[string]Parameter, error)
- func NormalizeParameters(params map[string]Parameter)
- type DataModel
- func (dm *DataModel) AddEvent(evt string)
- func (dm *DataModel) AddObject(name string) (int, error)
- func (dm *DataModel) CanSetValue(param Parameter) *rpc.FaultCode
- func (dm *DataModel) ClearEvents()
- func (dm *DataModel) CommandKey() string
- func (dm *DataModel) ConnectionRequestPassword() Parameter
- func (dm *DataModel) ConnectionRequestURL() Parameter
- func (dm *DataModel) ConnectionRequestUsername() Parameter
- func (dm *DataModel) DeleteObject(name string)
- func (dm *DataModel) DeviceID() DeviceID
- func (dm *DataModel) DownUntil() time.Time
- func (dm *DataModel) Each(fn func(p Parameter) (cont bool))
- func (dm *DataModel) ForcedInformParameters() []string
- func (dm *DataModel) GetAll(path string) (params []Parameter, ok bool)
- func (dm *DataModel) GetValue(path string) (p Parameter, ok bool)
- func (dm *DataModel) GetValues(paths ...string) (params []Parameter, ok bool)
- func (dm *DataModel) IncrRetryAttempts()
- func (dm *DataModel) IsBootstrapped() bool
- func (dm *DataModel) NotifyParams() []string
- func (dm *DataModel) ParameterNames(path string, nextLevel bool) []Parameter
- func (dm *DataModel) PendingEvents() []string
- func (dm *DataModel) PeriodicInformEnabled() bool
- func (dm *DataModel) PeriodicInformInterval() time.Duration
- func (dm *DataModel) PeriodicInformTime() time.Time
- func (dm *DataModel) Reset()
- func (dm *DataModel) ResetRetryAttempts()
- func (dm *DataModel) RetryAttempts() uint32
- func (dm *DataModel) SaveState(stateFile string) error
- func (dm *DataModel) SetBootstrapped(b bool)
- func (dm *DataModel) SetCommandKey(ck string)
- func (dm *DataModel) SetConnectionRequestURL(val string)
- func (dm *DataModel) SetDownUntil(du time.Time)
- func (dm *DataModel) SetFirmwareVersion(ver string)
- func (dm *DataModel) SetParameterAttribute(name string, notif int, notifChange bool, acl []string, aclChange bool)
- func (dm *DataModel) SetParameterKey(val string)
- func (dm *DataModel) SetPeriodicInformInterval(sec int64)
- func (dm *DataModel) SetPeriodicInformTime(ts time.Time)
- func (dm *DataModel) SetSerialNumber(val string)
- func (dm *DataModel) SetUDPConnectionRequestAddress(val string)
- func (dm *DataModel) SetUptime(dur time.Duration)
- func (dm *DataModel) SetValue(path, val string)
- func (dm *DataModel) SetValues(params []Parameter)
- func (dm *DataModel) UDPConnectionRequestAddress() Parameter
- func (dm *DataModel) Version() string
- type DeviceID
- type Parameter
- type State
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadDataModel ¶ added in v0.2.1
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
LoadDataModelFile loads the data model from the specified file path.
func NormalizeParameters ¶ added in v0.2.1
NormalizeParameters will normalize all datamodel parameters.
Types ¶
type DataModel ¶
type DataModel struct {
// contains filtered or unexported fields
}
DataModel describes a stateful CPE datamodel.
func (*DataModel) AddEvent ¶
AddEvent adds a new event to be advertised during the next inform message.
func (*DataModel) CanSetValue ¶
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 ¶
CommandKey returns the current command key.
func (*DataModel) ConnectionRequestPassword ¶ added in v0.3.0
ConnectionRequestPassword returns the connection request password.
func (*DataModel) ConnectionRequestURL ¶
ConnectionRequestURL returns the connection request URL.
func (*DataModel) ConnectionRequestUsername ¶ added in v0.3.0
ConnectionRequestUsername returns the connection request username.
func (*DataModel) DeleteObject ¶
DeleteObject deletes the given object.
func (*DataModel) DownUntil ¶
DownUntil returns the time the CPE will stop pretending to be offline.
func (*DataModel) Each ¶ added in v0.3.1
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
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) GetValue ¶
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
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 ¶
IsBootstrapped returns true if CPE is had a successful bootstrap message exchange.
func (*DataModel) NotifyParams ¶
NotifyParams returns a list of parameters that should be included in the next inform message. This will always include forced parameters.
func (*DataModel) ParameterNames ¶
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 ¶
PendingEvents returns all events to be advertised during the next inform message.
func (*DataModel) PeriodicInformEnabled ¶
PeriodicInformEnabled returns true if periodic inform is enabled.
func (*DataModel) PeriodicInformInterval ¶
PeriodicInformInterval returns the value of periodic inform interval.
func (*DataModel) PeriodicInformTime ¶
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 ¶
RetryAttempts returns the number of currently take attepts to inform.
func (*DataModel) SetBootstrapped ¶
SetBootstrapped assigns the bootstrap flag to the given value.
func (*DataModel) SetCommandKey ¶
SetCommandKey sets the command key value.
func (*DataModel) SetConnectionRequestURL ¶
SetConnectionRequestURL sets connection request URL to the given value.
func (*DataModel) SetDownUntil ¶
SetDownUntil sets the time until the CPE should pretend to be offline.
func (*DataModel) SetFirmwareVersion ¶
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 ¶
SetParameterKey sets parameter key to the given value.
func (*DataModel) SetPeriodicInformInterval ¶
SetPeriodicInformInterval sets periodic inform interval to the given value.
func (*DataModel) SetPeriodicInformTime ¶
SetPeriodicInformTime sets periodic inform time to the given value.
func (*DataModel) SetSerialNumber ¶
SetSerialNumber sets serial number to the given value.
func (*DataModel) SetUDPConnectionRequestAddress ¶ added in v0.3.0
SetUDPConnectionRequestAddress sets UDP connection request address to the given value.
func (*DataModel) SetUptime ¶ added in v0.2.0
SetUptime sets the device uptime to the given duration.
func (*DataModel) UDPConnectionRequestAddress ¶ added in v0.3.0
UDPConnectionRequestAddress returns the UDP connection request address.
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
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.
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.
Source Files
¶
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. |