Bug 5334 84/35184/1
authorPeriyasamy Palanisamy <periyasamy.palanisamy@ericsson.com>
Mon, 22 Feb 2016 11:40:57 +0000 (17:10 +0530)
committerPeriyasamy Palanisamy <periyasamy.palanisamy@ericsson.com>
Mon, 22 Feb 2016 11:40:57 +0000 (17:10 +0530)
Added code to handle SMAC expiry and nodeconnector removal properly

Change-Id: Iff3c7abedaedb9bd6fd105aa3dda637eaa7de2f4
Signed-off-by: Periyasamy Palanisamy <periyasamy.palanisamy@ericsson.com>
elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/internal/ElanForwardingEntriesHandler.java
elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/internal/ElanInterfaceManager.java
elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/internal/ElanPacketInHandler.java
elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/internal/ElanSmacFlowEventListener.java
elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/utils/ElanUtils.java
mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/vpnservice/mdsalutil/MDSALUtil.java

index 42af14364f0b71f2c498e04dd52b28adcd53fea1..9be6b79be91038588933768a99eb44618e5cd553 100644 (file)
@@ -107,6 +107,7 @@ public class ElanForwardingEntriesHandler extends AbstractDataChangeListener<Ela
     public void deleteElanInterfaceForwardingEntries(ElanInstance elanInfo, InterfaceInfo interfaceInfo, MacEntry macEntry) {
         InstanceIdentifier<MacEntry> macEntryId = ElanUtils.getMacEntryOperationalDataPath(elanInfo.getElanInstanceName(), macEntry.getMacAddress());
         ElanUtils.delete(broker, LogicalDatastoreType.OPERATIONAL, macEntryId);
+        deleteElanInterfaceForwardingTablesList(interfaceInfo.getInterfaceName(), macEntry);
         ElanUtils.deleteMacFlows(elanInfo, interfaceInfo, macEntry);
     }
 
index 5bffcfc4f6e3c1bd414c8285c2bce8636e6903f7..985037d8dbab299a0648aae7d748be106b757521 100644 (file)
@@ -194,7 +194,7 @@ public class ElanInterfaceManager extends AbstractDataChangeListener<ElanInterfa
         InstanceIdentifier<ElanInterfaceMac> elanInterfaceId = ElanUtils.getElanInterfaceMacEntriesOperationalDataPath(interfaceName);
         Optional<ElanInterfaceMac> existingElanInterface = ElanUtils.read(broker, LogicalDatastoreType.OPERATIONAL, elanInterfaceId);
         if(existingElanInterface.isPresent()) {
-            List<MacEntry> macEntries = existingElanInterface.get().getMacEntry();
+            List<MacEntry> macEntries = new ArrayList<>(existingElanInterface.get().getMacEntry());
             if(macEntries != null && !macEntries.isEmpty()) {
                 for (MacEntry macEntry : macEntries) {
                     logger.debug("removing the  mac-entry:{} present on elanInterface:{}", macEntry.getMacAddress().getValue(), interfaceName);
index 04de7e3a953a858e4cb01425c574ff0dab4391b4..314275c936c90c76fc7e00a716ff84d7b5e9532e 100755 (executable)
@@ -7,19 +7,19 @@
  */
 package org.opendaylight.vpnservice.elan.internal;
 
+import java.math.BigInteger;
+
+import org.opendaylight.controller.liblldp.NetUtils;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.vpnservice.elan.utils.ElanConstants;
 import org.opendaylight.vpnservice.elan.utils.ElanUtils;
-//import org.opendaylight.vpnservice.interfacemgr.globals.InterfaceInfo;
 import org.opendaylight.vpnservice.interfacemgr.globals.InterfaceInfo;
 import org.opendaylight.vpnservice.interfacemgr.interfaces.IInterfaceManager;
 import org.opendaylight.vpnservice.mdsalutil.MDSALUtil;
 import org.opendaylight.vpnservice.mdsalutil.MetaDataUtil;
 import org.opendaylight.vpnservice.mdsalutil.NWUtil;
-import org.opendaylight.controller.liblldp.NetUtils;
 import org.opendaylight.vpnservice.mdsalutil.packet.Ethernet;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
 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.packet.service.rev130709.NoMatch;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketInReason;
@@ -36,8 +36,9 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.math.BigInteger;
+import com.google.common.base.Optional;
 
+@SuppressWarnings("deprecation")
 public class ElanPacketInHandler implements PacketProcessingListener {
 
     private final DataBroker broker;
@@ -72,12 +73,12 @@ public class ElanPacketInHandler implements PacketProcessingListener {
 
                 long portTag = MetaDataUtil.getLportFromMetadata(metadata).intValue();
 
-                IfIndexInterface interfaceInfo = ElanUtils.getInterfaceInfoByInterfaceTag(portTag);
-                if (interfaceInfo == null) {
+                Optional<IfIndexInterface> interfaceInfoOp = ElanUtils.getInterfaceInfoByInterfaceTag(portTag);
+                if (!interfaceInfoOp.isPresent()) {
                     logger.warn("There is no interface for given portTag {}", portTag);
                     return;
                 }
-                String interfaceName = interfaceInfo.getInterfaceName();
+                String interfaceName = interfaceInfoOp.get().getInterfaceName();
                 ElanTagName elanTagName = ElanUtils.getElanInfoByElanTag(elanTag);
                 String elanName = elanTagName.getName();
                 Elan elanInfo = ElanUtils.getElanByName(elanName);
index f10073592949f66c893e4a570bf22ed582d36c37..d8ff705d101ee26b644e206da5450a16556f017c 100644 (file)
@@ -7,36 +7,41 @@
  */
 package org.opendaylight.vpnservice.elan.internal;
 
+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.vpnservice.elan.utils.ElanConstants;
 import org.opendaylight.vpnservice.elan.utils.ElanUtils;
 import org.opendaylight.vpnservice.interfacemgr.globals.InterfaceInfo;
 import org.opendaylight.vpnservice.interfacemgr.interfaces.IInterfaceManager;
-import org.opendaylight.vpnservice.itm.api.IITMProvider;
 import org.opendaylight.vpnservice.mdsalutil.MetaDataUtil;
 import org.opendaylight.vpnservice.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.*;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.alivenessmonitor.rev150629.LivenessState;
+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.FlowUpdated;
+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.vpnservice.elan.rev150602.elan.tag.name.map.ElanTagName;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.elan.rev150602.forwarding.entries.MacEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._if.indexes._interface.map.IfIndexInterface;
-//import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331._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;
-import com.google.common.util.concurrent.FutureCallback;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-
-
-import java.math.BigInteger;
 
+@SuppressWarnings("deprecation")
 public class ElanSmacFlowEventListener implements SalFlowListener {
     private final DataBroker broker;
-    private IMdsalApiManager mdsalManager;
     private IInterfaceManager interfaceManager;
     private static final Logger logger = LoggerFactory.getLogger(ElanSmacFlowEventListener.class);
 
@@ -58,7 +63,6 @@ public class ElanSmacFlowEventListener implements SalFlowListener {
 
 
     public void setMdSalApiManager(IMdsalApiManager mdsalManager) {
-        this.mdsalManager = mdsalManager;
     }
     @Override
     public void onFlowAdded(FlowAdded arg0) {
@@ -100,15 +104,19 @@ public class ElanSmacFlowEventListener implements SalFlowListener {
             if (elanTagInfo == null) {
                 return;
             }
-            String srcMacAddress = switchFlowRemoved.getMatch().getEthernetMatch()
+            final String srcMacAddress = switchFlowRemoved.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;
             }
-            IfIndexInterface existingInterfaceInfo = ElanUtils.getInterfaceInfoByInterfaceTag(portTag);
-            String interfaceName = existingInterfaceInfo.getInterfaceName();
+            Optional<IfIndexInterface> existingInterfaceInfo = ElanUtils.getInterfaceInfoByInterfaceTag(portTag);
+            if (!existingInterfaceInfo.isPresent()) {
+                logger.debug("Interface is not available for port Tag {}", portTag);
+                return;
+            }
+            String interfaceName = existingInterfaceInfo.get().getInterfaceName();
             PhysAddress physAddress = new PhysAddress(srcMacAddress);
             if (interfaceName == null) {
                 logger.error(String.format("LPort record not found for tag %d", portTag));
@@ -130,12 +138,12 @@ public class ElanSmacFlowEventListener implements SalFlowListener {
             Futures.addCallback(writeResult, new FutureCallback<Void>() {
                 @Override
                 public void onSuccess(Void noarg) {
-                    logger.debug("Successfully removed macEntries from Operational Datastore");
+                    logger.debug("Successfully removed macEntry {} from Operational Datastore", srcMacAddress);
                 }
 
                 @Override
                 public void onFailure(Throwable error) {
-                    logger.debug("Error while removing macEntries from Operational Datastore", error);
+                    logger.debug("Error {} while removing macEntry {} from Operational Datastore", error, srcMacAddress);
                 }
             });
         }
index 10d4df2b79fae955f1ccb44910ffb284464149d2..40bedd614e9e7de12d0c127858c8eada4251753e 100644 (file)
@@ -337,14 +337,10 @@ public class ElanUtils {
     }
 
     // interface-index-tag operational container
-    public static IfIndexInterface getInterfaceInfoByInterfaceTag(long interfaceTag) {
+    public static Optional<IfIndexInterface> getInterfaceInfoByInterfaceTag(long interfaceTag) {
         DataBroker broker = elanServiceProvider.getBroker();
         InstanceIdentifier<IfIndexInterface> interfaceId = getInterfaceInfoEntriesOperationalDataPath(interfaceTag);
-        Optional<IfIndexInterface> existingInterfaceInfo = ElanUtils.read(broker, LogicalDatastoreType.OPERATIONAL, interfaceId);
-        if(existingInterfaceInfo.isPresent()) {
-            return existingInterfaceInfo.get();
-        }
-        return null;
+        return ElanUtils.read(broker, LogicalDatastoreType.OPERATIONAL, interfaceId);
     }
 
     public static InstanceIdentifier<IfIndexInterface> getInterfaceInfoEntriesOperationalDataPath(long interfaceTag) {
@@ -663,32 +659,31 @@ public class ElanUtils {
 
     public static void deleteMacFlows(ElanInstance elanInfo, InterfaceInfo interfaceInfo, String macAddress, boolean deleteSmac) {
         String elanInstanceName = elanInfo.getElanInstanceName();
-        String ifName = interfaceInfo.getInterfaceName();
         long ifTag = interfaceInfo.getInterfaceTag();
         List<DpnInterfaces> remoteFEs = getInvolvedDpnsInElan(elanInstanceName);
         IMdsalApiManager mdsalApiManager = elanServiceProvider.getMdsalManager();
         ItmRpcService itmRpcService = elanServiceProvider.getItmRpcService();
         BigInteger srcdpId = interfaceInfo.getDpId();
-        String displayName = elanInstanceName;
-        long groupId = interfaceInfo.getGroupId();
         for (DpnInterfaces dpnInterface: remoteFEs) {
             Long elanTag = elanInfo.getElanTag();
-            if (dpnInterface.getDpId().equals(srcdpId)) {
+            BigInteger dstDpId = dpnInterface.getDpId();
+            if (dstDpId.equals(srcdpId)) {
                 if(deleteSmac) {
-                    mdsalApiManager.removeFlow(getKnownSmacFlowEntity(elanInfo, interfaceInfo, 0, macAddress));
+                    mdsalApiManager.removeFlow(srcdpId, MDSALUtil.buildFlow(ElanConstants.ELAN_SMAC_TABLE,
+                            getKnownDynamicmacFlowRef(ElanConstants.ELAN_SMAC_TABLE, srcdpId, ifTag, macAddress, elanTag)));
                 }
-                mdsalApiManager.removeFlow(dpnInterface.getDpId(), getLocalDmacFlowEntry(elanTag, dpnInterface.getDpId(), ifName, macAddress, displayName, ifTag));
-                RemoveTerminatingServiceActionsInput removeTerminatingServiceActionsInput = new RemoveTerminatingServiceActionsInputBuilder().setServiceId(interfaceInfo.getInterfaceTag()).setDpnId(dpnInterface.getDpId()).build();
+                mdsalApiManager.removeFlow(srcdpId, MDSALUtil.buildFlow(ElanConstants.ELAN_DMAC_TABLE,
+                        getKnownDynamicmacFlowRef(ElanConstants.ELAN_DMAC_TABLE, srcdpId, ifTag, macAddress, elanTag)));
+                RemoveTerminatingServiceActionsInput removeTerminatingServiceActionsInput = new RemoveTerminatingServiceActionsInputBuilder().setServiceId(interfaceInfo.getInterfaceTag()).setDpnId(srcdpId).build();
                 itmRpcService.removeTerminatingServiceActions(removeTerminatingServiceActionsInput);
                   if (logger.isDebugEnabled()) {
-                    logger.debug("All the required flows deleted for elan:{}, logical Interface port:{} and mac address:{} on dpn:{}", elanInstanceName, interfaceInfo.getPortName(), macAddress, dpnInterface.getDpId());
+                    logger.debug("All the required flows deleted for elan:{}, logical Interface port:{} and mac address:{} on dpn:{}", elanInstanceName, interfaceInfo.getPortName(), macAddress, srcdpId);
                 }
-            } else if (isDpnPresent(dpnInterface.getDpId())) {
-                mdsalApiManager.removeFlow(dpnInterface.getDpId(),
-                        getRemoteDmacFlowEntry(dpnInterface.getDpId(), srcdpId, interfaceInfo.getInterfaceTag(), elanTag, macAddress,
-                                displayName));
+            } else if (isDpnPresent(dstDpId)) {
+                mdsalApiManager.removeFlow(dstDpId, MDSALUtil.buildFlow(ElanConstants.ELAN_DMAC_TABLE,
+                        getKnownDynamicmacFlowRef(ElanConstants.ELAN_DMAC_TABLE, srcdpId, dstDpId, macAddress, elanTag)));
                 if (logger.isDebugEnabled()) {
-                    logger.debug("Dmac flow entry deleted for elan:{}, logical interface port:{} and mac address:{} on dpn:{}", elanInstanceName, interfaceInfo.getPortName(), macAddress, dpnInterface.getDpId());
+                    logger.debug("Dmac flow entry deleted for elan:{}, logical interface port:{} and mac address:{} on dpn:{}", elanInstanceName, interfaceInfo.getPortName(), macAddress, dstDpId);
                 }
             }
         }
index f31a9675ad23a9475e644f476f743b7a7519065a..29ec0854edd8b3c7c536f681a0b8c91cb036791b 100644 (file)
@@ -138,6 +138,10 @@ public class MDSALUtil {
                 .setCookie(new FlowCookie(cookie)).build();
     }
 
+    public static Flow buildFlow(short tableId, String flowId) {
+        return new FlowBuilder().setTableId(tableId).setId(new FlowId(flowId)).build();
+    }
+
     public static Flow buildFlowNew(short tableId, String flowId, int priority, String flowName, int idleTimeOut,
                                  int hardTimeOut, BigInteger cookie, List<MatchInfo> listMatchInfo, List<Instruction> listInstructionInfo) {
         return MDSALUtil.buildFlowNew(tableId, flowId, priority, flowName, idleTimeOut, hardTimeOut, cookie,