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