Search in sources :

Example 31 with FixedIps

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps in project netvirt by opendaylight.

the class NeutronvpnNatManager method addExternalRouter.

public void addExternalRouter(Router update) {
    Uuid routerId = update.getUuid();
    Uuid extNetId = update.getExternalGatewayInfo().getExternalNetworkId();
    Uuid gatewayPortId = update.getGatewayPortId();
    // Create and add Routers object for this Router to the ExtRouters list
    // Create a Routers object
    InstanceIdentifier<Routers> routersIdentifier = NeutronvpnUtils.buildExtRoutersIdentifier(routerId);
    try {
        Network input = neutronvpnUtils.getNeutronNetwork(extNetId);
        ProviderTypes providerNwType = NeutronvpnUtils.getProviderNetworkType(input);
        if (providerNwType == null) {
            LOG.error("Unable to get Network Provider Type for network {}", input.getUuid().getValue());
            return;
        }
        Optional<Routers> optionalRouters = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier);
        LOG.trace("Creating/Updating a new Routers node: {}", routerId.getValue());
        RoutersBuilder builder = null;
        if (optionalRouters.isPresent()) {
            builder = new RoutersBuilder(optionalRouters.get());
        } else {
            builder = new RoutersBuilder().setKey(new RoutersKey(routerId.getValue()));
        }
        builder.setRouterName(routerId.getValue());
        builder.setNetworkId(extNetId);
        builder.setEnableSnat(update.getExternalGatewayInfo().isEnableSnat());
        ArrayList<ExternalIps> externalIps = new ArrayList<>();
        for (ExternalFixedIps fixedIps : update.getExternalGatewayInfo().getExternalFixedIps()) {
            addExternalFixedIpToExternalIpsList(externalIps, fixedIps);
        }
        builder.setExternalIps(externalIps);
        if (gatewayPortId != null) {
            LOG.trace("Setting/Updating gateway Mac for router {}", routerId.getValue());
            Port port = neutronvpnUtils.getNeutronPort(gatewayPortId);
            if (port != null && port.getDeviceOwner().equals(NeutronConstants.DEVICE_OWNER_GATEWAY_INF)) {
                builder.setExtGwMacAddress(port.getMacAddress().getValue());
            }
        }
        List<Uuid> subList = neutronvpnUtils.getNeutronRouterSubnetIds(routerId);
        builder.setSubnetIds(subList);
        Routers routers = builder.build();
        // Add Routers object to the ExtRouters list
        LOG.trace("Creating extrouters {}", routers);
        SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier, builder.build());
        LOG.trace("Wrote successfully Routers to CONFIG Datastore");
    } catch (ReadFailedException | TransactionCommitFailedException ex) {
        LOG.error("Creation of extrouters failed for router {} failed", routerId.getValue(), ex);
    }
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes) Port(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port) ArrayList(java.util.ArrayList) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps) RoutersKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.RoutersKey) ExternalFixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router.external_gateway_info.ExternalFixedIps) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) RoutersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.RoutersBuilder) Network(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network)

Example 32 with FixedIps

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps in project netvirt by opendaylight.

the class NeutronvpnUtils method buildStaticMacEntry.

public static List<StaticMacEntries> buildStaticMacEntry(Port port) {
    PhysAddress physAddress = new PhysAddress(port.getMacAddress().getValue());
    List<FixedIps> fixedIps = port.getFixedIps();
    IpAddress ipAddress = null;
    if (isNotEmpty(fixedIps)) {
        ipAddress = port.getFixedIps().get(0).getIpAddress();
    }
    StaticMacEntriesBuilder staticMacEntriesBuilder = new StaticMacEntriesBuilder();
    List<StaticMacEntries> staticMacEntries = new ArrayList<>();
    if (ipAddress != null) {
        staticMacEntries.add(staticMacEntriesBuilder.setMacAddress(physAddress).setIpPrefix(ipAddress).build());
    } else {
        staticMacEntries.add(staticMacEntriesBuilder.setMacAddress(physAddress).build());
    }
    return staticMacEntries;
}
Also used : StaticMacEntriesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.elan._interface.StaticMacEntriesBuilder) ArrayList(java.util.ArrayList) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) FixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps) StaticMacEntries(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.elan._interface.StaticMacEntries) PhysAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress)

Example 33 with FixedIps

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps in project netvirt by opendaylight.

the class NeutronPortChangeListener method update.

@Override
protected void update(InstanceIdentifier<Port> identifier, Port original, Port update) {
    // in order to validate the supported vnic types from the hostconfig
    if (isPortTypeSwitchdev(original) && !isPortBound(original) && isPortBound(update)) {
        handleNeutronPortCreated(update);
    }
    final String portName = update.getUuid().getValue();
    Network network = neutronvpnUtils.getNeutronNetwork(update.getNetworkId());
    LOG.info("Update port {} from network {}", portName, update.getNetworkId().toString());
    if (network == null || !NeutronvpnUtils.isNetworkTypeSupported(network)) {
        LOG.error("neutron vpn received a port update() for a network without a provider extension augmentation " + "or with an unsupported network type for the port {} which is part of network {}", portName, network);
        return;
    }
    neutronvpnUtils.addToPortCache(update);
    if ((Strings.isNullOrEmpty(original.getDeviceOwner()) || Strings.isNullOrEmpty(original.getDeviceId()) || NeutronConstants.FLOATING_IP_DEVICE_ID_PENDING.equalsIgnoreCase(original.getDeviceId())) && !Strings.isNullOrEmpty(update.getDeviceOwner()) && !Strings.isNullOrEmpty(update.getDeviceId())) {
        if (update.getDeviceOwner().equals(NeutronConstants.DEVICE_OWNER_ROUTER_INF)) {
            handleRouterInterfaceAdded(update);
            return;
        }
        if (NeutronConstants.DEVICE_OWNER_GATEWAY_INF.equals(update.getDeviceOwner())) {
            handleRouterGatewayUpdated(update);
        } else if (NeutronConstants.DEVICE_OWNER_FLOATING_IP.equals(update.getDeviceOwner())) {
            handleFloatingIpPortUpdated(original, update);
        }
    } else {
        Set<FixedIps> oldIPs = getFixedIpSet(original.getFixedIps());
        Set<FixedIps> newIPs = getFixedIpSet(update.getFixedIps());
        if (!oldIPs.equals(newIPs)) {
            handleNeutronPortUpdated(original, update);
        }
    }
    // check if port security enabled/disabled as part of port update
    boolean origSecurityEnabled = NeutronvpnUtils.getPortSecurityEnabled(original);
    boolean updatedSecurityEnabled = NeutronvpnUtils.getPortSecurityEnabled(update);
    if (origSecurityEnabled || updatedSecurityEnabled) {
        InstanceIdentifier<Interface> interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(portName);
        jobCoordinator.enqueueJob("PORT- " + portName, () -> {
            WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
            try {
                Optional<Interface> optionalInf = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, interfaceIdentifier);
                if (optionalInf.isPresent()) {
                    InterfaceBuilder interfaceBuilder = new InterfaceBuilder(optionalInf.get());
                    InterfaceAcl infAcl = handlePortSecurityUpdated(original, update, origSecurityEnabled, updatedSecurityEnabled, interfaceBuilder).build();
                    interfaceBuilder.addAugmentation(InterfaceAcl.class, infAcl);
                    LOG.info("update: Of-port-interface updation for port {}", portName);
                    // Update OFPort interface for this neutron port
                    wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier, interfaceBuilder.build());
                } else {
                    LOG.warn("update: Interface {} is not present", portName);
                }
            } catch (ReadFailedException e) {
                LOG.error("update: Failed to update interface {}", portName, e);
            }
            List<ListenableFuture<Void>> futures = new ArrayList<>();
            futures.add(wrtConfigTxn.submit());
            return futures;
        });
    }
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) ArrayList(java.util.ArrayList) ElanInterfaceBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterfaceBuilder) InterfaceBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder) InterfaceAcl(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.InterfaceAcl) Network(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) FixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface) ElanInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterface)

Example 34 with FixedIps

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps in project netvirt by opendaylight.

the class NeutronPortChangeListener method handleNeutronPortDeleted.

private void handleNeutronPortDeleted(final Port port) {
    final String portName = port.getUuid().getValue();
    final Uuid portId = port.getUuid();
    final List<FixedIps> portIpsList = port.getFixedIps();
    jobCoordinator.enqueueJob("PORT- " + portName, () -> {
        WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
        List<ListenableFuture<Void>> futures = new ArrayList<>();
        if (!(NeutronUtils.isPortVnicTypeNormal(port) || isPortTypeSwitchdev(port))) {
            for (FixedIps ip : portIpsList) {
                // remove direct port from subnetMaps config DS
                nvpnManager.removePortsFromSubnetmapNode(ip.getSubnetId(), null, portId);
            }
            LOG.info("Port {} is not a normal and not a direct with switchdev VNIC type ;" + "Skipping OF Port interfaces removal", portName);
            return futures;
        }
        Uuid vpnId = null;
        Set<Uuid> routerIds = new HashSet<>();
        Uuid internetVpnId = null;
        for (FixedIps ip : portIpsList) {
            Subnetmap subnetMap = nvpnManager.removePortsFromSubnetmapNode(ip.getSubnetId(), portId, null);
            if (subnetMap == null) {
                continue;
            }
            if (subnetMap.getVpnId() != null) {
                // can't use NeutronvpnUtils.getVpnForNetwork to optimise here, because it gives BGPVPN id
                // obtained subnetMaps belongs to one network => vpnId must be the same for each port Ip
                vpnId = subnetMap.getVpnId();
            }
            if (subnetMap.getRouterId() != null) {
                routerIds.add(subnetMap.getRouterId());
            }
            internetVpnId = subnetMap.getInternetVpnId();
        }
        if (vpnId != null || internetVpnId != null) {
            // remove vpn-interface for this neutron port
            LOG.debug("removing VPN Interface for port {}", portName);
            if (!routerIds.isEmpty()) {
                for (Uuid routerId : routerIds) {
                    nvpnManager.removeFromNeutronRouterInterfacesMap(routerId, portName);
                }
            }
            nvpnManager.deleteVpnInterface(portName, null, /* vpn-id */
            wrtConfigTxn);
        }
        // Remove of-port interface for this neutron port
        // ELAN interface is also implicitly deleted as part of this operation
        LOG.debug("Of-port-interface removal for port {}", portName);
        deleteOfPortInterface(port, wrtConfigTxn);
        // dissociate fixedIP from floatingIP if associated
        nvpnManager.dissociatefixedIPFromFloatingIP(port.getUuid().getValue());
        futures.add(wrtConfigTxn.submit());
        return futures;
    });
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ArrayList(java.util.ArrayList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) FixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps) HashSet(java.util.HashSet)

Example 35 with FixedIps

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps in project netvirt by opendaylight.

the class NeutronPortChangeListener method handleNeutronPortUpdated.

private void handleNeutronPortUpdated(final Port portoriginal, final Port portupdate) {
    final List<FixedIps> portoriginalIps = portoriginal.getFixedIps();
    final List<FixedIps> portupdateIps = portupdate.getFixedIps();
    if (portoriginalIps == null || portoriginalIps.isEmpty()) {
        handleNeutronPortCreated(portupdate);
        return;
    }
    if (portupdateIps == null || portupdateIps.isEmpty()) {
        LOG.info("Ignoring portUpdate (fixed_ip removal) for port {} as this case is handled " + "during subnet deletion event.", portupdate.getUuid().getValue());
        return;
    }
    jobCoordinator.enqueueJob("PORT- " + portupdate.getUuid().getValue(), () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
        final List<Uuid> originalSnMapsIds = portoriginalIps.stream().map(FixedIps::getSubnetId).collect(Collectors.toList());
        final List<Uuid> updateSnMapsIds = portupdateIps.stream().map(FixedIps::getSubnetId).collect(Collectors.toList());
        Set<Uuid> originalRouterIds = new HashSet<>();
        Set<Uuid> oldVpnIds = new HashSet<Uuid>();
        Uuid oldRouterId = null;
        for (Uuid snId : originalSnMapsIds) {
            if (!updateSnMapsIds.remove(snId)) {
                // snId was present in originalSnMapsIds, but not in updateSnMapsIds
                Subnetmap subnetMapOld = nvpnManager.removePortsFromSubnetmapNode(snId, portoriginal.getUuid(), null);
                if (subnetMapOld != null && subnetMapOld.getVpnId() != null) {
                    oldVpnIds.add(subnetMapOld.getVpnId());
                }
                if (subnetMapOld != null && subnetMapOld.getInternetVpnId() != null) {
                    oldVpnIds.add(subnetMapOld.getInternetVpnId());
                }
                if (subnetMapOld != null && subnetMapOld.getRouterId() != null) {
                    originalRouterIds.add(subnetMapOld.getRouterId());
                }
            }
        }
        Set<Uuid> newVpnIds = new HashSet();
        Set<Uuid> newRouterIds = new HashSet<>();
        for (Uuid snId : updateSnMapsIds) {
            Subnetmap subnetMapNew = nvpnManager.updateSubnetmapNodeWithPorts(snId, portupdate.getUuid(), null);
            if (subnetMapNew != null) {
                if (subnetMapNew.getVpnId() != null) {
                    newVpnIds.add(subnetMapNew.getVpnId());
                }
                if (subnetMapNew.getInternetVpnId() != null) {
                    newVpnIds.add(subnetMapNew.getInternetVpnId());
                }
                if (subnetMapNew.getRouterId() != null) {
                    newRouterIds.add(subnetMapNew.getRouterId());
                }
            }
        }
        WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
        if (!oldVpnIds.isEmpty()) {
            LOG.info("removing VPN Interface for port {}", portoriginal.getUuid().getValue());
            if (!originalRouterIds.isEmpty()) {
                for (Uuid routerId : originalRouterIds) {
                    nvpnManager.removeFromNeutronRouterInterfacesMap(routerId, portoriginal.getUuid().getValue());
                }
            }
            nvpnManager.deleteVpnInterface(portoriginal.getUuid().getValue(), null, /* vpn-id */
            wrtConfigTxn);
        }
        if (!newVpnIds.isEmpty()) {
            LOG.info("Adding VPN Interface for port {}", portupdate.getUuid().getValue());
            nvpnManager.createVpnInterface(newVpnIds, portupdate, wrtConfigTxn);
            if (!newRouterIds.isEmpty()) {
                for (Uuid routerId : newRouterIds) {
                    nvpnManager.addToNeutronRouterInterfacesMap(routerId, portupdate.getUuid().getValue());
                }
            }
        }
    })));
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) FixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps) HashSet(java.util.HashSet)

Aggregations

FixedIps (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps)27 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)20 ArrayList (java.util.ArrayList)17 Port (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port)11 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)7 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)6 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)6 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)6 HashSet (java.util.HashSet)5 LearntVpnVipToPort (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort)5 BigInteger (java.math.BigInteger)4 Test (org.junit.Test)4 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)4 Eid (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid)4 ExecutionException (java.util.concurrent.ExecutionException)3 IpVersionChoice (org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)3 PortBindingExtension (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.binding.rev150712.PortBindingExtension)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 Collections (java.util.Collections)2 List (java.util.List)2