Search in sources :

Example 56 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 ElanServiceTest method readBgpNetworkFromDS.

public Networks readBgpNetworkFromDS(String prefix) throws ReadFailedException {
    InstanceIdentifier<Networks> iid = InstanceIdentifier.create(Bgp.class).child(NetworksContainer.class).child(Networks.class, new NetworksKey(prefix, RD));
    awaitForData(LogicalDatastoreType.CONFIGURATION, iid);
    return singleTxdataBroker.syncRead(CONFIGURATION, iid);
}
Also used : Networks(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks) NetworksKey(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.NetworksKey) NetworksContainer(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.NetworksContainer)

Example 57 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 ExternalNetworksChangeListener method remove.

@Override
public void remove(InstanceIdentifier<Networks> identifier, Networks networks) {
    if (identifier == null || networks == null || networks.getRouterIds() == null || networks.getRouterIds().isEmpty()) {
        LOG.warn("remove : returning without processing since networks/identifier is null: " + "identifier: {}, networks: {}", identifier, networks);
        return;
    }
    for (Uuid routerId : networks.getRouterIds()) {
        String routerName = routerId.toString();
        InstanceIdentifier<RouterToNaptSwitch> routerToNaptSwitchInstanceIdentifier = NatUtil.buildNaptSwitchIdentifier(routerName);
        MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.OPERATIONAL, routerToNaptSwitchInstanceIdentifier);
        LOG.debug("remove : successful deletion of data in napt-switches container");
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) RouterToNaptSwitch(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitch)

Example 58 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 ExternalNetworksChangeListener method removeSnatEntries.

private void removeSnatEntries(Networks original, Uuid networkUuid) {
    if (original.getRouterIds() != null) {
        for (Uuid routerUuid : original.getRouterIds()) {
            Uint32 routerId = NatUtil.getVpnId(dataBroker, routerUuid.getValue());
            if (routerId == NatConstants.INVALID_ID) {
                LOG.error("removeSnatEntries : Invalid routerId returned for routerName {}", routerUuid.getValue());
                return;
            }
            Collection<String> externalIps = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
            if (natMode == NatMode.Controller) {
                coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + routerUuid.getValue(), () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> externalRouterListener.handleDisableSnatInternetVpn(routerUuid.getValue(), routerId, networkUuid, externalIps, original.getVpnid().getValue(), tx))), NatConstants.NAT_DJC_MAX_RETRIES);
            }
        }
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Uint32(org.opendaylight.yangtools.yang.common.Uint32)

Example 59 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 ExternalNetworksChangeListener method associateExternalNetworkWithVPN.

private void associateExternalNetworkWithVPN(Networks network) {
    if (network.getRouterIds() != null) {
        List<Uuid> routerIds = network.getRouterIds();
        for (Uuid routerId : routerIds) {
            // long router = NatUtil.getVpnId(dataBroker, routerId.getValue());
            InstanceIdentifier<RouterPorts> routerPortsId = NatUtil.getRouterPortsId(routerId.getValue());
            Optional<RouterPorts> optRouterPorts = null;
            try {
                optRouterPorts = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsId);
            } catch (ExecutionException | InterruptedException e) {
                LOG.error("associateExternalNetworkWithVPN: Exception while reading RouterPorts DS for the " + "router {} network {} ", routerId, network.getId().getValue(), e);
                continue;
            }
            if (!optRouterPorts.isPresent()) {
                LOG.debug("associateExternalNetworkWithVPN : Could not read Router Ports data object with id: {} " + "to handle associate ext nw {}", routerId, network.getId());
                continue;
            }
            RouterPorts routerPorts = optRouterPorts.get();
            for (Ports port : routerPorts.nonnullPorts().values()) {
                String portName = port.getPortName();
                Uint64 dpnId = NatUtil.getDpnForInterface(interfaceManager, portName);
                if (dpnId.equals(Uint64.ZERO)) {
                    LOG.debug("associateExternalNetworkWithVPN : DPN not found for {}, " + "skip handling of ext nw {} association", portName, network.getId());
                    continue;
                }
                for (InternalToExternalPortMap ipMap : port.nonnullInternalToExternalPortMap().values()) {
                    // remove all VPN related entries
                    coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + ipMap.key(), () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> floatingIpListener.createNATFlowEntries(dpnId, portName, routerId.getValue(), network.getId(), ipMap, tx))), NatConstants.NAT_DJC_MAX_RETRIES);
                }
            }
        }
        // SNAT
        for (Uuid routerId : routerIds) {
            LOG.debug("associateExternalNetworkWithVPN() : for routerId {}", routerId);
            Uuid networkId = network.getId();
            if (networkId == null) {
                LOG.error("associateExternalNetworkWithVPN : networkId is null for the router ID {}", routerId);
                return;
            }
            final String vpnName = network.getVpnid().getValue();
            if (vpnName == null) {
                LOG.error("associateExternalNetworkWithVPN : No VPN associated with ext nw {} for router {}", networkId, routerId);
                return;
            }
            Uint64 dpnId = Uint64.valueOf("0");
            InstanceIdentifier<RouterToNaptSwitch> routerToNaptSwitch = NatUtil.buildNaptSwitchRouterIdentifier(routerId.getValue());
            Optional<RouterToNaptSwitch> rtrToNapt = Optional.empty();
            try {
                rtrToNapt = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routerToNaptSwitch);
            } catch (ExecutionException | InterruptedException e) {
                LOG.error("associateExternalNetworkWithVPN: Exception while reading routerToNaptSwitch DS for the " + "router {}", routerId, e);
            }
            if (rtrToNapt.isPresent()) {
                dpnId = rtrToNapt.get().getPrimarySwitchId();
            }
            LOG.debug("associateExternalNetworkWithVPN : got primarySwitch as dpnId{} ", dpnId);
            if (dpnId == null || dpnId.equals(Uint64.ZERO)) {
                LOG.warn("associateExternalNetworkWithVPN : primary napt Switch not found for router {} on dpn: {}", routerId, dpnId);
                return;
            }
            final Uint64 finalDpnId = dpnId;
            coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + routerId.getValue(), () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, confTx -> {
                Uint32 routerIdentifier = NatUtil.getVpnId(dataBroker, routerId.getValue());
                InstanceIdentifierBuilder<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping> idBuilder = InstanceIdentifier.builder(IntextIpMap.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMappingKey(routerIdentifier));
                InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping> id = idBuilder.build();
                Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping> ipMapping = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
                if (ipMapping.isPresent()) {
                    for (IpMap ipMap : ipMapping.get().nonnullIpMap().values()) {
                        String externalIp = ipMap.getExternalIp();
                        LOG.debug("associateExternalNetworkWithVPN : Calling advToBgpAndInstallFibAndTsFlows " + "for dpnId {},vpnName {} and externalIp {}", finalDpnId, vpnName, externalIp);
                        if (natMode == NatMode.Controller) {
                            externalRouterListener.advToBgpAndInstallFibAndTsFlows(finalDpnId, NwConstants.INBOUND_NAPT_TABLE, vpnName, routerIdentifier, routerId.getValue(), externalIp, network.getId(), null, /* external-router */
                            confTx);
                        }
                    }
                } else {
                    LOG.warn("associateExternalNetworkWithVPN: No ipMapping present fot the routerId {}", routerId);
                }
                Uint32 vpnId = NatUtil.getVpnId(dataBroker, vpnName);
                // Install 47 entry to point to 21
                if (natMode == NatMode.Controller) {
                    externalRouterListener.installNaptPfibEntriesForExternalSubnets(routerId.getValue(), finalDpnId, confTx);
                    if (vpnId.longValue() != -1) {
                        LOG.debug("associateExternalNetworkWithVPN : Calling externalRouterListener " + "installNaptPfibEntry for dpnId {} and vpnId {}", finalDpnId, vpnId);
                        externalRouterListener.installNaptPfibEntry(finalDpnId, vpnId, confTx);
                    }
                }
            })), NatConstants.NAT_DJC_MAX_RETRIES);
        }
    }
}
Also used : RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) IntextIpMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.IntextIpMap) ExecutionException(java.util.concurrent.ExecutionException) InternalToExternalPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap) Uint32(org.opendaylight.yangtools.yang.common.Uint32) RouterToNaptSwitch(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitch) RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) Ports(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.Ports) IpMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMap) IntextIpMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.IntextIpMap) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Example 60 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 getVpnUuid.

private Uuid getVpnUuid(Uuid extNwId, Uuid floatingIpExternalId) {
    InstanceIdentifier<Networks> nwId = InstanceIdentifier.builder(ExternalNetworks.class).child(Networks.class, new NetworksKey(extNwId)).build();
    Optional<Networks> nw = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, nwId);
    if (!nw.isPresent()) {
        LOG.error("getVpnId : Unable to read external network for {}", extNwId);
        return null;
    }
    ProviderTypes providerType = nw.get().getProviderNetworkType();
    if (providerType == ProviderTypes.FLAT || providerType == ProviderTypes.VLAN) {
        Uuid subnetId = NatUtil.getFloatingIpPortSubnetIdFromFloatingIpId(dataBroker, floatingIpExternalId);
        if (subnetId != null) {
            return subnetId;
        }
    }
    Uuid vpnUuid = nw.get().getVpnid();
    if (vpnUuid == null) {
        LOG.error("getVpnId : Unable to read vpn from External network: {}", extNwId);
        return null;
    }
    return vpnUuid;
}
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) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)

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