blob: 483eca979adc0299200ff5f8f2f980bee6726c67 [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;
Jonathan Hart29afca32015-01-20 18:17:39 -080034import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsLabelInstruction;
Brian O'Connorabafb502014-12-02 22:26:20 -080035import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction;
36import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanPcpInstruction;
Brian O'Connorabafb502014-12-02 22:26:20 -080037import org.onosproject.net.flow.instructions.L2ModificationInstruction.PushHeaderInstructions;
Hyunsun Moona08c5d02015-07-14 17:53:00 -070038import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModTunnelIdInstruction;
Brian O'Connorabafb502014-12-02 22:26:20 -080039import org.onosproject.net.flow.instructions.L3ModificationInstruction;
40import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -080041import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -070042import org.onosproject.net.flow.instructions.L4ModificationInstruction;
43import org.onosproject.net.flow.instructions.L4ModificationInstruction.ModTransportPortInstruction;
Jonathan Hart86e59352014-10-22 10:42:16 -070044import org.projectfloodlight.openflow.protocol.OFFactory;
45import org.projectfloodlight.openflow.protocol.OFFlowAdd;
46import org.projectfloodlight.openflow.protocol.OFFlowDelete;
47import org.projectfloodlight.openflow.protocol.OFFlowMod;
48import org.projectfloodlight.openflow.protocol.OFFlowModFlags;
49import org.projectfloodlight.openflow.protocol.action.OFAction;
sangho8995ac52015-02-04 11:29:03 -080050import org.projectfloodlight.openflow.protocol.action.OFActionGroup;
Charles M.C. Chanfe421812015-01-12 18:20:51 +080051import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
alshabib9af70072015-02-09 14:34:16 -080052import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
Jonathan Hart86e59352014-10-22 10:42:16 -070053import org.projectfloodlight.openflow.protocol.match.Match;
54import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
55import org.projectfloodlight.openflow.types.CircuitSignalID;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -080056import org.projectfloodlight.openflow.types.EthType;
Jonathan Hart86e59352014-10-22 10:42:16 -070057import org.projectfloodlight.openflow.types.IPv4Address;
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -080058import org.projectfloodlight.openflow.types.IPv6Address;
59import org.projectfloodlight.openflow.types.IPv6FlowLabel;
Jonathan Hart86e59352014-10-22 10:42:16 -070060import org.projectfloodlight.openflow.types.MacAddress;
61import org.projectfloodlight.openflow.types.OFBufferId;
sangho8995ac52015-02-04 11:29:03 -080062import org.projectfloodlight.openflow.types.OFGroup;
Jonathan Hart86e59352014-10-22 10:42:16 -070063import org.projectfloodlight.openflow.types.OFPort;
64import org.projectfloodlight.openflow.types.OFVlanVidMatch;
alshabib9af70072015-02-09 14:34:16 -080065import org.projectfloodlight.openflow.types.TableId;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -070066import org.projectfloodlight.openflow.types.TransportPort;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -080067import org.projectfloodlight.openflow.types.U32;
Jonathan Hart86e59352014-10-22 10:42:16 -070068import org.projectfloodlight.openflow.types.U64;
69import org.projectfloodlight.openflow.types.VlanPcp;
70import org.slf4j.Logger;
71import org.slf4j.LoggerFactory;
72
Jonathan Hart29afca32015-01-20 18:17:39 -080073import java.util.Collections;
74import java.util.LinkedList;
75import java.util.List;
76import java.util.Optional;
77
Jonathan Hart86e59352014-10-22 10:42:16 -070078/**
79 * Flow mod builder for OpenFlow 1.3+.
80 */
81public class FlowModBuilderVer13 extends FlowModBuilder {
82
alshabib10580802015-02-18 18:30:33 -080083 private final Logger log = LoggerFactory.getLogger(getClass());
Charles M.C. Chanfe421812015-01-12 18:20:51 +080084 private static final int OFPCML_NO_BUFFER = 0xffff;
Jonathan Hart86e59352014-10-22 10:42:16 -070085
86 private final TrafficTreatment treatment;
87
88 /**
89 * Constructor for a flow mod builder for OpenFlow 1.3.
90 *
91 * @param flowRule the flow rule to transform into a flow mod
92 * @param factory the OpenFlow factory to use to build the flow mod
Pavlin Radoslavov119fd5c2014-11-25 19:08:19 -080093 * @param xid the transaction ID
Jonathan Hart86e59352014-10-22 10:42:16 -070094 */
Brian O'Connor427a1762014-11-19 18:40:32 -080095 protected FlowModBuilderVer13(FlowRule flowRule, OFFactory factory, Optional<Long> xid) {
96 super(flowRule, factory, xid);
Jonathan Hart86e59352014-10-22 10:42:16 -070097
98 this.treatment = flowRule.treatment();
99 }
100
101 @Override
102 public OFFlowAdd buildFlowAdd() {
103 Match match = buildMatch();
alshabib346b5b32015-03-06 00:42:16 -0800104 List<OFAction> deferredActions = buildActions(treatment.deferred());
105 List<OFAction> immediateActions = buildActions(treatment.immediate());
106 List<OFInstruction> instructions = Lists.newLinkedList();
Saurav Dascbe6de32015-03-01 18:30:46 -0800107
Jonathan Hartd4a8bba2014-10-28 12:44:20 -0700108
alshabib346b5b32015-03-06 00:42:16 -0800109 if (treatment.clearedDeferred()) {
110 instructions.add(factory().instructions().clearActions());
111 }
sangho1e575652015-05-14 00:39:53 -0700112 if (immediateActions.size() > 0) {
113 instructions.add(factory().instructions().applyActions(immediateActions));
114 }
alshabib346b5b32015-03-06 00:42:16 -0800115 if (deferredActions.size() > 0) {
116 instructions.add(factory().instructions().writeActions(deferredActions));
117 }
118 if (treatment.tableTransition() != null) {
119 instructions.add(buildTableGoto(treatment.tableTransition()));
Saurav Dascbe6de32015-03-01 18:30:46 -0800120 }
Saurav Das86af8f12015-05-25 23:55:33 -0700121 if (treatment.writeMetadata() != null) {
122 instructions.add(buildMetadata(treatment.writeMetadata()));
123 }
Jonathan Hart86e59352014-10-22 10:42:16 -0700124
125 long cookie = flowRule().id().value();
126
Jonathan Hart86e59352014-10-22 10:42:16 -0700127 OFFlowAdd fm = factory().buildFlowAdd()
Brian O'Connor427a1762014-11-19 18:40:32 -0800128 .setXid(xid)
Jonathan Hart86e59352014-10-22 10:42:16 -0700129 .setCookie(U64.of(cookie))
130 .setBufferId(OFBufferId.NO_BUFFER)
alshabib9af70072015-02-09 14:34:16 -0800131 .setInstructions(instructions)
Jonathan Hart86e59352014-10-22 10:42:16 -0700132 .setMatch(match)
133 .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM))
134 .setPriority(flowRule().priority())
alshabib08d98982015-04-21 16:25:50 -0700135 .setTableId(TableId.of(flowRule().tableId()))
Jonathan Hart86e59352014-10-22 10:42:16 -0700136 .build();
137
138 return fm;
139 }
140
141 @Override
142 public OFFlowMod buildFlowMod() {
143 Match match = buildMatch();
alshabib346b5b32015-03-06 00:42:16 -0800144 List<OFAction> deferredActions = buildActions(treatment.deferred());
145 List<OFAction> immediateActions = buildActions(treatment.immediate());
146 List<OFInstruction> instructions = Lists.newLinkedList();
Jonathan Harteda33872015-02-18 10:22:32 -0800147
alshabib346b5b32015-03-06 00:42:16 -0800148
149 if (immediateActions.size() > 0) {
150 instructions.add(factory().instructions().applyActions(immediateActions));
151 }
152 if (treatment.clearedDeferred()) {
153 instructions.add(factory().instructions().clearActions());
154 }
155 if (deferredActions.size() > 0) {
156 instructions.add(factory().instructions().writeActions(deferredActions));
157 }
158 if (treatment.tableTransition() != null) {
159 instructions.add(buildTableGoto(treatment.tableTransition()));
Saurav Dascbe6de32015-03-01 18:30:46 -0800160 }
Saurav Das86af8f12015-05-25 23:55:33 -0700161 if (treatment.writeMetadata() != null) {
162 instructions.add(buildMetadata(treatment.writeMetadata()));
163 }
alshabib10c810b2015-08-18 16:59:04 -0700164 if (treatment.metered() != null) {
165 instructions.add(buildMeter(treatment.metered()));
166 }
Jonathan Hart86e59352014-10-22 10:42:16 -0700167
168 long cookie = flowRule().id().value();
169
Jonathan Hart86e59352014-10-22 10:42:16 -0700170 OFFlowMod fm = factory().buildFlowModify()
Brian O'Connor427a1762014-11-19 18:40:32 -0800171 .setXid(xid)
Jonathan Hart86e59352014-10-22 10:42:16 -0700172 .setCookie(U64.of(cookie))
173 .setBufferId(OFBufferId.NO_BUFFER)
alshabib9af70072015-02-09 14:34:16 -0800174 .setInstructions(instructions)
Jonathan Hart86e59352014-10-22 10:42:16 -0700175 .setMatch(match)
176 .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM))
177 .setPriority(flowRule().priority())
alshabib08d98982015-04-21 16:25:50 -0700178 .setTableId(TableId.of(flowRule().tableId()))
Jonathan Hart86e59352014-10-22 10:42:16 -0700179 .build();
180
181 return fm;
182 }
183
184 @Override
185 public OFFlowDelete buildFlowDel() {
186 Match match = buildMatch();
Jonathan Hart86e59352014-10-22 10:42:16 -0700187
188 long cookie = flowRule().id().value();
189
190 OFFlowDelete fm = factory().buildFlowDelete()
Brian O'Connor427a1762014-11-19 18:40:32 -0800191 .setXid(xid)
Jonathan Hart86e59352014-10-22 10:42:16 -0700192 .setCookie(U64.of(cookie))
193 .setBufferId(OFBufferId.NO_BUFFER)
Jonathan Hart86e59352014-10-22 10:42:16 -0700194 .setMatch(match)
195 .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM))
196 .setPriority(flowRule().priority())
alshabib08d98982015-04-21 16:25:50 -0700197 .setTableId(TableId.of(flowRule().tableId()))
Jonathan Hart86e59352014-10-22 10:42:16 -0700198 .build();
199
200 return fm;
201 }
202
alshabib346b5b32015-03-06 00:42:16 -0800203 private List<OFAction> buildActions(List<Instruction> treatments) {
Jonathan Hart86e59352014-10-22 10:42:16 -0700204 if (treatment == null) {
Sho SHIMIZU6601dd72015-05-11 19:00:29 -0700205 return Collections.emptyList();
Jonathan Hart86e59352014-10-22 10:42:16 -0700206 }
Sho SHIMIZU6601dd72015-05-11 19:00:29 -0700207
208 boolean tableFound = false;
209 List<OFAction> actions = new LinkedList<>();
alshabib346b5b32015-03-06 00:42:16 -0800210 for (Instruction i : treatments) {
Jonathan Hart86e59352014-10-22 10:42:16 -0700211 switch (i.type()) {
alshabib9af70072015-02-09 14:34:16 -0800212 case DROP:
Sho SHIMIZUb35ed362015-04-28 11:05:19 -0700213 return Collections.emptyList();
alshabib9af70072015-02-09 14:34:16 -0800214 case L0MODIFICATION:
215 actions.add(buildL0Modification(i));
216 break;
217 case L2MODIFICATION:
218 actions.add(buildL2Modification(i));
219 break;
220 case L3MODIFICATION:
221 actions.add(buildL3Modification(i));
222 break;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700223 case L4MODIFICATION:
224 actions.add(buildL4Modification(i));
225 break;
alshabib9af70072015-02-09 14:34:16 -0800226 case OUTPUT:
227 OutputInstruction out = (OutputInstruction) i;
228 OFActionOutput.Builder action = factory().actions().buildOutput()
229 .setPort(OFPort.of((int) out.port().toLong()));
230 if (out.port().equals(PortNumber.CONTROLLER)) {
231 action.setMaxLen(OFPCML_NO_BUFFER);
232 }
233 actions.add(action.build());
234 break;
235 case GROUP:
236 GroupInstruction group = (GroupInstruction) i;
237 OFActionGroup.Builder groupBuilder = factory().actions().buildGroup()
238 .setGroup(OFGroup.of(group.groupId().id()));
239 actions.add(groupBuilder.build());
240 break;
alshabib10580802015-02-18 18:30:33 -0800241 case TABLE:
242 //FIXME: should not occur here.
Saurav Dascbe6de32015-03-01 18:30:46 -0800243 tableFound = true;
alshabib10580802015-02-18 18:30:33 -0800244 break;
alshabib9af70072015-02-09 14:34:16 -0800245 default:
246 log.warn("Instruction type {} not yet implemented.", i.type());
Jonathan Hart86e59352014-10-22 10:42:16 -0700247 }
248 }
Saurav Dascbe6de32015-03-01 18:30:46 -0800249 if (tableFound && actions.isEmpty()) {
250 // handles the case where there are no actions, but there is
251 // a goto instruction for the next table
Sho SHIMIZU6601dd72015-05-11 19:00:29 -0700252 return Collections.emptyList();
Saurav Dascbe6de32015-03-01 18:30:46 -0800253 }
Jonathan Hart86e59352014-10-22 10:42:16 -0700254 return actions;
255 }
256
alshabib9af70072015-02-09 14:34:16 -0800257 private OFInstruction buildTableGoto(Instructions.TableTypeTransition i) {
258 OFInstruction instruction = factory().instructions().gotoTable(
alshabibd17abc22015-04-21 18:26:35 -0700259 TableId.of(i.tableId()));
alshabib9af70072015-02-09 14:34:16 -0800260 return instruction;
261 }
262
Saurav Das86af8f12015-05-25 23:55:33 -0700263 private OFInstruction buildMetadata(Instructions.MetadataInstruction m) {
264 OFInstruction instruction = factory().instructions().writeMetadata(
265 U64.of(m.metadata()), U64.of(m.metadataMask()));
266 return instruction;
267 }
268
alshabib10c810b2015-08-18 16:59:04 -0700269 private OFInstruction buildMeter(Instructions.MeterInstruction metered) {
270 return factory().instructions().meter(metered.meterId().id());
271 }
272
273
Jonathan Hart86e59352014-10-22 10:42:16 -0700274 private OFAction buildL0Modification(Instruction i) {
275 L0ModificationInstruction l0m = (L0ModificationInstruction) i;
276 switch (l0m.subtype()) {
Sho SHIMIZU5cd7ce92015-05-11 19:10:38 -0700277 case LAMBDA:
Sho SHIMIZUe397ffe2015-05-12 16:24:23 -0700278 return buildModLambdaInstruction((ModLambdaInstruction) i);
279 case OCH:
280 try {
281 return buildModOchSignalInstruction((ModOchSignalInstruction) i);
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700282 } catch (NoMappingFoundException e) {
Sho SHIMIZUe397ffe2015-05-12 16:24:23 -0700283 log.warn(e.getMessage());
284 break;
285 }
Sho SHIMIZU5cd7ce92015-05-11 19:10:38 -0700286 default:
287 log.warn("Unimplemented action type {}.", l0m.subtype());
288 break;
Jonathan Hart86e59352014-10-22 10:42:16 -0700289 }
290 return null;
291 }
292
Sho SHIMIZUe397ffe2015-05-12 16:24:23 -0700293 private OFAction buildModLambdaInstruction(ModLambdaInstruction instruction) {
294 return factory().actions().circuit(factory().oxms().ochSigidBasic(
295 new CircuitSignalID((byte) 1, (byte) 2, instruction.lambda(), (short) 1)));
296 }
297
298 private OFAction buildModOchSignalInstruction(ModOchSignalInstruction instruction) {
299 OchSignal signal = instruction.lambda();
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700300 byte gridType = OpenFlowValueMapper.lookupGridType(signal.gridType());
301 byte channelSpacing = OpenFlowValueMapper.lookupChannelSpacing(signal.channelSpacing());
Sho SHIMIZUe397ffe2015-05-12 16:24:23 -0700302
303 return factory().actions().circuit(factory().oxms().ochSigidBasic(
304 new CircuitSignalID(gridType, channelSpacing,
305 (short) signal.spacingMultiplier(), (short) signal.slotGranularity())
306 ));
307 }
308
Jonathan Hart86e59352014-10-22 10:42:16 -0700309 private OFAction buildL2Modification(Instruction i) {
310 L2ModificationInstruction l2m = (L2ModificationInstruction) i;
311 ModEtherInstruction eth;
312 OFOxm<?> oxm = null;
313 switch (l2m.subtype()) {
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800314 case ETH_DST:
315 eth = (ModEtherInstruction) l2m;
316 oxm = factory().oxms().ethDst(MacAddress.of(eth.mac().toLong()));
317 break;
318 case ETH_SRC:
319 eth = (ModEtherInstruction) l2m;
320 oxm = factory().oxms().ethSrc(MacAddress.of(eth.mac().toLong()));
321 break;
322 case VLAN_ID:
323 ModVlanIdInstruction vlanId = (ModVlanIdInstruction) l2m;
324 oxm = factory().oxms().vlanVid(OFVlanVidMatch.ofVlan(vlanId.vlanId().toShort()));
325 break;
326 case VLAN_PCP:
327 ModVlanPcpInstruction vlanPcp = (ModVlanPcpInstruction) l2m;
328 oxm = factory().oxms().vlanPcp(VlanPcp.of(vlanPcp.vlanPcp()));
329 break;
330 case MPLS_PUSH:
331 PushHeaderInstructions pushHeaderInstructions =
332 (PushHeaderInstructions) l2m;
333 return factory().actions().pushMpls(EthType.of(pushHeaderInstructions
alshabib7b808c52015-06-26 14:22:24 -0700334 .ethernetType().toShort()));
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800335 case MPLS_POP:
Jonathan Hart67fc0972015-03-19 15:21:20 -0700336 PushHeaderInstructions popHeaderInstructions =
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800337 (PushHeaderInstructions) l2m;
338 return factory().actions().popMpls(EthType.of(popHeaderInstructions
alshabib7b808c52015-06-26 14:22:24 -0700339 .ethernetType().toShort()));
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800340 case MPLS_LABEL:
341 ModMplsLabelInstruction mplsLabel =
342 (ModMplsLabelInstruction) l2m;
343 oxm = factory().oxms().mplsLabel(U32.of(mplsLabel.label()
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700344 .longValue()));
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800345 break;
sangho3f97a17d2015-01-29 22:56:29 -0800346 case DEC_MPLS_TTL:
347 return factory().actions().decMplsTtl();
Saurav Dasfbe25c52015-03-04 11:12:00 -0800348 case VLAN_POP:
349 return factory().actions().popVlan();
Jonathan Hart54b406b2015-03-06 16:24:14 -0800350 case VLAN_PUSH:
351 PushHeaderInstructions pushVlanInstruction = (PushHeaderInstructions) l2m;
352 return factory().actions().pushVlan(
alshabib7b808c52015-06-26 14:22:24 -0700353 EthType.of(pushVlanInstruction.ethernetType().toShort()));
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700354 case TUNNEL_ID:
355 ModTunnelIdInstruction tunnelId = (ModTunnelIdInstruction) l2m;
356 oxm = factory().oxms().tunnelId(U64.of(tunnelId.tunnelId()));
357 break;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800358 default:
359 log.warn("Unimplemented action type {}.", l2m.subtype());
360 break;
Jonathan Hart86e59352014-10-22 10:42:16 -0700361 }
362
363 if (oxm != null) {
364 return factory().actions().buildSetField().setField(oxm).build();
365 }
366 return null;
367 }
368
369 private OFAction buildL3Modification(Instruction i) {
370 L3ModificationInstruction l3m = (L3ModificationInstruction) i;
371 ModIPInstruction ip;
Pavlin Radoslavov23e398d2014-11-05 15:17:57 -0800372 Ip4Address ip4;
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800373 Ip6Address ip6;
Jonathan Hart86e59352014-10-22 10:42:16 -0700374 OFOxm<?> oxm = null;
375 switch (l3m.subtype()) {
Sho SHIMIZU5cd7ce92015-05-11 19:10:38 -0700376 case IPV4_SRC:
377 ip = (ModIPInstruction) i;
378 ip4 = ip.ip().getIp4Address();
379 oxm = factory().oxms().ipv4Src(IPv4Address.of(ip4.toInt()));
380 break;
381 case IPV4_DST:
382 ip = (ModIPInstruction) i;
383 ip4 = ip.ip().getIp4Address();
384 oxm = factory().oxms().ipv4Dst(IPv4Address.of(ip4.toInt()));
385 break;
386 case IPV6_SRC:
387 ip = (ModIPInstruction) i;
388 ip6 = ip.ip().getIp6Address();
389 oxm = factory().oxms().ipv6Src(IPv6Address.of(ip6.toOctets()));
390 break;
391 case IPV6_DST:
392 ip = (ModIPInstruction) i;
393 ip6 = ip.ip().getIp6Address();
394 oxm = factory().oxms().ipv6Dst(IPv6Address.of(ip6.toOctets()));
395 break;
396 case IPV6_FLABEL:
397 ModIPv6FlowLabelInstruction flowLabelInstruction =
398 (ModIPv6FlowLabelInstruction) i;
399 int flowLabel = flowLabelInstruction.flowLabel();
400 oxm = factory().oxms().ipv6Flabel(IPv6FlowLabel.of(flowLabel));
401 break;
402 case DEC_TTL:
403 return factory().actions().decNwTtl();
404 case TTL_IN:
405 return factory().actions().copyTtlIn();
406 case TTL_OUT:
407 return factory().actions().copyTtlOut();
408 default:
409 log.warn("Unimplemented action type {}.", l3m.subtype());
410 break;
Jonathan Hart86e59352014-10-22 10:42:16 -0700411 }
412
413 if (oxm != null) {
414 return factory().actions().buildSetField().setField(oxm).build();
415 }
416 return null;
417 }
418
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700419 private OFAction buildL4Modification(Instruction i) {
420 L4ModificationInstruction l4m = (L4ModificationInstruction) i;
421 ModTransportPortInstruction tp;
422 OFOxm<?> oxm = null;
423 switch (l4m.subtype()) {
424 case TCP_SRC:
425 tp = (ModTransportPortInstruction) l4m;
426 oxm = factory().oxms().tcpSrc(TransportPort.of(tp.port()));
427 break;
428 case TCP_DST:
429 tp = (ModTransportPortInstruction) l4m;
430 oxm = factory().oxms().tcpDst(TransportPort.of(tp.port()));
431 break;
432 case UDP_SRC:
433 tp = (ModTransportPortInstruction) l4m;
434 oxm = factory().oxms().udpSrc(TransportPort.of(tp.port()));
435 break;
436 case UDP_DST:
437 tp = (ModTransportPortInstruction) l4m;
438 oxm = factory().oxms().udpDst(TransportPort.of(tp.port()));
439 break;
440 default:
441 log.warn("Unimplemented action type {}.", l4m.subtype());
442 break;
443 }
444
445 if (oxm != null) {
446 return factory().actions().buildSetField().setField(oxm).build();
447 }
448 return null;
449 }
450
Jonathan Hart86e59352014-10-22 10:42:16 -0700451}