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 | ✓ |
| Message type | Ingress | Egress |
|---|---|---|
| PADI | ✓ | |
| PADO | ✓ | |
| PADR | ✓ | |
| PADS | ✓ | |
| PADT | ✓ | ✓ |
| LCP | ✓ | ✓ |
| PAP | ✓ | ✓ |
| CHAP | ✓ | ✓ |
| IPCP | ✓ | ✓ |
| IPv6CP | ✓ | ✓ |
| Message type | Ingress | Egress |
|---|---|---|
| Discover | ✓ | ✓ (relay) |
| Offer | ✓ (relay) | ✓ |
| Request | ✓ | ✓ (relay) |
| Ack | ✓ (relay) | ✓ |
| Decline | ✓ | ✓ (relay) |
| Nak | ✓ (relay) | ✓ |
| Release | ✓ | ✓ (relay) |
| Inform | ✓ | ✓ (relay) |
| Lease-Query | ✓ | ✓ (relay) |
| Message type | Ingress | Egress |
|---|---|---|
| Solicit | ✓ | ✓ (relay) |
| Advertise | ✓ (relay) | ✓ |
| Request | ✓ | ✓ (relay) |
| Confirm | ✓ | ✓ (relay) |
| Renew | ✓ | ✓ (relay) |
| Rebind | ✓ | ✓ (relay) |
| Reply | ✓ (relay) | ✓ |
| Release | ✓ | ✓ (relay) |
| Decline | ✓ | ✓ (relay) |
| Info-Request | ✓ | ✓ (relay) |
| Relay-Forward | ✓ (LDRA) | ✓ (relay) |
| Relay-Reply | ✓ (relay) | ✓ (LDRA) |
- (relay) means supported only for relayed messages
- (LDRA) means supported only for lightweight DHCPv6 relay agent (LDRA)
Operational commands
info from state /subscriber-management python python-script <name> oper-stateinfo from state /subscriber-management python python-script <name> source-in-usetools subscriber-management python python-script reload scriptConfiguring 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 management pod or upload it to an
HTTP or FTP server.
Note: When storing the script file in the /python folder of the management pod, it must be backed up on a Kubernetes cluster storage, so that the management 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 /python/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
}
}