blob: dec66c9149fd66ccba9e87c9e7cec1349d002cc6 [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
Phaneendra Mandaa272a9f2015-12-04 02:42:55 +053019import java.util.Objects;
20
Phaneendra Mandaab5a7362015-12-02 01:10:01 +053021import org.onlab.util.KryoNamespace;
Phaneendra Mandaa272a9f2015-12-04 02:42:55 +053022import org.onosproject.net.NshServiceIndex;
Jonathan Hart26a8d952015-12-02 15:16:35 -080023import org.onosproject.net.flow.AbstractExtension;
24import org.onosproject.net.flow.instructions.ExtensionTreatment;
Phaneendra Mandaab5a7362015-12-02 01:10:01 +053025import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
26
Phaneendra Mandaa272a9f2015-12-04 02:42:55 +053027import com.google.common.base.MoreObjects;
Phaneendra Mandaab5a7362015-12-02 01:10:01 +053028
29/**
30 * Nicira set NSH SI extension instruction.
31 */
Jonathan Hart26a8d952015-12-02 15:16:35 -080032public class NiciraSetNshSi extends AbstractExtension implements
33 ExtensionTreatment {
Phaneendra Mandaab5a7362015-12-02 01:10:01 +053034
Phaneendra Mandaa272a9f2015-12-04 02:42:55 +053035 private NshServiceIndex nshSi;
Phaneendra Mandaab5a7362015-12-02 01:10:01 +053036
37 private final KryoNamespace appKryo = new KryoNamespace.Builder().build();
38
39 /**
40 * Creates a new set nsh si instruction.
41 */
42 NiciraSetNshSi() {
Phaneendra Mandaa272a9f2015-12-04 02:42:55 +053043 nshSi = NshServiceIndex.of((short) 0);
Phaneendra Mandaab5a7362015-12-02 01:10:01 +053044 }
45
46 /**
47 * Creates a new set nsh si instruction with given si.
48 *
49 * @param nshSi nsh service index
50 */
Phaneendra Mandaa272a9f2015-12-04 02:42:55 +053051 NiciraSetNshSi(NshServiceIndex nshSi) {
Phaneendra Mandaab5a7362015-12-02 01:10:01 +053052 this.nshSi = nshSi;
53 }
54
55 /**
56 * Gets the nsh service index.
57 *
58 * @return nsh service index
59 */
Phaneendra Mandaa272a9f2015-12-04 02:42:55 +053060 public NshServiceIndex nshSi() {
Phaneendra Mandaab5a7362015-12-02 01:10:01 +053061 return nshSi;
62 }
63
64 @Override
65 public ExtensionTreatmentType type() {
66 return ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type();
67 }
68
69 @Override
70 public void deserialize(byte[] data) {
Phaneendra Mandaa272a9f2015-12-04 02:42:55 +053071 nshSi = NshServiceIndex.of(appKryo.deserialize(data));
Phaneendra Mandaab5a7362015-12-02 01:10:01 +053072 }
73
74 @Override
75 public byte[] serialize() {
Phaneendra Mandaa272a9f2015-12-04 02:42:55 +053076 return appKryo.serialize(nshSi.serviceIndex());
Phaneendra Mandaab5a7362015-12-02 01:10:01 +053077 }
78
79 @Override
80 public int hashCode() {
81 return Objects.hash(nshSi);
82 }
83
84 @Override
85 public boolean equals(Object obj) {
86 if (this == obj) {
87 return true;
88 }
89 if (obj instanceof NiciraSetNshSi) {
90 NiciraSetNshSi that = (NiciraSetNshSi) obj;
91 return Objects.equals(nshSi, that.nshSi);
92
93 }
94 return false;
95 }
96
97 @Override
98 public String toString() {
99 return MoreObjects.toStringHelper(getClass())
100 .add("nshSi", nshSi)
101 .toString();
102 }
103}