blob: 51d32df12b6bb0be95078259a8f82d7b40091e36 [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.provider.of.flow.impl;
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;
48import org.onosproject.net.flow.instructions.ExtensionTreatmentType.ExtensionTreatmentTypes;
Sho SHIMIZU9553bb82015-06-30 16:02:45 -070049import org.onosproject.net.flow.instructions.Instructions;
Charles Chan14967c22015-12-07 11:11:50 -080050import org.onosproject.openflow.controller.ExtensionSelectorInterpreter;
alshabib880b6442015-11-23 22:13:04 -080051import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter;
Brian O'Connor72cb19a2015-01-16 16:14:41 -080052import org.projectfloodlight.openflow.protocol.OFFlowMod;
alshabib6b5cfec2014-09-18 17:42:18 -070053import org.projectfloodlight.openflow.protocol.OFFlowRemoved;
54import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry;
Charles Chan14967c22015-12-07 11:11:50 -080055import org.projectfloodlight.openflow.protocol.OFMatchV3;
Brian O'Connor21564612015-12-05 19:24:59 -080056import org.projectfloodlight.openflow.protocol.OFVersion;
alshabib6b5cfec2014-09-18 17:42:18 -070057import org.projectfloodlight.openflow.protocol.action.OFAction;
Marc De Leenheer49087752014-10-23 13:54:09 -070058import org.projectfloodlight.openflow.protocol.action.OFActionCircuit;
Steffen Gebertba2d3b72015-10-22 11:14:31 +020059import org.projectfloodlight.openflow.protocol.action.OFActionEnqueue;
Marc De Leenheer49087752014-10-23 13:54:09 -070060import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter;
sangho8995ac52015-02-04 11:29:03 -080061import org.projectfloodlight.openflow.protocol.action.OFActionGroup;
alshabib6b5cfec2014-09-18 17:42:18 -070062import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
sangho3f97a17d2015-01-29 22:56:29 -080063import org.projectfloodlight.openflow.protocol.action.OFActionPopMpls;
alshabib6b5cfec2014-09-18 17:42:18 -070064import org.projectfloodlight.openflow.protocol.action.OFActionSetDlDst;
65import org.projectfloodlight.openflow.protocol.action.OFActionSetDlSrc;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080066import org.projectfloodlight.openflow.protocol.action.OFActionSetField;
alshabib6b5cfec2014-09-18 17:42:18 -070067import org.projectfloodlight.openflow.protocol.action.OFActionSetNwDst;
68import org.projectfloodlight.openflow.protocol.action.OFActionSetNwSrc;
Jonathan Hart8cf212a2015-10-29 17:42:03 -070069import org.projectfloodlight.openflow.protocol.action.OFActionSetQueue;
alshabib6b5cfec2014-09-18 17:42:18 -070070import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanPcp;
71import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanVid;
alshabib19fdc122014-10-03 11:38:19 -070072import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
Jonathan Hartcf783202014-11-24 18:55:42 -080073import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions;
alshabibbdcbb102015-04-22 14:16:38 -070074import org.projectfloodlight.openflow.protocol.instruction.OFInstructionGotoTable;
alshabib346b5b32015-03-06 00:42:16 -080075import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteActions;
Saurav Das86af8f12015-05-25 23:55:33 -070076import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteMetadata;
alshabib6b5cfec2014-09-18 17:42:18 -070077import org.projectfloodlight.openflow.protocol.match.Match;
78import org.projectfloodlight.openflow.protocol.match.MatchField;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080079import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
Yafit Hadar4cc65f72016-02-10 11:23:06 +020080import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigid;
alshabib346b5b32015-03-06 00:42:16 -080081import org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070082import org.projectfloodlight.openflow.types.CircuitSignalID;
alshabib6b5cfec2014-09-18 17:42:18 -070083import org.projectfloodlight.openflow.types.IPv4Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080084import org.projectfloodlight.openflow.types.IPv6Address;
Jonathan Hart0e12fad2014-10-17 14:54:58 -070085import org.projectfloodlight.openflow.types.Masked;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080086import org.projectfloodlight.openflow.types.OFVlanVidMatch;
Jonathan Harte4e74f02016-03-03 12:57:40 -080087import org.projectfloodlight.openflow.types.OduSignalID;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -070088import org.projectfloodlight.openflow.types.TransportPort;
sangho3f97a17d2015-01-29 22:56:29 -080089import org.projectfloodlight.openflow.types.U32;
Hyunsun Moona08c5d02015-07-14 17:53:00 -070090import org.projectfloodlight.openflow.types.U64;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070091import org.projectfloodlight.openflow.types.U8;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080092import org.projectfloodlight.openflow.types.VlanPcp;
alshabib6b5cfec2014-09-18 17:42:18 -070093import org.slf4j.Logger;
Jian Lia0d9a172016-04-01 16:58:06 -070094import org.slf4j.LoggerFactory;
alshabib6b5cfec2014-09-18 17:42:18 -070095
Jonathan Hart8cf212a2015-10-29 17:42:03 -070096import java.util.List;
97
98import static org.onosproject.net.flow.criteria.Criteria.matchLambda;
99import static org.onosproject.net.flow.criteria.Criteria.matchOchSignalType;
Yafit Hadar73514612015-11-04 10:14:21 +0200100import static org.onosproject.net.flow.criteria.Criteria.matchOduSignalId;
Jonathan Harte4e74f02016-03-03 12:57:40 -0800101import static org.onosproject.net.flow.criteria.Criteria.matchOduSignalType;
Yafit Hadar73514612015-11-04 10:14:21 +0200102import static org.onosproject.net.flow.instructions.Instructions.modL0Lambda;
103import static org.onosproject.net.flow.instructions.Instructions.modL1OduSignalId;
Jonathan Hart8cf212a2015-10-29 17:42:03 -0700104import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupChannelSpacing;
105import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupGridType;
106import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupOchSignalType;
Yafit Hadar73514612015-11-04 10:14:21 +0200107import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupOduSignalType;
alshabib19fdc122014-10-03 11:38:19 -0700108
alshabib1c319ff2014-10-04 20:29:09 -0700109public class FlowEntryBuilder {
Jian Lia0d9a172016-04-01 16:58:06 -0700110 private static final Logger log = LoggerFactory.getLogger(FlowEntryBuilder.class);
alshabib6b5cfec2014-09-18 17:42:18 -0700111
112 private final OFFlowStatsEntry stat;
113 private final OFFlowRemoved removed;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800114 private final OFFlowMod flowMod;
alshabib6b5cfec2014-09-18 17:42:18 -0700115
116 private final Match match;
alshabib346b5b32015-03-06 00:42:16 -0800117
Jonathan Hart67fc0972015-03-19 15:21:20 -0700118 // All actions are contained in an OFInstruction. For OF1.0
119 // the instruction type is apply instruction (immediate set in ONOS speak)
alshabib346b5b32015-03-06 00:42:16 -0800120 private final List<OFInstruction> instructions;
alshabib6b5cfec2014-09-18 17:42:18 -0700121
Jonathan Harte4e74f02016-03-03 12:57:40 -0800122 private final DeviceId deviceId;
alshabib6b5cfec2014-09-18 17:42:18 -0700123
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800124 public enum FlowType { STAT, REMOVED, MOD }
125
126 private final FlowType type;
alshabib6b5cfec2014-09-18 17:42:18 -0700127
Jonathan Hart3c259162015-10-21 21:31:19 -0700128 private final DriverService driverService;
129
Jonathan Harte4e74f02016-03-03 12:57:40 -0800130 public FlowEntryBuilder(DeviceId deviceId, OFFlowStatsEntry entry, DriverService driverService) {
Saurav Dasfa2fa932015-03-03 11:29:48 -0800131 this.stat = entry;
132 this.match = entry.getMatch();
alshabib346b5b32015-03-06 00:42:16 -0800133 this.instructions = getInstructions(entry);
Jonathan Harte4e74f02016-03-03 12:57:40 -0800134 this.deviceId = deviceId;
Saurav Dasfa2fa932015-03-03 11:29:48 -0800135 this.removed = null;
136 this.flowMod = null;
137 this.type = FlowType.STAT;
Jonathan Hart3c259162015-10-21 21:31:19 -0700138 this.driverService = driverService;
Saurav Dasfa2fa932015-03-03 11:29:48 -0800139 }
140
Jonathan Harte4e74f02016-03-03 12:57:40 -0800141 public FlowEntryBuilder(DeviceId deviceId, OFFlowRemoved removed, DriverService driverService) {
alshabib6b5cfec2014-09-18 17:42:18 -0700142 this.match = removed.getMatch();
143 this.removed = removed;
Jonathan Harte4e74f02016-03-03 12:57:40 -0800144 this.deviceId = deviceId;
alshabib346b5b32015-03-06 00:42:16 -0800145 this.instructions = null;
alshabib6b5cfec2014-09-18 17:42:18 -0700146 this.stat = null;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800147 this.flowMod = null;
148 this.type = FlowType.REMOVED;
Jonathan Hart3c259162015-10-21 21:31:19 -0700149 this.driverService = driverService;
alshabib6b5cfec2014-09-18 17:42:18 -0700150 }
151
Jonathan Harte4e74f02016-03-03 12:57:40 -0800152 public FlowEntryBuilder(DeviceId deviceId, OFFlowMod fm, DriverService driverService) {
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800153 this.match = fm.getMatch();
Jonathan Harte4e74f02016-03-03 12:57:40 -0800154 this.deviceId = deviceId;
alshabib346b5b32015-03-06 00:42:16 -0800155 this.instructions = getInstructions(fm);
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800156 this.type = FlowType.MOD;
157 this.flowMod = fm;
158 this.stat = null;
159 this.removed = null;
Jonathan Hart3c259162015-10-21 21:31:19 -0700160 this.driverService = driverService;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800161 }
alshabib1c319ff2014-10-04 20:29:09 -0700162
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800163 public FlowEntry build(FlowEntryState... state) {
Brian O'Connor21564612015-12-05 19:24:59 -0800164 FlowRule.Builder builder;
165 try {
166 switch (this.type) {
167 case STAT:
168 builder = DefaultFlowRule.builder()
Jonathan Harte4e74f02016-03-03 12:57:40 -0800169 .forDevice(deviceId)
Brian O'Connor21564612015-12-05 19:24:59 -0800170 .withSelector(buildSelector())
171 .withTreatment(buildTreatment())
172 .withPriority(stat.getPriority())
173 .makeTemporary(stat.getIdleTimeout())
Jonathan Hartd1ce4b02016-01-11 13:28:36 -0800174 .withCookie(stat.getCookie().getValue());
175 if (stat.getVersion() != OFVersion.OF_10) {
176 builder.forTable(stat.getTableId().getValue());
177 }
alshabibbdcbb102015-04-22 14:16:38 -0700178
Brian O'Connor21564612015-12-05 19:24:59 -0800179 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
180 stat.getDurationSec(),
181 stat.getPacketCount().getValue(),
182 stat.getByteCount().getValue());
183 case REMOVED:
184 builder = DefaultFlowRule.builder()
Jonathan Harte4e74f02016-03-03 12:57:40 -0800185 .forDevice(deviceId)
Brian O'Connor21564612015-12-05 19:24:59 -0800186 .withSelector(buildSelector())
187 .withPriority(removed.getPriority())
188 .makeTemporary(removed.getIdleTimeout())
189 .withCookie(removed.getCookie().getValue());
190 if (removed.getVersion() != OFVersion.OF_10) {
191 builder.forTable(removed.getTableId().getValue());
192 }
alshabibbdcbb102015-04-22 14:16:38 -0700193
Brian O'Connor21564612015-12-05 19:24:59 -0800194 return new DefaultFlowEntry(builder.build(), FlowEntryState.REMOVED,
195 removed.getDurationSec(),
196 removed.getPacketCount().getValue(),
197 removed.getByteCount().getValue());
198 case MOD:
199 FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED;
200 builder = DefaultFlowRule.builder()
Jonathan Harte4e74f02016-03-03 12:57:40 -0800201 .forDevice(deviceId)
Brian O'Connor21564612015-12-05 19:24:59 -0800202 .withSelector(buildSelector())
203 .withTreatment(buildTreatment())
204 .withPriority(flowMod.getPriority())
205 .makeTemporary(flowMod.getIdleTimeout())
206 .withCookie(flowMod.getCookie().getValue());
207 if (flowMod.getVersion() != OFVersion.OF_10) {
208 builder.forTable(flowMod.getTableId().getValue());
209 }
alshabibbdcbb102015-04-22 14:16:38 -0700210
Brian O'Connor21564612015-12-05 19:24:59 -0800211 return new DefaultFlowEntry(builder.build(), flowState, 0, 0, 0);
212 default:
213 log.error("Unknown flow type : {}", this.type);
214 return null;
215 }
216 } catch (UnsupportedOperationException e) {
217 log.warn("Error building flow entry", e);
218 return null;
alshabib6b5cfec2014-09-18 17:42:18 -0700219 }
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800220
alshabib6b5cfec2014-09-18 17:42:18 -0700221 }
222
alshabib346b5b32015-03-06 00:42:16 -0800223 private List<OFInstruction> getInstructions(OFFlowMod entry) {
alshabib19fdc122014-10-03 11:38:19 -0700224 switch (entry.getVersion()) {
225 case OF_10:
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700226 return Lists.newArrayList(OFFactoryVer13.INSTANCE.instructions()
227 .applyActions(
228 entry.getActions()));
alshabib19fdc122014-10-03 11:38:19 -0700229 case OF_11:
230 case OF_12:
231 case OF_13:
alshabib346b5b32015-03-06 00:42:16 -0800232 return entry.getInstructions();
233 default:
234 log.warn("Unknown OF version {}", entry.getVersion());
235 }
236 return Lists.newLinkedList();
237 }
238
239 private List<OFInstruction> getInstructions(OFFlowStatsEntry entry) {
240 switch (entry.getVersion()) {
241 case OF_10:
242 return Lists.newArrayList(
243 OFFactoryVer13.INSTANCE.instructions().applyActions(entry.getActions()));
244 case OF_11:
245 case OF_12:
246 case OF_13:
247 return entry.getInstructions();
alshabib19fdc122014-10-03 11:38:19 -0700248 default:
249 log.warn("Unknown OF version {}", entry.getVersion());
250 }
251 return Lists.newLinkedList();
252 }
alshabib6b5cfec2014-09-18 17:42:18 -0700253
254 private TrafficTreatment buildTreatment() {
tom9a693fd2014-10-03 11:32:19 -0700255 TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
alshabib346b5b32015-03-06 00:42:16 -0800256 for (OFInstruction in : instructions) {
257 switch (in.getType()) {
258 case GOTO_TABLE:
alshabibbdcbb102015-04-22 14:16:38 -0700259 builder.transition(((int) ((OFInstructionGotoTable) in)
260 .getTableId().getValue()));
alshabib346b5b32015-03-06 00:42:16 -0800261 break;
262 case WRITE_METADATA:
Saurav Das86af8f12015-05-25 23:55:33 -0700263 OFInstructionWriteMetadata m = (OFInstructionWriteMetadata) in;
264 builder.writeMetadata(m.getMetadata().getValue(),
265 m.getMetadataMask().getValue());
alshabib346b5b32015-03-06 00:42:16 -0800266 break;
267 case WRITE_ACTIONS:
268 builder.deferred();
269 buildActions(((OFInstructionWriteActions) in).getActions(),
270 builder);
271 break;
272 case APPLY_ACTIONS:
273 builder.immediate();
274 buildActions(((OFInstructionApplyActions) in).getActions(),
275 builder);
276 break;
277 case CLEAR_ACTIONS:
278 builder.wipeDeferred();
279 break;
280 case EXPERIMENTER:
281 break;
282 case METER:
283 break;
284 default:
285 log.warn("Unknown instructions type {}", in.getType());
alshabib6b5cfec2014-09-18 17:42:18 -0700286 }
287 }
288
289 return builder.build();
290 }
291
Jian Lia0d9a172016-04-01 16:58:06 -0700292 /**
293 * Configures traffic treatment builder with a given collection of actions.
294 *
295 * @param actions a set of OpenFlow actions
296 * @param builder traffic treatment builder
297 * @param driverHandler driver handler
298 * @param deviceId device identifier
299 * @return configured traffic treatment builder
300 */
301 public static TrafficTreatment.Builder configureTreatmentBuilder(List<OFAction> actions,
302 TrafficTreatment.Builder builder,
303 DriverHandler driverHandler,
304 DeviceId deviceId) {
305 ExtensionTreatmentInterpreter interpreter;
Charles Chan14967c22015-12-07 11:11:50 -0800306 if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
Jian Lia0d9a172016-04-01 16:58:06 -0700307 interpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class);
Charles Chan14967c22015-12-07 11:11:50 -0800308 } else {
Jian Lia0d9a172016-04-01 16:58:06 -0700309 interpreter = null;
Charles Chan14967c22015-12-07 11:11:50 -0800310 }
311
alshabib346b5b32015-03-06 00:42:16 -0800312 for (OFAction act : actions) {
313 switch (act.getType()) {
314 case OUTPUT:
315 OFActionOutput out = (OFActionOutput) act;
316 builder.setOutput(
317 PortNumber.portNumber(out.getPort().getPortNumber()));
318 break;
319 case SET_VLAN_VID:
320 OFActionSetVlanVid vlan = (OFActionSetVlanVid) act;
321 builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan()));
322 break;
323 case SET_VLAN_PCP:
324 OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act;
325 builder.setVlanPcp(pcp.getVlanPcp().getValue());
326 break;
327 case SET_DL_DST:
328 OFActionSetDlDst dldst = (OFActionSetDlDst) act;
329 builder.setEthDst(
330 MacAddress.valueOf(dldst.getDlAddr().getLong()));
331 break;
332 case SET_DL_SRC:
333 OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act;
334 builder.setEthSrc(
335 MacAddress.valueOf(dlsrc.getDlAddr().getLong()));
alshabib346b5b32015-03-06 00:42:16 -0800336 break;
337 case SET_NW_DST:
338 OFActionSetNwDst nwdst = (OFActionSetNwDst) act;
339 IPv4Address di = nwdst.getNwAddr();
340 builder.setIpDst(Ip4Address.valueOf(di.getInt()));
341 break;
342 case SET_NW_SRC:
343 OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act;
344 IPv4Address si = nwsrc.getNwAddr();
345 builder.setIpSrc(Ip4Address.valueOf(si.getInt()));
346 break;
347 case EXPERIMENTER:
348 OFActionExperimenter exp = (OFActionExperimenter) act;
349 if (exp.getExperimenter() == 0x80005A06 ||
350 exp.getExperimenter() == 0x748771) {
351 OFActionCircuit ct = (OFActionCircuit) exp;
Yafit Hadar4cc65f72016-02-10 11:23:06 +0200352 CircuitSignalID circuitSignalID = ((OFOxmOchSigid) ct.getField()).getValue();
353 builder.add(Instructions.modL0Lambda(Lambda.ochSignal(
354 lookupGridType(circuitSignalID.getGridType()),
355 lookupChannelSpacing(circuitSignalID.getChannelSpacing()),
356 circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth())));
Jian Lia0d9a172016-04-01 16:58:06 -0700357 } else if (interpreter != null) {
358 builder.extension(interpreter.mapAction(exp), deviceId);
alshabib346b5b32015-03-06 00:42:16 -0800359 } else {
360 log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter());
361 }
362 break;
363 case SET_FIELD:
364 OFActionSetField setField = (OFActionSetField) act;
Jian Lia0d9a172016-04-01 16:58:06 -0700365 handleSetField(builder, setField, driverHandler, deviceId);
alshabib346b5b32015-03-06 00:42:16 -0800366 break;
367 case POP_MPLS:
368 OFActionPopMpls popMpls = (OFActionPopMpls) act;
Ray Milkey84d5a292016-02-22 14:04:01 -0800369 builder.popMpls(new EthType(popMpls.getEthertype().getValue()));
alshabib346b5b32015-03-06 00:42:16 -0800370 break;
371 case PUSH_MPLS:
372 builder.pushMpls();
373 break;
374 case COPY_TTL_IN:
375 builder.copyTtlIn();
376 break;
377 case COPY_TTL_OUT:
378 builder.copyTtlOut();
379 break;
380 case DEC_MPLS_TTL:
381 builder.decMplsTtl();
382 break;
383 case DEC_NW_TTL:
384 builder.decNwTtl();
385 break;
386 case GROUP:
387 OFActionGroup group = (OFActionGroup) act;
388 builder.group(new DefaultGroupId(group.getGroup().getGroupNumber()));
389 break;
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200390 case SET_QUEUE:
391 OFActionSetQueue setQueue = (OFActionSetQueue) act;
392 builder.setQueue(setQueue.getQueueId());
393 break;
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200394 case ENQUEUE:
395 OFActionEnqueue enqueue = (OFActionEnqueue) act;
396 builder.setQueue(enqueue.getQueueId(), PortNumber.portNumber(enqueue.getPort().getPortNumber()));
397 break;
Jonathan Hart67fc0972015-03-19 15:21:20 -0700398 case STRIP_VLAN:
alshabib346b5b32015-03-06 00:42:16 -0800399 case POP_VLAN:
400 builder.popVlan();
401 break;
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700402 case PUSH_VLAN:
403 builder.pushVlan();
404 break;
alshabib346b5b32015-03-06 00:42:16 -0800405 case SET_TP_DST:
406 case SET_TP_SRC:
407 case POP_PBB:
408 case PUSH_PBB:
alshabib346b5b32015-03-06 00:42:16 -0800409 case SET_MPLS_LABEL:
410 case SET_MPLS_TC:
411 case SET_MPLS_TTL:
412 case SET_NW_ECN:
413 case SET_NW_TOS:
414 case SET_NW_TTL:
alshabib346b5b32015-03-06 00:42:16 -0800415
alshabib346b5b32015-03-06 00:42:16 -0800416 default:
417 log.warn("Action type {} not yet implemented.", act.getType());
418 }
419 }
420 return builder;
421 }
422
Jian Lia0d9a172016-04-01 16:58:06 -0700423 private TrafficTreatment.Builder buildActions(List<OFAction> actions,
424 TrafficTreatment.Builder builder) {
Jonathan Harte4e74f02016-03-03 12:57:40 -0800425 DriverHandler driverHandler = getDriver(deviceId);
Jian Lia0d9a172016-04-01 16:58:06 -0700426
427 return configureTreatmentBuilder(actions, builder, driverHandler, deviceId);
428 }
429
430
431 private static void handleSetField(TrafficTreatment.Builder builder,
432 OFActionSetField action,
433 DriverHandler driverHandler,
434 DeviceId deviceId) {
Charles Chan14967c22015-12-07 11:11:50 -0800435 ExtensionTreatmentInterpreter treatmentInterpreter;
436 if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
437 treatmentInterpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class);
438 } else {
439 treatmentInterpreter = null;
440 }
441
Jonathan Hart3c259162015-10-21 21:31:19 -0700442 OFOxm<?> oxm = action.getField();
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800443 switch (oxm.getMatchField().id) {
444 case VLAN_PCP:
445 @SuppressWarnings("unchecked")
446 OFOxm<VlanPcp> vlanpcp = (OFOxm<VlanPcp>) oxm;
447 builder.setVlanPcp(vlanpcp.getValue().getValue());
448 break;
449 case VLAN_VID:
Charles Chan14967c22015-12-07 11:11:50 -0800450 if (treatmentInterpreter != null &&
451 treatmentInterpreter.supported(ExtensionTreatmentTypes.OFDPA_SET_VLAN_ID.type())) {
452 builder.extension(treatmentInterpreter.mapAction(action),
Jonathan Harte4e74f02016-03-03 12:57:40 -0800453 deviceId);
Charles Chan14967c22015-12-07 11:11:50 -0800454 } else {
455 @SuppressWarnings("unchecked")
456 OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm;
457 builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan()));
458 }
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:
Charles Chan14967c22015-12-07 11:11:50 -0800518 if (treatmentInterpreter != null &&
519 treatmentInterpreter.supported(ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) {
Jonathan Harte4e74f02016-03-03 12:57:40 -0800520 builder.extension(treatmentInterpreter.mapAction(action), deviceId);
Jonathan Hart3c259162015-10-21 21:31:19 -0700521 }
522 break;
Yafit Hadar73514612015-11-04 10:14:21 +0200523 case EXP_ODU_SIG_ID:
524 @SuppressWarnings("unchecked")
525 OFOxm<OduSignalID> oduID = (OFOxm<OduSignalID>) oxm;
526 OduSignalID oduSignalID = oduID.getValue();
527 OduSignalId oduSignalId = OduSignalId.oduSignalId(oduSignalID.getTpn(),
528 oduSignalID.getTslen(),
529 oduSignalID.getTsmap());
530 builder.add(modL1OduSignalId(oduSignalId));
531 break;
532 case EXP_OCH_SIG_ID:
533 try {
534 @SuppressWarnings("unchecked")
535 OFOxm<CircuitSignalID> ochId = (OFOxm<CircuitSignalID>) oxm;
536 CircuitSignalID circuitSignalID = ochId.getValue();
537 builder.add(modL0Lambda(Lambda.ochSignal(
538 lookupGridType(circuitSignalID.getGridType()),
539 lookupChannelSpacing(circuitSignalID.getChannelSpacing()),
540 circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth())));
541 } catch (NoMappingFoundException e) {
542 log.warn(e.getMessage());
543 break;
544 }
545 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800546 case ARP_OP:
547 case ARP_SHA:
548 case ARP_SPA:
549 case ARP_THA:
550 case ARP_TPA:
551 case BSN_EGR_PORT_GROUP_ID:
552 case BSN_GLOBAL_VRF_ALLOWED:
553 case BSN_IN_PORTS_128:
554 case BSN_L3_DST_CLASS_ID:
555 case BSN_L3_INTERFACE_CLASS_ID:
556 case BSN_L3_SRC_CLASS_ID:
557 case BSN_LAG_ID:
558 case BSN_TCP_FLAGS:
559 case BSN_UDF0:
560 case BSN_UDF1:
561 case BSN_UDF2:
562 case BSN_UDF3:
563 case BSN_UDF4:
564 case BSN_UDF5:
565 case BSN_UDF6:
566 case BSN_UDF7:
567 case BSN_VLAN_XLATE_PORT_GROUP_ID:
568 case BSN_VRF:
569 case ETH_TYPE:
570 case ICMPV4_CODE:
571 case ICMPV4_TYPE:
572 case ICMPV6_CODE:
573 case ICMPV6_TYPE:
574 case IN_PHY_PORT:
575 case IN_PORT:
576 case IPV6_DST:
577 case IPV6_FLABEL:
578 case IPV6_ND_SLL:
579 case IPV6_ND_TARGET:
580 case IPV6_ND_TLL:
581 case IPV6_SRC:
582 case IP_DSCP:
583 case IP_ECN:
584 case IP_PROTO:
585 case METADATA:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800586 case MPLS_TC:
587 case OCH_SIGID:
588 case OCH_SIGID_BASIC:
589 case OCH_SIGTYPE:
590 case OCH_SIGTYPE_BASIC:
591 case SCTP_DST:
592 case SCTP_SRC:
Yafit Hadar73514612015-11-04 10:14:21 +0200593 case EXP_ODU_SIGTYPE:
594 case EXP_OCH_SIGTYPE:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800595 default:
596 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
597 break;
598 }
599 }
600
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700601 // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES
alshabib6b5cfec2014-09-18 17:42:18 -0700602 private TrafficSelector buildSelector() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800603 MacAddress mac;
604 Ip4Prefix ip4Prefix;
605 Ip6Address ip6Address;
606 Ip6Prefix ip6Prefix;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800607 Ip4Address ip;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800608
Jonathan Harte4e74f02016-03-03 12:57:40 -0800609 DriverHandler driverHandler = getDriver(deviceId);
Charles Chan14967c22015-12-07 11:11:50 -0800610 ExtensionSelectorInterpreter selectorInterpreter;
611 if (driverHandler.hasBehaviour(ExtensionSelectorInterpreter.class)) {
612 selectorInterpreter = driverHandler.behaviour(ExtensionSelectorInterpreter.class);
613 } else {
614 selectorInterpreter = null;
615 }
616
tom9a693fd2014-10-03 11:32:19 -0700617 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700618 for (MatchField<?> field : match.getMatchFields()) {
619 switch (field.id) {
620 case IN_PORT:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800621 builder.matchInPort(PortNumber
alshabib010c31d2014-09-26 10:01:12 -0700622 .portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700623 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800624 case IN_PHY_PORT:
625 builder.matchInPhyPort(PortNumber
626 .portNumber(match.get(MatchField.IN_PHY_PORT).getPortNumber()));
627 break;
628 case METADATA:
629 long metadata =
630 match.get(MatchField.METADATA).getValue().getValue();
631 builder.matchMetadata(metadata);
632 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700633 case ETH_DST:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800634 if (match.isPartiallyMasked(MatchField.ETH_DST)) {
635 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
636 match.getMasked(MatchField.ETH_DST);
637 builder.matchEthDstMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
638 MacAddress.valueOf(maskedMac.getMask().getLong()));
639 } else {
640 mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
641 builder.matchEthDst(mac);
642 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800643 break;
644 case ETH_SRC:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800645 if (match.isPartiallyMasked(MatchField.ETH_SRC)) {
646 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
647 match.getMasked(MatchField.ETH_SRC);
648 builder.matchEthSrcMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
649 MacAddress.valueOf(maskedMac.getMask().getLong()));
650 } else {
651 mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
652 builder.matchEthSrc(mac);
653 }
alshabib6b5cfec2014-09-18 17:42:18 -0700654 break;
655 case ETH_TYPE:
656 int ethType = match.get(MatchField.ETH_TYPE).getValue();
Jonathan Hart8cf212a2015-10-29 17:42:03 -0700657 builder.matchEthType((short) ethType);
alshabib6b5cfec2014-09-18 17:42:18 -0700658 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700659 case VLAN_VID:
Charles Chan14967c22015-12-07 11:11:50 -0800660 if (selectorInterpreter != null &&
661 selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
662 if (match.getVersion().equals(OFVersion.OF_13)) {
663 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.VLAN_VID);
664 builder.extension(selectorInterpreter.mapOxm(oxm),
Jonathan Harte4e74f02016-03-03 12:57:40 -0800665 deviceId);
Charles Chan14967c22015-12-07 11:11:50 -0800666 } else {
667 break;
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800668 }
669 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800670 VlanId vlanId = null;
671 if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
672 Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
673 if (masked.getValue().equals(OFVlanVidMatch.PRESENT)
674 && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
675 vlanId = VlanId.ANY;
676 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700677 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800678 if (!match.get(MatchField.VLAN_VID).isPresentBitSet()) {
679 vlanId = VlanId.NONE;
680 } else {
681 vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
682 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700683 }
Charles Chan14967c22015-12-07 11:11:50 -0800684 if (vlanId != null) {
685 builder.matchVlanId(vlanId);
686 }
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800687 }
alshabib6b5cfec2014-09-18 17:42:18 -0700688 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800689 case VLAN_PCP:
690 byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
691 builder.matchVlanPcp(vlanPcp);
692 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800693 case IP_DSCP:
694 byte ipDscp = match.get(MatchField.IP_DSCP).getDscpValue();
695 builder.matchIPDscp(ipDscp);
696 break;
697 case IP_ECN:
698 byte ipEcn = match.get(MatchField.IP_ECN).getEcnValue();
699 builder.matchIPEcn(ipEcn);
700 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800701 case IP_PROTO:
702 short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
703 builder.matchIPProtocol((byte) proto);
704 break;
705 case IPV4_SRC:
706 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
707 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800708 ip4Prefix = Ip4Prefix.valueOf(
709 maskedIp.getValue().getInt(),
710 maskedIp.getMask().asCidrMaskLength());
711 } else {
712 ip4Prefix = Ip4Prefix.valueOf(
713 match.get(MatchField.IPV4_SRC).getInt(),
714 Ip4Prefix.MAX_MASK_LENGTH);
715 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800716 builder.matchIPSrc(ip4Prefix);
717 break;
718 case IPV4_DST:
719 if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
720 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800721 ip4Prefix = Ip4Prefix.valueOf(
722 maskedIp.getValue().getInt(),
723 maskedIp.getMask().asCidrMaskLength());
724 } else {
725 ip4Prefix = Ip4Prefix.valueOf(
726 match.get(MatchField.IPV4_DST).getInt(),
727 Ip4Prefix.MAX_MASK_LENGTH);
728 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800729 builder.matchIPDst(ip4Prefix);
Jonathan Hart34bc6142014-10-17 11:00:43 -0700730 break;
731 case TCP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700732 builder.matchTcpSrc(TpPort.tpPort(match.get(MatchField.TCP_SRC).getPort()));
Jonathan Hart34bc6142014-10-17 11:00:43 -0700733 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800734 case TCP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700735 builder.matchTcpDst(TpPort.tpPort(match.get(MatchField.TCP_DST).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800736 break;
737 case UDP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700738 builder.matchUdpSrc(TpPort.tpPort(match.get(MatchField.UDP_SRC).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800739 break;
740 case UDP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700741 builder.matchUdpDst(TpPort.tpPort(match.get(MatchField.UDP_DST).getPort()));
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700742 break;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100743 case MPLS_LABEL:
744 builder.matchMplsLabel(MplsLabel.mplsLabel((int) match.get(MatchField.MPLS_LABEL)
745 .getValue()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800746 break;
Saurav Dasffc5bbc2015-08-18 23:30:19 -0700747 case MPLS_BOS:
748 builder.matchMplsBos(match.get(MatchField.MPLS_BOS).getValue());
749 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800750 case SCTP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700751 builder.matchSctpSrc(TpPort.tpPort(match.get(MatchField.SCTP_SRC).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800752 break;
753 case SCTP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700754 builder.matchSctpDst(TpPort.tpPort(match.get(MatchField.SCTP_DST).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800755 break;
756 case ICMPV4_TYPE:
757 byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
758 builder.matchIcmpType(icmpType);
759 break;
760 case ICMPV4_CODE:
761 byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode();
762 builder.matchIcmpCode(icmpCode);
763 break;
764 case IPV6_SRC:
765 if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
766 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
767 ip6Prefix = Ip6Prefix.valueOf(
768 maskedIp.getValue().getBytes(),
769 maskedIp.getMask().asCidrMaskLength());
770 } else {
771 ip6Prefix = Ip6Prefix.valueOf(
772 match.get(MatchField.IPV6_SRC).getBytes(),
773 Ip6Prefix.MAX_MASK_LENGTH);
774 }
775 builder.matchIPv6Src(ip6Prefix);
776 break;
777 case IPV6_DST:
778 if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
779 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
780 ip6Prefix = Ip6Prefix.valueOf(
781 maskedIp.getValue().getBytes(),
782 maskedIp.getMask().asCidrMaskLength());
783 } else {
784 ip6Prefix = Ip6Prefix.valueOf(
785 match.get(MatchField.IPV6_DST).getBytes(),
786 Ip6Prefix.MAX_MASK_LENGTH);
787 }
788 builder.matchIPv6Dst(ip6Prefix);
789 break;
790 case IPV6_FLABEL:
791 int flowLabel =
792 match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue();
793 builder.matchIPv6FlowLabel(flowLabel);
794 break;
795 case ICMPV6_TYPE:
796 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
797 builder.matchIcmpv6Type(icmpv6type);
798 break;
799 case ICMPV6_CODE:
800 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
801 builder.matchIcmpv6Code(icmpv6code);
802 break;
803 case IPV6_ND_TARGET:
804 ip6Address =
805 Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes());
806 builder.matchIPv6NDTargetAddress(ip6Address);
807 break;
808 case IPV6_ND_SLL:
809 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong());
810 builder.matchIPv6NDSourceLinkLayerAddress(mac);
811 break;
812 case IPV6_ND_TLL:
813 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong());
814 builder.matchIPv6NDTargetLinkLayerAddress(mac);
815 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800816 case IPV6_EXTHDR:
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800817 builder.matchIPv6ExthdrFlags((short) match.get(MatchField.IPV6_EXTHDR)
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700818 .getValue());
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800819 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700820 case OCH_SIGID:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700821 CircuitSignalID sigId = match.get(MatchField.OCH_SIGID);
822 builder.add(matchLambda(Lambda.ochSignal(
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700823 lookupGridType(sigId.getGridType()), lookupChannelSpacing(sigId.getChannelSpacing()),
Marc De Leenheer0b8b2ef2015-08-03 15:39:00 -0700824 sigId.getChannelNumber(), sigId.getSpectralWidth())
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700825 ));
Marc De Leenheer49087752014-10-23 13:54:09 -0700826 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800827 case OCH_SIGTYPE:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700828 U8 sigType = match.get(MatchField.OCH_SIGTYPE);
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700829 builder.add(matchOchSignalType(lookupOchSignalType((byte) sigType.getValue())));
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800830 break;
Yafit Hadar73514612015-11-04 10:14:21 +0200831 case EXP_OCH_SIG_ID:
832 try {
833 CircuitSignalID expSigId = match.get(MatchField.EXP_OCH_SIG_ID);
834 builder.add(matchLambda(Lambda.ochSignal(
835 lookupGridType(expSigId.getGridType()), lookupChannelSpacing(expSigId.getChannelSpacing()),
836 expSigId.getChannelNumber(), expSigId.getSpectralWidth())));
837 } catch (NoMappingFoundException e) {
838 log.warn(e.getMessage());
839 break;
840 }
841 break;
842 case EXP_OCH_SIGTYPE:
843 try {
844 U8 expOchSigType = match.get(MatchField.EXP_OCH_SIGTYPE);
845 builder.add(matchOchSignalType(lookupOchSignalType((byte) expOchSigType.getValue())));
846 } catch (NoMappingFoundException e) {
847 log.warn(e.getMessage());
848 break;
849 }
850 break;
851 case EXP_ODU_SIG_ID:
852 OduSignalId oduSignalId = OduSignalId.oduSignalId(match.get(MatchField.EXP_ODU_SIG_ID).getTpn(),
853 match.get(MatchField.EXP_ODU_SIG_ID).getTslen(),
854 match.get(MatchField.EXP_ODU_SIG_ID).getTsmap());
855 builder.add(matchOduSignalId(oduSignalId));
856 break;
857 case EXP_ODU_SIGTYPE:
858 try {
859 U8 oduSigType = match.get(MatchField.EXP_ODU_SIGTYPE);
860 builder.add(matchOduSignalType(lookupOduSignalType((byte) oduSigType.getValue())));
861 } catch (NoMappingFoundException e) {
862 log.warn(e.getMessage());
863 break;
864 }
865 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700866 case TUNNEL_ID:
867 long tunnelId = match.get(MatchField.TUNNEL_ID).getValue();
868 builder.matchTunnelId(tunnelId);
869 break;
BitOhenryb40129a2015-11-30 12:41:18 +0800870 case ARP_OP:
871 int arpOp = match.get(MatchField.ARP_OP).getOpcode();
872 builder.matchArpOp(arpOp);
873 break;
BitOhenrya331b182015-11-23 08:39:37 +0800874 case ARP_SHA:
875 mac = MacAddress.valueOf(match.get(MatchField.ARP_SHA).getLong());
876 builder.matchArpSha(mac);
877 break;
BitOhenry296b4542015-11-24 08:41:58 +0800878 case ARP_SPA:
879 ip = Ip4Address.valueOf(match.get(MatchField.ARP_SPA).getInt());
880 builder.matchArpSpa(ip);
881 break;
BitOhenry76430852015-11-20 19:04:49 +0800882 case ARP_THA:
883 mac = MacAddress.valueOf(match.get(MatchField.ARP_THA).getLong());
884 builder.matchArpTha(mac);
885 break;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800886 case ARP_TPA:
887 ip = Ip4Address.valueOf(match.get(MatchField.ARP_TPA).getInt());
888 builder.matchArpTpa(ip);
889 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700890 case MPLS_TC:
alshabib6b5cfec2014-09-18 17:42:18 -0700891 default:
892 log.warn("Match type {} not yet implemented.", field.id);
alshabib6b5cfec2014-09-18 17:42:18 -0700893 }
894 }
895 return builder.build();
896 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700897
Jonathan Harte4e74f02016-03-03 12:57:40 -0800898 private DriverHandler getDriver(DeviceId deviceId) {
Jonathan Hart3c259162015-10-21 21:31:19 -0700899 Driver driver = driverService.getDriver(deviceId);
900 DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, deviceId));
901 return handler;
902 }
alshabib6b5cfec2014-09-18 17:42:18 -0700903}