Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 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 | |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 18 | import com.google.common.collect.Lists; |
Jonathan Hart | 29afca3 | 2015-01-20 18:17:39 -0800 | [diff] [blame] | 19 | import org.onlab.packet.Ip4Address; |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 20 | import org.onlab.packet.Ip6Address; |
Charles M.C. Chan | fe42181 | 2015-01-12 18:20:51 +0800 | [diff] [blame] | 21 | import org.onosproject.net.PortNumber; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 22 | import org.onosproject.net.flow.FlowRule; |
| 23 | import org.onosproject.net.flow.TrafficTreatment; |
| 24 | import org.onosproject.net.flow.instructions.Instruction; |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 25 | import org.onosproject.net.flow.instructions.Instructions; |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 26 | import org.onosproject.net.flow.instructions.Instructions.GroupInstruction; |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 27 | import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 28 | import org.onosproject.net.flow.instructions.L0ModificationInstruction; |
| 29 | import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModLambdaInstruction; |
| 30 | import org.onosproject.net.flow.instructions.L2ModificationInstruction; |
| 31 | import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction; |
Jonathan Hart | 29afca3 | 2015-01-20 18:17:39 -0800 | [diff] [blame] | 32 | import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsLabelInstruction; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 33 | import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction; |
| 34 | import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanPcpInstruction; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 35 | import org.onosproject.net.flow.instructions.L2ModificationInstruction.PushHeaderInstructions; |
| 36 | import org.onosproject.net.flow.instructions.L3ModificationInstruction; |
| 37 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction; |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 38 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction; |
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 | |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 77 | private final Logger log = LoggerFactory.getLogger(getClass()); |
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(); |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 98 | List<OFAction> deferredActions = buildActions(treatment.deferred()); |
| 99 | List<OFAction> immediateActions = buildActions(treatment.immediate()); |
| 100 | List<OFInstruction> instructions = Lists.newLinkedList(); |
Saurav Das | cbe6de3 | 2015-03-01 18:30:46 -0800 | [diff] [blame] | 101 | |
Jonathan Hart | d4a8bba | 2014-10-28 12:44:20 -0700 | [diff] [blame] | 102 | |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 103 | if (immediateActions.size() > 0) { |
| 104 | instructions.add(factory().instructions().applyActions(immediateActions)); |
| 105 | } |
| 106 | if (treatment.clearedDeferred()) { |
| 107 | instructions.add(factory().instructions().clearActions()); |
| 108 | } |
| 109 | if (deferredActions.size() > 0) { |
| 110 | instructions.add(factory().instructions().writeActions(deferredActions)); |
| 111 | } |
| 112 | if (treatment.tableTransition() != null) { |
| 113 | instructions.add(buildTableGoto(treatment.tableTransition())); |
Saurav Das | cbe6de3 | 2015-03-01 18:30:46 -0800 | [diff] [blame] | 114 | } |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 115 | |
| 116 | long cookie = flowRule().id().value(); |
| 117 | |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 118 | OFFlowAdd fm = factory().buildFlowAdd() |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 119 | .setXid(xid) |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 120 | .setCookie(U64.of(cookie)) |
| 121 | .setBufferId(OFBufferId.NO_BUFFER) |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 122 | .setInstructions(instructions) |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 123 | .setMatch(match) |
| 124 | .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM)) |
| 125 | .setPriority(flowRule().priority()) |
alshabib | 08d9898 | 2015-04-21 16:25:50 -0700 | [diff] [blame] | 126 | .setTableId(TableId.of(flowRule().tableId())) |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 127 | .build(); |
| 128 | |
| 129 | return fm; |
| 130 | } |
| 131 | |
| 132 | @Override |
| 133 | public OFFlowMod buildFlowMod() { |
| 134 | Match match = buildMatch(); |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 135 | List<OFAction> deferredActions = buildActions(treatment.deferred()); |
| 136 | List<OFAction> immediateActions = buildActions(treatment.immediate()); |
| 137 | List<OFInstruction> instructions = Lists.newLinkedList(); |
Jonathan Hart | eda3387 | 2015-02-18 10:22:32 -0800 | [diff] [blame] | 138 | |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 139 | |
| 140 | if (immediateActions.size() > 0) { |
| 141 | instructions.add(factory().instructions().applyActions(immediateActions)); |
| 142 | } |
| 143 | if (treatment.clearedDeferred()) { |
| 144 | instructions.add(factory().instructions().clearActions()); |
| 145 | } |
| 146 | if (deferredActions.size() > 0) { |
| 147 | instructions.add(factory().instructions().writeActions(deferredActions)); |
| 148 | } |
| 149 | if (treatment.tableTransition() != null) { |
| 150 | instructions.add(buildTableGoto(treatment.tableTransition())); |
Saurav Das | cbe6de3 | 2015-03-01 18:30:46 -0800 | [diff] [blame] | 151 | } |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 152 | |
| 153 | long cookie = flowRule().id().value(); |
| 154 | |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 155 | OFFlowMod fm = factory().buildFlowModify() |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 156 | .setXid(xid) |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 157 | .setCookie(U64.of(cookie)) |
| 158 | .setBufferId(OFBufferId.NO_BUFFER) |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 159 | .setInstructions(instructions) |
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()) |
alshabib | 08d9898 | 2015-04-21 16:25:50 -0700 | [diff] [blame] | 163 | .setTableId(TableId.of(flowRule().tableId())) |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 164 | .build(); |
| 165 | |
| 166 | return fm; |
| 167 | } |
| 168 | |
| 169 | @Override |
| 170 | public OFFlowDelete buildFlowDel() { |
| 171 | Match match = buildMatch(); |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 172 | |
| 173 | long cookie = flowRule().id().value(); |
| 174 | |
| 175 | OFFlowDelete fm = factory().buildFlowDelete() |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 176 | .setXid(xid) |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 177 | .setCookie(U64.of(cookie)) |
| 178 | .setBufferId(OFBufferId.NO_BUFFER) |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 179 | .setMatch(match) |
| 180 | .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM)) |
| 181 | .setPriority(flowRule().priority()) |
alshabib | 08d9898 | 2015-04-21 16:25:50 -0700 | [diff] [blame] | 182 | .setTableId(TableId.of(flowRule().tableId())) |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 183 | .build(); |
| 184 | |
| 185 | return fm; |
| 186 | } |
| 187 | |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 188 | private List<OFAction> buildActions(List<Instruction> treatments) { |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 189 | List<OFAction> actions = new LinkedList<>(); |
Saurav Das | cbe6de3 | 2015-03-01 18:30:46 -0800 | [diff] [blame] | 190 | boolean tableFound = false; |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 191 | if (treatment == null) { |
| 192 | return actions; |
| 193 | } |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 194 | for (Instruction i : treatments) { |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 195 | switch (i.type()) { |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 196 | case DROP: |
Sho SHIMIZU | b35ed36 | 2015-04-28 11:05:19 -0700 | [diff] [blame^] | 197 | return Collections.emptyList(); |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 198 | case L0MODIFICATION: |
| 199 | actions.add(buildL0Modification(i)); |
| 200 | break; |
| 201 | case L2MODIFICATION: |
| 202 | actions.add(buildL2Modification(i)); |
| 203 | break; |
| 204 | case L3MODIFICATION: |
| 205 | actions.add(buildL3Modification(i)); |
| 206 | break; |
| 207 | case OUTPUT: |
| 208 | OutputInstruction out = (OutputInstruction) i; |
| 209 | OFActionOutput.Builder action = factory().actions().buildOutput() |
| 210 | .setPort(OFPort.of((int) out.port().toLong())); |
| 211 | if (out.port().equals(PortNumber.CONTROLLER)) { |
| 212 | action.setMaxLen(OFPCML_NO_BUFFER); |
| 213 | } |
| 214 | actions.add(action.build()); |
| 215 | break; |
| 216 | case GROUP: |
| 217 | GroupInstruction group = (GroupInstruction) i; |
| 218 | OFActionGroup.Builder groupBuilder = factory().actions().buildGroup() |
| 219 | .setGroup(OFGroup.of(group.groupId().id())); |
| 220 | actions.add(groupBuilder.build()); |
| 221 | break; |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 222 | case TABLE: |
| 223 | //FIXME: should not occur here. |
Saurav Das | cbe6de3 | 2015-03-01 18:30:46 -0800 | [diff] [blame] | 224 | tableFound = true; |
alshabib | 1058080 | 2015-02-18 18:30:33 -0800 | [diff] [blame] | 225 | break; |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 226 | default: |
| 227 | log.warn("Instruction type {} not yet implemented.", i.type()); |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 228 | } |
| 229 | } |
Saurav Das | cbe6de3 | 2015-03-01 18:30:46 -0800 | [diff] [blame] | 230 | if (tableFound && actions.isEmpty()) { |
| 231 | // handles the case where there are no actions, but there is |
| 232 | // a goto instruction for the next table |
| 233 | return null; |
| 234 | } |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 235 | return actions; |
| 236 | } |
| 237 | |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 238 | private OFInstruction buildTableGoto(Instructions.TableTypeTransition i) { |
| 239 | OFInstruction instruction = factory().instructions().gotoTable( |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 240 | TableId.of(i.tableId())); |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 241 | return instruction; |
| 242 | } |
| 243 | |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 244 | private OFAction buildL0Modification(Instruction i) { |
| 245 | L0ModificationInstruction l0m = (L0ModificationInstruction) i; |
| 246 | switch (l0m.subtype()) { |
| 247 | case LAMBDA: |
| 248 | ModLambdaInstruction ml = (ModLambdaInstruction) i; |
| 249 | return factory().actions().circuit(factory().oxms().ochSigidBasic( |
| 250 | new CircuitSignalID((byte) 1, (byte) 2, ml.lambda(), (short) 1))); |
| 251 | default: |
| 252 | log.warn("Unimplemented action type {}.", l0m.subtype()); |
| 253 | break; |
| 254 | } |
| 255 | return null; |
| 256 | } |
| 257 | |
| 258 | private OFAction buildL2Modification(Instruction i) { |
| 259 | L2ModificationInstruction l2m = (L2ModificationInstruction) i; |
| 260 | ModEtherInstruction eth; |
| 261 | OFOxm<?> oxm = null; |
| 262 | switch (l2m.subtype()) { |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 263 | case ETH_DST: |
| 264 | eth = (ModEtherInstruction) l2m; |
| 265 | oxm = factory().oxms().ethDst(MacAddress.of(eth.mac().toLong())); |
| 266 | break; |
| 267 | case ETH_SRC: |
| 268 | eth = (ModEtherInstruction) l2m; |
| 269 | oxm = factory().oxms().ethSrc(MacAddress.of(eth.mac().toLong())); |
| 270 | break; |
| 271 | case VLAN_ID: |
| 272 | ModVlanIdInstruction vlanId = (ModVlanIdInstruction) l2m; |
| 273 | oxm = factory().oxms().vlanVid(OFVlanVidMatch.ofVlan(vlanId.vlanId().toShort())); |
| 274 | break; |
| 275 | case VLAN_PCP: |
| 276 | ModVlanPcpInstruction vlanPcp = (ModVlanPcpInstruction) l2m; |
| 277 | oxm = factory().oxms().vlanPcp(VlanPcp.of(vlanPcp.vlanPcp())); |
| 278 | break; |
| 279 | case MPLS_PUSH: |
| 280 | PushHeaderInstructions pushHeaderInstructions = |
| 281 | (PushHeaderInstructions) l2m; |
| 282 | return factory().actions().pushMpls(EthType.of(pushHeaderInstructions |
Yuta HIGUCHI | 32a53c5 | 2015-02-08 01:25:40 -0800 | [diff] [blame] | 283 | .ethernetType())); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 284 | case MPLS_POP: |
Jonathan Hart | 67fc097 | 2015-03-19 15:21:20 -0700 | [diff] [blame] | 285 | PushHeaderInstructions popHeaderInstructions = |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 286 | (PushHeaderInstructions) l2m; |
| 287 | return factory().actions().popMpls(EthType.of(popHeaderInstructions |
Yuta HIGUCHI | 32a53c5 | 2015-02-08 01:25:40 -0800 | [diff] [blame] | 288 | .ethernetType())); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 289 | case MPLS_LABEL: |
| 290 | ModMplsLabelInstruction mplsLabel = |
| 291 | (ModMplsLabelInstruction) l2m; |
| 292 | oxm = factory().oxms().mplsLabel(U32.of(mplsLabel.label() |
| 293 | .longValue())); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 294 | break; |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 295 | case DEC_MPLS_TTL: |
| 296 | return factory().actions().decMplsTtl(); |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 297 | case VLAN_POP: |
| 298 | return factory().actions().popVlan(); |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 299 | case VLAN_PUSH: |
| 300 | PushHeaderInstructions pushVlanInstruction = (PushHeaderInstructions) l2m; |
| 301 | return factory().actions().pushVlan( |
| 302 | EthType.of(pushVlanInstruction.ethernetType())); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 303 | default: |
| 304 | log.warn("Unimplemented action type {}.", l2m.subtype()); |
| 305 | break; |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | if (oxm != null) { |
| 309 | return factory().actions().buildSetField().setField(oxm).build(); |
| 310 | } |
| 311 | return null; |
| 312 | } |
| 313 | |
| 314 | private OFAction buildL3Modification(Instruction i) { |
| 315 | L3ModificationInstruction l3m = (L3ModificationInstruction) i; |
| 316 | ModIPInstruction ip; |
Pavlin Radoslavov | 23e398d | 2014-11-05 15:17:57 -0800 | [diff] [blame] | 317 | Ip4Address ip4; |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 318 | Ip6Address ip6; |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 319 | OFOxm<?> oxm = null; |
| 320 | switch (l3m.subtype()) { |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 321 | case IPV4_SRC: |
| 322 | ip = (ModIPInstruction) i; |
| 323 | ip4 = ip.ip().getIp4Address(); |
| 324 | oxm = factory().oxms().ipv4Src(IPv4Address.of(ip4.toInt())); |
| 325 | break; |
| 326 | case IPV4_DST: |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 327 | ip = (ModIPInstruction) i; |
Pavlin Radoslavov | 23e398d | 2014-11-05 15:17:57 -0800 | [diff] [blame] | 328 | ip4 = ip.ip().getIp4Address(); |
| 329 | oxm = factory().oxms().ipv4Dst(IPv4Address.of(ip4.toInt())); |
Ray Milkey | 241b96a | 2014-11-17 13:08:20 -0800 | [diff] [blame] | 330 | break; |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 331 | case IPV6_SRC: |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 332 | ip = (ModIPInstruction) i; |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 333 | ip6 = ip.ip().getIp6Address(); |
| 334 | oxm = factory().oxms().ipv6Src(IPv6Address.of(ip6.toOctets())); |
| 335 | break; |
| 336 | case IPV6_DST: |
| 337 | ip = (ModIPInstruction) i; |
| 338 | ip6 = ip.ip().getIp6Address(); |
| 339 | oxm = factory().oxms().ipv6Dst(IPv6Address.of(ip6.toOctets())); |
| 340 | break; |
| 341 | case IPV6_FLABEL: |
| 342 | ModIPv6FlowLabelInstruction flowLabelInstruction = |
| 343 | (ModIPv6FlowLabelInstruction) i; |
| 344 | int flowLabel = flowLabelInstruction.flowLabel(); |
| 345 | oxm = factory().oxms().ipv6Flabel(IPv6FlowLabel.of(flowLabel)); |
Ray Milkey | 241b96a | 2014-11-17 13:08:20 -0800 | [diff] [blame] | 346 | break; |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 347 | case DEC_TTL: |
| 348 | return factory().actions().decNwTtl(); |
| 349 | case TTL_IN: |
| 350 | return factory().actions().copyTtlIn(); |
| 351 | case TTL_OUT: |
| 352 | return factory().actions().copyTtlOut(); |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 353 | default: |
| 354 | log.warn("Unimplemented action type {}.", l3m.subtype()); |
| 355 | break; |
| 356 | } |
| 357 | |
| 358 | if (oxm != null) { |
| 359 | return factory().actions().buildSetField().setField(oxm).build(); |
| 360 | } |
| 361 | return null; |
| 362 | } |
| 363 | |
| 364 | } |