Search in sources :

Example 61 with Networks

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks in project netvirt by opendaylight.

the class NaptSwitchHA method getRouterIdsForExtNetwork.

@NonNull
private List<String> getRouterIdsForExtNetwork(Uuid extNetworkId) {
    List<String> routerUuidsAsString = new ArrayList<>();
    InstanceIdentifier<Networks> extNetwork = InstanceIdentifier.builder(ExternalNetworks.class).child(Networks.class, new NetworksKey(extNetworkId)).build();
    Optional<Networks> extNetworkData = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, extNetwork);
    if (extNetworkData.isPresent()) {
        List<Uuid> routerUuids = extNetworkData.get().getRouterIds();
        if (routerUuids != null) {
            for (Uuid routerUuid : routerUuids) {
                routerUuidsAsString.add(routerUuid.getValue());
            }
        }
    }
    return routerUuidsAsString;
}
Also used : Networks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks) ExternalNetworks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks) NetworksKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ArrayList(java.util.ArrayList) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 62 with Networks

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks in project netvirt by opendaylight.

the class FloatingIPListener method createNATFlowEntries.

void createNATFlowEntries(String interfaceName, final InternalToExternalPortMap mapping, final InstanceIdentifier<RouterPorts> portIid, final String routerName, @Nullable Uint64 dpnId, TypedReadWriteTransaction<Configuration> confTx) throws ExecutionException, InterruptedException {
    if (!validateIpMapping(mapping)) {
        LOG.error("createNATFlowEntries : Not a valid ip addresses in the mapping {}", mapping);
        return;
    }
    Uuid extNwId = getExtNetworkId(portIid, LogicalDatastoreType.CONFIGURATION);
    if (extNwId == null) {
        LOG.error("createNATFlowEntries : External network associated with interface {} could not be retrieved", interfaceName);
        return;
    }
    // For Overlay Networks, get the DPN on which this interface resides.
    // For FLAT/VLAN Networks, get the DPN with provider_mappings for external network.
    dpnId = getAssociatedDpnWithExternalInterface(routerName, extNwId, dpnId, interfaceName);
    if (dpnId == null || dpnId.equals(Uint64.ZERO)) {
        LOG.warn("createNATFlowEntries : No DPN for interface {}. NAT flow entries for ip mapping {} will " + "not be installed", interfaceName, mapping);
        return;
    }
    Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
    if (routerId == NatConstants.INVALID_ID) {
        LOG.error("createNATFlowEntries : Could not retrieve router id for {} to create NAT Flow entries", routerName);
        return;
    }
    // Check if the router to vpn association is present
    // long associatedVpnId = NatUtil.getAssociatedVpn(dataBroker, routerName);
    Uuid associatedVpn = NatUtil.getVpnForRouter(dataBroker, routerName);
    Uint32 associatedVpnId = NatConstants.INVALID_ID;
    if (associatedVpn == null) {
        LOG.debug("createNATFlowEntries : Router {} is not assicated with any BGP VPN instance", routerName);
    } else {
        LOG.debug("createNATFlowEntries : Router {} is associated with VPN Instance with Id {}", routerName, associatedVpn);
        associatedVpnId = NatUtil.getVpnId(dataBroker, associatedVpn.getValue());
        LOG.debug("createNATFlowEntries : vpninstance Id is {} for VPN {}", associatedVpnId, associatedVpn);
    // routerId = associatedVpnId;
    }
    Uuid vpnUuid = getVpnUuid(extNwId, mapping.getExternalId());
    LOG.trace("createNATFlowEntries : vpnUuid {} for External Network {}", vpnUuid, extNwId);
    if (vpnUuid == null) {
        LOG.error("createNATFlowEntries : No VPN associated with Ext nw {}. Unable to create SNAT table entry " + "for fixed ip {}", extNwId, mapping.getInternalIp());
        return;
    }
    VpnInstance vpnInstance = NatUtil.getVpnIdToVpnInstance(dataBroker, vpnUuid.getValue());
    if (vpnInstance == null || vpnInstance.getVpnId() == null) {
        LOG.error("createNATFlowEntries : No VPN associated with Ext nw {}. Unable to create SNAT table entry " + "for fixed ip {}", extNwId, mapping.getInternalIp());
        return;
    }
    // Install the DNAT default FIB flow L3_FIB_TABLE (21) -> PSNAT_TABLE (26) if SNAT is disabled
    boolean isSnatEnabled = NatUtil.isSnatEnabledForRouterId(dataBroker, routerName);
    if (!isSnatEnabled) {
        addOrDelDefaultFibRouteForDnat(dpnId, routerName, routerId, confTx, true);
    }
    // Create the DNAT and SNAT table entries
    Uint32 vpnId = vpnInstance.getVpnId();
    String vrfId = vpnInstance.getVrfId();
    createDNATTblEntry(dpnId, mapping, routerId, associatedVpnId, confTx);
    createSNATTblEntry(dpnId, mapping, vpnId, routerId, associatedVpnId, extNwId, confTx);
    floatingIPHandler.onAddFloatingIp(dpnId, routerName, routerId, extNwId, interfaceName, mapping, vrfId, confTx);
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance) Uint32(org.opendaylight.yangtools.yang.common.Uint32)

Example 63 with Networks

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks in project netvirt by opendaylight.

the class NeutronvpnManager method updateVpnMaps.

protected void updateVpnMaps(Uuid vpnId, @Nullable String name, @Nullable Uuid router, @Nullable Uuid tenantId, @Nullable List<Uuid> networks) {
    VpnMapBuilder builder;
    InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class, new VpnMapKey(vpnId)).build();
    try {
        Optional<VpnMap> optionalVpnMap = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
        if (optionalVpnMap.isPresent()) {
            builder = new VpnMapBuilder(optionalVpnMap.get());
        } else {
            builder = new VpnMapBuilder().withKey(new VpnMapKey(vpnId)).setVpnId(vpnId);
        }
        if (name != null) {
            builder.setName(name);
        }
        if (tenantId != null) {
            builder.setTenantId(tenantId);
        }
        if (router != null) {
            RouterIds vpnRouterId = new RouterIdsBuilder().setRouterId(router).build();
            List<RouterIds> rtrIds = builder.getRouterIds() != null ? new ArrayList<>(builder.getRouterIds().values()) : null;
            if (rtrIds == null) {
                rtrIds = Collections.singletonList(vpnRouterId);
            } else {
                // Add vpnRouterId to rtrIds list only if update routerId is not existing in the VpnMap already
                for (RouterIds routerId : rtrIds) {
                    if (!Objects.equals(routerId, vpnRouterId)) {
                        rtrIds.add(vpnRouterId);
                    }
                }
            }
            builder.setRouterIds(rtrIds);
        }
        if (networks != null) {
            List<Uuid> nwList = builder.getNetworkIds() != null ? new ArrayList<>(builder.getNetworkIds()) : new ArrayList<>();
            nwList.addAll(networks);
            builder.setNetworkIds(nwList);
        }
        try (AcquireResult lock = tryVpnLock(vpnId)) {
            if (!lock.wasAcquired()) {
                // FIXME: why do we even bother with locking if we do not honor it?!
                logTryLockFailure(vpnId);
            }
            LOG.debug("Creating/Updating vpnMaps node: {} ", vpnId.getValue());
            SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier, builder.build());
            LOG.debug("VPNMaps DS updated for VPN {} ", vpnId.getValue());
        }
    } catch (TransactionCommitFailedException | ExecutionException | InterruptedException e) {
        LOG.error("UpdateVpnMaps failed for node: {} ", vpnId.getValue());
    }
}
Also used : VpnMapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMapKey) AcquireResult(org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) RouterIds(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.vpnmap.RouterIds) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnMapBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMapBuilder) VpnMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap) RouterIdsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.vpnmap.RouterIdsBuilder) ExecutionException(java.util.concurrent.ExecutionException)

Example 64 with Networks

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks in project netvirt by opendaylight.

the class NeutronvpnManager method dissociateNetworks.

/**
 * It handles the invocations to the neutronvpn:dissociateNetworks RPC method.
 */
@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public ListenableFuture<RpcResult<DissociateNetworksOutput>> dissociateNetworks(DissociateNetworksInput input) {
    DissociateNetworksOutputBuilder opBuilder = new DissociateNetworksOutputBuilder();
    SettableFuture<RpcResult<DissociateNetworksOutput>> result = SettableFuture.create();
    LOG.debug("dissociateNetworks {}", input);
    StringBuilder returnMsg = new StringBuilder();
    Uuid vpnId = input.getVpnId();
    try {
        if (neutronvpnUtils.getVpnMap(vpnId) != null) {
            LOG.debug("dissociateNetworks RPC: VpnId {}, networkList {}", vpnId.getValue(), input.getNetworkId());
            List<Uuid> netIds = input.getNetworkId();
            if (netIds != null && !netIds.isEmpty()) {
                List<String> failed = dissociateNetworksFromVpn(vpnId, netIds);
                if (!failed.isEmpty()) {
                    returnMsg.append(failed);
                }
            }
        } else {
            returnMsg.append("VPN not found : ").append(vpnId.getValue());
        }
        if (returnMsg.length() != 0) {
            opBuilder.setResponse("ErrorType: PROTOCOL, ErrorTag: invalid-value, ErrorMessage: " + formatAndLog(LOG::error, "dissociate Networks to vpn {} failed due to {}", vpnId.getValue(), returnMsg));
            result.set(RpcResultBuilder.<DissociateNetworksOutput>success().withResult(opBuilder.build()).build());
        } else {
            result.set(RpcResultBuilder.<DissociateNetworksOutput>success().build());
        }
    } catch (Exception ex) {
        result.set(RpcResultBuilder.<DissociateNetworksOutput>failed().withError(ErrorType.APPLICATION, formatAndLog(LOG::error, "dissociate Networks to vpn {} failed due to {}", input.getVpnId().getValue(), ex.getMessage(), ex)).build());
    }
    LOG.debug("dissociateNetworks returns..");
    return result;
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) DissociateNetworksOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DissociateNetworksOutput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) DissociateNetworksOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DissociateNetworksOutputBuilder) ExecutionException(java.util.concurrent.ExecutionException) OptimisticLockFailedException(org.opendaylight.mdsal.common.api.OptimisticLockFailedException) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException)

Example 65 with Networks

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks in project netvirt by opendaylight.

the class NeutronvpnManager method addExternalNetworkToVpn.

private boolean addExternalNetworkToVpn(Network extNet, Uuid vpnId) {
    Uuid extNetId = extNet.getUuid();
    InstanceIdentifier<Networks> extNetIdentifier = InstanceIdentifier.builder(ExternalNetworks.class).child(Networks.class, new NetworksKey(extNetId)).build();
    try {
        Optional<Networks> optionalExtNets = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, extNetIdentifier);
        if (!optionalExtNets.isPresent()) {
            LOG.error("addExternalNetworkToVpn: Provider Network {} is not present in ConfigDS", extNetId.getValue());
            return false;
        }
        NetworksBuilder builder = new NetworksBuilder(optionalExtNets.get());
        builder.setVpnid(vpnId);
        Networks networks = builder.build();
        // Add Networks object to the ExternalNetworks list
        LOG.trace("addExternalNetworkToVpn: Set VPN Id {} for Provider Network {}", vpnId.getValue(), extNetId.getValue());
        SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, extNetIdentifier, networks);
        return true;
    } catch (TransactionCommitFailedException | ExecutionException | InterruptedException ex) {
        LOG.error("addExternalNetworkToVpn: Failed to set VPN Id {} to Provider Network {}: ", vpnId.getValue(), extNetId.getValue(), ex);
    }
    return false;
}
Also used : Networks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks) ExternalNetworks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks) NetworksKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ExecutionException(java.util.concurrent.ExecutionException) NetworksBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksBuilder)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)43 ExecutionException (java.util.concurrent.ExecutionException)19 ArrayList (java.util.ArrayList)16 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)14 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)13 ExternalNetworks (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks)13 Networks (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks)13 NetworksKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey)11 Uint32 (org.opendaylight.yangtools.yang.common.Uint32)9 BigInteger (java.math.BigInteger)6 Networks (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks)6 NetworksKey (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.NetworksKey)6 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)5 HashSet (java.util.HashSet)4 NonNull (org.eclipse.jdt.annotation.NonNull)4 AcquireResult (org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult)4 NetworksBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksBuilder)4 InternalToExternalPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap)4 VpnMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap)4 Network (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network)4