blob: ddc1930cd6eb80e25ddaa092f9fcaec5fd0a0fc5 [file] [log] [blame]
Georgios Katsikas83600982017-05-28 20:41:45 +02001/*
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 Katsikas2ebd8a02018-06-27 18:32:50 +020016package org.onosproject.drivers.server.devices.nic;
Georgios Katsikas83600982017-05-28 20:41:45 +020017
18import org.onlab.packet.MplsLabel;
19
20import java.util.Objects;
21
22import static com.google.common.base.Preconditions.checkNotNull;
23
24/**
25 * An MPLS Rx filter value.
26 */
Georgios Katsikas70671b32018-07-02 18:47:27 +020027public final class MplsRxFilterValue extends RxFilterValue {
Georgios Katsikas83600982017-05-28 20:41:45 +020028
29 private MplsLabel mplsLabel;
30
Georgios Katsikas70671b32018-07-02 18:47:27 +020031 /**
32 * Constructs an MPLS-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 MplsRxFilterValue(int cpuId) {
37 super(cpuId);
Georgios Katsikas83600982017-05-28 20:41:45 +020038 this.mplsLabel = null;
39 }
40
Georgios Katsikas70671b32018-07-02 18:47:27 +020041 /**
42 * Constructs an MPLS-based Rx filter with specific label.
43 *
44 * @param mplsLabel an MPLS label to use as a filter
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 MplsRxFilterValue(MplsLabel mplsLabel, int cpuId) {
48 super(cpuId);
Georgios Katsikas2ebd8a02018-06-27 18:32:50 +020049 setValue(mplsLabel);
Georgios Katsikas83600982017-05-28 20:41:45 +020050 }
51
Georgios Katsikas70671b32018-07-02 18:47:27 +020052 /**
53 * Constructs an MPLS-based Rx filter out of an existing one.
54 *
55 * @param other a source MplsRxFilterValue object
56 */
Georgios Katsikas83600982017-05-28 20:41:45 +020057 public MplsRxFilterValue(MplsRxFilterValue other) {
Georgios Katsikas6dc11c12018-12-20 08:43:29 +010058 super(other.cpuId);
Georgios Katsikas2ebd8a02018-06-27 18:32:50 +020059 setValue(other.value());
Georgios Katsikas83600982017-05-28 20:41:45 +020060 }
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 Katsikas83600982017-05-28 20:41:45 +020078 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}