BGP Monitoring in ONOS.
Jira Id: ONOS-8136

Implement bgpmonitoring Api.

Change-Id: I3542cf63b3b3ec604d293c166dbf413b7c158ac7
diff --git a/apps/bgpmonitoring/api/BUILD b/apps/bgpmonitoring/api/BUILD
new file mode 100644
index 0000000..6109d51
--- /dev/null
+++ b/apps/bgpmonitoring/api/BUILD
@@ -0,0 +1,10 @@
+COMPILE_DEPS = CORE_DEPS + [
+    "//core/store/serializers:onos-core-serializers",
+    "//protocols/bgp/bgpio:onos-protocols-bgp-bgpio",
+    "@io_netty_netty//jar",
+]
+
+osgi_jar_with_tests(
+    test_deps = TEST_ADAPTERS,
+    deps = COMPILE_DEPS,
+)
diff --git a/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpController.java b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpController.java
new file mode 100644
index 0000000..d36e9a9
--- /dev/null
+++ b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpController.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2021-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.bgpmonitoring;
+
+/**
+ * Abstraction of an BMP controller. It handles BMP messages from BMP routers
+ */
+public interface BmpController {
+
+    /**
+     * Start listening bmp messages from bmp router.
+     */
+    void startListener();
+
+    /**
+     * Stop listening bmp messages from bmp router.
+     */
+    void closeListener();
+
+    /**
+     * Process bmp message and notify the appropriate listeners.
+     *
+     * @param message   the message to process.
+     * @throws BmpParseException on data processing error
+     */
+    void processBmpPacket(BmpMessage message) throws BmpParseException;
+
+}
diff --git a/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpParseException.java b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpParseException.java
new file mode 100644
index 0000000..9c48547
--- /dev/null
+++ b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpParseException.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2021-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.bgpmonitoring;
+
+
+/**
+ * Custom Exception for BMP IO.
+ */
+public class BmpParseException extends Exception {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * Default constructor to create a new exception.
+     */
+    public BmpParseException() {
+        super();
+    }
+
+    /**
+     * Constructor to create exception from message and cause.
+     *
+     * @param message  the detail of exception in string
+     * @param cause underlying cause of the error
+     */
+    public BmpParseException(final String message, final Throwable cause) {
+        super(message, cause);
+    }
+
+    /**
+     * Constructor to create exception from message.
+     *
+     * @param message the detail of exception in string
+     */
+    public BmpParseException(final String message) {
+        super(message);
+    }
+
+    /**
+     * Constructor to create exception from cause.
+     *
+     * @param cause underlying cause of the error
+     */
+    public BmpParseException(final Throwable cause) {
+        super(cause);
+    }
+
+}
diff --git a/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpType.java b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpType.java
new file mode 100644
index 0000000..93a94fe
--- /dev/null
+++ b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpType.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2021-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.bgpmonitoring;
+
+/**
+ * Enum to Provide the Different types of BMP messages.
+ */
+public enum BmpType {
+
+    ROUTE_MONITORING((byte) 0x0),
+
+    STATISTICS_REPORT((byte) 0x1),
+
+    PEER_DOWN_NOTIFICATION((byte) 0x2),
+
+    PEER_UP_NOTIFICATION((byte) 0x3),
+
+    INITIATION_MESSAGE((byte) 0x4),
+
+    TERMINATION_MESSAGE((byte) 0x5),
+
+    ROUTE_MIRRORING_MESSAGE((byte) 0x6);
+
+    private final byte value;
+
+    /**
+     * Assign value with the value val as the types of BMP message.
+     *
+     * @param val type of BMP message
+     */
+    BmpType(byte val) {
+        value = val;
+    }
+
+
+    /**
+     * Returns value as type of BMP message.
+     *
+     * @return value type of BMP message
+     */
+    public byte getType() {
+        return value;
+    }
+}
diff --git a/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpVersion.java b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpVersion.java
new file mode 100644
index 0000000..4d1da8f9
--- /dev/null
+++ b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpVersion.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2021-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.bgpmonitoring;
+
+
+/**
+ * Enum to provide BMP Message Version.
+ */
+public enum BmpVersion {
+
+    BMP_3(3);
+
+    public final int packetVersion;
+
+    /**
+     * Assign BMP PacketVersion with specified packetVersion.
+     *
+     * @param packetVersion version of BMP
+     */
+    BmpVersion(final int packetVersion) {
+        this.packetVersion = packetVersion;
+    }
+
+    /**
+     * Returns Packet version of BMP Message.
+     *
+     * @return packetVersion
+     */
+    public int getPacketVersion() {
+        return packetVersion;
+    }
+}
\ No newline at end of file
diff --git a/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/MirroringType.java b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/MirroringType.java
new file mode 100644
index 0000000..7fcf4cc
--- /dev/null
+++ b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/MirroringType.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2021-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.bgpmonitoring;
+
+/**
+ * Enum to Provide the Different types of BMP mirroring message.
+ */
+public enum MirroringType {
+
+    BGP_MESSAGE(0),
+
+    INFORMATION(1);
+
+    private final int value;
+
+    /**
+     * Assign value with the value val as the types of BMP mirroring message.
+     *
+     * @param val type of BMP mirroring message
+     */
+    MirroringType(int val) {
+        value = val;
+    }
+
+
+    /**
+     * Returns value as type of BMP mirroring message.
+     *
+     * @return value type of BMP mirroring message
+     */
+    public int getType() {
+        return value;
+    }
+}
diff --git a/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/PeerDownReason.java b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/PeerDownReason.java
new file mode 100644
index 0000000..b6e0e8e
--- /dev/null
+++ b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/PeerDownReason.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2021-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.bgpmonitoring;
+
+/**
+ * Enum to Provide the Different types of BMP peer down reasons.
+ */
+public enum PeerDownReason {
+
+    LOCAL_SYSTEM_CLOSED_SESSION_WITH_NOTIFICATION((byte) 0x01),
+
+    LOCAL_SYSTEM_CLOSED_SESSION_WITHOUT_NOTIFICATION((byte) 0x02),
+
+    REMOTE_SYSTEM_CLOSED_SESSION_WITH_NOTIFICATION((byte) 0x03),
+
+    REMOTE_SYSTEM_CLOSED_SESSION_WITHOUT_NOTIFICATION((byte) 0x04);
+
+
+    private final byte value;
+
+    /**
+     * Assign value with the value val as the types of BMP peer down reasons.
+     *
+     * @param val type of BMP peer down reasons
+     */
+    PeerDownReason(byte val) {
+        value = val;
+    }
+
+    /**
+     * Returns value as type of BMP peer down reasons.
+     *
+     * @return value type of BMP peer down reasons
+     */
+    public byte getReason() {
+        return value;
+    }
+}
diff --git a/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/StatsType.java b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/StatsType.java
new file mode 100644
index 0000000..9ab93d8
--- /dev/null
+++ b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/StatsType.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2021-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.bgpmonitoring;
+
+/**
+ * Enum to Provide the Different types of BMP stats.
+ */
+public enum StatsType {
+
+    PREFIXES_REJECTED(0),
+
+    DUPLICATE_PREFIX(1),
+
+    DUPLICATE_WITHDRAW(2),
+
+    CLUSTER_LIST(3),
+
+    AS_PATH(4),
+
+    ORIGINATOR_ID(5),
+
+    AS_CONFED(6),
+
+    ADJ_RIB_IN(7),
+
+    LOC_RIB(8),
+
+    ADJ_RIB_IN_AFI_SAFI(9),
+
+    LOC_RIB_AFI_SAFI(10),
+
+    UPDATES_SUBJECTED_WITHDRAW(11),
+
+    PREFIXES_SUBJECTED_WITHDRAW(12),
+
+    DUPLICATE_UPDATE_MESSAGES(13),
+
+    JNX_ADJ_RIB_IN(17);
+
+
+    private final int value;
+
+    /**
+     * Assign value with the value val as the types of BMP stats.
+     *
+     * @param val type of BMP stats
+     */
+    StatsType(int val) {
+        value = val;
+    }
+
+    /**
+     * Returns value as type of BMP stats.
+     *
+     * @return value type of BMP stats
+     */
+    public int getType() {
+        return value;
+    }
+}
diff --git a/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/TerminationType.java b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/TerminationType.java
new file mode 100644
index 0000000..5e7ad01
--- /dev/null
+++ b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/TerminationType.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2021-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.bgpmonitoring;
+
+/**
+ * Enum to Provide the Different types of BMP termination message.
+ */
+public enum TerminationType {
+
+    UTF8_STRING(0),
+
+    REASON(1);
+
+    private final int value;
+
+    /**
+     * Assign value with the value val as the types of BMP termination message.
+     *
+     * @param val type of BMP termination message
+     */
+    TerminationType(int val) {
+        value = val;
+    }
+
+    /**
+     * Returns value as type of BMP termination message.
+     *
+     * @return value type of BMP termination message
+     */
+    public int getType() {
+        return value;
+    }
+}
diff --git a/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/package-info.java b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/package-info.java
new file mode 100644
index 0000000..492c271
--- /dev/null
+++ b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2021-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.
+ */
+
+/**
+ * BMP api components.
+ */
+package org.onosproject.bgpmonitoring;
\ No newline at end of file