Search in sources :

Example 6 with Routers

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

the class FlatVlanConntrackBasedSnatService method handleSnat.

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

Example 7 with Routers

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

the class NatTunnelInterfaceStateListener method handleTepDelForAllRtrs.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private boolean handleTepDelForAllRtrs(BigInteger srcDpnId, String tunnelType, String tunnelName, String srcTepIp, String destTepIp, WriteTransaction writeFlowInvTx) {
    LOG.trace("handleTepDelForAllRtrs : TEP DEL ----- for EXTERNAL/HWVTEP ITM Tunnel,TYPE {},State is UP b/w SRC IP" + " : {} and DEST IP: {}", fibManager.getTransportTypeStr(tunnelType), srcTepIp, destTepIp);
    // When tunnel EP is deleted on a DPN , VPN gets two deletion event.
    // One for a DPN on which tunnel EP was deleted and another for other-end DPN.
    // Handle only the DPN on which it was deleted , ignore other event.
    // DPN on which TEP is deleted , endpoint IP will be null.
    String endpointIpForDPN = null;
    try {
        endpointIpForDPN = NatUtil.getEndpointIpAddressForDPN(dataBroker, srcDpnId);
    } catch (Exception e) {
        /* this dpn does not have the VTEP */
        LOG.error("handleTepDelForAllRtrs : DPN {} does not have the VTEP", srcDpnId);
        endpointIpForDPN = null;
    }
    if (endpointIpForDPN != null) {
        LOG.trace("handleTepDelForAllRtrs : Ignore TEP DELETE event received for DPN {} VTEP IP {} since its " + "the other end DPN w.r.t the delted TEP", srcDpnId, srcTepIp);
        return false;
    }
    List<RoutersList> routersList = null;
    InstanceIdentifier<DpnRoutersList> dpnRoutersListId = NatUtil.getDpnRoutersId(srcDpnId);
    Optional<DpnRoutersList> optionalRouterDpnList = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, dpnRoutersListId);
    if (optionalRouterDpnList.isPresent()) {
        routersList = optionalRouterDpnList.get().getRoutersList();
    } else {
        LOG.warn("handleTepDelForAllRtrs : RouterDpnList is empty for DPN {}.Hence ignoring TEP DEL event " + "for the ITM TUNNEL TYPE {} b/w SRC IP {} and DST IP {} and TUNNEL NAME {} ", srcDpnId, tunnelType, srcTepIp, destTepIp, tunnelName);
        return false;
    }
    if (routersList == null) {
        LOG.error("handleTepDelForAllRtrs : DPN {} does not have the Routers presence", srcDpnId);
        return false;
    }
    for (RoutersList router : routersList) {
        String routerName = router.getRouter();
        LOG.debug("handleTepDelForAllRtrs :  TEP DEL : DNAT -> Withdrawing routes for router {} ", routerName);
        long routerId = NatUtil.getVpnId(dataBroker, routerName);
        if (routerId == NatConstants.INVALID_ID) {
            LOG.error("handleTepDelForAllRtrs :Invalid ROUTER-ID {} returned for routerName {}", routerId, routerName);
            return false;
        }
        Uuid externalNetworkId = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
        ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, externalNetworkId);
        if (extNwProvType == null) {
            return false;
        }
        hndlTepDelForDnatInEachRtr(router, routerId, srcDpnId, extNwProvType);
        LOG.debug("handleTepDelForAllRtrs :  TEP DEL : SNAT -> Withdrawing and Advertising routes for router {} ", router.getRouter());
        hndlTepDelForSnatInEachRtr(router, routerId, srcDpnId, tunnelType, srcTepIp, destTepIp, tunnelName, extNwProvType, writeFlowInvTx);
    }
    return true;
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) DpnRoutersList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.dpn.routers.DpnRoutersList) RoutersList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.dpn.routers.dpn.routers.list.RoutersList) DpnRoutersList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.dpn.routers.DpnRoutersList) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)

Example 8 with Routers

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

the class NatTunnelInterfaceStateListener method hndlTepAddForAllRtrs.

private boolean hndlTepAddForAllRtrs(BigInteger srcDpnId, String tunnelType, String tunnelName, String srcTepIp, String destTepIp, WriteTransaction writeFlowInvTx) {
    LOG.trace("hndlTepAddForAllRtrs: TEP ADD ----- for EXTERNAL/HWVTEP ITM Tunnel, TYPE {} ,State is UP b/w SRC IP" + " : {} and DEST IP: {}", fibManager.getTransportTypeStr(tunnelType), srcTepIp, destTepIp);
    InstanceIdentifier<DpnRoutersList> dpnRoutersListId = NatUtil.getDpnRoutersId(srcDpnId);
    Optional<DpnRoutersList> optionalRouterDpnList = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, dpnRoutersListId);
    if (!optionalRouterDpnList.isPresent()) {
        LOG.info("hndlTepAddForAllRtrs : RouterDpnList model is empty for DPN {}. Hence ignoring TEP add event " + "for the ITM TUNNEL TYPE {} b/w SRC IP {} and DST IP {} and TUNNEL NAME {} ", srcDpnId, tunnelType, srcTepIp, destTepIp, tunnelName);
        return false;
    }
    List<RoutersList> routersList = optionalRouterDpnList.get().getRoutersList();
    if (routersList == null) {
        LOG.debug("hndlTepAddForAllRtrs : Ignoring TEP add for the DPN {} since no routers are associated" + " for the DPN having the TUNNEL TYPE {} b/w SRC IP {} and DST IP {} and" + "TUNNEL NAME {} ", srcDpnId, tunnelType, srcTepIp, destTepIp, tunnelName);
        return false;
    }
    String nextHopIp = NatUtil.getEndpointIpAddressForDPN(dataBroker, srcDpnId);
    for (RoutersList router : routersList) {
        String routerName = router.getRouter();
        long routerId = NatUtil.getVpnId(dataBroker, routerName);
        if (routerId == NatConstants.INVALID_ID) {
            LOG.error("hndlTepAddForAllRtrs :Invalid ROUTER-ID {} returned for routerName {}", routerId, routerName);
            return false;
        }
        LOG.debug("hndlTepAddForAllRtrs : TEP ADD : DNAT -> Advertising routes for router {} ", routerName);
        Uuid externalNetworkId = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
        ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, externalNetworkId);
        if (extNwProvType == null) {
            return false;
        }
        hndlTepAddForDnatInEachRtr(router, routerId, nextHopIp, srcDpnId, extNwProvType, writeFlowInvTx);
        LOG.debug("hndlTepAddForAllRtrs : TEP ADD : SNAT -> Advertising routes for router {} ", routerName);
        hndlTepAddForSnatInEachRtr(router, routerId, srcDpnId, tunnelType, srcTepIp, destTepIp, tunnelName, nextHopIp, extNwProvType, writeFlowInvTx);
    }
    return true;
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) DpnRoutersList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.dpn.routers.DpnRoutersList) DpnRoutersList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.dpn.routers.DpnRoutersList) RoutersList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.dpn.routers.dpn.routers.list.RoutersList) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)

Example 9 with Routers

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

the class NatTunnelInterfaceStateListener method hndlTepAddOnNaptSwitch.

private boolean hndlTepAddOnNaptSwitch(BigInteger srcDpnId, String tunnelType, String srcTepIp, String destTepIp, String tunnelName, long routerId, Optional<Routers> routerData, String nextHopIp, Uuid vpnName, ProviderTypes extNwProvType, WriteTransaction writeFlowInvTx) {
    if (!routerData.isPresent()) {
        LOG.warn("hndlTepAddOnNaptSwitch: routerData is not present");
        return false;
    }
    Routers router = routerData.get();
    String routerName = router.getRouterName();
    LOG.debug("hndlTepAddOnNaptSwitch : SNAT -> Processing TEP add for the DPN {} having the router {} since " + "its THE NAPT switch for the TUNNEL TYPE {} b/w SRC IP {} and DST IP {} " + "and TUNNEL NAME {} ", srcDpnId, routerName, tunnelType, srcTepIp, destTepIp, tunnelName);
    Uuid networkId = router.getNetworkId();
    if (networkId == null) {
        LOG.warn("hndlTepAddOnNaptSwitch : SNAT -> Ignoring TEP add since the router {} is not associated to the " + "external network", routerName);
        return false;
    }
    LOG.debug("hndlTepAddOnNaptSwitch : SNAT -> Router {} is associated with Ext nw {}", routerId, networkId);
    Long vpnId;
    if (vpnName == null) {
        LOG.debug("hndlTepAddOnNaptSwitch : SNAT -> Internal VPN associated to router {}", routerId);
        vpnId = NatUtil.getNetworkVpnIdFromRouterId(dataBroker, routerId);
        if (vpnId == NatConstants.INVALID_ID) {
            LOG.error("hndlTepAddOnNaptSwitch : Invalid External VPN-ID returned for routerName {}", routerName);
            return false;
        }
        LOG.debug("hndlTepAddOnNaptSwitch : SNAT -> Retrieved External VPN-ID {} for router {}", vpnId, routerId);
    } else {
        LOG.debug("hndlTepAddOnNaptSwitch : SNAT -> Private BGP VPN associated to router {}", routerId);
        vpnId = NatUtil.getVpnId(dataBroker, vpnName.getValue());
        if (vpnId == null || vpnId == NatConstants.INVALID_ID) {
            LOG.error("hndlTepAddOnNaptSwitch : Invalid vpnId returned for routerName {}", routerName);
            return false;
        }
        LOG.debug("hndlTepAddOnNaptSwitch : SNAT -> Retrieved vpnId {} for router {}", vpnId, routerId);
    }
    /*1) Withdraw the old route to the external IP from the BGP which was having the
             next hop as the old TEP IP.
          2) Advertise to the BGP about the new route to the external IP having the
          new TEP IP as the next hop.
          3) Populate a new FIB entry with the next hop IP as the new TEP IP using the
          FIB manager.
        */
    // Withdraw the old route to the external IP from the BGP which was having the
    // next hop as the old TEP IP.
    final String externalVpnName = NatUtil.getAssociatedVPN(dataBroker, networkId);
    if (externalVpnName == null) {
        LOG.error("hndlTepAddOnNaptSwitch :  SNAT -> No VPN associated with ext nw {} in router {}", networkId, routerId);
        return false;
    }
    Collection<String> externalIps = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
    LOG.debug("hndlTepAddOnNaptSwitch : Clearing the FIB entries but not the BGP routes");
    for (String externalIp : externalIps) {
        String rd = NatUtil.getVpnRd(dataBroker, externalVpnName);
        LOG.debug("hndlTepAddOnNaptSwitch : Removing Fib entry rd {} prefix {}", rd, externalIp);
        fibManager.removeFibEntry(rd, externalIp, null);
    }
    /*
        Advertise to the BGP about the new route to the external IP having the
        new TEP IP as the next hop.
        Populate a new FIB entry with the next hop IP as the new TEP IP using the
        FIB manager.
        */
    String rd = NatUtil.getVpnRd(dataBroker, externalVpnName);
    if (extNwProvType == null) {
        return false;
    }
    String gwMacAddress = null;
    long l3Vni = 0;
    if (extNwProvType == ProviderTypes.VXLAN) {
        // Get the External Gateway MAC Address which is Router gateway MAC address for SNAT
        gwMacAddress = NatUtil.getExtGwMacAddFromRouterName(dataBroker, routerName);
        if (gwMacAddress != null) {
            LOG.debug("hndlTepAddOnNaptSwitch : External Gateway MAC address {} found for External Router ID {}", gwMacAddress, routerId);
        } else {
            LOG.error("hndlTepAddOnNaptSwitch : No External Gateway MAC address found for External Router ID {}", routerId);
            return false;
        }
        // get l3Vni value for external VPN
        l3Vni = NatEvpnUtil.getL3Vni(dataBroker, rd);
        if (l3Vni == NatConstants.DEFAULT_L3VNI_VALUE) {
            LOG.debug("hndlTepAddOnNaptSwitch : L3VNI value is not configured in Internet VPN {} and RD {} " + "Carve-out L3VNI value from OpenDaylight VXLAN VNI Pool and continue to installing " + "NAT flows", vpnName, rd);
            l3Vni = NatOverVxlanUtil.getInternetVpnVni(idManager, externalVpnName, routerId).longValue();
        }
    }
    for (final String externalIp : externalIps) {
        long serviceId = 0;
        String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp);
        if (extNwProvType == ProviderTypes.VXLAN) {
            LOG.debug("hndlTepAddOnNaptSwitch : SNAT -> Advertise the route to the externalIp {} " + "having nextHopIp {}", externalIp, nextHopIp);
            NatEvpnUtil.addRoutesForVxLanProvType(dataBroker, bgpManager, fibManager, externalVpnName, rd, externalIp, nextHopIp, l3Vni, tunnelName, gwMacAddress, writeFlowInvTx, RouteOrigin.STATIC, srcDpnId);
            serviceId = l3Vni;
        } else {
            Long label = externalRouterListner.checkExternalIpLabel(routerId, externalIp);
            if (label == null || label == NatConstants.INVALID_ID) {
                LOG.error("hndlTepAddOnNaptSwitch : SNAT->Unable to advertise to the DC GW " + "since label is invalid");
                return false;
            }
            LOG.debug("hndlTepAddOnNaptSwitch : SNAT -> Advertise the route to the externalIp {} " + "having nextHopIp {}", externalIp, nextHopIp);
            long l3vni = 0;
            if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
                l3vni = NatOverVxlanUtil.getInternetVpnVni(idManager, externalVpnName, l3vni).longValue();
            }
            Uuid externalSubnetId = NatUtil.getExternalSubnetForRouterExternalIp(externalIp, router);
            NatUtil.addPrefixToBGP(dataBroker, bgpManager, fibManager, externalVpnName, rd, externalSubnetId, fibExternalIp, nextHopIp, networkId.getValue(), null, /* mac-address */
            label, l3vni, RouteOrigin.STATIC, srcDpnId);
            serviceId = label;
        }
        LOG.debug("hndlTepAddOnNaptSwitch: SNAT -> Install custom FIB routes " + "(Table 21 -> Push MPLS label to Tunnel port");
        List<Instruction> customInstructions = new ArrayList<>();
        int customInstructionIndex = 0;
        long externalSubnetVpnId = NatUtil.getExternalSubnetVpnIdForRouterExternalIp(dataBroker, externalIp, router);
        if (externalSubnetVpnId != NatConstants.INVALID_ID) {
            LOG.debug("hndlTepAddOnNaptSwitch : Will install custom FIB router with external subnet VPN ID {}", externalSubnetVpnId);
            BigInteger subnetIdMetaData = MetaDataUtil.getVpnIdMetadata(externalSubnetVpnId);
            customInstructions.add(new InstructionWriteMetadata(subnetIdMetaData, MetaDataUtil.METADATA_MASK_VRFID).buildInstruction(customInstructionIndex));
            customInstructionIndex++;
        }
        customInstructions.add(new InstructionGotoTable(NwConstants.INBOUND_NAPT_TABLE).buildInstruction(customInstructionIndex));
        CreateFibEntryInput input = new CreateFibEntryInputBuilder().setVpnName(externalVpnName).setSourceDpid(srcDpnId).setInstruction(customInstructions).setIpAddress(fibExternalIp).setServiceId(serviceId).setInstruction(customInstructions).build();
        Future<RpcResult<Void>> future = fibRpcService.createFibEntry(input);
        ListenableFuture<RpcResult<Void>> listenableFuture = JdkFutureAdapters.listenInPoolThread(future);
        Futures.addCallback(listenableFuture, new FutureCallback<RpcResult<Void>>() {

            @Override
            public void onFailure(@Nonnull Throwable error) {
                LOG.error("hndlTepAddOnNaptSwitch : SNAT->Error in generate label or fib install process", error);
            }

            @Override
            public void onSuccess(@Nonnull RpcResult<Void> result) {
                if (result.isSuccessful()) {
                    LOG.info("hndlTepAddOnNaptSwitch : SNAT -> Successfully installed custom FIB routes " + "for prefix {}", externalIp);
                } else {
                    LOG.error("hndlTepAddOnNaptSwitch : SNAT -> Error in rpc call to create custom Fib entries " + "for prefix {} in DPN {}, {}", externalIp, srcDpnId, result.getErrors());
                }
            }
        }, MoreExecutors.directExecutor());
    }
    return true;
}
Also used : InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) CreateFibEntryInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryInputBuilder) ArrayList(java.util.ArrayList) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction) CreateFibEntryInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryInput) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) BigInteger(java.math.BigInteger) InstructionWriteMetadata(org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata)

Example 10 with Routers

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

the class NatUtil method getAssociatedExternalNetwork.

static String getAssociatedExternalNetwork(DataBroker dataBroker, String routerId) {
    InstanceIdentifier<Routers> id = NatUtil.buildRouterIdentifier(routerId);
    Optional<Routers> routerData = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
    if (routerData.isPresent()) {
        Uuid networkId = routerData.get().getNetworkId();
        if (networkId != null) {
            return networkId.getValue();
        }
    }
    LOG.info("getAssociatedExternalNetwork : External Network missing for routerid : {}", routerId);
    return null;
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) DpnRouters(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.DpnRouters) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) ExtRouters(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters)

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