use of org.opendaylight.genius.utils.batching.SubTransaction in project netvirt by opendaylight.
the class VrfEntryListener method populateFibOnNewDpn.
public void populateFibOnNewDpn(final BigInteger dpnId, final long vpnId, final String rd, final FutureCallback<List<Void>> callback) {
LOG.trace("New dpn {} for vpn {} : populateFibOnNewDpn", dpnId, rd);
InstanceIdentifier<VrfTables> id = buildVrfId(rd);
final VpnInstanceOpDataEntry vpnInstance = fibUtil.getVpnInstance(rd);
final Optional<VrfTables> vrfTable = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
List<SubTransaction> txnObjects = new ArrayList<>();
if (!vrfTable.isPresent()) {
LOG.info("populateFibOnNewDpn: dpn: {}: VRF Table not yet available for RD {}", dpnId, rd);
if (callback != null) {
List<ListenableFuture<Void>> futures = new ArrayList<>();
ListenableFuture<List<Void>> listenableFuture = Futures.allAsList(futures);
Futures.addCallback(listenableFuture, callback, MoreExecutors.directExecutor());
}
return;
}
jobCoordinator.enqueueJob(FibUtil.getJobKeyForVpnIdDpnId(vpnId, dpnId), () -> {
List<ListenableFuture<Void>> futures = new ArrayList<>();
synchronized (vpnInstance.getVpnInstanceName().intern()) {
futures.add(retryingTxRunner.callWithNewReadWriteTransactionAndSubmit(tx -> {
for (final VrfEntry vrfEntry : vrfTable.get().getVrfEntry()) {
SubnetRoute subnetRoute = vrfEntry.getAugmentation(SubnetRoute.class);
if (subnetRoute != null) {
long elanTag = subnetRoute.getElantag();
installSubnetRouteInFib(dpnId, elanTag, rd, vpnId, vrfEntry, tx);
installSubnetBroadcastAddrDropRule(dpnId, rd, vpnId, vrfEntry, NwConstants.ADD_FLOW, tx);
continue;
}
RouterInterface routerInt = vrfEntry.getAugmentation(RouterInterface.class);
if (routerInt != null) {
LOG.trace("Router augmented vrfentry found rd:{}, uuid:{}, ip:{}, mac:{}", rd, routerInt.getUuid(), routerInt.getIpAddress(), routerInt.getMacAddress());
routerInterfaceVrfEntryHandler.installRouterFibEntry(vrfEntry, dpnId, vpnId, routerInt.getIpAddress(), new MacAddress(routerInt.getMacAddress()), NwConstants.ADD_FLOW);
continue;
}
// Handle local flow creation for imports
if (RouteOrigin.value(vrfEntry.getOrigin()) == RouteOrigin.SELF_IMPORTED) {
java.util.Optional<Long> optionalLabel = FibUtil.getLabelFromRoutePaths(vrfEntry);
if (optionalLabel.isPresent()) {
List<String> nextHopList = FibHelper.getNextHopListFromRoutePaths(vrfEntry);
LabelRouteInfo lri = getLabelRouteInfo(optionalLabel.get());
if (isPrefixAndNextHopPresentInLri(vrfEntry.getDestPrefix(), nextHopList, lri)) {
if (lri.getDpnId().equals(dpnId)) {
createLocalFibEntry(vpnId, rd, vrfEntry);
continue;
}
}
}
}
boolean shouldCreateRemoteFibEntry = shouldCreateFibEntryForVrfAndVpnIdOnDpn(vpnId, vrfEntry, dpnId);
if (shouldCreateRemoteFibEntry) {
LOG.trace("Will create remote FIB entry for vrfEntry {} on DPN {}", vrfEntry, dpnId);
if (RouteOrigin.BGP.getValue().equals(vrfEntry.getOrigin())) {
bgpRouteVrfEntryHandler.createRemoteFibEntry(dpnId, vpnId, vrfTable.get().getRouteDistinguisher(), vrfEntry, tx, txnObjects);
} else {
createRemoteFibEntry(dpnId, vpnId, vrfTable.get().getRouteDistinguisher(), vrfEntry, tx);
}
}
}
}));
if (callback != null) {
ListenableFuture<List<Void>> listenableFuture = Futures.allAsList(futures);
Futures.addCallback(listenableFuture, callback, MoreExecutors.directExecutor());
}
}
return futures;
});
}
use of org.opendaylight.genius.utils.batching.SubTransaction in project netvirt by opendaylight.
the class VrfEntryListener method populateExternalRoutesOnDpn.
public void populateExternalRoutesOnDpn(final BigInteger dpnId, final long vpnId, final String rd, final String localNextHopIp, final String remoteNextHopIp) {
LOG.trace("populateExternalRoutesOnDpn : dpn {}, vpn {}, rd {}, localNexthopIp {} , remoteNextHopIp {} ", dpnId, vpnId, rd, localNextHopIp, remoteNextHopIp);
InstanceIdentifier<VrfTables> id = buildVrfId(rd);
final VpnInstanceOpDataEntry vpnInstance = fibUtil.getVpnInstance(rd);
List<SubTransaction> txnObjects = new ArrayList<>();
final Optional<VrfTables> vrfTable = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
if (vrfTable.isPresent()) {
jobCoordinator.enqueueJob(FibUtil.getJobKeyForVpnIdDpnId(vpnId, dpnId), () -> {
List<ListenableFuture<Void>> futures = new ArrayList<>();
synchronized (vpnInstance.getVpnInstanceName().intern()) {
WriteTransaction writeCfgTxn = dataBroker.newWriteOnlyTransaction();
vrfTable.get().getVrfEntry().stream().filter(vrfEntry -> RouteOrigin.BGP == RouteOrigin.value(vrfEntry.getOrigin())).forEach(bgpRouteVrfEntryHandler.getConsumerForCreatingRemoteFib(dpnId, vpnId, rd, remoteNextHopIp, vrfTable, writeCfgTxn, txnObjects));
futures.add(writeCfgTxn.submit());
}
return futures;
});
}
}
use of org.opendaylight.genius.utils.batching.SubTransaction in project netvirt by opendaylight.
the class BaseVrfEntryHandler method makeConnectedRoute.
protected void makeConnectedRoute(BigInteger dpId, long vpnId, VrfEntry vrfEntry, String rd, List<InstructionInfo> instructions, int addOrRemove, WriteTransaction tx, List<SubTransaction> subTxns) {
Boolean wrTxPresent = true;
if (tx == null) {
wrTxPresent = false;
tx = dataBroker.newWriteOnlyTransaction();
}
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), 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.getKey()).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.put(LogicalDatastoreType.CONFIGURATION, flowInstanceId, flow, true);
} else {
tx.delete(LogicalDatastoreType.CONFIGURATION, flowInstanceId);
}
if (!wrTxPresent) {
tx.submit();
}
}
use of org.opendaylight.genius.utils.batching.SubTransaction in project netvirt by opendaylight.
the class EvpnVrfEntryHandler method deleteRemoteEvpnFlows.
private void deleteRemoteEvpnFlows(String rd, VrfEntry vrfEntry, VpnInstanceOpDataEntry vpnInstance, VrfTablesKey vrfTableKey, List<BigInteger> localDpnIdList) {
List<VpnToDpnList> vpnToDpnList = vpnInstance.getVpnToDpnList();
List<SubTransaction> subTxns = new ArrayList<>();
if (vpnToDpnList != null) {
jobCoordinator.enqueueJob("FIB" + rd + vrfEntry.getDestPrefix(), () -> {
WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
final Optional<Routes> extraRouteOptional = Optional.absent();
if (localDpnIdList.size() <= 0) {
for (VpnToDpnList curDpn1 : vpnToDpnList) {
if (RouteOrigin.value(vrfEntry.getOrigin()) == RouteOrigin.BGP) {
if (curDpn1.getDpnState() == VpnToDpnList.DpnState.Active) {
bgpRouteVrfEntryHandler.deleteRemoteRoute(BigInteger.ZERO, curDpn1.getDpnId(), vpnInstance.getVpnId(), vrfTableKey, vrfEntry, extraRouteOptional, tx, subTxns);
}
} else {
deleteRemoteRoute(BigInteger.ZERO, curDpn1.getDpnId(), vpnInstance.getVpnId(), vrfTableKey, vrfEntry, extraRouteOptional, tx);
}
}
} else {
for (BigInteger localDpnId : localDpnIdList) {
for (VpnToDpnList curDpn2 : vpnToDpnList) {
if (!curDpn2.getDpnId().equals(localDpnId)) {
if (RouteOrigin.value(vrfEntry.getOrigin()) == RouteOrigin.BGP) {
if (curDpn2.getDpnState() == VpnToDpnList.DpnState.Active) {
bgpRouteVrfEntryHandler.deleteRemoteRoute(localDpnId, curDpn2.getDpnId(), vpnInstance.getVpnId(), vrfTableKey, vrfEntry, extraRouteOptional, tx, subTxns);
}
} else {
deleteRemoteRoute(localDpnId, curDpn2.getDpnId(), vpnInstance.getVpnId(), vrfTableKey, vrfEntry, extraRouteOptional, tx);
}
}
}
}
}
List<ListenableFuture<Void>> futures = new ArrayList<>();
futures.add(tx.submit());
return futures;
});
}
}
use of org.opendaylight.genius.utils.batching.SubTransaction in project genius by opendaylight.
the class MdSalUtilBatchHandler method buildSubTransactions.
private void buildSubTransactions(List<SubTransaction> transactionObjects, InstanceIdentifier identifier, Object data, short subTransactionType) {
// enable retries
SubTransaction subTransaction = new SubTransactionImpl();
subTransaction.setInstanceIdentifier(identifier);
subTransaction.setInstance(data);
subTransaction.setAction(subTransactionType);
transactionObjects.add(subTransaction);
}
Aggregations