Refactor: split api from SONA simple fabric

Change-Id: Icbdb10b730af29057097b14df8ddc377f4107853
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
new file mode 100644
index 0000000..d307e7f
--- /dev/null
+++ b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/IpSubnet.java
@@ -0,0 +1,148 @@
+/*
+ * 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
new file mode 100644
index 0000000..0b38f48
--- /dev/null
+++ b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/L2Network.java
@@ -0,0 +1,304 @@
+/*
+ * 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.intf.Interface;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Host;
+import org.onosproject.net.HostId;
+import org.onosproject.net.EncapsulationType;
+
+import java.util.Collection;
+import java.util.Objects;
+import java.util.Set;
+
+
+/**
+ * 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 = (SimpleFabricService.ALLOW_ETH_ADDRESS_SELECTOR) ? l2Forward : false;
+        this.l2Broadcast = (SimpleFabricService.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 = (SimpleFabricService.ALLOW_ETH_ADDRESS_SELECTOR) ? true : false;
+        this.l2Broadcast = (SimpleFabricService.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 = (SimpleFabricService.ALLOW_ETH_ADDRESS_SELECTOR) ? l2Network.l2Forward() : false;
+        l2NetworkCopy.l2Broadcast = (SimpleFabricService.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
new file mode 100644
index 0000000..a008193
--- /dev/null
+++ b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/Route.java
@@ -0,0 +1,167 @@
+/*
+ * 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/SimpleFabricEvent.java b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/SimpleFabricEvent.java
new file mode 100644
index 0000000..aac465b
--- /dev/null
+++ b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/SimpleFabricEvent.java
@@ -0,0 +1,65 @@
+/*
+ * 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.onosproject.event.AbstractEvent;
+
+import java.io.OutputStream;
+import java.io.PrintStream;
+
+/**
+ * Describes an interface event.
+ */
+public class SimpleFabricEvent extends AbstractEvent<SimpleFabricEvent.Type, String> {
+
+    public enum Type {
+        SIMPLE_FABRIC_UPDATED,  /* Indicates topology info has been updated. */
+        SIMPLE_FABRIC_FLUSH,    /* Indicates flush triggered. */
+        SIMPLE_FABRIC_IDLE,     /* Indicates idle check. */
+        SIMPLE_FABRIC_DUMP      /* Indicates to dump info on the subject to output stream. */
+    }
+
+    private PrintStream printStream;  // output stream for SIMPLE_FABRIC_DUMP
+
+    /**
+     * Creates an interface event with type and subject.
+     *
+     * @param type event type
+     * @param subject subject for dump event or dummy
+     */
+    public SimpleFabricEvent(Type type, String subject) {
+        super(type, subject);   /* subject is dummy */
+    }
+
+    /**
+     * Creates an interface event with type, subject and output stream for dump.
+     *
+     * @param type event type
+     * @param subject subject for dump event
+     * @param out output stream to dump out
+     */
+    public SimpleFabricEvent(Type type, String subject, OutputStream out) {
+        super(type, subject);   /* subject is dummy */
+        printStream = new PrintStream(out, true);
+    }
+
+    public PrintStream out() {
+        return printStream;
+    }
+
+}
+
diff --git a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/SimpleFabricListener.java b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/SimpleFabricListener.java
new file mode 100644
index 0000000..25bf529
--- /dev/null
+++ b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/SimpleFabricListener.java
@@ -0,0 +1,25 @@
+/*
+ * 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.onosproject.event.EventListener;
+
+/**
+ * Entity capable of receiving alarm related events.
+ */
+public interface SimpleFabricListener extends EventListener<SimpleFabricEvent> {
+}
+
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
new file mode 100644
index 0000000..18464dc
--- /dev/null
+++ b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/SimpleFabricService.java
@@ -0,0 +1,189 @@
+/*
+ * 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.MacAddress;
+import org.onlab.packet.VlanId;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.event.ListenerService;
+import org.onosproject.net.intf.Interface;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.Host;
+
+import java.io.OutputStream;
+import java.util.Set;
+import java.util.Collection;
+
+/**
+ * Provides information about the routing configuration.
+ */
+public interface SimpleFabricService
+        extends ListenerService<SimpleFabricEvent, SimpleFabricListener> {
+
+    // App symbols
+    static final String APP_ID = "org.onosproject.simplefabric";
+    static final String L2FORWARD_APP_ID = "org.onosproject.simplefabric.l2forward";
+    static final String REACTIVE_APP_ID = "org.onosproject.simplefabric.reactive";
+
+    // Priority for l2NetworkRouting: L2NETWORK_UNICAST or L2NETWORK_BROADCAST
+    static final int PRI_L2NETWORK_UNICAST = 601;
+    static final int PRI_L2NETWORK_BROADCAST = 600;
+
+    // Reactive Routing within Local Subnets
+    // ASSUME: local subnets NEVER overlaps each other
+    static final int PRI_REACTIVE_LOCAL_FORWARD = 501;
+    static final int PRI_REACTIVE_LOCAL_INTERCEPT = 500;
+    // Reactive Routing for Border Routes with local subnet
+    // Priority: REACTIVE_BROUTE_BASE + routeIpPrefix * REACTIVE_BROUTE_STEP
+    //           + REACTIVE_BROUTE_FORWARD or REACTIVE_BROUTE_INTERCEPT
+    static final int PRI_REACTIVE_BORDER_BASE = 100;
+    static final int PRI_REACTIVE_BORDER_STEP = 2;
+    static final int PRI_REACTIVE_BORDER_FORWARD = 1;
+    static final int PRI_REACTIVE_BORDER_INTERCEPT = 0;
+
+    // Simple fabric event related timers
+    static final long IDLE_INTERVAL_MSEC = 5000;
+
+    // Feature control parameters
+    static final boolean ALLOW_IPV6 = false;
+    static final boolean ALLOW_ETH_ADDRESS_SELECTOR = true;
+    static final boolean REACTIVE_SINGLE_TO_SINGLE = false;
+    static final boolean REACTIVE_ALLOW_LINK_CP = false;  // MUST BE false (yjlee, 2017-10-18)
+    static final boolean REACTIVE_HASHED_PATH_SELECTION = false;
+    static final boolean REACTIVE_MATCH_IP_PROTO = false;
+
+    /**
+     * Gets appId.
+     *
+     * @return appId of simple fabric app
+     */
+    ApplicationId getAppId();
+
+    /**
+     * Gets all the l2Networks.
+     *
+     * @return all the l2Networks
+     */
+    Collection<L2Network> getL2Networks();
+
+    /**
+     * Retrieves the entire set of ipSubnets configuration.
+     *
+     * @return all the ipSubnets
+     */
+    Set<IpSubnet> getIpSubnets();
+
+    /**
+     * Retrieves the entire set of static routes to outer networks.
+     *
+     * @return the set of static routes to outer networks.
+     */
+    Set<Route> getBorderRoutes();
+
+    /**
+     * 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
+     */
+    boolean isVMac(MacAddress mac);
+
+    /**
+     * Evaluates whether an Interface belongs to l2Networks.
+     *
+     * @param intf the interface to evaluate
+     * @return true if the inteface belongs to l2Networks configed, otherwise false
+     */
+    boolean isL2NetworkInterface(Interface intf);
+
+    /**
+     * Find 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
+     */
+    MacAddress findVMacForIp(IpAddress ip);
+
+    /**
+     * Finds the L2 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);
+
+    /**
+     * Finds the L2 Network of the name.
+     *
+     * @param name the name to be matched
+     * @return the L2 Network for specific name
+     */
+    L2Network findL2Network(String name);
+
+    /**
+     * Finds the IpSubnet containing the ipAddress.
+     *
+     * @param ipAddress the ipAddress to be matched
+     * @return the IpSubnet for specific ipAddress
+     */
+    IpSubnet findIpSubnet(IpAddress ipAddress);
+
+    /**
+     * Finds the Border Route containing the ipAddress.
+     * ASSUME: ipAddress is out of ipSubnets
+     *
+     * @param ipAddress the ipAddress to be matched
+     * @return the IpSubnet for specific ipAddress
+     */
+    Route findBorderRoute(IpAddress ipAddress);
+
+    /**
+     * Finds the network interface related to the host.
+     *
+     * @param host the host
+     * @return the interface related to the host
+     */
+    Interface findHostInterface(Host host);
+
+    /**
+     * 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
+     */
+    boolean requestMac(IpAddress ip);
+
+    /**
+     * 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
+     */
+    void dumpToStream(String subject, OutputStream out);
+
+    /**
+     * Triggers to send Refresh Notification to all sub modules.
+     */
+    void triggerRefresh();
+
+    /**
+     * Triggers to send Flush Notification to all sub modules.
+     */
+    void triggerFlush();
+
+}
diff --git a/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/package-info.java b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/package-info.java
new file mode 100644
index 0000000..a11519f
--- /dev/null
+++ b/apps/simplefabric/api/src/main/java/org/onosproject/simplefabric/api/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Simple fabric API package.
+ */
+package org.onosproject.simplefabric.api;
\ No newline at end of file