use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.VpnInterfacesBuilder in project netvirt by opendaylight.
the class SubnetOpDpnManager method removeInterfaceFromDpn.
public boolean removeInterfaceFromDpn(Uuid subnetId, BigInteger 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 = VpnUtil.read(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());
List<VpnInterfaces> vpnIntfList = subDpnBuilder.getVpnInterfaces();
VpnInterfaces vpnIntfs = new VpnInterfacesBuilder().setKey(new VpnInterfacesKey(intfName)).setInterfaceName(intfName).build();
vpnIntfList.remove(vpnIntfs);
if (vpnIntfList.isEmpty()) {
// Remove the DPN as well
removeDpnFromSubnet(subnetId, dpnId);
dpnRemoved = true;
} else {
subDpnBuilder.setVpnInterfaces(vpnIntfList);
SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId, subDpnBuilder.build());
}
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);
return false;
}
return dpnRemoved;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.VpnInterfacesBuilder in project netvirt by opendaylight.
the class SubnetOpDpnManager method addInterfaceToDpn.
public SubnetToDpn addInterfaceToDpn(Uuid subnetId, BigInteger dpnId, String intfName) {
SubnetToDpn subDpn = null;
try {
// Create and add SubnetOpDataEntry object for this subnet to the SubnetOpData container
InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
// Please use a synchronize block here as we donot need a cluster-wide lock
InstanceIdentifier<SubnetToDpn> dpnOpId = subOpIdentifier.child(SubnetToDpn.class, new SubnetToDpnKey(dpnId));
Optional<SubnetToDpn> optionalSubDpn = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId);
if (!optionalSubDpn.isPresent()) {
// Create a new DPN Entry
subDpn = addDpnToSubnet(subnetId, dpnId);
} else {
subDpn = optionalSubDpn.get();
}
SubnetToDpnBuilder subDpnBuilder = new SubnetToDpnBuilder(subDpn);
List<VpnInterfaces> vpnIntfList = subDpnBuilder.getVpnInterfaces();
VpnInterfaces vpnIntfs = new VpnInterfacesBuilder().setKey(new VpnInterfacesKey(intfName)).setInterfaceName(intfName).build();
vpnIntfList.add(vpnIntfs);
subDpnBuilder.setVpnInterfaces(vpnIntfList);
subDpn = subDpnBuilder.build();
SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId, subDpn);
LOG.info("addInterfaceToDpn: Created SubnetToDpn entry for subnet {} with DPNId {} intfName {}", subnetId.getValue(), dpnId, intfName);
} catch (TransactionCommitFailedException ex) {
LOG.error("addInterfaceToDpn: Addition of Interface {} for SubnetToDpn on subnet {} with DPN {} failed", intfName, subnetId.getValue(), dpnId, ex);
return null;
}
return subDpn;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.VpnInterfacesBuilder 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.VpnInterfacesBuilder 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.VpnInterfacesBuilder 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