blob: d3765d41a51194e65f838ed7a7f23ec80f8f0ba8 [file] [log] [blame]
Frank Wang5733c382017-03-28 10:15:18 +08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Frank Wang5733c382017-03-28 10:15:18 +08003 *
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 java.util.Objects;
20
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 com.google.common.base.MoreObjects;
27
28/**
29 * Nicira conntrack zone extension selector.
30 */
31public class NiciraMatchCtZone extends AbstractExtension implements ExtensionSelector {
32
33 private int ctZone;
34
35 private final KryoNamespace appKryo = new KryoNamespace.Builder().build();
36
37 /**
38 * Creates a new conntrack zone selector.
39 */
40 NiciraMatchCtZone() {
41 ctZone = 0;
42 }
43
44 /**
45 * Creates a new conntrack zone selector with given zone.
46 *
47 * @param ctZone conntrack zone
48 */
49 public NiciraMatchCtZone(int ctZone) {
50 this.ctZone = ctZone;
51 }
52
53 /**
54 * Gets the conntrack zone.
55 *
56 * @return ctZone
57 */
58 public int ctZone() {
59 return ctZone;
60 }
61
62 @Override
63 public ExtensionSelectorType type() {
64 return ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_ZONE.type();
65 }
66
67 @Override
68 public void deserialize(byte[] data) {
69 ctZone = (int) (appKryo.deserialize(data));
70 }
71
72 @Override
73 public byte[] serialize() {
74 return appKryo.serialize(ctZone);
75 }
76
77 @Override
78 public int hashCode() {
79 return Objects.hash(ctZone);
80 }
81
82 @Override
83 public boolean equals(Object obj) {
84 if (this == obj) {
85 return true;
86 }
87 if (obj instanceof NiciraMatchCtZone) {
88 NiciraMatchCtZone that = (NiciraMatchCtZone) obj;
89 return Objects.equals(ctZone, that.ctZone());
90
91 }
92 return false;
93 }
94
95 @Override
96 public String toString() {
97 return MoreObjects.toStringHelper(getClass()).add("ctZone", ctZone).toString();
98 }
99}