blob: b2666d4d8bdb1dbebff08e65024aba98717ef5b8 [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 {
alshabib7b808c52015-06-26 14:22:24 -070028
29
30 private final EthType ethType;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070031
32 /**
33 * Constructor.
34 *
35 * @param ethType the Ethernet frame type to match (16 bits unsigned
36 * integer)
37 */
38 EthTypeCriterion(int ethType) {
alshabib7b808c52015-06-26 14:22:24 -070039 this.ethType = new EthType(ethType);
alshabibcaf1ca22015-06-25 15:18:16 -070040 }
41
42 /**
43 * Constructor.
44 *
45 * @param ethType the Ethernet frame type to match
46 */
47 EthTypeCriterion(EthType ethType) {
48 this.ethType = ethType;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070049 }
50
51 @Override
52 public Type type() {
53 return Type.ETH_TYPE;
54 }
55
56 /**
57 * Gets the Ethernet frame type to match.
58 *
59 * @return the Ethernet frame type to match (16 bits unsigned integer)
60 */
alshabibcaf1ca22015-06-25 15:18:16 -070061 public EthType ethType() {
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070062 return ethType;
63 }
64
65 @Override
66 public String toString() {
67 return toStringHelper(type().toString())
alshabibcaf1ca22015-06-25 15:18:16 -070068 .add("ethType", ethType.toString())
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070069 .toString();
70 }
71
72 @Override
73 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -070074 return Objects.hash(type().ordinal(), ethType);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070075 }
76
77 @Override
78 public boolean equals(Object obj) {
79 if (this == obj) {
80 return true;
81 }
82 if (obj instanceof EthTypeCriterion) {
83 EthTypeCriterion that = (EthTypeCriterion) obj;
84 return Objects.equals(ethType, that.ethType) &&
85 Objects.equals(this.type(), that.type());
86 }
87 return false;
88 }
89}