Search in sources :

Example 91 with Router

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router in project netvirt by opendaylight.

the class NeutronFloatingToFixedIpMappingChangeListener method dissociatefixedIPFromFloatingIP.

protected void dissociatefixedIPFromFloatingIP(String fixedNeutronPortName) {
    boolean isLockAcquired = false;
    InstanceIdentifier.InstanceIdentifierBuilder<FloatingIpInfo> floatingIpInfoIdentifierBuilder = InstanceIdentifier.builder(FloatingIpInfo.class);
    try {
        Optional<FloatingIpInfo> optionalFloatingIPInfo = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, floatingIpInfoIdentifierBuilder.build());
        if (optionalFloatingIPInfo.isPresent()) {
            List<RouterPorts> routerPortsList = optionalFloatingIPInfo.get().getRouterPorts();
            if (routerPortsList != null && !routerPortsList.isEmpty()) {
                for (RouterPorts routerPorts : routerPortsList) {
                    List<Ports> portsList = routerPorts.getPorts();
                    if (portsList != null && !portsList.isEmpty()) {
                        for (Ports ports : portsList) {
                            if (ports.getPortName().equals(fixedNeutronPortName)) {
                                String routerName = routerPorts.getRouterId();
                                InstanceIdentifier.InstanceIdentifierBuilder<RouterPorts> routerPortsIdentifierBuilder = floatingIpInfoIdentifierBuilder.child(RouterPorts.class, new RouterPortsKey(routerName));
                                removeRouterPortsOrPortsNode(routerName, routerPortsIdentifierBuilder, portsList, fixedNeutronPortName, isLockAcquired);
                                LOG.debug("Deletion from FloatingIpInfo DS successful for fixedIP neutron port {} ", fixedNeutronPortName);
                                break;
                            }
                        }
                    }
                }
            } else {
                LOG.debug("No router present containing fixed to floating IP association(s)");
            }
        } else {
            LOG.debug("FloatingIPInfo DS empty. Hence, no router present containing fixed to floating IP " + "association(s)");
        }
    } catch (ReadFailedException e) {
        LOG.error("Failed to dissociate fixedIP from FloatingIpInfo DS for neutron port {}", fixedNeutronPortName, e);
    }
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) RouterPortsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPortsKey) 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) FloatingIpInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.FloatingIpInfo) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier)

Example 92 with Router

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router in project netvirt by opendaylight.

the class NeutronFloatingToFixedIpMappingChangeListener method clearFromFloatingIpInfo.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void clearFromFloatingIpInfo(String routerName, String fixedNeutronPortName, String fixedIpAddress) {
    boolean isLockAcquired = false;
    InstanceIdentifier.InstanceIdentifierBuilder<RouterPorts> routerPortsIdentifierBuilder = InstanceIdentifier.builder(FloatingIpInfo.class).child(RouterPorts.class, new RouterPortsKey(routerName));
    try {
        Optional<RouterPorts> optionalRouterPorts = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsIdentifierBuilder.build());
        if (optionalRouterPorts.isPresent()) {
            RouterPorts routerPorts = optionalRouterPorts.get();
            List<Ports> portsList = routerPorts.getPorts();
            List<InternalToExternalPortMap> intExtPortMap = new ArrayList<>();
            for (Ports ports : portsList) {
                if (ports.getPortName().equals(fixedNeutronPortName)) {
                    intExtPortMap = ports.getInternalToExternalPortMap();
                    break;
                }
            }
            if (intExtPortMap.size() == 1) {
                removeRouterPortsOrPortsNode(routerName, routerPortsIdentifierBuilder, portsList, fixedNeutronPortName, isLockAcquired);
            } else {
                for (InternalToExternalPortMap intToExtMap : intExtPortMap) {
                    if (intToExtMap.getInternalIp().equals(fixedIpAddress)) {
                        InstanceIdentifier<InternalToExternalPortMap> intExtPortMapIdentifier = routerPortsIdentifierBuilder.child(Ports.class, new PortsKey(fixedNeutronPortName)).child(InternalToExternalPortMap.class, new InternalToExternalPortMapKey(fixedIpAddress)).build();
                        try {
                            // remove particular internal-to-external-port-map
                            isLockAcquired = routerLock.tryLock(fixedIpAddress, LOCK_WAIT_TIME, TimeUnit.SECONDS);
                            LOG.debug("removing particular internal-to-external-port-map {}", intExtPortMap);
                            MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, intExtPortMapIdentifier);
                        } catch (Exception e) {
                            LOG.error("Failure in deletion of internal-to-external-port-map {}", intExtPortMap, e);
                        } finally {
                            if (isLockAcquired) {
                                routerLock.unlock(fixedIpAddress);
                            }
                        }
                    }
                }
            }
            LOG.debug("Deletion from FloatingIpInfo DS successful for fixedIp {} ", fixedIpAddress);
        } else {
            LOG.warn("routerPorts for router {} - fixedIp {} not found", routerName, fixedIpAddress);
        }
    } catch (RuntimeException | ReadFailedException e) {
        LOG.error("Failed to delete internal-to-external-port-map from FloatingIpInfo DS for fixed Ip {}", fixedIpAddress, e);
    }
}
Also used : InternalToExternalPortMapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMapKey) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) RouterPortsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPortsKey) RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) ArrayList(java.util.ArrayList) 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) FloatingIpInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.FloatingIpInfo) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) InternalToExternalPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap) PortsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.PortsKey) RouterPortsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPortsKey)

Example 93 with Router

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router in project netvirt by opendaylight.

the class NeutronPortChangeListener method setExternalGwMac.

private void setExternalGwMac(Port routerGwPort, Uuid routerId) {
    // During full-sync networking-odl syncs routers before ports. As such,
    // the MAC of the router's gw port is not available to be set when the
    // router is written. We catch that here.
    InstanceIdentifier<Routers> routersId = NeutronvpnUtils.buildExtRoutersIdentifier(routerId);
    Optional<Routers> optionalRouter = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, routersId);
    if (!optionalRouter.isPresent()) {
        return;
    }
    Routers extRouters = optionalRouter.get();
    if (extRouters.getExtGwMacAddress() != null) {
        return;
    }
    RoutersBuilder builder = new RoutersBuilder(extRouters);
    builder.setExtGwMacAddress(routerGwPort.getMacAddress().getValue());
    MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routersId, builder.build());
}
Also used : RoutersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.RoutersBuilder) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)

Example 94 with Router

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router in project netvirt by opendaylight.

the class NeutronPortChangeListener method handleRouterInterfaceRemoved.

private void handleRouterInterfaceRemoved(Port routerPort) {
    if (routerPort.getDeviceId() != null) {
        Uuid routerId = new Uuid(routerPort.getDeviceId());
        Uuid infNetworkId = routerPort.getNetworkId();
        elanService.removeKnownL3DmacAddress(routerPort.getMacAddress().getValue(), infNetworkId.getValue());
        Uuid vpnId = neutronvpnUtils.getVpnForRouter(routerId, true);
        if (vpnId == null) {
            vpnId = routerId;
        }
        List<FixedIps> portIps = routerPort.getFixedIps();
        boolean vpnInstanceInternetIpVersionRemoved = false;
        Uuid vpnInstanceInternetUuid = null;
        for (FixedIps portIP : portIps) {
            // Internet VPN : flush InternetVPN first
            Uuid subnetId = portIP.getSubnetId();
            Subnetmap sn = neutronvpnUtils.getSubnetmap(subnetId);
            if (sn != null && sn.getInternetVpnId() != null) {
                if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToRemove(sn, sn.getInternetVpnId())) {
                    vpnInstanceInternetIpVersionRemoved = true;
                    vpnInstanceInternetUuid = sn.getInternetVpnId();
                }
                nvpnManager.updateVpnInternetForSubnet(sn, sn.getInternetVpnId(), false);
            }
        }
        /* Remove ping responder for router interfaces
             *  A router interface reference in a VPN will have to be removed before the host interface references
             * for that subnet in the VPN are removed. This is to ensure that the FIB Entry of the router interface
             *  is not the last entry to be removed for that subnet in the VPN.
             *  If router interface FIB entry is the last to be removed for a subnet in a VPN , then all the host
             *  interface references in the vpn will already have been cleared, which will cause failures in
             *  cleanup of router interface flows*/
        nvpnManager.deleteVpnInterface(routerPort.getUuid().getValue(), null, /* vpn-id */
        null);
        // update RouterInterfaces map
        WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
        boolean vpnInstanceIpVersionRemoved = false;
        IpVersionChoice vpnInstanceIpVersionToRemove = IpVersionChoice.UNDEFINED;
        for (FixedIps portIP : portIps) {
            Subnetmap sn = neutronvpnUtils.getSubnetmap(portIP.getSubnetId());
            // router Port have either IPv4 or IPv6, never both
            if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToRemove(sn, vpnId)) {
                vpnInstanceIpVersionRemoved = true;
                vpnInstanceIpVersionToRemove = neutronvpnUtils.getIpVersionFromString(sn.getSubnetIp());
            }
            String ipValue = String.valueOf(portIP.getIpAddress().getValue());
            neutronvpnUtils.removeVpnPortFixedIpToPort(vpnId.getValue(), ipValue, wrtConfigTxn);
            // NOTE:  Please donot change the order of calls to removeSubnetFromVpn and
            // and updateSubnetNodeWithFixedIP
            nvpnManager.removeSubnetFromVpn(vpnId, portIP.getSubnetId(), sn != null ? sn.getInternetVpnId() : null);
            nvpnManager.updateSubnetNodeWithFixedIp(portIP.getSubnetId(), null, null, null, null, null);
        }
        nvpnManager.removeFromNeutronRouterInterfacesMap(routerId, routerPort.getUuid().getValue());
        deleteElanInterface(routerPort.getUuid().getValue(), wrtConfigTxn);
        deleteOfPortInterface(routerPort, wrtConfigTxn);
        wrtConfigTxn.submit();
        nvpnNatManager.handleSubnetsForExternalRouter(routerId);
        if (vpnInstanceIpVersionRemoved) {
            neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), vpnInstanceIpVersionToRemove, false);
        }
        if (vpnInstanceInternetIpVersionRemoved) {
            neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnInstanceInternetUuid.getValue(), IpVersionChoice.IPV6, false);
            neutronvpnUtils.updateVpnInstanceWithFallback(vpnInstanceInternetUuid.getValue(), false);
        }
    }
}
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) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) FixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps) IpVersionChoice(org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)

Example 95 with Router

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router in project netvirt by opendaylight.

the class NeutronPortChangeListener method handleRouterInterfaceAdded.

private void handleRouterInterfaceAdded(Port routerPort) {
    if (routerPort.getDeviceId() != null) {
        Uuid routerId = new Uuid(routerPort.getDeviceId());
        Uuid infNetworkId = routerPort.getNetworkId();
        Uuid existingVpnId = neutronvpnUtils.getVpnForNetwork(infNetworkId);
        elanService.addKnownL3DmacAddress(routerPort.getMacAddress().getValue(), infNetworkId.getValue());
        if (existingVpnId == null) {
            Set<Uuid> listVpnIds = new HashSet<>();
            Uuid vpnId = neutronvpnUtils.getVpnForRouter(routerId, true);
            if (vpnId == null) {
                vpnId = routerId;
            }
            listVpnIds.add(vpnId);
            Uuid internetVpnId = neutronvpnUtils.getInternetvpnUuidBoundToRouterId(routerId);
            List<Subnetmap> subnetMapList = new ArrayList<>();
            List<FixedIps> portIps = routerPort.getFixedIps();
            boolean portIsIpv6 = false;
            for (FixedIps portIP : portIps) {
                // and addSubnetToVpn here
                if (internetVpnId != null && portIP.getIpAddress().getIpv6Address() != null) {
                    portIsIpv6 = true;
                }
                String ipValue = String.valueOf(portIP.getIpAddress().getValue());
                Uuid subnetId = portIP.getSubnetId();
                nvpnManager.updateSubnetNodeWithFixedIp(subnetId, routerId, routerPort.getUuid(), ipValue, routerPort.getMacAddress().getValue(), vpnId);
                Subnetmap sn = neutronvpnUtils.getSubnetmap(subnetId);
                subnetMapList.add(sn);
            }
            if (portIsIpv6) {
                listVpnIds.add(internetVpnId);
                if (neutronvpnUtils.shouldVpnHandleIpVersionChoiceChangeToAdd(IpVersionChoice.IPV6, internetVpnId)) {
                    neutronvpnUtils.updateVpnInstanceWithIpFamily(internetVpnId.getValue(), IpVersionChoice.IPV6, true);
                    neutronvpnUtils.updateVpnInstanceWithFallback(internetVpnId.getValue(), true);
                }
            }
            if (!subnetMapList.isEmpty()) {
                nvpnManager.createVpnInterface(listVpnIds, routerPort, null);
            }
            for (FixedIps portIP : routerPort.getFixedIps()) {
                String ipValue = String.valueOf(portIP.getIpAddress().getValue());
                IpVersionChoice version = neutronvpnUtils.getIpVersionFromString(ipValue);
                if (neutronvpnUtils.shouldVpnHandleIpVersionChoiceChangeToAdd(version, vpnId)) {
                    neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), version, true);
                }
                if (version.isIpVersionChosen(IpVersionChoice.IPV4)) {
                    nvpnManager.addSubnetToVpn(vpnId, portIP.getSubnetId(), null);
                } else {
                    nvpnManager.addSubnetToVpn(vpnId, portIP.getSubnetId(), internetVpnId);
                }
                LOG.trace("NeutronPortChangeListener Add Subnet Gateway IP {} MAC {} Interface {} VPN {}", ipValue, routerPort.getMacAddress(), routerPort.getUuid().getValue(), vpnId.getValue());
            }
            nvpnManager.addToNeutronRouterInterfacesMap(routerId, routerPort.getUuid().getValue());
            nvpnNatManager.handleSubnetsForExternalRouter(routerId);
            WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
            String portInterfaceName = createOfPortInterface(routerPort, wrtConfigTxn);
            createElanInterface(routerPort, portInterfaceName, wrtConfigTxn);
            wrtConfigTxn.submit();
        } else {
            LOG.error("Neutron network {} corresponding to router interface port {} for neutron router {}" + " already associated to VPN {}", infNetworkId.getValue(), routerPort.getUuid().getValue(), routerId.getValue(), existingVpnId.getValue());
        }
    }
}
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) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) FixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps) HashSet(java.util.HashSet) IpVersionChoice(org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)93 BigInteger (java.math.BigInteger)60 ArrayList (java.util.ArrayList)46 ExecutionException (java.util.concurrent.ExecutionException)27 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)24 Routers (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)24 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)23 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)21 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)20 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)20 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)19 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)15 ExternalIps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)14 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)13 UnknownHostException (java.net.UnknownHostException)12 Instruction (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction)12 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)11 RouterPorts (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts)11 List (java.util.List)10 InternalToExternalPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap)10