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