blob: 5c1f4ff8406b4a4f3708bb91270e9388d01fa310 [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 * BMv2 header instance model.
Carmelo Cascone5899c132016-04-06 22:09:08 -070026 */
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070027@Beta
28public final class Bmv2HeaderModel {
Carmelo Cascone5899c132016-04-06 22:09:08 -070029
30 private final String name;
31 private final int id;
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070032 private final Bmv2HeaderTypeModel type;
Carmelo Cascone5899c132016-04-06 22:09:08 -070033 private final boolean isMetadata;
34
35 /**
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070036 * Creates a new header instance model.
Carmelo Cascone5899c132016-04-06 22:09:08 -070037 *
38 * @param name name
39 * @param id id
40 * @param type header type
41 * @param metadata if is metadata
42 */
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070043 protected Bmv2HeaderModel(String name, int id, Bmv2HeaderTypeModel type, boolean metadata) {
Carmelo Cascone5899c132016-04-06 22:09:08 -070044 this.name = name;
45 this.id = id;
46 this.type = type;
47 this.isMetadata = metadata;
48 }
49
50 /**
51 * Returns the name of this header instance.
52 *
53 * @return a string value
54 */
55 public String name() {
56 return name;
57 }
58
59 /**
60 * Return the id of this header instance.
61 *
62 * @return an integer value
63 */
64 public int id() {
65 return id;
66 }
67
68 /**
69 * Return the type of this header instance.
70 *
71 * @return a header type value
72 */
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070073 public Bmv2HeaderTypeModel type() {
Carmelo Cascone5899c132016-04-06 22:09:08 -070074 return type;
75 }
76
77 /**
78 * Return true if this header instance is a metadata, false elsewhere.
79 *
80 * @return a boolean value
81 */
82 public boolean isMetadata() {
83 return isMetadata;
84 }
85
86 @Override
87 public int hashCode() {
88 return Objects.hashCode(name, id, type, isMetadata);
89 }
90
91 @Override
92 public boolean equals(Object obj) {
93 if (this == obj) {
94 return true;
95 }
96 if (obj == null || getClass() != obj.getClass()) {
97 return false;
98 }
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070099 final Bmv2HeaderModel other = (Bmv2HeaderModel) obj;
Carmelo Cascone5899c132016-04-06 22:09:08 -0700100 return Objects.equal(this.name, other.name)
101 && Objects.equal(this.id, other.id)
102 && Objects.equal(this.type, other.type)
103 && Objects.equal(this.isMetadata, other.isMetadata);
104 }
105
106 @Override
107 public String toString() {
108 return toStringHelper(this)
109 .add("name", name)
110 .add("id", id)
111 .add("type", type)
112 .add("isMetadata", isMetadata)
113 .toString();
114 }
115}