blob: 42bb78d45f13119b7777ca7aee373a80d2235f37 [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.NshServicePathId;
24import org.onosproject.net.flow.AbstractExtension;
25import org.onosproject.net.flow.criteria.ExtensionSelector;
26import org.onosproject.net.flow.criteria.ExtensionSelectorType;
27
28/**
29 * Implementation of NSH Service Path Id selector.
30 */
31public final class NiciraMatchNshSpi extends AbstractExtension implements ExtensionSelector {
32 private NshServicePathId nshSpi;
33
34 private final KryoNamespace appKryo = new KryoNamespace.Builder().build();
35
36 /**
37 * Default constructor.
38 */
39 public NiciraMatchNshSpi() {
40 this.nshSpi = null;
41 }
42
43 /**
44 * Gets the network service path id to match.
45 *
46 * @return the nshSpi to match
47 */
48 public NshServicePathId nshSpi() {
49 return nshSpi;
50 }
51
52 @Override
53 public ExtensionSelectorType type() {
54 return ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SPI.type();
55 }
56
57 @Override
58 public byte[] serialize() {
59 return appKryo.serialize(nshSpi);
60 }
61
62 @Override
63 public void deserialize(byte[] data) {
64 nshSpi = NshServicePathId.of(appKryo.deserialize(data));
65 }
66
67 @Override
68 public String toString() {
69 return toStringHelper(type().toString())
70 .add("nshSpi", nshSpi.toString())
71 .toString();
72 }
73
74 @Override
75 public int hashCode() {
76 return Objects.hash(type(), nshSpi);
77 }
78
79 @Override
80 public boolean equals(Object obj) {
81 if (this == obj) {
82 return true;
83 }
84 if (obj instanceof NiciraMatchNshSpi) {
85 NiciraMatchNshSpi that = (NiciraMatchNshSpi) obj;
86 return Objects.equals(nshSpi, that.nshSpi) &&
87 Objects.equals(this.type(), that.type());
88 }
89 return false;
90 }
91}