blob: 3a0778e38c5fedb060d621bf4aaa22dcecb730d9 [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
Phaneendra Manda8db7d092016-06-04 00:17:24 +053019import static com.google.common.base.Preconditions.checkNotNull;
20import static org.onlab.util.Tools.nullIsIllegal;
21
Jonathan Hart3c259162015-10-21 21:31:19 -070022import org.onlab.packet.Ip4Address;
Jian Lidab72562016-04-12 14:10:32 -070023import org.onosproject.codec.CodecContext;
Phaneendra Manda8db7d092016-06-04 00:17:24 +053024import org.onosproject.net.NshContextHeader;
25import org.onosproject.net.NshServiceIndex;
26import org.onosproject.net.NshServicePathId;
Jian Lid4163882016-03-30 20:03:14 -070027import org.onosproject.net.PortNumber;
alshabib880b6442015-11-23 22:13:04 -080028import org.onosproject.net.behaviour.ExtensionTreatmentResolver;
Jonathan Hart3c259162015-10-21 21:31:19 -070029import org.onosproject.net.driver.AbstractHandlerBehaviour;
alshabib880b6442015-11-23 22:13:04 -080030import org.onosproject.net.flow.instructions.ExtensionTreatment;
31import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
32import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter;
Jonathan Hart3c259162015-10-21 21:31:19 -070033import org.projectfloodlight.openflow.protocol.OFActionType;
34import org.projectfloodlight.openflow.protocol.OFFactory;
35import org.projectfloodlight.openflow.protocol.action.OFAction;
samueljcc4f4d25a2015-12-07 10:52:28 +080036import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter;
37import org.projectfloodlight.openflow.protocol.action.OFActionNicira;
38import org.projectfloodlight.openflow.protocol.action.OFActionNiciraMove;
Jian Lid4163882016-03-30 20:03:14 -070039import org.projectfloodlight.openflow.protocol.action.OFActionNiciraResubmit;
Phaneendra Manda8db7d092016-06-04 00:17:24 +053040import org.projectfloodlight.openflow.protocol.action.OFActionNiciraResubmitTable;
Jonathan Hart3c259162015-10-21 21:31:19 -070041import org.projectfloodlight.openflow.protocol.action.OFActionSetField;
42import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
Phaneendra Manda8db7d092016-06-04 00:17:24 +053043import org.projectfloodlight.openflow.protocol.oxm.OFOxmEncapEthDst;
44import org.projectfloodlight.openflow.protocol.oxm.OFOxmEncapEthSrc;
45import org.projectfloodlight.openflow.protocol.oxm.OFOxmEncapEthType;
46import org.projectfloodlight.openflow.protocol.oxm.OFOxmNshC1;
47import org.projectfloodlight.openflow.protocol.oxm.OFOxmNshC2;
48import org.projectfloodlight.openflow.protocol.oxm.OFOxmNshC3;
49import org.projectfloodlight.openflow.protocol.oxm.OFOxmNshC4;
50import org.projectfloodlight.openflow.protocol.oxm.OFOxmNshMdtype;
51import org.projectfloodlight.openflow.protocol.oxm.OFOxmNshNp;
52import org.projectfloodlight.openflow.protocol.oxm.OFOxmNsi;
53import org.projectfloodlight.openflow.protocol.oxm.OFOxmNsp;
54import org.projectfloodlight.openflow.protocol.oxm.OFOxmTunGpeNp;
Jonathan Hart3c259162015-10-21 21:31:19 -070055import org.projectfloodlight.openflow.protocol.oxm.OFOxmTunnelIpv4Dst;
56import org.projectfloodlight.openflow.types.IPv4Address;
Phaneendra Manda8db7d092016-06-04 00:17:24 +053057import org.projectfloodlight.openflow.types.MacAddress;
58import org.projectfloodlight.openflow.types.U16;
59import org.projectfloodlight.openflow.types.U32;
60import org.projectfloodlight.openflow.types.U8;
Jonathan Hart3c259162015-10-21 21:31:19 -070061
Phaneendra Manda8db7d092016-06-04 00:17:24 +053062import com.fasterxml.jackson.databind.node.ObjectNode;
Jian Lidab72562016-04-12 14:10:32 -070063
Jonathan Hart3c259162015-10-21 21:31:19 -070064/**
Jonathan Hart26a8d952015-12-02 15:16:35 -080065 * Interpreter for Nicira OpenFlow treatment extensions.
Jonathan Hart3c259162015-10-21 21:31:19 -070066 */
alshabib880b6442015-11-23 22:13:04 -080067public class NiciraExtensionTreatmentInterpreter extends AbstractHandlerBehaviour
68 implements ExtensionTreatmentInterpreter, ExtensionTreatmentResolver {
Jonathan Hart3c259162015-10-21 21:31:19 -070069
samueljcc4f4d25a2015-12-07 10:52:28 +080070 private static final int TYPE_NICIRA = 0x2320;
samueljcc4f4d25a2015-12-07 10:52:28 +080071 private static final int SRC_ARP_SHA = 0x00012206;
72 private static final int SRC_ARP_SPA = 0x00002004;
73 private static final int SRC_ETH = 0x00000406;
74 private static final int SRC_IP = 0x00000e04;
75
Phaneendra Manda8db7d092016-06-04 00:17:24 +053076 private static final int NSH_C1 = 0x0001e604;
77 private static final int NSH_C2 = 0x0001e804;
78 private static final int NSH_C3 = 0x0001ea04;
79 private static final int NSH_C4 = 0x0001ec04;
80 private static final int TUN_IPV4_DST = 0x00014004;
81 private static final int TUN_ID = 0x12008;
82
Jian Lid4163882016-03-30 20:03:14 -070083 private static final int SUB_TYPE_RESUBMIT = 1;
Phaneendra Manda8db7d092016-06-04 00:17:24 +053084 private static final int SUB_TYPE_RESUBMIT_TABLE = 14;
Jian Lid4163882016-03-30 20:03:14 -070085 private static final int SUB_TYPE_MOVE = 6;
Phaneendra Manda8db7d092016-06-04 00:17:24 +053086 private static final int SUB_TYPE_PUSH_NSH = 38;
87 private static final int SUB_TYPE_POP_NSH = 39;
Jian Lid4163882016-03-30 20:03:14 -070088
Jian Lidab72562016-04-12 14:10:32 -070089 private static final String TUNNEL_DST = "tunnelDst";
90 private static final String RESUBMIT = "resubmit";
91 private static final String RESUBMIT_TABLE = "resubmitTable";
92 private static final String NICIRA_NSH_SPI = "niciraNshSpi";
93 private static final String NICIRA_NSH_SI = "niciraNshSi";
94 private static final String NICIRA_NSH_CH = "niciraNshCh";
95 private static final String NICIRA_MOVE = "niciraMove";
96
97 private static final String TYPE = "type";
98
99 private static final String MISSING_MEMBER_MESSAGE = " member is required in NiciraExtensionTreatmentInterpreter";
100
Jonathan Hart3c259162015-10-21 21:31:19 -0700101 @Override
alshabib880b6442015-11-23 22:13:04 -0800102 public boolean supported(ExtensionTreatmentType extensionTreatmentType) {
103 if (extensionTreatmentType.equals(
104 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) {
Jonathan Hart3c259162015-10-21 21:31:19 -0700105 return true;
106 }
alshabib880b6442015-11-23 22:13:04 -0800107 if (extensionTreatmentType.equals(
108 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) {
BitOhenryb53ac6c2015-11-16 20:58:58 +0800109 return true;
110 }
Phaneendra Mandaab5a7362015-12-02 01:10:01 +0530111 if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) {
112 return true;
113 }
114 if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) {
115 return true;
116 }
117 if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())) {
118 return true;
119 }
120 if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())) {
121 return true;
122 }
123 if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())) {
124 return true;
125 }
126 if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) {
Phaneendra Mandace66cbc2015-11-26 18:07:48 +0530127 return true;
128 }
BitOhenry74dd7e12015-12-01 09:07:19 +0800129 if (extensionTreatmentType.equals(
130 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) {
131 return true;
132 }
samueljcc4a527ed2015-12-03 13:59:49 +0800133 if (extensionTreatmentType.equals(
134 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type())) {
135 return true;
136 }
137 if (extensionTreatmentType.equals(
138 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type())) {
139 return true;
140 }
141 if (extensionTreatmentType.equals(
142 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type())) {
143 return true;
144 }
145 if (extensionTreatmentType.equals(
146 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) {
147 return true;
148 }
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530149 if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_NSH_MDTYPE.type())) {
150 return true;
151 }
152 if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_NSH_NP.type())) {
153 return true;
154 }
155 if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_ENCAP_ETH_SRC.type())) {
156 return true;
157 }
158 if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_ENCAP_ETH_DST.type())) {
159 return true;
160 }
161 if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_ENCAP_ETH_TYPE
162 .type())) {
163 return true;
164 }
165 if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_PUSH_NSH.type())) {
166 return true;
167 }
168 if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_POP_NSH.type())) {
169 return true;
170 }
171 if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_TUN_GPE_NP.type())) {
172 return true;
173 }
174 if (extensionTreatmentType
175 .equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C1_TO_C1.type())) {
176 return true;
177 }
178 if (extensionTreatmentType
179 .equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C2_TO_C2.type())) {
180 return true;
181 }
182 if (extensionTreatmentType
183 .equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C3_TO_C3.type())) {
184 return true;
185 }
186 if (extensionTreatmentType
187 .equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C4_TO_C4.type())) {
188 return true;
189 }
190 if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes
191 .NICIRA_MOV_TUN_IPV4_DST_TO_TUN_IPV4_DST.type())) {
192 return true;
193 }
194 if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_TUN_ID_TO_TUN_ID
195 .type())) {
196 return true;
197 }
198 if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C2_TO_TUN_ID
199 .type())) {
200 return true;
201 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700202 return false;
203 }
204
205 @Override
alshabib880b6442015-11-23 22:13:04 -0800206 public OFAction mapInstruction(OFFactory factory, ExtensionTreatment extensionTreatment) {
207 ExtensionTreatmentType type = extensionTreatment.type();
208 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) {
209 NiciraSetTunnelDst tunnelDst = (NiciraSetTunnelDst) extensionTreatment;
Jonathan Hart3c259162015-10-21 21:31:19 -0700210 return factory.actions().setField(factory.oxms().tunnelIpv4Dst(
211 IPv4Address.of(tunnelDst.tunnelDst().toInt())));
212 }
alshabib880b6442015-11-23 22:13:04 -0800213 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) {
BitOhenry5e2233a2015-12-08 09:26:38 +0800214 NiciraResubmit resubmit = (NiciraResubmit) extensionTreatment;
215 return factory.actions().niciraResubmit((int) resubmit.inPort().toLong(),
216 resubmit.table());
BitOhenryb53ac6c2015-11-16 20:58:58 +0800217 }
BitOhenry74dd7e12015-12-01 09:07:19 +0800218 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) {
BitOhenry5e2233a2015-12-08 09:26:38 +0800219 NiciraResubmitTable resubmitTable = (NiciraResubmitTable) extensionTreatment;
220 return factory.actions().niciraResubmitTable((int) resubmitTable.inPort().toLong(),
221 resubmitTable.table());
Phaneendra Mandaab5a7362015-12-02 01:10:01 +0530222 }
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530223
224 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) {
225 NiciraSetNshSpi niciraNshSpi = (NiciraSetNshSpi) extensionTreatment;
226 return factory.actions().setField(factory.oxms().nsp(U32.of(niciraNshSpi.nshSpi().servicePathId())));
227 }
228 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) {
229 NiciraSetNshSi niciraNshSi = (NiciraSetNshSi) extensionTreatment;
230 return factory.actions().setField(factory.oxms().nsi(U8.of(niciraNshSi.nshSi().serviceIndex())));
231 }
232 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())) {
233 NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment;
234 return factory.actions().setField(factory.oxms().nshC1(U32.of(niciraNshch.nshCh().nshContextHeader())));
235 }
236 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())) {
237 NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment;
238 return factory.actions().setField(factory.oxms().nshC2(U32.of(niciraNshch.nshCh().nshContextHeader())));
239 }
240 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())) {
241 NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment;
242 return factory.actions().setField(factory.oxms().nshC3(U32.of(niciraNshch.nshCh().nshContextHeader())));
243 }
244 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) {
245 NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment;
246 return factory.actions().setField(factory.oxms().nshC4(U32.of(niciraNshch.nshCh().nshContextHeader())));
247 }
248 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_NSH_MDTYPE.type())) {
249 NiciraNshMdType niciraNshMdType = (NiciraNshMdType) extensionTreatment;
250 return factory.actions().setField(factory.oxms().nshMdtype(U8.of(niciraNshMdType.nshMdType())));
251 }
252 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_NSH_NP.type())) {
253 NiciraNshNp niciraNshNp = (NiciraNshNp) extensionTreatment;
254 return factory.actions().setField(factory.oxms().nshNp(U8.of(niciraNshNp.nshNp())));
255 }
256 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_ENCAP_ETH_SRC.type())) {
257 NiciraEncapEthSrc niciraEncapEthSrc = (NiciraEncapEthSrc) extensionTreatment;
258 return factory.actions().setField(factory.oxms().encapEthSrc(MacAddress.of(niciraEncapEthSrc.encapEthSrc()
259 .toBytes())));
260 }
261 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_ENCAP_ETH_DST.type())) {
262 NiciraEncapEthDst niciraEncapEthDst = (NiciraEncapEthDst) extensionTreatment;
263 return factory.actions().setField(factory.oxms().encapEthDst(MacAddress.of(niciraEncapEthDst.encapEthDst()
264 .toBytes())));
265 }
266 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_ENCAP_ETH_TYPE.type())) {
267 NiciraEncapEthType niciraEncapEthType = (NiciraEncapEthType) extensionTreatment;
268 return factory.actions().setField(factory.oxms().encapEthType(U16.of(niciraEncapEthType.encapEthType())));
269 }
270 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_PUSH_NSH.type())) {
271 return factory.actions().niciraPushNsh();
272 }
273 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_POP_NSH.type())) {
274 return factory.actions().niciraPopNsh();
275 }
276 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_TUN_GPE_NP.type())) {
277 NiciraTunGpeNp niciraTunGpeNp = (NiciraTunGpeNp) extensionTreatment;
278 return factory.actions().setField(factory.oxms().tunGpeNp(U8.of(niciraTunGpeNp.tunGpeNp())));
279 }
samueljcc4f4d25a2015-12-07 10:52:28 +0800280 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type())
samueljcc4a527ed2015-12-03 13:59:49 +0800281 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type())
282 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type())
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530283 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())
284 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C1_TO_C1.type())
285 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C2_TO_C2.type())
286 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C3_TO_C3.type())
287 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C4_TO_C4.type())
288 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_TUN_IPV4_DST_TO_TUN_IPV4_DST
289 .type())
290 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_TUN_ID_TO_TUN_ID.type())
291 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C2_TO_TUN_ID.type())) {
samueljcc4f4d25a2015-12-07 10:52:28 +0800292 MoveExtensionTreatment mov = (MoveExtensionTreatment) extensionTreatment;
293 OFActionNiciraMove.Builder action = factory.actions()
294 .buildNiciraMove();
295 action.setDstOfs(mov.dstOffset());
296 action.setSrcOfs(mov.srcOffset());
297 action.setNBits(mov.nBits());
298 action.setSrc(mov.src());
299 action.setDst(mov.dst());
300 return action.build();
samueljcc4a527ed2015-12-03 13:59:49 +0800301 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700302 return null;
303 }
304
305 @Override
Jian Liffef5002016-04-04 23:27:37 -0700306 public ExtensionTreatment mapAction(OFAction action) throws UnsupportedOperationException {
Jonathan Hart3c259162015-10-21 21:31:19 -0700307 if (action.getType().equals(OFActionType.SET_FIELD)) {
308 OFActionSetField setFieldAction = (OFActionSetField) action;
309 OFOxm<?> oxm = setFieldAction.getField();
310 switch (oxm.getMatchField().id) {
311 case TUNNEL_IPV4_DST:
312 OFOxmTunnelIpv4Dst tunnelIpv4Dst = (OFOxmTunnelIpv4Dst) oxm;
313 return new NiciraSetTunnelDst(Ip4Address.valueOf(tunnelIpv4Dst.getValue().getInt()));
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530314 case NSP:
315 OFOxmNsp nsp = (OFOxmNsp) oxm;
316 return new NiciraSetNshSpi(NshServicePathId.of((nsp.getValue().getRaw())));
317 case NSI:
318 OFOxmNsi nsi = (OFOxmNsi) oxm;
319 return new NiciraSetNshSi(NshServiceIndex.of((nsi.getValue().getRaw())));
320 case NSH_C1:
321 OFOxmNshC1 nshC1 = (OFOxmNshC1) oxm;
322 return new NiciraSetNshContextHeader(NshContextHeader.of((nshC1.getValue().getRaw())),
323 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1
324 .type());
325 case NSH_C2:
326 OFOxmNshC2 nshC2 = (OFOxmNshC2) oxm;
327 return new NiciraSetNshContextHeader(NshContextHeader.of((nshC2.getValue().getRaw())),
328 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2
329 .type());
330 case NSH_C3:
331 OFOxmNshC3 nshC3 = (OFOxmNshC3) oxm;
332 return new NiciraSetNshContextHeader(NshContextHeader.of((nshC3.getValue().getRaw())),
333 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3
334 .type());
335 case NSH_C4:
336 OFOxmNshC4 nshC4 = (OFOxmNshC4) oxm;
337 return new NiciraSetNshContextHeader(NshContextHeader.of((nshC4.getValue().getRaw())),
338 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4
339 .type());
340 case NSH_MDTYPE:
341 OFOxmNshMdtype nshMdType = (OFOxmNshMdtype) oxm;
342 return new NiciraNshMdType((nshMdType.getValue().getRaw()));
343 case NSH_NP:
344 OFOxmNshNp nshNp = (OFOxmNshNp) oxm;
345 return new NiciraNshNp((nshNp.getValue().getRaw()));
346 case ENCAP_ETH_SRC:
347 OFOxmEncapEthSrc encapEthSrc = (OFOxmEncapEthSrc) oxm;
348 return new NiciraEncapEthSrc(org.onlab.packet.MacAddress.valueOf((encapEthSrc.getValue().getBytes())));
349 case ENCAP_ETH_DST:
350 OFOxmEncapEthDst encapEthDst = (OFOxmEncapEthDst) oxm;
351 return new NiciraEncapEthDst(org.onlab.packet.MacAddress.valueOf((encapEthDst.getValue().getBytes())));
352 case ENCAP_ETH_TYPE:
353 OFOxmEncapEthType encapEthType = (OFOxmEncapEthType) oxm;
354 return new NiciraEncapEthType((encapEthType.getValue().getRaw()));
355 case TUN_GPE_NP:
356 OFOxmTunGpeNp tunGpeNp = (OFOxmTunGpeNp) oxm;
357 return new NiciraTunGpeNp((tunGpeNp.getValue().getRaw()));
Jonathan Hart3c259162015-10-21 21:31:19 -0700358 default:
359 throw new UnsupportedOperationException(
360 "Driver does not support extension type " + oxm.getMatchField().id);
361 }
362 }
samueljcc4f4d25a2015-12-07 10:52:28 +0800363 if (action.getType().equals(OFActionType.EXPERIMENTER)) {
364 OFActionExperimenter experimenter = (OFActionExperimenter) action;
365 if (Long.valueOf(experimenter.getExperimenter())
366 .intValue() == TYPE_NICIRA) {
367 OFActionNicira nicira = (OFActionNicira) experimenter;
Jian Lid4163882016-03-30 20:03:14 -0700368 switch (nicira.getSubtype()) {
369 case SUB_TYPE_MOVE:
370 OFActionNiciraMove moveAction = (OFActionNiciraMove) nicira;
371 switch (Long.valueOf(moveAction.getSrc()).intValue()) {
372 case SRC_ARP_SHA:
373 return NiciraMoveTreatmentFactory
374 .createNiciraMovArpShaToTha();
375 case SRC_ETH:
376 return NiciraMoveTreatmentFactory
377 .createNiciraMovEthSrcToDst();
378 case SRC_IP:
379 return NiciraMoveTreatmentFactory
380 .createNiciraMovIpSrcToDst();
381 case SRC_ARP_SPA:
382 return NiciraMoveTreatmentFactory
383 .createNiciraMovArpSpaToTpa();
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530384 case NSH_C1:
385 return NiciraMoveTreatmentFactory.createNiciraMovNshC1ToC1();
386 case NSH_C2:
387 if (Long.valueOf(moveAction.getDst()).intValue() == TUN_ID) {
388 return NiciraMoveTreatmentFactory.createNiciraMovNshC2ToTunId();
389 }
390 return NiciraMoveTreatmentFactory.createNiciraMovNshC2ToC2();
391 case NSH_C3:
392 return NiciraMoveTreatmentFactory.createNiciraMovNshC3ToC3();
393 case NSH_C4:
394 return NiciraMoveTreatmentFactory.createNiciraMovNshC4ToC4();
395 case TUN_IPV4_DST:
396 return NiciraMoveTreatmentFactory.createNiciraMovTunDstToTunDst();
397 case TUN_ID:
398 return NiciraMoveTreatmentFactory.createNiciraMovTunIdToTunId();
Jian Lid4163882016-03-30 20:03:14 -0700399 default:
400 throw new UnsupportedOperationException("Driver does not support move from "
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530401 + moveAction.getSrc() + " to " + moveAction.getDst() + "of length "
402 + moveAction.getNBits());
Jian Lid4163882016-03-30 20:03:14 -0700403 }
404 case SUB_TYPE_RESUBMIT:
405 OFActionNiciraResubmit resubmitAction = (OFActionNiciraResubmit) nicira;
406 return new NiciraResubmit(PortNumber.portNumber(resubmitAction.getInPort()));
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530407 case SUB_TYPE_PUSH_NSH:
408 return new NiciraPushNsh();
409 case SUB_TYPE_POP_NSH:
410 return new NiciraPopNsh();
411 case SUB_TYPE_RESUBMIT_TABLE:
412 OFActionNiciraResubmitTable resubmitTable = (OFActionNiciraResubmitTable) nicira;
413 return new NiciraResubmitTable(PortNumber.portNumber(resubmitTable.getInPort()),
414 resubmitTable.getTable());
samueljcc4f4d25a2015-12-07 10:52:28 +0800415 default:
Jian Lid4163882016-03-30 20:03:14 -0700416 throw new UnsupportedOperationException("Driver does not support extension subtype "
417 + nicira.getSubtype());
samueljcc4f4d25a2015-12-07 10:52:28 +0800418 }
419 }
420 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700421 return null;
422 }
423
424 @Override
alshabib880b6442015-11-23 22:13:04 -0800425 public ExtensionTreatment getExtensionInstruction(ExtensionTreatmentType type) {
426 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) {
Jonathan Hart3c259162015-10-21 21:31:19 -0700427 return new NiciraSetTunnelDst();
428 }
alshabib880b6442015-11-23 22:13:04 -0800429 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) {
BitOhenryb53ac6c2015-11-16 20:58:58 +0800430 return new NiciraResubmit();
431 }
Phaneendra Mandaab5a7362015-12-02 01:10:01 +0530432 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) {
433 return new NiciraResubmitTable();
434 }
Phaneendra Mandace66cbc2015-11-26 18:07:48 +0530435 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) {
436 return new NiciraSetNshSpi();
437 }
Phaneendra Mandaab5a7362015-12-02 01:10:01 +0530438 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) {
439 return new NiciraSetNshSi();
440 }
441 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())
442 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())
443 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())
444 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) {
445 return new NiciraSetNshContextHeader(type);
BitOhenry74dd7e12015-12-01 09:07:19 +0800446 }
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530447 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_PUSH_NSH.type())) {
448 return new NiciraPushNsh();
449 }
450 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_POP_NSH.type())) {
451 return new NiciraPopNsh();
452 }
453 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_NSH_MDTYPE.type())) {
454 return new NiciraNshMdType();
455 }
456 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_NSH_NP.type())) {
457 return new NiciraNshNp();
458 }
459 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_ENCAP_ETH_SRC.type())) {
460 return new NiciraEncapEthSrc();
461 }
462 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_ENCAP_ETH_DST.type())) {
463 return new NiciraEncapEthDst();
464 }
465 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_ENCAP_ETH_TYPE.type())) {
466 return new NiciraEncapEthType();
467 }
samueljcc4a527ed2015-12-03 13:59:49 +0800468 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type())) {
469 return NiciraMoveTreatmentFactory.createNiciraMovArpShaToTha();
470 }
471 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type())) {
472 return NiciraMoveTreatmentFactory.createNiciraMovArpSpaToTpa();
473 }
474 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type())) {
475 return NiciraMoveTreatmentFactory.createNiciraMovEthSrcToDst();
476 }
477 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) {
478 return NiciraMoveTreatmentFactory.createNiciraMovIpSrcToDst();
479 }
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530480 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_TUN_GPE_NP.type())) {
481 return new NiciraTunGpeNp();
482 }
483 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C1_TO_C1.type())) {
484 return NiciraMoveTreatmentFactory.createNiciraMovNshC1ToC1();
485 }
486 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C2_TO_C2.type())) {
487 return NiciraMoveTreatmentFactory.createNiciraMovNshC2ToC2();
488 }
489 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C3_TO_C3.type())) {
490 return NiciraMoveTreatmentFactory.createNiciraMovNshC3ToC3();
491 }
492 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C4_TO_C4.type())) {
493 return NiciraMoveTreatmentFactory.createNiciraMovNshC4ToC4();
494 }
495 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_TUN_IPV4_DST_TO_TUN_IPV4_DST
496 .type())) {
497 return NiciraMoveTreatmentFactory.createNiciraMovTunDstToTunDst();
498 }
499 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_TUN_ID_TO_TUN_ID.type())) {
500 return NiciraMoveTreatmentFactory.createNiciraMovTunIdToTunId();
501 }
502 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C2_TO_TUN_ID.type())) {
503 return NiciraMoveTreatmentFactory.createNiciraMovNshC2ToTunId();
504 }
505 throw new UnsupportedOperationException("Driver does not support extension type " + type.toString());
Jonathan Hart3c259162015-10-21 21:31:19 -0700506 }
Jian Lidab72562016-04-12 14:10:32 -0700507
508 @Override
509 public ObjectNode encode(ExtensionTreatment extensionTreatment, CodecContext context) {
510 checkNotNull(extensionTreatment, "Extension treatment cannot be null");
511 ExtensionTreatmentType type = extensionTreatment.type();
512 ObjectNode root = context.mapper().createObjectNode();
513
514 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) {
515 NiciraSetTunnelDst tunnelDst = (NiciraSetTunnelDst) extensionTreatment;
516 root.set(TUNNEL_DST, context.codec(NiciraSetTunnelDst.class).encode(tunnelDst, context));
517 }
518
519 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) {
520 NiciraResubmit resubmit = (NiciraResubmit) extensionTreatment;
521 root.set(RESUBMIT, context.codec(NiciraResubmit.class).encode(resubmit, context));
522 }
523 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) {
524 NiciraResubmitTable resubmitTable = (NiciraResubmitTable) extensionTreatment;
525 root.set(RESUBMIT_TABLE, context.codec(NiciraResubmitTable.class).encode(resubmitTable, context));
526 }
527 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) {
528 NiciraSetNshSpi niciraNshSpi = (NiciraSetNshSpi) extensionTreatment;
529 root.set(NICIRA_NSH_SPI, context.codec(NiciraSetNshSpi.class).encode(niciraNshSpi, context));
530 }
531 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) {
532 NiciraSetNshSi niciraNshSi = (NiciraSetNshSi) extensionTreatment;
533 root.set(NICIRA_NSH_SI, context.codec(NiciraSetNshSi.class).encode(niciraNshSi, context));
534 }
535 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())) {
536 NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment;
537 root.set(NICIRA_NSH_CH, context.codec(NiciraSetNshContextHeader.class).encode(niciraNshch, context));
538 }
539 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())) {
540 NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment;
541 root.set(NICIRA_NSH_CH, context.codec(NiciraSetNshContextHeader.class).encode(niciraNshch, context));
542 }
543 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())) {
544 NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment;
545 root.set(NICIRA_NSH_CH, context.codec(NiciraSetNshContextHeader.class).encode(niciraNshch, context));
546 }
547 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) {
548 NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment;
549 root.set(NICIRA_NSH_CH, context.codec(NiciraSetNshContextHeader.class).encode(niciraNshch, context));
550 }
551 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type())
552 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type())
553 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type())
554 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) {
555 MoveExtensionTreatment mov = (MoveExtensionTreatment) extensionTreatment;
556 root.set(NICIRA_MOVE, context.codec(MoveExtensionTreatment.class).encode(mov, context));
557 }
558
559 return root;
560 }
561
562 @Override
563 public ExtensionTreatment decode(ObjectNode json, CodecContext context) {
564 if (json == null || !json.isObject()) {
565 return null;
566 }
567
568 // parse extension type
569 int typeInt = nullIsIllegal(json.get(TYPE), TYPE + MISSING_MEMBER_MESSAGE).asInt();
570 ExtensionTreatmentType type = new ExtensionTreatmentType(typeInt);
571
572 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) {
573 return context.codec(NiciraSetTunnelDst.class).decode(json, context);
574 }
575
576 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) {
577 return context.codec(NiciraResubmit.class).decode(json, context);
578 }
579 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) {
580 return context.codec(NiciraResubmitTable.class).decode(json, context);
581 }
582 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) {
583 return context.codec(NiciraSetNshSpi.class).decode(json, context);
584 }
585 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) {
586 return context.codec(NiciraSetNshSi.class).decode(json, context);
587 }
588 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())) {
589 return context.codec(NiciraSetNshContextHeader.class).decode(json, context);
590 }
591 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())) {
592 return context.codec(NiciraSetNshContextHeader.class).decode(json, context);
593 }
594 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())) {
595 return context.codec(NiciraSetNshContextHeader.class).decode(json, context);
596 }
597 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) {
598 return context.codec(NiciraSetNshContextHeader.class).decode(json, context);
599 }
600 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type())
601 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type())
602 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type())
603 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) {
604 return context.codec(MoveExtensionTreatment.class).decode(json, context);
605 }
606 throw new UnsupportedOperationException(
607 "Driver does not support extension type " + type.toString());
608 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700609}