Yi Tseng | f33c077 | 2017-06-06 14:56:18 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Yi Tseng | f33c077 | 2017-06-06 14:56:18 -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 | |
| 17 | package org.onosproject.bmv2.model; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | import com.google.common.base.Objects; |
| 21 | import org.onosproject.net.pi.model.PiMatchType; |
| 22 | import org.onosproject.net.pi.model.PiTableMatchFieldModel; |
| 23 | |
| 24 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 25 | import static com.google.common.base.Preconditions.*; |
| 26 | import static com.google.common.base.Preconditions.checkNotNull; |
| 27 | |
| 28 | /** |
| 29 | * BMv2 table match field model. |
| 30 | */ |
| 31 | @Beta |
| 32 | public final class Bmv2TableMatchFieldModel implements PiTableMatchFieldModel { |
| 33 | private final PiMatchType matchType; |
| 34 | private final Bmv2HeaderFieldModel field; |
| 35 | |
| 36 | /** |
| 37 | * Creates new BMv2 table match field model using the given type and header field. |
| 38 | * |
| 39 | * @param matchType the match type |
| 40 | * @param field the header field |
| 41 | */ |
| 42 | public Bmv2TableMatchFieldModel(PiMatchType matchType, Bmv2HeaderFieldModel field) { |
| 43 | checkNotNull(matchType, "Match type can't be null"); |
| 44 | checkNotNull(field, "Header field can't be null"); |
| 45 | |
| 46 | this.matchType = matchType; |
| 47 | this.field = field; |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public PiMatchType matchType() { |
| 52 | return matchType; |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public Bmv2HeaderFieldModel field() { |
| 57 | return field; |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public int hashCode() { |
| 62 | return Objects.hashCode(matchType, field); |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public boolean equals(Object obj) { |
| 67 | if (this == obj) { |
| 68 | return true; |
| 69 | } |
| 70 | if (obj == null || getClass() != obj.getClass()) { |
| 71 | return false; |
| 72 | } |
| 73 | final Bmv2TableMatchFieldModel other = (Bmv2TableMatchFieldModel) obj; |
| 74 | return Objects.equal(this.matchType, other.matchType) |
| 75 | && Objects.equal(this.field, other.field); |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public String toString() { |
| 80 | return toStringHelper(this) |
| 81 | .add("matchType", matchType) |
| 82 | .add("field", field) |
| 83 | .toString(); |
| 84 | } |
| 85 | |
| 86 | |
| 87 | } |