Search in sources :

Example 31 with ExternalIps

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps 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 32 with ExternalIps

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps in project netvirt by opendaylight.

the class NeutronvpnNatManager method addExternalFixedIpToExternalIpsList.

private void addExternalFixedIpToExternalIpsList(List<ExternalIps> externalIps, ExternalFixedIps fixedIps) {
    Uuid subnetId = fixedIps.getSubnetId();
    String ip = fixedIps.getIpAddress().getIpv4Address().getValue();
    ExternalIpsBuilder externalIpsBuilder = new ExternalIpsBuilder();
    externalIpsBuilder.setKey(new ExternalIpsKey(ip, subnetId));
    externalIpsBuilder.setIpAddress(ip);
    externalIpsBuilder.setSubnetId(subnetId);
    externalIps.add(externalIpsBuilder.build());
}
Also used : ExternalIpsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIpsKey) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ExternalIpsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIpsBuilder)

Example 33 with ExternalIps

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps 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)23 ExternalIps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)15 BigInteger (java.math.BigInteger)10 ArrayList (java.util.ArrayList)8 Routers (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)8 ExecutionException (java.util.concurrent.ExecutionException)6 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)6 UnknownHostException (java.net.UnknownHostException)5 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)5 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)4 IpPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.intext.ip.protocol.type.IpPortMap)4 IpPortExternal (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.intext.ip.protocol.type.ip.port.map.IpPortExternal)4 HashSet (java.util.HashSet)3 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)3 IntextIpPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.IntextIpPortMap)3 IpPortMapping (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.IpPortMapping)3 IntextIpProtocolType (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.IntextIpProtocolType)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 InetAddress (java.net.InetAddress)2 List (java.util.List)2