blob: 5b944cc3ff02ae37ac6dd1e35759e0dfe44cad57 [file] [log] [blame]
Carmelo Cascone5899c132016-04-06 22:09:08 -07001/*
Carmelo Casconeaa8b6292016-04-13 14:27:06 -07002 * Copyright 2016-present Open Networking Laboratory
Carmelo Cascone5899c132016-04-06 22:09:08 -07003 *
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
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070017package org.onosproject.bmv2.api.context;
Carmelo Cascone5899c132016-04-06 22:09:08 -070018
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070019import com.google.common.annotations.Beta;
Carmelo Cascone5899c132016-04-06 22:09:08 -070020import com.google.common.base.Objects;
21
22import static com.google.common.base.MoreObjects.toStringHelper;
23
24/**
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070025 * A BMv2 header type field model.
Carmelo Cascone5899c132016-04-06 22:09:08 -070026 */
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070027@Beta
28public final class Bmv2FieldTypeModel {
Carmelo Cascone5899c132016-04-06 22:09:08 -070029
30 private final String name;
31 private final int bitWidth;
32
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070033 protected Bmv2FieldTypeModel(String name, int bitWidth) {
Carmelo Cascone5899c132016-04-06 22:09:08 -070034 this.name = name;
35 this.bitWidth = bitWidth;
36 }
37
38 /**
39 * Returns the name of this header type field.
40 *
41 * @return a string value
42 */
43 public String name() {
44 return name;
45 }
46
47 /**
48 * Returns the bit width of this header type field.
49 *
50 * @return an integer value
51 */
52 public int bitWidth() {
53 return bitWidth;
54 }
55
56 @Override
57 public int hashCode() {
58 return Objects.hashCode(name, bitWidth);
59 }
60
61 @Override
62 public boolean equals(Object obj) {
63 if (this == obj) {
64 return true;
65 }
66 if (obj == null || getClass() != obj.getClass()) {
67 return false;
68 }
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070069 final Bmv2FieldTypeModel other = (Bmv2FieldTypeModel) obj;
Carmelo Cascone5899c132016-04-06 22:09:08 -070070 return Objects.equal(this.name, other.name)
71 && Objects.equal(this.bitWidth, other.bitWidth);
72 }
73
74 @Override
75 public String toString() {
76 return toStringHelper(this)
77 .add("name", name)
78 .add("bitWidth", bitWidth)
79 .toString();
80 }
81}