Table of Content Hide

Description

Routing control functions (RCF) is a language that can be used to express route filtering and attribute modification logic in a powerful and programmatic fashion. 

This document covers:

  • The core RCF language including
    • Language syntax
    • Matching and modifying route attributes
  • Workflows to define routing control functions
  • CLI commands to provide visibility into operational status

Salient aspects and language primitives

  • The new language syntax is independent of the existing route map syntax.
  • RCF code consists of RCF function definitions that can be applied at points of application or reused in other RCF functions. Each function is a sequence of statements that are evaluated in the order in which they are written. Example:
    # Accept all routes as they are
    
    function ACCEPT_ALL() {
       return true;
    }
    
    # Reject all routes unconditionally
    
    function DENY_ALL() {
       return false;
    }
    
    # Set the med to 100 and accept all routes
    
    function SET_MED() {
       med = 100;
       return true;
    }
  • RCF functions always return a value of true, false, or unknown, along with possible modifications made to the route attributes in the function.


    • A function returns the value of unknown if no explicit return statement is specified.
    • A return value of true from an RCF function applied at a point of RCF application accepts the route with all modifications applied. A return value of false or unknown rejects the route.
    • If the point of RCF application refers to an RCF function that is not configured as part of the RCF code, all routes at that point of RCF application get rejected. For example, if ACCEPT_ALL() is applied to peer 192.168.1.1 inbound and ACCEPT_ALL() is not configured, all updates from peer 192.168.1.1 are dropped.
  • RCF functions can also reuse other RCF functions. RCF functions can call other RCF functions to:
    • make conditional code execution decisions (use of if … else …)
      # DEFAULT_ROUTE() returns if the prefix is 0.0.0.0/0 or ::/0
      
      function DEFAULT_ROUTE() {
         return prefix is 0.0.0.0/0 or prefix is ::/0;
      }
      
      # All routes are accepted by FUNC_A(). If the route under review
      # is the default route, then the med is set to 100.
      
      function FUNC_A() {
         if DEFAULT_ROUTE() {
            med = 100;
         }
         return true;
      }
      
    • delegate return value evaluation (use of return)
      function DEFAULT_ROUTE() {
         return prefix is 0.0.0.0/0 or prefix is ::/0;
      }
      
      # Only accepts the default route. All other prefixes are rejected
      
      function FUNC_A() {
         # some RCF code
         return DEFAULT_ROUTE();
      }
      
    • apply a common set of path attribute modifications
      # Modify LOCAL_PREF and AS_PATH attributes. Note that
      # TAG_PEERS() returns 'unknown' implicitly since
      # no explicit 'return true' or 'return false' is
      # specified.
      
      function TAG_PEERS() {
         local_preference = 1000;
         as_path prepend 64501 64502;
      }
      
      # Reuse TAG_PEERS to apply a common set of path attribute
      # modifications. The return value of 'unknown' from
      # TAG_PEERS() is ignored.
      
      function FUNC_A() {
         TAG_PEERS();
         return true;
      }
      
  • The return value of the RCF function at the point of application is mapped to accepting (return value of true) or rejecting routes (return value of false or unknown). The return value of reused RCF functions need not accept or reject routes. Consider the following two examples.


    # Returns if the MULTI_EXIT_DISC is 200 after incrementing
    # it by 100
    
    function IS_INC_MED_200() {
       med += 100;
       return med is 200;
    }
    
    # MED_TEST() demonstrates that even though IS_INC_MED_200
    # returns true, the route gets rejected because of the
    # decision made in MED_TEST()
    
    function MED_TEST() {
       if IS_INC_MED_200() {
          return false;
       }
       return true;
    }
    
    
    # Sets LOCAL_PREF for all routes (in the RCF evaluation
    # engine) to 100. Return true only for 0.0.0.0/0; false
    # for all other routes
    
    function SET_LOCAL_PREF_IS_DEFAULT() {
       local_preference = 100;
       return prefix is 0.0.0.0/0;
    }
    
    # The return value (true/false) is returned as is from
    # LOCAL_PREF_TEST() and thus accepts or rejects routes
    
    function LOCAL_PREF_TEST() {
       # some RCF code
       return SET_LOCAL_PREF_IS_DEFAULT();
    }
  • Allows reusing AS path lists, community lists, and IPv4 and IPv6 prefix lists. See examples later in the document. If the RCF function has references to undefined prefix lists, community lists, or AS path lists, all routes applied against this RCF function are dropped.
  • Allows arbitrary levels of if … else … nesting
    function COND_EXAMPLE() {
       if med >= 100 {
          if prefix is 0.0.0.0/0 {
             local_preference = 200;
          } else {
             local_preference = 100;
          }
          return true;
       } else {
          return false;
       }
    }
  • Support for logical expressions using and, or, and not. These operations always return a value of true or false.
    function EXPR_EXAMPLE() {
       return not ( med >= 100 and ( not prefix match prefix_list_v4 DEFAULT_ROUTE or community match community_list CLIST ) );
    }
    • Expression short circuiting
      • With the and operator, if the first operand returns false or unknown, the second operand (or function) is not evaluated.
        function SET_MED() {
           med = 100;
           return true;
        }
        
        function SHORT_CIRCUITING_1() {
           return false and SET_MED();   # SET_MED() is never
                                         # evaluated
        }
      • With the or operator, if the first operand returns true, the second operand (or function) is not evaluated.
        function SET_MED() {
           med = 100;
           return true;
        }
        
        function SHORT_CIRCUITING_2() {
           return true or SET_MED();    # SET_MED() is never
                                        # evaluated
        }
  • Comparison against modified path attributes: all modifications of path attributes take immediate effect inside the RCF evaluation engine. All subsequent reads and comparisons of the path attribute will return the modified value.
    function MOD_COMP_EXAMPLE() {
       local_preference += 100;
       return local_preference is 150; # Compares against modified value of LOCAL_PREF
    }
    • With the EOS-4.26.0F release, the value of unmodified path attributes are also available.
      # FUNC() is applied as inbound RCF function
      
      function FUNC() {
         med = 10;
         return input.med is 5 and      # Compare the unmodified value and
                med is 10;              # the modified value. 'med is 10' is true.
      }
  • Preserve attribute modifications as a result of the RCF evaluation even if the modifications are followed with a return false inside the RCF evaluation engine.
    function MODIFY_MED() {
       med = 100;
       return false;
    }
    
    function FUNC_A() {
       MODIFY_MED();
       return med is 100;  # This will always return true as
                           # MODIFY_MED() will always set the
                           # med to 100 inside the RCF evaluation
                           # engine.
    }
  • Ability to perform sequential modifications of the same attribute in the user defined order
    function COMM_MODIFICATIONS() {
       community add community_list COMM_LIST1;    # Add communities from COMM_LIST1
       community remove community_list COMM_LIST2; # Next, remove communities from COMM_LIST2
       return true;
    }
    

Language syntax

Comments

Comments start with the hash (#) character and the comment continues till the end of the line.

# This comment appears before a function
function DENY_ALL() {
   # comments can appear inside functions too!
   return false;   # This function always returns false
}

A comment can appear anywhere in the RCF code.

Functions

Function syntax:

function <FUNCTION_NAME>() {
# statements 
}

A function name can only contain letters a-z, A-Z, 0-9, and the underscore character (_). A function name must start with a-z, A-Z, or the underscore character (_).

Examples of valid function names:

  • GOOD_FUNCTION_11
  • GoodFunction11
  • _good_function_11

Examples of invalid function names:

  • 9badFunctionName
  • Bad Function Name
  • Bad-Function-Name

Function calls

An RCF function (the callee) can be called from another RCF function (the caller).

An RCF function call can be used as part of an expression.

Function call syntax 1:

<CALLEE_FUNCTION_NAME>()

Example:

function SET_MED() { med = 100; }

function ACCEPT_ALL() { return true; }

function CALLER() { return local_preference is 10 or ACCEPT_ALL(); }

When used as a standalone statement, it must be followed by a semicolon.

Function call syntax 2:

<CALLEE_FUNCTION_NAME>();

Example:

function SET_MED() { med = 100; }

function CALLER() {
   SET_MED();
   return true;
}

Trilean logic states

RCF supports trilean states denoted as true, false, and unknown.

Expression

An expression is composed of one or more clauses of the following types:

  • Comparisons
    • Example: local_preference is 100
  • Match operations
    • Example: prefix match prefix_list_v4 ALLOW_ROUTES
  • Function calls
    • Example: DEFAULT_ROUTE()
  • Sequential operator expression (see Sequential operator)
    • Example: FUNC_A() ?? FUNC_B() is true

These clauses are combined using logical operators such as and, or, and not operators to form complex expressions.The expressions support the use of parentheses for grouping and precedence.

The expression is evaluated from left to right honoring the decreasing precedence of evaluation listed below.

  • parentheses "()"
  • not
  • and
  • or

Examples:

  • local_preference is 100
  • not prefix match prefix_list_v4 PREFIX_LIST_NAME
  • DEFAULT_ROUTE() and ( local_preference >= 100 and community match community_list COMM_LIST )

Supported comparison and match operations are listed with examples in the next section. 

Truth table for the not operator.

NOT Operand true false unknown
Result false true true

Truth table for the and operator.

AND RHS true false unknown
LHS  
true true false false
false false false false
unknown false false false

If the first clause of an and operation evaluates to false or unknown, the second clause is not evaluated.

Truth table for the or operator.

OR RHS true false unknown
LHS  
true true true true
false true false false
unknown true false false

If the first clause of an or operation evaluates to true, the second clause is not evaluated.

Sequential operator

Supported since EOS-4.25.0F release.

The sequential operator "??" allows conditional evaluation of functions in a sequence. The syntax for the sequential operator is

<FUNC1_NAME>() ?? <FUNC2_NAME>()

The operator can be repeated to form a longer sequence of function invocations.

<FUNC1_NAME>() ?? <FUNC2_NAME>() ?? <FUNC3_NAME>() ?? ...

The sequential operator evaluates the first function first.

  1. If the function invocation returns true, the evaluation of the expression terminates (no other function in the sequence is evaluated) and the entire expression returns true.
  2. If the function invocation returns false, the evaluation of the expression terminates and the entire expression returns false.
  3. Only if the function invocation returns unknown, the sequential operator evaluation proceeds to the next term and repeats.

In summary, if a function can neither take a true nor a false decision and returns unknown, the evaluation will proceed to the next term. If this process reaches the last term in the sequence, then the value from the last function is returned by the expression.

Example:

function PEER_192_168_1_1_IN() {
   ### RCF function for peer 192.168.1.1.

   # If FUNC_GLOBAL() returns true (or false), accept (or reject) the
   # route immediately.
   # Otherwise, if FUNC_ASN100() returns true (or false), accept (or
   # reject) the route immediately.
   # Otherwise, return the result from evaluating FUNC_192_168_1_1_IN().
   return FUNC_GLOBAL() ?? FUNC_ASN100() ?? FUNC_192_168_1_1_IN();
}

The trailing term can also be true, false, or unknown. This allows defining the default return value when all function invocations return unknown.

function PEER_192_168_1_1_IN() {
   ### RCF function for peer 192.168.1.1.

   # If the 3 function calls don't return an an explicit true or false,
   # accept the route.
   return FUNC_GLOBAL() ?? FUNC_ASN100() ?? FUNC_192_168_1_1_IN() ?? true;
}

The sequential operator's result can also be compared against a trilean logic state.

<FUNC1_NAME>() ?? <FUNC2_NAME>() is <true | false | unknown>
Comparing sequential operator, logical and, logical or, and statements

The 4 syntaxes with sequential operator (??), and, or, and functions in statements with (;) can be used to achieve different goals with function invocations. The following examples illustrate the difference.

function SEQ_OP() {
           return FUNC1() ?? FUNC2();
        }
FUNC2() is conditionally evaluated and its result returned by SEQ_OP() only if FUNC1() evaluation returns unknown.
function AND() {
           return FUNC1() and FUNC2();
        }
FUNC2() is conditionally evaluated and its result returned by AND() only if FUNC1() returns true.
function OR() {
           return FUNC1() or FUNC2();
        }
FUNC2() is conditionally evaluated and its result returned by OR() only if FUNC1() returns false or unknown.
function STMT() {
           FUNC1();
           return FUNC2();
        }
FUNC1() is always evaluated. The return value from this invocation is not used. FUNC2() is also always evaluated and its result is returned by STMT().

Numerical operators

Modification operators on numerical attributes do not allow the result to exceed the range of values valid for the attribute. For example, the result of local_preference += 100 is bounded by 4294967295 and med -= 10000 is bounded by 0.

Return statement

The return statement returns the provided immediate value or the result of evaluating the provided expression to the caller.

return true | false | unknown | <EXPRESSION>;

A semicolon is required at the end of the return statement.

Examples:

function ALWAYS_TRUE() {
   # Example of returning an immediate value
   return true;
}

function DEFAULT_ROUTE() {
   # Example of returning a comparison
   return prefix is 0.0.0.0/0;
}

function RETURN_EXPR() {
   # Example of returning the result of an expression
   return ALWAYS_TRUE() and DEFAULT_ROUTE();
}

Exit statement

The exit statement immediately halts RCF function evaluation and returns the provided immediate value or the result of evaluating the provided expression to the point of application. The value is used at the point of application to accept or reject the route as explained in the section "Salient aspects and language primitives".

Supported since EOS-4.27.0F release.

exit true | false | unknown | <EXPRESSION>;

A semicolon is required at the end of the exit statement.

Examples:

function MAYBE_EXIT_TRUE() {
   # Example of function that may immediately exit true
   if prefix is 1.2.3.0/24 {
      exit true;
   }
}

function MAYBE_SET_MED() {
   # If MAYBE_EXIT_TRUE() exits, med will not be set and the policy will evaluate to
   # true even though we do not explicitly handle it.
   MAYBE_EXIT_TRUE();
   med = 10;
   return false;
}

Attribute modification statement

Attribute modifications follow the following syntax.

<ATTRIBUTE> <OPERATION> <VALUE>;

A semicolon is required at the end of the modification statement. Examples are provided alongside each supported attribute and operation in the next section.

If … condition

RCF allows an if … construct, followed by optional else if clauses, concluding with an optional else clause. The else if clause is supported since EOS-4.24.2F.

if syntax without an else block:

if <EXPRESSION> {
   # if block
}

if syntax with an else block:

if <EXPRESSION>  {
   # if block
} else {
   # else block
}

if syntax with an else if block:

if <EXPRESSION1>  {
   # if block
} else if <EXPRESSION2>  {
   # else if block
} else {
   # else block
}

Examples:

function MED_TEST_1() {
   if med is 100 {
      return true;
   }
   return false;
}

function MED_TEST_2() {
   if med >= 100 {
      return true;
   } else {
      return false;
   }
}

function MED_TEST_3() {
   if med >= 400 {
      local_preference = 400;
   } else if med >= 300 {
      local_preference = 300;
   } else if med >= 200 {
      local_preference = 200;
   } else {
      local_preference = 100;
   }
   return true;
}

Immediate values

asdot notation

For operations that include AS number immediate values, 4 byte AS numbers can be given in the asdot notation as specified by RFC5396.

For example:

as_path.origin_as is 1.10
MAC address notation

For operations that include MAC addresses, immediate values can use colon or dot notation.

For example:

evpn.mac_ip_route is 1a:2b:3c:4d:5e:6f

evpn.mac_ip_route is 1a2b.3c4d.5e6f
Sets

RCF supports a set collection. A set is a collection of unique values. When multiple instances of the same value are present only one takes effect.

The set collection has been supported since the EOS-4.25.2F release.

Example:

community add { 100, 200, 300 }

Attributes are supported in community sets since the EOS-4.29.1F release.

Example:

community add { 100, 200, igp.tag }
Ranges

RCF supports a range construct. A range has a lower and upper bound value. 

A value will match against a range if both of the following are true

  • the value is greater than or equal to the lower bound value.
  • the value is less than or equal to the upper bound value.

If the lower bound value is greater than the upper bound value in a given range, no value will match against it.

A range can be defined as part of a set collection. A set that contains a range can only be used with the in operator.

The set can contain any mix of singleton values and ranges.

The range construct has been supported since the EOS-4.29.1F release.

Example:

as_path.origin_as in { 64500, 64505 to 64510, 64503, 64515 to 64520 }

Attributes and functions

The RCF language provides a list of supported attributes that can be compared against values or modified. The language also includes builtin functions that provide some predefined functionality. The complete list of all attributes and builtin functions is available in the "Routing control functions - Attribute and builtin function reference" TOI.

The 'input' attribute scope

With the EOS-4.26.0F release, the RCF evaluation engine provides access to the unmodified attribute values, as seen by the evaluation engine at the point of application, during the evaluation of the function.

router general
   control-functions
      code
      function INPUT_AND_MODIFIED_LP_CHECK() {
         return input.local_preference is 500 and
                local_preference is 1000;
      }

      function INBOUND_POLICY() {
         local_preference = 1000;
         return INPUT_AND_MODIFIED_LP_CHECK();
      }
      EOF
!

In the example above, local_preference is modified to 1000 for all paths in INBOUND_POLICY(). However, INPUT_AND_MODIFIED_LP_CHECK() will return true only if the local_preference value received by the point of application function (INBOUND_POLICY) is 500 and the modified value is 1000.

Platform compatibility

The feature is supported on all EOS platforms.

Configuration

Providing RCF configuration

RCF code is a part of the EOS configuration. The supported workflows allow adding, modifying, and removing RCF configuration. RCF code operations are performed under a newly introduced control-functions sub-configuration mode, under the existing router-general configuration mode.

The CLI workflow revolves around 3 basic operations:

  • Pulling RCF code into the CLI session's "pending" buffer from a source (a remote URL or a local file).
  • Compiling the content’s of the CLI session’s pending buffer
  • Committing the contents of the CLI session's pending buffer into the running configuration after a successful compilation


Modifying the RCF code involves pushing the RCF code to an external source, editing it there, pulling it back from the external source into the pending buffer, followed by compiling and committing the successfully compiling code to the running configuration.


Code units

As of the EOS-4.26.2F release, RCF code can be organized into named code units. A code unit consists of zero or more RCF functions. RCF code units provide the smallest unit of RCF configuration that can be committed to the running configuration.

All code units are compiled together. Issuing the commit command updates all modified code units in the running configuration.

  1. Functions in one code unit may invoke functions in another code unit
  2. Function names must be unique across all code units
router general
   control-functions
      code unit COMMON
      function DEFAULT_ROUTE() {
         return prefix is 0.0.0.0/0 or prefix is ::/0;
      }
      EOF
      code unit AS_65535_FUNCTIONS
      function AS_65535_IN() {
         # Rejects default route, accepts all other routes
         if DEFAULT_ROUTE() {
            return false;
         }
         return true;
      }

      function AS_65535_OUT() {
         # Add a community and advertise all routes
         community add { 64500:200 };
         return true;
      }
      EOF

Configuration commands

To support these operations, the following commands are available under the control-functions configuration mode.

pull [unit <NAME>] replace <URL> Populate the pending buffer for the specified code unit with contents of the file located at the specified URL. For backward compatibility, pulling into the unnamed code unit causes the RCF code to compile automatically.
compile Compile all code units together. Modified code units are taken from the pending buffer, unmodified code units are taken from the running configuration.
commit If compilation is successful, update all modified code units from the pending buffer to the running configuration.
push [unit <NAME>] <URL> Push the contents of the specified code unit to the location identified by the URL. The contents are taken from the pending buffer if the code unit is modified. Otherwise, the code unit contents are taken from the running configuration.
discard [(unit <NAME>) | all] Discard the contents of the pending buffer for the specified code unit, or for all code units if the “all” keyword is specified
code [unit <NAME>] Create or replace RCF code for the specified code unit as multi-line input in EOS CLI
edit [unit <NAME>] Create or modify RCF code for the specified code unit using the GNU nano text editor (since EOS-4.27.1F)

Note that [unit <NAME>]is optional in the above commands. If a unit name is not specified, the command is applied to the singular unnamed code unit. This unnamed code unit behaves the same as named code units aside from the absence of a name.

Once RCF code units are committed to the running configuration, they will appear in show running-config along with the rest of the system configuration. This preserves EOS's ease of provisioning devices by keeping all the system configuration in a single file.

An example of pulling, compiling, and committing two RCF code units is shown below.

Arista(config)#router general
Arista(config-router-general)#control-functions
Arista(config-router-general-control-functions)#pull unit A replace http://192.168.1.1/rcf-code-unit-a.txt
Arista(config-router-general-control-functions)#pull unit B replace http://192.168.1.1/rcf-code-unit-b.txt
Arista(config-router-general-control-functions)#compile
Compilation successful
Arista(config-router-general-control-functions)#commit
Arista(config-router-general-control-functions)#

An example of taking an RCF code unit from the running configuration, modifying it, addressing compilation issues, and eventually committing it back to the running configuration is shown next.

Arista(config)#router general
Arista(config-router-general)#control-functions
Arista(config-router-general-control-functions)#push unit A flash:rcf-code-unit-a.txt
Arista(config-router-general-control-functions)#bash vi /mnt/flash/rcf-code-unit-a.txt   ! edit the contents
Arista(config-router-general-control-functions)#pull unit A replace flash:rcf-code-unit-a.txt
Arista(config-router-general-control-functions)#compile
% Error (syntax): line 1:13: mismatched input '{' expecting '('
Arista(config-router-general-control-functions)#push unit A flash:rcf-code-unit-a.txt   ! optionally push the RCF code unit again
Arista(config-router-general-control-functions)#bash vi /mnt/flash/rcf-code-unit-a.txt   ! edit the contents to fix compilation errors
Arista(config-router-general-control-functions)#pull unit A replace flash:rcf-code-unit-a.txt
Arista(config-router-general-control-functions)#compile
Compilation successful
Arista(config-router-general-control-functions)#commit
Arista(config-router-general-control-functions)#

Since EOS-4.27.1F, it is possible to add and modify RCF code units directly from the CLI using the edit [unit <NAME>] command. This will open the GNU nano text editor with the specified code unit, or create it. Saving the file and closing the editor will write the contents back to the pending buffer.

Compilation errors

RCF compilation provides some verification of the RCF code to ensure it can be evaluated. When compilation is invoked for RCF code that is malformed or cannot be evaluated errors will be reported. The following are some examples of common compilation errors explained. 

Examples

Missing semicolon

RCF requires a semicolon to separate statements even when statements are on different lines.

Below the semicolon is missing from the end of line 2.

Configuration:

router general
   control-functions
      code unit COMPILATION_ERROR
      function SET_MED() {
         med = 10
         return true;
      }
      EOF

Compilation output:

% Error unit COMPILATION_ERROR line 2:17: missing ';'
2          med = 10
                   ^
3          return true;
Missing curly brace

RCF requires a curly brace to indicate the end of a block of code.

Below the curly brace is missing.

Configuration:

router general
   control-functions
      code unit COMPILATION_ERROR
      function CHECK_MED() {
         return med is 10;
      function SET_MED() {
         med = 10;
      }
      EOF

Compilation output:

% Error unit COMPILATION_ERROR line 3:6: missing '}' at 'function SET_MED'
2          return med is 10;
3       function SET_MED() {
        ^~~~~~~~~~~~~~~~
Missing operator

If an expression is specified without an operator then RCF cannot determine what to do with the given values.

Below the operator is missing between the attribute med and the value 10.

Configuration:

router general
   control-functions
      code unit COMPILATION_ERROR
      function CHECK_MED() {
         return med 10;
      }
      EOF

Compilation output:

% Error unit COMPILATION_ERROR line 2:20: no viable alternative at input 'med 10'
2          return med 10;
                      ^~
Mismatching types

The left side and the right side of an RCF operator must have interoperable types for that operator.

Below is an expression comparing a community set with an integer.

Configuration:

router general
   control-functions
      code unit COMPILATION_ERROR
      function CHECK_COMMUNITY() {
         return community is 10;
      }
      EOF

Compilation output:

% Error unit COMPILATION_ERROR line 2:16 (function 'CHECK_COMMUNITY'): invalid operation 'is' between 'community' and '10'
2          return community is 10;
                  ^~~~~~~~~~~~~~~
Mismatching set contents

An RCF set must contain values with interoperable types.

Below a community set is defined that also contains invalid values or values from other set types.

Configuration:

router general
   control-functions
      code unit COMPILATION_ERROR
      function SET_COMMUNITY() {
         community = { FOO,  100, 200, 300, LINK-BANDWIDTH-AS:101:100.101MBps, 
                       LEVEL2, 100:100:100
         };
      }
      EOF

Compilation output:

% Error unit COMPILATION_ERROR line 2:23 (function 'SET_COMMUNITY'): invalid immediate values '{FOO, LINK-BANDWIDTH-AS:101:100.101MBps, LEVEL2, 100:100:100}' in an immediate community set
2          community = { FOO,  100, 200, 300, LINK-BANDWIDTH-AS:101:100.101MBps,
                         ^~~                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3                        LEVEL2, 100:100:100
                         ^~~~~~  ^~~~~~~~~~~
4          };
Undefined reference

For RCF to correctly determine the attribute or function being referred to in an expression, the attribute or function must be defined.

Below is an RCF function specifying the misspelled attribute aspath instead of as_path.

Configuration:

router general
   control-functions
      code unit COMPILATION_ERROR
      function SET_AS_PATH() {
        aspath prepend 10;
      }
      EOF

Compilation output:

% Error unit COMPILATION_ERROR line 2:8 (function 'SET_AS_PATH'): undefined reference to attribute 'aspath'
2         aspath prepend 10;
          ^~~~~~
Function redefinition

RCF requires that a function is only defined once.

Below is a configuration where two functions are defined with the same name.

Configuration:

router general
   control-functions
      code unit FIRST_DEFINITION
      function CHECK_MED() {
         if med is 10 {
            return true;
         }
      }
      EOF
      code unit SECOND_DEFINITION
      function CHECK_MED() {
         if med is 20 {
            return false;
         }
      }
      EOF

Compilation output:

% Error unit FIRST_DEFINITION line 1:6: redefinition of function 'CHECK_MED'
1       function CHECK_MED() {
        ^~~~~~~~~~~~~~~~~~

Previously defined in code unit SECOND_DEFINITION:
1       function CHECK_MED() {
        ^~~~~~~~~~~~~~~~~~
Function call cycles

An RCF function cannot directly or indirectly call itself.

Configuration:

router general
   control-functions
      code unit UNIT_A
      function A() {
         return B();
      }
      EOF
      code unit UNIT_B
      function B() {
         return true or C();
      }
      EOF
      code unit UNIT_C
      function C() {
         if ( false or A() or false) {
            return true;
         }
      }
      EOF

Compilation output:

% Error: cycle found in function callgraph 'A -> B -> C -> A'
Code unit UNIT_A
1       function A() {
        ^~~~~~~~~~

2          return B();
                  ^~~

Code unit UNIT_B
1       function B() {
        ^~~~~~~~~~

2          return true or C();
                          ^~~

Code unit UNIT_C
1       function C() {
        ^~~~~~~~~~

2          if ( false or A() or false) {
                         ^~~

Code unit UNIT_A
1       function A() {
        ^~~~~~~~~~

Compilation Warnings

RCF compilation provides some verification of the RCF code to ensure unusual behavior specified is intended. When compilation is invoked for RCF code that may not have the desired effect, warnings are reported. The following are some examples of common compilation warnings explained.

Examples

Statement with no effect

A condition in RCF where the result is not used for control flow has no effect.
Below is a logical operator whose result is not used, and so the operation has no effect.

Configuration:

router general
   control-functions
      code unit COMPILATION_WARNING
      function CHECK_MED() {
         med is 10 or 
         med is 20;
      }
      EOF

Compilation output:

! Warning unit COMPILATION_ERROR line 2:9 (function 'CHECK_MED'): statement has no effect
2          med is 10 or
           ^~~~~~~~~~~~
3          med is 20;
           \~~~~~~~~

Labeled code editing

Since EOS-4.26.2F release, an RCF function can be organized into labeled blocks. A labeled block is 0 or more RCF statements delimited by curly braces and identified by a name (the label). Labeled blocks can be added, modified, or removed via dedicated CLI commands. These dedicated CLI commands do not require the user to repeat the rest of the content in the code unit getting modified. The compile and commit commands are still required to apply the changes to the running configuration.

Example:

function PEER_192_168_1_1_IN() {
   @EARLY_RETURN {
      if prefix is 0.0.0.0 or prefix is ::/0 {
         return false;
      }
   }

   @REQUIRED_SETTERS {
      local_preference = 200;
      community add { 64500:200 };
   }

   @CONDITIONAL_STEPS {
      # Empty labeled block that can be filled in later
   }

   @FINAL_RESULT {
      return true;
   }
}

The operator should assign these labels within the RCF function upfront.

  • Labeled blocks can be nested
  • Label names can be reused across functions
  • Label names used within a function must be unique

A label name must start with @ followed by

  1. a-z, A-Z, 0-9, _ for the next character, and
  2. zero or more of a-z, A-Z, 0-9, _, ., {, }, =, -, :, \, [, ] characters

Examples of valid label names:

  • @main
  • @_seq1
  • @BgpOverload

Examples of invalid label names:

  • @-badLabelName
  • @Bad Label Name
  • BadLabelName

Labeled code modifications are auto-indented by EOS by approximating the indentation style used in the RCF function.

Replacing labeled blocks

The code [unit <UNIT_NAME>] replace block function <FUNC_NAME> <LABEL_NAME> command replaces the labeled block <LABEL_NAME> with a new labeled block specified by the operator as multi-line input in EOS CLI.

  • The label of the labeled block provided by the operator as multi-line input must match <LABEL_NAME>
  • <LABEL_NAME> must exist within the function <FUNC_NAME>
  • <FUNC_NAME> must exist within the code unit <UNIT_NAME>. 

The following example demonstrates replacing the labeled block @LABEL1:

Arista(config)#router general
Arista(config-router-general)#control-functions
Arista(config-router-general-control-functions)#show pending
code unit UNIT_A
function LABELED_BLOCK_EXAMPLE() {
   @LABEL1 {
      if med >= 100 {
         return false;
      }
   }

   @LABEL2 {
      return true;
   }
}
EOF
Arista(config-router-general-control-functions)#code unit UNIT_A replace block function LABELED_BLOCK_EXAMPLE @LABEL1
Enter RCF code. Type 'EOF' on its own line to end.
@LABEL1 {
   community add {64500:200};
}
EOF
Arista(config-router-general-control-functions)#show pending
code unit UNIT_A
function LABELED_BLOCK_EXAMPLE() {
   @LABEL1 {
      community add {64500:200};
   }

   @LABEL2 {
      return true;
   }
}
EOF

Inserting labeled blocks

The code [unit <UNIT_NAME>] insert block function <FUNC_NAME> {before, after} <LABEL_NAME> command inserts a new labeled block specified by the operator as multi-line input in EOS CLI before or after the labeled block <LABEL_NAME>.

  • The label name of the labeled block provided by the operator as multi-line input must not exist within the function <FUNC_NAME>
  • <LABEL_NAME> must exist within the function <FUNC_NAME>
  • <FUNC_NAME> must exist within the code unit <UNIT_NAME>. 

The following example demonstrates inserting a labeled block @LABEL_NEW before the labeled block @LABEL2:

Arista(config)#router general
Arista(config-router-general)#control-functions
Arista(config-router-general-control-functions)#show pending
code unit UNIT_A
function LABELED_BLOCK_EXAMPLE() {
   @LABEL2 {
      return true;
   }
}
EOF
Arista(config-router-general-control-functions)#code unit UNIT_A insert block function LABELED_BLOCK_EXAMPLE before @LABEL2
Enter RCF code. Type 'EOF' on its own line to end.
@LABEL_NEW {
   if community has_any {64500:100, 64500:200} {
      return false;
   }
}
EOF
Arista(config-router-general-control-functions)#show pending
code unit UNIT_A
function LABELED_BLOCK_EXAMPLE() {
   @LABEL_NEW {
      if community has_any {64500:100, 64500:200} {
         return false;
      }
   }
   @LABEL2 {
      return true;
   }
}
EOF

Deleting labeled blocks

The code [unit <UNIT_NAME>] delete block function <FUNC_NAME> <LABEL_NAME> command deletes the labeled block <LABEL_NAME>.

  • <LABEL_NAME> must exist within the function <FUNC_NAME>
  • <FUNC_NAME> must exist within the code unit <UNIT_NAME>. 

The following example demonstrates deleting the labeled block @LABEL1:

Arista(config)#router general
Arista(config-router-general)#control-functions
Arista(config-router-general-control-functions)#show pending
code unit UNIT_A
function LABELED_BLOCK_EXAMPLE() {
   @LABEL1 {
      if med >= 100 {
         return false;
      }
   }

   @LABEL2 {
      return true;
   }
}
EOF
Arista(config-router-general-control-functions)#code unit UNIT_A delete block function LABELED_BLOCK_EXAMPLE @LABEL1
Arista(config-router-general-control-functions)#show pending
code unit UNIT_A
function LABELED_BLOCK_EXAMPLE() {

   @LABEL2 {
      return true;
   }
}
EOF

EAPI support

Starting with the EOS-4.25.2F release, RCF configuration can be modified using EAPI. New or modified RCF configuration added via EAPI will automatically be compiled and committed into the running-config (or session-config if using a config session) upon exiting the control-functions submode or when the last CLI command in the EAPI request has been processed, whichever comes first.

Config session

RCF code can also be modified in a config session. The workflows described above can be invoked inside a config session. The RCF code must be committed to the config session by invoking commit inside the control-functions configuration mode before committing the config session. Otherwise, the RCF code changes made inside the session-config will get lost.

Arista(config)#configure session
Arista(config-s-sess-2)#router general
Arista(config-s-sess-2-router-general)#control-functions
Arista(config-s-sess-2-router-general-control-functions)#pull unit A replace flash:rcf-code-unit-a.txt
Arista(config-s-sess-2-router-general-control-functions)#compile
Compilation successful
Arista(config-s-sess-2-router-general-control-functions)#commit      ! RCF code commit
Arista(config-s-sess-2-router-general-control-functions)#show session-config
...
router general
   control-functions
      code unit A
      function ACCEPT_ALL() {
         # Accepts all routes
         return true;
      }

      function DENY_ALL() {
         # Rejects all routes
         return false;
      }
      EOF
...
Arista(config-s-sess-2-router-general-control-functions)#exit
Arista(config-s-sess-2-router-general)#commit      ! session commit

Config replace

The configure replace <URL> command replaces the running configuration with contents fetched from the specified URL. If the RCF code in the configuration fetched from the URL fails to compile, the entire configure replace operation fails to complete. An error log is generated at the end of configure replace execution.

Copy command

The copy <SRC_URL> running-config and the copy <SRC_URL> session-config commands replace the full RCF code at the destination with the RCF code available at the source if the RCF code compiles successfully. If the RCF code does not compile successfully, the RCF code from the source URL is ignored.  Compilation errors in the RCF code do not affect the copying of non-RCF configuration present at the source.

Points of application

The above sections specify how RCF functions can be configured and edited on EOS. RCF functions have to additionally be configured at the desired point of evaluation, in various agents, to use the RCF functionality. Documentation covering configuration in these agents can be found in the “Resources” section.

Show commands

Workflow show commands

Displaying pending RCF configuration

The show router rcf pending command or the show pending command in the router general > control-functions configuration mode, shows the contents of the CLI session's pending buffer.

With the EOS-4.24.2F release, it also shows the source of the RCF code pull at the top of the uncommitted RCF code.

With the EOS-4.26.2F release, the  show router rcf pending command or the show pending command will show the effective contents of all RCF code units that will take effect after a commit command. All code units will be displayed regardless of whether they have been modified in the pending buffer. If there are no changes to be committed (the pending buffer content is the same as the running configuration for all code units), the message No pending routing control function changes is printed at the top of the show command output.

Arista(config)#configure terminal
Arista(config)#router general
Arista(config-router-general)#control-functions
Arista(config-router-general-control-functions)#pull unit A replace flash:rcf-code-unit-a.txt
Arista(config-router-general-control-functions)#show pending
code unit A
! Source: file:/tmp/rcf-code-unit-a.txt
function ACCEPT_ALL() {
   # Accepts all routes
   return true;
}

function DENY_ALL() {
   # Rejects all routes
   return false;
}
EOF
Arista(config-router-general-control-functions)#compile
Compilation successful
Arista(config-router-general-control-functions)#commit
Arista(config-router-general-control-functions)#show pending
No pending routing control function changes
code unit A
! Source: file:/tmp/rcf-code-unit-a.txt
function ACCEPT_ALL() {
   # Accepts all routes
   return true;
}

function DENY_ALL() {
   # Rejects all routes
   return false;
}
EOF
Arista(config-router-general-control-functions)#

Displaying diff between RCF configuration in pending buffer and running configuration

The EOS-4.25.2F release adds support for show diff in the router general > control-functions configuration mode which shows the difference between the RCF code in the pending buffer and the RCF code in the running configuration.

With the EOS-4.26.2F release, the show diff command shows the difference between the RCF code in the pending buffer and the RCF code in the running configuration.

Arista(config-router-general-control-functions)#pull unit A replace file:/tmp/rcf-code-unit-a-2.txt
Arista(config-router-general-control-functions)#compile
Compilation successful
Arista(config-router-general-control-functions)#show diff
--- running-config: code unit A
+++ pending: code unit A
@@ -7,3 +7,7 @@
	# Rejects all routes
	return false;
 }
+
+function DEFAULT_ROUTE() {
+   return prefix is 0.0.0.0/0 or prefix is ::/0;
+}

Arista(config-router-general-control-functions)#

Displaying active RCF configuration

Note that show active and show running-config will also show the source of the committed RCF code. Built-in functions are not displayed since they are not defined by the user.

Arista(config-router-general-control-functions)#show active
router general
   control-functions
      code unit A source pulled-from flash:rcf-code-unit-a.txt
      code unit A
      function ACCEPT_ALL() {
         # Accepts all routes
         return true;
      }
      
      function DENY_ALL() {
         # Rejects all routes
         return false;
      }
      EOF
Arista(config-router-general-control-functions)#

Displaying RCF code units

The EOS-4.28.1F release adds support for show router rcf code [ unit <UNIT_NAME> ] which shows the committed RCF code in the running configuration.
RCF code committed in a config session will only be shown once the config session has been committed.

Arista(config-router-general-control-functions)#show router rcf code unit A
function ACCEPT_ALL() {
   # Accepts all routes
   return true;
}

Displaying RCF function locations

The EOS-4.29.0F release adds support for show router rcf function location [ ( function FUNC_NAME ) | ( unit UNIT_NAME ) ] which shows the code unit name and starting line number within the code unit for committed RCF function definitions.

Example
router general
   control-functions
      code
      function testA() {  
         med = 10;  
         return true;  
      }
      
      EOF
      code unit unit2
      function testC() {  
         med = 20;  
         return true;  
      }
      
      function testB() {  
         med = 30;  
         return true;  
      }
      
      EOF
      code unit unit3
      function testD() {  
         return true;  
      }
      EOF
Show the locations of all functions in all code units

By default, the show router rcf function location command will display all RCF functions across all code units.

Note: Built-in functions are not displayed since they are not defined by the user.

Arista(config-router-general-control-functions)#show router rcf function location
Function Name Code Unit         Line Number  
------------- ----------------- -----------  
testA         unnamed code unit           1  
testB         unit2                       6  
testC         unit2                       1  
testD         unit3                       1 
Show the location of a specific function

Locating a specific function can be done by adding the function FUNC_NAME filter to the command.

Note: Specifying a built-in function or a non-existing function will result in an error.

Arista(config-router-general-control-functions)#show router rcf function location function testB
Function Name Code Unit Line Number  
------------- --------- -----------  
testB         unit2               6 
Show the location of all functions in a code unit

Locating all functions in a code unit can be done by adding the unit UNIT_NAME filter to the command.

Note: Specifying a non-existing code unit will result in an error.

Arista(config-router-general-control-functions)#show router rcf function location unit unit2
Function Name Code Unit Line Number  
------------- --------- -----------  
testB         unit2               6  
testC         unit2               1

Debugging

With the EOS-4.27.2F release, the RCF evaluation engine provides a textual representation explaining the control flow of a given evaluation of an RCF function.

This textual representation aids the user in understanding how an RCF function evaluates a given route at a specified point of application. It indicates:

  • the overall result of the evaluation
  • the RCF code that was evaluated
  • the results of individual expressions
  • the evaluation of operators, including:
    • the overall result of the operator
    • whether the operators evaluation was short circuited
    • the precedence in the evaluation of multiple operators in a single expression
  • the evaluation of called functions, including
    • the overall result of the called function
    • the evaluation of the called function’s contents

The CLI command to debug the RCF evaluation of a route at a point of application is provided in the point of applications documentation. Documentation covering debugging at these points of application can be found in the “Resources” section.

The RCF evaluation is explained by way of textual annotations displayed above each line of evaluated RCF code.

The annotations are as follows:

Name Annotation Purpose
Evaluation bar ------------- Indicates a statement or assignment was evaluated.
True bar T------------ Indicates a condition, operator, or function call evaluated to true.
False bar F------------ Indicates a condition, operator, or function call evaluated to false.
Unknown bar U------------ Indicates a function call evaluated to unknown.
Exit bar X------------ Indicates the evaluation of a statement, expression, operator, or function call was halted due to an ‘exit’ statement.
Continuation bar \------------ Indicates that an evaluated statement, assignment, expression, or function call is continuing on from the previous line.

Examples

Return true

This example demonstrates how the overall result of a function is indicated.

Configuration:

router general
   control-functions
      code unit DEBUG
      function RETURN_TRUE() {
         return true;
      }
      EOF

Debugging output:

The path was allowed by the evaluation of main().

Code unit DEBUG
1 function RETURN_TRUE() {
     T----- T---
2    return true;

Note:

  • The initial sentence indicates the overall effect of the RCF function was to allow the path.
  • The function is defined at line number 1 in the DEBUG code unit.
Modify and compare attribute

This example demonstrates how assignment statements and comparison expressions are indicated.

Configuration:

router general
   control-functions
      code unit DEBUG
      function SET_AND_MATCH_MED_OVER_200() {
         # Increment med by 50 and return true 
         # if med is then greater than 200.
         med += 50;
         return med >= 200;
      }
      EOF

Debugging output with med = 100:

The path was disallowed by the evaluation of SET_AND_MATCH_MED_OVER_200().

Code unit DEBUG
1 function SET_AND_MATCH_MED_OVER_200() {
     ---------
4    med += 50;
     F----- F---------
5    return med >= 200;

Debugging output with med = 200:

The path was allowed by the evaluation of SET_AND_MATCH_MED_OVER_200().

Code unit DEBUG
1 function SET_AND_MATCH_MED_OVER_200() {
     ---------
4    med += 50;
     T----- T---------
5    return med >= 200; 

Note:

  • The comments are not included in the output (lines 2 and 3). Only lines of RCF code relevant to the evaluation are in the output.
  • An evaluation bar indicates that med += 50 evaluated. This statement’s evaluation has no trilean result so one is not indicated.
  • Depending on the value of med the return expression is indicated with a false bar or a true bar.
Logical operators

This example demonstrates how operators, short circuiting, and precedence are indicated.

Configuration:

router general
   control-functions
      code unit DEBUG
      function OPERATORS() {
         return false and true or true;
      }
      EOF

Debugging output:

The path was allowed by the evaluation of OPERATORS().

Code unit DEBUG
1 function OPERATORS() {
     T----- (F---- F--     ) T- T---
2    return  false and true  or true;

Note:

  • The overall result of the operator expressions are indicated above the operators.
  • The and operator takes precedence over the or operator. Thus the and expression is enclosed in brackets to indicate the implicit precedence. The or expression includes the result of the and expression as its left hand side.
  • The and operator evaluation has short circuited. Thus the right hand side of the expression does not have an evaluation bar because it did not evaluate.
  • The overall result of the logical expression is indicated by the true bar above the return statement. 
if else statement

This example demonstrates how an if … else if .. else control flow is indicated

Configuration:

router general
   control-functions
      code unit DEBUG
      function IF() {
        if false {
           return true;
        } else if true {
           return false;
        } else {
           return true;
        }
        return true;
      }
      EOF

Debugging output:

The path was disallowed by the evaluation of IF().

Code unit DEBUG
1 function IF() {                                                                                                                                                                                                     
    F- F----
2   if false {
      ---- T- T---
4   } else if true {
       F----- F----
5      return false;

Note:

  • The false bar above the if statement on line 2 indicates the overall result of the condition. 
  • The if condition on line 2 evaluated to false, therefore the if block did not evaluate. Thus it is not present in the output.
  • As the if condition on line 2 evaluated to false, the else if is evaluated, represented with an evaluation bar.
  • As the if condition on line 4 evaluates to true, the else if block is evaluated.
  • A return statement is evaluated in this block, resulting in the function’s evaluation ending. Thus the remainder of the function is not in the output.
Function calls

This example demonstrates how function calls and code unit names are indicated.

Configuration:

router general
   control-functions
      code unit DEBUG
      function SET_MED() {
         med = 10;
      }
      function MAIN() {
         SET_MED();
         return CHECK_MED_IS_SET();
      }
      function CHECK_MED_IS_SET() {
         if MED_IS_10() {
            return true;
         }
      }
      code unit MED_UNIT
      function MED_IS_10() {
         return med is 10;
      }
      EOF

Debugging output:

The path was allowed by the evaluation of MAIN().

Code unit DEBUG
4 function MAIN() {
     U--------
5    SET_MED();

Code unit DEBUG
|1 function SET_MED() {
|     --------
|2    med = 10;
|3 }

     T----- T-----------------
6    return CHECK_MED_IS_SET();

Code unit DEBUG                        
| 8 function CHECK_MED_IS_SET() {        
|      T- T----------
| 9    if MED_IS_10() {

Code unit MED_UNIT
||1 function MED_IS_10() {               
||     T----- T--------
||2    return med is 10;

|         T----- T---
|10       return true;     

Note:

  • The initial function called for the evaluation is indicated in the first sentence of the output. It is MAIN. 
  • The function call within the evaluation occurs on line 5, SET_MED().
  • The evaluation of SET_MED is below its call in the output. 
  • To indicate SET_MED is called from within another function the evaluation of SET_MED is indented by a single pipe (|). 
  • The return value of unknown from SET_MED is indicated by the unknown bar above the function call on line 5.
  • The evaluation of SET_MED does not encounter a return statement thus the function returns unknown. The closing curly bracket } ending the function block is included to indicate reaching the end of the block and thus the end of the function.
  • After the evaluation of SET_MED has finished the evaluation of MAIN continues from line 6.
  • The function MAIN returns on line 6 and the evaluation ends, however the evaluation of the called function in the last expression (CHECK_MED_IS_SET) is indicated below its call in the output.
  • The function MED_IS_10 is defined in a separate code unit MED_UNIT, indicated at the top of the function’s evaluation. Line numbers are relative to the code unit the function is defined in.
  • The function MED_IS_10 is called from within a function call to CHECK_MED_IS_SET. Thus two pipes (||) are used to indicate the called function’s evaluation.
exit statement

This example demonstrates how exit statement evaluations are indicated

Configuration:

router general
   control-functions
      code unit DEBUG
      function MAIN() {
         return EXIT();
      }
      function EXIT() {
         exit true;
      }
      EOF

Debugging output:

The path was allowed by the evaluation of MAIN().

Code unit DEBUG                        
1 function MAIN() {
     X----- X-----
2    return EXIT();                      

Code unit DEBUG
|4 function EXIT() {                     
|     T--- T---
|5    exit true;

Note:

  • The exit bar above the return EXIT() expression indicates that the evaluation of this expression was halted due to the evaluation of an exit expression. As these expressions did not complete they do not have trilean results.
  • The true bar above the exit statement indicates the exit expression was true. This is the overall result of the RCF evaluation invoked for function MAIN. 
Multiline expressions

This example demonstrates how multiline expressions are indicated

Configuration:

router general
   control-functions
      code unit DEBUG
      function COMMUNITY() {
         return community has_any { 64500:100, 
                                    64500:200 } 
      }
      EOF

Debugging output:

The path was allowed by the evaluation of COMMUNITY().

Code unit DEBUG
1 function COMMUNITY() {
     T----- T-----------------------------
2    return community has_any { 64500:100,
                                \----------
3                               64500:200 };

Note:

  • The true bar above the community operation indicates that the condition was true. 
  • The continuation bar above the RCF code on line 3 indicates that this is part of the same expression continuing from the previous line.

Limitations

  • Route maps cannot be invoked from inside an RCF function. Similarly, RCF functions cannot be invoked from within route maps.