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
Script Initialization: A Lua script is loaded with the device context (device ID, tenant ID, and variables)
Lua Environment Setup: The script runs in a secure Lua sandbox with access to predefined global variables and functions
Function Calls: The script can call Go functions to interact with devices and services
Status Return: The script must set a
provisioning_statusglobal variable to indicate success or failure
Global Variables
These variables are automatically available to scripts:
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
"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 devicemessage_body(string): XML-formatted CWMP messagetimeout(number): Timeout in seconds (for the operation)
Returns:
(boolean)
trueif the message was successfully sent(table) Error table with
error_messageanderror_codefields 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 flagusername(string): The full username (prefixed with organization ID)password(string): The passworderror_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)
trueif refresh was successfully triggered,falseotherwise
Example:
Best Practices
Always Check Return Values: Never assume a function succeeded
Use Descriptive Logging: Leverage the
print()functionSet Status Explicitly: Always set provisioning status before script ends
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
Creates a PPPoE WAN connection on the device
Sets PPPoE credentials using variables
Changes the WAN type to PPPoE
Refreshes device parameters
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
Last updated