[CORD-1616] Supports PD by DHCP relay App

Change-Id: I9a23534023ca2847bd3f77a3f9ee2b468c5bb422
diff --git a/apps/routing/fpm/api/BUCK b/apps/routing/fpm/api/BUCK
new file mode 100644
index 0000000..f5a98fc
--- /dev/null
+++ b/apps/routing/fpm/api/BUCK
@@ -0,0 +1,7 @@
+COMPILE_DEPS = [
+    '//lib:CORE_DEPS',
+]
+
+osgi_jar (
+    deps = COMPILE_DEPS,
+)
diff --git a/apps/routing/fpm/api/pom.xml b/apps/routing/fpm/api/pom.xml
new file mode 100644
index 0000000..1b8d310
--- /dev/null
+++ b/apps/routing/fpm/api/pom.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2017-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 xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>onos-apps-fpm</artifactId>
+        <groupId>org.onosproject</groupId>
+        <version>1.11.2-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>onos-apps-routing-fpm-api</artifactId>
+    <packaging>bundle</packaging>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-cli</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.karaf.shell</groupId>
+            <artifactId>org.apache.karaf.shell.console</artifactId>
+        </dependency>
+
+    </dependencies>
+
+
+</project>
diff --git a/apps/routing/fpm/api/src/main/java/org/onosproject/routing/fpm/api/FpmPrefixStore.java b/apps/routing/fpm/api/src/main/java/org/onosproject/routing/fpm/api/FpmPrefixStore.java
new file mode 100644
index 0000000..c2ed203
--- /dev/null
+++ b/apps/routing/fpm/api/src/main/java/org/onosproject/routing/fpm/api/FpmPrefixStore.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2017-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.routing.fpm.api;
+
+import org.onosproject.store.Store;
+import org.onosproject.store.StoreDelegate;
+import org.onlab.packet.IpPrefix;
+import java.util.Collection;
+import java.util.Optional;
+
+/**
+ * Interface to store Fpm records.
+ */
+public interface FpmPrefixStore extends Store<FpmPrefixStoreEvent, StoreDelegate<FpmPrefixStoreEvent>> {
+
+    /**
+     * Gets Fpm record for a prefix.
+     *
+     * @param prefix is the key
+     * @return the Fpm record; empty if record does not exist
+     */
+    Optional<FpmRecord> getFpmRecord(IpPrefix prefix);
+
+    /**
+     * Gets all Fpm records from the data store.
+     *
+     * @return all FPM records
+     */
+    Collection<FpmRecord> getFpmRecords();
+
+    /**
+     * Set a delegate on the data store to be notified of events.
+     *
+     * @param delegate is the delegate to be added
+     */
+    public void setDelegate(StoreDelegate<FpmPrefixStoreEvent> delegate);
+
+    /**
+     * Unset delegate on the data store.
+     *
+     * @param delegate us the delegate to be removed
+     */
+    public void unsetDelegate(StoreDelegate<FpmPrefixStoreEvent> delegate);
+}
diff --git a/apps/routing/fpm/api/src/main/java/org/onosproject/routing/fpm/api/FpmPrefixStoreEvent.java b/apps/routing/fpm/api/src/main/java/org/onosproject/routing/fpm/api/FpmPrefixStoreEvent.java
new file mode 100644
index 0000000..1d3cf28
--- /dev/null
+++ b/apps/routing/fpm/api/src/main/java/org/onosproject/routing/fpm/api/FpmPrefixStoreEvent.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2017-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.routing.fpm.api;
+
+import org.onosproject.event.AbstractEvent;
+
+/**
+ * Event class for FPM prefix store.
+ */
+public class FpmPrefixStoreEvent extends AbstractEvent<FpmPrefixStoreEvent.Type, FpmRecord> {
+
+    /**
+     * Types of the event.
+     */
+    public enum Type {
+        /**
+         * A Fpm record has been added.
+         */
+        ADD,
+
+        /**
+         * A Fpm record has been removed.
+         */
+        REMOVE
+    }
+
+    /**
+     * Creates a Fpm prefix store event with given data.
+     *
+     * @param type is the type of event
+     * @param subject is the Fpm record of this event
+     */
+    public FpmPrefixStoreEvent(Type type, FpmRecord subject) {
+        super(type, subject);
+    }
+}
diff --git a/apps/routing/fpm/api/src/main/java/org/onosproject/routing/fpm/api/FpmRecord.java b/apps/routing/fpm/api/src/main/java/org/onosproject/routing/fpm/api/FpmRecord.java
new file mode 100644
index 0000000..de63e44
--- /dev/null
+++ b/apps/routing/fpm/api/src/main/java/org/onosproject/routing/fpm/api/FpmRecord.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2017-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.routing.fpm.api;
+
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.IpPrefix;
+import java.util.Objects;
+import com.google.common.base.MoreObjects;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * A class to define a Fpm record.
+ */
+public class FpmRecord {
+
+    public enum Type {
+        /**
+         * Signifies that record came from Dhcp Relay.
+         */
+        DHCP_RELAY,
+
+        /**
+         * Signifies that record came from RIP.
+         */
+        RIP
+    }
+
+    private IpPrefix prefix;
+    private IpAddress nextHop;
+    private Type type;
+
+    public FpmRecord(IpPrefix prefix, IpAddress nextHop, Type type) {
+        checkNotNull(prefix, "prefix cannot be null");
+        checkNotNull(nextHop, "ipAddress cannot be null");
+
+        this.prefix = prefix;
+        this.nextHop = nextHop;
+        this.type = type;
+    }
+
+    /**
+     * Gets IP prefix of record.
+     *
+     * @return the IP prefix
+     */
+    public IpPrefix ipPrefix() {
+        return prefix;
+    }
+
+    /**
+     * Gets IP address of record.
+     *
+     * @return the IP address
+     */
+    public IpAddress nextHop() {
+        return nextHop;
+    }
+
+    /**
+     * Gets type of record.
+     *
+     * @return the type
+     */
+    public Type type() {
+        return type;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(prefix, nextHop, type);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!(obj instanceof FpmRecord)) {
+            return false;
+        }
+        FpmRecord that = (FpmRecord) obj;
+        return Objects.equals(prefix, that.prefix) &&
+                Objects.equals(nextHop, that.nextHop) &&
+                Objects.equals(type, that.type);
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(getClass())
+                .add("prefix", prefix)
+                .add("ipAddress", nextHop)
+                .add("type", type)
+                .toString();
+    }
+}
diff --git a/apps/routing/fpm/api/src/main/java/org/onosproject/routing/fpm/api/package-info.java b/apps/routing/fpm/api/src/main/java/org/onosproject/routing/fpm/api/package-info.java
new file mode 100644
index 0000000..a45fb74
--- /dev/null
+++ b/apps/routing/fpm/api/src/main/java/org/onosproject/routing/fpm/api/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-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.
+ */
+
+/**
+ * Forwarding Plane Manager (FPM) implementation.
+ */
+package org.onosproject.routing.fpm.api;