Add unit test for simple fabric default classes

Change-Id: I47e88a5819833effe92b4e802a7ecaf001e6a6c2
diff --git a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/FabricSubnet.java b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/FabricSubnet.java
index 2e7ba3c..ca56946 100644
--- a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/FabricSubnet.java
+++ b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/FabricSubnet.java
@@ -55,11 +55,11 @@
     EncapsulationType encapsulation();
 
     /**
-     * Gets the subnet name.
+     * Gets the network name.
      *
-     * @return the subnet name
+     * @return the network name
      */
-    String name();
+    String networkName();
 
     /**
      * Tests whether the IP version of this entry is IPv4.
@@ -86,7 +86,7 @@
          * @param ipPrefix IP prefix
          * @return FabricSubnet instance builder
          */
-        Builder ipPrefix(IpPrefix ipPrefix);
+        Builder prefix(IpPrefix ipPrefix);
 
         /**
          * Returns FabricSubnet builder with supplied gatewayIp.
@@ -113,12 +113,12 @@
         Builder encapsulation(EncapsulationType encapsulation);
 
         /**
-         * Returns FabricSubnet builder with supplied subnet name.
+         * Returns FabricSubnet builder with supplied network name.
          *
-         * @param name subnet name
+         * @param networkName network name
          * @return FabricSubnet instance builder
          */
-        Builder name(String name);
+        Builder networkName(String networkName);
 
         /**
          * Builds an immutable FabricSubnet instance.
diff --git a/apps/simplefabric/app/BUCK b/apps/simplefabric/app/BUCK
index 104aee1..6aefd2c 100644
--- a/apps/simplefabric/app/BUCK
+++ b/apps/simplefabric/app/BUCK
@@ -17,6 +17,7 @@
     api_description = 'REST API for Simple Fabric',
     api_package = 'org.onosproject.simplefabric.web',
     api_title = 'Simple Fabric API',
+    api_version = '1.0',
     deps = COMPILE_DEPS,
     test_deps = TEST_DEPS,
     web_context = '/onos/v1/simplefabric',
diff --git a/apps/simplefabric/app/BUILD b/apps/simplefabric/app/BUILD
index 9d93d06..a84652b 100644
--- a/apps/simplefabric/app/BUILD
+++ b/apps/simplefabric/app/BUILD
@@ -3,10 +3,18 @@
     "@concurrent_trees//jar",
 ]
 
+TEST_DEPS = TEST_ADAPTERS + TEST_REST + [
+    "//core/api:onos-api-tests",
+    "//core/common:onos-core-common-tests",
+    "//web/api:onos-rest-tests",
+]
+
 osgi_jar_with_tests(
     api_description = "REST API for Simple Fabric",
     api_package = "org.onosproject.simplefabric.web",
     api_title = "Simple Fabric API",
+    api_version = "1.0",
+    test_deps = TEST_DEPS,
     web_context = "/onos/v1/simplefabric",
     deps = COMPILE_DEPS,
 )
diff --git a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/DefaultFabricNetwork.java b/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/DefaultFabricNetwork.java
similarity index 93%
rename from apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/DefaultFabricNetwork.java
rename to apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/DefaultFabricNetwork.java
index 7b92a93..386a345 100644
--- a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/DefaultFabricNetwork.java
+++ b/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/DefaultFabricNetwork.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package org.onosproject.simplefabric.api;
+package org.onosproject.simplefabric.impl;
 
 import com.google.common.base.MoreObjects;
 import com.google.common.collect.ImmutableSet;
@@ -26,6 +26,7 @@
 import org.onosproject.net.Host;
 import org.onosproject.net.HostId;
 import org.onosproject.net.intf.Interface;
+import org.onosproject.simplefabric.api.FabricNetwork;
 
 import java.util.Collection;
 import java.util.Objects;
@@ -240,12 +241,12 @@
         }
         DefaultFabricNetwork other = (DefaultFabricNetwork) obj;
         return Objects.equals(other.name, this.name)
-               && Objects.equals(other.interfaceNames, this.interfaceNames)
-               && Objects.equals(other.encapsulation, this.encapsulation)
-               && Objects.equals(other.forward, this.forward)
-               && Objects.equals(other.broadcast, this.broadcast)
-               && Objects.equals(other.interfaces, this.interfaces)
-               && Objects.equals(other.hostIds, this.hostIds);
+                && Objects.equals(other.interfaceNames, this.interfaceNames)
+                && Objects.equals(other.encapsulation, this.encapsulation)
+                && Objects.equals(other.forward, this.forward)
+                && Objects.equals(other.broadcast, this.broadcast)
+                && Objects.equals(other.interfaces, this.interfaces)
+                && Objects.equals(other.hostIds, this.hostIds);
     }
 
     @Override
@@ -309,7 +310,7 @@
         public FabricNetwork build() {
             checkArgument(name != null, NOT_NULL_MSG, "name");
             return new DefaultFabricNetwork(name, interfaceNames,
-                                            encapsulation, forward, broadcast);
+                    encapsulation, forward, broadcast);
         }
     }
-}
+}
\ No newline at end of file
diff --git a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/DefaultFabricRoute.java b/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/DefaultFabricRoute.java
similarity index 97%
rename from apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/DefaultFabricRoute.java
rename to apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/DefaultFabricRoute.java
index 8861f9a..6b9a132 100644
--- a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/DefaultFabricRoute.java
+++ b/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/DefaultFabricRoute.java
@@ -14,11 +14,12 @@
  * limitations under the License.
  */
 
-package org.onosproject.simplefabric.api;
+package org.onosproject.simplefabric.impl;
 
 import org.onlab.packet.IpAddress;
 import org.onlab.packet.IpPrefix;
 import org.onosproject.cluster.NodeId;
+import org.onosproject.simplefabric.api.FabricRoute;
 
 import java.util.Objects;
 
diff --git a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/DefaultFabricSubnet.java b/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/DefaultFabricSubnet.java
similarity index 78%
rename from apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/DefaultFabricSubnet.java
rename to apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/DefaultFabricSubnet.java
index 79b1ed2..b7fec47 100644
--- a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/DefaultFabricSubnet.java
+++ b/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/DefaultFabricSubnet.java
@@ -13,13 +13,14 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.onosproject.simplefabric.api;
+package org.onosproject.simplefabric.impl;
 
 import com.google.common.base.MoreObjects;
 import org.onlab.packet.IpAddress;
 import org.onlab.packet.IpPrefix;
 import org.onlab.packet.MacAddress;
 import org.onosproject.net.EncapsulationType;
+import org.onosproject.simplefabric.api.FabricSubnet;
 
 import java.util.Objects;
 
@@ -36,7 +37,7 @@
     private final IpAddress gatewayIp;
     private final MacAddress gatewayMac;
     private EncapsulationType encapsulation;
-    private final String name;
+    private final String networkName;
 
     /**
      * Creates a new subnet entry.
@@ -45,16 +46,16 @@
      * @param gatewayIp IP of the virtual gateway
      * @param gatewayMac MacAddress of the virtual gateway
      * @param encapsulation encapsulation type
-     * @param name subnet name
+     * @param networkName network name
      */
     private DefaultFabricSubnet(IpPrefix prefix, IpAddress gatewayIp,
                                 MacAddress gatewayMac, EncapsulationType encapsulation,
-                                String name) {
+                                String networkName) {
         this.prefix = prefix;
         this.gatewayIp = gatewayIp;
         this.gatewayMac = gatewayMac;
         this.encapsulation = encapsulation;
-        this.name = name;
+        this.networkName = networkName;
     }
 
     @Override
@@ -78,8 +79,8 @@
     }
 
     @Override
-    public String name() {
-        return name;
+    public String networkName() {
+        return networkName;
     }
 
     @Override
@@ -94,7 +95,7 @@
 
     @Override
     public int hashCode() {
-        return Objects.hash(prefix, gatewayIp, gatewayMac, encapsulation, name);
+        return Objects.hash(prefix, gatewayIp, gatewayMac, encapsulation, networkName);
     }
 
     @Override
@@ -107,10 +108,10 @@
         }
         DefaultFabricSubnet that = (DefaultFabricSubnet) obj;
         return Objects.equals(this.prefix, that.prefix)
-               && Objects.equals(this.gatewayIp, that.gatewayIp)
-               && Objects.equals(this.gatewayMac, that.gatewayMac)
-               && Objects.equals(this.encapsulation, that.encapsulation)
-               && Objects.equals(this.name, that.name);
+                && Objects.equals(this.gatewayIp, that.gatewayIp)
+                && Objects.equals(this.gatewayMac, that.gatewayMac)
+                && Objects.equals(this.encapsulation, that.encapsulation)
+                && Objects.equals(this.networkName, that.networkName);
     }
 
     @Override
@@ -120,7 +121,7 @@
                 .add("gatewayIp", gatewayIp)
                 .add("gatewayMac", gatewayMac)
                 .add("encapsulation", encapsulation)
-                .add("name", name)
+                .add("networkName", networkName)
                 .toString();
     }
 
@@ -137,18 +138,18 @@
      * A builder class for Ip Subnet.
      */
     public static final class DefaultSubnetBuilder implements Builder {
-        private IpPrefix ipPrefix;
+        private IpPrefix prefix;
         private IpAddress gatewayIp;
         private MacAddress gatewayMac;
         private EncapsulationType encapsulation;
-        private String name;
+        private String networkName;
 
         private DefaultSubnetBuilder() {
         }
 
         @Override
-        public Builder ipPrefix(IpPrefix ipPrefix) {
-            this.ipPrefix = ipPrefix;
+        public Builder prefix(IpPrefix prefix) {
+            this.prefix = prefix;
             return this;
         }
 
@@ -171,24 +172,24 @@
         }
 
         @Override
-        public Builder name(String networkName) {
-            this.name = networkName;
+        public Builder networkName(String networkName) {
+            this.networkName = networkName;
             return this;
         }
 
         @Override
         public FabricSubnet build() {
-            checkArgument(ipPrefix != null, NOT_NULL_MSG, "prefix");
+            checkArgument(prefix != null, NOT_NULL_MSG, "prefix");
             checkArgument(gatewayIp != null, NOT_NULL_MSG, "gatewayIp");
             checkArgument(gatewayMac != null, NOT_NULL_MSG, "gatewayMac");
-            checkArgument(name != null, NOT_NULL_MSG, "name");
+            checkArgument(networkName != null, NOT_NULL_MSG, "name");
 
             if (this.encapsulation == null) {
                 encapsulation = EncapsulationType.NONE;
             }
 
-            return new DefaultFabricSubnet(ipPrefix, gatewayIp, gatewayMac,
-                                                            encapsulation, name);
+            return new DefaultFabricSubnet(prefix, gatewayIp, gatewayMac,
+                    encapsulation, networkName);
         }
     }
-}
+}
\ No newline at end of file
diff --git a/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/SimpleFabricConfig.java b/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/SimpleFabricConfig.java
index 53c33a4..1d4b97c 100644
--- a/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/SimpleFabricConfig.java
+++ b/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/SimpleFabricConfig.java
@@ -24,12 +24,9 @@
 import org.onosproject.core.ApplicationId;
 import org.onosproject.net.EncapsulationType;
 import org.onosproject.net.config.Config;
-import org.onosproject.simplefabric.api.DefaultFabricRoute;
-import org.onosproject.simplefabric.api.DefaultFabricSubnet;
-import org.onosproject.simplefabric.api.DefaultFabricNetwork;
+import org.onosproject.simplefabric.api.FabricNetwork;
 import org.onosproject.simplefabric.api.FabricRoute;
 import org.onosproject.simplefabric.api.FabricSubnet;
-import org.onosproject.simplefabric.api.FabricNetwork;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -128,11 +125,11 @@
             }
             try {
                 subnets.add(DefaultFabricSubnet.builder()
-                            .ipPrefix(IpPrefix.valueOf(jsonNode.get(PREFIX).asText()))
+                            .prefix(IpPrefix.valueOf(jsonNode.get(PREFIX).asText()))
                             .gatewayIp(IpAddress.valueOf(jsonNode.get(GATEWAY_IP).asText()))
                             .gatewayMac(MacAddress.valueOf(jsonNode.get(GATEWAY_MAC).asText()))
                             .encapsulation(EncapsulationType.enumFromString(encapsulation))
-                            .name(jsonNode.get(NETWORK_NAME).asText())
+                            .networkName(jsonNode.get(NETWORK_NAME).asText())
                             .build());
             } catch (Exception e) {
                 log.warn("Fabric subnet parse failed; skip: jsonNode={}", jsonNode);
diff --git a/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/SimpleFabricManager.java b/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/SimpleFabricManager.java
index de87ba1..1bdcacd 100644
--- a/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/SimpleFabricManager.java
+++ b/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/SimpleFabricManager.java
@@ -64,7 +64,6 @@
 import org.onosproject.net.packet.DefaultOutboundPacket;
 import org.onosproject.net.packet.OutboundPacket;
 import org.onosproject.net.packet.PacketService;
-import org.onosproject.simplefabric.api.DefaultFabricNetwork;
 import org.onosproject.simplefabric.api.FabricNetwork;
 import org.onosproject.simplefabric.api.FabricRoute;
 import org.onosproject.simplefabric.api.FabricSubnet;
@@ -450,10 +449,10 @@
             log.warn("simple fabric request mac failed for unknown fabricSubnet: {}", ip);
             return false;
         }
-        FabricNetwork fabricNetwork = fabricNetwork(fabricSubnet.name());
+        FabricNetwork fabricNetwork = fabricNetwork(fabricSubnet.networkName());
         if (fabricNetwork == null) {
             log.warn("simple fabric request mac failed for unknown fabricNetwork name {}: {}",
-                     fabricSubnet.name(), ip);
+                     fabricSubnet.networkName(), ip);
             return false;
         }
         log.debug("simple fabric send request mac fabricNetwork {}: {}", fabricNetwork.name(), ip);
diff --git a/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/SimpleFabricRouting.java b/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/SimpleFabricRouting.java
index 7a03b9d..9eefc03 100644
--- a/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/SimpleFabricRouting.java
+++ b/apps/simplefabric/app/src/main/java/org/onosproject/simplefabric/impl/SimpleFabricRouting.java
@@ -245,7 +245,7 @@
             for (FabricSubnet subnet : simpleFabric.defaultFabricSubnets()) {
                 newInterceptFlowRules.add(generateInterceptFlowRule(true, device.id(), subnet.prefix()));
                 // check if this devices has the fabricSubnet, then add ip broadcast flue rule
-                FabricNetwork fabricNetwork = simpleFabric.fabricNetwork(subnet.name());
+                FabricNetwork fabricNetwork = simpleFabric.fabricNetwork(subnet.networkName());
                 if (fabricNetwork != null && fabricNetwork.contains(device.id())) {
                     newInterceptFlowRules.add(generateLocalSubnetIpBctFlowRule(device.id(), subnet.prefix(),
                             fabricNetwork));
@@ -673,7 +673,7 @@
             // destination is local subnet ip
             if (ALLOW_ETH_ADDRESS_SELECTOR && dstSubnet.equals(srcSubnet)) {
                 // NOTE: if ALLOW_ETH_ADDRESS_SELECTOR=false; isForward is always false
-                FabricNetwork fabricNetwork = simpleFabric.fabricNetwork(dstSubnet.name());
+                FabricNetwork fabricNetwork = simpleFabric.fabricNetwork(dstSubnet.networkName());
                 treatmentSrcMac = ethPkt.getSourceMAC();
                 if (fabricNetwork != null && fabricNetwork.isForward()) {
                     // NOTE: no reactive route action but do forward packet for L2Forward do not handle packet
diff --git a/apps/simplefabric/app/src/test/java/org/onosproject/simplefabric/impl/DefaultFabricNetworkTest.java b/apps/simplefabric/app/src/test/java/org/onosproject/simplefabric/impl/DefaultFabricNetworkTest.java
new file mode 100644
index 0000000..57152e7
--- /dev/null
+++ b/apps/simplefabric/app/src/test/java/org/onosproject/simplefabric/impl/DefaultFabricNetworkTest.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.simplefabric.impl;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.testing.EqualsTester;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.MacAddress;
+import org.onlab.packet.VlanId;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.EncapsulationType;
+import org.onosproject.net.host.InterfaceIpAddress;
+import org.onosproject.net.intf.Interface;
+import org.onosproject.simplefabric.api.FabricNetwork;
+
+import java.util.List;
+import java.util.Set;
+
+import static junit.framework.TestCase.assertEquals;
+
+/**
+ * Unit tests for the default fabric network class.
+ */
+public final class DefaultFabricNetworkTest {
+
+    private static final String NAME_1 = "network1";
+    private static final String NAME_2 = "network2";
+
+    private static final String INTF_NAMES_1_1 = "h11";
+    private static final String INTF_NAMES_1_2 = "h12";
+    private static final String INTF_NAMES_2_1 = "h21";
+    private static final String INTF_NAMES_2_2 = "h22";
+
+    private static final Set<String> INTF_NAME_SET_1 =
+                            ImmutableSet.of(INTF_NAMES_1_1, INTF_NAMES_1_2);
+    private static final Set<String> INTF_NAME_SET_2 =
+                            ImmutableSet.of(INTF_NAMES_2_1, INTF_NAMES_2_2);
+
+    private static final EncapsulationType ENCAP_TYPE_1 = EncapsulationType.NONE;
+    private static final EncapsulationType ENCAP_TYPE_2 = EncapsulationType.NONE;
+
+    private static final boolean IS_FORWARD_1 = false;
+    private static final boolean IS_FORWARD_2 = true;
+    private static final boolean IS_BROADCAST_1 = false;
+    private static final boolean IS_BROADCAST_2 = true;
+
+    private FabricNetwork fabricNetwork1;
+    private FabricNetwork sameAsFabricNetwork1;
+    private FabricNetwork fabricNetwork2;
+
+    private static Interface createInterface(int index) {
+
+        String name = "INTF_NAME_" + index;
+        ConnectPoint cp = ConnectPoint.fromString("of:0011223344556677/" + index);
+        InterfaceIpAddress intfIp1 = InterfaceIpAddress.valueOf("10.10.10." + index + "/32");
+        InterfaceIpAddress intfIp2 = InterfaceIpAddress.valueOf("20.20.20." + index + "/32");
+        List<InterfaceIpAddress> intfIps = ImmutableList.of(intfIp1, intfIp2);
+        MacAddress mac = MacAddress.valueOf("00:00:00:00:00:00");
+        VlanId vlanId = VlanId.NONE;
+
+        return new Interface(name, cp, intfIps, mac, vlanId);
+    }
+
+    /**
+     * Initial setup for this unit test.
+     */
+    @Before
+    public void setUp() {
+
+        fabricNetwork1 = DefaultFabricNetwork.builder()
+                                .name(NAME_1)
+                                .interfaceNames(INTF_NAME_SET_1)
+                                .encapsulation(ENCAP_TYPE_1)
+                                .forward(IS_FORWARD_1)
+                                .broadcast(IS_BROADCAST_1)
+                                .build();
+
+        sameAsFabricNetwork1 = DefaultFabricNetwork.builder()
+                                .name(NAME_1)
+                                .interfaceNames(INTF_NAME_SET_1)
+                                .encapsulation(ENCAP_TYPE_1)
+                                .forward(IS_FORWARD_1)
+                                .broadcast(IS_BROADCAST_1)
+                                .build();
+
+        fabricNetwork2 = DefaultFabricNetwork.builder()
+                                .name(NAME_2)
+                                .interfaceNames(INTF_NAME_SET_2)
+                                .encapsulation(ENCAP_TYPE_2)
+                                .forward(IS_FORWARD_2)
+                                .broadcast(IS_BROADCAST_2)
+                                .build();
+    }
+
+    /**
+     * Tests object equality.
+     */
+    @Test
+    public void testEquality() {
+        new EqualsTester().addEqualityGroup(fabricNetwork1, sameAsFabricNetwork1)
+                .addEqualityGroup(fabricNetwork2)
+                .testEquals();
+    }
+
+    /**
+     * Test object construction.
+     */
+    @Test
+    public void testConstruction() {
+        FabricNetwork network = fabricNetwork1;
+
+        assertEquals(network.name(), NAME_1);
+        assertEquals(network.interfaceNames(), INTF_NAME_SET_1);
+        assertEquals(network.encapsulation(), ENCAP_TYPE_1);
+        assertEquals(network.isForward(), IS_FORWARD_1);
+        assertEquals(network.isBroadcast(), IS_BROADCAST_1);
+    }
+}
diff --git a/apps/simplefabric/app/src/test/java/org/onosproject/simplefabric/impl/DefaultFabricRouteTest.java b/apps/simplefabric/app/src/test/java/org/onosproject/simplefabric/impl/DefaultFabricRouteTest.java
new file mode 100644
index 0000000..8a39179
--- /dev/null
+++ b/apps/simplefabric/app/src/test/java/org/onosproject/simplefabric/impl/DefaultFabricRouteTest.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.simplefabric.impl;
+
+import com.google.common.testing.EqualsTester;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.IpPrefix;
+import org.onosproject.cluster.NodeId;
+import org.onosproject.simplefabric.api.FabricRoute;
+import org.onosproject.simplefabric.api.FabricRoute.Source;
+
+import static junit.framework.TestCase.assertEquals;
+import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
+
+/**
+ * Unit tests for the default fabric router.
+ */
+public final class DefaultFabricRouteTest {
+
+    private static final Source SOURCE_1 = Source.STATIC;
+    private static final Source SOURCE_2 = Source.BGP;
+
+    private static final IpPrefix IP_PREFIX_1 = IpPrefix.valueOf("10.10.10.1/32");
+    private static final IpPrefix IP_PREFIX_2 = IpPrefix.valueOf("20.20.20.2/32");
+
+    private static final IpAddress NEXT_HOP_1 = IpAddress.valueOf("10.10.10.1");
+    private static final IpAddress NEXT_HOP_2 = IpAddress.valueOf("20.20.20.2");
+
+    private static final NodeId SOURCE_NODE_1 = NodeId.nodeId("1");
+    private static final NodeId SOURCE_NODE_2 = NodeId.nodeId("2");
+
+    private FabricRoute fabricRoute1;
+    private FabricRoute sameAsFabricRoute1;
+    private FabricRoute fabricRoute2;
+
+    /**
+     * Tests class immutability.
+     */
+    @Test
+    public void testImmutability() {
+        assertThatClassIsImmutable(DefaultFabricRoute.class);
+    }
+
+    /**
+     * Initial setup for this unit test.
+     */
+    @Before
+    public void setUp() {
+        fabricRoute1 = DefaultFabricRoute.builder()
+                                .source(SOURCE_1)
+                                .prefix(IP_PREFIX_1)
+                                .nextHop(NEXT_HOP_1)
+                                .sourceNode(SOURCE_NODE_1)
+                                .build();
+
+        sameAsFabricRoute1 = DefaultFabricRoute.builder()
+                                .source(SOURCE_1)
+                                .prefix(IP_PREFIX_1)
+                                .nextHop(NEXT_HOP_1)
+                                .sourceNode(SOURCE_NODE_1)
+                                .build();
+
+        fabricRoute2 = DefaultFabricRoute.builder()
+                                .source(SOURCE_2)
+                                .prefix(IP_PREFIX_2)
+                                .nextHop(NEXT_HOP_2)
+                                .sourceNode(SOURCE_NODE_2)
+                                .build();
+    }
+
+    /**
+     * Tests object equality.
+     */
+    @Test
+    public void testEquality() {
+        new EqualsTester().addEqualityGroup(fabricRoute1, sameAsFabricRoute1)
+                .addEqualityGroup(fabricRoute2)
+                .testEquals();
+    }
+
+    /**
+     * Test object construction.
+     */
+    @Test
+    public void testConstruction() {
+        FabricRoute route = fabricRoute1;
+
+        assertEquals(route.source(), SOURCE_1);
+        assertEquals(route.prefix(), IP_PREFIX_1);
+        assertEquals(route.nextHop(), NEXT_HOP_1);
+        assertEquals(route.sourceNode(), SOURCE_NODE_1);
+    }
+}
diff --git a/apps/simplefabric/app/src/test/java/org/onosproject/simplefabric/impl/DefaultFabricSubnetTest.java b/apps/simplefabric/app/src/test/java/org/onosproject/simplefabric/impl/DefaultFabricSubnetTest.java
new file mode 100644
index 0000000..82efd14
--- /dev/null
+++ b/apps/simplefabric/app/src/test/java/org/onosproject/simplefabric/impl/DefaultFabricSubnetTest.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.simplefabric.impl;
+
+import com.google.common.testing.EqualsTester;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.IpPrefix;
+import org.onlab.packet.MacAddress;
+import org.onosproject.net.EncapsulationType;
+import org.onosproject.simplefabric.api.FabricSubnet;
+
+import static junit.framework.TestCase.assertEquals;
+
+/**
+ * Unit tests for the default fabric IP subnet class.
+ */
+public final class DefaultFabricSubnetTest {
+
+    private static final IpPrefix IP_PREFIX_1 = IpPrefix.valueOf("10.10.10.11/32");
+    private static final IpPrefix IP_PREFIX_2 = IpPrefix.valueOf("20.20.20.11/32");
+
+    private static final IpAddress GATEWAY_IP_1 = IpAddress.valueOf("10.10.10.1");
+    private static final IpAddress GATEWAY_IP_2 = IpAddress.valueOf("20.20.20.1");
+
+    private static final MacAddress GATEWAY_MAC_1 = MacAddress.valueOf("00:11:22:33:44:55");
+    private static final MacAddress GATEWAY_MAC_2 = MacAddress.valueOf("11:22:33:44:55:66");
+
+    private static final EncapsulationType ENCAP_TYPE_1 = EncapsulationType.NONE;
+    private static final EncapsulationType ENCAP_TYPE_2 = EncapsulationType.NONE;
+
+    private static final String NETWORK_NAME_1 = "sonaFabric1";
+    private static final String NETWORK_NAME_2 = "sonaFabric2";
+
+    private FabricSubnet subnet1;
+    private FabricSubnet sameAsSubnet1;
+    private FabricSubnet subnet2;
+
+    /**
+     * Initial setup for this unit test.
+     */
+    @Before
+    public void setUp() {
+
+        subnet1 = DefaultFabricSubnet.builder()
+                            .prefix(IP_PREFIX_1)
+                            .gatewayIp(GATEWAY_IP_1)
+                            .gatewayMac(GATEWAY_MAC_1)
+                            .encapsulation(ENCAP_TYPE_1)
+                            .networkName(NETWORK_NAME_1)
+                            .build();
+
+        sameAsSubnet1 = DefaultFabricSubnet.builder()
+                            .prefix(IP_PREFIX_1)
+                            .gatewayIp(GATEWAY_IP_1)
+                            .gatewayMac(GATEWAY_MAC_1)
+                            .encapsulation(ENCAP_TYPE_1)
+                            .networkName(NETWORK_NAME_1)
+                            .build();
+
+        subnet2 = DefaultFabricSubnet.builder()
+                            .prefix(IP_PREFIX_2)
+                            .gatewayIp(GATEWAY_IP_2)
+                            .gatewayMac(GATEWAY_MAC_2)
+                            .encapsulation(ENCAP_TYPE_2)
+                            .networkName(NETWORK_NAME_2)
+                            .build();
+    }
+
+    /**
+     * Tests object equality.
+     */
+    @Test
+    public void testEquality() {
+        new EqualsTester().addEqualityGroup(subnet1, sameAsSubnet1)
+                .addEqualityGroup(subnet2)
+                .testEquals();
+    }
+
+    /**
+     * Test object construction.
+     */
+    @Test
+    public void testConstruction() {
+        FabricSubnet subnet = subnet1;
+
+        assertEquals(subnet.prefix(), IP_PREFIX_1);
+        assertEquals(subnet.gatewayIp(), GATEWAY_IP_1);
+        assertEquals(subnet.gatewayMac(), GATEWAY_MAC_1);
+        assertEquals(subnet.encapsulation(), ENCAP_TYPE_1);
+        assertEquals(subnet.networkName(), NETWORK_NAME_1);
+    }
+}