Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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 | */ |
| 26 | @Beta |
| 27 | public final class PiCounterCellData { |
| 28 | |
| 29 | private final PiCounterCellId cellId; |
| 30 | private final long packets; |
| 31 | private final long bytes; |
| 32 | |
| 33 | /** |
| 34 | * Creates a new counter cell data for the given cell identifier, number of packets and bytes. |
| 35 | * |
| 36 | * @param cellId counter cell identifier |
| 37 | * @param packets number of packets |
| 38 | * @param bytes number of bytes |
| 39 | */ |
| 40 | public PiCounterCellData(PiCounterCellId cellId, long packets, long bytes) { |
| 41 | this.cellId = cellId; |
| 42 | this.packets = packets; |
| 43 | this.bytes = bytes; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Returns the cell identifier. |
| 48 | * |
| 49 | * @return cell identifier |
| 50 | */ |
| 51 | public PiCounterCellId cellId() { |
| 52 | return cellId; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Returns the packet count value contained by this cell. |
| 57 | * |
| 58 | * @return number of packets |
| 59 | */ |
| 60 | public long packets() { |
| 61 | return packets; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Returns the byte count value contained by this cell. |
| 66 | * |
| 67 | * @return number of bytes |
| 68 | */ |
| 69 | public long bytes() { |
| 70 | return bytes; |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public boolean equals(Object o) { |
| 75 | if (this == o) { |
| 76 | return true; |
| 77 | } |
| 78 | if (!(o instanceof PiCounterCellData)) { |
| 79 | return false; |
| 80 | } |
| 81 | PiCounterCellData that = (PiCounterCellData) o; |
| 82 | return packets == that.packets && |
| 83 | bytes == that.bytes && |
| 84 | Objects.equal(cellId, that.cellId); |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public int hashCode() { |
| 89 | return Objects.hashCode(cellId, packets, bytes); |
| 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public String toString() { |
| 94 | return MoreObjects.toStringHelper(this) |
| 95 | .add("cellId", cellId) |
| 96 | .add("packets", packets) |
| 97 | .add("bytes", bytes) |
| 98 | .toString(); |
| 99 | } |
| 100 | } |