blob: 809fa7d1aa80ac5f81c59e76fb474b15b4aac888 [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
Phaneendra Mandaefb38752015-12-04 00:43:38 +053018import org.onlab.util.KryoNamespace;
19import org.onosproject.net.NshServiceIndex;
20import org.onosproject.net.flow.AbstractExtension;
21import org.onosproject.net.flow.criteria.ExtensionSelector;
22import org.onosproject.net.flow.criteria.ExtensionSelectorType;
Jian Lidab72562016-04-12 14:10:32 -070023
24import java.util.Objects;
25
26import static com.google.common.base.MoreObjects.toStringHelper;
Phaneendra Mandaefb38752015-12-04 00:43:38 +053027/**
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 /**
Jian Lidab72562016-04-12 14:10:32 -070045 * Creates an instance with initialized Nsh Service Index.
46 *
47 * @param nshSi nsh service index
48 */
49 public NiciraMatchNshSi(NshServiceIndex nshSi) {
50 this.nshSi = nshSi;
51 }
52
53 /**
Phaneendra Mandaefb38752015-12-04 00:43:38 +053054 * Gets the nsh service index to match.
55 *
56 * @return the si to match
57 */
58 public NshServiceIndex nshSi() {
59 return nshSi;
60 }
61
62 @Override
63 public byte[] serialize() {
64 return appKryo.serialize(nshSi.serviceIndex());
65 }
66
67 @Override
68 public void deserialize(byte[] data) {
69 nshSi = NshServiceIndex.of(appKryo.deserialize(data));
70 }
71
72 @Override
73 public ExtensionSelectorType type() {
74 return ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SI.type();
75 }
76
77 @Override
78 public String toString() {
79 return toStringHelper(type().toString())
80 .add("nshSi", nshSi.toString())
81 .toString();
82 }
83
84 @Override
85 public int hashCode() {
86 return Objects.hash(type(), nshSi);
87 }
88
89 @Override
90 public boolean equals(Object obj) {
91 if (this == obj) {
92 return true;
93 }
94 if (obj instanceof NiciraMatchNshSi) {
95 NiciraMatchNshSi that = (NiciraMatchNshSi) obj;
96 return Objects.equals(nshSi, that.nshSi);
97 }
98 return false;
99 }
100}