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 | } |
Phaneendra Manda | 0c0f14b | 2015-12-09 20:38:27 +0530 | [diff] [blame] | 139 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) { |
| 140 | NiciraSetNshSpi niciraNshSpi = (NiciraSetNshSpi) extensionTreatment; |
| 141 | return factory.actions().niciraSetNsp(niciraNshSpi.nshSpi().servicePathId()); |
| 142 | } |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 143 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) { |
Phaneendra Manda | 0c0f14b | 2015-12-09 20:38:27 +0530 | [diff] [blame] | 144 | NiciraSetNshSi niciraNshSi = (NiciraSetNshSi) extensionTreatment; |
| 145 | return factory.actions().niciraSetNsp(niciraNshSi.nshSi().serviceIndex()); |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 146 | } |
| 147 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())) { |
Phaneendra Manda | 0c0f14b | 2015-12-09 20:38:27 +0530 | [diff] [blame] | 148 | NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; |
| 149 | return factory.actions().niciraSetNshc1(niciraNshch.nshCh().nshContextHeader()); |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 150 | } |
| 151 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())) { |
Phaneendra Manda | 0c0f14b | 2015-12-09 20:38:27 +0530 | [diff] [blame] | 152 | NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; |
| 153 | return factory.actions().niciraSetNshc2(niciraNshch.nshCh().nshContextHeader()); |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 154 | } |
| 155 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())) { |
Phaneendra Manda | 0c0f14b | 2015-12-09 20:38:27 +0530 | [diff] [blame] | 156 | NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; |
| 157 | return factory.actions().niciraSetNshc3(niciraNshch.nshCh().nshContextHeader()); |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 158 | } |
| 159 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) { |
Phaneendra Manda | 0c0f14b | 2015-12-09 20:38:27 +0530 | [diff] [blame] | 160 | NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; |
| 161 | return factory.actions().niciraSetNshc4(niciraNshch.nshCh().nshContextHeader()); |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 162 | } |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 163 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type()) |
samueljcc | 4a527ed | 2015-12-03 13:59:49 +0800 | [diff] [blame] | 164 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type()) |
| 165 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type()) |
| 166 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) { |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 167 | MoveExtensionTreatment mov = (MoveExtensionTreatment) extensionTreatment; |
| 168 | OFActionNiciraMove.Builder action = factory.actions() |
| 169 | .buildNiciraMove(); |
| 170 | action.setDstOfs(mov.dstOffset()); |
| 171 | action.setSrcOfs(mov.srcOffset()); |
| 172 | action.setNBits(mov.nBits()); |
| 173 | action.setSrc(mov.src()); |
| 174 | action.setDst(mov.dst()); |
| 175 | return action.build(); |
samueljcc | 4a527ed | 2015-12-03 13:59:49 +0800 | [diff] [blame] | 176 | } |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 177 | return null; |
| 178 | } |
| 179 | |
| 180 | @Override |
Jian Li | ffef500 | 2016-04-04 23:27:37 -0700 | [diff] [blame] | 181 | public ExtensionTreatment mapAction(OFAction action) throws UnsupportedOperationException { |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 182 | if (action.getType().equals(OFActionType.SET_FIELD)) { |
| 183 | OFActionSetField setFieldAction = (OFActionSetField) action; |
| 184 | OFOxm<?> oxm = setFieldAction.getField(); |
| 185 | switch (oxm.getMatchField().id) { |
| 186 | case TUNNEL_IPV4_DST: |
| 187 | OFOxmTunnelIpv4Dst tunnelIpv4Dst = (OFOxmTunnelIpv4Dst) oxm; |
| 188 | return new NiciraSetTunnelDst(Ip4Address.valueOf(tunnelIpv4Dst.getValue().getInt())); |
| 189 | default: |
| 190 | throw new UnsupportedOperationException( |
| 191 | "Driver does not support extension type " + oxm.getMatchField().id); |
| 192 | } |
| 193 | } |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 194 | if (action.getType().equals(OFActionType.EXPERIMENTER)) { |
| 195 | OFActionExperimenter experimenter = (OFActionExperimenter) action; |
| 196 | if (Long.valueOf(experimenter.getExperimenter()) |
| 197 | .intValue() == TYPE_NICIRA) { |
| 198 | OFActionNicira nicira = (OFActionNicira) experimenter; |
Jian Li | d416388 | 2016-03-30 20:03:14 -0700 | [diff] [blame] | 199 | switch (nicira.getSubtype()) { |
| 200 | case SUB_TYPE_MOVE: |
| 201 | OFActionNiciraMove moveAction = (OFActionNiciraMove) nicira; |
| 202 | switch (Long.valueOf(moveAction.getSrc()).intValue()) { |
| 203 | case SRC_ARP_SHA: |
| 204 | return NiciraMoveTreatmentFactory |
| 205 | .createNiciraMovArpShaToTha(); |
| 206 | case SRC_ETH: |
| 207 | return NiciraMoveTreatmentFactory |
| 208 | .createNiciraMovEthSrcToDst(); |
| 209 | case SRC_IP: |
| 210 | return NiciraMoveTreatmentFactory |
| 211 | .createNiciraMovIpSrcToDst(); |
| 212 | case SRC_ARP_SPA: |
| 213 | return NiciraMoveTreatmentFactory |
| 214 | .createNiciraMovArpSpaToTpa(); |
| 215 | default: |
| 216 | throw new UnsupportedOperationException("Driver does not support move from " |
| 217 | + moveAction.getSrc() + " to " |
| 218 | + moveAction.getDst()); |
| 219 | } |
| 220 | case SUB_TYPE_RESUBMIT: |
| 221 | OFActionNiciraResubmit resubmitAction = (OFActionNiciraResubmit) nicira; |
| 222 | return new NiciraResubmit(PortNumber.portNumber(resubmitAction.getInPort())); |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 223 | default: |
Jian Li | d416388 | 2016-03-30 20:03:14 -0700 | [diff] [blame] | 224 | throw new UnsupportedOperationException("Driver does not support extension subtype " |
| 225 | + nicira.getSubtype()); |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | } |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 229 | return null; |
| 230 | } |
| 231 | |
| 232 | @Override |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 233 | public ExtensionTreatment getExtensionInstruction(ExtensionTreatmentType type) { |
| 234 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) { |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 235 | return new NiciraSetTunnelDst(); |
| 236 | } |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 237 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) { |
BitOhenry | b53ac6c | 2015-11-16 20:58:58 +0800 | [diff] [blame] | 238 | return new NiciraResubmit(); |
| 239 | } |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 240 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) { |
| 241 | return new NiciraResubmitTable(); |
| 242 | } |
Phaneendra Manda | ce66cbc | 2015-11-26 18:07:48 +0530 | [diff] [blame] | 243 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) { |
| 244 | return new NiciraSetNshSpi(); |
| 245 | } |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 246 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) { |
| 247 | return new NiciraSetNshSi(); |
| 248 | } |
| 249 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type()) |
| 250 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type()) |
| 251 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type()) |
| 252 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) { |
| 253 | return new NiciraSetNshContextHeader(type); |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 254 | } |
samueljcc | 4a527ed | 2015-12-03 13:59:49 +0800 | [diff] [blame] | 255 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type())) { |
| 256 | return NiciraMoveTreatmentFactory.createNiciraMovArpShaToTha(); |
| 257 | } |
| 258 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type())) { |
| 259 | return NiciraMoveTreatmentFactory.createNiciraMovArpSpaToTpa(); |
| 260 | } |
| 261 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type())) { |
| 262 | return NiciraMoveTreatmentFactory.createNiciraMovEthSrcToDst(); |
| 263 | } |
| 264 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) { |
| 265 | return NiciraMoveTreatmentFactory.createNiciraMovIpSrcToDst(); |
| 266 | } |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 267 | throw new UnsupportedOperationException( |
| 268 | "Driver does not support extension type " + type.toString()); |
| 269 | } |
Jian Li | dab7256 | 2016-04-12 14:10:32 -0700 | [diff] [blame] | 270 | |
| 271 | @Override |
| 272 | public ObjectNode encode(ExtensionTreatment extensionTreatment, CodecContext context) { |
| 273 | checkNotNull(extensionTreatment, "Extension treatment cannot be null"); |
| 274 | ExtensionTreatmentType type = extensionTreatment.type(); |
| 275 | ObjectNode root = context.mapper().createObjectNode(); |
| 276 | |
| 277 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) { |
| 278 | NiciraSetTunnelDst tunnelDst = (NiciraSetTunnelDst) extensionTreatment; |
| 279 | root.set(TUNNEL_DST, context.codec(NiciraSetTunnelDst.class).encode(tunnelDst, context)); |
| 280 | } |
| 281 | |
| 282 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) { |
| 283 | NiciraResubmit resubmit = (NiciraResubmit) extensionTreatment; |
| 284 | root.set(RESUBMIT, context.codec(NiciraResubmit.class).encode(resubmit, context)); |
| 285 | } |
| 286 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) { |
| 287 | NiciraResubmitTable resubmitTable = (NiciraResubmitTable) extensionTreatment; |
| 288 | root.set(RESUBMIT_TABLE, context.codec(NiciraResubmitTable.class).encode(resubmitTable, context)); |
| 289 | } |
| 290 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) { |
| 291 | NiciraSetNshSpi niciraNshSpi = (NiciraSetNshSpi) extensionTreatment; |
| 292 | root.set(NICIRA_NSH_SPI, context.codec(NiciraSetNshSpi.class).encode(niciraNshSpi, context)); |
| 293 | } |
| 294 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) { |
| 295 | NiciraSetNshSi niciraNshSi = (NiciraSetNshSi) extensionTreatment; |
| 296 | root.set(NICIRA_NSH_SI, context.codec(NiciraSetNshSi.class).encode(niciraNshSi, context)); |
| 297 | } |
| 298 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())) { |
| 299 | NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; |
| 300 | root.set(NICIRA_NSH_CH, context.codec(NiciraSetNshContextHeader.class).encode(niciraNshch, context)); |
| 301 | } |
| 302 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())) { |
| 303 | NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; |
| 304 | root.set(NICIRA_NSH_CH, context.codec(NiciraSetNshContextHeader.class).encode(niciraNshch, context)); |
| 305 | } |
| 306 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())) { |
| 307 | NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; |
| 308 | root.set(NICIRA_NSH_CH, context.codec(NiciraSetNshContextHeader.class).encode(niciraNshch, context)); |
| 309 | } |
| 310 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) { |
| 311 | NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; |
| 312 | root.set(NICIRA_NSH_CH, context.codec(NiciraSetNshContextHeader.class).encode(niciraNshch, context)); |
| 313 | } |
| 314 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type()) |
| 315 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type()) |
| 316 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type()) |
| 317 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) { |
| 318 | MoveExtensionTreatment mov = (MoveExtensionTreatment) extensionTreatment; |
| 319 | root.set(NICIRA_MOVE, context.codec(MoveExtensionTreatment.class).encode(mov, context)); |
| 320 | } |
| 321 | |
| 322 | return root; |
| 323 | } |
| 324 | |
| 325 | @Override |
| 326 | public ExtensionTreatment decode(ObjectNode json, CodecContext context) { |
| 327 | if (json == null || !json.isObject()) { |
| 328 | return null; |
| 329 | } |
| 330 | |
| 331 | // parse extension type |
| 332 | int typeInt = nullIsIllegal(json.get(TYPE), TYPE + MISSING_MEMBER_MESSAGE).asInt(); |
| 333 | ExtensionTreatmentType type = new ExtensionTreatmentType(typeInt); |
| 334 | |
| 335 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) { |
| 336 | return context.codec(NiciraSetTunnelDst.class).decode(json, context); |
| 337 | } |
| 338 | |
| 339 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) { |
| 340 | return context.codec(NiciraResubmit.class).decode(json, context); |
| 341 | } |
| 342 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) { |
| 343 | return context.codec(NiciraResubmitTable.class).decode(json, context); |
| 344 | } |
| 345 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) { |
| 346 | return context.codec(NiciraSetNshSpi.class).decode(json, context); |
| 347 | } |
| 348 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) { |
| 349 | return context.codec(NiciraSetNshSi.class).decode(json, context); |
| 350 | } |
| 351 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())) { |
| 352 | return context.codec(NiciraSetNshContextHeader.class).decode(json, context); |
| 353 | } |
| 354 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())) { |
| 355 | return context.codec(NiciraSetNshContextHeader.class).decode(json, context); |
| 356 | } |
| 357 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())) { |
| 358 | return context.codec(NiciraSetNshContextHeader.class).decode(json, context); |
| 359 | } |
| 360 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) { |
| 361 | return context.codec(NiciraSetNshContextHeader.class).decode(json, context); |
| 362 | } |
| 363 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type()) |
| 364 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type()) |
| 365 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type()) |
| 366 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) { |
| 367 | return context.codec(MoveExtensionTreatment.class).decode(json, context); |
| 368 | } |
| 369 | throw new UnsupportedOperationException( |
| 370 | "Driver does not support extension type " + type.toString()); |
| 371 | } |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 372 | } |