blob: 5828327890b44ea088f949b2486af666fc90048d [file] [log] [blame]
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -07003 *
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
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070020/**
21 * Implementation of ICMPv6 type criterion (8 bits unsigned integer).
22 */
23public final class Icmpv6TypeCriterion implements Criterion {
24 private static final short MASK = 0xff;
25 private final short icmpv6Type; // ICMPv6 type: 8 bits
26
27 /**
28 * Constructor.
29 *
30 * @param icmpv6Type the ICMPv6 type to match (8 bits unsigned integer)
31 */
32 Icmpv6TypeCriterion(short icmpv6Type) {
33 this.icmpv6Type = (short) (icmpv6Type & MASK);
34 }
35
36 @Override
37 public Type type() {
38 return Type.ICMPV6_TYPE;
39 }
40
41 /**
42 * Gets the ICMPv6 type to match.
43 *
44 * @return the ICMPv6 type to match (8 bits unsigned integer)
45 */
46 public short icmpv6Type() {
47 return icmpv6Type;
48 }
49
50 @Override
51 public String toString() {
Jonathan Hartc7840bd2016-01-21 23:26:29 -080052 return type().toString() + SEPARATOR + icmpv6Type;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070053 }
54
55 @Override
56 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -070057 return Objects.hash(type().ordinal(), icmpv6Type);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070058 }
59
60 @Override
61 public boolean equals(Object obj) {
62 if (this == obj) {
63 return true;
64 }
65 if (obj instanceof Icmpv6TypeCriterion) {
66 Icmpv6TypeCriterion that = (Icmpv6TypeCriterion) obj;
67 return Objects.equals(icmpv6Type, that.icmpv6Type) &&
68 Objects.equals(this.type(), that.type());
69 }
70 return false;
71 }
72}