Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.driver.extensions; |
| 18 | |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 19 | import static com.google.common.base.Preconditions.checkNotNull; |
| 20 | import static org.onlab.util.Tools.nullIsIllegal; |
| 21 | |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 22 | import org.onlab.packet.Ip4Address; |
Jian Li | dab7256 | 2016-04-12 14:10:32 -0700 | [diff] [blame] | 23 | import org.onosproject.codec.CodecContext; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 24 | import org.onosproject.net.NshContextHeader; |
| 25 | import org.onosproject.net.NshServiceIndex; |
| 26 | import org.onosproject.net.NshServicePathId; |
Jian Li | d416388 | 2016-03-30 20:03:14 -0700 | [diff] [blame] | 27 | import org.onosproject.net.PortNumber; |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 28 | import org.onosproject.net.behaviour.ExtensionTreatmentResolver; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 29 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 30 | import org.onosproject.net.flow.instructions.ExtensionTreatment; |
| 31 | import org.onosproject.net.flow.instructions.ExtensionTreatmentType; |
| 32 | import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 33 | import org.projectfloodlight.openflow.protocol.OFActionType; |
| 34 | import org.projectfloodlight.openflow.protocol.OFFactory; |
| 35 | import org.projectfloodlight.openflow.protocol.action.OFAction; |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 36 | import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter; |
| 37 | import org.projectfloodlight.openflow.protocol.action.OFActionNicira; |
| 38 | import org.projectfloodlight.openflow.protocol.action.OFActionNiciraMove; |
Jian Li | d416388 | 2016-03-30 20:03:14 -0700 | [diff] [blame] | 39 | import org.projectfloodlight.openflow.protocol.action.OFActionNiciraResubmit; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 40 | import org.projectfloodlight.openflow.protocol.action.OFActionNiciraResubmitTable; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 41 | import org.projectfloodlight.openflow.protocol.action.OFActionSetField; |
| 42 | import org.projectfloodlight.openflow.protocol.oxm.OFOxm; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 43 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmEncapEthDst; |
| 44 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmEncapEthSrc; |
| 45 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmEncapEthType; |
| 46 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmNshC1; |
| 47 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmNshC2; |
| 48 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmNshC3; |
| 49 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmNshC4; |
| 50 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmNshMdtype; |
| 51 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmNshNp; |
| 52 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmNsi; |
| 53 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmNsp; |
| 54 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmTunGpeNp; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 55 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmTunnelIpv4Dst; |
| 56 | import org.projectfloodlight.openflow.types.IPv4Address; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 57 | import org.projectfloodlight.openflow.types.MacAddress; |
| 58 | import org.projectfloodlight.openflow.types.U16; |
| 59 | import org.projectfloodlight.openflow.types.U32; |
| 60 | import org.projectfloodlight.openflow.types.U8; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 61 | |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 62 | import com.fasterxml.jackson.databind.node.ObjectNode; |
Jian Li | dab7256 | 2016-04-12 14:10:32 -0700 | [diff] [blame] | 63 | |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 64 | /** |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 65 | * Interpreter for Nicira OpenFlow treatment extensions. |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 66 | */ |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 67 | public class NiciraExtensionTreatmentInterpreter extends AbstractHandlerBehaviour |
| 68 | implements ExtensionTreatmentInterpreter, ExtensionTreatmentResolver { |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 69 | |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 70 | private static final int TYPE_NICIRA = 0x2320; |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 71 | 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 Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 76 | 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 Li | d416388 | 2016-03-30 20:03:14 -0700 | [diff] [blame] | 83 | private static final int SUB_TYPE_RESUBMIT = 1; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 84 | private static final int SUB_TYPE_RESUBMIT_TABLE = 14; |
Jian Li | d416388 | 2016-03-30 20:03:14 -0700 | [diff] [blame] | 85 | private static final int SUB_TYPE_MOVE = 6; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 86 | private static final int SUB_TYPE_PUSH_NSH = 38; |
| 87 | private static final int SUB_TYPE_POP_NSH = 39; |
Jian Li | d416388 | 2016-03-30 20:03:14 -0700 | [diff] [blame] | 88 | |
Jian Li | dab7256 | 2016-04-12 14:10:32 -0700 | [diff] [blame] | 89 | 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 Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 101 | @Override |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 102 | public boolean supported(ExtensionTreatmentType extensionTreatmentType) { |
| 103 | if (extensionTreatmentType.equals( |
| 104 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) { |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 105 | return true; |
| 106 | } |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 107 | if (extensionTreatmentType.equals( |
| 108 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) { |
BitOhenry | b53ac6c | 2015-11-16 20:58:58 +0800 | [diff] [blame] | 109 | return true; |
| 110 | } |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 111 | 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 Manda | ce66cbc | 2015-11-26 18:07:48 +0530 | [diff] [blame] | 127 | return true; |
| 128 | } |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 129 | if (extensionTreatmentType.equals( |
| 130 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) { |
| 131 | return true; |
| 132 | } |
samueljcc | 4a527ed | 2015-12-03 13:59:49 +0800 | [diff] [blame] | 133 | 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 Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 149 | 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 Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 202 | return false; |
| 203 | } |
| 204 | |
| 205 | @Override |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 206 | 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 Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 210 | return factory.actions().setField(factory.oxms().tunnelIpv4Dst( |
| 211 | IPv4Address.of(tunnelDst.tunnelDst().toInt()))); |
| 212 | } |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 213 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) { |
BitOhenry | 5e2233a | 2015-12-08 09:26:38 +0800 | [diff] [blame] | 214 | NiciraResubmit resubmit = (NiciraResubmit) extensionTreatment; |
| 215 | return factory.actions().niciraResubmit((int) resubmit.inPort().toLong(), |
| 216 | resubmit.table()); |
BitOhenry | b53ac6c | 2015-11-16 20:58:58 +0800 | [diff] [blame] | 217 | } |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 218 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) { |
BitOhenry | 5e2233a | 2015-12-08 09:26:38 +0800 | [diff] [blame] | 219 | NiciraResubmitTable resubmitTable = (NiciraResubmitTable) extensionTreatment; |
| 220 | return factory.actions().niciraResubmitTable((int) resubmitTable.inPort().toLong(), |
| 221 | resubmitTable.table()); |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 222 | } |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 223 | |
| 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 | } |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 280 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type()) |
samueljcc | 4a527ed | 2015-12-03 13:59:49 +0800 | [diff] [blame] | 281 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type()) |
| 282 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type()) |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 283 | || 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())) { |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 292 | 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(); |
samueljcc | 4a527ed | 2015-12-03 13:59:49 +0800 | [diff] [blame] | 301 | } |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 302 | return null; |
| 303 | } |
| 304 | |
| 305 | @Override |
Jian Li | ffef500 | 2016-04-04 23:27:37 -0700 | [diff] [blame] | 306 | public ExtensionTreatment mapAction(OFAction action) throws UnsupportedOperationException { |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 307 | 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 Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 314 | 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 Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 358 | default: |
| 359 | throw new UnsupportedOperationException( |
| 360 | "Driver does not support extension type " + oxm.getMatchField().id); |
| 361 | } |
| 362 | } |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 363 | 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 Li | d416388 | 2016-03-30 20:03:14 -0700 | [diff] [blame] | 368 | 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 Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 384 | 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 Li | d416388 | 2016-03-30 20:03:14 -0700 | [diff] [blame] | 399 | default: |
| 400 | throw new UnsupportedOperationException("Driver does not support move from " |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 401 | + moveAction.getSrc() + " to " + moveAction.getDst() + "of length " |
| 402 | + moveAction.getNBits()); |
Jian Li | d416388 | 2016-03-30 20:03:14 -0700 | [diff] [blame] | 403 | } |
| 404 | case SUB_TYPE_RESUBMIT: |
| 405 | OFActionNiciraResubmit resubmitAction = (OFActionNiciraResubmit) nicira; |
| 406 | return new NiciraResubmit(PortNumber.portNumber(resubmitAction.getInPort())); |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 407 | 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()); |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 415 | default: |
Jian Li | d416388 | 2016-03-30 20:03:14 -0700 | [diff] [blame] | 416 | throw new UnsupportedOperationException("Driver does not support extension subtype " |
| 417 | + nicira.getSubtype()); |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 418 | } |
| 419 | } |
| 420 | } |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 421 | return null; |
| 422 | } |
| 423 | |
| 424 | @Override |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 425 | public ExtensionTreatment getExtensionInstruction(ExtensionTreatmentType type) { |
| 426 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) { |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 427 | return new NiciraSetTunnelDst(); |
| 428 | } |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 429 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) { |
BitOhenry | b53ac6c | 2015-11-16 20:58:58 +0800 | [diff] [blame] | 430 | return new NiciraResubmit(); |
| 431 | } |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 432 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) { |
| 433 | return new NiciraResubmitTable(); |
| 434 | } |
Phaneendra Manda | ce66cbc | 2015-11-26 18:07:48 +0530 | [diff] [blame] | 435 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) { |
| 436 | return new NiciraSetNshSpi(); |
| 437 | } |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 438 | 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); |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 446 | } |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 447 | 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 | } |
samueljcc | 4a527ed | 2015-12-03 13:59:49 +0800 | [diff] [blame] | 468 | 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 Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 480 | 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 Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 506 | } |
Jian Li | dab7256 | 2016-04-12 14:10:32 -0700 | [diff] [blame] | 507 | |
| 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 Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 609 | } |