use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnListBuilder in project netvirt by opendaylight.
the class VPNServiceChainHandlerTest method stubGetVpnInstance.
private void stubGetVpnInstance(String rd, String ipAddress, String ifaceName) throws Exception {
IpAddresses ipAddr = new IpAddressesBuilder().setIpAddress(ipAddress).setKey(new IpAddressesKey(ipAddress)).build();
List<VpnInterfaces> ifacesList = Collections.singletonList(new VpnInterfacesBuilder().setInterfaceName(ifaceName).build());
VpnToDpnListBuilder vtdlb = new VpnToDpnListBuilder().setKey(new VpnToDpnListKey(DPN_ID)).setDpnId(DPN_ID).setIpAddresses(Collections.singletonList(ipAddr)).setVpnInterfaces(ifacesList);
VpnInstanceOpDataEntry vpnInstanceOpDataEntry = new VpnInstanceOpDataEntryBuilder().setKey(new VpnInstanceOpDataEntryKey(rd)).setVpnId(VPN_ID).setVpnToDpnList(Collections.singletonList(vtdlb.build())).setVrfId("1").build();
CheckedFuture chkdFuture = mock(CheckedFuture.class);
when(chkdFuture.checkedGet()).thenReturn(Optional.of(vpnInstanceOpDataEntry));
when(readTx.read(eq(LogicalDatastoreType.OPERATIONAL), eq(VpnServiceChainUtils.getVpnInstanceOpDataIdentifier(rd)))).thenReturn(chkdFuture);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnListBuilder in project netvirt by opendaylight.
the class VpnFootprintService method removeOrUpdateVpnToDpnListForIpAddress.
private void removeOrUpdateVpnToDpnListForIpAddress(long vpnId, String rd, BigInteger dpnId, ImmutablePair<IpAddresses.IpAddressSource, String> ipAddressSourceValuePair, String vpnName) {
Boolean lastDpnOnVpn = Boolean.FALSE;
synchronized (vpnName.intern()) {
InstanceIdentifier<VpnToDpnList> id = VpnUtil.getVpnToDpnListIdentifier(rd, dpnId);
VpnToDpnList dpnInVpn = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id).orNull();
if (dpnInVpn == null) {
LOG.error("removeOrUpdateVpnToDpnList: Could not find DpnToVpn map for VPN=[name={} rd={} id={}]" + " and dpnId={}", vpnName, rd, id, dpnId);
return;
}
List<IpAddresses> ipAddresses = dpnInVpn.getIpAddresses();
if (ipAddresses == null) {
LOG.info("Could not find ipAddresses for DpnInVpn map for VPN=[name={} rd={} id={}] and dpnId={}", vpnName, rd, id, dpnId);
return;
}
IpAddresses currIpAddress = new IpAddressesBuilder().setKey(new IpAddressesKey(ipAddressSourceValuePair.getValue())).setIpAddressSource(ipAddressSourceValuePair.getKey()).build();
if (ipAddresses.remove(currIpAddress)) {
WriteTransaction writeTxn = dataBroker.newWriteOnlyTransaction();
if (ipAddresses.isEmpty()) {
List<VpnInterfaces> vpnInterfaces = dpnInVpn.getVpnInterfaces();
VpnToDpnListBuilder dpnInVpnBuilder = new VpnToDpnListBuilder(dpnInVpn).setIpAddresses(null);
if (vpnInterfaces == null || vpnInterfaces.isEmpty()) {
dpnInVpnBuilder.setDpnState(VpnToDpnList.DpnState.Inactive);
lastDpnOnVpn = Boolean.TRUE;
} else {
LOG.warn("ip addresses are empty but vpn interfaces are present for the vpn {} in dpn {}", vpnName, dpnId);
}
writeTxn.put(LogicalDatastoreType.OPERATIONAL, id, dpnInVpnBuilder.build(), true);
} else {
writeTxn.delete(LogicalDatastoreType.OPERATIONAL, id.child(IpAddresses.class, new IpAddressesKey(ipAddressSourceValuePair.getValue())));
}
try {
writeTxn.submit().get();
} catch (InterruptedException | ExecutionException e) {
LOG.error("Error removing from dpnToVpnList for vpn {} Ipaddress {} dpn {}", vpnName, ipAddressSourceValuePair.getValue(), dpnId, e);
throw new RuntimeException(e.getMessage(), e);
}
}
}
if (lastDpnOnVpn) {
LOG.debug("Sending cleanup event for dpn {} in VPN {}", dpnId, vpnName);
fibManager.cleanUpDpnForVpn(dpnId, vpnId, rd, new DpnEnterExitVpnWorker(dpnId, vpnName, rd, false));
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnListBuilder in project netvirt by opendaylight.
the class VpnFootprintService method createOrUpdateVpnToDpnListForIPAddress.
private void createOrUpdateVpnToDpnListForIPAddress(long vpnId, String primaryRd, BigInteger dpnId, ImmutablePair<IpAddresses.IpAddressSource, String> ipAddressSourceValuePair, String vpnName) {
Boolean newDpnOnVpn = Boolean.FALSE;
synchronized (vpnName.intern()) {
WriteTransaction writeTxn = dataBroker.newWriteOnlyTransaction();
InstanceIdentifier<VpnToDpnList> id = VpnUtil.getVpnToDpnListIdentifier(primaryRd, dpnId);
Optional<VpnToDpnList> dpnInVpn = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
IpAddressesBuilder ipAddressesBldr = new IpAddressesBuilder().setIpAddressSource(ipAddressSourceValuePair.getKey());
ipAddressesBldr.setKey(new IpAddressesKey(ipAddressSourceValuePair.getValue()));
ipAddressesBldr.setIpAddress(ipAddressSourceValuePair.getValue());
if (dpnInVpn.isPresent()) {
VpnToDpnList vpnToDpnList = dpnInVpn.get();
List<IpAddresses> ipAddresses = vpnToDpnList.getIpAddresses();
if (ipAddresses == null) {
ipAddresses = new ArrayList<>();
}
ipAddresses.add(ipAddressesBldr.build());
VpnToDpnListBuilder vpnToDpnListBuilder = new VpnToDpnListBuilder(vpnToDpnList);
vpnToDpnListBuilder.setDpnState(VpnToDpnList.DpnState.Active).setIpAddresses(ipAddresses);
writeTxn.put(LogicalDatastoreType.OPERATIONAL, id, vpnToDpnListBuilder.build(), true);
/*
* If earlier state was inactive, it is considered new DPN coming back to the
* same VPN
*/
if (vpnToDpnList.getDpnState() == VpnToDpnList.DpnState.Inactive) {
newDpnOnVpn = Boolean.TRUE;
}
} else {
List<IpAddresses> ipAddresses = new ArrayList<>();
ipAddresses.add(ipAddressesBldr.build());
VpnToDpnListBuilder vpnToDpnListBuilder = new VpnToDpnListBuilder().setDpnId(dpnId);
vpnToDpnListBuilder.setDpnState(VpnToDpnList.DpnState.Active).setIpAddresses(ipAddresses);
writeTxn.put(LogicalDatastoreType.OPERATIONAL, id, vpnToDpnListBuilder.build(), true);
newDpnOnVpn = Boolean.TRUE;
}
try {
writeTxn.submit().get();
} catch (InterruptedException | ExecutionException e) {
LOG.error("Error adding to dpnToVpnList for vpn {} ipAddresses {} dpn {}", vpnName, ipAddressSourceValuePair.getValue(), dpnId, e);
throw new RuntimeException(e.getMessage(), e);
}
}
/*
* Informing the Fib only after writeTxn is submitted successfuly.
*/
if (newDpnOnVpn) {
LOG.debug("Sending populateFib event for new dpn {} in VPN {}", dpnId, vpnName);
fibManager.populateFibOnNewDpn(dpnId, vpnId, primaryRd, new DpnEnterExitVpnWorker(dpnId, vpnName, primaryRd, true));
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnListBuilder in project netvirt by opendaylight.
the class VpnFootprintService method createOrUpdateVpnToDpnListForInterfaceName.
private void createOrUpdateVpnToDpnListForInterfaceName(long vpnId, String primaryRd, BigInteger dpnId, String intfName, String vpnName) {
Boolean newDpnOnVpn = Boolean.FALSE;
synchronized (vpnName.intern()) {
WriteTransaction writeTxn = dataBroker.newWriteOnlyTransaction();
InstanceIdentifier<VpnToDpnList> id = VpnUtil.getVpnToDpnListIdentifier(primaryRd, dpnId);
Optional<VpnToDpnList> dpnInVpn = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
VpnInterfaces vpnInterface = new VpnInterfacesBuilder().setInterfaceName(intfName).build();
if (dpnInVpn.isPresent()) {
VpnToDpnList vpnToDpnList = dpnInVpn.get();
List<VpnInterfaces> vpnInterfaces = vpnToDpnList.getVpnInterfaces();
if (vpnInterfaces == null) {
vpnInterfaces = new ArrayList<>();
}
vpnInterfaces.add(vpnInterface);
VpnToDpnListBuilder vpnToDpnListBuilder = new VpnToDpnListBuilder(vpnToDpnList);
vpnToDpnListBuilder.setDpnState(VpnToDpnList.DpnState.Active).setVpnInterfaces(vpnInterfaces);
writeTxn.put(LogicalDatastoreType.OPERATIONAL, id, vpnToDpnListBuilder.build(), WriteTransaction.CREATE_MISSING_PARENTS);
/*
* If earlier state was inactive, it is considered new DPN coming back to the
* same VPN
*/
if (vpnToDpnList.getDpnState() == VpnToDpnList.DpnState.Inactive) {
newDpnOnVpn = Boolean.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);
writeTxn.put(LogicalDatastoreType.OPERATIONAL, id, vpnToDpnListBuilder.build(), WriteTransaction.CREATE_MISSING_PARENTS);
newDpnOnVpn = Boolean.TRUE;
LOG.debug("createOrUpdateVpnToDpnList: Creating vpn footprint for vpn {} vpnId {} interface {}" + " on dpn {}", vpnName, vpnId, intfName, dpnId);
}
try {
writeTxn.submit().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);
}
}
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) {
if (VpnUtil.isVlan(dataBroker, intfName)) {
if (!VpnUtil.shouldPopulateFibForVlan(dataBroker, vpnName, null, dpnId, interfaceManager)) {
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.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnListBuilder in project netvirt by opendaylight.
the class VpnFootprintService method removeOrUpdateVpnToDpnListForInterfaceName.
private void removeOrUpdateVpnToDpnListForInterfaceName(long vpnId, String rd, BigInteger dpnId, String intfName, String vpnName) {
Boolean lastDpnOnVpn = Boolean.FALSE;
synchronized (vpnName.intern()) {
InstanceIdentifier<VpnToDpnList> id = VpnUtil.getVpnToDpnListIdentifier(rd, dpnId);
VpnToDpnList dpnInVpn = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id).orNull();
if (dpnInVpn == null) {
LOG.error("removeOrUpdateVpnToDpnList: Could not find DpnToVpn map for VPN=[name={} rd={} id={}]" + " and dpnId={}", vpnName, rd, id, dpnId);
return;
}
List<VpnInterfaces> vpnInterfaces = dpnInVpn.getVpnInterfaces();
if (vpnInterfaces == null) {
LOG.error("Could not find vpnInterfaces for DpnInVpn map for VPN=[name={} rd={} id={}] and dpnId={}", vpnName, rd, id, dpnId);
return;
}
VpnInterfaces currVpnInterface = new VpnInterfacesBuilder().setInterfaceName(intfName).build();
if (vpnInterfaces.remove(currVpnInterface)) {
WriteTransaction writeTxn = dataBroker.newWriteOnlyTransaction();
if (vpnInterfaces.isEmpty()) {
List<IpAddresses> ipAddresses = dpnInVpn.getIpAddresses();
VpnToDpnListBuilder dpnInVpnBuilder = new VpnToDpnListBuilder(dpnInVpn).setVpnInterfaces(null);
if (ipAddresses == null || ipAddresses.isEmpty()) {
dpnInVpnBuilder.setDpnState(VpnToDpnList.DpnState.Inactive);
lastDpnOnVpn = Boolean.TRUE;
} else {
LOG.error("removeOrUpdateVpnToDpnList: vpn interfaces are empty but ip addresses are present" + " for the vpn {} in dpn {} interface {}", vpnName, dpnId, intfName);
}
LOG.debug("removeOrUpdateVpnToDpnList: Removing vpn footprint for vpn {} vpnId {} interface {}," + " on dpn {}", vpnName, vpnName, intfName, dpnId);
writeTxn.put(LogicalDatastoreType.OPERATIONAL, id, dpnInVpnBuilder.build(), WriteTransaction.CREATE_MISSING_PARENTS);
} else {
writeTxn.delete(LogicalDatastoreType.OPERATIONAL, id.child(VpnInterfaces.class, new VpnInterfacesKey(intfName)));
LOG.debug("removeOrUpdateVpnToDpnList: Updating vpn footprint for vpn {} vpnId {} interface {}," + " on dpn {}", vpnName, vpnName, intfName, dpnId);
}
try {
writeTxn.submit().get();
} catch (InterruptedException | ExecutionException e) {
LOG.error("removeOrUpdateVpnToDpnList: Error removing from dpnToVpnList for vpn {} vpnId {}" + " interface {} dpn {}", vpnName, vpnId, intfName, dpnId, e);
throw new RuntimeException(e.getMessage(), e);
}
}
}
// Ends synchronized block
LOG.info("removeOrUpdateVpnToDpnList: Updated/Removed vpn footprint for vpn {} vpnId {} interface {}," + " on dpn {}", vpnName, vpnName, intfName, dpnId);
if (lastDpnOnVpn) {
fibManager.cleanUpDpnForVpn(dpnId, vpnId, rd, new DpnEnterExitVpnWorker(dpnId, vpnName, rd, false));
LOG.info("removeOrUpdateVpnToDpnList: Sent cleanup event for dpn {} in VPN {} vpnId {} interface {}", dpnId, vpnName, vpnId, intfName);
}
}
Aggregations