Search in sources :

Example 66 with VpnInstance

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance in project netvirt by opendaylight.

the class NeutronvpnManager method updateVpnInterfaceWithAdjacencies.

private void updateVpnInterfaceWithAdjacencies(Uuid vpnId, String infName, Adjacencies adjacencies, WriteTransaction wrtConfigTxn) {
    if (vpnId == null || infName == null) {
        LOG.error("vpn id or interface is null");
        return;
    }
    if (wrtConfigTxn == null) {
        wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
    }
    InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
    boolean isLockAcquired = false;
    try {
        isLockAcquired = interfaceLock.tryLock(infName, LOCK_WAIT_TIME, TimeUnit.SECONDS);
        Optional<VpnInterface> optionalVpnInterface = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
        if (optionalVpnInterface.isPresent()) {
            VpnInterfaceBuilder vpnIfBuilder = new VpnInterfaceBuilder(optionalVpnInterface.get());
            LOG.debug("Updating vpn interface {} with new adjacencies", infName);
            if (adjacencies == null) {
                if (isLockAcquired) {
                    interfaceLock.unlock(infName);
                }
                return;
            }
            vpnIfBuilder.addAugmentation(Adjacencies.class, adjacencies);
            if (optionalVpnInterface.get().getVpnInstanceNames() != null) {
                List<VpnInstanceNames> listVpnInstances = new ArrayList<>(optionalVpnInterface.get().getVpnInstanceNames());
                if (listVpnInstances.isEmpty() || !VpnHelper.doesVpnInterfaceBelongToVpnInstance(vpnId.getValue(), listVpnInstances)) {
                    VpnInstanceNames vpnInstance = VpnHelper.getVpnInterfaceVpnInstanceNames(vpnId.getValue(), AssociatedSubnetType.V4AndV6Subnets);
                    listVpnInstances.add(vpnInstance);
                    vpnIfBuilder.setVpnInstanceNames(listVpnInstances);
                }
            } else {
                VpnInstanceNames vpnInstance = VpnHelper.getVpnInterfaceVpnInstanceNames(vpnId.getValue(), AssociatedSubnetType.V4AndV6Subnets);
                List<VpnInstanceNames> listVpnInstances = new ArrayList<>();
                listVpnInstances.add(vpnInstance);
                vpnIfBuilder.setVpnInstanceNames(listVpnInstances);
            }
            LOG.info("Updating vpn interface {} with new adjacencies", infName);
            wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIfBuilder.build());
        }
    } catch (IllegalStateException | ReadFailedException ex) {
        LOG.error("Update of vpninterface {} failed", infName, ex);
    } finally {
        if (isLockAcquired) {
            interfaceLock.unlock(infName);
        }
    }
}
Also used : VpnInterfaceBuilder(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceBuilder) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) VpnInterface(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface) VpnInstanceNames(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames) ArrayList(java.util.ArrayList)

Example 67 with VpnInstance

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance in project netvirt by opendaylight.

the class NeutronvpnManager method updateVpnInterface.

protected void updateVpnInterface(Uuid vpnId, Uuid oldVpnId, Port port, boolean isBeingAssociated, boolean isSubnetIp, WriteTransaction writeConfigTxn) {
    if (vpnId == null || port == null) {
        return;
    }
    boolean isLockAcquired = false;
    String infName = port.getUuid().getValue();
    InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
    try {
        isLockAcquired = interfaceLock.tryLock(infName, LOCK_WAIT_TIME, TimeUnit.SECONDS);
        Optional<VpnInterface> optionalVpnInterface = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
        if (optionalVpnInterface.isPresent()) {
            VpnInstanceNames vpnInstance = VpnHelper.getVpnInterfaceVpnInstanceNames(vpnId.getValue(), AssociatedSubnetType.V4AndV6Subnets);
            List<VpnInstanceNames> listVpn = new ArrayList<>(optionalVpnInterface.get().getVpnInstanceNames());
            if (oldVpnId != null && VpnHelper.doesVpnInterfaceBelongToVpnInstance(oldVpnId.getValue(), listVpn)) {
                VpnHelper.removeVpnInterfaceVpnInstanceNamesFromList(oldVpnId.getValue(), listVpn);
            }
            if (vpnId.getValue() != null && !VpnHelper.doesVpnInterfaceBelongToVpnInstance(vpnId.getValue(), listVpn)) {
                listVpn.add(vpnInstance);
            }
            VpnInterfaceBuilder vpnIfBuilder = new VpnInterfaceBuilder(optionalVpnInterface.get()).setVpnInstanceNames(listVpn);
            LOG.debug("Updating vpn interface {}", infName);
            if (!isBeingAssociated) {
                Adjacencies adjs = vpnIfBuilder.getAugmentation(Adjacencies.class);
                List<Adjacency> adjacencyList = adjs != null ? adjs.getAdjacency() : new ArrayList<>();
                Iterator<Adjacency> adjacencyIter = adjacencyList.iterator();
                while (adjacencyIter.hasNext()) {
                    Adjacency adjacency = adjacencyIter.next();
                    String mipToQuery = adjacency.getIpAddress().split("/")[0];
                    InstanceIdentifier<LearntVpnVipToPort> id = NeutronvpnUtils.buildLearntVpnVipToPortIdentifier(oldVpnId.getValue(), mipToQuery);
                    Optional<LearntVpnVipToPort> optionalVpnVipToPort = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
                    if (optionalVpnVipToPort.isPresent()) {
                        LOG.trace("Removing adjacencies from vpninterface {} upon dissociation of router {} " + "from VPN {}", infName, vpnId, oldVpnId);
                        adjacencyIter.remove();
                        neutronvpnUtils.removeLearntVpnVipToPort(oldVpnId.getValue(), mipToQuery);
                        LOG.trace("Entry for fixedIP {} for port {} on VPN {} removed from VpnPortFixedIPToPortData", mipToQuery, infName, vpnId.getValue());
                    }
                }
                Adjacencies adjacencies = new AdjacenciesBuilder().setAdjacency(adjacencyList).build();
                vpnIfBuilder.addAugmentation(Adjacencies.class, adjacencies);
            }
            List<FixedIps> ips = port.getFixedIps();
            for (FixedIps ip : ips) {
                String ipValue = String.valueOf(ip.getIpAddress().getValue());
                if (oldVpnId != null) {
                    neutronvpnUtils.removeVpnPortFixedIpToPort(oldVpnId.getValue(), ipValue, writeConfigTxn);
                }
                neutronvpnUtils.createVpnPortFixedIpToPort(vpnId.getValue(), ipValue, infName, port.getMacAddress().getValue(), isSubnetIp, writeConfigTxn);
            }
            writeConfigTxn.put(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIfBuilder.build());
        } else {
            LOG.error("VPN Interface {} not found", infName);
        }
    } catch (ReadFailedException ex) {
        LOG.error("Updation of vpninterface {} failed", infName, ex);
    } finally {
        if (isLockAcquired) {
            interfaceLock.unlock(infName);
        }
    }
}
Also used : VpnInterfaceBuilder(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceBuilder) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) ArrayList(java.util.ArrayList) Adjacencies(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.Adjacencies) VpnInterface(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface) VpnInstanceNames(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames) AdjacenciesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesBuilder) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency) LearntVpnVipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort) FixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps)

Example 68 with VpnInstance

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance in project netvirt by opendaylight.

the class NeutronvpnManager method updateVpnInstanceWithRDs.

public void updateVpnInstanceWithRDs(String vpnInstanceId, final List<String> rds) {
    InstanceIdentifier<VpnInstance> vpnIdentifier = InstanceIdentifier.builder(VpnInstances.class).child(VpnInstance.class, new VpnInstanceKey(vpnInstanceId)).build();
    try {
        Optional<VpnInstance> vpnInstanceConfig = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier);
        if (!vpnInstanceConfig.isPresent()) {
            LOG.debug("No VpnInstance present under config vpnInstance:{}", vpnInstanceId);
            return;
        }
        VpnInstance vpnInstance = vpnInstanceConfig.get();
        VpnInstanceBuilder updateVpnInstanceBuilder = new VpnInstanceBuilder(vpnInstance);
        if (vpnInstance.getIpv4Family() != null) {
            Ipv4FamilyBuilder ipv4FamilyBuilder = new Ipv4FamilyBuilder(vpnInstance.getIpv4Family());
            updateVpnInstanceBuilder.setIpv4Family(ipv4FamilyBuilder.setRouteDistinguisher(rds).build());
        }
        if (vpnInstance.getIpv6Family() != null) {
            Ipv6FamilyBuilder ipv6FamilyBuilder = new Ipv6FamilyBuilder(vpnInstance.getIpv6Family());
            updateVpnInstanceBuilder.setIpv6Family(ipv6FamilyBuilder.setRouteDistinguisher(rds).build());
        }
        LOG.debug("Updating Config vpn-instance: {} with the list of RDs: {}", vpnInstanceId, rds);
        SingleTransactionDataBroker.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier, updateVpnInstanceBuilder.build());
    } catch (ReadFailedException | TransactionCommitFailedException ex) {
        LOG.warn("Error configuring feature ", ex);
    }
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) VpnInstance(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance) Ipv6FamilyBuilder(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.vpn.instance.Ipv6FamilyBuilder) VpnInstanceBuilder(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstanceBuilder) VpnInstanceKey(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstanceKey) Ipv4FamilyBuilder(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.vpn.instance.Ipv4FamilyBuilder)

Example 69 with VpnInstance

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance in project netvirt by opendaylight.

the class NeutronvpnManager method removeSubnetFromVpn.

protected void removeSubnetFromVpn(final Uuid vpnId, Uuid subnet, Uuid internetVpnId) {
    Preconditions.checkArgument(vpnId != null || internetVpnId != null, "removeSubnetFromVpn: at least one VPN must be not null");
    LOG.debug("Removing subnet {} from vpn {}/{}", subnet.getValue(), vpnId, internetVpnId);
    Subnetmap sn = neutronvpnUtils.getSubnetmap(subnet);
    if (sn == null) {
        LOG.error("removeSubnetFromVpn: Subnetmap for subnet {} not found", subnet.getValue());
        return;
    }
    VpnMap vpnMap = null;
    VpnInstance vpnInstance = null;
    if (vpnId != null) {
        vpnMap = neutronvpnUtils.getVpnMap(vpnId);
        if (vpnMap == null) {
            LOG.error("No vpnMap for vpnId {}, cannot remove subnet {} from VPN", vpnId.getValue(), subnet.getValue());
            return;
        }
        vpnInstance = VpnHelper.getVpnInstance(dataBroker, vpnId.getValue());
    }
    if (internetVpnId == null) {
        internetVpnId = sn.getInternetVpnId();
    }
    if (internetVpnId != null) {
        vpnMap = neutronvpnUtils.getVpnMap(internetVpnId);
        if (vpnMap == null) {
            LOG.error("No vpnMap for vpnId {}, cannot remove subnet {}" + " from Internet VPN", internetVpnId.getValue(), subnet.getValue());
            return;
        }
    }
    if (vpnInstance != null && isVpnOfTypeL2(vpnInstance)) {
        neutronEvpnUtils.updateElanAndVpn(vpnInstance, sn.getNetworkId().getValue(), NeutronEvpnUtils.Operation.DELETE);
    }
    boolean subnetVpnAssociation = false;
    if (vpnId != null && sn.getVpnId() != null && sn.getVpnId().getValue().equals(vpnId.getValue())) {
        subnetVpnAssociation = true;
    } else if (internetVpnId != null && sn.getInternetVpnId() != null && sn.getInternetVpnId().getValue().matches(internetVpnId.getValue())) {
        subnetVpnAssociation = true;
    }
    if (subnetVpnAssociation == false) {
        LOG.error("Removing subnet : Subnetmap is not in VPN {}/{}, owns {} and {}", vpnId, internetVpnId, sn.getVpnId(), sn.getInternetVpnId());
        return;
    }
    // Check if there are ports on this subnet; remove corresponding vpn-interfaces
    List<Uuid> portList = sn.getPortList();
    final Uuid internetId = internetVpnId;
    if (portList != null) {
        for (final Uuid portId : portList) {
            LOG.debug("withdrawing subnet IP {} from vpn-interface {}", sn.getSubnetIp(), portId.getValue());
            final Port port = neutronvpnUtils.getNeutronPort(portId);
            jobCoordinator.enqueueJob("PORT-" + portId.getValue(), () -> {
                WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
                List<ListenableFuture<Void>> futures = new ArrayList<>();
                if (port != null) {
                    withdrawPortIpFromVpnIface(vpnId, internetId, port, sn, wrtConfigTxn);
                } else {
                    LOG.warn("Cannot proceed with withdrawPortIpFromVpnIface for port {} in subnet {} since " + "port is absent in Neutron config DS", portId.getValue(), subnet.getValue());
                }
                futures.add(wrtConfigTxn.submit());
                return futures;
            });
        }
    }
    // update subnet-vpn association
    removeFromSubnetNode(subnet, null, null, vpnId, null);
}
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) VpnMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap) VpnInstance(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance) LearntVpnVipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort) Port(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port) ArrayList(java.util.ArrayList) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) ListenableFuture(com.google.common.util.concurrent.ListenableFuture)

Example 70 with VpnInstance

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance in project netvirt by opendaylight.

the class NeutronvpnUtils method updateVpnInstanceWithIpFamily.

public void updateVpnInstanceWithIpFamily(String vpnName, IpVersionChoice ipVersion, boolean add) {
    VpnInstanceOpDataEntry vpnInstanceOpDataEntry = getVpnInstanceOpDataEntryFromVpnId(vpnName);
    if (vpnInstanceOpDataEntry == null) {
        return;
    }
    if (vpnInstanceOpDataEntry.getType() == VpnInstanceOpDataEntry.Type.L2) {
        LOG.debug("updateVpnInstanceWithIpFamily: Update VpnInstance {} with ipFamily {}." + "VpnInstanceOpDataEntry is L2 instance. Do nothing.", vpnName, ipVersion.toString());
        return;
    }
    final boolean isFinalVpnInstanceIpv6Changed = ipVersion.isIpVersionChosen(IpVersionChoice.IPV6) ? true : false;
    final boolean isFinalVpnInstanceIpv4Changed = ipVersion.isIpVersionChosen(IpVersionChoice.IPV4) ? true : false;
    final boolean finalIsIpv4Configured = ipVersion.isIpVersionChosen(IpVersionChoice.IPV4) ? add : false;
    final boolean finalIsIpv6Configured = ipVersion.isIpVersionChosen(IpVersionChoice.IPV6) ? add : false;
    jobCoordinator.enqueueJob("VPN-" + vpnName, () -> {
        VpnInstanceOpDataEntryBuilder builder = new VpnInstanceOpDataEntryBuilder(vpnInstanceOpDataEntry);
        if (isFinalVpnInstanceIpv4Changed) {
            builder.setIpv4Configured(finalIsIpv4Configured);
        }
        if (isFinalVpnInstanceIpv6Changed) {
            builder.setIpv6Configured(finalIsIpv6Configured);
        }
        WriteTransaction writeTxn = dataBroker.newWriteOnlyTransaction();
        InstanceIdentifier<VpnInstanceOpDataEntry> id = InstanceIdentifier.builder(VpnInstanceOpData.class).child(VpnInstanceOpDataEntry.class, new VpnInstanceOpDataEntryKey(vpnInstanceOpDataEntry.getVrfId())).build();
        writeTxn.merge(LogicalDatastoreType.OPERATIONAL, id, builder.build(), false);
        LOG.info("updateVpnInstanceWithIpFamily: Successfully {} {} to Vpn {}", add ? "added" : "removed", ipVersion.toString(), vpnName);
        return Collections.singletonList(writeTxn.submit());
    });
    return;
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) VpnInstanceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry) VpnInstanceOpDataEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntryBuilder) VpnInstanceOpDataEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntryKey)

Aggregations

ArrayList (java.util.ArrayList)39 VpnInstanceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry)23 VpnInstance (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance)19 BigInteger (java.math.BigInteger)18 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)17 VpnToDpnList (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnList)16 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)15 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)14 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)14 VpnInterface (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface)13 VpnInstanceNames (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames)13 VpnInterfaceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry)13 VrfTablesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesKey)12 List (java.util.List)10 Routes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.extra.routes.Routes)9 Optional (com.google.common.base.Optional)7 PostConstruct (javax.annotation.PostConstruct)7 Inject (javax.inject.Inject)7 Singleton (javax.inject.Singleton)7 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)7