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.netvirt.elan.utils.ElanUtils;
import org.opendaylight.netvirt.elan.utils.ElanConstants;
+import org.opendaylight.netvirt.elan.utils.ElanUtils;
import org.opendaylight.genius.interfacemanager.globals.InterfaceInfo;
import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
import org.opendaylight.genius.mdsalutil.MetaDataUtil;
@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 ElanServiceProvider elanServiceProvider = null;
+ private static volatile ElanSmacFlowEventListener elanSmacFlowEventListener = null;
+ private static final Logger logger = LoggerFactory.getLogger(ElanSmacFlowEventListener.class);
- public SalFlowService getSalFlowService() {
- return this.salFlowService;
+ public ElanSmacFlowEventListener(ElanServiceProvider elanServiceProvider) {
+ this.elanServiceProvider = elanServiceProvider;
}
- public void setSalFlowService(final SalFlowService salFlowService) {
- this.salFlowService = salFlowService;
- }
- public void setInterfaceManager(IInterfaceManager interfaceManager) {
- this.interfaceManager = interfaceManager;
+ public static ElanSmacFlowEventListener getElanSmacFlowEventListener(ElanServiceProvider elanServiceProvider) {
+ if (elanSmacFlowEventListener == null)
+ synchronized (ElanPacketInHandler.class) {
+ if (elanSmacFlowEventListener == null) {
+ elanSmacFlowEventListener = new ElanSmacFlowEventListener(elanServiceProvider);
+ }
+ }
+ return elanSmacFlowEventListener;
}
}
@Override
- public void onFlowRemoved(FlowRemoved arg0) {
- // TODO Auto-generated method stub
-
- }
-
- @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) {
- short tableId = switchFlowRemoved.getTableId();
+ public void onFlowRemoved(FlowRemoved flowRemoved) {
+ short tableId = flowRemoved.getTableId();
if (tableId == ElanConstants.ELAN_SMAC_TABLE) {
- BigInteger metadata = switchFlowRemoved.getMatch().getMetadata().getMetadata();
+ BigInteger metadata = flowRemoved.getMatch().getMetadata().getMetadata();
long elanTag = MetaDataUtil.getElanTagFromMetadata(metadata);
ElanTagName elanTagInfo = ElanUtils.getElanInfoByElanTag(elanTag);
if (elanTagInfo == null) {
return;
}
- final String srcMacAddress = switchFlowRemoved.getMatch().getEthernetMatch()
- .getEthernetSource().getAddress().getValue().toUpperCase();
+ final String srcMacAddress = flowRemoved.getMatch().getEthernetMatch()
+ .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;
}
MacEntry macEntry = ElanUtils.getInterfaceMacEntriesOperationalDataPath(interfaceName, physAddress);
- InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfo(interfaceName);
- if(macEntry != null && interfaceInfo != null) {
- ElanUtils.deleteMacFlows(ElanUtils.getElanInstanceByName(elanTagInfo.getName()), interfaceInfo, macEntry);
+ InterfaceInfo interfaceInfo = elanServiceProvider.getInterfaceManager().getInterfaceInfo(interfaceName);
+ if (macEntry != null && interfaceInfo != null) {
+ WriteTransaction deleteFlowTx = elanServiceProvider.getBroker().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);
- WriteTransaction tx = broker.newWriteOnlyTransaction();
+ WriteTransaction tx = elanServiceProvider.getBroker().newWriteOnlyTransaction();
tx.delete(LogicalDatastoreType.OPERATIONAL, macEntryIdForElanInterface);
tx.delete(LogicalDatastoreType.OPERATIONAL, macEntryIdForElanInstance);
ListenableFuture<Void> writeResult = tx.submit();
+ addCallBack(writeResult, srcMacAddress);
+ }
- //WRITE Callback
- Futures.addCallback(writeResult, new FutureCallback<Void>() {
- @Override
- public void onSuccess(Void noarg) {
- logger.debug("Successfully removed macEntry {} from Operational Datastore", 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 onFailure(Throwable error) {
- logger.debug("Error {} while removing macEntry {} from Operational Datastore", error, srcMacAddress);
- }
- });
- }
}
+
+ @Override
+ public void onSwitchFlowRemoved(SwitchFlowRemoved switchFlowRemoved) {
+
+ }
+
+
}