blob: 71269dd1f84eaf18f0667a86e385329854814114 [file] [log] [blame]
BitOhenrycc024eb2015-11-10 17:17:36 +08001/*
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 */
16package org.onosproject.net.flow.criteria;
17
18import static com.google.common.base.MoreObjects.toStringHelper;
19import static com.google.common.base.Preconditions.checkNotNull;
20
21import java.util.Objects;
22
23import org.onlab.packet.MacAddress;
24
25/**
26 * Implementation of arp_eth_src address or arp_eth_dst address criterion.
27 */
28public final class ArpHaCriterion implements Criterion {
29 private final MacAddress mac;
30 private final Type type;
31
32 /**
33 * Constructor.
34 *
35 * @param mac the MAC Address to match.
36 * @param type the match type. Should be one of the following:
37 * Type.ARP_SHA, Type.ARP_THA
38 */
39 ArpHaCriterion(MacAddress mac, Type type) {
40 checkNotNull(mac, "mac cannot be null");
41 checkNotNull(type, "type cannot be null");
42 this.mac = mac;
43 this.type = type;
44 }
45
46 @Override
47 public Type type() {
48 return this.type;
49 }
50
51 /**
52 * Gets the MAC Address to match.
53 *
54 * @return the MAC Address to match
55 */
56 public MacAddress mac() {
57 return this.mac;
58 }
59
60 @Override
61 public String toString() {
62 return toStringHelper(type().toString())
63 .add("mac", mac).toString();
64 }
65
66 @Override
67 public int hashCode() {
68 return Objects.hash(type().ordinal(), mac);
69 }
70
71 @Override
72 public boolean equals(Object obj) {
73 if (this == obj) {
74 return true;
75 }
76 if (obj instanceof ArpHaCriterion) {
77 ArpHaCriterion that = (ArpHaCriterion) obj;
78 return Objects.equals(mac, that.mac) &&
79 Objects.equals(type, that.type);
80 }
81 return false;
82 }
83}