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