Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 1 | /* |
steven30801 | 8692bb2 | 2018-10-20 00:51:08 +0800 | [diff] [blame] | 2 | * Copyright 2018-present Open Networking Foundation |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.net.pi.runtime; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | import com.google.common.base.MoreObjects; |
| 21 | import com.google.common.base.Objects; |
| 22 | |
| 23 | /** |
| 24 | * Data of a counter cell of a protocol-independent pipeline. |
| 25 | */ |
steven30801 | 8692bb2 | 2018-10-20 00:51:08 +0800 | [diff] [blame] | 26 | |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 27 | @Beta |
| 28 | public final class PiCounterCellData { |
| 29 | |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 30 | private final long packets; |
| 31 | private final long bytes; |
| 32 | |
| 33 | /** |
steven30801 | 8692bb2 | 2018-10-20 00:51:08 +0800 | [diff] [blame] | 34 | * Creates a new counter cell data for the given number of packets and bytes. |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 35 | * |
steven30801 | 8692bb2 | 2018-10-20 00:51:08 +0800 | [diff] [blame] | 36 | * @param packets number of packets |
| 37 | * @param bytes number of bytes |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 38 | */ |
steven30801 | 8692bb2 | 2018-10-20 00:51:08 +0800 | [diff] [blame] | 39 | public PiCounterCellData(long packets, long bytes) { |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 40 | this.packets = packets; |
| 41 | this.bytes = bytes; |
| 42 | } |
| 43 | |
| 44 | /** |
steven30801 | 8692bb2 | 2018-10-20 00:51:08 +0800 | [diff] [blame] | 45 | * Returns the packet count value contained by this counter data. |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 46 | * |
| 47 | * @return number of packets |
| 48 | */ |
| 49 | public long packets() { |
| 50 | return packets; |
| 51 | } |
| 52 | |
| 53 | /** |
steven30801 | 8692bb2 | 2018-10-20 00:51:08 +0800 | [diff] [blame] | 54 | * Returns the byte count value contained by this counter data. |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 55 | * |
| 56 | * @return number of bytes |
| 57 | */ |
| 58 | public long bytes() { |
| 59 | return bytes; |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public boolean equals(Object o) { |
| 64 | if (this == o) { |
| 65 | return true; |
| 66 | } |
| 67 | if (!(o instanceof PiCounterCellData)) { |
| 68 | return false; |
| 69 | } |
| 70 | PiCounterCellData that = (PiCounterCellData) o; |
| 71 | return packets == that.packets && |
steven30801 | 8692bb2 | 2018-10-20 00:51:08 +0800 | [diff] [blame] | 72 | bytes == that.bytes; |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public int hashCode() { |
steven30801 | 8692bb2 | 2018-10-20 00:51:08 +0800 | [diff] [blame] | 77 | return Objects.hashCode(packets, bytes); |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public String toString() { |
| 82 | return MoreObjects.toStringHelper(this) |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 83 | .add("packets", packets) |
| 84 | .add("bytes", bytes) |
| 85 | .toString(); |
| 86 | } |
| 87 | } |