blob: 162ff8833aac32529d7365eef3e6cc87dad68074 [file] [log] [blame]
Phaneendra Mandaefb38752015-12-04 00:43:38 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Phaneendra Mandaefb38752015-12-04 00:43:38 +05303 *
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 /**
Jian Lidab72562016-04-12 14:10:32 -070044 * Creates an instance with initialized Nsh Service Path ID.
45 *
46 * @param nshSpi nsh service path ID
47 */
48 public NiciraMatchNshSpi(NshServicePathId nshSpi) {
49 this.nshSpi = nshSpi;
50 }
51
52 /**
Phaneendra Mandaefb38752015-12-04 00:43:38 +053053 * Gets the network service path id to match.
54 *
55 * @return the nshSpi to match
56 */
57 public NshServicePathId nshSpi() {
58 return nshSpi;
59 }
60
61 @Override
62 public ExtensionSelectorType type() {
63 return ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SPI.type();
64 }
65
66 @Override
67 public byte[] serialize() {
68 return appKryo.serialize(nshSpi);
69 }
70
71 @Override
72 public void deserialize(byte[] data) {
73 nshSpi = NshServicePathId.of(appKryo.deserialize(data));
74 }
75
76 @Override
77 public String toString() {
78 return toStringHelper(type().toString())
79 .add("nshSpi", nshSpi.toString())
80 .toString();
81 }
82
83 @Override
84 public int hashCode() {
85 return Objects.hash(type(), nshSpi);
86 }
87
88 @Override
89 public boolean equals(Object obj) {
90 if (this == obj) {
91 return true;
92 }
93 if (obj instanceof NiciraMatchNshSpi) {
94 NiciraMatchNshSpi that = (NiciraMatchNshSpi) obj;
95 return Objects.equals(nshSpi, that.nshSpi) &&
96 Objects.equals(this.type(), that.type());
97 }
98 return false;
99 }
100}