Carmelo Cascone | aa8b629 | 2016-04-13 14:27:06 -0700 | [diff] [blame^] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.bmv2.api.runtime; |
| 18 | |
| 19 | import com.google.common.base.MoreObjects; |
| 20 | import com.google.common.base.Objects; |
| 21 | import org.onlab.util.ImmutableByteSequence; |
| 22 | |
| 23 | import static com.google.common.base.Preconditions.checkNotNull; |
| 24 | |
| 25 | /** |
| 26 | * Representation of a Bmv2 exact match parameter. |
| 27 | */ |
| 28 | public class Bmv2ExactMatchParam implements Bmv2MatchParam { |
| 29 | |
| 30 | private final ImmutableByteSequence value; |
| 31 | |
| 32 | /** |
| 33 | * Creates a new match parameter object that matches exactly on the |
| 34 | * given byte sequence. |
| 35 | * |
| 36 | * @param value a byte sequence value |
| 37 | */ |
| 38 | public Bmv2ExactMatchParam(ImmutableByteSequence value) { |
| 39 | this.value = checkNotNull(value, "value cannot be null"); |
| 40 | } |
| 41 | |
| 42 | @Override |
| 43 | public Type type() { |
| 44 | return Type.EXACT; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Return the byte sequence value matched by this parameter. |
| 49 | * |
| 50 | * @return an immutable byte buffer value |
| 51 | */ |
| 52 | public ImmutableByteSequence value() { |
| 53 | return this.value; |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public int hashCode() { |
| 58 | return Objects.hashCode(value); |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public boolean equals(Object obj) { |
| 63 | if (this == obj) { |
| 64 | return true; |
| 65 | } |
| 66 | if (obj == null || getClass() != obj.getClass()) { |
| 67 | return false; |
| 68 | } |
| 69 | final Bmv2ExactMatchParam other = (Bmv2ExactMatchParam) obj; |
| 70 | return Objects.equal(this.value, other.value); |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public String toString() { |
| 75 | return MoreObjects.toStringHelper(this) |
| 76 | .add("value", value) |
| 77 | .toString(); |
| 78 | } |
| 79 | } |