Page cover
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Services

A set of parameters to define the CPE configuration.

The services are used in conjunction with TR-x69 discovery mechanisms to achieve Zero Touch Provisioning flows. The CPE is added to the system beforehand, and the proper service is attached to it. When the field technician plugs the CPE into the network infrastructure, the CPE is provisioned with the parameters defined in the ACS specific to that customer.

Service Definition

A service definition is a set of parameters, variables, and operations that dictate the communication structure with the CPE when applying the service to its configuration.

Scripts

Scripts in the zero-touch-provisioning system are written in Lua and provide the provisioning logic for CPE (Customer Premises Equipment) devices. They define how services are applied to devices, including configuration changes, credential management, and parameter updates.

Execution Flow

  1. Script Initialization: A Lua script is loaded with the device context (device ID, tenant ID, and variables)

  2. Lua Environment Setup: The script runs in a secure Lua sandbox with access to predefined global variables and functions

  3. Function Calls: The script can call Go functions to interact with devices and services

  4. Status Return: The script must set a provisioning_status global variable to indicate success or failure

Global Variables

These variables are automatically available to scripts:

Variable
Type
Description

device_id

string

The serial number or unique identifier of the target device

variables

table

A table containing service-specific variables passed during provisioning

provisioning_status

string

Must be set to indicate the final status (see below)

Provisioning Status Values

Value
Meaning

"provisioned"

Service successfully applied

"failed"

Service provisioning failed

Important: Scripts must explicitly set provisioning_status before completion. If not set, the provisioning will fail.

Example Structure

Available Functions

Provisioning Functions

set_provisioning_status(status)

Sets the final provisioning status for the script execution.

Parameters:

  • status (string): Either "provisioned" or "failed"

Returns: Nothing

Example:


get_device_id()

Retrieves the device serial number or identifier currently being provisioned.

Parameters: None

Returns:

  • (string) The device ID

Example:


get_variable_value(variable_name)

Retrieves a variable value from the service instance configuration.

Parameters:

  • variable_name (string): The name of the variable to retrieve

Returns:

  • (string) The variable value, or nil if not found

Example:


CPE Interaction Functions

send_cwmp_message_and_forget(device_id, message_body, timeout)

Enqueue a CWMP message to the device and does not wait for a response.

Parameters:

  • device_id (string): The serial number of the target device

  • message_body (string): XML-formatted CWMP message

  • timeout (number): Timeout in seconds (for the operation)

Returns:

  • (boolean) true if the message was successfully sent

  • (table) Error table with error_message and error_code fields if failed

Example:


Utility Functions

sleep(seconds)

Pauses script execution for the specified number of seconds.

Parameters:

  • seconds (number): Number of seconds to sleep

Returns: Nothing

Example:


generate_random_string(length)

Generates a random alphanumeric string of the specified length.

Parameters:

  • length (number): Length of the random string to generate (must be > 0)

Returns:

  • (string) Random string of the specified length, or empty string if length is invalid

Example:


create_or_update_device_credential(username, password)

Creates or updates device credentials for authentication.

Parameters:

  • username (string): The username (cannot contain dots, cannot be empty)

  • password (string): The password (cannot contain dots, cannot be empty)

Returns:

  • (table) Result table with the following fields:

    • ok (boolean): Success flag

    • username (string): The full username (prefixed with organization ID)

    • password (string): The password

    • error_msg (string): Error message if failed, empty if successful

Validation:

  • Username and password cannot be empty

  • Username and password cannot contain dots

  • Requires valid organization context

Example:


refresh_device_parameters(device_id)

Triggers a parameter refresh on the device, forcing it to send an updated parameter list to the ACS.

Parameters:

  • device_id (string): The serial number of the device

Returns:

  • (boolean) true if refresh was successfully triggered, false otherwise

Example:

Best Practices

  1. Always Check Return Values: Never assume a function succeeded

  2. Use Descriptive Logging: Leverage the print() function

  3. Set Status Explicitly: Always set provisioning status before script ends

  4. Handle Sequential Operations: Use proper error handling for multi-step processes

Limitations

  • Scripts run in a restricted Lua sandbox for security

  • File I/O is not available

  • Network operations are only available through the provided functions

  • Scripts must complete within reasonable timeout limits

Real-World Example: PPPoE Service Configuration

  1. Creates a PPPoE WAN connection on the device

  2. Sets PPPoE credentials using variables

  3. Changes the WAN type to PPPoE

  4. Refreshes device parameters

  5. Properly handles errors at each step

The example demonstrates:

  • Using variables from the service instance

  • Building XML CWMP messages

  • Sequential provisioning steps

  • Error handling

  • Device parameter refresh

Service Instances

The service instance is the attachment of a service to a CPE, defining the specific variable values for that equipment. This will be applied the first time the CPE connects to the platform and any time it is factory reset.

Event

Oktopus listens to CPE events and applies the services configuration on the equipment when an event of "0 BOOSTRAP" — first connection­ or factory reset — is triggered by the CPE.

Status

The service attached to the CPE has a few statuses:

  • Pending = It's waiting for an event to start running and being applied to the equipment.

  • Running = The event has triggered, and the script is being executed.

  • Provisioned = Execution was a success, the CPE received all the messages.

  • Failed = An issue happened during the execution of the script.

In Practice

After learning the concepts, let's understand how it works in a real use case.

Configure the CPE to connect to the ACS

The CPE must have a way to connect to the Controller system. You can use one of these options:

  • Firmware with ACS pre-configured

  • DHCP with option 43

  • PPPoE reply with ACS server URL

1

Add a CPE

Manually insert a new device with its unique identifier (e.g, serial number, agent endpoint id).

2

Create a service definition

Write the Lua scripts and necessary variables to apply that service to the CPE.

3

Attach the service to the CPE

Associate the CPE with a service, with its specific variable values for that device.

4

Plug the CPE into the network

As the CPE already has the ACS configured and a connection to it, all services will be provisioned when it establishes communication with the controller system, and the device will come online with the customer's specific configuration.

Last updated