blob: 5b55d284a85b613a3cf9ddcb9299627503ac7db1 [file] [log] [blame]
Carmelo Casconeaa8b6292016-04-13 14:27:06 -07001/*
2 * Copyright 2016-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.bmv2.api.runtime;
18
Carmelo Cascone9e39e312016-06-16 14:47:09 -070019import com.google.common.annotations.Beta;
Carmelo Casconeaa8b6292016-04-13 14:27:06 -070020import com.google.common.base.MoreObjects;
21import com.google.common.base.Objects;
22import org.onlab.util.ImmutableByteSequence;
23
24import static com.google.common.base.Preconditions.checkNotNull;
25
26/**
Carmelo Cascone9e39e312016-06-16 14:47:09 -070027 * A BMv2 exact match parameter.
Carmelo Casconeaa8b6292016-04-13 14:27:06 -070028 */
Carmelo Cascone9e39e312016-06-16 14:47:09 -070029@Beta
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070030public final class Bmv2ExactMatchParam implements Bmv2MatchParam {
Carmelo Casconeaa8b6292016-04-13 14:27:06 -070031
32 private final ImmutableByteSequence value;
33
34 /**
35 * Creates a new match parameter object that matches exactly on the
36 * given byte sequence.
37 *
38 * @param value a byte sequence value
39 */
40 public Bmv2ExactMatchParam(ImmutableByteSequence value) {
41 this.value = checkNotNull(value, "value cannot be null");
42 }
43
44 @Override
45 public Type type() {
46 return Type.EXACT;
47 }
48
49 /**
Carmelo Cascone9e39e312016-06-16 14:47:09 -070050 * Return the byte sequence matched by this parameter.
Carmelo Casconeaa8b6292016-04-13 14:27:06 -070051 *
52 * @return an immutable byte buffer value
53 */
54 public ImmutableByteSequence value() {
55 return this.value;
56 }
57
58 @Override
59 public int hashCode() {
60 return Objects.hashCode(value);
61 }
62
63 @Override
64 public boolean equals(Object obj) {
65 if (this == obj) {
66 return true;
67 }
68 if (obj == null || getClass() != obj.getClass()) {
69 return false;
70 }
71 final Bmv2ExactMatchParam other = (Bmv2ExactMatchParam) obj;
72 return Objects.equal(this.value, other.value);
73 }
74
75 @Override
76 public String toString() {
77 return MoreObjects.toStringHelper(this)
78 .add("value", value)
79 .toString();
80 }
81}