Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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 | */ |
Georgios Katsikas | 2ebd8a0 | 2018-06-27 18:32:50 +0200 | [diff] [blame] | 16 | package org.onosproject.drivers.server.devices.nic; |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 17 | |
| 18 | import org.onlab.packet.MacAddress; |
| 19 | |
| 20 | import java.util.Objects; |
| 21 | |
| 22 | import static com.google.common.base.Preconditions.checkNotNull; |
| 23 | |
| 24 | /** |
| 25 | * A MAC Rx filter value. |
| 26 | */ |
Georgios Katsikas | 70671b3 | 2018-07-02 18:47:27 +0200 | [diff] [blame] | 27 | public final class MacRxFilterValue extends RxFilterValue implements Comparable { |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 28 | |
| 29 | private MacAddress mac; |
| 30 | |
Georgios Katsikas | 70671b3 | 2018-07-02 18:47:27 +0200 | [diff] [blame] | 31 | /** |
| 32 | * Constructs a MAC-based Rx filter. |
Georgios Katsikas | 6dc11c1 | 2018-12-20 08:43:29 +0100 | [diff] [blame^] | 33 | * @param cpuId CPU ID of the server this tag will lead to |
Georgios Katsikas | 70671b3 | 2018-07-02 18:47:27 +0200 | [diff] [blame] | 34 | */ |
Georgios Katsikas | 6dc11c1 | 2018-12-20 08:43:29 +0100 | [diff] [blame^] | 35 | public MacRxFilterValue(int cpuId) { |
| 36 | super(cpuId); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 37 | this.mac = null; |
| 38 | } |
| 39 | |
Georgios Katsikas | 70671b3 | 2018-07-02 18:47:27 +0200 | [diff] [blame] | 40 | /** |
| 41 | * Constructs a MAC-based Rx filter with specific MAC address. |
| 42 | * |
| 43 | * @param mac a MAC address to use as a filter |
Georgios Katsikas | 6dc11c1 | 2018-12-20 08:43:29 +0100 | [diff] [blame^] | 44 | * @param cpuId CPU ID of the server this tag will lead to |
Georgios Katsikas | 70671b3 | 2018-07-02 18:47:27 +0200 | [diff] [blame] | 45 | */ |
Georgios Katsikas | 6dc11c1 | 2018-12-20 08:43:29 +0100 | [diff] [blame^] | 46 | public MacRxFilterValue(MacAddress mac, int cpuId) { |
| 47 | super(cpuId); |
Georgios Katsikas | 2ebd8a0 | 2018-06-27 18:32:50 +0200 | [diff] [blame] | 48 | setValue(mac); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 49 | } |
| 50 | |
Georgios Katsikas | 70671b3 | 2018-07-02 18:47:27 +0200 | [diff] [blame] | 51 | /** |
| 52 | * Constructs a MAC-based Rx filter out of an existing one. |
| 53 | * |
| 54 | * @param other a source MacRxFilterValue object |
| 55 | */ |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 56 | public MacRxFilterValue(MacRxFilterValue other) { |
Georgios Katsikas | 6dc11c1 | 2018-12-20 08:43:29 +0100 | [diff] [blame^] | 57 | super(other.cpuId); |
Georgios Katsikas | 2ebd8a0 | 2018-06-27 18:32:50 +0200 | [diff] [blame] | 58 | setValue(other.value()); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Returns the value of this Rx filter. |
| 63 | * |
| 64 | * @return MAC value |
| 65 | */ |
| 66 | public MacAddress value() { |
| 67 | return this.mac; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Sets the value of this Rx filter. |
| 72 | * |
| 73 | * @param mac MAC value |
| 74 | */ |
| 75 | public void setValue(MacAddress mac) { |
| 76 | checkNotNull(mac, "MAC address of Rx filter is NULL"); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 77 | this.mac = mac; |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public int hashCode() { |
| 82 | return Objects.hash(this.mac); |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public boolean equals(Object obj) { |
| 87 | if (this == obj) { |
| 88 | return true; |
| 89 | } |
| 90 | |
| 91 | if ((obj == null) || (!(obj instanceof MacRxFilterValue))) { |
| 92 | return false; |
| 93 | } |
| 94 | |
| 95 | MacRxFilterValue other = (MacRxFilterValue) obj; |
| 96 | |
| 97 | return this.value().equals(other.value()); |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public int compareTo(Object other) { |
| 102 | if (this == other) { |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | if (other == null) { |
| 107 | return -1; |
| 108 | } |
| 109 | |
| 110 | if (other instanceof MacRxFilterValue) { |
| 111 | MacRxFilterValue otherRxVal = (MacRxFilterValue) other; |
| 112 | |
| 113 | // Extract the digits out of the ID |
| 114 | String thisMac = this.toString(); |
| 115 | String otherMac = otherRxVal.toString(); |
| 116 | |
| 117 | return thisMac.compareToIgnoreCase(otherMac); |
| 118 | } |
| 119 | |
| 120 | return -1; |
| 121 | } |
| 122 | |
| 123 | @Override |
| 124 | public String toString() { |
| 125 | return this.value().toString(); |
| 126 | } |
| 127 | |
| 128 | } |