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