blob: 099f995c9a633ef9a1c01c7c55cba4d44efecc43 [file] [log] [blame]
Charles Chancad338a2016-09-16 18:03:11 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Charles Chancad338a2016-09-16 18:03:11 -07003 *
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
Jonghwan Hyun360b02f2017-08-11 14:00:07 -070019import com.fasterxml.jackson.databind.node.ObjectNode;
Pier Ventre6f630052016-10-18 09:58:41 -070020import org.onlab.packet.VlanId;
Jonghwan Hyun360b02f2017-08-11 14:00:07 -070021import org.onosproject.codec.CodecContext;
Charles Chancad338a2016-09-16 18:03:11 -070022import org.onosproject.net.behaviour.ExtensionTreatmentResolver;
23import org.onosproject.net.driver.AbstractHandlerBehaviour;
24import org.onosproject.net.flow.instructions.ExtensionTreatment;
25import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
26import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter;
27import org.projectfloodlight.openflow.protocol.OFActionType;
28import org.projectfloodlight.openflow.protocol.OFFactory;
29import org.projectfloodlight.openflow.protocol.action.OFAction;
Pier Ventreee4a8f22016-10-22 15:45:36 -070030import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter;
31import org.projectfloodlight.openflow.protocol.action.OFActionOfdpa;
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -070032import org.projectfloodlight.openflow.protocol.action.OFActionOnf;
33import org.projectfloodlight.openflow.protocol.action.OFActionOnfCopyField;
Charles Chancad338a2016-09-16 18:03:11 -070034import org.projectfloodlight.openflow.protocol.action.OFActionSetField;
35import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -070036import org.projectfloodlight.openflow.protocol.oxm.OFOxmOfdpaAllowVlanTranslation;
Pier Ventre9cf536b2016-10-21 13:30:18 -070037import org.projectfloodlight.openflow.protocol.oxm.OFOxmOfdpaMplsL2Port;
Charles Chancad338a2016-09-16 18:03:11 -070038import org.projectfloodlight.openflow.protocol.oxm.OFOxmOfdpaMplsType;
Pier Ventre6f630052016-10-18 09:58:41 -070039import org.projectfloodlight.openflow.protocol.oxm.OFOxmOfdpaOvid;
Pier Ventredb252cc2016-10-21 21:54:26 -070040import org.projectfloodlight.openflow.protocol.oxm.OFOxmOfdpaQosIndex;
Charles Chancad338a2016-09-16 18:03:11 -070041import org.projectfloodlight.openflow.types.U16;
Pier Ventre9cf536b2016-10-21 13:30:18 -070042import org.projectfloodlight.openflow.types.U32;
Pier Ventredb252cc2016-10-21 21:54:26 -070043import org.projectfloodlight.openflow.types.U8;
Pier Ventre6f630052016-10-18 09:58:41 -070044import org.slf4j.Logger;
45import org.slf4j.LoggerFactory;
Charles Chancad338a2016-09-16 18:03:11 -070046
Jonghwan Hyun360b02f2017-08-11 14:00:07 -070047import static com.google.common.base.Preconditions.checkNotNull;
48import static org.onlab.util.Tools.nullIsIllegal;
49
Charles Chancad338a2016-09-16 18:03:11 -070050/**
51 * Interpreter for OFDPA3 OpenFlow treatment extensions.
52 */
53public class Ofdpa3ExtensionTreatmentInterpreter extends AbstractHandlerBehaviour
54 implements ExtensionTreatmentInterpreter, ExtensionTreatmentResolver {
Pier Ventre6f630052016-10-18 09:58:41 -070055
Pier Ventreee4a8f22016-10-22 15:45:36 -070056 private static final int TYPE_OFDPA = 0x1018;
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -070057 private static final int TYPE_ONF = 0x4f4e4600;
Pier Ventreee4a8f22016-10-22 15:45:36 -070058 private static final int SUB_TYPE_PUSH_L2_HEADER = 1;
59 private static final int SUB_TYPE_POP_L2_HEADER = 2;
60 private static final int SUB_TYPE_PUSH_CW = 3;
61 private static final int SUB_TYPE_POP_CW = 4;
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -070062 private static final int SUB_TYPE_COPY_FIELD = 3200;
Jonghwan Hyun360b02f2017-08-11 14:00:07 -070063 private static final String TYPE = "type";
64 private static final String MISSING_MEMBER_MESSAGE = " member is required in Ofdpa3ExtensionTreatmentInterpreter";
65 private static final String MISSING_TREATMENT_MESSAGE = "Extension treatment cannot be null";
66 private static final String NOT_SUPPORTED_MESSAGE = "Driver does not support extension type of ";
67
Pier Ventre6f630052016-10-18 09:58:41 -070068 private final Logger log = LoggerFactory.getLogger(getClass());
69
Charles Chancad338a2016-09-16 18:03:11 -070070 @Override
71 public boolean supported(ExtensionTreatmentType extensionTreatmentType) {
72 if (extensionTreatmentType.equals(
73 ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_MPLS_TYPE.type())) {
74 return true;
Pier Ventre6f630052016-10-18 09:58:41 -070075 } else if (extensionTreatmentType.equals(
76 ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_OVID.type())) {
77 return true;
Pier Ventre9cf536b2016-10-21 13:30:18 -070078 } else if (extensionTreatmentType.equals(
79 ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_MPLS_L2_PORT.type())) {
80 return true;
Pier Ventredb252cc2016-10-21 21:54:26 -070081 } else if (extensionTreatmentType.equals(
82 ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_QOS_INDEX.type())) {
83 return true;
Pier Ventreee4a8f22016-10-22 15:45:36 -070084 } else if (extensionTreatmentType.equals(
85 ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_PUSH_L2_HEADER.type())) {
86 return true;
87 } else if (extensionTreatmentType.equals(
88 ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_PUSH_CW.type())) {
89 return true;
90 } else if (extensionTreatmentType.equals(
91 ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_POP_L2_HEADER.type())) {
92 return true;
93 } else if (extensionTreatmentType.equals(
94 ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_POP_CW.type())) {
95 return true;
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -070096 } else if (extensionTreatmentType.equals(
97 ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_ALLOW_VLAN_TRANSLATION.type())) {
98 return true;
99 } else if (extensionTreatmentType.equals(
100 ExtensionTreatmentType.ExtensionTreatmentTypes.ONF_COPY_FIELD.type())) {
101 return true;
Charles Chancad338a2016-09-16 18:03:11 -0700102 }
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -0700103
Charles Chancad338a2016-09-16 18:03:11 -0700104 return false;
105 }
106
107 @Override
108 public OFAction mapInstruction(OFFactory factory, ExtensionTreatment extensionTreatment) {
109 ExtensionTreatmentType type = extensionTreatment.type();
110 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_MPLS_TYPE.type())) {
111 short mplsType = ((Ofdpa3SetMplsType) extensionTreatment).mplsType();
112 return factory.actions().setField(factory.oxms().ofdpaMplsType(
113 U16.ofRaw(mplsType)));
Pier Ventre6f630052016-10-18 09:58:41 -0700114 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_OVID.type())) {
115 // OFDPA requires isPresent bit set to 1 for OVID.
116 VlanId vlanId = ((Ofdpa3SetOvid) extensionTreatment).vlanId();
117 short mask = (short) 0x1000;
118 short oVid = (short) (mask | vlanId.toShort());
119 return factory.actions().setField(factory.oxms().ofdpaOvid(
120 U16.ofRaw(oVid)));
Pier Ventre9cf536b2016-10-21 13:30:18 -0700121 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_MPLS_L2_PORT.type())) {
122 Integer mplsL2Port = ((Ofdpa3SetMplsL2Port) extensionTreatment).mplsL2Port();
123 /*
124 * 0x0000XXXX UNI Interface.
125 * 0x0002XXXX NNI Interface
126 */
127 if ((mplsL2Port >= 0 && mplsL2Port <= 0x0000FFFF) ||
128 (mplsL2Port >= 0x00020000 && mplsL2Port <= 0x0002FFFF)) {
129 return factory.actions().setField(
130 factory.oxms().ofdpaMplsL2Port(U32.ofRaw(mplsL2Port))
131 );
132 }
133 throw new UnsupportedOperationException(
134 "Unexpected ExtensionTreatment: " + extensionTreatment.toString());
Pier Ventredb252cc2016-10-21 21:54:26 -0700135 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_QOS_INDEX.type())) {
136 Integer qosIndex = ((Ofdpa3SetQosIndex) extensionTreatment).qosIndex();
137 /*
138 * Qos index is a single byte [0...255]
139 */
140 if (qosIndex >= 0 && qosIndex <= 255) {
141 return factory.actions().setField(
142 factory.oxms().ofdpaQosIndex(U8.ofRaw((byte) (qosIndex & 0xFF)))
143 );
144 }
145 throw new UnsupportedOperationException(
146 "Unexpected ExtensionTreatment: " + extensionTreatment.toString());
Pier Ventreee4a8f22016-10-22 15:45:36 -0700147 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_PUSH_L2_HEADER.type())) {
148 return factory.actions().ofdpaPushL2Header();
149 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_PUSH_CW.type())) {
150 return factory.actions().ofdpaPushCw();
151 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_POP_L2_HEADER.type())) {
152 return factory.actions().ofdpaPopL2Header();
153 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_POP_CW.type())) {
154 return factory.actions().ofdpaPopCw();
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -0700155 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_ALLOW_VLAN_TRANSLATION.type())) {
156 byte allow = ((OfdpaSetAllowVlanTranslation) extensionTreatment).getVlanTranslation();
157 return factory.actions().setField(factory.oxms().ofdpaAllowVlanTranslation(
158 U8.ofRaw(allow)));
159 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.ONF_COPY_FIELD.type())) {
160 Ofdpa3CopyField copyField = (Ofdpa3CopyField) extensionTreatment;
161
162 // this action uses the ONF experimenter id thus
163 // we differentiate here, but, we should treat the extensionTreatment
164 // as an ofdpa3 treatment, because it is ofdpa specific.
165 return factory.actions().buildOnfCopyField()
166 .setDstOffset(copyField.getDstOffset())
167 .setSrcOffset(copyField.getSrcOffset())
168 .setNBits(copyField.getnBits())
169 .setSrc(copyField.getSrc())
170 .setDst(copyField.getDst())
171 .build();
Charles Chancad338a2016-09-16 18:03:11 -0700172 }
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -0700173 throw new UnsupportedOperationException(
Charles Chancad338a2016-09-16 18:03:11 -0700174 "Unexpected ExtensionTreatment: " + extensionTreatment.toString());
175 }
176
177 @Override
178 public ExtensionTreatment mapAction(OFAction action) throws UnsupportedOperationException {
179 if (action.getType().equals(OFActionType.SET_FIELD)) {
180 OFActionSetField setFieldAction = (OFActionSetField) action;
181 OFOxm<?> oxm = setFieldAction.getField();
182 switch (oxm.getMatchField().id) {
183 case OFDPA_MPLS_TYPE:
184 OFOxmOfdpaMplsType mplsType = (OFOxmOfdpaMplsType) oxm;
185 return new Ofdpa3SetMplsType(mplsType.getValue().getRaw());
Pier Ventre6f630052016-10-18 09:58:41 -0700186 case OFDPA_OVID:
187 OFOxmOfdpaOvid ovid = ((OFOxmOfdpaOvid) oxm);
188 short mask = (short) 0x0FFF;
189 short oVid = (short) (mask & ovid.getValue().getRaw());
190 VlanId vlanId = VlanId.vlanId(oVid);
191 return new Ofdpa3SetOvid(vlanId);
Pier Ventre9cf536b2016-10-21 13:30:18 -0700192 case OFDPA_MPLS_L2_PORT:
193 OFOxmOfdpaMplsL2Port mplsl2Port = ((OFOxmOfdpaMplsL2Port) oxm);
194 Integer mplsL2Port = mplsl2Port.getValue().getRaw();
195 if ((mplsL2Port >= 0 && mplsL2Port <= 0x0000FFFF) ||
196 (mplsL2Port >= 0x00020000 && mplsL2Port <= 0x0002FFFF)) {
197 return new Ofdpa3SetMplsL2Port(mplsL2Port);
198 }
Pier Ventredb252cc2016-10-21 21:54:26 -0700199 break;
200 case OFDPA_QOS_INDEX:
201 OFOxmOfdpaQosIndex qosindex = ((OFOxmOfdpaQosIndex) oxm);
202 Integer qosIndex = (int) qosindex.getValue().getRaw();
203 if (qosIndex >= 0 && qosIndex <= 255) {
204 return new Ofdpa3SetQosIndex(qosIndex);
205 }
206 break;
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -0700207 case OFDPA_ALLOW_VLAN_TRANSLATION:
208 OFOxmOfdpaAllowVlanTranslation allowVlanTranslation = (OFOxmOfdpaAllowVlanTranslation) oxm;
209 Byte allowVlan = allowVlanTranslation.getValue().getRaw();
210 if ((allowVlan == 0) || (allowVlan == 1)) {
211 return new OfdpaSetAllowVlanTranslation(allowVlan);
212 }
213 break;
Charles Chancad338a2016-09-16 18:03:11 -0700214 default:
215 throw new UnsupportedOperationException(
216 "Driver does not support extension type " + oxm.getMatchField().id);
217 }
Pier Ventreee4a8f22016-10-22 15:45:36 -0700218 } else if (action.getType().equals(OFActionType.EXPERIMENTER)) {
219 OFActionExperimenter experimenter = (OFActionExperimenter) action;
220 if (Long.valueOf(experimenter.getExperimenter()).intValue() == TYPE_OFDPA) {
221 OFActionOfdpa ofdpa = (OFActionOfdpa) experimenter;
222 switch (ofdpa.getExpType()) {
223 case SUB_TYPE_PUSH_L2_HEADER:
224 return new Ofdpa3PushL2Header();
225 case SUB_TYPE_POP_L2_HEADER:
226 return new Ofdpa3PopL2Header();
227 case SUB_TYPE_PUSH_CW:
228 return new Ofdpa3PushCw();
229 case SUB_TYPE_POP_CW:
230 return new Ofdpa3PopCw();
231 default:
232 throw new UnsupportedOperationException(
233 "Unexpected OFAction: " + action.toString());
234 }
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -0700235 } else if (Long.valueOf(experimenter.getExperimenter()).intValue() == TYPE_ONF) {
236 OFActionOnf onf = (OFActionOnf) experimenter;
237 switch (onf.getExpType()) {
238 case SUB_TYPE_COPY_FIELD:
239 return new Ofdpa3CopyField(((OFActionOnfCopyField) onf).getNBits(),
240 ((OFActionOnfCopyField) onf).getSrcOffset(),
241 ((OFActionOnfCopyField) onf).getDstOffset(),
242 (int) ((OFActionOnfCopyField) onf).getSrc(),
243 (int) ((OFActionOnfCopyField) onf).getDst());
244 default:
245 throw new UnsupportedOperationException(
246 "Unexpected OFAction: " + action.toString());
247 }
Pier Ventreee4a8f22016-10-22 15:45:36 -0700248 }
249 throw new UnsupportedOperationException(
250 "Unexpected OFAction: " + action.toString());
Charles Chancad338a2016-09-16 18:03:11 -0700251 }
252 throw new UnsupportedOperationException(
253 "Unexpected OFAction: " + action.toString());
254 }
255
256 @Override
257 public ExtensionTreatment getExtensionInstruction(ExtensionTreatmentType type) {
258 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_MPLS_TYPE.type())) {
259 return new Ofdpa3SetMplsType();
Pier Ventre6f630052016-10-18 09:58:41 -0700260 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_OVID.type())) {
261 return new Ofdpa3SetOvid();
Pier Ventre9cf536b2016-10-21 13:30:18 -0700262 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_MPLS_L2_PORT.type())) {
263 return new Ofdpa3SetMplsL2Port();
Pier Ventredb252cc2016-10-21 21:54:26 -0700264 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_QOS_INDEX.type())) {
265 return new Ofdpa3SetQosIndex();
Pier Ventreee4a8f22016-10-22 15:45:36 -0700266 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_PUSH_L2_HEADER.type())) {
267 return new Ofdpa3PushL2Header();
268 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_PUSH_CW.type())) {
269 return new Ofdpa3PushCw();
270 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_POP_L2_HEADER.type())) {
271 return new Ofdpa3PopL2Header();
272 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_POP_CW.type())) {
273 return new Ofdpa3PopCw();
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -0700274 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_ALLOW_VLAN_TRANSLATION.type())) {
275 return new OfdpaSetAllowVlanTranslation();
276 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.ONF_COPY_FIELD.type())) {
277 return new Ofdpa3CopyField();
Charles Chancad338a2016-09-16 18:03:11 -0700278 }
Jonghwan Hyun360b02f2017-08-11 14:00:07 -0700279 throw new UnsupportedOperationException(NOT_SUPPORTED_MESSAGE + type.toString());
280 }
281
282 @Override
283 public ObjectNode encode(ExtensionTreatment extensionTreatment, CodecContext context) {
284 checkNotNull(extensionTreatment, MISSING_TREATMENT_MESSAGE);
285 ExtensionTreatmentType type = extensionTreatment.type();
286 ObjectNode root = context.mapper().createObjectNode();
287
288 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_MPLS_TYPE.type())) {
289 Ofdpa3SetMplsType setMplsType = (Ofdpa3SetMplsType) extensionTreatment;
290 root.put(TYPE, ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_MPLS_TYPE.name());
291 root.setAll(context.codec(Ofdpa3SetMplsType.class).encode(setMplsType, context));
292 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_OVID.type())) {
293 Ofdpa3SetOvid setOvid = (Ofdpa3SetOvid) extensionTreatment;
294 root.put(TYPE, ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_OVID.name());
295 root.setAll(context.codec(Ofdpa3SetOvid.class).encode(setOvid, context));
296 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_MPLS_L2_PORT.type())) {
297 Ofdpa3SetMplsL2Port setMplsL2Port = (Ofdpa3SetMplsL2Port) extensionTreatment;
298 root.put(TYPE, ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_MPLS_L2_PORT.name());
299 root.setAll(context.codec(Ofdpa3SetMplsL2Port.class).encode(setMplsL2Port, context));
300 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_QOS_INDEX.type())) {
301 Ofdpa3SetQosIndex setQosIndex = (Ofdpa3SetQosIndex) extensionTreatment;
302 root.put(TYPE, ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_QOS_INDEX.name());
303 root.setAll(context.codec(Ofdpa3SetQosIndex.class).encode(setQosIndex, context));
304 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_PUSH_L2_HEADER.type())) {
305 root.put(TYPE, ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_PUSH_L2_HEADER.name());
306 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_PUSH_CW.type())) {
307 root.put(TYPE, ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_PUSH_CW.name());
308 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_POP_L2_HEADER.type())) {
309 root.put(TYPE, ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_POP_L2_HEADER.name());
310 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_POP_CW.type())) {
311 root.put(TYPE, ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_POP_CW.name());
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -0700312 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_ALLOW_VLAN_TRANSLATION.type())) {
313 root.put(TYPE, ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_ALLOW_VLAN_TRANSLATION.name());
314 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.ONF_COPY_FIELD.type())) {
315 root.put(TYPE, ExtensionTreatmentType.ExtensionTreatmentTypes.ONF_COPY_FIELD.name());
Jonghwan Hyun360b02f2017-08-11 14:00:07 -0700316 }
317
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -0700318
Jonghwan Hyun360b02f2017-08-11 14:00:07 -0700319 return root;
320 }
321
322 @Override
323 public ExtensionTreatment decode(ObjectNode json, CodecContext context) {
324 if (json == null || !json.isObject()) {
325 return null;
326 }
327
328 String type = nullIsIllegal(json.get(TYPE), TYPE + MISSING_MEMBER_MESSAGE).asText();
329
330 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_MPLS_TYPE.name())) {
331 return context.codec(Ofdpa3SetMplsType.class).decode(json, context);
332 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_OVID.name())) {
333 return context.codec(Ofdpa3SetOvid.class).decode(json, context);
334 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_MPLS_L2_PORT.name())) {
335 return context.codec(Ofdpa3SetMplsL2Port.class).decode(json, context);
336 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_QOS_INDEX.name())) {
337 return context.codec(Ofdpa3SetQosIndex.class).decode(json, context);
338 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_PUSH_L2_HEADER.name())) {
339 return new Ofdpa3PushL2Header();
340 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_PUSH_CW.name())) {
341 return new Ofdpa3PushCw();
342 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_POP_L2_HEADER.name())) {
343 return new Ofdpa3PopL2Header();
344 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_POP_CW.name())) {
345 return new Ofdpa3PopCw();
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -0700346 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_ALLOW_VLAN_TRANSLATION.name())) {
347 return new OfdpaSetAllowVlanTranslation();
348 } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.ONF_COPY_FIELD.name())) {
349 return new Ofdpa3CopyField();
Jonghwan Hyun360b02f2017-08-11 14:00:07 -0700350 } else {
351 throw new UnsupportedOperationException(NOT_SUPPORTED_MESSAGE + type.toString());
352 }
Charles Chancad338a2016-09-16 18:03:11 -0700353 }
354}