Flow sample packet

Change-Id: I8949b1c60bb37ab5ab4b7e2387f19287eb17ad1e
diff --git a/apps/ipflow-monitor/sflow/api/src/main/java/org/onosproject/sflow/FlowSample.java b/apps/ipflow-monitor/sflow/api/src/main/java/org/onosproject/sflow/FlowSample.java
index fbce79c..73dff7b 100644
--- a/apps/ipflow-monitor/sflow/api/src/main/java/org/onosproject/sflow/FlowSample.java
+++ b/apps/ipflow-monitor/sflow/api/src/main/java/org/onosproject/sflow/FlowSample.java
@@ -15,10 +15,14 @@
  */
 package org.onosproject.sflow;
 
-import java.util.List;
-
 import org.onlab.packet.Deserializer;
 
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+
+import com.google.common.base.MoreObjects;
+
 /**
  * A sample involves either copying the packet's header, or
  * extracting features from the packet (see sFlow Datagram Format for a
@@ -90,4 +94,302 @@
         };
     }
 
+    @Override
+    public int hashCode() {
+        int hash = 3;
+        hash = 59 * hash + Objects.hashCode(this.type);
+        hash = 59 * hash + this.length;
+        hash = 59 * hash + this.sequenceNumber;
+        hash = 59 * hash + this.sourceId;
+        hash = 59 * hash + this.numberOfRecords;
+        hash = 59 * hash + this.samplingRate;
+        hash = 59 * hash + this.samplePool;
+        hash = 59 * hash + this.inputInterfaceId;
+        hash = 59 * hash + this.outputInterfaceId;
+        hash = 59 * hash + Objects.hashCode(this.records);
+        return hash;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        final FlowSample other = (FlowSample) obj;
+        if (this.type != other.type) {
+            return false;
+        }
+        if (this.length != other.length) {
+            return false;
+        }
+        if (this.sequenceNumber != other.sequenceNumber) {
+            return false;
+        }
+        if (this.sourceId != other.sourceId) {
+            return false;
+        }
+        if (this.sourceIndex != other.sourceIndex) {
+            return false;
+        }
+        if (this.numberOfRecords != other.numberOfRecords) {
+            return false;
+        }
+        if (this.samplingRate != other.samplingRate) {
+            return false;
+        }
+        if (this.samplePool != other.samplePool) {
+            return false;
+        }
+        if (this.drops != other.drops) {
+            return false;
+        }
+        if (this.inputInterfaceId != other.inputInterfaceId) {
+            return false;
+        }
+        if (this.outputInterfaceId != other.outputInterfaceId) {
+            return false;
+        }
+        return Objects.equals(this.records, other.records);
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(getClass())
+                .add("enterprise", enterprise)
+                .add("type", type)
+                .add("length", length)
+                .add("sequenceNumber", sequenceNumber)
+                .add("sourceId", sourceId)
+                .add("sourceIndex", sourceIndex)
+                .add("numberOfRecords", numberOfRecords)
+                .add("samplingRate", samplingRate)
+                .add("samplePool", samplePool)
+                .add("drops", drops)
+                .add("inputInterfaceId", inputInterfaceId)
+                .add("inputInterfaceValue", inputInterfaceValue)
+                .add("outputInterfaceId", outputInterfaceId)
+                .add("outputInterfaceValue", outputInterfaceValue)
+                .add("records", records)
+                .toString();
+    }
+
+    /**
+     * Builder for sFlow packet.
+     */
+    private static class Builder {
+
+        private int enterprise;
+
+        private SflowSample.Type type;
+
+        private int length;
+
+        private int sequenceNumber;
+
+        private int sourceId;
+
+        private int sourceIndex;
+
+        private int numberOfRecords;
+
+        private int samplingRate;
+
+        private int samplePool;
+
+        private int drops;
+
+        private int inputInterfaceId;
+
+        private int inputInterfaceValue;
+
+        private int outputInterfaceId;
+
+        private int outputInterfaceValue;
+
+        private List<Object> records = new LinkedList<>();
+
+        /**
+         * Setter sFlow packet sampling rate.
+         *
+         * @param samplingRate sampling rate.
+         * @return this class builder.
+         */
+        public Builder samplingRate(int samplingRate) {
+            this.samplingRate = samplingRate;
+            return this;
+        }
+
+        /**
+         * Setter sFlow packet sampling pool.
+         *
+         * @param samplePool sampling pool.
+         * @return this class builder.
+         */
+        public Builder samplePool(int samplePool) {
+            this.samplePool = samplePool;
+            return this;
+        }
+
+        /**
+         * Setter sFlow packet drops.
+         *
+         * @param drops packet drops.
+         * @return this class builder.
+         */
+        public Builder drops(int drops) {
+            this.drops = drops;
+            return this;
+        }
+
+        /**
+         * Setter sFlow packet ingress interface.
+         *
+         * @param inputInterfaceId ingress interface id.
+         * @return this class builder.
+         */
+        public Builder inputInterfaceId(int inputInterfaceId) {
+            this.inputInterfaceId = inputInterfaceId;
+            return this;
+        }
+
+        /**
+         * Setter sFlow packet ingress interface value.
+         *
+         * @param inputInterfaceValue ingress interface value.
+         * @return this class builder.
+         */
+        public Builder inputInterfaceValue(int inputInterfaceValue) {
+            this.inputInterfaceValue = inputInterfaceValue;
+            return this;
+        }
+
+        /**
+         * Setter sFlow packet egress interface.
+         *
+         * @param outputInterfaceId egress interface id.
+         * @return this class builder.
+         */
+        public Builder outputInterfaceId(int outputInterfaceId) {
+            this.outputInterfaceId = outputInterfaceId;
+            return this;
+        }
+
+        /**
+         * Setter sFlow packet egress interface value.
+         *
+         * @param outputInterfaceValue egress interface value.
+         * @return this class builder.
+         */
+        public Builder outputInterfaceValue(int outputInterfaceValue) {
+            this.outputInterfaceValue = outputInterfaceValue;
+            return this;
+        }
+
+        /**
+         * Setter sFlow flow packet record.
+         *
+         * @param records flow packet records.
+         * @return this class builder.
+         */
+        public Builder records(List<Object> records) {
+            this.records = records;
+            return this;
+        }
+
+        /**
+         * Setter sFlow flow packet record.
+         *
+         * @param record flow packet record.
+         * @return this class builder.
+         */
+        public Builder record(Object record) {
+            this.records.add(record);
+            return this;
+        }
+
+        /**
+         * Setter sFlow flow packet record count.
+         *
+         * @param numberOfRecords flow packet record count.
+         * @return this class builder.
+         */
+        public Builder numberOfRecords(int numberOfRecords) {
+            this.numberOfRecords = numberOfRecords;
+            return this;
+        }
+
+        /**
+         * Setter sFlow agent source index.
+         *
+         * @param sourceIndex agent source index.
+         * @return this class builder.
+         */
+        public Builder sourceIndex(int sourceIndex) {
+            this.sourceIndex = sourceIndex;
+            return this;
+        }
+
+        /**
+         * Setter sFlow agent source id.
+         *
+         * @param sourceId agent source id.
+         * @return this class builder.
+         */
+        public Builder sourceId(int sourceId) {
+            this.sourceId = sourceId;
+            return this;
+        }
+
+        /**
+         * Setter sFlow flow packet sequence number.
+         *
+         * @param sequenceNumber flow packet sequence number.
+         * @return this class builder.
+         */
+        public Builder sequenceNumber(int sequenceNumber) {
+            this.sequenceNumber = sequenceNumber;
+            return this;
+        }
+
+        /**
+         * Setter sFlow sample length.
+         *
+         * @param length sample length.
+         * @return this class builder.
+         */
+        public Builder length(int length) {
+            this.length = length;
+            return this;
+        }
+
+        /**
+         * Setter sFlow sample type.
+         *
+         * @param type sFlow sample type.
+         * @return this class builder.
+         */
+        public Builder type(SflowSample.Type type) {
+            this.type = type;
+            return this;
+        }
+
+        /**
+         * Setter sFlow enterprise id.
+         *
+         * @param enterprise sFlow enterprise id.
+         * @return this class builder.
+         */
+        public Builder enterprise(int enterprise) {
+            this.enterprise = enterprise;
+            return this;
+        }
+
+
+    }
 }
\ No newline at end of file
diff --git a/apps/ipflow-monitor/sflow/api/src/main/java/org/onosproject/sflow/SflowSample.java b/apps/ipflow-monitor/sflow/api/src/main/java/org/onosproject/sflow/SflowSample.java
index a05bb6b..d150739 100644
--- a/apps/ipflow-monitor/sflow/api/src/main/java/org/onosproject/sflow/SflowSample.java
+++ b/apps/ipflow-monitor/sflow/api/src/main/java/org/onosproject/sflow/SflowSample.java
@@ -32,19 +32,19 @@
  */
 public abstract class SflowSample extends BasePacket {
 
-    private int enterprise;
+    int enterprise;
 
-    private Type type;
+    Type type;
 
-    private int length;
+    int length;
 
-    private int sequenceNumber;
+    int sequenceNumber;
 
-    private int sourceId;
+    int sourceId;
 
-    private int sourceIndex;
+    int sourceIndex;
 
-    private int numberOfRecords;
+    int numberOfRecords;
 
     /**
      * Get sFlow agent enterprise id.