Configuring Subroutines in Routing Policy Match Conditions
You can use a routing policy called from another routing policy as a match condition. This process makes the called policy a subroutine.
For configuration instructions and examples, see the following section:
Configuring Subroutines
To configure a subroutine in a routing policy to be called from another routing policy, create the subroutine and specify its name using the policy match condition (described in Configuring Match Conditions in Routing Policy Terms) in the from or to statement of another routing policy:
![]() | Note: Do not evaluate a routing policy within itself. The result is that no prefixes ever match the routing policy. |
The action specified in a subroutine is used to provide a match condition to the calling policy. If the subroutine specifies an action of accept, the calling policy considers the route to be a match. If the subroutine specifies an action of reject, the calling policy considers the route not to match. If the subroutine specifies an action that is meant to manipulate the route characteristics, the changes are made. For more details about the subroutine evaluation, see How a Routing Policy Subroutine Is Evaluated.
Possible Consequences of Termination Actions in Subroutines
A subroutine with particular statements can behave differently from a routing policy that contains the same statements. With a subroutine, you must remember that the possible termination actions of accept or reject specified by the subroutine or the default policy can greatly affect the expected results. (For more information about default routing policies, see Default Routing Policies and Actions.)
In particular, you must consider what happens if a match does not occur with routes specified in a subroutine and if the default policy action that is taken is the action that you expect and want.
For example, imagine that you are a network administrator at an Internet service provider (ISP) that provides service to Customer A. You have configured several routing policies for the different classes of neighbors that Customer A presents on various links. To save time maintaining the routing policies for Customer A, you have configured a subroutine that identifies their routes and various routing policies that call the subroutine, as shown below:
The following results occur with this configuration:
- The group-level export statement resets the metric to 500 when advertising all BGP routes to neighbors 10.1.1.1 and 10.1.2.1 rather than just the routes that match the subroutine route filters.
- The neighbor-level export statements reset the metric to 100 and 200 when advertising all BGP routes to neighbors 10.1.3.1 and 10.1.4.1, respectively, rather than just the BGP routes that match the subroutine route filters.
These unexpected results occur because the subroutine policy does not specify a termination action for routes that do not match the route filter and therefore, the default BGP export policy of accepting all BGP routes is taken.
If the statements included in this particular subroutine had been contained within the calling policies themselves, only the desired routes would have their metrics reset.
This example illustrates the differences between routing policies and subroutines and the importance of the termination action in a subroutine. Here, the default BGP export policy action for the subroutine was not carefully considered. A solution to this particular example is to add one more term to the subroutine that rejects all other routes that do not match the route filters:
Termination action strategies for subroutines in general include the following:
- Depend upon the default policy action to handle all other routes.
- Add a term that accepts all other routes.
- Add a term that rejects all other routes.
The option that you choose depends upon what you want to achieve with your subroutine. Plan your subroutines carefully.
Example: Configuring a Subroutine
Create the subroutine is-customer and call it from the routing policies export-customer and import-customer. In import-customer, the action is taken only on routes that match the route filters defined in is-customer.