blob: 8e16321b0f4b6147f044af655761642e146e82a1 [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.VlanId;
19
20import java.util.Objects;
21
22import static com.google.common.base.Preconditions.checkNotNull;
23
24/**
25 * A VLAN Rx filter value.
26 */
27public class VlanRxFilterValue extends RxFilterValue {
28
29 private VlanId vlanId;
30
Georgios Katsikas70671b32018-07-02 18:47:27 +020031 /**
32 * Constructs a VLAN-based Rx filter.
Georgios Katsikas6dc11c12018-12-20 08:43:29 +010033 * @param cpuId CPU id of the server this tag will lead to
Georgios Katsikas70671b32018-07-02 18:47:27 +020034 */
Georgios Katsikas6dc11c12018-12-20 08:43:29 +010035 public VlanRxFilterValue(int cpuId) {
36 super(cpuId);
Georgios Katsikas2ebd8a02018-06-27 18:32:50 +020037 this.vlanId = VlanId.NONE;
Georgios Katsikas83600982017-05-28 20:41:45 +020038 }
39
Georgios Katsikas70671b32018-07-02 18:47:27 +020040 /**
41 * Constructs a VLAN-based Rx filter with specific ID.
42 *
43 * @param vlanId a VLAN ID to use as a filter
Georgios Katsikas6dc11c12018-12-20 08:43:29 +010044 * @param cpuId CPU id of the server this tag will lead to
Georgios Katsikas70671b32018-07-02 18:47:27 +020045 */
Georgios Katsikas6dc11c12018-12-20 08:43:29 +010046 public VlanRxFilterValue(VlanId vlanId, int cpuId) {
47 super(cpuId);
Georgios Katsikas2ebd8a02018-06-27 18:32:50 +020048 setValue(vlanId);
Georgios Katsikas83600982017-05-28 20:41:45 +020049 }
50
Georgios Katsikas70671b32018-07-02 18:47:27 +020051 /**
52 * Constructs a VLAN-based Rx filter out of an existing one.
53 *
54 * @param other a source VlanRxFilterValue object
55 */
Georgios Katsikas83600982017-05-28 20:41:45 +020056 public VlanRxFilterValue(VlanRxFilterValue other) {
Georgios Katsikas6dc11c12018-12-20 08:43:29 +010057 super(other.cpuId);
Georgios Katsikas2ebd8a02018-06-27 18:32:50 +020058 setValue(other.value());
Georgios Katsikas83600982017-05-28 20:41:45 +020059 }
60
61 /**
62 * Returns the value of this Rx filter.
63 *
64 * @return VLAN ID value
65 */
66 public VlanId value() {
67 return this.vlanId;
68 }
69
70 /**
71 * Sets the value of this Rx filter.
72 *
73 * @param vlanId VLAN ID value
74 */
75 public void setValue(VlanId vlanId) {
76 checkNotNull(vlanId, "VLAN ID of Rx filter is NULL");
Georgios Katsikas83600982017-05-28 20:41:45 +020077 this.vlanId = vlanId;
78 }
79
80 @Override
81 public int hashCode() {
82 return Objects.hash(this.vlanId);
83 }
84
85 @Override
86 public boolean equals(Object obj) {
87 if (this == obj) {
88 return true;
89 }
90
91 if ((obj == null) || (!(obj instanceof VlanRxFilterValue))) {
92 return false;
93 }
94
95 VlanRxFilterValue other = (VlanRxFilterValue) obj;
96
97 return this.value().equals(other.value());
98 }
99
100 @Override
101 public String toString() {
102 return this.value().toString();
103 }
104
105}