Search in sources :

Example 51 with Routers

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

the class UpgradeStateListener method update.

@Override
public void update(@Nonnull Config original, Config updated) {
    if (natMode != NatserviceConfig.NatMode.Conntrack) {
        return;
    }
    LOG.info("UpgradeStateListener update from {} to {}", original, updated);
    if (!(original.isUpgradeInProgress() && !updated.isUpgradeInProgress())) {
        return;
    }
    SingleTransactionDataBroker reader = new SingleTransactionDataBroker(dataBroker);
    ExtRouters routers;
    try {
        routers = reader.syncRead(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(ExtRouters.class));
    } catch (ReadFailedException e) {
        LOG.error("Error reading external routers", e);
        return;
    }
    for (Routers router : routers.getRouters()) {
        List<ExternalIps> externalIps = router.getExternalIps();
        if (router.isEnableSnat() && externalIps != null && !externalIps.isEmpty()) {
            centralizedSwitchScheduler.scheduleCentralizedSwitch(router);
        }
    }
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) ExtRouters(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker) ExtRouters(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)

Example 52 with Routers

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

the class VxlanGreConntrackBasedSnatService method handleSnatAllSwitch.

@Override
public boolean handleSnatAllSwitch(Routers routers, BigInteger primarySwitchId, int addOrRemove) {
    ProviderTypes extNwProviderType = NatUtil.getProviderTypefromNetworkId(dataBroker, routers.getNetworkId());
    LOG.debug("VxlanGreConntrackBasedSnatService: handleSnatAllSwitch ProviderTypes {}", extNwProviderType);
    if (extNwProviderType == ProviderTypes.FLAT || extNwProviderType == ProviderTypes.VLAN) {
        return false;
    }
    return super.handleSnatAllSwitch(routers, primarySwitchId, addOrRemove);
}
Also used : ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)

Example 53 with Routers

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

the class VxlanGreConntrackBasedSnatService method installSnatSpecificEntriesForNaptSwitch.

@Override
protected void installSnatSpecificEntriesForNaptSwitch(Routers routers, BigInteger dpnId, int addOrRemove) {
    LOG.info("installSnatSpecificEntriesForNaptSwitch for router {}", routers.getRouterName());
    String routerName = routers.getRouterName();
    Long routerId = NatUtil.getVpnId(dataBroker, routerName);
    int elanId = NatUtil.getElanInstanceByName(routers.getNetworkId().getValue(), dataBroker).getElanTag().intValue();
    /* Install Outbound NAT entries */
    installSnatMissEntryForPrimrySwch(dpnId, routerId, elanId, addOrRemove);
    installTerminatingServiceTblEntryForVxlanGre(dpnId, routerName, routerId, elanId, addOrRemove);
    // Long extNetVpnId = NatUtil.getNetworkVpnIdFromRouterId(dataBroker, routerId);
    Uuid vpnUuid = NatUtil.getVpnIdfromNetworkId(dataBroker, routers.getNetworkId());
    if (vpnUuid == null) {
        LOG.error("installSnatSpecificEntriesForNaptSwitch: Unable to retrieve external vpn_id for " + "external network {} with routerId {}", routers.getNetworkId(), routerId);
        return;
    }
    Long extNetVpnId = NatUtil.getVpnId(dataBroker, vpnUuid.getValue());
    /*//Long extNetVpnId = NatUtil.getAssociatedVPN(dataBroker, routers.getNetworkId(), LOG);
        if (extNetVpnId == NatConstants.INVALID_ID && addOrRemove == NwConstants.ADD_FLOW) {
            LOG.error("installSnatSpecificEntriesForNaptSwitch: Unable to retrieve external vpn_id for "
                    + "external network {} with routerId {}", routers.getNetworkId(), routerId);
            return;
        }*/
    LOG.info("installSnatSpecificEntriesForNaptSwitch: external network vpn_id {} for router {}", extNetVpnId, routers.getRouterName());
    List<ExternalIps> externalIps = routers.getExternalIps();
    createOutboundTblTrackEntryForVxlanGre(dpnId, routerId, extNetVpnId, addOrRemove);
    createOutboundTblEntryForVxlanGre(dpnId, routerId, extNetVpnId, externalIps, elanId, addOrRemove);
    installNaptPfibFlowForVxlanGre(routers, dpnId, extNetVpnId, addOrRemove);
    installNaptPfibEntry(dpnId, routerId, addOrRemove);
    // Install Inbound NAT entries
    installInboundEntryForVxlanGre(dpnId, routerId, extNetVpnId, externalIps, elanId, addOrRemove);
    if (externalIps.isEmpty()) {
        LOG.error("installSnatSpecificEntriesForNaptSwitch: No externalIP present for router {}", routerName);
        return;
    }
    // The logic now handle only one external IP per router, others if present will be ignored.
    String externalIp = externalIps.get(0).getIpAddress();
    externalIp = NatUtil.validateAndAddNetworkMask(externalIp);
    WriteTransaction writeFlowInvTx = dataBroker.newWriteOnlyTransaction();
    if (addOrRemove == NwConstants.ADD_FLOW) {
        externalRouterListener.handleSnatReverseTraffic(dpnId, routers, routerId, routerName, externalIp, writeFlowInvTx);
    } else {
        externalRouterListener.clearFibTsAndReverseTraffic(dpnId, routerId, routers.getNetworkId(), Collections.singletonList(externalIp), null, routers.getExtGwMacAddress(), writeFlowInvTx);
    }
}
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) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)

Example 54 with Routers

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.Routers 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 55 with Routers

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.Routers 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)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)33 Routers (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)26 BigInteger (java.math.BigInteger)22 ExternalIps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)16 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)12 ArrayList (java.util.ArrayList)11 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)7 UnknownHostException (java.net.UnknownHostException)6 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)6 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)6 RoutersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.RoutersBuilder)6 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 ExecutionException (java.util.concurrent.ExecutionException)5 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)5 InetAddress (java.net.InetAddress)4 List (java.util.List)4 ExtRouters (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters)4 IpPortMapping (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.IpPortMapping)4 IntextIpProtocolType (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.IntextIpProtocolType)4 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)3