blob: fbcd25bbb28bcb179915a04134a178cb7d9aee32 [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;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080019import org.onlab.packet.Ip4Address;
20import org.onlab.packet.Ip4Prefix;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080021import org.onlab.packet.Ip6Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080022import org.onlab.packet.Ip6Prefix;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080023import org.onlab.packet.MacAddress;
Michele Santuari4b6019e2014-12-19 11:31:45 +010024import org.onlab.packet.MplsLabel;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -070025import org.onlab.packet.TpPort;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080026import org.onlab.packet.VlanId;
sangho8995ac52015-02-04 11:29:03 -080027import org.onosproject.core.DefaultGroupId;
Brian O'Connorabafb502014-12-02 22:26:20 -080028import org.onosproject.net.DeviceId;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070029import org.onosproject.net.Lambda;
Yafit Hadar73514612015-11-04 10:14:21 +020030import org.onosproject.net.OduSignalId;
Brian O'Connorabafb502014-12-02 22:26:20 -080031import org.onosproject.net.PortNumber;
Jonathan Hart3c259162015-10-21 21:31:19 -070032import org.onosproject.net.driver.DefaultDriverData;
33import org.onosproject.net.driver.DefaultDriverHandler;
34import org.onosproject.net.driver.Driver;
35import org.onosproject.net.driver.DriverHandler;
36import org.onosproject.net.driver.DriverService;
Brian O'Connorabafb502014-12-02 22:26:20 -080037import org.onosproject.net.flow.DefaultFlowEntry;
38import org.onosproject.net.flow.DefaultFlowRule;
39import org.onosproject.net.flow.DefaultTrafficSelector;
40import org.onosproject.net.flow.DefaultTrafficTreatment;
41import org.onosproject.net.flow.FlowEntry;
42import org.onosproject.net.flow.FlowEntry.FlowEntryState;
43import org.onosproject.net.flow.FlowRule;
44import org.onosproject.net.flow.TrafficSelector;
45import org.onosproject.net.flow.TrafficTreatment;
Sho SHIMIZU9553bb82015-06-30 16:02:45 -070046import org.onosproject.net.flow.instructions.Instructions;
Brian O'Connorabafb502014-12-02 22:26:20 -080047import org.onosproject.openflow.controller.Dpid;
alshabib880b6442015-11-23 22:13:04 -080048import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter;
Brian O'Connor72cb19a2015-01-16 16:14:41 -080049import org.projectfloodlight.openflow.protocol.OFFlowMod;
alshabib6b5cfec2014-09-18 17:42:18 -070050import org.projectfloodlight.openflow.protocol.OFFlowRemoved;
51import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry;
Brian O'Connor21564612015-12-05 19:24:59 -080052import org.projectfloodlight.openflow.protocol.OFVersion;
alshabib6b5cfec2014-09-18 17:42:18 -070053import org.projectfloodlight.openflow.protocol.action.OFAction;
Marc De Leenheer49087752014-10-23 13:54:09 -070054import org.projectfloodlight.openflow.protocol.action.OFActionCircuit;
Steffen Gebertba2d3b72015-10-22 11:14:31 +020055import org.projectfloodlight.openflow.protocol.action.OFActionEnqueue;
Marc De Leenheer49087752014-10-23 13:54:09 -070056import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter;
sangho8995ac52015-02-04 11:29:03 -080057import org.projectfloodlight.openflow.protocol.action.OFActionGroup;
alshabib6b5cfec2014-09-18 17:42:18 -070058import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
sangho3f97a17d2015-01-29 22:56:29 -080059import org.projectfloodlight.openflow.protocol.action.OFActionPopMpls;
alshabib6b5cfec2014-09-18 17:42:18 -070060import org.projectfloodlight.openflow.protocol.action.OFActionSetDlDst;
61import org.projectfloodlight.openflow.protocol.action.OFActionSetDlSrc;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080062import org.projectfloodlight.openflow.protocol.action.OFActionSetField;
alshabib6b5cfec2014-09-18 17:42:18 -070063import org.projectfloodlight.openflow.protocol.action.OFActionSetNwDst;
64import org.projectfloodlight.openflow.protocol.action.OFActionSetNwSrc;
Jonathan Hart8cf212a2015-10-29 17:42:03 -070065import org.projectfloodlight.openflow.protocol.action.OFActionSetQueue;
alshabib6b5cfec2014-09-18 17:42:18 -070066import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanPcp;
67import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanVid;
alshabib19fdc122014-10-03 11:38:19 -070068import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
Jonathan Hartcf783202014-11-24 18:55:42 -080069import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions;
alshabibbdcbb102015-04-22 14:16:38 -070070import org.projectfloodlight.openflow.protocol.instruction.OFInstructionGotoTable;
alshabib346b5b32015-03-06 00:42:16 -080071import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteActions;
Saurav Das86af8f12015-05-25 23:55:33 -070072import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteMetadata;
alshabib6b5cfec2014-09-18 17:42:18 -070073import org.projectfloodlight.openflow.protocol.match.Match;
74import org.projectfloodlight.openflow.protocol.match.MatchField;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080075import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
Marc De Leenheer49087752014-10-23 13:54:09 -070076import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigidBasic;
alshabib346b5b32015-03-06 00:42:16 -080077import org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070078import org.projectfloodlight.openflow.types.CircuitSignalID;
alshabib6b5cfec2014-09-18 17:42:18 -070079import org.projectfloodlight.openflow.types.IPv4Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080080import org.projectfloodlight.openflow.types.IPv6Address;
Jonathan Hart0e12fad2014-10-17 14:54:58 -070081import org.projectfloodlight.openflow.types.Masked;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080082import org.projectfloodlight.openflow.types.OFVlanVidMatch;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -070083import org.projectfloodlight.openflow.types.TransportPort;
sangho3f97a17d2015-01-29 22:56:29 -080084import org.projectfloodlight.openflow.types.U32;
Hyunsun Moona08c5d02015-07-14 17:53:00 -070085import org.projectfloodlight.openflow.types.U64;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070086import org.projectfloodlight.openflow.types.U8;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080087import org.projectfloodlight.openflow.types.VlanPcp;
Yafit Hadar73514612015-11-04 10:14:21 +020088import org.projectfloodlight.openflow.types.OduSignalID;
alshabib6b5cfec2014-09-18 17:42:18 -070089import org.slf4j.Logger;
90
Jonathan Hart8cf212a2015-10-29 17:42:03 -070091import java.util.List;
92
93import static org.onosproject.net.flow.criteria.Criteria.matchLambda;
94import static org.onosproject.net.flow.criteria.Criteria.matchOchSignalType;
Yafit Hadar73514612015-11-04 10:14:21 +020095import static org.onosproject.net.flow.criteria.Criteria.matchOduSignalType;
96import static org.onosproject.net.flow.criteria.Criteria.matchOduSignalId;
97import static org.onosproject.net.flow.instructions.Instructions.modL0Lambda;
98import static org.onosproject.net.flow.instructions.Instructions.modL1OduSignalId;
Jonathan Hart8cf212a2015-10-29 17:42:03 -070099import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupChannelSpacing;
100import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupGridType;
101import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupOchSignalType;
Yafit Hadar73514612015-11-04 10:14:21 +0200102import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupOduSignalType;
Jonathan Hart8cf212a2015-10-29 17:42:03 -0700103import static org.slf4j.LoggerFactory.getLogger;
alshabib19fdc122014-10-03 11:38:19 -0700104
alshabib1c319ff2014-10-04 20:29:09 -0700105public class FlowEntryBuilder {
alshabib6b5cfec2014-09-18 17:42:18 -0700106 private final Logger log = getLogger(getClass());
107
108 private final OFFlowStatsEntry stat;
109 private final OFFlowRemoved removed;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800110 private final OFFlowMod flowMod;
alshabib6b5cfec2014-09-18 17:42:18 -0700111
112 private final Match match;
alshabib346b5b32015-03-06 00:42:16 -0800113
Jonathan Hart67fc0972015-03-19 15:21:20 -0700114 // All actions are contained in an OFInstruction. For OF1.0
115 // the instruction type is apply instruction (immediate set in ONOS speak)
alshabib346b5b32015-03-06 00:42:16 -0800116 private final List<OFInstruction> instructions;
alshabib6b5cfec2014-09-18 17:42:18 -0700117
118 private final Dpid dpid;
119
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800120 public enum FlowType { STAT, REMOVED, MOD }
121
122 private final FlowType type;
alshabib6b5cfec2014-09-18 17:42:18 -0700123
Jonathan Hart3c259162015-10-21 21:31:19 -0700124 private final DriverService driverService;
125
126 public FlowEntryBuilder(Dpid dpid, OFFlowStatsEntry entry, DriverService driverService) {
Saurav Dasfa2fa932015-03-03 11:29:48 -0800127 this.stat = entry;
128 this.match = entry.getMatch();
alshabib346b5b32015-03-06 00:42:16 -0800129 this.instructions = getInstructions(entry);
Saurav Dasfa2fa932015-03-03 11:29:48 -0800130 this.dpid = dpid;
131 this.removed = null;
132 this.flowMod = null;
133 this.type = FlowType.STAT;
Jonathan Hart3c259162015-10-21 21:31:19 -0700134 this.driverService = driverService;
Saurav Dasfa2fa932015-03-03 11:29:48 -0800135 }
136
Jonathan Hart3c259162015-10-21 21:31:19 -0700137 public FlowEntryBuilder(Dpid dpid, OFFlowRemoved removed, DriverService driverService) {
alshabib6b5cfec2014-09-18 17:42:18 -0700138 this.match = removed.getMatch();
139 this.removed = removed;
140
141 this.dpid = dpid;
alshabib346b5b32015-03-06 00:42:16 -0800142 this.instructions = null;
alshabib6b5cfec2014-09-18 17:42:18 -0700143 this.stat = null;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800144 this.flowMod = null;
145 this.type = FlowType.REMOVED;
Jonathan Hart3c259162015-10-21 21:31:19 -0700146 this.driverService = driverService;
alshabib6b5cfec2014-09-18 17:42:18 -0700147 }
148
Jonathan Hart3c259162015-10-21 21:31:19 -0700149 public FlowEntryBuilder(Dpid dpid, OFFlowMod fm, DriverService driverService) {
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800150 this.match = fm.getMatch();
151 this.dpid = dpid;
alshabib346b5b32015-03-06 00:42:16 -0800152 this.instructions = getInstructions(fm);
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800153 this.type = FlowType.MOD;
154 this.flowMod = fm;
155 this.stat = null;
156 this.removed = null;
Jonathan Hart3c259162015-10-21 21:31:19 -0700157 this.driverService = driverService;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800158 }
alshabib1c319ff2014-10-04 20:29:09 -0700159
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800160 public FlowEntry build(FlowEntryState... state) {
Brian O'Connor21564612015-12-05 19:24:59 -0800161 FlowRule.Builder builder;
162 try {
163 switch (this.type) {
164 case STAT:
165 builder = DefaultFlowRule.builder()
166 .forDevice(DeviceId.deviceId(Dpid.uri(dpid)))
167 .withSelector(buildSelector())
168 .withTreatment(buildTreatment())
169 .withPriority(stat.getPriority())
170 .makeTemporary(stat.getIdleTimeout())
Jonathan Hartd1ce4b02016-01-11 13:28:36 -0800171 .withCookie(stat.getCookie().getValue());
172 if (stat.getVersion() != OFVersion.OF_10) {
173 builder.forTable(stat.getTableId().getValue());
174 }
alshabibbdcbb102015-04-22 14:16:38 -0700175
Brian O'Connor21564612015-12-05 19:24:59 -0800176 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
177 stat.getDurationSec(),
178 stat.getPacketCount().getValue(),
179 stat.getByteCount().getValue());
180 case REMOVED:
181 builder = DefaultFlowRule.builder()
182 .forDevice(DeviceId.deviceId(Dpid.uri(dpid)))
183 .withSelector(buildSelector())
184 .withPriority(removed.getPriority())
185 .makeTemporary(removed.getIdleTimeout())
186 .withCookie(removed.getCookie().getValue());
187 if (removed.getVersion() != OFVersion.OF_10) {
188 builder.forTable(removed.getTableId().getValue());
189 }
alshabibbdcbb102015-04-22 14:16:38 -0700190
Brian O'Connor21564612015-12-05 19:24:59 -0800191 return new DefaultFlowEntry(builder.build(), FlowEntryState.REMOVED,
192 removed.getDurationSec(),
193 removed.getPacketCount().getValue(),
194 removed.getByteCount().getValue());
195 case MOD:
196 FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED;
197 builder = DefaultFlowRule.builder()
198 .forDevice(DeviceId.deviceId(Dpid.uri(dpid)))
199 .withSelector(buildSelector())
200 .withTreatment(buildTreatment())
201 .withPriority(flowMod.getPriority())
202 .makeTemporary(flowMod.getIdleTimeout())
203 .withCookie(flowMod.getCookie().getValue());
204 if (flowMod.getVersion() != OFVersion.OF_10) {
205 builder.forTable(flowMod.getTableId().getValue());
206 }
alshabibbdcbb102015-04-22 14:16:38 -0700207
Brian O'Connor21564612015-12-05 19:24:59 -0800208 return new DefaultFlowEntry(builder.build(), flowState, 0, 0, 0);
209 default:
210 log.error("Unknown flow type : {}", this.type);
211 return null;
212 }
213 } catch (UnsupportedOperationException e) {
214 log.warn("Error building flow entry", e);
215 return null;
alshabib6b5cfec2014-09-18 17:42:18 -0700216 }
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800217
alshabib6b5cfec2014-09-18 17:42:18 -0700218 }
219
alshabib346b5b32015-03-06 00:42:16 -0800220 private List<OFInstruction> getInstructions(OFFlowMod entry) {
alshabib19fdc122014-10-03 11:38:19 -0700221 switch (entry.getVersion()) {
222 case OF_10:
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700223 return Lists.newArrayList(OFFactoryVer13.INSTANCE.instructions()
224 .applyActions(
225 entry.getActions()));
alshabib19fdc122014-10-03 11:38:19 -0700226 case OF_11:
227 case OF_12:
228 case OF_13:
alshabib346b5b32015-03-06 00:42:16 -0800229 return entry.getInstructions();
230 default:
231 log.warn("Unknown OF version {}", entry.getVersion());
232 }
233 return Lists.newLinkedList();
234 }
235
236 private List<OFInstruction> getInstructions(OFFlowStatsEntry entry) {
237 switch (entry.getVersion()) {
238 case OF_10:
239 return Lists.newArrayList(
240 OFFactoryVer13.INSTANCE.instructions().applyActions(entry.getActions()));
241 case OF_11:
242 case OF_12:
243 case OF_13:
244 return entry.getInstructions();
alshabib19fdc122014-10-03 11:38:19 -0700245 default:
246 log.warn("Unknown OF version {}", entry.getVersion());
247 }
248 return Lists.newLinkedList();
249 }
alshabib6b5cfec2014-09-18 17:42:18 -0700250
251 private TrafficTreatment buildTreatment() {
tom9a693fd2014-10-03 11:32:19 -0700252 TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
alshabib346b5b32015-03-06 00:42:16 -0800253 for (OFInstruction in : instructions) {
254 switch (in.getType()) {
255 case GOTO_TABLE:
alshabibbdcbb102015-04-22 14:16:38 -0700256 builder.transition(((int) ((OFInstructionGotoTable) in)
257 .getTableId().getValue()));
alshabib346b5b32015-03-06 00:42:16 -0800258 break;
259 case WRITE_METADATA:
Saurav Das86af8f12015-05-25 23:55:33 -0700260 OFInstructionWriteMetadata m = (OFInstructionWriteMetadata) in;
261 builder.writeMetadata(m.getMetadata().getValue(),
262 m.getMetadataMask().getValue());
alshabib346b5b32015-03-06 00:42:16 -0800263 break;
264 case WRITE_ACTIONS:
265 builder.deferred();
266 buildActions(((OFInstructionWriteActions) in).getActions(),
267 builder);
268 break;
269 case APPLY_ACTIONS:
270 builder.immediate();
271 buildActions(((OFInstructionApplyActions) in).getActions(),
272 builder);
273 break;
274 case CLEAR_ACTIONS:
275 builder.wipeDeferred();
276 break;
277 case EXPERIMENTER:
278 break;
279 case METER:
280 break;
281 default:
282 log.warn("Unknown instructions type {}", in.getType());
alshabib6b5cfec2014-09-18 17:42:18 -0700283 }
284 }
285
286 return builder.build();
287 }
288
alshabib346b5b32015-03-06 00:42:16 -0800289 private TrafficTreatment.Builder buildActions(List<OFAction> actions,
290 TrafficTreatment.Builder builder) {
291 for (OFAction act : actions) {
292 switch (act.getType()) {
293 case OUTPUT:
294 OFActionOutput out = (OFActionOutput) act;
295 builder.setOutput(
296 PortNumber.portNumber(out.getPort().getPortNumber()));
297 break;
298 case SET_VLAN_VID:
299 OFActionSetVlanVid vlan = (OFActionSetVlanVid) act;
300 builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan()));
301 break;
302 case SET_VLAN_PCP:
303 OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act;
304 builder.setVlanPcp(pcp.getVlanPcp().getValue());
305 break;
306 case SET_DL_DST:
307 OFActionSetDlDst dldst = (OFActionSetDlDst) act;
308 builder.setEthDst(
309 MacAddress.valueOf(dldst.getDlAddr().getLong()));
310 break;
311 case SET_DL_SRC:
312 OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act;
313 builder.setEthSrc(
314 MacAddress.valueOf(dlsrc.getDlAddr().getLong()));
315
316 break;
317 case SET_NW_DST:
318 OFActionSetNwDst nwdst = (OFActionSetNwDst) act;
319 IPv4Address di = nwdst.getNwAddr();
320 builder.setIpDst(Ip4Address.valueOf(di.getInt()));
321 break;
322 case SET_NW_SRC:
323 OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act;
324 IPv4Address si = nwsrc.getNwAddr();
325 builder.setIpSrc(Ip4Address.valueOf(si.getInt()));
326 break;
327 case EXPERIMENTER:
328 OFActionExperimenter exp = (OFActionExperimenter) act;
329 if (exp.getExperimenter() == 0x80005A06 ||
330 exp.getExperimenter() == 0x748771) {
331 OFActionCircuit ct = (OFActionCircuit) exp;
Sho SHIMIZU9553bb82015-06-30 16:02:45 -0700332 short lambda = ((OFOxmOchSigidBasic) ct.getField()).getValue().getChannelNumber();
333 builder.add(Instructions.modL0Lambda(Lambda.indexedLambda(lambda)));
samueljcc4f4d25a2015-12-07 10:52:28 +0800334 } else if (exp.getExperimenter() == 0x2320) {
335 DriverHandler driver = getDriver(dpid);
336 ExtensionTreatmentInterpreter interpreter = driver
337 .behaviour(ExtensionTreatmentInterpreter.class);
338 if (interpreter != null) {
339 builder.extension(interpreter.mapAction(exp),
340 DeviceId.deviceId(Dpid.uri(dpid)));
341 }
alshabib346b5b32015-03-06 00:42:16 -0800342 } else {
343 log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter());
344 }
345 break;
346 case SET_FIELD:
347 OFActionSetField setField = (OFActionSetField) act;
Jonathan Hart3c259162015-10-21 21:31:19 -0700348 handleSetField(builder, setField);
alshabib346b5b32015-03-06 00:42:16 -0800349 break;
350 case POP_MPLS:
351 OFActionPopMpls popMpls = (OFActionPopMpls) act;
352 builder.popMpls((short) popMpls.getEthertype().getValue());
353 break;
354 case PUSH_MPLS:
355 builder.pushMpls();
356 break;
357 case COPY_TTL_IN:
358 builder.copyTtlIn();
359 break;
360 case COPY_TTL_OUT:
361 builder.copyTtlOut();
362 break;
363 case DEC_MPLS_TTL:
364 builder.decMplsTtl();
365 break;
366 case DEC_NW_TTL:
367 builder.decNwTtl();
368 break;
369 case GROUP:
370 OFActionGroup group = (OFActionGroup) act;
371 builder.group(new DefaultGroupId(group.getGroup().getGroupNumber()));
372 break;
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200373 case SET_QUEUE:
374 OFActionSetQueue setQueue = (OFActionSetQueue) act;
375 builder.setQueue(setQueue.getQueueId());
376 break;
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200377 case ENQUEUE:
378 OFActionEnqueue enqueue = (OFActionEnqueue) act;
379 builder.setQueue(enqueue.getQueueId(), PortNumber.portNumber(enqueue.getPort().getPortNumber()));
380 break;
Jonathan Hart67fc0972015-03-19 15:21:20 -0700381 case STRIP_VLAN:
alshabib346b5b32015-03-06 00:42:16 -0800382 case POP_VLAN:
383 builder.popVlan();
384 break;
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700385 case PUSH_VLAN:
386 builder.pushVlan();
387 break;
alshabib346b5b32015-03-06 00:42:16 -0800388 case SET_TP_DST:
389 case SET_TP_SRC:
390 case POP_PBB:
391 case PUSH_PBB:
alshabib346b5b32015-03-06 00:42:16 -0800392 case SET_MPLS_LABEL:
393 case SET_MPLS_TC:
394 case SET_MPLS_TTL:
395 case SET_NW_ECN:
396 case SET_NW_TOS:
397 case SET_NW_TTL:
alshabib346b5b32015-03-06 00:42:16 -0800398
alshabib346b5b32015-03-06 00:42:16 -0800399 default:
400 log.warn("Action type {} not yet implemented.", act.getType());
401 }
402 }
403 return builder;
404 }
405
406
Jonathan Hart3c259162015-10-21 21:31:19 -0700407 private void handleSetField(TrafficTreatment.Builder builder, OFActionSetField action) {
408 OFOxm<?> oxm = action.getField();
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800409 switch (oxm.getMatchField().id) {
410 case VLAN_PCP:
411 @SuppressWarnings("unchecked")
412 OFOxm<VlanPcp> vlanpcp = (OFOxm<VlanPcp>) oxm;
413 builder.setVlanPcp(vlanpcp.getValue().getValue());
414 break;
415 case VLAN_VID:
416 @SuppressWarnings("unchecked")
417 OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm;
418 builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan()));
419 break;
420 case ETH_DST:
421 @SuppressWarnings("unchecked")
422 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethdst =
423 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
424 builder.setEthDst(MacAddress.valueOf(ethdst.getValue().getLong()));
425 break;
426 case ETH_SRC:
427 @SuppressWarnings("unchecked")
428 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethsrc =
429 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
430 builder.setEthSrc(MacAddress.valueOf(ethsrc.getValue().getLong()));
431 break;
432 case IPV4_DST:
433 @SuppressWarnings("unchecked")
434 OFOxm<IPv4Address> ip4dst = (OFOxm<IPv4Address>) oxm;
435 builder.setIpDst(Ip4Address.valueOf(ip4dst.getValue().getInt()));
436 break;
437 case IPV4_SRC:
438 @SuppressWarnings("unchecked")
439 OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm;
440 builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt()));
441 break;
sangho3f97a17d2015-01-29 22:56:29 -0800442 case MPLS_LABEL:
443 @SuppressWarnings("unchecked")
444 OFOxm<U32> labelId = (OFOxm<U32>) oxm;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100445 builder.setMpls(MplsLabel.mplsLabel((int) labelId.getValue().getValue()));
sangho3f97a17d2015-01-29 22:56:29 -0800446 break;
Saurav Das73a7dd42015-08-19 22:20:31 -0700447 case MPLS_BOS:
448 @SuppressWarnings("unchecked")
449 OFOxm<U8> mplsBos = (OFOxm<U8>) oxm;
450 builder.setMplsBos(mplsBos.getValue() == U8.ZERO ? false : true);
451 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700452 case TUNNEL_ID:
453 @SuppressWarnings("unchecked")
454 OFOxm<U64> tunnelId = (OFOxm<U64>) oxm;
455 builder.setTunnelId(tunnelId.getValue().getValue());
456 break;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700457 case TCP_DST:
458 @SuppressWarnings("unchecked")
459 OFOxm<TransportPort> tcpdst = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700460 builder.setTcpDst(TpPort.tpPort(tcpdst.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700461 break;
462 case TCP_SRC:
463 @SuppressWarnings("unchecked")
464 OFOxm<TransportPort> tcpsrc = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700465 builder.setTcpSrc(TpPort.tpPort(tcpsrc.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700466 break;
467 case UDP_DST:
468 @SuppressWarnings("unchecked")
469 OFOxm<TransportPort> udpdst = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700470 builder.setUdpDst(TpPort.tpPort(udpdst.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700471 break;
472 case UDP_SRC:
473 @SuppressWarnings("unchecked")
474 OFOxm<TransportPort> udpsrc = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700475 builder.setUdpSrc(TpPort.tpPort(udpsrc.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700476 break;
Jonathan Hart3c259162015-10-21 21:31:19 -0700477 case TUNNEL_IPV4_DST:
478 DriverHandler driver = getDriver(dpid);
alshabib880b6442015-11-23 22:13:04 -0800479 ExtensionTreatmentInterpreter interpreter = driver.behaviour(ExtensionTreatmentInterpreter.class);
Jonathan Hart3c259162015-10-21 21:31:19 -0700480 if (interpreter != null) {
481 builder.extension(interpreter.mapAction(action), DeviceId.deviceId(Dpid.uri(dpid)));
482 }
483 break;
Yafit Hadar73514612015-11-04 10:14:21 +0200484 case EXP_ODU_SIG_ID:
485 @SuppressWarnings("unchecked")
486 OFOxm<OduSignalID> oduID = (OFOxm<OduSignalID>) oxm;
487 OduSignalID oduSignalID = oduID.getValue();
488 OduSignalId oduSignalId = OduSignalId.oduSignalId(oduSignalID.getTpn(),
489 oduSignalID.getTslen(),
490 oduSignalID.getTsmap());
491 builder.add(modL1OduSignalId(oduSignalId));
492 break;
493 case EXP_OCH_SIG_ID:
494 try {
495 @SuppressWarnings("unchecked")
496 OFOxm<CircuitSignalID> ochId = (OFOxm<CircuitSignalID>) oxm;
497 CircuitSignalID circuitSignalID = ochId.getValue();
498 builder.add(modL0Lambda(Lambda.ochSignal(
499 lookupGridType(circuitSignalID.getGridType()),
500 lookupChannelSpacing(circuitSignalID.getChannelSpacing()),
501 circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth())));
502 } catch (NoMappingFoundException e) {
503 log.warn(e.getMessage());
504 break;
505 }
506 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800507 case ARP_OP:
508 case ARP_SHA:
509 case ARP_SPA:
510 case ARP_THA:
511 case ARP_TPA:
512 case BSN_EGR_PORT_GROUP_ID:
513 case BSN_GLOBAL_VRF_ALLOWED:
514 case BSN_IN_PORTS_128:
515 case BSN_L3_DST_CLASS_ID:
516 case BSN_L3_INTERFACE_CLASS_ID:
517 case BSN_L3_SRC_CLASS_ID:
518 case BSN_LAG_ID:
519 case BSN_TCP_FLAGS:
520 case BSN_UDF0:
521 case BSN_UDF1:
522 case BSN_UDF2:
523 case BSN_UDF3:
524 case BSN_UDF4:
525 case BSN_UDF5:
526 case BSN_UDF6:
527 case BSN_UDF7:
528 case BSN_VLAN_XLATE_PORT_GROUP_ID:
529 case BSN_VRF:
530 case ETH_TYPE:
531 case ICMPV4_CODE:
532 case ICMPV4_TYPE:
533 case ICMPV6_CODE:
534 case ICMPV6_TYPE:
535 case IN_PHY_PORT:
536 case IN_PORT:
537 case IPV6_DST:
538 case IPV6_FLABEL:
539 case IPV6_ND_SLL:
540 case IPV6_ND_TARGET:
541 case IPV6_ND_TLL:
542 case IPV6_SRC:
543 case IP_DSCP:
544 case IP_ECN:
545 case IP_PROTO:
546 case METADATA:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800547 case MPLS_TC:
548 case OCH_SIGID:
549 case OCH_SIGID_BASIC:
550 case OCH_SIGTYPE:
551 case OCH_SIGTYPE_BASIC:
552 case SCTP_DST:
553 case SCTP_SRC:
Yafit Hadar73514612015-11-04 10:14:21 +0200554 case EXP_ODU_SIGTYPE:
555 case EXP_OCH_SIGTYPE:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800556 default:
557 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
558 break;
559 }
560 }
561
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700562 // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES
alshabib6b5cfec2014-09-18 17:42:18 -0700563 private TrafficSelector buildSelector() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800564 MacAddress mac;
565 Ip4Prefix ip4Prefix;
566 Ip6Address ip6Address;
567 Ip6Prefix ip6Prefix;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800568 Ip4Address ip;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800569
tom9a693fd2014-10-03 11:32:19 -0700570 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700571 for (MatchField<?> field : match.getMatchFields()) {
572 switch (field.id) {
573 case IN_PORT:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800574 builder.matchInPort(PortNumber
alshabib010c31d2014-09-26 10:01:12 -0700575 .portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700576 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800577 case IN_PHY_PORT:
578 builder.matchInPhyPort(PortNumber
579 .portNumber(match.get(MatchField.IN_PHY_PORT).getPortNumber()));
580 break;
581 case METADATA:
582 long metadata =
583 match.get(MatchField.METADATA).getValue().getValue();
584 builder.matchMetadata(metadata);
585 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700586 case ETH_DST:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800587 mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
588 builder.matchEthDst(mac);
589 break;
590 case ETH_SRC:
591 mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
592 builder.matchEthSrc(mac);
alshabib6b5cfec2014-09-18 17:42:18 -0700593 break;
594 case ETH_TYPE:
595 int ethType = match.get(MatchField.ETH_TYPE).getValue();
Jonathan Hart8cf212a2015-10-29 17:42:03 -0700596 builder.matchEthType((short) ethType);
alshabib6b5cfec2014-09-18 17:42:18 -0700597 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700598 case VLAN_VID:
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800599 VlanId vlanId = null;
600 if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
601 Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
602 if (masked.getValue().equals(OFVlanVidMatch.PRESENT)
603 && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
604 vlanId = VlanId.ANY;
605 }
606 } else {
Jonathan Hart1468fee2015-07-16 18:50:34 -0700607 if (!match.get(MatchField.VLAN_VID).isPresentBitSet()) {
608 vlanId = VlanId.NONE;
609 } else {
610 vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
611 }
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800612 }
613 if (vlanId != null) {
614 builder.matchVlanId(vlanId);
615 }
alshabib6b5cfec2014-09-18 17:42:18 -0700616 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800617 case VLAN_PCP:
618 byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
619 builder.matchVlanPcp(vlanPcp);
620 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800621 case IP_DSCP:
622 byte ipDscp = match.get(MatchField.IP_DSCP).getDscpValue();
623 builder.matchIPDscp(ipDscp);
624 break;
625 case IP_ECN:
626 byte ipEcn = match.get(MatchField.IP_ECN).getEcnValue();
627 builder.matchIPEcn(ipEcn);
628 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800629 case IP_PROTO:
630 short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
631 builder.matchIPProtocol((byte) proto);
632 break;
633 case IPV4_SRC:
634 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
635 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800636 ip4Prefix = Ip4Prefix.valueOf(
637 maskedIp.getValue().getInt(),
638 maskedIp.getMask().asCidrMaskLength());
639 } else {
640 ip4Prefix = Ip4Prefix.valueOf(
641 match.get(MatchField.IPV4_SRC).getInt(),
642 Ip4Prefix.MAX_MASK_LENGTH);
643 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800644 builder.matchIPSrc(ip4Prefix);
645 break;
646 case IPV4_DST:
647 if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
648 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800649 ip4Prefix = Ip4Prefix.valueOf(
650 maskedIp.getValue().getInt(),
651 maskedIp.getMask().asCidrMaskLength());
652 } else {
653 ip4Prefix = Ip4Prefix.valueOf(
654 match.get(MatchField.IPV4_DST).getInt(),
655 Ip4Prefix.MAX_MASK_LENGTH);
656 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800657 builder.matchIPDst(ip4Prefix);
Jonathan Hart34bc6142014-10-17 11:00:43 -0700658 break;
659 case TCP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700660 builder.matchTcpSrc(TpPort.tpPort(match.get(MatchField.TCP_SRC).getPort()));
Jonathan Hart34bc6142014-10-17 11:00:43 -0700661 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800662 case TCP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700663 builder.matchTcpDst(TpPort.tpPort(match.get(MatchField.TCP_DST).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800664 break;
665 case UDP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700666 builder.matchUdpSrc(TpPort.tpPort(match.get(MatchField.UDP_SRC).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800667 break;
668 case UDP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700669 builder.matchUdpDst(TpPort.tpPort(match.get(MatchField.UDP_DST).getPort()));
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700670 break;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100671 case MPLS_LABEL:
672 builder.matchMplsLabel(MplsLabel.mplsLabel((int) match.get(MatchField.MPLS_LABEL)
673 .getValue()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800674 break;
Saurav Dasffc5bbc2015-08-18 23:30:19 -0700675 case MPLS_BOS:
676 builder.matchMplsBos(match.get(MatchField.MPLS_BOS).getValue());
677 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800678 case SCTP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700679 builder.matchSctpSrc(TpPort.tpPort(match.get(MatchField.SCTP_SRC).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800680 break;
681 case SCTP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700682 builder.matchSctpDst(TpPort.tpPort(match.get(MatchField.SCTP_DST).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800683 break;
684 case ICMPV4_TYPE:
685 byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
686 builder.matchIcmpType(icmpType);
687 break;
688 case ICMPV4_CODE:
689 byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode();
690 builder.matchIcmpCode(icmpCode);
691 break;
692 case IPV6_SRC:
693 if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
694 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
695 ip6Prefix = Ip6Prefix.valueOf(
696 maskedIp.getValue().getBytes(),
697 maskedIp.getMask().asCidrMaskLength());
698 } else {
699 ip6Prefix = Ip6Prefix.valueOf(
700 match.get(MatchField.IPV6_SRC).getBytes(),
701 Ip6Prefix.MAX_MASK_LENGTH);
702 }
703 builder.matchIPv6Src(ip6Prefix);
704 break;
705 case IPV6_DST:
706 if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
707 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
708 ip6Prefix = Ip6Prefix.valueOf(
709 maskedIp.getValue().getBytes(),
710 maskedIp.getMask().asCidrMaskLength());
711 } else {
712 ip6Prefix = Ip6Prefix.valueOf(
713 match.get(MatchField.IPV6_DST).getBytes(),
714 Ip6Prefix.MAX_MASK_LENGTH);
715 }
716 builder.matchIPv6Dst(ip6Prefix);
717 break;
718 case IPV6_FLABEL:
719 int flowLabel =
720 match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue();
721 builder.matchIPv6FlowLabel(flowLabel);
722 break;
723 case ICMPV6_TYPE:
724 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
725 builder.matchIcmpv6Type(icmpv6type);
726 break;
727 case ICMPV6_CODE:
728 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
729 builder.matchIcmpv6Code(icmpv6code);
730 break;
731 case IPV6_ND_TARGET:
732 ip6Address =
733 Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes());
734 builder.matchIPv6NDTargetAddress(ip6Address);
735 break;
736 case IPV6_ND_SLL:
737 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong());
738 builder.matchIPv6NDSourceLinkLayerAddress(mac);
739 break;
740 case IPV6_ND_TLL:
741 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong());
742 builder.matchIPv6NDTargetLinkLayerAddress(mac);
743 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800744 case IPV6_EXTHDR:
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800745 builder.matchIPv6ExthdrFlags((short) match.get(MatchField.IPV6_EXTHDR)
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700746 .getValue());
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800747 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700748 case OCH_SIGID:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700749 CircuitSignalID sigId = match.get(MatchField.OCH_SIGID);
750 builder.add(matchLambda(Lambda.ochSignal(
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700751 lookupGridType(sigId.getGridType()), lookupChannelSpacing(sigId.getChannelSpacing()),
Marc De Leenheer0b8b2ef2015-08-03 15:39:00 -0700752 sigId.getChannelNumber(), sigId.getSpectralWidth())
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700753 ));
Marc De Leenheer49087752014-10-23 13:54:09 -0700754 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800755 case OCH_SIGTYPE:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700756 U8 sigType = match.get(MatchField.OCH_SIGTYPE);
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700757 builder.add(matchOchSignalType(lookupOchSignalType((byte) sigType.getValue())));
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800758 break;
Yafit Hadar73514612015-11-04 10:14:21 +0200759 case EXP_OCH_SIG_ID:
760 try {
761 CircuitSignalID expSigId = match.get(MatchField.EXP_OCH_SIG_ID);
762 builder.add(matchLambda(Lambda.ochSignal(
763 lookupGridType(expSigId.getGridType()), lookupChannelSpacing(expSigId.getChannelSpacing()),
764 expSigId.getChannelNumber(), expSigId.getSpectralWidth())));
765 } catch (NoMappingFoundException e) {
766 log.warn(e.getMessage());
767 break;
768 }
769 break;
770 case EXP_OCH_SIGTYPE:
771 try {
772 U8 expOchSigType = match.get(MatchField.EXP_OCH_SIGTYPE);
773 builder.add(matchOchSignalType(lookupOchSignalType((byte) expOchSigType.getValue())));
774 } catch (NoMappingFoundException e) {
775 log.warn(e.getMessage());
776 break;
777 }
778 break;
779 case EXP_ODU_SIG_ID:
780 OduSignalId oduSignalId = OduSignalId.oduSignalId(match.get(MatchField.EXP_ODU_SIG_ID).getTpn(),
781 match.get(MatchField.EXP_ODU_SIG_ID).getTslen(),
782 match.get(MatchField.EXP_ODU_SIG_ID).getTsmap());
783 builder.add(matchOduSignalId(oduSignalId));
784 break;
785 case EXP_ODU_SIGTYPE:
786 try {
787 U8 oduSigType = match.get(MatchField.EXP_ODU_SIGTYPE);
788 builder.add(matchOduSignalType(lookupOduSignalType((byte) oduSigType.getValue())));
789 } catch (NoMappingFoundException e) {
790 log.warn(e.getMessage());
791 break;
792 }
793 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700794 case TUNNEL_ID:
795 long tunnelId = match.get(MatchField.TUNNEL_ID).getValue();
796 builder.matchTunnelId(tunnelId);
797 break;
BitOhenryb40129a2015-11-30 12:41:18 +0800798 case ARP_OP:
799 int arpOp = match.get(MatchField.ARP_OP).getOpcode();
800 builder.matchArpOp(arpOp);
801 break;
BitOhenrya331b182015-11-23 08:39:37 +0800802 case ARP_SHA:
803 mac = MacAddress.valueOf(match.get(MatchField.ARP_SHA).getLong());
804 builder.matchArpSha(mac);
805 break;
BitOhenry296b4542015-11-24 08:41:58 +0800806 case ARP_SPA:
807 ip = Ip4Address.valueOf(match.get(MatchField.ARP_SPA).getInt());
808 builder.matchArpSpa(ip);
809 break;
BitOhenry76430852015-11-20 19:04:49 +0800810 case ARP_THA:
811 mac = MacAddress.valueOf(match.get(MatchField.ARP_THA).getLong());
812 builder.matchArpTha(mac);
813 break;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800814 case ARP_TPA:
815 ip = Ip4Address.valueOf(match.get(MatchField.ARP_TPA).getInt());
816 builder.matchArpTpa(ip);
817 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700818 case MPLS_TC:
alshabib6b5cfec2014-09-18 17:42:18 -0700819 default:
820 log.warn("Match type {} not yet implemented.", field.id);
alshabib6b5cfec2014-09-18 17:42:18 -0700821 }
822 }
823 return builder.build();
824 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700825
826 private DriverHandler getDriver(Dpid dpid) {
827 DeviceId deviceId = DeviceId.deviceId(Dpid.uri(dpid));
828 Driver driver = driverService.getDriver(deviceId);
829 DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, deviceId));
830 return handler;
831 }
alshabib6b5cfec2014-09-18 17:42:18 -0700832}