blob: 465de6bef44cf1b4d1a262f02da29a288dd96986 [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
alshabibcaf1ca22015-06-25 15:18:16 -070018import org.onlab.packet.EthType;
19
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070020import java.util.Objects;
21
22import static com.google.common.base.MoreObjects.toStringHelper;
23
24/**
25 * Implementation of Ethernet type criterion (16 bits unsigned integer).
26 */
27public final class EthTypeCriterion implements Criterion {
28 private static final int MASK = 0xffff;
alshabibcaf1ca22015-06-25 15:18:16 -070029 private final EthType ethType; // Ethernet type value: 16 bits
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070030
31 /**
32 * Constructor.
33 *
34 * @param ethType the Ethernet frame type to match (16 bits unsigned
35 * integer)
36 */
37 EthTypeCriterion(int ethType) {
alshabibcaf1ca22015-06-25 15:18:16 -070038 this.ethType = new EthType(ethType & MASK);
39 }
40
41 /**
42 * Constructor.
43 *
44 * @param ethType the Ethernet frame type to match
45 */
46 EthTypeCriterion(EthType ethType) {
47 this.ethType = ethType;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070048 }
49
50 @Override
51 public Type type() {
52 return Type.ETH_TYPE;
53 }
54
55 /**
56 * Gets the Ethernet frame type to match.
57 *
58 * @return the Ethernet frame type to match (16 bits unsigned integer)
59 */
alshabibcaf1ca22015-06-25 15:18:16 -070060 public EthType ethType() {
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070061 return ethType;
62 }
63
64 @Override
65 public String toString() {
66 return toStringHelper(type().toString())
alshabibcaf1ca22015-06-25 15:18:16 -070067 .add("ethType", ethType.toString())
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070068 .toString();
69 }
70
71 @Override
72 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -070073 return Objects.hash(type().ordinal(), ethType);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070074 }
75
76 @Override
77 public boolean equals(Object obj) {
78 if (this == obj) {
79 return true;
80 }
81 if (obj instanceof EthTypeCriterion) {
82 EthTypeCriterion that = (EthTypeCriterion) obj;
83 return Objects.equals(ethType, that.ethType) &&
84 Objects.equals(this.type(), that.type());
85 }
86 return false;
87 }
88}