blob: a3c502a61789690ecd5ea0f90319c27a73219be2 [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Thomas Vachuska95caba32016-04-04 10:42:05 -07002 * Copyright 2016 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
97import static org.onosproject.net.flow.criteria.Criteria.matchLambda;
98import static org.onosproject.net.flow.criteria.Criteria.matchOchSignalType;
Yafit Hadar73514612015-11-04 10:14:21 +020099import static org.onosproject.net.flow.criteria.Criteria.matchOduSignalId;
Jonathan Harte4e74f02016-03-03 12:57:40 -0800100import static org.onosproject.net.flow.criteria.Criteria.matchOduSignalType;
Yafit Hadar73514612015-11-04 10:14:21 +0200101import static org.onosproject.net.flow.instructions.Instructions.modL0Lambda;
102import static org.onosproject.net.flow.instructions.Instructions.modL1OduSignalId;
Thomas Vachuska95caba32016-04-04 10:42:05 -0700103import static org.onosproject.provider.of.flow.util.OpenFlowValueMapper.lookupChannelSpacing;
104import static org.onosproject.provider.of.flow.util.OpenFlowValueMapper.lookupGridType;
105import static org.onosproject.provider.of.flow.util.OpenFlowValueMapper.lookupOchSignalType;
106import static org.onosproject.provider.of.flow.util.OpenFlowValueMapper.lookupOduSignalType;
alshabib19fdc122014-10-03 11:38:19 -0700107
alshabib1c319ff2014-10-04 20:29:09 -0700108public class FlowEntryBuilder {
Jian Lia0d9a172016-04-01 16:58:06 -0700109 private static final Logger log = LoggerFactory.getLogger(FlowEntryBuilder.class);
alshabib6b5cfec2014-09-18 17:42:18 -0700110
111 private final OFFlowStatsEntry stat;
112 private final OFFlowRemoved removed;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800113 private final OFFlowMod flowMod;
alshabib6b5cfec2014-09-18 17:42:18 -0700114
115 private final Match match;
alshabib346b5b32015-03-06 00:42:16 -0800116
Jonathan Hart67fc0972015-03-19 15:21:20 -0700117 // All actions are contained in an OFInstruction. For OF1.0
118 // the instruction type is apply instruction (immediate set in ONOS speak)
alshabib346b5b32015-03-06 00:42:16 -0800119 private final List<OFInstruction> instructions;
alshabib6b5cfec2014-09-18 17:42:18 -0700120
Jonathan Harte4e74f02016-03-03 12:57:40 -0800121 private final DeviceId deviceId;
alshabib6b5cfec2014-09-18 17:42:18 -0700122
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800123 public enum FlowType { STAT, REMOVED, MOD }
124
125 private final FlowType type;
alshabib6b5cfec2014-09-18 17:42:18 -0700126
Jonathan Hart3c259162015-10-21 21:31:19 -0700127 private final DriverService driverService;
128
Jonathan Harte4e74f02016-03-03 12:57:40 -0800129 public FlowEntryBuilder(DeviceId deviceId, OFFlowStatsEntry entry, DriverService driverService) {
Saurav Dasfa2fa932015-03-03 11:29:48 -0800130 this.stat = entry;
131 this.match = entry.getMatch();
alshabib346b5b32015-03-06 00:42:16 -0800132 this.instructions = getInstructions(entry);
Jonathan Harte4e74f02016-03-03 12:57:40 -0800133 this.deviceId = deviceId;
Saurav Dasfa2fa932015-03-03 11:29:48 -0800134 this.removed = null;
135 this.flowMod = null;
136 this.type = FlowType.STAT;
Jonathan Hart3c259162015-10-21 21:31:19 -0700137 this.driverService = driverService;
Saurav Dasfa2fa932015-03-03 11:29:48 -0800138 }
139
Jonathan Harte4e74f02016-03-03 12:57:40 -0800140 public FlowEntryBuilder(DeviceId deviceId, OFFlowRemoved removed, DriverService driverService) {
alshabib6b5cfec2014-09-18 17:42:18 -0700141 this.match = removed.getMatch();
142 this.removed = removed;
Jonathan Harte4e74f02016-03-03 12:57:40 -0800143 this.deviceId = deviceId;
alshabib346b5b32015-03-06 00:42:16 -0800144 this.instructions = null;
alshabib6b5cfec2014-09-18 17:42:18 -0700145 this.stat = null;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800146 this.flowMod = null;
147 this.type = FlowType.REMOVED;
Jonathan Hart3c259162015-10-21 21:31:19 -0700148 this.driverService = driverService;
alshabib6b5cfec2014-09-18 17:42:18 -0700149 }
150
Jonathan Harte4e74f02016-03-03 12:57:40 -0800151 public FlowEntryBuilder(DeviceId deviceId, OFFlowMod fm, DriverService driverService) {
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800152 this.match = fm.getMatch();
Jonathan Harte4e74f02016-03-03 12:57:40 -0800153 this.deviceId = deviceId;
alshabib346b5b32015-03-06 00:42:16 -0800154 this.instructions = getInstructions(fm);
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800155 this.type = FlowType.MOD;
156 this.flowMod = fm;
157 this.stat = null;
158 this.removed = null;
Jonathan Hart3c259162015-10-21 21:31:19 -0700159 this.driverService = driverService;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800160 }
alshabib1c319ff2014-10-04 20:29:09 -0700161
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800162 public FlowEntry build(FlowEntryState... state) {
Brian O'Connor21564612015-12-05 19:24:59 -0800163 FlowRule.Builder builder;
164 try {
165 switch (this.type) {
166 case STAT:
167 builder = DefaultFlowRule.builder()
Jonathan Harte4e74f02016-03-03 12:57:40 -0800168 .forDevice(deviceId)
Brian O'Connor21564612015-12-05 19:24:59 -0800169 .withSelector(buildSelector())
170 .withTreatment(buildTreatment())
171 .withPriority(stat.getPriority())
172 .makeTemporary(stat.getIdleTimeout())
Jonathan Hartd1ce4b02016-01-11 13:28:36 -0800173 .withCookie(stat.getCookie().getValue());
174 if (stat.getVersion() != OFVersion.OF_10) {
175 builder.forTable(stat.getTableId().getValue());
176 }
alshabibbdcbb102015-04-22 14:16:38 -0700177
Brian O'Connor21564612015-12-05 19:24:59 -0800178 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
179 stat.getDurationSec(),
180 stat.getPacketCount().getValue(),
181 stat.getByteCount().getValue());
182 case REMOVED:
183 builder = DefaultFlowRule.builder()
Jonathan Harte4e74f02016-03-03 12:57:40 -0800184 .forDevice(deviceId)
Brian O'Connor21564612015-12-05 19:24:59 -0800185 .withSelector(buildSelector())
186 .withPriority(removed.getPriority())
187 .makeTemporary(removed.getIdleTimeout())
188 .withCookie(removed.getCookie().getValue());
189 if (removed.getVersion() != OFVersion.OF_10) {
190 builder.forTable(removed.getTableId().getValue());
191 }
alshabibbdcbb102015-04-22 14:16:38 -0700192
Brian O'Connor21564612015-12-05 19:24:59 -0800193 return new DefaultFlowEntry(builder.build(), FlowEntryState.REMOVED,
194 removed.getDurationSec(),
195 removed.getPacketCount().getValue(),
196 removed.getByteCount().getValue());
197 case MOD:
198 FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED;
199 builder = DefaultFlowRule.builder()
Jonathan Harte4e74f02016-03-03 12:57:40 -0800200 .forDevice(deviceId)
Brian O'Connor21564612015-12-05 19:24:59 -0800201 .withSelector(buildSelector())
202 .withTreatment(buildTreatment())
203 .withPriority(flowMod.getPriority())
204 .makeTemporary(flowMod.getIdleTimeout())
205 .withCookie(flowMod.getCookie().getValue());
206 if (flowMod.getVersion() != OFVersion.OF_10) {
207 builder.forTable(flowMod.getTableId().getValue());
208 }
alshabibbdcbb102015-04-22 14:16:38 -0700209
Brian O'Connor21564612015-12-05 19:24:59 -0800210 return new DefaultFlowEntry(builder.build(), flowState, 0, 0, 0);
211 default:
212 log.error("Unknown flow type : {}", this.type);
213 return null;
214 }
215 } catch (UnsupportedOperationException e) {
216 log.warn("Error building flow entry", e);
217 return null;
alshabib6b5cfec2014-09-18 17:42:18 -0700218 }
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800219
alshabib6b5cfec2014-09-18 17:42:18 -0700220 }
221
alshabib346b5b32015-03-06 00:42:16 -0800222 private List<OFInstruction> getInstructions(OFFlowMod entry) {
alshabib19fdc122014-10-03 11:38:19 -0700223 switch (entry.getVersion()) {
224 case OF_10:
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700225 return Lists.newArrayList(OFFactoryVer13.INSTANCE.instructions()
226 .applyActions(
227 entry.getActions()));
alshabib19fdc122014-10-03 11:38:19 -0700228 case OF_11:
229 case OF_12:
230 case OF_13:
alshabib346b5b32015-03-06 00:42:16 -0800231 return entry.getInstructions();
232 default:
233 log.warn("Unknown OF version {}", entry.getVersion());
234 }
235 return Lists.newLinkedList();
236 }
237
238 private List<OFInstruction> getInstructions(OFFlowStatsEntry entry) {
239 switch (entry.getVersion()) {
240 case OF_10:
241 return Lists.newArrayList(
242 OFFactoryVer13.INSTANCE.instructions().applyActions(entry.getActions()));
243 case OF_11:
244 case OF_12:
245 case OF_13:
246 return entry.getInstructions();
alshabib19fdc122014-10-03 11:38:19 -0700247 default:
248 log.warn("Unknown OF version {}", entry.getVersion());
249 }
250 return Lists.newLinkedList();
251 }
alshabib6b5cfec2014-09-18 17:42:18 -0700252
253 private TrafficTreatment buildTreatment() {
tom9a693fd2014-10-03 11:32:19 -0700254 TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
alshabib346b5b32015-03-06 00:42:16 -0800255 for (OFInstruction in : instructions) {
256 switch (in.getType()) {
257 case GOTO_TABLE:
alshabibbdcbb102015-04-22 14:16:38 -0700258 builder.transition(((int) ((OFInstructionGotoTable) in)
259 .getTableId().getValue()));
alshabib346b5b32015-03-06 00:42:16 -0800260 break;
261 case WRITE_METADATA:
Saurav Das86af8f12015-05-25 23:55:33 -0700262 OFInstructionWriteMetadata m = (OFInstructionWriteMetadata) in;
263 builder.writeMetadata(m.getMetadata().getValue(),
264 m.getMetadataMask().getValue());
alshabib346b5b32015-03-06 00:42:16 -0800265 break;
266 case WRITE_ACTIONS:
267 builder.deferred();
268 buildActions(((OFInstructionWriteActions) in).getActions(),
269 builder);
270 break;
271 case APPLY_ACTIONS:
272 builder.immediate();
273 buildActions(((OFInstructionApplyActions) in).getActions(),
274 builder);
275 break;
276 case CLEAR_ACTIONS:
277 builder.wipeDeferred();
278 break;
279 case EXPERIMENTER:
280 break;
281 case METER:
282 break;
283 default:
284 log.warn("Unknown instructions type {}", in.getType());
alshabib6b5cfec2014-09-18 17:42:18 -0700285 }
286 }
287
288 return builder.build();
289 }
290
Jian Lia0d9a172016-04-01 16:58:06 -0700291 /**
292 * Configures traffic treatment builder with a given collection of actions.
293 *
294 * @param actions a set of OpenFlow actions
295 * @param builder traffic treatment builder
296 * @param driverHandler driver handler
297 * @param deviceId device identifier
298 * @return configured traffic treatment builder
299 */
300 public static TrafficTreatment.Builder configureTreatmentBuilder(List<OFAction> actions,
301 TrafficTreatment.Builder builder,
302 DriverHandler driverHandler,
303 DeviceId deviceId) {
304 ExtensionTreatmentInterpreter interpreter;
Charles Chan14967c22015-12-07 11:11:50 -0800305 if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
Jian Lia0d9a172016-04-01 16:58:06 -0700306 interpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class);
Charles Chan14967c22015-12-07 11:11:50 -0800307 } else {
Jian Lia0d9a172016-04-01 16:58:06 -0700308 interpreter = null;
Charles Chan14967c22015-12-07 11:11:50 -0800309 }
310
alshabib346b5b32015-03-06 00:42:16 -0800311 for (OFAction act : actions) {
312 switch (act.getType()) {
313 case OUTPUT:
314 OFActionOutput out = (OFActionOutput) act;
315 builder.setOutput(
316 PortNumber.portNumber(out.getPort().getPortNumber()));
317 break;
318 case SET_VLAN_VID:
319 OFActionSetVlanVid vlan = (OFActionSetVlanVid) act;
320 builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan()));
321 break;
322 case SET_VLAN_PCP:
323 OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act;
324 builder.setVlanPcp(pcp.getVlanPcp().getValue());
325 break;
326 case SET_DL_DST:
327 OFActionSetDlDst dldst = (OFActionSetDlDst) act;
328 builder.setEthDst(
329 MacAddress.valueOf(dldst.getDlAddr().getLong()));
330 break;
331 case SET_DL_SRC:
332 OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act;
333 builder.setEthSrc(
334 MacAddress.valueOf(dlsrc.getDlAddr().getLong()));
alshabib346b5b32015-03-06 00:42:16 -0800335 break;
336 case SET_NW_DST:
337 OFActionSetNwDst nwdst = (OFActionSetNwDst) act;
338 IPv4Address di = nwdst.getNwAddr();
339 builder.setIpDst(Ip4Address.valueOf(di.getInt()));
340 break;
341 case SET_NW_SRC:
342 OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act;
343 IPv4Address si = nwsrc.getNwAddr();
344 builder.setIpSrc(Ip4Address.valueOf(si.getInt()));
345 break;
346 case EXPERIMENTER:
347 OFActionExperimenter exp = (OFActionExperimenter) act;
348 if (exp.getExperimenter() == 0x80005A06 ||
349 exp.getExperimenter() == 0x748771) {
350 OFActionCircuit ct = (OFActionCircuit) exp;
Yafit Hadar4cc65f72016-02-10 11:23:06 +0200351 CircuitSignalID circuitSignalID = ((OFOxmOchSigid) ct.getField()).getValue();
352 builder.add(Instructions.modL0Lambda(Lambda.ochSignal(
353 lookupGridType(circuitSignalID.getGridType()),
354 lookupChannelSpacing(circuitSignalID.getChannelSpacing()),
355 circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth())));
Jian Lia0d9a172016-04-01 16:58:06 -0700356 } else if (interpreter != null) {
357 builder.extension(interpreter.mapAction(exp), deviceId);
alshabib346b5b32015-03-06 00:42:16 -0800358 } else {
359 log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter());
360 }
361 break;
362 case SET_FIELD:
363 OFActionSetField setField = (OFActionSetField) act;
Jian Lia0d9a172016-04-01 16:58:06 -0700364 handleSetField(builder, setField, driverHandler, deviceId);
alshabib346b5b32015-03-06 00:42:16 -0800365 break;
366 case POP_MPLS:
367 OFActionPopMpls popMpls = (OFActionPopMpls) act;
Ray Milkey84d5a292016-02-22 14:04:01 -0800368 builder.popMpls(new EthType(popMpls.getEthertype().getValue()));
alshabib346b5b32015-03-06 00:42:16 -0800369 break;
370 case PUSH_MPLS:
371 builder.pushMpls();
372 break;
373 case COPY_TTL_IN:
374 builder.copyTtlIn();
375 break;
376 case COPY_TTL_OUT:
377 builder.copyTtlOut();
378 break;
379 case DEC_MPLS_TTL:
380 builder.decMplsTtl();
381 break;
382 case DEC_NW_TTL:
383 builder.decNwTtl();
384 break;
385 case GROUP:
386 OFActionGroup group = (OFActionGroup) act;
387 builder.group(new DefaultGroupId(group.getGroup().getGroupNumber()));
388 break;
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200389 case SET_QUEUE:
390 OFActionSetQueue setQueue = (OFActionSetQueue) act;
391 builder.setQueue(setQueue.getQueueId());
392 break;
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200393 case ENQUEUE:
394 OFActionEnqueue enqueue = (OFActionEnqueue) act;
Jian Liffef5002016-04-04 23:27:37 -0700395 builder.setQueue(enqueue.getQueueId(),
396 PortNumber.portNumber(enqueue.getPort().getPortNumber()));
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200397 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:
Jian Liffef5002016-04-04 23:27:37 -0700450 if (treatmentInterpreter != null) {
451 try {
452 builder.extension(treatmentInterpreter.mapAction(action), deviceId);
453 } catch (UnsupportedOperationException e) {
454 log.warn(e.getMessage());
455 }
Charles Chan14967c22015-12-07 11:11:50 -0800456 } else {
457 @SuppressWarnings("unchecked")
458 OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm;
459 builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan()));
460 }
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800461 break;
462 case ETH_DST:
463 @SuppressWarnings("unchecked")
464 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethdst =
465 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
466 builder.setEthDst(MacAddress.valueOf(ethdst.getValue().getLong()));
467 break;
468 case ETH_SRC:
469 @SuppressWarnings("unchecked")
470 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethsrc =
471 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
472 builder.setEthSrc(MacAddress.valueOf(ethsrc.getValue().getLong()));
473 break;
474 case IPV4_DST:
475 @SuppressWarnings("unchecked")
476 OFOxm<IPv4Address> ip4dst = (OFOxm<IPv4Address>) oxm;
477 builder.setIpDst(Ip4Address.valueOf(ip4dst.getValue().getInt()));
478 break;
479 case IPV4_SRC:
480 @SuppressWarnings("unchecked")
481 OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm;
482 builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt()));
483 break;
sangho3f97a17d2015-01-29 22:56:29 -0800484 case MPLS_LABEL:
485 @SuppressWarnings("unchecked")
486 OFOxm<U32> labelId = (OFOxm<U32>) oxm;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100487 builder.setMpls(MplsLabel.mplsLabel((int) labelId.getValue().getValue()));
sangho3f97a17d2015-01-29 22:56:29 -0800488 break;
Saurav Das73a7dd42015-08-19 22:20:31 -0700489 case MPLS_BOS:
490 @SuppressWarnings("unchecked")
491 OFOxm<U8> mplsBos = (OFOxm<U8>) oxm;
492 builder.setMplsBos(mplsBos.getValue() == U8.ZERO ? false : true);
493 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700494 case TUNNEL_ID:
495 @SuppressWarnings("unchecked")
496 OFOxm<U64> tunnelId = (OFOxm<U64>) oxm;
497 builder.setTunnelId(tunnelId.getValue().getValue());
498 break;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700499 case TCP_DST:
500 @SuppressWarnings("unchecked")
501 OFOxm<TransportPort> tcpdst = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700502 builder.setTcpDst(TpPort.tpPort(tcpdst.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700503 break;
504 case TCP_SRC:
505 @SuppressWarnings("unchecked")
506 OFOxm<TransportPort> tcpsrc = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700507 builder.setTcpSrc(TpPort.tpPort(tcpsrc.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700508 break;
509 case UDP_DST:
510 @SuppressWarnings("unchecked")
511 OFOxm<TransportPort> udpdst = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700512 builder.setUdpDst(TpPort.tpPort(udpdst.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700513 break;
514 case UDP_SRC:
515 @SuppressWarnings("unchecked")
516 OFOxm<TransportPort> udpsrc = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700517 builder.setUdpSrc(TpPort.tpPort(udpsrc.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700518 break;
Jonathan Hart3c259162015-10-21 21:31:19 -0700519 case TUNNEL_IPV4_DST:
Jian Liffef5002016-04-04 23:27:37 -0700520 if (treatmentInterpreter != null) {
521 try {
522 builder.extension(treatmentInterpreter.mapAction(action), deviceId);
523 } catch (UnsupportedOperationException e) {
524 log.warn(e.getMessage());
525 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700526 }
527 break;
Yafit Hadar73514612015-11-04 10:14:21 +0200528 case EXP_ODU_SIG_ID:
529 @SuppressWarnings("unchecked")
530 OFOxm<OduSignalID> oduID = (OFOxm<OduSignalID>) oxm;
531 OduSignalID oduSignalID = oduID.getValue();
532 OduSignalId oduSignalId = OduSignalId.oduSignalId(oduSignalID.getTpn(),
533 oduSignalID.getTslen(),
534 oduSignalID.getTsmap());
535 builder.add(modL1OduSignalId(oduSignalId));
536 break;
537 case EXP_OCH_SIG_ID:
538 try {
539 @SuppressWarnings("unchecked")
540 OFOxm<CircuitSignalID> ochId = (OFOxm<CircuitSignalID>) oxm;
541 CircuitSignalID circuitSignalID = ochId.getValue();
542 builder.add(modL0Lambda(Lambda.ochSignal(
543 lookupGridType(circuitSignalID.getGridType()),
544 lookupChannelSpacing(circuitSignalID.getChannelSpacing()),
545 circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth())));
546 } catch (NoMappingFoundException e) {
547 log.warn(e.getMessage());
548 break;
549 }
550 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800551 case ARP_OP:
552 case ARP_SHA:
553 case ARP_SPA:
554 case ARP_THA:
555 case ARP_TPA:
556 case BSN_EGR_PORT_GROUP_ID:
557 case BSN_GLOBAL_VRF_ALLOWED:
558 case BSN_IN_PORTS_128:
559 case BSN_L3_DST_CLASS_ID:
560 case BSN_L3_INTERFACE_CLASS_ID:
561 case BSN_L3_SRC_CLASS_ID:
562 case BSN_LAG_ID:
563 case BSN_TCP_FLAGS:
564 case BSN_UDF0:
565 case BSN_UDF1:
566 case BSN_UDF2:
567 case BSN_UDF3:
568 case BSN_UDF4:
569 case BSN_UDF5:
570 case BSN_UDF6:
571 case BSN_UDF7:
572 case BSN_VLAN_XLATE_PORT_GROUP_ID:
573 case BSN_VRF:
574 case ETH_TYPE:
575 case ICMPV4_CODE:
576 case ICMPV4_TYPE:
577 case ICMPV6_CODE:
578 case ICMPV6_TYPE:
579 case IN_PHY_PORT:
580 case IN_PORT:
581 case IPV6_DST:
582 case IPV6_FLABEL:
583 case IPV6_ND_SLL:
584 case IPV6_ND_TARGET:
585 case IPV6_ND_TLL:
586 case IPV6_SRC:
587 case IP_DSCP:
588 case IP_ECN:
589 case IP_PROTO:
590 case METADATA:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800591 case MPLS_TC:
592 case OCH_SIGID:
593 case OCH_SIGID_BASIC:
594 case OCH_SIGTYPE:
595 case OCH_SIGTYPE_BASIC:
596 case SCTP_DST:
597 case SCTP_SRC:
Yafit Hadar73514612015-11-04 10:14:21 +0200598 case EXP_ODU_SIGTYPE:
599 case EXP_OCH_SIGTYPE:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800600 default:
601 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
602 break;
603 }
604 }
605
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700606 // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES
alshabib6b5cfec2014-09-18 17:42:18 -0700607 private TrafficSelector buildSelector() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800608 MacAddress mac;
609 Ip4Prefix ip4Prefix;
610 Ip6Address ip6Address;
611 Ip6Prefix ip6Prefix;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800612 Ip4Address ip;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800613
Jonathan Harte4e74f02016-03-03 12:57:40 -0800614 DriverHandler driverHandler = getDriver(deviceId);
Charles Chan14967c22015-12-07 11:11:50 -0800615 ExtensionSelectorInterpreter selectorInterpreter;
616 if (driverHandler.hasBehaviour(ExtensionSelectorInterpreter.class)) {
617 selectorInterpreter = driverHandler.behaviour(ExtensionSelectorInterpreter.class);
618 } else {
619 selectorInterpreter = null;
620 }
621
tom9a693fd2014-10-03 11:32:19 -0700622 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700623 for (MatchField<?> field : match.getMatchFields()) {
624 switch (field.id) {
625 case IN_PORT:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800626 builder.matchInPort(PortNumber
alshabib010c31d2014-09-26 10:01:12 -0700627 .portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700628 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800629 case IN_PHY_PORT:
630 builder.matchInPhyPort(PortNumber
631 .portNumber(match.get(MatchField.IN_PHY_PORT).getPortNumber()));
632 break;
633 case METADATA:
634 long metadata =
635 match.get(MatchField.METADATA).getValue().getValue();
636 builder.matchMetadata(metadata);
637 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700638 case ETH_DST:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800639 if (match.isPartiallyMasked(MatchField.ETH_DST)) {
640 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
641 match.getMasked(MatchField.ETH_DST);
642 builder.matchEthDstMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
643 MacAddress.valueOf(maskedMac.getMask().getLong()));
644 } else {
645 mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
646 builder.matchEthDst(mac);
647 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800648 break;
649 case ETH_SRC:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800650 if (match.isPartiallyMasked(MatchField.ETH_SRC)) {
651 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
652 match.getMasked(MatchField.ETH_SRC);
653 builder.matchEthSrcMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
654 MacAddress.valueOf(maskedMac.getMask().getLong()));
655 } else {
656 mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
657 builder.matchEthSrc(mac);
658 }
alshabib6b5cfec2014-09-18 17:42:18 -0700659 break;
660 case ETH_TYPE:
661 int ethType = match.get(MatchField.ETH_TYPE).getValue();
Jonathan Hart8cf212a2015-10-29 17:42:03 -0700662 builder.matchEthType((short) ethType);
alshabib6b5cfec2014-09-18 17:42:18 -0700663 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700664 case VLAN_VID:
Charles Chan14967c22015-12-07 11:11:50 -0800665 if (selectorInterpreter != null &&
666 selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
667 if (match.getVersion().equals(OFVersion.OF_13)) {
668 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.VLAN_VID);
669 builder.extension(selectorInterpreter.mapOxm(oxm),
Jonathan Harte4e74f02016-03-03 12:57:40 -0800670 deviceId);
Charles Chan14967c22015-12-07 11:11:50 -0800671 } else {
672 break;
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800673 }
674 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800675 VlanId vlanId = null;
676 if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
677 Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
678 if (masked.getValue().equals(OFVlanVidMatch.PRESENT)
679 && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
680 vlanId = VlanId.ANY;
681 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700682 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800683 if (!match.get(MatchField.VLAN_VID).isPresentBitSet()) {
684 vlanId = VlanId.NONE;
685 } else {
686 vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
687 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700688 }
Charles Chan14967c22015-12-07 11:11:50 -0800689 if (vlanId != null) {
690 builder.matchVlanId(vlanId);
691 }
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800692 }
alshabib6b5cfec2014-09-18 17:42:18 -0700693 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800694 case VLAN_PCP:
695 byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
696 builder.matchVlanPcp(vlanPcp);
697 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800698 case IP_DSCP:
699 byte ipDscp = match.get(MatchField.IP_DSCP).getDscpValue();
700 builder.matchIPDscp(ipDscp);
701 break;
702 case IP_ECN:
703 byte ipEcn = match.get(MatchField.IP_ECN).getEcnValue();
704 builder.matchIPEcn(ipEcn);
705 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800706 case IP_PROTO:
707 short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
708 builder.matchIPProtocol((byte) proto);
709 break;
710 case IPV4_SRC:
711 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
712 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800713 ip4Prefix = Ip4Prefix.valueOf(
714 maskedIp.getValue().getInt(),
715 maskedIp.getMask().asCidrMaskLength());
716 } else {
717 ip4Prefix = Ip4Prefix.valueOf(
718 match.get(MatchField.IPV4_SRC).getInt(),
719 Ip4Prefix.MAX_MASK_LENGTH);
720 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800721 builder.matchIPSrc(ip4Prefix);
722 break;
723 case IPV4_DST:
724 if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
725 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800726 ip4Prefix = Ip4Prefix.valueOf(
727 maskedIp.getValue().getInt(),
728 maskedIp.getMask().asCidrMaskLength());
729 } else {
730 ip4Prefix = Ip4Prefix.valueOf(
731 match.get(MatchField.IPV4_DST).getInt(),
732 Ip4Prefix.MAX_MASK_LENGTH);
733 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800734 builder.matchIPDst(ip4Prefix);
Jonathan Hart34bc6142014-10-17 11:00:43 -0700735 break;
736 case TCP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700737 builder.matchTcpSrc(TpPort.tpPort(match.get(MatchField.TCP_SRC).getPort()));
Jonathan Hart34bc6142014-10-17 11:00:43 -0700738 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800739 case TCP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700740 builder.matchTcpDst(TpPort.tpPort(match.get(MatchField.TCP_DST).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800741 break;
742 case UDP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700743 builder.matchUdpSrc(TpPort.tpPort(match.get(MatchField.UDP_SRC).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800744 break;
745 case UDP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700746 builder.matchUdpDst(TpPort.tpPort(match.get(MatchField.UDP_DST).getPort()));
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700747 break;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100748 case MPLS_LABEL:
749 builder.matchMplsLabel(MplsLabel.mplsLabel((int) match.get(MatchField.MPLS_LABEL)
750 .getValue()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800751 break;
Saurav Dasffc5bbc2015-08-18 23:30:19 -0700752 case MPLS_BOS:
753 builder.matchMplsBos(match.get(MatchField.MPLS_BOS).getValue());
754 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800755 case SCTP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700756 builder.matchSctpSrc(TpPort.tpPort(match.get(MatchField.SCTP_SRC).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800757 break;
758 case SCTP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700759 builder.matchSctpDst(TpPort.tpPort(match.get(MatchField.SCTP_DST).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800760 break;
761 case ICMPV4_TYPE:
762 byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
763 builder.matchIcmpType(icmpType);
764 break;
765 case ICMPV4_CODE:
766 byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode();
767 builder.matchIcmpCode(icmpCode);
768 break;
769 case IPV6_SRC:
770 if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
771 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
772 ip6Prefix = Ip6Prefix.valueOf(
773 maskedIp.getValue().getBytes(),
774 maskedIp.getMask().asCidrMaskLength());
775 } else {
776 ip6Prefix = Ip6Prefix.valueOf(
777 match.get(MatchField.IPV6_SRC).getBytes(),
778 Ip6Prefix.MAX_MASK_LENGTH);
779 }
780 builder.matchIPv6Src(ip6Prefix);
781 break;
782 case IPV6_DST:
783 if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
784 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
785 ip6Prefix = Ip6Prefix.valueOf(
786 maskedIp.getValue().getBytes(),
787 maskedIp.getMask().asCidrMaskLength());
788 } else {
789 ip6Prefix = Ip6Prefix.valueOf(
790 match.get(MatchField.IPV6_DST).getBytes(),
791 Ip6Prefix.MAX_MASK_LENGTH);
792 }
793 builder.matchIPv6Dst(ip6Prefix);
794 break;
795 case IPV6_FLABEL:
796 int flowLabel =
797 match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue();
798 builder.matchIPv6FlowLabel(flowLabel);
799 break;
800 case ICMPV6_TYPE:
801 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
802 builder.matchIcmpv6Type(icmpv6type);
803 break;
804 case ICMPV6_CODE:
805 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
806 builder.matchIcmpv6Code(icmpv6code);
807 break;
808 case IPV6_ND_TARGET:
809 ip6Address =
810 Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes());
811 builder.matchIPv6NDTargetAddress(ip6Address);
812 break;
813 case IPV6_ND_SLL:
814 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong());
815 builder.matchIPv6NDSourceLinkLayerAddress(mac);
816 break;
817 case IPV6_ND_TLL:
818 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong());
819 builder.matchIPv6NDTargetLinkLayerAddress(mac);
820 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800821 case IPV6_EXTHDR:
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800822 builder.matchIPv6ExthdrFlags((short) match.get(MatchField.IPV6_EXTHDR)
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700823 .getValue());
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800824 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700825 case OCH_SIGID:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700826 CircuitSignalID sigId = match.get(MatchField.OCH_SIGID);
827 builder.add(matchLambda(Lambda.ochSignal(
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700828 lookupGridType(sigId.getGridType()), lookupChannelSpacing(sigId.getChannelSpacing()),
Marc De Leenheer0b8b2ef2015-08-03 15:39:00 -0700829 sigId.getChannelNumber(), sigId.getSpectralWidth())
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700830 ));
Marc De Leenheer49087752014-10-23 13:54:09 -0700831 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800832 case OCH_SIGTYPE:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700833 U8 sigType = match.get(MatchField.OCH_SIGTYPE);
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700834 builder.add(matchOchSignalType(lookupOchSignalType((byte) sigType.getValue())));
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800835 break;
Yafit Hadar73514612015-11-04 10:14:21 +0200836 case EXP_OCH_SIG_ID:
837 try {
838 CircuitSignalID expSigId = match.get(MatchField.EXP_OCH_SIG_ID);
839 builder.add(matchLambda(Lambda.ochSignal(
840 lookupGridType(expSigId.getGridType()), lookupChannelSpacing(expSigId.getChannelSpacing()),
841 expSigId.getChannelNumber(), expSigId.getSpectralWidth())));
842 } catch (NoMappingFoundException e) {
843 log.warn(e.getMessage());
844 break;
845 }
846 break;
847 case EXP_OCH_SIGTYPE:
848 try {
849 U8 expOchSigType = match.get(MatchField.EXP_OCH_SIGTYPE);
850 builder.add(matchOchSignalType(lookupOchSignalType((byte) expOchSigType.getValue())));
851 } catch (NoMappingFoundException e) {
852 log.warn(e.getMessage());
853 break;
854 }
855 break;
856 case EXP_ODU_SIG_ID:
857 OduSignalId oduSignalId = OduSignalId.oduSignalId(match.get(MatchField.EXP_ODU_SIG_ID).getTpn(),
858 match.get(MatchField.EXP_ODU_SIG_ID).getTslen(),
859 match.get(MatchField.EXP_ODU_SIG_ID).getTsmap());
860 builder.add(matchOduSignalId(oduSignalId));
861 break;
862 case EXP_ODU_SIGTYPE:
863 try {
864 U8 oduSigType = match.get(MatchField.EXP_ODU_SIGTYPE);
865 builder.add(matchOduSignalType(lookupOduSignalType((byte) oduSigType.getValue())));
866 } catch (NoMappingFoundException e) {
867 log.warn(e.getMessage());
868 break;
869 }
870 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700871 case TUNNEL_ID:
872 long tunnelId = match.get(MatchField.TUNNEL_ID).getValue();
873 builder.matchTunnelId(tunnelId);
874 break;
BitOhenryb40129a2015-11-30 12:41:18 +0800875 case ARP_OP:
876 int arpOp = match.get(MatchField.ARP_OP).getOpcode();
877 builder.matchArpOp(arpOp);
878 break;
BitOhenrya331b182015-11-23 08:39:37 +0800879 case ARP_SHA:
880 mac = MacAddress.valueOf(match.get(MatchField.ARP_SHA).getLong());
881 builder.matchArpSha(mac);
882 break;
BitOhenry296b4542015-11-24 08:41:58 +0800883 case ARP_SPA:
884 ip = Ip4Address.valueOf(match.get(MatchField.ARP_SPA).getInt());
885 builder.matchArpSpa(ip);
886 break;
BitOhenry76430852015-11-20 19:04:49 +0800887 case ARP_THA:
888 mac = MacAddress.valueOf(match.get(MatchField.ARP_THA).getLong());
889 builder.matchArpTha(mac);
890 break;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800891 case ARP_TPA:
892 ip = Ip4Address.valueOf(match.get(MatchField.ARP_TPA).getInt());
893 builder.matchArpTpa(ip);
894 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700895 case MPLS_TC:
alshabib6b5cfec2014-09-18 17:42:18 -0700896 default:
897 log.warn("Match type {} not yet implemented.", field.id);
alshabib6b5cfec2014-09-18 17:42:18 -0700898 }
899 }
900 return builder.build();
901 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700902
Jian Liffef5002016-04-04 23:27:37 -0700903 private DriverHandler getDriver(DeviceId devId) {
904 Driver driver = driverService.getDriver(devId);
905 DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, devId));
Jonathan Hart3c259162015-10-21 21:31:19 -0700906 return handler;
907 }
alshabib6b5cfec2014-09-18 17:42:18 -0700908}