blob: cc26575819fbd2bdcff614b8ca3270ba33afc12c [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 Open Networking Laboratory
Thomas Vachuska781d18b2014-10-27 10:31:25 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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 Vachuska781d18b2014-10-27 10:31:25 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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 Vachuska781d18b2014-10-27 10:31:25 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.provider.of.flow.impl;
Jonathan Hart86e59352014-10-22 10:42:16 -070017
alshabib346b5b32015-03-06 00:42:16 -080018import com.google.common.collect.Lists;
Jonathan Hart29afca32015-01-20 18:17:39 -080019import org.onlab.packet.Ip4Address;
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -080020import org.onlab.packet.Ip6Address;
Sho SHIMIZUe397ffe2015-05-12 16:24:23 -070021import org.onosproject.net.OchSignal;
Charles M.C. Chanfe421812015-01-12 18:20:51 +080022import org.onosproject.net.PortNumber;
Brian O'Connorabafb502014-12-02 22:26:20 -080023import org.onosproject.net.flow.FlowRule;
24import org.onosproject.net.flow.TrafficTreatment;
25import org.onosproject.net.flow.instructions.Instruction;
alshabib9af70072015-02-09 14:34:16 -080026import org.onosproject.net.flow.instructions.Instructions;
sangho8995ac52015-02-04 11:29:03 -080027import org.onosproject.net.flow.instructions.Instructions.GroupInstruction;
alshabib9af70072015-02-09 14:34:16 -080028import org.onosproject.net.flow.instructions.Instructions.OutputInstruction;
Brian O'Connorabafb502014-12-02 22:26:20 -080029import org.onosproject.net.flow.instructions.L0ModificationInstruction;
30import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModLambdaInstruction;
Sho SHIMIZUe397ffe2015-05-12 16:24:23 -070031import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModOchSignalInstruction;
Brian O'Connorabafb502014-12-02 22:26:20 -080032import org.onosproject.net.flow.instructions.L2ModificationInstruction;
33import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction;
Saurav Das73a7dd42015-08-19 22:20:31 -070034import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsBosInstruction;
Jonathan Hart29afca32015-01-20 18:17:39 -080035import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsLabelInstruction;
Brian O'Connorabafb502014-12-02 22:26:20 -080036import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction;
37import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanPcpInstruction;
Brian O'Connorabafb502014-12-02 22:26:20 -080038import org.onosproject.net.flow.instructions.L2ModificationInstruction.PushHeaderInstructions;
Hyunsun Moona08c5d02015-07-14 17:53:00 -070039import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModTunnelIdInstruction;
Brian O'Connorabafb502014-12-02 22:26:20 -080040import org.onosproject.net.flow.instructions.L3ModificationInstruction;
41import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -080042import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -070043import org.onosproject.net.flow.instructions.L4ModificationInstruction;
44import org.onosproject.net.flow.instructions.L4ModificationInstruction.ModTransportPortInstruction;
Jonathan Hart86e59352014-10-22 10:42:16 -070045import org.projectfloodlight.openflow.protocol.OFFactory;
46import org.projectfloodlight.openflow.protocol.OFFlowAdd;
47import org.projectfloodlight.openflow.protocol.OFFlowDelete;
48import org.projectfloodlight.openflow.protocol.OFFlowMod;
49import org.projectfloodlight.openflow.protocol.OFFlowModFlags;
50import org.projectfloodlight.openflow.protocol.action.OFAction;
sangho8995ac52015-02-04 11:29:03 -080051import org.projectfloodlight.openflow.protocol.action.OFActionGroup;
Charles M.C. Chanfe421812015-01-12 18:20:51 +080052import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
alshabib9af70072015-02-09 14:34:16 -080053import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
Jonathan Hart86e59352014-10-22 10:42:16 -070054import org.projectfloodlight.openflow.protocol.match.Match;
55import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
56import org.projectfloodlight.openflow.types.CircuitSignalID;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -080057import org.projectfloodlight.openflow.types.EthType;
Jonathan Hart86e59352014-10-22 10:42:16 -070058import org.projectfloodlight.openflow.types.IPv4Address;
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -080059import org.projectfloodlight.openflow.types.IPv6Address;
60import org.projectfloodlight.openflow.types.IPv6FlowLabel;
Jonathan Hart86e59352014-10-22 10:42:16 -070061import org.projectfloodlight.openflow.types.MacAddress;
Saurav Das73a7dd42015-08-19 22:20:31 -070062import org.projectfloodlight.openflow.types.OFBooleanValue;
Jonathan Hart86e59352014-10-22 10:42:16 -070063import org.projectfloodlight.openflow.types.OFBufferId;
sangho8995ac52015-02-04 11:29:03 -080064import org.projectfloodlight.openflow.types.OFGroup;
Jonathan Hart86e59352014-10-22 10:42:16 -070065import org.projectfloodlight.openflow.types.OFPort;
66import org.projectfloodlight.openflow.types.OFVlanVidMatch;
alshabib9af70072015-02-09 14:34:16 -080067import org.projectfloodlight.openflow.types.TableId;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -070068import org.projectfloodlight.openflow.types.TransportPort;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -080069import org.projectfloodlight.openflow.types.U32;
Jonathan Hart86e59352014-10-22 10:42:16 -070070import org.projectfloodlight.openflow.types.U64;
71import org.projectfloodlight.openflow.types.VlanPcp;
72import org.slf4j.Logger;
73import org.slf4j.LoggerFactory;
74
Jonathan Hart29afca32015-01-20 18:17:39 -080075import java.util.Collections;
76import java.util.LinkedList;
77import java.util.List;
78import java.util.Optional;
79
Jonathan Hart86e59352014-10-22 10:42:16 -070080/**
81 * Flow mod builder for OpenFlow 1.3+.
82 */
83public class FlowModBuilderVer13 extends FlowModBuilder {
84
alshabib10580802015-02-18 18:30:33 -080085 private final Logger log = LoggerFactory.getLogger(getClass());
Charles M.C. Chanfe421812015-01-12 18:20:51 +080086 private static final int OFPCML_NO_BUFFER = 0xffff;
Jonathan Hart86e59352014-10-22 10:42:16 -070087
88 private final TrafficTreatment treatment;
89
90 /**
91 * Constructor for a flow mod builder for OpenFlow 1.3.
92 *
93 * @param flowRule the flow rule to transform into a flow mod
94 * @param factory the OpenFlow factory to use to build the flow mod
Pavlin Radoslavov119fd5c2014-11-25 19:08:19 -080095 * @param xid the transaction ID
Jonathan Hart86e59352014-10-22 10:42:16 -070096 */
Brian O'Connor427a1762014-11-19 18:40:32 -080097 protected FlowModBuilderVer13(FlowRule flowRule, OFFactory factory, Optional<Long> xid) {
98 super(flowRule, factory, xid);
Jonathan Hart86e59352014-10-22 10:42:16 -070099
100 this.treatment = flowRule.treatment();
101 }
102
103 @Override
104 public OFFlowAdd buildFlowAdd() {
105 Match match = buildMatch();
alshabib346b5b32015-03-06 00:42:16 -0800106 List<OFAction> deferredActions = buildActions(treatment.deferred());
107 List<OFAction> immediateActions = buildActions(treatment.immediate());
108 List<OFInstruction> instructions = Lists.newLinkedList();
Saurav Dascbe6de32015-03-01 18:30:46 -0800109
Jonathan Hartd4a8bba2014-10-28 12:44:20 -0700110
alshabib346b5b32015-03-06 00:42:16 -0800111 if (treatment.clearedDeferred()) {
112 instructions.add(factory().instructions().clearActions());
113 }
sangho1e575652015-05-14 00:39:53 -0700114 if (immediateActions.size() > 0) {
115 instructions.add(factory().instructions().applyActions(immediateActions));
116 }
alshabib346b5b32015-03-06 00:42:16 -0800117 if (deferredActions.size() > 0) {
118 instructions.add(factory().instructions().writeActions(deferredActions));
119 }
120 if (treatment.tableTransition() != null) {
121 instructions.add(buildTableGoto(treatment.tableTransition()));
Saurav Dascbe6de32015-03-01 18:30:46 -0800122 }
Saurav Das86af8f12015-05-25 23:55:33 -0700123 if (treatment.writeMetadata() != null) {
124 instructions.add(buildMetadata(treatment.writeMetadata()));
125 }
chengfane264bef2015-09-28 08:38:19 +0800126 if (treatment.metered() != null) {
127 instructions.add(buildMeter(treatment.metered()));
128 }
Jonathan Hart86e59352014-10-22 10:42:16 -0700129
130 long cookie = flowRule().id().value();
131
Jonathan Hart86e59352014-10-22 10:42:16 -0700132 OFFlowAdd fm = factory().buildFlowAdd()
Brian O'Connor427a1762014-11-19 18:40:32 -0800133 .setXid(xid)
Jonathan Hart86e59352014-10-22 10:42:16 -0700134 .setCookie(U64.of(cookie))
135 .setBufferId(OFBufferId.NO_BUFFER)
alshabib9af70072015-02-09 14:34:16 -0800136 .setInstructions(instructions)
Jonathan Hart86e59352014-10-22 10:42:16 -0700137 .setMatch(match)
138 .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM))
139 .setPriority(flowRule().priority())
alshabib08d98982015-04-21 16:25:50 -0700140 .setTableId(TableId.of(flowRule().tableId()))
Jonathan Hart86e59352014-10-22 10:42:16 -0700141 .build();
142
143 return fm;
144 }
145
146 @Override
147 public OFFlowMod buildFlowMod() {
148 Match match = buildMatch();
alshabib346b5b32015-03-06 00:42:16 -0800149 List<OFAction> deferredActions = buildActions(treatment.deferred());
150 List<OFAction> immediateActions = buildActions(treatment.immediate());
151 List<OFInstruction> instructions = Lists.newLinkedList();
Jonathan Harteda33872015-02-18 10:22:32 -0800152
alshabib346b5b32015-03-06 00:42:16 -0800153
154 if (immediateActions.size() > 0) {
155 instructions.add(factory().instructions().applyActions(immediateActions));
156 }
157 if (treatment.clearedDeferred()) {
158 instructions.add(factory().instructions().clearActions());
159 }
160 if (deferredActions.size() > 0) {
161 instructions.add(factory().instructions().writeActions(deferredActions));
162 }
163 if (treatment.tableTransition() != null) {
164 instructions.add(buildTableGoto(treatment.tableTransition()));
Saurav Dascbe6de32015-03-01 18:30:46 -0800165 }
Saurav Das86af8f12015-05-25 23:55:33 -0700166 if (treatment.writeMetadata() != null) {
167 instructions.add(buildMetadata(treatment.writeMetadata()));
168 }
alshabib10c810b2015-08-18 16:59:04 -0700169 if (treatment.metered() != null) {
170 instructions.add(buildMeter(treatment.metered()));
171 }
Jonathan Hart86e59352014-10-22 10:42:16 -0700172
173 long cookie = flowRule().id().value();
174
Jonathan Hart86e59352014-10-22 10:42:16 -0700175 OFFlowMod fm = factory().buildFlowModify()
Brian O'Connor427a1762014-11-19 18:40:32 -0800176 .setXid(xid)
Jonathan Hart86e59352014-10-22 10:42:16 -0700177 .setCookie(U64.of(cookie))
178 .setBufferId(OFBufferId.NO_BUFFER)
alshabib9af70072015-02-09 14:34:16 -0800179 .setInstructions(instructions)
Jonathan Hart86e59352014-10-22 10:42:16 -0700180 .setMatch(match)
181 .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM))
182 .setPriority(flowRule().priority())
alshabib08d98982015-04-21 16:25:50 -0700183 .setTableId(TableId.of(flowRule().tableId()))
Jonathan Hart86e59352014-10-22 10:42:16 -0700184 .build();
185
186 return fm;
187 }
188
189 @Override
190 public OFFlowDelete buildFlowDel() {
191 Match match = buildMatch();
Jonathan Hart86e59352014-10-22 10:42:16 -0700192
193 long cookie = flowRule().id().value();
194
195 OFFlowDelete fm = factory().buildFlowDelete()
Brian O'Connor427a1762014-11-19 18:40:32 -0800196 .setXid(xid)
Jonathan Hart86e59352014-10-22 10:42:16 -0700197 .setCookie(U64.of(cookie))
198 .setBufferId(OFBufferId.NO_BUFFER)
Jonathan Hart86e59352014-10-22 10:42:16 -0700199 .setMatch(match)
200 .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM))
201 .setPriority(flowRule().priority())
alshabib08d98982015-04-21 16:25:50 -0700202 .setTableId(TableId.of(flowRule().tableId()))
Jonathan Hart86e59352014-10-22 10:42:16 -0700203 .build();
204
205 return fm;
206 }
207
alshabib346b5b32015-03-06 00:42:16 -0800208 private List<OFAction> buildActions(List<Instruction> treatments) {
Jonathan Hart86e59352014-10-22 10:42:16 -0700209 if (treatment == null) {
Sho SHIMIZU6601dd72015-05-11 19:00:29 -0700210 return Collections.emptyList();
Jonathan Hart86e59352014-10-22 10:42:16 -0700211 }
Sho SHIMIZU6601dd72015-05-11 19:00:29 -0700212
213 boolean tableFound = false;
214 List<OFAction> actions = new LinkedList<>();
alshabib346b5b32015-03-06 00:42:16 -0800215 for (Instruction i : treatments) {
Jonathan Hart86e59352014-10-22 10:42:16 -0700216 switch (i.type()) {
alshabib9af70072015-02-09 14:34:16 -0800217 case DROP:
Charles Chan7efabeb2015-09-28 15:12:19 -0700218 case NOACTION:
Sho SHIMIZUb35ed362015-04-28 11:05:19 -0700219 return Collections.emptyList();
alshabib9af70072015-02-09 14:34:16 -0800220 case L0MODIFICATION:
221 actions.add(buildL0Modification(i));
222 break;
223 case L2MODIFICATION:
224 actions.add(buildL2Modification(i));
225 break;
226 case L3MODIFICATION:
227 actions.add(buildL3Modification(i));
228 break;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700229 case L4MODIFICATION:
230 actions.add(buildL4Modification(i));
231 break;
alshabib9af70072015-02-09 14:34:16 -0800232 case OUTPUT:
233 OutputInstruction out = (OutputInstruction) i;
234 OFActionOutput.Builder action = factory().actions().buildOutput()
235 .setPort(OFPort.of((int) out.port().toLong()));
236 if (out.port().equals(PortNumber.CONTROLLER)) {
237 action.setMaxLen(OFPCML_NO_BUFFER);
238 }
239 actions.add(action.build());
240 break;
241 case GROUP:
242 GroupInstruction group = (GroupInstruction) i;
243 OFActionGroup.Builder groupBuilder = factory().actions().buildGroup()
244 .setGroup(OFGroup.of(group.groupId().id()));
245 actions.add(groupBuilder.build());
246 break;
alshabib10580802015-02-18 18:30:33 -0800247 case TABLE:
248 //FIXME: should not occur here.
Saurav Dascbe6de32015-03-01 18:30:46 -0800249 tableFound = true;
alshabib10580802015-02-18 18:30:33 -0800250 break;
alshabib9af70072015-02-09 14:34:16 -0800251 default:
252 log.warn("Instruction type {} not yet implemented.", i.type());
Jonathan Hart86e59352014-10-22 10:42:16 -0700253 }
254 }
Saurav Dascbe6de32015-03-01 18:30:46 -0800255 if (tableFound && actions.isEmpty()) {
256 // handles the case where there are no actions, but there is
257 // a goto instruction for the next table
Sho SHIMIZU6601dd72015-05-11 19:00:29 -0700258 return Collections.emptyList();
Saurav Dascbe6de32015-03-01 18:30:46 -0800259 }
Jonathan Hart86e59352014-10-22 10:42:16 -0700260 return actions;
261 }
262
alshabib9af70072015-02-09 14:34:16 -0800263 private OFInstruction buildTableGoto(Instructions.TableTypeTransition i) {
264 OFInstruction instruction = factory().instructions().gotoTable(
alshabibd17abc22015-04-21 18:26:35 -0700265 TableId.of(i.tableId()));
alshabib9af70072015-02-09 14:34:16 -0800266 return instruction;
267 }
268
Saurav Das86af8f12015-05-25 23:55:33 -0700269 private OFInstruction buildMetadata(Instructions.MetadataInstruction m) {
270 OFInstruction instruction = factory().instructions().writeMetadata(
271 U64.of(m.metadata()), U64.of(m.metadataMask()));
272 return instruction;
273 }
274
alshabib10c810b2015-08-18 16:59:04 -0700275 private OFInstruction buildMeter(Instructions.MeterInstruction metered) {
276 return factory().instructions().meter(metered.meterId().id());
277 }
278
279
Jonathan Hart86e59352014-10-22 10:42:16 -0700280 private OFAction buildL0Modification(Instruction i) {
281 L0ModificationInstruction l0m = (L0ModificationInstruction) i;
282 switch (l0m.subtype()) {
Sho SHIMIZU5cd7ce92015-05-11 19:10:38 -0700283 case LAMBDA:
Sho SHIMIZUe397ffe2015-05-12 16:24:23 -0700284 return buildModLambdaInstruction((ModLambdaInstruction) i);
285 case OCH:
286 try {
287 return buildModOchSignalInstruction((ModOchSignalInstruction) i);
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700288 } catch (NoMappingFoundException e) {
Sho SHIMIZUe397ffe2015-05-12 16:24:23 -0700289 log.warn(e.getMessage());
290 break;
291 }
Sho SHIMIZU5cd7ce92015-05-11 19:10:38 -0700292 default:
293 log.warn("Unimplemented action type {}.", l0m.subtype());
294 break;
Jonathan Hart86e59352014-10-22 10:42:16 -0700295 }
296 return null;
297 }
298
Sho SHIMIZUe397ffe2015-05-12 16:24:23 -0700299 private OFAction buildModLambdaInstruction(ModLambdaInstruction instruction) {
300 return factory().actions().circuit(factory().oxms().ochSigidBasic(
301 new CircuitSignalID((byte) 1, (byte) 2, instruction.lambda(), (short) 1)));
302 }
303
304 private OFAction buildModOchSignalInstruction(ModOchSignalInstruction instruction) {
305 OchSignal signal = instruction.lambda();
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700306 byte gridType = OpenFlowValueMapper.lookupGridType(signal.gridType());
307 byte channelSpacing = OpenFlowValueMapper.lookupChannelSpacing(signal.channelSpacing());
Sho SHIMIZUe397ffe2015-05-12 16:24:23 -0700308
309 return factory().actions().circuit(factory().oxms().ochSigidBasic(
310 new CircuitSignalID(gridType, channelSpacing,
311 (short) signal.spacingMultiplier(), (short) signal.slotGranularity())
312 ));
313 }
314
Jonathan Hart86e59352014-10-22 10:42:16 -0700315 private OFAction buildL2Modification(Instruction i) {
316 L2ModificationInstruction l2m = (L2ModificationInstruction) i;
317 ModEtherInstruction eth;
318 OFOxm<?> oxm = null;
319 switch (l2m.subtype()) {
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800320 case ETH_DST:
321 eth = (ModEtherInstruction) l2m;
322 oxm = factory().oxms().ethDst(MacAddress.of(eth.mac().toLong()));
323 break;
324 case ETH_SRC:
325 eth = (ModEtherInstruction) l2m;
326 oxm = factory().oxms().ethSrc(MacAddress.of(eth.mac().toLong()));
327 break;
328 case VLAN_ID:
329 ModVlanIdInstruction vlanId = (ModVlanIdInstruction) l2m;
330 oxm = factory().oxms().vlanVid(OFVlanVidMatch.ofVlan(vlanId.vlanId().toShort()));
331 break;
332 case VLAN_PCP:
333 ModVlanPcpInstruction vlanPcp = (ModVlanPcpInstruction) l2m;
334 oxm = factory().oxms().vlanPcp(VlanPcp.of(vlanPcp.vlanPcp()));
335 break;
336 case MPLS_PUSH:
337 PushHeaderInstructions pushHeaderInstructions =
338 (PushHeaderInstructions) l2m;
339 return factory().actions().pushMpls(EthType.of(pushHeaderInstructions
alshabib7b808c52015-06-26 14:22:24 -0700340 .ethernetType().toShort()));
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800341 case MPLS_POP:
Jonathan Hart67fc0972015-03-19 15:21:20 -0700342 PushHeaderInstructions popHeaderInstructions =
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800343 (PushHeaderInstructions) l2m;
344 return factory().actions().popMpls(EthType.of(popHeaderInstructions
alshabib7b808c52015-06-26 14:22:24 -0700345 .ethernetType().toShort()));
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800346 case MPLS_LABEL:
347 ModMplsLabelInstruction mplsLabel =
348 (ModMplsLabelInstruction) l2m;
HIGUCHI Yuta04b49fc2015-08-28 09:58:58 -0700349 oxm = factory().oxms().mplsLabel(U32.of(mplsLabel.mplsLabel().toInt()));
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800350 break;
Saurav Das73a7dd42015-08-19 22:20:31 -0700351 case MPLS_BOS:
352 ModMplsBosInstruction mplsBos = (ModMplsBosInstruction) l2m;
353 oxm = factory().oxms()
354 .mplsBos(mplsBos.mplsBos() ? OFBooleanValue.TRUE
355 : OFBooleanValue.FALSE);
356 break;
sangho3f97a17d2015-01-29 22:56:29 -0800357 case DEC_MPLS_TTL:
358 return factory().actions().decMplsTtl();
Saurav Dasfbe25c52015-03-04 11:12:00 -0800359 case VLAN_POP:
360 return factory().actions().popVlan();
Jonathan Hart54b406b2015-03-06 16:24:14 -0800361 case VLAN_PUSH:
362 PushHeaderInstructions pushVlanInstruction = (PushHeaderInstructions) l2m;
363 return factory().actions().pushVlan(
alshabib7b808c52015-06-26 14:22:24 -0700364 EthType.of(pushVlanInstruction.ethernetType().toShort()));
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700365 case TUNNEL_ID:
366 ModTunnelIdInstruction tunnelId = (ModTunnelIdInstruction) l2m;
367 oxm = factory().oxms().tunnelId(U64.of(tunnelId.tunnelId()));
368 break;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800369 default:
370 log.warn("Unimplemented action type {}.", l2m.subtype());
371 break;
Jonathan Hart86e59352014-10-22 10:42:16 -0700372 }
373
374 if (oxm != null) {
375 return factory().actions().buildSetField().setField(oxm).build();
376 }
377 return null;
378 }
379
380 private OFAction buildL3Modification(Instruction i) {
381 L3ModificationInstruction l3m = (L3ModificationInstruction) i;
382 ModIPInstruction ip;
Pavlin Radoslavov23e398d2014-11-05 15:17:57 -0800383 Ip4Address ip4;
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800384 Ip6Address ip6;
Jonathan Hart86e59352014-10-22 10:42:16 -0700385 OFOxm<?> oxm = null;
386 switch (l3m.subtype()) {
Sho SHIMIZU5cd7ce92015-05-11 19:10:38 -0700387 case IPV4_SRC:
388 ip = (ModIPInstruction) i;
389 ip4 = ip.ip().getIp4Address();
390 oxm = factory().oxms().ipv4Src(IPv4Address.of(ip4.toInt()));
391 break;
392 case IPV4_DST:
393 ip = (ModIPInstruction) i;
394 ip4 = ip.ip().getIp4Address();
395 oxm = factory().oxms().ipv4Dst(IPv4Address.of(ip4.toInt()));
396 break;
397 case IPV6_SRC:
398 ip = (ModIPInstruction) i;
399 ip6 = ip.ip().getIp6Address();
400 oxm = factory().oxms().ipv6Src(IPv6Address.of(ip6.toOctets()));
401 break;
402 case IPV6_DST:
403 ip = (ModIPInstruction) i;
404 ip6 = ip.ip().getIp6Address();
405 oxm = factory().oxms().ipv6Dst(IPv6Address.of(ip6.toOctets()));
406 break;
407 case IPV6_FLABEL:
408 ModIPv6FlowLabelInstruction flowLabelInstruction =
409 (ModIPv6FlowLabelInstruction) i;
410 int flowLabel = flowLabelInstruction.flowLabel();
411 oxm = factory().oxms().ipv6Flabel(IPv6FlowLabel.of(flowLabel));
412 break;
413 case DEC_TTL:
414 return factory().actions().decNwTtl();
415 case TTL_IN:
416 return factory().actions().copyTtlIn();
417 case TTL_OUT:
418 return factory().actions().copyTtlOut();
419 default:
420 log.warn("Unimplemented action type {}.", l3m.subtype());
421 break;
Jonathan Hart86e59352014-10-22 10:42:16 -0700422 }
423
424 if (oxm != null) {
425 return factory().actions().buildSetField().setField(oxm).build();
426 }
427 return null;
428 }
429
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700430 private OFAction buildL4Modification(Instruction i) {
431 L4ModificationInstruction l4m = (L4ModificationInstruction) i;
432 ModTransportPortInstruction tp;
433 OFOxm<?> oxm = null;
434 switch (l4m.subtype()) {
435 case TCP_SRC:
436 tp = (ModTransportPortInstruction) l4m;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700437 oxm = factory().oxms().tcpSrc(TransportPort.of(tp.port().toInt()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700438 break;
439 case TCP_DST:
440 tp = (ModTransportPortInstruction) l4m;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700441 oxm = factory().oxms().tcpDst(TransportPort.of(tp.port().toInt()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700442 break;
443 case UDP_SRC:
444 tp = (ModTransportPortInstruction) l4m;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700445 oxm = factory().oxms().udpSrc(TransportPort.of(tp.port().toInt()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700446 break;
447 case UDP_DST:
448 tp = (ModTransportPortInstruction) l4m;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700449 oxm = factory().oxms().udpDst(TransportPort.of(tp.port().toInt()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700450 break;
451 default:
452 log.warn("Unimplemented action type {}.", l4m.subtype());
453 break;
454 }
455
456 if (oxm != null) {
457 return factory().actions().buildSetField().setField(oxm).build();
458 }
459 return null;
460 }
461
Jonathan Hart86e59352014-10-22 10:42:16 -0700462}