< Home

Route Change Event Subscription

Interface Name

Route change event subscription

Application Phase

Subscription phase

API Prototype

result1_value, result2_description = ops.route.subscribe(tag, network, maskLen, minLen=None, maxLen=None, neLen=None, optype=all, protocol=all)

Description

Parameter

Description

Value

tag

Indicates conditions.

The value is a string of 1 to 12 case-insensitive characters, consists of letters, digits, and underscores (_), and starts with a letter. The value cannot be one of the following: "", None, and, or, andnot. The value cannot contain \0.

network

Indicates a route prefix.

The value is in dotted decimal notation.

maskLen

Indicates the mask length.

The value is an integer that ranges from 0 to 32.

minLen

Indicates the shortest mask length.

The value is an integer that must be greater than or equal to the maskLen value. The default value is None, indicating the shortest mask length is 0.

maxLen

Indicates the longest mask length.

The value is an integer that must be greater than or equal to the minLen value. The default value is None, indicating the longest mask length is 0.

neLen

Indicates the unmatching mask length.

The value is an integer that must be greater than or equal to the minLen value and less than or equal to the maxLen value. The default value is None, indicating the unmatching mask length is 0.

optype

Indicates the route change event type.

The value is of the enumerated type:

  • add: Routes are added.

  • delete: Routes are deleted.

  • modify: Routes are modified.

  • all: Indicates all changes of routes.

The default value is all.

protocol

Indicates routing protocol attributes.

The value is a string of characters. The default value is all, indicating all routing protocols.

  • direct: direct routes

  • static: static routes

  • ospf: OSPF routes

  • isis: IS-IS routes

  • bgp: BGP routes

  • rip: RIP routes

  • unr: user network routes

Return Value

The result1_value and result2_description in the API prototype indicate return values.

The result1_value is the first return value, 0 indicates success, and 1 indicates failure.

The result2_description is the second return value, indicating the failure cause. It is returned only when the first return value is 1.

Usage Description

If multiple simple events are defined using the ops.route.subscribe API in the subscription phase, but the simple events are not combined through the Multi-Condition Combination API, the Python script assistant cannot be configured.

Directly omit parameters using default values. For example, the following statements indicate that parameters minLen, maxLen, neLen, optype, and protocol use default values.

value, descri_str = ops.route.subscribe("route", "192.168.1.0", 24)

Using the route change event subscription, you can monitor changes in routes of specified network segments and protocols.

Example

Example 1

Subscribe to changes of OSPF routes on the network segment 10.2.1.0/24. Once OSPF routes on this network segment are added, deleted, or modified, the corresponding action is triggered.

value, descri_str = ops.route.subscribe("route1", "10.2.1.0", 24, minLen=None, maxLen=None, neLen=None, optype="all", protocol="ospf")

Example 2

A user wants to subscribe to changes of OSPF routes on the network segment 10.2.1.0/24 through the ops.route.subscribe API in the Python script, and then needs to subscribe to changes of OSPF routes on the network segment 10.2.2.0/24. To omit the process of uninstalling the original script and installing a new script, you can define an environment variable in the subscription phase, and specify the value of the environment variable using the environment command.

value, descri_str = ops.route.subscribe("route1", "ospf_routes", 24, minLen=None, maxLen=None, neLen=None, optype="all", protocol="ospf")  # ospf_routes is a user-defined environment variable

Set the value of the user-defined environment variable to 10.2.1.0 when changes of OSPF routes on the network segment 10.2.1.0/24 need to be subscribed to.

<HUAWEI> system-view
[HUAWEI] ops
[HUAWEI-ops] environment ospf_routes 10.2.1.0

Set the value of the user-defined environment variable to 10.2.2.0 when changes of OSPF routes on the network segment 10.2.2.0/24 need to be subscribed to.

[HUAWEI-ops] environment ospf_routes 10.2.2.0
Copyright © Huawei Technologies Co., Ltd.
Copyright © Huawei Technologies Co., Ltd.
< Previous topic Next topic >