blob: 22ab4458090e50c3a0f6a62bb5d230462fba5f42 [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 Ethernet type criterion (16 bits unsigned integer).
24 */
25public final class EthTypeCriterion implements Criterion {
26 private static final int MASK = 0xffff;
27 private final int ethType; // Ethernet type value: 16 bits
28
29 /**
30 * Constructor.
31 *
32 * @param ethType the Ethernet frame type to match (16 bits unsigned
33 * integer)
34 */
35 EthTypeCriterion(int ethType) {
36 this.ethType = ethType & MASK;
37 }
38
39 @Override
40 public Type type() {
41 return Type.ETH_TYPE;
42 }
43
44 /**
45 * Gets the Ethernet frame type to match.
46 *
47 * @return the Ethernet frame type to match (16 bits unsigned integer)
48 */
49 public int ethType() {
50 return ethType;
51 }
52
53 @Override
54 public String toString() {
55 return toStringHelper(type().toString())
56 .add("ethType", Long.toHexString(ethType))
57 .toString();
58 }
59
60 @Override
61 public int hashCode() {
62 return Objects.hash(type(), ethType);
63 }
64
65 @Override
66 public boolean equals(Object obj) {
67 if (this == obj) {
68 return true;
69 }
70 if (obj instanceof EthTypeCriterion) {
71 EthTypeCriterion that = (EthTypeCriterion) obj;
72 return Objects.equals(ethType, that.ethType) &&
73 Objects.equals(this.type(), that.type());
74 }
75 return false;
76 }
77}