blob: ad601c98cc7a169e886407a2270bb4a40a3b8085 [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
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;
Yafit Hadar73514612015-11-04 10:14:21 +020022import org.onosproject.net.OduSignalId;
Charles M.C. Chanfe421812015-01-12 18:20:51 +080023import org.onosproject.net.PortNumber;
Jonathan Hart3c259162015-10-21 21:31:19 -070024import org.onosproject.net.driver.DefaultDriverData;
25import org.onosproject.net.driver.DefaultDriverHandler;
26import org.onosproject.net.driver.Driver;
27import org.onosproject.net.driver.DriverService;
Brian O'Connorabafb502014-12-02 22:26:20 -080028import org.onosproject.net.flow.FlowRule;
29import org.onosproject.net.flow.TrafficTreatment;
alshabib880b6442015-11-23 22:13:04 -080030import org.onosproject.net.flow.instructions.ExtensionTreatment;
Brian O'Connorabafb502014-12-02 22:26:20 -080031import org.onosproject.net.flow.instructions.Instruction;
alshabib9af70072015-02-09 14:34:16 -080032import org.onosproject.net.flow.instructions.Instructions;
sangho8995ac52015-02-04 11:29:03 -080033import org.onosproject.net.flow.instructions.Instructions.GroupInstruction;
alshabib9af70072015-02-09 14:34:16 -080034import org.onosproject.net.flow.instructions.Instructions.OutputInstruction;
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +020035import org.onosproject.net.flow.instructions.Instructions.SetQueueInstruction;
Brian O'Connorabafb502014-12-02 22:26:20 -080036import org.onosproject.net.flow.instructions.L0ModificationInstruction;
Sho SHIMIZUe397ffe2015-05-12 16:24:23 -070037import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModOchSignalInstruction;
Yafit Hadar73514612015-11-04 10:14:21 +020038import org.onosproject.net.flow.instructions.L1ModificationInstruction;
39import org.onosproject.net.flow.instructions.L1ModificationInstruction.ModOduSignalIdInstruction;
Brian O'Connorabafb502014-12-02 22:26:20 -080040import org.onosproject.net.flow.instructions.L2ModificationInstruction;
41import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction;
Saurav Das73a7dd42015-08-19 22:20:31 -070042import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsBosInstruction;
Jian Li11260a02016-05-19 13:07:22 -070043import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsHeaderInstruction;
Jonathan Hart29afca32015-01-20 18:17:39 -080044import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsLabelInstruction;
Jonathan Hart3c259162015-10-21 21:31:19 -070045import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModTunnelIdInstruction;
Jian Li11260a02016-05-19 13:07:22 -070046import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanHeaderInstruction;
Brian O'Connorabafb502014-12-02 22:26:20 -080047import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction;
48import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanPcpInstruction;
Brian O'Connorabafb502014-12-02 22:26:20 -080049import org.onosproject.net.flow.instructions.L3ModificationInstruction;
lishuai3cce60b2015-12-01 19:35:16 +080050import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpEthInstruction;
Jonathan Hart42feabd2016-02-03 17:56:21 -080051import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpIPInstruction;
lishuai3cce60b2015-12-01 19:35:16 +080052import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpOpInstruction;
Jonathan Hart42feabd2016-02-03 17:56:21 -080053import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -080054import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -070055import org.onosproject.net.flow.instructions.L4ModificationInstruction;
56import org.onosproject.net.flow.instructions.L4ModificationInstruction.ModTransportPortInstruction;
alshabib880b6442015-11-23 22:13:04 -080057import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter;
Thomas Vachuska95caba32016-04-04 10:42:05 -070058import org.onosproject.provider.of.flow.util.NoMappingFoundException;
59import org.onosproject.provider.of.flow.util.OpenFlowValueMapper;
Jonathan Hart86e59352014-10-22 10:42:16 -070060import org.projectfloodlight.openflow.protocol.OFFactory;
61import org.projectfloodlight.openflow.protocol.OFFlowAdd;
Jonathan Hart42feabd2016-02-03 17:56:21 -080062import org.projectfloodlight.openflow.protocol.OFFlowDeleteStrict;
Jonathan Hart86e59352014-10-22 10:42:16 -070063import org.projectfloodlight.openflow.protocol.OFFlowMod;
64import org.projectfloodlight.openflow.protocol.OFFlowModFlags;
65import org.projectfloodlight.openflow.protocol.action.OFAction;
sangho8995ac52015-02-04 11:29:03 -080066import org.projectfloodlight.openflow.protocol.action.OFActionGroup;
Charles M.C. Chanfe421812015-01-12 18:20:51 +080067import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +020068import org.projectfloodlight.openflow.protocol.action.OFActionSetQueue;
alshabib9af70072015-02-09 14:34:16 -080069import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
Jonathan Hart86e59352014-10-22 10:42:16 -070070import org.projectfloodlight.openflow.protocol.match.Match;
71import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
lishuai3cce60b2015-12-01 19:35:16 +080072import org.projectfloodlight.openflow.types.ArpOpcode;
Jonathan Hart86e59352014-10-22 10:42:16 -070073import org.projectfloodlight.openflow.types.CircuitSignalID;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -080074import org.projectfloodlight.openflow.types.EthType;
Jonathan Hart86e59352014-10-22 10:42:16 -070075import org.projectfloodlight.openflow.types.IPv4Address;
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -080076import org.projectfloodlight.openflow.types.IPv6Address;
77import org.projectfloodlight.openflow.types.IPv6FlowLabel;
Jonathan Hart86e59352014-10-22 10:42:16 -070078import org.projectfloodlight.openflow.types.MacAddress;
Saurav Das73a7dd42015-08-19 22:20:31 -070079import org.projectfloodlight.openflow.types.OFBooleanValue;
Jonathan Hart86e59352014-10-22 10:42:16 -070080import org.projectfloodlight.openflow.types.OFBufferId;
sangho8995ac52015-02-04 11:29:03 -080081import org.projectfloodlight.openflow.types.OFGroup;
Jonathan Hart86e59352014-10-22 10:42:16 -070082import org.projectfloodlight.openflow.types.OFPort;
83import org.projectfloodlight.openflow.types.OFVlanVidMatch;
Yafit Hadar73514612015-11-04 10:14:21 +020084import org.projectfloodlight.openflow.types.OduSignalID;
alshabib9af70072015-02-09 14:34:16 -080085import org.projectfloodlight.openflow.types.TableId;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -070086import org.projectfloodlight.openflow.types.TransportPort;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -080087import org.projectfloodlight.openflow.types.U32;
Jonathan Hart86e59352014-10-22 10:42:16 -070088import org.projectfloodlight.openflow.types.U64;
89import org.projectfloodlight.openflow.types.VlanPcp;
90import org.slf4j.Logger;
91import org.slf4j.LoggerFactory;
92
Jonathan Hart29afca32015-01-20 18:17:39 -080093import java.util.Collections;
94import java.util.LinkedList;
95import java.util.List;
96import java.util.Optional;
97
Jonathan Hart86e59352014-10-22 10:42:16 -070098/**
99 * Flow mod builder for OpenFlow 1.3+.
100 */
101public class FlowModBuilderVer13 extends FlowModBuilder {
102
Cem Türker3baff672017-10-12 15:09:01 +0300103 protected final Logger log = LoggerFactory.getLogger(getClass());
104 protected static final int OFPCML_NO_BUFFER = 0xffff;
Jonathan Hart86e59352014-10-22 10:42:16 -0700105
Cem Türker3baff672017-10-12 15:09:01 +0300106 protected final TrafficTreatment treatment;
Jonathan Hart86e59352014-10-22 10:42:16 -0700107
108 /**
109 * Constructor for a flow mod builder for OpenFlow 1.3.
110 *
111 * @param flowRule the flow rule to transform into a flow mod
112 * @param factory the OpenFlow factory to use to build the flow mod
Pavlin Radoslavov119fd5c2014-11-25 19:08:19 -0800113 * @param xid the transaction ID
Charles Chan30ba4002015-11-05 14:45:16 -0800114 * @param driverService the device driver service
Jonathan Hart86e59352014-10-22 10:42:16 -0700115 */
Jonathan Hart3c259162015-10-21 21:31:19 -0700116 protected FlowModBuilderVer13(FlowRule flowRule, OFFactory factory, Optional<Long> xid,
117 Optional<DriverService> driverService) {
118 super(flowRule, factory, xid, driverService);
Jonathan Hart86e59352014-10-22 10:42:16 -0700119
120 this.treatment = flowRule.treatment();
121 }
122
123 @Override
Jonathan Hart42feabd2016-02-03 17:56:21 -0800124 public OFFlowMod buildFlowAdd() {
Jonathan Hart86e59352014-10-22 10:42:16 -0700125 Match match = buildMatch();
alshabib346b5b32015-03-06 00:42:16 -0800126 List<OFAction> deferredActions = buildActions(treatment.deferred());
127 List<OFAction> immediateActions = buildActions(treatment.immediate());
128 List<OFInstruction> instructions = Lists.newLinkedList();
Saurav Dascbe6de32015-03-01 18:30:46 -0800129
Jonathan Hartd4a8bba2014-10-28 12:44:20 -0700130
alshabib346b5b32015-03-06 00:42:16 -0800131 if (treatment.clearedDeferred()) {
132 instructions.add(factory().instructions().clearActions());
133 }
Jon Hallcbd1b392017-01-18 20:15:44 -0800134 if (!immediateActions.isEmpty()) {
sangho1e575652015-05-14 00:39:53 -0700135 instructions.add(factory().instructions().applyActions(immediateActions));
136 }
Jon Hallcbd1b392017-01-18 20:15:44 -0800137 if (!deferredActions.isEmpty()) {
alshabib346b5b32015-03-06 00:42:16 -0800138 instructions.add(factory().instructions().writeActions(deferredActions));
139 }
140 if (treatment.tableTransition() != null) {
141 instructions.add(buildTableGoto(treatment.tableTransition()));
Saurav Dascbe6de32015-03-01 18:30:46 -0800142 }
Saurav Das86af8f12015-05-25 23:55:33 -0700143 if (treatment.writeMetadata() != null) {
144 instructions.add(buildMetadata(treatment.writeMetadata()));
145 }
chengfane264bef2015-09-28 08:38:19 +0800146 if (treatment.metered() != null) {
147 instructions.add(buildMeter(treatment.metered()));
148 }
Jonathan Hart86e59352014-10-22 10:42:16 -0700149
150 long cookie = flowRule().id().value();
151
Jonathan Hart86e59352014-10-22 10:42:16 -0700152 OFFlowAdd fm = factory().buildFlowAdd()
Brian O'Connor427a1762014-11-19 18:40:32 -0800153 .setXid(xid)
Jonathan Hart86e59352014-10-22 10:42:16 -0700154 .setCookie(U64.of(cookie))
155 .setBufferId(OFBufferId.NO_BUFFER)
alshabib9af70072015-02-09 14:34:16 -0800156 .setInstructions(instructions)
Jonathan Hart86e59352014-10-22 10:42:16 -0700157 .setMatch(match)
158 .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM))
159 .setPriority(flowRule().priority())
alshabib08d98982015-04-21 16:25:50 -0700160 .setTableId(TableId.of(flowRule().tableId()))
Murat Parlakisikc6759e82016-06-29 03:22:22 -0700161 .setHardTimeout(flowRule().hardTimeout())
Jonathan Hart86e59352014-10-22 10:42:16 -0700162 .build();
163
164 return fm;
165 }
166
167 @Override
168 public OFFlowMod buildFlowMod() {
169 Match match = buildMatch();
alshabib346b5b32015-03-06 00:42:16 -0800170 List<OFAction> deferredActions = buildActions(treatment.deferred());
171 List<OFAction> immediateActions = buildActions(treatment.immediate());
172 List<OFInstruction> instructions = Lists.newLinkedList();
Jonathan Harteda33872015-02-18 10:22:32 -0800173
alshabib346b5b32015-03-06 00:42:16 -0800174
Jon Hallcbd1b392017-01-18 20:15:44 -0800175 if (!immediateActions.isEmpty()) {
alshabib346b5b32015-03-06 00:42:16 -0800176 instructions.add(factory().instructions().applyActions(immediateActions));
177 }
178 if (treatment.clearedDeferred()) {
179 instructions.add(factory().instructions().clearActions());
180 }
Jon Hallcbd1b392017-01-18 20:15:44 -0800181 if (!deferredActions.isEmpty()) {
alshabib346b5b32015-03-06 00:42:16 -0800182 instructions.add(factory().instructions().writeActions(deferredActions));
183 }
184 if (treatment.tableTransition() != null) {
185 instructions.add(buildTableGoto(treatment.tableTransition()));
Saurav Dascbe6de32015-03-01 18:30:46 -0800186 }
Saurav Das86af8f12015-05-25 23:55:33 -0700187 if (treatment.writeMetadata() != null) {
188 instructions.add(buildMetadata(treatment.writeMetadata()));
189 }
alshabib10c810b2015-08-18 16:59:04 -0700190 if (treatment.metered() != null) {
191 instructions.add(buildMeter(treatment.metered()));
192 }
Jonathan Hart86e59352014-10-22 10:42:16 -0700193
194 long cookie = flowRule().id().value();
195
Jonathan Hart86e59352014-10-22 10:42:16 -0700196 OFFlowMod fm = factory().buildFlowModify()
Brian O'Connor427a1762014-11-19 18:40:32 -0800197 .setXid(xid)
Jonathan Hart86e59352014-10-22 10:42:16 -0700198 .setCookie(U64.of(cookie))
199 .setBufferId(OFBufferId.NO_BUFFER)
alshabib9af70072015-02-09 14:34:16 -0800200 .setInstructions(instructions)
Jonathan Hart86e59352014-10-22 10:42:16 -0700201 .setMatch(match)
202 .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM))
203 .setPriority(flowRule().priority())
alshabib08d98982015-04-21 16:25:50 -0700204 .setTableId(TableId.of(flowRule().tableId()))
Murat Parlakisikc6759e82016-06-29 03:22:22 -0700205 .setHardTimeout(flowRule().hardTimeout())
Jonathan Hart86e59352014-10-22 10:42:16 -0700206 .build();
207
208 return fm;
209 }
210
211 @Override
Jonathan Hart42feabd2016-02-03 17:56:21 -0800212 public OFFlowMod buildFlowDel() {
Jonathan Hart86e59352014-10-22 10:42:16 -0700213 Match match = buildMatch();
Jonathan Hart86e59352014-10-22 10:42:16 -0700214
215 long cookie = flowRule().id().value();
216
Jonathan Hart42feabd2016-02-03 17:56:21 -0800217 OFFlowDeleteStrict fm = factory().buildFlowDeleteStrict()
Brian O'Connor427a1762014-11-19 18:40:32 -0800218 .setXid(xid)
Jonathan Hart86e59352014-10-22 10:42:16 -0700219 .setCookie(U64.of(cookie))
220 .setBufferId(OFBufferId.NO_BUFFER)
Jonathan Hart86e59352014-10-22 10:42:16 -0700221 .setMatch(match)
222 .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM))
223 .setPriority(flowRule().priority())
alshabib08d98982015-04-21 16:25:50 -0700224 .setTableId(TableId.of(flowRule().tableId()))
Murat Parlakisikc6759e82016-06-29 03:22:22 -0700225 .setHardTimeout(flowRule().hardTimeout())
Jonathan Hart86e59352014-10-22 10:42:16 -0700226 .build();
227
228 return fm;
229 }
230
alshabib346b5b32015-03-06 00:42:16 -0800231 private List<OFAction> buildActions(List<Instruction> treatments) {
Jonathan Hart86e59352014-10-22 10:42:16 -0700232 if (treatment == null) {
Sho SHIMIZU6601dd72015-05-11 19:00:29 -0700233 return Collections.emptyList();
Jonathan Hart86e59352014-10-22 10:42:16 -0700234 }
Sho SHIMIZU6601dd72015-05-11 19:00:29 -0700235
236 boolean tableFound = false;
237 List<OFAction> actions = new LinkedList<>();
alshabib346b5b32015-03-06 00:42:16 -0800238 for (Instruction i : treatments) {
Jonathan Hart86e59352014-10-22 10:42:16 -0700239 switch (i.type()) {
Charles Chan7efabeb2015-09-28 15:12:19 -0700240 case NOACTION:
Sho SHIMIZUb35ed362015-04-28 11:05:19 -0700241 return Collections.emptyList();
alshabib9af70072015-02-09 14:34:16 -0800242 case L0MODIFICATION:
243 actions.add(buildL0Modification(i));
244 break;
Yafit Hadar73514612015-11-04 10:14:21 +0200245 case L1MODIFICATION:
246 actions.add(buildL1Modification(i));
247 break;
alshabib9af70072015-02-09 14:34:16 -0800248 case L2MODIFICATION:
249 actions.add(buildL2Modification(i));
250 break;
251 case L3MODIFICATION:
252 actions.add(buildL3Modification(i));
253 break;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700254 case L4MODIFICATION:
255 actions.add(buildL4Modification(i));
256 break;
alshabib9af70072015-02-09 14:34:16 -0800257 case OUTPUT:
258 OutputInstruction out = (OutputInstruction) i;
259 OFActionOutput.Builder action = factory().actions().buildOutput()
260 .setPort(OFPort.of((int) out.port().toLong()));
261 if (out.port().equals(PortNumber.CONTROLLER)) {
262 action.setMaxLen(OFPCML_NO_BUFFER);
263 }
264 actions.add(action.build());
265 break;
266 case GROUP:
267 GroupInstruction group = (GroupInstruction) i;
268 OFActionGroup.Builder groupBuilder = factory().actions().buildGroup()
269 .setGroup(OFGroup.of(group.groupId().id()));
270 actions.add(groupBuilder.build());
271 break;
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200272 case QUEUE:
273 SetQueueInstruction queue = (SetQueueInstruction) i;
274 OFActionSetQueue.Builder queueBuilder = factory().actions().buildSetQueue()
275 .setQueueId(queue.queueId());
276 actions.add(queueBuilder.build());
277 break;
alshabib10580802015-02-18 18:30:33 -0800278 case TABLE:
279 //FIXME: should not occur here.
Saurav Dascbe6de32015-03-01 18:30:46 -0800280 tableFound = true;
alshabib10580802015-02-18 18:30:33 -0800281 break;
Jonathan Hart3c259162015-10-21 21:31:19 -0700282 case EXTENSION:
283 actions.add(buildExtensionAction(((Instructions.ExtensionInstructionWrapper) i)
284 .extensionInstruction()));
285 break;
alshabib9af70072015-02-09 14:34:16 -0800286 default:
287 log.warn("Instruction type {} not yet implemented.", i.type());
Jonathan Hart86e59352014-10-22 10:42:16 -0700288 }
289 }
Saurav Dascbe6de32015-03-01 18:30:46 -0800290 if (tableFound && actions.isEmpty()) {
291 // handles the case where there are no actions, but there is
292 // a goto instruction for the next table
Sho SHIMIZU6601dd72015-05-11 19:00:29 -0700293 return Collections.emptyList();
Saurav Dascbe6de32015-03-01 18:30:46 -0800294 }
Jonathan Hart86e59352014-10-22 10:42:16 -0700295 return actions;
296 }
297
Cem Türker3baff672017-10-12 15:09:01 +0300298 protected OFInstruction buildTableGoto(Instructions.TableTypeTransition i) {
alshabib9af70072015-02-09 14:34:16 -0800299 OFInstruction instruction = factory().instructions().gotoTable(
alshabibd17abc22015-04-21 18:26:35 -0700300 TableId.of(i.tableId()));
alshabib9af70072015-02-09 14:34:16 -0800301 return instruction;
302 }
303
Cem Türker3baff672017-10-12 15:09:01 +0300304 protected OFInstruction buildMetadata(Instructions.MetadataInstruction m) {
Saurav Das86af8f12015-05-25 23:55:33 -0700305 OFInstruction instruction = factory().instructions().writeMetadata(
306 U64.of(m.metadata()), U64.of(m.metadataMask()));
307 return instruction;
308 }
309
Cem Türker3baff672017-10-12 15:09:01 +0300310 protected OFInstruction buildMeter(Instructions.MeterInstruction metered) {
alshabib10c810b2015-08-18 16:59:04 -0700311 return factory().instructions().meter(metered.meterId().id());
312 }
313
314
Cem Türker3baff672017-10-12 15:09:01 +0300315 protected OFAction buildL0Modification(Instruction i) {
Jonathan Hart86e59352014-10-22 10:42:16 -0700316 L0ModificationInstruction l0m = (L0ModificationInstruction) i;
Yafit Hadar73514612015-11-04 10:14:21 +0200317 OFOxm<?> oxm = null;
Jonathan Hart86e59352014-10-22 10:42:16 -0700318 switch (l0m.subtype()) {
Sho SHIMIZUe397ffe2015-05-12 16:24:23 -0700319 case OCH:
320 try {
Yafit Hadar73514612015-11-04 10:14:21 +0200321 ModOchSignalInstruction modOchSignalInstruction = (ModOchSignalInstruction) l0m;
322 OchSignal signal = modOchSignalInstruction.lambda();
323 byte gridType = OpenFlowValueMapper.lookupGridType(signal.gridType());
324 byte channelSpacing = OpenFlowValueMapper.lookupChannelSpacing(signal.channelSpacing());
325 oxm = factory().oxms().expOchSigId(
326 new CircuitSignalID(gridType, channelSpacing,
327 (short) signal.spacingMultiplier(), (short) signal.slotGranularity()));
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700328 } catch (NoMappingFoundException e) {
Sho SHIMIZUe397ffe2015-05-12 16:24:23 -0700329 log.warn(e.getMessage());
330 break;
331 }
Yafit Hadar73514612015-11-04 10:14:21 +0200332 break;
Sho SHIMIZU5cd7ce92015-05-11 19:10:38 -0700333 default:
334 log.warn("Unimplemented action type {}.", l0m.subtype());
335 break;
Jonathan Hart86e59352014-10-22 10:42:16 -0700336 }
Yafit Hadar73514612015-11-04 10:14:21 +0200337 if (oxm != null) {
338 return factory().actions().buildSetField().setField(oxm).build();
339 }
Jonathan Hart86e59352014-10-22 10:42:16 -0700340 return null;
341 }
342
Cem Türker3baff672017-10-12 15:09:01 +0300343 protected OFAction buildL1Modification(Instruction i) {
Yafit Hadar73514612015-11-04 10:14:21 +0200344 L1ModificationInstruction l1m = (L1ModificationInstruction) i;
345 OFOxm<?> oxm = null;
346 switch (l1m.subtype()) {
347 case ODU_SIGID:
348 ModOduSignalIdInstruction modOduSignalIdInstruction = (ModOduSignalIdInstruction) l1m;
349 OduSignalId oduSignalId = modOduSignalIdInstruction.oduSignalId();
350
351 OduSignalID oduSignalID = new OduSignalID((short) oduSignalId.tributaryPortNumber(),
352 (short) oduSignalId.tributarySlotLength(),
353 oduSignalId.tributarySlotBitmap());
354
355 oxm = factory().oxms().expOduSigId(oduSignalID);
356 break;
357 default:
358 log.warn("Unimplemented action type {}.", l1m.subtype());
359 break;
360 }
361
362 if (oxm != null) {
363 return factory().actions().buildSetField().setField(oxm).build();
364 }
365 return null;
366 }
367
Cem Türker3baff672017-10-12 15:09:01 +0300368 protected OFAction buildL2Modification(Instruction i) {
Jonathan Hart86e59352014-10-22 10:42:16 -0700369 L2ModificationInstruction l2m = (L2ModificationInstruction) i;
370 ModEtherInstruction eth;
371 OFOxm<?> oxm = null;
372 switch (l2m.subtype()) {
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800373 case ETH_DST:
374 eth = (ModEtherInstruction) l2m;
375 oxm = factory().oxms().ethDst(MacAddress.of(eth.mac().toLong()));
376 break;
377 case ETH_SRC:
378 eth = (ModEtherInstruction) l2m;
379 oxm = factory().oxms().ethSrc(MacAddress.of(eth.mac().toLong()));
380 break;
381 case VLAN_ID:
382 ModVlanIdInstruction vlanId = (ModVlanIdInstruction) l2m;
383 oxm = factory().oxms().vlanVid(OFVlanVidMatch.ofVlan(vlanId.vlanId().toShort()));
384 break;
385 case VLAN_PCP:
386 ModVlanPcpInstruction vlanPcp = (ModVlanPcpInstruction) l2m;
387 oxm = factory().oxms().vlanPcp(VlanPcp.of(vlanPcp.vlanPcp()));
388 break;
389 case MPLS_PUSH:
Jian Li11260a02016-05-19 13:07:22 -0700390 ModMplsHeaderInstruction pushHeaderInstructions =
391 (ModMplsHeaderInstruction) l2m;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800392 return factory().actions().pushMpls(EthType.of(pushHeaderInstructions
alshabib7b808c52015-06-26 14:22:24 -0700393 .ethernetType().toShort()));
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800394 case MPLS_POP:
Jian Li11260a02016-05-19 13:07:22 -0700395 ModMplsHeaderInstruction popHeaderInstructions =
396 (ModMplsHeaderInstruction) l2m;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800397 return factory().actions().popMpls(EthType.of(popHeaderInstructions
alshabib7b808c52015-06-26 14:22:24 -0700398 .ethernetType().toShort()));
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800399 case MPLS_LABEL:
400 ModMplsLabelInstruction mplsLabel =
401 (ModMplsLabelInstruction) l2m;
Ray Milkey125572b2016-02-22 16:48:17 -0800402 oxm = factory().oxms().mplsLabel(U32.of(mplsLabel.label().toInt()));
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800403 break;
Saurav Das73a7dd42015-08-19 22:20:31 -0700404 case MPLS_BOS:
405 ModMplsBosInstruction mplsBos = (ModMplsBosInstruction) l2m;
406 oxm = factory().oxms()
407 .mplsBos(mplsBos.mplsBos() ? OFBooleanValue.TRUE
408 : OFBooleanValue.FALSE);
409 break;
sangho3f97a17d2015-01-29 22:56:29 -0800410 case DEC_MPLS_TTL:
411 return factory().actions().decMplsTtl();
Saurav Dasfbe25c52015-03-04 11:12:00 -0800412 case VLAN_POP:
413 return factory().actions().popVlan();
Jonathan Hart54b406b2015-03-06 16:24:14 -0800414 case VLAN_PUSH:
Jian Li11260a02016-05-19 13:07:22 -0700415 ModVlanHeaderInstruction pushVlanInstruction = (ModVlanHeaderInstruction) l2m;
Jonathan Hart54b406b2015-03-06 16:24:14 -0800416 return factory().actions().pushVlan(
alshabib7b808c52015-06-26 14:22:24 -0700417 EthType.of(pushVlanInstruction.ethernetType().toShort()));
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700418 case TUNNEL_ID:
419 ModTunnelIdInstruction tunnelId = (ModTunnelIdInstruction) l2m;
420 oxm = factory().oxms().tunnelId(U64.of(tunnelId.tunnelId()));
421 break;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800422 default:
423 log.warn("Unimplemented action type {}.", l2m.subtype());
424 break;
Jonathan Hart86e59352014-10-22 10:42:16 -0700425 }
426
427 if (oxm != null) {
428 return factory().actions().buildSetField().setField(oxm).build();
429 }
430 return null;
431 }
432
Cem Türker3baff672017-10-12 15:09:01 +0300433 protected OFAction buildL3Modification(Instruction i) {
Jonathan Hart86e59352014-10-22 10:42:16 -0700434 L3ModificationInstruction l3m = (L3ModificationInstruction) i;
435 ModIPInstruction ip;
Pavlin Radoslavov23e398d2014-11-05 15:17:57 -0800436 Ip4Address ip4;
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800437 Ip6Address ip6;
Jonathan Hart86e59352014-10-22 10:42:16 -0700438 OFOxm<?> oxm = null;
439 switch (l3m.subtype()) {
Sho SHIMIZU5cd7ce92015-05-11 19:10:38 -0700440 case IPV4_SRC:
441 ip = (ModIPInstruction) i;
442 ip4 = ip.ip().getIp4Address();
443 oxm = factory().oxms().ipv4Src(IPv4Address.of(ip4.toInt()));
444 break;
445 case IPV4_DST:
446 ip = (ModIPInstruction) i;
447 ip4 = ip.ip().getIp4Address();
448 oxm = factory().oxms().ipv4Dst(IPv4Address.of(ip4.toInt()));
449 break;
450 case IPV6_SRC:
451 ip = (ModIPInstruction) i;
452 ip6 = ip.ip().getIp6Address();
453 oxm = factory().oxms().ipv6Src(IPv6Address.of(ip6.toOctets()));
454 break;
455 case IPV6_DST:
456 ip = (ModIPInstruction) i;
457 ip6 = ip.ip().getIp6Address();
458 oxm = factory().oxms().ipv6Dst(IPv6Address.of(ip6.toOctets()));
459 break;
460 case IPV6_FLABEL:
461 ModIPv6FlowLabelInstruction flowLabelInstruction =
462 (ModIPv6FlowLabelInstruction) i;
463 int flowLabel = flowLabelInstruction.flowLabel();
464 oxm = factory().oxms().ipv6Flabel(IPv6FlowLabel.of(flowLabel));
465 break;
lishuai3cce60b2015-12-01 19:35:16 +0800466 case ARP_SPA:
467 ModArpIPInstruction aip = (ModArpIPInstruction) i;
468 ip4 = aip.ip().getIp4Address();
469 oxm = factory().oxms().arpSpa(IPv4Address.of(ip4.toInt()));
470 break;
471 case ARP_SHA:
472 ModArpEthInstruction ei = (ModArpEthInstruction) i;
473 oxm = factory().oxms().arpSha(MacAddress.of(ei.mac().toLong()));
474 break;
475 case ARP_OP:
476 ModArpOpInstruction oi = (ModArpOpInstruction) i;
477 oxm = factory().oxms().arpOp(ArpOpcode.of((int) oi.op()));
478 break;
Sho SHIMIZU5cd7ce92015-05-11 19:10:38 -0700479 case DEC_TTL:
480 return factory().actions().decNwTtl();
481 case TTL_IN:
482 return factory().actions().copyTtlIn();
483 case TTL_OUT:
484 return factory().actions().copyTtlOut();
485 default:
486 log.warn("Unimplemented action type {}.", l3m.subtype());
487 break;
Jonathan Hart86e59352014-10-22 10:42:16 -0700488 }
489
490 if (oxm != null) {
491 return factory().actions().buildSetField().setField(oxm).build();
492 }
493 return null;
494 }
495
Cem Türker3baff672017-10-12 15:09:01 +0300496 protected OFAction buildL4Modification(Instruction i) {
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700497 L4ModificationInstruction l4m = (L4ModificationInstruction) i;
498 ModTransportPortInstruction tp;
499 OFOxm<?> oxm = null;
500 switch (l4m.subtype()) {
501 case TCP_SRC:
502 tp = (ModTransportPortInstruction) l4m;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700503 oxm = factory().oxms().tcpSrc(TransportPort.of(tp.port().toInt()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700504 break;
505 case TCP_DST:
506 tp = (ModTransportPortInstruction) l4m;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700507 oxm = factory().oxms().tcpDst(TransportPort.of(tp.port().toInt()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700508 break;
509 case UDP_SRC:
510 tp = (ModTransportPortInstruction) l4m;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700511 oxm = factory().oxms().udpSrc(TransportPort.of(tp.port().toInt()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700512 break;
513 case UDP_DST:
514 tp = (ModTransportPortInstruction) l4m;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700515 oxm = factory().oxms().udpDst(TransportPort.of(tp.port().toInt()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700516 break;
517 default:
518 log.warn("Unimplemented action type {}.", l4m.subtype());
519 break;
520 }
521
522 if (oxm != null) {
523 return factory().actions().buildSetField().setField(oxm).build();
524 }
525 return null;
526 }
527
Cem Türker3baff672017-10-12 15:09:01 +0300528 protected OFAction buildExtensionAction(ExtensionTreatment i) {
Jonathan Hart3c259162015-10-21 21:31:19 -0700529 if (!driverService.isPresent()) {
530 log.error("No driver service present");
531 return null;
532 }
533 Driver driver = driverService.get().getDriver(deviceId);
alshabib880b6442015-11-23 22:13:04 -0800534 if (driver.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
Jonathan Hart3c259162015-10-21 21:31:19 -0700535 DefaultDriverHandler handler =
536 new DefaultDriverHandler(new DefaultDriverData(driver, deviceId));
alshabib880b6442015-11-23 22:13:04 -0800537 ExtensionTreatmentInterpreter interpreter = handler.behaviour(ExtensionTreatmentInterpreter.class);
Jonathan Hart3c259162015-10-21 21:31:19 -0700538 return interpreter.mapInstruction(factory(), i);
539 }
540
541 return null;
542 }
543
Jonathan Hart86e59352014-10-22 10:42:16 -0700544}