blob: 1a168d013677323bf25e49918b564fd0bca02819 [file] [log] [blame]
Phaneendra Mandace66cbc2015-11-26 18:07:48 +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 */
16
17package org.onosproject.driver.extensions;
18
19import java.util.Objects;
20
21import org.onlab.util.KryoNamespace;
22import org.onosproject.net.flow.instructions.AbstractExtensionTreatment;
23import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
Phaneendra Mandace66cbc2015-11-26 18:07:48 +053024
25import com.google.common.base.MoreObjects;
26
27/**
28 * Nicira set NSH SPI extension instruction.
29 */
30public class NiciraSetNshSpi extends AbstractExtensionTreatment {
31
32 private int nshSpi;
33
Phaneendra Mandaab5a7362015-12-02 01:10:01 +053034 private final KryoNamespace appKryo = new KryoNamespace.Builder().build();
Phaneendra Mandace66cbc2015-11-26 18:07:48 +053035
36 /**
37 * Creates a new set nsh spi instruction.
38 */
39 NiciraSetNshSpi() {
40 nshSpi = 0;
41 }
42
43 /**
44 * Creates a new set nsh spi instruction with given spi.
45 *
46 * @param nshSpi nsh service path index
47 */
48 NiciraSetNshSpi(int nshSpi) {
49 this.nshSpi = nshSpi;
50 }
51
52 /**
53 * Gets the nsh service path index.
54 *
55 * @return nsh service path index
56 */
57 public int nshSpi() {
58 return nshSpi;
59 }
60
61 @Override
62 public ExtensionTreatmentType type() {
63 return ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type();
64 }
65
66 @Override
67 public void deserialize(byte[] data) {
68 nshSpi = appKryo.deserialize(data);
69 }
70
71 @Override
72 public byte[] serialize() {
73 return appKryo.serialize(nshSpi);
74 }
75
76 @Override
77 public int hashCode() {
78 return Objects.hash(nshSpi);
79 }
80
81 @Override
82 public boolean equals(Object obj) {
83 if (this == obj) {
84 return true;
85 }
86 if (obj instanceof NiciraSetNshSpi) {
87 NiciraSetNshSpi that = (NiciraSetNshSpi) obj;
88 return Objects.equals(nshSpi, that.nshSpi);
89
90 }
91 return false;
92 }
93
94 @Override
95 public String toString() {
96 return MoreObjects.toStringHelper(getClass())
97 .add("nshSpi", nshSpi)
98 .toString();
99 }
100}