Пример #1
0
def _create_vpp_vif(dev, iface_id, mac, mtu,
                    instance_id, interface_type=None,
                    vhost_server_path=None):
    vapi = VPPApi(LOG, 'nova_os_vif')
    # iface_id is the port UUID as seen in neutron. Use this as the tag
    # on the interface which will be later used as the key for endpoint lookup
    mac_address = vpp_api.mac_to_bytes(mac)
    if interface_type == constants.VPP_VHOSTUSER_CLIENT_INTERFACE_TYPE:
        sw_if_index = vapi.create_vhost_user_if(
                        str(vhost_server_path).encode('utf-8'),
                        0, mac_address, iface_id)
    else:
        sw_if_index = vapi.create_vhost_user_if(
                        str(vhost_server_path).encode('utf-8'),
                        1, mac_address, iface_id)
    LOG.debug("sw_if_index:{}".format(sw_if_index))
    if mtu:
        vapi.set_interface_mtu(sw_if_index, mtu)
    # Default admin state  for port in VPP is down, so do admin-up here
    vapi.set_interface_state(sw_if_index, 1)
    return sw_if_index
Пример #2
0
    def plug_new(self,
                 network_id,
                 port_id,
                 device_name,
                 mac_address,
                 bridge=None,
                 namespace=None,
                 prefix=None,
                 mtu=None):
        """Plugin the interface."""
        ip = ip_lib.IPWrapper()

        # Enable agent to define the prefix
        tap_name = device_name.replace(prefix or self.DEV_NAME_PREFIX,
                                       lib_constants.VETH_DEVICE_PREFIX)
        # Create ns_veth in a namespace if one is configured.
        root_veth, ns_veth = ip.add_veth(tap_name,
                                         device_name,
                                         namespace2=namespace)
        root_veth.disable_ipv6()
        ns_veth.link.set_address(mac_address)
        if mtu:
            self.set_mtu(device_name, mtu, namespace=namespace, prefix=prefix)
        else:
            LOG.warning("No MTU configured for port %s", port_id)
        root_veth.link.set_up()
        # VPP section
        mac_address = vpp_api.mac_to_bytes(mac_address)

        vapi = VPPApi(LOG, 'vpp_dhcp')
        sw_if_index = vapi.create_host_interface(
            str(tap_name).encode('utf-8'), mac_address,
            str(port_id).encode('utf-8'))
        if mtu:
            vapi.set_interface_mtu(sw_if_index, mtu)
        vapi.set_interface_state(sw_if_index, '1')