def is_bridge_present(br, root_helper):
    ovs_bridges = ovs_lib.get_bridges(root_helper)
    if br in ovs_bridges:
        return True
    else:
        return False
    def setup_lldpad_ports(self):
        """Setup the flows for passing LLDP/VDP frames in OVS."""
        # Creating the physical bridge and setting up patch ports is done by
        # Openstack
        ovs_bridges = ovs_lib.get_bridges(self.root_helper)
        if self.ext_br not in ovs_bridges or self.integ_br not in ovs_bridges:
            LOG.error(_LE("Integ or Physical Bridge not configured by" "Openstack"))
            raise dfae.DfaAgentFailed(reason="Bridge Unavailable")
        br = ovs_lib.OVSBridge(self.ext_br, root_helper=self.root_helper)
        self.ext_br_obj = br
        int_br = ovs_lib.OVSBridge(self.integ_br, root_helper=self.root_helper)
        self.integ_br_obj = int_br

        self.phy_peer_port, self.int_peer_port = self.find_interconnect_ports()
        if self.phy_peer_port is None or self.int_peer_port is None:
            LOG.error(_LE("Integ or Physical Patch/Veth Ports not " "configured by Openstack"))
            raise dfae.DfaAgentFailed(reason="Ports Unconfigured")

        lldp_ovs_veth_str = constants.LLDPAD_OVS_VETH_PORT + self.uplink
        if len(lldp_ovs_veth_str) > constants.MAX_VETH_NAME:
            lldp_ovs_veth_str = self.gen_veth_str(constants.LLDPAD_OVS_VETH_PORT, self.uplink)
        lldp_loc_veth_str = constants.LLDPAD_LOC_VETH_PORT + self.uplink
        if len(lldp_loc_veth_str) > constants.MAX_VETH_NAME:
            lldp_loc_veth_str = self.gen_veth_str(constants.LLDPAD_LOC_VETH_PORT, self.uplink)
        ip_wrapper = ip_lib.IPWrapper()
        self.delete_vdp_flows()
        br.delete_port(lldp_ovs_veth_str)
        if ip_lib.device_exists(lldp_ovs_veth_str):
            # What about OVS restart cases fixme(padkrish)

            # IMPORTANT.. The link delete should be done only for non-restart
            # cases. Otherwise, The MAC address of the veth interface changes
            # for every delete/create. So, if lldpad has the association sent
            # already, retriggering it will make the ASSOC appear as coming
            # from another station and more than one VSI instance will appear
            # at the Leaf. Deleting the assoc and creating the assoc for new
            # veth is not optimal. fixme(padkrish)
            # ip_lib.IPDevice(lldp_ovs_veth_str,self.root_helper).link.delete()
            ovs_lib.execute(["/sbin/udevadm", "settle", "--timeout=10"])
            lldp_loc_veth = ip_wrapper.device(lldp_loc_veth_str)
            lldp_ovs_veth = ip_wrapper.device(lldp_ovs_veth_str)
        else:
            # fixme(padkrish) Due to above reason, do the vethcreate below only
            # if it doesn't exist and not deleted.
            lldp_loc_veth, lldp_ovs_veth = ip_wrapper.add_veth(lldp_loc_veth_str, lldp_ovs_veth_str)
        if not br.port_exists(self.uplink):
            phy_port_num = br.add_port(self.uplink)
        else:
            phy_port_num = br.get_port_ofport(self.uplink)
        if phy_port_num == cconstants.INVALID_OFPORT:
            LOG.error(_LE("Uplink port not detected on external bridge"))
            return False
        if not br.port_exists(lldp_ovs_veth_str):
            lldp_ovs_portnum = br.add_port(lldp_ovs_veth)
        else:
            lldp_ovs_portnum = br.get_port_ofport(lldp_ovs_veth)
        if lldp_ovs_portnum == cconstants.INVALID_OFPORT:
            LOG.error(_LE("lldp veth port not detected on external bridge"))
            return False
        lldp_loc_veth.link.set_up()
        lldp_ovs_veth.link.set_up()
        # What about OVS restart cases fixme(padkrish)
        self.program_vdp_flows(lldp_ovs_portnum, phy_port_num)

        self.phy_peer_port_num = br.get_port_ofport(self.phy_peer_port)
        self.int_peer_port_num = int_br.get_port_ofport(self.int_peer_port)
        if self.phy_peer_port_num == cconstants.INVALID_OFPORT or self.int_peer_port_num == cconstants.INVALID_OFPORT:
            LOG.error(
                _LE("int or phy peer OF Port not detected on Int or" "Phy Bridge %(phy)s %(int)s"),
                {"phy": self.phy_peer_port_num, "int": self.int_peer_port_num},
            )
            return False
        self.lldpad_info = lldpad.LldpadDriver(lldp_loc_veth_str, self.uplink, self.root_helper)
        ret = self.lldpad_info.enable_evb()
        if not ret:
            LOG.error(_LE("Unable to cfg EVB"))
            return False
        self.lldp_veth_port = lldp_loc_veth_str
        LOG.info(_LI("Setting up lldpad ports complete"))
        return True
    def setup_lldpad_ports(self):
        """Setup the flows for passing LLDP/VDP frames in OVS. """
        # Creating the physical bridge and setting up patch ports is done by
        # OpenStack
        ovs_bridges = ovs_lib.get_bridges(self.root_helper)
        if self.ext_br not in ovs_bridges or self.integ_br not in ovs_bridges:
            self.uplink_fail_reason = cconstants.bridge_not_cfgd_reason % (
                ovs_bridges, self.integ_br, self.ext_br)
            LOG.error("%s", self.uplink_fail_reason)
            raise dfae.DfaAgentFailed(reason=self.uplink_fail_reason)
        br = ovs_lib.OVSBridge(self.ext_br, root_helper=self.root_helper)
        self.ext_br_obj = br
        int_br = ovs_lib.OVSBridge(self.integ_br, root_helper=self.root_helper)
        self.integ_br_obj = int_br

        self.phy_peer_port, self.int_peer_port = self.find_interconnect_ports()
        if self.phy_peer_port is None or self.int_peer_port is None:
            self.uplink_fail_reason = cconstants.veth_not_cfgd_reason % (
                self.phy_peer_port, self.int_peer_port)
            LOG.error("%s", self.uplink_fail_reason)
            raise dfae.DfaAgentFailed(reason=self.uplink_fail_reason)
        lldp_ovs_veth_str = constants.LLDPAD_OVS_VETH_PORT + self.uplink
        if len(lldp_ovs_veth_str) > constants.MAX_VETH_NAME:
            lldp_ovs_veth_str = self.gen_veth_str(
                constants.LLDPAD_OVS_VETH_PORT,
                self.uplink)
        lldp_loc_veth_str = constants.LLDPAD_LOC_VETH_PORT + self.uplink
        if len(lldp_loc_veth_str) > constants.MAX_VETH_NAME:
            lldp_loc_veth_str = self.gen_veth_str(
                constants.LLDPAD_LOC_VETH_PORT,
                self.uplink)
        ip_wrapper = ip_lib.IPWrapper()
        self.delete_vdp_flows()
        br.delete_port(lldp_ovs_veth_str)
        if ip_lib.device_exists(lldp_ovs_veth_str):
            # What about OVS restart cases fixme(padkrish)

            # IMPORTANT.. The link delete should be done only for non-restart
            # cases. Otherwise, The MAC address of the veth interface changes
            # for every delete/create. So, if lldpad has the association sent
            # already, retriggering it will make the ASSOC appear as coming
            # from another station and more than one VSI instance will appear
            # at the Leaf. Deleting the assoc and creating the assoc for new
            # veth is not optimal. fixme(padkrish)
            # ip_lib.IPDevice(lldp_ovs_veth_str,self.root_helper).link.delete()
            lldp_loc_veth = ip_wrapper.device(lldp_loc_veth_str)
            lldp_ovs_veth = ip_wrapper.device(lldp_ovs_veth_str)
        else:
            # fixme(padkrish) Due to above reason, do the vethcreate below only
            # if it doesn't exist and not deleted.
            lldp_loc_veth, lldp_ovs_veth = (
                ip_wrapper.add_veth(lldp_loc_veth_str,
                                    lldp_ovs_veth_str))
        if not br.port_exists(self.uplink):
            phy_port_num = br.add_port(self.uplink)
        else:
            phy_port_num = br.get_port_ofport(self.uplink)
        if phy_port_num == cconstants.INVALID_OFPORT:
            self.uplink_fail_reason = cconstants.invalid_uplink_ofport_reason
            LOG.error("%s", self.uplink_fail_reason)
            return False
        if not br.port_exists(lldp_ovs_veth_str):
            lldp_ovs_portnum = br.add_port(lldp_ovs_veth)
        else:
            lldp_ovs_portnum = br.get_port_ofport(lldp_ovs_veth)
        if lldp_ovs_portnum == cconstants.INVALID_OFPORT:
            self.uplink_fail_reason = cconstants.lldp_ofport_not_detect_reason
            LOG.error("%s", self.uplink_fail_reason)
            return False
        lldp_loc_veth.link.set_up()
        lldp_ovs_veth.link.set_up()
        # What about OVS restart cases fixme(padkrish)
        self.program_vdp_flows(lldp_ovs_portnum, phy_port_num)

        self.phy_peer_port_num = br.get_port_ofport(self.phy_peer_port)
        self.int_peer_port_num = int_br.get_port_ofport(self.int_peer_port)
        if (self.phy_peer_port_num == cconstants.INVALID_OFPORT or
                self.int_peer_port_num == cconstants.INVALID_OFPORT):
            self.uplink_fail_reason = cconstants.invalid_peer_ofport_reason % (
                self.phy_peer_port_num, self.int_peer_port_num)
            LOG.error("%s", self.uplink_fail_reason)
            return False
        self.lldpad_info = (lldpad.LldpadDriver(lldp_loc_veth_str, self.uplink,
                                                self.root_helper))
        ret = self.lldpad_info.enable_evb()
        if not ret:
            self.uplink_fail_reason = cconstants.evb_cfg_fail_reason
            LOG.error("%s", self.uplink_fail_reason)
            return False
        self.lldp_local_veth_port = lldp_loc_veth_str
        self.lldp_ovs_veth_port = lldp_ovs_veth_str
        LOG.info("Setting up lldpad ports complete")
        return True
def is_bridge_present(br, root_helper):
    ovs_bridges = ovs_lib.get_bridges(root_helper)
    if br in ovs_bridges:
        return True
    else:
        return False
Exemple #5
0
    def setup_lldpad_ports(self):
        '''Setup the flows for passing LLDP/VDP frames in OVS.'''
        # Creating the physical bridge and setting up patch ports is done by
        # Openstack
        ovs_bridges = ovs_lib.get_bridges(self.root_helper)
        if self.ext_br not in ovs_bridges or self.integ_br not in ovs_bridges:
            LOG.error(
                _LE("Integ or Physical Bridge not configured by"
                    "Openstack"))
            raise dfae.DfaAgentFailed(reason="Bridge Unavailable")
        br = ovs_lib.OVSBridge(self.ext_br, root_helper=self.root_helper)
        self.ext_br_obj = br
        int_br = ovs_lib.OVSBridge(self.integ_br, root_helper=self.root_helper)
        self.integ_br_obj = int_br

        self.phy_peer_port, self.int_peer_port = self.find_interconnect_ports()
        if self.phy_peer_port is None or self.int_peer_port is None:
            LOG.error(
                _LE("Integ or Physical Patch/Veth Ports not "
                    "configured by Openstack"))
            raise dfae.DfaAgentFailed(reason="Ports Unconfigured")

        lldp_ovs_veth_str = constants.LLDPAD_OVS_VETH_PORT + self.uplink
        if len(lldp_ovs_veth_str) > constants.MAX_VETH_NAME:
            lldp_ovs_veth_str = self.gen_veth_str(
                constants.LLDPAD_OVS_VETH_PORT, self.uplink)
        lldp_loc_veth_str = constants.LLDPAD_LOC_VETH_PORT + self.uplink
        if len(lldp_loc_veth_str) > constants.MAX_VETH_NAME:
            lldp_loc_veth_str = self.gen_veth_str(
                constants.LLDPAD_LOC_VETH_PORT, self.uplink)
        ip_wrapper = ip_lib.IPWrapper()
        self.delete_vdp_flows()
        br.delete_port(lldp_ovs_veth_str)
        if ip_lib.device_exists(lldp_ovs_veth_str):
            # What about OVS restart cases fixme(padkrish)

            # IMPORTANT.. The link delete should be done only for non-restart
            # cases. Otherwise, The MAC address of the veth interface changes
            # for every delete/create. So, if lldpad has the association sent
            # already, retriggering it will make the ASSOC appear as coming
            # from another station and more than one VSI instance will appear
            # at the Leaf. Deleting the assoc and creating the assoc for new
            # veth is not optimal. fixme(padkrish)
            # ip_lib.IPDevice(lldp_ovs_veth_str,self.root_helper).link.delete()
            ovs_lib.execute(['/sbin/udevadm', 'settle', '--timeout=10'])
            lldp_loc_veth = ip_wrapper.device(lldp_loc_veth_str)
            lldp_ovs_veth = ip_wrapper.device(lldp_ovs_veth_str)
        else:
            # fixme(padkrish) Due to above reason, do the vethcreate below only
            # if it doesn't exist and not deleted.
            lldp_loc_veth, lldp_ovs_veth = (ip_wrapper.add_veth(
                lldp_loc_veth_str, lldp_ovs_veth_str))
        if not br.port_exists(self.uplink):
            phy_port_num = br.add_port(self.uplink)
        else:
            phy_port_num = br.get_port_ofport(self.uplink)
        if phy_port_num == cconstants.INVALID_OFPORT:
            LOG.error(_LE("Uplink port not detected on external bridge"))
            return False
        if not br.port_exists(lldp_ovs_veth_str):
            lldp_ovs_portnum = br.add_port(lldp_ovs_veth)
        else:
            lldp_ovs_portnum = br.get_port_ofport(lldp_ovs_veth)
        if lldp_ovs_portnum == cconstants.INVALID_OFPORT:
            LOG.error(_LE("lldp veth port not detected on external bridge"))
            return False
        lldp_loc_veth.link.set_up()
        lldp_ovs_veth.link.set_up()
        # What about OVS restart cases fixme(padkrish)
        self.program_vdp_flows(lldp_ovs_portnum, phy_port_num)

        self.phy_peer_port_num = br.get_port_ofport(self.phy_peer_port)
        self.int_peer_port_num = int_br.get_port_ofport(self.int_peer_port)
        if (self.phy_peer_port_num == cconstants.INVALID_OFPORT
                or self.int_peer_port_num == cconstants.INVALID_OFPORT):
            LOG.error(
                _LE("int or phy peer OF Port not detected on Int or"
                    "Phy Bridge %(phy)s %(int)s"), {
                        'phy': self.phy_peer_port_num,
                        'int': self.int_peer_port_num
                    })
            return False
        self.lldpad_info = (lldpad.LldpadDriver(lldp_loc_veth_str, self.uplink,
                                                self.root_helper))
        ret = self.lldpad_info.enable_evb()
        if not ret:
            LOG.error(_LE("Unable to cfg EVB"))
            return False
        self.lldp_veth_port = lldp_loc_veth_str
        LOG.info(_LI("Setting up lldpad ports complete"))
        return True