Search in sources :

Example 21 with WriteTransaction

use of org.opendaylight.mdsal.binding.api.WriteTransaction in project netvirt by opendaylight.

the class PolicyRouteFlowProgrammer method programPolicyClassifierFlow.

public void programPolicyClassifierFlow(String policyClassifierName, BigInteger localDpId, BigInteger remoteDpId, int addOrRemove, boolean createIfMissing) {
    long policyClassifierId = policyIdManager.getPolicyClassifierId(policyClassifierName);
    if (policyClassifierId == PolicyServiceConstants.INVALID_ID) {
        LOG.error("Failed to get policy classifier id for classifier {}", policyClassifierName);
        return;
    }
    long groupId = policyIdManager.getPolicyClassifierGroupId(policyClassifierName, remoteDpId);
    if (groupId == PolicyServiceConstants.INVALID_ID) {
        LOG.error("Failed to get group id for policy classifier {} DPN {}", policyClassifierName, remoteDpId);
        return;
    }
    if (addOrRemove == NwConstants.ADD_FLOW && createIfMissing) {
        addPolicyClassifierGroup(policyClassifierName, localDpId, remoteDpId, addOrRemove, groupId);
    }
    List<InstructionInfo> instructions = policyFlowUtil.getPolicyRouteInstructions(groupId);
    coordinator.enqueueJob(policyClassifierName, () -> {
        WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
        programPolicyClassifierFlow(policyClassifierName, policyClassifierId, instructions, localDpId, remoteDpId, tx, addOrRemove);
        return Collections.singletonList(tx.submit());
    });
}
Also used : WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo)

Example 22 with WriteTransaction

use of org.opendaylight.mdsal.binding.api.WriteTransaction in project netvirt by opendaylight.

the class BgpRouteVrfEntryHandler method deleteRemoteRoute.

// Allow deprecated TransactionRunner calls for now
@SuppressWarnings("ForbidCertainMethod")
public void deleteRemoteRoute(@Nullable final Uint64 localDpnId, final Uint64 remoteDpnId, final Uint32 vpnId, final VrfTablesKey vrfTableKey, final VrfEntry vrfEntry, Optional<Routes> extraRouteOptional, @Nullable WriteTransaction tx, List<SubTransaction> subTxns) {
    if (tx == null) {
        LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.CONFIGURATION, newTx -> deleteRemoteRoute(localDpnId, remoteDpnId, vpnId, vrfTableKey, vrfEntry, extraRouteOptional, TransactionAdapter.toWriteTransaction(newTx))), LOG, "Error deleting remote route");
        return;
    }
    LOG.debug("deleting remote route: prefix={}, vpnId={} localDpnId {} remoteDpnId {}", vrfEntry.getDestPrefix(), vpnId, localDpnId, remoteDpnId);
    String rd = vrfTableKey.getRouteDistinguisher();
    if (localDpnId != null && !Uint64.ZERO.equals(localDpnId)) {
        // localDpnId is not known when clean up happens for last vm for a vpn on a dpn
        if (extraRouteOptional.isPresent()) {
            nexthopManager.deleteLoadBalancingNextHop(vpnId, remoteDpnId, vrfEntry.getDestPrefix());
        }
        deleteFibEntryForBgpRoutes(remoteDpnId, vpnId, vrfEntry, rd, tx, subTxns);
        return;
    }
    // below two reads are kept as is, until best way is found to identify dpnID
    VpnNexthop localNextHopInfo = nexthopManager.getVpnNexthop(vpnId, vrfEntry.getDestPrefix());
    if (extraRouteOptional.isPresent()) {
        nexthopManager.deleteLoadBalancingNextHop(vpnId, remoteDpnId, vrfEntry.getDestPrefix());
    } else {
        checkDpnDeleteFibEntry(localNextHopInfo, remoteDpnId, vpnId, vrfEntry, rd, tx, subTxns);
    }
}
Also used : ActionableResources(org.opendaylight.genius.utils.batching.ActionableResources) LoggerFactory(org.slf4j.LoggerFactory) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) Nullable(org.eclipse.jdt.annotation.Nullable) DataTreeEventCallbackRegistrar(org.opendaylight.genius.datastoreutils.listeners.DataTreeEventCallbackRegistrar) Map(java.util.Map) Datastore(org.opendaylight.mdsal.binding.util.Datastore) Identifier(org.opendaylight.yangtools.concepts.Identifier) LoggingFutures(org.opendaylight.infrautils.utils.concurrent.LoggingFutures) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) UpgradeState(org.opendaylight.serviceutils.upgrade.UpgradeState) VpnToDpnListKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnListKey) ResourceBatchingManager(org.opendaylight.genius.utils.batching.ResourceBatchingManager) TunnelTypeMplsOverGre(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeMplsOverGre) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.extra.routes.Routes) BlockingQueue(java.util.concurrent.BlockingQueue) ActionNxLoadInPort(org.opendaylight.genius.mdsalutil.actions.ActionNxLoadInPort) ActionPushMpls(org.opendaylight.genius.mdsalutil.actions.ActionPushMpls) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) SubTransaction(org.opendaylight.genius.utils.batching.SubTransaction) List(java.util.List) ActionSetFieldEthernetDestination(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetDestination) ManagedNewTransactionRunnerImpl(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl) TunnelTypeBase(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeBase) VpnInstanceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry) PostConstruct(javax.annotation.PostConstruct) ActionableResource(org.opendaylight.genius.utils.batching.ActionableResource) Optional(java.util.Optional) ActionSetFieldMplsLabel(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldMplsLabel) ActionSetFieldTunnelId(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldTunnelId) Uint64(org.opendaylight.yangtools.yang.common.Uint64) ResourceHandler(org.opendaylight.genius.utils.batching.ResourceHandler) ManagedNewTransactionRunner(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner) VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) Singleton(javax.inject.Singleton) TransactionAdapter(org.opendaylight.mdsal.binding.util.TransactionAdapter) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) TunnelTypeVxlan(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeVxlan) Objects.requireNonNull(java.util.Objects.requireNonNull) ActionRegLoad(org.opendaylight.genius.mdsalutil.actions.ActionRegLoad) NwConstants(org.opendaylight.genius.mdsalutil.NwConstants) VpnNexthop(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.VpnNexthop) VpnExtraRouteHelper(org.opendaylight.netvirt.vpnmanager.api.VpnExtraRouteHelper) Uint32(org.opendaylight.yangtools.yang.common.Uint32) ActionGroup(org.opendaylight.genius.mdsalutil.actions.ActionGroup) Logger(org.slf4j.Logger) VrfTablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesKey) WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) VrfTables(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTables) Consumer(java.util.function.Consumer) Collectors.toList(java.util.stream.Collectors.toList) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) Prefixes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.Prefixes) VpnToDpnList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnList) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) VpnNexthop(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.VpnNexthop)

Example 23 with WriteTransaction

use of org.opendaylight.mdsal.binding.api.WriteTransaction in project netvirt by opendaylight.

the class PolicyAceFlowProgrammer method programAceFlows.

public void programAceFlows(Ace ace, List<InstructionInfo> instructions, BigInteger dpId, int addOrRemove) {
    Optional<PolicyAceFlowWrapper> policyFlowWrapperOpt = getPolicyAceFlowWrapper(ace.getMatches());
    if (policyFlowWrapperOpt.isPresent()) {
        PolicyAceFlowWrapper policyFlowWrapper = policyFlowWrapperOpt.get();
        if (policyFlowWrapper.isPartial()) {
            LOG.debug("Delaying policy ACE rule {} installation due to partial information", ace.getRuleName());
            return;
        }
        BigInteger policyFlowDpId = policyFlowWrapper.getDpId();
        if (!BigInteger.ZERO.equals(policyFlowDpId) && !Objects.equals(dpId, policyFlowDpId)) {
            LOG.trace("Ignoring policy ACE rule {} flow {} on DPN {}", ace.getRuleName(), policyFlowWrapper.getFlowName(), dpId);
            return;
        }
    }
    Map<String, List<MatchInfoBase>> aclFlowMap = aclServiceUtil.programIpFlow(ace.getMatches());
    if (aclFlowMap == null || aclFlowMap.isEmpty()) {
        LOG.warn("Failed to create flow matches for ACE rule {}", ace.getRuleName());
        return;
    }
    coordinator.enqueueJob(ace.getRuleName(), () -> {
        WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
        aclFlowMap.forEach((flowName, matches) -> {
            String policyFlowName = "Policy_" + flowName;
            List<MatchInfoBase> policyMatches = matches;
            int policyPriority = PolicyServiceConstants.POLICY_FLOW_PRIOPITY;
            if (policyFlowWrapperOpt.isPresent()) {
                PolicyAceFlowWrapper policyFlowWrapper = policyFlowWrapperOpt.get();
                policyFlowName += '_' + policyFlowWrapper.getFlowName();
                policyPriority = policyFlowWrapper.getPriority();
                policyMatches = Stream.concat(matches.stream(), policyFlowWrapper.getMatches().stream()).collect(Collectors.toList());
            }
            LOG.debug("{} policy ACE rule {} on DPN {} flow {}", addOrRemove == NwConstants.ADD_FLOW ? "Installing" : "Removing", ace.getRuleName(), dpId, policyFlowName);
            policyFlowUtil.updateFlowToTx(dpId, NwConstants.EGRESS_POLICY_CLASSIFIER_TABLE, policyFlowName, policyPriority, NwConstants.EGRESS_POLICY_CLASSIFIER_COOKIE, policyMatches, instructions, addOrRemove, tx);
        });
        return Collections.singletonList(tx.submit());
    });
}
Also used : WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) BigInteger(java.math.BigInteger) List(java.util.List) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase)

Aggregations

WriteTransaction (org.opendaylight.mdsal.binding.api.WriteTransaction)23 InstructionInfo (org.opendaylight.genius.mdsalutil.InstructionInfo)6 List (java.util.List)5 ArrayList (java.util.ArrayList)4 Optional (java.util.Optional)4 Collectors.toList (java.util.stream.Collectors.toList)4 Inject (javax.inject.Inject)4 Singleton (javax.inject.Singleton)4 NonNull (org.eclipse.jdt.annotation.NonNull)4 Nullable (org.eclipse.jdt.annotation.Nullable)4 DataTreeEventCallbackRegistrar (org.opendaylight.genius.datastoreutils.listeners.DataTreeEventCallbackRegistrar)4 ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)4 NwConstants (org.opendaylight.genius.mdsalutil.NwConstants)4 ActionNxLoadInPort (org.opendaylight.genius.mdsalutil.actions.ActionNxLoadInPort)4 ActionSetFieldEthernetDestination (org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetDestination)4 ActionSetFieldTunnelId (org.opendaylight.genius.mdsalutil.actions.ActionSetFieldTunnelId)4 InstructionApplyActions (org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)4 Inet4Address (java.net.Inet4Address)3 InetAddress (java.net.InetAddress)3 UnknownHostException (java.net.UnknownHostException)3