use of org.opendaylight.mdsal.binding.util.TypedWriteTransaction in project netvirt by opendaylight.
the class FibUtil method removeOrUpdateFibEntry.
/**
* Removes a specific Nexthop from a VrfEntry. If Nexthop to remove is the
* last one in the VrfEntry, then the VrfEntry is removed too.
* @param rd Route-Distinguisher to which the VrfEntry belongs to
* @param prefix Destination of the route
* @param nextHopToRemove Specific nexthop within the Route to be removed.
* If null or empty, then the whole VrfEntry is removed
*/
public void removeOrUpdateFibEntry(String rd, String prefix, String nextHopToRemove, TypedWriteTransaction<Configuration> writeConfigTxn) {
LOG.debug("Removing fib entry with destination prefix {} from vrf table for rd {} nextHop {}", prefix, rd, nextHopToRemove);
// Looking for existing prefix in MDSAL database
InstanceIdentifier<VrfEntry> vrfEntryId = InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(rd)).child(VrfEntry.class, new VrfEntryKey(prefix)).build();
Optional<VrfEntry> entry = Optional.empty();
try {
entry = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vrfEntryId);
} catch (ExecutionException | InterruptedException e) {
LOG.error("removeOrUpdateFibEntry: Exception while reading vrfEntry for the prefix {} rd {} nexthop {}", prefix, rd, nextHopToRemove, e);
}
if (entry.isPresent()) {
final List<RoutePaths> routePaths = new ArrayList<>(entry.get().nonnullRoutePaths().values());
if (routePaths == null || routePaths.isEmpty()) {
LOG.warn("routePaths is null/empty for given rd {}, prefix {}", rd, prefix);
return;
}
java.util.Optional<RoutePaths> optRoutePath = routePaths.stream().filter(routePath -> Objects.equals(routePath.getNexthopAddress(), nextHopToRemove)).findFirst();
if (!optRoutePath.isPresent()) {
LOG.error("Unable to find a routePath that contains the given nextHop to remove {}", nextHopToRemove);
return;
}
RoutePaths routePath = optRoutePath.get();
if (routePaths.size() == 1) {
// Remove the whole entry
if (writeConfigTxn != null) {
writeConfigTxn.delete(vrfEntryId);
} else {
MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, vrfEntryId);
}
LOG.info("Removed Fib Entry rd {} prefix {} nextHop {}", rd, prefix, nextHopToRemove);
} else {
InstanceIdentifier<RoutePaths> routePathsId = FibHelper.buildRoutePathId(rd, prefix, routePath.getNexthopAddress());
// Remove route
MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, routePathsId);
LOG.info("Removed Route Path rd {} prefix {}, nextHop {}, label {}", rd, prefix, routePath.getNexthopAddress(), routePath.getLabel());
}
} else {
LOG.warn("Could not find VrfEntry for Route-Distinguisher {} prefix {} nexthop {}", rd, prefix, nextHopToRemove);
}
}
use of org.opendaylight.mdsal.binding.util.TypedWriteTransaction in project netvirt by opendaylight.
the class NeutronvpnManager method deleteVpnInterface.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected void deleteVpnInterface(String infName, @Nullable String vpnId, @Nullable TypedWriteTransaction<Configuration> wrtConfigTxn) {
if (wrtConfigTxn == null) {
LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> deleteVpnInterface(infName, vpnId, tx)), LOG, "Error deleting VPN interface {} {}", infName, vpnId);
return;
}
InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
Optional<VpnInterface> optionalVpnInterface;
try {
optionalVpnInterface = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
} catch (ExecutionException | InterruptedException ex) {
LOG.error("Error during deletion of vpninterface {}", infName, ex);
return;
}
if (!optionalVpnInterface.isPresent()) {
LOG.warn("Deletion of vpninterface {}, optionalVpnInterface is not present()", infName);
return;
}
if (vpnId != null) {
VpnInterface vpnInterface = optionalVpnInterface.get();
Map<VpnInstanceNamesKey, VpnInstanceNames> keyVpnInstanceNamesMap = vpnInterface.getVpnInstanceNames();
if (keyVpnInstanceNamesMap != null && VpnHelper.doesVpnInterfaceBelongToVpnInstance(vpnId, new ArrayList<>(keyVpnInstanceNamesMap.values()))) {
VpnHelper.removeVpnInterfaceVpnInstanceNamesFromList(vpnId, new ArrayList<>(keyVpnInstanceNamesMap.values()));
if (!keyVpnInstanceNamesMap.isEmpty()) {
LOG.debug("Deleting vpn interface {} not immediately since vpnInstanceName " + "List not empty", infName);
return;
}
VpnInterfaceBuilder vpnIfBuilder = new VpnInterfaceBuilder(optionalVpnInterface.get()).setVpnInstanceNames(keyVpnInstanceNamesMap);
wrtConfigTxn.put(vpnIfIdentifier, vpnIfBuilder.build());
}
}
LOG.debug("Deleting vpn interface {}", infName);
wrtConfigTxn.delete(vpnIfIdentifier);
}
use of org.opendaylight.mdsal.binding.util.TypedWriteTransaction in project netvirt by opendaylight.
the class VpnInstanceListener method addVpnInstance.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void addVpnInstance(VpnInstance value, TypedWriteTransaction<Configuration> writeConfigTxn, TypedWriteTransaction<Operational> writeOperTxn) {
if (writeConfigTxn == null) {
LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> addVpnInstance(value, tx, writeOperTxn)), LOG, "Error adding VPN instance {}", value);
return;
}
if (writeOperTxn == null) {
LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, tx -> addVpnInstance(value, writeConfigTxn, tx)), LOG, "Error adding VPN instance {}", value);
return;
}
String vpnInstanceName = value.getVpnInstanceName();
Uint32 vpnId = vpnUtil.getUniqueId(VpnConstants.VPN_IDPOOL_NAME, vpnInstanceName);
if (vpnId.longValue() == 0) {
LOG.error("{} addVpnInstance: Unable to fetch label from Id Manager. Bailing out of adding operational" + " data for Vpn Instance {}", LOGGING_PREFIX_ADD, value.getVpnInstanceName());
return;
}
LOG.info("{} addVpnInstance: VPN Id {} generated for VpnInstanceName {}", LOGGING_PREFIX_ADD, vpnId, vpnInstanceName);
String primaryRd = VpnUtil.getPrimaryRd(value);
org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance vpnInstanceToVpnId = VpnUtil.getVpnInstanceToVpnId(vpnInstanceName, vpnId, primaryRd);
writeConfigTxn.mergeParentStructurePut(VpnOperDsUtils.getVpnInstanceToVpnIdIdentifier(vpnInstanceName), vpnInstanceToVpnId);
VpnIds vpnIdToVpnInstance = VpnUtil.getVpnIdToVpnInstance(vpnId, value.getVpnInstanceName(), primaryRd, VpnUtil.isBgpVpn(vpnInstanceName, primaryRd));
writeConfigTxn.mergeParentStructurePut(VpnUtil.getVpnIdToVpnInstanceIdentifier(vpnId), vpnIdToVpnInstance);
try {
String cachedTransType = fibManager.getConfTransType();
if (cachedTransType.equals("Invalid")) {
try {
fibManager.setConfTransType("L3VPN", "VXLAN");
} catch (Exception e) {
LOG.error("{} addVpnInstance: Exception caught setting the L3VPN tunnel transportType for vpn {}", LOGGING_PREFIX_ADD, vpnInstanceName, e);
}
} else {
LOG.debug("{} addVpnInstance: Configured tunnel transport type for L3VPN {} as {}", LOGGING_PREFIX_ADD, vpnInstanceName, cachedTransType);
}
} catch (Exception e) {
LOG.error("{} addVpnInstance: Error when trying to retrieve tunnel transport type for L3VPN {}", LOGGING_PREFIX_ADD, vpnInstanceName, e);
}
VpnInstanceOpDataEntryBuilder builder = new VpnInstanceOpDataEntryBuilder().setVrfId(primaryRd).setVpnId(vpnId).setVpnInstanceName(vpnInstanceName).setVpnState(VpnInstanceOpDataEntry.VpnState.Created);
if (VpnUtil.isBgpVpn(vpnInstanceName, primaryRd)) {
List<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpntargets.VpnTarget> opVpnTargetList = new ArrayList<>();
if (value.getL3vni() != null) {
builder.setL3vni(value.getL3vni());
}
if (value.isL2vpn()) {
builder.setType(VpnInstanceOpDataEntry.Type.L2);
}
VpnTargets vpnTargets = value.getVpnTargets();
if (vpnTargets != null) {
@Nullable Map<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.vpn.instance.vpntargets.VpnTargetKey, VpnTarget> vpnTargetListMap = vpnTargets.nonnullVpnTarget();
if (vpnTargetListMap != null) {
for (VpnTarget vpnTarget : vpnTargetListMap.values()) {
VpnTargetBuilder vpnTargetBuilder = new VpnTargetBuilder().withKey(new VpnTargetKey(vpnTarget.key().getVrfRTValue())).setVrfRTType(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpntargets.VpnTarget.VrfRTType.forValue(vpnTarget.getVrfRTType().getIntValue())).setVrfRTValue(vpnTarget.getVrfRTValue());
opVpnTargetList.add(vpnTargetBuilder.build());
}
}
}
VpnTargetsBuilder vpnTargetsBuilder = new VpnTargetsBuilder().setVpnTarget(opVpnTargetList);
builder.setVpnTargets(vpnTargetsBuilder.build());
List<String> rds = value.getRouteDistinguisher();
builder.setRd(rds);
}
// Get BGP-VPN type configured details from config vpn-instance
builder.setBgpvpnType(VpnInstanceOpDataEntry.BgpvpnType.forValue(value.getBgpvpnType().getIntValue()));
writeOperTxn.mergeParentStructureMerge(VpnUtil.getVpnInstanceOpDataIdentifier(primaryRd), builder.build());
LOG.info("{} addVpnInstance: VpnInstanceOpData populated successfully for vpn {} rd {}", LOGGING_PREFIX_ADD, vpnInstanceName, primaryRd);
}
use of org.opendaylight.mdsal.binding.util.TypedWriteTransaction in project netvirt by opendaylight.
the class VrfEntryListener method installSubnetRouteInFib.
void installSubnetRouteInFib(final Uint64 dpnId, final long elanTag, final String rd, final Uint32 vpnId, final VrfEntry vrfEntry, TypedWriteTransaction<Configuration> tx) {
if (tx == null) {
LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, newTx -> installSubnetRouteInFib(dpnId, elanTag, rd, vpnId, vrfEntry, newTx)), LOG, "Error installing subnet route in FIB");
return;
}
int etherType;
try {
etherType = NWUtil.getEtherTypeFromIpPrefix(vrfEntry.getDestPrefix());
} catch (IllegalArgumentException ex) {
LOG.error("Unable to get etherType for IP Prefix {}", vrfEntry.getDestPrefix());
return;
}
final List<InstructionInfo> instructions = new ArrayList<>();
Uint64 subnetRouteMeta = Uint64.valueOf(BigInteger.valueOf(elanTag).shiftLeft(24).or(BigInteger.valueOf(vpnId.longValue()).shiftLeft(1)));
instructions.add(new InstructionWriteMetadata(subnetRouteMeta, MetaDataUtil.METADATA_MASK_SUBNET_ROUTE));
instructions.add(new InstructionGotoTable(NwConstants.L3_SUBNET_ROUTE_TABLE));
baseVrfEntryHandler.makeConnectedRoute(dpnId, vpnId, vrfEntry, rd, instructions, NwConstants.ADD_FLOW, TransactionAdapter.toWriteTransaction(tx), null);
if (vrfEntry.getRoutePaths() != null) {
for (RoutePaths routePath : vrfEntry.getRoutePaths().values()) {
if (RouteOrigin.value(vrfEntry.getOrigin()) != RouteOrigin.SELF_IMPORTED) {
List<ActionInfo> actionsInfos = new ArrayList<>();
// reinitialize instructions list for LFIB Table
final List<InstructionInfo> LFIBinstructions = new ArrayList<>();
actionsInfos.add(new ActionPopMpls(etherType));
LFIBinstructions.add(new InstructionApplyActions(actionsInfos));
LFIBinstructions.add(new InstructionWriteMetadata(subnetRouteMeta, MetaDataUtil.METADATA_MASK_SUBNET_ROUTE));
LFIBinstructions.add(new InstructionGotoTable(NwConstants.L3_SUBNET_ROUTE_TABLE));
makeLFibTableEntry(dpnId, routePath.getLabel(), LFIBinstructions, DEFAULT_FIB_FLOW_PRIORITY, NwConstants.ADD_FLOW, tx);
}
}
}
}
use of org.opendaylight.mdsal.binding.util.TypedWriteTransaction in project netvirt by opendaylight.
the class VrfEntryListener method makeLFibTableEntry.
private void makeLFibTableEntry(Uint64 dpId, Uint32 label, @Nullable List<InstructionInfo> instructions, int priority, int addOrRemove, TypedWriteTransaction<Configuration> tx) {
if (tx == null) {
LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, newTx -> makeLFibTableEntry(dpId, label, instructions, priority, addOrRemove, newTx)), LOG, "Error making LFIB table entry");
return;
}
List<MatchInfo> matches = new ArrayList<>();
matches.add(MatchEthernetType.MPLS_UNICAST);
matches.add(new MatchMplsLabel(label.longValue()));
// Install the flow entry in L3_LFIB_TABLE
String flowRef = FibUtil.getFlowRef(dpId, NwConstants.L3_LFIB_TABLE, label, priority);
FlowEntity flowEntity;
flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.L3_LFIB_TABLE, flowRef, priority, flowRef, 0, 0, NwConstants.COOKIE_VM_LFIB_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 (addOrRemove == NwConstants.ADD_FLOW) {
tx.mergeParentStructurePut(flowInstanceId, flow);
} else {
tx.delete(flowInstanceId);
}
LOG.debug("LFIB Entry for dpID {} : label : {} instructions {} : key {} {} successfully", dpId, label, instructions, flowKey, NwConstants.ADD_FLOW == addOrRemove ? "ADDED" : "REMOVED");
}
Aggregations