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:
- [edit]
- policy-options {
-
- policy-statement customer-a-subroutine {
-
- from {
- route-filter 10.1/16 exact;
- route-filter 10.5/16 exact;
- route-filter 192.168.10/24 exact;
- }
- then accept;
- }
- }
- policy-options {
-
- policy-statement send-customer-a-default {
-
- from {
- policy customer-a-subroutine;
- }
-
- then {
- set metric 500;
- accept;
- }
- }
- }
- policy-options {
-
- policy-statement send-customer-a-primary {
-
- from {
- policy customer-a-subroutine;
- }
-
- then {
- set metric 100;
- accept;
- }
- }
- }
- policy-options {
-
- policy-statement send-customer-a-secondary {
-
- from {
- policy customer-a-subroutine;
- }
-
- then {
- set metric 200;
- accept;
- }
- }
- }
- protocols {
-
- bgp {
-
- group customer-a {
- export send-customer-a-default;
- neighbor 10.1.1.1;
- neighbor 10.1.2.1;
-
- neighbor 10.1.3.1 {
- export send-customer-a-primary;
- }
-
- neighbor 10.1.4.1 {
- export send-customer-a-secondary;
- }
- }
- }
- }
The following results occur with this configuration:
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:
- [edit]
- policy-options {
-
- policy-statement customer-a-subroutine {
-
- term accept-exact {
-
- from {
- route-filter 10.1/16 exact;
- route-filter 10.5/16 exact;
- route-filter 192.168.10/24 exact;
- }
- then accept;
- }
-
- term reject-others {
- then reject;
- }
- }
- }
Termination action strategies for subroutines in general include the following:
The option that you choose depends upon what you want to achieve with your subroutine. Plan your subroutines carefully.