blob: 7894ba82a11b4a6925c56c8e9a098ec2b158634b [file] [log] [blame]
Carmelo Cascone1022a4e2017-05-25 00:16:18 -04001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Carmelo Cascone1022a4e2017-05-25 00:16:18 -04003 *
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;
Carmelo Cascone87892e22017-11-13 16:01:29 -080021import org.onosproject.net.pi.model.PiMatchFieldId;
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040022import org.onosproject.net.pi.model.PiMatchType;
23
24/**
Carmelo Cascone87892e22017-11-13 16:01:29 -080025 * Instance of a valid field match in a protocol-independent pipeline.
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040026 */
27@Beta
28public 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 Cascone87892e22017-11-13 16:01:29 -080038 public PiValidFieldMatch(PiMatchFieldId fieldId, boolean isValid) {
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040039 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}