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