Refactor prune_lcps()

Fold in the qinx, 1-tag sub, and phy/lookback into one loop, reducing
total LOC by 3x.

Tested by running a hippo integration test (ie 169 config-to-config
transitions), with no material diffs between the old and the new code:

@@ -182,9 +182,9 @@
 /tmp/vppcfg-exec_hippo1.yaml: lcp create HundredGigabitEthernet12/0/0.1235 host-if ice0.1234.1000
 /tmp/vppcfg-exec_hippo1.yaml_hippo10.yaml: lcp delete HundredGigabitEthernet12/0/0.1235
 /tmp/vppcfg-exec_hippo1.yaml_hippo10.yaml: lcp delete HundredGigabitEthernet12/0/0.1234
-/tmp/vppcfg-exec_hippo1.yaml_hippo10.yaml: lcp delete loop1
-/tmp/vppcfg-exec_hippo1.yaml_hippo10.yaml: lcp delete loop0
 /tmp/vppcfg-exec_hippo1.yaml_hippo10.yaml: lcp delete HundredGigabitEthernet12/0/0
+/tmp/vppcfg-exec_hippo1.yaml_hippo10.yaml: lcp delete loop0
+/tmp/vppcfg-exec_hippo1.yaml_hippo10.yaml: lcp delete loop1
 /tmp/vppcfg-exec_hippo1.yaml_hippo11.yaml: lcp delete HundredGigabitEthernet12/0/0.1235
 /tmp/vppcfg-exec_hippo1.yaml_hippo11.yaml: lcp delete HundredGigabitEthernet12/0/0.1234
 /tmp/vppcfg-exec_hippo1.yaml_hippo11.yaml: lcp delete loop1
@@ -202,8 +202,8 @@
 /tmp/vppcfg-exec_hippo1.yaml_hippo2.yaml: lcp delete HundredGigabitEthernet12/0/0.1235
 /tmp/vppcfg-exec_hippo1.yaml_hippo2.yaml: lcp delete HundredGigabitEthernet12/0/0.1234
 /tmp/vppcfg-exec_hippo1.yaml_hippo2.yaml: lcp delete loop1
-/tmp/vppcfg-exec_hippo1.yaml_hippo2.yaml: lcp delete loop0
 /tmp/vppcfg-exec_hippo1.yaml_hippo2.yaml: lcp delete BondEthernet0
+/tmp/vppcfg-exec_hippo1.yaml_hippo2.yaml: lcp delete loop0
 /tmp/vppcfg-exec_hippo1.yaml_hippo2.yaml: lcp delete HundredGigabitEthernet12/0/0
 /tmp/vppcfg-exec_hippo1.yaml_hippo3.yaml: lcp delete HundredGigabitEthernet12/0/0.1235
 /tmp/vppcfg-exec_hippo1.yaml_hippo3.yaml: lcp delete HundredGigabitEthernet12/0/0.1234
This commit is contained in:
Pim van Pelt
2022-03-28 16:38:35 +00:00
parent 4704780362
commit 2003a21068

View File

@ -406,22 +406,26 @@ class Reconciler():
lcps = self.vpp.config['lcps'] lcps = self.vpp.config['lcps']
removed_lcps = [] removed_lcps = []
## Remove LCPs for QinX interfaces for numtags in [ 2, 1, 0 ]:
for idx, lcp in lcps.items(): for idx, lcp in lcps.items():
vpp_iface = self.vpp.config['interfaces'][lcp.phy_sw_if_index] vpp_iface = self.vpp.config['interfaces'][lcp.phy_sw_if_index]
if vpp_iface.sub_inner_vlan_id == 0: if vpp_iface.sub_number_of_tags != numtags:
continue continue
if vpp_iface.interface_dev_type=='Loopback':
config_ifname, config_iface = loopback.get_by_lcp_name(self.cfg, lcp.host_if_name)
else:
config_ifname, config_iface = interface.get_by_lcp_name(self.cfg, lcp.host_if_name) config_ifname, config_iface = interface.get_by_lcp_name(self.cfg, lcp.host_if_name)
if not config_iface: if not config_iface:
## QinX doesn't exist in the config ## Interface doesn't exist in the config
self.logger.info("1> lcp delete %s" % vpp_iface.interface_name) self.logger.info("1> lcp delete %s" % vpp_iface.interface_name)
removed_lcps.append(lcp.host_if_name) removed_lcps.append(lcp.host_if_name)
continue continue
if not 'lcp' in config_iface: if not 'lcp' in config_iface:
## QinX doesn't have an LCP ## Interface doesn't have an LCP
self.logger.info("2> lcp delete %s" % vpp_iface.interface_name) self.logger.info("2> lcp delete %s" % vpp_iface.interface_name)
removed_lcps.append(lcp.host_if_name) removed_lcps.append(lcp.host_if_name)
continue continue
if vpp_iface.sub_number_of_tags == 2:
vpp_parent_idx = self.__parent_iface_by_encap(vpp_iface.sup_sw_if_index, vpp_iface.sub_outer_vlan_id, vpp_iface.sub_if_flags&8) vpp_parent_idx = self.__parent_iface_by_encap(vpp_iface.sup_sw_if_index, vpp_iface.sub_outer_vlan_id, vpp_iface.sub_if_flags&8)
vpp_parent_iface = self.vpp.config['interfaces'][vpp_parent_idx] vpp_parent_iface = self.vpp.config['interfaces'][vpp_parent_idx]
parent_lcp = lcps[vpp_parent_iface.sw_if_index] parent_lcp = lcps[vpp_parent_iface.sw_if_index]
@ -441,107 +445,45 @@ class Reconciler():
self.logger.info("5> lcp delete %s" % vpp_iface.interface_name) self.logger.info("5> lcp delete %s" % vpp_iface.interface_name)
removed_lcps.append(lcp.host_if_name) removed_lcps.append(lcp.host_if_name)
continue continue
phy_lcp = lcps[vpp_iface.sup_sw_if_index]
config_phy_ifname, config_phy_iface = interface.get_by_lcp_name(self.cfg, phy_lcp.host_if_name)
if not config_phy_iface:
## QinX's phy doesn't exist in the config
self.logger.info("6> lcp delete %s" % vpp_iface.interface_name)
removed_lcps.append(lcp.host_if_name)
continue
if not 'lcp' in config_phy_iface:
## QinX's phy doesn't have an LCP
self.logger.info("6> lcp delete %s" % vpp_iface.interface_name)
removed_lcps.append(lcp.host_if_name)
continue
if phy_lcp.host_if_name != config_phy_iface['lcp']:
## QinX's phy LCP name mismatch
self.logger.info("7> lcp delete %s" % vpp_iface.interface_name)
removed_lcps.append(lcp.host_if_name)
continue
config_encap = interface.get_encapsulation(self.cfg, config_ifname)
vpp_encap = self.__get_encapsulation(vpp_iface)
config_parent_encap = interface.get_encapsulation(self.cfg, config_parent_ifname) config_parent_encap = interface.get_encapsulation(self.cfg, config_parent_ifname)
vpp_parent_encap = self.__get_encapsulation(vpp_parent_iface) vpp_parent_encap = self.__get_encapsulation(vpp_parent_iface)
if config_encap != vpp_encap:
## QinX's encapsulation mismatch
self.logger.info("8> lcp delete %s" % vpp_iface.interface_name)
removed_lcps.append(lcp.host_if_name)
continue
if config_parent_encap != vpp_parent_encap: if config_parent_encap != vpp_parent_encap:
## QinX's parent encapsulation mismatch ## QinX's parent encapsulation mismatch
self.logger.info("9> lcp delete %s" % vpp_iface.interface_name) self.logger.info("9> lcp delete %s" % vpp_iface.interface_name)
removed_lcps.append(lcp.host_if_name) removed_lcps.append(lcp.host_if_name)
continue continue
self.logger.debug("QinX LCP OK: %s -> (vpp=%s, config=%s)" % (lcp.host_if_name, vpp_iface.interface_name, config_ifname))
## Remove LCPs for sub-interfaces if vpp_iface.sub_number_of_tags > 1:
for idx, lcp in lcps.items(): config_encap = interface.get_encapsulation(self.cfg, config_ifname)
vpp_iface = self.vpp.config['interfaces'][lcp.phy_sw_if_index] vpp_encap = self.__get_encapsulation(vpp_iface)
if vpp_iface.sub_inner_vlan_id > 0 or vpp_iface.sub_outer_vlan_id == 0: if config_encap != vpp_encap:
continue ## Encapsulation mismatch
config_ifname, config_iface = interface.get_by_lcp_name(self.cfg, lcp.host_if_name) self.logger.info("8> lcp delete %s" % vpp_iface.interface_name)
if not config_iface:
## Sub doesn't exist in the config
self.logger.info("11> lcp delete %s" % vpp_iface.interface_name)
removed_lcps.append(lcp.host_if_name) removed_lcps.append(lcp.host_if_name)
continue continue
if not 'lcp' in config_iface:
## Sub doesn't have an LCP if vpp_iface.interface_dev_type=='Loopback':
self.logger.info("12> lcp delete %s" % vpp_iface.interface_name) ## Loopbacks will not have a PHY to check.
removed_lcps.append(lcp.host_if_name)
continue continue
phy_lcp = lcps[vpp_iface.sup_sw_if_index] phy_lcp = lcps[vpp_iface.sup_sw_if_index]
config_phy_ifname, config_phy_iface = interface.get_by_lcp_name(self.cfg, phy_lcp.host_if_name) config_phy_ifname, config_phy_iface = interface.get_by_lcp_name(self.cfg, phy_lcp.host_if_name)
if not config_phy_iface: if not config_phy_iface:
## Sub's phy doesn't exist in the config ## Phy doesn't exist in the config
self.logger.info("13> lcp delete %s" % vpp_iface.interface_name) self.logger.info("6> lcp delete %s" % vpp_iface.interface_name)
removed_lcps.append(lcp.host_if_name) removed_lcps.append(lcp.host_if_name)
continue continue
if not 'lcp' in config_phy_iface: if not 'lcp' in config_phy_iface:
## Sub's phy doesn't have an LCP ## Phy doesn't have an LCP
self.logger.info("14> lcp delete %s" % vpp_iface.interface_name) self.logger.info("6> lcp delete %s" % vpp_iface.interface_name)
removed_lcps.append(lcp.host_if_name) removed_lcps.append(lcp.host_if_name)
continue continue
if phy_lcp.host_if_name != config_phy_iface['lcp']: if phy_lcp.host_if_name != config_phy_iface['lcp']:
## Sub's phy LCP name mismatch ## Phy LCP name mismatch
self.logger.info("15> lcp delete %s" % vpp_iface.interface_name) self.logger.info("7> lcp delete %s" % vpp_iface.interface_name)
removed_lcps.append(lcp.host_if_name) removed_lcps.append(lcp.host_if_name)
continue continue
config_encap = interface.get_encapsulation(self.cfg, config_ifname)
vpp_encap = self.__get_encapsulation(vpp_iface)
if config_encap != vpp_encap:
## Sub's encapsulation mismatch
self.logger.info("16> lcp delete %s" % vpp_iface.interface_name)
removed_lcps.append(lcp.host_if_name)
continue
self.logger.debug("Dot1Q/Dot1AD LCP OK: %s -> (vpp=%s, config=%s)" % (lcp.host_if_name, vpp_iface.interface_name, config_ifname))
## Remove LCPs for interfaces, bonds, tunnels, loops
for idx, lcp in lcps.items():
vpp_iface = self.vpp.config['interfaces'][lcp.phy_sw_if_index]
if vpp_iface.sub_inner_vlan_id > 0 or vpp_iface.sub_outer_vlan_id > 0:
continue
if vpp_iface.interface_dev_type=='Loopback':
config_ifname, config_iface = loopback.get_by_lcp_name(self.cfg, lcp.host_if_name)
else:
config_ifname, config_iface = interface.get_by_lcp_name(self.cfg, lcp.host_if_name)
if not config_iface:
## Interface doesn't exist in the config
self.logger.info("21> lcp delete %s" % vpp_iface.interface_name)
removed_lcps.append(lcp.host_if_name)
continue
if not 'lcp' in config_iface:
## Interface doesn't have an LCP
self.logger.info("22> lcp delete %s" % vpp_iface.interface_name)
removed_lcps.append(lcp.host_if_name)
continue
self.logger.debug("LCP OK: %s -> (vpp=%s, config=%s)" % (lcp.host_if_name, vpp_iface.interface_name, config_ifname)) self.logger.debug("LCP OK: %s -> (vpp=%s, config=%s)" % (lcp.host_if_name, vpp_iface.interface_name, config_ifname))
for lcpname in removed_lcps: for lcpname in removed_lcps: