blob: 65ebf28e0300df9e7d5d2c23904c439277621022 [file] [log] [blame]
Phaneendra Mandaab5a7362015-12-02 01:10:01 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Phaneendra Mandaab5a7362015-12-02 01:10:01 +05303 *
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 Manda8db7d092016-06-04 00:17:24 +053019import java.util.Map;
Phaneendra Mandaa272a9f2015-12-04 02:42:55 +053020import java.util.Objects;
21
Phaneendra Mandaab5a7362015-12-02 01:10:01 +053022import org.onlab.util.KryoNamespace;
Phaneendra Mandaa272a9f2015-12-04 02:42:55 +053023import org.onosproject.net.NshContextHeader;
Jonathan Hart26a8d952015-12-02 15:16:35 -080024import org.onosproject.net.flow.AbstractExtension;
25import org.onosproject.net.flow.instructions.ExtensionTreatment;
Phaneendra Mandaab5a7362015-12-02 01:10:01 +053026import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
27
Phaneendra Mandaa272a9f2015-12-04 02:42:55 +053028import com.google.common.base.MoreObjects;
Phaneendra Manda8db7d092016-06-04 00:17:24 +053029import com.google.common.collect.Maps;
Phaneendra Mandaab5a7362015-12-02 01:10:01 +053030
31/**
32 * Nicira set NSH Context header extension instruction.
33 */
Jonathan Hart26a8d952015-12-02 15:16:35 -080034public class NiciraSetNshContextHeader extends AbstractExtension implements
35 ExtensionTreatment {
Phaneendra Mandaab5a7362015-12-02 01:10:01 +053036
Phaneendra Mandaa272a9f2015-12-04 02:42:55 +053037 private NshContextHeader nshCh;
Phaneendra Mandaab5a7362015-12-02 01:10:01 +053038 private ExtensionTreatmentType type;
39
40 private final KryoNamespace appKryo = new KryoNamespace.Builder().build();
41
42 /**
43 * Creates a new set nsh context header instruction.
44 *
45 * @param type extension treatment type
46 */
47 NiciraSetNshContextHeader(ExtensionTreatmentType type) {
Phaneendra Mandaa272a9f2015-12-04 02:42:55 +053048 this.nshCh = NshContextHeader.of(0);
Phaneendra Mandaab5a7362015-12-02 01:10:01 +053049 this.type = type;
50 }
51
52 /**
53 * Creates a new set nsh context header instruction.
54 *
55 * @param nshCh nsh context header
56 * @param type extension treatment type
57 */
Jian Lidab72562016-04-12 14:10:32 -070058 public NiciraSetNshContextHeader(NshContextHeader nshCh, ExtensionTreatmentType type) {
Phaneendra Mandaab5a7362015-12-02 01:10:01 +053059 this.nshCh = nshCh;
60 this.type = type;
61 }
62
63 /**
64 * Gets the nsh context header.
65 *
66 * @return nsh context header
67 */
Phaneendra Mandaa272a9f2015-12-04 02:42:55 +053068 public NshContextHeader nshCh() {
Phaneendra Mandaab5a7362015-12-02 01:10:01 +053069 return nshCh;
70 }
71
72 @Override
73 public ExtensionTreatmentType type() {
74 return type;
75 }
76
77 @Override
78 public void deserialize(byte[] data) {
Phaneendra Manda8db7d092016-06-04 00:17:24 +053079 Map<String, Object> values = appKryo.deserialize(data);
80 nshCh = (NshContextHeader) values.get("nshCh");
81 type = (ExtensionTreatmentType) values.get("type");
Phaneendra Mandaab5a7362015-12-02 01:10:01 +053082 }
83
84 @Override
85 public byte[] serialize() {
Phaneendra Manda8db7d092016-06-04 00:17:24 +053086 Map<String, Object> values = Maps.newHashMap();
87 values.put("nshCh", nshCh);
88 values.put("type", type);
89 return appKryo.serialize(values);
Phaneendra Mandaab5a7362015-12-02 01:10:01 +053090 }
91
92 @Override
93 public int hashCode() {
94 return Objects.hash(nshCh, type);
95 }
96
97 @Override
98 public boolean equals(Object obj) {
99 if (this == obj) {
100 return true;
101 }
102 if (obj instanceof NiciraSetNshContextHeader) {
103 NiciraSetNshContextHeader that = (NiciraSetNshContextHeader) obj;
104 return Objects.equals(nshCh, that.nshCh) && Objects.equals(type, that.type);
105
106 }
107 return false;
108 }
109
110 @Override
111 public String toString() {
112 return MoreObjects.toStringHelper(getClass())
113 .add("nshCh", nshCh)
114 .add("type", type)
115 .toString();
116 }
117}