use of org.opendaylight.controller.md.sal.binding.api.WriteTransaction in project netvirt by opendaylight.
the class CentralizedSwitchChangeListener method update.
@Override
protected void update(InstanceIdentifier<RouterToNaptSwitch> key, RouterToNaptSwitch origRouterToNaptSwitch, RouterToNaptSwitch updatedRouterToNaptSwitch) {
LOG.debug("Updating old {} new {}", origRouterToNaptSwitch, updatedRouterToNaptSwitch);
if (updatedRouterToNaptSwitch.getPrimarySwitchId() != origRouterToNaptSwitch.getPrimarySwitchId()) {
WriteTransaction removeTx = dataBroker.newWriteOnlyTransaction();
setupRouterGwFlows(origRouterToNaptSwitch, removeTx, NwConstants.DEL_FLOW);
removeTx.submit();
WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
setupRouterGwFlows(updatedRouterToNaptSwitch, writeTx, NwConstants.ADD_FLOW);
writeTx.submit();
}
}
use of org.opendaylight.controller.md.sal.binding.api.WriteTransaction in project netvirt by opendaylight.
the class DpnInVpnChangeListener method onRemoveDpnEvent.
@Override
public void onRemoveDpnEvent(RemoveDpnEvent notification) {
RemoveEventData eventData = notification.getRemoveEventData();
final String rd = eventData.getRd();
final String vpnName = eventData.getVpnName();
BigInteger dpnId = eventData.getDpnId();
LOG.trace("Remove Dpn Event notification received for rd {} VpnName {} DpnId {}", rd, vpnName, dpnId);
synchronized (vpnName.intern()) {
InstanceIdentifier<VpnInstanceOpDataEntry> id = VpnUtil.getVpnInstanceOpDataIdentifier(rd);
Optional<VpnInstanceOpDataEntry> vpnOpValue = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
if (vpnOpValue.isPresent()) {
VpnInstanceOpDataEntry vpnInstOpData = vpnOpValue.get();
List<VpnToDpnList> vpnToDpnList = vpnInstOpData.getVpnToDpnList();
boolean flushDpnsOnVpn = true;
for (VpnToDpnList dpn : vpnToDpnList) {
if (dpn.getDpnState() == VpnToDpnList.DpnState.Active) {
flushDpnsOnVpn = false;
break;
}
}
if (flushDpnsOnVpn) {
WriteTransaction writeTxn = dataBroker.newWriteOnlyTransaction();
deleteDpn(vpnToDpnList, rd, writeTxn);
try {
writeTxn.submit().get();
} catch (InterruptedException | ExecutionException e) {
LOG.error("Error removing dpnToVpnList for vpn {} ", vpnName);
throw new RuntimeException(e.getMessage(), e);
}
}
}
}
}
use of org.opendaylight.controller.md.sal.binding.api.WriteTransaction in project netvirt by opendaylight.
the class StatisticsImpl method deleteCounterRequest.
private void deleteCounterRequest(CounterRequests counterRequest, ElementCountersDirection direction) {
WriteTransaction tx = db.newWriteOnlyTransaction();
if (ElementCountersDirection.INGRESS.equals(direction)) {
tx.delete(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(IngressElementCountersRequestConfig.class).child(CounterRequests.class, new CounterRequestsKey(counterRequest.getKey().getRequestId())).build());
} else if (ElementCountersDirection.EGRESS.equals(direction)) {
tx.delete(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(EgressElementCountersRequestConfig.class).child(CounterRequests.class, new CounterRequestsKey(counterRequest.getKey().getRequestId())).build());
}
tx.submit();
}
use of org.opendaylight.controller.md.sal.binding.api.WriteTransaction in project netvirt by opendaylight.
the class ExternalNetworksChangeListener method update.
@Override
protected void update(InstanceIdentifier<Networks> identifier, Networks original, Networks update) {
// Check for VPN disassociation
Uuid originalVpn = original.getVpnid();
Uuid updatedVpn = update.getVpnid();
coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + update.getKey(), () -> {
WriteTransaction writeFlowInvTx = dataBroker.newWriteOnlyTransaction();
List<ListenableFuture<Void>> futures = new ArrayList<>();
if (originalVpn == null && updatedVpn != null) {
// external network is dis-associated from L3VPN instance
associateExternalNetworkWithVPN(update, writeFlowInvTx);
} else if (originalVpn != null && updatedVpn == null) {
// external network is associated with vpn
disassociateExternalNetworkFromVPN(update, originalVpn.getValue());
// Remove the SNAT entries
removeSnatEntries(original, original.getId(), writeFlowInvTx);
}
futures.add(NatUtil.waitForTransactionToComplete(writeFlowInvTx));
return futures;
}, NatConstants.NAT_DJC_MAX_RETRIES);
}
use of org.opendaylight.controller.md.sal.binding.api.WriteTransaction in project netvirt by opendaylight.
the class ExternalNetworksChangeListener method disassociateExternalNetworkFromVPN.
private void disassociateExternalNetworkFromVPN(Networks network, String vpnName) {
List<Uuid> routerIds = network.getRouterIds();
for (Uuid routerId : routerIds) {
InstanceIdentifier<RouterPorts> routerPortsId = NatUtil.getRouterPortsId(routerId.getValue());
Optional<RouterPorts> optRouterPorts = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsId);
if (!optRouterPorts.isPresent()) {
LOG.debug("disassociateExternalNetworkFromVPN : Could not read Router Ports data object with id: {} " + "to handle disassociate ext nw {}", routerId, network.getId());
continue;
}
RouterPorts routerPorts = optRouterPorts.get();
List<Ports> interfaces = routerPorts.getPorts();
WriteTransaction removeFlowInvTx = dataBroker.newWriteOnlyTransaction();
for (Ports port : interfaces) {
String portName = port.getPortName();
BigInteger dpnId = NatUtil.getDpnForInterface(interfaceManager, portName);
if (dpnId.equals(BigInteger.ZERO)) {
LOG.debug("disassociateExternalNetworkFromVPN : DPN not found for {}," + "skip handling of ext nw {} disassociation", portName, network.getId());
continue;
}
List<InternalToExternalPortMap> intExtPortMapList = port.getInternalToExternalPortMap();
for (InternalToExternalPortMap intExtPortMap : intExtPortMapList) {
floatingIpListener.removeNATFlowEntries(dpnId, portName, vpnName, routerId.getValue(), intExtPortMap, removeFlowInvTx);
}
}
NatUtil.waitForTransactionToComplete(removeFlowInvTx);
}
}
Aggregations