blob: 26ae3632b9c26417fec4763f2f10e9f7d076852b [file] [log] [blame]
Carmelo Cascone7f75be42017-09-07 14:37:02 +02001/*
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.Objects;
21
22import static com.google.common.base.Preconditions.checkArgument;
23import static com.google.common.base.Preconditions.checkNotNull;
24import static java.lang.String.format;
25import static org.onosproject.net.pi.runtime.PiCounterType.DIRECT;
26
27/**
28 * Identifier of a direct counter cell of a protocol-independent pipeline.
29 */
30@Beta
31public final class PiDirectCounterCellId implements PiCounterCellId {
32
33 private final PiCounterId counterId;
34 private final PiTableEntry tableEntry;
35
36 private PiDirectCounterCellId(PiCounterId counterId, PiTableEntry tableEntry) {
37 this.counterId = counterId;
38 this.tableEntry = tableEntry;
39 }
40
41 /**
42 * Returns a direct counter cell identifier for the given counter identifier and table entry.
43 *
44 * @param counterId counter identifier
45 * @param tableEntry table entry
46 * @return direct counter cell identifier
47 */
48 public static PiDirectCounterCellId of(PiCounterId counterId, PiTableEntry tableEntry) {
49 checkNotNull(counterId);
50 checkNotNull(tableEntry);
51 checkArgument(counterId.type() == DIRECT, "Counter ID must be of type DIRECT");
52 return new PiDirectCounterCellId(counterId, tableEntry);
53 }
54
55 /**
56 * Returns the table entry associated with this cell identifier.
57 *
58 * @return cell table entry
59 */
60 public PiTableEntry tableEntry() {
61 return tableEntry;
62 }
63
64 @Override
65 public PiCounterId counterId() {
66 return counterId;
67 }
68
69 @Override
70 public PiCounterType type() {
71 return DIRECT;
72 }
73
74 @Override
75 public boolean equals(Object o) {
76 if (this == o) {
77 return true;
78 }
79 if (!(o instanceof PiDirectCounterCellId)) {
80 return false;
81 }
82 PiDirectCounterCellId that = (PiDirectCounterCellId) o;
83 return Objects.equal(counterId, that.counterId) &&
84 Objects.equal(tableEntry, that.tableEntry);
85 }
86
87 @Override
88 public int hashCode() {
89 return Objects.hashCode(counterId, tableEntry);
90 }
91
92 @Override
93 public String toString() {
94 return format("%s[{%s}]", counterId, tableEntry);
95 }
96}