BitOhenry | cc024eb | 2015-11-10 17:17:36 +0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
BitOhenry | cc024eb | 2015-11-10 17:17:36 +0800 | [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 | |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 18 | import org.onlab.packet.MacAddress; |
BitOhenry | cc024eb | 2015-11-10 17:17:36 +0800 | [diff] [blame] | 19 | |
| 20 | import java.util.Objects; |
| 21 | |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 22 | import static com.google.common.base.Preconditions.checkNotNull; |
BitOhenry | cc024eb | 2015-11-10 17:17:36 +0800 | [diff] [blame] | 23 | |
| 24 | /** |
| 25 | * Implementation of arp_eth_src address or arp_eth_dst address criterion. |
| 26 | */ |
| 27 | public final class ArpHaCriterion implements Criterion { |
| 28 | private final MacAddress mac; |
| 29 | private final Type type; |
| 30 | |
| 31 | /** |
| 32 | * Constructor. |
| 33 | * |
| 34 | * @param mac the MAC Address to match. |
| 35 | * @param type the match type. Should be one of the following: |
| 36 | * Type.ARP_SHA, Type.ARP_THA |
| 37 | */ |
| 38 | ArpHaCriterion(MacAddress mac, Type type) { |
| 39 | checkNotNull(mac, "mac cannot be null"); |
| 40 | checkNotNull(type, "type cannot be null"); |
| 41 | this.mac = mac; |
| 42 | this.type = type; |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | public Type type() { |
| 47 | return this.type; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Gets the MAC Address to match. |
| 52 | * |
| 53 | * @return the MAC Address to match |
| 54 | */ |
| 55 | public MacAddress mac() { |
| 56 | return this.mac; |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public String toString() { |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 61 | return type().toString() + SEPARATOR + mac; |
BitOhenry | cc024eb | 2015-11-10 17:17:36 +0800 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public int hashCode() { |
| 66 | return Objects.hash(type().ordinal(), mac); |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public boolean equals(Object obj) { |
| 71 | if (this == obj) { |
| 72 | return true; |
| 73 | } |
| 74 | if (obj instanceof ArpHaCriterion) { |
| 75 | ArpHaCriterion that = (ArpHaCriterion) obj; |
| 76 | return Objects.equals(mac, that.mac) && |
| 77 | Objects.equals(type, that.type); |
| 78 | } |
| 79 | return false; |
| 80 | } |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 81 | } |