Bug 5512 86/36286/1
authorPeriyasamy Palanisamy <periyasamy.palanisamy@ericsson.com>
Wed, 16 Mar 2016 10:34:06 +0000 (16:04 +0530)
committerPeriyasamy Palanisamy <periyasamy.palanisamy@ericsson.com>
Wed, 16 Mar 2016 10:34:06 +0000 (16:04 +0530)
Change-Id: I03b726b6b993e29c0f7f5f53eda8f902c682f7d1
Signed-off-by: Periyasamy Palanisamy <periyasamy.palanisamy@ericsson.com>
elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/internal/ElanInterfaceManager.java
elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/internal/ElanInterfaceStateChangeListener.java
elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/utils/ElanUtils.java
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/InterfacemgrProvider.java

index 5dbe4168330050ae794c64a495508e61843c6102..d191d82f7a5d6cd27267ae3a38e6ca3ad2f4b2aa 100644 (file)
@@ -193,8 +193,12 @@ 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 = new ArrayList<>(existingElanInterface.get().getMacEntry());
-            if(macEntries != null && !macEntries.isEmpty()) {
+            List<MacEntry> existingMacEntries = existingElanInterface.get().getMacEntry();
+            List<MacEntry> macEntries = new ArrayList<>();
+            if (existingMacEntries != null && !existingMacEntries.isEmpty()) {
+                macEntries.addAll(existingMacEntries);
+            }
+            if(!macEntries.isEmpty()) {
                 for (MacEntry macEntry : macEntries) {
                     logger.debug("removing the  mac-entry:{} present on elanInterface:{}", macEntry.getMacAddress().getValue(), interfaceName);
                     elanForwardingEntriesHandler.deleteElanInterfaceForwardingEntries(elanInfo, interfaceInfo, macEntry);
@@ -290,6 +294,10 @@ public class ElanInterfaceManager extends AbstractDataChangeListener<ElanInterfa
         String elanInstanceName = elanInterfaceAdded.getElanInstanceName();
         String interfaceName = elanInterfaceAdded.getName();
         InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfo(interfaceName);
+        if (interfaceInfo == null) {
+            logger.warn("Interface {} is removed from Interface Oper DS due to port down ", interfaceName);
+            return;
+        }
         ElanInstance elanInstance = ElanUtils.getElanInstanceByName(elanInstanceName);
 
         if (elanInstance == null) {
@@ -327,6 +335,35 @@ public class ElanInterfaceManager extends AbstractDataChangeListener<ElanInterfa
         }
     }
 
+    void programRemoteDmacFlow(ElanInstance elanInstance, InterfaceInfo interfaceInfo){
+        ElanDpnInterfacesList elanDpnInterfacesList =  ElanUtils.getElanDpnInterfacesList(elanInstance.getElanInstanceName());
+        List<DpnInterfaces> dpnInterfaceLists =  elanDpnInterfacesList.getDpnInterfaces();
+        for(DpnInterfaces dpnInterfaces : dpnInterfaceLists){
+            if(dpnInterfaces.getDpId().equals(interfaceInfo.getDpId())) {
+                continue;
+            }
+            List<String> remoteElanInterfaces = dpnInterfaces.getInterfaces();
+            for(String remoteIf : remoteElanInterfaces) {
+                ElanInterfaceMac elanIfMac = ElanUtils.getElanInterfaceMacByInterfaceName(remoteIf);
+                InterfaceInfo remoteInterface = interfaceManager.getInterfaceInfo(remoteIf);
+                if(elanIfMac == null) {
+                    continue;
+                }
+                List<MacEntry> remoteMacEntries = elanIfMac.getMacEntry();
+                if(remoteMacEntries != null) {
+                    for (MacEntry macEntry : remoteMacEntries) {
+                        PhysAddress physAddress = macEntry.getMacAddress();
+                        ElanUtils.setupRemoteDmacFlow(interfaceInfo.getDpId(), remoteInterface.getDpId(),
+                                remoteInterface.getInterfaceTag(),
+                                elanInstance.getElanTag(),
+                                physAddress.getValue(),
+                                elanInstance.getElanInstanceName());
+                    }
+                }
+            }
+        }
+    }
+
     void addElanInterface(ElanInterface elanInterface, InterfaceInfo interfaceInfo, ElanInstance elanInstance) {
         String interfaceName = elanInterface.getName();
         String elanInstanceName = elanInterface.getElanInstanceName();
@@ -344,6 +381,12 @@ public class ElanInterfaceManager extends AbstractDataChangeListener<ElanInterfa
             Optional<DpnInterfaces> existingElanDpnInterfaces = ElanUtils.read(broker, LogicalDatastoreType.OPERATIONAL, elanDpnInterfaces);
             if (!existingElanDpnInterfaces.isPresent()) {
                 createElanInterfacesList(elanInstanceName, interfaceName, dpId);
+                /*
+                 * Install remote DMAC flow.
+                 * This is required since this DPN is added later to the elan instance
+                 * and remote DMACs of other interfaces in this elan instance are not present in the current dpn.
+                 */
+                programRemoteDmacFlow(elanInstance, interfaceInfo);
             } else {
                 List<String> elanInterfaces = existingElanDpnInterfaces.get().getInterfaces();
                 elanInterfaces.add(interfaceName);
@@ -369,7 +412,7 @@ public class ElanInterfaceManager extends AbstractDataChangeListener<ElanInterfa
                 } else {
                     elanForwardingEntriesHandler.addElanInterfaceForwardingTableList(elanInstance, interfaceName, physAddress);
                 }
-                if(interfaceInfo != null && isOperational(interfaceInfo)) {
+                if(isOperational(interfaceInfo)) {
                     logger.debug("Installing Static Mac-Entry on the Elan Interface:{} with MacAddress:{}", interfaceInfo, physAddress.getValue());
                     ElanUtils.setupMacFlows(elanInstance, interfaceInfo, ElanConstants.STATIC_MAC_TIMEOUT, physAddress.getValue());
                 }
@@ -695,7 +738,7 @@ public class ElanInterfaceManager extends AbstractDataChangeListener<ElanInterfa
             // In case if there is a InterfacePort in the cache which is not in
             // operational state, skip processing it
             InterfaceInfo ifInfo = interfaceManager.getInterfaceInfoFromOperationalDataStore(ifName, interfaceInfo.getInterfaceType());
-            if (ifInfo == null || !isOperational(ifInfo)) {
+            if (!isOperational(ifInfo)) {
                 continue;
             }
 
@@ -727,7 +770,7 @@ public class ElanInterfaceManager extends AbstractDataChangeListener<ElanInterfa
             // In case if there is a InterfacePort in the cache which is not in
             // operational state, skip processing it
             InterfaceInfo ifInfo = interfaceManager.getInterfaceInfoFromOperationalDataStore(ifName, interfaceInfo.getInterfaceType());
-            if (ifInfo == null || !isOperational(ifInfo)) {
+            if (!isOperational(ifInfo)) {
                 continue;
             }
 
@@ -931,6 +974,9 @@ public class ElanInterfaceManager extends AbstractDataChangeListener<ElanInterfa
     }
 
     private boolean isOperational(InterfaceInfo interfaceInfo) {
+        if (interfaceInfo == null) {
+            return false;
+        }
         return ((interfaceInfo.getOpState() == InterfaceInfo.InterfaceOpState.UP) && (interfaceInfo.getAdminState() == InterfaceInfo.InterfaceAdminState.ENABLED));
     }
 
index 256e8b267ba3181062afeb962b0b6995d9c96970..3d4a5a20f8a7b2b2d1b52797c67219b78063ae1f 100644 (file)
@@ -95,7 +95,7 @@ public class ElanInterfaceStateChangeListener extends AbstractDataChangeListener
             return;
         }
         NodeConnectorId nodeConnectorId = new NodeConnectorId(delIf.getLowerLayerIf().get(0));
-        BigInteger dpId = MDSALUtil.getDpnIdFromNodeName(nodeConnectorId.getValue());
+        BigInteger dpId = BigInteger.valueOf(MDSALUtil.getDpnIdFromPortName(nodeConnectorId));
         InterfaceInfo interfaceInfo = new InterfaceInfo(dpId, nodeConnectorId.getValue());
         interfaceInfo.setInterfaceName(interfaceName);
         interfaceInfo.setInterfaceType(InterfaceInfo.InterfaceType.VLAN_INTERFACE);
index 6b6228d7fcbf071e7305dc6f4f07fb2558edffa3..2d4c834b974aad33764821954bd0d6cddae83a1d 100644 (file)
@@ -676,7 +676,7 @@ public class ElanUtils {
                 }
             } else if (isDpnPresent(dstDpId)) {
                 mdsalApiManager.removeFlow(dstDpId, MDSALUtil.buildFlow(ElanConstants.ELAN_DMAC_TABLE,
-                        getKnownDynamicmacFlowRef(ElanConstants.ELAN_DMAC_TABLE, srcdpId, dstDpId, macAddress, elanTag)));
+                        getKnownDynamicmacFlowRef(ElanConstants.ELAN_DMAC_TABLE, dstDpId, srcdpId, 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, dstDpId);
                 }
index 6f11053658c5adea2dd75d613dd8f57c6b861f9c..caac3ab19f45fca8c9d52ee3b05dda5d4dc5d7bb 100644 (file)
@@ -192,13 +192,17 @@ public class InterfacemgrProvider implements BindingAwareProvider, AutoCloseable
         org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface
                 ifState = InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(interfaceName,dataBroker);
 
-        if(ifState == null){
+        if(ifState == null) {
             LOG.error("Interface {} is not present", interfaceName);
             return null;
         }
 
         Integer lportTag = ifState.getIfIndex();
         Interface intf = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(new InterfaceKey(interfaceName), dataBroker);
+        if (intf == null) {
+            LOG.error("Interface {} doesn't exist in config datastore", interfaceName);
+            return null;
+        }
 
         NodeConnectorId ncId = IfmUtil.getNodeConnectorIdFromInterface(intf, dataBroker);
         InterfaceInfo.InterfaceType interfaceType = IfmUtil.getInterfaceType(intf);