diff options
Diffstat (limited to 'tools/frr-reload.py')
| -rwxr-xr-x | tools/frr-reload.py | 69 |
1 files changed, 67 insertions, 2 deletions
diff --git a/tools/frr-reload.py b/tools/frr-reload.py index ef92e8b59f..461f0e8c61 100755 --- a/tools/frr-reload.py +++ b/tools/frr-reload.py @@ -220,6 +220,23 @@ def get_normalized_mac_ip_line(line): return line +def get_normalized_interface_vrf(line): + """ + If 'interface <int_name> vrf <vrf_name>' is present in file, + we need to remove the explicit "vrf <vrf_name>" + so that the context information is created + correctly and configurations are matched appropriately. + """ + + intf_vrf = re.search("interface (\S+) vrf (\S+)", line) + if intf_vrf: + old_line = "vrf %s" % intf_vrf.group(2) + new_line = line.replace(old_line, "").strip() + return new_line + + return line + + # This dictionary contains a tree of all commands that we know start a # new multi-line context. All other commands are treated either as # commands inside a multi-line context or as single-line contexts. This @@ -295,6 +312,10 @@ class Config(object): # Compress duplicate whitespaces line = " ".join(line.split()) + # Remove 'vrf <vrf_name>' from 'interface <x> vrf <vrf_name>' + if line.startswith("interface ") and "vrf" in line: + line = get_normalized_interface_vrf(line) + if ":" in line: line = get_normalized_mac_ip_line(line) @@ -1062,19 +1083,34 @@ def pim_delete_move_lines(lines_to_add, lines_to_del): # Remove all such depdendent options from delete # pending list. pim_disable = False + lines_to_del_to_del = [] + index = -1 for ctx_keys, line in lines_to_del: + index = index + 1 if ctx_keys[0].startswith("interface") and line and line == "ip pim": pim_disable = True + # no ip msdp peer <> does not accept source so strip it off. + if line and line.startswith("ip msdp peer "): + pim_msdp_peer = re.search("ip msdp peer (\S+) source (\S+)", line) + if pim_msdp_peer: + source_sub_str = "source %s" % pim_msdp_peer.group(2) + new_line = line.replace(source_sub_str, "").strip() + lines_to_del.remove((ctx_keys, line)) + lines_to_del.insert(index, (ctx_keys, new_line)) + if pim_disable: for ctx_keys, line in lines_to_del: if ( ctx_keys[0].startswith("interface") and line - and line.startswith("ip pim ") + and (line.startswith("ip pim ") or line.startswith("ip multicast ")) ): - lines_to_del.remove((ctx_keys, line)) + lines_to_del_to_del.append((ctx_keys, line)) + + for ctx_keys, line in lines_to_del_to_del: + lines_to_del.remove((ctx_keys, line)) return (lines_to_add, lines_to_del) @@ -1439,6 +1475,35 @@ def ignore_delete_re_add_lines(lines_to_add, lines_to_del): lines_to_add.append((add_cmd, None)) lines_to_del_to_del.append((ctx_keys, None)) + # bgp as-path access-list can be specified without a seq number. + # However, the running config always + # adds `seq X` (sequence number). So, ignore such lines as well. + # Examples: + # bgp as-path access-list important_internet_bgp_as_numbers seq 30 permit _40841_" + re_bgp_as_path = re.search( + "^(bgp )(as-path )(access-list )(\S+\s+)(seq \d+\s+)(permit|deny)(.*)$", + ctx_keys[0], + ) + if re_bgp_as_path: + found = False + tmpline = ( + re_bgp_as_path.group(1) + + re_bgp_as_path.group(2) + + re_bgp_as_path.group(3) + + re_bgp_as_path.group(4) + + re_bgp_as_path.group(6) + + re_bgp_as_path.group(7) + ) + for ctx in lines_to_add: + if ctx[0][0] == tmpline: + lines_to_del_to_del.append((ctx_keys, None)) + lines_to_add_to_del.append(((tmpline,), None)) + found = True + if found is False: + add_cmd = ("no " + ctx_keys[0],) + lines_to_add.append((add_cmd, None)) + lines_to_del_to_del.append((ctx_keys, None)) + if ( len(ctx_keys) == 3 and ctx_keys[0].startswith("router bgp") |
