Search in sources :

Example 51 with VpnInterface

use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface in project netvirt by opendaylight.

the class NeutronvpnManager method writeVpnInterfaceToDs.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void writeVpnInterfaceToDs(@Nonnull Collection<Uuid> vpnIdList, String infName, Adjacencies adjacencies, Boolean isRouterInterface, WriteTransaction wrtConfigTxn) {
    if (vpnIdList.isEmpty() || infName == null) {
        LOG.error("vpn id or interface is null");
        return;
    }
    List<VpnInstanceNames> vpnIdListStruct = new ArrayList<>();
    for (Uuid vpnId : vpnIdList) {
        VpnInstanceNames vpnInstance = VpnHelper.getVpnInterfaceVpnInstanceNames(vpnId.getValue(), AssociatedSubnetType.V4AndV6Subnets);
        vpnIdListStruct.add(vpnInstance);
    }
    Boolean wrtConfigTxnPresent = true;
    if (wrtConfigTxn == null) {
        wrtConfigTxnPresent = false;
        wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
    }
    InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
    VpnInterfaceBuilder vpnb = new VpnInterfaceBuilder().setKey(new VpnInterfaceKey(infName)).setName(infName).setVpnInstanceNames(vpnIdListStruct).setRouterInterface(isRouterInterface);
    if (adjacencies != null) {
        vpnb.addAugmentation(Adjacencies.class, adjacencies);
    }
    VpnInterface vpnIf = vpnb.build();
    try {
        LOG.info("Creating vpn interface {}", vpnIf);
        wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIf);
    } catch (Exception ex) {
        LOG.error("Creation of vpninterface {} failed", infName, ex);
    }
    if (!wrtConfigTxnPresent) {
        wrtConfigTxn.submit();
    }
}
Also used : VpnInterfaceBuilder(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceBuilder) VpnInterfaceKey(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceKey) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnInstanceNames(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames) VpnInterface(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface) ArrayList(java.util.ArrayList) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ExecutionException(java.util.concurrent.ExecutionException) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)

Example 52 with VpnInterface

use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface 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 53 with VpnInterface

use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface 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)

Aggregations

VpnInterface (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface)33 ArrayList (java.util.ArrayList)32 VpnInstanceNames (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames)24 Adjacency (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency)23 Adjacencies (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.Adjacencies)17 VpnInterfaceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry)17 BigInteger (java.math.BigInteger)16 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)14 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)12 VpnInterfaceKey (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceKey)12 ExecutionException (java.util.concurrent.ExecutionException)11 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)10 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)10 VpnInterfaceBuilder (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceBuilder)10 List (java.util.List)9 AdjacencyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.AdjacencyBuilder)8 Interface (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface)7 VpnInterfaceOpDataEntryKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntryKey)7 Optional (com.google.common.base.Optional)6 PostConstruct (javax.annotation.PostConstruct)6