blob: c697967eee22b9529e9cb06618f902c6130dc31c [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Thomas Vachuska781d18b2014-10-27 10:31:25 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Thomas Vachuska781d18b2014-10-27 10:31:25 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
Thomas Vachuska781d18b2014-10-27 10:31:25 -070015 */
Thomas Vachuska95caba32016-04-04 10:42:05 -070016package org.onosproject.provider.of.flow.util;
alshabib6b5cfec2014-09-18 17:42:18 -070017
Jonathan Hart8cf212a2015-10-29 17:42:03 -070018import com.google.common.collect.Lists;
Ray Milkey84d5a292016-02-22 14:04:01 -080019import org.onlab.packet.EthType;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080020import org.onlab.packet.Ip4Address;
21import org.onlab.packet.Ip4Prefix;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080022import org.onlab.packet.Ip6Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080023import org.onlab.packet.Ip6Prefix;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080024import org.onlab.packet.MacAddress;
Michele Santuari4b6019e2014-12-19 11:31:45 +010025import org.onlab.packet.MplsLabel;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -070026import org.onlab.packet.TpPort;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080027import org.onlab.packet.VlanId;
sangho8995ac52015-02-04 11:29:03 -080028import org.onosproject.core.DefaultGroupId;
Brian O'Connorabafb502014-12-02 22:26:20 -080029import org.onosproject.net.DeviceId;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070030import org.onosproject.net.Lambda;
Yafit Hadar73514612015-11-04 10:14:21 +020031import org.onosproject.net.OduSignalId;
Brian O'Connorabafb502014-12-02 22:26:20 -080032import org.onosproject.net.PortNumber;
Jonathan Hart3c259162015-10-21 21:31:19 -070033import org.onosproject.net.driver.DefaultDriverData;
34import org.onosproject.net.driver.DefaultDriverHandler;
35import org.onosproject.net.driver.Driver;
36import org.onosproject.net.driver.DriverHandler;
37import org.onosproject.net.driver.DriverService;
Brian O'Connorabafb502014-12-02 22:26:20 -080038import org.onosproject.net.flow.DefaultFlowEntry;
39import org.onosproject.net.flow.DefaultFlowRule;
40import org.onosproject.net.flow.DefaultTrafficSelector;
41import org.onosproject.net.flow.DefaultTrafficTreatment;
42import org.onosproject.net.flow.FlowEntry;
43import org.onosproject.net.flow.FlowEntry.FlowEntryState;
44import org.onosproject.net.flow.FlowRule;
45import org.onosproject.net.flow.TrafficSelector;
46import org.onosproject.net.flow.TrafficTreatment;
Charles Chan14967c22015-12-07 11:11:50 -080047import org.onosproject.net.flow.criteria.ExtensionSelectorType.ExtensionSelectorTypes;
Sho SHIMIZU9553bb82015-06-30 16:02:45 -070048import org.onosproject.net.flow.instructions.Instructions;
Charles Chan14967c22015-12-07 11:11:50 -080049import org.onosproject.openflow.controller.ExtensionSelectorInterpreter;
alshabib880b6442015-11-23 22:13:04 -080050import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter;
Brian O'Connor72cb19a2015-01-16 16:14:41 -080051import org.projectfloodlight.openflow.protocol.OFFlowMod;
alshabib6b5cfec2014-09-18 17:42:18 -070052import org.projectfloodlight.openflow.protocol.OFFlowRemoved;
53import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry;
Charles Chan14967c22015-12-07 11:11:50 -080054import org.projectfloodlight.openflow.protocol.OFMatchV3;
Brian O'Connor21564612015-12-05 19:24:59 -080055import org.projectfloodlight.openflow.protocol.OFVersion;
alshabib6b5cfec2014-09-18 17:42:18 -070056import org.projectfloodlight.openflow.protocol.action.OFAction;
Marc De Leenheer49087752014-10-23 13:54:09 -070057import org.projectfloodlight.openflow.protocol.action.OFActionCircuit;
Steffen Gebertba2d3b72015-10-22 11:14:31 +020058import org.projectfloodlight.openflow.protocol.action.OFActionEnqueue;
Marc De Leenheer49087752014-10-23 13:54:09 -070059import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter;
sangho8995ac52015-02-04 11:29:03 -080060import org.projectfloodlight.openflow.protocol.action.OFActionGroup;
alshabib6b5cfec2014-09-18 17:42:18 -070061import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
sangho3f97a17d2015-01-29 22:56:29 -080062import org.projectfloodlight.openflow.protocol.action.OFActionPopMpls;
alshabib6b5cfec2014-09-18 17:42:18 -070063import org.projectfloodlight.openflow.protocol.action.OFActionSetDlDst;
64import org.projectfloodlight.openflow.protocol.action.OFActionSetDlSrc;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080065import org.projectfloodlight.openflow.protocol.action.OFActionSetField;
alshabib6b5cfec2014-09-18 17:42:18 -070066import org.projectfloodlight.openflow.protocol.action.OFActionSetNwDst;
67import org.projectfloodlight.openflow.protocol.action.OFActionSetNwSrc;
Jonathan Hart8cf212a2015-10-29 17:42:03 -070068import org.projectfloodlight.openflow.protocol.action.OFActionSetQueue;
alshabib6b5cfec2014-09-18 17:42:18 -070069import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanPcp;
70import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanVid;
alshabib19fdc122014-10-03 11:38:19 -070071import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
Jonathan Hartcf783202014-11-24 18:55:42 -080072import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions;
alshabibbdcbb102015-04-22 14:16:38 -070073import org.projectfloodlight.openflow.protocol.instruction.OFInstructionGotoTable;
alshabib346b5b32015-03-06 00:42:16 -080074import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteActions;
Saurav Das86af8f12015-05-25 23:55:33 -070075import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteMetadata;
alshabib6b5cfec2014-09-18 17:42:18 -070076import org.projectfloodlight.openflow.protocol.match.Match;
77import org.projectfloodlight.openflow.protocol.match.MatchField;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080078import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
Yafit Hadar4cc65f72016-02-10 11:23:06 +020079import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigid;
alshabib346b5b32015-03-06 00:42:16 -080080import org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070081import org.projectfloodlight.openflow.types.CircuitSignalID;
alshabib6b5cfec2014-09-18 17:42:18 -070082import org.projectfloodlight.openflow.types.IPv4Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080083import org.projectfloodlight.openflow.types.IPv6Address;
Jonathan Hart0e12fad2014-10-17 14:54:58 -070084import org.projectfloodlight.openflow.types.Masked;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080085import org.projectfloodlight.openflow.types.OFVlanVidMatch;
Jonathan Harte4e74f02016-03-03 12:57:40 -080086import org.projectfloodlight.openflow.types.OduSignalID;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -070087import org.projectfloodlight.openflow.types.TransportPort;
sangho3f97a17d2015-01-29 22:56:29 -080088import org.projectfloodlight.openflow.types.U32;
Hyunsun Moona08c5d02015-07-14 17:53:00 -070089import org.projectfloodlight.openflow.types.U64;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070090import org.projectfloodlight.openflow.types.U8;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080091import org.projectfloodlight.openflow.types.VlanPcp;
alshabib6b5cfec2014-09-18 17:42:18 -070092import org.slf4j.Logger;
Jian Lia0d9a172016-04-01 16:58:06 -070093import org.slf4j.LoggerFactory;
alshabib6b5cfec2014-09-18 17:42:18 -070094
Jonathan Hart8cf212a2015-10-29 17:42:03 -070095import java.util.List;
96
alshabib44852fb2016-04-15 15:56:51 -070097import static org.onosproject.net.flow.criteria.Criteria.*;
Yafit Hadar73514612015-11-04 10:14:21 +020098import static org.onosproject.net.flow.instructions.Instructions.modL0Lambda;
99import static org.onosproject.net.flow.instructions.Instructions.modL1OduSignalId;
alshabib44852fb2016-04-15 15:56:51 -0700100import static org.onosproject.provider.of.flow.util.OpenFlowValueMapper.*;
alshabib19fdc122014-10-03 11:38:19 -0700101
alshabib1c319ff2014-10-04 20:29:09 -0700102public class FlowEntryBuilder {
Jian Lia0d9a172016-04-01 16:58:06 -0700103 private static final Logger log = LoggerFactory.getLogger(FlowEntryBuilder.class);
alshabib6b5cfec2014-09-18 17:42:18 -0700104
105 private final OFFlowStatsEntry stat;
106 private final OFFlowRemoved removed;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800107 private final OFFlowMod flowMod;
alshabib6b5cfec2014-09-18 17:42:18 -0700108
109 private final Match match;
alshabib346b5b32015-03-06 00:42:16 -0800110
Jonathan Hart67fc0972015-03-19 15:21:20 -0700111 // All actions are contained in an OFInstruction. For OF1.0
112 // the instruction type is apply instruction (immediate set in ONOS speak)
alshabib346b5b32015-03-06 00:42:16 -0800113 private final List<OFInstruction> instructions;
alshabib6b5cfec2014-09-18 17:42:18 -0700114
Jonathan Harte4e74f02016-03-03 12:57:40 -0800115 private final DeviceId deviceId;
alshabib6b5cfec2014-09-18 17:42:18 -0700116
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800117 public enum FlowType { STAT, REMOVED, MOD }
118
119 private final FlowType type;
alshabib6b5cfec2014-09-18 17:42:18 -0700120
Jonathan Hart3c259162015-10-21 21:31:19 -0700121 private final DriverService driverService;
122
Jonathan Harte4e74f02016-03-03 12:57:40 -0800123 public FlowEntryBuilder(DeviceId deviceId, OFFlowStatsEntry entry, DriverService driverService) {
Saurav Dasfa2fa932015-03-03 11:29:48 -0800124 this.stat = entry;
125 this.match = entry.getMatch();
alshabib346b5b32015-03-06 00:42:16 -0800126 this.instructions = getInstructions(entry);
Jonathan Harte4e74f02016-03-03 12:57:40 -0800127 this.deviceId = deviceId;
Saurav Dasfa2fa932015-03-03 11:29:48 -0800128 this.removed = null;
129 this.flowMod = null;
130 this.type = FlowType.STAT;
Jonathan Hart3c259162015-10-21 21:31:19 -0700131 this.driverService = driverService;
Saurav Dasfa2fa932015-03-03 11:29:48 -0800132 }
133
Jonathan Harte4e74f02016-03-03 12:57:40 -0800134 public FlowEntryBuilder(DeviceId deviceId, OFFlowRemoved removed, DriverService driverService) {
alshabib6b5cfec2014-09-18 17:42:18 -0700135 this.match = removed.getMatch();
136 this.removed = removed;
Jonathan Harte4e74f02016-03-03 12:57:40 -0800137 this.deviceId = deviceId;
alshabib346b5b32015-03-06 00:42:16 -0800138 this.instructions = null;
alshabib6b5cfec2014-09-18 17:42:18 -0700139 this.stat = null;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800140 this.flowMod = null;
141 this.type = FlowType.REMOVED;
Jonathan Hart3c259162015-10-21 21:31:19 -0700142 this.driverService = driverService;
alshabib6b5cfec2014-09-18 17:42:18 -0700143 }
144
Jonathan Harte4e74f02016-03-03 12:57:40 -0800145 public FlowEntryBuilder(DeviceId deviceId, OFFlowMod fm, DriverService driverService) {
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800146 this.match = fm.getMatch();
Jonathan Harte4e74f02016-03-03 12:57:40 -0800147 this.deviceId = deviceId;
alshabib346b5b32015-03-06 00:42:16 -0800148 this.instructions = getInstructions(fm);
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800149 this.type = FlowType.MOD;
150 this.flowMod = fm;
151 this.stat = null;
152 this.removed = null;
Jonathan Hart3c259162015-10-21 21:31:19 -0700153 this.driverService = driverService;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800154 }
alshabib1c319ff2014-10-04 20:29:09 -0700155
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800156 public FlowEntry build(FlowEntryState... state) {
Brian O'Connor21564612015-12-05 19:24:59 -0800157 FlowRule.Builder builder;
158 try {
159 switch (this.type) {
160 case STAT:
161 builder = DefaultFlowRule.builder()
Jonathan Harte4e74f02016-03-03 12:57:40 -0800162 .forDevice(deviceId)
Brian O'Connor21564612015-12-05 19:24:59 -0800163 .withSelector(buildSelector())
164 .withTreatment(buildTreatment())
165 .withPriority(stat.getPriority())
166 .makeTemporary(stat.getIdleTimeout())
Jonathan Hartd1ce4b02016-01-11 13:28:36 -0800167 .withCookie(stat.getCookie().getValue());
168 if (stat.getVersion() != OFVersion.OF_10) {
169 builder.forTable(stat.getTableId().getValue());
170 }
alshabibbdcbb102015-04-22 14:16:38 -0700171
Brian O'Connor21564612015-12-05 19:24:59 -0800172 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
173 stat.getDurationSec(),
174 stat.getPacketCount().getValue(),
175 stat.getByteCount().getValue());
176 case REMOVED:
177 builder = DefaultFlowRule.builder()
Jonathan Harte4e74f02016-03-03 12:57:40 -0800178 .forDevice(deviceId)
Brian O'Connor21564612015-12-05 19:24:59 -0800179 .withSelector(buildSelector())
180 .withPriority(removed.getPriority())
181 .makeTemporary(removed.getIdleTimeout())
182 .withCookie(removed.getCookie().getValue());
183 if (removed.getVersion() != OFVersion.OF_10) {
184 builder.forTable(removed.getTableId().getValue());
185 }
alshabibbdcbb102015-04-22 14:16:38 -0700186
Brian O'Connor21564612015-12-05 19:24:59 -0800187 return new DefaultFlowEntry(builder.build(), FlowEntryState.REMOVED,
188 removed.getDurationSec(),
189 removed.getPacketCount().getValue(),
190 removed.getByteCount().getValue());
191 case MOD:
192 FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED;
193 builder = DefaultFlowRule.builder()
Jonathan Harte4e74f02016-03-03 12:57:40 -0800194 .forDevice(deviceId)
Brian O'Connor21564612015-12-05 19:24:59 -0800195 .withSelector(buildSelector())
196 .withTreatment(buildTreatment())
197 .withPriority(flowMod.getPriority())
198 .makeTemporary(flowMod.getIdleTimeout())
199 .withCookie(flowMod.getCookie().getValue());
200 if (flowMod.getVersion() != OFVersion.OF_10) {
201 builder.forTable(flowMod.getTableId().getValue());
202 }
alshabibbdcbb102015-04-22 14:16:38 -0700203
Brian O'Connor21564612015-12-05 19:24:59 -0800204 return new DefaultFlowEntry(builder.build(), flowState, 0, 0, 0);
205 default:
206 log.error("Unknown flow type : {}", this.type);
207 return null;
208 }
209 } catch (UnsupportedOperationException e) {
210 log.warn("Error building flow entry", e);
211 return null;
alshabib6b5cfec2014-09-18 17:42:18 -0700212 }
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800213
alshabib6b5cfec2014-09-18 17:42:18 -0700214 }
215
alshabib346b5b32015-03-06 00:42:16 -0800216 private List<OFInstruction> getInstructions(OFFlowMod entry) {
alshabib19fdc122014-10-03 11:38:19 -0700217 switch (entry.getVersion()) {
218 case OF_10:
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700219 return Lists.newArrayList(OFFactoryVer13.INSTANCE.instructions()
220 .applyActions(
221 entry.getActions()));
alshabib19fdc122014-10-03 11:38:19 -0700222 case OF_11:
223 case OF_12:
224 case OF_13:
alshabib346b5b32015-03-06 00:42:16 -0800225 return entry.getInstructions();
226 default:
227 log.warn("Unknown OF version {}", entry.getVersion());
228 }
229 return Lists.newLinkedList();
230 }
231
232 private List<OFInstruction> getInstructions(OFFlowStatsEntry entry) {
233 switch (entry.getVersion()) {
234 case OF_10:
235 return Lists.newArrayList(
236 OFFactoryVer13.INSTANCE.instructions().applyActions(entry.getActions()));
237 case OF_11:
238 case OF_12:
239 case OF_13:
240 return entry.getInstructions();
alshabib19fdc122014-10-03 11:38:19 -0700241 default:
242 log.warn("Unknown OF version {}", entry.getVersion());
243 }
244 return Lists.newLinkedList();
245 }
alshabib6b5cfec2014-09-18 17:42:18 -0700246
247 private TrafficTreatment buildTreatment() {
tom9a693fd2014-10-03 11:32:19 -0700248 TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
alshabib346b5b32015-03-06 00:42:16 -0800249 for (OFInstruction in : instructions) {
250 switch (in.getType()) {
251 case GOTO_TABLE:
alshabibbdcbb102015-04-22 14:16:38 -0700252 builder.transition(((int) ((OFInstructionGotoTable) in)
253 .getTableId().getValue()));
alshabib346b5b32015-03-06 00:42:16 -0800254 break;
255 case WRITE_METADATA:
Saurav Das86af8f12015-05-25 23:55:33 -0700256 OFInstructionWriteMetadata m = (OFInstructionWriteMetadata) in;
257 builder.writeMetadata(m.getMetadata().getValue(),
258 m.getMetadataMask().getValue());
alshabib346b5b32015-03-06 00:42:16 -0800259 break;
260 case WRITE_ACTIONS:
261 builder.deferred();
262 buildActions(((OFInstructionWriteActions) in).getActions(),
263 builder);
264 break;
265 case APPLY_ACTIONS:
266 builder.immediate();
267 buildActions(((OFInstructionApplyActions) in).getActions(),
268 builder);
269 break;
270 case CLEAR_ACTIONS:
271 builder.wipeDeferred();
272 break;
273 case EXPERIMENTER:
274 break;
275 case METER:
276 break;
277 default:
278 log.warn("Unknown instructions type {}", in.getType());
alshabib6b5cfec2014-09-18 17:42:18 -0700279 }
280 }
281
282 return builder.build();
283 }
284
Jian Lia0d9a172016-04-01 16:58:06 -0700285 /**
286 * Configures traffic treatment builder with a given collection of actions.
287 *
288 * @param actions a set of OpenFlow actions
289 * @param builder traffic treatment builder
290 * @param driverHandler driver handler
291 * @param deviceId device identifier
292 * @return configured traffic treatment builder
293 */
294 public static TrafficTreatment.Builder configureTreatmentBuilder(List<OFAction> actions,
295 TrafficTreatment.Builder builder,
296 DriverHandler driverHandler,
297 DeviceId deviceId) {
298 ExtensionTreatmentInterpreter interpreter;
Charles Chan14967c22015-12-07 11:11:50 -0800299 if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
Jian Lia0d9a172016-04-01 16:58:06 -0700300 interpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class);
Charles Chan14967c22015-12-07 11:11:50 -0800301 } else {
Jian Lia0d9a172016-04-01 16:58:06 -0700302 interpreter = null;
Charles Chan14967c22015-12-07 11:11:50 -0800303 }
304
alshabib346b5b32015-03-06 00:42:16 -0800305 for (OFAction act : actions) {
306 switch (act.getType()) {
307 case OUTPUT:
308 OFActionOutput out = (OFActionOutput) act;
309 builder.setOutput(
310 PortNumber.portNumber(out.getPort().getPortNumber()));
311 break;
312 case SET_VLAN_VID:
313 OFActionSetVlanVid vlan = (OFActionSetVlanVid) act;
314 builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan()));
315 break;
316 case SET_VLAN_PCP:
317 OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act;
318 builder.setVlanPcp(pcp.getVlanPcp().getValue());
319 break;
320 case SET_DL_DST:
321 OFActionSetDlDst dldst = (OFActionSetDlDst) act;
322 builder.setEthDst(
323 MacAddress.valueOf(dldst.getDlAddr().getLong()));
324 break;
325 case SET_DL_SRC:
326 OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act;
327 builder.setEthSrc(
328 MacAddress.valueOf(dlsrc.getDlAddr().getLong()));
alshabib346b5b32015-03-06 00:42:16 -0800329 break;
330 case SET_NW_DST:
331 OFActionSetNwDst nwdst = (OFActionSetNwDst) act;
332 IPv4Address di = nwdst.getNwAddr();
333 builder.setIpDst(Ip4Address.valueOf(di.getInt()));
334 break;
335 case SET_NW_SRC:
336 OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act;
337 IPv4Address si = nwsrc.getNwAddr();
338 builder.setIpSrc(Ip4Address.valueOf(si.getInt()));
339 break;
340 case EXPERIMENTER:
341 OFActionExperimenter exp = (OFActionExperimenter) act;
342 if (exp.getExperimenter() == 0x80005A06 ||
343 exp.getExperimenter() == 0x748771) {
344 OFActionCircuit ct = (OFActionCircuit) exp;
Yafit Hadar4cc65f72016-02-10 11:23:06 +0200345 CircuitSignalID circuitSignalID = ((OFOxmOchSigid) ct.getField()).getValue();
346 builder.add(Instructions.modL0Lambda(Lambda.ochSignal(
347 lookupGridType(circuitSignalID.getGridType()),
348 lookupChannelSpacing(circuitSignalID.getChannelSpacing()),
349 circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth())));
Jian Lia0d9a172016-04-01 16:58:06 -0700350 } else if (interpreter != null) {
351 builder.extension(interpreter.mapAction(exp), deviceId);
alshabib346b5b32015-03-06 00:42:16 -0800352 } else {
353 log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter());
354 }
355 break;
356 case SET_FIELD:
357 OFActionSetField setField = (OFActionSetField) act;
Jian Lia0d9a172016-04-01 16:58:06 -0700358 handleSetField(builder, setField, driverHandler, deviceId);
alshabib346b5b32015-03-06 00:42:16 -0800359 break;
360 case POP_MPLS:
361 OFActionPopMpls popMpls = (OFActionPopMpls) act;
Ray Milkey84d5a292016-02-22 14:04:01 -0800362 builder.popMpls(new EthType(popMpls.getEthertype().getValue()));
alshabib346b5b32015-03-06 00:42:16 -0800363 break;
364 case PUSH_MPLS:
365 builder.pushMpls();
366 break;
367 case COPY_TTL_IN:
368 builder.copyTtlIn();
369 break;
370 case COPY_TTL_OUT:
371 builder.copyTtlOut();
372 break;
373 case DEC_MPLS_TTL:
374 builder.decMplsTtl();
375 break;
376 case DEC_NW_TTL:
377 builder.decNwTtl();
378 break;
379 case GROUP:
380 OFActionGroup group = (OFActionGroup) act;
381 builder.group(new DefaultGroupId(group.getGroup().getGroupNumber()));
382 break;
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200383 case SET_QUEUE:
384 OFActionSetQueue setQueue = (OFActionSetQueue) act;
385 builder.setQueue(setQueue.getQueueId());
386 break;
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200387 case ENQUEUE:
388 OFActionEnqueue enqueue = (OFActionEnqueue) act;
Jian Liffef5002016-04-04 23:27:37 -0700389 builder.setQueue(enqueue.getQueueId(),
390 PortNumber.portNumber(enqueue.getPort().getPortNumber()));
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200391 break;
Jonathan Hart67fc0972015-03-19 15:21:20 -0700392 case STRIP_VLAN:
alshabib346b5b32015-03-06 00:42:16 -0800393 case POP_VLAN:
394 builder.popVlan();
395 break;
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700396 case PUSH_VLAN:
397 builder.pushVlan();
398 break;
alshabib346b5b32015-03-06 00:42:16 -0800399 case SET_TP_DST:
400 case SET_TP_SRC:
401 case POP_PBB:
402 case PUSH_PBB:
alshabib346b5b32015-03-06 00:42:16 -0800403 case SET_MPLS_LABEL:
404 case SET_MPLS_TC:
405 case SET_MPLS_TTL:
406 case SET_NW_ECN:
407 case SET_NW_TOS:
408 case SET_NW_TTL:
alshabib346b5b32015-03-06 00:42:16 -0800409
alshabib346b5b32015-03-06 00:42:16 -0800410 default:
411 log.warn("Action type {} not yet implemented.", act.getType());
412 }
413 }
414 return builder;
415 }
416
Jian Lia0d9a172016-04-01 16:58:06 -0700417 private TrafficTreatment.Builder buildActions(List<OFAction> actions,
418 TrafficTreatment.Builder builder) {
Jonathan Harte4e74f02016-03-03 12:57:40 -0800419 DriverHandler driverHandler = getDriver(deviceId);
Jian Lia0d9a172016-04-01 16:58:06 -0700420
421 return configureTreatmentBuilder(actions, builder, driverHandler, deviceId);
422 }
423
424
425 private static void handleSetField(TrafficTreatment.Builder builder,
426 OFActionSetField action,
427 DriverHandler driverHandler,
428 DeviceId deviceId) {
Charles Chan14967c22015-12-07 11:11:50 -0800429 ExtensionTreatmentInterpreter treatmentInterpreter;
430 if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
431 treatmentInterpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class);
432 } else {
433 treatmentInterpreter = null;
434 }
435
Jonathan Hart3c259162015-10-21 21:31:19 -0700436 OFOxm<?> oxm = action.getField();
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800437 switch (oxm.getMatchField().id) {
438 case VLAN_PCP:
439 @SuppressWarnings("unchecked")
440 OFOxm<VlanPcp> vlanpcp = (OFOxm<VlanPcp>) oxm;
441 builder.setVlanPcp(vlanpcp.getValue().getValue());
442 break;
443 case VLAN_VID:
Charles Chan4211baa2016-04-20 17:10:40 -0700444 if (treatmentInterpreter != null) {
445 try {
446 builder.extension(treatmentInterpreter.mapAction(action), deviceId);
447 break;
448 } catch (UnsupportedOperationException e) {
449 log.debug("Unsupported action extension; defaulting to native OF");
450 }
Charles Chan14967c22015-12-07 11:11:50 -0800451 }
alshabib44852fb2016-04-15 15:56:51 -0700452 @SuppressWarnings("unchecked")
453 OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm;
454 builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan()));
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800455 break;
456 case ETH_DST:
457 @SuppressWarnings("unchecked")
458 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethdst =
459 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
460 builder.setEthDst(MacAddress.valueOf(ethdst.getValue().getLong()));
461 break;
462 case ETH_SRC:
463 @SuppressWarnings("unchecked")
464 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethsrc =
465 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
466 builder.setEthSrc(MacAddress.valueOf(ethsrc.getValue().getLong()));
467 break;
468 case IPV4_DST:
469 @SuppressWarnings("unchecked")
470 OFOxm<IPv4Address> ip4dst = (OFOxm<IPv4Address>) oxm;
471 builder.setIpDst(Ip4Address.valueOf(ip4dst.getValue().getInt()));
472 break;
473 case IPV4_SRC:
474 @SuppressWarnings("unchecked")
475 OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm;
476 builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt()));
477 break;
sangho3f97a17d2015-01-29 22:56:29 -0800478 case MPLS_LABEL:
479 @SuppressWarnings("unchecked")
480 OFOxm<U32> labelId = (OFOxm<U32>) oxm;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100481 builder.setMpls(MplsLabel.mplsLabel((int) labelId.getValue().getValue()));
sangho3f97a17d2015-01-29 22:56:29 -0800482 break;
Saurav Das73a7dd42015-08-19 22:20:31 -0700483 case MPLS_BOS:
484 @SuppressWarnings("unchecked")
485 OFOxm<U8> mplsBos = (OFOxm<U8>) oxm;
486 builder.setMplsBos(mplsBos.getValue() == U8.ZERO ? false : true);
487 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700488 case TUNNEL_ID:
489 @SuppressWarnings("unchecked")
490 OFOxm<U64> tunnelId = (OFOxm<U64>) oxm;
491 builder.setTunnelId(tunnelId.getValue().getValue());
492 break;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700493 case TCP_DST:
494 @SuppressWarnings("unchecked")
495 OFOxm<TransportPort> tcpdst = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700496 builder.setTcpDst(TpPort.tpPort(tcpdst.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700497 break;
498 case TCP_SRC:
499 @SuppressWarnings("unchecked")
500 OFOxm<TransportPort> tcpsrc = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700501 builder.setTcpSrc(TpPort.tpPort(tcpsrc.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700502 break;
503 case UDP_DST:
504 @SuppressWarnings("unchecked")
505 OFOxm<TransportPort> udpdst = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700506 builder.setUdpDst(TpPort.tpPort(udpdst.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700507 break;
508 case UDP_SRC:
509 @SuppressWarnings("unchecked")
510 OFOxm<TransportPort> udpsrc = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700511 builder.setUdpSrc(TpPort.tpPort(udpsrc.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700512 break;
Jonathan Hart3c259162015-10-21 21:31:19 -0700513 case TUNNEL_IPV4_DST:
Jian Liffef5002016-04-04 23:27:37 -0700514 if (treatmentInterpreter != null) {
515 try {
516 builder.extension(treatmentInterpreter.mapAction(action), deviceId);
517 } catch (UnsupportedOperationException e) {
alshabib44852fb2016-04-15 15:56:51 -0700518 log.debug(e.getMessage());
Jian Liffef5002016-04-04 23:27:37 -0700519 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700520 }
521 break;
Yafit Hadar73514612015-11-04 10:14:21 +0200522 case EXP_ODU_SIG_ID:
523 @SuppressWarnings("unchecked")
524 OFOxm<OduSignalID> oduID = (OFOxm<OduSignalID>) oxm;
525 OduSignalID oduSignalID = oduID.getValue();
526 OduSignalId oduSignalId = OduSignalId.oduSignalId(oduSignalID.getTpn(),
527 oduSignalID.getTslen(),
528 oduSignalID.getTsmap());
529 builder.add(modL1OduSignalId(oduSignalId));
530 break;
531 case EXP_OCH_SIG_ID:
532 try {
533 @SuppressWarnings("unchecked")
534 OFOxm<CircuitSignalID> ochId = (OFOxm<CircuitSignalID>) oxm;
535 CircuitSignalID circuitSignalID = ochId.getValue();
536 builder.add(modL0Lambda(Lambda.ochSignal(
537 lookupGridType(circuitSignalID.getGridType()),
538 lookupChannelSpacing(circuitSignalID.getChannelSpacing()),
539 circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth())));
540 } catch (NoMappingFoundException e) {
541 log.warn(e.getMessage());
542 break;
543 }
544 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800545 case ARP_OP:
546 case ARP_SHA:
547 case ARP_SPA:
548 case ARP_THA:
549 case ARP_TPA:
550 case BSN_EGR_PORT_GROUP_ID:
551 case BSN_GLOBAL_VRF_ALLOWED:
552 case BSN_IN_PORTS_128:
553 case BSN_L3_DST_CLASS_ID:
554 case BSN_L3_INTERFACE_CLASS_ID:
555 case BSN_L3_SRC_CLASS_ID:
556 case BSN_LAG_ID:
557 case BSN_TCP_FLAGS:
558 case BSN_UDF0:
559 case BSN_UDF1:
560 case BSN_UDF2:
561 case BSN_UDF3:
562 case BSN_UDF4:
563 case BSN_UDF5:
564 case BSN_UDF6:
565 case BSN_UDF7:
566 case BSN_VLAN_XLATE_PORT_GROUP_ID:
567 case BSN_VRF:
568 case ETH_TYPE:
569 case ICMPV4_CODE:
570 case ICMPV4_TYPE:
571 case ICMPV6_CODE:
572 case ICMPV6_TYPE:
573 case IN_PHY_PORT:
574 case IN_PORT:
575 case IPV6_DST:
576 case IPV6_FLABEL:
577 case IPV6_ND_SLL:
578 case IPV6_ND_TARGET:
579 case IPV6_ND_TLL:
580 case IPV6_SRC:
581 case IP_DSCP:
582 case IP_ECN:
583 case IP_PROTO:
584 case METADATA:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800585 case MPLS_TC:
586 case OCH_SIGID:
587 case OCH_SIGID_BASIC:
588 case OCH_SIGTYPE:
589 case OCH_SIGTYPE_BASIC:
590 case SCTP_DST:
591 case SCTP_SRC:
Yafit Hadar73514612015-11-04 10:14:21 +0200592 case EXP_ODU_SIGTYPE:
593 case EXP_OCH_SIGTYPE:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800594 default:
595 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
596 break;
597 }
598 }
599
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700600 // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES
alshabib6b5cfec2014-09-18 17:42:18 -0700601 private TrafficSelector buildSelector() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800602 MacAddress mac;
603 Ip4Prefix ip4Prefix;
604 Ip6Address ip6Address;
605 Ip6Prefix ip6Prefix;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800606 Ip4Address ip;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800607
Jonathan Harte4e74f02016-03-03 12:57:40 -0800608 DriverHandler driverHandler = getDriver(deviceId);
Charles Chan14967c22015-12-07 11:11:50 -0800609 ExtensionSelectorInterpreter selectorInterpreter;
610 if (driverHandler.hasBehaviour(ExtensionSelectorInterpreter.class)) {
611 selectorInterpreter = driverHandler.behaviour(ExtensionSelectorInterpreter.class);
612 } else {
613 selectorInterpreter = null;
614 }
615
tom9a693fd2014-10-03 11:32:19 -0700616 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700617 for (MatchField<?> field : match.getMatchFields()) {
618 switch (field.id) {
619 case IN_PORT:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800620 builder.matchInPort(PortNumber
alshabib010c31d2014-09-26 10:01:12 -0700621 .portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700622 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800623 case IN_PHY_PORT:
624 builder.matchInPhyPort(PortNumber
625 .portNumber(match.get(MatchField.IN_PHY_PORT).getPortNumber()));
626 break;
627 case METADATA:
628 long metadata =
629 match.get(MatchField.METADATA).getValue().getValue();
630 builder.matchMetadata(metadata);
631 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700632 case ETH_DST:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800633 if (match.isPartiallyMasked(MatchField.ETH_DST)) {
634 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
635 match.getMasked(MatchField.ETH_DST);
636 builder.matchEthDstMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
637 MacAddress.valueOf(maskedMac.getMask().getLong()));
638 } else {
639 mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
640 builder.matchEthDst(mac);
641 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800642 break;
643 case ETH_SRC:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800644 if (match.isPartiallyMasked(MatchField.ETH_SRC)) {
645 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
646 match.getMasked(MatchField.ETH_SRC);
647 builder.matchEthSrcMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
648 MacAddress.valueOf(maskedMac.getMask().getLong()));
649 } else {
650 mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
651 builder.matchEthSrc(mac);
652 }
alshabib6b5cfec2014-09-18 17:42:18 -0700653 break;
654 case ETH_TYPE:
655 int ethType = match.get(MatchField.ETH_TYPE).getValue();
Jonathan Hart8cf212a2015-10-29 17:42:03 -0700656 builder.matchEthType((short) ethType);
alshabib6b5cfec2014-09-18 17:42:18 -0700657 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700658 case VLAN_VID:
Charles Chan14967c22015-12-07 11:11:50 -0800659 if (selectorInterpreter != null &&
660 selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
661 if (match.getVersion().equals(OFVersion.OF_13)) {
662 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.VLAN_VID);
663 builder.extension(selectorInterpreter.mapOxm(oxm),
Jonathan Harte4e74f02016-03-03 12:57:40 -0800664 deviceId);
Charles Chan14967c22015-12-07 11:11:50 -0800665 } else {
666 break;
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800667 }
668 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800669 VlanId vlanId = null;
670 if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
671 Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
672 if (masked.getValue().equals(OFVlanVidMatch.PRESENT)
673 && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
674 vlanId = VlanId.ANY;
675 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700676 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800677 if (!match.get(MatchField.VLAN_VID).isPresentBitSet()) {
678 vlanId = VlanId.NONE;
679 } else {
680 vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
681 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700682 }
Charles Chan14967c22015-12-07 11:11:50 -0800683 if (vlanId != null) {
684 builder.matchVlanId(vlanId);
685 }
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800686 }
alshabib6b5cfec2014-09-18 17:42:18 -0700687 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800688 case VLAN_PCP:
689 byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
690 builder.matchVlanPcp(vlanPcp);
691 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800692 case IP_DSCP:
693 byte ipDscp = match.get(MatchField.IP_DSCP).getDscpValue();
694 builder.matchIPDscp(ipDscp);
695 break;
696 case IP_ECN:
697 byte ipEcn = match.get(MatchField.IP_ECN).getEcnValue();
698 builder.matchIPEcn(ipEcn);
699 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800700 case IP_PROTO:
701 short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
702 builder.matchIPProtocol((byte) proto);
703 break;
704 case IPV4_SRC:
705 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
706 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800707 ip4Prefix = Ip4Prefix.valueOf(
708 maskedIp.getValue().getInt(),
709 maskedIp.getMask().asCidrMaskLength());
710 } else {
711 ip4Prefix = Ip4Prefix.valueOf(
712 match.get(MatchField.IPV4_SRC).getInt(),
713 Ip4Prefix.MAX_MASK_LENGTH);
714 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800715 builder.matchIPSrc(ip4Prefix);
716 break;
717 case IPV4_DST:
718 if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
719 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800720 ip4Prefix = Ip4Prefix.valueOf(
721 maskedIp.getValue().getInt(),
722 maskedIp.getMask().asCidrMaskLength());
723 } else {
724 ip4Prefix = Ip4Prefix.valueOf(
725 match.get(MatchField.IPV4_DST).getInt(),
726 Ip4Prefix.MAX_MASK_LENGTH);
727 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800728 builder.matchIPDst(ip4Prefix);
Jonathan Hart34bc6142014-10-17 11:00:43 -0700729 break;
730 case TCP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700731 builder.matchTcpSrc(TpPort.tpPort(match.get(MatchField.TCP_SRC).getPort()));
Jonathan Hart34bc6142014-10-17 11:00:43 -0700732 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800733 case TCP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700734 builder.matchTcpDst(TpPort.tpPort(match.get(MatchField.TCP_DST).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800735 break;
736 case UDP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700737 builder.matchUdpSrc(TpPort.tpPort(match.get(MatchField.UDP_SRC).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800738 break;
739 case UDP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700740 builder.matchUdpDst(TpPort.tpPort(match.get(MatchField.UDP_DST).getPort()));
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700741 break;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100742 case MPLS_LABEL:
743 builder.matchMplsLabel(MplsLabel.mplsLabel((int) match.get(MatchField.MPLS_LABEL)
744 .getValue()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800745 break;
Saurav Dasffc5bbc2015-08-18 23:30:19 -0700746 case MPLS_BOS:
747 builder.matchMplsBos(match.get(MatchField.MPLS_BOS).getValue());
748 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800749 case SCTP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700750 builder.matchSctpSrc(TpPort.tpPort(match.get(MatchField.SCTP_SRC).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800751 break;
752 case SCTP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700753 builder.matchSctpDst(TpPort.tpPort(match.get(MatchField.SCTP_DST).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800754 break;
755 case ICMPV4_TYPE:
756 byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
757 builder.matchIcmpType(icmpType);
758 break;
759 case ICMPV4_CODE:
760 byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode();
761 builder.matchIcmpCode(icmpCode);
762 break;
763 case IPV6_SRC:
764 if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
765 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
766 ip6Prefix = Ip6Prefix.valueOf(
767 maskedIp.getValue().getBytes(),
768 maskedIp.getMask().asCidrMaskLength());
769 } else {
770 ip6Prefix = Ip6Prefix.valueOf(
771 match.get(MatchField.IPV6_SRC).getBytes(),
772 Ip6Prefix.MAX_MASK_LENGTH);
773 }
774 builder.matchIPv6Src(ip6Prefix);
775 break;
776 case IPV6_DST:
777 if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
778 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
779 ip6Prefix = Ip6Prefix.valueOf(
780 maskedIp.getValue().getBytes(),
781 maskedIp.getMask().asCidrMaskLength());
782 } else {
783 ip6Prefix = Ip6Prefix.valueOf(
784 match.get(MatchField.IPV6_DST).getBytes(),
785 Ip6Prefix.MAX_MASK_LENGTH);
786 }
787 builder.matchIPv6Dst(ip6Prefix);
788 break;
789 case IPV6_FLABEL:
790 int flowLabel =
791 match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue();
792 builder.matchIPv6FlowLabel(flowLabel);
793 break;
794 case ICMPV6_TYPE:
795 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
796 builder.matchIcmpv6Type(icmpv6type);
797 break;
798 case ICMPV6_CODE:
799 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
800 builder.matchIcmpv6Code(icmpv6code);
801 break;
802 case IPV6_ND_TARGET:
803 ip6Address =
804 Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes());
805 builder.matchIPv6NDTargetAddress(ip6Address);
806 break;
807 case IPV6_ND_SLL:
808 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong());
809 builder.matchIPv6NDSourceLinkLayerAddress(mac);
810 break;
811 case IPV6_ND_TLL:
812 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong());
813 builder.matchIPv6NDTargetLinkLayerAddress(mac);
814 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800815 case IPV6_EXTHDR:
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800816 builder.matchIPv6ExthdrFlags((short) match.get(MatchField.IPV6_EXTHDR)
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700817 .getValue());
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800818 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700819 case OCH_SIGID:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700820 CircuitSignalID sigId = match.get(MatchField.OCH_SIGID);
821 builder.add(matchLambda(Lambda.ochSignal(
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700822 lookupGridType(sigId.getGridType()), lookupChannelSpacing(sigId.getChannelSpacing()),
Marc De Leenheer0b8b2ef2015-08-03 15:39:00 -0700823 sigId.getChannelNumber(), sigId.getSpectralWidth())
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700824 ));
Marc De Leenheer49087752014-10-23 13:54:09 -0700825 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800826 case OCH_SIGTYPE:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700827 U8 sigType = match.get(MatchField.OCH_SIGTYPE);
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700828 builder.add(matchOchSignalType(lookupOchSignalType((byte) sigType.getValue())));
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800829 break;
Yafit Hadar73514612015-11-04 10:14:21 +0200830 case EXP_OCH_SIG_ID:
831 try {
832 CircuitSignalID expSigId = match.get(MatchField.EXP_OCH_SIG_ID);
833 builder.add(matchLambda(Lambda.ochSignal(
834 lookupGridType(expSigId.getGridType()), lookupChannelSpacing(expSigId.getChannelSpacing()),
835 expSigId.getChannelNumber(), expSigId.getSpectralWidth())));
836 } catch (NoMappingFoundException e) {
837 log.warn(e.getMessage());
838 break;
839 }
840 break;
841 case EXP_OCH_SIGTYPE:
842 try {
843 U8 expOchSigType = match.get(MatchField.EXP_OCH_SIGTYPE);
844 builder.add(matchOchSignalType(lookupOchSignalType((byte) expOchSigType.getValue())));
845 } catch (NoMappingFoundException e) {
846 log.warn(e.getMessage());
847 break;
848 }
849 break;
850 case EXP_ODU_SIG_ID:
851 OduSignalId oduSignalId = OduSignalId.oduSignalId(match.get(MatchField.EXP_ODU_SIG_ID).getTpn(),
852 match.get(MatchField.EXP_ODU_SIG_ID).getTslen(),
853 match.get(MatchField.EXP_ODU_SIG_ID).getTsmap());
854 builder.add(matchOduSignalId(oduSignalId));
855 break;
856 case EXP_ODU_SIGTYPE:
857 try {
858 U8 oduSigType = match.get(MatchField.EXP_ODU_SIGTYPE);
859 builder.add(matchOduSignalType(lookupOduSignalType((byte) oduSigType.getValue())));
860 } catch (NoMappingFoundException e) {
861 log.warn(e.getMessage());
862 break;
863 }
864 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700865 case TUNNEL_ID:
866 long tunnelId = match.get(MatchField.TUNNEL_ID).getValue();
867 builder.matchTunnelId(tunnelId);
868 break;
BitOhenryb40129a2015-11-30 12:41:18 +0800869 case ARP_OP:
870 int arpOp = match.get(MatchField.ARP_OP).getOpcode();
871 builder.matchArpOp(arpOp);
872 break;
BitOhenrya331b182015-11-23 08:39:37 +0800873 case ARP_SHA:
874 mac = MacAddress.valueOf(match.get(MatchField.ARP_SHA).getLong());
875 builder.matchArpSha(mac);
876 break;
BitOhenry296b4542015-11-24 08:41:58 +0800877 case ARP_SPA:
878 ip = Ip4Address.valueOf(match.get(MatchField.ARP_SPA).getInt());
879 builder.matchArpSpa(ip);
880 break;
BitOhenry76430852015-11-20 19:04:49 +0800881 case ARP_THA:
882 mac = MacAddress.valueOf(match.get(MatchField.ARP_THA).getLong());
883 builder.matchArpTha(mac);
884 break;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800885 case ARP_TPA:
886 ip = Ip4Address.valueOf(match.get(MatchField.ARP_TPA).getInt());
887 builder.matchArpTpa(ip);
888 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700889 case MPLS_TC:
alshabib6b5cfec2014-09-18 17:42:18 -0700890 default:
891 log.warn("Match type {} not yet implemented.", field.id);
alshabib6b5cfec2014-09-18 17:42:18 -0700892 }
893 }
894 return builder.build();
895 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700896
Jian Liffef5002016-04-04 23:27:37 -0700897 private DriverHandler getDriver(DeviceId devId) {
898 Driver driver = driverService.getDriver(devId);
899 DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, devId));
Jonathan Hart3c259162015-10-21 21:31:19 -0700900 return handler;
901 }
alshabib6b5cfec2014-09-18 17:42:18 -0700902}