blob: 5f37247f338fc2e68de2d2f2ea17f60d4ff8e87d [file] [log] [blame]
Phaneendra Mandaefb38752015-12-04 00:43:38 +05301/*
2 * Copyright 2015 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 */
16package org.onosproject.driver.extensions;
17
18import static com.google.common.base.MoreObjects.toStringHelper;
19
20import java.util.Objects;
21
22import org.onlab.util.KryoNamespace;
23import org.onosproject.net.NshContextHeader;
24import org.onosproject.net.flow.AbstractExtension;
25import org.onosproject.net.flow.criteria.ExtensionSelector;
26import org.onosproject.net.flow.criteria.ExtensionSelectorType;
27/**
28 * Implementation of Nsh context header criterion.
29 */
30public final class NiciraMatchNshContextHeader extends AbstractExtension implements ExtensionSelector {
31 private NshContextHeader nshContextHeader;
32 private ExtensionSelectorType type;
33
34 private final KryoNamespace appKryo = new KryoNamespace.Builder().build();
35
36 /**
37 * Constructor to create Nsh context header.
38 *
39 * @param type extension selector type
40 */
41 public NiciraMatchNshContextHeader(ExtensionSelectorType type) {
42 this.nshContextHeader = null;
43 this.type = type;
44 }
45
46 /**
47 * Gets the nsh context header to match.
48 *
49 * @return the nsh context header to match
50 */
51 public NshContextHeader nshContextHeader() {
52 return nshContextHeader;
53 }
54
55 @Override
56 public byte[] serialize() {
57 return appKryo.serialize(nshContextHeader.nshContextHeader());
58 }
59
60 @Override
61 public void deserialize(byte[] data) {
62 nshContextHeader = nshContextHeader.of(appKryo.deserialize(data));
63
64 }
65
66 @Override
67 public ExtensionSelectorType type() {
68 return type;
69 }
70
71 @Override
72 public String toString() {
73 return toStringHelper(type().toString())
74 .add("nshContextHeader", nshContextHeader.toString())
75 .toString();
76 }
77
78 @Override
79 public int hashCode() {
80 return Objects.hash(type(), nshContextHeader);
81 }
82
83 @Override
84 public boolean equals(Object obj) {
85 if (this == obj) {
86 return true;
87 }
88 if (obj instanceof NiciraMatchNshContextHeader) {
89 NiciraMatchNshContextHeader that = (NiciraMatchNshContextHeader) obj;
90 return Objects.equals(nshContextHeader, that.nshContextHeader) &&
91 Objects.equals(this.type(), that.type());
92 }
93 return false;
94 }
95}