Search in sources :

Example 51 with RouterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.RouterId in project netvirt by opendaylight.

the class ExternalRoutersListener method addOrDelDefFibRouteToSNAT.

private void addOrDelDefFibRouteToSNAT(String routerName, Uint32 routerId, Uint32 bgpVpnId, Uuid bgpVpnUuid, boolean create, TypedReadWriteTransaction<Configuration> confTx) throws ExecutionException, InterruptedException {
    // Check if BGP VPN exists. If exists then invoke the new method.
    if (bgpVpnId != NatConstants.INVALID_ID) {
        if (bgpVpnUuid != null) {
            String bgpVpnName = bgpVpnUuid.getValue();
            LOG.debug("Populate the router-id-name container with the mapping BGP VPN-ID {} -> BGP VPN-NAME {}", bgpVpnId, bgpVpnName);
            RouterIds rtrs = new RouterIdsBuilder().withKey(new RouterIdsKey(bgpVpnId)).setRouterId(bgpVpnId).setRouterName(bgpVpnName).build();
            confTx.mergeParentStructurePut(getRoutersIdentifier(bgpVpnId), rtrs);
        }
        if (create) {
            addDefaultFibRouteForSnatWithBgpVpn(routerName, routerId, bgpVpnId, confTx);
        } else {
            removeDefaultFibRouteForSnatWithBgpVpn(routerName, routerId, bgpVpnId, confTx);
        }
        return;
    }
    // Router ID is used as the internal VPN's name, hence the vrf-id in VpnInstance Op DataStore
    addOrDelDefaultFibRouteForSNAT(routerName, routerId, create, confTx);
}
Also used : RouterIds(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.id.name.RouterIds) RouterIdsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.id.name.RouterIdsKey) RouterIdsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.id.name.RouterIdsBuilder)

Example 52 with RouterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.RouterId in project netvirt by opendaylight.

the class ExternalRoutersListener method installNaptPfibExternalOutputFlow.

protected void installNaptPfibExternalOutputFlow(String routerName, Uint32 routerId, Uint64 dpnId, TypedWriteTransaction<Configuration> confTx) {
    Uint32 extVpnId = NatUtil.getNetworkVpnIdFromRouterId(dataBroker, routerId);
    if (extVpnId == NatConstants.INVALID_ID) {
        LOG.error("installNaptPfibExternalOutputFlow - not found extVpnId for router {}", routerId);
        extVpnId = routerId;
    }
    List<String> externalIps = NatUtil.getExternalIpsForRouter(dataBroker, routerName);
    if (externalIps.isEmpty()) {
        LOG.error("installNaptPfibExternalOutputFlow - empty external Ips list for dpnId {} extVpnId {}", dpnId, extVpnId);
        return;
    }
    for (String ip : externalIps) {
        Uuid subnetId = getSubnetIdForFixedIp(ip);
        if (subnetId != null) {
            Uint32 subnetVpnId = NatUtil.getExternalSubnetVpnId(dataBroker, subnetId);
            if (subnetVpnId != NatConstants.INVALID_ID) {
                extVpnId = subnetVpnId;
            }
            LOG.debug("installNaptPfibExternalOutputFlow - dpnId {} extVpnId {} subnetId {}", dpnId, extVpnId, subnetId);
            FlowEntity postNaptFlowEntity = buildNaptPfibFlowEntity(dpnId, extVpnId);
            if (postNaptFlowEntity != null) {
                mdsalManager.addFlow(confTx, postNaptFlowEntity);
            }
        }
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Uint32(org.opendaylight.yangtools.yang.common.Uint32) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity)

Example 53 with RouterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.RouterId in project netvirt by opendaylight.

the class ExternalRoutersListener method removeNaptFibExternalOutputFlows.

protected void removeNaptFibExternalOutputFlows(Uint32 routerId, Uint64 dpnId, Uuid networkId, @NonNull Collection<String> externalIps, TypedReadWriteTransaction<Configuration> writeFlowInvTx) throws ExecutionException, InterruptedException {
    Uint32 extVpnId = NatConstants.INVALID_ID;
    if (networkId != null) {
        Uuid vpnUuid = NatUtil.getVpnIdfromNetworkId(dataBroker, networkId);
        if (vpnUuid != null) {
            extVpnId = NatUtil.getVpnId(dataBroker, vpnUuid.getValue());
        } else {
            LOG.debug("removeNaptFibExternalOutputFlows : vpnUuid is null");
        }
    } else {
        LOG.debug("removeNaptFibExternalOutputFlows : networkId is null");
        extVpnId = NatUtil.getNetworkVpnIdFromRouterId(dataBroker, routerId);
    }
    if (extVpnId == NatConstants.INVALID_ID) {
        LOG.warn("removeNaptFibExternalOutputFlows : extVpnId not found for routerId {}", routerId);
        extVpnId = routerId;
    }
    for (String ip : externalIps) {
        String extIp = removeMaskFromIp(ip);
        String naptFlowRef = getFlowRefNaptPreFib(dpnId, NwConstants.NAPT_PFIB_TABLE, extVpnId);
        LOG.info("removeNaptFlowsFromActiveSwitch : Remove the flow in table {} for the active switch" + " with the DPN ID {} and router ID {} and IP {} flowRef {}", NwConstants.NAPT_PFIB_TABLE, dpnId, routerId, extIp, naptFlowRef);
        FlowEntity natPfibVpnFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.NAPT_PFIB_TABLE, naptFlowRef);
        mdsalManager.removeFlow(writeFlowInvTx, natPfibVpnFlowEntity);
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Uint32(org.opendaylight.yangtools.yang.common.Uint32) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity)

Example 54 with RouterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.RouterId in project netvirt by opendaylight.

the class ExternalRoutersListener method handlePrimaryNaptSwitch.

protected void handlePrimaryNaptSwitch(Uint64 dpnId, String routerName, Uint32 routerId, Uuid externalNwUuid, TypedWriteTransaction<Configuration> confTx) {
    /*
        * Primary NAPT Switch – bucket Should always point back to its own Outbound Table
        */
    LOG.debug("handlePrimaryNaptSwitch : Installing SNAT miss entry in Primary NAPT switch {} ", dpnId);
    /*
        List<BucketInfo> listBucketInfo = new ArrayList<>();
        List<ActionInfo> listActionInfoPrimary = new ArrayList<>();
        listActionInfoPrimary.add(new ActionNxResubmit(NatConstants.TERMINATING_SERVICE_TABLE));
        BucketInfo bucketPrimary = new BucketInfo(listActionInfoPrimary);
        listBucketInfo.add(0, bucketPrimary);
*/
    installSnatMissEntryForPrimrySwch(dpnId, routerName, routerId, confTx);
    installTerminatingServiceTblEntry(dpnId, routerName, routerId, confTx);
    // Install the NAPT PFIB TABLE which forwards the outgoing packet to FIB Table matching on the router ID.
    installNaptPfibEntry(dpnId, routerId, confTx);
    Uuid networkId = NatUtil.getNetworkIdFromRouterId(dataBroker, routerId);
    if (networkId != null) {
        Uuid vpnUuid = NatUtil.getVpnIdfromNetworkId(dataBroker, networkId);
        if (vpnUuid != null) {
            Uint32 extVpnId = NatUtil.getExternalVpnIdForExtNetwork(dataBroker, externalNwUuid);
            coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + networkId, () -> {
                installNaptPfibEntriesForExternalSubnets(routerName, dpnId, null);
                // Install the NAPT PFIB TABLE which forwards outgoing packet to FIB Table matching on the VPN ID.
                if (extVpnId != null && extVpnId != NatConstants.INVALID_ID) {
                    installNaptPfibEntry(dpnId, extVpnId, null);
                }
                return Collections.emptyList();
            });
        } else {
            LOG.warn("handlePrimaryNaptSwitch : External Vpn ID missing for Ext-Network : {}", networkId);
        }
    } else {
        LOG.warn("handlePrimaryNaptSwitch : External Network not available for router : {}", routerName);
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Uint32(org.opendaylight.yangtools.yang.common.Uint32)

Example 55 with RouterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.RouterId in project netvirt by opendaylight.

the class ExternalRoutersListener method delFibTsAndReverseTraffic.

protected void delFibTsAndReverseTraffic(final Uint64 dpnId, String routerName, Uint32 routerId, String extIp, String vpnName, Uuid extNetworkId, Uint32 tempLabel, String gwMacAddress, boolean switchOver, TypedReadWriteTransaction<Configuration> removeFlowInvTx) throws ExecutionException, InterruptedException {
    LOG.debug("delFibTsAndReverseTraffic : Removing fib entry for externalIp {} in routerId {}", extIp, routerId);
    // String routerName = NatUtil.getRouterName(dataBroker,routerId);
    if (routerName == null) {
        LOG.error("delFibTsAndReverseTraffic : Could not retrieve Router Name from Router ID {} ", routerId);
        return;
    }
    ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, extNetworkId);
    if (extNwProvType == null) {
        LOG.error("delFibTsAndReverseTraffic : External Network Provider Type Missing");
        return;
    }
    /*  Remove the flow table19->44 and table36->44 entries for SNAT reverse traffic flow if the
         * external network provided type is VxLAN
         */
    if (extNwProvType == ProviderTypes.VXLAN) {
        evpnSnatFlowProgrammer.evpnDelFibTsAndReverseTraffic(dpnId, routerId, extIp, vpnName, gwMacAddress);
        return;
    }
    if (tempLabel.longValue() < 0) {
        LOG.error("delFibTsAndReverseTraffic : Label not found for externalIp {} with router id {}", extIp, routerId);
        return;
    }
    final Uint32 label = tempLabel;
    final String externalIp = NatUtil.validateAndAddNetworkMask(extIp);
    RemoveFibEntryInput input = null;
    if (extNwProvType == ProviderTypes.FLAT || extNwProvType == ProviderTypes.VLAN) {
        LOG.debug("delFibTsAndReverseTraffic : Using extSubnetId as vpnName for FLAT/VLAN use-cases");
        Routers extRouter = NatUtil.getRoutersFromConfigDS(dataBroker, routerName);
        Uuid externalSubnetId = NatUtil.getExternalSubnetForRouterExternalIp(externalIp, extRouter);
        Optional<Subnets> externalSubnet = NatUtil.getOptionalExternalSubnets(dataBroker, externalSubnetId);
        if (externalSubnet.isPresent()) {
            vpnName = externalSubnetId.getValue();
        }
    }
    final String externalVpn = vpnName;
    if (label != null && label.toJava() <= 0) {
        LOG.error("delFibTsAndReverseTraffic : Label not found for externalIp {} with router id {}", extIp, routerId);
        input = new RemoveFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(dpnId).setIpAddress(externalIp).setIpAddressSource(RemoveFibEntryInput.IpAddressSource.ExternalFixedIP).build();
    } else {
        input = new RemoveFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(dpnId).setIpAddress(externalIp).setServiceId(label).setIpAddressSource(RemoveFibEntryInput.IpAddressSource.ExternalFixedIP).build();
        removeTunnelTableEntry(dpnId, label, removeFlowInvTx);
        removeLFibTableEntry(dpnId, label, removeFlowInvTx);
    }
    ListenableFuture<RpcResult<RemoveFibEntryOutput>> future = fibService.removeFibEntry(input);
    removeTunnelTableEntry(dpnId, label, removeFlowInvTx);
    removeLFibTableEntry(dpnId, label, removeFlowInvTx);
    if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
        // Remove the flow table 25->44 If there is no FIP Match on table 25 (PDNAT_TABLE)
        NatUtil.removePreDnatToSnatTableEntry(removeFlowInvTx, mdsalManager, dpnId);
    }
    if (!switchOver) {
        ListenableFuture<RpcResult<RemoveVpnLabelOutput>> labelFuture = Futures.transformAsync(future, result -> {
            // Release label
            if (result.isSuccessful() && label != null && label.toJava() > 0) {
                NatUtil.removePreDnatToSnatTableEntry(removeFlowInvTx, mdsalManager, dpnId);
                RemoveVpnLabelInput labelInput = new RemoveVpnLabelInputBuilder().setVpnName(externalVpn).setIpPrefix(externalIp).build();
                Future<RpcResult<RemoveVpnLabelOutput>> labelFuture1 = vpnService.removeVpnLabel(labelInput);
                if (labelFuture1.get() == null || !labelFuture1.get().isSuccessful()) {
                    String errMsg = String.format("ExternalRoutersListener: RPC call to remove VPN label " + "on dpn %s for prefix %s failed for vpn %s - %s", dpnId, externalIp, result.getErrors());
                    LOG.error(errMsg);
                    return Futures.immediateFailedFuture(new RuntimeException(errMsg));
                }
                return JdkFutureAdapters.listenInPoolThread(labelFuture1);
            } else {
                String errMsg = String.format("RPC call to remove custom FIB entries on dpn %s for " + "prefix %s Failed - %s", dpnId, externalIp, result.getErrors());
                LOG.error(errMsg);
                return Futures.immediateFailedFuture(new RuntimeException(errMsg));
            }
        }, MoreExecutors.directExecutor());
        Futures.addCallback(labelFuture, new FutureCallback<RpcResult<RemoveVpnLabelOutput>>() {

            @Override
            public void onFailure(@NonNull Throwable error) {
                LOG.error("delFibTsAndReverseTraffic : Error in removing the label:{} or custom fib entries" + "got external ip {}", label, extIp, error);
            }

            @Override
            public void onSuccess(@NonNull RpcResult<RemoveVpnLabelOutput> result) {
                if (result.isSuccessful()) {
                    LOG.debug("delFibTsAndReverseTraffic : Successfully removed the label for the prefix {} " + "from VPN {}", externalIp, externalVpn);
                } else {
                    LOG.error("delFibTsAndReverseTraffic : Error in removing the label for prefix {} " + " from VPN {}, {}", externalIp, externalVpn, result.getErrors());
                }
            }
        }, MoreExecutors.directExecutor());
    } else {
        LOG.debug("delFibTsAndReverseTraffic: switch-over is happened on DpnId {}. No need to release allocated " + "label {} for external fixed ip {} for router {}", dpnId, label, externalIp, routerId);
    }
}
Also used : 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) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes) RemoveVpnLabelOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.RemoveVpnLabelOutput) RemoveVpnLabelInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.RemoveVpnLabelInput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) RemoveVpnLabelInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.RemoveVpnLabelInputBuilder) 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) RemoveFibEntryInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.RemoveFibEntryInputBuilder) RemoveFibEntryInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.RemoveFibEntryInput) Uint32(org.opendaylight.yangtools.yang.common.Uint32)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)152 ArrayList (java.util.ArrayList)78 Uint32 (org.opendaylight.yangtools.yang.common.Uint32)76 ExecutionException (java.util.concurrent.ExecutionException)63 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)44 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)43 Routers (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)34 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)34 BigInteger (java.math.BigInteger)33 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)33 ExternalIps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)29 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)29 Logger (org.slf4j.Logger)27 LoggerFactory (org.slf4j.LoggerFactory)27 Inject (javax.inject.Inject)25 Singleton (javax.inject.Singleton)25 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)25 InternalToExternalPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap)24 List (java.util.List)23 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)23