blob: 67d9733e7c96850e413bfbf3a239092caaae63a7 [file] [log] [blame]
Frank Wang5733c382017-03-28 10:15:18 +08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-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
Jian Liba1e75a2018-10-27 20:32:24 +090019import java.util.HashMap;
Frank Wang5733c382017-03-28 10:15:18 +080020import java.util.Map;
21import java.util.Objects;
22
23import com.google.common.collect.Maps;
24import org.onlab.util.KryoNamespace;
25import org.onosproject.net.flow.AbstractExtension;
26import org.onosproject.net.flow.criteria.ExtensionSelector;
27import org.onosproject.net.flow.criteria.ExtensionSelectorType;
28
29import com.google.common.base.MoreObjects;
30
31/**
32 * Nicira conntrack mark extension selector.
33 */
34public class NiciraMatchCtMark extends AbstractExtension implements ExtensionSelector {
35
36 private long ctMark;
37 private long ctMarkMask;
38
Jian Liba1e75a2018-10-27 20:32:24 +090039 private final KryoNamespace appKryo = new KryoNamespace.Builder()
40 .register(HashMap.class)
41 .build();
Frank Wang5733c382017-03-28 10:15:18 +080042
43 /**
44 * Creates a new conntrack mark selector.
45 */
46 NiciraMatchCtMark() {
47 ctMark = 0L;
48 ctMarkMask = ~0L;
49 }
50
51 /**
52 * Creates a new conntrack state selector with given mark.
53 *
54 * @param ctMark conntrack mark
55 */
56 public NiciraMatchCtMark(long ctMark) {
57 this.ctMark = ctMark;
58 this.ctMarkMask = ~0L;
59 }
60
61 /**
62 * Creates a new conntrack state selector with given mark.
63 *
64 * @param ctMark conntrack mark
65 * @param mask conntrack mark mask
66 */
67 public NiciraMatchCtMark(long ctMark, long mask) {
68 this.ctMark = ctMark;
69 this.ctMarkMask = mask;
70 }
71
72 /**
73 * Gets the conntrack mark.
74 *
75 * @return ctMark
76 */
77 public long ctMark() {
78 return ctMark;
79 }
80
81 /**
82 * Gets the conntrack mark mask.
83 *
84 * @return ctMarkMask
85 */
86 public long ctMarkMask() {
87 return ctMarkMask;
88 }
89
90 @Override
91 public ExtensionSelectorType type() {
92 return ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_MARK.type();
93 }
94
95 @Override
96 public void deserialize(byte[] data) {
97 Map<String, Object> values = appKryo.deserialize(data);
98 ctMark = (long) values.get("ctMark");
99 ctMarkMask = (long) values.get("ctMarkMask");
100 }
101
102 @Override
103 public byte[] serialize() {
104 Map<String, Object> values = Maps.newHashMap();
105 values.put("ctMark", ctMark);
106 values.put("ctMarkMask", ctMarkMask);
107 return appKryo.serialize(values);
108 }
109
110 @Override
111 public int hashCode() {
112 return Objects.hash(ctMark, ctMarkMask);
113 }
114
115 @Override
116 public boolean equals(Object obj) {
117 if (this == obj) {
118 return true;
119 }
120 if (obj instanceof NiciraMatchCtMark) {
121 NiciraMatchCtMark that = (NiciraMatchCtMark) obj;
122 return Objects.equals(ctMark, that.ctMark)
123 && Objects.equals(ctMarkMask, that.ctMarkMask);
124
125 }
126 return false;
127 }
128
129 @Override
130 public String toString() {
131 return MoreObjects.toStringHelper(getClass())
132 .add("ctMark", ctMark)
133 .add("ctMarkMask", ctMarkMask)
134 .toString();
135 }
136}