Record Class CounterEntry

java.lang.Object
java.lang.Record
io.github.zhh2001.jp4.entity.CounterEntry
Record Components:
counterName - the counter's fully-qualified P4 name (resolved from the wire counter_id during read response parsing); never null
index - the cell index within the counter array, as returned by the device
packetCount - cumulative packet count for the cell; meaningful for PACKETS and BOTH unit counters
byteCount - cumulative byte count for the cell; meaningful for BYTES and BOTH unit counters

public record CounterEntry(String counterName, long index, long packetCount, long byteCount) extends Record
One P4 counter cell returned by P4Switch.readCounter. The record carries the counter's fully-qualified P4 name, the cell index within the counter array, and the two cumulative values BMv2 reports back: packetCount and byteCount.

Which of the two counts is meaningful depends on the counter's unit, available through P4Info.counter(counterName).unit(): a BYTES counter reports byte_count and leaves packet_count at 0; a PACKETS counter does the opposite; a BOTH counter populates both. The record stores both fields uniformly as primitive long to keep the wire mapping unambiguous; consumers interpret the appropriate field for their counter's unit.

Records are immutable. The canonical constructor rejects null in the reference component; the long components carry no null surface.

Since:
1.4.0
  • Constructor Details

    • CounterEntry

      public CounterEntry(String counterName, long index, long packetCount, long byteCount)
      Creates an instance of a CounterEntry record class.
      Parameters:
      counterName - the value for the counterName record component
      index - the value for the index record component
      packetCount - the value for the packetCount record component
      byteCount - the value for the byteCount record component
  • Method Details

    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • counterName

      public String counterName()
      Returns the value of the counterName record component.
      Returns:
      the value of the counterName record component
    • index

      public long index()
      Returns the value of the index record component.
      Returns:
      the value of the index record component
    • packetCount

      public long packetCount()
      Returns the value of the packetCount record component.
      Returns:
      the value of the packetCount record component
    • byteCount

      public long byteCount()
      Returns the value of the byteCount record component.
      Returns:
      the value of the byteCount record component