blob: c98a584a95b694a70023a0f30a06171bfcffe5ca [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.NshServiceIndex;
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 Service Index(SI).
29 */
30public final class NiciraMatchNshSi extends AbstractExtension implements ExtensionSelector {
31
32 private NshServiceIndex nshSi;
33
34 private final KryoNamespace appKryo = new KryoNamespace.Builder().build();
35
36 /**
37 * Default constructor.
38 *
39 */
40 public NiciraMatchNshSi() {
41 this.nshSi = null;
42 }
43
44 /**
45 * Gets the nsh service index to match.
46 *
47 * @return the si to match
48 */
49 public NshServiceIndex nshSi() {
50 return nshSi;
51 }
52
53 @Override
54 public byte[] serialize() {
55 return appKryo.serialize(nshSi.serviceIndex());
56 }
57
58 @Override
59 public void deserialize(byte[] data) {
60 nshSi = NshServiceIndex.of(appKryo.deserialize(data));
61 }
62
63 @Override
64 public ExtensionSelectorType type() {
65 return ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SI.type();
66 }
67
68 @Override
69 public String toString() {
70 return toStringHelper(type().toString())
71 .add("nshSi", nshSi.toString())
72 .toString();
73 }
74
75 @Override
76 public int hashCode() {
77 return Objects.hash(type(), nshSi);
78 }
79
80 @Override
81 public boolean equals(Object obj) {
82 if (this == obj) {
83 return true;
84 }
85 if (obj instanceof NiciraMatchNshSi) {
86 NiciraMatchNshSi that = (NiciraMatchNshSi) obj;
87 return Objects.equals(nshSi, that.nshSi);
88 }
89 return false;
90 }
91}