blob: 9508cbca3e937b6ddc6395c0e97ccc6b8b642592 [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;
22
23/**
24 * Counter cell of a protocol-independent pipeline.
25 */
26@Beta
27public final class PiCounterCell {
28
29 private final PiCounterCellId cellId;
30 private final PiCounterCellData counterData;
31
32 /**
33 * Creates a new counter cell for the given cell identifier and counter cell data.
34 *
35 * @param cellId counter cell identifier
36 * @param piCounterCellData counter cell data
37 */
38 public PiCounterCell(PiCounterCellId cellId, PiCounterCellData piCounterCellData) {
39 this.cellId = cellId;
40 this.counterData = piCounterCellData;
41 }
42
43 /**
44 * Creates a new counter cell for the given cell identifier, number of packets and bytes.
45 *
46 * @param cellId counter cell identifier
47 * @param packets number of packets
48 * @param bytes number of bytes
49 */
50 public PiCounterCell(PiCounterCellId cellId, long packets, long bytes) {
51 this.cellId = cellId;
52 this.counterData = new PiCounterCellData(packets, bytes);
53 }
54
55 /**
56 * Returns the cell identifier.
57 *
58 * @return cell identifier
59 */
60 public PiCounterCellId cellId() {
61 return cellId;
62 }
63
64 /**
65 * Returns the data contained by this cell.
66 *
67 * @return counter cell data
68 */
69 public PiCounterCellData data() {
70 return counterData;
71 }
72
73 @Override
74 public boolean equals(Object o) {
75 if (this == o) {
76 return true;
77 }
78 if (!(o instanceof PiCounterCell)) {
79 return false;
80 }
81 PiCounterCell that = (PiCounterCell) o;
82 return Objects.equal(cellId, that.cellId) &&
83 Objects.equal(counterData, that.counterData);
84 }
85
86 @Override
87 public int hashCode() {
88 return Objects.hashCode(cellId, counterData);
89 }
90
91 @Override
92 public String toString() {
93 return MoreObjects.toStringHelper(this)
94 .add("cellId", cellId)
95 .add("counterData", counterData)
96 .toString();
97 }
98}