[ONOS-5420] CP/untagged ifaces support in VPLS

Changes:
- Tests to account for tag-tag and tag-notag connectivity
- Introducing untagged ifaces in netcfg and topo files

Change-Id: If56fd4d8bbe4f1f2505e4d5d85c3eeda8c22ac5c
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/config/VplsAppConfig.java b/apps/vpls/src/main/java/org/onosproject/vpls/config/VplsAppConfig.java
index 398962e..66f7882 100644
--- a/apps/vpls/src/main/java/org/onosproject/vpls/config/VplsAppConfig.java
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/config/VplsAppConfig.java
@@ -23,8 +23,6 @@
 import org.onosproject.core.ApplicationId;
 import org.onosproject.net.EncapsulationType;
 import org.onosproject.net.config.Config;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import java.util.Set;
 
@@ -37,8 +35,6 @@
     private static final String INTERFACE = "interfaces";
     private static final String ENCAPSULATION = "encapsulation";
 
-    private final Logger log = LoggerFactory.getLogger(getClass());
-
     /**
      * Returns a set of configured VPLSs.
      *
@@ -57,17 +53,19 @@
             String name = jsonNode.get(NAME).asText();
 
             Set<String> ifaces = Sets.newHashSet();
-            jsonNode.path(INTERFACE).forEach(ifacesNode ->
-                    ifaces.add(ifacesNode.asText())
-            );
+            JsonNode vplsIfaces = jsonNode.path(INTERFACE);
+            if (vplsIfaces.toString().isEmpty()) {
+                vplsIfaces = ((ObjectNode) jsonNode).putArray(INTERFACE);
+            }
+            vplsIfaces.forEach(ifacesNode -> ifaces.add(ifacesNode.asText()));
 
             String encap = null;
             if (jsonNode.hasNonNull(ENCAPSULATION)) {
                 encap = jsonNode.get(ENCAPSULATION).asText();
             }
             vplss.add(new VplsConfig(name,
-                                    ifaces,
-                                    EncapsulationType.enumFromString(encap)));
+                                     ifaces,
+                                     EncapsulationType.enumFromString(encap)));
         });
 
         return vplss;
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/config/VplsConfig.java b/apps/vpls/src/main/java/org/onosproject/vpls/config/VplsConfig.java
index 94e96ab..0d8c0c1 100644
--- a/apps/vpls/src/main/java/org/onosproject/vpls/config/VplsConfig.java
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/config/VplsConfig.java
@@ -73,11 +73,10 @@
 
     /**
      * States if a given interface is part of a VPLS.
-     *
      * @param iface the interface attached to a VPLS
      * @return true if the interface is associated to the VPLS; false otherwise
      */
-    public boolean isAttached(String iface) {
+    protected boolean isAttached(String iface) {
         return ifaces.stream().anyMatch(iface::equals);
     }
 
@@ -89,8 +88,8 @@
         if (obj instanceof VplsConfig) {
             VplsConfig that = (VplsConfig) obj;
             return Objects.equals(name, that.name) &&
-                   Objects.equals(ifaces, that.ifaces) &&
-                   Objects.equals(encap, that.encap);
+                    Objects.equals(ifaces, that.ifaces) &&
+                    Objects.equals(encap, that.encap);
         }
         return false;
     }
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/config/VplsConfigurationService.java b/apps/vpls/src/main/java/org/onosproject/vpls/config/VplsConfigService.java
similarity index 95%
rename from apps/vpls/src/main/java/org/onosproject/vpls/config/VplsConfigurationService.java
rename to apps/vpls/src/main/java/org/onosproject/vpls/config/VplsConfigService.java
index 6579378..7500a08 100644
--- a/apps/vpls/src/main/java/org/onosproject/vpls/config/VplsConfigurationService.java
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/config/VplsConfigService.java
@@ -27,7 +27,7 @@
 /**
  * Provides information about the VPLS configuration.
  */
-public interface VplsConfigurationService {
+public interface VplsConfigService {
     Class<VplsAppConfig> CONFIG_CLASS = VplsAppConfig.class;
 
     /**
@@ -98,6 +98,13 @@
     Set<Interface> allIfaces();
 
     /**
+     * Retrieves the interfaces from the VPLS configuration.
+     *
+     * @return a set of interfaces belonging to the VPLS
+     */
+    Set<Interface> ifaces();
+
+    /**
      * Retrieves the interfaces belonging to the VPLS.
      *
      * @param vplsName the name of the VPLS
diff --git a/apps/vpls/src/main/java/org/onosproject/vpls/config/impl/VplsConfigurationImpl.java b/apps/vpls/src/main/java/org/onosproject/vpls/config/impl/VplsConfigImpl.java
similarity index 94%
rename from apps/vpls/src/main/java/org/onosproject/vpls/config/impl/VplsConfigurationImpl.java
rename to apps/vpls/src/main/java/org/onosproject/vpls/config/impl/VplsConfigImpl.java
index 0c2f09b..658a27d 100644
--- a/apps/vpls/src/main/java/org/onosproject/vpls/config/impl/VplsConfigurationImpl.java
+++ b/apps/vpls/src/main/java/org/onosproject/vpls/config/impl/VplsConfigImpl.java
@@ -42,7 +42,7 @@
 import org.onosproject.net.config.basics.SubjectFactories;
 import org.onosproject.vpls.config.VplsAppConfig;
 import org.onosproject.vpls.config.VplsConfig;
-import org.onosproject.vpls.config.VplsConfigurationService;
+import org.onosproject.vpls.config.VplsConfigService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -57,7 +57,7 @@
  */
 @Component(immediate = true)
 @Service
-public class VplsConfigurationImpl implements VplsConfigurationService {
+public class VplsConfigImpl implements VplsConfigService {
     private static final String VPLS_APP = "org.onosproject.vpls";
     private static final String VPLS = "vpls";
     private static final String EMPTY = "";
@@ -90,6 +90,7 @@
     private SetMultimap<String, String> ifacesOfVpls = HashMultimap.create();
     private SetMultimap<String, String> oldIfacesOfVpls = HashMultimap.create();
     private SetMultimap<String, Interface> vplsIfaces = HashMultimap.create();
+
     private Map<String, EncapsulationType> vplsEncaps = Maps.newHashMap();
 
     private final InternalNetworkConfigListener configListener =
@@ -201,15 +202,20 @@
     public Set<String> vplsAffectedByApi() {
         Set<String> vplsNames = ImmutableSet.copyOf(vplsAffectedByApi);
         vplsAffectedByApi.clear();
-
         return vplsNames;
     }
 
     @Override
     public Set<Interface> allIfaces() {
         Set<Interface> allVplsInterfaces = new HashSet<>();
-        vplsIfaces.values().forEach(allVplsInterfaces::add);
+        interfaceService.getInterfaces().forEach(allVplsInterfaces::add);
+        return allVplsInterfaces;
+    }
 
+    @Override
+    public Set<Interface> ifaces() {
+        Set<Interface> allVplsInterfaces = new HashSet<>();
+        vplsIfaces.values().forEach(allVplsInterfaces::add);
         return allVplsInterfaces;
     }
 
@@ -217,7 +223,6 @@
     public Set<Interface> ifaces(String vplsName) {
         Set<Interface> vplsInterfaces = new HashSet<>();
         vplsIfaces.get(vplsName).forEach(vplsInterfaces::add);
-
         return vplsInterfaces;
     }
 
@@ -243,7 +248,7 @@
                 vplsIfaces.entries().stream()
                         .filter(e -> e.getValue().connectPoint().equals(connectPoint))
                         .filter(e -> e.getValue().vlan().equals(vlan))
-                        .map(e -> e.getKey())
+                        .map(Map.Entry::getKey)
                         .findFirst()
                         .orElse(null);
         SetMultimap<String, Interface> result = HashMultimap.create();
@@ -276,7 +281,7 @@
 
         oldIfacesOfVpls = ifacesOfVpls;
         ifacesOfVpls = getConfigInterfaces();
-        vplsIfaces = getConfigCPoints();
+        vplsIfaces = getConfigCPointsFromIfaces();
         vplsEncaps = getConfigEncap();
 
         log.debug(CONFIG_CHANGED, ifacesOfVpls);
@@ -310,7 +315,7 @@
         Map<String, EncapsulationType> configEncap = new HashMap<>();
 
         vplsAppConfig.vplss().forEach(vpls -> {
-                configEncap.put(vpls.name(), vpls.encap());
+            configEncap.put(vpls.name(), vpls.encap());
         });
 
         return configEncap;
@@ -341,7 +346,7 @@
      *
      * @return a map of VPLS names and related interfaces
      */
-    private SetMultimap<String, Interface> getConfigCPoints() {
+    private SetMultimap<String, Interface> getConfigCPointsFromIfaces() {
         log.debug(CHECK_CONFIG);
 
         SetMultimap<String, Interface> confCPointsByIntf =
@@ -364,7 +369,7 @@
     private class InternalNetworkConfigListener implements NetworkConfigListener {
         @Override
         public void event(NetworkConfigEvent event) {
-            if (event.configClass() == VplsConfigurationService.CONFIG_CLASS) {
+            if (event.configClass() == VplsConfigService.CONFIG_CLASS) {
                 log.debug(NET_CONF_EVENT, event.configClass());
                 switch (event.type()) {
                     case CONFIG_ADDED:
@@ -378,4 +383,4 @@
             }
         }
     }
-}
+}
\ No newline at end of file