blob: d81da996340f1c272899b11a337f59c7cd3e81af [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 an exact field match in a protocol-independent pipeline.
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040030 */
31@Beta
32public final class PiExactFieldMatch extends PiFieldMatch {
33
34 private final ImmutableByteSequence value;
35
36 /**
37 * Creates an exact field match.
38 *
39 * @param fieldId field identifier
40 * @param value value
41 */
Carmelo Cascone87892e22017-11-13 16:01:29 -080042 public PiExactFieldMatch(PiMatchFieldId fieldId, ImmutableByteSequence value) {
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040043 super(fieldId);
44 this.value = checkNotNull(value);
45 checkArgument(value.size() > 0, "Value can't have size 0");
46 }
47
48 @Override
49 public PiMatchType type() {
50 return PiMatchType.EXACT;
51 }
52
53 /**
54 * Returns the byte sequence value to be matched.
55 *
56 * @return an immutable byte sequence
57 */
58 public ImmutableByteSequence value() {
59 return value;
60 }
61
62 @Override
63 public boolean equals(Object o) {
64 if (this == o) {
65 return true;
66 }
67 if (o == null || getClass() != o.getClass()) {
68 return false;
69 }
70 PiExactFieldMatch that = (PiExactFieldMatch) o;
71 return Objects.equal(this.fieldId(), that.fieldId()) &&
72 Objects.equal(value, that.value);
73 }
74
75 @Override
76 public int hashCode() {
77 return Objects.hashCode(this.fieldId(), value);
78 }
79
80 @Override
81 public String toString() {
82 return this.fieldId().toString() + "=" + value.toString();
83 }
84}