Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Charles Chan | cad338a | 2016-09-16 18:03:11 -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 | |
Jonghwan Hyun | 360b02f | 2017-08-11 14:00:07 -0700 | [diff] [blame] | 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 20 | import org.onlab.packet.VlanId; |
Jonghwan Hyun | 360b02f | 2017-08-11 14:00:07 -0700 | [diff] [blame] | 21 | import org.onosproject.codec.CodecContext; |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 22 | import org.onosproject.net.behaviour.ExtensionTreatmentResolver; |
| 23 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
| 24 | import org.onosproject.net.flow.instructions.ExtensionTreatment; |
| 25 | import org.onosproject.net.flow.instructions.ExtensionTreatmentType; |
| 26 | import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter; |
| 27 | import org.projectfloodlight.openflow.protocol.OFActionType; |
| 28 | import org.projectfloodlight.openflow.protocol.OFFactory; |
| 29 | import org.projectfloodlight.openflow.protocol.action.OFAction; |
Pier Ventre | ee4a8f2 | 2016-10-22 15:45:36 -0700 | [diff] [blame] | 30 | import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter; |
| 31 | import org.projectfloodlight.openflow.protocol.action.OFActionOfdpa; |
Andreas Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 32 | import org.projectfloodlight.openflow.protocol.action.OFActionOnf; |
| 33 | import org.projectfloodlight.openflow.protocol.action.OFActionOnfCopyField; |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 34 | import org.projectfloodlight.openflow.protocol.action.OFActionSetField; |
| 35 | import org.projectfloodlight.openflow.protocol.oxm.OFOxm; |
Andreas Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 36 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmOfdpaAllowVlanTranslation; |
Pier Ventre | 9cf536b | 2016-10-21 13:30:18 -0700 | [diff] [blame] | 37 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmOfdpaMplsL2Port; |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 38 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmOfdpaMplsType; |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 39 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmOfdpaOvid; |
Pier Ventre | db252cc | 2016-10-21 21:54:26 -0700 | [diff] [blame] | 40 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmOfdpaQosIndex; |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 41 | import org.projectfloodlight.openflow.types.U16; |
Pier Ventre | 9cf536b | 2016-10-21 13:30:18 -0700 | [diff] [blame] | 42 | import org.projectfloodlight.openflow.types.U32; |
Pier Ventre | db252cc | 2016-10-21 21:54:26 -0700 | [diff] [blame] | 43 | import org.projectfloodlight.openflow.types.U8; |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 44 | import org.slf4j.Logger; |
| 45 | import org.slf4j.LoggerFactory; |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 46 | |
Jonghwan Hyun | 360b02f | 2017-08-11 14:00:07 -0700 | [diff] [blame] | 47 | import static com.google.common.base.Preconditions.checkNotNull; |
| 48 | import static org.onlab.util.Tools.nullIsIllegal; |
| 49 | |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 50 | /** |
| 51 | * Interpreter for OFDPA3 OpenFlow treatment extensions. |
| 52 | */ |
| 53 | public class Ofdpa3ExtensionTreatmentInterpreter extends AbstractHandlerBehaviour |
| 54 | implements ExtensionTreatmentInterpreter, ExtensionTreatmentResolver { |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 55 | |
Pier Ventre | ee4a8f2 | 2016-10-22 15:45:36 -0700 | [diff] [blame] | 56 | private static final int TYPE_OFDPA = 0x1018; |
Andreas Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 57 | private static final int TYPE_ONF = 0x4f4e4600; |
Pier Ventre | ee4a8f2 | 2016-10-22 15:45:36 -0700 | [diff] [blame] | 58 | private static final int SUB_TYPE_PUSH_L2_HEADER = 1; |
| 59 | private static final int SUB_TYPE_POP_L2_HEADER = 2; |
| 60 | private static final int SUB_TYPE_PUSH_CW = 3; |
| 61 | private static final int SUB_TYPE_POP_CW = 4; |
Andreas Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 62 | private static final int SUB_TYPE_COPY_FIELD = 3200; |
Jonghwan Hyun | 360b02f | 2017-08-11 14:00:07 -0700 | [diff] [blame] | 63 | private static final String TYPE = "type"; |
| 64 | private static final String MISSING_MEMBER_MESSAGE = " member is required in Ofdpa3ExtensionTreatmentInterpreter"; |
| 65 | private static final String MISSING_TREATMENT_MESSAGE = "Extension treatment cannot be null"; |
| 66 | private static final String NOT_SUPPORTED_MESSAGE = "Driver does not support extension type of "; |
| 67 | |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 68 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 69 | |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 70 | @Override |
| 71 | public boolean supported(ExtensionTreatmentType extensionTreatmentType) { |
| 72 | if (extensionTreatmentType.equals( |
| 73 | ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_MPLS_TYPE.type())) { |
| 74 | return true; |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 75 | } else if (extensionTreatmentType.equals( |
| 76 | ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_OVID.type())) { |
| 77 | return true; |
Pier Ventre | 9cf536b | 2016-10-21 13:30:18 -0700 | [diff] [blame] | 78 | } else if (extensionTreatmentType.equals( |
| 79 | ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_MPLS_L2_PORT.type())) { |
| 80 | return true; |
Pier Ventre | db252cc | 2016-10-21 21:54:26 -0700 | [diff] [blame] | 81 | } else if (extensionTreatmentType.equals( |
| 82 | ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_QOS_INDEX.type())) { |
| 83 | return true; |
Pier Ventre | ee4a8f2 | 2016-10-22 15:45:36 -0700 | [diff] [blame] | 84 | } else if (extensionTreatmentType.equals( |
| 85 | ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_PUSH_L2_HEADER.type())) { |
| 86 | return true; |
| 87 | } else if (extensionTreatmentType.equals( |
| 88 | ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_PUSH_CW.type())) { |
| 89 | return true; |
| 90 | } else if (extensionTreatmentType.equals( |
| 91 | ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_POP_L2_HEADER.type())) { |
| 92 | return true; |
| 93 | } else if (extensionTreatmentType.equals( |
| 94 | ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_POP_CW.type())) { |
| 95 | return true; |
Andreas Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 96 | } else if (extensionTreatmentType.equals( |
| 97 | ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_ALLOW_VLAN_TRANSLATION.type())) { |
| 98 | return true; |
| 99 | } else if (extensionTreatmentType.equals( |
| 100 | ExtensionTreatmentType.ExtensionTreatmentTypes.ONF_COPY_FIELD.type())) { |
| 101 | return true; |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 102 | } |
Andreas Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 103 | |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 104 | return false; |
| 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public OFAction mapInstruction(OFFactory factory, ExtensionTreatment extensionTreatment) { |
| 109 | ExtensionTreatmentType type = extensionTreatment.type(); |
| 110 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_MPLS_TYPE.type())) { |
| 111 | short mplsType = ((Ofdpa3SetMplsType) extensionTreatment).mplsType(); |
| 112 | return factory.actions().setField(factory.oxms().ofdpaMplsType( |
| 113 | U16.ofRaw(mplsType))); |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 114 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_OVID.type())) { |
| 115 | // OFDPA requires isPresent bit set to 1 for OVID. |
| 116 | VlanId vlanId = ((Ofdpa3SetOvid) extensionTreatment).vlanId(); |
| 117 | short mask = (short) 0x1000; |
| 118 | short oVid = (short) (mask | vlanId.toShort()); |
| 119 | return factory.actions().setField(factory.oxms().ofdpaOvid( |
| 120 | U16.ofRaw(oVid))); |
Pier Ventre | 9cf536b | 2016-10-21 13:30:18 -0700 | [diff] [blame] | 121 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_MPLS_L2_PORT.type())) { |
| 122 | Integer mplsL2Port = ((Ofdpa3SetMplsL2Port) extensionTreatment).mplsL2Port(); |
| 123 | /* |
| 124 | * 0x0000XXXX UNI Interface. |
| 125 | * 0x0002XXXX NNI Interface |
| 126 | */ |
| 127 | if ((mplsL2Port >= 0 && mplsL2Port <= 0x0000FFFF) || |
| 128 | (mplsL2Port >= 0x00020000 && mplsL2Port <= 0x0002FFFF)) { |
| 129 | return factory.actions().setField( |
| 130 | factory.oxms().ofdpaMplsL2Port(U32.ofRaw(mplsL2Port)) |
| 131 | ); |
| 132 | } |
| 133 | throw new UnsupportedOperationException( |
| 134 | "Unexpected ExtensionTreatment: " + extensionTreatment.toString()); |
Pier Ventre | db252cc | 2016-10-21 21:54:26 -0700 | [diff] [blame] | 135 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_QOS_INDEX.type())) { |
| 136 | Integer qosIndex = ((Ofdpa3SetQosIndex) extensionTreatment).qosIndex(); |
| 137 | /* |
| 138 | * Qos index is a single byte [0...255] |
| 139 | */ |
| 140 | if (qosIndex >= 0 && qosIndex <= 255) { |
| 141 | return factory.actions().setField( |
| 142 | factory.oxms().ofdpaQosIndex(U8.ofRaw((byte) (qosIndex & 0xFF))) |
| 143 | ); |
| 144 | } |
| 145 | throw new UnsupportedOperationException( |
| 146 | "Unexpected ExtensionTreatment: " + extensionTreatment.toString()); |
Pier Ventre | ee4a8f2 | 2016-10-22 15:45:36 -0700 | [diff] [blame] | 147 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_PUSH_L2_HEADER.type())) { |
| 148 | return factory.actions().ofdpaPushL2Header(); |
| 149 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_PUSH_CW.type())) { |
| 150 | return factory.actions().ofdpaPushCw(); |
| 151 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_POP_L2_HEADER.type())) { |
| 152 | return factory.actions().ofdpaPopL2Header(); |
| 153 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_POP_CW.type())) { |
| 154 | return factory.actions().ofdpaPopCw(); |
Andreas Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 155 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_ALLOW_VLAN_TRANSLATION.type())) { |
| 156 | byte allow = ((OfdpaSetAllowVlanTranslation) extensionTreatment).getVlanTranslation(); |
| 157 | return factory.actions().setField(factory.oxms().ofdpaAllowVlanTranslation( |
| 158 | U8.ofRaw(allow))); |
| 159 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.ONF_COPY_FIELD.type())) { |
| 160 | Ofdpa3CopyField copyField = (Ofdpa3CopyField) extensionTreatment; |
| 161 | |
| 162 | // this action uses the ONF experimenter id thus |
| 163 | // we differentiate here, but, we should treat the extensionTreatment |
| 164 | // as an ofdpa3 treatment, because it is ofdpa specific. |
| 165 | return factory.actions().buildOnfCopyField() |
| 166 | .setDstOffset(copyField.getDstOffset()) |
| 167 | .setSrcOffset(copyField.getSrcOffset()) |
| 168 | .setNBits(copyField.getnBits()) |
| 169 | .setSrc(copyField.getSrc()) |
| 170 | .setDst(copyField.getDst()) |
| 171 | .build(); |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 172 | } |
Andreas Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 173 | throw new UnsupportedOperationException( |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 174 | "Unexpected ExtensionTreatment: " + extensionTreatment.toString()); |
| 175 | } |
| 176 | |
| 177 | @Override |
| 178 | public ExtensionTreatment mapAction(OFAction action) throws UnsupportedOperationException { |
| 179 | if (action.getType().equals(OFActionType.SET_FIELD)) { |
| 180 | OFActionSetField setFieldAction = (OFActionSetField) action; |
| 181 | OFOxm<?> oxm = setFieldAction.getField(); |
| 182 | switch (oxm.getMatchField().id) { |
| 183 | case OFDPA_MPLS_TYPE: |
| 184 | OFOxmOfdpaMplsType mplsType = (OFOxmOfdpaMplsType) oxm; |
| 185 | return new Ofdpa3SetMplsType(mplsType.getValue().getRaw()); |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 186 | case OFDPA_OVID: |
| 187 | OFOxmOfdpaOvid ovid = ((OFOxmOfdpaOvid) oxm); |
| 188 | short mask = (short) 0x0FFF; |
| 189 | short oVid = (short) (mask & ovid.getValue().getRaw()); |
| 190 | VlanId vlanId = VlanId.vlanId(oVid); |
| 191 | return new Ofdpa3SetOvid(vlanId); |
Pier Ventre | 9cf536b | 2016-10-21 13:30:18 -0700 | [diff] [blame] | 192 | case OFDPA_MPLS_L2_PORT: |
| 193 | OFOxmOfdpaMplsL2Port mplsl2Port = ((OFOxmOfdpaMplsL2Port) oxm); |
| 194 | Integer mplsL2Port = mplsl2Port.getValue().getRaw(); |
| 195 | if ((mplsL2Port >= 0 && mplsL2Port <= 0x0000FFFF) || |
| 196 | (mplsL2Port >= 0x00020000 && mplsL2Port <= 0x0002FFFF)) { |
| 197 | return new Ofdpa3SetMplsL2Port(mplsL2Port); |
| 198 | } |
Pier Ventre | db252cc | 2016-10-21 21:54:26 -0700 | [diff] [blame] | 199 | break; |
| 200 | case OFDPA_QOS_INDEX: |
| 201 | OFOxmOfdpaQosIndex qosindex = ((OFOxmOfdpaQosIndex) oxm); |
| 202 | Integer qosIndex = (int) qosindex.getValue().getRaw(); |
| 203 | if (qosIndex >= 0 && qosIndex <= 255) { |
| 204 | return new Ofdpa3SetQosIndex(qosIndex); |
| 205 | } |
| 206 | break; |
Andreas Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 207 | case OFDPA_ALLOW_VLAN_TRANSLATION: |
| 208 | OFOxmOfdpaAllowVlanTranslation allowVlanTranslation = (OFOxmOfdpaAllowVlanTranslation) oxm; |
| 209 | Byte allowVlan = allowVlanTranslation.getValue().getRaw(); |
| 210 | if ((allowVlan == 0) || (allowVlan == 1)) { |
| 211 | return new OfdpaSetAllowVlanTranslation(allowVlan); |
| 212 | } |
| 213 | break; |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 214 | default: |
| 215 | throw new UnsupportedOperationException( |
| 216 | "Driver does not support extension type " + oxm.getMatchField().id); |
| 217 | } |
Pier Ventre | ee4a8f2 | 2016-10-22 15:45:36 -0700 | [diff] [blame] | 218 | } else if (action.getType().equals(OFActionType.EXPERIMENTER)) { |
| 219 | OFActionExperimenter experimenter = (OFActionExperimenter) action; |
| 220 | if (Long.valueOf(experimenter.getExperimenter()).intValue() == TYPE_OFDPA) { |
| 221 | OFActionOfdpa ofdpa = (OFActionOfdpa) experimenter; |
| 222 | switch (ofdpa.getExpType()) { |
| 223 | case SUB_TYPE_PUSH_L2_HEADER: |
| 224 | return new Ofdpa3PushL2Header(); |
| 225 | case SUB_TYPE_POP_L2_HEADER: |
| 226 | return new Ofdpa3PopL2Header(); |
| 227 | case SUB_TYPE_PUSH_CW: |
| 228 | return new Ofdpa3PushCw(); |
| 229 | case SUB_TYPE_POP_CW: |
| 230 | return new Ofdpa3PopCw(); |
| 231 | default: |
| 232 | throw new UnsupportedOperationException( |
| 233 | "Unexpected OFAction: " + action.toString()); |
| 234 | } |
Andreas Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 235 | } else if (Long.valueOf(experimenter.getExperimenter()).intValue() == TYPE_ONF) { |
| 236 | OFActionOnf onf = (OFActionOnf) experimenter; |
| 237 | switch (onf.getExpType()) { |
| 238 | case SUB_TYPE_COPY_FIELD: |
| 239 | return new Ofdpa3CopyField(((OFActionOnfCopyField) onf).getNBits(), |
| 240 | ((OFActionOnfCopyField) onf).getSrcOffset(), |
| 241 | ((OFActionOnfCopyField) onf).getDstOffset(), |
| 242 | (int) ((OFActionOnfCopyField) onf).getSrc(), |
| 243 | (int) ((OFActionOnfCopyField) onf).getDst()); |
| 244 | default: |
| 245 | throw new UnsupportedOperationException( |
| 246 | "Unexpected OFAction: " + action.toString()); |
| 247 | } |
Pier Ventre | ee4a8f2 | 2016-10-22 15:45:36 -0700 | [diff] [blame] | 248 | } |
| 249 | throw new UnsupportedOperationException( |
| 250 | "Unexpected OFAction: " + action.toString()); |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 251 | } |
| 252 | throw new UnsupportedOperationException( |
| 253 | "Unexpected OFAction: " + action.toString()); |
| 254 | } |
| 255 | |
| 256 | @Override |
| 257 | public ExtensionTreatment getExtensionInstruction(ExtensionTreatmentType type) { |
| 258 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_MPLS_TYPE.type())) { |
| 259 | return new Ofdpa3SetMplsType(); |
Pier Ventre | 6f63005 | 2016-10-18 09:58:41 -0700 | [diff] [blame] | 260 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_OVID.type())) { |
| 261 | return new Ofdpa3SetOvid(); |
Pier Ventre | 9cf536b | 2016-10-21 13:30:18 -0700 | [diff] [blame] | 262 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_MPLS_L2_PORT.type())) { |
| 263 | return new Ofdpa3SetMplsL2Port(); |
Pier Ventre | db252cc | 2016-10-21 21:54:26 -0700 | [diff] [blame] | 264 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_QOS_INDEX.type())) { |
| 265 | return new Ofdpa3SetQosIndex(); |
Pier Ventre | ee4a8f2 | 2016-10-22 15:45:36 -0700 | [diff] [blame] | 266 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_PUSH_L2_HEADER.type())) { |
| 267 | return new Ofdpa3PushL2Header(); |
| 268 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_PUSH_CW.type())) { |
| 269 | return new Ofdpa3PushCw(); |
| 270 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_POP_L2_HEADER.type())) { |
| 271 | return new Ofdpa3PopL2Header(); |
| 272 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_POP_CW.type())) { |
| 273 | return new Ofdpa3PopCw(); |
Andreas Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 274 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_ALLOW_VLAN_TRANSLATION.type())) { |
| 275 | return new OfdpaSetAllowVlanTranslation(); |
| 276 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.ONF_COPY_FIELD.type())) { |
| 277 | return new Ofdpa3CopyField(); |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 278 | } |
Jonghwan Hyun | 360b02f | 2017-08-11 14:00:07 -0700 | [diff] [blame] | 279 | throw new UnsupportedOperationException(NOT_SUPPORTED_MESSAGE + type.toString()); |
| 280 | } |
| 281 | |
| 282 | @Override |
| 283 | public ObjectNode encode(ExtensionTreatment extensionTreatment, CodecContext context) { |
| 284 | checkNotNull(extensionTreatment, MISSING_TREATMENT_MESSAGE); |
| 285 | ExtensionTreatmentType type = extensionTreatment.type(); |
| 286 | ObjectNode root = context.mapper().createObjectNode(); |
| 287 | |
| 288 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_MPLS_TYPE.type())) { |
| 289 | Ofdpa3SetMplsType setMplsType = (Ofdpa3SetMplsType) extensionTreatment; |
| 290 | root.put(TYPE, ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_MPLS_TYPE.name()); |
| 291 | root.setAll(context.codec(Ofdpa3SetMplsType.class).encode(setMplsType, context)); |
| 292 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_OVID.type())) { |
| 293 | Ofdpa3SetOvid setOvid = (Ofdpa3SetOvid) extensionTreatment; |
| 294 | root.put(TYPE, ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_OVID.name()); |
| 295 | root.setAll(context.codec(Ofdpa3SetOvid.class).encode(setOvid, context)); |
| 296 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_MPLS_L2_PORT.type())) { |
| 297 | Ofdpa3SetMplsL2Port setMplsL2Port = (Ofdpa3SetMplsL2Port) extensionTreatment; |
| 298 | root.put(TYPE, ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_MPLS_L2_PORT.name()); |
| 299 | root.setAll(context.codec(Ofdpa3SetMplsL2Port.class).encode(setMplsL2Port, context)); |
| 300 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_QOS_INDEX.type())) { |
| 301 | Ofdpa3SetQosIndex setQosIndex = (Ofdpa3SetQosIndex) extensionTreatment; |
| 302 | root.put(TYPE, ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_QOS_INDEX.name()); |
| 303 | root.setAll(context.codec(Ofdpa3SetQosIndex.class).encode(setQosIndex, context)); |
| 304 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_PUSH_L2_HEADER.type())) { |
| 305 | root.put(TYPE, ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_PUSH_L2_HEADER.name()); |
| 306 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_PUSH_CW.type())) { |
| 307 | root.put(TYPE, ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_PUSH_CW.name()); |
| 308 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_POP_L2_HEADER.type())) { |
| 309 | root.put(TYPE, ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_POP_L2_HEADER.name()); |
| 310 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_POP_CW.type())) { |
| 311 | root.put(TYPE, ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_POP_CW.name()); |
Andreas Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 312 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_ALLOW_VLAN_TRANSLATION.type())) { |
| 313 | root.put(TYPE, ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_ALLOW_VLAN_TRANSLATION.name()); |
| 314 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.ONF_COPY_FIELD.type())) { |
| 315 | root.put(TYPE, ExtensionTreatmentType.ExtensionTreatmentTypes.ONF_COPY_FIELD.name()); |
Jonghwan Hyun | 360b02f | 2017-08-11 14:00:07 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Andreas Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 318 | |
Jonghwan Hyun | 360b02f | 2017-08-11 14:00:07 -0700 | [diff] [blame] | 319 | return root; |
| 320 | } |
| 321 | |
| 322 | @Override |
| 323 | public ExtensionTreatment decode(ObjectNode json, CodecContext context) { |
| 324 | if (json == null || !json.isObject()) { |
| 325 | return null; |
| 326 | } |
| 327 | |
| 328 | String type = nullIsIllegal(json.get(TYPE), TYPE + MISSING_MEMBER_MESSAGE).asText(); |
| 329 | |
| 330 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_MPLS_TYPE.name())) { |
| 331 | return context.codec(Ofdpa3SetMplsType.class).decode(json, context); |
| 332 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_OVID.name())) { |
| 333 | return context.codec(Ofdpa3SetOvid.class).decode(json, context); |
| 334 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_MPLS_L2_PORT.name())) { |
| 335 | return context.codec(Ofdpa3SetMplsL2Port.class).decode(json, context); |
| 336 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_QOS_INDEX.name())) { |
| 337 | return context.codec(Ofdpa3SetQosIndex.class).decode(json, context); |
| 338 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_PUSH_L2_HEADER.name())) { |
| 339 | return new Ofdpa3PushL2Header(); |
| 340 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_PUSH_CW.name())) { |
| 341 | return new Ofdpa3PushCw(); |
| 342 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_POP_L2_HEADER.name())) { |
| 343 | return new Ofdpa3PopL2Header(); |
| 344 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_POP_CW.name())) { |
| 345 | return new Ofdpa3PopCw(); |
Andreas Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 346 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_ALLOW_VLAN_TRANSLATION.name())) { |
| 347 | return new OfdpaSetAllowVlanTranslation(); |
| 348 | } else if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.ONF_COPY_FIELD.name())) { |
| 349 | return new Ofdpa3CopyField(); |
Jonghwan Hyun | 360b02f | 2017-08-11 14:00:07 -0700 | [diff] [blame] | 350 | } else { |
| 351 | throw new UnsupportedOperationException(NOT_SUPPORTED_MESSAGE + type.toString()); |
| 352 | } |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 353 | } |
| 354 | } |