blob: f85e790b6f9bde083a001ed78430e985ef3ac41d [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present 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 */
Thomas Vachuska95caba32016-04-04 10:42:05 -070016package org.onosproject.provider.of.flow.util;
alshabib6b5cfec2014-09-18 17:42:18 -070017
Jonathan Hart8cf212a2015-10-29 17:42:03 -070018import com.google.common.collect.Lists;
Ray Milkey84d5a292016-02-22 14:04:01 -080019import org.onlab.packet.EthType;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080020import org.onlab.packet.Ip4Address;
21import org.onlab.packet.Ip4Prefix;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080022import org.onlab.packet.Ip6Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080023import org.onlab.packet.Ip6Prefix;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080024import org.onlab.packet.MacAddress;
Michele Santuari4b6019e2014-12-19 11:31:45 +010025import org.onlab.packet.MplsLabel;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -070026import org.onlab.packet.TpPort;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080027import org.onlab.packet.VlanId;
sangho8995ac52015-02-04 11:29:03 -080028import org.onosproject.core.DefaultGroupId;
Brian O'Connorabafb502014-12-02 22:26:20 -080029import org.onosproject.net.DeviceId;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070030import org.onosproject.net.Lambda;
Yafit Hadar73514612015-11-04 10:14:21 +020031import org.onosproject.net.OduSignalId;
Brian O'Connorabafb502014-12-02 22:26:20 -080032import org.onosproject.net.PortNumber;
Jonathan Hart3c259162015-10-21 21:31:19 -070033import org.onosproject.net.driver.DefaultDriverData;
34import org.onosproject.net.driver.DefaultDriverHandler;
35import org.onosproject.net.driver.Driver;
36import org.onosproject.net.driver.DriverHandler;
37import org.onosproject.net.driver.DriverService;
Brian O'Connorabafb502014-12-02 22:26:20 -080038import org.onosproject.net.flow.DefaultFlowEntry;
39import org.onosproject.net.flow.DefaultFlowRule;
40import org.onosproject.net.flow.DefaultTrafficSelector;
41import org.onosproject.net.flow.DefaultTrafficTreatment;
42import org.onosproject.net.flow.FlowEntry;
43import org.onosproject.net.flow.FlowEntry.FlowEntryState;
44import org.onosproject.net.flow.FlowRule;
45import org.onosproject.net.flow.TrafficSelector;
46import org.onosproject.net.flow.TrafficTreatment;
Charles Chan14967c22015-12-07 11:11:50 -080047import org.onosproject.net.flow.criteria.ExtensionSelectorType.ExtensionSelectorTypes;
Sho SHIMIZU9553bb82015-06-30 16:02:45 -070048import org.onosproject.net.flow.instructions.Instructions;
Charles Chan14967c22015-12-07 11:11:50 -080049import org.onosproject.openflow.controller.ExtensionSelectorInterpreter;
alshabib880b6442015-11-23 22:13:04 -080050import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter;
Brian O'Connor72cb19a2015-01-16 16:14:41 -080051import org.projectfloodlight.openflow.protocol.OFFlowMod;
alshabib6b5cfec2014-09-18 17:42:18 -070052import org.projectfloodlight.openflow.protocol.OFFlowRemoved;
53import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry;
Charles Chan14967c22015-12-07 11:11:50 -080054import org.projectfloodlight.openflow.protocol.OFMatchV3;
Brian O'Connor21564612015-12-05 19:24:59 -080055import org.projectfloodlight.openflow.protocol.OFVersion;
alshabib6b5cfec2014-09-18 17:42:18 -070056import org.projectfloodlight.openflow.protocol.action.OFAction;
Marc De Leenheer49087752014-10-23 13:54:09 -070057import org.projectfloodlight.openflow.protocol.action.OFActionCircuit;
Steffen Gebertba2d3b72015-10-22 11:14:31 +020058import org.projectfloodlight.openflow.protocol.action.OFActionEnqueue;
Marc De Leenheer49087752014-10-23 13:54:09 -070059import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter;
sangho8995ac52015-02-04 11:29:03 -080060import org.projectfloodlight.openflow.protocol.action.OFActionGroup;
alshabib6b5cfec2014-09-18 17:42:18 -070061import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
sangho3f97a17d2015-01-29 22:56:29 -080062import org.projectfloodlight.openflow.protocol.action.OFActionPopMpls;
Konstantinos Kanonakis9215ff22016-11-04 13:28:11 -050063import org.projectfloodlight.openflow.protocol.action.OFActionPushVlan;
alshabib6b5cfec2014-09-18 17:42:18 -070064import org.projectfloodlight.openflow.protocol.action.OFActionSetDlDst;
65import org.projectfloodlight.openflow.protocol.action.OFActionSetDlSrc;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080066import org.projectfloodlight.openflow.protocol.action.OFActionSetField;
alshabib6b5cfec2014-09-18 17:42:18 -070067import org.projectfloodlight.openflow.protocol.action.OFActionSetNwDst;
68import org.projectfloodlight.openflow.protocol.action.OFActionSetNwSrc;
Jonathan Hart8cf212a2015-10-29 17:42:03 -070069import org.projectfloodlight.openflow.protocol.action.OFActionSetQueue;
alshabib6b5cfec2014-09-18 17:42:18 -070070import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanPcp;
71import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanVid;
alshabib19fdc122014-10-03 11:38:19 -070072import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
Jonathan Hartcf783202014-11-24 18:55:42 -080073import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions;
alshabibbdcbb102015-04-22 14:16:38 -070074import org.projectfloodlight.openflow.protocol.instruction.OFInstructionGotoTable;
alshabib346b5b32015-03-06 00:42:16 -080075import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteActions;
Saurav Das86af8f12015-05-25 23:55:33 -070076import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteMetadata;
alshabib6b5cfec2014-09-18 17:42:18 -070077import org.projectfloodlight.openflow.protocol.match.Match;
78import org.projectfloodlight.openflow.protocol.match.MatchField;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080079import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
Yafit Hadar4cc65f72016-02-10 11:23:06 +020080import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigid;
alshabib346b5b32015-03-06 00:42:16 -080081import org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070082import org.projectfloodlight.openflow.types.CircuitSignalID;
alshabib6b5cfec2014-09-18 17:42:18 -070083import org.projectfloodlight.openflow.types.IPv4Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080084import org.projectfloodlight.openflow.types.IPv6Address;
Jonathan Hart0e12fad2014-10-17 14:54:58 -070085import org.projectfloodlight.openflow.types.Masked;
Pier Ventre23f78672016-11-15 08:46:34 -080086import org.projectfloodlight.openflow.types.OFBooleanValue;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080087import org.projectfloodlight.openflow.types.OFVlanVidMatch;
Jonathan Harte4e74f02016-03-03 12:57:40 -080088import org.projectfloodlight.openflow.types.OduSignalID;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -070089import org.projectfloodlight.openflow.types.TransportPort;
sangho3f97a17d2015-01-29 22:56:29 -080090import org.projectfloodlight.openflow.types.U32;
Hyunsun Moona08c5d02015-07-14 17:53:00 -070091import org.projectfloodlight.openflow.types.U64;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070092import org.projectfloodlight.openflow.types.U8;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080093import org.projectfloodlight.openflow.types.VlanPcp;
alshabib6b5cfec2014-09-18 17:42:18 -070094import org.slf4j.Logger;
Jian Lia0d9a172016-04-01 16:58:06 -070095import org.slf4j.LoggerFactory;
alshabib6b5cfec2014-09-18 17:42:18 -070096
Jonathan Hart8cf212a2015-10-29 17:42:03 -070097import java.util.List;
98
Thiago Santos877914d2016-07-20 18:29:29 -030099import static java.util.concurrent.TimeUnit.NANOSECONDS;
100import static java.util.concurrent.TimeUnit.SECONDS;
alshabib44852fb2016-04-15 15:56:51 -0700101import static org.onosproject.net.flow.criteria.Criteria.*;
Yafit Hadar73514612015-11-04 10:14:21 +0200102import static org.onosproject.net.flow.instructions.Instructions.modL0Lambda;
103import static org.onosproject.net.flow.instructions.Instructions.modL1OduSignalId;
alshabib44852fb2016-04-15 15:56:51 -0700104import static org.onosproject.provider.of.flow.util.OpenFlowValueMapper.*;
alshabib19fdc122014-10-03 11:38:19 -0700105
alshabib1c319ff2014-10-04 20:29:09 -0700106public class FlowEntryBuilder {
Jian Lia0d9a172016-04-01 16:58:06 -0700107 private static final Logger log = LoggerFactory.getLogger(FlowEntryBuilder.class);
alshabib6b5cfec2014-09-18 17:42:18 -0700108
109 private final OFFlowStatsEntry stat;
110 private final OFFlowRemoved removed;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800111 private final OFFlowMod flowMod;
alshabib6b5cfec2014-09-18 17:42:18 -0700112
113 private final Match match;
alshabib346b5b32015-03-06 00:42:16 -0800114
Jonathan Hart67fc0972015-03-19 15:21:20 -0700115 // All actions are contained in an OFInstruction. For OF1.0
116 // the instruction type is apply instruction (immediate set in ONOS speak)
alshabib346b5b32015-03-06 00:42:16 -0800117 private final List<OFInstruction> instructions;
alshabib6b5cfec2014-09-18 17:42:18 -0700118
Jonathan Harte4e74f02016-03-03 12:57:40 -0800119 private final DeviceId deviceId;
alshabib6b5cfec2014-09-18 17:42:18 -0700120
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800121 public enum FlowType { STAT, REMOVED, MOD }
122
123 private final FlowType type;
alshabib6b5cfec2014-09-18 17:42:18 -0700124
Jonathan Hart3c259162015-10-21 21:31:19 -0700125 private final DriverService driverService;
126
Jonathan Harte4e74f02016-03-03 12:57:40 -0800127 public FlowEntryBuilder(DeviceId deviceId, OFFlowStatsEntry entry, DriverService driverService) {
Saurav Dasfa2fa932015-03-03 11:29:48 -0800128 this.stat = entry;
129 this.match = entry.getMatch();
alshabib346b5b32015-03-06 00:42:16 -0800130 this.instructions = getInstructions(entry);
Jonathan Harte4e74f02016-03-03 12:57:40 -0800131 this.deviceId = deviceId;
Saurav Dasfa2fa932015-03-03 11:29:48 -0800132 this.removed = null;
133 this.flowMod = null;
134 this.type = FlowType.STAT;
Jonathan Hart3c259162015-10-21 21:31:19 -0700135 this.driverService = driverService;
Saurav Dasfa2fa932015-03-03 11:29:48 -0800136 }
137
Jonathan Harte4e74f02016-03-03 12:57:40 -0800138 public FlowEntryBuilder(DeviceId deviceId, OFFlowRemoved removed, DriverService driverService) {
alshabib6b5cfec2014-09-18 17:42:18 -0700139 this.match = removed.getMatch();
140 this.removed = removed;
Jonathan Harte4e74f02016-03-03 12:57:40 -0800141 this.deviceId = deviceId;
alshabib346b5b32015-03-06 00:42:16 -0800142 this.instructions = null;
alshabib6b5cfec2014-09-18 17:42:18 -0700143 this.stat = null;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800144 this.flowMod = null;
145 this.type = FlowType.REMOVED;
Jonathan Hart3c259162015-10-21 21:31:19 -0700146 this.driverService = driverService;
alshabib6b5cfec2014-09-18 17:42:18 -0700147 }
148
Jonathan Harte4e74f02016-03-03 12:57:40 -0800149 public FlowEntryBuilder(DeviceId deviceId, OFFlowMod fm, DriverService driverService) {
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800150 this.match = fm.getMatch();
Jonathan Harte4e74f02016-03-03 12:57:40 -0800151 this.deviceId = deviceId;
alshabib346b5b32015-03-06 00:42:16 -0800152 this.instructions = getInstructions(fm);
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800153 this.type = FlowType.MOD;
154 this.flowMod = fm;
155 this.stat = null;
156 this.removed = null;
Jonathan Hart3c259162015-10-21 21:31:19 -0700157 this.driverService = driverService;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800158 }
alshabib1c319ff2014-10-04 20:29:09 -0700159
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800160 public FlowEntry build(FlowEntryState... state) {
Brian O'Connor21564612015-12-05 19:24:59 -0800161 FlowRule.Builder builder;
162 try {
163 switch (this.type) {
164 case STAT:
165 builder = DefaultFlowRule.builder()
Jonathan Harte4e74f02016-03-03 12:57:40 -0800166 .forDevice(deviceId)
Brian O'Connor21564612015-12-05 19:24:59 -0800167 .withSelector(buildSelector())
168 .withTreatment(buildTreatment())
169 .withPriority(stat.getPriority())
170 .makeTemporary(stat.getIdleTimeout())
Jonathan Hartd1ce4b02016-01-11 13:28:36 -0800171 .withCookie(stat.getCookie().getValue());
172 if (stat.getVersion() != OFVersion.OF_10) {
173 builder.forTable(stat.getTableId().getValue());
174 }
alshabibbdcbb102015-04-22 14:16:38 -0700175
Brian O'Connor21564612015-12-05 19:24:59 -0800176 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
Thiago Santos877914d2016-07-20 18:29:29 -0300177 SECONDS.toNanos(stat.getDurationSec())
178 + stat.getDurationNsec(), NANOSECONDS,
Brian O'Connor21564612015-12-05 19:24:59 -0800179 stat.getPacketCount().getValue(),
180 stat.getByteCount().getValue());
181 case REMOVED:
182 builder = DefaultFlowRule.builder()
Jonathan Harte4e74f02016-03-03 12:57:40 -0800183 .forDevice(deviceId)
Brian O'Connor21564612015-12-05 19:24:59 -0800184 .withSelector(buildSelector())
185 .withPriority(removed.getPriority())
186 .makeTemporary(removed.getIdleTimeout())
Murat Parlakisikc6759e82016-06-29 03:22:22 -0700187 .withCookie(removed.getCookie().getValue())
188 .withReason(FlowRule.FlowRemoveReason.parseShort(removed.getReason()));
189
Brian O'Connor21564612015-12-05 19:24:59 -0800190 if (removed.getVersion() != OFVersion.OF_10) {
191 builder.forTable(removed.getTableId().getValue());
192 }
alshabibbdcbb102015-04-22 14:16:38 -0700193
Brian O'Connor21564612015-12-05 19:24:59 -0800194 return new DefaultFlowEntry(builder.build(), FlowEntryState.REMOVED,
Thiago Santos877914d2016-07-20 18:29:29 -0300195 SECONDS.toNanos(removed.getDurationSec())
196 + removed.getDurationNsec(), NANOSECONDS,
Brian O'Connor21564612015-12-05 19:24:59 -0800197 removed.getPacketCount().getValue(),
198 removed.getByteCount().getValue());
199 case MOD:
200 FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED;
201 builder = DefaultFlowRule.builder()
Jonathan Harte4e74f02016-03-03 12:57:40 -0800202 .forDevice(deviceId)
Brian O'Connor21564612015-12-05 19:24:59 -0800203 .withSelector(buildSelector())
204 .withTreatment(buildTreatment())
205 .withPriority(flowMod.getPriority())
206 .makeTemporary(flowMod.getIdleTimeout())
207 .withCookie(flowMod.getCookie().getValue());
208 if (flowMod.getVersion() != OFVersion.OF_10) {
209 builder.forTable(flowMod.getTableId().getValue());
210 }
alshabibbdcbb102015-04-22 14:16:38 -0700211
Brian O'Connor21564612015-12-05 19:24:59 -0800212 return new DefaultFlowEntry(builder.build(), flowState, 0, 0, 0);
213 default:
214 log.error("Unknown flow type : {}", this.type);
215 return null;
216 }
217 } catch (UnsupportedOperationException e) {
218 log.warn("Error building flow entry", e);
219 return null;
alshabib6b5cfec2014-09-18 17:42:18 -0700220 }
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800221
alshabib6b5cfec2014-09-18 17:42:18 -0700222 }
223
alshabib346b5b32015-03-06 00:42:16 -0800224 private List<OFInstruction> getInstructions(OFFlowMod entry) {
alshabib19fdc122014-10-03 11:38:19 -0700225 switch (entry.getVersion()) {
226 case OF_10:
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700227 return Lists.newArrayList(OFFactoryVer13.INSTANCE.instructions()
228 .applyActions(
229 entry.getActions()));
alshabib19fdc122014-10-03 11:38:19 -0700230 case OF_11:
231 case OF_12:
232 case OF_13:
alshabib346b5b32015-03-06 00:42:16 -0800233 return entry.getInstructions();
234 default:
235 log.warn("Unknown OF version {}", entry.getVersion());
236 }
237 return Lists.newLinkedList();
238 }
239
240 private List<OFInstruction> getInstructions(OFFlowStatsEntry entry) {
241 switch (entry.getVersion()) {
242 case OF_10:
243 return Lists.newArrayList(
244 OFFactoryVer13.INSTANCE.instructions().applyActions(entry.getActions()));
245 case OF_11:
246 case OF_12:
247 case OF_13:
248 return entry.getInstructions();
alshabib19fdc122014-10-03 11:38:19 -0700249 default:
250 log.warn("Unknown OF version {}", entry.getVersion());
251 }
252 return Lists.newLinkedList();
253 }
alshabib6b5cfec2014-09-18 17:42:18 -0700254
255 private TrafficTreatment buildTreatment() {
tom9a693fd2014-10-03 11:32:19 -0700256 TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
alshabib346b5b32015-03-06 00:42:16 -0800257 for (OFInstruction in : instructions) {
258 switch (in.getType()) {
259 case GOTO_TABLE:
alshabibbdcbb102015-04-22 14:16:38 -0700260 builder.transition(((int) ((OFInstructionGotoTable) in)
261 .getTableId().getValue()));
alshabib346b5b32015-03-06 00:42:16 -0800262 break;
263 case WRITE_METADATA:
Saurav Das86af8f12015-05-25 23:55:33 -0700264 OFInstructionWriteMetadata m = (OFInstructionWriteMetadata) in;
265 builder.writeMetadata(m.getMetadata().getValue(),
266 m.getMetadataMask().getValue());
alshabib346b5b32015-03-06 00:42:16 -0800267 break;
268 case WRITE_ACTIONS:
269 builder.deferred();
270 buildActions(((OFInstructionWriteActions) in).getActions(),
271 builder);
272 break;
273 case APPLY_ACTIONS:
274 builder.immediate();
275 buildActions(((OFInstructionApplyActions) in).getActions(),
276 builder);
277 break;
278 case CLEAR_ACTIONS:
279 builder.wipeDeferred();
280 break;
281 case EXPERIMENTER:
282 break;
283 case METER:
284 break;
285 default:
286 log.warn("Unknown instructions type {}", in.getType());
alshabib6b5cfec2014-09-18 17:42:18 -0700287 }
288 }
289
290 return builder.build();
291 }
292
Jian Lia0d9a172016-04-01 16:58:06 -0700293 /**
294 * Configures traffic treatment builder with a given collection of actions.
295 *
296 * @param actions a set of OpenFlow actions
297 * @param builder traffic treatment builder
298 * @param driverHandler driver handler
299 * @param deviceId device identifier
300 * @return configured traffic treatment builder
301 */
302 public static TrafficTreatment.Builder configureTreatmentBuilder(List<OFAction> actions,
303 TrafficTreatment.Builder builder,
304 DriverHandler driverHandler,
305 DeviceId deviceId) {
306 ExtensionTreatmentInterpreter interpreter;
Charles Chan14967c22015-12-07 11:11:50 -0800307 if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
Jian Lia0d9a172016-04-01 16:58:06 -0700308 interpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class);
Charles Chan14967c22015-12-07 11:11:50 -0800309 } else {
Jian Lia0d9a172016-04-01 16:58:06 -0700310 interpreter = null;
Charles Chan14967c22015-12-07 11:11:50 -0800311 }
312
alshabib346b5b32015-03-06 00:42:16 -0800313 for (OFAction act : actions) {
314 switch (act.getType()) {
315 case OUTPUT:
316 OFActionOutput out = (OFActionOutput) act;
317 builder.setOutput(
318 PortNumber.portNumber(out.getPort().getPortNumber()));
319 break;
320 case SET_VLAN_VID:
321 OFActionSetVlanVid vlan = (OFActionSetVlanVid) act;
322 builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan()));
323 break;
324 case SET_VLAN_PCP:
325 OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act;
326 builder.setVlanPcp(pcp.getVlanPcp().getValue());
327 break;
328 case SET_DL_DST:
329 OFActionSetDlDst dldst = (OFActionSetDlDst) act;
330 builder.setEthDst(
331 MacAddress.valueOf(dldst.getDlAddr().getLong()));
332 break;
333 case SET_DL_SRC:
334 OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act;
335 builder.setEthSrc(
336 MacAddress.valueOf(dlsrc.getDlAddr().getLong()));
alshabib346b5b32015-03-06 00:42:16 -0800337 break;
338 case SET_NW_DST:
339 OFActionSetNwDst nwdst = (OFActionSetNwDst) act;
340 IPv4Address di = nwdst.getNwAddr();
341 builder.setIpDst(Ip4Address.valueOf(di.getInt()));
342 break;
343 case SET_NW_SRC:
344 OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act;
345 IPv4Address si = nwsrc.getNwAddr();
346 builder.setIpSrc(Ip4Address.valueOf(si.getInt()));
347 break;
348 case EXPERIMENTER:
349 OFActionExperimenter exp = (OFActionExperimenter) act;
350 if (exp.getExperimenter() == 0x80005A06 ||
351 exp.getExperimenter() == 0x748771) {
352 OFActionCircuit ct = (OFActionCircuit) exp;
Yafit Hadar4cc65f72016-02-10 11:23:06 +0200353 CircuitSignalID circuitSignalID = ((OFOxmOchSigid) ct.getField()).getValue();
354 builder.add(Instructions.modL0Lambda(Lambda.ochSignal(
355 lookupGridType(circuitSignalID.getGridType()),
356 lookupChannelSpacing(circuitSignalID.getChannelSpacing()),
357 circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth())));
Jian Lia0d9a172016-04-01 16:58:06 -0700358 } else if (interpreter != null) {
359 builder.extension(interpreter.mapAction(exp), deviceId);
alshabib346b5b32015-03-06 00:42:16 -0800360 } else {
361 log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter());
362 }
363 break;
364 case SET_FIELD:
365 OFActionSetField setField = (OFActionSetField) act;
Jian Lia0d9a172016-04-01 16:58:06 -0700366 handleSetField(builder, setField, driverHandler, deviceId);
alshabib346b5b32015-03-06 00:42:16 -0800367 break;
368 case POP_MPLS:
369 OFActionPopMpls popMpls = (OFActionPopMpls) act;
Ray Milkey84d5a292016-02-22 14:04:01 -0800370 builder.popMpls(new EthType(popMpls.getEthertype().getValue()));
alshabib346b5b32015-03-06 00:42:16 -0800371 break;
372 case PUSH_MPLS:
373 builder.pushMpls();
374 break;
375 case COPY_TTL_IN:
376 builder.copyTtlIn();
377 break;
378 case COPY_TTL_OUT:
379 builder.copyTtlOut();
380 break;
381 case DEC_MPLS_TTL:
382 builder.decMplsTtl();
383 break;
384 case DEC_NW_TTL:
385 builder.decNwTtl();
386 break;
387 case GROUP:
388 OFActionGroup group = (OFActionGroup) act;
389 builder.group(new DefaultGroupId(group.getGroup().getGroupNumber()));
390 break;
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200391 case SET_QUEUE:
392 OFActionSetQueue setQueue = (OFActionSetQueue) act;
393 builder.setQueue(setQueue.getQueueId());
394 break;
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200395 case ENQUEUE:
396 OFActionEnqueue enqueue = (OFActionEnqueue) act;
Jian Liffef5002016-04-04 23:27:37 -0700397 builder.setQueue(enqueue.getQueueId(),
398 PortNumber.portNumber(enqueue.getPort().getPortNumber()));
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200399 break;
Jonathan Hart67fc0972015-03-19 15:21:20 -0700400 case STRIP_VLAN:
alshabib346b5b32015-03-06 00:42:16 -0800401 case POP_VLAN:
402 builder.popVlan();
403 break;
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700404 case PUSH_VLAN:
Konstantinos Kanonakis9215ff22016-11-04 13:28:11 -0500405 OFActionPushVlan pushVlan = (OFActionPushVlan) act;
406 builder.pushVlan(new EthType((short) pushVlan.getEthertype().getValue()));
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700407 break;
alshabib346b5b32015-03-06 00:42:16 -0800408 case SET_TP_DST:
409 case SET_TP_SRC:
410 case POP_PBB:
411 case PUSH_PBB:
alshabib346b5b32015-03-06 00:42:16 -0800412 case SET_MPLS_LABEL:
413 case SET_MPLS_TC:
414 case SET_MPLS_TTL:
415 case SET_NW_ECN:
416 case SET_NW_TOS:
417 case SET_NW_TTL:
alshabib346b5b32015-03-06 00:42:16 -0800418
alshabib346b5b32015-03-06 00:42:16 -0800419 default:
420 log.warn("Action type {} not yet implemented.", act.getType());
421 }
422 }
423 return builder;
424 }
425
Jian Lia0d9a172016-04-01 16:58:06 -0700426 private TrafficTreatment.Builder buildActions(List<OFAction> actions,
427 TrafficTreatment.Builder builder) {
Jonathan Harte4e74f02016-03-03 12:57:40 -0800428 DriverHandler driverHandler = getDriver(deviceId);
Jian Lia0d9a172016-04-01 16:58:06 -0700429
430 return configureTreatmentBuilder(actions, builder, driverHandler, deviceId);
431 }
432
Charles Chancad338a2016-09-16 18:03:11 -0700433 // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES
Jian Lia0d9a172016-04-01 16:58:06 -0700434 private static void handleSetField(TrafficTreatment.Builder builder,
435 OFActionSetField action,
436 DriverHandler driverHandler,
437 DeviceId deviceId) {
Charles Chan14967c22015-12-07 11:11:50 -0800438 ExtensionTreatmentInterpreter treatmentInterpreter;
439 if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
440 treatmentInterpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class);
441 } else {
442 treatmentInterpreter = null;
443 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700444 OFOxm<?> oxm = action.getField();
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800445 switch (oxm.getMatchField().id) {
446 case VLAN_PCP:
447 @SuppressWarnings("unchecked")
448 OFOxm<VlanPcp> vlanpcp = (OFOxm<VlanPcp>) oxm;
449 builder.setVlanPcp(vlanpcp.getValue().getValue());
450 break;
451 case VLAN_VID:
Charles Chan4211baa2016-04-20 17:10:40 -0700452 if (treatmentInterpreter != null) {
453 try {
454 builder.extension(treatmentInterpreter.mapAction(action), deviceId);
455 break;
456 } catch (UnsupportedOperationException e) {
457 log.debug("Unsupported action extension; defaulting to native OF");
458 }
Charles Chan14967c22015-12-07 11:11:50 -0800459 }
alshabib44852fb2016-04-15 15:56:51 -0700460 @SuppressWarnings("unchecked")
461 OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm;
462 builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan()));
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800463 break;
464 case ETH_DST:
465 @SuppressWarnings("unchecked")
466 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethdst =
467 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
468 builder.setEthDst(MacAddress.valueOf(ethdst.getValue().getLong()));
469 break;
470 case ETH_SRC:
471 @SuppressWarnings("unchecked")
472 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethsrc =
473 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
474 builder.setEthSrc(MacAddress.valueOf(ethsrc.getValue().getLong()));
475 break;
476 case IPV4_DST:
477 @SuppressWarnings("unchecked")
478 OFOxm<IPv4Address> ip4dst = (OFOxm<IPv4Address>) oxm;
479 builder.setIpDst(Ip4Address.valueOf(ip4dst.getValue().getInt()));
480 break;
481 case IPV4_SRC:
482 @SuppressWarnings("unchecked")
483 OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm;
484 builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt()));
485 break;
sangho3f97a17d2015-01-29 22:56:29 -0800486 case MPLS_LABEL:
487 @SuppressWarnings("unchecked")
488 OFOxm<U32> labelId = (OFOxm<U32>) oxm;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100489 builder.setMpls(MplsLabel.mplsLabel((int) labelId.getValue().getValue()));
sangho3f97a17d2015-01-29 22:56:29 -0800490 break;
Saurav Das73a7dd42015-08-19 22:20:31 -0700491 case MPLS_BOS:
492 @SuppressWarnings("unchecked")
Pier Ventre23f78672016-11-15 08:46:34 -0800493 OFOxm<OFBooleanValue> mplsBos = (OFOxm<OFBooleanValue>) oxm;
494 builder.setMplsBos(mplsBos.getValue().getValue());
Saurav Das73a7dd42015-08-19 22:20:31 -0700495 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700496 case TUNNEL_ID:
497 @SuppressWarnings("unchecked")
498 OFOxm<U64> tunnelId = (OFOxm<U64>) oxm;
499 builder.setTunnelId(tunnelId.getValue().getValue());
500 break;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700501 case TCP_DST:
502 @SuppressWarnings("unchecked")
503 OFOxm<TransportPort> tcpdst = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700504 builder.setTcpDst(TpPort.tpPort(tcpdst.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700505 break;
506 case TCP_SRC:
507 @SuppressWarnings("unchecked")
508 OFOxm<TransportPort> tcpsrc = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700509 builder.setTcpSrc(TpPort.tpPort(tcpsrc.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700510 break;
511 case UDP_DST:
512 @SuppressWarnings("unchecked")
513 OFOxm<TransportPort> udpdst = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700514 builder.setUdpDst(TpPort.tpPort(udpdst.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700515 break;
516 case UDP_SRC:
517 @SuppressWarnings("unchecked")
518 OFOxm<TransportPort> udpsrc = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700519 builder.setUdpSrc(TpPort.tpPort(udpsrc.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700520 break;
Jonathan Hart3c259162015-10-21 21:31:19 -0700521 case TUNNEL_IPV4_DST:
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530522 case NSP:
523 case NSI:
524 case NSH_C1:
525 case NSH_C2:
526 case NSH_C3:
527 case NSH_C4:
528 case NSH_MDTYPE:
529 case NSH_NP:
530 case ENCAP_ETH_SRC:
531 case ENCAP_ETH_DST:
532 case ENCAP_ETH_TYPE:
533 case TUN_GPE_NP:
Jian Liffef5002016-04-04 23:27:37 -0700534 if (treatmentInterpreter != null) {
535 try {
536 builder.extension(treatmentInterpreter.mapAction(action), deviceId);
537 } catch (UnsupportedOperationException e) {
alshabib44852fb2016-04-15 15:56:51 -0700538 log.debug(e.getMessage());
Jian Liffef5002016-04-04 23:27:37 -0700539 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700540 }
541 break;
Yafit Hadar73514612015-11-04 10:14:21 +0200542 case EXP_ODU_SIG_ID:
543 @SuppressWarnings("unchecked")
544 OFOxm<OduSignalID> oduID = (OFOxm<OduSignalID>) oxm;
545 OduSignalID oduSignalID = oduID.getValue();
546 OduSignalId oduSignalId = OduSignalId.oduSignalId(oduSignalID.getTpn(),
547 oduSignalID.getTslen(),
548 oduSignalID.getTsmap());
549 builder.add(modL1OduSignalId(oduSignalId));
550 break;
551 case EXP_OCH_SIG_ID:
552 try {
553 @SuppressWarnings("unchecked")
554 OFOxm<CircuitSignalID> ochId = (OFOxm<CircuitSignalID>) oxm;
555 CircuitSignalID circuitSignalID = ochId.getValue();
556 builder.add(modL0Lambda(Lambda.ochSignal(
557 lookupGridType(circuitSignalID.getGridType()),
558 lookupChannelSpacing(circuitSignalID.getChannelSpacing()),
559 circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth())));
560 } catch (NoMappingFoundException e) {
561 log.warn(e.getMessage());
562 break;
563 }
564 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800565 case ARP_OP:
lishuai67574ce2016-05-12 16:39:59 +0800566 @SuppressWarnings("unchecked")
567 OFOxm<org.projectfloodlight.openflow.types.ArpOpcode> arpop =
568 (OFOxm<org.projectfloodlight.openflow.types.ArpOpcode>) oxm;
569 builder.setArpOp((short) arpop.getValue().getOpcode());
570 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800571 case ARP_SHA:
lishuai67574ce2016-05-12 16:39:59 +0800572 @SuppressWarnings("unchecked")
573 OFOxm<org.projectfloodlight.openflow.types.MacAddress> arpsha =
574 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
575 builder.setArpSha(MacAddress.valueOf(arpsha.getValue().getLong()));
576 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800577 case ARP_SPA:
lishuai67574ce2016-05-12 16:39:59 +0800578 @SuppressWarnings("unchecked")
579 OFOxm<IPv4Address> arpspa = (OFOxm<IPv4Address>) oxm;
580 builder.setArpSpa(Ip4Address.valueOf(arpspa.getValue().getInt()));
581 break;
Charles Chancad338a2016-09-16 18:03:11 -0700582 case OFDPA_MPLS_TYPE:
Pier Ventre6f630052016-10-18 09:58:41 -0700583 case OFDPA_OVID:
Charles Chancad338a2016-09-16 18:03:11 -0700584 if (treatmentInterpreter != null) {
585 try {
586 builder.extension(treatmentInterpreter.mapAction(action), deviceId);
587 break;
588 } catch (UnsupportedOperationException e) {
589 log.warn("Unsupported action extension");
590 }
591 }
592 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800593 case ARP_THA:
594 case ARP_TPA:
595 case BSN_EGR_PORT_GROUP_ID:
596 case BSN_GLOBAL_VRF_ALLOWED:
597 case BSN_IN_PORTS_128:
598 case BSN_L3_DST_CLASS_ID:
599 case BSN_L3_INTERFACE_CLASS_ID:
600 case BSN_L3_SRC_CLASS_ID:
601 case BSN_LAG_ID:
602 case BSN_TCP_FLAGS:
603 case BSN_UDF0:
604 case BSN_UDF1:
605 case BSN_UDF2:
606 case BSN_UDF3:
607 case BSN_UDF4:
608 case BSN_UDF5:
609 case BSN_UDF6:
610 case BSN_UDF7:
611 case BSN_VLAN_XLATE_PORT_GROUP_ID:
612 case BSN_VRF:
613 case ETH_TYPE:
614 case ICMPV4_CODE:
615 case ICMPV4_TYPE:
616 case ICMPV6_CODE:
617 case ICMPV6_TYPE:
618 case IN_PHY_PORT:
619 case IN_PORT:
620 case IPV6_DST:
621 case IPV6_FLABEL:
622 case IPV6_ND_SLL:
623 case IPV6_ND_TARGET:
624 case IPV6_ND_TLL:
625 case IPV6_SRC:
626 case IP_DSCP:
627 case IP_ECN:
628 case IP_PROTO:
629 case METADATA:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800630 case MPLS_TC:
631 case OCH_SIGID:
632 case OCH_SIGID_BASIC:
633 case OCH_SIGTYPE:
634 case OCH_SIGTYPE_BASIC:
635 case SCTP_DST:
636 case SCTP_SRC:
Yafit Hadar73514612015-11-04 10:14:21 +0200637 case EXP_ODU_SIGTYPE:
638 case EXP_OCH_SIGTYPE:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800639 default:
640 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
641 break;
642 }
643 }
644
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700645 // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES
alshabib6b5cfec2014-09-18 17:42:18 -0700646 private TrafficSelector buildSelector() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800647 MacAddress mac;
648 Ip4Prefix ip4Prefix;
649 Ip6Address ip6Address;
650 Ip6Prefix ip6Prefix;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800651 Ip4Address ip;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800652
Jonathan Harte4e74f02016-03-03 12:57:40 -0800653 DriverHandler driverHandler = getDriver(deviceId);
Charles Chan14967c22015-12-07 11:11:50 -0800654 ExtensionSelectorInterpreter selectorInterpreter;
655 if (driverHandler.hasBehaviour(ExtensionSelectorInterpreter.class)) {
656 selectorInterpreter = driverHandler.behaviour(ExtensionSelectorInterpreter.class);
657 } else {
658 selectorInterpreter = null;
659 }
660
tom9a693fd2014-10-03 11:32:19 -0700661 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700662 for (MatchField<?> field : match.getMatchFields()) {
663 switch (field.id) {
664 case IN_PORT:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800665 builder.matchInPort(PortNumber
alshabib010c31d2014-09-26 10:01:12 -0700666 .portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700667 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800668 case IN_PHY_PORT:
669 builder.matchInPhyPort(PortNumber
670 .portNumber(match.get(MatchField.IN_PHY_PORT).getPortNumber()));
671 break;
672 case METADATA:
673 long metadata =
674 match.get(MatchField.METADATA).getValue().getValue();
675 builder.matchMetadata(metadata);
676 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700677 case ETH_DST:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800678 if (match.isPartiallyMasked(MatchField.ETH_DST)) {
679 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
680 match.getMasked(MatchField.ETH_DST);
681 builder.matchEthDstMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
682 MacAddress.valueOf(maskedMac.getMask().getLong()));
683 } else {
684 mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
685 builder.matchEthDst(mac);
686 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800687 break;
688 case ETH_SRC:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800689 if (match.isPartiallyMasked(MatchField.ETH_SRC)) {
690 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
691 match.getMasked(MatchField.ETH_SRC);
692 builder.matchEthSrcMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
693 MacAddress.valueOf(maskedMac.getMask().getLong()));
694 } else {
695 mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
696 builder.matchEthSrc(mac);
697 }
alshabib6b5cfec2014-09-18 17:42:18 -0700698 break;
699 case ETH_TYPE:
700 int ethType = match.get(MatchField.ETH_TYPE).getValue();
Jonathan Hart8cf212a2015-10-29 17:42:03 -0700701 builder.matchEthType((short) ethType);
alshabib6b5cfec2014-09-18 17:42:18 -0700702 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700703 case VLAN_VID:
Charles Chan14967c22015-12-07 11:11:50 -0800704 if (selectorInterpreter != null &&
705 selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
706 if (match.getVersion().equals(OFVersion.OF_13)) {
707 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.VLAN_VID);
708 builder.extension(selectorInterpreter.mapOxm(oxm),
Jonathan Harte4e74f02016-03-03 12:57:40 -0800709 deviceId);
Charles Chan14967c22015-12-07 11:11:50 -0800710 } else {
711 break;
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800712 }
713 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800714 VlanId vlanId = null;
715 if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
716 Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
717 if (masked.getValue().equals(OFVlanVidMatch.PRESENT)
718 && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
719 vlanId = VlanId.ANY;
720 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700721 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800722 if (!match.get(MatchField.VLAN_VID).isPresentBitSet()) {
723 vlanId = VlanId.NONE;
724 } else {
725 vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
726 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700727 }
Charles Chan14967c22015-12-07 11:11:50 -0800728 if (vlanId != null) {
729 builder.matchVlanId(vlanId);
730 }
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800731 }
alshabib6b5cfec2014-09-18 17:42:18 -0700732 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800733 case VLAN_PCP:
734 byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
735 builder.matchVlanPcp(vlanPcp);
736 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800737 case IP_DSCP:
738 byte ipDscp = match.get(MatchField.IP_DSCP).getDscpValue();
739 builder.matchIPDscp(ipDscp);
740 break;
741 case IP_ECN:
742 byte ipEcn = match.get(MatchField.IP_ECN).getEcnValue();
743 builder.matchIPEcn(ipEcn);
744 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800745 case IP_PROTO:
746 short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
747 builder.matchIPProtocol((byte) proto);
748 break;
749 case IPV4_SRC:
750 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
751 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800752 ip4Prefix = Ip4Prefix.valueOf(
753 maskedIp.getValue().getInt(),
754 maskedIp.getMask().asCidrMaskLength());
755 } else {
756 ip4Prefix = Ip4Prefix.valueOf(
757 match.get(MatchField.IPV4_SRC).getInt(),
758 Ip4Prefix.MAX_MASK_LENGTH);
759 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800760 builder.matchIPSrc(ip4Prefix);
761 break;
762 case IPV4_DST:
763 if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
764 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800765 ip4Prefix = Ip4Prefix.valueOf(
766 maskedIp.getValue().getInt(),
767 maskedIp.getMask().asCidrMaskLength());
768 } else {
769 ip4Prefix = Ip4Prefix.valueOf(
770 match.get(MatchField.IPV4_DST).getInt(),
771 Ip4Prefix.MAX_MASK_LENGTH);
772 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800773 builder.matchIPDst(ip4Prefix);
Jonathan Hart34bc6142014-10-17 11:00:43 -0700774 break;
775 case TCP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700776 builder.matchTcpSrc(TpPort.tpPort(match.get(MatchField.TCP_SRC).getPort()));
Jonathan Hart34bc6142014-10-17 11:00:43 -0700777 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800778 case TCP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700779 builder.matchTcpDst(TpPort.tpPort(match.get(MatchField.TCP_DST).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800780 break;
781 case UDP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700782 builder.matchUdpSrc(TpPort.tpPort(match.get(MatchField.UDP_SRC).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800783 break;
784 case UDP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700785 builder.matchUdpDst(TpPort.tpPort(match.get(MatchField.UDP_DST).getPort()));
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700786 break;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100787 case MPLS_LABEL:
788 builder.matchMplsLabel(MplsLabel.mplsLabel((int) match.get(MatchField.MPLS_LABEL)
789 .getValue()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800790 break;
Saurav Dasffc5bbc2015-08-18 23:30:19 -0700791 case MPLS_BOS:
792 builder.matchMplsBos(match.get(MatchField.MPLS_BOS).getValue());
793 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800794 case SCTP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700795 builder.matchSctpSrc(TpPort.tpPort(match.get(MatchField.SCTP_SRC).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800796 break;
797 case SCTP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700798 builder.matchSctpDst(TpPort.tpPort(match.get(MatchField.SCTP_DST).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800799 break;
800 case ICMPV4_TYPE:
801 byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
802 builder.matchIcmpType(icmpType);
803 break;
804 case ICMPV4_CODE:
805 byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode();
806 builder.matchIcmpCode(icmpCode);
807 break;
808 case IPV6_SRC:
809 if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
810 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
811 ip6Prefix = Ip6Prefix.valueOf(
812 maskedIp.getValue().getBytes(),
813 maskedIp.getMask().asCidrMaskLength());
814 } else {
815 ip6Prefix = Ip6Prefix.valueOf(
816 match.get(MatchField.IPV6_SRC).getBytes(),
817 Ip6Prefix.MAX_MASK_LENGTH);
818 }
819 builder.matchIPv6Src(ip6Prefix);
820 break;
821 case IPV6_DST:
822 if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
823 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
824 ip6Prefix = Ip6Prefix.valueOf(
825 maskedIp.getValue().getBytes(),
826 maskedIp.getMask().asCidrMaskLength());
827 } else {
828 ip6Prefix = Ip6Prefix.valueOf(
829 match.get(MatchField.IPV6_DST).getBytes(),
830 Ip6Prefix.MAX_MASK_LENGTH);
831 }
832 builder.matchIPv6Dst(ip6Prefix);
833 break;
834 case IPV6_FLABEL:
835 int flowLabel =
836 match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue();
837 builder.matchIPv6FlowLabel(flowLabel);
838 break;
839 case ICMPV6_TYPE:
840 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
841 builder.matchIcmpv6Type(icmpv6type);
842 break;
843 case ICMPV6_CODE:
844 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
845 builder.matchIcmpv6Code(icmpv6code);
846 break;
847 case IPV6_ND_TARGET:
848 ip6Address =
849 Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes());
850 builder.matchIPv6NDTargetAddress(ip6Address);
851 break;
852 case IPV6_ND_SLL:
853 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong());
854 builder.matchIPv6NDSourceLinkLayerAddress(mac);
855 break;
856 case IPV6_ND_TLL:
857 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong());
858 builder.matchIPv6NDTargetLinkLayerAddress(mac);
859 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800860 case IPV6_EXTHDR:
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800861 builder.matchIPv6ExthdrFlags((short) match.get(MatchField.IPV6_EXTHDR)
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700862 .getValue());
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800863 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700864 case OCH_SIGID:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700865 CircuitSignalID sigId = match.get(MatchField.OCH_SIGID);
866 builder.add(matchLambda(Lambda.ochSignal(
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700867 lookupGridType(sigId.getGridType()), lookupChannelSpacing(sigId.getChannelSpacing()),
Marc De Leenheer0b8b2ef2015-08-03 15:39:00 -0700868 sigId.getChannelNumber(), sigId.getSpectralWidth())
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700869 ));
Marc De Leenheer49087752014-10-23 13:54:09 -0700870 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800871 case OCH_SIGTYPE:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700872 U8 sigType = match.get(MatchField.OCH_SIGTYPE);
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700873 builder.add(matchOchSignalType(lookupOchSignalType((byte) sigType.getValue())));
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800874 break;
Yafit Hadar73514612015-11-04 10:14:21 +0200875 case EXP_OCH_SIG_ID:
876 try {
877 CircuitSignalID expSigId = match.get(MatchField.EXP_OCH_SIG_ID);
878 builder.add(matchLambda(Lambda.ochSignal(
879 lookupGridType(expSigId.getGridType()), lookupChannelSpacing(expSigId.getChannelSpacing()),
880 expSigId.getChannelNumber(), expSigId.getSpectralWidth())));
881 } catch (NoMappingFoundException e) {
882 log.warn(e.getMessage());
883 break;
884 }
885 break;
886 case EXP_OCH_SIGTYPE:
887 try {
888 U8 expOchSigType = match.get(MatchField.EXP_OCH_SIGTYPE);
889 builder.add(matchOchSignalType(lookupOchSignalType((byte) expOchSigType.getValue())));
890 } catch (NoMappingFoundException e) {
891 log.warn(e.getMessage());
892 break;
893 }
894 break;
895 case EXP_ODU_SIG_ID:
896 OduSignalId oduSignalId = OduSignalId.oduSignalId(match.get(MatchField.EXP_ODU_SIG_ID).getTpn(),
897 match.get(MatchField.EXP_ODU_SIG_ID).getTslen(),
898 match.get(MatchField.EXP_ODU_SIG_ID).getTsmap());
899 builder.add(matchOduSignalId(oduSignalId));
900 break;
901 case EXP_ODU_SIGTYPE:
902 try {
903 U8 oduSigType = match.get(MatchField.EXP_ODU_SIGTYPE);
904 builder.add(matchOduSignalType(lookupOduSignalType((byte) oduSigType.getValue())));
905 } catch (NoMappingFoundException e) {
906 log.warn(e.getMessage());
907 break;
908 }
909 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700910 case TUNNEL_ID:
911 long tunnelId = match.get(MatchField.TUNNEL_ID).getValue();
912 builder.matchTunnelId(tunnelId);
913 break;
BitOhenryb40129a2015-11-30 12:41:18 +0800914 case ARP_OP:
915 int arpOp = match.get(MatchField.ARP_OP).getOpcode();
916 builder.matchArpOp(arpOp);
917 break;
BitOhenrya331b182015-11-23 08:39:37 +0800918 case ARP_SHA:
919 mac = MacAddress.valueOf(match.get(MatchField.ARP_SHA).getLong());
920 builder.matchArpSha(mac);
921 break;
BitOhenry296b4542015-11-24 08:41:58 +0800922 case ARP_SPA:
923 ip = Ip4Address.valueOf(match.get(MatchField.ARP_SPA).getInt());
924 builder.matchArpSpa(ip);
925 break;
BitOhenry76430852015-11-20 19:04:49 +0800926 case ARP_THA:
927 mac = MacAddress.valueOf(match.get(MatchField.ARP_THA).getLong());
928 builder.matchArpTha(mac);
929 break;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800930 case ARP_TPA:
931 ip = Ip4Address.valueOf(match.get(MatchField.ARP_TPA).getInt());
932 builder.matchArpTpa(ip);
933 break;
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530934 case NSP:
935 if (selectorInterpreter != null) {
936 try {
937 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.NSP);
938 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
939 } catch (UnsupportedOperationException e) {
940 log.debug(e.getMessage());
941 }
942 }
943 break;
944 case NSI:
945 if (selectorInterpreter != null) {
946 try {
947 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.NSI);
948 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
949 } catch (UnsupportedOperationException e) {
950 log.debug(e.getMessage());
951 }
952 }
953 break;
954 case ENCAP_ETH_TYPE:
955 if (selectorInterpreter != null) {
956 try {
957 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.ENCAP_ETH_TYPE);
958 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
959 } catch (UnsupportedOperationException e) {
960 log.debug(e.getMessage());
961 }
962 }
963 break;
Pier Ventre6f630052016-10-18 09:58:41 -0700964 case OFDPA_OVID:
965 if (selectorInterpreter != null &&
966 selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_OVID.type())) {
967 if (match.getVersion().equals(OFVersion.OF_13)) {
968 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.OFDPA_OVID);
969 builder.extension(selectorInterpreter.mapOxm(oxm),
970 deviceId);
971 } else {
972 break;
973 }
974 }
975 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700976 case MPLS_TC:
alshabib6b5cfec2014-09-18 17:42:18 -0700977 default:
978 log.warn("Match type {} not yet implemented.", field.id);
alshabib6b5cfec2014-09-18 17:42:18 -0700979 }
980 }
981 return builder.build();
982 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700983
Jian Liffef5002016-04-04 23:27:37 -0700984 private DriverHandler getDriver(DeviceId devId) {
985 Driver driver = driverService.getDriver(devId);
986 DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, devId));
Jonathan Hart3c259162015-10-21 21:31:19 -0700987 return handler;
988 }
alshabib6b5cfec2014-09-18 17:42:18 -0700989}