Python support
Customize the cMAG-c behavior by applying user-defined Python scripts to inspect and modify control protocol packets.
Python scripts
Sending or receiving specific control protocol packets can trigger a user-defined Python script. Using the packet as input, the script applies a set of Nokia API calls to inspect and modify the packet. The script outputs the modified packet.
The direction of the triggering protocol message defines when the Python script runs:
- ingress – before the subscriber management processing
- egress – after the subscriber management processing
For example, when the cMAG-c receives a RADIUS Access-Accept message, a user-defined Python script can update the Alc-SLA-Prof-Str attribute in the message to a new SLA profile name. The system processes the modified packet and creates the session with the new SLA profile.
Python version and libraries
- Python standard libraries
- Nokia-provided TPSDA API
- Cryptodome package, see PyCryptodome
For more information about the Nokia-provided TPSDA APIs, see cMAG-c TPSDA Python 3 API.
Supported protocol messages
The following tables list the supported protocol message types and direction.
Message type | Ingress | Egress |
---|---|---|
Access-Request | ✓ | |
Access-Accept | ✓ | |
Access-Reject | ✓ | |
Account-Request | ✓ | |
Account-Response | ✓ | |
Access-Challenge | ✓ |
Message type | Ingress | Egress |
---|---|---|
CoA Request | ✓ | |
DM Request | ✓ | |
CoA or DM Reply | ✓ |
Operational commands
info from state /subscriber-management python python-script <name> oper-state
info from state /subscriber-management python python-script <name> source-in-use
tools subscriber-management python python-script reload script
Configuring a Python script
You can customize the cMAG-c behavior with a Python script.
-
Create a Python script file, and either save it in the
/python folder of the Python pod or upload it to an
HTTP or FTP server.
Note: When storing the script file in the /python folder of the Python pod, it must be backed up on a cMAG-c-wide storage, so that the Python pod can still access the file if the pod is rescheduled to a different worker.
-
Configure the URL of the script file.
subscriber-management python python-script
-
Specify the trigger packet type, the direction, and the corresponding Python
script in a Python policy.
subscriber-management python python-policy
- Reference the Python policy in the corresponding protocol configuration; for example, inside the radius-authentication-profile for the RADIUS authentication messages.
The following example configures to run the cf3:/test.py Python script file upon sending the RADIUS Access-Request message.
# info from running /subscriber-management python
python-script test {
admin-state enable
code {
path /python/test.py
}
}
python-policy rad {
radius access-request direction egress {
script test
}
}
# info from running /subscriber-management profiles radius-authentication-profile auth1
server-selection-profile sel1
python-policy rad
password $aes1$AWPJEozXM6/vxG8=$P6tGQqEKHwszh6LDBJ3e1w==
username-format {
ipoe {
format mac-address
mac-format ab:ab:ab:ab:ab:ab
}
}