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