blob: c579550f38d6869474ac2036942e368c726df7a5 [file] [log] [blame]
BitOhenrycc024eb2015-11-10 17:17:36 +08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
BitOhenrycc024eb2015-11-10 17:17:36 +08003 *
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
Jonathan Hartc7840bd2016-01-21 23:26:29 -080018import org.onlab.packet.MacAddress;
BitOhenrycc024eb2015-11-10 17:17:36 +080019
20import java.util.Objects;
21
Jonathan Hartc7840bd2016-01-21 23:26:29 -080022import static com.google.common.base.Preconditions.checkNotNull;
BitOhenrycc024eb2015-11-10 17:17:36 +080023
24/**
25 * Implementation of arp_eth_src address or arp_eth_dst address criterion.
26 */
27public 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 Hartc7840bd2016-01-21 23:26:29 -080061 return type().toString() + SEPARATOR + mac;
BitOhenrycc024eb2015-11-10 17:17:36 +080062 }
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 Hartc7840bd2016-01-21 23:26:29 -080081}