blob: fd354ecb64a886ab56b71414b3165c009f97a37f [file] [log] [blame]
FrankWang2674e452018-05-24 17:13:35 +08001/*
2 * Copyright 2018-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;
22import org.onosproject.net.pi.model.PiData;
23
24import static com.google.common.base.Preconditions.checkNotNull;
25
26/**
27 * A register cell entry of a protocol-independent pipeline.
28 */
29@Beta
30public final class PiRegisterCell implements PiEntity {
31
32 private final PiRegisterCellId registerCellId;
33 private final PiData piData;
34
35 private PiRegisterCell(PiRegisterCellId registerCellId, PiData piData) {
36 this.registerCellId = registerCellId;
37 this.piData = piData;
38 }
39
40 /**
41 * Returns the cell identifier.
42 *
43 * @return cell identifier
44 */
45 public PiRegisterCellId cellId() {
46 return registerCellId;
47 }
48
49 /**
50 * Returns the data contained by this cell ID.
51 *
52 * @return PI data or null
53 */
54 public PiData data() {
55 return piData;
56 }
57
58 @Override
59 public PiEntityType piEntityType() {
60 return PiEntityType.REGISTER_CELL;
61 }
62
63 @Override
64 public boolean equals(Object obj) {
65 if (this == obj) {
66 return true;
67 }
68 if (obj == null || getClass() != obj.getClass()) {
69 return false;
70 }
71 final PiRegisterCell other = (PiRegisterCell) obj;
72 return Objects.equal(this.registerCellId, other.registerCellId) &&
73 Objects.equal(this.piData, other.piData);
74 }
75
76 @Override
77 public int hashCode() {
78 return Objects.hashCode(registerCellId, piData);
79 }
80
81 @Override
82 public String toString() {
83 return MoreObjects.toStringHelper(this)
84 .add("cellId", registerCellId)
85 .add("piData", piData)
86 .toString();
87 }
88
89 /**
90 * Returns a register cell entry builder.
91 *
92 * @return a new builder
93 */
94 public static Builder builder() {
95 return new Builder();
96 }
97
98 public static final class Builder {
99 private PiRegisterCellId cellId;
100 private PiData piData;
101
102
103 private Builder() {
104 // Hides constructor.
105 }
106
107 /**
108 * Sets the register cell identifier for this register.
109 *
110 * @param registerCellId register cell identifier
111 * @return this
112 */
113 public PiRegisterCell.Builder withCellId(PiRegisterCellId registerCellId) {
114 this.cellId = registerCellId;
115 return this;
116 }
117
118
119 /**
120 * Sets the data of this register cell.
121 *
122 * @param data protocol-independent data
123 * @return this
124 */
125 public PiRegisterCell.Builder withData(PiData data) {
126 this.piData = data;
127 return this;
128 }
129
130 /**
131 * Builds the register cell entry.
132 *
133 * @return a new register cell entry
134 */
135 public PiRegisterCell build() {
136 checkNotNull(cellId);
137 return new PiRegisterCell(cellId, piData);
138 }
139 }
140}