blob: a41b6fef6ef1ab7f327f49e0dfab7c9cbad2a136 [file] [log] [blame]
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -07001/*
2 * Copyright 2015 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 */
16package org.onosproject.net.flow.criteria;
17
18import java.util.Objects;
19
20import static com.google.common.base.MoreObjects.toStringHelper;
21
22/**
23 * Implementation of ICMPv6 code criterion (8 bits unsigned integer).
24 */
25public final class Icmpv6CodeCriterion implements Criterion {
26 private static final short MASK = 0xff;
27 private final short icmpv6Code; // ICMPv6 code: 8 bits
28
29 /**
30 * Constructor.
31 *
32 * @param icmpv6Code the ICMPv6 code to match (8 bits unsigned integer)
33 */
34 Icmpv6CodeCriterion(short icmpv6Code) {
35 this.icmpv6Code = (short) (icmpv6Code & MASK);
36 }
37
38 @Override
39 public Type type() {
40 return Type.ICMPV6_CODE;
41 }
42
43 /**
44 * Gets the ICMPv6 code to match.
45 *
46 * @return the ICMPv6 code to match (8 bits unsigned integer)
47 */
48 public short icmpv6Code() {
49 return icmpv6Code;
50 }
51
52 @Override
53 public String toString() {
54 return toStringHelper(type().toString())
55 .add("icmpv6Code", icmpv6Code).toString();
56 }
57
58 @Override
59 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -070060 return Objects.hash(type().ordinal(), icmpv6Code);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070061 }
62
63 @Override
64 public boolean equals(Object obj) {
65 if (this == obj) {
66 return true;
67 }
68 if (obj instanceof Icmpv6CodeCriterion) {
69 Icmpv6CodeCriterion that = (Icmpv6CodeCriterion) obj;
70 return Objects.equals(icmpv6Code, that.icmpv6Code) &&
71 Objects.equals(this.type(), that.type());
72 }
73 return false;
74 }
75}