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