blob: 7a2edc2d4cf41e5907fc0bf4b993a0653ced5289 [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;
alshabib6b5cfec2014-09-18 17:42:18 -070063import org.projectfloodlight.openflow.protocol.action.OFActionSetDlDst;
64import org.projectfloodlight.openflow.protocol.action.OFActionSetDlSrc;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080065import org.projectfloodlight.openflow.protocol.action.OFActionSetField;
alshabib6b5cfec2014-09-18 17:42:18 -070066import org.projectfloodlight.openflow.protocol.action.OFActionSetNwDst;
67import org.projectfloodlight.openflow.protocol.action.OFActionSetNwSrc;
Jonathan Hart8cf212a2015-10-29 17:42:03 -070068import org.projectfloodlight.openflow.protocol.action.OFActionSetQueue;
alshabib6b5cfec2014-09-18 17:42:18 -070069import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanPcp;
70import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanVid;
alshabib19fdc122014-10-03 11:38:19 -070071import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
Jonathan Hartcf783202014-11-24 18:55:42 -080072import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions;
alshabibbdcbb102015-04-22 14:16:38 -070073import org.projectfloodlight.openflow.protocol.instruction.OFInstructionGotoTable;
alshabib346b5b32015-03-06 00:42:16 -080074import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteActions;
Saurav Das86af8f12015-05-25 23:55:33 -070075import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteMetadata;
alshabib6b5cfec2014-09-18 17:42:18 -070076import org.projectfloodlight.openflow.protocol.match.Match;
77import org.projectfloodlight.openflow.protocol.match.MatchField;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080078import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
Yafit Hadar4cc65f72016-02-10 11:23:06 +020079import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigid;
alshabib346b5b32015-03-06 00:42:16 -080080import org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070081import org.projectfloodlight.openflow.types.CircuitSignalID;
alshabib6b5cfec2014-09-18 17:42:18 -070082import org.projectfloodlight.openflow.types.IPv4Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080083import org.projectfloodlight.openflow.types.IPv6Address;
Jonathan Hart0e12fad2014-10-17 14:54:58 -070084import org.projectfloodlight.openflow.types.Masked;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080085import org.projectfloodlight.openflow.types.OFVlanVidMatch;
Jonathan Harte4e74f02016-03-03 12:57:40 -080086import org.projectfloodlight.openflow.types.OduSignalID;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -070087import org.projectfloodlight.openflow.types.TransportPort;
sangho3f97a17d2015-01-29 22:56:29 -080088import org.projectfloodlight.openflow.types.U32;
Hyunsun Moona08c5d02015-07-14 17:53:00 -070089import org.projectfloodlight.openflow.types.U64;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070090import org.projectfloodlight.openflow.types.U8;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080091import org.projectfloodlight.openflow.types.VlanPcp;
alshabib6b5cfec2014-09-18 17:42:18 -070092import org.slf4j.Logger;
Jian Lia0d9a172016-04-01 16:58:06 -070093import org.slf4j.LoggerFactory;
alshabib6b5cfec2014-09-18 17:42:18 -070094
Jonathan Hart8cf212a2015-10-29 17:42:03 -070095import java.util.List;
96
Thiago Santos877914d2016-07-20 18:29:29 -030097import static java.util.concurrent.TimeUnit.NANOSECONDS;
98import static java.util.concurrent.TimeUnit.SECONDS;
alshabib44852fb2016-04-15 15:56:51 -070099import static org.onosproject.net.flow.criteria.Criteria.*;
Yafit Hadar73514612015-11-04 10:14:21 +0200100import static org.onosproject.net.flow.instructions.Instructions.modL0Lambda;
101import static org.onosproject.net.flow.instructions.Instructions.modL1OduSignalId;
alshabib44852fb2016-04-15 15:56:51 -0700102import static org.onosproject.provider.of.flow.util.OpenFlowValueMapper.*;
alshabib19fdc122014-10-03 11:38:19 -0700103
alshabib1c319ff2014-10-04 20:29:09 -0700104public class FlowEntryBuilder {
Jian Lia0d9a172016-04-01 16:58:06 -0700105 private static final Logger log = LoggerFactory.getLogger(FlowEntryBuilder.class);
alshabib6b5cfec2014-09-18 17:42:18 -0700106
107 private final OFFlowStatsEntry stat;
108 private final OFFlowRemoved removed;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800109 private final OFFlowMod flowMod;
alshabib6b5cfec2014-09-18 17:42:18 -0700110
111 private final Match match;
alshabib346b5b32015-03-06 00:42:16 -0800112
Jonathan Hart67fc0972015-03-19 15:21:20 -0700113 // All actions are contained in an OFInstruction. For OF1.0
114 // the instruction type is apply instruction (immediate set in ONOS speak)
alshabib346b5b32015-03-06 00:42:16 -0800115 private final List<OFInstruction> instructions;
alshabib6b5cfec2014-09-18 17:42:18 -0700116
Jonathan Harte4e74f02016-03-03 12:57:40 -0800117 private final DeviceId deviceId;
alshabib6b5cfec2014-09-18 17:42:18 -0700118
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800119 public enum FlowType { STAT, REMOVED, MOD }
120
121 private final FlowType type;
alshabib6b5cfec2014-09-18 17:42:18 -0700122
Jonathan Hart3c259162015-10-21 21:31:19 -0700123 private final DriverService driverService;
124
Jonathan Harte4e74f02016-03-03 12:57:40 -0800125 public FlowEntryBuilder(DeviceId deviceId, OFFlowStatsEntry entry, DriverService driverService) {
Saurav Dasfa2fa932015-03-03 11:29:48 -0800126 this.stat = entry;
127 this.match = entry.getMatch();
alshabib346b5b32015-03-06 00:42:16 -0800128 this.instructions = getInstructions(entry);
Jonathan Harte4e74f02016-03-03 12:57:40 -0800129 this.deviceId = deviceId;
Saurav Dasfa2fa932015-03-03 11:29:48 -0800130 this.removed = null;
131 this.flowMod = null;
132 this.type = FlowType.STAT;
Jonathan Hart3c259162015-10-21 21:31:19 -0700133 this.driverService = driverService;
Saurav Dasfa2fa932015-03-03 11:29:48 -0800134 }
135
Jonathan Harte4e74f02016-03-03 12:57:40 -0800136 public FlowEntryBuilder(DeviceId deviceId, OFFlowRemoved removed, DriverService driverService) {
alshabib6b5cfec2014-09-18 17:42:18 -0700137 this.match = removed.getMatch();
138 this.removed = removed;
Jonathan Harte4e74f02016-03-03 12:57:40 -0800139 this.deviceId = deviceId;
alshabib346b5b32015-03-06 00:42:16 -0800140 this.instructions = null;
alshabib6b5cfec2014-09-18 17:42:18 -0700141 this.stat = null;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800142 this.flowMod = null;
143 this.type = FlowType.REMOVED;
Jonathan Hart3c259162015-10-21 21:31:19 -0700144 this.driverService = driverService;
alshabib6b5cfec2014-09-18 17:42:18 -0700145 }
146
Jonathan Harte4e74f02016-03-03 12:57:40 -0800147 public FlowEntryBuilder(DeviceId deviceId, OFFlowMod fm, DriverService driverService) {
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800148 this.match = fm.getMatch();
Jonathan Harte4e74f02016-03-03 12:57:40 -0800149 this.deviceId = deviceId;
alshabib346b5b32015-03-06 00:42:16 -0800150 this.instructions = getInstructions(fm);
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800151 this.type = FlowType.MOD;
152 this.flowMod = fm;
153 this.stat = null;
154 this.removed = null;
Jonathan Hart3c259162015-10-21 21:31:19 -0700155 this.driverService = driverService;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800156 }
alshabib1c319ff2014-10-04 20:29:09 -0700157
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800158 public FlowEntry build(FlowEntryState... state) {
Brian O'Connor21564612015-12-05 19:24:59 -0800159 FlowRule.Builder builder;
160 try {
161 switch (this.type) {
162 case STAT:
163 builder = DefaultFlowRule.builder()
Jonathan Harte4e74f02016-03-03 12:57:40 -0800164 .forDevice(deviceId)
Brian O'Connor21564612015-12-05 19:24:59 -0800165 .withSelector(buildSelector())
166 .withTreatment(buildTreatment())
167 .withPriority(stat.getPriority())
168 .makeTemporary(stat.getIdleTimeout())
Jonathan Hartd1ce4b02016-01-11 13:28:36 -0800169 .withCookie(stat.getCookie().getValue());
170 if (stat.getVersion() != OFVersion.OF_10) {
171 builder.forTable(stat.getTableId().getValue());
172 }
alshabibbdcbb102015-04-22 14:16:38 -0700173
Brian O'Connor21564612015-12-05 19:24:59 -0800174 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
Thiago Santos877914d2016-07-20 18:29:29 -0300175 SECONDS.toNanos(stat.getDurationSec())
176 + stat.getDurationNsec(), NANOSECONDS,
Brian O'Connor21564612015-12-05 19:24:59 -0800177 stat.getPacketCount().getValue(),
178 stat.getByteCount().getValue());
179 case REMOVED:
180 builder = DefaultFlowRule.builder()
Jonathan Harte4e74f02016-03-03 12:57:40 -0800181 .forDevice(deviceId)
Brian O'Connor21564612015-12-05 19:24:59 -0800182 .withSelector(buildSelector())
183 .withPriority(removed.getPriority())
184 .makeTemporary(removed.getIdleTimeout())
185 .withCookie(removed.getCookie().getValue());
186 if (removed.getVersion() != OFVersion.OF_10) {
187 builder.forTable(removed.getTableId().getValue());
188 }
alshabibbdcbb102015-04-22 14:16:38 -0700189
Brian O'Connor21564612015-12-05 19:24:59 -0800190 return new DefaultFlowEntry(builder.build(), FlowEntryState.REMOVED,
Thiago Santos877914d2016-07-20 18:29:29 -0300191 SECONDS.toNanos(removed.getDurationSec())
192 + removed.getDurationNsec(), NANOSECONDS,
Brian O'Connor21564612015-12-05 19:24:59 -0800193 removed.getPacketCount().getValue(),
194 removed.getByteCount().getValue());
195 case MOD:
196 FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED;
197 builder = DefaultFlowRule.builder()
Jonathan Harte4e74f02016-03-03 12:57:40 -0800198 .forDevice(deviceId)
Brian O'Connor21564612015-12-05 19:24:59 -0800199 .withSelector(buildSelector())
200 .withTreatment(buildTreatment())
201 .withPriority(flowMod.getPriority())
202 .makeTemporary(flowMod.getIdleTimeout())
203 .withCookie(flowMod.getCookie().getValue());
204 if (flowMod.getVersion() != OFVersion.OF_10) {
205 builder.forTable(flowMod.getTableId().getValue());
206 }
alshabibbdcbb102015-04-22 14:16:38 -0700207
Brian O'Connor21564612015-12-05 19:24:59 -0800208 return new DefaultFlowEntry(builder.build(), flowState, 0, 0, 0);
209 default:
210 log.error("Unknown flow type : {}", this.type);
211 return null;
212 }
213 } catch (UnsupportedOperationException e) {
214 log.warn("Error building flow entry", e);
215 return null;
alshabib6b5cfec2014-09-18 17:42:18 -0700216 }
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800217
alshabib6b5cfec2014-09-18 17:42:18 -0700218 }
219
alshabib346b5b32015-03-06 00:42:16 -0800220 private List<OFInstruction> getInstructions(OFFlowMod entry) {
alshabib19fdc122014-10-03 11:38:19 -0700221 switch (entry.getVersion()) {
222 case OF_10:
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700223 return Lists.newArrayList(OFFactoryVer13.INSTANCE.instructions()
224 .applyActions(
225 entry.getActions()));
alshabib19fdc122014-10-03 11:38:19 -0700226 case OF_11:
227 case OF_12:
228 case OF_13:
alshabib346b5b32015-03-06 00:42:16 -0800229 return entry.getInstructions();
230 default:
231 log.warn("Unknown OF version {}", entry.getVersion());
232 }
233 return Lists.newLinkedList();
234 }
235
236 private List<OFInstruction> getInstructions(OFFlowStatsEntry entry) {
237 switch (entry.getVersion()) {
238 case OF_10:
239 return Lists.newArrayList(
240 OFFactoryVer13.INSTANCE.instructions().applyActions(entry.getActions()));
241 case OF_11:
242 case OF_12:
243 case OF_13:
244 return entry.getInstructions();
alshabib19fdc122014-10-03 11:38:19 -0700245 default:
246 log.warn("Unknown OF version {}", entry.getVersion());
247 }
248 return Lists.newLinkedList();
249 }
alshabib6b5cfec2014-09-18 17:42:18 -0700250
251 private TrafficTreatment buildTreatment() {
tom9a693fd2014-10-03 11:32:19 -0700252 TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
alshabib346b5b32015-03-06 00:42:16 -0800253 for (OFInstruction in : instructions) {
254 switch (in.getType()) {
255 case GOTO_TABLE:
alshabibbdcbb102015-04-22 14:16:38 -0700256 builder.transition(((int) ((OFInstructionGotoTable) in)
257 .getTableId().getValue()));
alshabib346b5b32015-03-06 00:42:16 -0800258 break;
259 case WRITE_METADATA:
Saurav Das86af8f12015-05-25 23:55:33 -0700260 OFInstructionWriteMetadata m = (OFInstructionWriteMetadata) in;
261 builder.writeMetadata(m.getMetadata().getValue(),
262 m.getMetadataMask().getValue());
alshabib346b5b32015-03-06 00:42:16 -0800263 break;
264 case WRITE_ACTIONS:
265 builder.deferred();
266 buildActions(((OFInstructionWriteActions) in).getActions(),
267 builder);
268 break;
269 case APPLY_ACTIONS:
270 builder.immediate();
271 buildActions(((OFInstructionApplyActions) in).getActions(),
272 builder);
273 break;
274 case CLEAR_ACTIONS:
275 builder.wipeDeferred();
276 break;
277 case EXPERIMENTER:
278 break;
279 case METER:
280 break;
281 default:
282 log.warn("Unknown instructions type {}", in.getType());
alshabib6b5cfec2014-09-18 17:42:18 -0700283 }
284 }
285
286 return builder.build();
287 }
288
Jian Lia0d9a172016-04-01 16:58:06 -0700289 /**
290 * Configures traffic treatment builder with a given collection of actions.
291 *
292 * @param actions a set of OpenFlow actions
293 * @param builder traffic treatment builder
294 * @param driverHandler driver handler
295 * @param deviceId device identifier
296 * @return configured traffic treatment builder
297 */
298 public static TrafficTreatment.Builder configureTreatmentBuilder(List<OFAction> actions,
299 TrafficTreatment.Builder builder,
300 DriverHandler driverHandler,
301 DeviceId deviceId) {
302 ExtensionTreatmentInterpreter interpreter;
Charles Chan14967c22015-12-07 11:11:50 -0800303 if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
Jian Lia0d9a172016-04-01 16:58:06 -0700304 interpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class);
Charles Chan14967c22015-12-07 11:11:50 -0800305 } else {
Jian Lia0d9a172016-04-01 16:58:06 -0700306 interpreter = null;
Charles Chan14967c22015-12-07 11:11:50 -0800307 }
308
alshabib346b5b32015-03-06 00:42:16 -0800309 for (OFAction act : actions) {
310 switch (act.getType()) {
311 case OUTPUT:
312 OFActionOutput out = (OFActionOutput) act;
313 builder.setOutput(
314 PortNumber.portNumber(out.getPort().getPortNumber()));
315 break;
316 case SET_VLAN_VID:
317 OFActionSetVlanVid vlan = (OFActionSetVlanVid) act;
318 builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan()));
319 break;
320 case SET_VLAN_PCP:
321 OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act;
322 builder.setVlanPcp(pcp.getVlanPcp().getValue());
323 break;
324 case SET_DL_DST:
325 OFActionSetDlDst dldst = (OFActionSetDlDst) act;
326 builder.setEthDst(
327 MacAddress.valueOf(dldst.getDlAddr().getLong()));
328 break;
329 case SET_DL_SRC:
330 OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act;
331 builder.setEthSrc(
332 MacAddress.valueOf(dlsrc.getDlAddr().getLong()));
alshabib346b5b32015-03-06 00:42:16 -0800333 break;
334 case SET_NW_DST:
335 OFActionSetNwDst nwdst = (OFActionSetNwDst) act;
336 IPv4Address di = nwdst.getNwAddr();
337 builder.setIpDst(Ip4Address.valueOf(di.getInt()));
338 break;
339 case SET_NW_SRC:
340 OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act;
341 IPv4Address si = nwsrc.getNwAddr();
342 builder.setIpSrc(Ip4Address.valueOf(si.getInt()));
343 break;
344 case EXPERIMENTER:
345 OFActionExperimenter exp = (OFActionExperimenter) act;
346 if (exp.getExperimenter() == 0x80005A06 ||
347 exp.getExperimenter() == 0x748771) {
348 OFActionCircuit ct = (OFActionCircuit) exp;
Yafit Hadar4cc65f72016-02-10 11:23:06 +0200349 CircuitSignalID circuitSignalID = ((OFOxmOchSigid) ct.getField()).getValue();
350 builder.add(Instructions.modL0Lambda(Lambda.ochSignal(
351 lookupGridType(circuitSignalID.getGridType()),
352 lookupChannelSpacing(circuitSignalID.getChannelSpacing()),
353 circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth())));
Jian Lia0d9a172016-04-01 16:58:06 -0700354 } else if (interpreter != null) {
355 builder.extension(interpreter.mapAction(exp), deviceId);
alshabib346b5b32015-03-06 00:42:16 -0800356 } else {
357 log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter());
358 }
359 break;
360 case SET_FIELD:
361 OFActionSetField setField = (OFActionSetField) act;
Jian Lia0d9a172016-04-01 16:58:06 -0700362 handleSetField(builder, setField, driverHandler, deviceId);
alshabib346b5b32015-03-06 00:42:16 -0800363 break;
364 case POP_MPLS:
365 OFActionPopMpls popMpls = (OFActionPopMpls) act;
Ray Milkey84d5a292016-02-22 14:04:01 -0800366 builder.popMpls(new EthType(popMpls.getEthertype().getValue()));
alshabib346b5b32015-03-06 00:42:16 -0800367 break;
368 case PUSH_MPLS:
369 builder.pushMpls();
370 break;
371 case COPY_TTL_IN:
372 builder.copyTtlIn();
373 break;
374 case COPY_TTL_OUT:
375 builder.copyTtlOut();
376 break;
377 case DEC_MPLS_TTL:
378 builder.decMplsTtl();
379 break;
380 case DEC_NW_TTL:
381 builder.decNwTtl();
382 break;
383 case GROUP:
384 OFActionGroup group = (OFActionGroup) act;
385 builder.group(new DefaultGroupId(group.getGroup().getGroupNumber()));
386 break;
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200387 case SET_QUEUE:
388 OFActionSetQueue setQueue = (OFActionSetQueue) act;
389 builder.setQueue(setQueue.getQueueId());
390 break;
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200391 case ENQUEUE:
392 OFActionEnqueue enqueue = (OFActionEnqueue) act;
Jian Liffef5002016-04-04 23:27:37 -0700393 builder.setQueue(enqueue.getQueueId(),
394 PortNumber.portNumber(enqueue.getPort().getPortNumber()));
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200395 break;
Jonathan Hart67fc0972015-03-19 15:21:20 -0700396 case STRIP_VLAN:
alshabib346b5b32015-03-06 00:42:16 -0800397 case POP_VLAN:
398 builder.popVlan();
399 break;
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700400 case PUSH_VLAN:
401 builder.pushVlan();
402 break;
alshabib346b5b32015-03-06 00:42:16 -0800403 case SET_TP_DST:
404 case SET_TP_SRC:
405 case POP_PBB:
406 case PUSH_PBB:
alshabib346b5b32015-03-06 00:42:16 -0800407 case SET_MPLS_LABEL:
408 case SET_MPLS_TC:
409 case SET_MPLS_TTL:
410 case SET_NW_ECN:
411 case SET_NW_TOS:
412 case SET_NW_TTL:
alshabib346b5b32015-03-06 00:42:16 -0800413
alshabib346b5b32015-03-06 00:42:16 -0800414 default:
415 log.warn("Action type {} not yet implemented.", act.getType());
416 }
417 }
418 return builder;
419 }
420
Jian Lia0d9a172016-04-01 16:58:06 -0700421 private TrafficTreatment.Builder buildActions(List<OFAction> actions,
422 TrafficTreatment.Builder builder) {
Jonathan Harte4e74f02016-03-03 12:57:40 -0800423 DriverHandler driverHandler = getDriver(deviceId);
Jian Lia0d9a172016-04-01 16:58:06 -0700424
425 return configureTreatmentBuilder(actions, builder, driverHandler, deviceId);
426 }
427
428
429 private static void handleSetField(TrafficTreatment.Builder builder,
430 OFActionSetField action,
431 DriverHandler driverHandler,
432 DeviceId deviceId) {
Charles Chan14967c22015-12-07 11:11:50 -0800433 ExtensionTreatmentInterpreter treatmentInterpreter;
434 if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
435 treatmentInterpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class);
436 } else {
437 treatmentInterpreter = null;
438 }
439
Jonathan Hart3c259162015-10-21 21:31:19 -0700440 OFOxm<?> oxm = action.getField();
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800441 switch (oxm.getMatchField().id) {
442 case VLAN_PCP:
443 @SuppressWarnings("unchecked")
444 OFOxm<VlanPcp> vlanpcp = (OFOxm<VlanPcp>) oxm;
445 builder.setVlanPcp(vlanpcp.getValue().getValue());
446 break;
447 case VLAN_VID:
Charles Chan4211baa2016-04-20 17:10:40 -0700448 if (treatmentInterpreter != null) {
449 try {
450 builder.extension(treatmentInterpreter.mapAction(action), deviceId);
451 break;
452 } catch (UnsupportedOperationException e) {
453 log.debug("Unsupported action extension; defaulting to native OF");
454 }
Charles Chan14967c22015-12-07 11:11:50 -0800455 }
alshabib44852fb2016-04-15 15:56:51 -0700456 @SuppressWarnings("unchecked")
457 OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm;
458 builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan()));
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800459 break;
460 case ETH_DST:
461 @SuppressWarnings("unchecked")
462 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethdst =
463 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
464 builder.setEthDst(MacAddress.valueOf(ethdst.getValue().getLong()));
465 break;
466 case ETH_SRC:
467 @SuppressWarnings("unchecked")
468 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethsrc =
469 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
470 builder.setEthSrc(MacAddress.valueOf(ethsrc.getValue().getLong()));
471 break;
472 case IPV4_DST:
473 @SuppressWarnings("unchecked")
474 OFOxm<IPv4Address> ip4dst = (OFOxm<IPv4Address>) oxm;
475 builder.setIpDst(Ip4Address.valueOf(ip4dst.getValue().getInt()));
476 break;
477 case IPV4_SRC:
478 @SuppressWarnings("unchecked")
479 OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm;
480 builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt()));
481 break;
sangho3f97a17d2015-01-29 22:56:29 -0800482 case MPLS_LABEL:
483 @SuppressWarnings("unchecked")
484 OFOxm<U32> labelId = (OFOxm<U32>) oxm;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100485 builder.setMpls(MplsLabel.mplsLabel((int) labelId.getValue().getValue()));
sangho3f97a17d2015-01-29 22:56:29 -0800486 break;
Saurav Das73a7dd42015-08-19 22:20:31 -0700487 case MPLS_BOS:
488 @SuppressWarnings("unchecked")
489 OFOxm<U8> mplsBos = (OFOxm<U8>) oxm;
490 builder.setMplsBos(mplsBos.getValue() == U8.ZERO ? false : true);
491 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700492 case TUNNEL_ID:
493 @SuppressWarnings("unchecked")
494 OFOxm<U64> tunnelId = (OFOxm<U64>) oxm;
495 builder.setTunnelId(tunnelId.getValue().getValue());
496 break;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700497 case TCP_DST:
498 @SuppressWarnings("unchecked")
499 OFOxm<TransportPort> tcpdst = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700500 builder.setTcpDst(TpPort.tpPort(tcpdst.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700501 break;
502 case TCP_SRC:
503 @SuppressWarnings("unchecked")
504 OFOxm<TransportPort> tcpsrc = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700505 builder.setTcpSrc(TpPort.tpPort(tcpsrc.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700506 break;
507 case UDP_DST:
508 @SuppressWarnings("unchecked")
509 OFOxm<TransportPort> udpdst = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700510 builder.setUdpDst(TpPort.tpPort(udpdst.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700511 break;
512 case UDP_SRC:
513 @SuppressWarnings("unchecked")
514 OFOxm<TransportPort> udpsrc = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700515 builder.setUdpSrc(TpPort.tpPort(udpsrc.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700516 break;
Jonathan Hart3c259162015-10-21 21:31:19 -0700517 case TUNNEL_IPV4_DST:
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530518 case NSP:
519 case NSI:
520 case NSH_C1:
521 case NSH_C2:
522 case NSH_C3:
523 case NSH_C4:
524 case NSH_MDTYPE:
525 case NSH_NP:
526 case ENCAP_ETH_SRC:
527 case ENCAP_ETH_DST:
528 case ENCAP_ETH_TYPE:
529 case TUN_GPE_NP:
Jian Liffef5002016-04-04 23:27:37 -0700530 if (treatmentInterpreter != null) {
531 try {
532 builder.extension(treatmentInterpreter.mapAction(action), deviceId);
533 } catch (UnsupportedOperationException e) {
alshabib44852fb2016-04-15 15:56:51 -0700534 log.debug(e.getMessage());
Jian Liffef5002016-04-04 23:27:37 -0700535 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700536 }
537 break;
Yafit Hadar73514612015-11-04 10:14:21 +0200538 case EXP_ODU_SIG_ID:
539 @SuppressWarnings("unchecked")
540 OFOxm<OduSignalID> oduID = (OFOxm<OduSignalID>) oxm;
541 OduSignalID oduSignalID = oduID.getValue();
542 OduSignalId oduSignalId = OduSignalId.oduSignalId(oduSignalID.getTpn(),
543 oduSignalID.getTslen(),
544 oduSignalID.getTsmap());
545 builder.add(modL1OduSignalId(oduSignalId));
546 break;
547 case EXP_OCH_SIG_ID:
548 try {
549 @SuppressWarnings("unchecked")
550 OFOxm<CircuitSignalID> ochId = (OFOxm<CircuitSignalID>) oxm;
551 CircuitSignalID circuitSignalID = ochId.getValue();
552 builder.add(modL0Lambda(Lambda.ochSignal(
553 lookupGridType(circuitSignalID.getGridType()),
554 lookupChannelSpacing(circuitSignalID.getChannelSpacing()),
555 circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth())));
556 } catch (NoMappingFoundException e) {
557 log.warn(e.getMessage());
558 break;
559 }
560 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800561 case ARP_OP:
lishuai67574ce2016-05-12 16:39:59 +0800562 @SuppressWarnings("unchecked")
563 OFOxm<org.projectfloodlight.openflow.types.ArpOpcode> arpop =
564 (OFOxm<org.projectfloodlight.openflow.types.ArpOpcode>) oxm;
565 builder.setArpOp((short) arpop.getValue().getOpcode());
566 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800567 case ARP_SHA:
lishuai67574ce2016-05-12 16:39:59 +0800568 @SuppressWarnings("unchecked")
569 OFOxm<org.projectfloodlight.openflow.types.MacAddress> arpsha =
570 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
571 builder.setArpSha(MacAddress.valueOf(arpsha.getValue().getLong()));
572 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800573 case ARP_SPA:
lishuai67574ce2016-05-12 16:39:59 +0800574 @SuppressWarnings("unchecked")
575 OFOxm<IPv4Address> arpspa = (OFOxm<IPv4Address>) oxm;
576 builder.setArpSpa(Ip4Address.valueOf(arpspa.getValue().getInt()));
577 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800578 case ARP_THA:
579 case ARP_TPA:
580 case BSN_EGR_PORT_GROUP_ID:
581 case BSN_GLOBAL_VRF_ALLOWED:
582 case BSN_IN_PORTS_128:
583 case BSN_L3_DST_CLASS_ID:
584 case BSN_L3_INTERFACE_CLASS_ID:
585 case BSN_L3_SRC_CLASS_ID:
586 case BSN_LAG_ID:
587 case BSN_TCP_FLAGS:
588 case BSN_UDF0:
589 case BSN_UDF1:
590 case BSN_UDF2:
591 case BSN_UDF3:
592 case BSN_UDF4:
593 case BSN_UDF5:
594 case BSN_UDF6:
595 case BSN_UDF7:
596 case BSN_VLAN_XLATE_PORT_GROUP_ID:
597 case BSN_VRF:
598 case ETH_TYPE:
599 case ICMPV4_CODE:
600 case ICMPV4_TYPE:
601 case ICMPV6_CODE:
602 case ICMPV6_TYPE:
603 case IN_PHY_PORT:
604 case IN_PORT:
605 case IPV6_DST:
606 case IPV6_FLABEL:
607 case IPV6_ND_SLL:
608 case IPV6_ND_TARGET:
609 case IPV6_ND_TLL:
610 case IPV6_SRC:
611 case IP_DSCP:
612 case IP_ECN:
613 case IP_PROTO:
614 case METADATA:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800615 case MPLS_TC:
616 case OCH_SIGID:
617 case OCH_SIGID_BASIC:
618 case OCH_SIGTYPE:
619 case OCH_SIGTYPE_BASIC:
620 case SCTP_DST:
621 case SCTP_SRC:
Yafit Hadar73514612015-11-04 10:14:21 +0200622 case EXP_ODU_SIGTYPE:
623 case EXP_OCH_SIGTYPE:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800624 default:
625 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
626 break;
627 }
628 }
629
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700630 // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES
alshabib6b5cfec2014-09-18 17:42:18 -0700631 private TrafficSelector buildSelector() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800632 MacAddress mac;
633 Ip4Prefix ip4Prefix;
634 Ip6Address ip6Address;
635 Ip6Prefix ip6Prefix;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800636 Ip4Address ip;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800637
Jonathan Harte4e74f02016-03-03 12:57:40 -0800638 DriverHandler driverHandler = getDriver(deviceId);
Charles Chan14967c22015-12-07 11:11:50 -0800639 ExtensionSelectorInterpreter selectorInterpreter;
640 if (driverHandler.hasBehaviour(ExtensionSelectorInterpreter.class)) {
641 selectorInterpreter = driverHandler.behaviour(ExtensionSelectorInterpreter.class);
642 } else {
643 selectorInterpreter = null;
644 }
645
tom9a693fd2014-10-03 11:32:19 -0700646 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700647 for (MatchField<?> field : match.getMatchFields()) {
648 switch (field.id) {
649 case IN_PORT:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800650 builder.matchInPort(PortNumber
alshabib010c31d2014-09-26 10:01:12 -0700651 .portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700652 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800653 case IN_PHY_PORT:
654 builder.matchInPhyPort(PortNumber
655 .portNumber(match.get(MatchField.IN_PHY_PORT).getPortNumber()));
656 break;
657 case METADATA:
658 long metadata =
659 match.get(MatchField.METADATA).getValue().getValue();
660 builder.matchMetadata(metadata);
661 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700662 case ETH_DST:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800663 if (match.isPartiallyMasked(MatchField.ETH_DST)) {
664 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
665 match.getMasked(MatchField.ETH_DST);
666 builder.matchEthDstMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
667 MacAddress.valueOf(maskedMac.getMask().getLong()));
668 } else {
669 mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
670 builder.matchEthDst(mac);
671 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800672 break;
673 case ETH_SRC:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800674 if (match.isPartiallyMasked(MatchField.ETH_SRC)) {
675 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
676 match.getMasked(MatchField.ETH_SRC);
677 builder.matchEthSrcMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
678 MacAddress.valueOf(maskedMac.getMask().getLong()));
679 } else {
680 mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
681 builder.matchEthSrc(mac);
682 }
alshabib6b5cfec2014-09-18 17:42:18 -0700683 break;
684 case ETH_TYPE:
685 int ethType = match.get(MatchField.ETH_TYPE).getValue();
Jonathan Hart8cf212a2015-10-29 17:42:03 -0700686 builder.matchEthType((short) ethType);
alshabib6b5cfec2014-09-18 17:42:18 -0700687 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700688 case VLAN_VID:
Charles Chan14967c22015-12-07 11:11:50 -0800689 if (selectorInterpreter != null &&
690 selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
691 if (match.getVersion().equals(OFVersion.OF_13)) {
692 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.VLAN_VID);
693 builder.extension(selectorInterpreter.mapOxm(oxm),
Jonathan Harte4e74f02016-03-03 12:57:40 -0800694 deviceId);
Charles Chan14967c22015-12-07 11:11:50 -0800695 } else {
696 break;
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800697 }
698 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800699 VlanId vlanId = null;
700 if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
701 Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
702 if (masked.getValue().equals(OFVlanVidMatch.PRESENT)
703 && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
704 vlanId = VlanId.ANY;
705 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700706 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800707 if (!match.get(MatchField.VLAN_VID).isPresentBitSet()) {
708 vlanId = VlanId.NONE;
709 } else {
710 vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
711 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700712 }
Charles Chan14967c22015-12-07 11:11:50 -0800713 if (vlanId != null) {
714 builder.matchVlanId(vlanId);
715 }
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800716 }
alshabib6b5cfec2014-09-18 17:42:18 -0700717 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800718 case VLAN_PCP:
719 byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
720 builder.matchVlanPcp(vlanPcp);
721 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800722 case IP_DSCP:
723 byte ipDscp = match.get(MatchField.IP_DSCP).getDscpValue();
724 builder.matchIPDscp(ipDscp);
725 break;
726 case IP_ECN:
727 byte ipEcn = match.get(MatchField.IP_ECN).getEcnValue();
728 builder.matchIPEcn(ipEcn);
729 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800730 case IP_PROTO:
731 short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
732 builder.matchIPProtocol((byte) proto);
733 break;
734 case IPV4_SRC:
735 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
736 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800737 ip4Prefix = Ip4Prefix.valueOf(
738 maskedIp.getValue().getInt(),
739 maskedIp.getMask().asCidrMaskLength());
740 } else {
741 ip4Prefix = Ip4Prefix.valueOf(
742 match.get(MatchField.IPV4_SRC).getInt(),
743 Ip4Prefix.MAX_MASK_LENGTH);
744 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800745 builder.matchIPSrc(ip4Prefix);
746 break;
747 case IPV4_DST:
748 if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
749 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800750 ip4Prefix = Ip4Prefix.valueOf(
751 maskedIp.getValue().getInt(),
752 maskedIp.getMask().asCidrMaskLength());
753 } else {
754 ip4Prefix = Ip4Prefix.valueOf(
755 match.get(MatchField.IPV4_DST).getInt(),
756 Ip4Prefix.MAX_MASK_LENGTH);
757 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800758 builder.matchIPDst(ip4Prefix);
Jonathan Hart34bc6142014-10-17 11:00:43 -0700759 break;
760 case TCP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700761 builder.matchTcpSrc(TpPort.tpPort(match.get(MatchField.TCP_SRC).getPort()));
Jonathan Hart34bc6142014-10-17 11:00:43 -0700762 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800763 case TCP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700764 builder.matchTcpDst(TpPort.tpPort(match.get(MatchField.TCP_DST).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800765 break;
766 case UDP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700767 builder.matchUdpSrc(TpPort.tpPort(match.get(MatchField.UDP_SRC).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800768 break;
769 case UDP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700770 builder.matchUdpDst(TpPort.tpPort(match.get(MatchField.UDP_DST).getPort()));
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700771 break;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100772 case MPLS_LABEL:
773 builder.matchMplsLabel(MplsLabel.mplsLabel((int) match.get(MatchField.MPLS_LABEL)
774 .getValue()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800775 break;
Saurav Dasffc5bbc2015-08-18 23:30:19 -0700776 case MPLS_BOS:
777 builder.matchMplsBos(match.get(MatchField.MPLS_BOS).getValue());
778 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800779 case SCTP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700780 builder.matchSctpSrc(TpPort.tpPort(match.get(MatchField.SCTP_SRC).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800781 break;
782 case SCTP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700783 builder.matchSctpDst(TpPort.tpPort(match.get(MatchField.SCTP_DST).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800784 break;
785 case ICMPV4_TYPE:
786 byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
787 builder.matchIcmpType(icmpType);
788 break;
789 case ICMPV4_CODE:
790 byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode();
791 builder.matchIcmpCode(icmpCode);
792 break;
793 case IPV6_SRC:
794 if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
795 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
796 ip6Prefix = Ip6Prefix.valueOf(
797 maskedIp.getValue().getBytes(),
798 maskedIp.getMask().asCidrMaskLength());
799 } else {
800 ip6Prefix = Ip6Prefix.valueOf(
801 match.get(MatchField.IPV6_SRC).getBytes(),
802 Ip6Prefix.MAX_MASK_LENGTH);
803 }
804 builder.matchIPv6Src(ip6Prefix);
805 break;
806 case IPV6_DST:
807 if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
808 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
809 ip6Prefix = Ip6Prefix.valueOf(
810 maskedIp.getValue().getBytes(),
811 maskedIp.getMask().asCidrMaskLength());
812 } else {
813 ip6Prefix = Ip6Prefix.valueOf(
814 match.get(MatchField.IPV6_DST).getBytes(),
815 Ip6Prefix.MAX_MASK_LENGTH);
816 }
817 builder.matchIPv6Dst(ip6Prefix);
818 break;
819 case IPV6_FLABEL:
820 int flowLabel =
821 match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue();
822 builder.matchIPv6FlowLabel(flowLabel);
823 break;
824 case ICMPV6_TYPE:
825 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
826 builder.matchIcmpv6Type(icmpv6type);
827 break;
828 case ICMPV6_CODE:
829 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
830 builder.matchIcmpv6Code(icmpv6code);
831 break;
832 case IPV6_ND_TARGET:
833 ip6Address =
834 Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes());
835 builder.matchIPv6NDTargetAddress(ip6Address);
836 break;
837 case IPV6_ND_SLL:
838 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong());
839 builder.matchIPv6NDSourceLinkLayerAddress(mac);
840 break;
841 case IPV6_ND_TLL:
842 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong());
843 builder.matchIPv6NDTargetLinkLayerAddress(mac);
844 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800845 case IPV6_EXTHDR:
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800846 builder.matchIPv6ExthdrFlags((short) match.get(MatchField.IPV6_EXTHDR)
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700847 .getValue());
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800848 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700849 case OCH_SIGID:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700850 CircuitSignalID sigId = match.get(MatchField.OCH_SIGID);
851 builder.add(matchLambda(Lambda.ochSignal(
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700852 lookupGridType(sigId.getGridType()), lookupChannelSpacing(sigId.getChannelSpacing()),
Marc De Leenheer0b8b2ef2015-08-03 15:39:00 -0700853 sigId.getChannelNumber(), sigId.getSpectralWidth())
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700854 ));
Marc De Leenheer49087752014-10-23 13:54:09 -0700855 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800856 case OCH_SIGTYPE:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700857 U8 sigType = match.get(MatchField.OCH_SIGTYPE);
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700858 builder.add(matchOchSignalType(lookupOchSignalType((byte) sigType.getValue())));
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800859 break;
Yafit Hadar73514612015-11-04 10:14:21 +0200860 case EXP_OCH_SIG_ID:
861 try {
862 CircuitSignalID expSigId = match.get(MatchField.EXP_OCH_SIG_ID);
863 builder.add(matchLambda(Lambda.ochSignal(
864 lookupGridType(expSigId.getGridType()), lookupChannelSpacing(expSigId.getChannelSpacing()),
865 expSigId.getChannelNumber(), expSigId.getSpectralWidth())));
866 } catch (NoMappingFoundException e) {
867 log.warn(e.getMessage());
868 break;
869 }
870 break;
871 case EXP_OCH_SIGTYPE:
872 try {
873 U8 expOchSigType = match.get(MatchField.EXP_OCH_SIGTYPE);
874 builder.add(matchOchSignalType(lookupOchSignalType((byte) expOchSigType.getValue())));
875 } catch (NoMappingFoundException e) {
876 log.warn(e.getMessage());
877 break;
878 }
879 break;
880 case EXP_ODU_SIG_ID:
881 OduSignalId oduSignalId = OduSignalId.oduSignalId(match.get(MatchField.EXP_ODU_SIG_ID).getTpn(),
882 match.get(MatchField.EXP_ODU_SIG_ID).getTslen(),
883 match.get(MatchField.EXP_ODU_SIG_ID).getTsmap());
884 builder.add(matchOduSignalId(oduSignalId));
885 break;
886 case EXP_ODU_SIGTYPE:
887 try {
888 U8 oduSigType = match.get(MatchField.EXP_ODU_SIGTYPE);
889 builder.add(matchOduSignalType(lookupOduSignalType((byte) oduSigType.getValue())));
890 } catch (NoMappingFoundException e) {
891 log.warn(e.getMessage());
892 break;
893 }
894 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700895 case TUNNEL_ID:
896 long tunnelId = match.get(MatchField.TUNNEL_ID).getValue();
897 builder.matchTunnelId(tunnelId);
898 break;
BitOhenryb40129a2015-11-30 12:41:18 +0800899 case ARP_OP:
900 int arpOp = match.get(MatchField.ARP_OP).getOpcode();
901 builder.matchArpOp(arpOp);
902 break;
BitOhenrya331b182015-11-23 08:39:37 +0800903 case ARP_SHA:
904 mac = MacAddress.valueOf(match.get(MatchField.ARP_SHA).getLong());
905 builder.matchArpSha(mac);
906 break;
BitOhenry296b4542015-11-24 08:41:58 +0800907 case ARP_SPA:
908 ip = Ip4Address.valueOf(match.get(MatchField.ARP_SPA).getInt());
909 builder.matchArpSpa(ip);
910 break;
BitOhenry76430852015-11-20 19:04:49 +0800911 case ARP_THA:
912 mac = MacAddress.valueOf(match.get(MatchField.ARP_THA).getLong());
913 builder.matchArpTha(mac);
914 break;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800915 case ARP_TPA:
916 ip = Ip4Address.valueOf(match.get(MatchField.ARP_TPA).getInt());
917 builder.matchArpTpa(ip);
918 break;
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530919 case NSP:
920 if (selectorInterpreter != null) {
921 try {
922 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.NSP);
923 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
924 } catch (UnsupportedOperationException e) {
925 log.debug(e.getMessage());
926 }
927 }
928 break;
929 case NSI:
930 if (selectorInterpreter != null) {
931 try {
932 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.NSI);
933 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
934 } catch (UnsupportedOperationException e) {
935 log.debug(e.getMessage());
936 }
937 }
938 break;
939 case ENCAP_ETH_TYPE:
940 if (selectorInterpreter != null) {
941 try {
942 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.ENCAP_ETH_TYPE);
943 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
944 } catch (UnsupportedOperationException e) {
945 log.debug(e.getMessage());
946 }
947 }
948 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700949 case MPLS_TC:
alshabib6b5cfec2014-09-18 17:42:18 -0700950 default:
951 log.warn("Match type {} not yet implemented.", field.id);
alshabib6b5cfec2014-09-18 17:42:18 -0700952 }
953 }
954 return builder.build();
955 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700956
Jian Liffef5002016-04-04 23:27:37 -0700957 private DriverHandler getDriver(DeviceId devId) {
958 Driver driver = driverService.getDriver(devId);
959 DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, devId));
Jonathan Hart3c259162015-10-21 21:31:19 -0700960 return handler;
961 }
alshabib6b5cfec2014-09-18 17:42:18 -0700962}