Deserialize interface VG and VLAN counter
Change-Id: I7dc8e3f23a5c099cbf1bf7e34649b4714b8aee41
diff --git a/apps/ipflow-monitor/sflow/api/src/main/java/org/onosproject/sflow/VgCounter.java b/apps/ipflow-monitor/sflow/api/src/main/java/org/onosproject/sflow/VgCounter.java
index f229437..aa85d9b 100644
--- a/apps/ipflow-monitor/sflow/api/src/main/java/org/onosproject/sflow/VgCounter.java
+++ b/apps/ipflow-monitor/sflow/api/src/main/java/org/onosproject/sflow/VgCounter.java
@@ -16,11 +16,18 @@
package org.onosproject.sflow;
import com.google.common.base.MoreObjects;
+import java.nio.ByteBuffer;
+import org.onlab.packet.BasePacket;
+import org.onlab.packet.Deserializer;
+
+import java.util.function.BiPredicate;
/**
* Represents VG counters for network interfaces.
*/
-public final class VgCounter {
+public final class VgCounter extends BasePacket {
+
+ public static final int VG_COUNTER_LENGTH = 80;
private InterfaceCounter generic;
private int dot12InHighPriorityFrames;
@@ -214,6 +221,58 @@
}
/**
+ * Deserializer function for sFlow interface vg counter.
+ *
+ * @return deserializer function
+ */
+ public static Deserializer<VgCounter> deserializer() {
+ return (data, offset, length) -> {
+
+ BiPredicate<ByteBuffer, Integer> isValidBuffer = (b, l)
+ -> b.hasRemaining() && b.remaining() >= l;
+
+ ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
+ byte[] ifCounterBytes;
+ if (!isValidBuffer.test(bb, InterfaceCounter.INTERFACE_COUNTER_LENGTH)) {
+ throw new IllegalStateException("Invalid interface vg counter buffer size.");
+ }
+
+ ifCounterBytes = new byte[InterfaceCounter.INTERFACE_COUNTER_LENGTH];
+ bb.get(ifCounterBytes);
+
+ InterfaceCounter interfaceCounter = InterfaceCounter.deserializer().deserialize(ifCounterBytes,
+ 0, InterfaceCounter.INTERFACE_COUNTER_LENGTH);
+ if (!isValidBuffer.test(bb, VG_COUNTER_LENGTH)) {
+ throw new IllegalStateException("Invalid interface vg counter buffer size.");
+ }
+
+ Builder builder = new Builder();
+ return builder.generic(interfaceCounter)
+ .dot12InHighPriorityFrames(bb.getInt())
+ .dot12InHighPriorityOctets(bb.getLong())
+ .dot12InNormPriorityFrames(bb.getInt())
+ .dot12InNormPriorityOctets(bb.getLong())
+ .dot12InIpmErrors(bb.getInt())
+ .dot12InOversizeFrameErrors(bb.getInt())
+ .dot12InDataErrors(bb.getInt())
+ .dot12InNullAddressedFrames(bb.getInt())
+ .dot12OutHighPriorityFrames(bb.getInt())
+ .dot12OutHighPriorityOctets(bb.getLong())
+ .dot12TransitionIntoTrainings(bb.getInt())
+ .dot12HCInHighPriorityOctets(bb.getLong())
+ .dot12HCInNormPriorityOctets(bb.getLong())
+ .dot12HCOutHighPriorityOctets(bb.getLong())
+ .build();
+
+ };
+ }
+
+ @Override
+ public byte[] serialize() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ /**
* Builder pattern to create an instance of InterfaceCounter.
*/
private static class Builder {
diff --git a/apps/ipflow-monitor/sflow/api/src/main/java/org/onosproject/sflow/VlanCounter.java b/apps/ipflow-monitor/sflow/api/src/main/java/org/onosproject/sflow/VlanCounter.java
index 798a260..deb699a 100644
--- a/apps/ipflow-monitor/sflow/api/src/main/java/org/onosproject/sflow/VlanCounter.java
+++ b/apps/ipflow-monitor/sflow/api/src/main/java/org/onosproject/sflow/VlanCounter.java
@@ -16,11 +16,19 @@
package org.onosproject.sflow;
import com.google.common.base.MoreObjects;
+import java.nio.ByteBuffer;
+import org.onlab.packet.BasePacket;
+import org.onlab.packet.Deserializer;
+
+import java.util.function.BiPredicate;
/**
* Represents VLAN counters for network interfaces.
*/
-public final class VlanCounter {
+public final class VlanCounter extends BasePacket {
+
+ public static final int VLAN_COUNTER_LENGTH = 28;
+
private int vlanId;
private long octets;
private int ucastPkts;
@@ -105,6 +113,38 @@
}
/**
+ * Deserializer function for sFlow interface vlan counter.
+ *
+ * @return deserializer function
+ */
+ public static Deserializer<VlanCounter> deserializer() {
+ return (data, offset, length) -> {
+
+ BiPredicate<ByteBuffer, Integer> isValidBuffer = (b, l)
+ -> b.hasRemaining() && b.remaining() >= l;
+
+ ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
+ if (!isValidBuffer.test(bb, VLAN_COUNTER_LENGTH)) {
+ throw new IllegalStateException("Invalid interface vlan counter buffer size.");
+ }
+
+ Builder builder = new Builder();
+ return builder.vlanId(bb.getInt())
+ .octets(bb.getLong())
+ .ucastPkts(bb.getInt())
+ .multicastPkts(bb.getInt())
+ .broadcastPkts(bb.getInt())
+ .discards(bb.getInt())
+ .build();
+ };
+ }
+
+ @Override
+ public byte[] serialize() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ /**
* Builder pattern to create an instance of VlanCounter.
*/
public static class Builder {