Handling port up down event for Bug 3558 71/22171/1
authorSasidharan Sambasivam <sasidharan.s.sambasivam@ericsson.com>
Thu, 4 Jun 2015 10:15:34 +0000 (15:45 +0530)
committerSasidharan Sambasivam <sasidharan.s.sambasivam@ericsson.com>
Tue, 9 Jun 2015 09:33:19 +0000 (09:33 +0000)
Change-Id: Ic76ec245aca3d0557a62ec88b6ae17585b3e81fb
Signed-off-by: Sasidharan Sambasivam <sasidharan.s.sambasivam@ericsson.com>
(cherry picked from commit 6284a153d3f187e71892b4bd472a654051b0df5f)

interfacemgr/interfacemgr-api/src/main/java/org/opendaylight/vpnservice/interfacemgr/interfaces/IInterfaceManager.java
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/IfmUtil.java
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/InterfaceManager.java
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/InterfacemgrProvider.java
mdsalutil/mdsalutil-impl/src/main/java/org/opendaylight/vpnservice/mdsalutil/internal/MDSALManager.java
nexthopmgr/nexthopmgr-impl/src/main/java/org/opendaylight/vpnservice/nexthopmgr/NexthopManager.java
vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/vpnservice/InterfaceChangeListener.java [new file with mode: 0644]
vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/vpnservice/VpnInterfaceManager.java
vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/vpnservice/VpnUtil.java
vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/vpnservice/VpnserviceProvider.java

index 0923c9345aa4f1cddb3a040277585927cd8f2a93..8ef4efdb474a82d5f24e019faf2466201d0d0ae8 100644 (file)
@@ -23,5 +23,6 @@ public interface IInterfaceManager {
     public String getEndpointIpForDpn(BigInteger dpnId);
     public List<MatchInfo> getInterfaceIngressRule(String ifName);
     public List<ActionInfo> getInterfaceEgressActions(String ifName);
+    public Long getPortForInterface(Interface intf);
 
 }
\ No newline at end of file
index c36df7f34d96e5246aff4e72de63c0c75a7d51d5..a347d9a185df69ce7f9722eeca01f387b074f2d2 100644 (file)
@@ -31,6 +31,13 @@ public class IfmUtil {
         return split[1];
     }
 
+    public static String getPortNoFromNodeConnectorId(NodeConnectorId portId) {
+        /*
+         * NodeConnectorId is of form 'openflow:dpnid:portnum'
+         */
+        String[] split = portId.getValue().split(IfmConstants.OF_URI_SEPARATOR);
+        return split[2];
+    }
 
     public static NodeId buildDpnNodeId(BigInteger dpnId) {
         return new NodeId(IfmConstants.OF_URI_PREFIX + dpnId);
index 1543b57a621d66ef426ca1a543a41206f2317bf7..84d4350acbb47d840e5430473c2c06cfc8b148d2 100644 (file)
@@ -434,12 +434,34 @@ public class InterfaceManager extends AbstractDataChangeListener<Interface> impl
         return getPortNumForInterface(iface);
     }
 
+    Long getPortForInterface(Interface intrf) {
+        try {
+            NodeConnector port = getNodeConnectorFromDataStore(intrf);
+            NodeConnectorId id = null;
+            if(port == null) {
+                id = getNodeConnectorIdFromInterface(intrf);
+            } else {
+                id = port.getId();
+            }
+            String portNo = IfmUtil.getPortNoFromNodeConnectorId(id);
+            return Long.parseLong(portNo);
+        } catch (NullPointerException e) {
+            LOG.error("Port for Interface {} not found", intrf.getName(), e);
+        }
+        return 0L;
+    }
 
     public BigInteger getDpnForInterface(Interface intrf) {
         try {
             NodeConnector port = getNodeConnectorFromDataStore(intrf);
+            NodeConnectorId id = null;
+            if(port == null) {
+                id = getNodeConnectorIdFromInterface(intrf);
+            } else {
+                id = port.getId();
+            }
             //TODO: This should be an MDSAL Util method
-            return new BigInteger(IfmUtil.getDpnFromNodeConnectorId(port.getId()));
+            return new BigInteger(IfmUtil.getDpnFromNodeConnectorId(id));
         } catch (NullPointerException e) {
             LOG.error("dpn for Interface {} not found", intrf.getName(), e);
         }
index c8166a7a2774fc721066e501d80939b50a1fb84c..74074883aad0f659bd67d11d0cda1552861ae1f5 100644 (file)
@@ -77,6 +77,12 @@ public class InterfacemgrProvider implements BindingAwareProvider, AutoCloseable
         return interfaceManager.getPortForInterface(ifName);
     }
 
+    @Override
+    public Long getPortForInterface(Interface intf) {
+        return interfaceManager.getPortForInterface(intf);
+    }
+
+
     @Override
     public BigInteger getDpnForInterface(String ifName) {
         return interfaceManager.getDpnForInterface(ifName);
index fc9a5ff782b1544905175c0da2861be0ab5c114a..5ca603cab20c0536699c4986291dc60a3b3bb7c0 100644 (file)
@@ -172,6 +172,7 @@ public class MDSALManager implements AutoCloseable {
 
     public void removeFlow(FlowEntity flowEntity) {
         try {
+            s_logger.debug("Remove flow {}",flowEntity);
             Node nodeDpn = buildDpnNode(flowEntity.getDpnId());
             FlowKey flowKey = new FlowKey(new FlowId(flowEntity.getFlowId()));
             InstanceIdentifier<Flow> flowInstanceId = InstanceIdentifier.builder(Nodes.class)
index 052ed98f4e3998d82ad45f8325a82f1a2f4c8d1e..1543a81947a6de5e16e3f9a4d42d4a5d02fdbda4 100644 (file)
@@ -210,7 +210,7 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
             GroupEntity groupEntity = MDSALUtil.buildGroupEntity(
                 dpnId, groupId, ipAddress, GroupTypes.GroupIndirect, listBucketInfo);
             mdsalManager.installGroup(groupEntity);
-            makeRemoteFlow(dpnId, ifName, NwConstants.ADD_FLOW);
+            //makeRemoteFlow(dpnId, ifName, NwConstants.ADD_FLOW);
 
             //update MD-SAL DS
             addTunnelNexthopToDS(dpnId, ipAddress, groupId);
@@ -399,7 +399,7 @@ public class NexthopManager implements L3nexthopService, AutoCloseable {
                     dpnId, nh.getEgressPointer(), ipAddress, GroupTypes.GroupIndirect, null);
             // remove Group ...
             mdsalManager.removeGroup(groupEntity);
-            makeRemoteFlow(dpnId, ifName, NwConstants.DEL_FLOW);
+            //makeRemoteFlow(dpnId, ifName, NwConstants.DEL_FLOW);
             //update MD-SAL DS
             removeTunnelNexthopFromDS(dpnId, ipAddress);
         } else {
diff --git a/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/vpnservice/InterfaceChangeListener.java b/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/vpnservice/InterfaceChangeListener.java
new file mode 100644 (file)
index 0000000..7e05414
--- /dev/null
@@ -0,0 +1,82 @@
+package org.opendaylight.vpnservice;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.vpnservice.interfacemgr.interfaces.IInterfaceManager;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class InterfaceChangeListener extends AbstractDataChangeListener<Interface> implements AutoCloseable {
+    private static final Logger LOG = LoggerFactory.getLogger(InterfaceChangeListener.class);
+
+    private ListenerRegistration<DataChangeListener> listenerRegistration;
+    private final DataBroker broker;
+    private VpnInterfaceManager vpnInterfaceManager;
+
+
+    public InterfaceChangeListener(final DataBroker db, VpnInterfaceManager vpnInterfaceManager) {
+        super(Interface.class);
+        broker = db;
+        this.vpnInterfaceManager = vpnInterfaceManager;
+        registerListener(db);
+    }
+
+    @Override
+    public void close() throws Exception {
+        if (listenerRegistration != null) {
+            try {
+                listenerRegistration.close();
+            } catch (final Exception e) {
+                LOG.error("Error when cleaning up DataChangeListener.", e);
+            }
+            listenerRegistration = null;
+        }
+        LOG.info("Interface listener Closed");
+    }
+
+
+    private void registerListener(final DataBroker db) {
+        try {
+            listenerRegistration = db.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
+                    getWildCardPath(), InterfaceChangeListener.this, DataChangeScope.SUBTREE);
+        } catch (final Exception e) {
+            LOG.error("Interface DataChange listener registration failed", e);
+            throw new IllegalStateException("Nexthop Manager registration Listener failed.", e);
+        }
+    }
+
+    @Override
+    protected void add(InstanceIdentifier<Interface> identifier, Interface intrf) {
+        LOG.trace("Adding Interface : key: " + identifier + ", value=" + intrf );
+
+    }
+
+
+    private InstanceIdentifier<Interface> getWildCardPath() {
+        return InstanceIdentifier.create(Interfaces.class).child(Interface.class);
+    }
+
+    @Override
+    protected void remove(InstanceIdentifier<Interface> identifier, Interface intrf) {
+        LOG.trace("Remove interface event - key: {}, value: {}", identifier, intrf );
+        VpnInterface vpnInterface = vpnInterfaceManager.getVpnInterface(intrf.getName());
+        InstanceIdentifier<VpnInterface> id = VpnUtil.getVpnInterfaceIdentifier(intrf.getName());
+        LOG.debug("Removing VPN Interface associated with Interface {}", intrf.getName());
+        vpnInterfaceManager.remove(id, vpnInterface);
+    }
+
+    @Override
+    protected void update(InstanceIdentifier<Interface> identifier,
+            Interface original, Interface update) {
+        // TODO Auto-generated method stub
+
+    }
+
+}
index e2101882f1fe4fef0d528c6ee177a23e03b78853..92f990df978d7fbac1426f7256ebcd56f9c4b7d2 100644 (file)
@@ -35,6 +35,7 @@ import org.opendaylight.vpnservice.mdsalutil.MDSALUtil;
 import org.opendaylight.vpnservice.mdsalutil.MatchFieldType;
 import org.opendaylight.vpnservice.mdsalutil.MatchInfo;
 import org.opendaylight.vpnservice.mdsalutil.MetaDataUtil;
+import org.opendaylight.vpnservice.mdsalutil.NwConstants;
 import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.DataObject;
@@ -46,8 +47,10 @@ import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
+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.Interface;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.AdjacencyList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.adjacency.list.Adjacency;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.adjacency.list.AdjacencyBuilder;
@@ -71,7 +74,7 @@ import org.slf4j.LoggerFactory;
 
 public class VpnInterfaceManager extends AbstractDataChangeListener<VpnInterface> implements AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(VpnInterfaceManager.class);
-    private ListenerRegistration<DataChangeListener> listenerRegistration;
+    private ListenerRegistration<DataChangeListener> listenerRegistration, interfaceListenerRegistration;
     private final DataBroker broker;
     private final IBgpManager bgpManager;
     private IFibManager fibManager;
@@ -80,6 +83,7 @@ public class VpnInterfaceManager extends AbstractDataChangeListener<VpnInterface
     private IdManagerService idManager;
     private Map<Long, Collection<BigInteger>> vpnToDpnsDb;
     private Map<BigInteger, Collection<String>> dpnToInterfaceDb;
+    private InterfaceListener interfaceListener;
 
     private static final FutureCallback<Void> DEFAULT_CALLBACK =
             new FutureCallback<Void>() {
@@ -104,6 +108,7 @@ public class VpnInterfaceManager extends AbstractDataChangeListener<VpnInterface
         this.bgpManager = bgpManager;
         vpnToDpnsDb = new ConcurrentHashMap<>();
         dpnToInterfaceDb = new ConcurrentHashMap<>();
+        interfaceListener = new InterfaceListener();
         registerListener(db);
     }
 
@@ -128,10 +133,12 @@ public class VpnInterfaceManager extends AbstractDataChangeListener<VpnInterface
         if (listenerRegistration != null) {
             try {
                 listenerRegistration.close();
+                interfaceListenerRegistration.close();
             } catch (final Exception e) {
                 LOG.error("Error when cleaning up DataChangeListener.", e);
             }
             listenerRegistration = null;
+            interfaceListenerRegistration = null;
         }
         LOG.info("VPN Interface Manager Closed");
     }
@@ -140,12 +147,19 @@ public class VpnInterfaceManager extends AbstractDataChangeListener<VpnInterface
         try {
             listenerRegistration = db.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
                     getWildCardPath(), VpnInterfaceManager.this, DataChangeScope.SUBTREE);
+            interfaceListenerRegistration = db.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
+                    getInterfaceListenerPath(), interfaceListener, DataChangeScope.SUBTREE);
         } catch (final Exception e) {
             LOG.error("VPN Service DataChange listener registration fail!", e);
             throw new IllegalStateException("VPN Service registration Listener failed.", e);
         }
     }
 
+    private InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> getInterfaceListenerPath() {
+        return InstanceIdentifier.create(InterfacesState.class)
+        .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.class);
+    }
+
     @Override
     protected void add(final InstanceIdentifier<VpnInterface> identifier,
             final VpnInterface vpnInterface) {
@@ -407,16 +421,17 @@ public class VpnInterfaceManager extends AbstractDataChangeListener<VpnInterface
         LOG.trace("Unbind service on interface {} for VPN: {}", intf, vpnName);
 
         long vpnId = getVpnId(vpnName);
-        BigInteger dpId = interfaceManager.getDpnForInterface(intf.getName());
+        BigInteger dpId = interfaceManager.getDpnForInterface(intf);
         if(dpId.equals(BigInteger.ZERO)) {
             LOG.warn("DPN for interface {} not found. Unbind service on this interface aborted.", intf.getName());
             return;
         } else {
             String rd = getRouteDistinguisher(vpnName);
             remoteFromMappingDbs(vpnId, dpId, intf.getName(), rd);
+            LOG.debug("removed vpn mapping for interface {} from VPN RD {}", intf.getName(), rd);
         }
 
-        long portNo = interfaceManager.getPortForInterface(intf.getName());
+        long portNo = interfaceManager.getPortForInterface(intf);
         String flowRef = getVpnInterfaceFlowRef(dpId, VpnConstants.LPORT_INGRESS_TABLE, vpnId, portNo);
 
         String flowName = intf.getName();
@@ -429,6 +444,7 @@ public class VpnInterfaceManager extends AbstractDataChangeListener<VpnInterface
 
         FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, VpnConstants.LPORT_INGRESS_TABLE, flowRef,
                           priority, flowName, 0, 0, null, matches, null);
+        LOG.debug("Remove ingress flow for port {} in dpn {}", portNo, dpId.intValue());
 
         mdsalManager.removeFlow(flowEntity);
     }
@@ -481,8 +497,9 @@ public class VpnInterfaceManager extends AbstractDataChangeListener<VpnInterface
                         label = getUniqueId(nextHop.getIpAddress());
                     }
                     removePrefixFromBGP(rd, nextHop);
-                    updatePrefixToBGP(newRd, nextHop, nextHopIp, label);
+                    //updatePrefixToBGP(newRd, nextHop, nextHopIp, label);
                 }
+                updateNextHops(identifier, update);
                 asyncUpdate(LogicalDatastoreType.OPERATIONAL, identifier, update, DEFAULT_CALLBACK);
             }
         } else {
@@ -519,4 +536,126 @@ public class VpnInterfaceManager extends AbstractDataChangeListener<VpnInterface
             return Collections.emptyList();
         }
     }
+
+    VpnInterface getVpnInterface(String interfaceName) {
+        Optional<VpnInterfaces> optVpnInterfaces = read(LogicalDatastoreType.CONFIGURATION, VpnUtil.getVpnInterfacesIdentifier());
+        if(optVpnInterfaces.isPresent()) {
+            List<VpnInterface> interfaces = optVpnInterfaces.get().getVpnInterface();
+            for(VpnInterface intf : interfaces) {
+                if(intf.getName().equals(interfaceName)) {
+                    return intf;
+                }
+            }
+        }
+        return null;
+    }
+
+    private Interface getInterface(String interfaceName) {
+        Optional<Interface> optInterface = read(LogicalDatastoreType.CONFIGURATION, VpnUtil.getInterfaceIdentifier(interfaceName));
+        if(optInterface.isPresent()) {
+            return optInterface.get();
+        }
+        return null;
+    }
+
+    private String getTunnelInterfaceFlowRef(BigInteger dpnId, short tableId, String ifName) {
+        return new StringBuilder().append(dpnId).append(tableId).append(ifName).toString();
+    }
+
+
+    private void makeTunnelIngressFlow(BigInteger dpnId, String ifName, int addOrRemoveFlow) {
+        long portNo = 0;
+        String flowName = ifName;
+        String flowRef = getTunnelInterfaceFlowRef(dpnId, VpnConstants.LPORT_INGRESS_TABLE, ifName);
+        List<MatchInfo> matches = new ArrayList<MatchInfo>();
+        List<InstructionInfo> mkInstructions = new ArrayList<InstructionInfo>();
+        if (NwConstants.ADD_FLOW == addOrRemoveFlow) {
+            portNo = interfaceManager.getPortForInterface(ifName);
+            matches.add(new MatchInfo(MatchFieldType.in_port, new BigInteger[] {
+                dpnId, BigInteger.valueOf(portNo) }));
+            mkInstructions.add(new InstructionInfo(InstructionType.goto_table, new long[] {VpnConstants.LFIB_TABLE}));
+        }
+
+        BigInteger COOKIE_VM_INGRESS_TABLE = new BigInteger("8000001", 16);
+        FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpnId, VpnConstants.LPORT_INGRESS_TABLE, flowRef,
+                VpnConstants.DEFAULT_FLOW_PRIORITY, flowName, 0, 0, COOKIE_VM_INGRESS_TABLE, matches, mkInstructions);
+
+        if (NwConstants.ADD_FLOW == addOrRemoveFlow) {
+            mdsalManager.installFlow(flowEntity);
+        } else {
+            mdsalManager.removeFlow(flowEntity);
+        }
+    }
+
+    private class InterfaceListener extends AbstractDataChangeListener<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface>  {
+
+        public InterfaceListener() {
+            super(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.class);
+        }
+
+        @Override
+        protected void remove(InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> identifier,
+                org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface del) {
+            LOG.trace("Operational Interface remove event - {}", del);
+        }
+
+        @Override
+        protected void update(InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> identifier,
+                org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface original, 
+                org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface update) {
+            LOG.trace("Operation Interface update event - Old: {}, New: {}", original, update);
+            String interfaceName = update.getName();
+            Interface intf = getInterface(interfaceName);
+            if (intf != null && intf.getType().equals(L3tunnel.class)) {
+                BigInteger dpnId = interfaceManager.getDpnForInterface(interfaceName);
+                if(update.getOperStatus().equals(OperStatus.Up)) {
+                    //Create ingress to LFIB
+                    LOG.debug("Installing Ingress for tunnel interface {}", interfaceName);
+                    makeTunnelIngressFlow(dpnId, interfaceName, NwConstants.ADD_FLOW);
+                } else if(update.getOperStatus().equals(OperStatus.Down)) {
+                    LOG.debug("Removing Ingress flow for tunnel interface {}", interfaceName);
+                    makeTunnelIngressFlow(dpnId, interfaceName, NwConstants.DEL_FLOW);
+                }
+            } else {
+                VpnInterface vpnInterface = getVpnInterface(interfaceName);
+                if(vpnInterface != null) {
+                    if(update.getOperStatus().equals(OperStatus.Up)) {
+                        LOG.debug("Installing VPN related rules for interface {}", interfaceName);
+                        addInterface(VpnUtil.getVpnInterfaceIdentifier(vpnInterface.getName()), vpnInterface);
+                    } else if(update.getOperStatus().equals(OperStatus.Down)) {
+                        LOG.debug("Removing VPN related rules for interface {}", interfaceName);
+                        VpnInterfaceManager.this.remove(VpnUtil.getVpnInterfaceIdentifier(vpnInterface.getName()), vpnInterface);
+                    }
+                } else {
+                    LOG.debug("No VPN Interface associated with interface {} to handle Update Operation", interfaceName);
+                }
+            }
+        }
+
+        @Override
+        protected void add(InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> identifier,
+                org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface add) {
+            LOG.trace("Operational Interface add event - {}", add);
+            String interfaceName = add.getName();
+            Interface intf = getInterface(interfaceName);
+            if (intf != null && intf.getType().equals(L3tunnel.class)) {
+                BigInteger dpnId = interfaceManager.getDpnForInterface(interfaceName);
+                if(add.getOperStatus().equals(OperStatus.Up)) {
+                    //Create ingress to LFIB
+                    LOG.debug("Installing Ingress for tunnel interface {}", interfaceName);
+                    makeTunnelIngressFlow(dpnId, interfaceName, NwConstants.ADD_FLOW);
+                }
+            } else {
+                VpnInterface vpnInterface = getVpnInterface(interfaceName);
+                if(vpnInterface != null) {
+                    if(add.getOperStatus().equals(OperStatus.Up)) {
+                        LOG.debug("Installing VPN related rules for interface {}", interfaceName);
+                        addInterface(VpnUtil.getVpnInterfaceIdentifier(vpnInterface.getName()), vpnInterface);
+                    }
+                } else {
+                    LOG.debug("No VPN Interface associated with interface {} to handle add Operation", interfaceName);
+                }
+            }
+        }
+    }
 }
index fe87901381c713c28b7c7fe990ad2ec7330ac7fe..9befc1fa5bcbfed7dffaf3df82342313ca4e7f37 100644 (file)
@@ -19,6 +19,9 @@ import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev14081
 import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface;
 import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceKey;
 import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.adjacency.list.Adjacency;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.Adjacencies;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.AdjacenciesBuilder;
@@ -54,4 +57,13 @@ public class VpnUtil {
         InstanceIdentifier<IdPool> id = idBuilder.build();
         return id;
     }
+
+    static InstanceIdentifier<VpnInterfaces> getVpnInterfacesIdentifier() {
+        return InstanceIdentifier.builder(VpnInterfaces.class).build();
+    }
+
+    static InstanceIdentifier<Interface> getInterfaceIdentifier(String interfaceName) {
+        return InstanceIdentifier.builder(Interfaces.class)
+                .child(Interface.class, new InterfaceKey(interfaceName)).build();
+    }
 }
index a5198ba74d77f56b2a02b0e2d47054315aa79de4..ab1666228ccc5014ad9ebf40db5ecac3429af8d3 100644 (file)
@@ -39,6 +39,7 @@ public class VpnserviceProvider implements BindingAwareProvider, IVpnManager,
     private IMdsalApiManager mdsalManager;
     private IInterfaceManager interfaceManager;
     private IdManagerService idManager;
+    private InterfaceChangeListener interfaceListener;
 
     @Override
     public void onSessionInitiated(ProviderContext session) {
@@ -52,6 +53,7 @@ public class VpnserviceProvider implements BindingAwareProvider, IVpnManager,
             vpnInterfaceManager.setInterfaceManager(interfaceManager);
             vpnInterfaceManager.setIdManager(idManager);
             vpnManager.setVpnInterfaceManager(vpnInterfaceManager);
+            interfaceListener = new InterfaceChangeListener(dataBroker, vpnInterfaceManager);
             createIdPool();
         } catch (Exception e) {
             LOG.error("Error initializing services", e);
@@ -99,6 +101,7 @@ public class VpnserviceProvider implements BindingAwareProvider, IVpnManager,
     public void close() throws Exception {
         vpnManager.close();
         vpnInterfaceManager.close();
+        interfaceListener.close();
     }
 
     @Override