Dependency pattern enhances the ability to parse complex, multi-layered Config-lets for golden configuration checks. In dependency pattern, the parser results of different patterns can be merged in the parsing process to get the desired output, which will be a table variable constructed with all the variables in all the level patterns.
Level in Dependency Pattern
A level in dependency pattern contains a predefined single-variable pattern or paragraph pattern. A dependency pattern includes one or more levels that will be automatically named Level 1, Level 2…Level n, and the outputs of the parser at one level will be merged with the outputs from the previous levels to enrich the parser outputs.
Define Dependency Pattern
Complete the following main steps to define a dependency pattern.
- Select dependency pattern: Click New Pattern>Advanced>Dependency.
- Define Level 1: A predefined pattern can be selected as Level 1 pattern, which will serve as a fundamental pattern, and the pattern in Level 1 is read-only.
- Define more Levels: More Levels can be added, and the added Levels will follow the rules below:
- The line patterns for the Level can be refreshed, and the pattern can also be deleted.
- The pattern that has already been selected for a Level will be dimmed and cannot be selected for another level.
- If the added level pattern contains local scopes, the scope will not be shown in Dependency pattern.
- Parent pattern and its sub-pattern can be selected independently as Level in dependency pattern.
- Define Replace: Replace constant text in all the line patterns of the current level pattern with a variable defined in previous levels. When Replace works, the constant texts in levels will be replaced by the level creation time, which means the constant texts in the level created earlier will be replaced first.
- Manually enter variable or select variables (clicking the
icon) to make replacement. The variables selected must be variable in the previous levels.
- Prefix and suffix can be added to make precise replacement.
- Multiple Replaces can be defined for one Level by adding ‘Replace’ (clicking the
icon).
- Replace can be removed by clicking the
icon.
- Manually enter variable or select variables (clicking the
Example of How to Define Dependency Pattern
In this example, define a dependency pattern to parse all the related config of each route OSPF instance, including the OSPF config, route map config, and prefix list config.
Prerequisites: Before defining a dependency pattern, define some single-variable patterns or paragraph patterns in the current parser, these patterns can be selected as Level.
- Define a paragraph pattern L1_ospf as below.
- Parser variable $int: ospf_id by ID line.
- Parse variable $route_map_id by Var Line 1.
- Parser variable $ospf_config by Parse Lines > The line of variable function using the variable $ospf_id.
- Add End of Paragraph to limit the parse scope.
- Define a paragraph pattern L2_route_map as below:
- Parser variable $rou_map, then define enumeration (B2O) for the variable in the ID Line.
- Parse variable $prefix_list by Var Line 1.
- Parse variable $rout_config by Parse Lines > The Line between variables function using existing variables $rout_map and $prefix_list.
- Define a single-variable pattern L3_prefix: Parse variable $prefix_config by the Parse Lines > The line contains keyword function.
Follow the steps below to define a dependency pattern.
- Click +New Pattern > Advanced > Dependency.
- Click the
icon at the upper left corner of the right pane, then modify the dependency pattern name, for example, change the dependency pattern name to dependency_config.
- Click + Level, then select the predefined pattern L1_ospf in this parser as Level 1.
- Click + Level, then select the predefined pattern L2_route_map in this parser as Level 2.
- Click +Add Replace to define Replace for Level 2: Replace B2O in the line patterns in the current level 2 with the values of $route_map_id to get more results according to the values of $route_map_id.
Note: ‘Replace’ can be defined for all Levels except Level 1. - Click + Level, then select the predefined pattern L3_prefix in this parser as Level 3.
- Click + Add Replace to define replacement for Level 3. Replace B2O in the line patterns of Level 3 with $prefix_list.
- Click to + Add Additional Variable to add a variable by merging the variables $ospf_config, $rout_config and $prefix_config by the Merge String by Line method. Finally, the variable $all_config that combine the three variables $ospf_config, $rout_config and $prefix_config is added.
Note: For more information about the Add Additional Variable function, see Add Additional Column/Variable in Parser Output Table. - Click the
icon at the upper-right corner to save the parser. The output table of this dependency pattern is as below: