Subscribe to IPv4 Route Change Events

Function Description

You can subscribe to IPv4 route change events. After you subscribe to IPv4 route change events and an IPv4 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.subscribe (tag, network, maskLen, minLen=None, maxLen=None, neLen=None, type="all", protocol="all")

Parameter Description

Table 1 describes parameters supported by IPv4 route change event APIs.
Table 1 Parameters supported by IPv4 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 a route prefix. The value is in the IPv4 address format, such as 10.1.1.1.

maskLen

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

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.

neLen

Specifies a length that cannot be a mask length. The value must be greater than or equal to the value of minLen and less than or equal to the value of maxLen.

type

Specifies an IPv4 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, ospf, bgp, rip, 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.
  • A route change event can be triggered only when public network routes change.

Example

test.py

import ops

def ops_condition(_ops):
    ret, reason = _ops.route.subscribe("con0", "10.1.1.1",maskLen=32, type="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 10.1.1.1/32 is added or deleted, a route change event is triggered.

Copyright © Huawei Technologies Co., Ltd.
Copyright © Huawei Technologies Co., Ltd.
Next topic >