blob: 0905d9ca69f451f072acc2b6327260fb5129403d [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;
21import org.onlab.util.ImmutableByteSequence;
Carmelo Cascone87892e22017-11-13 16:01:29 -080022import org.onosproject.net.pi.model.PiMatchFieldId;
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040023import org.onosproject.net.pi.model.PiMatchType;
24
25import static com.google.common.base.Preconditions.checkArgument;
26import static com.google.common.base.Preconditions.checkNotNull;
27
28/**
Carmelo Cascone87892e22017-11-13 16:01:29 -080029 * Instance of a range field match in a protocol-independent pipeline.
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040030 */
31@Beta
32public final class PiRangeFieldMatch extends PiFieldMatch {
33
34 private final ImmutableByteSequence lowValue;
35 private final ImmutableByteSequence highValue;
36
37 /**
38 * Creates a new range field match for the given low and high value.
39 *
40 * @param fieldId field identifier
41 * @param lowValue low value
42 * @param highValue high value
43 */
Carmelo Cascone87892e22017-11-13 16:01:29 -080044 public PiRangeFieldMatch(PiMatchFieldId fieldId, ImmutableByteSequence lowValue,
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040045 ImmutableByteSequence highValue) {
46 super(fieldId);
47 this.lowValue = checkNotNull(lowValue);
48 this.highValue = checkNotNull(highValue);
49 checkArgument(lowValue.size() == highValue.size() && lowValue.size() > 0,
50 "Low and high values must have the same non-zero size.");
51 }
52
53 @Override
54 public PiMatchType type() {
55 return PiMatchType.RANGE;
56 }
57
58 /**
59 * Returns the low value of this range field match.
60 *
61 * @return low value
62 */
63 public ImmutableByteSequence lowValue() {
64 return lowValue;
65 }
66
67 /**
68 * Returns the high value of this range field match.
69 *
70 * @return high value
71 */
72 public ImmutableByteSequence highValue() {
73 return highValue;
74 }
75
76 @Override
77 public boolean equals(Object o) {
78 if (this == o) {
79 return true;
80 }
81 if (o == null || getClass() != o.getClass()) {
82 return false;
83 }
84 PiRangeFieldMatch that = (PiRangeFieldMatch) o;
85 return Objects.equal(this.fieldId(), that.fieldId()) &&
86 Objects.equal(lowValue, that.lowValue) &&
87 Objects.equal(highValue, that.highValue);
88 }
89
90 @Override
91 public int hashCode() {
92 return Objects.hashCode(this.fieldId(), lowValue, highValue);
93 }
94
95 @Override
96 public String toString() {
97 return this.fieldId().toString() + '=' + lowValue.toString() + "--" + highValue.toString();
98 }
99}