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