blob: 16ad6d81b781ca062ecd2a4c21c9f300e5055c6e [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:
alshabib44852fb2016-04-15 15:56:51 -0700444 try {
445 builder.extension(treatmentInterpreter.mapAction(action), deviceId);
446 break;
447 } catch (UnsupportedOperationException e) {
448 log.debug("Unsupported action extension; defaulting to native OF");
Charles Chan14967c22015-12-07 11:11:50 -0800449 }
alshabib44852fb2016-04-15 15:56:51 -0700450 @SuppressWarnings("unchecked")
451 OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm;
452 builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan()));
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800453 break;
454 case ETH_DST:
455 @SuppressWarnings("unchecked")
456 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethdst =
457 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
458 builder.setEthDst(MacAddress.valueOf(ethdst.getValue().getLong()));
459 break;
460 case ETH_SRC:
461 @SuppressWarnings("unchecked")
462 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethsrc =
463 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
464 builder.setEthSrc(MacAddress.valueOf(ethsrc.getValue().getLong()));
465 break;
466 case IPV4_DST:
467 @SuppressWarnings("unchecked")
468 OFOxm<IPv4Address> ip4dst = (OFOxm<IPv4Address>) oxm;
469 builder.setIpDst(Ip4Address.valueOf(ip4dst.getValue().getInt()));
470 break;
471 case IPV4_SRC:
472 @SuppressWarnings("unchecked")
473 OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm;
474 builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt()));
475 break;
sangho3f97a17d2015-01-29 22:56:29 -0800476 case MPLS_LABEL:
477 @SuppressWarnings("unchecked")
478 OFOxm<U32> labelId = (OFOxm<U32>) oxm;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100479 builder.setMpls(MplsLabel.mplsLabel((int) labelId.getValue().getValue()));
sangho3f97a17d2015-01-29 22:56:29 -0800480 break;
Saurav Das73a7dd42015-08-19 22:20:31 -0700481 case MPLS_BOS:
482 @SuppressWarnings("unchecked")
483 OFOxm<U8> mplsBos = (OFOxm<U8>) oxm;
484 builder.setMplsBos(mplsBos.getValue() == U8.ZERO ? false : true);
485 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700486 case TUNNEL_ID:
487 @SuppressWarnings("unchecked")
488 OFOxm<U64> tunnelId = (OFOxm<U64>) oxm;
489 builder.setTunnelId(tunnelId.getValue().getValue());
490 break;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700491 case TCP_DST:
492 @SuppressWarnings("unchecked")
493 OFOxm<TransportPort> tcpdst = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700494 builder.setTcpDst(TpPort.tpPort(tcpdst.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700495 break;
496 case TCP_SRC:
497 @SuppressWarnings("unchecked")
498 OFOxm<TransportPort> tcpsrc = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700499 builder.setTcpSrc(TpPort.tpPort(tcpsrc.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700500 break;
501 case UDP_DST:
502 @SuppressWarnings("unchecked")
503 OFOxm<TransportPort> udpdst = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700504 builder.setUdpDst(TpPort.tpPort(udpdst.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700505 break;
506 case UDP_SRC:
507 @SuppressWarnings("unchecked")
508 OFOxm<TransportPort> udpsrc = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700509 builder.setUdpSrc(TpPort.tpPort(udpsrc.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700510 break;
Jonathan Hart3c259162015-10-21 21:31:19 -0700511 case TUNNEL_IPV4_DST:
Jian Liffef5002016-04-04 23:27:37 -0700512 if (treatmentInterpreter != null) {
513 try {
514 builder.extension(treatmentInterpreter.mapAction(action), deviceId);
515 } catch (UnsupportedOperationException e) {
alshabib44852fb2016-04-15 15:56:51 -0700516 log.debug(e.getMessage());
Jian Liffef5002016-04-04 23:27:37 -0700517 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700518 }
519 break;
Yafit Hadar73514612015-11-04 10:14:21 +0200520 case EXP_ODU_SIG_ID:
521 @SuppressWarnings("unchecked")
522 OFOxm<OduSignalID> oduID = (OFOxm<OduSignalID>) oxm;
523 OduSignalID oduSignalID = oduID.getValue();
524 OduSignalId oduSignalId = OduSignalId.oduSignalId(oduSignalID.getTpn(),
525 oduSignalID.getTslen(),
526 oduSignalID.getTsmap());
527 builder.add(modL1OduSignalId(oduSignalId));
528 break;
529 case EXP_OCH_SIG_ID:
530 try {
531 @SuppressWarnings("unchecked")
532 OFOxm<CircuitSignalID> ochId = (OFOxm<CircuitSignalID>) oxm;
533 CircuitSignalID circuitSignalID = ochId.getValue();
534 builder.add(modL0Lambda(Lambda.ochSignal(
535 lookupGridType(circuitSignalID.getGridType()),
536 lookupChannelSpacing(circuitSignalID.getChannelSpacing()),
537 circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth())));
538 } catch (NoMappingFoundException e) {
539 log.warn(e.getMessage());
540 break;
541 }
542 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800543 case ARP_OP:
544 case ARP_SHA:
545 case ARP_SPA:
546 case ARP_THA:
547 case ARP_TPA:
548 case BSN_EGR_PORT_GROUP_ID:
549 case BSN_GLOBAL_VRF_ALLOWED:
550 case BSN_IN_PORTS_128:
551 case BSN_L3_DST_CLASS_ID:
552 case BSN_L3_INTERFACE_CLASS_ID:
553 case BSN_L3_SRC_CLASS_ID:
554 case BSN_LAG_ID:
555 case BSN_TCP_FLAGS:
556 case BSN_UDF0:
557 case BSN_UDF1:
558 case BSN_UDF2:
559 case BSN_UDF3:
560 case BSN_UDF4:
561 case BSN_UDF5:
562 case BSN_UDF6:
563 case BSN_UDF7:
564 case BSN_VLAN_XLATE_PORT_GROUP_ID:
565 case BSN_VRF:
566 case ETH_TYPE:
567 case ICMPV4_CODE:
568 case ICMPV4_TYPE:
569 case ICMPV6_CODE:
570 case ICMPV6_TYPE:
571 case IN_PHY_PORT:
572 case IN_PORT:
573 case IPV6_DST:
574 case IPV6_FLABEL:
575 case IPV6_ND_SLL:
576 case IPV6_ND_TARGET:
577 case IPV6_ND_TLL:
578 case IPV6_SRC:
579 case IP_DSCP:
580 case IP_ECN:
581 case IP_PROTO:
582 case METADATA:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800583 case MPLS_TC:
584 case OCH_SIGID:
585 case OCH_SIGID_BASIC:
586 case OCH_SIGTYPE:
587 case OCH_SIGTYPE_BASIC:
588 case SCTP_DST:
589 case SCTP_SRC:
Yafit Hadar73514612015-11-04 10:14:21 +0200590 case EXP_ODU_SIGTYPE:
591 case EXP_OCH_SIGTYPE:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800592 default:
593 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
594 break;
595 }
596 }
597
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700598 // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES
alshabib6b5cfec2014-09-18 17:42:18 -0700599 private TrafficSelector buildSelector() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800600 MacAddress mac;
601 Ip4Prefix ip4Prefix;
602 Ip6Address ip6Address;
603 Ip6Prefix ip6Prefix;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800604 Ip4Address ip;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800605
Jonathan Harte4e74f02016-03-03 12:57:40 -0800606 DriverHandler driverHandler = getDriver(deviceId);
Charles Chan14967c22015-12-07 11:11:50 -0800607 ExtensionSelectorInterpreter selectorInterpreter;
608 if (driverHandler.hasBehaviour(ExtensionSelectorInterpreter.class)) {
609 selectorInterpreter = driverHandler.behaviour(ExtensionSelectorInterpreter.class);
610 } else {
611 selectorInterpreter = null;
612 }
613
tom9a693fd2014-10-03 11:32:19 -0700614 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700615 for (MatchField<?> field : match.getMatchFields()) {
616 switch (field.id) {
617 case IN_PORT:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800618 builder.matchInPort(PortNumber
alshabib010c31d2014-09-26 10:01:12 -0700619 .portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700620 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800621 case IN_PHY_PORT:
622 builder.matchInPhyPort(PortNumber
623 .portNumber(match.get(MatchField.IN_PHY_PORT).getPortNumber()));
624 break;
625 case METADATA:
626 long metadata =
627 match.get(MatchField.METADATA).getValue().getValue();
628 builder.matchMetadata(metadata);
629 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700630 case ETH_DST:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800631 if (match.isPartiallyMasked(MatchField.ETH_DST)) {
632 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
633 match.getMasked(MatchField.ETH_DST);
634 builder.matchEthDstMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
635 MacAddress.valueOf(maskedMac.getMask().getLong()));
636 } else {
637 mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
638 builder.matchEthDst(mac);
639 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800640 break;
641 case ETH_SRC:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800642 if (match.isPartiallyMasked(MatchField.ETH_SRC)) {
643 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
644 match.getMasked(MatchField.ETH_SRC);
645 builder.matchEthSrcMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
646 MacAddress.valueOf(maskedMac.getMask().getLong()));
647 } else {
648 mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
649 builder.matchEthSrc(mac);
650 }
alshabib6b5cfec2014-09-18 17:42:18 -0700651 break;
652 case ETH_TYPE:
653 int ethType = match.get(MatchField.ETH_TYPE).getValue();
Jonathan Hart8cf212a2015-10-29 17:42:03 -0700654 builder.matchEthType((short) ethType);
alshabib6b5cfec2014-09-18 17:42:18 -0700655 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700656 case VLAN_VID:
Charles Chan14967c22015-12-07 11:11:50 -0800657 if (selectorInterpreter != null &&
658 selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
659 if (match.getVersion().equals(OFVersion.OF_13)) {
660 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.VLAN_VID);
661 builder.extension(selectorInterpreter.mapOxm(oxm),
Jonathan Harte4e74f02016-03-03 12:57:40 -0800662 deviceId);
Charles Chan14967c22015-12-07 11:11:50 -0800663 } else {
664 break;
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800665 }
666 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800667 VlanId vlanId = null;
668 if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
669 Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
670 if (masked.getValue().equals(OFVlanVidMatch.PRESENT)
671 && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
672 vlanId = VlanId.ANY;
673 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700674 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800675 if (!match.get(MatchField.VLAN_VID).isPresentBitSet()) {
676 vlanId = VlanId.NONE;
677 } else {
678 vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
679 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700680 }
Charles Chan14967c22015-12-07 11:11:50 -0800681 if (vlanId != null) {
682 builder.matchVlanId(vlanId);
683 }
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800684 }
alshabib6b5cfec2014-09-18 17:42:18 -0700685 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800686 case VLAN_PCP:
687 byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
688 builder.matchVlanPcp(vlanPcp);
689 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800690 case IP_DSCP:
691 byte ipDscp = match.get(MatchField.IP_DSCP).getDscpValue();
692 builder.matchIPDscp(ipDscp);
693 break;
694 case IP_ECN:
695 byte ipEcn = match.get(MatchField.IP_ECN).getEcnValue();
696 builder.matchIPEcn(ipEcn);
697 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800698 case IP_PROTO:
699 short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
700 builder.matchIPProtocol((byte) proto);
701 break;
702 case IPV4_SRC:
703 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
704 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800705 ip4Prefix = Ip4Prefix.valueOf(
706 maskedIp.getValue().getInt(),
707 maskedIp.getMask().asCidrMaskLength());
708 } else {
709 ip4Prefix = Ip4Prefix.valueOf(
710 match.get(MatchField.IPV4_SRC).getInt(),
711 Ip4Prefix.MAX_MASK_LENGTH);
712 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800713 builder.matchIPSrc(ip4Prefix);
714 break;
715 case IPV4_DST:
716 if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
717 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800718 ip4Prefix = Ip4Prefix.valueOf(
719 maskedIp.getValue().getInt(),
720 maskedIp.getMask().asCidrMaskLength());
721 } else {
722 ip4Prefix = Ip4Prefix.valueOf(
723 match.get(MatchField.IPV4_DST).getInt(),
724 Ip4Prefix.MAX_MASK_LENGTH);
725 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800726 builder.matchIPDst(ip4Prefix);
Jonathan Hart34bc6142014-10-17 11:00:43 -0700727 break;
728 case TCP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700729 builder.matchTcpSrc(TpPort.tpPort(match.get(MatchField.TCP_SRC).getPort()));
Jonathan Hart34bc6142014-10-17 11:00:43 -0700730 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800731 case TCP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700732 builder.matchTcpDst(TpPort.tpPort(match.get(MatchField.TCP_DST).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800733 break;
734 case UDP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700735 builder.matchUdpSrc(TpPort.tpPort(match.get(MatchField.UDP_SRC).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800736 break;
737 case UDP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700738 builder.matchUdpDst(TpPort.tpPort(match.get(MatchField.UDP_DST).getPort()));
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700739 break;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100740 case MPLS_LABEL:
741 builder.matchMplsLabel(MplsLabel.mplsLabel((int) match.get(MatchField.MPLS_LABEL)
742 .getValue()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800743 break;
Saurav Dasffc5bbc2015-08-18 23:30:19 -0700744 case MPLS_BOS:
745 builder.matchMplsBos(match.get(MatchField.MPLS_BOS).getValue());
746 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800747 case SCTP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700748 builder.matchSctpSrc(TpPort.tpPort(match.get(MatchField.SCTP_SRC).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800749 break;
750 case SCTP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700751 builder.matchSctpDst(TpPort.tpPort(match.get(MatchField.SCTP_DST).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800752 break;
753 case ICMPV4_TYPE:
754 byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
755 builder.matchIcmpType(icmpType);
756 break;
757 case ICMPV4_CODE:
758 byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode();
759 builder.matchIcmpCode(icmpCode);
760 break;
761 case IPV6_SRC:
762 if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
763 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
764 ip6Prefix = Ip6Prefix.valueOf(
765 maskedIp.getValue().getBytes(),
766 maskedIp.getMask().asCidrMaskLength());
767 } else {
768 ip6Prefix = Ip6Prefix.valueOf(
769 match.get(MatchField.IPV6_SRC).getBytes(),
770 Ip6Prefix.MAX_MASK_LENGTH);
771 }
772 builder.matchIPv6Src(ip6Prefix);
773 break;
774 case IPV6_DST:
775 if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
776 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
777 ip6Prefix = Ip6Prefix.valueOf(
778 maskedIp.getValue().getBytes(),
779 maskedIp.getMask().asCidrMaskLength());
780 } else {
781 ip6Prefix = Ip6Prefix.valueOf(
782 match.get(MatchField.IPV6_DST).getBytes(),
783 Ip6Prefix.MAX_MASK_LENGTH);
784 }
785 builder.matchIPv6Dst(ip6Prefix);
786 break;
787 case IPV6_FLABEL:
788 int flowLabel =
789 match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue();
790 builder.matchIPv6FlowLabel(flowLabel);
791 break;
792 case ICMPV6_TYPE:
793 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
794 builder.matchIcmpv6Type(icmpv6type);
795 break;
796 case ICMPV6_CODE:
797 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
798 builder.matchIcmpv6Code(icmpv6code);
799 break;
800 case IPV6_ND_TARGET:
801 ip6Address =
802 Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes());
803 builder.matchIPv6NDTargetAddress(ip6Address);
804 break;
805 case IPV6_ND_SLL:
806 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong());
807 builder.matchIPv6NDSourceLinkLayerAddress(mac);
808 break;
809 case IPV6_ND_TLL:
810 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong());
811 builder.matchIPv6NDTargetLinkLayerAddress(mac);
812 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800813 case IPV6_EXTHDR:
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800814 builder.matchIPv6ExthdrFlags((short) match.get(MatchField.IPV6_EXTHDR)
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700815 .getValue());
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800816 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700817 case OCH_SIGID:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700818 CircuitSignalID sigId = match.get(MatchField.OCH_SIGID);
819 builder.add(matchLambda(Lambda.ochSignal(
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700820 lookupGridType(sigId.getGridType()), lookupChannelSpacing(sigId.getChannelSpacing()),
Marc De Leenheer0b8b2ef2015-08-03 15:39:00 -0700821 sigId.getChannelNumber(), sigId.getSpectralWidth())
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700822 ));
Marc De Leenheer49087752014-10-23 13:54:09 -0700823 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800824 case OCH_SIGTYPE:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700825 U8 sigType = match.get(MatchField.OCH_SIGTYPE);
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700826 builder.add(matchOchSignalType(lookupOchSignalType((byte) sigType.getValue())));
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800827 break;
Yafit Hadar73514612015-11-04 10:14:21 +0200828 case EXP_OCH_SIG_ID:
829 try {
830 CircuitSignalID expSigId = match.get(MatchField.EXP_OCH_SIG_ID);
831 builder.add(matchLambda(Lambda.ochSignal(
832 lookupGridType(expSigId.getGridType()), lookupChannelSpacing(expSigId.getChannelSpacing()),
833 expSigId.getChannelNumber(), expSigId.getSpectralWidth())));
834 } catch (NoMappingFoundException e) {
835 log.warn(e.getMessage());
836 break;
837 }
838 break;
839 case EXP_OCH_SIGTYPE:
840 try {
841 U8 expOchSigType = match.get(MatchField.EXP_OCH_SIGTYPE);
842 builder.add(matchOchSignalType(lookupOchSignalType((byte) expOchSigType.getValue())));
843 } catch (NoMappingFoundException e) {
844 log.warn(e.getMessage());
845 break;
846 }
847 break;
848 case EXP_ODU_SIG_ID:
849 OduSignalId oduSignalId = OduSignalId.oduSignalId(match.get(MatchField.EXP_ODU_SIG_ID).getTpn(),
850 match.get(MatchField.EXP_ODU_SIG_ID).getTslen(),
851 match.get(MatchField.EXP_ODU_SIG_ID).getTsmap());
852 builder.add(matchOduSignalId(oduSignalId));
853 break;
854 case EXP_ODU_SIGTYPE:
855 try {
856 U8 oduSigType = match.get(MatchField.EXP_ODU_SIGTYPE);
857 builder.add(matchOduSignalType(lookupOduSignalType((byte) oduSigType.getValue())));
858 } catch (NoMappingFoundException e) {
859 log.warn(e.getMessage());
860 break;
861 }
862 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700863 case TUNNEL_ID:
864 long tunnelId = match.get(MatchField.TUNNEL_ID).getValue();
865 builder.matchTunnelId(tunnelId);
866 break;
BitOhenryb40129a2015-11-30 12:41:18 +0800867 case ARP_OP:
868 int arpOp = match.get(MatchField.ARP_OP).getOpcode();
869 builder.matchArpOp(arpOp);
870 break;
BitOhenrya331b182015-11-23 08:39:37 +0800871 case ARP_SHA:
872 mac = MacAddress.valueOf(match.get(MatchField.ARP_SHA).getLong());
873 builder.matchArpSha(mac);
874 break;
BitOhenry296b4542015-11-24 08:41:58 +0800875 case ARP_SPA:
876 ip = Ip4Address.valueOf(match.get(MatchField.ARP_SPA).getInt());
877 builder.matchArpSpa(ip);
878 break;
BitOhenry76430852015-11-20 19:04:49 +0800879 case ARP_THA:
880 mac = MacAddress.valueOf(match.get(MatchField.ARP_THA).getLong());
881 builder.matchArpTha(mac);
882 break;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800883 case ARP_TPA:
884 ip = Ip4Address.valueOf(match.get(MatchField.ARP_TPA).getInt());
885 builder.matchArpTpa(ip);
886 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700887 case MPLS_TC:
alshabib6b5cfec2014-09-18 17:42:18 -0700888 default:
889 log.warn("Match type {} not yet implemented.", field.id);
alshabib6b5cfec2014-09-18 17:42:18 -0700890 }
891 }
892 return builder.build();
893 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700894
Jian Liffef5002016-04-04 23:27:37 -0700895 private DriverHandler getDriver(DeviceId devId) {
896 Driver driver = driverService.getDriver(devId);
897 DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, devId));
Jonathan Hart3c259162015-10-21 21:31:19 -0700898 return handler;
899 }
alshabib6b5cfec2014-09-18 17:42:18 -0700900}