*/
package org.opendaylight.netvirt.elan.internal;
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
import java.math.BigInteger;
-
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.mdsalutil.NwConstants;
import org.opendaylight.netvirt.elan.utils.ElanUtils;
-import org.opendaylight.netvirt.elan.utils.ElanConstants;
import org.opendaylight.genius.interfacemanager.globals.InterfaceInfo;
import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
import org.opendaylight.genius.mdsalutil.MetaDataUtil;
-import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
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.flow.service.rev130819.FlowAdded;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeErrorNotification;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeExperimenterErrorNotification;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowListener;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SwitchFlowRemoved;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406._if.indexes._interface.map.IfIndexInterface;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.tag.name.map.ElanTagName;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.forwarding.entries.MacEntry;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406._if.indexes._interface.map.IfIndexInterface;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
-
@SuppressWarnings("deprecation")
public class ElanSmacFlowEventListener implements SalFlowListener {
- private final DataBroker broker;
- private IInterfaceManager interfaceManager;
- private static final Logger logger = LoggerFactory.getLogger(ElanSmacFlowEventListener.class);
- public ElanSmacFlowEventListener(DataBroker dataBroker) {
- broker = dataBroker;
- }
- private SalFlowService salFlowService;
+ private static final Logger logger = LoggerFactory.getLogger(ElanSmacFlowEventListener.class);
- public SalFlowService getSalFlowService() {
- return this.salFlowService;
- }
+ private final DataBroker broker;
+ private final IInterfaceManager interfaceManager;
+ private final ElanUtils elanUtils;
- public void setSalFlowService(final SalFlowService salFlowService) {
- this.salFlowService = salFlowService;
- }
- public void setInterfaceManager(IInterfaceManager interfaceManager) {
+ public ElanSmacFlowEventListener(DataBroker broker, IInterfaceManager interfaceManager, ElanUtils elanUtils) {
+ this.broker = broker;
this.interfaceManager = interfaceManager;
+ this.elanUtils = elanUtils;
}
- public void setMdSalApiManager(IMdsalApiManager mdsalManager) {
- }
@Override
public void onFlowAdded(FlowAdded arg0) {
// TODO Auto-generated method stub
+
}
@Override
public void onFlowRemoved(FlowRemoved flowRemoved) {
short tableId = flowRemoved.getTableId();
- if (tableId == ElanConstants.ELAN_SMAC_TABLE) {
+ if (tableId == NwConstants.ELAN_SMAC_TABLE) {
BigInteger metadata = flowRemoved.getMatch().getMetadata().getMetadata();
long elanTag = MetaDataUtil.getElanTagFromMetadata(metadata);
- ElanTagName elanTagInfo = ElanUtils.getElanInfoByElanTag(elanTag);
+ ElanTagName elanTagInfo = elanUtils.getElanInfoByElanTag(elanTag);
if (elanTagInfo == null) {
return;
}
final String srcMacAddress = flowRemoved.getMatch().getEthernetMatch()
- .getEthernetSource().getAddress().getValue().toUpperCase();
+ .getEthernetSource().getAddress().getValue().toUpperCase();
int portTag = MetaDataUtil.getLportFromMetadata(metadata).intValue();
if (portTag == 0) {
logger.debug(String.format("Flow removed event on SMAC flow entry. But having port Tag as 0 "));
return;
}
- Optional<IfIndexInterface> existingInterfaceInfo = ElanUtils.getInterfaceInfoByInterfaceTag(portTag);
+ Optional<IfIndexInterface> existingInterfaceInfo = elanUtils.getInterfaceInfoByInterfaceTag(portTag);
if (!existingInterfaceInfo.isPresent()) {
logger.debug("Interface is not available for port Tag {}", portTag);
return;
logger.error(String.format("LPort record not found for tag %d", portTag));
return;
}
- MacEntry macEntry = ElanUtils.getInterfaceMacEntriesOperationalDataPath(interfaceName, physAddress);
+ MacEntry macEntry = elanUtils.getInterfaceMacEntriesOperationalDataPath(interfaceName, physAddress);
InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfo(interfaceName);
- if(macEntry != null && interfaceInfo != null) {
- ElanUtils.deleteMacFlows(ElanUtils.getElanInstanceByName(elanTagInfo.getName()), interfaceInfo, macEntry);
+ if (macEntry != null && interfaceInfo != null) {
+ WriteTransaction deleteFlowTx = broker.newWriteOnlyTransaction();
+ elanUtils.deleteMacFlows(elanUtils.getElanInstanceByName(elanTagInfo.getName()), interfaceInfo, macEntry, deleteFlowTx);
+ ListenableFuture<Void> result = deleteFlowTx.submit();
+ addCallBack(result, srcMacAddress);
}
InstanceIdentifier<MacEntry> macEntryIdForElanInterface = ElanUtils.getInterfaceMacEntriesIdentifierOperationalDataPath(interfaceName, physAddress);
InstanceIdentifier<MacEntry> macEntryIdForElanInstance = ElanUtils.getMacEntryOperationalDataPath(elanTagInfo.getName(), physAddress);
tx.delete(LogicalDatastoreType.OPERATIONAL, macEntryIdForElanInterface);
tx.delete(LogicalDatastoreType.OPERATIONAL, macEntryIdForElanInstance);
ListenableFuture<Void> writeResult = tx.submit();
-
- //WRITE Callback
- Futures.addCallback(writeResult, new FutureCallback<Void>() {
- @Override
- public void onSuccess(Void noarg) {
- logger.debug("Successfully removed macEntry {} from Operational Datastore", srcMacAddress);
- }
-
- @Override
- public void onFailure(Throwable error) {
- logger.debug("Error {} while removing macEntry {} from Operational Datastore", error, srcMacAddress);
- }
- });
+ addCallBack(writeResult, srcMacAddress);
}
+
+ }
+
+ private void addCallBack(ListenableFuture<Void> writeResult, String srcMacAddress) {
+ //WRITE Callback
+ Futures.addCallback(writeResult, new FutureCallback<Void>() {
+ @Override
+ public void onSuccess(Void noarg) {
+ logger.debug("Successfully removed macEntry {} from Operational Datastore", srcMacAddress);
+ }
+
+ @Override
+ public void onFailure(Throwable error) {
+ logger.debug("Error {} while removing macEntry {} from Operational Datastore", error, srcMacAddress);
+ }
+ });
}
@Override
public void onFlowUpdated(FlowUpdated arg0) {
// TODO Auto-generated method stub
+
}
@Override
public void onNodeErrorNotification(NodeErrorNotification arg0) {
// TODO Auto-generated method stub
+
}
@Override
public void onNodeExperimenterErrorNotification(NodeExperimenterErrorNotification arg0) {
// TODO Auto-generated method stub
+
}
@Override
public void onSwitchFlowRemoved(SwitchFlowRemoved switchFlowRemoved) {
- // TODO Auto-generated method stub
+
}
+
+
}