steven30801 | 7632e15 | 2018-10-20 00:51:08 +0800 | [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; |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 22 | import org.onosproject.net.DeviceId; |
steven30801 | 7632e15 | 2018-10-20 00:51:08 +0800 | [diff] [blame] | 23 | |
| 24 | /** |
| 25 | * Counter cell of a protocol-independent pipeline. |
| 26 | */ |
| 27 | @Beta |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 28 | public final class PiCounterCell implements PiEntity { |
steven30801 | 7632e15 | 2018-10-20 00:51:08 +0800 | [diff] [blame] | 29 | |
| 30 | private final PiCounterCellId cellId; |
| 31 | private final PiCounterCellData counterData; |
| 32 | |
| 33 | /** |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 34 | * Creates a new counter cell for the given cell identifier and counter cell |
| 35 | * data. |
steven30801 | 7632e15 | 2018-10-20 00:51:08 +0800 | [diff] [blame] | 36 | * |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 37 | * @param cellId counter cell identifier |
| 38 | * @param piCounterCellData counter cell data |
steven30801 | 7632e15 | 2018-10-20 00:51:08 +0800 | [diff] [blame] | 39 | */ |
| 40 | public PiCounterCell(PiCounterCellId cellId, PiCounterCellData piCounterCellData) { |
| 41 | this.cellId = cellId; |
| 42 | this.counterData = piCounterCellData; |
| 43 | } |
| 44 | |
| 45 | /** |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 46 | * Creates a new counter cell for the given cell identifier, number of |
| 47 | * packets and bytes. |
steven30801 | 7632e15 | 2018-10-20 00:51:08 +0800 | [diff] [blame] | 48 | * |
| 49 | * @param cellId counter cell identifier |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 50 | * @param packets number of packets |
| 51 | * @param bytes number of bytes |
steven30801 | 7632e15 | 2018-10-20 00:51:08 +0800 | [diff] [blame] | 52 | */ |
| 53 | public PiCounterCell(PiCounterCellId cellId, long packets, long bytes) { |
| 54 | this.cellId = cellId; |
| 55 | this.counterData = new PiCounterCellData(packets, bytes); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Returns the cell identifier. |
| 60 | * |
| 61 | * @return cell identifier |
| 62 | */ |
| 63 | public PiCounterCellId cellId() { |
| 64 | return cellId; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Returns the data contained by this cell. |
| 69 | * |
| 70 | * @return counter cell data |
| 71 | */ |
| 72 | public PiCounterCellData data() { |
| 73 | return counterData; |
| 74 | } |
| 75 | |
| 76 | @Override |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 77 | public PiEntityType piEntityType() { |
| 78 | return PiEntityType.COUNTER_CELL; |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public PiCounterCellHandle handle(DeviceId deviceId) { |
| 83 | return PiCounterCellHandle.of(deviceId, this); |
| 84 | } |
| 85 | |
| 86 | @Override |
steven30801 | 7632e15 | 2018-10-20 00:51:08 +0800 | [diff] [blame] | 87 | public boolean equals(Object o) { |
| 88 | if (this == o) { |
| 89 | return true; |
| 90 | } |
| 91 | if (!(o instanceof PiCounterCell)) { |
| 92 | return false; |
| 93 | } |
| 94 | PiCounterCell that = (PiCounterCell) o; |
| 95 | return Objects.equal(cellId, that.cellId) && |
| 96 | Objects.equal(counterData, that.counterData); |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public int hashCode() { |
| 101 | return Objects.hashCode(cellId, counterData); |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public String toString() { |
| 106 | return MoreObjects.toStringHelper(this) |
| 107 | .add("cellId", cellId) |
| 108 | .add("counterData", counterData) |
| 109 | .toString(); |
| 110 | } |
| 111 | } |