blob: 8c3cb928f97028449b90401795d975c838b771d8 [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
alshabib44852fb2016-04-15 15:56:51 -070097import static org.onosproject.net.flow.criteria.Criteria.*;
Yafit Hadar73514612015-11-04 10:14:21 +020098import static org.onosproject.net.flow.instructions.Instructions.modL0Lambda;
99import static org.onosproject.net.flow.instructions.Instructions.modL1OduSignalId;
alshabib44852fb2016-04-15 15:56:51 -0700100import static org.onosproject.provider.of.flow.util.OpenFlowValueMapper.*;
alshabib19fdc122014-10-03 11:38:19 -0700101
alshabib1c319ff2014-10-04 20:29:09 -0700102public class FlowEntryBuilder {
Jian Lia0d9a172016-04-01 16:58:06 -0700103 private static final Logger log = LoggerFactory.getLogger(FlowEntryBuilder.class);
alshabib6b5cfec2014-09-18 17:42:18 -0700104
105 private final OFFlowStatsEntry stat;
106 private final OFFlowRemoved removed;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800107 private final OFFlowMod flowMod;
alshabib6b5cfec2014-09-18 17:42:18 -0700108
109 private final Match match;
alshabib346b5b32015-03-06 00:42:16 -0800110
Jonathan Hart67fc0972015-03-19 15:21:20 -0700111 // All actions are contained in an OFInstruction. For OF1.0
112 // the instruction type is apply instruction (immediate set in ONOS speak)
alshabib346b5b32015-03-06 00:42:16 -0800113 private final List<OFInstruction> instructions;
alshabib6b5cfec2014-09-18 17:42:18 -0700114
Jonathan Harte4e74f02016-03-03 12:57:40 -0800115 private final DeviceId deviceId;
alshabib6b5cfec2014-09-18 17:42:18 -0700116
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800117 public enum FlowType { STAT, REMOVED, MOD }
118
119 private final FlowType type;
alshabib6b5cfec2014-09-18 17:42:18 -0700120
Jonathan Hart3c259162015-10-21 21:31:19 -0700121 private final DriverService driverService;
122
Jonathan Harte4e74f02016-03-03 12:57:40 -0800123 public FlowEntryBuilder(DeviceId deviceId, OFFlowStatsEntry entry, DriverService driverService) {
Saurav Dasfa2fa932015-03-03 11:29:48 -0800124 this.stat = entry;
125 this.match = entry.getMatch();
alshabib346b5b32015-03-06 00:42:16 -0800126 this.instructions = getInstructions(entry);
Jonathan Harte4e74f02016-03-03 12:57:40 -0800127 this.deviceId = deviceId;
Saurav Dasfa2fa932015-03-03 11:29:48 -0800128 this.removed = null;
129 this.flowMod = null;
130 this.type = FlowType.STAT;
Jonathan Hart3c259162015-10-21 21:31:19 -0700131 this.driverService = driverService;
Saurav Dasfa2fa932015-03-03 11:29:48 -0800132 }
133
Jonathan Harte4e74f02016-03-03 12:57:40 -0800134 public FlowEntryBuilder(DeviceId deviceId, OFFlowRemoved removed, DriverService driverService) {
alshabib6b5cfec2014-09-18 17:42:18 -0700135 this.match = removed.getMatch();
136 this.removed = removed;
Jonathan Harte4e74f02016-03-03 12:57:40 -0800137 this.deviceId = deviceId;
alshabib346b5b32015-03-06 00:42:16 -0800138 this.instructions = null;
alshabib6b5cfec2014-09-18 17:42:18 -0700139 this.stat = null;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800140 this.flowMod = null;
141 this.type = FlowType.REMOVED;
Jonathan Hart3c259162015-10-21 21:31:19 -0700142 this.driverService = driverService;
alshabib6b5cfec2014-09-18 17:42:18 -0700143 }
144
Jonathan Harte4e74f02016-03-03 12:57:40 -0800145 public FlowEntryBuilder(DeviceId deviceId, OFFlowMod fm, DriverService driverService) {
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800146 this.match = fm.getMatch();
Jonathan Harte4e74f02016-03-03 12:57:40 -0800147 this.deviceId = deviceId;
alshabib346b5b32015-03-06 00:42:16 -0800148 this.instructions = getInstructions(fm);
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800149 this.type = FlowType.MOD;
150 this.flowMod = fm;
151 this.stat = null;
152 this.removed = null;
Jonathan Hart3c259162015-10-21 21:31:19 -0700153 this.driverService = driverService;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800154 }
alshabib1c319ff2014-10-04 20:29:09 -0700155
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800156 public FlowEntry build(FlowEntryState... state) {
Brian O'Connor21564612015-12-05 19:24:59 -0800157 FlowRule.Builder builder;
158 try {
159 switch (this.type) {
160 case STAT:
161 builder = DefaultFlowRule.builder()
Jonathan Harte4e74f02016-03-03 12:57:40 -0800162 .forDevice(deviceId)
Brian O'Connor21564612015-12-05 19:24:59 -0800163 .withSelector(buildSelector())
164 .withTreatment(buildTreatment())
165 .withPriority(stat.getPriority())
166 .makeTemporary(stat.getIdleTimeout())
Jonathan Hartd1ce4b02016-01-11 13:28:36 -0800167 .withCookie(stat.getCookie().getValue());
168 if (stat.getVersion() != OFVersion.OF_10) {
169 builder.forTable(stat.getTableId().getValue());
170 }
alshabibbdcbb102015-04-22 14:16:38 -0700171
Brian O'Connor21564612015-12-05 19:24:59 -0800172 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
173 stat.getDurationSec(),
174 stat.getPacketCount().getValue(),
175 stat.getByteCount().getValue());
176 case REMOVED:
177 builder = DefaultFlowRule.builder()
Jonathan Harte4e74f02016-03-03 12:57:40 -0800178 .forDevice(deviceId)
Brian O'Connor21564612015-12-05 19:24:59 -0800179 .withSelector(buildSelector())
180 .withPriority(removed.getPriority())
181 .makeTemporary(removed.getIdleTimeout())
182 .withCookie(removed.getCookie().getValue());
183 if (removed.getVersion() != OFVersion.OF_10) {
184 builder.forTable(removed.getTableId().getValue());
185 }
alshabibbdcbb102015-04-22 14:16:38 -0700186
Brian O'Connor21564612015-12-05 19:24:59 -0800187 return new DefaultFlowEntry(builder.build(), FlowEntryState.REMOVED,
188 removed.getDurationSec(),
189 removed.getPacketCount().getValue(),
190 removed.getByteCount().getValue());
191 case MOD:
192 FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED;
193 builder = DefaultFlowRule.builder()
Jonathan Harte4e74f02016-03-03 12:57:40 -0800194 .forDevice(deviceId)
Brian O'Connor21564612015-12-05 19:24:59 -0800195 .withSelector(buildSelector())
196 .withTreatment(buildTreatment())
197 .withPriority(flowMod.getPriority())
198 .makeTemporary(flowMod.getIdleTimeout())
199 .withCookie(flowMod.getCookie().getValue());
200 if (flowMod.getVersion() != OFVersion.OF_10) {
201 builder.forTable(flowMod.getTableId().getValue());
202 }
alshabibbdcbb102015-04-22 14:16:38 -0700203
Brian O'Connor21564612015-12-05 19:24:59 -0800204 return new DefaultFlowEntry(builder.build(), flowState, 0, 0, 0);
205 default:
206 log.error("Unknown flow type : {}", this.type);
207 return null;
208 }
209 } catch (UnsupportedOperationException e) {
210 log.warn("Error building flow entry", e);
211 return null;
alshabib6b5cfec2014-09-18 17:42:18 -0700212 }
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800213
alshabib6b5cfec2014-09-18 17:42:18 -0700214 }
215
alshabib346b5b32015-03-06 00:42:16 -0800216 private List<OFInstruction> getInstructions(OFFlowMod entry) {
alshabib19fdc122014-10-03 11:38:19 -0700217 switch (entry.getVersion()) {
218 case OF_10:
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700219 return Lists.newArrayList(OFFactoryVer13.INSTANCE.instructions()
220 .applyActions(
221 entry.getActions()));
alshabib19fdc122014-10-03 11:38:19 -0700222 case OF_11:
223 case OF_12:
224 case OF_13:
alshabib346b5b32015-03-06 00:42:16 -0800225 return entry.getInstructions();
226 default:
227 log.warn("Unknown OF version {}", entry.getVersion());
228 }
229 return Lists.newLinkedList();
230 }
231
232 private List<OFInstruction> getInstructions(OFFlowStatsEntry entry) {
233 switch (entry.getVersion()) {
234 case OF_10:
235 return Lists.newArrayList(
236 OFFactoryVer13.INSTANCE.instructions().applyActions(entry.getActions()));
237 case OF_11:
238 case OF_12:
239 case OF_13:
240 return entry.getInstructions();
alshabib19fdc122014-10-03 11:38:19 -0700241 default:
242 log.warn("Unknown OF version {}", entry.getVersion());
243 }
244 return Lists.newLinkedList();
245 }
alshabib6b5cfec2014-09-18 17:42:18 -0700246
247 private TrafficTreatment buildTreatment() {
tom9a693fd2014-10-03 11:32:19 -0700248 TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
alshabib346b5b32015-03-06 00:42:16 -0800249 for (OFInstruction in : instructions) {
250 switch (in.getType()) {
251 case GOTO_TABLE:
alshabibbdcbb102015-04-22 14:16:38 -0700252 builder.transition(((int) ((OFInstructionGotoTable) in)
253 .getTableId().getValue()));
alshabib346b5b32015-03-06 00:42:16 -0800254 break;
255 case WRITE_METADATA:
Saurav Das86af8f12015-05-25 23:55:33 -0700256 OFInstructionWriteMetadata m = (OFInstructionWriteMetadata) in;
257 builder.writeMetadata(m.getMetadata().getValue(),
258 m.getMetadataMask().getValue());
alshabib346b5b32015-03-06 00:42:16 -0800259 break;
260 case WRITE_ACTIONS:
261 builder.deferred();
262 buildActions(((OFInstructionWriteActions) in).getActions(),
263 builder);
264 break;
265 case APPLY_ACTIONS:
266 builder.immediate();
267 buildActions(((OFInstructionApplyActions) in).getActions(),
268 builder);
269 break;
270 case CLEAR_ACTIONS:
271 builder.wipeDeferred();
272 break;
273 case EXPERIMENTER:
274 break;
275 case METER:
276 break;
277 default:
278 log.warn("Unknown instructions type {}", in.getType());
alshabib6b5cfec2014-09-18 17:42:18 -0700279 }
280 }
281
282 return builder.build();
283 }
284
Jian Lia0d9a172016-04-01 16:58:06 -0700285 /**
286 * Configures traffic treatment builder with a given collection of actions.
287 *
288 * @param actions a set of OpenFlow actions
289 * @param builder traffic treatment builder
290 * @param driverHandler driver handler
291 * @param deviceId device identifier
292 * @return configured traffic treatment builder
293 */
294 public static TrafficTreatment.Builder configureTreatmentBuilder(List<OFAction> actions,
295 TrafficTreatment.Builder builder,
296 DriverHandler driverHandler,
297 DeviceId deviceId) {
298 ExtensionTreatmentInterpreter interpreter;
Charles Chan14967c22015-12-07 11:11:50 -0800299 if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
Jian Lia0d9a172016-04-01 16:58:06 -0700300 interpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class);
Charles Chan14967c22015-12-07 11:11:50 -0800301 } else {
Jian Lia0d9a172016-04-01 16:58:06 -0700302 interpreter = null;
Charles Chan14967c22015-12-07 11:11:50 -0800303 }
304
alshabib346b5b32015-03-06 00:42:16 -0800305 for (OFAction act : actions) {
306 switch (act.getType()) {
307 case OUTPUT:
308 OFActionOutput out = (OFActionOutput) act;
309 builder.setOutput(
310 PortNumber.portNumber(out.getPort().getPortNumber()));
311 break;
312 case SET_VLAN_VID:
313 OFActionSetVlanVid vlan = (OFActionSetVlanVid) act;
314 builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan()));
315 break;
316 case SET_VLAN_PCP:
317 OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act;
318 builder.setVlanPcp(pcp.getVlanPcp().getValue());
319 break;
320 case SET_DL_DST:
321 OFActionSetDlDst dldst = (OFActionSetDlDst) act;
322 builder.setEthDst(
323 MacAddress.valueOf(dldst.getDlAddr().getLong()));
324 break;
325 case SET_DL_SRC:
326 OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act;
327 builder.setEthSrc(
328 MacAddress.valueOf(dlsrc.getDlAddr().getLong()));
alshabib346b5b32015-03-06 00:42:16 -0800329 break;
330 case SET_NW_DST:
331 OFActionSetNwDst nwdst = (OFActionSetNwDst) act;
332 IPv4Address di = nwdst.getNwAddr();
333 builder.setIpDst(Ip4Address.valueOf(di.getInt()));
334 break;
335 case SET_NW_SRC:
336 OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act;
337 IPv4Address si = nwsrc.getNwAddr();
338 builder.setIpSrc(Ip4Address.valueOf(si.getInt()));
339 break;
340 case EXPERIMENTER:
341 OFActionExperimenter exp = (OFActionExperimenter) act;
342 if (exp.getExperimenter() == 0x80005A06 ||
343 exp.getExperimenter() == 0x748771) {
344 OFActionCircuit ct = (OFActionCircuit) exp;
Yafit Hadar4cc65f72016-02-10 11:23:06 +0200345 CircuitSignalID circuitSignalID = ((OFOxmOchSigid) ct.getField()).getValue();
346 builder.add(Instructions.modL0Lambda(Lambda.ochSignal(
347 lookupGridType(circuitSignalID.getGridType()),
348 lookupChannelSpacing(circuitSignalID.getChannelSpacing()),
349 circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth())));
Jian Lia0d9a172016-04-01 16:58:06 -0700350 } else if (interpreter != null) {
351 builder.extension(interpreter.mapAction(exp), deviceId);
alshabib346b5b32015-03-06 00:42:16 -0800352 } else {
353 log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter());
354 }
355 break;
356 case SET_FIELD:
357 OFActionSetField setField = (OFActionSetField) act;
Jian Lia0d9a172016-04-01 16:58:06 -0700358 handleSetField(builder, setField, driverHandler, deviceId);
alshabib346b5b32015-03-06 00:42:16 -0800359 break;
360 case POP_MPLS:
361 OFActionPopMpls popMpls = (OFActionPopMpls) act;
Ray Milkey84d5a292016-02-22 14:04:01 -0800362 builder.popMpls(new EthType(popMpls.getEthertype().getValue()));
alshabib346b5b32015-03-06 00:42:16 -0800363 break;
364 case PUSH_MPLS:
365 builder.pushMpls();
366 break;
367 case COPY_TTL_IN:
368 builder.copyTtlIn();
369 break;
370 case COPY_TTL_OUT:
371 builder.copyTtlOut();
372 break;
373 case DEC_MPLS_TTL:
374 builder.decMplsTtl();
375 break;
376 case DEC_NW_TTL:
377 builder.decNwTtl();
378 break;
379 case GROUP:
380 OFActionGroup group = (OFActionGroup) act;
381 builder.group(new DefaultGroupId(group.getGroup().getGroupNumber()));
382 break;
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200383 case SET_QUEUE:
384 OFActionSetQueue setQueue = (OFActionSetQueue) act;
385 builder.setQueue(setQueue.getQueueId());
386 break;
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200387 case ENQUEUE:
388 OFActionEnqueue enqueue = (OFActionEnqueue) act;
Jian Liffef5002016-04-04 23:27:37 -0700389 builder.setQueue(enqueue.getQueueId(),
390 PortNumber.portNumber(enqueue.getPort().getPortNumber()));
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200391 break;
Jonathan Hart67fc0972015-03-19 15:21:20 -0700392 case STRIP_VLAN:
alshabib346b5b32015-03-06 00:42:16 -0800393 case POP_VLAN:
394 builder.popVlan();
395 break;
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700396 case PUSH_VLAN:
397 builder.pushVlan();
398 break;
alshabib346b5b32015-03-06 00:42:16 -0800399 case SET_TP_DST:
400 case SET_TP_SRC:
401 case POP_PBB:
402 case PUSH_PBB:
alshabib346b5b32015-03-06 00:42:16 -0800403 case SET_MPLS_LABEL:
404 case SET_MPLS_TC:
405 case SET_MPLS_TTL:
406 case SET_NW_ECN:
407 case SET_NW_TOS:
408 case SET_NW_TTL:
alshabib346b5b32015-03-06 00:42:16 -0800409
alshabib346b5b32015-03-06 00:42:16 -0800410 default:
411 log.warn("Action type {} not yet implemented.", act.getType());
412 }
413 }
414 return builder;
415 }
416
Jian Lia0d9a172016-04-01 16:58:06 -0700417 private TrafficTreatment.Builder buildActions(List<OFAction> actions,
418 TrafficTreatment.Builder builder) {
Jonathan Harte4e74f02016-03-03 12:57:40 -0800419 DriverHandler driverHandler = getDriver(deviceId);
Jian Lia0d9a172016-04-01 16:58:06 -0700420
421 return configureTreatmentBuilder(actions, builder, driverHandler, deviceId);
422 }
423
424
425 private static void handleSetField(TrafficTreatment.Builder builder,
426 OFActionSetField action,
427 DriverHandler driverHandler,
428 DeviceId deviceId) {
Charles Chan14967c22015-12-07 11:11:50 -0800429 ExtensionTreatmentInterpreter treatmentInterpreter;
430 if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
431 treatmentInterpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class);
432 } else {
433 treatmentInterpreter = null;
434 }
435
Jonathan Hart3c259162015-10-21 21:31:19 -0700436 OFOxm<?> oxm = action.getField();
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800437 switch (oxm.getMatchField().id) {
438 case VLAN_PCP:
439 @SuppressWarnings("unchecked")
440 OFOxm<VlanPcp> vlanpcp = (OFOxm<VlanPcp>) oxm;
441 builder.setVlanPcp(vlanpcp.getValue().getValue());
442 break;
443 case VLAN_VID:
Charles Chan4211baa2016-04-20 17:10:40 -0700444 if (treatmentInterpreter != null) {
445 try {
446 builder.extension(treatmentInterpreter.mapAction(action), deviceId);
447 break;
448 } catch (UnsupportedOperationException e) {
449 log.debug("Unsupported action extension; defaulting to native OF");
450 }
Charles Chan14967c22015-12-07 11:11:50 -0800451 }
alshabib44852fb2016-04-15 15:56:51 -0700452 @SuppressWarnings("unchecked")
453 OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm;
454 builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan()));
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800455 break;
456 case ETH_DST:
457 @SuppressWarnings("unchecked")
458 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethdst =
459 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
460 builder.setEthDst(MacAddress.valueOf(ethdst.getValue().getLong()));
461 break;
462 case ETH_SRC:
463 @SuppressWarnings("unchecked")
464 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethsrc =
465 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
466 builder.setEthSrc(MacAddress.valueOf(ethsrc.getValue().getLong()));
467 break;
468 case IPV4_DST:
469 @SuppressWarnings("unchecked")
470 OFOxm<IPv4Address> ip4dst = (OFOxm<IPv4Address>) oxm;
471 builder.setIpDst(Ip4Address.valueOf(ip4dst.getValue().getInt()));
472 break;
473 case IPV4_SRC:
474 @SuppressWarnings("unchecked")
475 OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm;
476 builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt()));
477 break;
sangho3f97a17d2015-01-29 22:56:29 -0800478 case MPLS_LABEL:
479 @SuppressWarnings("unchecked")
480 OFOxm<U32> labelId = (OFOxm<U32>) oxm;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100481 builder.setMpls(MplsLabel.mplsLabel((int) labelId.getValue().getValue()));
sangho3f97a17d2015-01-29 22:56:29 -0800482 break;
Saurav Das73a7dd42015-08-19 22:20:31 -0700483 case MPLS_BOS:
484 @SuppressWarnings("unchecked")
485 OFOxm<U8> mplsBos = (OFOxm<U8>) oxm;
486 builder.setMplsBos(mplsBos.getValue() == U8.ZERO ? false : true);
487 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700488 case TUNNEL_ID:
489 @SuppressWarnings("unchecked")
490 OFOxm<U64> tunnelId = (OFOxm<U64>) oxm;
491 builder.setTunnelId(tunnelId.getValue().getValue());
492 break;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700493 case TCP_DST:
494 @SuppressWarnings("unchecked")
495 OFOxm<TransportPort> tcpdst = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700496 builder.setTcpDst(TpPort.tpPort(tcpdst.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700497 break;
498 case TCP_SRC:
499 @SuppressWarnings("unchecked")
500 OFOxm<TransportPort> tcpsrc = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700501 builder.setTcpSrc(TpPort.tpPort(tcpsrc.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700502 break;
503 case UDP_DST:
504 @SuppressWarnings("unchecked")
505 OFOxm<TransportPort> udpdst = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700506 builder.setUdpDst(TpPort.tpPort(udpdst.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700507 break;
508 case UDP_SRC:
509 @SuppressWarnings("unchecked")
510 OFOxm<TransportPort> udpsrc = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700511 builder.setUdpSrc(TpPort.tpPort(udpsrc.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700512 break;
Jonathan Hart3c259162015-10-21 21:31:19 -0700513 case TUNNEL_IPV4_DST:
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530514 case NSP:
515 case NSI:
516 case NSH_C1:
517 case NSH_C2:
518 case NSH_C3:
519 case NSH_C4:
520 case NSH_MDTYPE:
521 case NSH_NP:
522 case ENCAP_ETH_SRC:
523 case ENCAP_ETH_DST:
524 case ENCAP_ETH_TYPE:
525 case TUN_GPE_NP:
Jian Liffef5002016-04-04 23:27:37 -0700526 if (treatmentInterpreter != null) {
527 try {
528 builder.extension(treatmentInterpreter.mapAction(action), deviceId);
529 } catch (UnsupportedOperationException e) {
alshabib44852fb2016-04-15 15:56:51 -0700530 log.debug(e.getMessage());
Jian Liffef5002016-04-04 23:27:37 -0700531 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700532 }
533 break;
Yafit Hadar73514612015-11-04 10:14:21 +0200534 case EXP_ODU_SIG_ID:
535 @SuppressWarnings("unchecked")
536 OFOxm<OduSignalID> oduID = (OFOxm<OduSignalID>) oxm;
537 OduSignalID oduSignalID = oduID.getValue();
538 OduSignalId oduSignalId = OduSignalId.oduSignalId(oduSignalID.getTpn(),
539 oduSignalID.getTslen(),
540 oduSignalID.getTsmap());
541 builder.add(modL1OduSignalId(oduSignalId));
542 break;
543 case EXP_OCH_SIG_ID:
544 try {
545 @SuppressWarnings("unchecked")
546 OFOxm<CircuitSignalID> ochId = (OFOxm<CircuitSignalID>) oxm;
547 CircuitSignalID circuitSignalID = ochId.getValue();
548 builder.add(modL0Lambda(Lambda.ochSignal(
549 lookupGridType(circuitSignalID.getGridType()),
550 lookupChannelSpacing(circuitSignalID.getChannelSpacing()),
551 circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth())));
552 } catch (NoMappingFoundException e) {
553 log.warn(e.getMessage());
554 break;
555 }
556 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800557 case ARP_OP:
lishuai67574ce2016-05-12 16:39:59 +0800558 @SuppressWarnings("unchecked")
559 OFOxm<org.projectfloodlight.openflow.types.ArpOpcode> arpop =
560 (OFOxm<org.projectfloodlight.openflow.types.ArpOpcode>) oxm;
561 builder.setArpOp((short) arpop.getValue().getOpcode());
562 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800563 case ARP_SHA:
lishuai67574ce2016-05-12 16:39:59 +0800564 @SuppressWarnings("unchecked")
565 OFOxm<org.projectfloodlight.openflow.types.MacAddress> arpsha =
566 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
567 builder.setArpSha(MacAddress.valueOf(arpsha.getValue().getLong()));
568 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800569 case ARP_SPA:
lishuai67574ce2016-05-12 16:39:59 +0800570 @SuppressWarnings("unchecked")
571 OFOxm<IPv4Address> arpspa = (OFOxm<IPv4Address>) oxm;
572 builder.setArpSpa(Ip4Address.valueOf(arpspa.getValue().getInt()));
573 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800574 case ARP_THA:
575 case ARP_TPA:
576 case BSN_EGR_PORT_GROUP_ID:
577 case BSN_GLOBAL_VRF_ALLOWED:
578 case BSN_IN_PORTS_128:
579 case BSN_L3_DST_CLASS_ID:
580 case BSN_L3_INTERFACE_CLASS_ID:
581 case BSN_L3_SRC_CLASS_ID:
582 case BSN_LAG_ID:
583 case BSN_TCP_FLAGS:
584 case BSN_UDF0:
585 case BSN_UDF1:
586 case BSN_UDF2:
587 case BSN_UDF3:
588 case BSN_UDF4:
589 case BSN_UDF5:
590 case BSN_UDF6:
591 case BSN_UDF7:
592 case BSN_VLAN_XLATE_PORT_GROUP_ID:
593 case BSN_VRF:
594 case ETH_TYPE:
595 case ICMPV4_CODE:
596 case ICMPV4_TYPE:
597 case ICMPV6_CODE:
598 case ICMPV6_TYPE:
599 case IN_PHY_PORT:
600 case IN_PORT:
601 case IPV6_DST:
602 case IPV6_FLABEL:
603 case IPV6_ND_SLL:
604 case IPV6_ND_TARGET:
605 case IPV6_ND_TLL:
606 case IPV6_SRC:
607 case IP_DSCP:
608 case IP_ECN:
609 case IP_PROTO:
610 case METADATA:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800611 case MPLS_TC:
612 case OCH_SIGID:
613 case OCH_SIGID_BASIC:
614 case OCH_SIGTYPE:
615 case OCH_SIGTYPE_BASIC:
616 case SCTP_DST:
617 case SCTP_SRC:
Yafit Hadar73514612015-11-04 10:14:21 +0200618 case EXP_ODU_SIGTYPE:
619 case EXP_OCH_SIGTYPE:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800620 default:
621 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
622 break;
623 }
624 }
625
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700626 // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES
alshabib6b5cfec2014-09-18 17:42:18 -0700627 private TrafficSelector buildSelector() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800628 MacAddress mac;
629 Ip4Prefix ip4Prefix;
630 Ip6Address ip6Address;
631 Ip6Prefix ip6Prefix;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800632 Ip4Address ip;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800633
Jonathan Harte4e74f02016-03-03 12:57:40 -0800634 DriverHandler driverHandler = getDriver(deviceId);
Charles Chan14967c22015-12-07 11:11:50 -0800635 ExtensionSelectorInterpreter selectorInterpreter;
636 if (driverHandler.hasBehaviour(ExtensionSelectorInterpreter.class)) {
637 selectorInterpreter = driverHandler.behaviour(ExtensionSelectorInterpreter.class);
638 } else {
639 selectorInterpreter = null;
640 }
641
tom9a693fd2014-10-03 11:32:19 -0700642 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700643 for (MatchField<?> field : match.getMatchFields()) {
644 switch (field.id) {
645 case IN_PORT:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800646 builder.matchInPort(PortNumber
alshabib010c31d2014-09-26 10:01:12 -0700647 .portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700648 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800649 case IN_PHY_PORT:
650 builder.matchInPhyPort(PortNumber
651 .portNumber(match.get(MatchField.IN_PHY_PORT).getPortNumber()));
652 break;
653 case METADATA:
654 long metadata =
655 match.get(MatchField.METADATA).getValue().getValue();
656 builder.matchMetadata(metadata);
657 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700658 case ETH_DST:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800659 if (match.isPartiallyMasked(MatchField.ETH_DST)) {
660 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
661 match.getMasked(MatchField.ETH_DST);
662 builder.matchEthDstMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
663 MacAddress.valueOf(maskedMac.getMask().getLong()));
664 } else {
665 mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
666 builder.matchEthDst(mac);
667 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800668 break;
669 case ETH_SRC:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800670 if (match.isPartiallyMasked(MatchField.ETH_SRC)) {
671 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
672 match.getMasked(MatchField.ETH_SRC);
673 builder.matchEthSrcMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
674 MacAddress.valueOf(maskedMac.getMask().getLong()));
675 } else {
676 mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
677 builder.matchEthSrc(mac);
678 }
alshabib6b5cfec2014-09-18 17:42:18 -0700679 break;
680 case ETH_TYPE:
681 int ethType = match.get(MatchField.ETH_TYPE).getValue();
Jonathan Hart8cf212a2015-10-29 17:42:03 -0700682 builder.matchEthType((short) ethType);
alshabib6b5cfec2014-09-18 17:42:18 -0700683 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700684 case VLAN_VID:
Charles Chan14967c22015-12-07 11:11:50 -0800685 if (selectorInterpreter != null &&
686 selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
687 if (match.getVersion().equals(OFVersion.OF_13)) {
688 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.VLAN_VID);
689 builder.extension(selectorInterpreter.mapOxm(oxm),
Jonathan Harte4e74f02016-03-03 12:57:40 -0800690 deviceId);
Charles Chan14967c22015-12-07 11:11:50 -0800691 } else {
692 break;
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800693 }
694 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800695 VlanId vlanId = null;
696 if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
697 Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
698 if (masked.getValue().equals(OFVlanVidMatch.PRESENT)
699 && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
700 vlanId = VlanId.ANY;
701 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700702 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800703 if (!match.get(MatchField.VLAN_VID).isPresentBitSet()) {
704 vlanId = VlanId.NONE;
705 } else {
706 vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
707 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700708 }
Charles Chan14967c22015-12-07 11:11:50 -0800709 if (vlanId != null) {
710 builder.matchVlanId(vlanId);
711 }
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800712 }
alshabib6b5cfec2014-09-18 17:42:18 -0700713 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800714 case VLAN_PCP:
715 byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
716 builder.matchVlanPcp(vlanPcp);
717 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800718 case IP_DSCP:
719 byte ipDscp = match.get(MatchField.IP_DSCP).getDscpValue();
720 builder.matchIPDscp(ipDscp);
721 break;
722 case IP_ECN:
723 byte ipEcn = match.get(MatchField.IP_ECN).getEcnValue();
724 builder.matchIPEcn(ipEcn);
725 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800726 case IP_PROTO:
727 short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
728 builder.matchIPProtocol((byte) proto);
729 break;
730 case IPV4_SRC:
731 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
732 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800733 ip4Prefix = Ip4Prefix.valueOf(
734 maskedIp.getValue().getInt(),
735 maskedIp.getMask().asCidrMaskLength());
736 } else {
737 ip4Prefix = Ip4Prefix.valueOf(
738 match.get(MatchField.IPV4_SRC).getInt(),
739 Ip4Prefix.MAX_MASK_LENGTH);
740 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800741 builder.matchIPSrc(ip4Prefix);
742 break;
743 case IPV4_DST:
744 if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
745 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800746 ip4Prefix = Ip4Prefix.valueOf(
747 maskedIp.getValue().getInt(),
748 maskedIp.getMask().asCidrMaskLength());
749 } else {
750 ip4Prefix = Ip4Prefix.valueOf(
751 match.get(MatchField.IPV4_DST).getInt(),
752 Ip4Prefix.MAX_MASK_LENGTH);
753 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800754 builder.matchIPDst(ip4Prefix);
Jonathan Hart34bc6142014-10-17 11:00:43 -0700755 break;
756 case TCP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700757 builder.matchTcpSrc(TpPort.tpPort(match.get(MatchField.TCP_SRC).getPort()));
Jonathan Hart34bc6142014-10-17 11:00:43 -0700758 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800759 case TCP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700760 builder.matchTcpDst(TpPort.tpPort(match.get(MatchField.TCP_DST).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800761 break;
762 case UDP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700763 builder.matchUdpSrc(TpPort.tpPort(match.get(MatchField.UDP_SRC).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800764 break;
765 case UDP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700766 builder.matchUdpDst(TpPort.tpPort(match.get(MatchField.UDP_DST).getPort()));
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700767 break;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100768 case MPLS_LABEL:
769 builder.matchMplsLabel(MplsLabel.mplsLabel((int) match.get(MatchField.MPLS_LABEL)
770 .getValue()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800771 break;
Saurav Dasffc5bbc2015-08-18 23:30:19 -0700772 case MPLS_BOS:
773 builder.matchMplsBos(match.get(MatchField.MPLS_BOS).getValue());
774 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800775 case SCTP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700776 builder.matchSctpSrc(TpPort.tpPort(match.get(MatchField.SCTP_SRC).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800777 break;
778 case SCTP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700779 builder.matchSctpDst(TpPort.tpPort(match.get(MatchField.SCTP_DST).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800780 break;
781 case ICMPV4_TYPE:
782 byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
783 builder.matchIcmpType(icmpType);
784 break;
785 case ICMPV4_CODE:
786 byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode();
787 builder.matchIcmpCode(icmpCode);
788 break;
789 case IPV6_SRC:
790 if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
791 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
792 ip6Prefix = Ip6Prefix.valueOf(
793 maskedIp.getValue().getBytes(),
794 maskedIp.getMask().asCidrMaskLength());
795 } else {
796 ip6Prefix = Ip6Prefix.valueOf(
797 match.get(MatchField.IPV6_SRC).getBytes(),
798 Ip6Prefix.MAX_MASK_LENGTH);
799 }
800 builder.matchIPv6Src(ip6Prefix);
801 break;
802 case IPV6_DST:
803 if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
804 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
805 ip6Prefix = Ip6Prefix.valueOf(
806 maskedIp.getValue().getBytes(),
807 maskedIp.getMask().asCidrMaskLength());
808 } else {
809 ip6Prefix = Ip6Prefix.valueOf(
810 match.get(MatchField.IPV6_DST).getBytes(),
811 Ip6Prefix.MAX_MASK_LENGTH);
812 }
813 builder.matchIPv6Dst(ip6Prefix);
814 break;
815 case IPV6_FLABEL:
816 int flowLabel =
817 match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue();
818 builder.matchIPv6FlowLabel(flowLabel);
819 break;
820 case ICMPV6_TYPE:
821 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
822 builder.matchIcmpv6Type(icmpv6type);
823 break;
824 case ICMPV6_CODE:
825 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
826 builder.matchIcmpv6Code(icmpv6code);
827 break;
828 case IPV6_ND_TARGET:
829 ip6Address =
830 Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes());
831 builder.matchIPv6NDTargetAddress(ip6Address);
832 break;
833 case IPV6_ND_SLL:
834 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong());
835 builder.matchIPv6NDSourceLinkLayerAddress(mac);
836 break;
837 case IPV6_ND_TLL:
838 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong());
839 builder.matchIPv6NDTargetLinkLayerAddress(mac);
840 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800841 case IPV6_EXTHDR:
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800842 builder.matchIPv6ExthdrFlags((short) match.get(MatchField.IPV6_EXTHDR)
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700843 .getValue());
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800844 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700845 case OCH_SIGID:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700846 CircuitSignalID sigId = match.get(MatchField.OCH_SIGID);
847 builder.add(matchLambda(Lambda.ochSignal(
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700848 lookupGridType(sigId.getGridType()), lookupChannelSpacing(sigId.getChannelSpacing()),
Marc De Leenheer0b8b2ef2015-08-03 15:39:00 -0700849 sigId.getChannelNumber(), sigId.getSpectralWidth())
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700850 ));
Marc De Leenheer49087752014-10-23 13:54:09 -0700851 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800852 case OCH_SIGTYPE:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700853 U8 sigType = match.get(MatchField.OCH_SIGTYPE);
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700854 builder.add(matchOchSignalType(lookupOchSignalType((byte) sigType.getValue())));
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800855 break;
Yafit Hadar73514612015-11-04 10:14:21 +0200856 case EXP_OCH_SIG_ID:
857 try {
858 CircuitSignalID expSigId = match.get(MatchField.EXP_OCH_SIG_ID);
859 builder.add(matchLambda(Lambda.ochSignal(
860 lookupGridType(expSigId.getGridType()), lookupChannelSpacing(expSigId.getChannelSpacing()),
861 expSigId.getChannelNumber(), expSigId.getSpectralWidth())));
862 } catch (NoMappingFoundException e) {
863 log.warn(e.getMessage());
864 break;
865 }
866 break;
867 case EXP_OCH_SIGTYPE:
868 try {
869 U8 expOchSigType = match.get(MatchField.EXP_OCH_SIGTYPE);
870 builder.add(matchOchSignalType(lookupOchSignalType((byte) expOchSigType.getValue())));
871 } catch (NoMappingFoundException e) {
872 log.warn(e.getMessage());
873 break;
874 }
875 break;
876 case EXP_ODU_SIG_ID:
877 OduSignalId oduSignalId = OduSignalId.oduSignalId(match.get(MatchField.EXP_ODU_SIG_ID).getTpn(),
878 match.get(MatchField.EXP_ODU_SIG_ID).getTslen(),
879 match.get(MatchField.EXP_ODU_SIG_ID).getTsmap());
880 builder.add(matchOduSignalId(oduSignalId));
881 break;
882 case EXP_ODU_SIGTYPE:
883 try {
884 U8 oduSigType = match.get(MatchField.EXP_ODU_SIGTYPE);
885 builder.add(matchOduSignalType(lookupOduSignalType((byte) oduSigType.getValue())));
886 } catch (NoMappingFoundException e) {
887 log.warn(e.getMessage());
888 break;
889 }
890 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700891 case TUNNEL_ID:
892 long tunnelId = match.get(MatchField.TUNNEL_ID).getValue();
893 builder.matchTunnelId(tunnelId);
894 break;
BitOhenryb40129a2015-11-30 12:41:18 +0800895 case ARP_OP:
896 int arpOp = match.get(MatchField.ARP_OP).getOpcode();
897 builder.matchArpOp(arpOp);
898 break;
BitOhenrya331b182015-11-23 08:39:37 +0800899 case ARP_SHA:
900 mac = MacAddress.valueOf(match.get(MatchField.ARP_SHA).getLong());
901 builder.matchArpSha(mac);
902 break;
BitOhenry296b4542015-11-24 08:41:58 +0800903 case ARP_SPA:
904 ip = Ip4Address.valueOf(match.get(MatchField.ARP_SPA).getInt());
905 builder.matchArpSpa(ip);
906 break;
BitOhenry76430852015-11-20 19:04:49 +0800907 case ARP_THA:
908 mac = MacAddress.valueOf(match.get(MatchField.ARP_THA).getLong());
909 builder.matchArpTha(mac);
910 break;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800911 case ARP_TPA:
912 ip = Ip4Address.valueOf(match.get(MatchField.ARP_TPA).getInt());
913 builder.matchArpTpa(ip);
914 break;
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530915 case NSP:
916 if (selectorInterpreter != null) {
917 try {
918 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.NSP);
919 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
920 } catch (UnsupportedOperationException e) {
921 log.debug(e.getMessage());
922 }
923 }
924 break;
925 case NSI:
926 if (selectorInterpreter != null) {
927 try {
928 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.NSI);
929 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
930 } catch (UnsupportedOperationException e) {
931 log.debug(e.getMessage());
932 }
933 }
934 break;
935 case ENCAP_ETH_TYPE:
936 if (selectorInterpreter != null) {
937 try {
938 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.ENCAP_ETH_TYPE);
939 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
940 } catch (UnsupportedOperationException e) {
941 log.debug(e.getMessage());
942 }
943 }
944 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700945 case MPLS_TC:
alshabib6b5cfec2014-09-18 17:42:18 -0700946 default:
947 log.warn("Match type {} not yet implemented.", field.id);
alshabib6b5cfec2014-09-18 17:42:18 -0700948 }
949 }
950 return builder.build();
951 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700952
Jian Liffef5002016-04-04 23:27:37 -0700953 private DriverHandler getDriver(DeviceId devId) {
954 Driver driver = driverService.getDriver(devId);
955 DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, devId));
Jonathan Hart3c259162015-10-21 21:31:19 -0700956 return handler;
957 }
alshabib6b5cfec2014-09-18 17:42:18 -0700958}