Search in sources :

Example 41 with Ports

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.Ports in project netvirt by opendaylight.

the class NeutronvpnManager method createSubnetmapNode.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected void createSubnetmapNode(Uuid subnetId, String subnetIp, Uuid tenantId, Uuid networkId, NetworkAttributes.@Nullable NetworkType networkType, long segmentationId, boolean isExternalNw) {
    try {
        InstanceIdentifier<Subnetmap> subnetMapIdentifier = NeutronvpnUtils.buildSubnetMapIdentifier(subnetId);
        final ReentrantLock lock = lockForUuid(subnetId);
        lock.lock();
        try {
            LOG.info("createSubnetmapNode: subnet ID {}", subnetId.getValue());
            Optional<Subnetmap> sn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, subnetMapIdentifier);
            if (sn.isPresent()) {
                LOG.error("createSubnetmapNode: Subnetmap node for subnet ID {} already exists, returning", subnetId.getValue());
                return;
            }
            SubnetmapBuilder subnetmapBuilder = new SubnetmapBuilder().withKey(new SubnetmapKey(subnetId)).setId(subnetId).setSubnetIp(subnetIp).setTenantId(tenantId).setNetworkId(networkId).setNetworkType(networkType).setSegmentationId(segmentationId).setExternal(isExternalNw);
            LOG.debug("createSubnetmapNode: Adding a new subnet node in Subnetmaps DS for subnet {}", subnetId.getValue());
            SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, subnetMapIdentifier, subnetmapBuilder.build());
        } finally {
            lock.unlock();
        }
    } catch (TransactionCommitFailedException | ExecutionException | InterruptedException e) {
        LOG.error("createSubnetmapNode: Creating subnetmap node failed for subnet {}", subnetId.getValue());
    }
    // check if there are ports to update for already created Subnetmap node
    LOG.debug("createSubnetmapNode: Update created Subnetmap for subnet {} with ports", subnetId.getValue());
    for (Map.Entry<Uuid, Uuid> entry : unprocessedPortsMap.entrySet()) {
        if (entry.getValue().getValue().equals(subnetId.getValue())) {
            updateSubnetmapNodeWithPorts(subnetId, entry.getKey(), null);
            unprocessedPortsMap.remove(entry.getKey());
        }
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) SubnetmapBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapBuilder) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) SubnetmapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapKey) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map) VpnMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) RouterInterfacesMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.RouterInterfacesMap)

Example 42 with Ports

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.Ports 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 = null;
    try {
        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());
    } catch (ExecutionException | InterruptedException e) {
        LOG.error("setExternalGwMac: failed to read EXT-Routers for router Id {} rout-Gw port {} due to exception", routerId, routerGwPort, e);
    }
}
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) ExecutionException(java.util.concurrent.ExecutionException)

Example 43 with Ports

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.Ports 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) {
    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();
            Map<PortsKey, Ports> keyPortsMap = routerPorts.nonnullPorts();
            Map<InternalToExternalPortMapKey, InternalToExternalPortMap> keyInternalToExternalPortMapMap = new HashMap<InternalToExternalPortMapKey, InternalToExternalPortMap>();
            for (Ports ports : keyPortsMap.values()) {
                if (Objects.equals(ports.getPortName(), fixedNeutronPortName)) {
                    keyInternalToExternalPortMapMap = ports.nonnullInternalToExternalPortMap();
                    break;
                }
            }
            if (keyInternalToExternalPortMapMap.size() == 1) {
                removeRouterPortsOrPortsNode(routerName, routerPortsIdentifierBuilder, new ArrayList<Ports>(keyPortsMap.values()), fixedNeutronPortName);
            } else {
                for (InternalToExternalPortMap intToExtMap : keyInternalToExternalPortMapMap.values()) {
                    if (Objects.equals(intToExtMap.getInternalIp(), fixedIpAddress)) {
                        InstanceIdentifier<InternalToExternalPortMap> intExtPortMapIdentifier = routerPortsIdentifierBuilder.child(Ports.class, new PortsKey(fixedNeutronPortName)).child(InternalToExternalPortMap.class, new InternalToExternalPortMapKey(fixedIpAddress)).build();
                        try (AcquireResult lock = tryRouterLock(fixedIpAddress)) {
                            if (!lock.wasAcquired()) {
                                // FIXME: why do we even bother with locking if we do not honor it?!
                                logTryLockFailure(fixedIpAddress);
                            }
                            // remove particular internal-to-external-port-map
                            LOG.debug("removing particular internal-to-external-port-map {}", keyInternalToExternalPortMapMap);
                            try {
                                MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, intExtPortMapIdentifier);
                            } catch (Exception e) {
                                LOG.error("Failure in deletion of internal-to-external-port-map {}", keyInternalToExternalPortMapMap, e);
                            }
                        }
                    }
                }
            }
            LOG.debug("Deletion from FloatingIpInfo DS successful for fixedIp {} ", fixedIpAddress);
        } else {
            LOG.warn("routerPorts for router {} - fixedIp {} not found", routerName, fixedIpAddress);
        }
    } catch (RuntimeException | ExecutionException | InterruptedException 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) HashMap(java.util.HashMap) 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) AcquireResult(org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult) FloatingIpInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.FloatingIpInfo) ExecutionException(java.util.concurrent.ExecutionException) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) ExecutionException(java.util.concurrent.ExecutionException) 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 44 with Ports

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.Ports in project netvirt by opendaylight.

the class NeutronFloatingToFixedIpMappingChangeListener method removeRouterPortsOrPortsNode.

private void removeRouterPortsOrPortsNode(String routerName, InstanceIdentifier.InstanceIdentifierBuilder<RouterPorts> routerPortsIdentifierBuilder, List<Ports> portsList, String fixedNeutronPortName) {
    if (portsList.size() == 1) {
        // remove entire routerPorts node
        try (AcquireResult lock = tryRouterLock(routerName)) {
            if (!lock.wasAcquired()) {
                // FIXME: why do we even bother with locking if we do not honor it?!
                logTryLockFailure(routerName);
            }
            LOG.debug("removing routerPorts node: {} ", routerName);
            MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsIdentifierBuilder.build());
        }
    } else {
        // remove entire ports node under this routerPorts node
        try (AcquireResult lock = tryRouterLock(fixedNeutronPortName)) {
            if (!lock.wasAcquired()) {
                // FIXME: why do we even bother with locking if we do not honor it?!
                logTryLockFailure(fixedNeutronPortName);
            }
            LOG.debug("removing ports node {} under routerPorts node {}", fixedNeutronPortName, routerName);
            MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsIdentifierBuilder.child(Ports.class, new PortsKey(fixedNeutronPortName)).build());
        }
    }
}
Also used : AcquireResult(org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult) 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 45 with Ports

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.Ports in project netvirt by opendaylight.

the class NeutronFloatingToFixedIpMappingChangeListener method dissociatefixedIPFromFloatingIP.

protected void dissociatefixedIPFromFloatingIP(String fixedNeutronPortName) {
    InstanceIdentifier.InstanceIdentifierBuilder<FloatingIpInfo> floatingIpInfoIdentifierBuilder = InstanceIdentifier.builder(FloatingIpInfo.class);
    try {
        Optional<FloatingIpInfo> optionalFloatingIPInfo = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, floatingIpInfoIdentifierBuilder.build());
        if (optionalFloatingIPInfo.isPresent()) {
            Map<RouterPortsKey, RouterPorts> keyRouterPortsMap = optionalFloatingIPInfo.get().getRouterPorts();
            if (keyRouterPortsMap != null && !keyRouterPortsMap.isEmpty()) {
                for (RouterPorts routerPorts : keyRouterPortsMap.values()) {
                    Map<PortsKey, Ports> keyPortsMap = routerPorts.getPorts();
                    if (keyPortsMap != null && !keyPortsMap.isEmpty()) {
                        for (Ports ports : keyPortsMap.values()) {
                            if (Objects.equals(ports.getPortName(), fixedNeutronPortName)) {
                                String routerName = routerPorts.getRouterId();
                                InstanceIdentifier.InstanceIdentifierBuilder<RouterPorts> routerPortsIdentifierBuilder = floatingIpInfoIdentifierBuilder.child(RouterPorts.class, new RouterPortsKey(routerName));
                                removeRouterPortsOrPortsNode(routerName, routerPortsIdentifierBuilder, new ArrayList<Ports>(keyPortsMap.values()), fixedNeutronPortName);
                                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 (ExecutionException | InterruptedException e) {
        LOG.error("Failed to dissociate fixedIP from FloatingIpInfo DS for neutron port {}", fixedNeutronPortName, e);
    }
}
Also used : 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) ExecutionException(java.util.concurrent.ExecutionException) 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)

Aggregations

ArrayList (java.util.ArrayList)36 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)32 ExecutionException (java.util.concurrent.ExecutionException)22 Ports (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.Ports)21 RouterPorts (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts)19 InternalToExternalPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap)18 Port (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port)13 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)13 BigInteger (java.math.BigInteger)11 Test (org.junit.Test)11 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)9 LearntVpnVipToPort (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort)9 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)9 PortsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.PortsKey)8 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)7 HashSet (java.util.HashSet)6 VpnPortipToPort (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPort)6 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 ByteBuf (io.netty.buffer.ByteBuf)5 HashMap (java.util.HashMap)5