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