blob: 2b042e6ccc7afaa5a599ee7df3de1f8567f5b7c9 [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:
Pier Ventre9cf536b2016-10-21 13:30:18 -0700584 case OFDPA_MPLS_L2_PORT:
Pier Ventredb252cc2016-10-21 21:54:26 -0700585 case OFDPA_QOS_INDEX:
Charles Chancad338a2016-09-16 18:03:11 -0700586 if (treatmentInterpreter != null) {
587 try {
588 builder.extension(treatmentInterpreter.mapAction(action), deviceId);
589 break;
590 } catch (UnsupportedOperationException e) {
591 log.warn("Unsupported action extension");
592 }
593 }
594 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800595 case ARP_THA:
596 case ARP_TPA:
597 case BSN_EGR_PORT_GROUP_ID:
598 case BSN_GLOBAL_VRF_ALLOWED:
599 case BSN_IN_PORTS_128:
600 case BSN_L3_DST_CLASS_ID:
601 case BSN_L3_INTERFACE_CLASS_ID:
602 case BSN_L3_SRC_CLASS_ID:
603 case BSN_LAG_ID:
604 case BSN_TCP_FLAGS:
605 case BSN_UDF0:
606 case BSN_UDF1:
607 case BSN_UDF2:
608 case BSN_UDF3:
609 case BSN_UDF4:
610 case BSN_UDF5:
611 case BSN_UDF6:
612 case BSN_UDF7:
613 case BSN_VLAN_XLATE_PORT_GROUP_ID:
614 case BSN_VRF:
615 case ETH_TYPE:
616 case ICMPV4_CODE:
617 case ICMPV4_TYPE:
618 case ICMPV6_CODE:
619 case ICMPV6_TYPE:
620 case IN_PHY_PORT:
621 case IN_PORT:
622 case IPV6_DST:
623 case IPV6_FLABEL:
624 case IPV6_ND_SLL:
625 case IPV6_ND_TARGET:
626 case IPV6_ND_TLL:
627 case IPV6_SRC:
628 case IP_DSCP:
629 case IP_ECN:
630 case IP_PROTO:
631 case METADATA:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800632 case MPLS_TC:
633 case OCH_SIGID:
634 case OCH_SIGID_BASIC:
635 case OCH_SIGTYPE:
636 case OCH_SIGTYPE_BASIC:
637 case SCTP_DST:
638 case SCTP_SRC:
Yafit Hadar73514612015-11-04 10:14:21 +0200639 case EXP_ODU_SIGTYPE:
640 case EXP_OCH_SIGTYPE:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800641 default:
642 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
643 break;
644 }
645 }
646
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700647 // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES
alshabib6b5cfec2014-09-18 17:42:18 -0700648 private TrafficSelector buildSelector() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800649 MacAddress mac;
650 Ip4Prefix ip4Prefix;
651 Ip6Address ip6Address;
652 Ip6Prefix ip6Prefix;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800653 Ip4Address ip;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800654
Jonathan Harte4e74f02016-03-03 12:57:40 -0800655 DriverHandler driverHandler = getDriver(deviceId);
Charles Chan14967c22015-12-07 11:11:50 -0800656 ExtensionSelectorInterpreter selectorInterpreter;
657 if (driverHandler.hasBehaviour(ExtensionSelectorInterpreter.class)) {
658 selectorInterpreter = driverHandler.behaviour(ExtensionSelectorInterpreter.class);
659 } else {
660 selectorInterpreter = null;
661 }
662
tom9a693fd2014-10-03 11:32:19 -0700663 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700664 for (MatchField<?> field : match.getMatchFields()) {
665 switch (field.id) {
666 case IN_PORT:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800667 builder.matchInPort(PortNumber
alshabib010c31d2014-09-26 10:01:12 -0700668 .portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700669 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800670 case IN_PHY_PORT:
671 builder.matchInPhyPort(PortNumber
672 .portNumber(match.get(MatchField.IN_PHY_PORT).getPortNumber()));
673 break;
674 case METADATA:
675 long metadata =
676 match.get(MatchField.METADATA).getValue().getValue();
677 builder.matchMetadata(metadata);
678 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700679 case ETH_DST:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800680 if (match.isPartiallyMasked(MatchField.ETH_DST)) {
681 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
682 match.getMasked(MatchField.ETH_DST);
683 builder.matchEthDstMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
684 MacAddress.valueOf(maskedMac.getMask().getLong()));
685 } else {
686 mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
687 builder.matchEthDst(mac);
688 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800689 break;
690 case ETH_SRC:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800691 if (match.isPartiallyMasked(MatchField.ETH_SRC)) {
692 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
693 match.getMasked(MatchField.ETH_SRC);
694 builder.matchEthSrcMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
695 MacAddress.valueOf(maskedMac.getMask().getLong()));
696 } else {
697 mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
698 builder.matchEthSrc(mac);
699 }
alshabib6b5cfec2014-09-18 17:42:18 -0700700 break;
701 case ETH_TYPE:
702 int ethType = match.get(MatchField.ETH_TYPE).getValue();
Jonathan Hart8cf212a2015-10-29 17:42:03 -0700703 builder.matchEthType((short) ethType);
alshabib6b5cfec2014-09-18 17:42:18 -0700704 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700705 case VLAN_VID:
Charles Chan14967c22015-12-07 11:11:50 -0800706 if (selectorInterpreter != null &&
707 selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
708 if (match.getVersion().equals(OFVersion.OF_13)) {
709 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.VLAN_VID);
710 builder.extension(selectorInterpreter.mapOxm(oxm),
Jonathan Harte4e74f02016-03-03 12:57:40 -0800711 deviceId);
Charles Chan14967c22015-12-07 11:11:50 -0800712 } else {
713 break;
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800714 }
715 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800716 VlanId vlanId = null;
717 if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
718 Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
719 if (masked.getValue().equals(OFVlanVidMatch.PRESENT)
720 && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
721 vlanId = VlanId.ANY;
722 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700723 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800724 if (!match.get(MatchField.VLAN_VID).isPresentBitSet()) {
725 vlanId = VlanId.NONE;
726 } else {
727 vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
728 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700729 }
Charles Chan14967c22015-12-07 11:11:50 -0800730 if (vlanId != null) {
731 builder.matchVlanId(vlanId);
732 }
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800733 }
alshabib6b5cfec2014-09-18 17:42:18 -0700734 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800735 case VLAN_PCP:
736 byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
737 builder.matchVlanPcp(vlanPcp);
738 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800739 case IP_DSCP:
740 byte ipDscp = match.get(MatchField.IP_DSCP).getDscpValue();
741 builder.matchIPDscp(ipDscp);
742 break;
743 case IP_ECN:
744 byte ipEcn = match.get(MatchField.IP_ECN).getEcnValue();
745 builder.matchIPEcn(ipEcn);
746 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800747 case IP_PROTO:
748 short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
749 builder.matchIPProtocol((byte) proto);
750 break;
751 case IPV4_SRC:
752 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
753 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800754 ip4Prefix = Ip4Prefix.valueOf(
755 maskedIp.getValue().getInt(),
756 maskedIp.getMask().asCidrMaskLength());
757 } else {
758 ip4Prefix = Ip4Prefix.valueOf(
759 match.get(MatchField.IPV4_SRC).getInt(),
760 Ip4Prefix.MAX_MASK_LENGTH);
761 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800762 builder.matchIPSrc(ip4Prefix);
763 break;
764 case IPV4_DST:
765 if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
766 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800767 ip4Prefix = Ip4Prefix.valueOf(
768 maskedIp.getValue().getInt(),
769 maskedIp.getMask().asCidrMaskLength());
770 } else {
771 ip4Prefix = Ip4Prefix.valueOf(
772 match.get(MatchField.IPV4_DST).getInt(),
773 Ip4Prefix.MAX_MASK_LENGTH);
774 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800775 builder.matchIPDst(ip4Prefix);
Jonathan Hart34bc6142014-10-17 11:00:43 -0700776 break;
777 case TCP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700778 builder.matchTcpSrc(TpPort.tpPort(match.get(MatchField.TCP_SRC).getPort()));
Jonathan Hart34bc6142014-10-17 11:00:43 -0700779 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800780 case TCP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700781 builder.matchTcpDst(TpPort.tpPort(match.get(MatchField.TCP_DST).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800782 break;
783 case UDP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700784 builder.matchUdpSrc(TpPort.tpPort(match.get(MatchField.UDP_SRC).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800785 break;
786 case UDP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700787 builder.matchUdpDst(TpPort.tpPort(match.get(MatchField.UDP_DST).getPort()));
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700788 break;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100789 case MPLS_LABEL:
790 builder.matchMplsLabel(MplsLabel.mplsLabel((int) match.get(MatchField.MPLS_LABEL)
791 .getValue()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800792 break;
Saurav Dasffc5bbc2015-08-18 23:30:19 -0700793 case MPLS_BOS:
794 builder.matchMplsBos(match.get(MatchField.MPLS_BOS).getValue());
795 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800796 case SCTP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700797 builder.matchSctpSrc(TpPort.tpPort(match.get(MatchField.SCTP_SRC).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800798 break;
799 case SCTP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700800 builder.matchSctpDst(TpPort.tpPort(match.get(MatchField.SCTP_DST).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800801 break;
802 case ICMPV4_TYPE:
803 byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
804 builder.matchIcmpType(icmpType);
805 break;
806 case ICMPV4_CODE:
807 byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode();
808 builder.matchIcmpCode(icmpCode);
809 break;
810 case IPV6_SRC:
811 if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
812 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
813 ip6Prefix = Ip6Prefix.valueOf(
814 maskedIp.getValue().getBytes(),
815 maskedIp.getMask().asCidrMaskLength());
816 } else {
817 ip6Prefix = Ip6Prefix.valueOf(
818 match.get(MatchField.IPV6_SRC).getBytes(),
819 Ip6Prefix.MAX_MASK_LENGTH);
820 }
821 builder.matchIPv6Src(ip6Prefix);
822 break;
823 case IPV6_DST:
824 if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
825 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
826 ip6Prefix = Ip6Prefix.valueOf(
827 maskedIp.getValue().getBytes(),
828 maskedIp.getMask().asCidrMaskLength());
829 } else {
830 ip6Prefix = Ip6Prefix.valueOf(
831 match.get(MatchField.IPV6_DST).getBytes(),
832 Ip6Prefix.MAX_MASK_LENGTH);
833 }
834 builder.matchIPv6Dst(ip6Prefix);
835 break;
836 case IPV6_FLABEL:
837 int flowLabel =
838 match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue();
839 builder.matchIPv6FlowLabel(flowLabel);
840 break;
841 case ICMPV6_TYPE:
842 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
843 builder.matchIcmpv6Type(icmpv6type);
844 break;
845 case ICMPV6_CODE:
846 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
847 builder.matchIcmpv6Code(icmpv6code);
848 break;
849 case IPV6_ND_TARGET:
850 ip6Address =
851 Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes());
852 builder.matchIPv6NDTargetAddress(ip6Address);
853 break;
854 case IPV6_ND_SLL:
855 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong());
856 builder.matchIPv6NDSourceLinkLayerAddress(mac);
857 break;
858 case IPV6_ND_TLL:
859 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong());
860 builder.matchIPv6NDTargetLinkLayerAddress(mac);
861 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800862 case IPV6_EXTHDR:
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800863 builder.matchIPv6ExthdrFlags((short) match.get(MatchField.IPV6_EXTHDR)
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700864 .getValue());
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800865 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700866 case OCH_SIGID:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700867 CircuitSignalID sigId = match.get(MatchField.OCH_SIGID);
868 builder.add(matchLambda(Lambda.ochSignal(
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700869 lookupGridType(sigId.getGridType()), lookupChannelSpacing(sigId.getChannelSpacing()),
Marc De Leenheer0b8b2ef2015-08-03 15:39:00 -0700870 sigId.getChannelNumber(), sigId.getSpectralWidth())
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700871 ));
Marc De Leenheer49087752014-10-23 13:54:09 -0700872 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800873 case OCH_SIGTYPE:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700874 U8 sigType = match.get(MatchField.OCH_SIGTYPE);
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700875 builder.add(matchOchSignalType(lookupOchSignalType((byte) sigType.getValue())));
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800876 break;
Yafit Hadar73514612015-11-04 10:14:21 +0200877 case EXP_OCH_SIG_ID:
878 try {
879 CircuitSignalID expSigId = match.get(MatchField.EXP_OCH_SIG_ID);
880 builder.add(matchLambda(Lambda.ochSignal(
881 lookupGridType(expSigId.getGridType()), lookupChannelSpacing(expSigId.getChannelSpacing()),
882 expSigId.getChannelNumber(), expSigId.getSpectralWidth())));
883 } catch (NoMappingFoundException e) {
884 log.warn(e.getMessage());
885 break;
886 }
887 break;
888 case EXP_OCH_SIGTYPE:
889 try {
890 U8 expOchSigType = match.get(MatchField.EXP_OCH_SIGTYPE);
891 builder.add(matchOchSignalType(lookupOchSignalType((byte) expOchSigType.getValue())));
892 } catch (NoMappingFoundException e) {
893 log.warn(e.getMessage());
894 break;
895 }
896 break;
897 case EXP_ODU_SIG_ID:
898 OduSignalId oduSignalId = OduSignalId.oduSignalId(match.get(MatchField.EXP_ODU_SIG_ID).getTpn(),
899 match.get(MatchField.EXP_ODU_SIG_ID).getTslen(),
900 match.get(MatchField.EXP_ODU_SIG_ID).getTsmap());
901 builder.add(matchOduSignalId(oduSignalId));
902 break;
903 case EXP_ODU_SIGTYPE:
904 try {
905 U8 oduSigType = match.get(MatchField.EXP_ODU_SIGTYPE);
906 builder.add(matchOduSignalType(lookupOduSignalType((byte) oduSigType.getValue())));
907 } catch (NoMappingFoundException e) {
908 log.warn(e.getMessage());
909 break;
910 }
911 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700912 case TUNNEL_ID:
913 long tunnelId = match.get(MatchField.TUNNEL_ID).getValue();
914 builder.matchTunnelId(tunnelId);
915 break;
BitOhenryb40129a2015-11-30 12:41:18 +0800916 case ARP_OP:
917 int arpOp = match.get(MatchField.ARP_OP).getOpcode();
918 builder.matchArpOp(arpOp);
919 break;
BitOhenrya331b182015-11-23 08:39:37 +0800920 case ARP_SHA:
921 mac = MacAddress.valueOf(match.get(MatchField.ARP_SHA).getLong());
922 builder.matchArpSha(mac);
923 break;
BitOhenry296b4542015-11-24 08:41:58 +0800924 case ARP_SPA:
925 ip = Ip4Address.valueOf(match.get(MatchField.ARP_SPA).getInt());
926 builder.matchArpSpa(ip);
927 break;
BitOhenry76430852015-11-20 19:04:49 +0800928 case ARP_THA:
929 mac = MacAddress.valueOf(match.get(MatchField.ARP_THA).getLong());
930 builder.matchArpTha(mac);
931 break;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800932 case ARP_TPA:
933 ip = Ip4Address.valueOf(match.get(MatchField.ARP_TPA).getInt());
934 builder.matchArpTpa(ip);
935 break;
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530936 case NSP:
937 if (selectorInterpreter != null) {
938 try {
939 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.NSP);
940 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
941 } catch (UnsupportedOperationException e) {
942 log.debug(e.getMessage());
943 }
944 }
945 break;
946 case NSI:
947 if (selectorInterpreter != null) {
948 try {
949 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.NSI);
950 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
951 } catch (UnsupportedOperationException e) {
952 log.debug(e.getMessage());
953 }
954 }
955 break;
956 case ENCAP_ETH_TYPE:
957 if (selectorInterpreter != null) {
958 try {
959 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.ENCAP_ETH_TYPE);
960 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
961 } catch (UnsupportedOperationException e) {
962 log.debug(e.getMessage());
963 }
964 }
965 break;
Pier Ventre6f630052016-10-18 09:58:41 -0700966 case OFDPA_OVID:
967 if (selectorInterpreter != null &&
968 selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_OVID.type())) {
969 if (match.getVersion().equals(OFVersion.OF_13)) {
970 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.OFDPA_OVID);
971 builder.extension(selectorInterpreter.mapOxm(oxm),
972 deviceId);
973 } else {
974 break;
975 }
976 }
977 break;
Pier Ventre9cf536b2016-10-21 13:30:18 -0700978 case OFDPA_MPLS_L2_PORT:
979 if (selectorInterpreter != null &&
980 selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_MPLS_L2_PORT.type())) {
981 if (match.getVersion().equals(OFVersion.OF_13)) {
982 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.OFDPA_MPLS_L2_PORT);
983 builder.extension(selectorInterpreter.mapOxm(oxm),
984 deviceId);
985 } else {
986 break;
987 }
988 }
989 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700990 case MPLS_TC:
alshabib6b5cfec2014-09-18 17:42:18 -0700991 default:
992 log.warn("Match type {} not yet implemented.", field.id);
alshabib6b5cfec2014-09-18 17:42:18 -0700993 }
994 }
995 return builder.build();
996 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700997
Jian Liffef5002016-04-04 23:27:37 -0700998 private DriverHandler getDriver(DeviceId devId) {
999 Driver driver = driverService.getDriver(devId);
1000 DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, devId));
Jonathan Hart3c259162015-10-21 21:31:19 -07001001 return handler;
1002 }
alshabib6b5cfec2014-09-18 17:42:18 -07001003}