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 | * A BMv2 header type field 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 Bmv2FieldTypeModel { |
Carmelo Cascone | 5899c13 | 2016-04-06 22:09:08 -0700 | [diff] [blame] | 29 | |
| 30 | private final String name; |
| 31 | private final int bitWidth; |
| 32 | |
Carmelo Cascone | 17fc9e4 | 2016-05-31 11:29:21 -0700 | [diff] [blame] | 33 | protected Bmv2FieldTypeModel(String name, int bitWidth) { |
Carmelo Cascone | 5899c13 | 2016-04-06 22:09:08 -0700 | [diff] [blame] | 34 | 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 Cascone | 17fc9e4 | 2016-05-31 11:29:21 -0700 | [diff] [blame] | 69 | final Bmv2FieldTypeModel other = (Bmv2FieldTypeModel) obj; |
Carmelo Cascone | 5899c13 | 2016-04-06 22:09:08 -0700 | [diff] [blame] | 70 | 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 | } |