ONOS-4401 VPLS: react to intf config changes.

Change-Id: Id34a9de669a3ab571e690b27072b44057d863768
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/Vpls.java b/apps/vpls/src/main/java/org/onosproject/vpls/Vpls.java
index ebf0750..4898f91 100644
--- a/apps/vpls/src/main/java/org/onosproject/vpls/Vpls.java
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/Vpls.java
@@ -28,6 +28,8 @@
 import org.onosproject.app.ApplicationService;
 import org.onosproject.core.ApplicationId;
 import org.onosproject.core.CoreService;
+import org.onosproject.incubator.net.intf.InterfaceEvent;
+import org.onosproject.incubator.net.intf.InterfaceListener;
 import org.onosproject.incubator.net.intf.InterfaceService;
 import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.Host;
@@ -75,6 +77,9 @@
 
     private final HostListener hostListener = new InternalHostListener();
 
+    private final InternalInterfaceListener interfaceListener
+            = new InternalInterfaceListener();
+
     private IntentInstaller intentInstaller;
 
     private ApplicationId appId;
@@ -91,6 +96,7 @@
                                                   intentSynchronizerAdmin::removeIntents);
 
         hostService.addListener(hostListener);
+        interfaceService.addListener(interfaceListener);
 
         setupConnectivity();
 
@@ -200,4 +206,23 @@
             }
         }
     }
+
+    /**
+     * Listener for interface configuration events.
+     */
+    private class InternalInterfaceListener implements InterfaceListener {
+        @Override
+        public void event(InterfaceEvent event) {
+            log.debug("Received InterfaceConfigEvent {}", event);
+            switch (event.type()) {
+                case INTERFACE_ADDED:
+                case INTERFACE_UPDATED:
+                case INTERFACE_REMOVED:
+                    setupConnectivity();
+                    break;
+                default:
+                    break;
+            }
+        }
+    }
 }
diff --git a/apps/vpls/src/test/java/org/onosproject/vpls/VplsTest.java b/apps/vpls/src/test/java/org/onosproject/vpls/VplsTest.java
index e8715dc..18d1d03 100644
--- a/apps/vpls/src/test/java/org/onosproject/vpls/VplsTest.java
+++ b/apps/vpls/src/test/java/org/onosproject/vpls/VplsTest.java
@@ -28,6 +28,7 @@
 import org.onosproject.core.CoreService;
 import org.onosproject.core.IdGenerator;
 import org.onosproject.incubator.net.intf.Interface;
+import org.onosproject.incubator.net.intf.InterfaceListener;
 import org.onosproject.incubator.net.intf.InterfaceService;
 import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.DefaultHost;
@@ -57,16 +58,14 @@
 
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.stream.Collectors;
 
 import static java.lang.String.format;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.*;
+import static org.easymock.EasyMock.expectLastCall;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
@@ -157,6 +156,8 @@
                 new TestIntentSynchronizer(intentService);
 
         interfaceService = createMock(InterfaceService.class);
+        interfaceService.addListener(anyObject(InterfaceListener.class));
+        expectLastCall().anyTimes();
         addIntfConfig();
 
         vpls = new Vpls();
@@ -177,21 +178,24 @@
      */
     private void addIntfConfig() {
         Set<Interface> interfaces = Sets.newHashSet();
-        Set<Interface> vlanOneSet = new HashSet<>();
-        Set<Interface> vlanTwoSet = new HashSet<>();
+        Set<Interface> vlanOneSet = Sets.newHashSet();
+        Set<Interface> vlanTwoSet = Sets.newHashSet();
 
         for (int i = 1; i <= NUM_DEVICES - 1; i++) {
             ConnectPoint cp = new ConnectPoint(getDeviceId(i), P1);
 
             Interface intf =
-                    new Interface(cp, Collections.emptySet(), null, VlanId.NONE);
+                    new Interface("intfOne", cp, Collections.emptyList(), null,
+                                  VlanId.NONE);
 
             if (i <= 3) {
-                intf = new Interface(cp, Collections.emptySet(), null, VLAN1);
+                intf = new Interface("intfTwo", cp, Collections.emptyList(),
+                                     null, VLAN1);
                 interfaces.add(intf);
                 vlanOneSet.add(intf);
             } else if (i > 3 && i <= 6) {
-                intf = new Interface(cp, Collections.emptySet(), null, VLAN2);
+                intf = new Interface("intfThree", cp, Collections.emptyList(),
+                                     null, VLAN2);
                 interfaces.add(intf);
                 vlanTwoSet.add(intf);
             }