예제 #1
0
    def __init__(self, integ_br, db, root_helper):
        self.root_helper = root_helper
        (ofp_controller_addr, ofp_rest_api_addr) = check_ofp_mode(db)

        self.nw_id_external = rest_nw_id.NW_ID_EXTERNAL
        self.api = OFPClient(ofp_rest_api_addr)
        self._setup_integration_br(integ_br, ofp_controller_addr)
예제 #2
0
파일: vif.py 프로젝트: hongbin/quantum
class LibvirtOpenVswitchOFPRyuDriver(libvirt_vif.LibvirtOpenVswitchDriver):
    def __init__(self, **kwargs):
        super(LibvirtOpenVswitchOFPRyuDriver, self).__init__()
        LOG.debug('ryu rest host %s', FLAGS.libvirt_ovs_bridge)
        self.ryu_client = OFPClient(FLAGS.libvirt_ovs_ryu_api_host)
        self.datapath_id = _get_datapath_id(FLAGS.libvirt_ovs_bridge)

    def _get_port_no(self, mapping):
        iface_id = mapping['vif_uuid']
        dev = self.get_dev_name(iface_id)
        return _get_port_no(dev)

    def plug(self, instance, network, mapping):
        result = super(LibvirtOpenVswitchOFPRyuDriver,
                       self).plug(instance, network, mapping)
        port_no = self._get_port_no(mapping)
        self.ryu_client.create_port(network['id'], self.datapath_id, port_no)
        return result

    def unplug(self, instance, network, mapping):
        port_no = self._get_port_no(mapping)
        try:
            self.ryu_client.delete_port(network['id'], self.datapath_id,
                                        port_no)
        except httplib.HTTPException as e:
            res = e.args[0]
            if res.status != httplib.NOT_FOUND:
                raise
        super(LibvirtOpenVswitchOFPRyuDriver,
              self).unplug(instance, network, mapping)
예제 #3
0
class RyuInterfaceDriver(OVSInterfaceDriver):
    """Driver for creating a Ryu OVS interface."""

    def __init__(self, conf):
        super(RyuInterfaceDriver, self).__init__(conf)

        from ryu.app.client import OFPClient
        LOG.debug('ryu rest host %s', self.conf.ryu_api_host)
        self.ryu_client = OFPClient(self.conf.ryu_api_host)

    def plug(self, network_id, port_id, device_name, mac_address,
             bridge=None, namespace=None, prefix=None):
        """Plug in the interface."""
        super(RyuInterfaceDriver, self).plug(network_id, port_id, device_name,
                                             mac_address, bridge=bridge,
                                             namespace=namespace,
                                             prefix=prefix)
        if not bridge:
            bridge = self.conf.ovs_integration_bridge

        self.check_bridge_exists(bridge)
        ovs_br = ovs_lib.OVSBridge(bridge, self.conf.root_helper)
        datapath_id = ovs_br.get_datapath_id()
        port_no = ovs_br.get_port_ofport(device_name)
        self.ryu_client.create_port(network_id, datapath_id, port_no)
예제 #4
0
class RyuInterfaceDriver(OVSInterfaceDriver):
    """Driver for creating a Ryu OVS interface."""

    def __init__(self, conf):
        super(RyuInterfaceDriver, self).__init__(conf)

        from ryu.app.client import OFPClient
        LOG.debug('ryu rest host %s', self.conf.ryu_api_host)
        self.ryu_client = OFPClient(self.conf.ryu_api_host)

    def plug(self, network_id, port_id, device_name, mac_address,
             bridge=None, namespace=None, prefix=None):
        """Plug in the interface."""
        super(RyuInterfaceDriver, self).plug(network_id, port_id, device_name,
                                             mac_address, bridge=bridge,
                                             namespace=namespace,
                                             prefix=prefix)
        if not bridge:
            bridge = self.conf.ovs_integration_bridge

        self.check_bridge_exists(bridge)
        ovs_br = ovs_lib.OVSBridge(bridge, self.conf.root_helper)
        datapath_id = ovs_br.get_datapath_id()
        port_no = ovs_br.get_port_ofport(device_name)
        self.ryu_client.create_port(network_id, datapath_id, port_no)
예제 #5
0
class LibvirtOpenVswitchOFPRyuDriver(libvirt_vif.LibvirtOpenVswitchDriver):
    def __init__(self, **kwargs):
        super(LibvirtOpenVswitchOFPRyuDriver, self).__init__()
        LOG.debug('ryu rest host %s', FLAGS.libvirt_ovs_bridge)
        self.ryu_client = OFPClient(FLAGS.libvirt_ovs_ryu_api_host)
        self.datapath_id = ovs_utils.get_datapath_id(FLAGS.libvirt_ovs_bridge)

    def _get_port_no(self, mapping):
        iface_id = mapping['vif_uuid']
        dev = self.get_dev_name(iface_id)
        return ovs_utils.get_port_no(dev)

    def plug(self, instance, network, mapping):
        result = super(LibvirtOpenVswitchOFPRyuDriver, self).plug(
            instance, network, mapping)
        port_no = self._get_port_no(mapping)
        self.ryu_client.create_port(network['id'],
                                    self.datapath_id, port_no)
        return result

    def unplug(self, instance, network, mapping):
        port_no = self._get_port_no(mapping)
        try:
            self.ryu_client.delete_port(network['id'],
                                        self.datapath_id, port_no)
        except httplib.HTTPException as e:
            res = e.args[0]
            if res.status != httplib.NOT_FOUND:
                raise
        super(LibvirtOpenVswitchOFPRyuDriver, self).unplug(instance, network,
                                                           mapping)
예제 #6
0
class LinuxOVSRyuInterfaceDriver(linux_net.LinuxOVSInterfaceDriver):
    def __init__(self):
        super(LinuxOVSRyuInterfaceDriver, self).__init__()

        LOG.debug('ryu rest host %s', FLAGS.linuxnet_ovs_ryu_api_host)
        self.ryu_client = OFPClient(FLAGS.linuxnet_ovs_ryu_api_host)
        self.datapath_id = _get_datapath_id(
            FLAGS.linuxnet_ovs_integration_bridge)

        if linux_net.binary_name == 'nova-network':
            for tables in [linux_net.iptables_manager.ipv4,
                           linux_net.iptables_manager.ipv6]:
                tables['filter'].add_rule(
                    'FORWARD',
                    '--in-interface gw-+ --out-interface gw-+ -j DROP')
            linux_net.iptables_manager.apply()

    def plug(self, network, mac_address, gateway=True):
        LOG.debug("network %s mac_adress %s gateway %s",
                  network, mac_address, gateway)
        ret = super(LinuxOVSRyuInterfaceDriver, self).plug(
            network, mac_address, gateway)

        port_no = _get_port_no(self.get_dev(network))
        self.ryu_client.create_port(network['uuid'], self.datapath_id, port_no)
        return ret
예제 #7
0
class LinuxOVSRyuInterfaceDriver(linux_net.LinuxOVSInterfaceDriver):
    def __init__(self):
        super(LinuxOVSRyuInterfaceDriver, self).__init__()

        LOG.debug('ryu rest host %s', FLAGS.linuxnet_ovs_ryu_api_host)
        self.ryu_client = OFPClient(FLAGS.linuxnet_ovs_ryu_api_host)
        self.datapath_id = _get_datapath_id(
            FLAGS.linuxnet_ovs_integration_bridge)

        if linux_net.binary_name == 'nova-network':
            for tables in [linux_net.iptables_manager.ipv4,
                           linux_net.iptables_manager.ipv6]:
                tables['filter'].add_rule(
                    'FORWARD',
                    '--in-interface gw-+ --out-interface gw-+ -j DROP')
            linux_net.iptables_manager.apply()

    def plug(self, network, mac_address, gateway=True):
        LOG.debug("network %s mac_adress %s gateway %s",
                  network, mac_address, gateway)
        ret = super(LinuxOVSRyuInterfaceDriver, self).plug(
            network, mac_address, gateway)

        port_no = _get_port_no(self.get_dev(network))
        self.ryu_client.create_port(network['uuid'], self.datapath_id, port_no)
        return ret
예제 #8
0
    def __init__(self):
        super(LinuxOVSRyuInterfaceDriver, self).__init__()

        LOG.debug('ryu rest host %s', FLAGS.linuxnet_ovs_ryu_api_host)
        self.ryu_client = OFPClient(FLAGS.linuxnet_ovs_ryu_api_host)
        self.datapath_id = _get_datapath_id(
            FLAGS.linuxnet_ovs_integration_bridge)

        if linux_net.binary_name == 'nova-network':
            for tables in [linux_net.iptables_manager.ipv4,
                           linux_net.iptables_manager.ipv6]:
                tables['filter'].add_rule(
                    'FORWARD',
                    '--in-interface gw-+ --out-interface gw-+ -j DROP')
            linux_net.iptables_manager.apply()
예제 #9
0
    def __init__(self, integ_br, db, root_helper):
        self.root_helper = root_helper
        (ofp_controller_addr, ofp_rest_api_addr) = check_ofp_mode(db)

        self.nw_id_external = rest_nw_id.NW_ID_EXTERNAL
        self.api = OFPClient(ofp_rest_api_addr)
        self._setup_integration_br(integ_br, ofp_controller_addr)
예제 #10
0
    def __init__(self, conf):
        super(RyuInterfaceDriver, self).__init__(conf)

        from ryu.app.client import OFPClient

        LOG.debug("ryu rest host %s", self.conf.ryu_api_host)
        self.ryu_client = OFPClient(self.conf.ryu_api_host)
예제 #11
0
    def __init__(self, config, integ_br, db):
        ret = check_ofp_mode(db)
        assert ret

        (ofp_controller_addr, ofp_rest_api_addr) = ret

        self.nw_id_external = rest_nw_id.NW_ID_EXTERNAL
        self.api = OFPClient(ofp_rest_api_addr)
        self._setup_integration_br(integ_br, ofp_controller_addr)
예제 #12
0
    def __init__(self, conf):
        super(RyuInterfaceDriver, self).__init__(conf)

        from ryu.app.client import OFPClient
        LOG.debug('ryu rest host %s', self.conf.ryu_api_host)
        self.ryu_client = OFPClient(self.conf.ryu_api_host)

        self.check_bridge_exists(self.conf.ovs_integration_bridge)
        self.ovs_br = ovs_lib.OVSBridge(self.conf.ovs_integration_bridge,
                                        self.conf.root_helper)
        self.datapath_id = self.ovs_br.get_datapath_id()
예제 #13
0
class LinuxOVSRyuInterfaceDriver(object):
    nova_linux_net = None

    def __init__(self):
        if self.nova_linux_net is None:
            self.nova_linux_net = utils.import_object('nova.network.linux_net')

        cls = utils.import_class(
            'nova.network.linux_net.LinuxOVSInterfaceDriver')
        self.parent = cls()

        LOG.debug('ryu rest host %s', FLAGS.linuxnet_ovs_ryu_api_host)
        self.ryu_client = OFPClient(FLAGS.linuxnet_ovs_ryu_api_host)
        self.datapath_id = ovs_utils.get_datapath_id(
            FLAGS.linuxnet_ovs_integration_bridge)

        if self.nova_linux_net.binary_name == 'nova-network':
            for tables in [
                    self.nova_linux_net.iptables_manager.ipv4,
                    self.nova_linux_net.iptables_manager.ipv6
            ]:
                tables['filter'].add_rule(
                    'FORWARD',
                    '--in-interface gw-+ --out-interface gw-+ -j DROP')
            self.nova_linux_net.iptables_manager.apply()

    def plug(self, network, mac_address, gateway=True):
        LOG.debug("network %s mac_adress %s gateway %s", network, mac_address,
                  gateway)
        ret = self.parent.plug(network, mac_address, gateway)
        port_no = ovs_utils.get_port_no(self.get_dev(network))
        self.ryu_client.create_port(network['uuid'], self.datapath_id, port_no)
        return ret

    def unplug(self, network):
        return self.parent.unplug(network)

    def get_dev(self, network):
        return self.parent.get_dev(network)
    def __init__(self):
        super(LinuxOVSRyuInterfaceDriver, self).__init__()

        LOG.debug('ryu rest host %s', FLAGS.linuxnet_ovs_ryu_api_host)
        self.ryu_client = OFPClient(FLAGS.linuxnet_ovs_ryu_api_host)
        self.datapath_id = _get_datapath_id(
            FLAGS.linuxnet_ovs_integration_bridge)

        if linux_net.binary_name == 'nova-network':
            for tables in [linux_net.iptables_manager.ipv4,
                           linux_net.iptables_manager.ipv6]:
                tables['filter'].add_rule('FORWARD',
                        '--in-interface gw-+ --out-interface gw-+ -j DROP')
            linux_net.iptables_manager.apply()
예제 #15
0
class LibvirtOpenVswitchOFPRyuDriver(libvirt_vif.LibvirtHybridOVSBridgeDriver):
    def __init__(self, **kwargs):
        super(LibvirtOpenVswitchOFPRyuDriver, self).__init__()
        LOG.debug('ryu rest host %s', FLAGS.libvirt_ovs_bridge)
        self.ryu_client = OFPClient(FLAGS.libvirt_ovs_ryu_api_host)
        self.datapath_id = _get_datapath_id(FLAGS.libvirt_ovs_bridge)

    def _get_port_no(self, mapping):
        iface_id = mapping['vif_uuid']
        _v1_name, v2_name = self.get_veth_pair_names(iface_id)
        return _get_port_no(v2_name)

    def plug(self, instance, vif):
        result = super(LibvirtOpenVswitchOFPRyuDriver, self).plug(
            instance, vif)
        network, mapping = vif
        port_no = self._get_port_no(mapping)
        try:
            self.ryu_client.create_port(network['id'], self.datapath_id,
                                        port_no)
        except httplib.HTTPException as e:
            res = e.args[0]
            if res.status != httplib.CONFLICT:
                raise
        return result

    def unplug(self, instance, vif):
        network, mapping = vif
        port_no = self._get_port_no(mapping)
        try:
            self.ryu_client.delete_port(network['id'],
                                        self.datapath_id, port_no)
        except httplib.HTTPException as e:
            res = e.args[0]
            if res.status != httplib.NOT_FOUND:
                raise
        super(LibvirtOpenVswitchOFPRyuDriver, self).unplug(instance, vif)
예제 #16
0
    def __init__(self):
        if self.nova_linux_net is None:
            self.nova_linux_net = utils.import_object('nova.network.linux_net')

        cls = utils.import_class(
            'nova.network.linux_net.LinuxOVSInterfaceDriver')
        self.parent = cls()

        LOG.debug('ryu rest host %s', FLAGS.linuxnet_ovs_ryu_api_host)
        self.ryu_client = OFPClient(FLAGS.linuxnet_ovs_ryu_api_host)
        self.datapath_id = ovs_utils.get_datapath_id(
            FLAGS.linuxnet_ovs_integration_bridge)

        if self.nova_linux_net.binary_name == 'nova-network':
            for tables in [self.nova_linux_net.iptables_manager.ipv4,
                           self.nova_linux_net.iptables_manager.ipv6]:
                tables['filter'].add_rule('FORWARD',
                        '--in-interface gw-+ --out-interface gw-+ -j DROP')
            self.nova_linux_net.iptables_manager.apply()
예제 #17
0
 def __init__(self, **kwargs):
     super(LibvirtOpenVswitchOFPRyuDriver, self).__init__()
     LOG.debug('ryu rest host %s', FLAGS.libvirt_ovs_bridge)
     self.ryu_client = OFPClient(FLAGS.libvirt_ovs_ryu_api_host)
     self.datapath_id = ovs_utils.get_datapath_id(FLAGS.libvirt_ovs_bridge)
예제 #18
0
    def __init__(self, conf):
        super(RyuInterfaceDriver, self).__init__(conf)

        from ryu.app.client import OFPClient
        LOG.debug('ryu rest host %s', self.conf.ryu_api_host)
        self.ryu_client = OFPClient(self.conf.ryu_api_host)
예제 #19
0
파일: vif.py 프로젝트: hongbin/quantum
 def __init__(self, **kwargs):
     super(LibvirtOpenVswitchOFPRyuDriver, self).__init__()
     LOG.debug('ryu rest host %s', FLAGS.libvirt_ovs_bridge)
     self.ryu_client = OFPClient(FLAGS.libvirt_ovs_ryu_api_host)
     self.datapath_id = _get_datapath_id(FLAGS.libvirt_ovs_bridge)
예제 #20
0
class OVSQuantumOFPRyuAgent:
    def __init__(self, integ_br, db, root_helper):
        self.root_helper = root_helper
        (ofp_controller_addr, ofp_rest_api_addr) = check_ofp_mode(db)

        self.nw_id_external = rest_nw_id.NW_ID_EXTERNAL
        self.api = OFPClient(ofp_rest_api_addr)
        self._setup_integration_br(integ_br, ofp_controller_addr)

    def _setup_integration_br(self, integ_br, ofp_controller_addr):
        self.int_br = OVSBridge(integ_br, self.root_helper)
        self.int_br.find_datapath_id()
        self.int_br.set_controller(ofp_controller_addr)
        for port in self.int_br.get_external_ports():
            self._port_update(self.nw_id_external, port)

    def _port_update(self, network_id, port):
        self.api.update_port(network_id, port.switch.datapath_id, port.ofport)

    def _all_bindings(self, db):
        """return interface id -> port which include network id bindings"""
        return dict((port.id, port) for port in db.ports.all())

    def _set_port_status(self, port, status):
        port.status = status

    def daemon_loop(self, db):
        # on startup, register all existing ports
        all_bindings = self._all_bindings(db)

        local_bindings = {}
        vif_ports = {}
        for port in self.int_br.get_vif_ports():
            vif_ports[port.vif_id] = port
            if port.vif_id in all_bindings:
                net_id = all_bindings[port.vif_id].network_id
                local_bindings[port.vif_id] = net_id
                self._port_update(net_id, port)
                self._set_port_status(all_bindings[port.vif_id],
                                      constants.PORT_STATUS_ACTIVE)
                LOG.info("Updating binding to net-id = %s for %s", net_id,
                         str(port))
        db.commit()

        old_vif_ports = vif_ports
        old_local_bindings = local_bindings

        while True:
            all_bindings = self._all_bindings(db)

            new_vif_ports = {}
            new_local_bindings = {}
            for port in self.int_br.get_vif_ports():
                new_vif_ports[port.vif_id] = port
                if port.vif_id in all_bindings:
                    net_id = all_bindings[port.vif_id].network_id
                    new_local_bindings[port.vif_id] = net_id

                old_b = old_local_bindings.get(port.vif_id)
                new_b = new_local_bindings.get(port.vif_id)
                if old_b == new_b:
                    continue

                if old_b:
                    LOG.info("Removing binding to net-id = %s for %s", old_b,
                             str(port))
                    if port.vif_id in all_bindings:
                        self._set_port_status(all_bindings[port.vif_id],
                                              constants.PORT_STATUS_DOWN)
                if new_b:
                    if port.vif_id in all_bindings:
                        self._set_port_status(all_bindings[port.vif_id],
                                              constants.PORT_STATUS_ACTIVE)
                    LOG.info("Adding binding to net-id = %s for %s", new_b,
                             str(port))

            for vif_id in old_vif_ports:
                if vif_id not in new_vif_ports:
                    LOG.info("Port Disappeared: %s", vif_id)
                    if vif_id in all_bindings:
                        self._set_port_status(all_bindings[port.vif_id],
                                              constants.PORT_STATUS_DOWN)

            old_vif_ports = new_vif_ports
            old_local_bindings = new_local_bindings
            db.commit()
            time.sleep(2)
예제 #21
0
class OVSQuantumOFPRyuAgent:
    def __init__(self, integ_br, db, root_helper):
        self.root_helper = root_helper
        (ofp_controller_addr, ofp_rest_api_addr) = check_ofp_mode(db)

        self.nw_id_external = rest_nw_id.NW_ID_EXTERNAL
        self.api = OFPClient(ofp_rest_api_addr)
        self._setup_integration_br(integ_br, ofp_controller_addr)

    def _setup_integration_br(self, integ_br, ofp_controller_addr):
        self.int_br = OVSBridge(integ_br, self.root_helper)
        self.int_br.find_datapath_id()
        self.int_br.set_controller(ofp_controller_addr)
        for port in self.int_br.get_external_ports():
            self._port_update(self.nw_id_external, port)

    def _port_update(self, network_id, port):
        self.api.update_port(network_id, port.switch.datapath_id, port.ofport)

    def _all_bindings(self, db):
        """return interface id -> port which include network id bindings"""
        return dict((port.interface_id, port) for port in db.ports.all())

    def daemon_loop(self, db):
        # on startup, register all existing ports
        all_bindings = self._all_bindings(db)

        local_bindings = {}
        vif_ports = {}
        for port in self.int_br.get_vif_ports():
            vif_ports[port.vif_id] = port
            if port.vif_id in all_bindings:
                net_id = all_bindings[port.vif_id].network_id
                local_bindings[port.vif_id] = net_id
                self._port_update(net_id, port)
                all_bindings[port.vif_id].op_status = OP_STATUS_UP
                LOG.info("Updating binding to net-id = %s for %s",
                         net_id, str(port))
        db.commit()

        old_vif_ports = vif_ports
        old_local_bindings = local_bindings

        while True:
            all_bindings = self._all_bindings(db)

            new_vif_ports = {}
            new_local_bindings = {}
            for port in self.int_br.get_vif_ports():
                new_vif_ports[port.vif_id] = port
                if port.vif_id in all_bindings:
                    net_id = all_bindings[port.vif_id].network_id
                    new_local_bindings[port.vif_id] = net_id

                old_b = old_local_bindings.get(port.vif_id)
                new_b = new_local_bindings.get(port.vif_id)
                if old_b == new_b:
                    continue

                if not old_b:
                    LOG.info("Removing binding to net-id = %s for %s",
                             old_b, str(port))
                    if port.vif_id in all_bindings:
                        all_bindings[port.vif_id].op_status = OP_STATUS_DOWN
                if not new_b:
                    if port.vif_id in all_bindings:
                        all_bindings[port.vif_id].op_status = OP_STATUS_UP
                    LOG.info("Adding binding to net-id = %s for %s",
                             new_b, str(port))

            for vif_id in old_vif_ports:
                if vif_id not in new_vif_ports:
                    LOG.info("Port Disappeared: %s", vif_id)
                    if vif_id in all_bindings:
                        all_bindings[vif_id].op_status = OP_STATUS_DOWN

            old_vif_ports = new_vif_ports
            old_local_bindings = new_local_bindings
            db.commit()
            time.sleep(2)