Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 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 | |
| 22 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 23 | |
| 24 | /** |
| 25 | * Implementation of Ethernet type criterion (16 bits unsigned integer). |
| 26 | */ |
| 27 | public final class EthTypeCriterion implements Criterion { |
alshabib | 7b808c5 | 2015-06-26 14:22:24 -0700 | [diff] [blame] | 28 | |
| 29 | |
| 30 | private final EthType ethType; |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * Constructor. |
| 34 | * |
| 35 | * @param ethType the Ethernet frame type to match (16 bits unsigned |
| 36 | * integer) |
| 37 | */ |
| 38 | EthTypeCriterion(int ethType) { |
alshabib | 7b808c5 | 2015-06-26 14:22:24 -0700 | [diff] [blame] | 39 | this.ethType = new EthType(ethType); |
alshabib | caf1ca2 | 2015-06-25 15:18:16 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Constructor. |
| 44 | * |
| 45 | * @param ethType the Ethernet frame type to match |
| 46 | */ |
| 47 | EthTypeCriterion(EthType ethType) { |
| 48 | this.ethType = ethType; |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 49 | } |
| 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 | */ |
alshabib | caf1ca2 | 2015-06-25 15:18:16 -0700 | [diff] [blame] | 61 | public EthType ethType() { |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 62 | return ethType; |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public String toString() { |
| 67 | return toStringHelper(type().toString()) |
alshabib | caf1ca2 | 2015-06-25 15:18:16 -0700 | [diff] [blame] | 68 | .add("ethType", ethType.toString()) |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 69 | .toString(); |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public int hashCode() { |
Thomas Vachuska | 6c8eff3 | 2015-05-27 16:11:44 -0700 | [diff] [blame] | 74 | return Objects.hash(type().ordinal(), ethType); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 75 | } |
| 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 | } |