use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance in project netvirt by opendaylight.
the class VrfEntryListener method deleteLabelRouteInfo.
private boolean deleteLabelRouteInfo(LabelRouteInfo lri, String vpnInstanceName, WriteTransaction tx) {
if (lri == null) {
return true;
}
LOG.debug("deleting LRI : for label {} vpninstancename {}", lri.getLabel(), vpnInstanceName);
InstanceIdentifier<LabelRouteInfo> lriId = InstanceIdentifier.builder(LabelRouteMap.class).child(LabelRouteInfo.class, new LabelRouteInfoKey(lri.getLabel())).build();
List<String> vpnInstancesList = lri.getVpnInstanceList() != null ? lri.getVpnInstanceList() : new ArrayList<>();
if (vpnInstancesList.contains(vpnInstanceName)) {
LOG.debug("vpninstance {} name is present", vpnInstanceName);
vpnInstancesList.remove(vpnInstanceName);
}
if (vpnInstancesList.isEmpty()) {
LOG.debug("deleting LRI instance object for label {}", lri.getLabel());
if (tx != null) {
tx.delete(LogicalDatastoreType.OPERATIONAL, lriId);
} else {
MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.OPERATIONAL, lriId);
}
return true;
} else {
LOG.debug("updating LRI instance object for label {}", lri.getLabel());
LabelRouteInfoBuilder builder = new LabelRouteInfoBuilder(lri).setVpnInstanceList(vpnInstancesList);
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, lriId, builder.build());
}
return false;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance 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.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance in project netvirt by opendaylight.
the class NeutronvpnManager method updateVpnInstanceNode.
private void updateVpnInstanceNode(Uuid vpnId, List<String> rd, List<String> irt, List<String> ert, VpnInstance.Type type, long l3vni, IpVersionChoice ipVersion) {
String vpnName = vpnId.getValue();
VpnInstanceBuilder builder = null;
List<VpnTarget> vpnTargetList = new ArrayList<>();
boolean isLockAcquired = false;
InstanceIdentifier<VpnInstance> vpnIdentifier = InstanceIdentifier.builder(VpnInstances.class).child(VpnInstance.class, new VpnInstanceKey(vpnName)).build();
try {
Optional<VpnInstance> optionalVpn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier);
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().setKey(new VpnInstanceKey(vpnName)).setVpnInstanceName(vpnName).setType(type).setL3vni(l3vni);
}
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().setKey(new VpnTargetKey(common)).setVrfRTValue(common).setVrfRTType(VpnTarget.VrfRTType.Both).build();
vpnTargetList.add(vpnTarget);
}
}
for (String importRT : irt) {
VpnTarget vpnTarget = new VpnTargetBuilder().setKey(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().setKey(new VpnTargetKey(exportRT)).setVrfRTValue(exportRT).setVrfRTType(VpnTarget.VrfRTType.ExportExtcommunity).build();
vpnTargetList.add(vpnTarget);
}
}
VpnTargets vpnTargets = new VpnTargetsBuilder().setVpnTarget(vpnTargetList).build();
Ipv4FamilyBuilder ipv4vpnBuilder = new Ipv4FamilyBuilder().setVpnTargets(vpnTargets);
Ipv6FamilyBuilder ipv6vpnBuilder = new Ipv6FamilyBuilder().setVpnTargets(vpnTargets);
if (rd != null && !rd.isEmpty()) {
ipv4vpnBuilder.setRouteDistinguisher(rd);
ipv6vpnBuilder.setRouteDistinguisher(rd);
}
if (ipVersion != null && ipVersion.isIpVersionChosen(IpVersionChoice.IPV4)) {
builder.setIpv4Family(ipv4vpnBuilder.build());
}
if (ipVersion != null && ipVersion.isIpVersionChosen(IpVersionChoice.IPV6)) {
builder.setIpv6Family(ipv6vpnBuilder.build());
}
if (ipVersion != null && ipVersion.isIpVersionChosen(IpVersionChoice.UNDEFINED)) {
builder.setIpv4Family(ipv4vpnBuilder.build());
}
VpnInstance newVpn = builder.build();
isLockAcquired = vpnLock.tryLock(vpnId, LOCK_WAIT_TIME, TimeUnit.SECONDS);
LOG.debug("Creating/Updating vpn-instance for {} ", vpnName);
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier, newVpn);
} catch (ReadFailedException | TransactionCommitFailedException e) {
LOG.error("Update VPN Instance node failed for node: {} {} {} {}", vpnName, rd, irt, ert);
} finally {
if (isLockAcquired) {
vpnLock.unlock(vpnId);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance in project netvirt by opendaylight.
the class NeutronvpnManager method writeVpnInterfaceToDs.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void writeVpnInterfaceToDs(@Nonnull Collection<Uuid> vpnIdList, String infName, Adjacencies adjacencies, Boolean isRouterInterface, WriteTransaction wrtConfigTxn) {
if (vpnIdList.isEmpty() || infName == null) {
LOG.error("vpn id or interface is null");
return;
}
List<VpnInstanceNames> vpnIdListStruct = new ArrayList<>();
for (Uuid vpnId : vpnIdList) {
VpnInstanceNames vpnInstance = VpnHelper.getVpnInterfaceVpnInstanceNames(vpnId.getValue(), AssociatedSubnetType.V4AndV6Subnets);
vpnIdListStruct.add(vpnInstance);
}
Boolean wrtConfigTxnPresent = true;
if (wrtConfigTxn == null) {
wrtConfigTxnPresent = false;
wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
}
InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
VpnInterfaceBuilder vpnb = new VpnInterfaceBuilder().setKey(new VpnInterfaceKey(infName)).setName(infName).setVpnInstanceNames(vpnIdListStruct).setRouterInterface(isRouterInterface);
if (adjacencies != null) {
vpnb.addAugmentation(Adjacencies.class, adjacencies);
}
VpnInterface vpnIf = vpnb.build();
try {
LOG.info("Creating vpn interface {}", vpnIf);
wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIf);
} catch (Exception ex) {
LOG.error("Creation of vpninterface {} failed", infName, ex);
}
if (!wrtConfigTxnPresent) {
wrtConfigTxn.submit();
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance in project netvirt by opendaylight.
the class NeutronvpnManager method updateVpnInterfaceWithAdjacencies.
private void updateVpnInterfaceWithAdjacencies(Uuid vpnId, String infName, Adjacencies adjacencies, WriteTransaction wrtConfigTxn) {
if (vpnId == null || infName == null) {
LOG.error("vpn id or interface is null");
return;
}
if (wrtConfigTxn == null) {
wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
}
InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
boolean isLockAcquired = false;
try {
isLockAcquired = interfaceLock.tryLock(infName, LOCK_WAIT_TIME, TimeUnit.SECONDS);
Optional<VpnInterface> optionalVpnInterface = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
if (optionalVpnInterface.isPresent()) {
VpnInterfaceBuilder vpnIfBuilder = new VpnInterfaceBuilder(optionalVpnInterface.get());
LOG.debug("Updating vpn interface {} with new adjacencies", infName);
if (adjacencies == null) {
if (isLockAcquired) {
interfaceLock.unlock(infName);
}
return;
}
vpnIfBuilder.addAugmentation(Adjacencies.class, adjacencies);
if (optionalVpnInterface.get().getVpnInstanceNames() != null) {
List<VpnInstanceNames> listVpnInstances = new ArrayList<>(optionalVpnInterface.get().getVpnInstanceNames());
if (listVpnInstances.isEmpty() || !VpnHelper.doesVpnInterfaceBelongToVpnInstance(vpnId.getValue(), listVpnInstances)) {
VpnInstanceNames vpnInstance = VpnHelper.getVpnInterfaceVpnInstanceNames(vpnId.getValue(), AssociatedSubnetType.V4AndV6Subnets);
listVpnInstances.add(vpnInstance);
vpnIfBuilder.setVpnInstanceNames(listVpnInstances);
}
} else {
VpnInstanceNames vpnInstance = VpnHelper.getVpnInterfaceVpnInstanceNames(vpnId.getValue(), AssociatedSubnetType.V4AndV6Subnets);
List<VpnInstanceNames> listVpnInstances = new ArrayList<>();
listVpnInstances.add(vpnInstance);
vpnIfBuilder.setVpnInstanceNames(listVpnInstances);
}
LOG.info("Updating vpn interface {} with new adjacencies", infName);
wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIfBuilder.build());
}
} catch (IllegalStateException | ReadFailedException ex) {
LOG.error("Update of vpninterface {} failed", infName, ex);
} finally {
if (isLockAcquired) {
interfaceLock.unlock(infName);
}
}
}
Aggregations