ONOS-2843 Fix bug post NBI subnet get an error.

Change-Id: I93b52a0c69a57b458b610afbb78cfdec0b50e3a5
diff --git a/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultSubnet.java b/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultSubnet.java
index 6311a80..88fabff 100644
--- a/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultSubnet.java
+++ b/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultSubnet.java
@@ -18,6 +18,7 @@
 import static com.google.common.base.MoreObjects.toStringHelper;

 

 import java.util.Objects;

+import java.util.Set;

 

 import org.onlab.packet.IpAddress;

 import org.onlab.packet.IpAddress.Version;

@@ -38,8 +39,8 @@
     private final boolean shared;

     private final Mode ipV6AddressMode;

     private final Mode ipV6RaMode;

-    private final Iterable<HostRoute> hostRoutes;

-    private final Iterable<AllocationPool> allocationPools;

+    private final Set<HostRoute> hostRoutes;

+    private final Set<AllocationPool> allocationPools;

 

     /**

      * Creates a subnet object.

@@ -64,9 +65,9 @@
                          TenantNetworkId networkId, TenantId tenantId,

                          Version ipVersion, IpPrefix cidr, IpAddress gatewayIp,

                          boolean dhcpEnabled, boolean shared,

-                         Iterable<HostRoute> hostRoutes, Mode ipV6AddressMode,

+                         Set<HostRoute> hostRoutes, Mode ipV6AddressMode,

                          Mode ipV6RaMode,

-                         Iterable<AllocationPool> allocationPoolsIt) {

+                         Set<AllocationPool> allocationPoolsIt) {

         this.id = id;

         this.subnetName = subnetName;

         this.networkId = networkId;

diff --git a/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultVirtualPort.java b/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultVirtualPort.java
index 4de131a..adf3a3a 100644
--- a/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultVirtualPort.java
+++ b/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultVirtualPort.java
@@ -43,8 +43,8 @@
     private final String bindingVnicType;

     private final String bindingVifType;

     private final String bindingVifDetails;

-    private final Collection<AllowedAddressPair> allowedAddressPairs;

-    private final Collection<SecurityGroup> securityGroups;

+    private final Set<AllowedAddressPair> allowedAddressPairs;

+    private final Set<SecurityGroup> securityGroups;

 

     /**

      * Creates a VirtualPort object.

@@ -72,8 +72,8 @@
                               DeviceId deviceId,

                               Set<FixedIp> fixedIps,

                               BindingHostId bindingHostId,

-                              Collection<AllowedAddressPair> allowedAddressPairs,

-                              Collection<SecurityGroup> securityGroups) {

+                              Set<AllowedAddressPair> allowedAddressPairs,

+                              Set<SecurityGroup> securityGroups) {

         this.id = id;

         this.networkId = networkId;

         this.adminStateUp = adminStateUp;

diff --git a/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/subnet/SubnetCreateCommand.java b/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/subnet/SubnetCreateCommand.java
index a673d17..5623640 100644
--- a/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/subnet/SubnetCreateCommand.java
+++ b/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/subnet/SubnetCreateCommand.java
@@ -88,11 +88,11 @@
 
     @Option(name = "-h", aliases = "--hostRoutes", description = "Subnet jsonnode hostRoutes",
             required = false, multiValued = false)
-    Iterable<HostRoute> hostRoutes = null;
+    Set<HostRoute> hostRoutes = Sets.newHashSet();
 
     @Option(name = "-a", aliases = "--allocationPools",
             description = "Subnet jsonnode allocationPools", required = false, multiValued = false)
-    Iterable<AllocationPool> allocationPools = Sets.newHashSet();
+    Set<AllocationPool> allocationPools = Sets.newHashSet();
 
     @Override
     protected void execute() {
diff --git a/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/subnet/SubnetUpdateCommand.java b/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/subnet/SubnetUpdateCommand.java
index 2e8fc20..f8ee6b9 100644
--- a/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/subnet/SubnetUpdateCommand.java
+++ b/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/subnet/SubnetUpdateCommand.java
@@ -88,11 +88,11 @@
 
     @Option(name = "-h", aliases = "--hostRoutes", description = "Subnet jsonnode hostRoutes",
             required = false, multiValued = false)
-    Iterable<HostRoute> hostRoutes = null;
+    Set<HostRoute> hostRoutes = Sets.newHashSet();
 
     @Option(name = "-a", aliases = "--allocationPools",
             description = "Subnet jsonnode allocationPools", required = false, multiValued = false)
-    Iterable<AllocationPool> allocationPools = Sets.newHashSet();;
+    Set<AllocationPool> allocationPools = Sets.newHashSet();;
 
     @Override
     protected void execute() {
diff --git a/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortCreateCommand.java b/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortCreateCommand.java
index 956f8ce..4c555e3 100644
--- a/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortCreateCommand.java
+++ b/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortCreateCommand.java
@@ -15,7 +15,6 @@
  */
 package org.onosproject.vtnrsc.cli.virtualport;
 
-import java.util.Collection;
 import java.util.Map;
 import java.util.Set;
 
@@ -106,11 +105,11 @@
 
     @Option(name = "-l", aliases = "--allowedAddress", description = "virtual allowedAddressPair.",
             required = false, multiValued = false)
-    Collection<AllowedAddressPair> allowedAddressPairs = Sets.newHashSet();
+    Set<AllowedAddressPair> allowedAddressPairs = Sets.newHashSet();
 
     @Option(name = "-e", aliases = "--securityGroups", description = "virtualPort securityGroups.",
             required = false, multiValued = false)
-    Collection<SecurityGroup> securityGroups = Sets.newHashSet();
+    Set<SecurityGroup> securityGroups = Sets.newHashSet();
 
     @Override
     protected void execute() {
diff --git a/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortUpdateCommand.java b/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortUpdateCommand.java
index fd218e0..6df4b23 100644
--- a/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortUpdateCommand.java
+++ b/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortUpdateCommand.java
@@ -15,7 +15,6 @@
  */
 package org.onosproject.vtnrsc.cli.virtualport;
 
-import java.util.Collection;
 import java.util.Map;
 import java.util.Set;
 
@@ -107,11 +106,11 @@
 
     @Option(name = "-l", aliases = "--allowedAddress", description = "virtual allowedAddressPair.",
             required = false, multiValued = false)
-    Collection<AllowedAddressPair> allowedAddressPairs = Sets.newHashSet();
+    Set<AllowedAddressPair> allowedAddressPairs = Sets.newHashSet();
 
     @Option(name = "-e", aliases = "--securityGroups", description = "virtualPort securityGroups.",
             required = false, multiValued = false)
-    Collection<SecurityGroup> securityGroups = Sets.newHashSet();
+    Set<SecurityGroup> securityGroups = Sets.newHashSet();
 
     @Override
     protected void execute() {
diff --git a/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/subnet/impl/SubnetManager.java b/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/subnet/impl/SubnetManager.java
index 879dd35..ab810a8 100644
--- a/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/subnet/impl/SubnetManager.java
+++ b/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/subnet/impl/SubnetManager.java
@@ -21,12 +21,14 @@
 import org.apache.felix.scr.annotations.Reference;

 import org.apache.felix.scr.annotations.ReferenceCardinality;

 import org.apache.felix.scr.annotations.Service;

+import org.onlab.packet.IpAddress;

 import org.onosproject.core.ApplicationId;

 import org.onosproject.core.CoreService;

 import org.onosproject.store.serializers.KryoNamespaces;

 import org.onosproject.store.service.Serializer;

 import org.onosproject.store.service.StorageService;

 import org.onosproject.vtnrsc.AllocationPool;

+import org.onosproject.vtnrsc.DefaultSubnet;

 import org.onosproject.vtnrsc.HostRoute;

 import org.onosproject.vtnrsc.Subnet;

 import org.onosproject.vtnrsc.SubnetId;

@@ -86,7 +88,9 @@
                                                  TenantId.class,

                                                  HostRoute.class,

                                                  Subnet.Mode.class,

-                                                 AllocationPool.class))

+                                                 AllocationPool.class,

+                                                 DefaultSubnet.class,

+                                                 IpAddress.Version.class))

                 .build().asJavaMap();

 

         log.info("Started");

diff --git a/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/virtualport/impl/VirtualPortManager.java b/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/virtualport/impl/VirtualPortManager.java
index a94ea1f..e0c49f5 100644
--- a/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/virtualport/impl/VirtualPortManager.java
+++ b/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/virtualport/impl/VirtualPortManager.java
@@ -30,6 +30,7 @@
 import org.onosproject.store.service.StorageService;

 import org.onosproject.vtnrsc.AllowedAddressPair;

 import org.onosproject.vtnrsc.BindingHostId;

+import org.onosproject.vtnrsc.DefaultVirtualPort;

 import org.onosproject.vtnrsc.FixedIp;

 import org.onosproject.vtnrsc.SecurityGroup;

 import org.onosproject.vtnrsc.SubnetId;

@@ -98,7 +99,8 @@
                                                  BindingHostId.class,

                                                  SecurityGroup.class,

                                                  SubnetId.class,

-                                                 IpAddress.class))

+                                                 IpAddress.class,

+                                                 DefaultVirtualPort.class))

                 .build().asJavaMap();

         log.info("Started");

     }

diff --git a/apps/vtnweb/src/main/java/org/onosproject/vtnweb/resources/SubnetWebResource.java b/apps/vtnweb/src/main/java/org/onosproject/vtnweb/resources/SubnetWebResource.java
index 7494f02..c46af6e 100644
--- a/apps/vtnweb/src/main/java/org/onosproject/vtnweb/resources/SubnetWebResource.java
+++ b/apps/vtnweb/src/main/java/org/onosproject/vtnweb/resources/SubnetWebResource.java
@@ -63,6 +63,7 @@
 import com.fasterxml.jackson.databind.ObjectMapper;

 import com.fasterxml.jackson.databind.node.ObjectNode;

 import com.google.common.collect.Maps;

+import com.google.common.collect.Sets;

 

 @Path("subnets")

 public class SubnetWebResource extends AbstractWebResource {

@@ -211,8 +212,8 @@
             Subnet subnet = new DefaultSubnet(id, subnetName, networkId,

                                               tenantId, ipVersion, cidr,

                                               gatewayIp, dhcpEnabled, shared,

-                                              hostRoutesIt, ipV6AddressMode,

-                                              ipV6RaMode, allocationPoolsIt);

+                                              Sets.newHashSet(hostRoutesIt), ipV6AddressMode,

+                                              ipV6RaMode, Sets.newHashSet(allocationPoolsIt));

             subMap.put(id, subnet);

         }

         return Collections.unmodifiableCollection(subMap.values());

@@ -267,9 +268,9 @@
 

         Subnet subnet = new DefaultSubnet(id, subnetName, networkId, tenantId,

                                           ipVersion, cidr, gatewayIp,

-                                          dhcpEnabled, shared, hostRoutesIt,

+                                          dhcpEnabled, shared, Sets.newHashSet(hostRoutesIt),

                                           ipV6AddressMode, ipV6RaMode,

-                                          allocationPoolsIt);

+                                          Sets.newHashSet(allocationPoolsIt));

         subMap.put(id, subnet);

         return Collections.unmodifiableCollection(subMap.values());

     }

diff --git a/apps/vtnweb/src/main/java/org/onosproject/vtnweb/resources/VirtualPortWebResource.java b/apps/vtnweb/src/main/java/org/onosproject/vtnweb/resources/VirtualPortWebResource.java
index 28f0c42..0a427bb 100644
--- a/apps/vtnweb/src/main/java/org/onosproject/vtnweb/resources/VirtualPortWebResource.java
+++ b/apps/vtnweb/src/main/java/org/onosproject/vtnweb/resources/VirtualPortWebResource.java
@@ -54,8 +54,8 @@
 import org.onosproject.vtnrsc.TenantId;

 import org.onosproject.vtnrsc.TenantNetworkId;

 import org.onosproject.vtnrsc.VirtualPort;

-import org.onosproject.vtnrsc.VirtualPortId;

 import org.onosproject.vtnrsc.VirtualPort.State;

+import org.onosproject.vtnrsc.VirtualPortId;

 import org.onosproject.vtnrsc.virtualport.VirtualPortService;

 import org.onosproject.vtnrsc.web.VirtualPortCodec;

 import org.slf4j.Logger;

@@ -65,6 +65,7 @@
 import com.fasterxml.jackson.databind.ObjectMapper;

 import com.fasterxml.jackson.databind.node.ObjectNode;

 import com.google.common.collect.Maps;

+import com.google.common.collect.Sets;

 

 /**

  * REST resource for interacting with the inventory of infrastructure

@@ -249,8 +250,8 @@
                                                        macAddress, tenantId,

                                                        deviceId, fixedIps,

                                                        bindingHostId,

-                                                       allowedAddressPairs,

-                                                       securityGroups);

+                                                       Sets.newHashSet(allowedAddressPairs),

+                                                       Sets.newHashSet(securityGroups));

             portMap.put(id, vPort);

         }

         return Collections.unmodifiableCollection(portMap.values());

@@ -308,8 +309,8 @@
                                                    macAddress, tenantId,

                                                    deviceId, fixedIps,

                                                    bindingHostId,

-                                                   allowedAddressPairs,

-                                                   securityGroups);

+                                                   Sets.newHashSet(allowedAddressPairs),

+                                                   Sets.newHashSet(securityGroups));

         vportMap.put(id, vPort);

 

         return Collections.unmodifiableCollection(vportMap.values());