From: Periyasamy Palanisamy Date: Mon, 22 Feb 2016 11:40:57 +0000 (+0530) Subject: Bug 5334 X-Git-Tag: release/beryllium-sr1~10 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=3983bb08d4601d410df2354f241fa001d746987d;p=vpnservice.git Bug 5334 Added code to handle SMAC expiry and nodeconnector removal properly Change-Id: Iff3c7abedaedb9bd6fd105aa3dda637eaa7de2f4 Signed-off-by: Periyasamy Palanisamy --- diff --git a/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/internal/ElanForwardingEntriesHandler.java b/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/internal/ElanForwardingEntriesHandler.java index 42af1436..9be6b79b 100644 --- a/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/internal/ElanForwardingEntriesHandler.java +++ b/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/internal/ElanForwardingEntriesHandler.java @@ -107,6 +107,7 @@ public class ElanForwardingEntriesHandler extends AbstractDataChangeListener macEntryId = ElanUtils.getMacEntryOperationalDataPath(elanInfo.getElanInstanceName(), macEntry.getMacAddress()); ElanUtils.delete(broker, LogicalDatastoreType.OPERATIONAL, macEntryId); + deleteElanInterfaceForwardingTablesList(interfaceInfo.getInterfaceName(), macEntry); ElanUtils.deleteMacFlows(elanInfo, interfaceInfo, macEntry); } diff --git a/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/internal/ElanInterfaceManager.java b/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/internal/ElanInterfaceManager.java index 5bffcfc4..985037d8 100644 --- a/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/internal/ElanInterfaceManager.java +++ b/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/internal/ElanInterfaceManager.java @@ -194,7 +194,7 @@ public class ElanInterfaceManager extends AbstractDataChangeListener elanInterfaceId = ElanUtils.getElanInterfaceMacEntriesOperationalDataPath(interfaceName); Optional existingElanInterface = ElanUtils.read(broker, LogicalDatastoreType.OPERATIONAL, elanInterfaceId); if(existingElanInterface.isPresent()) { - List macEntries = existingElanInterface.get().getMacEntry(); + List 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); diff --git a/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/internal/ElanPacketInHandler.java b/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/internal/ElanPacketInHandler.java index 04de7e3a..314275c9 100755 --- a/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/internal/ElanPacketInHandler.java +++ b/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/internal/ElanPacketInHandler.java @@ -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 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); diff --git a/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/internal/ElanSmacFlowEventListener.java b/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/internal/ElanSmacFlowEventListener.java index f1007359..d8ff705d 100644 --- a/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/internal/ElanSmacFlowEventListener.java +++ b/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/internal/ElanSmacFlowEventListener.java @@ -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 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() { @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); } }); } diff --git a/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/utils/ElanUtils.java b/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/utils/ElanUtils.java index 10d4df2b..40bedd61 100644 --- a/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/utils/ElanUtils.java +++ b/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/utils/ElanUtils.java @@ -337,14 +337,10 @@ public class ElanUtils { } // interface-index-tag operational container - public static IfIndexInterface getInterfaceInfoByInterfaceTag(long interfaceTag) { + public static Optional getInterfaceInfoByInterfaceTag(long interfaceTag) { DataBroker broker = elanServiceProvider.getBroker(); InstanceIdentifier interfaceId = getInterfaceInfoEntriesOperationalDataPath(interfaceTag); - Optional 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 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 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); } } } diff --git a/mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/vpnservice/mdsalutil/MDSALUtil.java b/mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/vpnservice/mdsalutil/MDSALUtil.java index f31a9675..29ec0854 100644 --- a/mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/vpnservice/mdsalutil/MDSALUtil.java +++ b/mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/vpnservice/mdsalutil/MDSALUtil.java @@ -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 listMatchInfo, List listInstructionInfo) { return MDSALUtil.buildFlowNew(tableId, flowId, priority, flowName, idleTimeOut, hardTimeOut, cookie,