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