Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [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.net.pi.runtime; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | import com.google.common.base.Objects; |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 21 | import org.onosproject.net.pi.model.PiMatchFieldId; |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 22 | import org.onosproject.net.pi.model.PiMatchType; |
| 23 | |
| 24 | /** |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 25 | * Instance of a valid field match in a protocol-independent pipeline. |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 26 | */ |
| 27 | @Beta |
| 28 | public final class PiValidFieldMatch extends PiFieldMatch { |
| 29 | |
| 30 | private final boolean isValid; |
| 31 | |
| 32 | /** |
| 33 | * Creates a new valid field match. |
| 34 | * |
| 35 | * @param fieldId field identifier |
| 36 | * @param isValid validity flag |
| 37 | */ |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 38 | public PiValidFieldMatch(PiMatchFieldId fieldId, boolean isValid) { |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 39 | super(fieldId); |
| 40 | this.isValid = isValid; |
| 41 | } |
| 42 | |
| 43 | @Override |
| 44 | public final PiMatchType type() { |
| 45 | return PiMatchType.VALID; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Returns the boolean flag of this valid match parameter. |
| 50 | * |
| 51 | * @return valid match flag |
| 52 | */ |
| 53 | public boolean isValid() { |
| 54 | return isValid; |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public boolean equals(Object o) { |
| 59 | if (this == o) { |
| 60 | return true; |
| 61 | } |
| 62 | if (o == null || getClass() != o.getClass()) { |
| 63 | return false; |
| 64 | } |
| 65 | PiValidFieldMatch that = (PiValidFieldMatch) o; |
| 66 | return Objects.equal(this.fieldId(), that.fieldId()) && |
| 67 | isValid == that.isValid; |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public int hashCode() { |
| 72 | return Objects.hashCode(this.fieldId(), isValid); |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public String toString() { |
| 77 | return this.fieldId().toString() + '=' + (isValid ? "VALID" : "NOT_VALID"); |
| 78 | } |
| 79 | } |