Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 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 | */ |
| 16 | package org.onosproject.net.flow.criteria; |
| 17 | |
alshabib | caf1ca2 | 2015-06-25 15:18:16 -0700 | [diff] [blame] | 18 | import org.onlab.packet.EthType; |
| 19 | |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 20 | import java.util.Objects; |
| 21 | |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 22 | /** |
| 23 | * Implementation of Ethernet type criterion (16 bits unsigned integer). |
| 24 | */ |
| 25 | public final class EthTypeCriterion implements Criterion { |
alshabib | 7b808c5 | 2015-06-26 14:22:24 -0700 | [diff] [blame] | 26 | |
| 27 | |
| 28 | private final EthType ethType; |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * Constructor. |
| 32 | * |
| 33 | * @param ethType the Ethernet frame type to match (16 bits unsigned |
| 34 | * integer) |
| 35 | */ |
| 36 | EthTypeCriterion(int ethType) { |
alshabib | 7b808c5 | 2015-06-26 14:22:24 -0700 | [diff] [blame] | 37 | this.ethType = new EthType(ethType); |
alshabib | caf1ca2 | 2015-06-25 15:18:16 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Constructor. |
| 42 | * |
| 43 | * @param ethType the Ethernet frame type to match |
| 44 | */ |
| 45 | EthTypeCriterion(EthType ethType) { |
| 46 | this.ethType = ethType; |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 47 | } |
| 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 | */ |
alshabib | caf1ca2 | 2015-06-25 15:18:16 -0700 | [diff] [blame] | 59 | public EthType ethType() { |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 60 | return ethType; |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public String toString() { |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 65 | return type().toString() + SEPARATOR + ethType; |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public int hashCode() { |
Thomas Vachuska | 6c8eff3 | 2015-05-27 16:11:44 -0700 | [diff] [blame] | 70 | return Objects.hash(type().ordinal(), ethType); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 71 | } |
| 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 | } |