Refactor BMP protocol
Change-Id: I54aca350f00d3335cfa6606f2b10819c3858ad56
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
index d36e9a9..f16aef6 100644
--- a/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpController.java
+++ b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpController.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021-present Open Networking Foundation
+ * 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.
@@ -17,7 +17,7 @@
package org.onosproject.bgpmonitoring;
/**
- * Abstraction of an BMP controller. It handles BMP messages from BMP routers
+ * Service for interacting with the BMP controller.
*/
public interface BmpController {
@@ -34,9 +34,9 @@
/**
* Process bmp message and notify the appropriate listeners.
*
- * @param message the message to process.
+ * @param packet the BMP packet to process.
* @throws BmpParseException on data processing error
*/
- void processBmpPacket(BmpMessage message) throws BmpParseException;
+ void processBmpPacket(BmpPacket packet) throws BmpParseException;
}
diff --git a/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpMessage.java b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpMessage.java
index 4508f0e..7d28a86 100644
--- a/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpMessage.java
+++ b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpMessage.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021-present Open Networking Foundation
+ * 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.
@@ -13,54 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.onosproject.bgpmonitoring;
-import org.onlab.packet.bmp.Bmp;
-import org.onlab.packet.bmp.BmpPeer;
+import org.onlab.packet.BasePacket;
/**
* Abstraction of an entity providing BMP Messages.
*/
-public interface BmpMessage {
+public abstract class BmpMessage extends BasePacket {
- /**
- * Returns BMP Header of BMP Message.
- *
- * @return BMP Header of BMP Message
- */
- Bmp getHeader();
-
- /**
- * Returns BMP Peer Header of BMP Message.
- *
- * @return BMP Peer Header of BMP Message
- */
- default BmpPeer getPeerHeader() {
- throw new UnsupportedOperationException("Bmp Per Peer Header not supported");
+ @Override
+ public byte[] serialize() {
+ throw new UnsupportedOperationException("Not supported yet.");
}
- /**
- * Is bmp message has peer header.
- *
- * @return true if bmp has peer header otherwise false
- */
- default boolean hasPeerHeader() {
- return true;
- }
-
- /**
- * Returns version of BMP Message.
- *
- * @return version of BMP Message
- */
- default BmpVersion getVersion() {
- return BmpVersion.BMP_3;
- }
-
- /**
- * Returns BMP Type of BMP Message.
- *
- * @return BMP Type of BMP Message
- */
- BmpType getType();
}
diff --git a/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpMessageReader.java b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpMessageReader.java
deleted file mode 100644
index 56362ea..0000000
--- a/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpMessageReader.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.jboss.netty.buffer.ChannelBuffer;
-import org.onlab.packet.bmp.Bmp;
-
-/**
- * Abstraction of an entity providing BMP Message Reader.
- */
-public interface BmpMessageReader<T> {
-
- /**
- * Reads the Objects in the BMP Message and Returns BMP Message.
- *
- * @param cb Channel Buffer
- * @param bmpHeader BMP message header
- * @return BMP Message
- * @throws BmpParseException on while parsing BMP message.
- */
- T readFrom(ChannelBuffer cb, Bmp bmpHeader) throws BmpParseException;
-}
diff --git a/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpVersion.java b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpMsg.java
similarity index 60%
rename from apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpVersion.java
rename to apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpMsg.java
index 4d1da8f9..667f1a8 100644
--- a/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpVersion.java
+++ b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpMsg.java
@@ -16,31 +16,30 @@
package org.onosproject.bgpmonitoring;
-
/**
- * Enum to provide BMP Message Version.
+ * Enum to Provide the interface of BMP initiation message.
*/
-public enum BmpVersion {
-
- BMP_3(3);
-
- public final int packetVersion;
+public interface BmpMsg {
/**
- * Assign BMP PacketVersion with specified packetVersion.
+ * Returns BMP initiation message type.
*
- * @param packetVersion version of BMP
+ * @return BMP initiation message type
*/
- BmpVersion(final int packetVersion) {
- this.packetVersion = packetVersion;
- }
+ public abstract short getType();
/**
- * Returns Packet version of BMP Message.
+ * Returns BMP initiation message length.
*
- * @return packetVersion
+ * @return BMP initiation message length
*/
- public int getPacketVersion() {
- return packetVersion;
- }
+ public abstract short getLength();
+
+ /**
+ * Returns BMP initiation message.
+ *
+ * @return BMP initiation message
+ */
+ public abstract String getData();
+
}
\ No newline at end of file
diff --git a/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpPacket.java b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpPacket.java
new file mode 100644
index 0000000..3f65655
--- /dev/null
+++ b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpPacket.java
@@ -0,0 +1,59 @@
+/*
+ * 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.BasePacket;
+
+/**
+ * Abstraction of an entity providing BMP Packet.
+ */
+public abstract class BmpPacket extends BasePacket {
+
+ @Override
+ public byte[] serialize() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ /**
+ * Returns BMP packet length.
+ *
+ * @return BMP packet length
+ */
+ public abstract int getLength();
+
+ /**
+ * Returns BMP packet version.
+ *
+ * @return BMP packet version
+ */
+ public abstract BmpVersion getVersion();
+
+ /**
+ * Returns BMP message type.
+ *
+ * @return BMP message type
+ */
+ public abstract String getType();
+
+ /**
+ * Returns BMP message.
+ *
+ * @return BMP message
+ */
+ public abstract BmpMessage getMessage();
+
+}
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
index 9c48547..60b867a 100644
--- a/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpParseException.java
+++ b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpParseException.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021-present Open Networking Foundation
+ * 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.
@@ -20,7 +20,7 @@
/**
* Custom Exception for BMP IO.
*/
-public class BmpParseException extends Exception {
+public class BmpParseException extends RuntimeException {
private static final long serialVersionUID = 1L;
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
deleted file mode 100644
index 93a94fe..0000000
--- a/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/BmpType.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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/MirroringType.java b/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/MirroringType.java
deleted file mode 100644
index 7fcf4cc..0000000
--- a/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/MirroringType.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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
deleted file mode 100644
index b6e0e8e..0000000
--- a/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/PeerDownReason.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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
deleted file mode 100644
index 9ab93d8..0000000
--- a/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/StatsType.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * 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
deleted file mode 100644
index 5e7ad01..0000000
--- a/apps/bgpmonitoring/api/src/main/java/org/onosproject/bgpmonitoring/TerminationType.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpMessageVer4.java b/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpMessageVer4.java
index fd4669d..4982edf 100644
--- a/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpMessageVer4.java
+++ b/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpMessageVer4.java
@@ -49,7 +49,7 @@
* Reader class for reading BGP messages from channel buffer.
*
*/
- static class Reader implements BgpMessageReader<BgpMessage> {
+ public static class Reader implements BgpMessageReader<BgpMessage> {
@Override
public BgpMessage readFrom(ChannelBuffer cb, BgpHeader bgpHeader)
throws BgpParseException {
diff --git a/utils/misc/src/main/java/org/onlab/packet/bmp/Bmp.java b/utils/misc/src/main/java/org/onlab/packet/bmp/Bmp.java
deleted file mode 100644
index 6721f4d..0000000
--- a/utils/misc/src/main/java/org/onlab/packet/bmp/Bmp.java
+++ /dev/null
@@ -1,204 +0,0 @@
-/*
- * 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.onlab.packet.bmp;
-
-import com.google.common.base.MoreObjects;
-import org.onlab.packet.BasePacket;
-import org.onlab.packet.Deserializer;
-
-import java.nio.ByteBuffer;
-import java.util.Objects;
-
-import static org.onlab.packet.PacketUtils.checkInput;
-
-/**
- * The following common header appears in all BMP messages. The rest of
- * the data in a BMP message is dependent on the Message Type field in
- * the common header.
- * <p>
- * Version (1 byte): Indicates the BMP version. This is set to '3'
- * for all messages defined in this specification. ('1' and '2' were
- * used by draft versions of this document.) Version 0 is reserved
- * and MUST NOT be sent.
- * <p>
- * Message Length (4 bytes): Length of the message in bytes
- * (including headers, data, and encapsulated messages, if any).
- * <p>
- * Message Type (1 byte): This identifies the type of the BMP
- * message. A BMP implementation MUST ignore unrecognized message
- * types upon receipt.
- * <p>
- * Type = 0: Route Monitoring
- * Type = 1: Statistics Report
- * Type = 2: Peer Down Notification
- * Type = 3: Peer Up Notification
- * Type = 4: Initiation Message
- * Type = 5: Termination Message
- * Type = 6: Route Mirroring Message
- */
-public class Bmp extends BasePacket {
-
- /*
-
- 0 1 2 3
- 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
- +-+-+-+-+-+-+-+-+
- | Version |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Message Length |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Msg. Type |
- +---------------+
-
- */
-
-
- public static final short DEFAULT_HEADER_LENGTH = 6;
- public static final int DEFAULT_PACKET_MINIMUM_LENGTH = 4;
-
- protected byte version;
- protected byte type;
- protected int length;
-
-
- /**
- * Sets version field.
- *
- * @param version message version field
- */
- public void setVersion(byte version) {
- this.version = version;
- }
-
- /**
- * Sets message type.
- *
- * @param type message type
- */
- public void setType(byte type) {
- this.type = type;
- }
-
- /**
- * Sets message length.
- *
- * @param length message length
- */
- public void setLength(int length) {
- this.length = length;
- }
-
- /**
- * Returns message length.
- *
- * @return message length
- */
- public int getLength() {
- return this.length;
- }
-
- /**
- * Returns message version.
- *
- * @return message version
- */
- public byte getVersion() {
- return this.version;
- }
-
- /**
- * Returns message type.
- *
- * @return message type
- */
- public byte getType() {
- return this.type;
- }
-
-
- @Override
- public byte[] serialize() {
- final byte[] data = new byte[DEFAULT_HEADER_LENGTH];
- final ByteBuffer bb = ByteBuffer.wrap(data);
-
- bb.put(this.version);
- bb.putInt(this.length);
- bb.put(this.type);
-
- return data;
- }
-
-
- /**
- * Deserializer function for Bmp Packets.
- *
- * @return deserializer function
- */
- public static Deserializer<Bmp> deserializer() {
- return (data, offset, length) -> {
- checkInput(data, offset, length, DEFAULT_HEADER_LENGTH);
-
- ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
- Bmp bmp = new Bmp();
-
- bmp.version = bb.get();
- bmp.length = bb.getInt();
- bmp.type = bb.get();
-
- return bmp;
- };
- }
-
- @Override
- public String toString() {
- return MoreObjects.toStringHelper(getClass())
- .add("version", version)
- .add("type", type)
- .add("length", length)
- .toString();
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(super.hashCode(), version, type, length);
- }
-
- @Override
- public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof Bmp)) {
- return false;
- }
- final Bmp other = (Bmp) obj;
- if (this.version != other.version) {
- return false;
- }
- if (this.type != other.type) {
- return false;
- }
- if (this.length != other.length) {
- return false;
- }
- return true;
- }
-}
-
diff --git a/utils/misc/src/main/java/org/onlab/packet/bmp/BmpPeer.java b/utils/misc/src/main/java/org/onlab/packet/bmp/BmpPeer.java
deleted file mode 100644
index cff7fdc..0000000
--- a/utils/misc/src/main/java/org/onlab/packet/bmp/BmpPeer.java
+++ /dev/null
@@ -1,363 +0,0 @@
-/*
- * 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.onlab.packet.bmp;
-
-import com.google.common.base.MoreObjects;
-import org.onlab.packet.BasePacket;
-import org.onlab.packet.Deserializer;
-import org.slf4j.Logger;
-
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.nio.ByteBuffer;
-import java.util.Arrays;
-import java.util.Objects;
-
-import static org.onlab.packet.PacketUtils.checkInput;
-import static org.slf4j.LoggerFactory.getLogger;
-
-/**
- * The per-peer header follows the common header for most BMP messages.
- * The rest of the data in a BMP message is dependent on the Message
- * Type field in the common header.
- * <p>
- * Peer Type (1 byte): Identifies the type of peer. Currently, three
- * types of peers are identified:
- * <p>
- * * Peer Type = 0: Global Instance Peer
- * * Peer Type = 1: RD Instance Peer
- * * Peer Type = 2: Local Instance Peer
- * <p>
- * o Peer Flags (1 byte): These flags provide more information about
- * the peer. The flags are defined as follows:
- * <p>
- * 0 1 2 3 4 5 6 7
- * +-+-+-+-+-+-+-+-+
- * |V|L|A| Reserved|
- * +-+-+-+-+-+-+-+-+
- * <p>
- * * The V flag indicates that the Peer address is an IPv6 address.
- * For IPv4 peers, this is set to 0.
- * <p>
- * The L flag, if set to 1, indicates that the message reflects
- * the post-policy Adj-RIB-In (i.e., its path attributes reflect
- * the application of inbound policy). It is set to 0 if the
- * message reflects the pre-policy Adj-RIB-In. Locally sourced
- * routes also carry an L flag of 1. See Section 5 for further
- * detail. This flag has no significance when used with route
- * mirroring messages.
- * <p>
- * * The A flag, if set to 1, indicates that the message is
- * formatted using the legacy 2-byte AS_PATH format. If set to 0,
- * the message is formatted using the 4-byte AS_PATH format
- * [RFC6793]. A BMP speaker MAY choose to propagate the AS_PATH
- * information as received from its peer, or it MAY choose to
- * reformat all AS_PATH information into a 4-byte format
- * regardless of how it was received from the peer. In the latter
- * case, AS4_PATH or AS4_AGGREGATOR path attributes SHOULD NOT be
- * sent in the BMP UPDATE message. This flag has no significance
- * when used with route mirroring messages.
- * <p>
- * The remaining bits are reserved for future use. They MUST be
- * transmitted as 0 and their values MUST be ignored on receipt.
- * <p>
- * Peer Distinguisher (8 bytes): Routers today can have multiple
- * instances (example: Layer 3 Virtual Private Networks (L3VPNs)
- * [RFC4364]). This field is present to distinguish peers that
- * belong to one address domain from the other.
- * <p>
- * If the peer is a "Global Instance Peer", this field is zero-
- * filled. If the peer is a "RD Instance Peer", it is set to the
- * route distinguisher of the particular instance the peer belongs
- * to. If the peer is a "Local Instance Peer", it is set to a
- * unique, locally defined value. In all cases, the effect is that
- * the combination of the Peer Type and Peer Distinguisher is
- * sufficient to disambiguate peers for which other identifying
- * information might overlap.
- * <p>
- * Peer Address: The remote IP address associated with the TCP
- * session over which the encapsulated PDU was received. It is 4
- * bytes long if an IPv4 address is carried in this field (with the
- * 12 most significant bytes zero-filled) and 16 bytes long if an
- * IPv6 address is carried in this field.
- * <p>
- * Peer AS: The Autonomous System number of the peer from which the
- * encapsulated PDU was received. If a 16-bit AS number is stored in
- * this field [RFC6793], it should be padded with zeroes in the 16
- * most significant bits.
- * <p>
- * Timestamp: The time when the encapsulated routes were received
- * (one may also think of this as the time when they were installed
- * in the Adj-RIB-In), expressed in seconds and microseconds since
- * midnight (zero hour), January 1, 1970 (UTC). If zero, the time is
- * unavailable. Precision of the timestamp is implementation-
- * dependent.
- * <p>
- * 4.3. Initiation Message
- * <p>
- * The initiation message provides a means for the monitored router to
- * inform the monitoring station of its vendor, software version, and so
- * on. An initiation message MUST be sent as the first message after
- * the TCP session comes up. An initiation message MAY be sent at any
- * point thereafter, if warranted by a change on the monitored router.
- * <p>
- * The initiation message consists of the common BMP header followed by
- * two or more Information TLVs containing information
- * about the monitored router. The sysDescr and sysName Information
- * TLVs MUST be sent, any others are optional. The string TLV MAY be
- * included multiple times.
- */
-public class BmpPeer extends BasePacket {
-
- /*
- 0 1 2 3
- 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Peer Type | Peer Flags |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Peer Distinguisher (present based on peer type) |
- | |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Peer Address (16 bytes) |
- ~ ~
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Peer AS |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Peer BGP ID |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Timestamp (seconds) |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Timestamp (microseconds) |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- */
- public static final short PEER_HEADER_MINIMUM_LENGTH = 42;
-
- public static final short PEER_DISTINGUISHER = 8;
- public static final short IPV4_ADDRSZ = 4;
- public static final short IPV6_ADDRSZ = 16;
-
- protected byte type;
-
- protected byte flags;
-
- protected byte[] peerDistinguisher;
-
- protected InetAddress peerAddress;
-
- protected int peerAs;
-
- protected int peerBgpId;
-
- protected int seconds;
-
- protected int microseconds;
-
- private static Logger log = getLogger(BmpPeer.class);
-
-
- /**
- * Returns Peer Type.
- *
- * @return the peer type
- */
- public byte getType() {
- return type;
- }
-
- /**
- * Returns Peer Flag.
- *
- * @return the peer flag
- */
- public byte getFlag() {
- return flags;
- }
-
- /**
- * Returns Peer Distinguisher.
- *
- * @return the peer distingusiher
- */
- public byte[] getPeerDistinguisher() {
- return peerDistinguisher;
- }
-
- /**
- * Returns Peer IP Address.
- *
- * @return the peer ip address
- */
- public InetAddress getIntAddress() {
- return peerAddress;
- }
-
- /**
- * Returns Peer Autonomous System number.
- *
- * @return the peer AS number
- */
- public int getPeerAs() {
- return peerAs;
- }
-
- /**
- * Returns Peer Bgp Id.
- *
- * @return the bgp id
- */
- public int getPeerBgpId() {
- return peerBgpId;
- }
-
- /**
- * Returns timestamp in sec.
- *
- * @return the timestamp in sec
- */
- public int getSeconds() {
- return seconds;
- }
-
- /**
- * Returns timestamp in micro second.
- *
- * @return the timestamp in micro second
- */
- public int getMicroseconds() {
- return microseconds;
- }
-
-
- @Override
- public byte[] serialize() {
- final byte[] data = new byte[PEER_HEADER_MINIMUM_LENGTH];
- final ByteBuffer bb = ByteBuffer.wrap(data);
-
- bb.put(this.type);
- bb.put(this.flags);
- bb.put(this.peerDistinguisher);
- bb.put(this.peerAddress.getAddress());
- bb.putInt(this.peerAs);
- bb.putInt(this.peerBgpId);
- bb.putInt(this.seconds);
- bb.putInt(this.microseconds);
-
- return data;
- }
-
- public static Deserializer<BmpPeer> deserializer() {
- return (data, offset, length) -> {
- checkInput(data, offset, length, PEER_HEADER_MINIMUM_LENGTH);
-
- ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
- BmpPeer bmpPeer = new BmpPeer();
-
- bmpPeer.type = bb.get();
- bmpPeer.flags = bb.get();
- bmpPeer.peerDistinguisher = new byte[PEER_DISTINGUISHER];
- bb.get(bmpPeer.peerDistinguisher, 0, PEER_DISTINGUISHER);
-
- if ((bmpPeer.flags & 0x80) != 0x00) {
- bmpPeer.peerAddress = toInetAddress(IPV6_ADDRSZ, bb);
- } else {
- bb.position(bb.position() + (IPV6_ADDRSZ - IPV4_ADDRSZ));
- bmpPeer.peerAddress = toInetAddress(IPV4_ADDRSZ, bb);
- }
-
- bmpPeer.peerAs = bb.getInt();
- bmpPeer.peerBgpId = bb.getInt();
- bmpPeer.seconds = bb.getInt();
- bmpPeer.microseconds = bb.getInt();
-
- return bmpPeer;
- };
- }
-
- private static InetAddress toInetAddress(int length, ByteBuffer bb) {
- byte[] address = new byte[length];
- bb.get(address, 0, length);
- InetAddress ipAddress = null;
- try {
- ipAddress = InetAddress.getByAddress(address);
- } catch (UnknownHostException e) {
- log.error("InetAddress conversion failed");
- }
-
- return ipAddress;
- }
-
- @Override
- public String toString() {
-
- return MoreObjects.toStringHelper(getClass())
- .add("flags", flags)
- .add("type", type)
- .add("peerDistinguisher", Arrays.toString(peerDistinguisher))
- .add("peerAddress", peerAddress.getHostAddress())
- .add("peerAs", peerAs)
- .add("peerBgpId", peerBgpId)
- .add("seconds", seconds)
- .add("microseconds", microseconds)
- .toString();
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(super.hashCode(), flags, type, peerAddress,
- Arrays.hashCode(peerDistinguisher), peerAs, peerBgpId, seconds, microseconds);
- }
-
- @Override
- public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof BmpPeer)) {
- return false;
- }
- final BmpPeer other = (BmpPeer) obj;
- if (this.type != other.type) {
- return false;
- }
- if (this.flags != other.flags) {
- return false;
- }
- if (!Arrays.equals(this.peerDistinguisher, other.peerDistinguisher)) {
- return false;
- }
- if (this.peerAddress != other.peerAddress) {
- return false;
- }
- if (this.peerAs != other.peerAs) {
- return false;
- }
- if (this.peerBgpId != other.peerBgpId) {
- return false;
- }
- if (this.seconds != other.seconds) {
- return false;
- }
- if (this.microseconds != other.microseconds) {
- return false;
- }
- return true;
- }
-
-}
diff --git a/utils/misc/src/main/java/org/onlab/packet/bmp/package-info.java b/utils/misc/src/main/java/org/onlab/packet/bmp/package-info.java
deleted file mode 100644
index ea8cb4a..0000000
--- a/utils/misc/src/main/java/org/onlab/packet/bmp/package-info.java
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * 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.
- */
-/**
- * Utility for decoding bmp options.
- */
-package org.onlab.packet.bmp;
\ No newline at end of file
diff --git a/utils/misc/src/test/java/org/onlab/packet/bmp/BmpPeerTest.java b/utils/misc/src/test/java/org/onlab/packet/bmp/BmpPeerTest.java
deleted file mode 100644
index 4c73dc9..0000000
--- a/utils/misc/src/test/java/org/onlab/packet/bmp/BmpPeerTest.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * 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.onlab.packet.bmp;
-
-import com.google.common.testing.EqualsTester;
-import org.apache.commons.lang.StringUtils;
-import org.junit.Before;
-import org.junit.Test;
-import org.onlab.packet.Deserializer;
-import org.onlab.packet.PacketTestUtils;
-
-import java.net.InetAddress;
-import java.nio.ByteBuffer;
-import java.util.Arrays;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Unit test for BmpPeer class.
- */
-public class BmpPeerTest {
- private Deserializer<BmpPeer> deserializer;
-
- private byte type = 0;
- private byte flags = 0;
- private byte[] peerDistinguisher = new byte[BmpPeer.PEER_DISTINGUISHER];
- private InetAddress peerAddress;
- private int peerAs = 60300;
- private int peerBgpId = 65323;
- private int seconds = 1024;
- private int microseconds = 0;
-
- private byte[] headerBytes;
-
-
- @Before
- public void setUp() throws Exception {
- deserializer = BmpPeer.deserializer();
- peerAddress = InetAddress.getByAddress(new byte[]{127, 0, 0, 1});
-
- ByteBuffer bb = ByteBuffer.allocate(BmpPeer.PEER_HEADER_MINIMUM_LENGTH);
-
- bb.put(this.type);
- bb.put(this.flags);
- bb.put(this.peerDistinguisher);
- bb.put(new byte[]{0, 0, 0, 0,
- 0, 0, 0, 0,
- 0, 0, 0, 0,
- 127, 0, 0, 1});
- bb.putInt(this.peerAs);
- bb.putInt(this.peerBgpId);
- bb.putInt(this.seconds);
- bb.putInt(this.microseconds);
-
- headerBytes = bb.array();
- }
-
- @Test
- public void testDeserializeBadInput() throws Exception {
- PacketTestUtils.testDeserializeBadInput(deserializer);
- }
-
- @Test
- public void testDeserializeTruncated() throws Exception {
- PacketTestUtils.testDeserializeTruncated(deserializer, headerBytes);
- }
-
- /**
- * Test Deserialize and getters.
- *
- * @throws Exception
- */
- @Test
- public void testDeserialize() throws Exception {
- BmpPeer bmpPeer = deserializer.deserialize(headerBytes, 0, headerBytes.length);
-
- assertEquals(type, bmpPeer.getType());
- assertEquals(flags, bmpPeer.getFlag());
- assertEquals(peerDistinguisher.length, bmpPeer.getPeerDistinguisher().length);
- assertEquals(peerAddress.getHostAddress(), bmpPeer.getIntAddress().getHostAddress());
- assertEquals(peerAs, bmpPeer.getPeerAs());
- assertEquals(peerBgpId, bmpPeer.getPeerBgpId());
- assertEquals(seconds, bmpPeer.getSeconds());
- assertEquals(microseconds, bmpPeer.getMicroseconds());
- }
-
- /**
- * Tests toString.
- *
- * @throws Exception
- */
- @Test
- public void testToStringBmp() throws Exception {
- BmpPeer bmpPeer = deserializer.deserialize(headerBytes, 0, headerBytes.length);
- String str = bmpPeer.toString();
-
- assertTrue(StringUtils.contains(str, "flags=" + flags));
- assertTrue(StringUtils.contains(str, "type=" + type));
- assertTrue(StringUtils.contains(str, "peerDistinguisher=" + Arrays.toString(peerDistinguisher)));
- assertTrue(StringUtils.contains(str, "peerAddress=" + peerAddress.getHostAddress()));
- assertTrue(StringUtils.contains(str, "peerAs=" + peerAs));
- assertTrue(StringUtils.contains(str, "peerBgpId=" + peerBgpId));
- assertTrue(StringUtils.contains(str, "seconds=" + seconds));
- assertTrue(StringUtils.contains(str, "microseconds=" + microseconds));
- }
-
- /**
- * Tests equals method.
- *
- * @throws Exception
- */
- @Test
- public void testEquality() throws Exception {
- BmpPeer bmpPeer = deserializer.deserialize(headerBytes, 0, headerBytes.length);
- new EqualsTester()
- .addEqualityGroup(bmpPeer).testEquals();
- }
-}
diff --git a/utils/misc/src/test/java/org/onlab/packet/bmp/BmpTest.java b/utils/misc/src/test/java/org/onlab/packet/bmp/BmpTest.java
deleted file mode 100644
index d3eca29..0000000
--- a/utils/misc/src/test/java/org/onlab/packet/bmp/BmpTest.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * 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.onlab.packet.bmp;
-
-import com.google.common.testing.EqualsTester;
-import org.apache.commons.lang3.StringUtils;
-import org.junit.Before;
-import org.junit.Test;
-import org.onlab.packet.Deserializer;
-import org.onlab.packet.PacketTestUtils;
-
-import java.nio.ByteBuffer;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Unit test for Bmp class.
- */
-public class BmpTest {
- private Deserializer<Bmp> deserializer;
-
- private byte version = 3;
- private int length = 6;
- private byte type = 1;
-
- private byte[] headerBytes;
-
- @Before
- public void setUp() throws Exception {
- deserializer = Bmp.deserializer();
- ByteBuffer bb = ByteBuffer.allocate(Bmp.DEFAULT_HEADER_LENGTH);
-
- bb.put(version);
- bb.putInt(length);
- bb.put(type);
-
- headerBytes = bb.array();
- }
-
- @Test
- public void testDeserializeBadInput() throws Exception {
- PacketTestUtils.testDeserializeBadInput(deserializer);
- }
-
- @Test
- public void testDeserializeTruncated() throws Exception {
- PacketTestUtils.testDeserializeTruncated(deserializer, headerBytes);
- }
-
- /**
- * Test Deserialize and getters.
- */
- @Test
- public void testDeserialize() throws Exception {
- Bmp bmp = deserializer.deserialize(headerBytes, 0, headerBytes.length);
-
- assertEquals(version, bmp.getVersion());
- assertEquals(type, bmp.getType());
- assertEquals(length, bmp.getLength());
- }
-
- /**
- * Tests toString.
- *
- * @throws Exception
- */
- @Test
- public void testToStringBmp() throws Exception {
- Bmp bmp = deserializer.deserialize(headerBytes, 0, headerBytes.length);
- String str = bmp.toString();
-
- assertTrue(StringUtils.contains(str, "version=" + version));
- assertTrue(StringUtils.contains(str, "type=" + type));
- assertTrue(StringUtils.contains(str, "length=" + length));
- }
-
- /**
- * Tests equals method.
- *
- * @throws Exception
- */
- @Test
- public void testEquality() throws Exception {
- Bmp bmp = deserializer.deserialize(headerBytes, 0, headerBytes.length);
- new EqualsTester()
- .addEqualityGroup(bmp).testEquals();
- }
-
-}
diff --git a/utils/misc/src/test/java/org/onlab/packet/bmp/package-info.java b/utils/misc/src/test/java/org/onlab/packet/bmp/package-info.java
deleted file mode 100644
index 7df018f..0000000
--- a/utils/misc/src/test/java/org/onlab/packet/bmp/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * 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 Packet test.
- */
-package org.onlab.packet.bmp;
\ No newline at end of file