blob: a6d50a0f840b9a52ea820b747de7073ba948f1b6 [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.NshContextHeader;
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 Context header extension instruction.
31 */
Jonathan Hart26a8d952015-12-02 15:16:35 -080032public class NiciraSetNshContextHeader extends AbstractExtension implements
33 ExtensionTreatment {
Phaneendra Mandaab5a7362015-12-02 01:10:01 +053034
Phaneendra Mandaa272a9f2015-12-04 02:42:55 +053035 private NshContextHeader nshCh;
Phaneendra Mandaab5a7362015-12-02 01:10:01 +053036 private ExtensionTreatmentType type;
37
38 private final KryoNamespace appKryo = new KryoNamespace.Builder().build();
39
40 /**
41 * Creates a new set nsh context header instruction.
42 *
43 * @param type extension treatment type
44 */
45 NiciraSetNshContextHeader(ExtensionTreatmentType type) {
Phaneendra Mandaa272a9f2015-12-04 02:42:55 +053046 this.nshCh = NshContextHeader.of(0);
Phaneendra Mandaab5a7362015-12-02 01:10:01 +053047 this.type = type;
48 }
49
50 /**
51 * Creates a new set nsh context header instruction.
52 *
53 * @param nshCh nsh context header
54 * @param type extension treatment type
55 */
Phaneendra Mandaa272a9f2015-12-04 02:42:55 +053056 NiciraSetNshContextHeader(NshContextHeader nshCh, ExtensionTreatmentType type) {
Phaneendra Mandaab5a7362015-12-02 01:10:01 +053057 this.nshCh = nshCh;
58 this.type = type;
59 }
60
61 /**
62 * Gets the nsh context header.
63 *
64 * @return nsh context header
65 */
Phaneendra Mandaa272a9f2015-12-04 02:42:55 +053066 public NshContextHeader nshCh() {
Phaneendra Mandaab5a7362015-12-02 01:10:01 +053067 return nshCh;
68 }
69
70 @Override
71 public ExtensionTreatmentType type() {
72 return type;
73 }
74
75 @Override
76 public void deserialize(byte[] data) {
Phaneendra Mandaa272a9f2015-12-04 02:42:55 +053077 nshCh = NshContextHeader.of(appKryo.deserialize(data));
Phaneendra Mandaab5a7362015-12-02 01:10:01 +053078 }
79
80 @Override
81 public byte[] serialize() {
Phaneendra Mandaa272a9f2015-12-04 02:42:55 +053082 return appKryo.serialize(nshCh.nshContextHeader());
Phaneendra Mandaab5a7362015-12-02 01:10:01 +053083 }
84
85 @Override
86 public int hashCode() {
87 return Objects.hash(nshCh, type);
88 }
89
90 @Override
91 public boolean equals(Object obj) {
92 if (this == obj) {
93 return true;
94 }
95 if (obj instanceof NiciraSetNshContextHeader) {
96 NiciraSetNshContextHeader that = (NiciraSetNshContextHeader) obj;
97 return Objects.equals(nshCh, that.nshCh) && Objects.equals(type, that.type);
98
99 }
100 return false;
101 }
102
103 @Override
104 public String toString() {
105 return MoreObjects.toStringHelper(getClass())
106 .add("nshCh", nshCh)
107 .add("type", type)
108 .toString();
109 }
110}