use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.vpn.instance.vpntargets.VpnTargetKey in project netvirt by opendaylight.
the class VpnServiceTest method test.
@Test
public void test() {
List<VpnTarget> vpnTargetList = new ArrayList<>();
VpnTarget vpneRTarget = new VpnTargetBuilder().withKey(new VpnTargetKey("100:1")).setVrfRTValue("100:1").setVrfRTType(VpnTarget.VrfRTType.ExportExtcommunity).build();
VpnTarget vpniRTarget = new VpnTargetBuilder().withKey(new VpnTargetKey("100:2")).setVrfRTValue("100:2").setVrfRTType(VpnTarget.VrfRTType.ImportExtcommunity).build();
vpnTargetList.add(vpneRTarget);
vpnTargetList.add(vpniRTarget);
VpnTargets vpnTargets = new VpnTargetsBuilder().setVpnTarget(vpnTargetList).build();
VpnInstanceBuilder builder = new VpnInstanceBuilder().withKey(new VpnInstanceKey("Vpn1")).setRouteDistinguisher(Arrays.asList("100:1", "100:2:")).setVpnTargets(vpnTargets);
VpnInstance instance = builder.build();
// TODO: Need to enhance the test case to handle ds read/write ops
// vpnManager.onDataChanged(event);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.vpn.instance.vpntargets.VpnTargetKey in project netvirt by opendaylight.
the class VpnOpStatusListener method update.
@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public void update(InstanceIdentifier<VpnInstanceOpDataEntry> identifier, VpnInstanceOpDataEntry original, VpnInstanceOpDataEntry update) {
LOG.info("update: Processing update for vpn {} with rd {}", update.getVpnInstanceName(), update.getVrfId());
if (update.getVpnState() == VpnInstanceOpDataEntry.VpnState.PendingDelete && vpnFootprintService.isVpnFootPrintCleared(update)) {
// Cleanup VPN data
final String vpnName = update.getVpnInstanceName();
final List<String> rds = update.getRd();
String primaryRd = update.getVrfId();
final Uint32 vpnId = vpnUtil.getVpnId(vpnName);
jobCoordinator.enqueueJob("VPN-" + update.getVpnInstanceName(), () -> {
// Two transactions are used, one for operational, one for config; we only submit the config
// transaction if the operational transaction succeeds
ListenableFuture<?> operationalFuture = txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.OPERATIONAL, operTx -> {
// Clean up VPNExtraRoutes Operational DS
if (rds != null && VpnUtil.isBgpVpn(vpnName, primaryRd)) {
if (update.getType() == VpnInstanceOpDataEntry.Type.L2) {
rds.parallelStream().forEach(rd -> bgpManager.deleteVrf(rd, false, AddressFamily.L2VPN));
}
if (update.getIpAddressFamilyConfigured() == VpnInstanceOpDataEntry.IpAddressFamilyConfigured.Ipv4) {
rds.parallelStream().forEach(rd -> bgpManager.deleteVrf(rd, false, AddressFamily.IPV4));
}
if (update.getIpAddressFamilyConfigured() == VpnInstanceOpDataEntry.IpAddressFamilyConfigured.Ipv6) {
rds.parallelStream().forEach(rd -> bgpManager.deleteVrf(rd, false, AddressFamily.IPV6));
}
if (update.getIpAddressFamilyConfigured() == VpnInstanceOpDataEntry.IpAddressFamilyConfigured.Ipv4AndIpv6) {
rds.parallelStream().forEach(rd -> bgpManager.deleteVrf(rd, false, AddressFamily.IPV4));
rds.parallelStream().forEach(rd -> bgpManager.deleteVrf(rd, false, AddressFamily.IPV6));
}
}
InstanceIdentifier<Vpn> vpnToExtraroute = VpnExtraRouteHelper.getVpnToExtrarouteVpnIdentifier(vpnName);
Optional<Vpn> optVpnToExtraroute = Optional.empty();
try {
optVpnToExtraroute = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, vpnToExtraroute);
} catch (InterruptedException | ExecutionException e) {
LOG.error("update: Failed to read VpnToExtraRoute for vpn {}", vpnName);
}
if (optVpnToExtraroute.isPresent()) {
VpnUtil.removeVpnExtraRouteForVpn(vpnName, operTx);
}
if (VpnUtil.isL3VpnOverVxLan(update.getL3vni())) {
vpnUtil.removeExternalTunnelDemuxFlows(vpnName);
}
// Clean up PrefixToInterface Operational DS
Optional<VpnIds> optPrefixToIntf = Optional.empty();
try {
optPrefixToIntf = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, VpnUtil.getPrefixToInterfaceIdentifier(vpnId));
} catch (InterruptedException | ExecutionException e) {
LOG.error("update: Failed to read PrefixToInterface for vpn {}", vpnName);
}
if (optPrefixToIntf.isPresent()) {
VpnUtil.removePrefixToInterfaceForVpnId(vpnId, operTx);
}
// Clean up L3NextHop Operational DS
InstanceIdentifier<VpnNexthops> vpnNextHops = InstanceIdentifier.builder(L3nexthop.class).child(VpnNexthops.class, new VpnNexthopsKey(vpnId)).build();
Optional<VpnNexthops> optL3nexthopForVpnId = Optional.empty();
try {
optL3nexthopForVpnId = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, vpnNextHops);
} catch (InterruptedException | ExecutionException e) {
LOG.error("update: Failed to read VpnNextHops for vpn {}", vpnName);
}
if (optL3nexthopForVpnId.isPresent()) {
VpnUtil.removeL3nexthopForVpnId(vpnId, operTx);
}
// Clean up VPNInstanceOpDataEntry
VpnUtil.removeVpnOpInstance(primaryRd, operTx);
});
Futures.addCallback(operationalFuture, new FutureCallback<Object>() {
@Override
public void onSuccess(Object result) {
Futures.addCallback(txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.CONFIGURATION, confTx -> {
// Clean up VpnInstanceToVpnId from Config DS
VpnUtil.removeVpnIdToVpnInstance(vpnId, confTx);
VpnUtil.removeVpnInstanceToVpnId(vpnName, confTx);
LOG.trace("Removed vpnIdentifier for rd{} vpnname {}", primaryRd, vpnName);
// Clean up FIB Entries Config DS
// FIXME: separate out to somehow?
final ReentrantLock lock = JvmGlobalLocks.getLockForString(vpnName);
lock.lock();
try {
fibManager.removeVrfTable(primaryRd, confTx);
} finally {
lock.unlock();
}
}), new VpnOpStatusListener.PostDeleteVpnInstanceWorker(vpnName), MoreExecutors.directExecutor());
// Note: Release the of VpnId will happen in PostDeleteVpnInstancWorker only if
// operationalTxn/Config succeeds.
}
@Override
public void onFailure(Throwable throwable) {
LOG.error("Error deleting VPN {}", vpnName, throwable);
}
}, MoreExecutors.directExecutor());
LOG.info("Removed vpn data for vpnname {}", vpnName);
return Collections.singletonList(operationalFuture);
}, SystemPropertyReader.getDataStoreJobCoordinatorMaxRetries());
} else if (update.getVpnState() == VpnInstanceOpDataEntry.VpnState.Created) {
final String vpnName = update.getVpnInstanceName();
String primaryRd = update.getVrfId();
if (!VpnUtil.isBgpVpn(vpnName, primaryRd)) {
return;
}
if (original == null) {
LOG.error("VpnOpStatusListener.update: vpn {} with RD {}. add() handler already called", vpnName, primaryRd);
return;
}
if (update.getVpnTargets() == null) {
LOG.error("VpnOpStatusListener.update: vpn {} with RD {} vpnTargets not ready", vpnName, primaryRd);
return;
}
Map<VpnTargetKey, VpnTarget> vpnTargetMap = update.getVpnTargets().getVpnTarget();
List<String> ertList = new ArrayList<>();
List<String> irtList = new ArrayList<>();
if (vpnTargetMap != null) {
for (VpnTarget vpnTarget : vpnTargetMap.values()) {
if (vpnTarget.getVrfRTType() == VpnTarget.VrfRTType.ExportExtcommunity) {
ertList.add(vpnTarget.getVrfRTValue());
}
if (vpnTarget.getVrfRTType() == VpnTarget.VrfRTType.ImportExtcommunity) {
irtList.add(vpnTarget.getVrfRTValue());
}
if (vpnTarget.getVrfRTType() == VpnTarget.VrfRTType.Both) {
ertList.add(vpnTarget.getVrfRTValue());
irtList.add(vpnTarget.getVrfRTValue());
}
}
} else {
LOG.error("VpnOpStatusListener.update: vpn target list is empty, cannot add BGP" + " VPN {} RD {}", vpnName, primaryRd);
return;
}
jobCoordinator.enqueueJob("VPN-" + update.getVpnInstanceName(), () -> {
// RD update case get only updated RD list
List<String> rds = update.getRd() != null ? new ArrayList<>(update.getRd()) : new ArrayList<>();
if (original.getRd() != null && original.getRd().size() != rds.size()) {
rds.removeAll(original.getRd());
}
rds.parallelStream().forEach(rd -> {
try {
List<String> importRTList = rd.equals(primaryRd) ? irtList : emptyList();
LOG.info("VpnOpStatusListener.update: updating BGPVPN for vpn {} with RD {}" + " Type is {}, IPtype is {}, iRT {}", vpnName, primaryRd, update.getType(), update.getIpAddressFamilyConfigured(), importRTList);
int ipValue = VpnUtil.getIpFamilyValueToRemove(original, update);
switch(ipValue) {
case 4:
bgpManager.deleteVrf(rd, false, AddressFamily.IPV4);
break;
case 6:
bgpManager.deleteVrf(rd, false, AddressFamily.IPV6);
break;
case 10:
bgpManager.deleteVrf(rd, false, AddressFamily.IPV4);
bgpManager.deleteVrf(rd, false, AddressFamily.IPV6);
break;
default:
break;
}
/* Update vrf entry with newly added RD list. VPN does not support for
* deleting existing RDs
*/
if (original.getRd().size() != update.getRd().size()) {
ipValue = VpnUtil.getIpFamilyValueToAdd(original, update);
switch(ipValue) {
case 4:
bgpManager.addVrf(rd, importRTList, ertList, AddressFamily.IPV4);
break;
case 6:
bgpManager.addVrf(rd, importRTList, ertList, AddressFamily.IPV6);
break;
case 10:
bgpManager.addVrf(rd, importRTList, ertList, AddressFamily.IPV4);
bgpManager.addVrf(rd, importRTList, ertList, AddressFamily.IPV6);
break;
default:
break;
}
}
} catch (RuntimeException e) {
LOG.error("VpnOpStatusListener.update: Exception when updating VRF to BGP for vpn {} rd {}", vpnName, rd, e);
}
});
return emptyList();
});
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.vpn.instance.vpntargets.VpnTargetKey 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.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.vpn.instance.vpntargets.VpnTargetKey in project netvirt by opendaylight.
the class NeutronvpnManager method updateVpnInstanceNode.
private void updateVpnInstanceNode(Uuid vpnId, List<String> rd, List<String> irt, List<String> ert, boolean isL2Vpn, long l3vni, IpVersionChoice ipVersion) {
String vpnName = vpnId.getValue();
VpnInstanceBuilder builder = null;
List<VpnTarget> vpnTargetList = new ArrayList<>();
InstanceIdentifier<VpnInstance> vpnIdentifier = InstanceIdentifier.builder(VpnInstances.class).child(VpnInstance.class, new VpnInstanceKey(vpnName)).build();
Optional<VpnInstance> optionalVpn;
try {
optionalVpn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier);
} catch (ExecutionException | InterruptedException e) {
LOG.error("Update VPN Instance node failed for node: {} {} {} {}", vpnName, rd, irt, ert);
return;
}
LOG.debug("Creating/Updating a new vpn-instance node: {} ", vpnName);
if (optionalVpn.isPresent()) {
builder = new VpnInstanceBuilder(optionalVpn.get());
LOG.debug("updating existing vpninstance node");
} else {
builder = new VpnInstanceBuilder().withKey(new VpnInstanceKey(vpnName)).setVpnInstanceName(vpnName).setL2vpn(isL2Vpn).setL3vni(l3vni).setBgpvpnType(VpnInstance.BgpvpnType.InternalVPN);
}
if (irt != null && !irt.isEmpty()) {
if (ert != null && !ert.isEmpty()) {
List<String> commonRT = new ArrayList<>(irt);
commonRT.retainAll(ert);
for (String common : commonRT) {
irt.remove(common);
ert.remove(common);
VpnTarget vpnTarget = new VpnTargetBuilder().withKey(new VpnTargetKey(common)).setVrfRTValue(common).setVrfRTType(VpnTarget.VrfRTType.Both).build();
vpnTargetList.add(vpnTarget);
}
}
for (String importRT : irt) {
VpnTarget vpnTarget = new VpnTargetBuilder().withKey(new VpnTargetKey(importRT)).setVrfRTValue(importRT).setVrfRTType(VpnTarget.VrfRTType.ImportExtcommunity).build();
vpnTargetList.add(vpnTarget);
}
}
if (ert != null && !ert.isEmpty()) {
for (String exportRT : ert) {
VpnTarget vpnTarget = new VpnTargetBuilder().withKey(new VpnTargetKey(exportRT)).setVrfRTValue(exportRT).setVrfRTType(VpnTarget.VrfRTType.ExportExtcommunity).build();
vpnTargetList.add(vpnTarget);
}
}
VpnTargets vpnTargets = new VpnTargetsBuilder().setVpnTarget(vpnTargetList).build();
if (rd != null && !rd.isEmpty()) {
builder.setRouteDistinguisher(rd).setVpnTargets(vpnTargets).setBgpvpnType(VpnInstance.BgpvpnType.BGPVPN);
}
builder.setIpAddressFamilyConfigured(VpnInstance.IpAddressFamilyConfigured.forValue(ipVersion.choice));
VpnInstance newVpn = builder.build();
try (AcquireResult lock = tryVpnLock(vpnId)) {
if (!lock.wasAcquired()) {
// FIXME: why do we even bother with locking if we do not honor it?!
logTryLockFailure(vpnId);
}
LOG.debug("Creating/Updating vpn-instance for {} ", vpnName);
try {
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier, newVpn);
} catch (TransactionCommitFailedException e) {
LOG.error("Update VPN Instance node failed for node: {} {} {} {}", vpnName, rd, irt, ert);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.vpn.instance.vpntargets.VpnTargetKey in project netvirt by opendaylight.
the class NeutronvpnManager method getL3VPN.
/**
* It handles the invocations to the neutronvpn:getL3VPN RPC method.
*/
@Override
public ListenableFuture<RpcResult<GetL3VPNOutput>> getL3VPN(GetL3VPNInput input) {
GetL3VPNOutputBuilder opBuilder = new GetL3VPNOutputBuilder();
SettableFuture<RpcResult<GetL3VPNOutput>> result = SettableFuture.create();
Uuid inputVpnId = input.getId();
List<VpnInstance> vpns = new ArrayList<>();
List<L3vpnInstances> l3vpnList = new ArrayList<>();
try {
if (inputVpnId == null) {
// get all vpns
InstanceIdentifier<VpnInstances> vpnsIdentifier = InstanceIdentifier.builder(VpnInstances.class).build();
Optional<VpnInstances> optionalVpns = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnsIdentifier);
if (optionalVpns.isPresent() && !optionalVpns.get().getVpnInstance().isEmpty()) {
for (VpnInstance vpn : optionalVpns.get().nonnullVpnInstance().values()) {
// from getL3VPN output
if (vpn.getRouteDistinguisher() != null) {
vpns.add(vpn);
}
}
} else {
// No VPN present
opBuilder.setL3vpnInstances(l3vpnList);
result.set(RpcResultBuilder.<GetL3VPNOutput>success().withResult(opBuilder.build()).build());
return result;
}
} else {
String name = inputVpnId.getValue();
InstanceIdentifier<VpnInstance> vpnIdentifier = InstanceIdentifier.builder(VpnInstances.class).child(VpnInstance.class, new VpnInstanceKey(name)).build();
// read VpnInstance Info
Optional<VpnInstance> optionalVpn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier);
// getL3VPN output
if (optionalVpn.isPresent() && optionalVpn.get().getRouteDistinguisher() != null) {
vpns.add(optionalVpn.get());
} else {
result.set(RpcResultBuilder.<GetL3VPNOutput>failed().withWarning(ErrorType.PROTOCOL, "invalid-value", formatAndLog(LOG::error, "GetL3VPN failed because VPN {} is not present", name)).build());
}
}
for (VpnInstance vpnInstance : vpns) {
Uuid vpnId = new Uuid(vpnInstance.getVpnInstanceName());
// create VpnMaps id
L3vpnInstancesBuilder l3vpn = new L3vpnInstancesBuilder();
List<String> rd = Collections.emptyList();
if (vpnInstance.getRouteDistinguisher() != null) {
rd = vpnInstance.getRouteDistinguisher();
}
List<String> ertList = new ArrayList<>();
List<String> irtList = new ArrayList<>();
if (vpnInstance.getVpnTargets() != null) {
Map<VpnTargetKey, VpnTarget> keyVpnTargetMap = Collections.emptyMap();
if (!vpnInstance.getVpnTargets().getVpnTarget().isEmpty()) {
keyVpnTargetMap = vpnInstance.getVpnTargets().getVpnTarget();
}
if (!keyVpnTargetMap.isEmpty()) {
for (VpnTarget vpnTarget : keyVpnTargetMap.values()) {
if (vpnTarget.getVrfRTType() == VpnTarget.VrfRTType.ExportExtcommunity) {
ertList.add(vpnTarget.getVrfRTValue());
}
if (vpnTarget.getVrfRTType() == VpnTarget.VrfRTType.ImportExtcommunity) {
irtList.add(vpnTarget.getVrfRTValue());
}
if (vpnTarget.getVrfRTType() == VpnTarget.VrfRTType.Both) {
ertList.add(vpnTarget.getVrfRTValue());
irtList.add(vpnTarget.getVrfRTValue());
}
}
}
}
l3vpn.setId(vpnId).setRouteDistinguisher(rd).setImportRT(irtList).setExportRT(ertList);
if (vpnInstance.getL3vni() != null) {
l3vpn.setL3vni(vpnInstance.getL3vni());
}
InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class, new VpnMapKey(vpnId)).build();
Optional<VpnMap> optionalVpnMap = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
if (optionalVpnMap.isPresent()) {
VpnMap vpnMap = optionalVpnMap.get();
List<Uuid> rtrIds = new ArrayList<>();
if (vpnMap.getRouterIds() != null && !vpnMap.getRouterIds().isEmpty()) {
for (RouterIds rtrId : vpnMap.getRouterIds().values()) {
rtrIds.add(rtrId.getRouterId());
}
}
l3vpn.setRouterIds(NeutronvpnUtils.getVpnInstanceRouterIdsList(rtrIds)).setNetworkIds(vpnMap.getNetworkIds()).setTenantId(vpnMap.getTenantId()).setName(vpnMap.getName());
}
l3vpnList.add(l3vpn.build());
}
opBuilder.setL3vpnInstances(l3vpnList);
result.set(RpcResultBuilder.<GetL3VPNOutput>success().withResult(opBuilder.build()).build());
} catch (ExecutionException | InterruptedException ex) {
result.set(RpcResultBuilder.<GetL3VPNOutput>failed().withError(ErrorType.APPLICATION, formatAndLog(LOG::error, "GetVPN failed due to {}", ex.getMessage())).build());
}
return result;
}
Aggregations