Moving Multicast subsystem into app and refactoring APIs to support multihomed sources and sinks

Change-Id: I95d07b163c619b018ff106159b134ff214aa2ffd
diff --git a/apps/mcast/api/BUCK b/apps/mcast/api/BUCK
new file mode 100644
index 0000000..db499cc
--- /dev/null
+++ b/apps/mcast/api/BUCK
@@ -0,0 +1,15 @@
+COMPILE_DEPS = [
+    '//lib:CORE_DEPS',
+    '//lib:KRYO',
+    '//core/store/serializers:onos-core-serializers',
+]
+
+TEST_DEPS = [
+    '//lib:TEST_ADAPTERS',
+    '//utils/osgi:onlab-osgi-tests',
+]
+
+osgi_jar_with_tests (
+    deps = COMPILE_DEPS,
+    test_deps = TEST_DEPS,
+)
diff --git a/apps/mcast/api/pom.xml b/apps/mcast/api/pom.xml
new file mode 100644
index 0000000..370d992
--- /dev/null
+++ b/apps/mcast/api/pom.xml
@@ -0,0 +1,72 @@
+<?xml version="1.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.
+  -->
+<project
+        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+        xmlns="http://maven.apache.org/POM/4.0.0"
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.onosproject</groupId>
+        <artifactId>onos-app-mcast</artifactId>
+        <version>1.12.1-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>onos-app-mcast-api</artifactId>
+    <packaging>bundle</packaging>
+
+    <dependencies>
+        <dependency>
+            <groupId>javax.ws.rs</groupId>
+            <artifactId>javax.ws.rs-api</artifactId>
+            <version>2.0.1</version>
+        </dependency>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-core-serializers</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onlab-osgi</artifactId>
+            <classifier>tests</classifier>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-api</artifactId>
+            <classifier>tests</classifier>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-core-common</artifactId>
+            <classifier>tests</classifier>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+    </dependencies>
+</project>
diff --git a/apps/mcast/api/src/main/java/org/onosproject/mcast/api/McastEvent.java b/apps/mcast/api/src/main/java/org/onosproject/mcast/api/McastEvent.java
new file mode 100644
index 0000000..9230736
--- /dev/null
+++ b/apps/mcast/api/src/main/java/org/onosproject/mcast/api/McastEvent.java
@@ -0,0 +1,121 @@
+/*
+ * 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.mcast.api;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.event.AbstractEvent;
+
+import java.util.Objects;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+/**
+ * An entity representing a multicast event. Event either add or remove
+ * sinks or sources.
+ */
+@Beta
+public class McastEvent extends AbstractEvent<McastEvent.Type, McastRouteUpdate> {
+
+    /**
+     * Mcast Event type enum.
+     */
+    public enum Type {
+        /**
+         * A new mcast route has been added.
+         */
+        ROUTE_ADDED,
+
+        /**
+         * A mcast route has been removed.
+         */
+        ROUTE_REMOVED,
+
+        /**
+         * A set of sources for a mcast route (ie. the subject) has been added.
+         */
+        SOURCES_ADDED,
+
+        /**
+         * A set of sources for a mcast route has been removed.
+         */
+        SOURCES_REMOVED,
+
+        /**
+         * A set of sinks for a mcast route (ie. the subject) has been added.
+         */
+        SINKS_ADDED,
+
+        /**
+         * A set of sinks for a mcast route (ie. the subject) has been removed.
+         */
+        SINKS_REMOVED
+    }
+
+    private McastRouteUpdate prevSubject;
+
+    /**
+     * Creates a McastEvent of a given type using the subject.
+     *
+     * @param type        the event type
+     * @param prevSubject the previous mcast information
+     * @param subject     the current mcast information
+     */
+    public McastEvent(McastEvent.Type type, McastRouteUpdate prevSubject, McastRouteUpdate subject) {
+        super(type, subject);
+        this.prevSubject = prevSubject;
+    }
+
+    /**
+     * Gets the previous subject in this Mcast event.
+     *
+     * @return the previous subject, or null if previous subject is not
+     * specified.
+     */
+    public McastRouteUpdate prevSubject() {
+        return this.prevSubject;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(type(), subject(), prevSubject());
+    }
+
+    @Override
+    public boolean equals(Object other) {
+        if (this == other) {
+            return true;
+        }
+
+        if (!(other instanceof McastEvent)) {
+            return false;
+        }
+
+        McastEvent that = (McastEvent) other;
+
+        return Objects.equals(this.subject(), that.subject()) &&
+                Objects.equals(this.type(), that.type()) &&
+                Objects.equals(this.prevSubject(), that.prevSubject());
+    }
+
+    @Override
+    public String toString() {
+        return toStringHelper(this)
+                .add("type", type())
+                .add("prevSubject", prevSubject())
+                .add("subject", subject())
+                .toString();
+    }
+}
diff --git a/apps/mcast/api/src/main/java/org/onosproject/mcast/api/McastListener.java b/apps/mcast/api/src/main/java/org/onosproject/mcast/api/McastListener.java
new file mode 100644
index 0000000..980e23c
--- /dev/null
+++ b/apps/mcast/api/src/main/java/org/onosproject/mcast/api/McastListener.java
@@ -0,0 +1,24 @@
+/*
+ * 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.mcast.api;
+
+import org.onosproject.event.EventListener;
+
+/**
+ * A listener interface for multicast events.
+ */
+public interface McastListener extends EventListener<McastEvent> {
+}
diff --git a/apps/mcast/api/src/main/java/org/onosproject/mcast/api/McastRoute.java b/apps/mcast/api/src/main/java/org/onosproject/mcast/api/McastRoute.java
new file mode 100644
index 0000000..9d5afeb
--- /dev/null
+++ b/apps/mcast/api/src/main/java/org/onosproject/mcast/api/McastRoute.java
@@ -0,0 +1,127 @@
+/*
+ * 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.mcast.api;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Objects;
+import org.onlab.packet.IpAddress;
+
+import java.util.Optional;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * An entity representing a multicast route consisting of a source ip
+ * and a multicast group address.
+ */
+@Beta
+public class McastRoute {
+
+    /**
+     * Possible route types.
+     */
+    public enum Type {
+        /**
+         * Route originates from PIM.
+         */
+        PIM,
+
+        /**
+         * Route originates from IGMP.
+         */
+        IGMP,
+
+        /**
+         * Route originates from other config (ie. REST, CLI).
+         */
+        STATIC
+    }
+
+    private final IpAddress source;
+    private final IpAddress group;
+    private final Type type;
+
+    /**
+     * Creates the McastRoute object. The source Ip can be null if this route is intent for ASM.
+     * @param source source Ip. Null if ASM route. Will translate in Optional.empty.
+     * @param group the multicast group
+     * @param type the route type.
+     */
+    public McastRoute(IpAddress source, IpAddress group, Type type) {
+        checkNotNull(group, "Multicast route must specify a group address");
+        this.source = source;
+        this.group = group;
+        this.type = type;
+    }
+
+    /**
+     * Fetches the source address of this route.
+     *
+     * @return an optional ip address.
+     */
+    public Optional<IpAddress> source() {
+        return Optional.ofNullable(source);
+    }
+
+    /**
+     * Fetches the group address of this route.
+     *
+     * @return an ip address
+     */
+    public IpAddress group() {
+        return group;
+    }
+
+
+    /**
+     * Type of this route.
+     *
+     * @return type
+     */
+    public Type type() {
+        return type;
+    }
+
+    @Override
+    public String toString() {
+        return toStringHelper(this)
+                .add("source", source)
+                .add("group", group)
+                .add("type", type())
+                .toString();
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+        McastRoute that = (McastRoute) o;
+        return Objects.equal(source, that.source) &&
+                Objects.equal(group, that.group) &&
+                Objects.equal(type, that.type());
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hashCode(source, group, type);
+    }
+
+}
diff --git a/apps/mcast/api/src/main/java/org/onosproject/mcast/api/McastRouteData.java b/apps/mcast/api/src/main/java/org/onosproject/mcast/api/McastRouteData.java
new file mode 100644
index 0000000..9965818
--- /dev/null
+++ b/apps/mcast/api/src/main/java/org/onosproject/mcast/api/McastRouteData.java
@@ -0,0 +1,219 @@
+/*
+ * 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.mcast.api;
+
+import com.google.common.annotations.Beta;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.HostId;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Data regarding a multicast route, comprised of a type, multiple sources and multiple sinks.
+ */
+@Beta
+public final class McastRouteData {
+
+    private final ConcurrentHashMap<ConnectPoint, Boolean> sources = new ConcurrentHashMap<>();
+    private final ConcurrentHashMap<HostId, Set<ConnectPoint>> sinks = new ConcurrentHashMap<>();
+
+    private McastRouteData() {
+    }
+
+    /**
+     * Sources contained in the associated route.
+     *
+     * @return set of sources
+     */
+    public Set<ConnectPoint> sources() {
+        return ImmutableSet.copyOf(sources.keySet());
+    }
+
+    /**
+     * Sources contained in the associated route.
+     *
+     * @return map of hostIds and associated sinks
+     */
+    public Map<HostId, Set<ConnectPoint>> sinks() {
+        return ImmutableMap.copyOf(sinks);
+    }
+
+    /**
+     * Sources contained in the associated route.
+     *
+     * @return map of hostIds and associated sinks
+     */
+    public Set<ConnectPoint> allSinks() {
+        return sinks.values().stream().flatMap(Collection::stream).collect(Collectors.toSet());
+    }
+
+    /**
+     * Sinks contained in the associated route for the given host.
+     *
+     * @param hostId the host
+     * @return set of sinks
+     */
+    public Set<ConnectPoint> sinks(HostId hostId) {
+        return sinks.get(hostId);
+    }
+
+    /**
+     * Sinks contained in the associated route that are not bound to any host.
+     *
+     * @return set of sinks
+     */
+    public Set<ConnectPoint> nonHostSinks() {
+        return sinks.get(HostId.NONE);
+    }
+
+    /**
+     * Add the sources for the associated route.
+     *
+     * @param sources set of sources
+     */
+    public void addSources(Set<ConnectPoint> sources) {
+        checkArgument(!sources.contains(null));
+        sources.forEach(source -> {
+            this.sources.put(source, true);
+        });
+    }
+
+    /**
+     * Removes all the sources contained in the associated route.
+     */
+    public void removeSources() {
+        sources.clear();
+    }
+
+    /**
+     * Removes the given sources contained in the associated route.
+     *
+     * @param sources the sources to remove
+     */
+    public void removeSources(Set<ConnectPoint> sources) {
+        checkArgument(!sources.contains(null));
+        sources.forEach(this.sources::remove);
+    }
+
+    /**
+     * Adds sinks for a given host Id. If the Host Id is {@link HostId#NONE} the sinks are intended to be
+     * used at all times independently of the attached host.
+     *
+     * @param hostId the host
+     * @param sinks  the sinks
+     */
+    public void addSinks(HostId hostId, Set<ConnectPoint> sinks) {
+        checkNotNull(hostId);
+        checkArgument(!sinks.contains(null));
+        this.sinks.put(hostId, sinks);
+    }
+
+    /**
+     * Adds sink for this route that are not associated directly with a given host.
+     *
+     * @param sinks the sinks
+     */
+    public void addNonHostSinks(Set<ConnectPoint> sinks) {
+        checkArgument(!sinks.contains(null));
+        this.sinks.put(HostId.NONE, sinks);
+    }
+
+    /**
+     * Removes all the sinks for this route.
+     */
+    public void removeSinks() {
+        sinks.clear();
+    }
+
+    /**
+     * Removes all the sinks for the given host for this route.
+     *
+     * @param hostId the host
+     */
+    public void removeSinks(HostId hostId) {
+        checkNotNull(hostId);
+        this.sinks.remove(hostId);
+    }
+
+    /**
+     * Removes all the given sinks for the given host for this route.
+     *
+     * @param hostId the host
+     * @param sinks  the sinks to remove
+     */
+    public void removeSinks(HostId hostId, Set<ConnectPoint> sinks) {
+        checkNotNull(hostId);
+        checkArgument(!sinks.contains(null));
+        this.sinks.get(hostId).removeAll(sinks);
+    }
+
+    /**
+     * Returns if the route has no sinks.
+     *
+     * @return true if no sinks
+     */
+    public boolean isEmpty() {
+        return sinks.isEmpty();
+    }
+
+    /**
+     * Creates an empty route object.
+     *
+     * @return an empty muticast rout data object.
+     */
+    public static McastRouteData empty() {
+        return new McastRouteData();
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(super.hashCode(), sources, sinks);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!(obj instanceof McastRouteData)) {
+            return false;
+        }
+        final McastRouteData other = (McastRouteData) obj;
+
+        return super.equals(obj) &&
+                Objects.equals(sources(), other.sources()) &&
+                Objects.equals(sinks(), other.sinks());
+    }
+
+    @Override
+    public String toString() {
+        return toStringHelper(this)
+                .add("sources", sources())
+                .add("sinks", sinks())
+                .toString();
+    }
+}
diff --git a/apps/mcast/api/src/main/java/org/onosproject/mcast/api/McastRouteUpdate.java b/apps/mcast/api/src/main/java/org/onosproject/mcast/api/McastRouteUpdate.java
new file mode 100644
index 0000000..4333465
--- /dev/null
+++ b/apps/mcast/api/src/main/java/org/onosproject/mcast/api/McastRouteUpdate.java
@@ -0,0 +1,117 @@
+/*
+ * 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.mcast.api;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.HostId;
+
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Utility class to propagate updates to multicast route information stored in the store.
+ */
+@Beta
+public final class McastRouteUpdate {
+
+    private static final String ROUTE_NOT_NULL = "Route cannot be null";
+    private static final String SOURCE_NOT_NULL = "Source cannot be null";
+    private static final String SINK_NOT_NULL = "Sink cannot be null";
+
+    private final McastRoute route;
+    private final Set<ConnectPoint> sources;
+    private final Map<HostId, Set<ConnectPoint>> sinks;
+
+    private McastRouteUpdate(McastRoute route, Set<ConnectPoint> source, Map<HostId, Set<ConnectPoint>> sinks) {
+        this.route = checkNotNull(route, ROUTE_NOT_NULL);
+        this.sources = checkNotNull(source, SOURCE_NOT_NULL);
+        this.sinks = checkNotNull(sinks, SINK_NOT_NULL);
+    }
+
+    /**
+     * Static method to create an McastRoutUpdate object.
+     *
+     * @param route   the route updated
+     * @param sources the different sources
+     * @param sinks   the different sinks
+     * @return the McastRouteUpdate object.
+     */
+    public static McastRouteUpdate mcastRouteUpdate(McastRoute route,
+                                                    Set<ConnectPoint> sources,
+                                                    Map<HostId, Set<ConnectPoint>> sinks) {
+        return new McastRouteUpdate(route, sources, sinks);
+    }
+
+    /**
+     * The route associated with this multicast information.
+     *
+     * @return a mulicast route
+     */
+    public McastRoute route() {
+        return route;
+    }
+
+    /**
+     * The sources.
+     *
+     * @return an optional connect point
+     */
+    public Set<ConnectPoint> sources() {
+        return sources;
+    }
+
+    /**
+     * The sinks.
+     *
+     * @return a set of connect points
+     */
+    public Map<HostId, Set<ConnectPoint>> sinks() {
+        return sinks;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+        McastRouteUpdate that = (McastRouteUpdate) o;
+        return Objects.equals(route, that.route) &&
+                Objects.equals(sources, that.sources) &&
+                Objects.equals(sinks, that.sinks);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(route, sources, sinks);
+    }
+
+    @Override
+    public String toString() {
+        return toStringHelper(this)
+                .add("route", route())
+                .add("sources", sources)
+                .add("sinks", sinks)
+                .toString();
+    }
+}
diff --git a/apps/mcast/api/src/main/java/org/onosproject/mcast/api/McastStore.java b/apps/mcast/api/src/main/java/org/onosproject/mcast/api/McastStore.java
new file mode 100644
index 0000000..53d444b
--- /dev/null
+++ b/apps/mcast/api/src/main/java/org/onosproject/mcast/api/McastStore.java
@@ -0,0 +1,161 @@
+/*
+ * 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.mcast.api;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.HostId;
+import org.onosproject.store.Store;
+
+import java.util.Set;
+
+/**
+ * Entity responsible for storing multicast state information.
+ */
+@Beta
+public interface McastStore extends Store<McastEvent, McastStoreDelegate> {
+
+    /**
+     * Updates the store with the route information.
+     *
+     * @param route a multicast route
+     */
+    void storeRoute(McastRoute route);
+
+    /**
+     * Updates the store with the route information.
+     *
+     * @param route a multicast route
+     */
+    void removeRoute(McastRoute route);
+
+    /**
+     * Add to the store with source information for the given route.
+     *
+     * @param route   a multicast route
+     * @param sources a set of sources
+     */
+    void storeSources(McastRoute route, Set<ConnectPoint> sources);
+
+    /**
+     * Removes from the store all the sources information for a given route.
+     *
+     * @param route a multicast route
+     */
+    void removeSources(McastRoute route);
+
+    /**
+     * Removes from the store the source information for the given route.
+     * value.
+     *
+     * @param route   a multicast route
+     * @param sources a set of sources
+     */
+    void removeSources(McastRoute route, Set<ConnectPoint> sources);
+
+    /**
+     * Updates the store with a host based sink information for a given route. There may be
+     * multiple sink connect points for the given host.
+     *
+     * @param route  a multicast route
+     * @param hostId the host sink
+     * @param sinks  the sinks
+     */
+    void addSink(McastRoute route, HostId hostId, Set<ConnectPoint> sinks);
+
+    /**
+     * Updates the store with sinks information for a given route.
+     * The sinks stored with this method are not tied with any host.
+     * Traffic will be sent to all of them.
+     *
+     * @param route a multicast route
+     * @param sinks set of specific connect points
+     */
+    void addSinks(McastRoute route, Set<ConnectPoint> sinks);
+
+    /**
+     * Removes from the store all the sink information for a given route.
+     *
+     * @param route a multicast route
+     */
+    void removeSinks(McastRoute route);
+
+    /**
+     * Removes from the store the complete set of sink information for a given host for a given route.
+     *
+     * @param route  a multicast route
+     * @param hostId a specific host
+     */
+    void removeSink(McastRoute route, HostId hostId);
+
+    /**
+     * Removes from the store the given set of sink information for a given host for a given route.
+     *
+     * @param route  a multicast route
+     * @param hostId the host
+     * @param sinks  a set of multicast sink connect points
+     */
+    void removeSinks(McastRoute route, HostId hostId, Set<ConnectPoint> sinks);
+
+    /**
+     * Removes from the store the set of non host bind sink information for a given route.
+     *
+     * @param route a multicast route
+     * @param sinks a set of multicast sinks
+     */
+    void removeSinks(McastRoute route, Set<ConnectPoint> sinks);
+
+    /**
+     * Obtains the sources for a multicast route.
+     *
+     * @param route a multicast route
+     * @return a connect point
+     */
+    Set<ConnectPoint> sourcesFor(McastRoute route);
+
+    /**
+     * Obtains the sinks for a multicast route.
+     *
+     * @param route a multicast route
+     * @return a set of sinks
+     */
+    Set<ConnectPoint> sinksFor(McastRoute route);
+
+    /**
+     * Obtains the sinks for a given host for a given multicast route.
+     *
+     * @param route  a multicast route
+     * @param hostId the host
+     * @return a set of sinks
+     */
+    Set<ConnectPoint> sinksFor(McastRoute route, HostId hostId);
+
+
+    /**
+     * Gets the set of all known multicast routes.
+     *
+     * @return set of multicast routes.
+     */
+    Set<McastRoute> getRoutes();
+
+    /**
+     * Gets the multicast data for a given route.
+     *
+     * @param route the route
+     * @return set of multicast routes.
+     */
+    McastRouteData getRouteData(McastRoute route);
+}
diff --git a/apps/mcast/api/src/main/java/org/onosproject/mcast/api/McastStoreDelegate.java b/apps/mcast/api/src/main/java/org/onosproject/mcast/api/McastStoreDelegate.java
new file mode 100644
index 0000000..49e894d
--- /dev/null
+++ b/apps/mcast/api/src/main/java/org/onosproject/mcast/api/McastStoreDelegate.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.mcast.api;
+
+
+import org.onosproject.store.StoreDelegate;
+
+/**
+ * Mcast store delegate abstraction.
+ */
+public interface McastStoreDelegate extends StoreDelegate<McastEvent> {
+}
diff --git a/apps/mcast/api/src/main/java/org/onosproject/mcast/api/MulticastRouteService.java b/apps/mcast/api/src/main/java/org/onosproject/mcast/api/MulticastRouteService.java
new file mode 100644
index 0000000..d9b1721
--- /dev/null
+++ b/apps/mcast/api/src/main/java/org/onosproject/mcast/api/MulticastRouteService.java
@@ -0,0 +1,183 @@
+/*
+ * 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.mcast.api;
+
+import com.google.common.annotations.Beta;
+import org.onlab.packet.IpAddress;
+import org.onosproject.event.ListenerService;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.HostId;
+
+import java.util.Optional;
+import java.util.Set;
+
+/**
+ * A service interface for maintaining multicast information.
+ */
+@Beta
+public interface MulticastRouteService
+        extends ListenerService<McastEvent, McastListener> {
+
+    /**
+     * Adds an empty route to the information base for the given group IP.
+     *
+     * @param route a multicast route
+     */
+    void add(McastRoute route);
+
+    /**
+     * Removes a route from the information base.
+     *
+     * @param route a multicast route
+     */
+    void remove(McastRoute route);
+
+    /**
+     * Gets all multicast routes in the system.
+     *
+     * @return set of multicast routes
+     */
+    Set<McastRoute> getRoutes();
+
+    /**
+     * Gets a multicast route in the system.
+     *
+     * @param groupIp multicast group IP address
+     * @param sourceIp multicasto source Ip address
+     * @return set of multicast routes
+     */
+    Optional<McastRoute> getRoute(IpAddress groupIp, IpAddress sourceIp);
+
+    /**
+     * Adds a set of source to the route from where the
+     * data stream is originating.
+     *
+     * @param route   the multicast route
+     * @param sources a set of sources
+     */
+    void addSources(McastRoute route, Set<ConnectPoint> sources);
+
+    /**
+     * Removes all the sources from the route.
+     *
+     * @param route the multicast route
+     */
+    void removeSources(McastRoute route);
+
+    /**
+     * Removes a set of sources from the route.
+     *
+     * @param route   the multicast route
+     * @param sources a set of sources
+     */
+    void removeSources(McastRoute route, Set<ConnectPoint> sources);
+
+    /**
+     * Adds a set of sink to the route to which a data stream should be
+     * sent to.
+     *
+     * @param route  a multicast route
+     * @param hostId a sink host
+     */
+    void addSink(McastRoute route, HostId hostId);
+
+    /**
+     * Adds a set of sink to the route to which a data stream should be
+     * sent to. If this method is used this the connect points will all
+     * be used a sink for that Mcast Tree. For dual-homed sinks please use
+     * {@link #addSink(McastRoute route, HostId hostId) addSink}.
+     *
+     * @param route a multicast route
+     * @param sinks a set of sink connect point
+     */
+    void addSink(McastRoute route, Set<ConnectPoint> sinks);
+
+    /**
+     * Removes all the sinks from the route.
+     *
+     * @param route the multicast route
+     */
+    void removeSinks(McastRoute route);
+
+    /**
+     * Removes a sink host from the route.
+     *
+     * @param route  the multicast route
+     * @param hostId a sink host
+     */
+    void removeSink(McastRoute route, HostId hostId);
+
+    /**
+     * Removes a set of sink connect points for a given host the route.
+     *
+     * @param route         the multicast route
+     * @param hostId        a sink host
+     * @param connectPoints a given set of connect points to remove
+     */
+    void removeSinks(McastRoute route, HostId hostId, Set<ConnectPoint> connectPoints);
+
+    /**
+     * Removes a set of sinks to the route to which a data stream should be
+     * sent to. If this method is used the mcast tree does not work
+     * for any other sink until it's added. For dual-homed sinks please use
+     * {@link #removeSink(McastRoute route, HostId hostId) removeSink}.
+     *
+     * @param route a multicast route
+     * @param sink  a sink connect point
+     */
+    void removeSinks(McastRoute route, Set<ConnectPoint> sink);
+
+    /**
+     * Return the Data for this route.
+     *
+     * @param route route
+     * @return the mcast route data
+     */
+    McastRouteData routeData(McastRoute route);
+
+    /**
+     * Find the data source association for this multicast route.
+     *
+     * @param route a multicast route
+     * @return a connect point
+     */
+    Set<ConnectPoint> sources(McastRoute route);
+
+    /**
+     * Find the list of sinks for this route.
+     *
+     * @param route a multicast route
+     * @return a list of connect points
+     */
+    Set<ConnectPoint> sinks(McastRoute route);
+
+    /**
+     * Find the list of sinks for a given host for this route.
+     *
+     * @param route  a multicast route
+     * @param hostId the host
+     * @return a list of connect points
+     */
+    Set<ConnectPoint> sinks(McastRoute route, HostId hostId);
+
+    /**
+     * Obtains all the non host specific sinks for a multicast route.
+     *
+     * @param route a multicast route
+     * @return a set of sinks
+     */
+    Set<ConnectPoint> nonHostSinks(McastRoute route);
+}
diff --git a/apps/mcast/api/src/main/java/org/onosproject/mcast/api/package-info.java b/apps/mcast/api/src/main/java/org/onosproject/mcast/api/package-info.java
new file mode 100644
index 0000000..bf4a398
--- /dev/null
+++ b/apps/mcast/api/src/main/java/org/onosproject/mcast/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.
+ */
+
+/**
+ * Multicast routes store and manager &amp; related services API definitions.
+ */
+package org.onosproject.mcast.api;