blob: f30680d710b262099920009ce063ae0bcf7364a8 [file] [log] [blame]
Jonathan Hart3c259162015-10-21 21:31:19 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Jonathan Hart3c259162015-10-21 21:31:19 -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
Jian Lidab72562016-04-12 14:10:32 -070019import com.fasterxml.jackson.databind.node.ObjectNode;
Jonathan Hart3c259162015-10-21 21:31:19 -070020import org.onlab.packet.Ip4Address;
Jian Lidab72562016-04-12 14:10:32 -070021import org.onosproject.codec.CodecContext;
Jian Lid4163882016-03-30 20:03:14 -070022import org.onosproject.net.PortNumber;
alshabib880b6442015-11-23 22:13:04 -080023import org.onosproject.net.behaviour.ExtensionTreatmentResolver;
Jonathan Hart3c259162015-10-21 21:31:19 -070024import org.onosproject.net.driver.AbstractHandlerBehaviour;
alshabib880b6442015-11-23 22:13:04 -080025import org.onosproject.net.flow.instructions.ExtensionTreatment;
26import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
27import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter;
Jonathan Hart3c259162015-10-21 21:31:19 -070028import org.projectfloodlight.openflow.protocol.OFActionType;
29import org.projectfloodlight.openflow.protocol.OFFactory;
30import org.projectfloodlight.openflow.protocol.action.OFAction;
samueljcc4f4d25a2015-12-07 10:52:28 +080031import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter;
32import org.projectfloodlight.openflow.protocol.action.OFActionNicira;
33import org.projectfloodlight.openflow.protocol.action.OFActionNiciraMove;
Jian Lid4163882016-03-30 20:03:14 -070034import org.projectfloodlight.openflow.protocol.action.OFActionNiciraResubmit;
Jonathan Hart3c259162015-10-21 21:31:19 -070035import org.projectfloodlight.openflow.protocol.action.OFActionSetField;
36import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
37import org.projectfloodlight.openflow.protocol.oxm.OFOxmTunnelIpv4Dst;
38import org.projectfloodlight.openflow.types.IPv4Address;
39
Jian Lidab72562016-04-12 14:10:32 -070040import static com.google.common.base.Preconditions.checkNotNull;
41import static org.onlab.util.Tools.nullIsIllegal;
42
Jonathan Hart3c259162015-10-21 21:31:19 -070043/**
Jonathan Hart26a8d952015-12-02 15:16:35 -080044 * Interpreter for Nicira OpenFlow treatment extensions.
Jonathan Hart3c259162015-10-21 21:31:19 -070045 */
alshabib880b6442015-11-23 22:13:04 -080046public class NiciraExtensionTreatmentInterpreter extends AbstractHandlerBehaviour
47 implements ExtensionTreatmentInterpreter, ExtensionTreatmentResolver {
Jonathan Hart3c259162015-10-21 21:31:19 -070048
samueljcc4f4d25a2015-12-07 10:52:28 +080049 private static final int TYPE_NICIRA = 0x2320;
samueljcc4f4d25a2015-12-07 10:52:28 +080050 private static final int SRC_ARP_SHA = 0x00012206;
51 private static final int SRC_ARP_SPA = 0x00002004;
52 private static final int SRC_ETH = 0x00000406;
53 private static final int SRC_IP = 0x00000e04;
54
Jian Lid4163882016-03-30 20:03:14 -070055 private static final int SUB_TYPE_RESUBMIT = 1;
56 private static final int SUB_TYPE_MOVE = 6;
57
Jian Lidab72562016-04-12 14:10:32 -070058 private static final String TUNNEL_DST = "tunnelDst";
59 private static final String RESUBMIT = "resubmit";
60 private static final String RESUBMIT_TABLE = "resubmitTable";
61 private static final String NICIRA_NSH_SPI = "niciraNshSpi";
62 private static final String NICIRA_NSH_SI = "niciraNshSi";
63 private static final String NICIRA_NSH_CH = "niciraNshCh";
64 private static final String NICIRA_MOVE = "niciraMove";
65
66 private static final String TYPE = "type";
67
68 private static final String MISSING_MEMBER_MESSAGE = " member is required in NiciraExtensionTreatmentInterpreter";
69
Jonathan Hart3c259162015-10-21 21:31:19 -070070 @Override
alshabib880b6442015-11-23 22:13:04 -080071 public boolean supported(ExtensionTreatmentType extensionTreatmentType) {
72 if (extensionTreatmentType.equals(
73 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) {
Jonathan Hart3c259162015-10-21 21:31:19 -070074 return true;
75 }
alshabib880b6442015-11-23 22:13:04 -080076 if (extensionTreatmentType.equals(
77 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) {
BitOhenryb53ac6c2015-11-16 20:58:58 +080078 return true;
79 }
Phaneendra Mandaab5a7362015-12-02 01:10:01 +053080 if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) {
81 return true;
82 }
83 if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) {
84 return true;
85 }
86 if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())) {
87 return true;
88 }
89 if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())) {
90 return true;
91 }
92 if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())) {
93 return true;
94 }
95 if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) {
Phaneendra Mandace66cbc2015-11-26 18:07:48 +053096 return true;
97 }
BitOhenry74dd7e12015-12-01 09:07:19 +080098 if (extensionTreatmentType.equals(
99 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) {
100 return true;
101 }
samueljcc4a527ed2015-12-03 13:59:49 +0800102 if (extensionTreatmentType.equals(
103 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type())) {
104 return true;
105 }
106 if (extensionTreatmentType.equals(
107 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type())) {
108 return true;
109 }
110 if (extensionTreatmentType.equals(
111 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type())) {
112 return true;
113 }
114 if (extensionTreatmentType.equals(
115 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) {
116 return true;
117 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700118 return false;
119 }
120
121 @Override
alshabib880b6442015-11-23 22:13:04 -0800122 public OFAction mapInstruction(OFFactory factory, ExtensionTreatment extensionTreatment) {
123 ExtensionTreatmentType type = extensionTreatment.type();
124 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) {
125 NiciraSetTunnelDst tunnelDst = (NiciraSetTunnelDst) extensionTreatment;
Jonathan Hart3c259162015-10-21 21:31:19 -0700126 return factory.actions().setField(factory.oxms().tunnelIpv4Dst(
127 IPv4Address.of(tunnelDst.tunnelDst().toInt())));
128 }
alshabib880b6442015-11-23 22:13:04 -0800129 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) {
BitOhenry5e2233a2015-12-08 09:26:38 +0800130 NiciraResubmit resubmit = (NiciraResubmit) extensionTreatment;
131 return factory.actions().niciraResubmit((int) resubmit.inPort().toLong(),
132 resubmit.table());
BitOhenryb53ac6c2015-11-16 20:58:58 +0800133 }
BitOhenry74dd7e12015-12-01 09:07:19 +0800134 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) {
BitOhenry5e2233a2015-12-08 09:26:38 +0800135 NiciraResubmitTable resubmitTable = (NiciraResubmitTable) extensionTreatment;
136 return factory.actions().niciraResubmitTable((int) resubmitTable.inPort().toLong(),
137 resubmitTable.table());
Phaneendra Mandaab5a7362015-12-02 01:10:01 +0530138 }
Phaneendra Manda0c0f14b2015-12-09 20:38:27 +0530139 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) {
140 NiciraSetNshSpi niciraNshSpi = (NiciraSetNshSpi) extensionTreatment;
141 return factory.actions().niciraSetNsp(niciraNshSpi.nshSpi().servicePathId());
142 }
Phaneendra Mandaab5a7362015-12-02 01:10:01 +0530143 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) {
Phaneendra Manda0c0f14b2015-12-09 20:38:27 +0530144 NiciraSetNshSi niciraNshSi = (NiciraSetNshSi) extensionTreatment;
145 return factory.actions().niciraSetNsp(niciraNshSi.nshSi().serviceIndex());
Phaneendra Mandaab5a7362015-12-02 01:10:01 +0530146 }
147 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())) {
Phaneendra Manda0c0f14b2015-12-09 20:38:27 +0530148 NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment;
149 return factory.actions().niciraSetNshc1(niciraNshch.nshCh().nshContextHeader());
Phaneendra Mandaab5a7362015-12-02 01:10:01 +0530150 }
151 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())) {
Phaneendra Manda0c0f14b2015-12-09 20:38:27 +0530152 NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment;
153 return factory.actions().niciraSetNshc2(niciraNshch.nshCh().nshContextHeader());
Phaneendra Mandaab5a7362015-12-02 01:10:01 +0530154 }
155 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())) {
Phaneendra Manda0c0f14b2015-12-09 20:38:27 +0530156 NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment;
157 return factory.actions().niciraSetNshc3(niciraNshch.nshCh().nshContextHeader());
Phaneendra Mandaab5a7362015-12-02 01:10:01 +0530158 }
159 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) {
Phaneendra Manda0c0f14b2015-12-09 20:38:27 +0530160 NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment;
161 return factory.actions().niciraSetNshc4(niciraNshch.nshCh().nshContextHeader());
Phaneendra Mandaab5a7362015-12-02 01:10:01 +0530162 }
samueljcc4f4d25a2015-12-07 10:52:28 +0800163 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type())
samueljcc4a527ed2015-12-03 13:59:49 +0800164 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type())
165 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type())
166 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) {
samueljcc4f4d25a2015-12-07 10:52:28 +0800167 MoveExtensionTreatment mov = (MoveExtensionTreatment) extensionTreatment;
168 OFActionNiciraMove.Builder action = factory.actions()
169 .buildNiciraMove();
170 action.setDstOfs(mov.dstOffset());
171 action.setSrcOfs(mov.srcOffset());
172 action.setNBits(mov.nBits());
173 action.setSrc(mov.src());
174 action.setDst(mov.dst());
175 return action.build();
samueljcc4a527ed2015-12-03 13:59:49 +0800176 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700177 return null;
178 }
179
180 @Override
Jian Liffef5002016-04-04 23:27:37 -0700181 public ExtensionTreatment mapAction(OFAction action) throws UnsupportedOperationException {
Jonathan Hart3c259162015-10-21 21:31:19 -0700182 if (action.getType().equals(OFActionType.SET_FIELD)) {
183 OFActionSetField setFieldAction = (OFActionSetField) action;
184 OFOxm<?> oxm = setFieldAction.getField();
185 switch (oxm.getMatchField().id) {
186 case TUNNEL_IPV4_DST:
187 OFOxmTunnelIpv4Dst tunnelIpv4Dst = (OFOxmTunnelIpv4Dst) oxm;
188 return new NiciraSetTunnelDst(Ip4Address.valueOf(tunnelIpv4Dst.getValue().getInt()));
189 default:
190 throw new UnsupportedOperationException(
191 "Driver does not support extension type " + oxm.getMatchField().id);
192 }
193 }
samueljcc4f4d25a2015-12-07 10:52:28 +0800194 if (action.getType().equals(OFActionType.EXPERIMENTER)) {
195 OFActionExperimenter experimenter = (OFActionExperimenter) action;
196 if (Long.valueOf(experimenter.getExperimenter())
197 .intValue() == TYPE_NICIRA) {
198 OFActionNicira nicira = (OFActionNicira) experimenter;
Jian Lid4163882016-03-30 20:03:14 -0700199 switch (nicira.getSubtype()) {
200 case SUB_TYPE_MOVE:
201 OFActionNiciraMove moveAction = (OFActionNiciraMove) nicira;
202 switch (Long.valueOf(moveAction.getSrc()).intValue()) {
203 case SRC_ARP_SHA:
204 return NiciraMoveTreatmentFactory
205 .createNiciraMovArpShaToTha();
206 case SRC_ETH:
207 return NiciraMoveTreatmentFactory
208 .createNiciraMovEthSrcToDst();
209 case SRC_IP:
210 return NiciraMoveTreatmentFactory
211 .createNiciraMovIpSrcToDst();
212 case SRC_ARP_SPA:
213 return NiciraMoveTreatmentFactory
214 .createNiciraMovArpSpaToTpa();
215 default:
216 throw new UnsupportedOperationException("Driver does not support move from "
217 + moveAction.getSrc() + " to "
218 + moveAction.getDst());
219 }
220 case SUB_TYPE_RESUBMIT:
221 OFActionNiciraResubmit resubmitAction = (OFActionNiciraResubmit) nicira;
222 return new NiciraResubmit(PortNumber.portNumber(resubmitAction.getInPort()));
samueljcc4f4d25a2015-12-07 10:52:28 +0800223 default:
Jian Lid4163882016-03-30 20:03:14 -0700224 throw new UnsupportedOperationException("Driver does not support extension subtype "
225 + nicira.getSubtype());
samueljcc4f4d25a2015-12-07 10:52:28 +0800226 }
227 }
228 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700229 return null;
230 }
231
232 @Override
alshabib880b6442015-11-23 22:13:04 -0800233 public ExtensionTreatment getExtensionInstruction(ExtensionTreatmentType type) {
234 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) {
Jonathan Hart3c259162015-10-21 21:31:19 -0700235 return new NiciraSetTunnelDst();
236 }
alshabib880b6442015-11-23 22:13:04 -0800237 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) {
BitOhenryb53ac6c2015-11-16 20:58:58 +0800238 return new NiciraResubmit();
239 }
Phaneendra Mandaab5a7362015-12-02 01:10:01 +0530240 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) {
241 return new NiciraResubmitTable();
242 }
Phaneendra Mandace66cbc2015-11-26 18:07:48 +0530243 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) {
244 return new NiciraSetNshSpi();
245 }
Phaneendra Mandaab5a7362015-12-02 01:10:01 +0530246 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) {
247 return new NiciraSetNshSi();
248 }
249 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())
250 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())
251 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())
252 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) {
253 return new NiciraSetNshContextHeader(type);
BitOhenry74dd7e12015-12-01 09:07:19 +0800254 }
samueljcc4a527ed2015-12-03 13:59:49 +0800255 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type())) {
256 return NiciraMoveTreatmentFactory.createNiciraMovArpShaToTha();
257 }
258 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type())) {
259 return NiciraMoveTreatmentFactory.createNiciraMovArpSpaToTpa();
260 }
261 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type())) {
262 return NiciraMoveTreatmentFactory.createNiciraMovEthSrcToDst();
263 }
264 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) {
265 return NiciraMoveTreatmentFactory.createNiciraMovIpSrcToDst();
266 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700267 throw new UnsupportedOperationException(
268 "Driver does not support extension type " + type.toString());
269 }
Jian Lidab72562016-04-12 14:10:32 -0700270
271 @Override
272 public ObjectNode encode(ExtensionTreatment extensionTreatment, CodecContext context) {
273 checkNotNull(extensionTreatment, "Extension treatment cannot be null");
274 ExtensionTreatmentType type = extensionTreatment.type();
275 ObjectNode root = context.mapper().createObjectNode();
276
277 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) {
278 NiciraSetTunnelDst tunnelDst = (NiciraSetTunnelDst) extensionTreatment;
279 root.set(TUNNEL_DST, context.codec(NiciraSetTunnelDst.class).encode(tunnelDst, context));
280 }
281
282 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) {
283 NiciraResubmit resubmit = (NiciraResubmit) extensionTreatment;
284 root.set(RESUBMIT, context.codec(NiciraResubmit.class).encode(resubmit, context));
285 }
286 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) {
287 NiciraResubmitTable resubmitTable = (NiciraResubmitTable) extensionTreatment;
288 root.set(RESUBMIT_TABLE, context.codec(NiciraResubmitTable.class).encode(resubmitTable, context));
289 }
290 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) {
291 NiciraSetNshSpi niciraNshSpi = (NiciraSetNshSpi) extensionTreatment;
292 root.set(NICIRA_NSH_SPI, context.codec(NiciraSetNshSpi.class).encode(niciraNshSpi, context));
293 }
294 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) {
295 NiciraSetNshSi niciraNshSi = (NiciraSetNshSi) extensionTreatment;
296 root.set(NICIRA_NSH_SI, context.codec(NiciraSetNshSi.class).encode(niciraNshSi, context));
297 }
298 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())) {
299 NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment;
300 root.set(NICIRA_NSH_CH, context.codec(NiciraSetNshContextHeader.class).encode(niciraNshch, context));
301 }
302 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())) {
303 NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment;
304 root.set(NICIRA_NSH_CH, context.codec(NiciraSetNshContextHeader.class).encode(niciraNshch, context));
305 }
306 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())) {
307 NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment;
308 root.set(NICIRA_NSH_CH, context.codec(NiciraSetNshContextHeader.class).encode(niciraNshch, context));
309 }
310 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) {
311 NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment;
312 root.set(NICIRA_NSH_CH, context.codec(NiciraSetNshContextHeader.class).encode(niciraNshch, context));
313 }
314 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type())
315 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type())
316 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type())
317 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) {
318 MoveExtensionTreatment mov = (MoveExtensionTreatment) extensionTreatment;
319 root.set(NICIRA_MOVE, context.codec(MoveExtensionTreatment.class).encode(mov, context));
320 }
321
322 return root;
323 }
324
325 @Override
326 public ExtensionTreatment decode(ObjectNode json, CodecContext context) {
327 if (json == null || !json.isObject()) {
328 return null;
329 }
330
331 // parse extension type
332 int typeInt = nullIsIllegal(json.get(TYPE), TYPE + MISSING_MEMBER_MESSAGE).asInt();
333 ExtensionTreatmentType type = new ExtensionTreatmentType(typeInt);
334
335 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) {
336 return context.codec(NiciraSetTunnelDst.class).decode(json, context);
337 }
338
339 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) {
340 return context.codec(NiciraResubmit.class).decode(json, context);
341 }
342 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) {
343 return context.codec(NiciraResubmitTable.class).decode(json, context);
344 }
345 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) {
346 return context.codec(NiciraSetNshSpi.class).decode(json, context);
347 }
348 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) {
349 return context.codec(NiciraSetNshSi.class).decode(json, context);
350 }
351 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())) {
352 return context.codec(NiciraSetNshContextHeader.class).decode(json, context);
353 }
354 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())) {
355 return context.codec(NiciraSetNshContextHeader.class).decode(json, context);
356 }
357 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())) {
358 return context.codec(NiciraSetNshContextHeader.class).decode(json, context);
359 }
360 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) {
361 return context.codec(NiciraSetNshContextHeader.class).decode(json, context);
362 }
363 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type())
364 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type())
365 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type())
366 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) {
367 return context.codec(MoveExtensionTreatment.class).decode(json, context);
368 }
369 throw new UnsupportedOperationException(
370 "Driver does not support extension type " + type.toString());
371 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700372}