Search in sources :

Example 51 with Update

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update in project netvirt by opendaylight.

the class NeutronvpnNatManager method updateExternalSubnet.

public void updateExternalSubnet(Uuid networkId, Uuid subnetId, List<Uuid> routerIds) {
    InstanceIdentifier<Subnets> subnetsIdentifier = InstanceIdentifier.builder(ExternalSubnets.class).child(Subnets.class, new SubnetsKey(subnetId)).build();
    try {
        Subnets newExternalSubnets = createSubnets(subnetId, networkId, routerIds);
        LOG.debug("Updating external subnet {}", newExternalSubnets);
        SingleTransactionDataBroker.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION, subnetsIdentifier, newExternalSubnets);
    } catch (TransactionCommitFailedException ex) {
        LOG.error("Update of External Subnets {} failed", subnetId, ex);
    }
}
Also used : SubnetsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.SubnetsKey) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ExternalSubnets(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalSubnets) Subnets(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.Subnets)

Example 52 with Update

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update in project netvirt by opendaylight.

the class NeutronvpnUtils method updateVpnInstanceOpWithType.

public void updateVpnInstanceOpWithType(VpnInstanceOpDataEntry.BgpvpnType choice, @Nonnull Uuid vpn) {
    String primaryRd = getVpnRd(vpn.getValue());
    if (primaryRd == null) {
        LOG.debug("updateVpnInstanceOpWithType: Update BgpvpnType {} for {}." + "Primary RD not found", choice, vpn.getValue());
        return;
    }
    InstanceIdentifier<VpnInstanceOpDataEntry> id = InstanceIdentifier.builder(VpnInstanceOpData.class).child(VpnInstanceOpDataEntry.class, new VpnInstanceOpDataEntryKey(primaryRd)).build();
    Optional<VpnInstanceOpDataEntry> vpnInstanceOpDataEntryOptional = read(LogicalDatastoreType.OPERATIONAL, id);
    if (!vpnInstanceOpDataEntryOptional.isPresent()) {
        LOG.debug("updateVpnInstanceOpWithType: Update BgpvpnType {} for {}." + "VpnInstanceOpDataEntry not found", choice, vpn.getValue());
        return;
    }
    VpnInstanceOpDataEntry vpnInstanceOpDataEntry = vpnInstanceOpDataEntryOptional.get();
    if (vpnInstanceOpDataEntry.getBgpvpnType().equals(choice)) {
        LOG.debug("updateVpnInstanceOpWithType: Update BgpvpnType {} for {}." + "VpnInstanceOpDataEntry already set", choice, vpn.getValue());
        return;
    }
    VpnInstanceOpDataEntryBuilder builder = new VpnInstanceOpDataEntryBuilder(vpnInstanceOpDataEntry);
    builder.setBgpvpnType(choice);
    WriteTransaction writeTxn = dataBroker.newWriteOnlyTransaction();
    writeTxn.merge(LogicalDatastoreType.OPERATIONAL, id, builder.build(), false);
    LOG.debug("updateVpnInstanceOpWithType: sent merge to operDS BgpvpnType {} for {}", choice, vpn.getValue());
    try {
        writeTxn.submit().get();
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("updateVpnInstanceOpWithType: on merge execution, error:  {}", e);
    }
    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) ExecutionException(java.util.concurrent.ExecutionException)

Example 53 with Update

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update in project netvirt by opendaylight.

the class NeutronTrunkChangeListener method deleteSubPortInterface.

private void deleteSubPortInterface(SubPorts subPort) {
    String portName = subPort.getPortId().getValue();
    InstanceIdentifier<Interface> interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(subPort.getPortId().getValue());
    jobCoordinator.enqueueJob("PORT- " + portName, () -> {
        Interface iface = ifMgr.getInterfaceInfoFromConfigDataStore(portName);
        List<ListenableFuture<Void>> futures = new ArrayList<>();
        if (iface == null) {
            LOG.warn("Interface not present for SubPort {}", subPort);
            return futures;
        }
        /*
             * We'll reset interface back to way it was? Can IFM handle parentRef delete?
             */
        InterfaceBuilder interfaceBuilder = new InterfaceBuilder(iface);
        // Reset augmentations
        interfaceBuilder.removeAugmentation(IfL2vlan.class).removeAugmentation(ParentRefs.class).removeAugmentation(SplitHorizon.class);
        IfL2vlan ifL2vlan = new IfL2vlanBuilder().setL2vlanMode(IfL2vlan.L2vlanMode.Trunk).build();
        interfaceBuilder.addAugmentation(IfL2vlan.class, ifL2vlan);
        iface = interfaceBuilder.build();
        /*
             * There is no means to do an update to remove elements from a node.
             * Our solution is to get existing iface, remove parentRef and VlanId,
             * and do a put to replace existing entry. This works out better as put
             * has better performance than merge.
             * Only drawback is any in-flight changes might be lost, but that is a corner case
             * and this being subport delete path, don't expect any significant changes to
             * corresponding Neutron Port. Deletion of NeutronPort should follow soon enough.
             */
        WriteTransaction txn = dataBroker.newWriteOnlyTransaction();
        txn.put(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier, iface);
        LOG.trace("Resetting trunk member interface {}", iface);
        futures.add(txn.submit());
        return futures;
    });
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) ParentRefs(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefs) ArrayList(java.util.ArrayList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) InterfaceBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder) IfL2vlanBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlanBuilder) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface) IfL2vlan(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan)

Example 54 with Update

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update in project netvirt by opendaylight.

the class NeutronvpnManager method addSubnetToVpn.

protected void addSubnetToVpn(@Nullable final Uuid vpnId, Uuid subnet, @Nullable final Uuid internetVpnId) {
    LOG.debug("addSubnetToVpn: Adding subnet {} to vpn {}", subnet.getValue(), vpnId != null ? vpnId.getValue() : internetVpnId.getValue());
    Subnetmap sn = updateSubnetNode(subnet, null, vpnId, internetVpnId);
    if (sn == null) {
        LOG.error("addSubnetToVpn: subnetmap is null, cannot add subnet {} to VPN {}", subnet.getValue(), vpnId != null ? vpnId.getValue() : internetVpnId.getValue());
        return;
    }
    if (vpnId != null) {
        VpnMap vpnMap = neutronvpnUtils.getVpnMap(vpnId);
        if (vpnMap == null) {
            LOG.error("addSubnetToVpn: No vpnMap for vpnId {}," + " cannot add subnet {} to VPN", vpnId.getValue(), subnet.getValue());
            return;
        }
        final VpnInstance vpnInstance = VpnHelper.getVpnInstance(dataBroker, vpnId.getValue());
        LOG.debug("addSubnetToVpn: VpnInstance {}", vpnInstance.toString());
        if (isVpnOfTypeL2(vpnInstance)) {
            neutronEvpnUtils.updateElanAndVpn(vpnInstance, sn.getNetworkId().getValue(), NeutronEvpnUtils.Operation.ADD);
        }
    }
    if (internetVpnId != null) {
        VpnMap vpnMap = neutronvpnUtils.getVpnMap(internetVpnId);
        if (vpnMap == null) {
            LOG.error("addSubnetToVpn: No vpnMap for InternetVpnId {}, cannot add " + "subnet {} to VPN", internetVpnId.getValue(), subnet.getValue());
            return;
        }
    }
    final Uuid internetId = internetVpnId;
    // Check if there are ports on this subnet and add corresponding vpn-interfaces
    List<Uuid> portList = sn.getPortList();
    if (portList != null) {
        for (final Uuid portId : portList) {
            String vpnInfName = portId.getValue();
            VpnInterface vpnIface = VpnHelper.getVpnInterface(dataBroker, vpnInfName);
            Port port = neutronvpnUtils.getNeutronPort(portId);
            if (port == null) {
                LOG.error("addSubnetToVpn: Cannot proceed with addSubnetToVpn for port {} in subnet {} " + "since port is absent in Neutron config DS", portId.getValue(), subnet.getValue());
                continue;
            }
            final Boolean isRouterInterface = port.getDeviceOwner().equals(NeutronConstants.DEVICE_OWNER_ROUTER_INF) ? true : false;
            jobCoordinator.enqueueJob("PORT-" + portId.getValue(), () -> singletonList(managedNewTransactionRunner.callWithNewWriteOnlyTransactionAndSubmit(wrtConfigTxn -> {
                Adjacencies portAdj = createPortIpAdjacencies(port, isRouterInterface, wrtConfigTxn, sn, vpnIface);
                if (vpnIface == null) {
                    LOG.trace("addSubnetToVpn: create new VpnInterface for Port {}", vpnInfName);
                    Set<Uuid> listVpn = new HashSet<Uuid>();
                    if (vpnId != null) {
                        listVpn.add(vpnId);
                    }
                    if (internetId != null) {
                        listVpn.add(internetId);
                    }
                    writeVpnInterfaceToDs(listVpn, vpnInfName, portAdj, isRouterInterface, wrtConfigTxn);
                    if (sn.getRouterId() != null) {
                        addToNeutronRouterInterfacesMap(sn.getRouterId(), portId.getValue());
                    }
                } else {
                    LOG.trace("update VpnInterface for Port {} with adj {}", vpnInfName, portAdj);
                    if (vpnId != null) {
                        updateVpnInterfaceWithAdjacencies(vpnId, vpnInfName, portAdj, wrtConfigTxn);
                    }
                    if (internetId != null) {
                        updateVpnInterfaceWithAdjacencies(internetId, vpnInfName, portAdj, wrtConfigTxn);
                    }
                }
            })));
        }
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnInterface(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface) 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) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) Adjacencies(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.Adjacencies) HashSet(java.util.HashSet)

Example 55 with Update

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update in project netvirt by opendaylight.

the class NeutronvpnManager method associateNetworksToVpn.

/**
 * Parses and associates networks list with given VPN.
 *
 * @param vpnId Uuid of given VPN.
 * @param networks List list of network Ids (Uuid), which will be associated.
 * @return list of formatted strings with detailed error messages.
 */
@Nonnull
protected List<String> associateNetworksToVpn(@Nonnull Uuid vpnId, @Nonnull List<Uuid> networks) {
    List<String> failedNwList = new ArrayList<>();
    HashSet<Uuid> passedNwList = new HashSet<>();
    if (networks.isEmpty()) {
        LOG.error("associateNetworksToVpn: Failed as given networks list is empty, VPN Id: {}", vpnId.getValue());
        failedNwList.add(String.format("Failed to associate networks with VPN %s as given networks list is empty", vpnId.getValue()));
        return failedNwList;
    }
    VpnInstance vpnInstance = VpnHelper.getVpnInstance(dataBroker, vpnId.getValue());
    if (vpnInstance == null) {
        LOG.error("associateNetworksToVpn: Can not find vpnInstance for VPN {} in ConfigDS", vpnId.getValue());
        failedNwList.add(String.format("Failed to associate network: can not found vpnInstance for VPN %s " + "in ConfigDS", vpnId.getValue()));
        return failedNwList;
    }
    try {
        if (isVpnOfTypeL2(vpnInstance) && neutronEvpnUtils.isVpnAssociatedWithNetwork(vpnInstance)) {
            LOG.error("associateNetworksToVpn: EVPN {} supports only one network to be associated with", vpnId.getValue());
            failedNwList.add(String.format("Failed to associate network: EVPN %s supports only one network to be " + "associated with", vpnId.getValue()));
            return failedNwList;
        }
        for (Uuid nw : networks) {
            Network network = neutronvpnUtils.getNeutronNetwork(nw);
            if (network == null) {
                LOG.error("associateNetworksToVpn: Network {} not found in ConfigDS", nw.getValue());
                failedNwList.add(String.format("Failed to associate network: network %s not found in ConfigDS", nw.getValue()));
                continue;
            }
            NetworkProviderExtension providerExtension = network.getAugmentation(NetworkProviderExtension.class);
            if (providerExtension.getSegments() != null && providerExtension.getSegments().size() > 1) {
                LOG.error("associateNetworksToVpn: MultiSegmented network {} not supported in BGPVPN {}", nw.getValue(), vpnId.getValue());
                failedNwList.add(String.format("Failed to associate multisegmented network %s with BGPVPN %s", nw.getValue(), vpnId.getValue()));
                continue;
            }
            Uuid networkVpnId = neutronvpnUtils.getVpnForNetwork(nw);
            if (networkVpnId != null) {
                LOG.error("associateNetworksToVpn: Network {} already associated with another VPN {}", nw.getValue(), networkVpnId.getValue());
                failedNwList.add(String.format("Failed to associate network %s as it is already associated to " + "another VPN %s", nw.getValue(), networkVpnId.getValue()));
                continue;
            }
            if (neutronvpnUtils.getIsExternal(network)) {
                if (associateExtNetworkToVpn(vpnId, network)) {
                    passedNwList.add(nw);
                    continue;
                } else {
                    LOG.error("associateNetworksToVpn: Failed to associate Provider Network {} with VPN {}", nw.getValue(), vpnId.getValue());
                    failedNwList.add(String.format("Failed to associate Provider Network %s with VPN %s", nw.getValue(), vpnId.getValue()));
                    continue;
                }
            }
            List<Uuid> networkSubnets = neutronvpnUtils.getSubnetIdsFromNetworkId(nw);
            if (networkSubnets == null) {
                passedNwList.add(nw);
                continue;
            }
            for (Uuid subnet : networkSubnets) {
                Uuid subnetVpnId = neutronvpnUtils.getVpnForSubnet(subnet);
                if (subnetVpnId != null) {
                    LOG.error("associateNetworksToVpn: Failed to associate subnet {} with VPN {} as it is already " + "associated", subnet.getValue(), subnetVpnId.getValue());
                    failedNwList.add(String.format("Failed to associate subnet %s with VPN %s as it is already " + "associated", subnet.getValue(), vpnId.getValue()));
                    continue;
                }
                Subnetmap sm = neutronvpnUtils.getSubnetmap(subnet);
                if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToAdd(sm, vpnId)) {
                    neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), NeutronvpnUtils.getIpVersionFromString(sm.getSubnetIp()), true);
                }
                LOG.debug("associateNetworksToVpn: Add subnet {} to VPN {}", subnet.getValue(), vpnId.getValue());
                addSubnetToVpn(vpnId, subnet, null);
                passedNwList.add(nw);
            }
        }
    } catch (ReadFailedException e) {
        LOG.error("associateNetworksToVpn: Failed to associate VPN {} with networks {}: ", vpnId.getValue(), networks, e);
        failedNwList.add(String.format("Failed to associate VPN %s with networks %s: %s", vpnId.getValue(), networks, e));
    }
    LOG.info("associateNetworksToVpn: update VPN {} with networks list: {}", vpnId.getValue(), passedNwList.toString());
    updateVpnMaps(vpnId, null, null, null, new ArrayList<Uuid>(passedNwList));
    return failedNwList;
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) VpnInstance(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance) ArrayList(java.util.ArrayList) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) NetworkProviderExtension(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.provider.ext.rev150712.NetworkProviderExtension) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Network(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network) HashSet(java.util.HashSet) Nonnull(javax.annotation.Nonnull)

Aggregations

ArrayList (java.util.ArrayList)80 Test (org.junit.Test)64 BigInteger (java.math.BigInteger)46 Update (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update)46 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)43 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)35 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)29 List (java.util.List)27 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)26 AbstractRIBSupportTest (org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest)24 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)24 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)23 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)23 UpdateBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.UpdateBuilder)19 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)18 Logger (org.slf4j.Logger)18 LoggerFactory (org.slf4j.LoggerFactory)18 Collections (java.util.Collections)17 Map (java.util.Map)17 Attributes1 (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes1)17