blob: 18a99bee7a0759093826ac63536f7ee1e05de06e [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.
33 */
Georgios Katsikas83600982017-05-28 20:41:45 +020034 public VlanRxFilterValue() {
35 super();
Georgios Katsikas2ebd8a02018-06-27 18:32:50 +020036 this.vlanId = VlanId.NONE;
Georgios Katsikas83600982017-05-28 20:41:45 +020037 }
38
Georgios Katsikas70671b32018-07-02 18:47:27 +020039 /**
40 * Constructs a VLAN-based Rx filter with specific ID.
41 *
42 * @param vlanId a VLAN ID to use as a filter
43 */
Georgios Katsikas83600982017-05-28 20:41:45 +020044 public VlanRxFilterValue(VlanId vlanId) {
45 super();
Georgios Katsikas2ebd8a02018-06-27 18:32:50 +020046 setValue(vlanId);
Georgios Katsikas83600982017-05-28 20:41:45 +020047 }
48
Georgios Katsikas70671b32018-07-02 18:47:27 +020049 /**
50 * Constructs a VLAN-based Rx filter out of an existing one.
51 *
52 * @param other a source VlanRxFilterValue object
53 */
Georgios Katsikas83600982017-05-28 20:41:45 +020054 public VlanRxFilterValue(VlanRxFilterValue other) {
55 super();
Georgios Katsikas2ebd8a02018-06-27 18:32:50 +020056 setValue(other.value());
Georgios Katsikas83600982017-05-28 20:41:45 +020057 }
58
59 /**
60 * Returns the value of this Rx filter.
61 *
62 * @return VLAN ID value
63 */
64 public VlanId value() {
65 return this.vlanId;
66 }
67
68 /**
69 * Sets the value of this Rx filter.
70 *
71 * @param vlanId VLAN ID value
72 */
73 public void setValue(VlanId vlanId) {
74 checkNotNull(vlanId, "VLAN ID of Rx filter is NULL");
Georgios Katsikas83600982017-05-28 20:41:45 +020075 this.vlanId = vlanId;
76 }
77
78 @Override
79 public int hashCode() {
80 return Objects.hash(this.vlanId);
81 }
82
83 @Override
84 public boolean equals(Object obj) {
85 if (this == obj) {
86 return true;
87 }
88
89 if ((obj == null) || (!(obj instanceof VlanRxFilterValue))) {
90 return false;
91 }
92
93 VlanRxFilterValue other = (VlanRxFilterValue) obj;
94
95 return this.value().equals(other.value());
96 }
97
98 @Override
99 public String toString() {
100 return this.value().toString();
101 }
102
103}