blob: 0aa0f4dec023fe60401340c19ca58bfdbd9bc043 [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 Context header extension instruction.
29 */
30public class NiciraSetNshContextHeader extends AbstractExtensionTreatment {
31
32 private int nshCh;
33 private ExtensionTreatmentType type;
34
35 private final KryoNamespace appKryo = new KryoNamespace.Builder().build();
36
37 /**
38 * Creates a new set nsh context header instruction.
39 *
40 * @param type extension treatment type
41 */
42 NiciraSetNshContextHeader(ExtensionTreatmentType type) {
43 this.nshCh = 0;
44 this.type = type;
45 }
46
47 /**
48 * Creates a new set nsh context header instruction.
49 *
50 * @param nshCh nsh context header
51 * @param type extension treatment type
52 */
53 NiciraSetNshContextHeader(int nshCh, ExtensionTreatmentType type) {
54 this.nshCh = nshCh;
55 this.type = type;
56 }
57
58 /**
59 * Gets the nsh context header.
60 *
61 * @return nsh context header
62 */
63 public int nshCh() {
64 return nshCh;
65 }
66
67 @Override
68 public ExtensionTreatmentType type() {
69 return type;
70 }
71
72 @Override
73 public void deserialize(byte[] data) {
74 nshCh = appKryo.deserialize(data);
75 }
76
77 @Override
78 public byte[] serialize() {
79 return appKryo.serialize(nshCh);
80 }
81
82 @Override
83 public int hashCode() {
84 return Objects.hash(nshCh, type);
85 }
86
87 @Override
88 public boolean equals(Object obj) {
89 if (this == obj) {
90 return true;
91 }
92 if (obj instanceof NiciraSetNshContextHeader) {
93 NiciraSetNshContextHeader that = (NiciraSetNshContextHeader) obj;
94 return Objects.equals(nshCh, that.nshCh) && Objects.equals(type, that.type);
95
96 }
97 return false;
98 }
99
100 @Override
101 public String toString() {
102 return MoreObjects.toStringHelper(getClass())
103 .add("nshCh", nshCh)
104 .add("type", type)
105 .toString();
106 }
107}