Search in sources :

Example 6 with RouterIds

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.id.name.RouterIds in project netvirt by opendaylight.

the class NeutronvpnNatManager method addRouterIdToExternalSubnet.

public void addRouterIdToExternalSubnet(Uuid networkId, Uuid subnetId, Uuid routerId) {
    Optional<Subnets> optionalExternalSubnets = neutronvpnUtils.getOptionalExternalSubnets(subnetId);
    if (optionalExternalSubnets.isPresent()) {
        Subnets subnets = optionalExternalSubnets.get();
        List<Uuid> routerIds;
        if (subnets.getRouterIds() != null) {
            routerIds = subnets.getRouterIds();
        } else {
            routerIds = new ArrayList<>();
        }
        if (subnets.getExternalNetworkId() != null && subnets.getExternalNetworkId().equals(networkId) && !routerIds.contains(routerId)) {
            LOG.debug("Will add routerID {} for external subnet {}.", routerId, subnetId);
            routerIds.add(routerId);
            updateExternalSubnet(networkId, subnetId, routerIds);
        }
    }
}
Also used : ExternalSubnets(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalSubnets) Subnets(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.Subnets) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)

Example 7 with RouterIds

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.id.name.RouterIds in project netvirt by opendaylight.

the class NeutronvpnNatManager method createSubnets.

private Subnets createSubnets(Uuid subnetId, Uuid networkId, List<Uuid> routerIds) {
    SubnetsBuilder subnetsBuilder = new SubnetsBuilder();
    subnetsBuilder.setKey(new SubnetsKey(subnetId));
    subnetsBuilder.setId(subnetId);
    subnetsBuilder.setVpnId(subnetId);
    subnetsBuilder.setExternalNetworkId(networkId);
    if (routerIds != null) {
        subnetsBuilder.setRouterIds(routerIds);
    }
    return subnetsBuilder.build();
}
Also used : SubnetsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.SubnetsKey) SubnetsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.SubnetsBuilder)

Example 8 with RouterIds

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.id.name.RouterIds in project netvirt by opendaylight.

the class NeutronvpnNatManager method updateExternalSubnet.

public void updateExternalSubnet(Uuid networkId, Uuid subnetId, List<Uuid> routerIds) {
    InstanceIdentifier<Subnets> subnetsIdentifier = InstanceIdentifier.builder(ExternalSubnets.class).child(Subnets.class, new SubnetsKey(subnetId)).build();
    try {
        Subnets newExternalSubnets = createSubnets(subnetId, networkId, routerIds);
        LOG.debug("Updating external subnet {}", newExternalSubnets);
        SingleTransactionDataBroker.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION, subnetsIdentifier, newExternalSubnets);
    } catch (TransactionCommitFailedException ex) {
        LOG.error("Update of External Subnets {} failed", subnetId, ex);
    }
}
Also used : SubnetsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.SubnetsKey) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ExternalSubnets(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalSubnets) Subnets(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.Subnets)

Example 9 with RouterIds

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.id.name.RouterIds in project netvirt by opendaylight.

the class NeutronExternalSubnetHandler method handleExternalSubnetAdded.

public void handleExternalSubnetAdded(Network network, Uuid subnetId, List<Uuid> routerIds) {
    Uuid networkId = network.getUuid();
    if (NeutronvpnUtils.getIsExternal(network) && NeutronvpnUtils.isFlatOrVlanNetwork(network)) {
        LOG.info("Added external subnet {} part of external network {} will create NAT external subnet", subnetId.getValue(), networkId.getValue());
        nvpnNatManager.updateOrAddExternalSubnet(networkId, subnetId, routerIds);
        nvpnManager.updateSubnetNode(subnetId, null, /* routerId */
        subnetId, null);
        nvpnManager.createVpnInstanceForSubnet(subnetId);
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)

Example 10 with RouterIds

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.id.name.RouterIds in project netvirt by opendaylight.

the class NeutronPortChangeListener method handleNeutronPortCreated.

private void handleNeutronPortCreated(final Port port) {
    final String portName = port.getUuid().getValue();
    final Uuid portId = port.getUuid();
    final List<FixedIps> portIpAddrsList = port.getFixedIps();
    if (NeutronConstants.IS_ODL_DHCP_PORT.test(port)) {
        return;
    }
    jobCoordinator.enqueueJob("PORT- " + portName, () -> {
        // add direct port to subnetMaps config DS
        if (!(NeutronUtils.isPortVnicTypeNormal(port) || (isPortTypeSwitchdev(port) && isSupportedVnicTypeByHost(port, NeutronConstants.VNIC_TYPE_DIRECT)))) {
            for (FixedIps ip : portIpAddrsList) {
                nvpnManager.updateSubnetmapNodeWithPorts(ip.getSubnetId(), null, portId);
            }
            LOG.info("Port {} is not a normal and not a direct with switchdev VNIC type ;" + "OF Port interfaces are not created", portName);
            return Collections.emptyList();
        }
        return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
            LOG.info("Of-port-interface creation for port {}", portName);
            // Create of-port interface for this neutron port
            String portInterfaceName = createOfPortInterface(port, tx);
            LOG.debug("Creating ELAN Interface for port {}", portName);
            createElanInterface(port, portInterfaceName, tx);
            Set<Uuid> vpnIdList = new HashSet<>();
            Set<Uuid> routerIds = new HashSet<>();
            for (FixedIps ip : portIpAddrsList) {
                Subnetmap subnetMap = nvpnManager.updateSubnetmapNodeWithPorts(ip.getSubnetId(), portId, null);
                if (subnetMap != null && subnetMap.getInternetVpnId() != null) {
                    if (!vpnIdList.contains(subnetMap.getInternetVpnId())) {
                        vpnIdList.add(subnetMap.getInternetVpnId());
                    }
                }
                if (subnetMap != null && subnetMap.getVpnId() != null) {
                    // can't use NeutronvpnUtils.getVpnForNetwork to optimise here, because it gives BGPVPN id
                    // obtained subnetMaps belongs to one network => vpnId must be the same for each port Ip
                    Uuid vpnId = subnetMap.getVpnId();
                    if (vpnId != null) {
                        vpnIdList.add(vpnId);
                    }
                }
                if (subnetMap != null && subnetMap.getRouterId() != null) {
                    routerIds.add(subnetMap.getRouterId());
                }
            }
            if (!vpnIdList.isEmpty()) {
                // create new vpn-interface for neutron port
                LOG.debug("handleNeutronPortCreated: Adding VPN Interface for port {} from network {}", portName, port.getNetworkId().toString());
                nvpnManager.createVpnInterface(vpnIdList, port, tx);
                if (!routerIds.isEmpty()) {
                    for (Uuid routerId : routerIds) {
                        nvpnManager.addToNeutronRouterInterfacesMap(routerId, port.getUuid().getValue());
                    }
                }
            }
        }));
    });
}
Also used : Ports(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports) JsonObject(com.google.gson.JsonObject) SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker) LoggerFactory(org.slf4j.LoggerFactory) InterfaceAcl(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.InterfaceAcl) PortBindingExtension(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.binding.rev150712.PortBindingExtension) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) RoutersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.RoutersBuilder) FixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps) Neutron(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron) IfL2vlanBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlanBuilder) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface) NeutronConstants(org.opendaylight.netvirt.neutronvpn.api.utils.NeutronConstants) AllowedAddressPairs(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.AllowedAddressPairs) Optional(com.google.common.base.Optional) Gson(com.google.gson.Gson) Locale(java.util.Locale) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) Hostconfig(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.hostconfigs.Hostconfig) Map(java.util.Map) MDSALUtil(org.opendaylight.genius.mdsalutil.MDSALUtil) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) ManagedNewTransactionRunner(org.opendaylight.genius.infra.ManagedNewTransactionRunner) NeutronUtils(org.opendaylight.netvirt.neutronvpn.api.utils.NeutronUtils) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) Set(java.util.Set) Collectors(java.util.stream.Collectors) WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) JsonArray(com.google.gson.JsonArray) List(java.util.List) Network(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network) PostConstruct(javax.annotation.PostConstruct) Router(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router) ElanInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterface) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) HashMap(java.util.HashMap) IElanService(org.opendaylight.netvirt.elanmanager.api.IElanService) Singleton(javax.inject.Singleton) IfL2vlan(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan) ArrayList(java.util.ArrayList) JsonElement(com.google.gson.JsonElement) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) ElanInterfaceBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterfaceBuilder) ManagedNewTransactionRunnerImpl(org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl) Logger(org.slf4j.Logger) ElanInterfaceKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterfaceKey) StaticMacEntries(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.elan._interface.StaticMacEntries) InterfaceAclBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.InterfaceAclBuilder) FloatingIpIdToPortMappingBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.port.info.FloatingIpIdToPortMappingBuilder) JobCoordinator(org.opendaylight.infrautils.jobcoordinator.JobCoordinator) AsyncDataTreeChangeListenerBase(org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase) L2vlan(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.L2vlan) NeutronvpnUtils.buildfloatingIpIdToPortMappingIdentifier(org.opendaylight.netvirt.neutronvpn.NeutronvpnUtils.buildfloatingIpIdToPortMappingIdentifier) Port(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port) IpVersionChoice(org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice) InterfaceBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) ElanInterfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInterfaces) FloatingIpIdToPortMappingKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.port.info.FloatingIpIdToPortMappingKey) Collections(java.util.Collections) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Set(java.util.Set) HashSet(java.util.HashSet) 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)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)10 BigInteger (java.math.BigInteger)4 ExternalSubnets (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalSubnets)4 Subnets (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.Subnets)4 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)3 SubnetsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.SubnetsKey)3 RouterIds (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.id.name.RouterIds)3 RouterIdsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.id.name.RouterIdsBuilder)3 RouterIdsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.id.name.RouterIdsKey)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)2 RouterPorts (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts)2 Ports (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.Ports)2 InternalToExternalPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap)2 Optional (com.google.common.base.Optional)1 Strings (com.google.common.base.Strings)1 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1