use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.VpnInterfaces in project netvirt by opendaylight.
the class VpnFootprintService method createOrUpdateVpnToDpnListForInterfaceName.
private void createOrUpdateVpnToDpnListForInterfaceName(Uint32 vpnId, String primaryRd, Uint64 dpnId, String intfName, String vpnName) {
AtomicBoolean newDpnOnVpn = new AtomicBoolean(false);
/* Starts synchronized block. This ensures only one reader/writer get access to vpn-dpn-list
* The future.get ensures that the write to the datastore is complete before leaving the synchronized block.
*/
// FIXME: separate this out somehow?
final ReentrantLock lock = JvmGlobalLocks.getLockForString(vpnName);
lock.lock();
try {
ListenableFuture<?> future = txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, tx -> {
InstanceIdentifier<VpnToDpnList> id = VpnHelper.getVpnToDpnListIdentifier(primaryRd, dpnId);
VpnInterfaces vpnInterface = new VpnInterfacesBuilder().setInterfaceName(intfName).build();
Optional<VpnToDpnList> dpnInVpn = tx.read(id).get();
if (dpnInVpn.isPresent()) {
VpnToDpnList vpnToDpnList = dpnInVpn.get();
List<VpnInterfaces> vpnInterfaces = new ArrayList<>(vpnToDpnList.nonnullVpnInterfaces().values());
vpnInterfaces.add(vpnInterface);
VpnToDpnListBuilder vpnToDpnListBuilder = new VpnToDpnListBuilder(vpnToDpnList);
vpnToDpnListBuilder.setDpnState(VpnToDpnList.DpnState.Active).setVpnInterfaces(vpnInterfaces);
tx.mergeParentStructurePut(id, vpnToDpnListBuilder.build());
/*
* If earlier state was inactive, it is considered new DPN coming back to the
* same VPN
*/
if (vpnToDpnList.getDpnState() == VpnToDpnList.DpnState.Inactive) {
newDpnOnVpn.set(true);
}
LOG.debug("createOrUpdateVpnToDpnList: Updating vpn footprint for vpn {} vpnId {} interface {}" + " on dpn {}", vpnName, vpnId, intfName, dpnId);
} else {
List<VpnInterfaces> vpnInterfaces = new ArrayList<>();
vpnInterfaces.add(vpnInterface);
VpnToDpnListBuilder vpnToDpnListBuilder = new VpnToDpnListBuilder().setDpnId(dpnId);
vpnToDpnListBuilder.setDpnState(VpnToDpnList.DpnState.Active).setVpnInterfaces(vpnInterfaces);
tx.mergeParentStructurePut(id, vpnToDpnListBuilder.build());
newDpnOnVpn.set(true);
LOG.debug("createOrUpdateVpnToDpnList: Creating vpn footprint for vpn {} vpnId {} interface {}" + " on dpn {}", vpnName, vpnId, intfName, dpnId);
}
});
future.get();
} catch (InterruptedException | ExecutionException e) {
LOG.error("createOrUpdateVpnToDpnList: Error adding to dpnToVpnList for vpn {} vpnId {} interface {}" + " dpn {}", vpnName, vpnId, intfName, dpnId, e);
throw new RuntimeException(e.getMessage(), e);
} finally {
lock.unlock();
}
LOG.info("createOrUpdateVpnToDpnList: Created/Updated vpn footprint for vpn {} vpnId {} interfacName{}" + " on dpn {}", vpnName, vpnId, intfName, dpnId);
/*
* Informing the FIB only after writeTxn is submitted successfully.
*/
if (newDpnOnVpn.get()) {
if (vpnUtil.isVlan(intfName)) {
if (!vpnUtil.shouldPopulateFibForVlan(vpnName, null, dpnId)) {
return;
}
}
fibManager.populateFibOnNewDpn(dpnId, vpnId, primaryRd, new DpnEnterExitVpnWorker(dpnId, vpnName, primaryRd, true));
LOG.info("createOrUpdateVpnToDpnList: Sent populateFib event for new dpn {} in VPN {} for interface {}", dpnId, vpnName, intfName);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.VpnInterfaces in project netvirt by opendaylight.
the class SubnetOpDpnManager method removeInterfaceFromDpn.
public boolean removeInterfaceFromDpn(Uuid subnetId, Uint64 dpnId, String intfName) {
boolean dpnRemoved = false;
try {
InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
InstanceIdentifier<SubnetToDpn> dpnOpId = subOpIdentifier.child(SubnetToDpn.class, new SubnetToDpnKey(dpnId));
Optional<SubnetToDpn> optionalSubDpn = SingleTransactionDataBroker.syncReadOptional(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId);
if (!optionalSubDpn.isPresent()) {
LOG.debug("removeInterfaceFromDpn: Cannot delete, SubnetToDpn for intf {} subnet {} DPN {}" + " not available in datastore", intfName, subnetId.getValue(), dpnId);
return false;
}
SubnetToDpnBuilder subDpnBuilder = new SubnetToDpnBuilder(optionalSubDpn.get());
Map<VpnInterfacesKey, VpnInterfaces> vpnInterfaceMap = new HashMap<>();
vpnInterfaceMap = (subDpnBuilder.getVpnInterfaces() != null && !subDpnBuilder.getVpnInterfaces().isEmpty()) ? new HashMap<>(subDpnBuilder.getVpnInterfaces()) : vpnInterfaceMap;
VpnInterfaces vpnIntfs = new VpnInterfacesBuilder().withKey(new VpnInterfacesKey(intfName)).setInterfaceName(intfName).build();
vpnInterfaceMap.remove(vpnIntfs.key());
if (vpnInterfaceMap.isEmpty()) {
// Remove the DPN as well
removeDpnFromSubnet(subnetId, dpnId);
dpnRemoved = true;
} else {
subDpnBuilder.setVpnInterfaces(vpnInterfaceMap);
SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId, subDpnBuilder.build(), VpnUtil.SINGLE_TRANSACTION_BROKER_NO_RETRY);
}
LOG.info("removeInterfaceFromDpn: Removed interface {} from sunbet {} dpn {}", intfName, subnetId.getValue(), dpnId);
} catch (TransactionCommitFailedException ex) {
LOG.error("removeInterfaceFromDpn: Deletion of Interface {} for SubnetToDpn on subnet {}" + " with DPN {} failed", intfName, subnetId.getValue(), dpnId, ex);
} catch (InterruptedException | ExecutionException e) {
LOG.error("removeInterfaceFromDpn: Failed to read data store for interface {} subnet {} dpn {}", intfName, subnetId, dpnId);
}
return dpnRemoved;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.VpnInterfaces in project netvirt by opendaylight.
the class SubnetOpDpnManager method addDpnToSubnet.
@Nullable
private SubnetToDpn addDpnToSubnet(Uuid subnetId, Uint64 dpnId) {
try {
InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
InstanceIdentifier<SubnetToDpn> dpnOpId = subOpIdentifier.child(SubnetToDpn.class, new SubnetToDpnKey(dpnId));
Optional<SubnetToDpn> optionalSubDpn = SingleTransactionDataBroker.syncReadOptional(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId);
if (optionalSubDpn.isPresent()) {
LOG.error("addDpnToSubnet: Cannot create, SubnetToDpn for subnet {} as DPN {}" + " already seen in datastore", subnetId.getValue(), dpnId);
return null;
}
SubnetToDpnBuilder subDpnBuilder = new SubnetToDpnBuilder().withKey(new SubnetToDpnKey(dpnId));
Map<VpnInterfacesKey, VpnInterfaces> vpnInterfaceMap = new HashMap<>();
subDpnBuilder.setVpnInterfaces(vpnInterfaceMap);
SubnetToDpn subDpn = subDpnBuilder.build();
SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId, subDpn, VpnUtil.SINGLE_TRANSACTION_BROKER_NO_RETRY);
LOG.info("addDpnToSubnet: Created SubnetToDpn entry for subnet {} with DPNId {} ", subnetId.getValue(), dpnId);
return subDpn;
} catch (TransactionCommitFailedException ex) {
LOG.error("addDpnToSubnet: Creation of SubnetToDpn for subnet {} with DpnId {} failed", subnetId.getValue(), dpnId, ex);
} catch (InterruptedException | ExecutionException e) {
LOG.error("addDpnToSubnet: Failed to read data store for subnet {} dpn {}", subnetId.getValue(), dpnId);
}
return null;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.VpnInterfaces in project netvirt by opendaylight.
the class TunnelEndPointChangeListener method add.
@Override
public void add(InstanceIdentifier<TunnelEndPoints> key, TunnelEndPoints tep) {
Uint64 dpnId = key.firstIdentifierOf(DPNTEPsInfo.class).firstKeyOf(DPNTEPsInfo.class).getDPNID();
if (Uint64.ZERO.equals(dpnId)) {
LOG.warn("add: Invalid DPN id for TEP {}", tep.getInterfaceName());
return;
}
List<VpnInstance> vpnInstances = VpnHelper.getAllVpnInstances(broker);
if (vpnInstances == null || vpnInstances.isEmpty()) {
LOG.warn("add: dpnId: {}: tep: {}: No VPN instances defined", dpnId, tep.getInterfaceName());
return;
}
for (VpnInstance vpnInstance : vpnInstances) {
final String vpnName = vpnInstance.getVpnInstanceName();
final Uint32 vpnId = vpnUtil.getVpnId(vpnName);
LOG.info("add: Handling TEP {} add for VPN instance {}", tep.getInterfaceName(), vpnName);
final String primaryRd = vpnUtil.getPrimaryRd(vpnName);
if (!vpnUtil.isVpnPendingDelete(primaryRd)) {
List<VpnInterfaces> vpnInterfaces = vpnUtil.getDpnVpnInterfaces(vpnInstance, dpnId);
if (vpnInterfaces != null) {
for (VpnInterfaces vpnInterface : vpnInterfaces) {
String vpnInterfaceName = vpnInterface.getInterfaceName();
jobCoordinator.enqueueJob("VPNINTERFACE-" + vpnInterfaceName, () -> {
final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface interfaceState = InterfaceUtils.getInterfaceStateFromOperDS(broker, vpnInterfaceName);
if (interfaceState == null) {
LOG.debug("add: Cannot retrieve interfaceState for vpnInterfaceName {}, " + "cannot generate lPortTag and process adjacencies", vpnInterfaceName);
return Collections.emptyList();
}
final int lPortTag = interfaceState.getIfIndex();
List<ListenableFuture<?>> futures = new ArrayList<>();
Set<String> prefixesForRefreshFib = new HashSet<>();
ListenableFuture<?> writeConfigFuture = txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, writeConfigTxn -> futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, writeOperTxn -> futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, writeInvTxn -> vpnInterfaceManager.processVpnInterfaceAdjacencies(dpnId, lPortTag, vpnName, primaryRd, vpnInterfaceName, vpnId, writeConfigTxn, writeOperTxn, writeInvTxn, interfaceState, prefixesForRefreshFib))))));
Futures.addCallback(writeConfigFuture, new FutureCallback<Object>() {
@Override
public void onSuccess(Object voidObj) {
prefixesForRefreshFib.forEach(prefix -> {
fibManager.refreshVrfEntry(primaryRd, prefix);
});
}
@Override
public void onFailure(Throwable throwable) {
LOG.debug("addVpnInterface: write Tx config execution failed", throwable);
}
}, MoreExecutors.directExecutor());
futures.add(writeConfigFuture);
LOG.trace("add: Handled TEP {} add for VPN instance {} VPN interface {}", tep.getInterfaceName(), vpnName, vpnInterfaceName);
return futures;
});
}
}
} else {
LOG.error("add: Ignoring addition of tunnel interface {} dpn {} for vpnInstance {} with primaryRd {}," + " as the VPN is already marked for deletion", tep.getInterfaceName(), dpnId, vpnName, primaryRd);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.VpnInterfaces in project netvirt by opendaylight.
the class AbstractSnatService method removeMipAdjacencies.
private void removeMipAdjacencies(Routers routers) {
LOG.info("removeMipAdjacencies for router {}", routers.getRouterName());
String externalSubNetId = null;
for (ExternalIps externalIp : routers.nonnullExternalIps().values()) {
if (!NWUtil.isIpv4Address(externalIp.getIpAddress())) {
// In this class we handle only IPv4 use-cases.
continue;
}
externalSubNetId = externalIp.getSubnetId().getValue();
break;
}
if (externalSubNetId == null) {
LOG.info("removeMipAdjacencies no external Ipv4 address present on router {}", routers.getRouterName());
return;
}
InstanceIdentifier<VpnInterfaces> vpnInterfacesId = InstanceIdentifier.builder(VpnInterfaces.class).build();
try {
VpnInterfaces vpnInterfaces = SingleTransactionDataBroker.syncRead(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnInterfacesId);
List<VpnInterface> updatedVpnInterface = new ArrayList<>();
for (VpnInterface vpnInterface : vpnInterfaces.nonnullVpnInterface().values()) {
List<Adjacency> updatedAdjacencies = new ArrayList<>();
Adjacencies adjacencies = vpnInterface.augmentation(Adjacencies.class);
if (null != adjacencies) {
for (Adjacency adjacency : adjacencies.nonnullAdjacency().values()) {
if (!adjacency.getSubnetId().getValue().equals(externalSubNetId)) {
updatedAdjacencies.add(adjacency);
}
}
}
AdjacenciesBuilder adjacenciesBuilder = new AdjacenciesBuilder();
adjacenciesBuilder.setAdjacency(updatedAdjacencies);
VpnInterfaceBuilder vpnInterfaceBuilder = new VpnInterfaceBuilder(vpnInterface);
vpnInterfaceBuilder.addAugmentation(adjacenciesBuilder.build());
updatedVpnInterface.add(vpnInterfaceBuilder.build());
}
VpnInterfacesBuilder vpnInterfacesBuilder = new VpnInterfacesBuilder();
vpnInterfacesBuilder.setVpnInterface(updatedVpnInterface);
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnInterfacesId, vpnInterfacesBuilder.build());
} catch (ExpectedDataObjectNotFoundException e) {
LOG.warn("Failed to read removeMipAdjacencies with error {}", e.getMessage());
} catch (TransactionCommitFailedException e) {
LOG.warn("Failed to remove removeMipAdjacencies with error {}", e.getMessage());
}
}
Aggregations