Carmelo Cascone | 5899c13 | 2016-04-06 22:09:08 -0700 | [diff] [blame] | 1 | /* |
Carmelo Cascone | aa8b629 | 2016-04-13 14:27:06 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Carmelo Cascone | 5899c13 | 2016-04-06 22:09:08 -0700 | [diff] [blame] | 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 | |
Carmelo Cascone | 17fc9e4 | 2016-05-31 11:29:21 -0700 | [diff] [blame] | 17 | package org.onosproject.bmv2.api.context; |
Carmelo Cascone | 5899c13 | 2016-04-06 22:09:08 -0700 | [diff] [blame] | 18 | |
Carmelo Cascone | 17fc9e4 | 2016-05-31 11:29:21 -0700 | [diff] [blame] | 19 | import com.google.common.annotations.Beta; |
Carmelo Cascone | 5899c13 | 2016-04-06 22:09:08 -0700 | [diff] [blame] | 20 | import com.google.common.base.Objects; |
| 21 | |
| 22 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 23 | |
| 24 | /** |
Carmelo Cascone | 17fc9e4 | 2016-05-31 11:29:21 -0700 | [diff] [blame] | 25 | * BMv2 header instance model. |
Carmelo Cascone | 5899c13 | 2016-04-06 22:09:08 -0700 | [diff] [blame] | 26 | */ |
Carmelo Cascone | 17fc9e4 | 2016-05-31 11:29:21 -0700 | [diff] [blame] | 27 | @Beta |
| 28 | public final class Bmv2HeaderModel { |
Carmelo Cascone | 5899c13 | 2016-04-06 22:09:08 -0700 | [diff] [blame] | 29 | |
| 30 | private final String name; |
| 31 | private final int id; |
Carmelo Cascone | 17fc9e4 | 2016-05-31 11:29:21 -0700 | [diff] [blame] | 32 | private final Bmv2HeaderTypeModel type; |
Carmelo Cascone | 5899c13 | 2016-04-06 22:09:08 -0700 | [diff] [blame] | 33 | private final boolean isMetadata; |
| 34 | |
| 35 | /** |
Carmelo Cascone | 17fc9e4 | 2016-05-31 11:29:21 -0700 | [diff] [blame] | 36 | * Creates a new header instance model. |
Carmelo Cascone | 5899c13 | 2016-04-06 22:09:08 -0700 | [diff] [blame] | 37 | * |
| 38 | * @param name name |
| 39 | * @param id id |
| 40 | * @param type header type |
| 41 | * @param metadata if is metadata |
| 42 | */ |
Carmelo Cascone | 17fc9e4 | 2016-05-31 11:29:21 -0700 | [diff] [blame] | 43 | protected Bmv2HeaderModel(String name, int id, Bmv2HeaderTypeModel type, boolean metadata) { |
Carmelo Cascone | 5899c13 | 2016-04-06 22:09:08 -0700 | [diff] [blame] | 44 | 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 Cascone | 17fc9e4 | 2016-05-31 11:29:21 -0700 | [diff] [blame] | 73 | public Bmv2HeaderTypeModel type() { |
Carmelo Cascone | 5899c13 | 2016-04-06 22:09:08 -0700 | [diff] [blame] | 74 | 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 Cascone | 17fc9e4 | 2016-05-31 11:29:21 -0700 | [diff] [blame] | 99 | final Bmv2HeaderModel other = (Bmv2HeaderModel) obj; |
Carmelo Cascone | 5899c13 | 2016-04-06 22:09:08 -0700 | [diff] [blame] | 100 | 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 | } |