Search in sources :

Example 6 with ExternalFixedIps

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

the class NeutronvpnNatManager method handleExternalNetworkForRouter.

public void handleExternalNetworkForRouter(Router original, Router update) {
    Uuid routerId = update.getUuid();
    Uuid origExtNetId = null;
    Uuid updExtNetId = null;
    List<ExternalFixedIps> origExtFixedIps;
    LOG.trace("handleExternalNetwork for router {}", routerId);
    int extNetChanged = externalNetworkChanged(original, update);
    if (extNetChanged != EXTERNAL_NO_CHANGE) {
        if (extNetChanged == EXTERNAL_ADDED) {
            updExtNetId = update.getExternalGatewayInfo().getExternalNetworkId();
            LOG.trace("External Network {} addition detected for router {}", updExtNetId.getValue(), routerId.getValue());
            addExternalNetworkToRouter(update);
            return;
        }
        if (extNetChanged == EXTERNAL_REMOVED) {
            origExtNetId = original.getExternalGatewayInfo().getExternalNetworkId();
            origExtFixedIps = original.getExternalGatewayInfo().getExternalFixedIps();
            LOG.trace("External Network removal detected for router {}", routerId.getValue());
            removeExternalNetworkFromRouter(origExtNetId, update, origExtFixedIps);
            // gateway mac unset handled as part of gateway clear deleting top-level routers node
            return;
        }
        origExtNetId = original.getExternalGatewayInfo().getExternalNetworkId();
        origExtFixedIps = original.getExternalGatewayInfo().getExternalFixedIps();
        updExtNetId = update.getExternalGatewayInfo().getExternalNetworkId();
        LOG.trace("External Network changed from {} to {} for router {}", origExtNetId.getValue(), updExtNetId.getValue(), routerId.getValue());
        removeExternalNetworkFromRouter(origExtNetId, update, origExtFixedIps);
        addExternalNetworkToRouter(update);
        return;
    }
    if (snatSettingChanged(original, update)) {
        LOG.trace("SNAT settings on gateway changed for router {}", routerId.getValue());
        handleSnatSettingChangeForRouter(update);
    }
    if (externalFixedIpsChanged(original, update)) {
        LOG.trace("External Fixed IPs changed for router {}", routerId.getValue());
        handleExternalFixedIpsForRouter(update);
    }
}
Also used : ExternalFixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router.external_gateway_info.ExternalFixedIps) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)

Example 7 with ExternalFixedIps

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

the class NeutronvpnNatManager method addExternalRouter.

public void addExternalRouter(Router update) {
    Uuid routerId = update.getUuid();
    Uuid extNetId = update.getExternalGatewayInfo().getExternalNetworkId();
    Uuid gatewayPortId = update.getGatewayPortId();
    // Create and add Routers object for this Router to the ExtRouters list
    // Create a Routers object
    InstanceIdentifier<Routers> routersIdentifier = NeutronvpnUtils.buildExtRoutersIdentifier(routerId);
    try {
        Network input = neutronvpnUtils.getNeutronNetwork(extNetId);
        ProviderTypes providerNwType = NeutronvpnUtils.getProviderNetworkType(input);
        if (providerNwType == null) {
            LOG.error("Unable to get Network Provider Type for network {}", input.getUuid().getValue());
            return;
        }
        Optional<Routers> optionalRouters = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier);
        LOG.trace("Creating/Updating a new Routers node: {}", routerId.getValue());
        RoutersBuilder builder = null;
        if (optionalRouters.isPresent()) {
            builder = new RoutersBuilder(optionalRouters.get());
        } else {
            builder = new RoutersBuilder().setKey(new RoutersKey(routerId.getValue()));
        }
        builder.setRouterName(routerId.getValue());
        builder.setNetworkId(extNetId);
        builder.setEnableSnat(update.getExternalGatewayInfo().isEnableSnat());
        ArrayList<ExternalIps> externalIps = new ArrayList<>();
        for (ExternalFixedIps fixedIps : update.getExternalGatewayInfo().getExternalFixedIps()) {
            addExternalFixedIpToExternalIpsList(externalIps, fixedIps);
        }
        builder.setExternalIps(externalIps);
        if (gatewayPortId != null) {
            LOG.trace("Setting/Updating gateway Mac for router {}", routerId.getValue());
            Port port = neutronvpnUtils.getNeutronPort(gatewayPortId);
            if (port != null && port.getDeviceOwner().equals(NeutronConstants.DEVICE_OWNER_GATEWAY_INF)) {
                builder.setExtGwMacAddress(port.getMacAddress().getValue());
            }
        }
        List<Uuid> subList = neutronvpnUtils.getNeutronRouterSubnetIds(routerId);
        builder.setSubnetIds(subList);
        Routers routers = builder.build();
        // Add Routers object to the ExtRouters list
        LOG.trace("Creating extrouters {}", routers);
        SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier, builder.build());
        LOG.trace("Wrote successfully Routers to CONFIG Datastore");
    } catch (ReadFailedException | TransactionCommitFailedException ex) {
        LOG.error("Creation of extrouters failed for router {} failed", routerId.getValue(), ex);
    }
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes) Port(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port) ArrayList(java.util.ArrayList) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps) RoutersKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.RoutersKey) ExternalFixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router.external_gateway_info.ExternalFixedIps) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) 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) Network(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network)

Example 8 with ExternalFixedIps

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

the class NeutronvpnNatManager method updateExternalSubnetsForRouter.

private void updateExternalSubnetsForRouter(Uuid routerId, Uuid externalNetworkId, List<ExternalFixedIps> externalFixedIps) {
    LOG.debug("Updating external subnets for router {} for external network ID {}", routerId, externalNetworkId);
    Set<Uuid> subnetsUuidsSet = getExternalSubnetsUuidsSetForFixedIps(externalFixedIps);
    for (Uuid subnetId : subnetsUuidsSet) {
        addRouterIdToExternalSubnet(externalNetworkId, subnetId, routerId);
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)

Example 9 with ExternalFixedIps

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

the class NeutronvpnNatManager method removeExternalNetworkFromRouter.

public void removeExternalNetworkFromRouter(Uuid origExtNetId, Router update, List<ExternalFixedIps> origExtFixedIps) {
    Uuid routerId = update.getUuid();
    // Remove the router to the ExtRouters list
    removeExternalRouter(update);
    // Remove router entry from floating-ip-info list
    removeRouterFromFloatingIpInfo(update, dataBroker);
    // Remove the router from External Subnets
    removeRouterFromExternalSubnets(routerId, origExtNetId, origExtFixedIps);
    // Remove the router from the ExternalNetworks list
    InstanceIdentifier<Networks> netsIdentifier = InstanceIdentifier.builder(ExternalNetworks.class).child(Networks.class, new NetworksKey(origExtNetId)).build();
    Optional<Networks> optionalNets = null;
    try {
        optionalNets = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier);
    } catch (ReadFailedException ex) {
        LOG.error("removeExternalNetworkFromRouter: Failed to remove provider network {} from router {}", origExtNetId.getValue(), routerId.getValue(), ex);
        return;
    }
    if (!optionalNets.isPresent()) {
        LOG.error("removeExternalNetworkFromRouter: Provider Network {} not present in the NVPN datamodel", origExtNetId.getValue());
        return;
    }
    Networks nets = optionalNets.get();
    try {
        NetworksBuilder builder = new NetworksBuilder(nets);
        List<Uuid> rtrList = builder.getRouterIds();
        if (rtrList != null) {
            rtrList.remove(routerId);
            builder.setRouterIds(rtrList);
            Networks networkss = builder.build();
            SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier, networkss);
            LOG.trace("removeExternalNetworkFromRouter: Remove router {} from External Networks node {}", routerId, origExtNetId.getValue());
        }
    } catch (TransactionCommitFailedException ex) {
        LOG.error("removeExternalNetworkFromRouter: Failed to remove provider network {} from router {}", origExtNetId.getValue(), routerId.getValue(), ex);
    }
    // Remove the vpnInternetId fromSubnetmap
    Network net = neutronvpnUtils.getNeutronNetwork(nets.getId());
    List<Uuid> submapIds = neutronvpnUtils.getPrivateSubnetsToExport(net);
    for (Uuid snId : submapIds) {
        Subnetmap subnetMap = neutronvpnUtils.getSubnetmap(snId);
        if ((subnetMap == null) || (subnetMap.getInternetVpnId() == null)) {
            LOG.error("removeExternalNetworkFromRouter: Can not find Subnetmap for SubnetId {} in ConfigDS", snId.getValue());
            continue;
        }
        LOG.trace("removeExternalNetworkFromRouter: Remove Internet VPN Id {} from SubnetMap {}", subnetMap.getInternetVpnId(), subnetMap.getId());
        IpVersionChoice ipVers = NeutronvpnUtils.getIpVersionFromString(subnetMap.getSubnetIp());
        if (ipVers == IpVersionChoice.IPV6) {
            nvpnManager.updateVpnInternetForSubnet(subnetMap, subnetMap.getInternetVpnId(), false);
            LOG.debug("removeExternalNetworkFromRouter: Withdraw IPv6 routes from VPN {}", subnetMap.getInternetVpnId());
        }
    }
}
Also used : Networks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks) ExternalNetworks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks) NetworksKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Network(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) NetworksBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksBuilder) IpVersionChoice(org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)

Example 10 with ExternalFixedIps

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

the class NeutronRouterChangeListener method remove.

@Override
protected void remove(InstanceIdentifier<Router> identifier, Router input) {
    LOG.trace("Removing router : key: {}, value={}", identifier, input);
    Uuid routerId = input.getUuid();
    /*External Router and networks is handled before deleting the internal VPN, as there is dependency
        on vpn operational data to release Lport tag in case of L3VPN over VxLAN*/
    if (input.getExternalGatewayInfo() != null) {
        Uuid extNetId = input.getExternalGatewayInfo().getExternalNetworkId();
        List<ExternalFixedIps> externalFixedIps = input.getExternalGatewayInfo().getExternalFixedIps();
        nvpnNatManager.removeExternalNetworkFromRouter(extNetId, input, externalFixedIps);
    }
    // NOTE: Pass an empty routerSubnetIds list, as router interfaces
    // will be removed from VPN by invocations from NeutronPortChangeListener
    List<Uuid> routerSubnetIds = new ArrayList<>();
    nvpnManager.handleNeutronRouterDeleted(routerId, routerSubnetIds);
    neutronvpnUtils.removeFromRouterCache(input);
}
Also used : ExternalFixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router.external_gateway_info.ExternalFixedIps) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ArrayList(java.util.ArrayList)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)9 ExternalFixedIps (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router.external_gateway_info.ExternalFixedIps)6 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)4 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)4 ArrayList (java.util.ArrayList)3 Network (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network)3 IpVersionChoice (org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)2 ExternalNetworks (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks)2 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)2 Routers (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)2 RoutersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.RoutersBuilder)2 ExternalIps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)2 Networks (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks)2 NetworksBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksBuilder)2 NetworksKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey)2 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)2 HashSet (java.util.HashSet)1 ExternalSubnets (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalSubnets)1 RoutersKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.RoutersKey)1 ExternalIpsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIpsBuilder)1