blob: b73e58bfe139fea745bfdb19197e69c36e000f79 [file] [log] [blame]
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -07001/*
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 org.onlab.packet.MacAddress;
19
20import java.util.Objects;
21
22import static com.google.common.base.MoreObjects.toStringHelper;
23
24/**
25 * Implementation of MAC address criterion.
26 */
27public final class EthCriterion implements Criterion {
28 private final MacAddress mac;
29 private final Type type;
30
31 /**
32 * Constructor.
33 *
34 * @param mac the source or destination MAC address to match
35 * @param type the match type. Should be either Type.ETH_DST or
36 * Type.ETH_SRC
37 */
38 EthCriterion(MacAddress mac, Type type) {
39 this.mac = mac;
40 this.type = type;
41 }
42
43 @Override
44 public Type type() {
45 return this.type;
46 }
47
48 /**
49 * Gets the MAC address to match.
50 *
51 * @return the MAC address to match
52 */
53 public MacAddress mac() {
54 return this.mac;
55 }
56
57 @Override
58 public String toString() {
59 return toStringHelper(type().toString())
60 .add("mac", mac).toString();
61 }
62
63 @Override
64 public int hashCode() {
65 return Objects.hash(type, mac);
66 }
67
68 @Override
69 public boolean equals(Object obj) {
70 if (this == obj) {
71 return true;
72 }
73 if (obj instanceof EthCriterion) {
74 EthCriterion that = (EthCriterion) obj;
75 return Objects.equals(mac, that.mac) &&
76 Objects.equals(type, that.type);
77 }
78 return false;
79 }
80}