blob: 58c19ad691d5cb777dac77f6d4042df80999da1e [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 }
Jonathan Hart86e59352014-10-22 10:42:16 -0700164
165 long cookie = flowRule().id().value();
166
Jonathan Hart86e59352014-10-22 10:42:16 -0700167 OFFlowMod fm = factory().buildFlowModify()
Brian O'Connor427a1762014-11-19 18:40:32 -0800168 .setXid(xid)
Jonathan Hart86e59352014-10-22 10:42:16 -0700169 .setCookie(U64.of(cookie))
170 .setBufferId(OFBufferId.NO_BUFFER)
alshabib9af70072015-02-09 14:34:16 -0800171 .setInstructions(instructions)
Jonathan Hart86e59352014-10-22 10:42:16 -0700172 .setMatch(match)
173 .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM))
174 .setPriority(flowRule().priority())
alshabib08d98982015-04-21 16:25:50 -0700175 .setTableId(TableId.of(flowRule().tableId()))
Jonathan Hart86e59352014-10-22 10:42:16 -0700176 .build();
177
178 return fm;
179 }
180
181 @Override
182 public OFFlowDelete buildFlowDel() {
183 Match match = buildMatch();
Jonathan Hart86e59352014-10-22 10:42:16 -0700184
185 long cookie = flowRule().id().value();
186
187 OFFlowDelete fm = factory().buildFlowDelete()
Brian O'Connor427a1762014-11-19 18:40:32 -0800188 .setXid(xid)
Jonathan Hart86e59352014-10-22 10:42:16 -0700189 .setCookie(U64.of(cookie))
190 .setBufferId(OFBufferId.NO_BUFFER)
Jonathan Hart86e59352014-10-22 10:42:16 -0700191 .setMatch(match)
192 .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM))
193 .setPriority(flowRule().priority())
alshabib08d98982015-04-21 16:25:50 -0700194 .setTableId(TableId.of(flowRule().tableId()))
Jonathan Hart86e59352014-10-22 10:42:16 -0700195 .build();
196
197 return fm;
198 }
199
alshabib346b5b32015-03-06 00:42:16 -0800200 private List<OFAction> buildActions(List<Instruction> treatments) {
Jonathan Hart86e59352014-10-22 10:42:16 -0700201 if (treatment == null) {
Sho SHIMIZU6601dd72015-05-11 19:00:29 -0700202 return Collections.emptyList();
Jonathan Hart86e59352014-10-22 10:42:16 -0700203 }
Sho SHIMIZU6601dd72015-05-11 19:00:29 -0700204
205 boolean tableFound = false;
206 List<OFAction> actions = new LinkedList<>();
alshabib346b5b32015-03-06 00:42:16 -0800207 for (Instruction i : treatments) {
Jonathan Hart86e59352014-10-22 10:42:16 -0700208 switch (i.type()) {
alshabib9af70072015-02-09 14:34:16 -0800209 case DROP:
Sho SHIMIZUb35ed362015-04-28 11:05:19 -0700210 return Collections.emptyList();
alshabib9af70072015-02-09 14:34:16 -0800211 case L0MODIFICATION:
212 actions.add(buildL0Modification(i));
213 break;
214 case L2MODIFICATION:
215 actions.add(buildL2Modification(i));
216 break;
217 case L3MODIFICATION:
218 actions.add(buildL3Modification(i));
219 break;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700220 case L4MODIFICATION:
221 actions.add(buildL4Modification(i));
222 break;
alshabib9af70072015-02-09 14:34:16 -0800223 case OUTPUT:
224 OutputInstruction out = (OutputInstruction) i;
225 OFActionOutput.Builder action = factory().actions().buildOutput()
226 .setPort(OFPort.of((int) out.port().toLong()));
227 if (out.port().equals(PortNumber.CONTROLLER)) {
228 action.setMaxLen(OFPCML_NO_BUFFER);
229 }
230 actions.add(action.build());
231 break;
232 case GROUP:
233 GroupInstruction group = (GroupInstruction) i;
234 OFActionGroup.Builder groupBuilder = factory().actions().buildGroup()
235 .setGroup(OFGroup.of(group.groupId().id()));
236 actions.add(groupBuilder.build());
237 break;
alshabib10580802015-02-18 18:30:33 -0800238 case TABLE:
239 //FIXME: should not occur here.
Saurav Dascbe6de32015-03-01 18:30:46 -0800240 tableFound = true;
alshabib10580802015-02-18 18:30:33 -0800241 break;
alshabib9af70072015-02-09 14:34:16 -0800242 default:
243 log.warn("Instruction type {} not yet implemented.", i.type());
Jonathan Hart86e59352014-10-22 10:42:16 -0700244 }
245 }
Saurav Dascbe6de32015-03-01 18:30:46 -0800246 if (tableFound && actions.isEmpty()) {
247 // handles the case where there are no actions, but there is
248 // a goto instruction for the next table
Sho SHIMIZU6601dd72015-05-11 19:00:29 -0700249 return Collections.emptyList();
Saurav Dascbe6de32015-03-01 18:30:46 -0800250 }
Jonathan Hart86e59352014-10-22 10:42:16 -0700251 return actions;
252 }
253
alshabib9af70072015-02-09 14:34:16 -0800254 private OFInstruction buildTableGoto(Instructions.TableTypeTransition i) {
255 OFInstruction instruction = factory().instructions().gotoTable(
alshabibd17abc22015-04-21 18:26:35 -0700256 TableId.of(i.tableId()));
alshabib9af70072015-02-09 14:34:16 -0800257 return instruction;
258 }
259
Saurav Das86af8f12015-05-25 23:55:33 -0700260 private OFInstruction buildMetadata(Instructions.MetadataInstruction m) {
261 OFInstruction instruction = factory().instructions().writeMetadata(
262 U64.of(m.metadata()), U64.of(m.metadataMask()));
263 return instruction;
264 }
265
Jonathan Hart86e59352014-10-22 10:42:16 -0700266 private OFAction buildL0Modification(Instruction i) {
267 L0ModificationInstruction l0m = (L0ModificationInstruction) i;
268 switch (l0m.subtype()) {
Sho SHIMIZU5cd7ce92015-05-11 19:10:38 -0700269 case LAMBDA:
Sho SHIMIZUe397ffe2015-05-12 16:24:23 -0700270 return buildModLambdaInstruction((ModLambdaInstruction) i);
271 case OCH:
272 try {
273 return buildModOchSignalInstruction((ModOchSignalInstruction) i);
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700274 } catch (NoMappingFoundException e) {
Sho SHIMIZUe397ffe2015-05-12 16:24:23 -0700275 log.warn(e.getMessage());
276 break;
277 }
Sho SHIMIZU5cd7ce92015-05-11 19:10:38 -0700278 default:
279 log.warn("Unimplemented action type {}.", l0m.subtype());
280 break;
Jonathan Hart86e59352014-10-22 10:42:16 -0700281 }
282 return null;
283 }
284
Sho SHIMIZUe397ffe2015-05-12 16:24:23 -0700285 private OFAction buildModLambdaInstruction(ModLambdaInstruction instruction) {
286 return factory().actions().circuit(factory().oxms().ochSigidBasic(
287 new CircuitSignalID((byte) 1, (byte) 2, instruction.lambda(), (short) 1)));
288 }
289
290 private OFAction buildModOchSignalInstruction(ModOchSignalInstruction instruction) {
291 OchSignal signal = instruction.lambda();
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700292 byte gridType = OpenFlowValueMapper.lookupGridType(signal.gridType());
293 byte channelSpacing = OpenFlowValueMapper.lookupChannelSpacing(signal.channelSpacing());
Sho SHIMIZUe397ffe2015-05-12 16:24:23 -0700294
295 return factory().actions().circuit(factory().oxms().ochSigidBasic(
296 new CircuitSignalID(gridType, channelSpacing,
297 (short) signal.spacingMultiplier(), (short) signal.slotGranularity())
298 ));
299 }
300
Jonathan Hart86e59352014-10-22 10:42:16 -0700301 private OFAction buildL2Modification(Instruction i) {
302 L2ModificationInstruction l2m = (L2ModificationInstruction) i;
303 ModEtherInstruction eth;
304 OFOxm<?> oxm = null;
305 switch (l2m.subtype()) {
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800306 case ETH_DST:
307 eth = (ModEtherInstruction) l2m;
308 oxm = factory().oxms().ethDst(MacAddress.of(eth.mac().toLong()));
309 break;
310 case ETH_SRC:
311 eth = (ModEtherInstruction) l2m;
312 oxm = factory().oxms().ethSrc(MacAddress.of(eth.mac().toLong()));
313 break;
314 case VLAN_ID:
315 ModVlanIdInstruction vlanId = (ModVlanIdInstruction) l2m;
316 oxm = factory().oxms().vlanVid(OFVlanVidMatch.ofVlan(vlanId.vlanId().toShort()));
317 break;
318 case VLAN_PCP:
319 ModVlanPcpInstruction vlanPcp = (ModVlanPcpInstruction) l2m;
320 oxm = factory().oxms().vlanPcp(VlanPcp.of(vlanPcp.vlanPcp()));
321 break;
322 case MPLS_PUSH:
323 PushHeaderInstructions pushHeaderInstructions =
324 (PushHeaderInstructions) l2m;
325 return factory().actions().pushMpls(EthType.of(pushHeaderInstructions
alshabib7b808c52015-06-26 14:22:24 -0700326 .ethernetType().toShort()));
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800327 case MPLS_POP:
Jonathan Hart67fc0972015-03-19 15:21:20 -0700328 PushHeaderInstructions popHeaderInstructions =
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800329 (PushHeaderInstructions) l2m;
330 return factory().actions().popMpls(EthType.of(popHeaderInstructions
alshabib7b808c52015-06-26 14:22:24 -0700331 .ethernetType().toShort()));
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800332 case MPLS_LABEL:
333 ModMplsLabelInstruction mplsLabel =
334 (ModMplsLabelInstruction) l2m;
335 oxm = factory().oxms().mplsLabel(U32.of(mplsLabel.label()
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700336 .longValue()));
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800337 break;
sangho3f97a17d2015-01-29 22:56:29 -0800338 case DEC_MPLS_TTL:
339 return factory().actions().decMplsTtl();
Saurav Dasfbe25c52015-03-04 11:12:00 -0800340 case VLAN_POP:
341 return factory().actions().popVlan();
Jonathan Hart54b406b2015-03-06 16:24:14 -0800342 case VLAN_PUSH:
343 PushHeaderInstructions pushVlanInstruction = (PushHeaderInstructions) l2m;
344 return factory().actions().pushVlan(
alshabib7b808c52015-06-26 14:22:24 -0700345 EthType.of(pushVlanInstruction.ethernetType().toShort()));
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700346 case TUNNEL_ID:
347 ModTunnelIdInstruction tunnelId = (ModTunnelIdInstruction) l2m;
348 oxm = factory().oxms().tunnelId(U64.of(tunnelId.tunnelId()));
349 break;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800350 default:
351 log.warn("Unimplemented action type {}.", l2m.subtype());
352 break;
Jonathan Hart86e59352014-10-22 10:42:16 -0700353 }
354
355 if (oxm != null) {
356 return factory().actions().buildSetField().setField(oxm).build();
357 }
358 return null;
359 }
360
361 private OFAction buildL3Modification(Instruction i) {
362 L3ModificationInstruction l3m = (L3ModificationInstruction) i;
363 ModIPInstruction ip;
Pavlin Radoslavov23e398d2014-11-05 15:17:57 -0800364 Ip4Address ip4;
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800365 Ip6Address ip6;
Jonathan Hart86e59352014-10-22 10:42:16 -0700366 OFOxm<?> oxm = null;
367 switch (l3m.subtype()) {
Sho SHIMIZU5cd7ce92015-05-11 19:10:38 -0700368 case IPV4_SRC:
369 ip = (ModIPInstruction) i;
370 ip4 = ip.ip().getIp4Address();
371 oxm = factory().oxms().ipv4Src(IPv4Address.of(ip4.toInt()));
372 break;
373 case IPV4_DST:
374 ip = (ModIPInstruction) i;
375 ip4 = ip.ip().getIp4Address();
376 oxm = factory().oxms().ipv4Dst(IPv4Address.of(ip4.toInt()));
377 break;
378 case IPV6_SRC:
379 ip = (ModIPInstruction) i;
380 ip6 = ip.ip().getIp6Address();
381 oxm = factory().oxms().ipv6Src(IPv6Address.of(ip6.toOctets()));
382 break;
383 case IPV6_DST:
384 ip = (ModIPInstruction) i;
385 ip6 = ip.ip().getIp6Address();
386 oxm = factory().oxms().ipv6Dst(IPv6Address.of(ip6.toOctets()));
387 break;
388 case IPV6_FLABEL:
389 ModIPv6FlowLabelInstruction flowLabelInstruction =
390 (ModIPv6FlowLabelInstruction) i;
391 int flowLabel = flowLabelInstruction.flowLabel();
392 oxm = factory().oxms().ipv6Flabel(IPv6FlowLabel.of(flowLabel));
393 break;
394 case DEC_TTL:
395 return factory().actions().decNwTtl();
396 case TTL_IN:
397 return factory().actions().copyTtlIn();
398 case TTL_OUT:
399 return factory().actions().copyTtlOut();
400 default:
401 log.warn("Unimplemented action type {}.", l3m.subtype());
402 break;
Jonathan Hart86e59352014-10-22 10:42:16 -0700403 }
404
405 if (oxm != null) {
406 return factory().actions().buildSetField().setField(oxm).build();
407 }
408 return null;
409 }
410
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700411 private OFAction buildL4Modification(Instruction i) {
412 L4ModificationInstruction l4m = (L4ModificationInstruction) i;
413 ModTransportPortInstruction tp;
414 OFOxm<?> oxm = null;
415 switch (l4m.subtype()) {
416 case TCP_SRC:
417 tp = (ModTransportPortInstruction) l4m;
418 oxm = factory().oxms().tcpSrc(TransportPort.of(tp.port()));
419 break;
420 case TCP_DST:
421 tp = (ModTransportPortInstruction) l4m;
422 oxm = factory().oxms().tcpDst(TransportPort.of(tp.port()));
423 break;
424 case UDP_SRC:
425 tp = (ModTransportPortInstruction) l4m;
426 oxm = factory().oxms().udpSrc(TransportPort.of(tp.port()));
427 break;
428 case UDP_DST:
429 tp = (ModTransportPortInstruction) l4m;
430 oxm = factory().oxms().udpDst(TransportPort.of(tp.port()));
431 break;
432 default:
433 log.warn("Unimplemented action type {}.", l4m.subtype());
434 break;
435 }
436
437 if (oxm != null) {
438 return factory().actions().buildSetField().setField(oxm).build();
439 }
440 return null;
441 }
442
Jonathan Hart86e59352014-10-22 10:42:16 -0700443}