Search in sources :

Example 21 with Ports

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.Ports in project netvirt by opendaylight.

the class NeutronvpnManager method createPortIpAdjacencies.

protected Adjacencies createPortIpAdjacencies(Port port, Boolean isRouterInterface, WriteTransaction wrtConfigTxn, Subnetmap sn, VpnInterface vpnIface) {
    List<Adjacency> adjList = new ArrayList<>();
    if (vpnIface != null) {
        adjList = vpnIface.getAugmentation(Adjacencies.class).getAdjacency();
    }
    String infName = port.getUuid().getValue();
    LOG.trace("neutronVpnManager: create config adjacencies for Port: {}", infName);
    for (FixedIps ip : port.getFixedIps()) {
        String ipValue = String.valueOf(ip.getIpAddress().getValue());
        String ipPrefix = ip.getIpAddress().getIpv4Address() != null ? ipValue + "/32" : ipValue + "/128";
        if (sn != null && !FibHelper.doesPrefixBelongToSubnet(ipPrefix, sn.getSubnetIp(), false)) {
            continue;
        }
        Adjacency vmAdj = new AdjacencyBuilder().setKey(new AdjacencyKey(ipPrefix)).setIpAddress(ipPrefix).setMacAddress(port.getMacAddress().getValue()).setAdjacencyType(AdjacencyType.PrimaryAdjacency).setSubnetId(ip.getSubnetId()).build();
        if (!adjList.contains(vmAdj)) {
            adjList.add(vmAdj);
        }
        Subnetmap snTemp = sn != null ? sn : neutronvpnUtils.getSubnetmap(ip.getSubnetId());
        Uuid routerId = snTemp != null ? snTemp.getRouterId() : null;
        Uuid vpnId = snTemp != null ? snTemp.getVpnId() : null;
        if (vpnId != null) {
            neutronvpnUtils.createVpnPortFixedIpToPort(vpnId.getValue(), ipValue, infName, port.getMacAddress().getValue(), isRouterInterface, wrtConfigTxn);
        }
        if (snTemp != null && snTemp.getInternetVpnId() != null) {
            neutronvpnUtils.createVpnPortFixedIpToPort(sn.getInternetVpnId().getValue(), ipValue, infName, port.getMacAddress().getValue(), isRouterInterface, wrtConfigTxn);
        }
        if (routerId != null) {
            Router rtr = neutronvpnUtils.getNeutronRouter(routerId);
            if (rtr != null && rtr.getRoutes() != null) {
                List<Routes> routeList = rtr.getRoutes();
                // create extraroute Adjacence for each ipValue,
                // because router can have IPv4 and IPv6 subnet ports, or can have
                // more that one IPv4 subnet port or more than one IPv6 subnet port
                List<Adjacency> erAdjList = getAdjacencyforExtraRoute(routeList, ipValue);
                if (!erAdjList.isEmpty()) {
                    adjList.addAll(erAdjList);
                }
            }
        }
    }
    return new AdjacenciesBuilder().setAdjacency(adjList).build();
}
Also used : AdjacencyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.AdjacencyBuilder) AdjacencyKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.AdjacencyKey) ArrayList(java.util.ArrayList) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) Router(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.l3.attributes.Routes) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) AdjacenciesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesBuilder) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency) FixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps)

Example 22 with Ports

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.Ports in project netvirt by opendaylight.

the class NeutronvpnManager method removeExternalVpnInterfaces.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected void removeExternalVpnInterfaces(Uuid extNetId) {
    Collection<String> extElanInterfaces = elanService.getExternalElanInterfaces(extNetId.getValue());
    if (extElanInterfaces == null || extElanInterfaces.isEmpty()) {
        LOG.error("No external ports attached for external network {}", extNetId.getValue());
        return;
    }
    try {
        WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
        for (String elanInterface : extElanInterfaces) {
            InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(elanInterface);
            LOG.info("Removing vpn interface {}", elanInterface);
            wrtConfigTxn.delete(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
        }
        wrtConfigTxn.submit();
    } catch (Exception ex) {
        LOG.error("Removal of vpninterfaces {} failed", extElanInterfaces, ex);
    }
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) VpnInterface(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ExecutionException(java.util.concurrent.ExecutionException) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)

Example 23 with Ports

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.Ports 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 24 with Ports

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.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) {
    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 25 with Ports

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.Ports in project netvirt by opendaylight.

the class NeutronFloatingToFixedIpMappingChangeListener method addToFloatingIpInfo.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void addToFloatingIpInfo(String routerName, Uuid extNetworkId, String fixedNeutronPortName, String fixedIpAddress, String floatingIpAddress, Uuid floatingIpId) {
    RouterPortsBuilder routerPortsBuilder;
    boolean isLockAcquired = false;
    InstanceIdentifier<RouterPorts> routerPortsIdentifier = InstanceIdentifier.builder(FloatingIpInfo.class).child(RouterPorts.class, new RouterPortsKey(routerName)).build();
    try {
        Optional<RouterPorts> optionalRouterPorts = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsIdentifier);
        if (optionalRouterPorts.isPresent()) {
            LOG.debug("Updating routerPorts node {} in floatingIpInfo DS for floating IP {} on fixed " + "neutron port {} : ", routerName, floatingIpAddress, fixedNeutronPortName);
            routerPortsBuilder = new RouterPortsBuilder(optionalRouterPorts.get());
        } else {
            LOG.debug("Creating new routerPorts node {} in floatingIpInfo DS for floating IP {} on fixed " + "neutron port {} : ", routerName, floatingIpAddress, fixedNeutronPortName);
            routerPortsBuilder = new RouterPortsBuilder().setKey(new RouterPortsKey(routerName)).setRouterId(routerName);
        }
        if (extNetworkId != null) {
            routerPortsBuilder.setExternalNetworkId(extNetworkId);
        }
        if (fixedNeutronPortName != null) {
            List<Ports> portsList = routerPortsBuilder.getPorts();
            if (portsList == null) {
                portsList = new ArrayList<>();
            }
            PortsBuilder fixedNeutronPortBuilder = null;
            for (Ports neutronPort : portsList) {
                if (neutronPort.getPortName().equals(fixedNeutronPortName)) {
                    fixedNeutronPortBuilder = new PortsBuilder(neutronPort);
                    break;
                }
            }
            if (fixedNeutronPortBuilder == null) {
                fixedNeutronPortBuilder = new PortsBuilder().setKey(new PortsKey(fixedNeutronPortName)).setPortName(fixedNeutronPortName);
            }
            if (fixedIpAddress != null) {
                List<InternalToExternalPortMap> intExtPortMapList = fixedNeutronPortBuilder.getInternalToExternalPortMap();
                if (intExtPortMapList == null) {
                    intExtPortMapList = new ArrayList<>();
                }
                InternalToExternalPortMap intExtPortMap = new InternalToExternalPortMapBuilder().setKey(new InternalToExternalPortMapKey(fixedIpAddress)).setInternalIp(fixedIpAddress).setExternalIp(floatingIpAddress).setExternalId(floatingIpId).setLabel(null).build();
                intExtPortMapList.add(intExtPortMap);
                fixedNeutronPortBuilder.setInternalToExternalPortMap(intExtPortMapList);
            }
            portsList.add(fixedNeutronPortBuilder.build());
            routerPortsBuilder.setPorts(portsList);
        }
        isLockAcquired = routerLock.tryLock(routerName, LOCK_WAIT_TIME, TimeUnit.SECONDS);
        LOG.debug("Creating/Updating routerPorts node {} in floatingIpInfo DS for floating IP {} on fixed " + "neutron port {} : ", routerName, floatingIpAddress, fixedNeutronPortName);
        MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsIdentifier, routerPortsBuilder.build());
        LOG.debug("FloatingIpInfo DS updated for floating IP {} ", floatingIpAddress);
    } catch (ReadFailedException | RuntimeException e) {
        LOG.error("addToFloatingIpInfo failed for floating IP: {} ", floatingIpAddress, e);
    } finally {
        if (isLockAcquired) {
            routerLock.unlock(routerName);
        }
    }
}
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) 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) InternalToExternalPortMapBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMapBuilder) RouterPortsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPortsBuilder) RouterPortsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPortsBuilder) PortsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.PortsBuilder) 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)

Aggregations

ArrayList (java.util.ArrayList)29 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)21 BigInteger (java.math.BigInteger)16 Ports (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.Ports)13 RouterPorts (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts)12 Test (org.junit.Test)11 InternalToExternalPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap)11 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)9 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)8 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)8 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)7 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)7 Port (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port)7 ExecutionException (java.util.concurrent.ExecutionException)6 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 ByteBuf (io.netty.buffer.ByteBuf)5 HashSet (java.util.HashSet)4 NodeConnectorId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId)4 RouterPortsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPortsKey)4 Ports (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc._case.multipart.reply.port.desc.Ports)4