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