Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
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; |
Frank Wang | 5733c38 | 2017-03-28 10:15:18 +0800 | [diff] [blame] | 21 | import com.google.common.collect.Lists; |
| 22 | import com.google.common.primitives.Bytes; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 23 | import org.onlab.packet.Ip4Address; |
Frank Wang | 5733c38 | 2017-03-28 10:15:18 +0800 | [diff] [blame] | 24 | import org.onlab.packet.IpAddress; |
Jian Li | dab7256 | 2016-04-12 14:10:32 -0700 | [diff] [blame] | 25 | import org.onosproject.codec.CodecContext; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 26 | import org.onosproject.net.NshContextHeader; |
| 27 | import org.onosproject.net.NshServiceIndex; |
| 28 | import org.onosproject.net.NshServicePathId; |
Jian Li | d416388 | 2016-03-30 20:03:14 -0700 | [diff] [blame] | 29 | import org.onosproject.net.PortNumber; |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 30 | import org.onosproject.net.behaviour.ExtensionTreatmentResolver; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 31 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 32 | import org.onosproject.net.flow.instructions.ExtensionTreatment; |
| 33 | import org.onosproject.net.flow.instructions.ExtensionTreatmentType; |
| 34 | import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 35 | import org.projectfloodlight.openflow.protocol.OFActionType; |
| 36 | import org.projectfloodlight.openflow.protocol.OFFactory; |
| 37 | import org.projectfloodlight.openflow.protocol.action.OFAction; |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 38 | import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter; |
| 39 | import org.projectfloodlight.openflow.protocol.action.OFActionNicira; |
Frank Wang | 5733c38 | 2017-03-28 10:15:18 +0800 | [diff] [blame] | 40 | import org.projectfloodlight.openflow.protocol.action.OFActionNiciraCt; |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 41 | import org.projectfloodlight.openflow.protocol.action.OFActionNiciraMove; |
Frank Wang | 5733c38 | 2017-03-28 10:15:18 +0800 | [diff] [blame] | 42 | import org.projectfloodlight.openflow.protocol.action.OFActionNiciraNat; |
Jian Li | d416388 | 2016-03-30 20:03:14 -0700 | [diff] [blame] | 43 | import org.projectfloodlight.openflow.protocol.action.OFActionNiciraResubmit; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 44 | import org.projectfloodlight.openflow.protocol.action.OFActionNiciraResubmitTable; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 45 | import org.projectfloodlight.openflow.protocol.action.OFActionSetField; |
| 46 | import org.projectfloodlight.openflow.protocol.oxm.OFOxm; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 47 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmEncapEthDst; |
| 48 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmEncapEthSrc; |
| 49 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmEncapEthType; |
| 50 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmNshC1; |
| 51 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmNshC2; |
| 52 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmNshC3; |
| 53 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmNshC4; |
| 54 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmNshMdtype; |
| 55 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmNshNp; |
| 56 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmNsi; |
| 57 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmNsp; |
| 58 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmTunGpeNp; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 59 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmTunnelIpv4Dst; |
| 60 | import org.projectfloodlight.openflow.types.IPv4Address; |
Frank Wang | 5733c38 | 2017-03-28 10:15:18 +0800 | [diff] [blame] | 61 | import org.projectfloodlight.openflow.types.IPv6Address; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 62 | import org.projectfloodlight.openflow.types.MacAddress; |
| 63 | import org.projectfloodlight.openflow.types.U16; |
| 64 | import org.projectfloodlight.openflow.types.U32; |
| 65 | import org.projectfloodlight.openflow.types.U8; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 66 | |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 67 | import com.fasterxml.jackson.databind.node.ObjectNode; |
Jian Li | dab7256 | 2016-04-12 14:10:32 -0700 | [diff] [blame] | 68 | |
Frank Wang | 5733c38 | 2017-03-28 10:15:18 +0800 | [diff] [blame] | 69 | import java.util.ArrayList; |
| 70 | import java.util.List; |
| 71 | |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 72 | /** |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 73 | * Interpreter for Nicira OpenFlow treatment extensions. |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 74 | */ |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 75 | public class NiciraExtensionTreatmentInterpreter extends AbstractHandlerBehaviour |
| 76 | implements ExtensionTreatmentInterpreter, ExtensionTreatmentResolver { |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 77 | |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 78 | private static final int TYPE_NICIRA = 0x2320; |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 79 | private static final int SRC_ARP_SHA = 0x00012206; |
| 80 | private static final int SRC_ARP_SPA = 0x00002004; |
| 81 | private static final int SRC_ETH = 0x00000406; |
| 82 | private static final int SRC_IP = 0x00000e04; |
| 83 | |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 84 | private static final int NSH_C1 = 0x0001e604; |
| 85 | private static final int NSH_C2 = 0x0001e804; |
| 86 | private static final int NSH_C3 = 0x0001ea04; |
| 87 | private static final int NSH_C4 = 0x0001ec04; |
| 88 | private static final int TUN_IPV4_DST = 0x00014004; |
| 89 | private static final int TUN_ID = 0x12008; |
| 90 | |
Frank Wang | 5733c38 | 2017-03-28 10:15:18 +0800 | [diff] [blame] | 91 | private static final int NAT_RANGE_IPV4_MIN = 0x01; |
| 92 | private static final int NAT_RANGE_IPV4_MAX = 0x02; |
| 93 | private static final int NAT_RANGE_IPV6_MIN = 0x04; |
| 94 | private static final int NAT_RANGE_IPV6_MAX = 0x08; |
| 95 | private static final int NAT_RANGE_PROTO_MIN = 0x10; |
| 96 | private static final int NAT_RANGE_PROTO_MAX = 0x20; |
| 97 | |
Jian Li | d416388 | 2016-03-30 20:03:14 -0700 | [diff] [blame] | 98 | private static final int SUB_TYPE_RESUBMIT = 1; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 99 | private static final int SUB_TYPE_RESUBMIT_TABLE = 14; |
Jian Li | d416388 | 2016-03-30 20:03:14 -0700 | [diff] [blame] | 100 | private static final int SUB_TYPE_MOVE = 6; |
Frank Wang | 5733c38 | 2017-03-28 10:15:18 +0800 | [diff] [blame] | 101 | private static final int SUB_TYPE_CT = 35; |
| 102 | private static final int SUB_TYPE_NAT = 36; |
| 103 | private static final int SUB_TYPE_CT_CLEAR = 43; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 104 | private static final int SUB_TYPE_PUSH_NSH = 38; |
| 105 | private static final int SUB_TYPE_POP_NSH = 39; |
Jian Li | d416388 | 2016-03-30 20:03:14 -0700 | [diff] [blame] | 106 | |
Jian Li | dab7256 | 2016-04-12 14:10:32 -0700 | [diff] [blame] | 107 | private static final String TUNNEL_DST = "tunnelDst"; |
| 108 | private static final String RESUBMIT = "resubmit"; |
| 109 | private static final String RESUBMIT_TABLE = "resubmitTable"; |
| 110 | private static final String NICIRA_NSH_SPI = "niciraNshSpi"; |
| 111 | private static final String NICIRA_NSH_SI = "niciraNshSi"; |
| 112 | private static final String NICIRA_NSH_CH = "niciraNshCh"; |
| 113 | private static final String NICIRA_MOVE = "niciraMove"; |
| 114 | |
| 115 | private static final String TYPE = "type"; |
| 116 | |
| 117 | private static final String MISSING_MEMBER_MESSAGE = " member is required in NiciraExtensionTreatmentInterpreter"; |
| 118 | |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 119 | @Override |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 120 | public boolean supported(ExtensionTreatmentType extensionTreatmentType) { |
| 121 | if (extensionTreatmentType.equals( |
| 122 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) { |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 123 | return true; |
| 124 | } |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 125 | if (extensionTreatmentType.equals( |
| 126 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) { |
BitOhenry | b53ac6c | 2015-11-16 20:58:58 +0800 | [diff] [blame] | 127 | return true; |
| 128 | } |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 129 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) { |
| 130 | return true; |
| 131 | } |
| 132 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) { |
| 133 | return true; |
| 134 | } |
| 135 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())) { |
| 136 | return true; |
| 137 | } |
| 138 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())) { |
| 139 | return true; |
| 140 | } |
| 141 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())) { |
| 142 | return true; |
| 143 | } |
| 144 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) { |
Phaneendra Manda | ce66cbc | 2015-11-26 18:07:48 +0530 | [diff] [blame] | 145 | return true; |
| 146 | } |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 147 | if (extensionTreatmentType.equals( |
| 148 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) { |
| 149 | return true; |
| 150 | } |
samueljcc | 4a527ed | 2015-12-03 13:59:49 +0800 | [diff] [blame] | 151 | if (extensionTreatmentType.equals( |
| 152 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type())) { |
| 153 | return true; |
| 154 | } |
| 155 | if (extensionTreatmentType.equals( |
| 156 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type())) { |
| 157 | return true; |
| 158 | } |
| 159 | if (extensionTreatmentType.equals( |
| 160 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type())) { |
| 161 | return true; |
| 162 | } |
| 163 | if (extensionTreatmentType.equals( |
| 164 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) { |
| 165 | return true; |
| 166 | } |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 167 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_NSH_MDTYPE.type())) { |
| 168 | return true; |
| 169 | } |
| 170 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_NSH_NP.type())) { |
| 171 | return true; |
| 172 | } |
| 173 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_ENCAP_ETH_SRC.type())) { |
| 174 | return true; |
| 175 | } |
| 176 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_ENCAP_ETH_DST.type())) { |
| 177 | return true; |
| 178 | } |
| 179 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_ENCAP_ETH_TYPE |
| 180 | .type())) { |
| 181 | return true; |
| 182 | } |
| 183 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_PUSH_NSH.type())) { |
| 184 | return true; |
| 185 | } |
| 186 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_POP_NSH.type())) { |
| 187 | return true; |
| 188 | } |
| 189 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_TUN_GPE_NP.type())) { |
| 190 | return true; |
| 191 | } |
| 192 | if (extensionTreatmentType |
| 193 | .equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C1_TO_C1.type())) { |
| 194 | return true; |
| 195 | } |
| 196 | if (extensionTreatmentType |
| 197 | .equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C2_TO_C2.type())) { |
| 198 | return true; |
| 199 | } |
| 200 | if (extensionTreatmentType |
| 201 | .equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C3_TO_C3.type())) { |
| 202 | return true; |
| 203 | } |
| 204 | if (extensionTreatmentType |
| 205 | .equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C4_TO_C4.type())) { |
| 206 | return true; |
| 207 | } |
| 208 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes |
| 209 | .NICIRA_MOV_TUN_IPV4_DST_TO_TUN_IPV4_DST.type())) { |
| 210 | return true; |
| 211 | } |
| 212 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_TUN_ID_TO_TUN_ID |
| 213 | .type())) { |
| 214 | return true; |
| 215 | } |
| 216 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C2_TO_TUN_ID |
| 217 | .type())) { |
| 218 | return true; |
| 219 | } |
Frank Wang | 5733c38 | 2017-03-28 10:15:18 +0800 | [diff] [blame] | 220 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_CT.type())) { |
| 221 | return true; |
| 222 | } |
| 223 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_NAT.type())) { |
| 224 | return true; |
| 225 | } |
| 226 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_CT_CLEAR.type())) { |
| 227 | return true; |
| 228 | } |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 229 | return false; |
| 230 | } |
| 231 | |
| 232 | @Override |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 233 | public OFAction mapInstruction(OFFactory factory, ExtensionTreatment extensionTreatment) { |
| 234 | ExtensionTreatmentType type = extensionTreatment.type(); |
| 235 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) { |
| 236 | NiciraSetTunnelDst tunnelDst = (NiciraSetTunnelDst) extensionTreatment; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 237 | return factory.actions().setField(factory.oxms().tunnelIpv4Dst( |
| 238 | IPv4Address.of(tunnelDst.tunnelDst().toInt()))); |
| 239 | } |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 240 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) { |
BitOhenry | 5e2233a | 2015-12-08 09:26:38 +0800 | [diff] [blame] | 241 | NiciraResubmit resubmit = (NiciraResubmit) extensionTreatment; |
| 242 | return factory.actions().niciraResubmit((int) resubmit.inPort().toLong(), |
| 243 | resubmit.table()); |
BitOhenry | b53ac6c | 2015-11-16 20:58:58 +0800 | [diff] [blame] | 244 | } |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 245 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) { |
BitOhenry | 5e2233a | 2015-12-08 09:26:38 +0800 | [diff] [blame] | 246 | NiciraResubmitTable resubmitTable = (NiciraResubmitTable) extensionTreatment; |
| 247 | return factory.actions().niciraResubmitTable((int) resubmitTable.inPort().toLong(), |
| 248 | resubmitTable.table()); |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 249 | } |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 250 | |
| 251 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) { |
| 252 | NiciraSetNshSpi niciraNshSpi = (NiciraSetNshSpi) extensionTreatment; |
| 253 | return factory.actions().setField(factory.oxms().nsp(U32.of(niciraNshSpi.nshSpi().servicePathId()))); |
| 254 | } |
| 255 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) { |
| 256 | NiciraSetNshSi niciraNshSi = (NiciraSetNshSi) extensionTreatment; |
| 257 | return factory.actions().setField(factory.oxms().nsi(U8.of(niciraNshSi.nshSi().serviceIndex()))); |
| 258 | } |
| 259 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())) { |
| 260 | NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; |
| 261 | return factory.actions().setField(factory.oxms().nshC1(U32.of(niciraNshch.nshCh().nshContextHeader()))); |
| 262 | } |
| 263 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())) { |
| 264 | NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; |
| 265 | return factory.actions().setField(factory.oxms().nshC2(U32.of(niciraNshch.nshCh().nshContextHeader()))); |
| 266 | } |
| 267 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())) { |
| 268 | NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; |
| 269 | return factory.actions().setField(factory.oxms().nshC3(U32.of(niciraNshch.nshCh().nshContextHeader()))); |
| 270 | } |
| 271 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) { |
| 272 | NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; |
| 273 | return factory.actions().setField(factory.oxms().nshC4(U32.of(niciraNshch.nshCh().nshContextHeader()))); |
| 274 | } |
| 275 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_NSH_MDTYPE.type())) { |
| 276 | NiciraNshMdType niciraNshMdType = (NiciraNshMdType) extensionTreatment; |
| 277 | return factory.actions().setField(factory.oxms().nshMdtype(U8.of(niciraNshMdType.nshMdType()))); |
| 278 | } |
| 279 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_NSH_NP.type())) { |
| 280 | NiciraNshNp niciraNshNp = (NiciraNshNp) extensionTreatment; |
| 281 | return factory.actions().setField(factory.oxms().nshNp(U8.of(niciraNshNp.nshNp()))); |
| 282 | } |
| 283 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_ENCAP_ETH_SRC.type())) { |
| 284 | NiciraEncapEthSrc niciraEncapEthSrc = (NiciraEncapEthSrc) extensionTreatment; |
| 285 | return factory.actions().setField(factory.oxms().encapEthSrc(MacAddress.of(niciraEncapEthSrc.encapEthSrc() |
| 286 | .toBytes()))); |
| 287 | } |
| 288 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_ENCAP_ETH_DST.type())) { |
| 289 | NiciraEncapEthDst niciraEncapEthDst = (NiciraEncapEthDst) extensionTreatment; |
| 290 | return factory.actions().setField(factory.oxms().encapEthDst(MacAddress.of(niciraEncapEthDst.encapEthDst() |
| 291 | .toBytes()))); |
| 292 | } |
| 293 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_ENCAP_ETH_TYPE.type())) { |
| 294 | NiciraEncapEthType niciraEncapEthType = (NiciraEncapEthType) extensionTreatment; |
| 295 | return factory.actions().setField(factory.oxms().encapEthType(U16.of(niciraEncapEthType.encapEthType()))); |
| 296 | } |
| 297 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_PUSH_NSH.type())) { |
| 298 | return factory.actions().niciraPushNsh(); |
| 299 | } |
| 300 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_POP_NSH.type())) { |
| 301 | return factory.actions().niciraPopNsh(); |
| 302 | } |
| 303 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_TUN_GPE_NP.type())) { |
| 304 | NiciraTunGpeNp niciraTunGpeNp = (NiciraTunGpeNp) extensionTreatment; |
| 305 | return factory.actions().setField(factory.oxms().tunGpeNp(U8.of(niciraTunGpeNp.tunGpeNp()))); |
| 306 | } |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 307 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type()) |
samueljcc | 4a527ed | 2015-12-03 13:59:49 +0800 | [diff] [blame] | 308 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type()) |
| 309 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type()) |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 310 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type()) |
| 311 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C1_TO_C1.type()) |
| 312 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C2_TO_C2.type()) |
| 313 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C3_TO_C3.type()) |
| 314 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C4_TO_C4.type()) |
| 315 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_TUN_IPV4_DST_TO_TUN_IPV4_DST |
| 316 | .type()) |
| 317 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_TUN_ID_TO_TUN_ID.type()) |
| 318 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C2_TO_TUN_ID.type())) { |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 319 | MoveExtensionTreatment mov = (MoveExtensionTreatment) extensionTreatment; |
| 320 | OFActionNiciraMove.Builder action = factory.actions() |
| 321 | .buildNiciraMove(); |
| 322 | action.setDstOfs(mov.dstOffset()); |
| 323 | action.setSrcOfs(mov.srcOffset()); |
| 324 | action.setNBits(mov.nBits()); |
| 325 | action.setSrc(mov.src()); |
| 326 | action.setDst(mov.dst()); |
| 327 | return action.build(); |
samueljcc | 4a527ed | 2015-12-03 13:59:49 +0800 | [diff] [blame] | 328 | } |
Frank Wang | 5733c38 | 2017-03-28 10:15:18 +0800 | [diff] [blame] | 329 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_CT.type())) { |
| 330 | NiciraCt niciraCt = (NiciraCt) extensionTreatment; |
| 331 | OFActionNiciraCt.Builder ctAction = factory.actions().buildNiciraCt(); |
| 332 | ctAction.setFlags(niciraCt.niciraCtFlags()); |
| 333 | ctAction.setZoneSrc(niciraCt.niciraCtZoneSrc()); |
| 334 | ctAction.setZone(niciraCt.niciraCtZone()); |
| 335 | ctAction.setRecircTable(niciraCt.niciraCtRecircTable()); |
| 336 | ctAction.setAlg(niciraCt.niciraCtAlg()); |
| 337 | |
| 338 | for (ExtensionTreatment nestedTreatment : niciraCt.niciraCtNestActions()) { |
| 339 | if (nestedTreatment instanceof NiciraNat) { |
| 340 | NiciraNat niciraNat = (NiciraNat) nestedTreatment; |
| 341 | OFActionNiciraNat.Builder action = factory.actions().buildNiciraNat(); |
| 342 | action.setFlags(niciraNat.niciraNatFlags()); |
| 343 | |
| 344 | int presetFlags = niciraNat.niciraNatPresentFlags(); |
| 345 | action.setRangePresent(presetFlags); |
| 346 | |
| 347 | List<IPv4Address> ipv4RangeList = Lists.newArrayList(); |
| 348 | List<IPv6Address> ipv6RangeList = Lists.newArrayList(); |
| 349 | List<U16> portRangeList = Lists.newArrayList(); |
| 350 | List<U8> padList = Lists.newArrayList(); |
| 351 | if ((presetFlags & NAT_RANGE_IPV4_MIN) != 0) { |
| 352 | ipv4RangeList.add(IPv4Address.of(niciraNat.niciraNatIpAddressMin().getIp4Address().toString())); |
| 353 | } |
| 354 | if ((presetFlags & NAT_RANGE_IPV4_MAX) != 0) { |
| 355 | ipv4RangeList.add(IPv4Address.of(niciraNat.niciraNatIpAddressMax().getIp4Address().toString())); |
| 356 | } |
| 357 | |
| 358 | if ((presetFlags & NAT_RANGE_IPV6_MIN) != 0) { |
| 359 | ipv6RangeList.add(IPv6Address.of(niciraNat.niciraNatIpAddressMin().getIp6Address().toString())); |
| 360 | } |
| 361 | if ((presetFlags & NAT_RANGE_IPV6_MAX) != 0) { |
| 362 | ipv6RangeList.add(IPv6Address.of(niciraNat.niciraNatIpAddressMax().getIp6Address().toString())); |
| 363 | } |
| 364 | |
| 365 | if ((presetFlags & NAT_RANGE_PROTO_MIN) != 0) { |
| 366 | portRangeList.add(U16.of(niciraNat.niciraNatPortMin())); |
| 367 | } |
| 368 | if ((presetFlags & NAT_RANGE_PROTO_MAX) != 0) { |
| 369 | portRangeList.add(U16.of(niciraNat.niciraNatPortMax())); |
| 370 | } |
| 371 | |
| 372 | for (; (ipv6RangeList.size() * 16 + ipv4RangeList.size() * 4 |
| 373 | + portRangeList.size() * 2 + padList.size()) % 8 != 0;) { |
| 374 | padList.add(U8.ofRaw((byte) 0)); |
| 375 | } |
| 376 | |
| 377 | action.setIpv4Range(ipv4RangeList); |
| 378 | action.setIpv6Range(ipv6RangeList); |
| 379 | action.setPortRange(portRangeList); |
| 380 | action.setPad(padList); |
| 381 | |
| 382 | //nat action must be nested in ct action |
| 383 | List<OFAction> actions = Lists.newArrayList(); |
| 384 | actions.add(action.build()); |
| 385 | ctAction.setActions(actions); |
| 386 | } |
| 387 | } |
| 388 | return ctAction.build(); |
| 389 | } |
| 390 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_CT_CLEAR.type())) { |
| 391 | return factory.actions().niciraCtClear(); |
| 392 | } |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 393 | return null; |
| 394 | } |
| 395 | |
| 396 | @Override |
Jian Li | ffef500 | 2016-04-04 23:27:37 -0700 | [diff] [blame] | 397 | public ExtensionTreatment mapAction(OFAction action) throws UnsupportedOperationException { |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 398 | if (action.getType().equals(OFActionType.SET_FIELD)) { |
| 399 | OFActionSetField setFieldAction = (OFActionSetField) action; |
| 400 | OFOxm<?> oxm = setFieldAction.getField(); |
| 401 | switch (oxm.getMatchField().id) { |
| 402 | case TUNNEL_IPV4_DST: |
| 403 | OFOxmTunnelIpv4Dst tunnelIpv4Dst = (OFOxmTunnelIpv4Dst) oxm; |
| 404 | return new NiciraSetTunnelDst(Ip4Address.valueOf(tunnelIpv4Dst.getValue().getInt())); |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 405 | case NSP: |
| 406 | OFOxmNsp nsp = (OFOxmNsp) oxm; |
| 407 | return new NiciraSetNshSpi(NshServicePathId.of((nsp.getValue().getRaw()))); |
| 408 | case NSI: |
| 409 | OFOxmNsi nsi = (OFOxmNsi) oxm; |
| 410 | return new NiciraSetNshSi(NshServiceIndex.of((nsi.getValue().getRaw()))); |
| 411 | case NSH_C1: |
| 412 | OFOxmNshC1 nshC1 = (OFOxmNshC1) oxm; |
| 413 | return new NiciraSetNshContextHeader(NshContextHeader.of((nshC1.getValue().getRaw())), |
| 414 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1 |
| 415 | .type()); |
| 416 | case NSH_C2: |
| 417 | OFOxmNshC2 nshC2 = (OFOxmNshC2) oxm; |
| 418 | return new NiciraSetNshContextHeader(NshContextHeader.of((nshC2.getValue().getRaw())), |
| 419 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2 |
| 420 | .type()); |
| 421 | case NSH_C3: |
| 422 | OFOxmNshC3 nshC3 = (OFOxmNshC3) oxm; |
| 423 | return new NiciraSetNshContextHeader(NshContextHeader.of((nshC3.getValue().getRaw())), |
| 424 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3 |
| 425 | .type()); |
| 426 | case NSH_C4: |
| 427 | OFOxmNshC4 nshC4 = (OFOxmNshC4) oxm; |
| 428 | return new NiciraSetNshContextHeader(NshContextHeader.of((nshC4.getValue().getRaw())), |
| 429 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4 |
| 430 | .type()); |
| 431 | case NSH_MDTYPE: |
| 432 | OFOxmNshMdtype nshMdType = (OFOxmNshMdtype) oxm; |
| 433 | return new NiciraNshMdType((nshMdType.getValue().getRaw())); |
| 434 | case NSH_NP: |
| 435 | OFOxmNshNp nshNp = (OFOxmNshNp) oxm; |
| 436 | return new NiciraNshNp((nshNp.getValue().getRaw())); |
| 437 | case ENCAP_ETH_SRC: |
| 438 | OFOxmEncapEthSrc encapEthSrc = (OFOxmEncapEthSrc) oxm; |
| 439 | return new NiciraEncapEthSrc(org.onlab.packet.MacAddress.valueOf((encapEthSrc.getValue().getBytes()))); |
| 440 | case ENCAP_ETH_DST: |
| 441 | OFOxmEncapEthDst encapEthDst = (OFOxmEncapEthDst) oxm; |
| 442 | return new NiciraEncapEthDst(org.onlab.packet.MacAddress.valueOf((encapEthDst.getValue().getBytes()))); |
| 443 | case ENCAP_ETH_TYPE: |
| 444 | OFOxmEncapEthType encapEthType = (OFOxmEncapEthType) oxm; |
| 445 | return new NiciraEncapEthType((encapEthType.getValue().getRaw())); |
| 446 | case TUN_GPE_NP: |
| 447 | OFOxmTunGpeNp tunGpeNp = (OFOxmTunGpeNp) oxm; |
| 448 | return new NiciraTunGpeNp((tunGpeNp.getValue().getRaw())); |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 449 | default: |
| 450 | throw new UnsupportedOperationException( |
| 451 | "Driver does not support extension type " + oxm.getMatchField().id); |
| 452 | } |
| 453 | } |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 454 | if (action.getType().equals(OFActionType.EXPERIMENTER)) { |
| 455 | OFActionExperimenter experimenter = (OFActionExperimenter) action; |
| 456 | if (Long.valueOf(experimenter.getExperimenter()) |
| 457 | .intValue() == TYPE_NICIRA) { |
| 458 | OFActionNicira nicira = (OFActionNicira) experimenter; |
Jian Li | d416388 | 2016-03-30 20:03:14 -0700 | [diff] [blame] | 459 | switch (nicira.getSubtype()) { |
| 460 | case SUB_TYPE_MOVE: |
| 461 | OFActionNiciraMove moveAction = (OFActionNiciraMove) nicira; |
| 462 | switch (Long.valueOf(moveAction.getSrc()).intValue()) { |
| 463 | case SRC_ARP_SHA: |
| 464 | return NiciraMoveTreatmentFactory |
| 465 | .createNiciraMovArpShaToTha(); |
| 466 | case SRC_ETH: |
| 467 | return NiciraMoveTreatmentFactory |
| 468 | .createNiciraMovEthSrcToDst(); |
| 469 | case SRC_IP: |
| 470 | return NiciraMoveTreatmentFactory |
| 471 | .createNiciraMovIpSrcToDst(); |
| 472 | case SRC_ARP_SPA: |
| 473 | return NiciraMoveTreatmentFactory |
| 474 | .createNiciraMovArpSpaToTpa(); |
Ray Milkey | d6a67c3 | 2018-02-02 10:30:35 -0800 | [diff] [blame] | 475 | case NSH_C1: |
| 476 | return NiciraMoveTreatmentFactory.createNiciraMovNshC1ToC1(); |
| 477 | case NSH_C2: |
| 478 | if (Long.valueOf(moveAction.getDst()).intValue() == TUN_ID) { |
| 479 | return NiciraMoveTreatmentFactory.createNiciraMovNshC2ToTunId(); |
| 480 | } |
| 481 | return NiciraMoveTreatmentFactory.createNiciraMovNshC2ToC2(); |
| 482 | case NSH_C3: |
| 483 | return NiciraMoveTreatmentFactory.createNiciraMovNshC3ToC3(); |
| 484 | case NSH_C4: |
| 485 | return NiciraMoveTreatmentFactory.createNiciraMovNshC4ToC4(); |
| 486 | case TUN_IPV4_DST: |
| 487 | return NiciraMoveTreatmentFactory.createNiciraMovTunDstToTunDst(); |
| 488 | case TUN_ID: |
| 489 | return NiciraMoveTreatmentFactory.createNiciraMovTunIdToTunId(); |
Jian Li | d416388 | 2016-03-30 20:03:14 -0700 | [diff] [blame] | 490 | default: |
| 491 | throw new UnsupportedOperationException("Driver does not support move from " |
Ray Milkey | d6a67c3 | 2018-02-02 10:30:35 -0800 | [diff] [blame] | 492 | + moveAction.getSrc() + " to " + moveAction.getDst() + "of length " |
| 493 | + moveAction.getNBits()); |
Jian Li | d416388 | 2016-03-30 20:03:14 -0700 | [diff] [blame] | 494 | } |
| 495 | case SUB_TYPE_RESUBMIT: |
| 496 | OFActionNiciraResubmit resubmitAction = (OFActionNiciraResubmit) nicira; |
| 497 | return new NiciraResubmit(PortNumber.portNumber(resubmitAction.getInPort())); |
Frank Wang | 5733c38 | 2017-03-28 10:15:18 +0800 | [diff] [blame] | 498 | case SUB_TYPE_PUSH_NSH: |
| 499 | return new NiciraPushNsh(); |
| 500 | case SUB_TYPE_POP_NSH: |
| 501 | return new NiciraPopNsh(); |
| 502 | case SUB_TYPE_RESUBMIT_TABLE: |
| 503 | OFActionNiciraResubmitTable resubmitTable = (OFActionNiciraResubmitTable) nicira; |
| 504 | return new NiciraResubmitTable(PortNumber.portNumber(resubmitTable.getInPort()), |
| 505 | resubmitTable.getTable()); |
| 506 | case SUB_TYPE_CT: |
| 507 | OFActionNiciraCt ctAction = (OFActionNiciraCt) nicira; |
| 508 | List<OFAction> actions = ctAction.getActions(); |
| 509 | for (OFAction act : actions) { |
| 510 | OFActionExperimenter ctExperimenter = (OFActionExperimenter) act; |
| 511 | if (Long.valueOf(ctExperimenter.getExperimenter()).intValue() == TYPE_NICIRA) { |
| 512 | OFActionNicira actionNicira = (OFActionNicira) ctExperimenter; |
| 513 | switch (actionNicira.getSubtype()) { |
| 514 | case SUB_TYPE_NAT: |
| 515 | OFActionNiciraNat natAction = (OFActionNiciraNat) actionNicira; |
| 516 | int portMin = 0; |
| 517 | int portMax = 0; |
| 518 | IpAddress ipAddressMin = IpAddress.valueOf(0); |
| 519 | IpAddress ipAddressMax = IpAddress.valueOf(0); |
| 520 | //FIXME: we need to get ipv6 and port from list<ipv4> temporarily, |
| 521 | // becase loxi don't know how to arrange these data to corresonding field. |
| 522 | IPv4Address[] arrays = (IPv4Address[]) natAction |
| 523 | .getIpv4Range().toArray(new IPv4Address[0]); |
| 524 | int index = 0; |
| 525 | if ((natAction.getRangePresent() & NAT_RANGE_IPV4_MIN) != 0) { |
| 526 | ipAddressMin = IpAddress.valueOf(arrays[index++].toString()); |
| 527 | } |
| 528 | if ((natAction.getRangePresent() & NAT_RANGE_IPV4_MAX) != 0) { |
| 529 | ipAddressMax = IpAddress.valueOf(arrays[index++].toString()); |
| 530 | } |
| 531 | if ((natAction.getRangePresent() & NAT_RANGE_IPV6_MIN) != 0) { |
| 532 | byte[] bytes = Bytes.concat(arrays[index++].getBytes(), |
| 533 | arrays[index++].getBytes(), |
| 534 | arrays[index++].getBytes(), |
| 535 | arrays[index++].getBytes()); |
| 536 | |
| 537 | ipAddressMin = IpAddress.valueOf(IpAddress.Version.INET6, bytes); |
| 538 | } |
| 539 | if ((natAction.getRangePresent() & NAT_RANGE_IPV6_MAX) != 0) { |
| 540 | byte[] bytes = Bytes.concat(arrays[index++].getBytes(), |
| 541 | arrays[index++].getBytes(), |
| 542 | arrays[index++].getBytes(), |
| 543 | arrays[index++].getBytes()); |
| 544 | |
| 545 | ipAddressMax = IpAddress.valueOf(IpAddress.Version.INET6, bytes); |
| 546 | } |
| 547 | if ((natAction.getRangePresent() & NAT_RANGE_PROTO_MIN) != 0) { |
| 548 | portMin = arrays[index].getInt() >> 16 & 0x0000ffff; |
| 549 | } |
| 550 | if ((natAction.getRangePresent() & NAT_RANGE_PROTO_MAX) != 0) { |
| 551 | portMax = arrays[index].getInt() & 0x0000ffff; |
| 552 | } |
| 553 | List<ExtensionTreatment> treatments = new ArrayList<>(); |
| 554 | NiciraNat natTreatment = new NiciraNat(natAction.getFlags(), |
| 555 | natAction.getRangePresent(), |
| 556 | portMin, portMax, |
| 557 | ipAddressMin, ipAddressMax); |
| 558 | treatments.add(natTreatment); |
| 559 | return new NiciraCt(ctAction.getFlags(), |
| 560 | ctAction.getZoneSrc(), |
| 561 | ctAction.getZone(), |
| 562 | ctAction.getRecircTable(), |
| 563 | ctAction.getAlg(), |
| 564 | treatments); |
| 565 | default: |
| 566 | throw new UnsupportedOperationException("Driver does not support nested" + |
| 567 | " in ct action extension subtype " + actionNicira.getSubtype()); |
| 568 | } |
| 569 | } |
| 570 | } |
| 571 | return new NiciraCt(ctAction.getFlags(), |
| 572 | ctAction.getZoneSrc(), |
| 573 | ctAction.getZone(), |
| 574 | ctAction.getRecircTable(), |
| 575 | ctAction.getAlg(), |
| 576 | new ArrayList<>()); |
| 577 | case SUB_TYPE_CT_CLEAR: |
| 578 | return new NiciraCtClear(); |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 579 | default: |
Jian Li | d416388 | 2016-03-30 20:03:14 -0700 | [diff] [blame] | 580 | throw new UnsupportedOperationException("Driver does not support extension subtype " |
| 581 | + nicira.getSubtype()); |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 582 | } |
| 583 | } |
| 584 | } |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 585 | return null; |
| 586 | } |
| 587 | |
| 588 | @Override |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 589 | public ExtensionTreatment getExtensionInstruction(ExtensionTreatmentType type) { |
| 590 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) { |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 591 | return new NiciraSetTunnelDst(); |
| 592 | } |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 593 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) { |
BitOhenry | b53ac6c | 2015-11-16 20:58:58 +0800 | [diff] [blame] | 594 | return new NiciraResubmit(); |
| 595 | } |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 596 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) { |
| 597 | return new NiciraResubmitTable(); |
| 598 | } |
Phaneendra Manda | ce66cbc | 2015-11-26 18:07:48 +0530 | [diff] [blame] | 599 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) { |
| 600 | return new NiciraSetNshSpi(); |
| 601 | } |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 602 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) { |
| 603 | return new NiciraSetNshSi(); |
| 604 | } |
| 605 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type()) |
| 606 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type()) |
| 607 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type()) |
| 608 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) { |
| 609 | return new NiciraSetNshContextHeader(type); |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 610 | } |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 611 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_PUSH_NSH.type())) { |
| 612 | return new NiciraPushNsh(); |
| 613 | } |
| 614 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_POP_NSH.type())) { |
| 615 | return new NiciraPopNsh(); |
| 616 | } |
| 617 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_NSH_MDTYPE.type())) { |
| 618 | return new NiciraNshMdType(); |
| 619 | } |
| 620 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_NSH_NP.type())) { |
| 621 | return new NiciraNshNp(); |
| 622 | } |
| 623 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_ENCAP_ETH_SRC.type())) { |
| 624 | return new NiciraEncapEthSrc(); |
| 625 | } |
| 626 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_ENCAP_ETH_DST.type())) { |
| 627 | return new NiciraEncapEthDst(); |
| 628 | } |
| 629 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_ENCAP_ETH_TYPE.type())) { |
| 630 | return new NiciraEncapEthType(); |
| 631 | } |
samueljcc | 4a527ed | 2015-12-03 13:59:49 +0800 | [diff] [blame] | 632 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type())) { |
| 633 | return NiciraMoveTreatmentFactory.createNiciraMovArpShaToTha(); |
| 634 | } |
| 635 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type())) { |
| 636 | return NiciraMoveTreatmentFactory.createNiciraMovArpSpaToTpa(); |
| 637 | } |
| 638 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type())) { |
| 639 | return NiciraMoveTreatmentFactory.createNiciraMovEthSrcToDst(); |
| 640 | } |
| 641 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) { |
| 642 | return NiciraMoveTreatmentFactory.createNiciraMovIpSrcToDst(); |
| 643 | } |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 644 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_TUN_GPE_NP.type())) { |
| 645 | return new NiciraTunGpeNp(); |
| 646 | } |
| 647 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C1_TO_C1.type())) { |
| 648 | return NiciraMoveTreatmentFactory.createNiciraMovNshC1ToC1(); |
| 649 | } |
| 650 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C2_TO_C2.type())) { |
| 651 | return NiciraMoveTreatmentFactory.createNiciraMovNshC2ToC2(); |
| 652 | } |
| 653 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C3_TO_C3.type())) { |
| 654 | return NiciraMoveTreatmentFactory.createNiciraMovNshC3ToC3(); |
| 655 | } |
| 656 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C4_TO_C4.type())) { |
| 657 | return NiciraMoveTreatmentFactory.createNiciraMovNshC4ToC4(); |
| 658 | } |
| 659 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_TUN_IPV4_DST_TO_TUN_IPV4_DST |
| 660 | .type())) { |
| 661 | return NiciraMoveTreatmentFactory.createNiciraMovTunDstToTunDst(); |
| 662 | } |
| 663 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_TUN_ID_TO_TUN_ID.type())) { |
| 664 | return NiciraMoveTreatmentFactory.createNiciraMovTunIdToTunId(); |
| 665 | } |
| 666 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C2_TO_TUN_ID.type())) { |
| 667 | return NiciraMoveTreatmentFactory.createNiciraMovNshC2ToTunId(); |
| 668 | } |
Frank Wang | 5733c38 | 2017-03-28 10:15:18 +0800 | [diff] [blame] | 669 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_CT.type())) { |
| 670 | return new NiciraCt(); |
| 671 | } |
| 672 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_NAT.type())) { |
| 673 | return new NiciraNat(); |
| 674 | } |
| 675 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_CT_CLEAR.type())) { |
| 676 | return new NiciraCtClear(); |
| 677 | } |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 678 | throw new UnsupportedOperationException("Driver does not support extension type " + type.toString()); |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 679 | } |
Jian Li | dab7256 | 2016-04-12 14:10:32 -0700 | [diff] [blame] | 680 | |
| 681 | @Override |
| 682 | public ObjectNode encode(ExtensionTreatment extensionTreatment, CodecContext context) { |
| 683 | checkNotNull(extensionTreatment, "Extension treatment cannot be null"); |
| 684 | ExtensionTreatmentType type = extensionTreatment.type(); |
| 685 | ObjectNode root = context.mapper().createObjectNode(); |
| 686 | |
| 687 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) { |
| 688 | NiciraSetTunnelDst tunnelDst = (NiciraSetTunnelDst) extensionTreatment; |
| 689 | root.set(TUNNEL_DST, context.codec(NiciraSetTunnelDst.class).encode(tunnelDst, context)); |
| 690 | } |
| 691 | |
| 692 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) { |
| 693 | NiciraResubmit resubmit = (NiciraResubmit) extensionTreatment; |
| 694 | root.set(RESUBMIT, context.codec(NiciraResubmit.class).encode(resubmit, context)); |
| 695 | } |
| 696 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) { |
| 697 | NiciraResubmitTable resubmitTable = (NiciraResubmitTable) extensionTreatment; |
| 698 | root.set(RESUBMIT_TABLE, context.codec(NiciraResubmitTable.class).encode(resubmitTable, context)); |
| 699 | } |
| 700 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) { |
| 701 | NiciraSetNshSpi niciraNshSpi = (NiciraSetNshSpi) extensionTreatment; |
| 702 | root.set(NICIRA_NSH_SPI, context.codec(NiciraSetNshSpi.class).encode(niciraNshSpi, context)); |
| 703 | } |
| 704 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) { |
| 705 | NiciraSetNshSi niciraNshSi = (NiciraSetNshSi) extensionTreatment; |
| 706 | root.set(NICIRA_NSH_SI, context.codec(NiciraSetNshSi.class).encode(niciraNshSi, context)); |
| 707 | } |
| 708 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())) { |
| 709 | NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; |
| 710 | root.set(NICIRA_NSH_CH, context.codec(NiciraSetNshContextHeader.class).encode(niciraNshch, context)); |
| 711 | } |
| 712 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())) { |
| 713 | NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; |
| 714 | root.set(NICIRA_NSH_CH, context.codec(NiciraSetNshContextHeader.class).encode(niciraNshch, context)); |
| 715 | } |
| 716 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())) { |
| 717 | NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; |
| 718 | root.set(NICIRA_NSH_CH, context.codec(NiciraSetNshContextHeader.class).encode(niciraNshch, context)); |
| 719 | } |
| 720 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) { |
| 721 | NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; |
| 722 | root.set(NICIRA_NSH_CH, context.codec(NiciraSetNshContextHeader.class).encode(niciraNshch, context)); |
| 723 | } |
| 724 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type()) |
| 725 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type()) |
| 726 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type()) |
| 727 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) { |
| 728 | MoveExtensionTreatment mov = (MoveExtensionTreatment) extensionTreatment; |
| 729 | root.set(NICIRA_MOVE, context.codec(MoveExtensionTreatment.class).encode(mov, context)); |
| 730 | } |
| 731 | |
| 732 | return root; |
| 733 | } |
| 734 | |
| 735 | @Override |
| 736 | public ExtensionTreatment decode(ObjectNode json, CodecContext context) { |
| 737 | if (json == null || !json.isObject()) { |
| 738 | return null; |
| 739 | } |
| 740 | |
| 741 | // parse extension type |
| 742 | int typeInt = nullIsIllegal(json.get(TYPE), TYPE + MISSING_MEMBER_MESSAGE).asInt(); |
| 743 | ExtensionTreatmentType type = new ExtensionTreatmentType(typeInt); |
| 744 | |
| 745 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) { |
| 746 | return context.codec(NiciraSetTunnelDst.class).decode(json, context); |
| 747 | } |
| 748 | |
| 749 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) { |
| 750 | return context.codec(NiciraResubmit.class).decode(json, context); |
| 751 | } |
| 752 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) { |
| 753 | return context.codec(NiciraResubmitTable.class).decode(json, context); |
| 754 | } |
| 755 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) { |
| 756 | return context.codec(NiciraSetNshSpi.class).decode(json, context); |
| 757 | } |
| 758 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) { |
| 759 | return context.codec(NiciraSetNshSi.class).decode(json, context); |
| 760 | } |
| 761 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())) { |
| 762 | return context.codec(NiciraSetNshContextHeader.class).decode(json, context); |
| 763 | } |
| 764 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())) { |
| 765 | return context.codec(NiciraSetNshContextHeader.class).decode(json, context); |
| 766 | } |
| 767 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())) { |
| 768 | return context.codec(NiciraSetNshContextHeader.class).decode(json, context); |
| 769 | } |
| 770 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) { |
| 771 | return context.codec(NiciraSetNshContextHeader.class).decode(json, context); |
| 772 | } |
| 773 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type()) |
| 774 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type()) |
| 775 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type()) |
| 776 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) { |
| 777 | return context.codec(MoveExtensionTreatment.class).decode(json, context); |
| 778 | } |
| 779 | throw new UnsupportedOperationException( |
| 780 | "Driver does not support extension type " + type.toString()); |
| 781 | } |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 782 | } |