Add ability to delete sub-ints on BVI + Loopback
- Add a get_sub_interfaces() call to fetch all DPDK / Bond sub-ints - In prune_bvis(), prune_loopbacks() and prune_sub_interfaces(), use sub_number_of_tags to go out-to-in (qinx, dot1x, untagged)
This commit is contained in:
		@@ -93,13 +93,19 @@ class Reconciler():
 | 
			
		||||
 | 
			
		||||
    def prune_loopbacks(self):
 | 
			
		||||
        """ Remove loopbacks from VPP, if they do not occur in the config. """
 | 
			
		||||
        for numtags in [ 2, 1, 0 ]:
 | 
			
		||||
            for idx, vpp_iface in self.vpp.config['interfaces'].items():
 | 
			
		||||
                if vpp_iface.interface_dev_type!='Loopback':
 | 
			
		||||
                    continue
 | 
			
		||||
                if vpp_iface.sub_number_of_tags != numtags:
 | 
			
		||||
                    continue
 | 
			
		||||
                config_ifname, config_iface = loopback.get_by_name(self.cfg, vpp_iface.interface_name)
 | 
			
		||||
                if not config_iface:
 | 
			
		||||
                    self.prune_addresses(vpp_iface.interface_name, [])
 | 
			
		||||
                    if numtags == 0:
 | 
			
		||||
                        self.logger.info("1> delete loopback interface intfc %s" % vpp_iface.interface_name)
 | 
			
		||||
                    else:
 | 
			
		||||
                        self.logger.info("1> delete sub %s" % vpp_iface.interface_name)
 | 
			
		||||
                    continue
 | 
			
		||||
                self.logger.debug("Loopback OK: %s" % (vpp_iface.interface_name))
 | 
			
		||||
                addresses = []
 | 
			
		||||
@@ -110,13 +116,19 @@ class Reconciler():
 | 
			
		||||
 | 
			
		||||
    def prune_bvis(self):
 | 
			
		||||
        """ Remove BVIs (bridge-domain virtual interfaces) from VPP, if they do not occur in the config. """
 | 
			
		||||
        for numtags in [ 2, 1, 0 ]:
 | 
			
		||||
            for idx, vpp_iface in self.vpp.config['interfaces'].items():
 | 
			
		||||
                if vpp_iface.interface_dev_type!='BVI':
 | 
			
		||||
                    continue
 | 
			
		||||
                if vpp_iface.sub_number_of_tags != numtags:
 | 
			
		||||
                    continue
 | 
			
		||||
                config_ifname, config_iface = bridgedomain.get_by_bvi_name(self.cfg, vpp_iface.interface_name)
 | 
			
		||||
                if not config_iface:
 | 
			
		||||
                    self.prune_addresses(vpp_iface.interface_name, [])
 | 
			
		||||
                    if numtags == 0:
 | 
			
		||||
                        self.logger.info("1> bvi delete %s" % vpp_iface.interface_name)
 | 
			
		||||
                    else:
 | 
			
		||||
                        self.logger.info("1> delete sub %s" % vpp_iface.interface_name)
 | 
			
		||||
                    continue
 | 
			
		||||
                self.logger.debug("BVI OK: %s" % (vpp_iface.interface_name))
 | 
			
		||||
                addresses = []
 | 
			
		||||
@@ -224,8 +236,11 @@ class Reconciler():
 | 
			
		||||
    def prune_sub_interfaces(self):
 | 
			
		||||
        """ Remove interfaces from VPP if they are not in the config. Start with inner-most (QinQ/QinAD), then
 | 
			
		||||
            Dot1Q/Dot1AD."""
 | 
			
		||||
        for vpp_ifname in self.vpp.get_qinx_interfaces() + self.vpp.get_dot1x_interfaces():
 | 
			
		||||
        for numtags in [ 2, 1 ]:
 | 
			
		||||
            for vpp_ifname in self.vpp.get_sub_interfaces():
 | 
			
		||||
                vpp_iface = self.vpp.config['interface_names'][vpp_ifname]
 | 
			
		||||
                if vpp_iface.sub_number_of_tags != numtags:
 | 
			
		||||
                    continue
 | 
			
		||||
                config_ifname, config_iface = interface.get_by_name(self.cfg, vpp_ifname)
 | 
			
		||||
                if not config_iface:
 | 
			
		||||
                    self.prune_addresses(vpp_ifname, [])
 | 
			
		||||
 
 | 
			
		||||
@@ -143,6 +143,10 @@ class VPPApi():
 | 
			
		||||
        self.dump_phys()
 | 
			
		||||
        self.dump_subints()
 | 
			
		||||
 | 
			
		||||
    def get_sub_interfaces(self):
 | 
			
		||||
        subints = [self.config['interfaces'][x].interface_name for x in self.config['interfaces'] if self.config['interfaces'][x].interface_dev_type in ['dpdk','bond'] and self.config['interfaces'][x].sub_id>0 and self.config['interfaces'][x].sub_number_of_tags > 0]
 | 
			
		||||
        return subints
 | 
			
		||||
 | 
			
		||||
    def get_qinx_interfaces(self):
 | 
			
		||||
        qinx_subints = [self.config['interfaces'][x].interface_name for x in self.config['interfaces'] if self.config['interfaces'][x].interface_dev_type in ['dpdk','bond'] and self.config['interfaces'][x].sub_id>0 and self.config['interfaces'][x].sub_inner_vlan_id>0]
 | 
			
		||||
        return qinx_subints
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user