Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 Open Networking Laboratory |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.provider.of.flow.impl; |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 17 | |
Jonathan Hart | 29afca3 | 2015-01-20 18:17:39 -0800 | [diff] [blame] | 18 | import org.onlab.packet.Ip4Address; |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 19 | import org.onlab.packet.Ip6Address; |
Charles M.C. Chan | fe42181 | 2015-01-12 18:20:51 +0800 | [diff] [blame] | 20 | import org.onosproject.net.PortNumber; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 21 | import org.onosproject.net.flow.FlowRule; |
| 22 | import org.onosproject.net.flow.TrafficTreatment; |
| 23 | import org.onosproject.net.flow.instructions.Instruction; |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 24 | import org.onosproject.net.flow.instructions.Instructions; |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 25 | import org.onosproject.net.flow.instructions.Instructions.GroupInstruction; |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 26 | import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 27 | import org.onosproject.net.flow.instructions.L0ModificationInstruction; |
| 28 | import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModLambdaInstruction; |
| 29 | import org.onosproject.net.flow.instructions.L2ModificationInstruction; |
| 30 | import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction; |
Jonathan Hart | 29afca3 | 2015-01-20 18:17:39 -0800 | [diff] [blame] | 31 | import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsLabelInstruction; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 32 | import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction; |
| 33 | import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanPcpInstruction; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 34 | import org.onosproject.net.flow.instructions.L2ModificationInstruction.PushHeaderInstructions; |
| 35 | import org.onosproject.net.flow.instructions.L3ModificationInstruction; |
| 36 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction; |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 37 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction; |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 38 | import org.onosproject.openflow.controller.OpenFlowSwitch; |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 39 | import org.projectfloodlight.openflow.protocol.OFFactory; |
| 40 | import org.projectfloodlight.openflow.protocol.OFFlowAdd; |
| 41 | import org.projectfloodlight.openflow.protocol.OFFlowDelete; |
| 42 | import org.projectfloodlight.openflow.protocol.OFFlowMod; |
| 43 | import org.projectfloodlight.openflow.protocol.OFFlowModFlags; |
| 44 | import org.projectfloodlight.openflow.protocol.action.OFAction; |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 45 | import org.projectfloodlight.openflow.protocol.action.OFActionGroup; |
Charles M.C. Chan | fe42181 | 2015-01-12 18:20:51 +0800 | [diff] [blame] | 46 | import org.projectfloodlight.openflow.protocol.action.OFActionOutput; |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 47 | import org.projectfloodlight.openflow.protocol.instruction.OFInstruction; |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 48 | import org.projectfloodlight.openflow.protocol.match.Match; |
| 49 | import org.projectfloodlight.openflow.protocol.oxm.OFOxm; |
| 50 | import org.projectfloodlight.openflow.types.CircuitSignalID; |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 51 | import org.projectfloodlight.openflow.types.EthType; |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 52 | import org.projectfloodlight.openflow.types.IPv4Address; |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 53 | import org.projectfloodlight.openflow.types.IPv6Address; |
| 54 | import org.projectfloodlight.openflow.types.IPv6FlowLabel; |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 55 | import org.projectfloodlight.openflow.types.MacAddress; |
| 56 | import org.projectfloodlight.openflow.types.OFBufferId; |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 57 | import org.projectfloodlight.openflow.types.OFGroup; |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 58 | import org.projectfloodlight.openflow.types.OFPort; |
| 59 | import org.projectfloodlight.openflow.types.OFVlanVidMatch; |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 60 | import org.projectfloodlight.openflow.types.TableId; |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 61 | import org.projectfloodlight.openflow.types.U32; |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 62 | import org.projectfloodlight.openflow.types.U64; |
| 63 | import org.projectfloodlight.openflow.types.VlanPcp; |
| 64 | import org.slf4j.Logger; |
| 65 | import org.slf4j.LoggerFactory; |
| 66 | |
Jonathan Hart | 29afca3 | 2015-01-20 18:17:39 -0800 | [diff] [blame] | 67 | import java.util.Collections; |
| 68 | import java.util.LinkedList; |
| 69 | import java.util.List; |
| 70 | import java.util.Optional; |
| 71 | |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 72 | /** |
| 73 | * Flow mod builder for OpenFlow 1.3+. |
| 74 | */ |
| 75 | public class FlowModBuilderVer13 extends FlowModBuilder { |
| 76 | |
| 77 | private static final Logger log = LoggerFactory.getLogger(FlowModBuilderVer10.class); |
Charles M.C. Chan | fe42181 | 2015-01-12 18:20:51 +0800 | [diff] [blame] | 78 | private static final int OFPCML_NO_BUFFER = 0xffff; |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 79 | |
| 80 | private final TrafficTreatment treatment; |
| 81 | |
| 82 | /** |
| 83 | * Constructor for a flow mod builder for OpenFlow 1.3. |
| 84 | * |
| 85 | * @param flowRule the flow rule to transform into a flow mod |
| 86 | * @param factory the OpenFlow factory to use to build the flow mod |
Pavlin Radoslavov | 119fd5c | 2014-11-25 19:08:19 -0800 | [diff] [blame] | 87 | * @param xid the transaction ID |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 88 | */ |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 89 | protected FlowModBuilderVer13(FlowRule flowRule, OFFactory factory, Optional<Long> xid) { |
| 90 | super(flowRule, factory, xid); |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 91 | |
| 92 | this.treatment = flowRule.treatment(); |
| 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public OFFlowAdd buildFlowAdd() { |
| 97 | Match match = buildMatch(); |
Jonathan Hart | d4a8bba | 2014-10-28 12:44:20 -0700 | [diff] [blame] | 98 | List<OFAction> actions = buildActions(); |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 99 | List<OFInstruction> instructions = buildInstructions(); |
Jonathan Hart | d4a8bba | 2014-10-28 12:44:20 -0700 | [diff] [blame] | 100 | // FIXME had to revert back to using apply-actions instead of |
| 101 | // write-actions because LINC-OE apparently doesn't support |
| 102 | // write-actions. I would prefer to change this back in the future |
| 103 | // because apply-actions is an optional instruction in OF 1.3. |
| 104 | |
| 105 | //OFInstruction writeActions = |
| 106 | //factory().instructions().writeActions(actions); |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 107 | |
| 108 | long cookie = flowRule().id().value(); |
| 109 | |
alshabib | 4785eec | 2014-12-04 16:45:45 -0800 | [diff] [blame] | 110 | |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 111 | OFFlowAdd fm = factory().buildFlowAdd() |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 112 | .setXid(xid) |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 113 | .setCookie(U64.of(cookie)) |
| 114 | .setBufferId(OFBufferId.NO_BUFFER) |
Jonathan Hart | d4a8bba | 2014-10-28 12:44:20 -0700 | [diff] [blame] | 115 | .setActions(actions) |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 116 | .setInstructions(instructions) |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 117 | .setMatch(match) |
| 118 | .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM)) |
| 119 | .setPriority(flowRule().priority()) |
| 120 | .build(); |
| 121 | |
| 122 | return fm; |
| 123 | } |
| 124 | |
| 125 | @Override |
| 126 | public OFFlowMod buildFlowMod() { |
| 127 | Match match = buildMatch(); |
Jonathan Hart | d4a8bba | 2014-10-28 12:44:20 -0700 | [diff] [blame] | 128 | List<OFAction> actions = buildActions(); |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 129 | List<OFInstruction> instructions = buildInstructions(); |
Jonathan Hart | d4a8bba | 2014-10-28 12:44:20 -0700 | [diff] [blame] | 130 | //OFInstruction writeActions = |
| 131 | //factory().instructions().writeActions(actions); |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 132 | |
| 133 | long cookie = flowRule().id().value(); |
| 134 | |
alshabib | 4785eec | 2014-12-04 16:45:45 -0800 | [diff] [blame] | 135 | |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 136 | OFFlowMod fm = factory().buildFlowModify() |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 137 | .setXid(xid) |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 138 | .setCookie(U64.of(cookie)) |
| 139 | .setBufferId(OFBufferId.NO_BUFFER) |
Jonathan Hart | d4a8bba | 2014-10-28 12:44:20 -0700 | [diff] [blame] | 140 | .setActions(actions) |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 141 | .setInstructions(instructions) |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 142 | .setMatch(match) |
| 143 | .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM)) |
| 144 | .setPriority(flowRule().priority()) |
| 145 | .build(); |
| 146 | |
| 147 | return fm; |
| 148 | } |
| 149 | |
| 150 | @Override |
| 151 | public OFFlowDelete buildFlowDel() { |
| 152 | Match match = buildMatch(); |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 153 | |
| 154 | long cookie = flowRule().id().value(); |
| 155 | |
| 156 | OFFlowDelete fm = factory().buildFlowDelete() |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 157 | .setXid(xid) |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 158 | .setCookie(U64.of(cookie)) |
| 159 | .setBufferId(OFBufferId.NO_BUFFER) |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 160 | .setMatch(match) |
| 161 | .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM)) |
| 162 | .setPriority(flowRule().priority()) |
| 163 | .build(); |
| 164 | |
| 165 | return fm; |
| 166 | } |
| 167 | |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 168 | |
| 169 | private List<OFInstruction> buildInstructions() { |
| 170 | List<OFInstruction> instructions = new LinkedList<>(); |
| 171 | if (treatment == null) { |
| 172 | return instructions; |
| 173 | } |
| 174 | for (Instruction i : treatment.instructions()) { |
| 175 | switch (i.type()) { |
| 176 | case TABLE: |
| 177 | instructions.add(buildTableGoto(((Instructions.TableTypeTransition) i))); |
| 178 | break; |
| 179 | default: |
| 180 | break; |
| 181 | } |
| 182 | } |
| 183 | return instructions; |
| 184 | } |
| 185 | |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 186 | private List<OFAction> buildActions() { |
| 187 | List<OFAction> actions = new LinkedList<>(); |
| 188 | if (treatment == null) { |
| 189 | return actions; |
| 190 | } |
| 191 | for (Instruction i : treatment.instructions()) { |
| 192 | switch (i.type()) { |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 193 | case DROP: |
| 194 | log.warn("Saw drop action; assigning drop action"); |
| 195 | return new LinkedList<>(); |
| 196 | case L0MODIFICATION: |
| 197 | actions.add(buildL0Modification(i)); |
| 198 | break; |
| 199 | case L2MODIFICATION: |
| 200 | actions.add(buildL2Modification(i)); |
| 201 | break; |
| 202 | case L3MODIFICATION: |
| 203 | actions.add(buildL3Modification(i)); |
| 204 | break; |
| 205 | case OUTPUT: |
| 206 | OutputInstruction out = (OutputInstruction) i; |
| 207 | OFActionOutput.Builder action = factory().actions().buildOutput() |
| 208 | .setPort(OFPort.of((int) out.port().toLong())); |
| 209 | if (out.port().equals(PortNumber.CONTROLLER)) { |
| 210 | action.setMaxLen(OFPCML_NO_BUFFER); |
| 211 | } |
| 212 | actions.add(action.build()); |
| 213 | break; |
| 214 | case GROUP: |
| 215 | GroupInstruction group = (GroupInstruction) i; |
| 216 | OFActionGroup.Builder groupBuilder = factory().actions().buildGroup() |
| 217 | .setGroup(OFGroup.of(group.groupId().id())); |
| 218 | actions.add(groupBuilder.build()); |
| 219 | break; |
| 220 | default: |
| 221 | log.warn("Instruction type {} not yet implemented.", i.type()); |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 222 | } |
| 223 | } |
| 224 | |
| 225 | return actions; |
| 226 | } |
| 227 | |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 228 | private OFInstruction buildTableGoto(Instructions.TableTypeTransition i) { |
| 229 | OFInstruction instruction = factory().instructions().gotoTable( |
| 230 | TableId.of(getTableType(i.tableType()).ordinal())); |
| 231 | return instruction; |
| 232 | } |
| 233 | |
| 234 | // FIXME: this has to go as well perhaps when we implement the SelectorService. |
| 235 | private OpenFlowSwitch.TableType getTableType(FlowRule.Type type) { |
| 236 | switch (type) { |
| 237 | |
| 238 | case DEFAULT: |
| 239 | return OpenFlowSwitch.TableType.NONE; |
| 240 | case IP: |
| 241 | return OpenFlowSwitch.TableType.IP; |
| 242 | case MPLS: |
| 243 | return OpenFlowSwitch.TableType.MPLS; |
| 244 | case ACL: |
| 245 | return OpenFlowSwitch.TableType.ACL; |
| 246 | case VLAN_MPLS: |
| 247 | return OpenFlowSwitch.TableType.VLAN_MPLS; |
| 248 | case VLAN: |
| 249 | return OpenFlowSwitch.TableType.VLAN; |
| 250 | case ETHER: |
| 251 | return OpenFlowSwitch.TableType.ETHER; |
| 252 | case COS: |
| 253 | return OpenFlowSwitch.TableType.COS; |
| 254 | default: |
| 255 | return OpenFlowSwitch.TableType.NONE; |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 260 | private OFAction buildL0Modification(Instruction i) { |
| 261 | L0ModificationInstruction l0m = (L0ModificationInstruction) i; |
| 262 | switch (l0m.subtype()) { |
| 263 | case LAMBDA: |
| 264 | ModLambdaInstruction ml = (ModLambdaInstruction) i; |
| 265 | return factory().actions().circuit(factory().oxms().ochSigidBasic( |
| 266 | new CircuitSignalID((byte) 1, (byte) 2, ml.lambda(), (short) 1))); |
| 267 | default: |
| 268 | log.warn("Unimplemented action type {}.", l0m.subtype()); |
| 269 | break; |
| 270 | } |
| 271 | return null; |
| 272 | } |
| 273 | |
| 274 | private OFAction buildL2Modification(Instruction i) { |
| 275 | L2ModificationInstruction l2m = (L2ModificationInstruction) i; |
| 276 | ModEtherInstruction eth; |
| 277 | OFOxm<?> oxm = null; |
| 278 | switch (l2m.subtype()) { |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 279 | case ETH_DST: |
| 280 | eth = (ModEtherInstruction) l2m; |
| 281 | oxm = factory().oxms().ethDst(MacAddress.of(eth.mac().toLong())); |
| 282 | break; |
| 283 | case ETH_SRC: |
| 284 | eth = (ModEtherInstruction) l2m; |
| 285 | oxm = factory().oxms().ethSrc(MacAddress.of(eth.mac().toLong())); |
| 286 | break; |
| 287 | case VLAN_ID: |
| 288 | ModVlanIdInstruction vlanId = (ModVlanIdInstruction) l2m; |
| 289 | oxm = factory().oxms().vlanVid(OFVlanVidMatch.ofVlan(vlanId.vlanId().toShort())); |
| 290 | break; |
| 291 | case VLAN_PCP: |
| 292 | ModVlanPcpInstruction vlanPcp = (ModVlanPcpInstruction) l2m; |
| 293 | oxm = factory().oxms().vlanPcp(VlanPcp.of(vlanPcp.vlanPcp())); |
| 294 | break; |
| 295 | case MPLS_PUSH: |
| 296 | PushHeaderInstructions pushHeaderInstructions = |
| 297 | (PushHeaderInstructions) l2m; |
| 298 | return factory().actions().pushMpls(EthType.of(pushHeaderInstructions |
Yuta HIGUCHI | 32a53c5 | 2015-02-08 01:25:40 -0800 | [diff] [blame] | 299 | .ethernetType())); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 300 | case MPLS_POP: |
| 301 | PushHeaderInstructions popHeaderInstructions = |
| 302 | (PushHeaderInstructions) l2m; |
| 303 | return factory().actions().popMpls(EthType.of(popHeaderInstructions |
Yuta HIGUCHI | 32a53c5 | 2015-02-08 01:25:40 -0800 | [diff] [blame] | 304 | .ethernetType())); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 305 | case MPLS_LABEL: |
| 306 | ModMplsLabelInstruction mplsLabel = |
| 307 | (ModMplsLabelInstruction) l2m; |
| 308 | oxm = factory().oxms().mplsLabel(U32.of(mplsLabel.label() |
| 309 | .longValue())); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 310 | break; |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 311 | case DEC_MPLS_TTL: |
| 312 | return factory().actions().decMplsTtl(); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 313 | default: |
| 314 | log.warn("Unimplemented action type {}.", l2m.subtype()); |
| 315 | break; |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | if (oxm != null) { |
| 319 | return factory().actions().buildSetField().setField(oxm).build(); |
| 320 | } |
| 321 | return null; |
| 322 | } |
| 323 | |
| 324 | private OFAction buildL3Modification(Instruction i) { |
| 325 | L3ModificationInstruction l3m = (L3ModificationInstruction) i; |
| 326 | ModIPInstruction ip; |
Pavlin Radoslavov | 23e398d | 2014-11-05 15:17:57 -0800 | [diff] [blame] | 327 | Ip4Address ip4; |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 328 | Ip6Address ip6; |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 329 | OFOxm<?> oxm = null; |
| 330 | switch (l3m.subtype()) { |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 331 | case IPV4_SRC: |
| 332 | ip = (ModIPInstruction) i; |
| 333 | ip4 = ip.ip().getIp4Address(); |
| 334 | oxm = factory().oxms().ipv4Src(IPv4Address.of(ip4.toInt())); |
| 335 | break; |
| 336 | case IPV4_DST: |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 337 | ip = (ModIPInstruction) i; |
Pavlin Radoslavov | 23e398d | 2014-11-05 15:17:57 -0800 | [diff] [blame] | 338 | ip4 = ip.ip().getIp4Address(); |
| 339 | oxm = factory().oxms().ipv4Dst(IPv4Address.of(ip4.toInt())); |
Ray Milkey | 241b96a | 2014-11-17 13:08:20 -0800 | [diff] [blame] | 340 | break; |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 341 | case IPV6_SRC: |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 342 | ip = (ModIPInstruction) i; |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 343 | ip6 = ip.ip().getIp6Address(); |
| 344 | oxm = factory().oxms().ipv6Src(IPv6Address.of(ip6.toOctets())); |
| 345 | break; |
| 346 | case IPV6_DST: |
| 347 | ip = (ModIPInstruction) i; |
| 348 | ip6 = ip.ip().getIp6Address(); |
| 349 | oxm = factory().oxms().ipv6Dst(IPv6Address.of(ip6.toOctets())); |
| 350 | break; |
| 351 | case IPV6_FLABEL: |
| 352 | ModIPv6FlowLabelInstruction flowLabelInstruction = |
| 353 | (ModIPv6FlowLabelInstruction) i; |
| 354 | int flowLabel = flowLabelInstruction.flowLabel(); |
| 355 | oxm = factory().oxms().ipv6Flabel(IPv6FlowLabel.of(flowLabel)); |
Ray Milkey | 241b96a | 2014-11-17 13:08:20 -0800 | [diff] [blame] | 356 | break; |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 357 | case DEC_TTL: |
| 358 | return factory().actions().decNwTtl(); |
| 359 | case TTL_IN: |
| 360 | return factory().actions().copyTtlIn(); |
| 361 | case TTL_OUT: |
| 362 | return factory().actions().copyTtlOut(); |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 363 | default: |
| 364 | log.warn("Unimplemented action type {}.", l3m.subtype()); |
| 365 | break; |
| 366 | } |
| 367 | |
| 368 | if (oxm != null) { |
| 369 | return factory().actions().buildSetField().setField(oxm).build(); |
| 370 | } |
| 371 | return null; |
| 372 | } |
| 373 | |
| 374 | } |