diff --git a/validator/__init__.py b/validator/__init__.py index 7d9eab6..6b3cf90 100644 --- a/validator/__init__.py +++ b/validator/__init__.py @@ -142,3 +142,7 @@ class Validator(object): self.logger.info("Configuration validated successfully") return True + + def get_phys(self, yaml): + """ Return all PHYs in the config """ + return interface.get_phys(yaml) diff --git a/vpp/vppapi.py b/vpp/vppapi.py index 3a4d1e5..896b10d 100644 --- a/vpp/vppapi.py +++ b/vpp/vppapi.py @@ -60,7 +60,7 @@ class VPPApi(): return True def clearconfig(self): - return {"lcps": {}, "interfaces": {}, "interface_addresses": {}, + return {"lcps": {}, "interface_names": {}, "interfaces": {}, "interface_addresses": {}, "bondethernets": {}, "bondethernet_members": {}, "bridgedomains": {}, "vxlan_tunnels": {}, "l2xcs": {}} @@ -79,6 +79,7 @@ class VPPApi(): r = self.vpp.api.sw_interface_dump() for iface in r: self.config['interfaces'][iface.sw_if_index] = iface + self.config['interface_names'][iface.interface_name] = iface self.config['interface_addresses'][iface.sw_if_index] = [] self.logger.debug("Retrieving IPv4 addresses for %s" % iface.interface_name) ipr = self.vpp.api.ip_address_dump(sw_if_index=iface.sw_if_index, is_ipv6=False) @@ -126,6 +127,16 @@ class VPPApi(): encap += " exact-match" return encap + def phys_exist(self, ifname_list): + """ Return True if all interfaces in the `ifname_list` exist as physical interface names + in VPP. Return False otherwise.""" + ret = True + for ifname in ifname_list: + if not ifname in self.config['interface_names']: + self.logger.warning("Interface %s does not exist in VPP" % ifname) + ret = False + return ret + def dump(self): self.dump_interfaces() self.dump_bridgedomains() diff --git a/vppcfg b/vppcfg index b91beb3..622515e 100755 --- a/vppcfg +++ b/vppcfg @@ -57,9 +57,16 @@ def main(): logging.error("Configuration is not valid, bailing") sys.exit(-2) + config_phys = validator.get_phys(cfg) vpp = VPPApi() vpp.readconfig() + if not vpp.phys_exist(config_phys): + logging.error("Not all PHYs in the config exist in VPP") + vpp.disconnect() + sys.exit(-3) + vpp.dump() + vpp.disconnect() if __name__ == "__main__":