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());
});
}
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);
}
}
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());
});
}
Aggregations