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