Search in sources :

Example 26 with Uuid

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid in project netvirt by opendaylight.

the class ExternalNetworkGroupInstaller method installExtNetGroupEntries.

public void installExtNetGroupEntries(Uuid subnetId, String macAddress) {
    Subnetmap subnetMap = NatUtil.getSubnetMap(broker, subnetId);
    if (subnetMap == null) {
        LOG.error("installExtNetGroupEntries : Subnetmap is null");
        return;
    }
    if (NatUtil.isIPv6Subnet(subnetMap.getSubnetIp())) {
        LOG.debug("installExtNetGroupEntries : Subnet-id {} is not an IPv4 subnet, hence skipping.", subnetMap.getId());
        return;
    }
    installExtNetGroupEntries(subnetMap, macAddress);
}
Also used : Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)

Example 27 with Uuid

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid in project netvirt by opendaylight.

the class ExternalNetworkGroupInstaller method installExtNetGroupEntries.

public void installExtNetGroupEntries(Uuid networkId, BigInteger dpnId) {
    if (networkId == null) {
        return;
    }
    List<Uuid> subnetIds = NatUtil.getSubnetIdsFromNetworkId(broker, networkId);
    if (subnetIds.isEmpty()) {
        LOG.error("installExtNetGroupEntries : No subnet ids associated network id {}", networkId.getValue());
        return;
    }
    for (Uuid subnetId : subnetIds) {
        String macAddress = NatUtil.getSubnetGwMac(broker, subnetId, networkId.getValue());
        installExtNetGroupEntry(networkId, subnetId, dpnId, macAddress);
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)

Example 28 with Uuid

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid in project netvirt by opendaylight.

the class ExternalNetworksChangeListener method update.

@Override
protected void update(InstanceIdentifier<Networks> identifier, Networks original, Networks update) {
    // Check for VPN disassociation
    Uuid originalVpn = original.getVpnid();
    Uuid updatedVpn = update.getVpnid();
    coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + update.getKey(), () -> {
        WriteTransaction writeFlowInvTx = dataBroker.newWriteOnlyTransaction();
        List<ListenableFuture<Void>> futures = new ArrayList<>();
        if (originalVpn == null && updatedVpn != null) {
            // external network is dis-associated from L3VPN instance
            associateExternalNetworkWithVPN(update, writeFlowInvTx);
        } else if (originalVpn != null && updatedVpn == null) {
            // external network is associated with vpn
            disassociateExternalNetworkFromVPN(update, originalVpn.getValue());
            // Remove the SNAT entries
            removeSnatEntries(original, original.getId(), writeFlowInvTx);
        }
        futures.add(NatUtil.waitForTransactionToComplete(writeFlowInvTx));
        return futures;
    }, NatConstants.NAT_DJC_MAX_RETRIES);
}
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) ArrayList(java.util.ArrayList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture)

Example 29 with Uuid

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid in project netvirt by opendaylight.

the class ExternalNetworksChangeListener method disassociateExternalNetworkFromVPN.

private void disassociateExternalNetworkFromVPN(Networks network, String vpnName) {
    List<Uuid> routerIds = network.getRouterIds();
    for (Uuid routerId : routerIds) {
        InstanceIdentifier<RouterPorts> routerPortsId = NatUtil.getRouterPortsId(routerId.getValue());
        Optional<RouterPorts> optRouterPorts = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsId);
        if (!optRouterPorts.isPresent()) {
            LOG.debug("disassociateExternalNetworkFromVPN : Could not read Router Ports data object with id: {} " + "to handle disassociate ext nw {}", routerId, network.getId());
            continue;
        }
        RouterPorts routerPorts = optRouterPorts.get();
        List<Ports> interfaces = routerPorts.getPorts();
        WriteTransaction removeFlowInvTx = dataBroker.newWriteOnlyTransaction();
        for (Ports port : interfaces) {
            String portName = port.getPortName();
            BigInteger dpnId = NatUtil.getDpnForInterface(interfaceManager, portName);
            if (dpnId.equals(BigInteger.ZERO)) {
                LOG.debug("disassociateExternalNetworkFromVPN : DPN not found for {}," + "skip handling of ext nw {} disassociation", portName, network.getId());
                continue;
            }
            List<InternalToExternalPortMap> intExtPortMapList = port.getInternalToExternalPortMap();
            for (InternalToExternalPortMap intExtPortMap : intExtPortMapList) {
                floatingIpListener.removeNATFlowEntries(dpnId, portName, vpnName, routerId.getValue(), intExtPortMap, removeFlowInvTx);
            }
        }
        NatUtil.waitForTransactionToComplete(removeFlowInvTx);
    }
}
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) RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) 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) BigInteger(java.math.BigInteger) InternalToExternalPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap)

Example 30 with Uuid

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid in project netvirt by opendaylight.

the class ExternalNetworksChangeListener method associateExternalNetworkWithVPN.

private void associateExternalNetworkWithVPN(Networks network, WriteTransaction writeFlowInvTx) {
    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 = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsId);
        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();
        List<Ports> interfaces = routerPorts.getPorts();
        for (Ports port : interfaces) {
            String portName = port.getPortName();
            BigInteger dpnId = NatUtil.getDpnForInterface(interfaceManager, portName);
            if (dpnId.equals(BigInteger.ZERO)) {
                LOG.debug("associateExternalNetworkWithVPN : DPN not found for {}, " + "skip handling of ext nw {} association", portName, network.getId());
                continue;
            }
            List<InternalToExternalPortMap> intExtPortMapList = port.getInternalToExternalPortMap();
            for (InternalToExternalPortMap ipMap : intExtPortMapList) {
                // remove all VPN related entries
                floatingIpListener.createNATFlowEntries(dpnId, portName, routerId.getValue(), network.getId(), ipMap, writeFlowInvTx);
            }
        }
    }
    // 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;
        }
        BigInteger dpnId = new BigInteger("0");
        InstanceIdentifier<RouterToNaptSwitch> routerToNaptSwitch = NatUtil.buildNaptSwitchRouterIdentifier(routerId.getValue());
        Optional<RouterToNaptSwitch> rtrToNapt = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, routerToNaptSwitch);
        if (rtrToNapt.isPresent()) {
            dpnId = rtrToNapt.get().getPrimarySwitchId();
        }
        LOG.debug("associateExternalNetworkWithVPN : got primarySwitch as dpnId{} ", dpnId);
        if (dpnId == null || dpnId.equals(BigInteger.ZERO)) {
            LOG.warn("associateExternalNetworkWithVPN : primary napt Switch not found for router {} on dpn: {}", routerId, dpnId);
            return;
        }
        Long 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()) {
            List<IpMap> ipMaps = ipMapping.get().getIpMap();
            for (IpMap ipMap : ipMaps) {
                String externalIp = ipMap.getExternalIp();
                LOG.debug("associateExternalNetworkWithVPN : Calling advToBgpAndInstallFibAndTsFlows for dpnId {}," + "vpnName {} and externalIp {}", dpnId, vpnName, externalIp);
                if (natMode == NatMode.Controller) {
                    externalRouterListener.advToBgpAndInstallFibAndTsFlows(dpnId, NwConstants.INBOUND_NAPT_TABLE, vpnName, routerIdentifier, routerId.getValue(), externalIp, network.getId(), null, /* external-router */
                    writeFlowInvTx);
                }
            }
        } else {
            LOG.warn("associateExternalNetworkWithVPN : No ipMapping present fot the routerId {}", routerId);
        }
        long vpnId = NatUtil.getVpnId(dataBroker, vpnName);
        // Install 47 entry to point to 21
        if (natMode == NatMode.Controller) {
            externalRouterListener.installNaptPfibEntriesForExternalSubnets(routerId.getValue(), dpnId, writeFlowInvTx);
            if (vpnId != -1) {
                LOG.debug("associateExternalNetworkWithVPN : Calling externalRouterListener installNaptPfibEntry " + "for dpnId {} and vpnId {}", dpnId, vpnId);
                externalRouterListener.installNaptPfibEntry(dpnId, vpnId, writeFlowInvTx);
            }
        }
    }
}
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) InternalToExternalPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap) 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) BigInteger(java.math.BigInteger)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)283 ArrayList (java.util.ArrayList)114 BigInteger (java.math.BigInteger)79 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)55 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)53 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)52 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)48 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)40 ExecutionException (java.util.concurrent.ExecutionException)35 Port (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port)32 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)29 Network (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network)27 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)25 HashSet (java.util.HashSet)23 List (java.util.List)23 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)23 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)22 VpnInterface (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface)19 Optional (com.google.common.base.Optional)17 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)17