blob: 3ca09793f88af6110d71767f548b637973bf1726 [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:
lishuai67574ce2016-05-12 16:39:59 +0800546 @SuppressWarnings("unchecked")
547 OFOxm<org.projectfloodlight.openflow.types.ArpOpcode> arpop =
548 (OFOxm<org.projectfloodlight.openflow.types.ArpOpcode>) oxm;
549 builder.setArpOp((short) arpop.getValue().getOpcode());
550 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800551 case ARP_SHA:
lishuai67574ce2016-05-12 16:39:59 +0800552 @SuppressWarnings("unchecked")
553 OFOxm<org.projectfloodlight.openflow.types.MacAddress> arpsha =
554 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
555 builder.setArpSha(MacAddress.valueOf(arpsha.getValue().getLong()));
556 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800557 case ARP_SPA:
lishuai67574ce2016-05-12 16:39:59 +0800558 @SuppressWarnings("unchecked")
559 OFOxm<IPv4Address> arpspa = (OFOxm<IPv4Address>) oxm;
560 builder.setArpSpa(Ip4Address.valueOf(arpspa.getValue().getInt()));
561 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800562 case ARP_THA:
563 case ARP_TPA:
564 case BSN_EGR_PORT_GROUP_ID:
565 case BSN_GLOBAL_VRF_ALLOWED:
566 case BSN_IN_PORTS_128:
567 case BSN_L3_DST_CLASS_ID:
568 case BSN_L3_INTERFACE_CLASS_ID:
569 case BSN_L3_SRC_CLASS_ID:
570 case BSN_LAG_ID:
571 case BSN_TCP_FLAGS:
572 case BSN_UDF0:
573 case BSN_UDF1:
574 case BSN_UDF2:
575 case BSN_UDF3:
576 case BSN_UDF4:
577 case BSN_UDF5:
578 case BSN_UDF6:
579 case BSN_UDF7:
580 case BSN_VLAN_XLATE_PORT_GROUP_ID:
581 case BSN_VRF:
582 case ETH_TYPE:
583 case ICMPV4_CODE:
584 case ICMPV4_TYPE:
585 case ICMPV6_CODE:
586 case ICMPV6_TYPE:
587 case IN_PHY_PORT:
588 case IN_PORT:
589 case IPV6_DST:
590 case IPV6_FLABEL:
591 case IPV6_ND_SLL:
592 case IPV6_ND_TARGET:
593 case IPV6_ND_TLL:
594 case IPV6_SRC:
595 case IP_DSCP:
596 case IP_ECN:
597 case IP_PROTO:
598 case METADATA:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800599 case MPLS_TC:
600 case OCH_SIGID:
601 case OCH_SIGID_BASIC:
602 case OCH_SIGTYPE:
603 case OCH_SIGTYPE_BASIC:
604 case SCTP_DST:
605 case SCTP_SRC:
Yafit Hadar73514612015-11-04 10:14:21 +0200606 case EXP_ODU_SIGTYPE:
607 case EXP_OCH_SIGTYPE:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800608 default:
609 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
610 break;
611 }
612 }
613
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700614 // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES
alshabib6b5cfec2014-09-18 17:42:18 -0700615 private TrafficSelector buildSelector() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800616 MacAddress mac;
617 Ip4Prefix ip4Prefix;
618 Ip6Address ip6Address;
619 Ip6Prefix ip6Prefix;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800620 Ip4Address ip;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800621
Jonathan Harte4e74f02016-03-03 12:57:40 -0800622 DriverHandler driverHandler = getDriver(deviceId);
Charles Chan14967c22015-12-07 11:11:50 -0800623 ExtensionSelectorInterpreter selectorInterpreter;
624 if (driverHandler.hasBehaviour(ExtensionSelectorInterpreter.class)) {
625 selectorInterpreter = driverHandler.behaviour(ExtensionSelectorInterpreter.class);
626 } else {
627 selectorInterpreter = null;
628 }
629
tom9a693fd2014-10-03 11:32:19 -0700630 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700631 for (MatchField<?> field : match.getMatchFields()) {
632 switch (field.id) {
633 case IN_PORT:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800634 builder.matchInPort(PortNumber
alshabib010c31d2014-09-26 10:01:12 -0700635 .portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700636 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800637 case IN_PHY_PORT:
638 builder.matchInPhyPort(PortNumber
639 .portNumber(match.get(MatchField.IN_PHY_PORT).getPortNumber()));
640 break;
641 case METADATA:
642 long metadata =
643 match.get(MatchField.METADATA).getValue().getValue();
644 builder.matchMetadata(metadata);
645 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700646 case ETH_DST:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800647 if (match.isPartiallyMasked(MatchField.ETH_DST)) {
648 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
649 match.getMasked(MatchField.ETH_DST);
650 builder.matchEthDstMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
651 MacAddress.valueOf(maskedMac.getMask().getLong()));
652 } else {
653 mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
654 builder.matchEthDst(mac);
655 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800656 break;
657 case ETH_SRC:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800658 if (match.isPartiallyMasked(MatchField.ETH_SRC)) {
659 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
660 match.getMasked(MatchField.ETH_SRC);
661 builder.matchEthSrcMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
662 MacAddress.valueOf(maskedMac.getMask().getLong()));
663 } else {
664 mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
665 builder.matchEthSrc(mac);
666 }
alshabib6b5cfec2014-09-18 17:42:18 -0700667 break;
668 case ETH_TYPE:
669 int ethType = match.get(MatchField.ETH_TYPE).getValue();
Jonathan Hart8cf212a2015-10-29 17:42:03 -0700670 builder.matchEthType((short) ethType);
alshabib6b5cfec2014-09-18 17:42:18 -0700671 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700672 case VLAN_VID:
Charles Chan14967c22015-12-07 11:11:50 -0800673 if (selectorInterpreter != null &&
674 selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
675 if (match.getVersion().equals(OFVersion.OF_13)) {
676 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.VLAN_VID);
677 builder.extension(selectorInterpreter.mapOxm(oxm),
Jonathan Harte4e74f02016-03-03 12:57:40 -0800678 deviceId);
Charles Chan14967c22015-12-07 11:11:50 -0800679 } else {
680 break;
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800681 }
682 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800683 VlanId vlanId = null;
684 if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
685 Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
686 if (masked.getValue().equals(OFVlanVidMatch.PRESENT)
687 && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
688 vlanId = VlanId.ANY;
689 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700690 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800691 if (!match.get(MatchField.VLAN_VID).isPresentBitSet()) {
692 vlanId = VlanId.NONE;
693 } else {
694 vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
695 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700696 }
Charles Chan14967c22015-12-07 11:11:50 -0800697 if (vlanId != null) {
698 builder.matchVlanId(vlanId);
699 }
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800700 }
alshabib6b5cfec2014-09-18 17:42:18 -0700701 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800702 case VLAN_PCP:
703 byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
704 builder.matchVlanPcp(vlanPcp);
705 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800706 case IP_DSCP:
707 byte ipDscp = match.get(MatchField.IP_DSCP).getDscpValue();
708 builder.matchIPDscp(ipDscp);
709 break;
710 case IP_ECN:
711 byte ipEcn = match.get(MatchField.IP_ECN).getEcnValue();
712 builder.matchIPEcn(ipEcn);
713 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800714 case IP_PROTO:
715 short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
716 builder.matchIPProtocol((byte) proto);
717 break;
718 case IPV4_SRC:
719 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
720 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800721 ip4Prefix = Ip4Prefix.valueOf(
722 maskedIp.getValue().getInt(),
723 maskedIp.getMask().asCidrMaskLength());
724 } else {
725 ip4Prefix = Ip4Prefix.valueOf(
726 match.get(MatchField.IPV4_SRC).getInt(),
727 Ip4Prefix.MAX_MASK_LENGTH);
728 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800729 builder.matchIPSrc(ip4Prefix);
730 break;
731 case IPV4_DST:
732 if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
733 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800734 ip4Prefix = Ip4Prefix.valueOf(
735 maskedIp.getValue().getInt(),
736 maskedIp.getMask().asCidrMaskLength());
737 } else {
738 ip4Prefix = Ip4Prefix.valueOf(
739 match.get(MatchField.IPV4_DST).getInt(),
740 Ip4Prefix.MAX_MASK_LENGTH);
741 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800742 builder.matchIPDst(ip4Prefix);
Jonathan Hart34bc6142014-10-17 11:00:43 -0700743 break;
744 case TCP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700745 builder.matchTcpSrc(TpPort.tpPort(match.get(MatchField.TCP_SRC).getPort()));
Jonathan Hart34bc6142014-10-17 11:00:43 -0700746 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800747 case TCP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700748 builder.matchTcpDst(TpPort.tpPort(match.get(MatchField.TCP_DST).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800749 break;
750 case UDP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700751 builder.matchUdpSrc(TpPort.tpPort(match.get(MatchField.UDP_SRC).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800752 break;
753 case UDP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700754 builder.matchUdpDst(TpPort.tpPort(match.get(MatchField.UDP_DST).getPort()));
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700755 break;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100756 case MPLS_LABEL:
757 builder.matchMplsLabel(MplsLabel.mplsLabel((int) match.get(MatchField.MPLS_LABEL)
758 .getValue()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800759 break;
Saurav Dasffc5bbc2015-08-18 23:30:19 -0700760 case MPLS_BOS:
761 builder.matchMplsBos(match.get(MatchField.MPLS_BOS).getValue());
762 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800763 case SCTP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700764 builder.matchSctpSrc(TpPort.tpPort(match.get(MatchField.SCTP_SRC).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800765 break;
766 case SCTP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700767 builder.matchSctpDst(TpPort.tpPort(match.get(MatchField.SCTP_DST).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800768 break;
769 case ICMPV4_TYPE:
770 byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
771 builder.matchIcmpType(icmpType);
772 break;
773 case ICMPV4_CODE:
774 byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode();
775 builder.matchIcmpCode(icmpCode);
776 break;
777 case IPV6_SRC:
778 if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
779 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
780 ip6Prefix = Ip6Prefix.valueOf(
781 maskedIp.getValue().getBytes(),
782 maskedIp.getMask().asCidrMaskLength());
783 } else {
784 ip6Prefix = Ip6Prefix.valueOf(
785 match.get(MatchField.IPV6_SRC).getBytes(),
786 Ip6Prefix.MAX_MASK_LENGTH);
787 }
788 builder.matchIPv6Src(ip6Prefix);
789 break;
790 case IPV6_DST:
791 if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
792 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
793 ip6Prefix = Ip6Prefix.valueOf(
794 maskedIp.getValue().getBytes(),
795 maskedIp.getMask().asCidrMaskLength());
796 } else {
797 ip6Prefix = Ip6Prefix.valueOf(
798 match.get(MatchField.IPV6_DST).getBytes(),
799 Ip6Prefix.MAX_MASK_LENGTH);
800 }
801 builder.matchIPv6Dst(ip6Prefix);
802 break;
803 case IPV6_FLABEL:
804 int flowLabel =
805 match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue();
806 builder.matchIPv6FlowLabel(flowLabel);
807 break;
808 case ICMPV6_TYPE:
809 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
810 builder.matchIcmpv6Type(icmpv6type);
811 break;
812 case ICMPV6_CODE:
813 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
814 builder.matchIcmpv6Code(icmpv6code);
815 break;
816 case IPV6_ND_TARGET:
817 ip6Address =
818 Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes());
819 builder.matchIPv6NDTargetAddress(ip6Address);
820 break;
821 case IPV6_ND_SLL:
822 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong());
823 builder.matchIPv6NDSourceLinkLayerAddress(mac);
824 break;
825 case IPV6_ND_TLL:
826 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong());
827 builder.matchIPv6NDTargetLinkLayerAddress(mac);
828 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800829 case IPV6_EXTHDR:
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800830 builder.matchIPv6ExthdrFlags((short) match.get(MatchField.IPV6_EXTHDR)
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700831 .getValue());
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800832 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700833 case OCH_SIGID:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700834 CircuitSignalID sigId = match.get(MatchField.OCH_SIGID);
835 builder.add(matchLambda(Lambda.ochSignal(
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700836 lookupGridType(sigId.getGridType()), lookupChannelSpacing(sigId.getChannelSpacing()),
Marc De Leenheer0b8b2ef2015-08-03 15:39:00 -0700837 sigId.getChannelNumber(), sigId.getSpectralWidth())
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700838 ));
Marc De Leenheer49087752014-10-23 13:54:09 -0700839 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800840 case OCH_SIGTYPE:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700841 U8 sigType = match.get(MatchField.OCH_SIGTYPE);
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700842 builder.add(matchOchSignalType(lookupOchSignalType((byte) sigType.getValue())));
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800843 break;
Yafit Hadar73514612015-11-04 10:14:21 +0200844 case EXP_OCH_SIG_ID:
845 try {
846 CircuitSignalID expSigId = match.get(MatchField.EXP_OCH_SIG_ID);
847 builder.add(matchLambda(Lambda.ochSignal(
848 lookupGridType(expSigId.getGridType()), lookupChannelSpacing(expSigId.getChannelSpacing()),
849 expSigId.getChannelNumber(), expSigId.getSpectralWidth())));
850 } catch (NoMappingFoundException e) {
851 log.warn(e.getMessage());
852 break;
853 }
854 break;
855 case EXP_OCH_SIGTYPE:
856 try {
857 U8 expOchSigType = match.get(MatchField.EXP_OCH_SIGTYPE);
858 builder.add(matchOchSignalType(lookupOchSignalType((byte) expOchSigType.getValue())));
859 } catch (NoMappingFoundException e) {
860 log.warn(e.getMessage());
861 break;
862 }
863 break;
864 case EXP_ODU_SIG_ID:
865 OduSignalId oduSignalId = OduSignalId.oduSignalId(match.get(MatchField.EXP_ODU_SIG_ID).getTpn(),
866 match.get(MatchField.EXP_ODU_SIG_ID).getTslen(),
867 match.get(MatchField.EXP_ODU_SIG_ID).getTsmap());
868 builder.add(matchOduSignalId(oduSignalId));
869 break;
870 case EXP_ODU_SIGTYPE:
871 try {
872 U8 oduSigType = match.get(MatchField.EXP_ODU_SIGTYPE);
873 builder.add(matchOduSignalType(lookupOduSignalType((byte) oduSigType.getValue())));
874 } catch (NoMappingFoundException e) {
875 log.warn(e.getMessage());
876 break;
877 }
878 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700879 case TUNNEL_ID:
880 long tunnelId = match.get(MatchField.TUNNEL_ID).getValue();
881 builder.matchTunnelId(tunnelId);
882 break;
BitOhenryb40129a2015-11-30 12:41:18 +0800883 case ARP_OP:
884 int arpOp = match.get(MatchField.ARP_OP).getOpcode();
885 builder.matchArpOp(arpOp);
886 break;
BitOhenrya331b182015-11-23 08:39:37 +0800887 case ARP_SHA:
888 mac = MacAddress.valueOf(match.get(MatchField.ARP_SHA).getLong());
889 builder.matchArpSha(mac);
890 break;
BitOhenry296b4542015-11-24 08:41:58 +0800891 case ARP_SPA:
892 ip = Ip4Address.valueOf(match.get(MatchField.ARP_SPA).getInt());
893 builder.matchArpSpa(ip);
894 break;
BitOhenry76430852015-11-20 19:04:49 +0800895 case ARP_THA:
896 mac = MacAddress.valueOf(match.get(MatchField.ARP_THA).getLong());
897 builder.matchArpTha(mac);
898 break;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800899 case ARP_TPA:
900 ip = Ip4Address.valueOf(match.get(MatchField.ARP_TPA).getInt());
901 builder.matchArpTpa(ip);
902 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700903 case MPLS_TC:
alshabib6b5cfec2014-09-18 17:42:18 -0700904 default:
905 log.warn("Match type {} not yet implemented.", field.id);
alshabib6b5cfec2014-09-18 17:42:18 -0700906 }
907 }
908 return builder.build();
909 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700910
Jian Liffef5002016-04-04 23:27:37 -0700911 private DriverHandler getDriver(DeviceId devId) {
912 Driver driver = driverService.getDriver(devId);
913 DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, devId));
Jonathan Hart3c259162015-10-21 21:31:19 -0700914 return handler;
915 }
alshabib6b5cfec2014-09-18 17:42:18 -0700916}