blob: 34ebd7b1a929ed46932fd793d5a97ff59c0b2832 [file] [log] [blame]
steven308017632e152018-10-20 00:51:08 +08001/*
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
17package org.onosproject.net.pi.runtime;
18
19import com.google.common.annotations.Beta;
20import com.google.common.base.MoreObjects;
21import com.google.common.base.Objects;
Carmelo Cascone4c289b72019-01-22 15:30:45 -080022import org.onosproject.net.DeviceId;
steven308017632e152018-10-20 00:51:08 +080023
24/**
25 * Counter cell of a protocol-independent pipeline.
26 */
27@Beta
Carmelo Cascone4c289b72019-01-22 15:30:45 -080028public final class PiCounterCell implements PiEntity {
steven308017632e152018-10-20 00:51:08 +080029
30 private final PiCounterCellId cellId;
31 private final PiCounterCellData counterData;
32
33 /**
Carmelo Cascone4c289b72019-01-22 15:30:45 -080034 * Creates a new counter cell for the given cell identifier and counter cell
35 * data.
steven308017632e152018-10-20 00:51:08 +080036 *
Carmelo Cascone4c289b72019-01-22 15:30:45 -080037 * @param cellId counter cell identifier
38 * @param piCounterCellData counter cell data
steven308017632e152018-10-20 00:51:08 +080039 */
40 public PiCounterCell(PiCounterCellId cellId, PiCounterCellData piCounterCellData) {
41 this.cellId = cellId;
42 this.counterData = piCounterCellData;
43 }
44
45 /**
Carmelo Cascone4c289b72019-01-22 15:30:45 -080046 * Creates a new counter cell for the given cell identifier, number of
47 * packets and bytes.
steven308017632e152018-10-20 00:51:08 +080048 *
49 * @param cellId counter cell identifier
Carmelo Cascone4c289b72019-01-22 15:30:45 -080050 * @param packets number of packets
51 * @param bytes number of bytes
steven308017632e152018-10-20 00:51:08 +080052 */
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 Cascone4c289b72019-01-22 15:30:45 -080077 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
steven308017632e152018-10-20 00:51:08 +080087 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}