blob: b75954fd8413143dbbe5c25d028bcdc5544ca548 [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 Open Networking Laboratory
Thomas Vachuska781d18b2014-10-27 10:31:25 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Thomas Vachuska781d18b2014-10-27 10:31:25 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
Thomas Vachuska781d18b2014-10-27 10:31:25 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.provider.of.flow.impl;
alshabib6b5cfec2014-09-18 17:42:18 -070017
Jonathan Hart8cf212a2015-10-29 17:42:03 -070018import com.google.common.collect.Lists;
Ray Milkey84d5a292016-02-22 14:04:01 -080019import org.onlab.packet.EthType;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080020import org.onlab.packet.Ip4Address;
21import org.onlab.packet.Ip4Prefix;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080022import org.onlab.packet.Ip6Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080023import org.onlab.packet.Ip6Prefix;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080024import org.onlab.packet.MacAddress;
Michele Santuari4b6019e2014-12-19 11:31:45 +010025import org.onlab.packet.MplsLabel;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -070026import org.onlab.packet.TpPort;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080027import org.onlab.packet.VlanId;
sangho8995ac52015-02-04 11:29:03 -080028import org.onosproject.core.DefaultGroupId;
Brian O'Connorabafb502014-12-02 22:26:20 -080029import org.onosproject.net.DeviceId;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070030import org.onosproject.net.Lambda;
Yafit Hadar73514612015-11-04 10:14:21 +020031import org.onosproject.net.OduSignalId;
Brian O'Connorabafb502014-12-02 22:26:20 -080032import org.onosproject.net.PortNumber;
Jonathan Hart3c259162015-10-21 21:31:19 -070033import org.onosproject.net.driver.DefaultDriverData;
34import org.onosproject.net.driver.DefaultDriverHandler;
35import org.onosproject.net.driver.Driver;
36import org.onosproject.net.driver.DriverHandler;
37import org.onosproject.net.driver.DriverService;
Brian O'Connorabafb502014-12-02 22:26:20 -080038import org.onosproject.net.flow.DefaultFlowEntry;
39import org.onosproject.net.flow.DefaultFlowRule;
40import org.onosproject.net.flow.DefaultTrafficSelector;
41import org.onosproject.net.flow.DefaultTrafficTreatment;
42import org.onosproject.net.flow.FlowEntry;
43import org.onosproject.net.flow.FlowEntry.FlowEntryState;
44import org.onosproject.net.flow.FlowRule;
45import org.onosproject.net.flow.TrafficSelector;
46import org.onosproject.net.flow.TrafficTreatment;
Charles Chan14967c22015-12-07 11:11:50 -080047import org.onosproject.net.flow.criteria.ExtensionSelectorType.ExtensionSelectorTypes;
48import org.onosproject.net.flow.instructions.ExtensionTreatmentType.ExtensionTreatmentTypes;
Sho SHIMIZU9553bb82015-06-30 16:02:45 -070049import org.onosproject.net.flow.instructions.Instructions;
Charles Chan14967c22015-12-07 11:11:50 -080050import org.onosproject.openflow.controller.ExtensionSelectorInterpreter;
alshabib880b6442015-11-23 22:13:04 -080051import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter;
Brian O'Connor72cb19a2015-01-16 16:14:41 -080052import org.projectfloodlight.openflow.protocol.OFFlowMod;
alshabib6b5cfec2014-09-18 17:42:18 -070053import org.projectfloodlight.openflow.protocol.OFFlowRemoved;
54import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry;
Charles Chan14967c22015-12-07 11:11:50 -080055import org.projectfloodlight.openflow.protocol.OFMatchV3;
Brian O'Connor21564612015-12-05 19:24:59 -080056import org.projectfloodlight.openflow.protocol.OFVersion;
alshabib6b5cfec2014-09-18 17:42:18 -070057import org.projectfloodlight.openflow.protocol.action.OFAction;
Marc De Leenheer49087752014-10-23 13:54:09 -070058import org.projectfloodlight.openflow.protocol.action.OFActionCircuit;
Steffen Gebertba2d3b72015-10-22 11:14:31 +020059import org.projectfloodlight.openflow.protocol.action.OFActionEnqueue;
Marc De Leenheer49087752014-10-23 13:54:09 -070060import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter;
sangho8995ac52015-02-04 11:29:03 -080061import org.projectfloodlight.openflow.protocol.action.OFActionGroup;
alshabib6b5cfec2014-09-18 17:42:18 -070062import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
sangho3f97a17d2015-01-29 22:56:29 -080063import org.projectfloodlight.openflow.protocol.action.OFActionPopMpls;
alshabib6b5cfec2014-09-18 17:42:18 -070064import org.projectfloodlight.openflow.protocol.action.OFActionSetDlDst;
65import org.projectfloodlight.openflow.protocol.action.OFActionSetDlSrc;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080066import org.projectfloodlight.openflow.protocol.action.OFActionSetField;
alshabib6b5cfec2014-09-18 17:42:18 -070067import org.projectfloodlight.openflow.protocol.action.OFActionSetNwDst;
68import org.projectfloodlight.openflow.protocol.action.OFActionSetNwSrc;
Jonathan Hart8cf212a2015-10-29 17:42:03 -070069import org.projectfloodlight.openflow.protocol.action.OFActionSetQueue;
alshabib6b5cfec2014-09-18 17:42:18 -070070import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanPcp;
71import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanVid;
alshabib19fdc122014-10-03 11:38:19 -070072import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
Jonathan Hartcf783202014-11-24 18:55:42 -080073import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions;
alshabibbdcbb102015-04-22 14:16:38 -070074import org.projectfloodlight.openflow.protocol.instruction.OFInstructionGotoTable;
alshabib346b5b32015-03-06 00:42:16 -080075import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteActions;
Saurav Das86af8f12015-05-25 23:55:33 -070076import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteMetadata;
alshabib6b5cfec2014-09-18 17:42:18 -070077import org.projectfloodlight.openflow.protocol.match.Match;
78import org.projectfloodlight.openflow.protocol.match.MatchField;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080079import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
Yafit Hadar4cc65f72016-02-10 11:23:06 +020080import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigid;
alshabib346b5b32015-03-06 00:42:16 -080081import org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070082import org.projectfloodlight.openflow.types.CircuitSignalID;
alshabib6b5cfec2014-09-18 17:42:18 -070083import org.projectfloodlight.openflow.types.IPv4Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080084import org.projectfloodlight.openflow.types.IPv6Address;
Jonathan Hart0e12fad2014-10-17 14:54:58 -070085import org.projectfloodlight.openflow.types.Masked;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080086import org.projectfloodlight.openflow.types.OFVlanVidMatch;
Jonathan Harte4e74f02016-03-03 12:57:40 -080087import org.projectfloodlight.openflow.types.OduSignalID;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -070088import org.projectfloodlight.openflow.types.TransportPort;
sangho3f97a17d2015-01-29 22:56:29 -080089import org.projectfloodlight.openflow.types.U32;
Hyunsun Moona08c5d02015-07-14 17:53:00 -070090import org.projectfloodlight.openflow.types.U64;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070091import org.projectfloodlight.openflow.types.U8;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080092import org.projectfloodlight.openflow.types.VlanPcp;
alshabib6b5cfec2014-09-18 17:42:18 -070093import org.slf4j.Logger;
94
Jonathan Hart8cf212a2015-10-29 17:42:03 -070095import java.util.List;
96
97import static org.onosproject.net.flow.criteria.Criteria.matchLambda;
98import static org.onosproject.net.flow.criteria.Criteria.matchOchSignalType;
Yafit Hadar73514612015-11-04 10:14:21 +020099import static org.onosproject.net.flow.criteria.Criteria.matchOduSignalId;
Jonathan Harte4e74f02016-03-03 12:57:40 -0800100import static org.onosproject.net.flow.criteria.Criteria.matchOduSignalType;
Yafit Hadar73514612015-11-04 10:14:21 +0200101import static org.onosproject.net.flow.instructions.Instructions.modL0Lambda;
102import static org.onosproject.net.flow.instructions.Instructions.modL1OduSignalId;
Jonathan Hart8cf212a2015-10-29 17:42:03 -0700103import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupChannelSpacing;
104import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupGridType;
105import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupOchSignalType;
Yafit Hadar73514612015-11-04 10:14:21 +0200106import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupOduSignalType;
Jonathan Hart8cf212a2015-10-29 17:42:03 -0700107import static org.slf4j.LoggerFactory.getLogger;
alshabib19fdc122014-10-03 11:38:19 -0700108
alshabib1c319ff2014-10-04 20:29:09 -0700109public class FlowEntryBuilder {
alshabib6b5cfec2014-09-18 17:42:18 -0700110 private final Logger log = getLogger(getClass());
111
112 private final OFFlowStatsEntry stat;
113 private final OFFlowRemoved removed;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800114 private final OFFlowMod flowMod;
alshabib6b5cfec2014-09-18 17:42:18 -0700115
116 private final Match match;
alshabib346b5b32015-03-06 00:42:16 -0800117
Jonathan Hart67fc0972015-03-19 15:21:20 -0700118 // All actions are contained in an OFInstruction. For OF1.0
119 // the instruction type is apply instruction (immediate set in ONOS speak)
alshabib346b5b32015-03-06 00:42:16 -0800120 private final List<OFInstruction> instructions;
alshabib6b5cfec2014-09-18 17:42:18 -0700121
Jonathan Harte4e74f02016-03-03 12:57:40 -0800122 private final DeviceId deviceId;
alshabib6b5cfec2014-09-18 17:42:18 -0700123
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800124 public enum FlowType { STAT, REMOVED, MOD }
125
126 private final FlowType type;
alshabib6b5cfec2014-09-18 17:42:18 -0700127
Jonathan Hart3c259162015-10-21 21:31:19 -0700128 private final DriverService driverService;
129
Jonathan Harte4e74f02016-03-03 12:57:40 -0800130 public FlowEntryBuilder(DeviceId deviceId, OFFlowStatsEntry entry, DriverService driverService) {
Saurav Dasfa2fa932015-03-03 11:29:48 -0800131 this.stat = entry;
132 this.match = entry.getMatch();
alshabib346b5b32015-03-06 00:42:16 -0800133 this.instructions = getInstructions(entry);
Jonathan Harte4e74f02016-03-03 12:57:40 -0800134 this.deviceId = deviceId;
Saurav Dasfa2fa932015-03-03 11:29:48 -0800135 this.removed = null;
136 this.flowMod = null;
137 this.type = FlowType.STAT;
Jonathan Hart3c259162015-10-21 21:31:19 -0700138 this.driverService = driverService;
Saurav Dasfa2fa932015-03-03 11:29:48 -0800139 }
140
Jonathan Harte4e74f02016-03-03 12:57:40 -0800141 public FlowEntryBuilder(DeviceId deviceId, OFFlowRemoved removed, DriverService driverService) {
alshabib6b5cfec2014-09-18 17:42:18 -0700142 this.match = removed.getMatch();
143 this.removed = removed;
Jonathan Harte4e74f02016-03-03 12:57:40 -0800144 this.deviceId = deviceId;
alshabib346b5b32015-03-06 00:42:16 -0800145 this.instructions = null;
alshabib6b5cfec2014-09-18 17:42:18 -0700146 this.stat = null;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800147 this.flowMod = null;
148 this.type = FlowType.REMOVED;
Jonathan Hart3c259162015-10-21 21:31:19 -0700149 this.driverService = driverService;
alshabib6b5cfec2014-09-18 17:42:18 -0700150 }
151
Jonathan Harte4e74f02016-03-03 12:57:40 -0800152 public FlowEntryBuilder(DeviceId deviceId, OFFlowMod fm, DriverService driverService) {
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800153 this.match = fm.getMatch();
Jonathan Harte4e74f02016-03-03 12:57:40 -0800154 this.deviceId = deviceId;
alshabib346b5b32015-03-06 00:42:16 -0800155 this.instructions = getInstructions(fm);
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800156 this.type = FlowType.MOD;
157 this.flowMod = fm;
158 this.stat = null;
159 this.removed = null;
Jonathan Hart3c259162015-10-21 21:31:19 -0700160 this.driverService = driverService;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800161 }
alshabib1c319ff2014-10-04 20:29:09 -0700162
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800163 public FlowEntry build(FlowEntryState... state) {
Brian O'Connor21564612015-12-05 19:24:59 -0800164 FlowRule.Builder builder;
165 try {
166 switch (this.type) {
167 case STAT:
168 builder = DefaultFlowRule.builder()
Jonathan Harte4e74f02016-03-03 12:57:40 -0800169 .forDevice(deviceId)
Brian O'Connor21564612015-12-05 19:24:59 -0800170 .withSelector(buildSelector())
171 .withTreatment(buildTreatment())
172 .withPriority(stat.getPriority())
173 .makeTemporary(stat.getIdleTimeout())
Jonathan Hartd1ce4b02016-01-11 13:28:36 -0800174 .withCookie(stat.getCookie().getValue());
175 if (stat.getVersion() != OFVersion.OF_10) {
176 builder.forTable(stat.getTableId().getValue());
177 }
alshabibbdcbb102015-04-22 14:16:38 -0700178
Brian O'Connor21564612015-12-05 19:24:59 -0800179 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
180 stat.getDurationSec(),
181 stat.getPacketCount().getValue(),
182 stat.getByteCount().getValue());
183 case REMOVED:
184 builder = DefaultFlowRule.builder()
Jonathan Harte4e74f02016-03-03 12:57:40 -0800185 .forDevice(deviceId)
Brian O'Connor21564612015-12-05 19:24:59 -0800186 .withSelector(buildSelector())
187 .withPriority(removed.getPriority())
188 .makeTemporary(removed.getIdleTimeout())
189 .withCookie(removed.getCookie().getValue());
190 if (removed.getVersion() != OFVersion.OF_10) {
191 builder.forTable(removed.getTableId().getValue());
192 }
alshabibbdcbb102015-04-22 14:16:38 -0700193
Brian O'Connor21564612015-12-05 19:24:59 -0800194 return new DefaultFlowEntry(builder.build(), FlowEntryState.REMOVED,
195 removed.getDurationSec(),
196 removed.getPacketCount().getValue(),
197 removed.getByteCount().getValue());
198 case MOD:
199 FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED;
200 builder = DefaultFlowRule.builder()
Jonathan Harte4e74f02016-03-03 12:57:40 -0800201 .forDevice(deviceId)
Brian O'Connor21564612015-12-05 19:24:59 -0800202 .withSelector(buildSelector())
203 .withTreatment(buildTreatment())
204 .withPriority(flowMod.getPriority())
205 .makeTemporary(flowMod.getIdleTimeout())
206 .withCookie(flowMod.getCookie().getValue());
207 if (flowMod.getVersion() != OFVersion.OF_10) {
208 builder.forTable(flowMod.getTableId().getValue());
209 }
alshabibbdcbb102015-04-22 14:16:38 -0700210
Brian O'Connor21564612015-12-05 19:24:59 -0800211 return new DefaultFlowEntry(builder.build(), flowState, 0, 0, 0);
212 default:
213 log.error("Unknown flow type : {}", this.type);
214 return null;
215 }
216 } catch (UnsupportedOperationException e) {
217 log.warn("Error building flow entry", e);
218 return null;
alshabib6b5cfec2014-09-18 17:42:18 -0700219 }
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800220
alshabib6b5cfec2014-09-18 17:42:18 -0700221 }
222
alshabib346b5b32015-03-06 00:42:16 -0800223 private List<OFInstruction> getInstructions(OFFlowMod entry) {
alshabib19fdc122014-10-03 11:38:19 -0700224 switch (entry.getVersion()) {
225 case OF_10:
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700226 return Lists.newArrayList(OFFactoryVer13.INSTANCE.instructions()
227 .applyActions(
228 entry.getActions()));
alshabib19fdc122014-10-03 11:38:19 -0700229 case OF_11:
230 case OF_12:
231 case OF_13:
alshabib346b5b32015-03-06 00:42:16 -0800232 return entry.getInstructions();
233 default:
234 log.warn("Unknown OF version {}", entry.getVersion());
235 }
236 return Lists.newLinkedList();
237 }
238
239 private List<OFInstruction> getInstructions(OFFlowStatsEntry entry) {
240 switch (entry.getVersion()) {
241 case OF_10:
242 return Lists.newArrayList(
243 OFFactoryVer13.INSTANCE.instructions().applyActions(entry.getActions()));
244 case OF_11:
245 case OF_12:
246 case OF_13:
247 return entry.getInstructions();
alshabib19fdc122014-10-03 11:38:19 -0700248 default:
249 log.warn("Unknown OF version {}", entry.getVersion());
250 }
251 return Lists.newLinkedList();
252 }
alshabib6b5cfec2014-09-18 17:42:18 -0700253
254 private TrafficTreatment buildTreatment() {
tom9a693fd2014-10-03 11:32:19 -0700255 TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
alshabib346b5b32015-03-06 00:42:16 -0800256 for (OFInstruction in : instructions) {
257 switch (in.getType()) {
258 case GOTO_TABLE:
alshabibbdcbb102015-04-22 14:16:38 -0700259 builder.transition(((int) ((OFInstructionGotoTable) in)
260 .getTableId().getValue()));
alshabib346b5b32015-03-06 00:42:16 -0800261 break;
262 case WRITE_METADATA:
Saurav Das86af8f12015-05-25 23:55:33 -0700263 OFInstructionWriteMetadata m = (OFInstructionWriteMetadata) in;
264 builder.writeMetadata(m.getMetadata().getValue(),
265 m.getMetadataMask().getValue());
alshabib346b5b32015-03-06 00:42:16 -0800266 break;
267 case WRITE_ACTIONS:
268 builder.deferred();
269 buildActions(((OFInstructionWriteActions) in).getActions(),
270 builder);
271 break;
272 case APPLY_ACTIONS:
273 builder.immediate();
274 buildActions(((OFInstructionApplyActions) in).getActions(),
275 builder);
276 break;
277 case CLEAR_ACTIONS:
278 builder.wipeDeferred();
279 break;
280 case EXPERIMENTER:
281 break;
282 case METER:
283 break;
284 default:
285 log.warn("Unknown instructions type {}", in.getType());
alshabib6b5cfec2014-09-18 17:42:18 -0700286 }
287 }
288
289 return builder.build();
290 }
291
alshabib346b5b32015-03-06 00:42:16 -0800292 private TrafficTreatment.Builder buildActions(List<OFAction> actions,
293 TrafficTreatment.Builder builder) {
Jonathan Harte4e74f02016-03-03 12:57:40 -0800294 DriverHandler driverHandler = getDriver(deviceId);
Charles Chan14967c22015-12-07 11:11:50 -0800295 ExtensionTreatmentInterpreter treatmentInterpreter;
296 if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
297 treatmentInterpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class);
298 } else {
299 treatmentInterpreter = null;
300 }
301
alshabib346b5b32015-03-06 00:42:16 -0800302 for (OFAction act : actions) {
303 switch (act.getType()) {
304 case OUTPUT:
305 OFActionOutput out = (OFActionOutput) act;
306 builder.setOutput(
307 PortNumber.portNumber(out.getPort().getPortNumber()));
308 break;
309 case SET_VLAN_VID:
310 OFActionSetVlanVid vlan = (OFActionSetVlanVid) act;
311 builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan()));
312 break;
313 case SET_VLAN_PCP:
314 OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act;
315 builder.setVlanPcp(pcp.getVlanPcp().getValue());
316 break;
317 case SET_DL_DST:
318 OFActionSetDlDst dldst = (OFActionSetDlDst) act;
319 builder.setEthDst(
320 MacAddress.valueOf(dldst.getDlAddr().getLong()));
321 break;
322 case SET_DL_SRC:
323 OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act;
324 builder.setEthSrc(
325 MacAddress.valueOf(dlsrc.getDlAddr().getLong()));
alshabib346b5b32015-03-06 00:42:16 -0800326 break;
327 case SET_NW_DST:
328 OFActionSetNwDst nwdst = (OFActionSetNwDst) act;
329 IPv4Address di = nwdst.getNwAddr();
330 builder.setIpDst(Ip4Address.valueOf(di.getInt()));
331 break;
332 case SET_NW_SRC:
333 OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act;
334 IPv4Address si = nwsrc.getNwAddr();
335 builder.setIpSrc(Ip4Address.valueOf(si.getInt()));
336 break;
337 case EXPERIMENTER:
338 OFActionExperimenter exp = (OFActionExperimenter) act;
339 if (exp.getExperimenter() == 0x80005A06 ||
340 exp.getExperimenter() == 0x748771) {
341 OFActionCircuit ct = (OFActionCircuit) exp;
Yafit Hadar4cc65f72016-02-10 11:23:06 +0200342 CircuitSignalID circuitSignalID = ((OFOxmOchSigid) ct.getField()).getValue();
343 builder.add(Instructions.modL0Lambda(Lambda.ochSignal(
344 lookupGridType(circuitSignalID.getGridType()),
345 lookupChannelSpacing(circuitSignalID.getChannelSpacing()),
346 circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth())));
Jian Lid4163882016-03-30 20:03:14 -0700347 } else if (treatmentInterpreter != null) {
348 builder.extension(treatmentInterpreter.mapAction(exp), deviceId);
alshabib346b5b32015-03-06 00:42:16 -0800349 } else {
350 log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter());
351 }
352 break;
353 case SET_FIELD:
354 OFActionSetField setField = (OFActionSetField) act;
Jonathan Hart3c259162015-10-21 21:31:19 -0700355 handleSetField(builder, setField);
alshabib346b5b32015-03-06 00:42:16 -0800356 break;
357 case POP_MPLS:
358 OFActionPopMpls popMpls = (OFActionPopMpls) act;
Ray Milkey84d5a292016-02-22 14:04:01 -0800359 builder.popMpls(new EthType(popMpls.getEthertype().getValue()));
alshabib346b5b32015-03-06 00:42:16 -0800360 break;
361 case PUSH_MPLS:
362 builder.pushMpls();
363 break;
364 case COPY_TTL_IN:
365 builder.copyTtlIn();
366 break;
367 case COPY_TTL_OUT:
368 builder.copyTtlOut();
369 break;
370 case DEC_MPLS_TTL:
371 builder.decMplsTtl();
372 break;
373 case DEC_NW_TTL:
374 builder.decNwTtl();
375 break;
376 case GROUP:
377 OFActionGroup group = (OFActionGroup) act;
378 builder.group(new DefaultGroupId(group.getGroup().getGroupNumber()));
379 break;
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200380 case SET_QUEUE:
381 OFActionSetQueue setQueue = (OFActionSetQueue) act;
382 builder.setQueue(setQueue.getQueueId());
383 break;
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200384 case ENQUEUE:
385 OFActionEnqueue enqueue = (OFActionEnqueue) act;
386 builder.setQueue(enqueue.getQueueId(), PortNumber.portNumber(enqueue.getPort().getPortNumber()));
387 break;
Jonathan Hart67fc0972015-03-19 15:21:20 -0700388 case STRIP_VLAN:
alshabib346b5b32015-03-06 00:42:16 -0800389 case POP_VLAN:
390 builder.popVlan();
391 break;
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700392 case PUSH_VLAN:
393 builder.pushVlan();
394 break;
alshabib346b5b32015-03-06 00:42:16 -0800395 case SET_TP_DST:
396 case SET_TP_SRC:
397 case POP_PBB:
398 case PUSH_PBB:
alshabib346b5b32015-03-06 00:42:16 -0800399 case SET_MPLS_LABEL:
400 case SET_MPLS_TC:
401 case SET_MPLS_TTL:
402 case SET_NW_ECN:
403 case SET_NW_TOS:
404 case SET_NW_TTL:
alshabib346b5b32015-03-06 00:42:16 -0800405
alshabib346b5b32015-03-06 00:42:16 -0800406 default:
407 log.warn("Action type {} not yet implemented.", act.getType());
408 }
409 }
410 return builder;
411 }
412
413
Jonathan Hart3c259162015-10-21 21:31:19 -0700414 private void handleSetField(TrafficTreatment.Builder builder, OFActionSetField action) {
Jonathan Harte4e74f02016-03-03 12:57:40 -0800415 DriverHandler driverHandler = getDriver(deviceId);
Charles Chan14967c22015-12-07 11:11:50 -0800416 ExtensionTreatmentInterpreter treatmentInterpreter;
417 if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
418 treatmentInterpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class);
419 } else {
420 treatmentInterpreter = null;
421 }
422
Jonathan Hart3c259162015-10-21 21:31:19 -0700423 OFOxm<?> oxm = action.getField();
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800424 switch (oxm.getMatchField().id) {
425 case VLAN_PCP:
426 @SuppressWarnings("unchecked")
427 OFOxm<VlanPcp> vlanpcp = (OFOxm<VlanPcp>) oxm;
428 builder.setVlanPcp(vlanpcp.getValue().getValue());
429 break;
430 case VLAN_VID:
Charles Chan14967c22015-12-07 11:11:50 -0800431 if (treatmentInterpreter != null &&
432 treatmentInterpreter.supported(ExtensionTreatmentTypes.OFDPA_SET_VLAN_ID.type())) {
433 builder.extension(treatmentInterpreter.mapAction(action),
Jonathan Harte4e74f02016-03-03 12:57:40 -0800434 deviceId);
Charles Chan14967c22015-12-07 11:11:50 -0800435 } else {
436 @SuppressWarnings("unchecked")
437 OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm;
438 builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan()));
439 }
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800440 break;
441 case ETH_DST:
442 @SuppressWarnings("unchecked")
443 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethdst =
444 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
445 builder.setEthDst(MacAddress.valueOf(ethdst.getValue().getLong()));
446 break;
447 case ETH_SRC:
448 @SuppressWarnings("unchecked")
449 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethsrc =
450 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
451 builder.setEthSrc(MacAddress.valueOf(ethsrc.getValue().getLong()));
452 break;
453 case IPV4_DST:
454 @SuppressWarnings("unchecked")
455 OFOxm<IPv4Address> ip4dst = (OFOxm<IPv4Address>) oxm;
456 builder.setIpDst(Ip4Address.valueOf(ip4dst.getValue().getInt()));
457 break;
458 case IPV4_SRC:
459 @SuppressWarnings("unchecked")
460 OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm;
461 builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt()));
462 break;
sangho3f97a17d2015-01-29 22:56:29 -0800463 case MPLS_LABEL:
464 @SuppressWarnings("unchecked")
465 OFOxm<U32> labelId = (OFOxm<U32>) oxm;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100466 builder.setMpls(MplsLabel.mplsLabel((int) labelId.getValue().getValue()));
sangho3f97a17d2015-01-29 22:56:29 -0800467 break;
Saurav Das73a7dd42015-08-19 22:20:31 -0700468 case MPLS_BOS:
469 @SuppressWarnings("unchecked")
470 OFOxm<U8> mplsBos = (OFOxm<U8>) oxm;
471 builder.setMplsBos(mplsBos.getValue() == U8.ZERO ? false : true);
472 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700473 case TUNNEL_ID:
474 @SuppressWarnings("unchecked")
475 OFOxm<U64> tunnelId = (OFOxm<U64>) oxm;
476 builder.setTunnelId(tunnelId.getValue().getValue());
477 break;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700478 case TCP_DST:
479 @SuppressWarnings("unchecked")
480 OFOxm<TransportPort> tcpdst = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700481 builder.setTcpDst(TpPort.tpPort(tcpdst.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700482 break;
483 case TCP_SRC:
484 @SuppressWarnings("unchecked")
485 OFOxm<TransportPort> tcpsrc = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700486 builder.setTcpSrc(TpPort.tpPort(tcpsrc.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700487 break;
488 case UDP_DST:
489 @SuppressWarnings("unchecked")
490 OFOxm<TransportPort> udpdst = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700491 builder.setUdpDst(TpPort.tpPort(udpdst.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700492 break;
493 case UDP_SRC:
494 @SuppressWarnings("unchecked")
495 OFOxm<TransportPort> udpsrc = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700496 builder.setUdpSrc(TpPort.tpPort(udpsrc.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700497 break;
Jonathan Hart3c259162015-10-21 21:31:19 -0700498 case TUNNEL_IPV4_DST:
Charles Chan14967c22015-12-07 11:11:50 -0800499 if (treatmentInterpreter != null &&
500 treatmentInterpreter.supported(ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) {
Jonathan Harte4e74f02016-03-03 12:57:40 -0800501 builder.extension(treatmentInterpreter.mapAction(action), deviceId);
Jonathan Hart3c259162015-10-21 21:31:19 -0700502 }
503 break;
Yafit Hadar73514612015-11-04 10:14:21 +0200504 case EXP_ODU_SIG_ID:
505 @SuppressWarnings("unchecked")
506 OFOxm<OduSignalID> oduID = (OFOxm<OduSignalID>) oxm;
507 OduSignalID oduSignalID = oduID.getValue();
508 OduSignalId oduSignalId = OduSignalId.oduSignalId(oduSignalID.getTpn(),
509 oduSignalID.getTslen(),
510 oduSignalID.getTsmap());
511 builder.add(modL1OduSignalId(oduSignalId));
512 break;
513 case EXP_OCH_SIG_ID:
514 try {
515 @SuppressWarnings("unchecked")
516 OFOxm<CircuitSignalID> ochId = (OFOxm<CircuitSignalID>) oxm;
517 CircuitSignalID circuitSignalID = ochId.getValue();
518 builder.add(modL0Lambda(Lambda.ochSignal(
519 lookupGridType(circuitSignalID.getGridType()),
520 lookupChannelSpacing(circuitSignalID.getChannelSpacing()),
521 circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth())));
522 } catch (NoMappingFoundException e) {
523 log.warn(e.getMessage());
524 break;
525 }
526 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800527 case ARP_OP:
528 case ARP_SHA:
529 case ARP_SPA:
530 case ARP_THA:
531 case ARP_TPA:
532 case BSN_EGR_PORT_GROUP_ID:
533 case BSN_GLOBAL_VRF_ALLOWED:
534 case BSN_IN_PORTS_128:
535 case BSN_L3_DST_CLASS_ID:
536 case BSN_L3_INTERFACE_CLASS_ID:
537 case BSN_L3_SRC_CLASS_ID:
538 case BSN_LAG_ID:
539 case BSN_TCP_FLAGS:
540 case BSN_UDF0:
541 case BSN_UDF1:
542 case BSN_UDF2:
543 case BSN_UDF3:
544 case BSN_UDF4:
545 case BSN_UDF5:
546 case BSN_UDF6:
547 case BSN_UDF7:
548 case BSN_VLAN_XLATE_PORT_GROUP_ID:
549 case BSN_VRF:
550 case ETH_TYPE:
551 case ICMPV4_CODE:
552 case ICMPV4_TYPE:
553 case ICMPV6_CODE:
554 case ICMPV6_TYPE:
555 case IN_PHY_PORT:
556 case IN_PORT:
557 case IPV6_DST:
558 case IPV6_FLABEL:
559 case IPV6_ND_SLL:
560 case IPV6_ND_TARGET:
561 case IPV6_ND_TLL:
562 case IPV6_SRC:
563 case IP_DSCP:
564 case IP_ECN:
565 case IP_PROTO:
566 case METADATA:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800567 case MPLS_TC:
568 case OCH_SIGID:
569 case OCH_SIGID_BASIC:
570 case OCH_SIGTYPE:
571 case OCH_SIGTYPE_BASIC:
572 case SCTP_DST:
573 case SCTP_SRC:
Yafit Hadar73514612015-11-04 10:14:21 +0200574 case EXP_ODU_SIGTYPE:
575 case EXP_OCH_SIGTYPE:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800576 default:
577 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
578 break;
579 }
580 }
581
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700582 // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES
alshabib6b5cfec2014-09-18 17:42:18 -0700583 private TrafficSelector buildSelector() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800584 MacAddress mac;
585 Ip4Prefix ip4Prefix;
586 Ip6Address ip6Address;
587 Ip6Prefix ip6Prefix;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800588 Ip4Address ip;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800589
Jonathan Harte4e74f02016-03-03 12:57:40 -0800590 DriverHandler driverHandler = getDriver(deviceId);
Charles Chan14967c22015-12-07 11:11:50 -0800591 ExtensionSelectorInterpreter selectorInterpreter;
592 if (driverHandler.hasBehaviour(ExtensionSelectorInterpreter.class)) {
593 selectorInterpreter = driverHandler.behaviour(ExtensionSelectorInterpreter.class);
594 } else {
595 selectorInterpreter = null;
596 }
597
tom9a693fd2014-10-03 11:32:19 -0700598 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700599 for (MatchField<?> field : match.getMatchFields()) {
600 switch (field.id) {
601 case IN_PORT:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800602 builder.matchInPort(PortNumber
alshabib010c31d2014-09-26 10:01:12 -0700603 .portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700604 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800605 case IN_PHY_PORT:
606 builder.matchInPhyPort(PortNumber
607 .portNumber(match.get(MatchField.IN_PHY_PORT).getPortNumber()));
608 break;
609 case METADATA:
610 long metadata =
611 match.get(MatchField.METADATA).getValue().getValue();
612 builder.matchMetadata(metadata);
613 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700614 case ETH_DST:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800615 if (match.isPartiallyMasked(MatchField.ETH_DST)) {
616 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
617 match.getMasked(MatchField.ETH_DST);
618 builder.matchEthDstMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
619 MacAddress.valueOf(maskedMac.getMask().getLong()));
620 } else {
621 mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
622 builder.matchEthDst(mac);
623 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800624 break;
625 case ETH_SRC:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800626 if (match.isPartiallyMasked(MatchField.ETH_SRC)) {
627 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
628 match.getMasked(MatchField.ETH_SRC);
629 builder.matchEthSrcMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
630 MacAddress.valueOf(maskedMac.getMask().getLong()));
631 } else {
632 mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
633 builder.matchEthSrc(mac);
634 }
alshabib6b5cfec2014-09-18 17:42:18 -0700635 break;
636 case ETH_TYPE:
637 int ethType = match.get(MatchField.ETH_TYPE).getValue();
Jonathan Hart8cf212a2015-10-29 17:42:03 -0700638 builder.matchEthType((short) ethType);
alshabib6b5cfec2014-09-18 17:42:18 -0700639 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700640 case VLAN_VID:
Charles Chan14967c22015-12-07 11:11:50 -0800641 if (selectorInterpreter != null &&
642 selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
643 if (match.getVersion().equals(OFVersion.OF_13)) {
644 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.VLAN_VID);
645 builder.extension(selectorInterpreter.mapOxm(oxm),
Jonathan Harte4e74f02016-03-03 12:57:40 -0800646 deviceId);
Charles Chan14967c22015-12-07 11:11:50 -0800647 } else {
648 break;
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800649 }
650 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800651 VlanId vlanId = null;
652 if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
653 Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
654 if (masked.getValue().equals(OFVlanVidMatch.PRESENT)
655 && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
656 vlanId = VlanId.ANY;
657 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700658 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800659 if (!match.get(MatchField.VLAN_VID).isPresentBitSet()) {
660 vlanId = VlanId.NONE;
661 } else {
662 vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
663 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700664 }
Charles Chan14967c22015-12-07 11:11:50 -0800665 if (vlanId != null) {
666 builder.matchVlanId(vlanId);
667 }
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800668 }
alshabib6b5cfec2014-09-18 17:42:18 -0700669 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800670 case VLAN_PCP:
671 byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
672 builder.matchVlanPcp(vlanPcp);
673 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800674 case IP_DSCP:
675 byte ipDscp = match.get(MatchField.IP_DSCP).getDscpValue();
676 builder.matchIPDscp(ipDscp);
677 break;
678 case IP_ECN:
679 byte ipEcn = match.get(MatchField.IP_ECN).getEcnValue();
680 builder.matchIPEcn(ipEcn);
681 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800682 case IP_PROTO:
683 short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
684 builder.matchIPProtocol((byte) proto);
685 break;
686 case IPV4_SRC:
687 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
688 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800689 ip4Prefix = Ip4Prefix.valueOf(
690 maskedIp.getValue().getInt(),
691 maskedIp.getMask().asCidrMaskLength());
692 } else {
693 ip4Prefix = Ip4Prefix.valueOf(
694 match.get(MatchField.IPV4_SRC).getInt(),
695 Ip4Prefix.MAX_MASK_LENGTH);
696 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800697 builder.matchIPSrc(ip4Prefix);
698 break;
699 case IPV4_DST:
700 if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
701 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800702 ip4Prefix = Ip4Prefix.valueOf(
703 maskedIp.getValue().getInt(),
704 maskedIp.getMask().asCidrMaskLength());
705 } else {
706 ip4Prefix = Ip4Prefix.valueOf(
707 match.get(MatchField.IPV4_DST).getInt(),
708 Ip4Prefix.MAX_MASK_LENGTH);
709 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800710 builder.matchIPDst(ip4Prefix);
Jonathan Hart34bc6142014-10-17 11:00:43 -0700711 break;
712 case TCP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700713 builder.matchTcpSrc(TpPort.tpPort(match.get(MatchField.TCP_SRC).getPort()));
Jonathan Hart34bc6142014-10-17 11:00:43 -0700714 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800715 case TCP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700716 builder.matchTcpDst(TpPort.tpPort(match.get(MatchField.TCP_DST).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800717 break;
718 case UDP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700719 builder.matchUdpSrc(TpPort.tpPort(match.get(MatchField.UDP_SRC).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800720 break;
721 case UDP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700722 builder.matchUdpDst(TpPort.tpPort(match.get(MatchField.UDP_DST).getPort()));
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700723 break;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100724 case MPLS_LABEL:
725 builder.matchMplsLabel(MplsLabel.mplsLabel((int) match.get(MatchField.MPLS_LABEL)
726 .getValue()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800727 break;
Saurav Dasffc5bbc2015-08-18 23:30:19 -0700728 case MPLS_BOS:
729 builder.matchMplsBos(match.get(MatchField.MPLS_BOS).getValue());
730 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800731 case SCTP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700732 builder.matchSctpSrc(TpPort.tpPort(match.get(MatchField.SCTP_SRC).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800733 break;
734 case SCTP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700735 builder.matchSctpDst(TpPort.tpPort(match.get(MatchField.SCTP_DST).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800736 break;
737 case ICMPV4_TYPE:
738 byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
739 builder.matchIcmpType(icmpType);
740 break;
741 case ICMPV4_CODE:
742 byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode();
743 builder.matchIcmpCode(icmpCode);
744 break;
745 case IPV6_SRC:
746 if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
747 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
748 ip6Prefix = Ip6Prefix.valueOf(
749 maskedIp.getValue().getBytes(),
750 maskedIp.getMask().asCidrMaskLength());
751 } else {
752 ip6Prefix = Ip6Prefix.valueOf(
753 match.get(MatchField.IPV6_SRC).getBytes(),
754 Ip6Prefix.MAX_MASK_LENGTH);
755 }
756 builder.matchIPv6Src(ip6Prefix);
757 break;
758 case IPV6_DST:
759 if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
760 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
761 ip6Prefix = Ip6Prefix.valueOf(
762 maskedIp.getValue().getBytes(),
763 maskedIp.getMask().asCidrMaskLength());
764 } else {
765 ip6Prefix = Ip6Prefix.valueOf(
766 match.get(MatchField.IPV6_DST).getBytes(),
767 Ip6Prefix.MAX_MASK_LENGTH);
768 }
769 builder.matchIPv6Dst(ip6Prefix);
770 break;
771 case IPV6_FLABEL:
772 int flowLabel =
773 match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue();
774 builder.matchIPv6FlowLabel(flowLabel);
775 break;
776 case ICMPV6_TYPE:
777 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
778 builder.matchIcmpv6Type(icmpv6type);
779 break;
780 case ICMPV6_CODE:
781 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
782 builder.matchIcmpv6Code(icmpv6code);
783 break;
784 case IPV6_ND_TARGET:
785 ip6Address =
786 Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes());
787 builder.matchIPv6NDTargetAddress(ip6Address);
788 break;
789 case IPV6_ND_SLL:
790 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong());
791 builder.matchIPv6NDSourceLinkLayerAddress(mac);
792 break;
793 case IPV6_ND_TLL:
794 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong());
795 builder.matchIPv6NDTargetLinkLayerAddress(mac);
796 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800797 case IPV6_EXTHDR:
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800798 builder.matchIPv6ExthdrFlags((short) match.get(MatchField.IPV6_EXTHDR)
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700799 .getValue());
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800800 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700801 case OCH_SIGID:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700802 CircuitSignalID sigId = match.get(MatchField.OCH_SIGID);
803 builder.add(matchLambda(Lambda.ochSignal(
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700804 lookupGridType(sigId.getGridType()), lookupChannelSpacing(sigId.getChannelSpacing()),
Marc De Leenheer0b8b2ef2015-08-03 15:39:00 -0700805 sigId.getChannelNumber(), sigId.getSpectralWidth())
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700806 ));
Marc De Leenheer49087752014-10-23 13:54:09 -0700807 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800808 case OCH_SIGTYPE:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700809 U8 sigType = match.get(MatchField.OCH_SIGTYPE);
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700810 builder.add(matchOchSignalType(lookupOchSignalType((byte) sigType.getValue())));
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800811 break;
Yafit Hadar73514612015-11-04 10:14:21 +0200812 case EXP_OCH_SIG_ID:
813 try {
814 CircuitSignalID expSigId = match.get(MatchField.EXP_OCH_SIG_ID);
815 builder.add(matchLambda(Lambda.ochSignal(
816 lookupGridType(expSigId.getGridType()), lookupChannelSpacing(expSigId.getChannelSpacing()),
817 expSigId.getChannelNumber(), expSigId.getSpectralWidth())));
818 } catch (NoMappingFoundException e) {
819 log.warn(e.getMessage());
820 break;
821 }
822 break;
823 case EXP_OCH_SIGTYPE:
824 try {
825 U8 expOchSigType = match.get(MatchField.EXP_OCH_SIGTYPE);
826 builder.add(matchOchSignalType(lookupOchSignalType((byte) expOchSigType.getValue())));
827 } catch (NoMappingFoundException e) {
828 log.warn(e.getMessage());
829 break;
830 }
831 break;
832 case EXP_ODU_SIG_ID:
833 OduSignalId oduSignalId = OduSignalId.oduSignalId(match.get(MatchField.EXP_ODU_SIG_ID).getTpn(),
834 match.get(MatchField.EXP_ODU_SIG_ID).getTslen(),
835 match.get(MatchField.EXP_ODU_SIG_ID).getTsmap());
836 builder.add(matchOduSignalId(oduSignalId));
837 break;
838 case EXP_ODU_SIGTYPE:
839 try {
840 U8 oduSigType = match.get(MatchField.EXP_ODU_SIGTYPE);
841 builder.add(matchOduSignalType(lookupOduSignalType((byte) oduSigType.getValue())));
842 } catch (NoMappingFoundException e) {
843 log.warn(e.getMessage());
844 break;
845 }
846 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700847 case TUNNEL_ID:
848 long tunnelId = match.get(MatchField.TUNNEL_ID).getValue();
849 builder.matchTunnelId(tunnelId);
850 break;
BitOhenryb40129a2015-11-30 12:41:18 +0800851 case ARP_OP:
852 int arpOp = match.get(MatchField.ARP_OP).getOpcode();
853 builder.matchArpOp(arpOp);
854 break;
BitOhenrya331b182015-11-23 08:39:37 +0800855 case ARP_SHA:
856 mac = MacAddress.valueOf(match.get(MatchField.ARP_SHA).getLong());
857 builder.matchArpSha(mac);
858 break;
BitOhenry296b4542015-11-24 08:41:58 +0800859 case ARP_SPA:
860 ip = Ip4Address.valueOf(match.get(MatchField.ARP_SPA).getInt());
861 builder.matchArpSpa(ip);
862 break;
BitOhenry76430852015-11-20 19:04:49 +0800863 case ARP_THA:
864 mac = MacAddress.valueOf(match.get(MatchField.ARP_THA).getLong());
865 builder.matchArpTha(mac);
866 break;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800867 case ARP_TPA:
868 ip = Ip4Address.valueOf(match.get(MatchField.ARP_TPA).getInt());
869 builder.matchArpTpa(ip);
870 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700871 case MPLS_TC:
alshabib6b5cfec2014-09-18 17:42:18 -0700872 default:
873 log.warn("Match type {} not yet implemented.", field.id);
alshabib6b5cfec2014-09-18 17:42:18 -0700874 }
875 }
876 return builder.build();
877 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700878
Jonathan Harte4e74f02016-03-03 12:57:40 -0800879 private DriverHandler getDriver(DeviceId deviceId) {
Jonathan Hart3c259162015-10-21 21:31:19 -0700880 Driver driver = driverService.getDriver(deviceId);
881 DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, deviceId));
882 return handler;
883 }
alshabib6b5cfec2014-09-18 17:42:18 -0700884}