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 | |
Jian Li | dab7256 | 2016-04-12 14:10:32 -0700 | [diff] [blame] | 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 20 | import org.onlab.packet.Ip4Address; |
Jian Li | dab7256 | 2016-04-12 14:10:32 -0700 | [diff] [blame] | 21 | import org.onosproject.codec.CodecContext; |
Jian Li | d416388 | 2016-03-30 20:03:14 -0700 | [diff] [blame] | 22 | import org.onosproject.net.PortNumber; |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 23 | import org.onosproject.net.behaviour.ExtensionTreatmentResolver; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 24 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 25 | import org.onosproject.net.flow.instructions.ExtensionTreatment; |
| 26 | import org.onosproject.net.flow.instructions.ExtensionTreatmentType; |
| 27 | import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 28 | import org.projectfloodlight.openflow.protocol.OFActionType; |
| 29 | import org.projectfloodlight.openflow.protocol.OFFactory; |
| 30 | import org.projectfloodlight.openflow.protocol.action.OFAction; |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 31 | import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter; |
| 32 | import org.projectfloodlight.openflow.protocol.action.OFActionNicira; |
| 33 | import org.projectfloodlight.openflow.protocol.action.OFActionNiciraMove; |
Jian Li | d416388 | 2016-03-30 20:03:14 -0700 | [diff] [blame] | 34 | import org.projectfloodlight.openflow.protocol.action.OFActionNiciraResubmit; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 35 | import org.projectfloodlight.openflow.protocol.action.OFActionSetField; |
| 36 | import org.projectfloodlight.openflow.protocol.oxm.OFOxm; |
| 37 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmTunnelIpv4Dst; |
| 38 | import org.projectfloodlight.openflow.types.IPv4Address; |
| 39 | |
Jian Li | dab7256 | 2016-04-12 14:10:32 -0700 | [diff] [blame] | 40 | import static com.google.common.base.Preconditions.checkNotNull; |
| 41 | import static org.onlab.util.Tools.nullIsIllegal; |
| 42 | |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 43 | /** |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 44 | * Interpreter for Nicira OpenFlow treatment extensions. |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 45 | */ |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 46 | public class NiciraExtensionTreatmentInterpreter extends AbstractHandlerBehaviour |
| 47 | implements ExtensionTreatmentInterpreter, ExtensionTreatmentResolver { |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 48 | |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 49 | private static final int TYPE_NICIRA = 0x2320; |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 50 | 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 Li | d416388 | 2016-03-30 20:03:14 -0700 | [diff] [blame] | 55 | private static final int SUB_TYPE_RESUBMIT = 1; |
| 56 | private static final int SUB_TYPE_MOVE = 6; |
| 57 | |
Jian Li | dab7256 | 2016-04-12 14:10:32 -0700 | [diff] [blame] | 58 | 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 Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 70 | @Override |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 71 | public boolean supported(ExtensionTreatmentType extensionTreatmentType) { |
| 72 | if (extensionTreatmentType.equals( |
| 73 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) { |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 74 | return true; |
| 75 | } |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 76 | if (extensionTreatmentType.equals( |
| 77 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) { |
BitOhenry | b53ac6c | 2015-11-16 20:58:58 +0800 | [diff] [blame] | 78 | return true; |
| 79 | } |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 80 | 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 Manda | ce66cbc | 2015-11-26 18:07:48 +0530 | [diff] [blame] | 96 | return true; |
| 97 | } |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 98 | if (extensionTreatmentType.equals( |
| 99 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) { |
| 100 | return true; |
| 101 | } |
samueljcc | 4a527ed | 2015-12-03 13:59:49 +0800 | [diff] [blame] | 102 | 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 Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 118 | return false; |
| 119 | } |
| 120 | |
| 121 | @Override |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 122 | 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 Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 126 | return factory.actions().setField(factory.oxms().tunnelIpv4Dst( |
| 127 | IPv4Address.of(tunnelDst.tunnelDst().toInt()))); |
| 128 | } |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 129 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) { |
BitOhenry | 5e2233a | 2015-12-08 09:26:38 +0800 | [diff] [blame] | 130 | NiciraResubmit resubmit = (NiciraResubmit) extensionTreatment; |
| 131 | return factory.actions().niciraResubmit((int) resubmit.inPort().toLong(), |
| 132 | resubmit.table()); |
BitOhenry | b53ac6c | 2015-11-16 20:58:58 +0800 | [diff] [blame] | 133 | } |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 134 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) { |
BitOhenry | 5e2233a | 2015-12-08 09:26:38 +0800 | [diff] [blame] | 135 | NiciraResubmitTable resubmitTable = (NiciraResubmitTable) extensionTreatment; |
| 136 | return factory.actions().niciraResubmitTable((int) resubmitTable.inPort().toLong(), |
| 137 | resubmitTable.table()); |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 138 | } |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 139 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type()) |
samueljcc | 4a527ed | 2015-12-03 13:59:49 +0800 | [diff] [blame] | 140 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type()) |
| 141 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type()) |
| 142 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) { |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 143 | MoveExtensionTreatment mov = (MoveExtensionTreatment) extensionTreatment; |
| 144 | OFActionNiciraMove.Builder action = factory.actions() |
| 145 | .buildNiciraMove(); |
| 146 | action.setDstOfs(mov.dstOffset()); |
| 147 | action.setSrcOfs(mov.srcOffset()); |
| 148 | action.setNBits(mov.nBits()); |
| 149 | action.setSrc(mov.src()); |
| 150 | action.setDst(mov.dst()); |
| 151 | return action.build(); |
samueljcc | 4a527ed | 2015-12-03 13:59:49 +0800 | [diff] [blame] | 152 | } |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 153 | return null; |
| 154 | } |
| 155 | |
| 156 | @Override |
Jian Li | ffef500 | 2016-04-04 23:27:37 -0700 | [diff] [blame] | 157 | public ExtensionTreatment mapAction(OFAction action) throws UnsupportedOperationException { |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 158 | if (action.getType().equals(OFActionType.SET_FIELD)) { |
| 159 | OFActionSetField setFieldAction = (OFActionSetField) action; |
| 160 | OFOxm<?> oxm = setFieldAction.getField(); |
| 161 | switch (oxm.getMatchField().id) { |
| 162 | case TUNNEL_IPV4_DST: |
| 163 | OFOxmTunnelIpv4Dst tunnelIpv4Dst = (OFOxmTunnelIpv4Dst) oxm; |
| 164 | return new NiciraSetTunnelDst(Ip4Address.valueOf(tunnelIpv4Dst.getValue().getInt())); |
| 165 | default: |
| 166 | throw new UnsupportedOperationException( |
| 167 | "Driver does not support extension type " + oxm.getMatchField().id); |
| 168 | } |
| 169 | } |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 170 | if (action.getType().equals(OFActionType.EXPERIMENTER)) { |
| 171 | OFActionExperimenter experimenter = (OFActionExperimenter) action; |
| 172 | if (Long.valueOf(experimenter.getExperimenter()) |
| 173 | .intValue() == TYPE_NICIRA) { |
| 174 | OFActionNicira nicira = (OFActionNicira) experimenter; |
Jian Li | d416388 | 2016-03-30 20:03:14 -0700 | [diff] [blame] | 175 | switch (nicira.getSubtype()) { |
| 176 | case SUB_TYPE_MOVE: |
| 177 | OFActionNiciraMove moveAction = (OFActionNiciraMove) nicira; |
| 178 | switch (Long.valueOf(moveAction.getSrc()).intValue()) { |
| 179 | case SRC_ARP_SHA: |
| 180 | return NiciraMoveTreatmentFactory |
| 181 | .createNiciraMovArpShaToTha(); |
| 182 | case SRC_ETH: |
| 183 | return NiciraMoveTreatmentFactory |
| 184 | .createNiciraMovEthSrcToDst(); |
| 185 | case SRC_IP: |
| 186 | return NiciraMoveTreatmentFactory |
| 187 | .createNiciraMovIpSrcToDst(); |
| 188 | case SRC_ARP_SPA: |
| 189 | return NiciraMoveTreatmentFactory |
| 190 | .createNiciraMovArpSpaToTpa(); |
| 191 | default: |
| 192 | throw new UnsupportedOperationException("Driver does not support move from " |
| 193 | + moveAction.getSrc() + " to " |
| 194 | + moveAction.getDst()); |
| 195 | } |
| 196 | case SUB_TYPE_RESUBMIT: |
| 197 | OFActionNiciraResubmit resubmitAction = (OFActionNiciraResubmit) nicira; |
| 198 | return new NiciraResubmit(PortNumber.portNumber(resubmitAction.getInPort())); |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 199 | default: |
Jian Li | d416388 | 2016-03-30 20:03:14 -0700 | [diff] [blame] | 200 | throw new UnsupportedOperationException("Driver does not support extension subtype " |
| 201 | + nicira.getSubtype()); |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | } |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 205 | return null; |
| 206 | } |
| 207 | |
| 208 | @Override |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 209 | public ExtensionTreatment getExtensionInstruction(ExtensionTreatmentType type) { |
| 210 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) { |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 211 | return new NiciraSetTunnelDst(); |
| 212 | } |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 213 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) { |
BitOhenry | b53ac6c | 2015-11-16 20:58:58 +0800 | [diff] [blame] | 214 | return new NiciraResubmit(); |
| 215 | } |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 216 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) { |
| 217 | return new NiciraResubmitTable(); |
| 218 | } |
Phaneendra Manda | ce66cbc | 2015-11-26 18:07:48 +0530 | [diff] [blame] | 219 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) { |
| 220 | return new NiciraSetNshSpi(); |
| 221 | } |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 222 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) { |
| 223 | return new NiciraSetNshSi(); |
| 224 | } |
| 225 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type()) |
| 226 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type()) |
| 227 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type()) |
| 228 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) { |
| 229 | return new NiciraSetNshContextHeader(type); |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 230 | } |
samueljcc | 4a527ed | 2015-12-03 13:59:49 +0800 | [diff] [blame] | 231 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type())) { |
| 232 | return NiciraMoveTreatmentFactory.createNiciraMovArpShaToTha(); |
| 233 | } |
| 234 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type())) { |
| 235 | return NiciraMoveTreatmentFactory.createNiciraMovArpSpaToTpa(); |
| 236 | } |
| 237 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type())) { |
| 238 | return NiciraMoveTreatmentFactory.createNiciraMovEthSrcToDst(); |
| 239 | } |
| 240 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) { |
| 241 | return NiciraMoveTreatmentFactory.createNiciraMovIpSrcToDst(); |
| 242 | } |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 243 | throw new UnsupportedOperationException( |
| 244 | "Driver does not support extension type " + type.toString()); |
| 245 | } |
Jian Li | dab7256 | 2016-04-12 14:10:32 -0700 | [diff] [blame] | 246 | |
| 247 | @Override |
| 248 | public ObjectNode encode(ExtensionTreatment extensionTreatment, CodecContext context) { |
| 249 | checkNotNull(extensionTreatment, "Extension treatment cannot be null"); |
| 250 | ExtensionTreatmentType type = extensionTreatment.type(); |
| 251 | ObjectNode root = context.mapper().createObjectNode(); |
| 252 | |
| 253 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) { |
| 254 | NiciraSetTunnelDst tunnelDst = (NiciraSetTunnelDst) extensionTreatment; |
| 255 | root.set(TUNNEL_DST, context.codec(NiciraSetTunnelDst.class).encode(tunnelDst, context)); |
| 256 | } |
| 257 | |
| 258 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) { |
| 259 | NiciraResubmit resubmit = (NiciraResubmit) extensionTreatment; |
| 260 | root.set(RESUBMIT, context.codec(NiciraResubmit.class).encode(resubmit, context)); |
| 261 | } |
| 262 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) { |
| 263 | NiciraResubmitTable resubmitTable = (NiciraResubmitTable) extensionTreatment; |
| 264 | root.set(RESUBMIT_TABLE, context.codec(NiciraResubmitTable.class).encode(resubmitTable, context)); |
| 265 | } |
| 266 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) { |
| 267 | NiciraSetNshSpi niciraNshSpi = (NiciraSetNshSpi) extensionTreatment; |
| 268 | root.set(NICIRA_NSH_SPI, context.codec(NiciraSetNshSpi.class).encode(niciraNshSpi, context)); |
| 269 | } |
| 270 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) { |
| 271 | NiciraSetNshSi niciraNshSi = (NiciraSetNshSi) extensionTreatment; |
| 272 | root.set(NICIRA_NSH_SI, context.codec(NiciraSetNshSi.class).encode(niciraNshSi, context)); |
| 273 | } |
| 274 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())) { |
| 275 | NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; |
| 276 | root.set(NICIRA_NSH_CH, context.codec(NiciraSetNshContextHeader.class).encode(niciraNshch, context)); |
| 277 | } |
| 278 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())) { |
| 279 | NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; |
| 280 | root.set(NICIRA_NSH_CH, context.codec(NiciraSetNshContextHeader.class).encode(niciraNshch, context)); |
| 281 | } |
| 282 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())) { |
| 283 | NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; |
| 284 | root.set(NICIRA_NSH_CH, context.codec(NiciraSetNshContextHeader.class).encode(niciraNshch, context)); |
| 285 | } |
| 286 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) { |
| 287 | NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; |
| 288 | root.set(NICIRA_NSH_CH, context.codec(NiciraSetNshContextHeader.class).encode(niciraNshch, context)); |
| 289 | } |
| 290 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type()) |
| 291 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type()) |
| 292 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type()) |
| 293 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) { |
| 294 | MoveExtensionTreatment mov = (MoveExtensionTreatment) extensionTreatment; |
| 295 | root.set(NICIRA_MOVE, context.codec(MoveExtensionTreatment.class).encode(mov, context)); |
| 296 | } |
| 297 | |
| 298 | return root; |
| 299 | } |
| 300 | |
| 301 | @Override |
| 302 | public ExtensionTreatment decode(ObjectNode json, CodecContext context) { |
| 303 | if (json == null || !json.isObject()) { |
| 304 | return null; |
| 305 | } |
| 306 | |
| 307 | // parse extension type |
| 308 | int typeInt = nullIsIllegal(json.get(TYPE), TYPE + MISSING_MEMBER_MESSAGE).asInt(); |
| 309 | ExtensionTreatmentType type = new ExtensionTreatmentType(typeInt); |
| 310 | |
| 311 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) { |
| 312 | return context.codec(NiciraSetTunnelDst.class).decode(json, context); |
| 313 | } |
| 314 | |
| 315 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) { |
| 316 | return context.codec(NiciraResubmit.class).decode(json, context); |
| 317 | } |
| 318 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) { |
| 319 | return context.codec(NiciraResubmitTable.class).decode(json, context); |
| 320 | } |
| 321 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) { |
| 322 | return context.codec(NiciraSetNshSpi.class).decode(json, context); |
| 323 | } |
| 324 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) { |
| 325 | return context.codec(NiciraSetNshSi.class).decode(json, context); |
| 326 | } |
| 327 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())) { |
| 328 | return context.codec(NiciraSetNshContextHeader.class).decode(json, context); |
| 329 | } |
| 330 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())) { |
| 331 | return context.codec(NiciraSetNshContextHeader.class).decode(json, context); |
| 332 | } |
| 333 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())) { |
| 334 | return context.codec(NiciraSetNshContextHeader.class).decode(json, context); |
| 335 | } |
| 336 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) { |
| 337 | return context.codec(NiciraSetNshContextHeader.class).decode(json, context); |
| 338 | } |
| 339 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type()) |
| 340 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type()) |
| 341 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type()) |
| 342 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) { |
| 343 | return context.codec(MoveExtensionTreatment.class).decode(json, context); |
| 344 | } |
| 345 | throw new UnsupportedOperationException( |
| 346 | "Driver does not support extension type " + type.toString()); |
| 347 | } |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 348 | } |