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