BMP abstraction for peer down notification
Change-Id: Ib330268d82430b54133c1b55d5cea21ff7510f39
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..6bcc406
--- /dev/null
+++ b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/MirroringType.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2024-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;
+
+import org.onlab.packet.DeserializationException;
+import java.util.Arrays;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * 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;
+ }
+
+
+ private static Map<Integer, MirroringType> parser = new ConcurrentHashMap<>();
+
+ static {
+ Arrays.stream(MirroringType.values()).forEach(v -> parser.put(v.value, v));
+ }
+
+ public static MirroringType getType(int type) throws DeserializationException {
+ if (type > 2) {
+ throw new DeserializationException("Invalid bmp mirroring type");
+ }
+ return Optional.of(type)
+ .filter(id -> parser.containsKey(id))
+ .map(id -> parser.get(id))
+ .orElse(BGP_MESSAGE);
+ }
+
+}
diff --git a/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/PeerDownNotificationMessage.java b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/PeerDownNotificationMessage.java
new file mode 100644
index 0000000..b66d986
--- /dev/null
+++ b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/PeerDownNotificationMessage.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2024-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;
+
+
+import org.onosproject.bgpio.protocol.BgpMessage;
+
+/**
+ * Abstraction of an BMP peer down notification message.
+ */
+public abstract class PeerDownNotificationMessage extends BmpMessage {
+
+ public static final int PEERDOWN_NOTIFICATION_HEADER_MIN_LENGTH = 4;
+
+ /**
+ * Returns BMP peer down reason.
+ *
+ * @return BMP peer down reason
+ */
+ public abstract PeerDownReason getReason();
+
+ /**
+ * Returns Bgp message.
+ *
+ * @return Bgp message
+ */
+ public abstract BgpMessage getBgpMessage();
+
+ /**
+ * Returns BMP Peer Header of BMP Message.
+ *
+ * @return BMP Peer Header of BMP Message
+ */
+ public abstract PerPeer getPerPeer();
+
+}
\ No newline at end of file
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..c132602
--- /dev/null
+++ b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/PeerDownReason.java
@@ -0,0 +1,76 @@
+/*
+ * 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;
+
+
+import org.onlab.packet.DeserializationException;
+import java.util.Arrays;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Enum to Provide the Different types of BMP peer down reasons.
+ */
+public enum PeerDownReason {
+
+ LOCAL_SYSTEM_CLOSED_SESSION_WITH_NOTIFICATION(1),
+
+ LOCAL_SYSTEM_CLOSED_SESSION_WITHOUT_NOTIFICATION(2),
+
+ REMOTE_SYSTEM_CLOSED_SESSION_WITH_NOTIFICATION(3),
+
+ REMOTE_SYSTEM_CLOSED_SESSION_WITHOUT_NOTIFICATION(4);
+
+
+ private final int value;
+
+ /**
+ * Assign value with the value val as the types of BMP peer down reasons.
+ *
+ * @param val type of BMP peer down reasons
+ */
+ PeerDownReason(int val) {
+ value = val;
+ }
+
+ /**
+ * Returns value as type of BMP peer down reasons.
+ *
+ * @return value type of BMP peer down reasons
+ */
+ public int getReason() {
+ return value;
+ }
+
+
+ private static Map<Integer, PeerDownReason> parser = new ConcurrentHashMap<>();
+
+ static {
+ Arrays.stream(PeerDownReason.values()).forEach(v -> parser.put(v.value, v));
+ }
+
+ public static PeerDownReason getType(int type) throws DeserializationException {
+ if (type > 4) {
+ throw new DeserializationException("Invalid bmp peer down reason type");
+ }
+ return Optional.of(type)
+ .filter(id -> parser.containsKey(id))
+ .map(id -> parser.get(id))
+ .orElse(LOCAL_SYSTEM_CLOSED_SESSION_WITH_NOTIFICATION);
+ }
+}