Subscribe to IPv6 Route Change Events

Function Description

You can subscribe to IPv6 route change events. After you subscribe to IPv6 route change events and an IPv6 route change event is triggered, the system executes the ops_execute() function in the maintenance assistant script.

This API can only be used in the ops_condition() function of the maintenance assistant script.

Command Prototype

opsObj.route.subscribe6(self, tag, network, maskLen, minLen=None, maxLen=None, vpnName="_public_", optype="all", protocol="all")

Parameter Description

Table 1 describes parameters supported by IPv6 route change event APIs.
Table 1 Parameters supported by IPv6 route change event APIs

Method

Description

opsObj

Specifies an OPS object. It is obtained through ops.ops() instantiation.

tag

Specifies a condition ID. The value is a string of 1 to 8 case-sensitive characters that starts with a letter and contains letters, digits, and underscores (_). Enter double quotation marks ("") or None for the only one condition. tag cannot be set to and, or, or not.

network

Specifies an IPv6 route prefix. The value is in the IPv6 address format, such as 2001:db8:1::2.

maskLen

Specifies a mask length. The value is an integer ranging from 0 to 128.

minLen

Specifies the minimum mask length. The value must be greater than or equal to the value of maskLen.

maxLen

Specifies the maximum mask length. The value must be greater than or equal to the value of minLen.

vpnName

Specifies the name of the VPN instance in which route change events are to be subscribed to. The value is a string of 1 to 31 characters. This parameter is optional. If the parameter is not specified, change events of the corresponding public network routes are subscribed to by default.

NOTE:

The specified VPN instance must be an existing one on the device, and the IPv6 address family must have been enabled in the VPN instance. If either condition is not met, the subscription rule does not take effect.

type

Specifies an IPv6 route change event type. The value can be add, remove, modify, or all. The value all indicates all route changes.

protocol

Specifies a routing protocol. After this parameter is set, change events of routes of the specified protocol are subscribed to. The value can be direct, static, isis, bgp, unr, or all. The default value is all, indicating that routes are not filtered by protocol type.

Description of Return Values

  • First return value: The value 0 indicates a success, and the value 1 indicates a failure.
  • Second return value: This value describes success or failure reasons, expressed in a character string.

Interface Constraints

  • A route change event can be triggered only when active routes change.
  • A route change event is not triggered when route recursion results change or inactive routes change.
  • The add event is triggered when an active route with a high preference is added.
  • When an active route is deleted and a sub-optimal route becomes active, the remove and add events are triggered, respectively.
  • A maximum of three route change events can be triggered per second. If multiple route changes match the subscription conditions, a maximum of 100 events can be triggered.
  • You can specify a VPN instance to subscribe to change events of VPN routes. If no VPN instance is specified, change events of the corresponding public network routes are subscribed to by default.
  • The specified VPN instance must be an existing one on the device, and the IPv6 address family must have been enabled in the VPN instance. If either condition is not met, the subscription rule does not take effect. After a specified VPN instance is deleted, the corresponding subscription rule is also deleted.

Example

test.py

import ops

def ops_condition(_ops):
    ret, reason = _ops.route.subscribe6("con0", "2001:db8:1::2", maskLen=64, vpnName="testVpn", optype="all", protocol="all") 
    ret, reason = _ops.correlate("(con0 and con1)")
    return ret

def ops_execute(_ops):
    a, des  = _ops.context.save("test.py", 'Route event trigger')
    return 0

When a route with the prefix 2001:db8:1::2/64 is added to or deleted from the VPN instance testVpn, a route change event is triggered.

Copyright © Huawei Technologies Co., Ltd.
Copyright © Huawei Technologies Co., Ltd.
< Previous topic