blob: f43a6dbf4ffdb820dccf561d8c9aa4020d99c036 [file] [log] [blame]
Georgios Katsikas70671b32018-07-02 18:47:27 +02001/*
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 Katsikas740d3282020-03-18 12:05:03 +010016
Georgios Katsikas70671b32018-07-02 18:47:27 +020017package org.onosproject.drivers.server.devices.nic;
18
19import java.util.Objects;
20
21import static com.google.common.base.Preconditions.checkArgument;
Georgios Katsikas740d3282020-03-18 12:05:03 +010022import static org.onosproject.drivers.server.Constants.MSG_NIC_FLOW_FILTER_RSS_NEGATIVE;
Georgios Katsikas70671b32018-07-02 18:47:27 +020023
24/**
25 * A Receice-Side Scaling (RSS)-based Rx filter value.
26 */
27public final class RssRxFilterValue extends RxFilterValue implements Comparable {
28
29 private int rssHash;
30
31 /**
32 * Constructs an RSS-based Rx filter.
Georgios Katsikas6dc11c12018-12-20 08:43:29 +010033 *
34 * @param cpuId CPU ID of the server this tag will lead to
Georgios Katsikas70671b32018-07-02 18:47:27 +020035 */
Georgios Katsikas6dc11c12018-12-20 08:43:29 +010036 public RssRxFilterValue(int cpuId) {
37 super(cpuId);
Georgios Katsikas70671b32018-07-02 18:47:27 +020038 setValue(0);
39 }
40
41 /**
42 * Constructs an RSS-based Rx filter with specific hash.
43 *
44 * @param rssHash a hash value
Georgios Katsikas6dc11c12018-12-20 08:43:29 +010045 * @param cpuId CPU ID of the server this tag will lead to
Georgios Katsikas70671b32018-07-02 18:47:27 +020046 */
Georgios Katsikas6dc11c12018-12-20 08:43:29 +010047 public RssRxFilterValue(int rssHash, int cpuId) {
48 super(cpuId);
Georgios Katsikas70671b32018-07-02 18:47:27 +020049 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 Katsikas6dc11c12018-12-20 08:43:29 +010058 super(other.cpuId);
Georgios Katsikas70671b32018-07-02 18:47:27 +020059 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 Katsikas740d3282020-03-18 12:05:03 +010077 checkArgument(rssHash >= 0, MSG_NIC_FLOW_FILTER_RSS_NEGATIVE);
Georgios Katsikas70671b32018-07-02 18:47:27 +020078 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}