* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
+
+/*
package org.opendaylight.netvirt.elan.internal;
-import com.google.common.base.Optional;
+import static org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION;
+import static org.opendaylight.mdsal.binding.util.Datastore.OPERATIONAL;
+
import com.google.common.util.concurrent.ListenableFuture;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Optional;
import java.util.concurrent.Callable;
-import javax.annotation.PostConstruct;
+import java.util.concurrent.ExecutionException;
import javax.inject.Inject;
import javax.inject.Singleton;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
-import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
-import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.mdsal.binding.util.Datastore.Configuration;
+import org.opendaylight.mdsal.binding.util.Datastore.Operational;
+import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner;
+import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.mdsal.binding.util.TypedReadWriteTransaction;
+import org.opendaylight.mdsal.binding.util.TypedWriteTransaction;
import org.opendaylight.genius.interfacemanager.globals.InterfaceInfo;
import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
-import org.opendaylight.netvirt.elan.ElanException;
+import org.opendaylight.infrautils.utils.concurrent.Executors;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
import org.opendaylight.netvirt.elan.cache.ElanInterfaceCache;
import org.opendaylight.netvirt.elan.utils.ElanConstants;
import org.opendaylight.netvirt.elan.utils.ElanUtils;
+import org.opendaylight.serviceutils.tools.listener.AbstractAsyncDataTreeChangeListener;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterface;
@Singleton
public class ElanLearntVpnVipToPortListener extends
- AsyncDataTreeChangeListenerBase<LearntVpnVipToPort, ElanLearntVpnVipToPortListener> {
+ AbstractAsyncDataTreeChangeListener<LearntVpnVipToPort> {
private static final Logger LOG = LoggerFactory.getLogger(ElanLearntVpnVipToPortListener.class);
private final DataBroker broker;
private final ManagedNewTransactionRunner txRunner;
@Inject
public ElanLearntVpnVipToPortListener(DataBroker broker, IInterfaceManager interfaceManager, ElanUtils elanUtils,
JobCoordinator jobCoordinator, ElanInstanceCache elanInstanceCache, ElanInterfaceCache elanInterfaceCache) {
- super(LearntVpnVipToPort.class, ElanLearntVpnVipToPortListener.class);
+ super(broker, LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(LearntVpnVipToPortData.class)
+ .child(LearntVpnVipToPort.class),
+ Executors.newListeningSingleThreadExecutor("ElanLearntVpnVipToPortListener", LOG));
this.broker = broker;
this.txRunner = new ManagedNewTransactionRunnerImpl(broker);
this.interfaceManager = interfaceManager;
this.elanInterfaceCache = elanInterfaceCache;
}
- @Override
- @PostConstruct
public void init() {
- registerListener(LogicalDatastoreType.OPERATIONAL, broker);
- }
+ LOG.info("{} registered", getClass().getSimpleName());
+
+ // ELAN will learn the MAC by itself using ElanPacketInHandler class.
+ //registerListener(LogicalDatastoreType.OPERATIONAL, broker);
- @Override
- protected InstanceIdentifier<LearntVpnVipToPort> getWildCardPath() {
- return InstanceIdentifier.create(LearntVpnVipToPortData.class).child(LearntVpnVipToPort.class);
}
@Override
- protected void remove(InstanceIdentifier<LearntVpnVipToPort> key, LearntVpnVipToPort dataObjectModification) {
+ public void remove(InstanceIdentifier<LearntVpnVipToPort> key, LearntVpnVipToPort dataObjectModification) {
String macAddress = dataObjectModification.getMacAddress();
String interfaceName = dataObjectModification.getPortName();
LOG.trace("Removing mac address {} from interface {} ", macAddress, interfaceName);
}
@Override
- protected void update(InstanceIdentifier<LearntVpnVipToPort> key, LearntVpnVipToPort dataObjectModificationBefore,
+ public void update(InstanceIdentifier<LearntVpnVipToPort> key, LearntVpnVipToPort dataObjectModificationBefore,
LearntVpnVipToPort dataObjectModificationAfter) {
}
@Override
- protected void add(InstanceIdentifier<LearntVpnVipToPort> key, LearntVpnVipToPort dataObjectModification) {
+ public void add(InstanceIdentifier<LearntVpnVipToPort> key, LearntVpnVipToPort dataObjectModification) {
String macAddress = dataObjectModification.getMacAddress();
String interfaceName = dataObjectModification.getPortName();
LOG.trace("Adding mac address {} to interface {} ", macAddress, interfaceName);
new StaticMacAddWorker(macAddress, interfaceName));
}
- @Override
- protected ElanLearntVpnVipToPortListener getDataTreeChangeListener() {
- return this;
- }
-
- private class StaticMacAddWorker implements Callable<List<ListenableFuture<Void>>> {
+ private class StaticMacAddWorker implements Callable<List<? extends ListenableFuture<?>>> {
String macAddress;
String interfaceName;
}
@Override
- public List<ListenableFuture<Void>> call() throws Exception {
+ public List<ListenableFuture<Void>> call() {
Optional<ElanInterface> elanInterface = elanInterfaceCache.get(interfaceName);
if (!elanInterface.isPresent()) {
LOG.debug("ElanInterface Not present for interfaceName {} for add event", interfaceName);
return Collections.emptyList();
}
List<ListenableFuture<Void>> futures = new ArrayList<>();
- futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(interfaceTx -> futures.add(
- txRunner.callWithNewWriteOnlyTransactionAndSubmit(
- flowTx -> addMacEntryToDsAndSetupFlows(elanInterface.get().getElanInstanceName(),
- interfaceTx, flowTx, ElanConstants.STATIC_MAC_TIMEOUT)))));
+ futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, interfaceTx ->
+ futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, flowTx ->
+ addMacEntryToDsAndSetupFlows(elanInterface.get().getElanInstanceName(), interfaceTx,
+ flowTx, ElanConstants.STATIC_MAC_TIMEOUT)))));
return futures;
}
- private void addMacEntryToDsAndSetupFlows(String elanName, WriteTransaction interfaceTx,
- WriteTransaction flowTx, int macTimeOut) throws ElanException {
+ private void addMacEntryToDsAndSetupFlows(String elanName, TypedWriteTransaction<Operational> interfaceTx,
+ TypedWriteTransaction<Configuration> flowTx, int macTimeOut) {
LOG.trace("Adding mac address {} and interface name {} to ElanInterfaceForwardingEntries and "
+ "ElanForwardingTables DS", macAddress, interfaceName);
BigInteger timeStamp = new BigInteger(String.valueOf(System.currentTimeMillis()));
PhysAddress physAddress = new PhysAddress(macAddress);
MacEntry macEntry = new MacEntryBuilder().setInterface(interfaceName).setMacAddress(physAddress)
- .setKey(new MacEntryKey(physAddress)).setControllerLearnedForwardingEntryTimestamp(timeStamp)
+ .withKey(new MacEntryKey(physAddress)).setControllerLearnedForwardingEntryTimestamp(timeStamp)
.setIsStaticAddress(false).build();
InstanceIdentifier<MacEntry> macEntryId = ElanUtils
.getInterfaceMacEntriesIdentifierOperationalDataPath(interfaceName, physAddress);
- interfaceTx.put(LogicalDatastoreType.OPERATIONAL, macEntryId, macEntry);
+ interfaceTx.put(macEntryId, macEntry);
InstanceIdentifier<MacEntry> elanMacEntryId =
ElanUtils.getMacEntryOperationalDataPath(elanName, physAddress);
- interfaceTx.put(LogicalDatastoreType.OPERATIONAL, elanMacEntryId, macEntry);
- ElanInstance elanInstance = elanInstanceCache.get(elanName).orNull();
+ interfaceTx.put(elanMacEntryId, macEntry);
+ ElanInstance elanInstance = elanInstanceCache.get(elanName).orElse(null);
elanUtils.setupMacFlows(elanInstance, interfaceManager.getInterfaceInfo(interfaceName), macTimeOut,
macAddress, true, flowTx);
}
}
- private class StaticMacRemoveWorker implements Callable<List<ListenableFuture<Void>>> {
+ private class StaticMacRemoveWorker implements Callable<List<? extends ListenableFuture<?>>> {
String macAddress;
String interfaceName;
return Collections.emptyList();
}
List<ListenableFuture<Void>> futures = new ArrayList<>();
- futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(interfaceTx -> futures.add(
- txRunner.callWithNewWriteOnlyTransactionAndSubmit(
- flowTx -> deleteMacEntryFromDsAndRemoveFlows(elanInterface.get().getElanInstanceName(),
- interfaceTx, flowTx)))));
+ futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, interfaceTx ->
+ futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, flowTx ->
+ deleteMacEntryFromDsAndRemoveFlows(elanInterface.get().getElanInstanceName(),
+ interfaceTx, flowTx)))));
return futures;
}
- private void deleteMacEntryFromDsAndRemoveFlows(String elanName, WriteTransaction interfaceTx,
- WriteTransaction flowTx) {
+ private void deleteMacEntryFromDsAndRemoveFlows(String elanName,
+ TypedWriteTransaction<Operational> interfaceTx, TypedReadWriteTransaction<Configuration> flowTx)
+ throws ExecutionException, InterruptedException {
LOG.trace("Deleting mac address {} and interface name {} from ElanInterfaceForwardingEntries "
+ "and ElanForwardingTables DS", macAddress, interfaceName);
PhysAddress physAddress = new PhysAddress(macAddress);
MacEntry macEntry = elanUtils.getInterfaceMacEntriesOperationalDataPath(interfaceName, physAddress);
InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfo(interfaceName);
if (macEntry != null && interfaceInfo != null) {
- elanUtils.deleteMacFlows(elanInstanceCache.get(elanName).orNull(), interfaceInfo, macEntry, flowTx);
- interfaceTx.delete(LogicalDatastoreType.OPERATIONAL,
+ elanUtils.deleteMacFlows(elanInstanceCache.get(elanName).orElse(null), interfaceInfo, macEntry, flowTx);
+ interfaceTx.delete(
ElanUtils.getInterfaceMacEntriesIdentifierOperationalDataPath(interfaceName, physAddress));
- interfaceTx.delete(LogicalDatastoreType.OPERATIONAL,
+ interfaceTx.delete(
ElanUtils.getMacEntryOperationalDataPath(elanName, physAddress));
}
}
}
- private String buildJobKey(String mac, String interfaceName) {
+ private static String buildJobKey(String mac, String interfaceName) {
return "ENTERPRISEMACJOB" + mac + interfaceName;
}
}
+*/