def __datapath_leave_db_actions(self, dpid):
        """ Actions related to datapath_leave event """
        nodes = []
        links = []
        hosts = []
        try:
            self.db_conn.open_transaction()

            d_idx  = self.db_conn.datapath_get_index(d_id=dpid)
            p_idxs = self.db_conn.port_get_indexes(d_id=dpid)
            for p_idx in p_idxs:
                nodes.append(nxw_utils.createNodeIPv4(d_idx, p_idx))

            try: # optional
                h_idxs = self.db_conn.host_get_indexes(d_id=dpid)
                for in_port, ip_addr in h_idxs:
                    port = self.db_conn.port_get_index(d_id=dpid,
                                                       port_no=in_port)
                    node = nxw_utils.createNodeIPv4(d_idx, port)

                    links.append((ip_addr, node))
                    hosts.append(ip_addr)

            except nxw_utils.DBException as err:
                LOG.error("host_get_indexes: " + str(err))

            try: # optional
                l_idxs = self.db_conn.link_get_indexes(src_dpid=dpid)
                for src_pno, dst_dpid, dst_pno in l_idxs:
                    src_port = self.db_conn.port_get_index(d_id=dpid,
                                                           port_no=src_pno)
                    src_node = nxw_utils.createNodeIPv4(d_idx, src_port)

                    dst_id = self.db_conn.datapath_get_index(d_id=dst_dpid)
                    dst_port = self.db_conn.port_get_index(d_id=dst_dpid,
                                                           port_no=dst_pno)
                    dst_node = nxw_utils.createNodeIPv4(dst_id, dst_port)

                    links.append((src_node, dst_node))

            except nxw_utils.DBException as err:
                LOG.error("link_get_indexes: " + str(err))

        except nxw_utils.DBException as err:
            LOG.error("dp_leave_db_actions: " + str(err))

        finally:
            self.db_conn.close()

        return (nodes, links, hosts)
    def node_get_frompidport(self, dpid, port):
        """ Get node from dpid and port """
        try:
            # connect and open transaction
            self.db_conn.open_transaction()

            didx = self.db_conn.datapath_get_index(dpid)
            pidx = self.db_conn.port_get_index(dpid, port)
            return nxw_utils.createNodeIPv4(didx, pidx)

        finally:
            self.db_conn.close()
예제 #3
0
    def __secure_interswitch_link_update(self, action, dpid_in, port_in,
                                         dpid_out, port_out, bw):
        try:
            avail_bw_ = self._db.link_get_bw(dpid_in, port_in,
                                             dpid_out, port_out)
            if action == 'increase':
                bw_ = ((avail_bw_ * 1000) + bw) / 1000
            elif action == 'decrease':
                bw_ = ((avail_bw_ * 1000) - bw) / 1000
            self._db.link_update_bw(dpid_in, port_in, dpid_out, port_out, bw_)

            didx_in_ = self._db.datapath_get_index(dpid_in)
            pidx_in_ = self._db.port_get_index(dpid_in, port_in)
            didx_out_ = self._db.datapath_get_index(dpid_out)
            pidx_out_ = self._db.port_get_index(dpid_out, port_out)

            src_node = nxw_utils.createNodeIPv4(didx_in_, pidx_in_)
            dst_node = nxw_utils.createNodeIPv4(didx_out_, pidx_out_)

            self._fpce.update_link_bw_from_strings(src_node, dst_node, bw_)

        except nxw_utils.DBException as err:
            BoDLOG.warning(str(err))
    def __host_leave(self, dladdr):
        """ Handler for host_leave event """
        LOG.debug("Received host_leave_ev for host with MAC %s" % str(dladdr))
        try:
            self.db_conn.open_transaction()
            try:
                mac_addresses = self.db_conn.port_get_macs()
                if dladdr in mac_addresses:
                    LOG.debug("Ignoring received leave_ev for OF switch...")
                    self.db_conn.close()
                    return False
            except Exception:
                LOG.debug("Received leave_ev for a MAC not present in DB")
                return False

            host  = self.db_conn.host_get_ipaddr(dladdr)
            nodes = [host]
            dpid  = self.db_conn.host_get_dpid(dladdr)
            port  = self.db_conn.host_get_inport(dladdr)
            didx  = self.db_conn.datapath_get_index(dpid)
            pidx  = self.db_conn.port_get_index(dpid, port)
            node  = nxw_utils.createNodeIPv4(didx, pidx)
            nodes.append(node)

            # update flow-pce topology (remove links)
            for node in nodes:
                others = [n for n in nodes if n != node]
                for oth in others:
                    self.fpce.del_link_from_strings(node, oth)

            self.fpce.del_node_from_string(host)

            # Delete hosts from DB
            host_idx = self.db_conn.host_get_index(dladdr)
            self.db_conn.host_delete(host_idx)
            self.db_conn.commit()
            LOG.debug("Successfully delete host '%s' from DB!" % str(dladdr))

        except nxw_utils.DBException as err:
            LOG.error(str(err))
            self.db_conn.rollback()
            return False
        except Exception, err:
            LOG.error(str(err))
            return False