blob: 7df852fe3f65e2e62a13e3c2f147f089afaa619b [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 IPv6 Flow Label (RFC 6437) criterion (20 bits unsigned
22 * integer).
23 */
24public final class IPv6FlowLabelCriterion implements Criterion {
25 private static final int MASK = 0xfffff;
26 private final int flowLabel; // IPv6 flow label: 20 bits
27
28 /**
29 * Constructor.
30 *
31 * @param flowLabel the IPv6 flow label to match (20 bits)
32 */
33 IPv6FlowLabelCriterion(int flowLabel) {
34 this.flowLabel = flowLabel & MASK;
35 }
36
37 @Override
38 public Type type() {
39 return Type.IPV6_FLABEL;
40 }
41
42 /**
43 * Gets the IPv6 flow label to match.
44 *
45 * @return the IPv6 flow label to match (20 bits)
46 */
47 public int flowLabel() {
48 return flowLabel;
49 }
50
51 @Override
52 public String toString() {
Jonathan Hartc7840bd2016-01-21 23:26:29 -080053 return type().toString() + SEPARATOR + Long.toHexString(flowLabel);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070054 }
55
56 @Override
57 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -070058 return Objects.hash(type().ordinal(), flowLabel);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070059 }
60
61 @Override
62 public boolean equals(Object obj) {
63 if (this == obj) {
64 return true;
65 }
66 if (obj instanceof IPv6FlowLabelCriterion) {
67 IPv6FlowLabelCriterion that = (IPv6FlowLabelCriterion) obj;
68 return Objects.equals(flowLabel, that.flowLabel) &&
69 Objects.equals(this.type(), that.type());
70 }
71 return false;
72 }
73}