use of org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION in project netvirt by opendaylight.
the class VpnRpcServiceImpl method addStaticRoute.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public ListenableFuture<RpcResult<AddStaticRouteOutput>> addStaticRoute(AddStaticRouteInput input) {
SettableFuture<RpcResult<AddStaticRouteOutput>> result = SettableFuture.create();
String destination = input.getDestination();
String vpnInstanceName = input.getVpnInstanceName();
String nexthop = input.getNexthop();
Uint32 label = input.getLabel();
LOG.info("Adding static route for Vpn {} with destination {}, nexthop {} and label {}", vpnInstanceName, destination, nexthop, label);
Collection<RpcError> rpcErrors = validateAddStaticRouteInput(input);
if (!rpcErrors.isEmpty()) {
result.set(RpcResultBuilder.<AddStaticRouteOutput>failed().withRpcErrors(rpcErrors).build());
return result;
}
if (label == null || label.longValue() == VpnConstants.INVALID_LABEL) {
label = vpnUtil.getUniqueId(VpnConstants.VPN_IDPOOL_NAME, VpnUtil.getNextHopLabelKey(vpnInstanceName, destination));
if (label.longValue() == VpnConstants.INVALID_LABEL) {
String message = "Unable to retrieve a new Label for the new Route";
result.set(RpcResultBuilder.<AddStaticRouteOutput>failed().withError(RpcError.ErrorType.APPLICATION, message).build());
LOG.error("addStaticRoute: Unable to retrieve label for static route with destination {}, vpninstance" + " {}, nexthop {}", destination, vpnInstanceName, nexthop);
return result;
}
}
String vpnRd = vpnUtil.getVpnRd(input.getVpnInstanceName());
VpnInstanceOpDataEntry vpnOpEntry = vpnUtil.getVpnInstanceOpData(vpnRd);
Boolean isVxlan = VpnUtil.isL3VpnOverVxLan(vpnOpEntry.getL3vni());
VrfEntry.EncapType encapType = VpnUtil.getEncapType(isVxlan);
if (vpnRd == null) {
String message = "Could not find Route-Distinguisher for VpnName " + vpnInstanceName;
result.set(RpcResultBuilder.<AddStaticRouteOutput>failed().withError(RpcError.ErrorType.APPLICATION, message).build());
return result;
}
Optional<InterVpnLinkDataComposite> optIVpnLink = interVpnLinkCache.getInterVpnLinkByEndpoint(nexthop);
if (optIVpnLink.isPresent()) {
try {
interVpnLinkUtil.handleStaticRoute(optIVpnLink.get(), vpnInstanceName, destination, nexthop, label);
} catch (Exception e) {
result.set(RpcResultBuilder.<AddStaticRouteOutput>failed().withError(ErrorType.APPLICATION, formatAndLog(LOG::warn, "Could not advertise route [vpn={}, prefix={}, label={}, nexthop={}] to BGP: {}", vpnRd, destination, label, nexthop, e.getMessage(), e)).build());
return result;
}
} else {
try {
txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, confTx -> vpnManager.addExtraRoute(vpnInstanceName, destination, nexthop, vpnRd, null, /* routerId */
vpnOpEntry.getL3vni(), RouteOrigin.STATIC, null, /* intfName */
null, /*Adjacency*/
encapType, new HashSet<>(), /*prefixListForRefreshFib*/
confTx)).get();
} catch (InterruptedException | ExecutionException e) {
LOG.error("Error adding static route {}", input, e);
result.set(RpcResultBuilder.<AddStaticRouteOutput>failed().withError(ErrorType.APPLICATION, "Error adding static route " + input, e).build());
return result;
}
}
AddStaticRouteOutput labelOutput = new AddStaticRouteOutputBuilder().setLabel(label).build();
result.set(RpcResultBuilder.success(labelOutput).build());
return result;
}
use of org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION 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.Datastore.CONFIGURATION in project netvirt by opendaylight.
the class VpnInterfaceManager method updateVpnInterfacesForUnProcessAdjancencies.
public void updateVpnInterfacesForUnProcessAdjancencies(String vpnName) {
String primaryRd = vpnUtil.getVpnRd(vpnName);
VpnInstanceOpDataEntry vpnInstanceOpData = vpnUtil.getVpnInstanceOpData(primaryRd);
if (vpnInstanceOpData == null || vpnInstanceOpData.getVpnToDpnList() == null) {
return;
}
List<VpnToDpnList> vpnToDpnLists = new ArrayList<>(vpnInstanceOpData.getVpnToDpnList().values());
if (vpnToDpnLists == null || vpnToDpnLists.isEmpty()) {
return;
}
LOG.debug("Update the VpnInterfaces for Unprocessed Adjancencies for vpnName:{}", vpnName);
vpnToDpnLists.forEach(vpnToDpnList -> {
if (vpnToDpnList.getVpnInterfaces() == null) {
return;
}
vpnToDpnList.nonnullVpnInterfaces().values().forEach(vpnInterface -> {
try {
InstanceIdentifier<VpnInterfaceOpDataEntry> existingVpnInterfaceId = VpnUtil.getVpnInterfaceOpDataEntryIdentifier(vpnInterface.getInterfaceName(), vpnName);
Optional<VpnInterfaceOpDataEntry> vpnInterfaceOptional = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, existingVpnInterfaceId);
if (!vpnInterfaceOptional.isPresent()) {
return;
}
List<Adjacency> configVpnAdjacencies = vpnUtil.getAdjacenciesForVpnInterfaceFromConfig(vpnInterface.getInterfaceName());
if (configVpnAdjacencies == null) {
LOG.debug("There is no adjacency available for vpnInterface:{}", vpnInterface);
return;
}
List<Adjacency> operationVpnAdjacencies = new ArrayList<>(vpnInterfaceOptional.get().augmentation(AdjacenciesOp.class).nonnullAdjacency().values());
// Due to insufficient rds, some of the extra route wont get processed when it is added.
// The unprocessed adjacencies will be present in config vpn interface DS but will be missing
// in operational DS. These unprocessed adjacencies will be handled below.
// To obtain unprocessed adjacencies, filtering is done by which the missing adjacencies in
// operational DS are retrieved which is used to call addNewAdjToVpnInterface method.
configVpnAdjacencies.stream().filter(adjacency -> operationVpnAdjacencies.stream().noneMatch(operationalAdjacency -> Objects.equals(operationalAdjacency.getIpAddress(), adjacency.getIpAddress()))).forEach(adjacency -> {
LOG.debug("Processing the vpnInterface{} for the Ajacency:{}", vpnInterface, adjacency);
jobCoordinator.enqueueJob("VPNINTERFACE-" + vpnInterface.getInterfaceName(), () -> {
// if the oper tx goes in
if (vpnUtil.isAdjacencyEligibleToVpn(adjacency, vpnName)) {
List<ListenableFuture<?>> futures = new ArrayList<>();
futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, operTx -> {
// set of prefix used, as entry in prefix-to-interface datastore
// is prerequisite for refresh Fib to avoid race condition leading
// to missing remote next hop in bucket actions on bgp-vpn delete
Set<String> prefixListForRefreshFib = new HashSet<>();
ListenableFuture<?> configTxFuture = txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, confTx -> addNewAdjToVpnInterface(existingVpnInterfaceId, primaryRd, adjacency, vpnInterfaceOptional.get().getDpnId(), operTx, confTx, confTx, prefixListForRefreshFib));
Futures.addCallback(configTxFuture, new VpnInterfaceCallBackHandler(primaryRd, prefixListForRefreshFib), MoreExecutors.directExecutor());
futures.add(configTxFuture);
}));
return futures;
} else {
return emptyList();
}
});
});
} catch (InterruptedException | ExecutionException e) {
LOG.error("updateVpnInterfacesForUnProcessAdjancencies: Failed to read data store for vpn {} rd {}", vpnName, primaryRd);
}
});
});
}
use of org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION in project netvirt by opendaylight.
the class NeutronSecurityGroupListener method add.
@Override
public void add(InstanceIdentifier<SecurityGroup> instanceIdentifier, SecurityGroup securityGroup) {
LOG.trace("Adding securityGroup: {}", securityGroup);
String securityGroupId = securityGroup.key().getUuid().getValue();
InstanceIdentifier<Acl> identifier = getAclInstanceIdentifier(securityGroup);
jobCoordinator.enqueueJob(securityGroupId, () -> {
Integer aclTag = neutronSecurityGroupUtils.allocateAclTag(securityGroupId);
Acl acl = toAclBuilder(securityGroup, aclTag).build();
return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> tx.mergeParentStructurePut(identifier, acl)));
});
}
use of org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION in project netvirt by opendaylight.
the class RouterDpnChangeListener method remove.
@Override
public void remove(InstanceIdentifier<DpnVpninterfacesList> identifier, DpnVpninterfacesList dpnInfo) {
LOG.trace("remove : key: {}, value: {}", dpnInfo.key(), dpnInfo);
final String routerUuid = identifier.firstKeyOf(RouterDpnList.class).getRouterId();
Uint32 routerId = NatUtil.getVpnId(dataBroker, routerUuid);
if (routerId == NatConstants.INVALID_ID) {
LOG.error("REMOVE: Invalid routId returned for routerName {}", routerUuid);
return;
}
Uint64 dpnId = dpnInfo.getDpnId();
// check router is associated to external network
InstanceIdentifier<Routers> id = NatUtil.buildRouterIdentifier(routerUuid);
Optional<Routers> routerData = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
if (routerData.isPresent()) {
Routers router = routerData.get();
Uuid networkId = router.getNetworkId();
if (networkId != null) {
if (natMode == NatMode.Conntrack) {
Uint64 naptSwitch = NatUtil.getPrimaryNaptfromRouterName(dataBroker, router.getRouterName());
if (naptSwitch == null || naptSwitch.equals(Uint64.ZERO)) {
LOG.warn("remove : NAPT switch is not selected.");
return;
}
// If it is for NAPT switch skip as the flows would be already programmed.
if (naptSwitch.equals(dpnId)) {
LOG.debug("Skipping the notification recived for NAPT switch {}", routerUuid);
return;
}
LoggingFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, confTx -> {
natServiceManager.notify(confTx, router, null, naptSwitch, dpnId, SnatServiceManager.Action.CNT_ROUTER_DISBL);
if (router.isEnableSnat()) {
natServiceManager.notify(confTx, router, null, naptSwitch, naptSwitch, SnatServiceManager.Action.SNAT_ROUTER_DISBL);
}
}), LOG, "Error notifying NAT service manager");
} else {
coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + routerUuid, () -> {
LOG.debug("remove : Router {} is associated with ext nw {}", routerUuid, networkId);
Uuid vpnName = NatUtil.getVpnForRouter(dataBroker, routerUuid);
return Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, confTx -> {
Uint32 vpnId;
if (vpnName == null) {
LOG.debug("remove : Internal vpn associated to router {}", routerUuid);
vpnId = routerId;
if (vpnId == NatConstants.INVALID_ID) {
LOG.error("remove : Invalid vpnId returned for routerName {}", routerUuid);
return;
}
LOG.debug("remove : Retrieved vpnId {} for router {}", vpnId, routerUuid);
// Remove default entry in FIB
LOG.debug("remove : Removing default route in FIB on dpn {} ...", dpnId);
snatDefaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, vpnId, confTx);
} else {
LOG.debug("remove : External vpn associated to router {}", routerUuid);
vpnId = NatUtil.getVpnId(dataBroker, vpnName.getValue());
if (vpnId == NatConstants.INVALID_ID) {
LOG.error("remove : Invalid vpnId returned for routerName {}", routerUuid);
return;
}
LOG.debug("remove : Retrieved vpnId {} for router {}", vpnId, routerUuid);
// Remove default entry in FIB
LOG.debug("remove : Removing default route in FIB on dpn {} for vpn {} ...", dpnId, vpnName);
snatDefaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, vpnId, routerId, confTx);
}
/* remove V6 internet default fallback rule in FIB_TABLE if router
* is having V6 subnet
*/
Uuid internetVpnId = NatUtil.getVpnIdfromNetworkId(dataBroker, networkId);
if (internetVpnId != null) {
nvpnManager.programV6InternetFallbackFlow(new Uuid(routerUuid), internetVpnId, NwConstants.DEL_FLOW);
}
if (router.isEnableSnat()) {
ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerUuid, networkId);
if (extNwProvType == null) {
return;
}
LOG.info("remove : SNAT enabled for router {}", routerUuid);
String externalVpnName = NatUtil.getAssociatedVPN(dataBroker, routerData.get().getNetworkId());
NatUtil.removeSNATFromDPN(dataBroker, mdsalManager, idManager, naptSwitchHA, dpnId, router, routerId, vpnId, externalVpnName, extNwProvType, confTx);
} else {
LOG.info("remove : SNAT is not enabled for router {} to handle removeDPN event {}", routerUuid, dpnId);
}
}));
}, NatConstants.NAT_DJC_MAX_RETRIES);
}
// end of controller based SNAT
}
}
}
Aggregations