simulator

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: 30 Imported by: 0

Documentation

Overview

Package simulator provides a TR-069 device simulator that can be used to emulate the behavior of TR-069 compliant devices. It includes functionalities to handle various TR-069 RPC methods, manage device state, and simulate periodic inform sessions. The simulator can be configured to handle connection requests, manage cookies, and log activities. It integrates with Prometheus for metrics collection and supports custom data models for device emulation. This package is useful for testing and development of TR-069 ACS (Auto Configuration Server) implementations.

Index

Constants

View Source
const (
	// AuthNone an identifier for no HTTP authentication.
	AuthNone = "none"
	// AuthBasic an identifier for HTTP basic access authentication.
	AuthBasic = "basic"
	// AuthDigest an identifier for HTTP digest access authentication.
	AuthDigest = "digest"
)

Variables

View Source
var Config struct {
	// LogLevel controls how verbose the levels are. Supported values: trace,
	// debug, info, warn, error, fatal, panic.
	LogLevel string `env:"LOG_LEVEL, default=info"`

	// ConnReqEnableHTTP enables an HTTP server that can accept connection
	// requests.
	ConnReqEnableHTTP bool `env:"CR_HTTP, default=true"`

	// ConnReqEnableUDP enables a UDP server that can accept connection
	// requests.
	ConnReqEnableUDP bool `env:"CR_UDP, default=true"`

	// ConnReqAuth enables authentication for connection requests.
	ConnReqAuth bool `env:"CR_AUTH, default=false"`

	// Host is the host name or IP address used by the simulator to accept
	// connection requests. If no value is provided it will be automatically
	// resolved.
	Host string `env:"API_HOST"`

	// Port defines the port number used by the simulator to accept connection
	// requests.
	Port uint16 `env:"API_PORT, default=7547"`

	// SerialNumber will overwrite the DeviceInfo.SerialNumber datamodel
	// parameter value.
	SerialNumber string `env:"SERIAL_NUMBER, required"`

	// DataModelPath must point to a datamodel file in CSV format.
	DataModelPath string `env:"DATAMODEL_PATH, required"`

	// StateFilePath points to the state file. If the file doesn't exist it will
	// be created and will maintain all changes made to the datamodel. Missing
	// state file will trigger a BOOTSTRAP inform event.
	StateFilePath string `env:"STATE_PATH"`

	// ACSURL is the URL for the ACS.
	ACSURL string `env:"ACS_URL, required"`

	// ACSAuth configures authentication scheme for the ACS. It defaults to
	// "none". Supported values: none, basic, digest.
	ACSAuth string `env:"ACS_AUTH, default=none"`

	// ACSUsername is used to authenticate requests to the ACS.
	ACSUsername string `env:"ACS_USERNAME"`

	// ACSPassword is used to authenticate requests to the ACS.
	ACSPassword string `env:"ACS_PASSWORD"`

	// ACSVerifyTLS when set to false ignores certificate errors when connecting
	// to the ACS.
	ACSVerifyTLS bool `env:"ACS_VERIFY_TLS, default=false"`

	// InformInterval allows to override inform interval in the datamodel.
	InformInterval time.Duration `env:"INFORM_INTERVAL"`

	// NormalizeParameters when set to true will attempt to normalize datamodel
	// parameter types and values in order to bring them closer to the spec.
	NormalizeParameters bool `env:"NORMALIZE_PARAMETERS, default=false"`

	// RebootDelay defines how long the simulator should wait and drop incoming
	// connection requests to pretend that it reboots.
	RebootDelay time.Duration `env:"REBOOT_DELAY, default=5s"`

	// UpgradeDelay defines how long the simulator should wait and drop incoming
	// connection requests to pretend that software upgrades take time.
	UpgradeDelay time.Duration `env:"UPGRADE_DELAY, default=15s"`

	// ConnectionTimeout defines how long it can take to establish a TCP
	// connection with the ACS.
	ConnectionTimeout time.Duration `env:"CONNECTION_TIMEOUT, default=5s"`

	// RequestTimeout defines how long request processing could take.
	RequestTimeout time.Duration `env:"REQUEST_TIMEOUT, default=5s"`

	// ArtificialLatency defines the maximum time for a simulator to wait before
	// sending a request or respoding to an ACS command. It can be used to
	// simulate slow devices.
	ArtificialLatency time.Duration `env:"ARTIFICIAL_LATENCY, default=0s"`
}

Config is a global configuration store.

View Source
var ErrNoCreds = errors.New("username/password missing")

ErrNoCreds is returned when ACS authentication is configured for digest access authentication but no credentials are provided.

Functions

func LoadConfig

func LoadConfig(ctx context.Context) error

LoadConfig attempts to load configuration from environment variables.

Types

type Simulator

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

Simulator is a TR-069 device simulator.

func New

func New(dm *datamodel.DataModel) *Simulator

New creates a new simulator instance.

func NewWithMetrics

func NewWithMetrics(dm *datamodel.DataModel, m *metrics.Metrics) *Simulator

NewWithMetrics creates a new simulator instance with a custom metrics collector.

func (*Simulator) SetArtificialLatency added in v0.3.0

func (s *Simulator) SetArtificialLatency(d time.Duration)

SetArtificialLatency sets the artificial latency for the simulator. This function allows you to introduce a delay in the simulator's operations, which can be useful for testing and simulating network conditions with latency.

func (*Simulator) SetPeriodicInformInterval

func (s *Simulator) SetPeriodicInformInterval(dur time.Duration)

SetPeriodicInformInterval sets the periodic inform interval for the simulator. If the provided duration is zero the interval will not be changed.

func (*Simulator) Start

func (s *Simulator) Start(ctx context.Context) error

Start starts the simulator and initiates an inform session.

func (*Simulator) Stop

func (s *Simulator) Stop(ctx context.Context) error

Stop stops the simulator.

func (*Simulator) UseLogger added in v0.3.0

func (s *Simulator) UseLogger(logger *blip.Logger)

UseLogger sets the logger for the simulator.

Directories

Path Synopsis
Package metrics provides a set of Prometheus metrics for monitoring the performance and behavior of a TR-069 simulator.
Package metrics provides a set of Prometheus metrics for monitoring the performance and behavior of a TR-069 simulator.

Jump to

Keyboard shortcuts

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