use of org.opendaylight.mdsal.binding.api.WriteTransaction in project netvirt by opendaylight.
the class BaseVrfEntryHandler method makeConnectedRoute.
// Allow deprecated TransactionRunner calls for now
@SuppressWarnings("ForbidCertainMethod")
protected void makeConnectedRoute(Uint64 dpId, Uint32 vpnId, VrfEntry vrfEntry, String rd, @Nullable List<InstructionInfo> instructions, int addOrRemove, WriteTransaction tx, @Nullable List<SubTransaction> subTxns) {
if (tx == null) {
LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.CONFIGURATION, newTx -> makeConnectedRoute(dpId, vpnId, vrfEntry, rd, instructions, addOrRemove, TransactionAdapter.toWriteTransaction(newTx), subTxns)), LOG, "Error making connected route");
return;
}
LOG.trace("makeConnectedRoute: vrfEntry {}", vrfEntry);
String[] values = vrfEntry.getDestPrefix().split("/");
String ipAddress = values[0];
int prefixLength = values.length == 1 ? 0 : Integer.parseInt(values[1]);
if (addOrRemove == NwConstants.ADD_FLOW) {
LOG.debug("Adding route to DPN {} for rd {} prefix {} ", dpId, rd, vrfEntry.getDestPrefix());
} else {
LOG.debug("Removing route from DPN {} for rd {} prefix {}", dpId, rd, vrfEntry.getDestPrefix());
}
InetAddress destPrefix;
try {
destPrefix = InetAddress.getByName(ipAddress);
} catch (UnknownHostException e) {
LOG.error("Failed to get destPrefix for prefix {} rd {} VpnId {} DPN {}", vrfEntry.getDestPrefix(), rd, vpnId, dpId, e);
return;
}
List<MatchInfo> matches = new ArrayList<>();
matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId.longValue()), MetaDataUtil.METADATA_MASK_VRFID));
if (destPrefix instanceof Inet4Address) {
matches.add(MatchEthernetType.IPV4);
if (prefixLength != 0) {
matches.add(new MatchIpv4Destination(destPrefix.getHostAddress(), Integer.toString(prefixLength)));
}
} else {
matches.add(MatchEthernetType.IPV6);
if (prefixLength != 0) {
matches.add(new MatchIpv6Destination(destPrefix.getHostAddress() + "/" + prefixLength));
}
}
int priority = DEFAULT_FIB_FLOW_PRIORITY + prefixLength;
String flowRef = FibUtil.getFlowRef(dpId, NwConstants.L3_FIB_TABLE, rd, priority, destPrefix);
FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.L3_FIB_TABLE, flowRef, priority, flowRef, 0, 0, COOKIE_VM_FIB_TABLE, matches, instructions);
Flow flow = flowEntity.getFlowBuilder().build();
String flowId = flowEntity.getFlowId();
FlowKey flowKey = new FlowKey(new FlowId(flowId));
Node nodeDpn = FibUtil.buildDpnNode(dpId);
InstanceIdentifier<Flow> flowInstanceId = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeDpn.key()).augmentation(FlowCapableNode.class).child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flowKey).build();
if (RouteOrigin.value(vrfEntry.getOrigin()) == RouteOrigin.BGP) {
SubTransaction subTransaction = new SubTransactionImpl();
if (addOrRemove == NwConstants.ADD_FLOW) {
subTransaction.setInstanceIdentifier(flowInstanceId);
subTransaction.setInstance(flow);
subTransaction.setAction(SubTransaction.CREATE);
} else {
subTransaction.setInstanceIdentifier(flowInstanceId);
subTransaction.setAction(SubTransaction.DELETE);
}
subTxns.add(subTransaction);
}
if (addOrRemove == NwConstants.ADD_FLOW) {
tx.mergeParentStructurePut(LogicalDatastoreType.CONFIGURATION, flowInstanceId, flow);
} else {
tx.delete(LogicalDatastoreType.CONFIGURATION, flowInstanceId);
}
}
use of org.opendaylight.mdsal.binding.api.WriteTransaction in project netvirt by opendaylight.
the class BaseVrfEntryHandler 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) {
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());
}
makeConnectedRoute(remoteDpnId, vpnId, vrfEntry, rd, null, NwConstants.DEL_FLOW, tx, null);
LOG.debug("Successfully delete FIB entry: vrfEntry={}, vpnId={}", vrfEntry.getDestPrefix(), vpnId);
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, null);
}
}
use of org.opendaylight.mdsal.binding.api.WriteTransaction in project netvirt by opendaylight.
the class BaseVrfEntryHandler method programRemoteFib.
// Allow deprecated TransactionRunner calls for now
@SuppressWarnings("ForbidCertainMethod")
public void programRemoteFib(final Uint64 remoteDpnId, final Uint32 vpnId, final VrfEntry vrfEntry, WriteTransaction tx, String rd, List<AdjacencyResult> adjacencyResults, @Nullable List<SubTransaction> subTxns) {
if (upgradeState.isUpgradeInProgress()) {
InstanceIdentifier<Interface> absentInterfaceStateIid = getFirstAbsentInterfaceStateIid(adjacencyResults);
if (absentInterfaceStateIid != null) {
LOG.info("programRemoteFib: interface state for {} not yet present, waiting...", absentInterfaceStateIid);
eventCallbacks.onAddOrUpdate(LogicalDatastoreType.OPERATIONAL, absentInterfaceStateIid, (before, after) -> {
LOG.info("programRemoteFib: waited for and got interface state {}", absentInterfaceStateIid);
LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.CONFIGURATION, (wtx) -> programRemoteFib(remoteDpnId, vpnId, vrfEntry, TransactionAdapter.toWriteTransaction(wtx), rd, adjacencyResults, null)), LOG, "Failed to program remote FIB {}", absentInterfaceStateIid);
return DataTreeEventCallbackRegistrar.NextAction.UNREGISTER;
}, Duration.of(15, ChronoUnit.MINUTES), (iid) -> {
LOG.error("programRemoteFib: timed out waiting for {}", absentInterfaceStateIid);
LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.CONFIGURATION, (wtx) -> programRemoteFib(remoteDpnId, vpnId, vrfEntry, TransactionAdapter.toWriteTransaction(wtx), rd, adjacencyResults, null)), LOG, "Failed to program timed-out remote FIB {}", absentInterfaceStateIid);
});
return;
}
}
List<InstructionInfo> instructions = new ArrayList<>();
for (AdjacencyResult adjacencyResult : adjacencyResults) {
List<ActionInfo> actionInfos = new ArrayList<>();
String egressInterface = adjacencyResult.getInterfaceName();
if (FibUtil.isTunnelInterface(adjacencyResult)) {
addTunnelInterfaceActions(adjacencyResult, vpnId, vrfEntry, actionInfos, rd);
} else {
addRewriteDstMacAction(vpnId, vrfEntry, null, actionInfos);
}
List<ActionInfo> egressActions = nextHopManager.getEgressActionsForInterface(egressInterface, actionInfos.size(), true, vpnId, vrfEntry.getDestPrefix());
if (egressActions.isEmpty()) {
LOG.error("Failed to retrieve egress action for prefix {} route-paths {} interface {}. " + "Aborting remote FIB entry creation.", vrfEntry.getDestPrefix(), new ArrayList<RoutePaths>(vrfEntry.nonnullRoutePaths().values()), egressInterface);
return;
}
actionInfos.addAll(egressActions);
instructions.add(new InstructionApplyActions(actionInfos));
}
makeConnectedRoute(remoteDpnId, vpnId, vrfEntry, rd, instructions, NwConstants.ADD_FLOW, tx, subTxns);
}
use of org.opendaylight.mdsal.binding.api.WriteTransaction in project netvirt by opendaylight.
the class ElanUtils method delete.
@SuppressWarnings("checkstyle:ForbidCertainMethod")
public static <T extends DataObject> void delete(DataBroker broker, LogicalDatastoreType datastoreType, InstanceIdentifier<T> path) {
WriteTransaction tx = broker.newWriteOnlyTransaction();
tx.delete(datastoreType, path);
FluentFuture<? extends @NonNull CommitInfo> future = tx.commit();
future.addCallback(DEFAULT_CALLBACK, MoreExecutors.directExecutor());
}
use of org.opendaylight.mdsal.binding.api.WriteTransaction in project netvirt by opendaylight.
the class PolicyRouteFlowProgrammer method programPolicyClassifierFlows.
public void programPolicyClassifierFlows(String policyClassifierName, List<BigInteger> localDpIds, List<BigInteger> remoteDpIds, int addOrRemove) {
long policyClassifierId = policyIdManager.getPolicyClassifierId(policyClassifierName);
if (policyClassifierId == PolicyServiceConstants.INVALID_ID) {
LOG.error("Failed to get policy classifier id for classifier {}", policyClassifierName);
return;
}
coordinator.enqueueJob(policyClassifierName, () -> {
WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
remoteDpIds.forEach(remoteDpId -> {
long groupId = policyIdManager.getPolicyClassifierGroupId(policyClassifierName, remoteDpId);
if (groupId != PolicyServiceConstants.INVALID_ID) {
List<InstructionInfo> instructions = policyFlowUtil.getPolicyRouteInstructions(groupId);
localDpIds.forEach(localDpId -> {
if (!remoteDpId.equals(localDpId)) {
programPolicyClassifierFlow(policyClassifierName, policyClassifierId, instructions, localDpId, remoteDpId, tx, addOrRemove);
}
});
} else {
LOG.error("Failed to get group id for policy classifier {} DPN {}", policyClassifierName, remoteDpId);
}
});
return Collections.singletonList(tx.submit());
});
}
Aggregations