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.MplsLabel; |
| 19 | |
| 20 | import java.util.Objects; |
| 21 | |
| 22 | import static com.google.common.base.Preconditions.checkNotNull; |
| 23 | |
| 24 | /** |
| 25 | * An MPLS Rx filter value. |
| 26 | */ |
Georgios Katsikas | 70671b3 | 2018-07-02 18:47:27 +0200 | [diff] [blame] | 27 | public final class MplsRxFilterValue extends RxFilterValue { |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 28 | |
| 29 | private MplsLabel mplsLabel; |
| 30 | |
Georgios Katsikas | 70671b3 | 2018-07-02 18:47:27 +0200 | [diff] [blame] | 31 | /** |
| 32 | * Constructs an MPLS-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 MplsRxFilterValue(int cpuId) { |
| 37 | super(cpuId); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 38 | this.mplsLabel = null; |
| 39 | } |
| 40 | |
Georgios Katsikas | 70671b3 | 2018-07-02 18:47:27 +0200 | [diff] [blame] | 41 | /** |
| 42 | * Constructs an MPLS-based Rx filter with specific label. |
| 43 | * |
| 44 | * @param mplsLabel an MPLS label to use as a filter |
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 MplsRxFilterValue(MplsLabel mplsLabel, int cpuId) { |
| 48 | super(cpuId); |
Georgios Katsikas | 2ebd8a0 | 2018-06-27 18:32:50 +0200 | [diff] [blame] | 49 | setValue(mplsLabel); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 50 | } |
| 51 | |
Georgios Katsikas | 70671b3 | 2018-07-02 18:47:27 +0200 | [diff] [blame] | 52 | /** |
| 53 | * Constructs an MPLS-based Rx filter out of an existing one. |
| 54 | * |
| 55 | * @param other a source MplsRxFilterValue object |
| 56 | */ |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 57 | public MplsRxFilterValue(MplsRxFilterValue other) { |
Georgios Katsikas | 6dc11c1 | 2018-12-20 08:43:29 +0100 | [diff] [blame^] | 58 | super(other.cpuId); |
Georgios Katsikas | 2ebd8a0 | 2018-06-27 18:32:50 +0200 | [diff] [blame] | 59 | setValue(other.value()); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Returns the value of this Rx filter. |
| 64 | * |
| 65 | * @return MPLS label value |
| 66 | */ |
| 67 | public MplsLabel value() { |
| 68 | return this.mplsLabel; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Sets the value of this Rx filter. |
| 73 | * |
| 74 | * @param mplsLabel MPLS label value |
| 75 | */ |
| 76 | public void setValue(MplsLabel mplsLabel) { |
| 77 | checkNotNull(mplsLabel, "MPLS label of Rx filter is NULL"); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 78 | this.mplsLabel = mplsLabel; |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public int hashCode() { |
| 83 | return Objects.hash(this.mplsLabel); |
| 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 MplsRxFilterValue))) { |
| 93 | return false; |
| 94 | } |
| 95 | |
| 96 | MplsRxFilterValue other = (MplsRxFilterValue) obj; |
| 97 | |
| 98 | return this.value().equals(other.value()); |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public String toString() { |
| 103 | return this.value().toString(); |
| 104 | } |
| 105 | |
| 106 | } |