BUG:5179 ITM Tunnel Event for Multi-DPN Elan 46/34346/2
authorepgoraj <p.govinda.rajulu@ericsson.com>
Tue, 9 Feb 2016 17:04:39 +0000 (22:34 +0530)
committergovind <p.govinda.rajulu@ericsson.com>
Tue, 9 Feb 2016 17:11:24 +0000 (17:11 +0000)
Change-Id: Id1ec2005dc1635b148354844eb5e8c25df29e736
Signed-off-by: epgoraj <p.govinda.rajulu@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

index 95460af6a37a1720e16c12cdcfbc099356c4b7e0..5bffcfc4f6e3c1bd414c8285c2bce8636e6903f7 100644 (file)
@@ -561,12 +561,24 @@ public class ElanInterfaceManager extends AbstractDataChangeListener<ElanInterfa
                                                InterfaceInfo interfaceInfo, BigInteger dstDpId) {
         int elanTag = elanInfo.getElanTag().intValue();
         long groupId = ElanUtils.getElanRemoteBCGID(elanTag);
+        DpnInterfaces dpnInterfaces = ElanUtils.getElanInterfaceInfoByElanDpn(elanInfo.getElanInstanceName(), interfaceInfo.getDpId());
         List<DpnInterfaces> elanDpns = ElanUtils.getInvolvedDpnsInElan(elanInfo.getElanInstanceName());
         if(elanDpns != null) {
             for(DpnInterfaces dpnInterface : elanDpns) {
                 int bucketId = 0;
                 List<Bucket> remoteListBucket = new ArrayList<Bucket>();
                 if(ElanUtils.isDpnPresent(dstDpId) && dpnInterface.getDpId().equals(dstDpId) && dpnInterface.getInterfaces() != null && !dpnInterface.getInterfaces().isEmpty()) {
+                    for(String ifName : dpnInterfaces.getInterfaces()) {
+                        // 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 (!isOperational(ifInfo)) {
+                            continue;
+                        }
+
+                        remoteListBucket.add(MDSALUtil.buildBucket(getInterfacePortActions(ifInfo), MDSALUtil.GROUP_WEIGHT, bucketId, MDSALUtil.WATCH_PORT, MDSALUtil.WATCH_GROUP));
+                        bucketId++;
+                    }
                     try {
                         List<Action> remoteListActionInfo = ElanUtils.getItmEgressAction(interfaceInfo.getDpId(), dstDpId, (int) elanTag);
                         remoteListBucket.add(MDSALUtil.buildBucket(remoteListActionInfo, MDSALUtil.GROUP_WEIGHT, bucketId, MDSALUtil.WATCH_PORT, MDSALUtil.WATCH_GROUP));
@@ -575,9 +587,6 @@ public class ElanInterfaceManager extends AbstractDataChangeListener<ElanInterfa
                         logger.error( "Logical Group Interface not found between source Dpn - {}, destination Dpn - {} " ,dpnInterface.getDpId(), dstDpId);
                         return;
                     }
-                    List<Action> remoteListActionInfo = new ArrayList<Action>();
-                    remoteListActionInfo.add(new ActionInfo(ActionType.group, new String[] {String.valueOf(ElanUtils.getElanLocalBCGID(elanTag))}).buildAction());
-                    remoteListBucket.add(MDSALUtil.buildBucket(remoteListActionInfo, MDSALUtil.GROUP_WEIGHT, bucketId, MDSALUtil.WATCH_PORT, MDSALUtil.WATCH_GROUP));
                     Group group = MDSALUtil.buildGroup(groupId, elanInfo.getElanInstanceName(), GroupTypes.GroupAll, MDSALUtil.buildBucketLists(remoteListBucket));
                     mdsalManager.syncInstallGroup(interfaceInfo.getDpId(), group, ElanConstants.DELAY_TIME_IN_MILLISECOND);
                     break;
@@ -687,7 +696,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 (!isOperational(ifInfo)) {
+            if (ifInfo == null || !isOperational(ifInfo)) {
                 continue;
             }
 
@@ -699,7 +708,13 @@ public class ElanInterfaceManager extends AbstractDataChangeListener<ElanInterfa
 
         Group group = MDSALUtil.buildGroup(groupId, elanInfo.getElanInstanceName(), GroupTypes.GroupAll, MDSALUtil.buildBucketLists(listBucket));
         logger.trace("installing the localBroadCast Group:{}", group);
-        mdsalManager.syncInstallGroup(dpnId, group, ElanConstants.DELAY_TIME_IN_MILLISECOND);
+        // In the case of OVS disconnected we receive null object when we query Interface Operation datastore
+        // so the size of the bucket will be zero
+        if(listBucket.size() == 0) {
+            mdsalManager.syncRemoveGroup(dpnId, group);
+        } else {
+            mdsalManager.syncInstallGroup(dpnId, group, ElanConstants.DELAY_TIME_IN_MILLISECOND);
+        }
     }
 
     public void setupLocalBroadcastGroups(ElanInstance elanInfo, InterfaceInfo interfaceInfo) {
@@ -713,7 +728,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 (!isOperational(ifInfo)) {
+            if (ifInfo == null || !isOperational(ifInfo)) {
                 continue;
             }
 
@@ -721,9 +736,16 @@ public class ElanInterfaceManager extends AbstractDataChangeListener<ElanInterfa
             bucketId++;
         }
 
+
         Group group = MDSALUtil.buildGroup(groupId, elanInfo.getElanInstanceName(), GroupTypes.GroupAll, MDSALUtil.buildBucketLists(listBucket));
         logger.trace("installing the localBroadCast Group:{}", group);
-        mdsalManager.syncInstallGroup(dpnId, group, ElanConstants.DELAY_TIME_IN_MILLISECOND);
+        // In the case of OVS disconnected we receive null object for the Interface Operation datastore
+        // so the size of the bucket will be zero
+        if(listBucket.size() == 0) {
+            mdsalManager.syncRemoveGroup(dpnId, group);
+        } else {
+            mdsalManager.syncInstallGroup(dpnId, group, ElanConstants.DELAY_TIME_IN_MILLISECOND);
+        }
     }
 
     public void removeLocalBroadcastGroup(ElanInstance elanInfo, InterfaceInfo interfaceInfo) {
index d056d1ae05fc2b2c47b3f0978ae11395a56f6180..58f0aea28b3c3553ed008fe2b6888a46445ee3af 100644 (file)
@@ -14,23 +14,26 @@ import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.vpnservice.elan.utils.ElanUtils;
-import org.opendaylight.vpnservice.interfacemgr.IfmUtil;
 import org.opendaylight.vpnservice.interfacemgr.globals.InterfaceInfo;
 import org.opendaylight.vpnservice.interfacemgr.interfaces.IInterfaceManager;
 import org.opendaylight.vpnservice.mdsalutil.AbstractDataChangeListener;
 import org.opendaylight.vpnservice.mdsalutil.MDSALUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.L2vlan;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.Tunnel;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.elan.rev150602.elan.instances.ElanInstance;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.elan.rev150602.elan.interfaces.ElanInterface;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.TunnelList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnel;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.math.BigInteger;
+import java.util.List;
 
 public class ElanInterfaceStateChangeListener extends AbstractDataChangeListener<Interface> implements AutoCloseable {
     private DataBroker broker;
@@ -90,6 +93,7 @@ public class ElanInterfaceStateChangeListener extends AbstractDataChangeListener
         BigInteger dpId = MDSALUtil.getDpnIdFromNodeName(nodeConnectorId.getValue());
         InterfaceInfo interfaceInfo = new InterfaceInfo(dpId, nodeConnectorId.getValue());
         interfaceInfo.setInterfaceName(interfaceName);
+        interfaceInfo.setInterfaceType(InterfaceInfo.InterfaceType.VLAN_INTERFACE);
         interfaceInfo.setInterfaceTag(delIf.getIfIndex());
         elanInterfaceManager.removeElanService(elanInterface, interfaceInfo);
     }
@@ -98,21 +102,27 @@ public class ElanInterfaceStateChangeListener extends AbstractDataChangeListener
     protected void update(InstanceIdentifier<Interface> identifier, Interface original, Interface update) {
         logger.trace("Operation Interface update event - Old: {}, New: {}", original, update);
         String interfaceName = update.getName();
-        ElanInterface elanInterface = ElanUtils.getElanInterfaceByElanInterfaceName(interfaceName);
-        if(elanInterface == null) {
-            logger.debug("No Elan Interface is created for the interface:{} ", interfaceName);
-            return;
-        }
-        Optional<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface>
-        intf = ElanUtils.read(broker, LogicalDatastoreType.CONFIGURATION, IfmUtil.buildId(interfaceName));
-        if (intf != null && intf.get().getType().equals(Tunnel.class)) {
-            if(update.getOperStatus().equals(Interface.OperStatus.Up) && update.getAdminStatus() == Interface.AdminStatus.Up) {
+        if(update.getType().equals(Tunnel.class)) {
+            if (update.getOperStatus().equals(Interface.OperStatus.Up)) {
+                InternalTunnel internalTunnel = getTunnelState(interfaceName);
+                if (internalTunnel != null) {
+                    elanInterfaceManager.handleTunnelStateEvent(internalTunnel.getSourceDPN(), internalTunnel.getDestinationDPN());
+                }
+            }
+        } else if(update.getType().equals(L2vlan.class)) {
+            ElanInterface elanInterface = ElanUtils.getElanInterfaceByElanInterfaceName(interfaceName);
+            if(elanInterface == null) {
+                logger.debug("No Elan Interface is created for the interface:{} ", interfaceName);
+                return;
+            }
+            if (update.getOperStatus().equals(Interface.OperStatus.Up) && update.getAdminStatus() == Interface.AdminStatus.Up) {
                 logger.trace("Operation Status for Interface:{}  event state UP ", interfaceName);
                 handleVlanInterfaceOperationalStateChange(interfaceName, true);
-            } else if(update.getOperStatus().equals(Interface.OperStatus.Down)) {
+            } else if (update.getOperStatus().equals(Interface.OperStatus.Down)) {
                 logger.trace("Operation Status for Interface:{}  event state DOWN ", interfaceName);
                 handleVlanInterfaceOperationalStateChange(interfaceName, false);
             }
+
         }
     }
 
@@ -122,7 +132,14 @@ public class ElanInterfaceStateChangeListener extends AbstractDataChangeListener
         String interfaceName =  intrf.getName();
         ElanInterface elanInterface = ElanUtils.getElanInterfaceByElanInterfaceName(interfaceName);
         if(elanInterface == null) {
-            logger.debug("No Elan Interface is created for the interface:{} ", interfaceName);
+            if (intrf.getType() != null && intrf.getType().equals(Tunnel.class)) {
+                if(intrf.getOperStatus().equals(Interface.OperStatus.Up)) {
+                    InternalTunnel internalTunnel = getTunnelState(interfaceName);
+                    if (internalTunnel != null) {
+                        elanInterfaceManager.handleTunnelStateEvent(internalTunnel.getSourceDPN(), internalTunnel.getDestinationDPN());
+                    }
+                }
+            }
             return;
         }
         InstanceIdentifier<ElanInterface> elanInterfaceId = ElanUtils.getElanInterfaceConfigurationDataPathId(interfaceName);
@@ -133,4 +150,19 @@ public class ElanInterfaceStateChangeListener extends AbstractDataChangeListener
     public void close() throws Exception {
 
     }
+
+    public  InternalTunnel getTunnelState(String interfaceName) {
+        InternalTunnel internalTunnel = null;
+        TunnelList tunnelList = ElanUtils.buildInternalTunnel(broker);
+        if (tunnelList.getInternalTunnel() != null) {
+            List<InternalTunnel> internalTunnels = tunnelList.getInternalTunnel();
+            for (InternalTunnel tunnel : internalTunnels) {
+                if (internalTunnel.getTunnelInterfaceName().equalsIgnoreCase(interfaceName)) {
+                    internalTunnel = tunnel;
+                    break;
+                }
+            }
+        }
+        return internalTunnel;
+    }
 }
index 96ad2c80e231bf92d6217467591d58e299ef98b2..10d4df2b79fae955f1ccb44910ffb284464149d2 100644 (file)
@@ -76,6 +76,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rpc
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rpcs.rev151003.GetEgressActionsInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rpcs.rev151003.GetEgressActionsOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rpcs.rev151003.OdlInterfaceRpcService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.TunnelList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.CreateTerminatingServiceActionsInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.CreateTerminatingServiceActionsInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.GetTunnelInterfaceNameInput;
@@ -835,4 +836,13 @@ public class ElanUtils {
 
         itmRpcService.createTerminatingServiceActions(input);
     }
+
+    public static TunnelList buildInternalTunnel(DataBroker dataBroker) {
+        InstanceIdentifier<TunnelList> tunnelListInstanceIdentifier = InstanceIdentifier.builder(TunnelList.class).build();
+        Optional<TunnelList> tunnelList = read(dataBroker, LogicalDatastoreType.CONFIGURATION, tunnelListInstanceIdentifier);
+        if(tunnelList.isPresent()) {
+            return tunnelList.get();
+        }
+        return null;
+    }
 }