blob: 8b924eff79f0c451c5fad5138b836f3ef6af00a2 [file] [log] [blame]
Carmelo Cascone5899c132016-04-06 22:09:08 -07001/*
Brian O'Connorce2a03d2017-08-03 19:21:03 -07002 * Copyright 2016-present Open Networking Foundation
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 field model.
Carmelo Cascone5899c132016-04-06 22:09:08 -070026 */
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070027@Beta
28public final class Bmv2FieldModel {
Carmelo Cascone5899c132016-04-06 22:09:08 -070029
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070030 private final Bmv2HeaderModel header;
31 private final Bmv2FieldTypeModel type;
Carmelo Cascone5899c132016-04-06 22:09:08 -070032
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070033 protected Bmv2FieldModel(Bmv2HeaderModel header, Bmv2FieldTypeModel type) {
Carmelo Cascone5899c132016-04-06 22:09:08 -070034 this.header = header;
35 this.type = type;
36 }
37
38 /**
39 * Returns the header instance of this field instance.
40 *
41 * @return a header instance
42 */
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070043 public Bmv2HeaderModel header() {
Carmelo Cascone5899c132016-04-06 22:09:08 -070044 return header;
45 }
46
47 /**
48 * Returns the type of this field instance.
49 *
50 * @return a field type value
51 */
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070052 public Bmv2FieldTypeModel type() {
Carmelo Cascone5899c132016-04-06 22:09:08 -070053 return type;
54 }
55
56 @Override
57 public int hashCode() {
58 return Objects.hashCode(header, type);
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 Bmv2FieldModel other = (Bmv2FieldModel) obj;
Carmelo Cascone5899c132016-04-06 22:09:08 -070070 return Objects.equal(this.header, other.header)
71 && Objects.equal(this.type, other.type);
72 }
73
74 @Override
75 public String toString() {
76 return toStringHelper(this)
77 .add("header", header)
78 .add("type", type)
79 .toString();
80 }
81}