Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 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 | |
| 19 | import org.onlab.packet.Ip4Address; |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 20 | import org.onosproject.net.behaviour.ExtensionTreatmentResolver; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 21 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 22 | import org.onosproject.net.flow.instructions.ExtensionTreatment; |
| 23 | import org.onosproject.net.flow.instructions.ExtensionTreatmentType; |
| 24 | import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 25 | import org.projectfloodlight.openflow.protocol.OFActionType; |
| 26 | import org.projectfloodlight.openflow.protocol.OFFactory; |
| 27 | import org.projectfloodlight.openflow.protocol.action.OFAction; |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 28 | import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter; |
| 29 | import org.projectfloodlight.openflow.protocol.action.OFActionNicira; |
| 30 | import org.projectfloodlight.openflow.protocol.action.OFActionNiciraMove; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 31 | import org.projectfloodlight.openflow.protocol.action.OFActionSetField; |
| 32 | import org.projectfloodlight.openflow.protocol.oxm.OFOxm; |
| 33 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmTunnelIpv4Dst; |
| 34 | import org.projectfloodlight.openflow.types.IPv4Address; |
| 35 | |
| 36 | /** |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 37 | * Interpreter for Nicira OpenFlow treatment extensions. |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 38 | */ |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 39 | public class NiciraExtensionTreatmentInterpreter extends AbstractHandlerBehaviour |
| 40 | implements ExtensionTreatmentInterpreter, ExtensionTreatmentResolver { |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 41 | |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 42 | private static final int TYPE_NICIRA = 0x2320; |
| 43 | private static final int SUB_TYPE_MOVE = 6; |
| 44 | private static final int SRC_ARP_SHA = 0x00012206; |
| 45 | private static final int SRC_ARP_SPA = 0x00002004; |
| 46 | private static final int SRC_ETH = 0x00000406; |
| 47 | private static final int SRC_IP = 0x00000e04; |
| 48 | |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 49 | @Override |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 50 | public boolean supported(ExtensionTreatmentType extensionTreatmentType) { |
| 51 | if (extensionTreatmentType.equals( |
| 52 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) { |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 53 | return true; |
| 54 | } |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 55 | if (extensionTreatmentType.equals( |
| 56 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) { |
BitOhenry | b53ac6c | 2015-11-16 20:58:58 +0800 | [diff] [blame] | 57 | return true; |
| 58 | } |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 59 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) { |
| 60 | return true; |
| 61 | } |
| 62 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) { |
| 63 | return true; |
| 64 | } |
| 65 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())) { |
| 66 | return true; |
| 67 | } |
| 68 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())) { |
| 69 | return true; |
| 70 | } |
| 71 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())) { |
| 72 | return true; |
| 73 | } |
| 74 | if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) { |
Phaneendra Manda | ce66cbc | 2015-11-26 18:07:48 +0530 | [diff] [blame] | 75 | return true; |
| 76 | } |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 77 | if (extensionTreatmentType.equals( |
| 78 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) { |
| 79 | return true; |
| 80 | } |
samueljcc | 4a527ed | 2015-12-03 13:59:49 +0800 | [diff] [blame] | 81 | if (extensionTreatmentType.equals( |
| 82 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type())) { |
| 83 | return true; |
| 84 | } |
| 85 | if (extensionTreatmentType.equals( |
| 86 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type())) { |
| 87 | return true; |
| 88 | } |
| 89 | if (extensionTreatmentType.equals( |
| 90 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type())) { |
| 91 | return true; |
| 92 | } |
| 93 | if (extensionTreatmentType.equals( |
| 94 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) { |
| 95 | return true; |
| 96 | } |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 97 | return false; |
| 98 | } |
| 99 | |
| 100 | @Override |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 101 | public OFAction mapInstruction(OFFactory factory, ExtensionTreatment extensionTreatment) { |
| 102 | ExtensionTreatmentType type = extensionTreatment.type(); |
| 103 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) { |
| 104 | NiciraSetTunnelDst tunnelDst = (NiciraSetTunnelDst) extensionTreatment; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 105 | return factory.actions().setField(factory.oxms().tunnelIpv4Dst( |
| 106 | IPv4Address.of(tunnelDst.tunnelDst().toInt()))); |
| 107 | } |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 108 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) { |
BitOhenry | 5e2233a | 2015-12-08 09:26:38 +0800 | [diff] [blame] | 109 | NiciraResubmit resubmit = (NiciraResubmit) extensionTreatment; |
| 110 | return factory.actions().niciraResubmit((int) resubmit.inPort().toLong(), |
| 111 | resubmit.table()); |
BitOhenry | b53ac6c | 2015-11-16 20:58:58 +0800 | [diff] [blame] | 112 | } |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 113 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) { |
BitOhenry | 5e2233a | 2015-12-08 09:26:38 +0800 | [diff] [blame] | 114 | NiciraResubmitTable resubmitTable = (NiciraResubmitTable) extensionTreatment; |
| 115 | return factory.actions().niciraResubmitTable((int) resubmitTable.inPort().toLong(), |
| 116 | resubmitTable.table()); |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 117 | } |
Phaneendra Manda | 0c0f14b | 2015-12-09 20:38:27 +0530 | [diff] [blame] | 118 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) { |
| 119 | NiciraSetNshSpi niciraNshSpi = (NiciraSetNshSpi) extensionTreatment; |
| 120 | return factory.actions().niciraSetNsp(niciraNshSpi.nshSpi().servicePathId()); |
| 121 | } |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 122 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) { |
Phaneendra Manda | 0c0f14b | 2015-12-09 20:38:27 +0530 | [diff] [blame] | 123 | NiciraSetNshSi niciraNshSi = (NiciraSetNshSi) extensionTreatment; |
| 124 | return factory.actions().niciraSetNsp(niciraNshSi.nshSi().serviceIndex()); |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 125 | } |
| 126 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())) { |
Phaneendra Manda | 0c0f14b | 2015-12-09 20:38:27 +0530 | [diff] [blame] | 127 | NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; |
| 128 | return factory.actions().niciraSetNshc1(niciraNshch.nshCh().nshContextHeader()); |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 129 | } |
| 130 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())) { |
Phaneendra Manda | 0c0f14b | 2015-12-09 20:38:27 +0530 | [diff] [blame] | 131 | NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; |
| 132 | return factory.actions().niciraSetNshc2(niciraNshch.nshCh().nshContextHeader()); |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 133 | } |
| 134 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())) { |
Phaneendra Manda | 0c0f14b | 2015-12-09 20:38:27 +0530 | [diff] [blame] | 135 | NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; |
| 136 | return factory.actions().niciraSetNshc3(niciraNshch.nshCh().nshContextHeader()); |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 137 | } |
| 138 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) { |
Phaneendra Manda | 0c0f14b | 2015-12-09 20:38:27 +0530 | [diff] [blame] | 139 | NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; |
| 140 | return factory.actions().niciraSetNshc4(niciraNshch.nshCh().nshContextHeader()); |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 141 | } |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 142 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type()) |
samueljcc | 4a527ed | 2015-12-03 13:59:49 +0800 | [diff] [blame] | 143 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type()) |
| 144 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type()) |
| 145 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) { |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 146 | MoveExtensionTreatment mov = (MoveExtensionTreatment) extensionTreatment; |
| 147 | OFActionNiciraMove.Builder action = factory.actions() |
| 148 | .buildNiciraMove(); |
| 149 | action.setDstOfs(mov.dstOffset()); |
| 150 | action.setSrcOfs(mov.srcOffset()); |
| 151 | action.setNBits(mov.nBits()); |
| 152 | action.setSrc(mov.src()); |
| 153 | action.setDst(mov.dst()); |
| 154 | return action.build(); |
samueljcc | 4a527ed | 2015-12-03 13:59:49 +0800 | [diff] [blame] | 155 | } |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 156 | return null; |
| 157 | } |
| 158 | |
| 159 | @Override |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 160 | public ExtensionTreatment mapAction(OFAction action) { |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 161 | if (action.getType().equals(OFActionType.SET_FIELD)) { |
| 162 | OFActionSetField setFieldAction = (OFActionSetField) action; |
| 163 | OFOxm<?> oxm = setFieldAction.getField(); |
| 164 | switch (oxm.getMatchField().id) { |
| 165 | case TUNNEL_IPV4_DST: |
| 166 | OFOxmTunnelIpv4Dst tunnelIpv4Dst = (OFOxmTunnelIpv4Dst) oxm; |
| 167 | return new NiciraSetTunnelDst(Ip4Address.valueOf(tunnelIpv4Dst.getValue().getInt())); |
| 168 | default: |
| 169 | throw new UnsupportedOperationException( |
| 170 | "Driver does not support extension type " + oxm.getMatchField().id); |
| 171 | } |
| 172 | } |
samueljcc | 4f4d25a | 2015-12-07 10:52:28 +0800 | [diff] [blame] | 173 | if (action.getType().equals(OFActionType.EXPERIMENTER)) { |
| 174 | OFActionExperimenter experimenter = (OFActionExperimenter) action; |
| 175 | if (Long.valueOf(experimenter.getExperimenter()) |
| 176 | .intValue() == TYPE_NICIRA) { |
| 177 | OFActionNicira nicira = (OFActionNicira) experimenter; |
| 178 | if (nicira.getSubtype() == SUB_TYPE_MOVE) { |
| 179 | OFActionNiciraMove moveAction = (OFActionNiciraMove) nicira; |
| 180 | switch (Long.valueOf(moveAction.getSrc()).intValue()) { |
| 181 | case SRC_ARP_SHA: |
| 182 | return NiciraMoveTreatmentFactory |
| 183 | .createNiciraMovArpShaToTha(); |
| 184 | case SRC_ETH: |
| 185 | return NiciraMoveTreatmentFactory |
| 186 | .createNiciraMovEthSrcToDst(); |
| 187 | case SRC_IP: |
| 188 | return NiciraMoveTreatmentFactory |
| 189 | .createNiciraMovIpSrcToDst(); |
| 190 | case SRC_ARP_SPA: |
| 191 | return NiciraMoveTreatmentFactory |
| 192 | .createNiciraMovArpSpaToTpa(); |
| 193 | default: |
| 194 | throw new UnsupportedOperationException("Driver does not support move from " |
| 195 | + moveAction.getSrc() + " to " |
| 196 | + moveAction.getDst()); |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | } |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 201 | return null; |
| 202 | } |
| 203 | |
| 204 | @Override |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 205 | public ExtensionTreatment getExtensionInstruction(ExtensionTreatmentType type) { |
| 206 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) { |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 207 | return new NiciraSetTunnelDst(); |
| 208 | } |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 209 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) { |
BitOhenry | b53ac6c | 2015-11-16 20:58:58 +0800 | [diff] [blame] | 210 | return new NiciraResubmit(); |
| 211 | } |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 212 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) { |
| 213 | return new NiciraResubmitTable(); |
| 214 | } |
Phaneendra Manda | ce66cbc | 2015-11-26 18:07:48 +0530 | [diff] [blame] | 215 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) { |
| 216 | return new NiciraSetNshSpi(); |
| 217 | } |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 218 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) { |
| 219 | return new NiciraSetNshSi(); |
| 220 | } |
| 221 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type()) |
| 222 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type()) |
| 223 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type()) |
| 224 | || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) { |
| 225 | return new NiciraSetNshContextHeader(type); |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 226 | } |
samueljcc | 4a527ed | 2015-12-03 13:59:49 +0800 | [diff] [blame] | 227 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type())) { |
| 228 | return NiciraMoveTreatmentFactory.createNiciraMovArpShaToTha(); |
| 229 | } |
| 230 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type())) { |
| 231 | return NiciraMoveTreatmentFactory.createNiciraMovArpSpaToTpa(); |
| 232 | } |
| 233 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type())) { |
| 234 | return NiciraMoveTreatmentFactory.createNiciraMovEthSrcToDst(); |
| 235 | } |
| 236 | if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) { |
| 237 | return NiciraMoveTreatmentFactory.createNiciraMovIpSrcToDst(); |
| 238 | } |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 239 | throw new UnsupportedOperationException( |
| 240 | "Driver does not support extension type " + type.toString()); |
| 241 | } |
| 242 | } |