blob: 0c3b7faacf69fde4298bc817decaba86313f3f64 [file] [log] [blame]
Charles Chan14967c22015-12-07 11:11:50 -08001/*
2 * Copyright 2016 Open Networking Laboratory
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 */
16
17package org.onosproject.driver.extensions;
18
19import com.google.common.base.MoreObjects;
20import org.onlab.packet.VlanId;
21import org.onlab.util.KryoNamespace;
22import org.onosproject.net.flow.AbstractExtension;
23import org.onosproject.net.flow.criteria.ExtensionSelector;
24import org.onosproject.net.flow.criteria.ExtensionSelectorType;
25
26import java.util.Objects;
27
28import static com.google.common.base.Preconditions.checkNotNull;
29
30/**
31 * OFDPA VLAN ID extension match.
32 */
33public class OfdpaMatchVlanVid extends AbstractExtension implements ExtensionSelector {
34 private VlanId vlanId;
35
36 private static final KryoNamespace APPKRYO = new KryoNamespace.Builder()
37 .register(VlanId.class)
38 .build();
39
40 /**
41 * OFDPA VLAN ID extension match.
42 */
43 protected OfdpaMatchVlanVid() {
44 vlanId = null;
45 }
46
47 /**
48 * Constructs a new VLAN ID match with given VLAN ID.
49 *
50 * @param vlanId VLAN ID
51 */
52 public OfdpaMatchVlanVid(VlanId vlanId) {
53 checkNotNull(vlanId);
54 this.vlanId = vlanId;
55 }
56
57 /**
58 * Gets the VLAN ID.
59 *
60 * @return VLAN ID
61 */
62 public VlanId vlanId() {
63 return vlanId;
64 }
65
66 @Override
67 public ExtensionSelectorType type() {
68 return ExtensionSelectorType.ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type();
69 }
70
71 @Override
72 public void deserialize(byte[] data) {
73 vlanId = APPKRYO.deserialize(data);
74 }
75
76 @Override
77 public byte[] serialize() {
78 return APPKRYO.serialize(vlanId);
79 }
80
81 @Override
82 public int hashCode() {
83 return Objects.hash(vlanId);
84 }
85
86 @Override
87 public boolean equals(Object obj) {
88 if (this == obj) {
89 return true;
90 }
91 if (obj instanceof OfdpaMatchVlanVid) {
92 OfdpaMatchVlanVid that = (OfdpaMatchVlanVid) obj;
93 return Objects.equals(vlanId, that.vlanId);
94
95 }
96 return false;
97 }
98
99 @Override
100 public String toString() {
101 return MoreObjects.toStringHelper(getClass())
102 .add("vlanId", vlanId)
103 .toString();
104 }
105}