Refactor: extract interfaces for a set of simple fabric classes

Change-Id: I4a23fb2277498f466ce20f82e38d5e9cb25dab6e
diff --git a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/Constants.java b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/Constants.java
index 793eadc..703e01b 100644
--- a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/Constants.java
+++ b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/Constants.java
@@ -26,8 +26,8 @@
 
     // App symbols
     public static final String APP_ID = "org.onosproject.simplefabric";
-    public static final String L2FORWARD_APP_ID = "org.onosproject.simplefabric.l2forward";
-    public static final String REACTIVE_APP_ID = "org.onosproject.simplefabric.reactive";
+    public static final String FORWARDING_APP_ID = "org.onosproject.simplefabric.forwarding";
+    public static final String ROUTING_APP_ID = "org.onosproject.simplefabric.routing";
 
     // Priority for l2NetworkRouting: L2NETWORK_UNICAST or L2NETWORK_BROADCAST
     public static final int PRI_L2NETWORK_UNICAST = 601;
diff --git a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/DefaultFabricNetwork.java b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/DefaultFabricNetwork.java
new file mode 100644
index 0000000..7b92a93
--- /dev/null
+++ b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/DefaultFabricNetwork.java
@@ -0,0 +1,315 @@
+/*
+ * 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.api;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Sets;
+import org.onlab.packet.VlanId;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.EncapsulationType;
+import org.onosproject.net.Host;
+import org.onosproject.net.HostId;
+import org.onosproject.net.intf.Interface;
+
+import java.util.Collection;
+import java.util.Objects;
+import java.util.Set;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static org.onosproject.simplefabric.api.Constants.ALLOW_ETH_ADDRESS_SELECTOR;
+
+
+/**
+ * Class stores a DefaultFabricNetwork information.
+ */
+public final class DefaultFabricNetwork implements FabricNetwork {
+
+    private static final String NOT_NULL_MSG = "FabricNetwork % cannot be null";
+
+    private final String name;
+    private final Set<String> interfaceNames;
+    private final EncapsulationType encapsulation;
+    private boolean forward;
+    private boolean broadcast;
+
+    /* status variables */
+    private final Set<Interface> interfaces;
+    private final Set<HostId> hostIds;
+    private boolean dirty;
+
+    /**
+     * Constructs a DefaultFabricNetwork instance.
+     *
+     * @param name              fabric name name
+     * @param interfaceNames    a collection of  interface names
+     * @param encapsulation     encapsulation type
+     * @param forward           flag for forward intents to be installed or not
+     * @param broadcast         flag for broadcast intents to be installed or not
+     */
+    private DefaultFabricNetwork(String name, Collection<String> interfaceNames,
+                                 EncapsulationType encapsulation,
+                                 boolean forward, boolean broadcast) {
+        this.name = name;
+        this.interfaceNames = Sets.newHashSet();
+
+        if (interfaceNames != null) {
+            this.interfaceNames.addAll(interfaceNames);
+        }
+
+        this.encapsulation = encapsulation;
+        this.forward = (ALLOW_ETH_ADDRESS_SELECTOR) && forward;
+        this.broadcast = (ALLOW_ETH_ADDRESS_SELECTOR) && broadcast;
+        this.interfaces = Sets.newHashSet();
+        this.hostIds = Sets.newHashSet();
+        this.dirty = false;
+    }
+
+    /**
+     * Constructs a DefaultFabricNetwork instance.
+     *
+     * @param name              fabric network name
+     * @param encapsulation     encapsulation type
+     */
+    private DefaultFabricNetwork(String name, EncapsulationType encapsulation) {
+        this.name = name;
+        this.interfaceNames = Sets.newHashSet();
+        this.encapsulation = encapsulation;
+        this.forward = ALLOW_ETH_ADDRESS_SELECTOR;
+        this.broadcast = ALLOW_ETH_ADDRESS_SELECTOR;
+        this.interfaces = Sets.newHashSet();
+        this.hostIds = Sets.newHashSet();
+        this.dirty = false;
+    }
+
+    /**
+     * Creates a DefaultFabricNetwork data by given name.
+     * The encapsulation type of the DefaultFabricNetwork will be NONE.
+     *
+     * @param name              fabric network name
+     * @return DefaultFabricNetwork instance
+     */
+    public static FabricNetwork of(String name) {
+        Objects.requireNonNull(name);
+        return new DefaultFabricNetwork(name, EncapsulationType.NONE);
+    }
+
+    /**
+     * Creates a copy of DefaultFabricNetwork instance.
+     *
+     * @param fabricNetwork DefaultFabricNetwork instance
+     * @return the copy of the DefaultFabricNetwork instance
+     */
+    public static FabricNetwork of(FabricNetwork fabricNetwork) {
+        Objects.requireNonNull(fabricNetwork);
+        DefaultFabricNetwork fabricNetworkCopy =
+                new DefaultFabricNetwork(fabricNetwork.name(), fabricNetwork.encapsulation());
+        fabricNetworkCopy.interfaceNames.addAll(fabricNetwork.interfaceNames());
+        fabricNetworkCopy.forward = (ALLOW_ETH_ADDRESS_SELECTOR) && fabricNetwork.isForward();
+        fabricNetworkCopy.broadcast = (ALLOW_ETH_ADDRESS_SELECTOR) && fabricNetwork.isBroadcast();
+        fabricNetworkCopy.interfaces.addAll(fabricNetwork.interfaces());
+        fabricNetworkCopy.hostIds.addAll(fabricNetwork.hostIds());
+        fabricNetworkCopy.setDirty(fabricNetwork.isDirty());
+        return fabricNetworkCopy;
+    }
+
+    // field queries
+
+    @Override
+    public String name() {
+        return name;
+    }
+
+    @Override
+    public Set<String> interfaceNames() {
+        return ImmutableSet.copyOf(interfaceNames);
+    }
+
+    @Override
+    public EncapsulationType encapsulation() {
+        return encapsulation;
+    }
+
+    @Override
+    public boolean isForward() {
+        return forward;
+    }
+
+    @Override
+    public boolean isBroadcast() {
+        return broadcast;
+    }
+
+    @Override
+    public Set<Interface> interfaces() {
+        return ImmutableSet.copyOf(interfaces);
+    }
+
+    @Override
+    public Set<HostId> hostIds() {
+        return ImmutableSet.copyOf(hostIds);
+    }
+
+    @Override
+    public boolean isDirty() {
+        return dirty;
+    }
+
+    @Override
+    public boolean contains(Interface iface) {
+        return interfaces.contains(iface);
+    }
+
+    @Override
+    public boolean contains(ConnectPoint port, VlanId vlanId) {
+        for (Interface iface : interfaces) {
+            if (iface.connectPoint().equals(port) && iface.vlan().equals(vlanId)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public boolean contains(DeviceId deviceId) {
+        for (Interface iface : interfaces) {
+            if (iface.connectPoint().deviceId().equals(deviceId)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public void addInterface(Interface iface) {
+        Objects.requireNonNull(iface);
+        if (interfaces.add(iface)) {
+            setDirty(true);
+        }
+    }
+
+    @Override
+    public void addHost(Host host) {
+        Objects.requireNonNull(host);
+        if (hostIds.add(host.id())) {
+            setDirty(true);
+        }
+    }
+
+    @Override
+    public void setDirty(boolean newDirty) {
+        dirty = newDirty;
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(getClass())
+                .add("name", name)
+                .add("interfaceNames", interfaceNames)
+                .add("encapsulation", encapsulation)
+                .add("forward", forward)
+                .add("broadcast", broadcast)
+                .add("interfaces", interfaces)
+                .add("hostIds", hostIds)
+                .add("isDirty", dirty)
+                .toString();
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == this) {
+            return true;
+        }
+        if (!(obj instanceof DefaultFabricNetwork)) {
+            return false;
+        }
+        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);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(name, interfaces, encapsulation, forward, broadcast);
+    }
+
+    /**
+     * Returns new builder instance.
+     *
+     * @return fabric network builder
+     */
+    public static DefaultFabricNetworkBuilder builder() {
+        return new DefaultFabricNetworkBuilder();
+    }
+
+    /**
+     * A builder class for fabric network.
+     */
+    public static final class DefaultFabricNetworkBuilder implements Builder {
+        private String name;
+        private Set<String> interfaceNames;
+        private EncapsulationType encapsulation;
+        private boolean forward;
+        private boolean broadcast;
+
+        private DefaultFabricNetworkBuilder() {
+        }
+
+        @Override
+        public Builder name(String name) {
+            this.name = name;
+            return this;
+        }
+
+        @Override
+        public Builder interfaceNames(Set<String> interfaceNames) {
+            this.interfaceNames = interfaceNames;
+            return this;
+        }
+
+        @Override
+        public Builder encapsulation(EncapsulationType encapsulation) {
+            this.encapsulation = encapsulation;
+            return this;
+        }
+
+        @Override
+        public Builder forward(boolean forward) {
+            this.forward = forward;
+            return this;
+        }
+
+        @Override
+        public Builder broadcast(boolean broadcast) {
+            this.broadcast = broadcast;
+            return this;
+        }
+
+        @Override
+        public FabricNetwork build() {
+            checkArgument(name != null, NOT_NULL_MSG, "name");
+            return new DefaultFabricNetwork(name, interfaceNames,
+                                            encapsulation, forward, broadcast);
+        }
+    }
+}
diff --git a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/DefaultFabricRoute.java b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/DefaultFabricRoute.java
new file mode 100644
index 0000000..8861f9a
--- /dev/null
+++ b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/DefaultFabricRoute.java
@@ -0,0 +1,179 @@
+/*
+ * 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.api;
+
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.IpPrefix;
+import org.onosproject.cluster.NodeId;
+
+import java.util.Objects;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Represents a route.
+ */
+public final class DefaultFabricRoute implements FabricRoute {
+
+    private static final String VERSION_MISMATCH =
+            "Prefix and next hop must be in the same address family";
+
+    private static final NodeId UNDEFINED = new NodeId("-");
+
+    private final Source source;
+    private final IpPrefix prefix;
+    private final IpAddress nextHop;
+    private final NodeId sourceNode;
+
+    /**
+     * Creates a route.
+     *
+     * @param source route source
+     * @param prefix IP prefix
+     * @param nextHop next hop IP address
+     */
+    private DefaultFabricRoute(Source source, IpPrefix prefix, IpAddress nextHop) {
+        this(source, prefix, nextHop, UNDEFINED);
+    }
+
+    /**
+     * Creates a route.
+     *
+     * @param source route source
+     * @param prefix IP prefix
+     * @param nextHop next hop IP address
+     * @param sourceNode ONOS node the route was sourced from
+     */
+    private DefaultFabricRoute(Source source, IpPrefix prefix,
+                              IpAddress nextHop, NodeId sourceNode) {
+        this.source = checkNotNull(source);
+        this.prefix = prefix;
+        this.nextHop = nextHop;
+        this.sourceNode = checkNotNull(sourceNode);
+    }
+
+    @Override
+    public Source source() {
+        return source;
+    }
+
+    @Override
+    public IpPrefix prefix() {
+        return prefix;
+    }
+
+    @Override
+    public IpAddress nextHop() {
+        return nextHop;
+    }
+
+    @Override
+    public NodeId sourceNode() {
+        return sourceNode;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(prefix, nextHop);
+    }
+
+    @Override
+    public boolean equals(Object other) {
+        if (this == other) {
+            return true;
+        }
+
+        if (!(other instanceof DefaultFabricRoute)) {
+            return false;
+        }
+
+        DefaultFabricRoute that = (DefaultFabricRoute) other;
+
+        return Objects.equals(this.prefix, that.prefix) &&
+                Objects.equals(this.nextHop, that.nextHop);
+    }
+
+    @Override
+    public String toString() {
+        return toStringHelper(this)
+                .add("prefix", prefix)
+                .add("nextHop", nextHop)
+                .toString();
+    }
+
+    /**
+     * Returns new builder instance.
+     *
+     * @return fabric route builder
+     */
+    public static DefaultFabricRouteBuilder builder() {
+        return new DefaultFabricRouteBuilder();
+    }
+
+    /**
+     * A builder class for fabric route.
+     */
+    public static final class DefaultFabricRouteBuilder implements Builder {
+        private Source source;
+        private IpPrefix prefix;
+        private IpAddress nextHop;
+        private NodeId sourceNode;
+
+        private DefaultFabricRouteBuilder() {
+        }
+
+        @Override
+        public Builder source(Source source) {
+            this.source = source;
+            return this;
+        }
+
+        @Override
+        public Builder prefix(IpPrefix prefix) {
+            this.prefix = prefix;
+            return this;
+        }
+
+        @Override
+        public Builder nextHop(IpAddress nextHop) {
+            this.nextHop = nextHop;
+            return this;
+        }
+
+        @Override
+        public Builder sourceNode(NodeId sourceNode) {
+            this.sourceNode = sourceNode;
+            return this;
+        }
+
+        @Override
+        public FabricRoute build() {
+
+            checkNotNull(prefix);
+            checkNotNull(nextHop);
+            checkArgument(prefix.version().equals(nextHop.version()), VERSION_MISMATCH);
+
+            if (sourceNode != null) {
+                return new DefaultFabricRoute(source, prefix, nextHop, sourceNode);
+            } else {
+                return new DefaultFabricRoute(source, prefix, nextHop);
+            }
+        }
+    }
+}
diff --git a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/DefaultFabricSubnet.java b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/DefaultFabricSubnet.java
new file mode 100644
index 0000000..79b1ed2
--- /dev/null
+++ b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/DefaultFabricSubnet.java
@@ -0,0 +1,194 @@
+/*
+ * 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.api;
+
+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 java.util.Objects;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+/**
+ * Configuration details for an ip subnet entry.
+ */
+public final class DefaultFabricSubnet implements FabricSubnet {
+
+    private static final String NOT_NULL_MSG = "FabricSubnet % cannot be null";
+
+    private final IpPrefix prefix;
+    private final IpAddress gatewayIp;
+    private final MacAddress gatewayMac;
+    private EncapsulationType encapsulation;
+    private final String name;
+
+    /**
+     * Creates a new subnet entry.
+     *
+     * @param prefix  an ip subnet
+     * @param gatewayIp IP of the virtual gateway
+     * @param gatewayMac MacAddress of the virtual gateway
+     * @param encapsulation encapsulation type
+     * @param name subnet name
+     */
+    private DefaultFabricSubnet(IpPrefix prefix, IpAddress gatewayIp,
+                                MacAddress gatewayMac, EncapsulationType encapsulation,
+                                String name) {
+        this.prefix = prefix;
+        this.gatewayIp = gatewayIp;
+        this.gatewayMac = gatewayMac;
+        this.encapsulation = encapsulation;
+        this.name = name;
+    }
+
+    @Override
+    public IpPrefix prefix() {
+        return prefix;
+    }
+
+    @Override
+    public IpAddress gatewayIp() {
+        return gatewayIp;
+    }
+
+    @Override
+    public MacAddress gatewayMac() {
+        return gatewayMac;
+    }
+
+    @Override
+    public EncapsulationType encapsulation() {
+        return encapsulation;
+    }
+
+    @Override
+    public String name() {
+        return name;
+    }
+
+    @Override
+    public boolean isIp4() {
+        return prefix.isIp4();
+    }
+
+    @Override
+    public boolean isIp6() {
+        return prefix.isIp6();
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(prefix, gatewayIp, gatewayMac, encapsulation, name);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == this) {
+            return true;
+        }
+        if (!(obj instanceof DefaultFabricSubnet)) {
+            return false;
+        }
+        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);
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(getClass())
+                .add("prefix", prefix)
+                .add("gatewayIp", gatewayIp)
+                .add("gatewayMac", gatewayMac)
+                .add("encapsulation", encapsulation)
+                .add("name", name)
+                .toString();
+    }
+
+    /**
+     * Returns new builder instance.
+     *
+     * @return fabric IP subnet builder
+     */
+    public static DefaultSubnetBuilder builder() {
+        return new DefaultSubnetBuilder();
+    }
+
+    /**
+     * A builder class for Ip Subnet.
+     */
+    public static final class DefaultSubnetBuilder implements Builder {
+        private IpPrefix ipPrefix;
+        private IpAddress gatewayIp;
+        private MacAddress gatewayMac;
+        private EncapsulationType encapsulation;
+        private String name;
+
+        private DefaultSubnetBuilder() {
+        }
+
+        @Override
+        public Builder ipPrefix(IpPrefix ipPrefix) {
+            this.ipPrefix = ipPrefix;
+            return this;
+        }
+
+        @Override
+        public Builder gatewayIp(IpAddress gatewayIp) {
+            this.gatewayIp = gatewayIp;
+            return this;
+        }
+
+        @Override
+        public Builder gatewayMac(MacAddress gatewayMac) {
+            this.gatewayMac = gatewayMac;
+            return this;
+        }
+
+        @Override
+        public Builder encapsulation(EncapsulationType encapsulation) {
+            this.encapsulation = encapsulation;
+            return this;
+        }
+
+        @Override
+        public Builder name(String networkName) {
+            this.name = networkName;
+            return this;
+        }
+
+        @Override
+        public FabricSubnet build() {
+            checkArgument(ipPrefix != 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");
+
+            if (this.encapsulation == null) {
+                encapsulation = EncapsulationType.NONE;
+            }
+
+            return new DefaultFabricSubnet(ipPrefix, gatewayIp, gatewayMac,
+                                                            encapsulation, name);
+        }
+    }
+}
diff --git a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/FabricNetwork.java b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/FabricNetwork.java
new file mode 100644
index 0000000..bae189d
--- /dev/null
+++ b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/FabricNetwork.java
@@ -0,0 +1,188 @@
+/*
+ * 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.api;
+
+import org.onlab.packet.VlanId;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.EncapsulationType;
+import org.onosproject.net.Host;
+import org.onosproject.net.HostId;
+import org.onosproject.net.intf.Interface;
+
+import java.util.Set;
+
+/**
+ * Interface of fabric network.
+ */
+public interface FabricNetwork {
+
+    /**
+     * Gets DefaultFabricNetwork name.
+     *
+     * @return the name of DefaultFabricNetwork
+     */
+    String name();
+
+    /**
+     * Gets DefaultFabricNetwork interfaceNames.
+     *
+     * @return the interfaceNames of DefaultFabricNetwork
+     */
+    Set<String> interfaceNames();
+
+    /**
+     * Gets DefaultFabricNetwork encapsulation type.
+     *
+     * @return the encapsulation type of DefaultFabricNetwork
+     */
+    EncapsulationType encapsulation();
+
+    /**
+     * Gets DefaultFabricNetwork forward flag.
+     *
+     * @return the forward flag of DefaultFabricNetwork
+     */
+    boolean isForward();
+
+    /**
+     * Gets DefaultFabricNetwork broadcast flag.
+     *
+     * @return the broadcast flag of DefaultFabricNetwork
+     */
+    boolean isBroadcast();
+
+    /**
+     * Gets DefaultFabricNetwork interfaces.
+     *
+     * @return the interfaces of DefaultFabricNetwork
+     */
+    Set<Interface> interfaces();
+
+    /**
+     * Gets DefaultFabricNetwork hosts.
+     *
+     * @return the hosts of DefaultFabricNetwork
+     */
+    Set<HostId> hostIds();
+
+    /**
+     * Gets DefaultFabricNetwork isDirty flag.
+     *
+     * @return the isDirty flag of DefaultFabricNetwork
+     */
+    boolean isDirty();
+
+    /**
+     * Checks if the interface is of DefaultFabricNetwork.
+     *
+     * @param iface the interface to be checked
+     * @return true if DefaultFabricNetwork contains the interface
+     */
+    boolean contains(Interface iface);
+
+    /**
+     * Checks if the ConnectPoint and Vlan is of DefaultFabricNetwork.
+     *
+     * @param port the ConnectPoint to be checked
+     * @param vlanId the VlanId of the ConnectPoint to be checked
+     * @return true if DefaultFabricNetwork contains the interface of the ConnnectPoint and VlanId
+     */
+    boolean contains(ConnectPoint port, VlanId vlanId);
+
+    /**
+     * Checks if the DeviceId is of DefaultFabricNetwork.
+     *
+     * @param deviceId the DeviceId to be checked
+     * @return true if DefaultFabricNetwork contains any interface of the DeviceId
+     */
+    boolean contains(DeviceId deviceId);
+
+    /**
+     * Adds interface to DefaultFabricNetwork.
+     *
+     * @param iface the Interface to be added
+     */
+    void addInterface(Interface iface);
+
+    /**
+     * Adds host to DefaultFabricNetwork.
+     *
+     * @param host the Host to be added
+     */
+    void addHost(Host host);
+
+    /**
+     * Sets DefaultFabricNetwork isDirty flag.
+     *
+     * @param newDirty the isDirty flag to be set
+     */
+    void setDirty(boolean newDirty);
+
+    /**
+     * Builder of FabricNetwork.
+     */
+    interface Builder {
+
+        /**
+         * Returns FabricNetwork builder with supplied network name.
+         *
+         * @param name network name
+         * @return FabricNetwork instance builder
+         */
+        Builder name(String name);
+
+        /**
+         * Returns FabricNetwork builder with supplied interface names.
+         *
+         * @param interfaceNames interface names
+         * @return FabricNetwork instance builder
+         */
+        Builder interfaceNames(Set<String> interfaceNames);
+
+        /**
+         * Returns FabricNetwork builder with supplied encapsulation type.
+         *
+         * @param encapsulation encapsulation type
+         * @return FabricNetwork instance builder
+         */
+        Builder encapsulation(EncapsulationType encapsulation);
+
+        /**
+         * Returns FabricNetwork builder with supplied forward flag.
+         *
+         * @param forward forward flag
+         * @return FabricNetwork instance builder
+         */
+        Builder forward(boolean forward);
+
+        /**
+         * Returns FabricNetwork builder with supplied broadcast flag.
+         *
+         * @param broadcast broadcast flag
+         * @return FabricNetwork instance builder
+         */
+        Builder broadcast(boolean broadcast);
+
+        /**
+         * Builds an immutable FabricNetwork instance.
+         *
+         * @return FabricNetwork instance
+         */
+        FabricNetwork build();
+    }
+}
diff --git a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/FabricRoute.java b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/FabricRoute.java
new file mode 100644
index 0000000..f12260a
--- /dev/null
+++ b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/FabricRoute.java
@@ -0,0 +1,124 @@
+/*
+ * 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.api;
+
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.IpPrefix;
+import org.onosproject.cluster.NodeId;
+
+/**
+ * Interface of fabric route.
+ */
+public interface FabricRoute {
+
+    /**
+     * Source of the route.
+     */
+    enum Source {
+        /**
+         * Route came from the iBGP route source.
+         */
+        BGP,
+
+        /**
+         * Route came from the FPM route source.
+         */
+        FPM,
+
+        /**
+         * Route can from the static route source.
+         */
+        STATIC,
+
+        /**
+         * Route source was not defined.
+         */
+        UNDEFINED
+    }
+
+    /**
+     * Returns the route source.
+     *
+     * @return route source
+     */
+    Source source();
+
+    /**
+     * Returns the IP prefix of the route.
+     *
+     * @return IP prefix
+     */
+    IpPrefix prefix();
+
+    /**
+     * Returns the next hop IP address.
+     *
+     * @return next hop
+     */
+    IpAddress nextHop();
+
+    /**
+     * Returns the ONOS node the route was sourced from.
+     *
+     * @return ONOS node ID
+     */
+    NodeId sourceNode();
+
+    /**
+     * Builder of FabricRoute.
+     */
+    interface Builder {
+
+        /**
+         * Returns FabricRoute builder with supplied source.
+         *
+         * @param source source of route
+         * @return FabricRoute instance builder
+         */
+        Builder source(Source source);
+
+        /**
+         * Returns FabricRoute builder with supplied IP prefix.
+         *
+         * @param prefix IP prefix
+         * @return FabricRoute instance builder
+         */
+        Builder prefix(IpPrefix prefix);
+
+        /**
+         * Returns Fabric builder with supplied next hop.
+         *
+         * @param nextHop next hop
+         * @return FabricRoute instance builder
+         */
+        Builder nextHop(IpAddress nextHop);
+
+        /**
+         * Returns Fabric builder with supplied source node identifier.
+         *
+         * @param sourceNode source node identifier
+         * @return FabricRoute instance builder
+         */
+        Builder sourceNode(NodeId sourceNode);
+
+        /**
+         * Builds an immutable FabricRoute instance.
+         *
+         * @return FabricRoute instance
+         */
+        FabricRoute build();
+    }
+}
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
new file mode 100644
index 0000000..2e7ba3c
--- /dev/null
+++ b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/FabricSubnet.java
@@ -0,0 +1,130 @@
+/*
+ * 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.api;
+
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.IpPrefix;
+import org.onlab.packet.MacAddress;
+import org.onosproject.net.EncapsulationType;
+
+/**
+ * Interface of FabricSubnet.
+ */
+public interface FabricSubnet {
+
+    /**
+     * Gets the IP subnet of the IP subnet entry.
+     *
+     * @return the IP subnet
+     */
+    IpPrefix prefix();
+
+    /**
+     * Gets the virtual gateway IP address of the IP subnet entry.
+     *
+     * @return the virtual gateway IP address
+     */
+    IpAddress gatewayIp();
+
+    /**
+     * Gets the virtual gateway Mac address of the IP subnet entry.
+     *
+     * @return the virtuai gateway Mac address
+     */
+    MacAddress gatewayMac();
+
+    /**
+     * Gets the encapsulation type of IP subnet entry.
+     *
+     * @return the encapsulation type
+     */
+    EncapsulationType encapsulation();
+
+    /**
+     * Gets the subnet name.
+     *
+     * @return the subnet name
+     */
+    String name();
+
+    /**
+     * Tests whether the IP version of this entry is IPv4.
+     *
+     * @return true if the IP version of this entry is IPv4, otherwise false.
+     */
+    boolean isIp4();
+
+    /**
+     * Tests whether the IP version of this entry is IPv6.
+     *
+     * @return true if the IP version of this entry is IPv6, otherwise false.
+     */
+    boolean isIp6();
+
+    /**
+     * Builder of Ip Subnet.
+     */
+    interface Builder {
+
+        /**
+         * Returns FabricSubnet builder with supplied IpPrefix.
+         *
+         * @param ipPrefix IP prefix
+         * @return FabricSubnet instance builder
+         */
+        Builder ipPrefix(IpPrefix ipPrefix);
+
+        /**
+         * Returns FabricSubnet builder with supplied gatewayIp.
+         *
+         * @param gatewayIp gateway IP
+         * @return FabricSubnet instance builder
+         */
+        Builder gatewayIp(IpAddress gatewayIp);
+
+        /**
+         * Returns FabricSubnet builder with supplied gatewayMac.
+         *
+         * @param gatewayMac gateway MAC
+         * @return FabricSubnet instance builder
+         */
+        Builder gatewayMac(MacAddress gatewayMac);
+
+        /**
+         * Returns FabricSubnet builder with supplied encapsulation type.
+         *
+         * @param encapsulation encapsulation type
+         * @return FabricSubnet instance builder
+         */
+        Builder encapsulation(EncapsulationType encapsulation);
+
+        /**
+         * Returns FabricSubnet builder with supplied subnet name.
+         *
+         * @param name subnet name
+         * @return FabricSubnet instance builder
+         */
+        Builder name(String name);
+
+        /**
+         * Builds an immutable FabricSubnet instance.
+         *
+         * @return FabricSubnet instance
+         */
+        FabricSubnet build();
+    }
+}
diff --git a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/IpSubnet.java b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/IpSubnet.java
deleted file mode 100644
index d307e7f..0000000
--- a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/IpSubnet.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * 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.api;
-
-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 java.util.Objects;
-
-/**
- * Configuration details for an ip subnet entry.
- */
-public class IpSubnet {
-    private final IpPrefix ipPrefix;
-    private final IpAddress gatewayIp;
-    private final MacAddress gatewayMac;
-    private EncapsulationType encapsulation;
-    private final String l2NetworkName;
-
-    /**
-     * Creates a new ip subnet entry.
-     *
-     * @param ipPrefix  an ip subnet
-     * @param gatewayIp IP of the virtual gateway
-     * @param gatewayMac MacAddress of the virtual gateway
-     * @param encapsulation EnacaptulatioType for routes related to this subnet
-     * @param l2NetworkName Name of L2 Network this subnet is bound
-     */
-    public IpSubnet(IpPrefix ipPrefix, IpAddress gatewayIp, MacAddress gatewayMac,
-                    EncapsulationType encapsulation, String l2NetworkName) {
-        this.ipPrefix = ipPrefix;
-        this.gatewayIp = gatewayIp;
-        this.gatewayMac = gatewayMac;
-        this.encapsulation = EncapsulationType.NONE;
-        this.l2NetworkName = l2NetworkName;
-    }
-
-    /**
-     * Gets the ip subnet of the ip subnet entry.
-     *
-     * @return the ip subnet
-     */
-    public IpPrefix ipPrefix() {
-        return ipPrefix;
-    }
-
-    /**
-     * Gets the virtual gateway IP address of the ip subnet entry.
-     *
-     * @return the virtual gateway IP address
-     */
-    public IpAddress gatewayIp() {
-        return gatewayIp;
-    }
-
-    /**
-     * Gets the virtual gateway Mac address of the ip subnet entry.
-     *
-     * @return the virtuai gateway Mac address
-     */
-    public MacAddress gatewayMac() {
-        return gatewayMac;
-    }
-
-    /**
-     * Gets the encapsulation type of ip subnet entry.
-     *
-     * @return the encapsulation type
-     */
-    public EncapsulationType encapsulation() {
-        return encapsulation;
-    }
-
-    /**
-     * Gets the name of L2 Network this subnet is bound.
-     *
-     * @return the l2Network name this subnet is allocated
-     */
-    public String l2NetworkName() {
-        return l2NetworkName;
-    }
-
-    /**
-     * Tests whether the IP version of this entry is IPv4.
-     *
-     * @return true if the IP version of this entry is IPv4, otherwise false.
-     */
-    public boolean isIp4() {
-        return ipPrefix.isIp4();
-    }
-
-    /**
-     * Tests whether the IP version of this entry is IPv6.
-     *
-     * @return true if the IP version of this entry is IPv6, otherwise false.
-     */
-    public boolean isIp6() {
-        return ipPrefix.isIp6();
-    }
-
-    @Override
-    public int hashCode() {
-        return Objects.hash(ipPrefix, gatewayIp, gatewayMac, encapsulation, l2NetworkName);
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (obj == this) {
-            return true;
-        }
-        if (!(obj instanceof IpSubnet)) {
-            return false;
-        }
-        IpSubnet that = (IpSubnet) obj;
-        return Objects.equals(this.ipPrefix, that.ipPrefix)
-               && Objects.equals(this.gatewayIp, that.gatewayIp)
-               && Objects.equals(this.gatewayMac, that.gatewayMac)
-               && Objects.equals(this.encapsulation, that.encapsulation)
-               && Objects.equals(this.l2NetworkName, that.l2NetworkName);
-    }
-
-    @Override
-    public String toString() {
-        return MoreObjects.toStringHelper(getClass())
-                .add("ipPrefix", ipPrefix)
-                .add("gatewayIp", gatewayIp)
-                .add("gatewayMac", gatewayMac)
-                .add("encapsulation", encapsulation)
-                .add("l2NetworkName", l2NetworkName)
-                .toString();
-    }
-}
diff --git a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/L2Network.java b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/L2Network.java
deleted file mode 100644
index fc28ae2..0000000
--- a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/L2Network.java
+++ /dev/null
@@ -1,306 +0,0 @@
-/*
- * 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.api;
-
-import com.google.common.base.MoreObjects;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Sets;
-import org.onlab.packet.VlanId;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.EncapsulationType;
-import org.onosproject.net.Host;
-import org.onosproject.net.HostId;
-import org.onosproject.net.intf.Interface;
-
-import java.util.Collection;
-import java.util.Objects;
-import java.util.Set;
-
-import static org.onosproject.simplefabric.api.Constants.ALLOW_ETH_ADDRESS_SELECTOR;
-
-
-/**
- * Class stores a L2Network information.
- */
-public final class L2Network {
-
-    private String name;                  // also for network configuration
-    private Set<String> interfaceNames;   // also for network configuration
-    private EncapsulationType encapsulation;  // also for network configuration
-    private boolean l2Forward;            // do l2Forward (default:true) or not
-    private boolean l2Broadcast;          // do l2Broadcast (default:true) or not
-
-    /* status variables */
-    private Set<Interface> interfaces;    // available interfaces from interfaceNames
-    private Set<HostId> hostIds;          // available hosts from interfaces
-    private boolean dirty;
-
-    /**
-     * Constructs a L2Network data for Config value.
-     *
-     * @param name the given name
-     * @param ifaceNames the interface names
-     * @param encapsulation the encapsulation type
-     * @param l2Forward flag for l2Forward intents to be installed or not
-     * @param l2Broadcast flag for l2Broadcast intents to be installed or not
-     */
-    public L2Network(String name, Collection<String> ifaceNames, EncapsulationType encapsulation,
-              boolean l2Forward, boolean l2Broadcast) {
-        this.name = name;
-        this.interfaceNames = Sets.newHashSet();
-        this.interfaceNames.addAll(ifaceNames);
-        this.encapsulation = encapsulation;
-        this.l2Forward = (ALLOW_ETH_ADDRESS_SELECTOR) ? l2Forward : false;
-        this.l2Broadcast = (ALLOW_ETH_ADDRESS_SELECTOR) ? l2Broadcast : false;
-        this.interfaces = Sets.newHashSet();
-        this.hostIds = Sets.newHashSet();
-        this.dirty = false;
-    }
-
-    /**
-     * Constructs a L2Network data by given name and encapsulation type.
-     *
-     * @param name the given name
-     * @param encapsulation the encapsulation type
-     */
-    private L2Network(String name, EncapsulationType encapsulation) {
-        this.name = name;
-        this.interfaceNames = Sets.newHashSet();
-        this.encapsulation = encapsulation;
-        this.l2Forward = (ALLOW_ETH_ADDRESS_SELECTOR) ? true : false;
-        this.l2Broadcast = (ALLOW_ETH_ADDRESS_SELECTOR) ? true : false;
-        this.interfaces = Sets.newHashSet();
-        this.hostIds = Sets.newHashSet();
-        this.dirty = false;
-    }
-
-    /**
-     * Creates a L2Network data by given name.
-     * The encapsulation type of the L2Network will be NONE.
-     *
-     * @param name the given name
-     * @return the L2Network data
-     */
-    public static L2Network of(String name) {
-        Objects.requireNonNull(name);
-        return new L2Network(name, EncapsulationType.NONE);
-    }
-
-    /**
-     * Creates a copy of L2Network data.
-     *
-     * @param l2Network the L2Network data
-     * @return the copy of the L2Network data
-     */
-    public static L2Network of(L2Network l2Network) {
-        Objects.requireNonNull(l2Network);
-        L2Network l2NetworkCopy = new L2Network(l2Network.name(), l2Network.encapsulation());
-        l2NetworkCopy.interfaceNames.addAll(l2Network.interfaceNames());
-        l2NetworkCopy.l2Forward = (ALLOW_ETH_ADDRESS_SELECTOR) ? l2Network.l2Forward() : false;
-        l2NetworkCopy.l2Broadcast = (ALLOW_ETH_ADDRESS_SELECTOR) ? l2Network.l2Broadcast() : false;
-        l2NetworkCopy.interfaces.addAll(l2Network.interfaces());
-        l2NetworkCopy.hostIds.addAll(l2Network.hostIds());
-        l2NetworkCopy.setDirty(l2Network.dirty());
-        return l2NetworkCopy;
-    }
-
-    // field queries
-
-    /**
-     * Gets L2Network name.
-     *
-     * @return the name of L2Network
-     */
-    public String name() {
-        return name;
-    }
-
-    /**
-     * Gets L2Network interfaceNames.
-     *
-     * @return the interfaceNames of L2Network
-     */
-    public Set<String> interfaceNames() {
-        return ImmutableSet.copyOf(interfaceNames);
-    }
-
-    /**
-     * Gets L2Network encapsulation type.
-     *
-     * @return the encapsulation type of L2Network
-     */
-    public EncapsulationType encapsulation() {
-        return encapsulation;
-    }
-
-    /**
-     * Gets L2Network l2Forward flag.
-     *
-     * @return the l2Forward flag of L2Network
-     */
-    public boolean l2Forward() {
-        return l2Forward;
-    }
-
-    /**
-     * Gets L2Network l2Broadcast flag.
-     *
-     * @return the l2Broadcast flag of L2Network
-     */
-    public boolean l2Broadcast() {
-        return l2Broadcast;
-    }
-
-    /**
-     * Gets L2Network interfaces.
-     *
-     * @return the interfaces of L2Network
-     */
-    public Set<Interface> interfaces() {
-        return ImmutableSet.copyOf(interfaces);
-    }
-
-    /**
-     * Gets L2Network hosts.
-     *
-     * @return the hosts of L2Network
-     */
-    public Set<HostId> hostIds() {
-        return ImmutableSet.copyOf(hostIds);
-    }
-
-    /**
-     * Gets L2Network dirty flag.
-     *
-     * @return the dirty flag of L2Network
-     */
-    public boolean dirty() {
-        return dirty;
-    }
-
-    /**
-     * Checks if the interface is of L2Network.
-     *
-     * @param iface the interface to be checked
-     * @return true if L2Network contains the interface
-     */
-    public boolean contains(Interface iface) {
-        return interfaces.contains(iface);
-    }
-
-    /**
-     * Checks if the ConnectPoint and Vlan is of L2Network.
-     *
-     * @param port the ConnectPoint to be checked
-     * @param vlanId the VlanId of the ConnectPoint to be checked
-     * @return true if L2Network contains the interface of the ConnnectPoint and VlanId
-     */
-    public boolean contains(ConnectPoint port, VlanId vlanId) {
-        for (Interface iface : interfaces) {
-            if (iface.connectPoint().equals(port) && iface.vlan().equals(vlanId)) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    /**
-     * Checks if the DeviceId is of L2Network.
-     *
-     * @param deviceId the DeviceId to be checked
-     * @return true if L2Network contains any interface of the DeviceId
-     */
-    public boolean contains(DeviceId deviceId) {
-        for (Interface iface : interfaces) {
-            if (iface.connectPoint().deviceId().equals(deviceId)) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    /**
-     * Adds interface to L2Network.
-     *
-     * @param iface the Interface to be added
-     */
-    public void addInterface(Interface iface) {
-        Objects.requireNonNull(iface);
-        if (interfaces.add(iface)) {
-            setDirty(true);
-        }
-    }
-
-    /**
-     * Adds host to L2Network.
-     *
-     * @param host the Host to be added
-     */
-    public void addHost(Host host) {
-        Objects.requireNonNull(host);
-        if (hostIds.add(host.id())) {
-            setDirty(true);
-        }
-    }
-
-    /**
-     * Sets L2Network dirty flag.
-     *
-     * @param newDirty the dirty flag to be set
-     */
-    public void setDirty(boolean newDirty) {
-        dirty = newDirty;
-    }
-
-    @Override
-    public String toString() {
-        return MoreObjects.toStringHelper(getClass())
-                .add("name", name)
-                .add("interfaceNames", interfaceNames)
-                .add("encapsulation", encapsulation)
-                .add("l2Forward", l2Forward)
-                .add("l2Broadcast", l2Broadcast)
-                .add("interfaces", interfaces)
-                .add("hostIds", hostIds)
-                .add("dirty", dirty)
-                .toString();
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (obj == this) {
-            return true;
-        }
-        if (!(obj instanceof L2Network)) {
-            return false;
-        }
-        L2Network other = (L2Network) obj;
-        return Objects.equals(other.name, this.name)
-               && Objects.equals(other.interfaceNames, this.interfaceNames)
-               && Objects.equals(other.encapsulation, this.encapsulation)
-               && Objects.equals(other.l2Forward, this.l2Forward)
-               && Objects.equals(other.l2Broadcast, this.l2Broadcast)
-               && Objects.equals(other.interfaces, this.interfaces)
-               && Objects.equals(other.hostIds, this.hostIds);
-    }
-
-    @Override
-    public int hashCode() {
-        return Objects.hash(name, interfaces, encapsulation, l2Forward, l2Broadcast);
-    }
-}
diff --git a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/Route.java b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/Route.java
deleted file mode 100644
index a008193..0000000
--- a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/Route.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * 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.
- */
-/*
- * local copy of onos/incubator/api/src/main/java/org/onosproject/incubator/net/routing/Route.java
- * to remove dependency on onos.incubator.routing services, since 2017-08-09.
- */
-
-package org.onosproject.simplefabric.api;
-
-import org.onlab.packet.IpAddress;
-import org.onlab.packet.IpPrefix;
-import org.onosproject.cluster.NodeId;
-
-import java.util.Objects;
-
-import static com.google.common.base.MoreObjects.toStringHelper;
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-
-/**
- * Represents a route.
- */
-public class Route {
-
-    private static final String VERSION_MISMATCH =
-            "Prefix and next hop must be in the same address family";
-
-    private static final NodeId UNDEFINED = new NodeId("-");
-
-    /**
-     * Source of the route.
-     */
-    public enum Source {
-        /**
-         * Route came from the iBGP route source.
-         */
-        BGP,
-
-        /**
-         * Route came from the FPM route source.
-         */
-        FPM,
-
-        /**
-         * Route can from the static route source.
-         */
-        STATIC,
-
-        /**
-         * Route source was not defined.
-         */
-        UNDEFINED
-    }
-
-    private final Source source;
-    private final IpPrefix prefix;
-    private final IpAddress nextHop;
-    private final NodeId sourceNode;
-
-    /**
-     * Creates a route.
-     *
-     * @param source route source
-     * @param prefix IP prefix
-     * @param nextHop next hop IP address
-     */
-    public Route(Source source, IpPrefix prefix, IpAddress nextHop) {
-        this(source, prefix, nextHop, UNDEFINED);
-    }
-
-    /**
-     * Creates a route.
-     *
-     * @param source route source
-     * @param prefix IP prefix
-     * @param nextHop next hop IP address
-     * @param sourceNode ONOS node the route was sourced from
-     */
-    public Route(Source source, IpPrefix prefix, IpAddress nextHop, NodeId sourceNode) {
-        checkNotNull(prefix);
-        checkNotNull(nextHop);
-        checkArgument(prefix.version().equals(nextHop.version()), VERSION_MISMATCH);
-
-        this.source = checkNotNull(source);
-        this.prefix = prefix;
-        this.nextHop = nextHop;
-        this.sourceNode = checkNotNull(sourceNode);
-    }
-
-    /**
-     * Returns the route source.
-     *
-     * @return route source
-     */
-    public Source source() {
-        return source;
-    }
-
-    /**
-     * Returns the IP prefix of the route.
-     *
-     * @return IP prefix
-     */
-    public IpPrefix prefix() {
-        return prefix;
-    }
-
-    /**
-     * Returns the next hop IP address.
-     *
-     * @return next hop
-     */
-    public IpAddress nextHop() {
-        return nextHop;
-    }
-
-    /**
-     * Returns the ONOS node the route was sourced from.
-     *
-     * @return ONOS node ID
-     */
-    public NodeId sourceNode() {
-        return sourceNode;
-    }
-
-    @Override
-    public int hashCode() {
-        return Objects.hash(prefix, nextHop);
-    }
-
-    @Override
-    public boolean equals(Object other) {
-        if (this == other) {
-            return true;
-        }
-
-        if (!(other instanceof Route)) {
-            return false;
-        }
-
-        Route that = (Route) other;
-
-        return Objects.equals(this.prefix, that.prefix) &&
-                Objects.equals(this.nextHop, that.nextHop);
-    }
-
-    @Override
-    public String toString() {
-        return toStringHelper(this)
-                .add("prefix", prefix)
-                .add("nextHop", nextHop)
-                .toString();
-    }
-}
diff --git a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/SimpleFabricService.java b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/SimpleFabricService.java
index 2687c9d..33b9c5e 100644
--- a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/SimpleFabricService.java
+++ b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/SimpleFabricService.java
@@ -39,105 +39,104 @@
      *
      * @return appId of simple fabric app
      */
-    ApplicationId getAppId();
+    ApplicationId appId();
 
     /**
-     * Gets all the l2Networks.
+     * Gets all the fabric networks.
      *
-     * @return all the l2Networks
+     * @return all the fabric networks
      */
-    Collection<L2Network> getL2Networks();
+    Collection<FabricNetwork> fabricNetworks();
 
     /**
-     * Retrieves the entire set of ipSubnets configuration.
+     * Retrieves the entire set of fabricSubnets configuration.
      *
-     * @return all the ipSubnets
+     * @return all the fabricSubnets
      */
-    Set<IpSubnet> getIpSubnets();
+    Set<FabricSubnet> defaultFabricSubnets();
 
     /**
      * Retrieves the entire set of static routes to outer networks.
      *
      * @return the set of static routes to outer networks.
      */
-    Set<Route> getBorderRoutes();
+    Set<FabricRoute> fabricRoutes();
 
     /**
-     * Evaluates whether a mac is of Virtual Gateway Mac Addresses.
+     * Evaluates whether a MAC is of virtual gateway MAC addresses.
      *
-     * @param mac the MacAddress to evaluate
-     * @return true if the mac is of any Vitrual Gateway Mac Address of ipSubnets
+     * @param mac the MAC address to evaluate
+     * @return true if the mac is of any virtual gateway MAC address of fabricSubnets
      */
-    boolean isVMac(MacAddress mac);
+    boolean isVirtualGatewayMac(MacAddress mac);
 
     /**
-     * Evaluates whether an Interface belongs to l2Networks.
+     * Evaluates whether an interface belongs to fabric network or not.
      *
      * @param intf the interface to evaluate
-     * @return true if the inteface belongs to l2Networks configed, otherwise false
+     * @return true if the interface belongs to fabric network, otherwise false
      */
-    boolean isL2NetworkInterface(Interface intf);
+    boolean isFabricNetworkInterface(Interface intf);
 
     /**
-     * Find Virtual Gateway Mac Address for Local Subnet Virtual Gateway Ip.
+     * Finds virtual gateway MAC address for local subnet virtual gateway IP.
      *
-     * @param ip the ip to check for Virtual Gateway Ip
-     * @return mac address of virtual gateway
+     * @param ip the IP to check for virtual gateway IP
+     * @return MAC address of virtual gateway
      */
-    MacAddress findVMacForIp(IpAddress ip);
+    MacAddress vMacForIp(IpAddress ip);
 
     /**
-     * Finds the L2 Network with given port and vlanId.
+     * Finds the L2 fabric network with given port and vlanId.
      *
      * @param port the port to be matched
      * @param vlanId the vlanId to be matched
      * @return the L2 Network for specific port and vlanId or null
      */
-    L2Network findL2Network(ConnectPoint port, VlanId vlanId);
+    FabricNetwork fabricNetwork(ConnectPoint port, VlanId vlanId);
 
     /**
-     * Finds the L2 Network of the name.
+     * Finds the fabric network by its name.
      *
      * @param name the name to be matched
-     * @return the L2 Network for specific name
+     * @return the fabric network
      */
-    L2Network findL2Network(String name);
+    FabricNetwork fabricNetwork(String name);
 
     /**
-     * Finds the IpSubnet containing the ipAddress.
+     * Finds the FabricSubnet which contains the given IP address.
      *
-     * @param ipAddress the ipAddress to be matched
-     * @return the IpSubnet for specific ipAddress
+     * @param ipAddress the IP address to be matched
+     * @return the FabricSubnet
      */
-    IpSubnet findIpSubnet(IpAddress ipAddress);
+    FabricSubnet fabricSubnet(IpAddress ipAddress);
 
     /**
-     * Finds the Border Route containing the ipAddress.
-     * ASSUME: ipAddress is out of ipSubnets
+     * Finds the FabricRoute which contains the given IP address.
      *
-     * @param ipAddress the ipAddress to be matched
-     * @return the IpSubnet for specific ipAddress
+     * @param ipAddress the IP address to be matched
+     * @return the FabricRoute
      */
-    Route findBorderRoute(IpAddress ipAddress);
+    FabricRoute fabricRoute(IpAddress ipAddress);
 
     /**
-     * Finds the network interface related to the host.
+     * Finds the network interface which associated with the host.
      *
      * @param host the host
-     * @return the interface related to the host
+     * @return the interface associated with the host
      */
-    Interface findHostInterface(Host host);
+    Interface hostInterface(Host host);
 
     /**
-     * Sends Neighbour Query (ARP or NDP) to Find Host Location.
+     * Sends neighbour query (ARP or NDP) to find host location.
      *
-     * @param ip the ip address to resolve
-     * @return true if request mac packets are emitted. otherwise false
+     * @param ip the IP address to resolve
+     * @return true if request MAC packets are emitted, false otherwise
      */
     boolean requestMac(IpAddress ip);
 
     /**
-     * Sends Dump Event to all SimpleFabricListeners to Dump Info on the Subject.
+     * Sends dump event to all SimpleFabricListeners to dump info on the subject.
      *
      * @param subject the subject to dump
      * @param out the output stream to dump
@@ -145,13 +144,12 @@
     void dumpToStream(String subject, OutputStream out);
 
     /**
-     * Triggers to send Refresh Notification to all sub modules.
+     * Triggers to send refresh notification to all sub modules.
      */
     void triggerRefresh();
 
     /**
-     * Triggers to send Flush Notification to all sub modules.
+     * Triggers to send flush notification to all sub modules.
      */
     void triggerFlush();
-
 }