blob: 50bffa61b73e138ab91657a6073a14621ee15c7e [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.onlab.util.ImmutableByteSequence;
22import org.onosproject.net.pi.model.PiMatchType;
23
24import static com.google.common.base.Preconditions.checkArgument;
25import static com.google.common.base.Preconditions.checkNotNull;
26
27/**
28 * Exact field match in a protocol-independent pipeline.
29 */
30@Beta
31public final class PiExactFieldMatch extends PiFieldMatch {
32
33 private final ImmutableByteSequence value;
34
35 /**
36 * Creates an exact field match.
37 *
38 * @param fieldId field identifier
39 * @param value value
40 */
41 public PiExactFieldMatch(PiHeaderFieldId fieldId, ImmutableByteSequence value) {
42 super(fieldId);
43 this.value = checkNotNull(value);
44 checkArgument(value.size() > 0, "Value can't have size 0");
45 }
46
47 @Override
48 public PiMatchType type() {
49 return PiMatchType.EXACT;
50 }
51
52 /**
53 * Returns the byte sequence value to be matched.
54 *
55 * @return an immutable byte sequence
56 */
57 public ImmutableByteSequence value() {
58 return value;
59 }
60
61 @Override
62 public boolean equals(Object o) {
63 if (this == o) {
64 return true;
65 }
66 if (o == null || getClass() != o.getClass()) {
67 return false;
68 }
69 PiExactFieldMatch that = (PiExactFieldMatch) o;
70 return Objects.equal(this.fieldId(), that.fieldId()) &&
71 Objects.equal(value, that.value);
72 }
73
74 @Override
75 public int hashCode() {
76 return Objects.hashCode(this.fieldId(), value);
77 }
78
79 @Override
80 public String toString() {
81 return this.fieldId().toString() + "=" + value.toString();
82 }
83}