blob: 679e8fabb320e61f8871fcdb499f53da861ad7d0 [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
alshabibcaf1ca22015-06-25 15:18:16 -070018import org.onlab.packet.EthType;
19
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070020import java.util.Objects;
21
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070022/**
23 * Implementation of Ethernet type criterion (16 bits unsigned integer).
24 */
25public final class EthTypeCriterion implements Criterion {
alshabib7b808c52015-06-26 14:22:24 -070026
27
28 private final EthType ethType;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070029
30 /**
31 * Constructor.
32 *
33 * @param ethType the Ethernet frame type to match (16 bits unsigned
34 * integer)
35 */
36 EthTypeCriterion(int ethType) {
alshabib7b808c52015-06-26 14:22:24 -070037 this.ethType = new EthType(ethType);
alshabibcaf1ca22015-06-25 15:18:16 -070038 }
39
40 /**
41 * Constructor.
42 *
43 * @param ethType the Ethernet frame type to match
44 */
45 EthTypeCriterion(EthType ethType) {
46 this.ethType = ethType;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070047 }
48
49 @Override
50 public Type type() {
51 return Type.ETH_TYPE;
52 }
53
54 /**
55 * Gets the Ethernet frame type to match.
56 *
57 * @return the Ethernet frame type to match (16 bits unsigned integer)
58 */
alshabibcaf1ca22015-06-25 15:18:16 -070059 public EthType ethType() {
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070060 return ethType;
61 }
62
63 @Override
64 public String toString() {
Jonathan Hartc7840bd2016-01-21 23:26:29 -080065 return type().toString() + SEPARATOR + ethType;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070066 }
67
68 @Override
69 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -070070 return Objects.hash(type().ordinal(), ethType);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070071 }
72
73 @Override
74 public boolean equals(Object obj) {
75 if (this == obj) {
76 return true;
77 }
78 if (obj instanceof EthTypeCriterion) {
79 EthTypeCriterion that = (EthTypeCriterion) obj;
80 return Objects.equals(ethType, that.ethType) &&
81 Objects.equals(this.type(), that.type());
82 }
83 return false;
84 }
85}