*/
package org.opendaylight.netvirt.dhcpservice;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+
import com.google.common.base.Optional;
import com.google.common.util.concurrent.ListenableFuture;
import java.math.BigInteger;
import org.apache.commons.lang3.tuple.Pair;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.genius.infra.Datastore.Configuration;
import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.genius.infra.TransactionAdapter;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
import org.opendaylight.genius.mdsalutil.MDSALUtil;
import org.opendaylight.genius.mdsalutil.NwConstants;
private final JobCoordinator jobCoordinator;
private final L2GatewayCache l2GatewayCache;
private IElanService elanService;
+ private final DhcpServiceCounters dhcpServiceCounters;
private final ConcurrentMap<BigInteger, Set<Pair<IpAddress, String>>> designatedDpnsToTunnelIpElanNameCache =
new ConcurrentHashMap<>();
final IMdsalApiManager mdsalUtil, final ItmRpcService itmRpcService,
final EntityOwnershipService entityOwnershipService, final IInterfaceManager interfaceManager,
final JobCoordinator jobCoordinator, final L2GatewayCache l2GatewayCache,
- @Named("elanService") IElanService ielanService) {
+ @Named("elanService") IElanService ielanService, DhcpServiceCounters dhcpServiceCounters) {
this.broker = broker;
this.txRunner = new ManagedNewTransactionRunnerImpl(broker);
this.mdsalUtil = mdsalUtil;
this.jobCoordinator = jobCoordinator;
this.l2GatewayCache = l2GatewayCache;
this.elanService = ielanService;
+ this.dhcpServiceCounters = dhcpServiceCounters;
}
@PostConstruct
jobCoordinator.enqueueJob(getJobKey(tunnelIpDpnKey), () -> {
if (entityOwnershipUtils.isEntityOwner(HwvtepSouthboundConstants.ELAN_ENTITY_TYPE,
HwvtepSouthboundConstants.ELAN_ENTITY_NAME)) {
- return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
- dpns.remove(designatedDpnId);
- for (BigInteger dpn : dpns) {
- installDhcpDropAction(dpn, vmMacAddress, tx);
- }
- installDhcpEntries(designatedDpnId, vmMacAddress, tx);
- }));
+ return Collections.singletonList(
+ txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
+ dpns.remove(designatedDpnId);
+ for (BigInteger dpn : dpns) {
+ installDhcpDropAction(dpn, vmMacAddress, tx);
+ }
+ installDhcpEntries(designatedDpnId, vmMacAddress, tx);
+ }));
} else {
LOG.trace("Exiting installDhcpEntries since this cluster node is not the owner for dpn");
}
updateLocalCache(tunnelIp, elanInstanceName, vmMacAddress);
}
- public void installDhcpFlowsForVms(BigInteger designatedDpnId, Set<String> listVmMacAddress, WriteTransaction tx) {
+ public void installDhcpFlowsForVms(BigInteger designatedDpnId, Set<String> listVmMacAddress,
+ TypedWriteTransaction<Configuration> tx) {
for (String vmMacAddress : listVmMacAddress) {
installDhcpEntries(designatedDpnId, vmMacAddress, tx);
}
DesignatedSwitchForTunnel designatedSwitchForTunnel =
new DesignatedSwitchForTunnelBuilder().setDpId(dpnId.longValue())
.setElanInstanceName(elanInstanceName).setTunnelRemoteIpAddress(tunnelIp)
- .setKey(designatedSwitchForTunnelKey).build();
+ .withKey(designatedSwitchForTunnelKey).build();
LOG.trace("Writing into CONFIG DS tunnelIp {}, elanInstanceName {}, dpnId {}", tunnelIp, elanInstanceName,
dpnId);
MDSALUtil.syncUpdate(broker, LogicalDatastoreType.CONFIGURATION, instanceIdentifier, designatedSwitchForTunnel);
}
List<String> vmMacs = getAllVmMacs();
LOG.trace("Installing drop actions to this new DPN {} VMs {}", dpId, vmMacs);
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+ ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
for (String vmMacAddress : vmMacs) {
installDhcpDropAction(dpId, vmMacAddress, tx);
}
if (setOfTunnelIpElanNamePairs == null || setOfTunnelIpElanNamePairs.isEmpty()) {
LOG.trace("No tunnelIpElanName to handle for dpn {}. Returning", dpnId);
} else {
- ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(tx -> {
+ ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
if (!dpnId.equals(DhcpMConstants.INVALID_DPID)) {
List<String> listOfVms = getAllVmMacs();
for (String vmMacAddress : listOfVms) {
}
public void updateCacheAndInstallNewFlows(List<BigInteger> listOfDpns, Pair<IpAddress, String> pair,
- WriteTransaction tx) {
+ TypedWriteTransaction<Configuration> tx) {
BigInteger newDesignatedDpn = chooseDpn(pair.getLeft(), pair.getRight(), listOfDpns);
if (newDesignatedDpn.equals(DhcpMConstants.INVALID_DPID)) {
return;
}
private void changeExistingFlowToDrop(Pair<IpAddress, String> tunnelIpElanNamePair, BigInteger dpnId,
- WriteTransaction tx) {
+ TypedWriteTransaction<Configuration> tx) {
Set<String> setOfVmMacAddress = tunnelIpElanNameToVmMacCache.get(tunnelIpElanNamePair);
if (setOfVmMacAddress == null || setOfVmMacAddress.isEmpty()) {
return;
writeDesignatedSwitchForExternalTunnel(DhcpMConstants.INVALID_DPID, tunnelIp, elanInstanceName);
}
- private void installDhcpEntries(BigInteger dpnId, String vmMacAddress, WriteTransaction tx) {
+ private void installDhcpEntries(BigInteger dpnId, String vmMacAddress, TypedWriteTransaction<Configuration> tx) {
DhcpServiceUtils.setupDhcpFlowEntry(dpnId, NwConstants.DHCP_TABLE_EXTERNAL_TUNNEL,
- vmMacAddress, NwConstants.ADD_FLOW, mdsalUtil, tx);
+ vmMacAddress, NwConstants.ADD_FLOW, mdsalUtil, dhcpServiceCounters, tx);
}
public void addOrRemoveDhcpArpFlowforElan(String elanInstanceName, boolean addFlow, String dhcpIpAddress,
builder.setDpId(dpnId).setInterfaceName(interfaceName).setSpa(dhcpIpAddress).setSha(dhcpMacAddress)
.setLportTag(lportTag);
builder.setInstructions(ArpResponderUtil.getInterfaceInstructions(interfaceManager, interfaceName,
- dhcpIpAddress, dhcpMacAddress));
+ dhcpIpAddress, dhcpMacAddress, itmRpcService));
elanService.addExternalTunnelArpResponderFlow(builder.buildForInstallFlow(), elanInstanceName);
}
}
- public void unInstallDhcpEntries(BigInteger dpnId, String vmMacAddress, WriteTransaction tx) {
+ public void unInstallDhcpEntries(BigInteger dpnId, String vmMacAddress, TypedWriteTransaction<Configuration> tx) {
DhcpServiceUtils.setupDhcpFlowEntry(dpnId, NwConstants.DHCP_TABLE_EXTERNAL_TUNNEL,
- vmMacAddress, NwConstants.DEL_FLOW, mdsalUtil, tx);
+ vmMacAddress, NwConstants.DEL_FLOW, mdsalUtil, dhcpServiceCounters, tx);
}
- private void installDhcpDropAction(BigInteger dpn, String vmMacAddress, WriteTransaction tx) {
+ private void installDhcpDropAction(BigInteger dpn, String vmMacAddress, TypedWriteTransaction<Configuration> tx) {
DhcpServiceUtils.setupDhcpDropAction(dpn, NwConstants.DHCP_TABLE_EXTERNAL_TUNNEL,
- vmMacAddress, NwConstants.ADD_FLOW, mdsalUtil, tx);
+ vmMacAddress, NwConstants.ADD_FLOW, mdsalUtil, dhcpServiceCounters, tx);
}
public List<ListenableFuture<Void>> handleTunnelStateDown(IpAddress tunnelIp, BigInteger interfaceDpn) {
}
}
}
- return Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(tx -> {
+ return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
for (Pair<IpAddress, String> tunnelElanPair : tunnelElanPairSet) {
IpAddress tunnelIpInDpn = tunnelElanPair.getLeft();
String elanInstanceName = tunnelElanPair.getRight();
.setMacEntryKey(new MacAddress(UNKNOWN_DMAC))
.setLogicalSwitchRef(lsRef).build();
InstanceIdentifier<RemoteMcastMacs> iid = HwvtepSouthboundUtils.createRemoteMcastMacsInstanceIdentifier(
- dstDevice.getNodeId(), remoteMcastMacs.getKey());
+ dstDevice.getNodeId(), remoteMcastMacs.key());
ReadOnlyTransaction transaction = broker.newReadOnlyTransaction();
try {
//TODO do async mdsal read
return null;
}
- private WriteTransaction putRemoteMcastMac(WriteTransaction transaction, String elanName,
- L2GatewayDevice device, IpAddress internalTunnelIp) {
+ private void putRemoteMcastMac(TypedWriteTransaction<Configuration> transaction, String elanName,
+ L2GatewayDevice device, IpAddress internalTunnelIp) {
Optional<Node> optionalNode = getNode(broker, device.getHwvtepNodeId());
Node dstNode = optionalNode.get();
if (dstNode == null) {
LOG.trace("could not get device node {} ", device.getHwvtepNodeId());
- return null;
+ return;
}
RemoteMcastMacs macs = createRemoteMcastMac(dstNode, elanName, internalTunnelIp);
- HwvtepUtils.putRemoteMcastMac(transaction, dstNode.getNodeId(), macs);
- return transaction;
+ HwvtepUtils.putRemoteMcastMac(TransactionAdapter.toWriteTransaction(transaction), dstNode.getNodeId(), macs);
}
public void installRemoteMcastMac(final BigInteger designatedDpnId, final IpAddress tunnelIp,
LOG.trace("Tunnel Interface is not present {}", tunnelInterfaceName);
return Collections.emptyList();
}
- return Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(
+ return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
tx -> putRemoteMcastMac(tx, elanInstanceName, device,
- tunnelInterface.getAugmentation(IfTunnel.class).getTunnelSource())));
+ tunnelInterface.augmentation(IfTunnel.class).getTunnelSource())));
}
return Collections.emptyList();
});
LOG.trace("There are no undesignated DPNs");
return Collections.emptyList();
}
- return Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(tx -> {
+ return Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
for (Pair<IpAddress, String> pair : tunnelIpElanPair) {
if (tunnelIp.equals(pair.getLeft())) {
String elanInstanceName = pair.getRight();
jobCoordinator.enqueueJob(getJobKey(vmMacAddress), () -> {
if (entityOwnershipUtils.isEntityOwner(HwvtepSouthboundConstants.ELAN_ENTITY_TYPE,
HwvtepSouthboundConstants.ELAN_ENTITY_NAME)) {
- return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
- for (final BigInteger dpn : dpns) {
- unInstallDhcpEntries(dpn, vmMacAddress, tx);
- }
- }));
+ return Collections.singletonList(
+ txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
+ for (final BigInteger dpn : dpns) {
+ unInstallDhcpEntries(dpn, vmMacAddress, tx);
+ }
+ }));
} else {
LOG.trace("Exiting unInstallDhcpEntries since this cluster node is not the owner for dpn");
}