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