blob: e78b4f19f37a1bbe2a5f4d4761ad82552aa04d44 [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())
171 .withCookie(stat.getCookie().getValue())
172 .forTable(stat.getTableId().getValue());
alshabibbdcbb102015-04-22 14:16:38 -0700173
Brian O'Connor21564612015-12-05 19:24:59 -0800174 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
175 stat.getDurationSec(),
176 stat.getPacketCount().getValue(),
177 stat.getByteCount().getValue());
178 case REMOVED:
179 builder = DefaultFlowRule.builder()
180 .forDevice(DeviceId.deviceId(Dpid.uri(dpid)))
181 .withSelector(buildSelector())
182 .withPriority(removed.getPriority())
183 .makeTemporary(removed.getIdleTimeout())
184 .withCookie(removed.getCookie().getValue());
185 if (removed.getVersion() != OFVersion.OF_10) {
186 builder.forTable(removed.getTableId().getValue());
187 }
alshabibbdcbb102015-04-22 14:16:38 -0700188
Brian O'Connor21564612015-12-05 19:24:59 -0800189 return new DefaultFlowEntry(builder.build(), FlowEntryState.REMOVED,
190 removed.getDurationSec(),
191 removed.getPacketCount().getValue(),
192 removed.getByteCount().getValue());
193 case MOD:
194 FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED;
195 builder = DefaultFlowRule.builder()
196 .forDevice(DeviceId.deviceId(Dpid.uri(dpid)))
197 .withSelector(buildSelector())
198 .withTreatment(buildTreatment())
199 .withPriority(flowMod.getPriority())
200 .makeTemporary(flowMod.getIdleTimeout())
201 .withCookie(flowMod.getCookie().getValue());
202 if (flowMod.getVersion() != OFVersion.OF_10) {
203 builder.forTable(flowMod.getTableId().getValue());
204 }
alshabibbdcbb102015-04-22 14:16:38 -0700205
Brian O'Connor21564612015-12-05 19:24:59 -0800206 return new DefaultFlowEntry(builder.build(), flowState, 0, 0, 0);
207 default:
208 log.error("Unknown flow type : {}", this.type);
209 return null;
210 }
211 } catch (UnsupportedOperationException e) {
212 log.warn("Error building flow entry", e);
213 return null;
alshabib6b5cfec2014-09-18 17:42:18 -0700214 }
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800215
alshabib6b5cfec2014-09-18 17:42:18 -0700216 }
217
alshabib346b5b32015-03-06 00:42:16 -0800218 private List<OFInstruction> getInstructions(OFFlowMod entry) {
alshabib19fdc122014-10-03 11:38:19 -0700219 switch (entry.getVersion()) {
220 case OF_10:
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700221 return Lists.newArrayList(OFFactoryVer13.INSTANCE.instructions()
222 .applyActions(
223 entry.getActions()));
alshabib19fdc122014-10-03 11:38:19 -0700224 case OF_11:
225 case OF_12:
226 case OF_13:
alshabib346b5b32015-03-06 00:42:16 -0800227 return entry.getInstructions();
228 default:
229 log.warn("Unknown OF version {}", entry.getVersion());
230 }
231 return Lists.newLinkedList();
232 }
233
234 private List<OFInstruction> getInstructions(OFFlowStatsEntry entry) {
235 switch (entry.getVersion()) {
236 case OF_10:
237 return Lists.newArrayList(
238 OFFactoryVer13.INSTANCE.instructions().applyActions(entry.getActions()));
239 case OF_11:
240 case OF_12:
241 case OF_13:
242 return entry.getInstructions();
alshabib19fdc122014-10-03 11:38:19 -0700243 default:
244 log.warn("Unknown OF version {}", entry.getVersion());
245 }
246 return Lists.newLinkedList();
247 }
alshabib6b5cfec2014-09-18 17:42:18 -0700248
249 private TrafficTreatment buildTreatment() {
tom9a693fd2014-10-03 11:32:19 -0700250 TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
alshabib346b5b32015-03-06 00:42:16 -0800251 for (OFInstruction in : instructions) {
252 switch (in.getType()) {
253 case GOTO_TABLE:
alshabibbdcbb102015-04-22 14:16:38 -0700254 builder.transition(((int) ((OFInstructionGotoTable) in)
255 .getTableId().getValue()));
alshabib346b5b32015-03-06 00:42:16 -0800256 break;
257 case WRITE_METADATA:
Saurav Das86af8f12015-05-25 23:55:33 -0700258 OFInstructionWriteMetadata m = (OFInstructionWriteMetadata) in;
259 builder.writeMetadata(m.getMetadata().getValue(),
260 m.getMetadataMask().getValue());
alshabib346b5b32015-03-06 00:42:16 -0800261 break;
262 case WRITE_ACTIONS:
263 builder.deferred();
264 buildActions(((OFInstructionWriteActions) in).getActions(),
265 builder);
266 break;
267 case APPLY_ACTIONS:
268 builder.immediate();
269 buildActions(((OFInstructionApplyActions) in).getActions(),
270 builder);
271 break;
272 case CLEAR_ACTIONS:
273 builder.wipeDeferred();
274 break;
275 case EXPERIMENTER:
276 break;
277 case METER:
278 break;
279 default:
280 log.warn("Unknown instructions type {}", in.getType());
alshabib6b5cfec2014-09-18 17:42:18 -0700281 }
282 }
283
284 return builder.build();
285 }
286
alshabib346b5b32015-03-06 00:42:16 -0800287 private TrafficTreatment.Builder buildActions(List<OFAction> actions,
288 TrafficTreatment.Builder builder) {
289 for (OFAction act : actions) {
290 switch (act.getType()) {
291 case OUTPUT:
292 OFActionOutput out = (OFActionOutput) act;
293 builder.setOutput(
294 PortNumber.portNumber(out.getPort().getPortNumber()));
295 break;
296 case SET_VLAN_VID:
297 OFActionSetVlanVid vlan = (OFActionSetVlanVid) act;
298 builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan()));
299 break;
300 case SET_VLAN_PCP:
301 OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act;
302 builder.setVlanPcp(pcp.getVlanPcp().getValue());
303 break;
304 case SET_DL_DST:
305 OFActionSetDlDst dldst = (OFActionSetDlDst) act;
306 builder.setEthDst(
307 MacAddress.valueOf(dldst.getDlAddr().getLong()));
308 break;
309 case SET_DL_SRC:
310 OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act;
311 builder.setEthSrc(
312 MacAddress.valueOf(dlsrc.getDlAddr().getLong()));
313
314 break;
315 case SET_NW_DST:
316 OFActionSetNwDst nwdst = (OFActionSetNwDst) act;
317 IPv4Address di = nwdst.getNwAddr();
318 builder.setIpDst(Ip4Address.valueOf(di.getInt()));
319 break;
320 case SET_NW_SRC:
321 OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act;
322 IPv4Address si = nwsrc.getNwAddr();
323 builder.setIpSrc(Ip4Address.valueOf(si.getInt()));
324 break;
325 case EXPERIMENTER:
326 OFActionExperimenter exp = (OFActionExperimenter) act;
327 if (exp.getExperimenter() == 0x80005A06 ||
328 exp.getExperimenter() == 0x748771) {
329 OFActionCircuit ct = (OFActionCircuit) exp;
Sho SHIMIZU9553bb82015-06-30 16:02:45 -0700330 short lambda = ((OFOxmOchSigidBasic) ct.getField()).getValue().getChannelNumber();
331 builder.add(Instructions.modL0Lambda(Lambda.indexedLambda(lambda)));
samueljcc4f4d25a2015-12-07 10:52:28 +0800332 } else if (exp.getExperimenter() == 0x2320) {
333 DriverHandler driver = getDriver(dpid);
334 ExtensionTreatmentInterpreter interpreter = driver
335 .behaviour(ExtensionTreatmentInterpreter.class);
336 if (interpreter != null) {
337 builder.extension(interpreter.mapAction(exp),
338 DeviceId.deviceId(Dpid.uri(dpid)));
339 }
alshabib346b5b32015-03-06 00:42:16 -0800340 } else {
341 log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter());
342 }
343 break;
344 case SET_FIELD:
345 OFActionSetField setField = (OFActionSetField) act;
Jonathan Hart3c259162015-10-21 21:31:19 -0700346 handleSetField(builder, setField);
alshabib346b5b32015-03-06 00:42:16 -0800347 break;
348 case POP_MPLS:
349 OFActionPopMpls popMpls = (OFActionPopMpls) act;
350 builder.popMpls((short) popMpls.getEthertype().getValue());
351 break;
352 case PUSH_MPLS:
353 builder.pushMpls();
354 break;
355 case COPY_TTL_IN:
356 builder.copyTtlIn();
357 break;
358 case COPY_TTL_OUT:
359 builder.copyTtlOut();
360 break;
361 case DEC_MPLS_TTL:
362 builder.decMplsTtl();
363 break;
364 case DEC_NW_TTL:
365 builder.decNwTtl();
366 break;
367 case GROUP:
368 OFActionGroup group = (OFActionGroup) act;
369 builder.group(new DefaultGroupId(group.getGroup().getGroupNumber()));
370 break;
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200371 case SET_QUEUE:
372 OFActionSetQueue setQueue = (OFActionSetQueue) act;
373 builder.setQueue(setQueue.getQueueId());
374 break;
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200375 case ENQUEUE:
376 OFActionEnqueue enqueue = (OFActionEnqueue) act;
377 builder.setQueue(enqueue.getQueueId(), PortNumber.portNumber(enqueue.getPort().getPortNumber()));
378 break;
Jonathan Hart67fc0972015-03-19 15:21:20 -0700379 case STRIP_VLAN:
alshabib346b5b32015-03-06 00:42:16 -0800380 case POP_VLAN:
381 builder.popVlan();
382 break;
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700383 case PUSH_VLAN:
384 builder.pushVlan();
385 break;
alshabib346b5b32015-03-06 00:42:16 -0800386 case SET_TP_DST:
387 case SET_TP_SRC:
388 case POP_PBB:
389 case PUSH_PBB:
alshabib346b5b32015-03-06 00:42:16 -0800390 case SET_MPLS_LABEL:
391 case SET_MPLS_TC:
392 case SET_MPLS_TTL:
393 case SET_NW_ECN:
394 case SET_NW_TOS:
395 case SET_NW_TTL:
alshabib346b5b32015-03-06 00:42:16 -0800396
alshabib346b5b32015-03-06 00:42:16 -0800397 default:
398 log.warn("Action type {} not yet implemented.", act.getType());
399 }
400 }
401 return builder;
402 }
403
404
Jonathan Hart3c259162015-10-21 21:31:19 -0700405 private void handleSetField(TrafficTreatment.Builder builder, OFActionSetField action) {
406 OFOxm<?> oxm = action.getField();
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800407 switch (oxm.getMatchField().id) {
408 case VLAN_PCP:
409 @SuppressWarnings("unchecked")
410 OFOxm<VlanPcp> vlanpcp = (OFOxm<VlanPcp>) oxm;
411 builder.setVlanPcp(vlanpcp.getValue().getValue());
412 break;
413 case VLAN_VID:
414 @SuppressWarnings("unchecked")
415 OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm;
416 builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan()));
417 break;
418 case ETH_DST:
419 @SuppressWarnings("unchecked")
420 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethdst =
421 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
422 builder.setEthDst(MacAddress.valueOf(ethdst.getValue().getLong()));
423 break;
424 case ETH_SRC:
425 @SuppressWarnings("unchecked")
426 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethsrc =
427 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
428 builder.setEthSrc(MacAddress.valueOf(ethsrc.getValue().getLong()));
429 break;
430 case IPV4_DST:
431 @SuppressWarnings("unchecked")
432 OFOxm<IPv4Address> ip4dst = (OFOxm<IPv4Address>) oxm;
433 builder.setIpDst(Ip4Address.valueOf(ip4dst.getValue().getInt()));
434 break;
435 case IPV4_SRC:
436 @SuppressWarnings("unchecked")
437 OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm;
438 builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt()));
439 break;
sangho3f97a17d2015-01-29 22:56:29 -0800440 case MPLS_LABEL:
441 @SuppressWarnings("unchecked")
442 OFOxm<U32> labelId = (OFOxm<U32>) oxm;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100443 builder.setMpls(MplsLabel.mplsLabel((int) labelId.getValue().getValue()));
sangho3f97a17d2015-01-29 22:56:29 -0800444 break;
Saurav Das73a7dd42015-08-19 22:20:31 -0700445 case MPLS_BOS:
446 @SuppressWarnings("unchecked")
447 OFOxm<U8> mplsBos = (OFOxm<U8>) oxm;
448 builder.setMplsBos(mplsBos.getValue() == U8.ZERO ? false : true);
449 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700450 case TUNNEL_ID:
451 @SuppressWarnings("unchecked")
452 OFOxm<U64> tunnelId = (OFOxm<U64>) oxm;
453 builder.setTunnelId(tunnelId.getValue().getValue());
454 break;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700455 case TCP_DST:
456 @SuppressWarnings("unchecked")
457 OFOxm<TransportPort> tcpdst = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700458 builder.setTcpDst(TpPort.tpPort(tcpdst.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700459 break;
460 case TCP_SRC:
461 @SuppressWarnings("unchecked")
462 OFOxm<TransportPort> tcpsrc = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700463 builder.setTcpSrc(TpPort.tpPort(tcpsrc.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700464 break;
465 case UDP_DST:
466 @SuppressWarnings("unchecked")
467 OFOxm<TransportPort> udpdst = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700468 builder.setUdpDst(TpPort.tpPort(udpdst.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700469 break;
470 case UDP_SRC:
471 @SuppressWarnings("unchecked")
472 OFOxm<TransportPort> udpsrc = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700473 builder.setUdpSrc(TpPort.tpPort(udpsrc.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700474 break;
Jonathan Hart3c259162015-10-21 21:31:19 -0700475 case TUNNEL_IPV4_DST:
476 DriverHandler driver = getDriver(dpid);
alshabib880b6442015-11-23 22:13:04 -0800477 ExtensionTreatmentInterpreter interpreter = driver.behaviour(ExtensionTreatmentInterpreter.class);
Jonathan Hart3c259162015-10-21 21:31:19 -0700478 if (interpreter != null) {
479 builder.extension(interpreter.mapAction(action), DeviceId.deviceId(Dpid.uri(dpid)));
480 }
481 break;
Yafit Hadar73514612015-11-04 10:14:21 +0200482 case EXP_ODU_SIG_ID:
483 @SuppressWarnings("unchecked")
484 OFOxm<OduSignalID> oduID = (OFOxm<OduSignalID>) oxm;
485 OduSignalID oduSignalID = oduID.getValue();
486 OduSignalId oduSignalId = OduSignalId.oduSignalId(oduSignalID.getTpn(),
487 oduSignalID.getTslen(),
488 oduSignalID.getTsmap());
489 builder.add(modL1OduSignalId(oduSignalId));
490 break;
491 case EXP_OCH_SIG_ID:
492 try {
493 @SuppressWarnings("unchecked")
494 OFOxm<CircuitSignalID> ochId = (OFOxm<CircuitSignalID>) oxm;
495 CircuitSignalID circuitSignalID = ochId.getValue();
496 builder.add(modL0Lambda(Lambda.ochSignal(
497 lookupGridType(circuitSignalID.getGridType()),
498 lookupChannelSpacing(circuitSignalID.getChannelSpacing()),
499 circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth())));
500 } catch (NoMappingFoundException e) {
501 log.warn(e.getMessage());
502 break;
503 }
504 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800505 case ARP_OP:
506 case ARP_SHA:
507 case ARP_SPA:
508 case ARP_THA:
509 case ARP_TPA:
510 case BSN_EGR_PORT_GROUP_ID:
511 case BSN_GLOBAL_VRF_ALLOWED:
512 case BSN_IN_PORTS_128:
513 case BSN_L3_DST_CLASS_ID:
514 case BSN_L3_INTERFACE_CLASS_ID:
515 case BSN_L3_SRC_CLASS_ID:
516 case BSN_LAG_ID:
517 case BSN_TCP_FLAGS:
518 case BSN_UDF0:
519 case BSN_UDF1:
520 case BSN_UDF2:
521 case BSN_UDF3:
522 case BSN_UDF4:
523 case BSN_UDF5:
524 case BSN_UDF6:
525 case BSN_UDF7:
526 case BSN_VLAN_XLATE_PORT_GROUP_ID:
527 case BSN_VRF:
528 case ETH_TYPE:
529 case ICMPV4_CODE:
530 case ICMPV4_TYPE:
531 case ICMPV6_CODE:
532 case ICMPV6_TYPE:
533 case IN_PHY_PORT:
534 case IN_PORT:
535 case IPV6_DST:
536 case IPV6_FLABEL:
537 case IPV6_ND_SLL:
538 case IPV6_ND_TARGET:
539 case IPV6_ND_TLL:
540 case IPV6_SRC:
541 case IP_DSCP:
542 case IP_ECN:
543 case IP_PROTO:
544 case METADATA:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800545 case MPLS_TC:
546 case OCH_SIGID:
547 case OCH_SIGID_BASIC:
548 case OCH_SIGTYPE:
549 case OCH_SIGTYPE_BASIC:
550 case SCTP_DST:
551 case SCTP_SRC:
Yafit Hadar73514612015-11-04 10:14:21 +0200552 case EXP_ODU_SIGTYPE:
553 case EXP_OCH_SIGTYPE:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800554 default:
555 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
556 break;
557 }
558 }
559
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700560 // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES
alshabib6b5cfec2014-09-18 17:42:18 -0700561 private TrafficSelector buildSelector() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800562 MacAddress mac;
563 Ip4Prefix ip4Prefix;
564 Ip6Address ip6Address;
565 Ip6Prefix ip6Prefix;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800566 Ip4Address ip;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800567
tom9a693fd2014-10-03 11:32:19 -0700568 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700569 for (MatchField<?> field : match.getMatchFields()) {
570 switch (field.id) {
571 case IN_PORT:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800572 builder.matchInPort(PortNumber
alshabib010c31d2014-09-26 10:01:12 -0700573 .portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700574 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800575 case IN_PHY_PORT:
576 builder.matchInPhyPort(PortNumber
577 .portNumber(match.get(MatchField.IN_PHY_PORT).getPortNumber()));
578 break;
579 case METADATA:
580 long metadata =
581 match.get(MatchField.METADATA).getValue().getValue();
582 builder.matchMetadata(metadata);
583 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700584 case ETH_DST:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800585 mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
586 builder.matchEthDst(mac);
587 break;
588 case ETH_SRC:
589 mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
590 builder.matchEthSrc(mac);
alshabib6b5cfec2014-09-18 17:42:18 -0700591 break;
592 case ETH_TYPE:
593 int ethType = match.get(MatchField.ETH_TYPE).getValue();
Jonathan Hart8cf212a2015-10-29 17:42:03 -0700594 builder.matchEthType((short) ethType);
alshabib6b5cfec2014-09-18 17:42:18 -0700595 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700596 case VLAN_VID:
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800597 VlanId vlanId = null;
598 if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
599 Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
600 if (masked.getValue().equals(OFVlanVidMatch.PRESENT)
601 && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
602 vlanId = VlanId.ANY;
603 }
604 } else {
Jonathan Hart1468fee2015-07-16 18:50:34 -0700605 if (!match.get(MatchField.VLAN_VID).isPresentBitSet()) {
606 vlanId = VlanId.NONE;
607 } else {
608 vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
609 }
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800610 }
611 if (vlanId != null) {
612 builder.matchVlanId(vlanId);
613 }
alshabib6b5cfec2014-09-18 17:42:18 -0700614 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800615 case VLAN_PCP:
616 byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
617 builder.matchVlanPcp(vlanPcp);
618 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800619 case IP_DSCP:
620 byte ipDscp = match.get(MatchField.IP_DSCP).getDscpValue();
621 builder.matchIPDscp(ipDscp);
622 break;
623 case IP_ECN:
624 byte ipEcn = match.get(MatchField.IP_ECN).getEcnValue();
625 builder.matchIPEcn(ipEcn);
626 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800627 case IP_PROTO:
628 short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
629 builder.matchIPProtocol((byte) proto);
630 break;
631 case IPV4_SRC:
632 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
633 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800634 ip4Prefix = Ip4Prefix.valueOf(
635 maskedIp.getValue().getInt(),
636 maskedIp.getMask().asCidrMaskLength());
637 } else {
638 ip4Prefix = Ip4Prefix.valueOf(
639 match.get(MatchField.IPV4_SRC).getInt(),
640 Ip4Prefix.MAX_MASK_LENGTH);
641 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800642 builder.matchIPSrc(ip4Prefix);
643 break;
644 case IPV4_DST:
645 if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
646 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800647 ip4Prefix = Ip4Prefix.valueOf(
648 maskedIp.getValue().getInt(),
649 maskedIp.getMask().asCidrMaskLength());
650 } else {
651 ip4Prefix = Ip4Prefix.valueOf(
652 match.get(MatchField.IPV4_DST).getInt(),
653 Ip4Prefix.MAX_MASK_LENGTH);
654 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800655 builder.matchIPDst(ip4Prefix);
Jonathan Hart34bc6142014-10-17 11:00:43 -0700656 break;
657 case TCP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700658 builder.matchTcpSrc(TpPort.tpPort(match.get(MatchField.TCP_SRC).getPort()));
Jonathan Hart34bc6142014-10-17 11:00:43 -0700659 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800660 case TCP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700661 builder.matchTcpDst(TpPort.tpPort(match.get(MatchField.TCP_DST).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800662 break;
663 case UDP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700664 builder.matchUdpSrc(TpPort.tpPort(match.get(MatchField.UDP_SRC).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800665 break;
666 case UDP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700667 builder.matchUdpDst(TpPort.tpPort(match.get(MatchField.UDP_DST).getPort()));
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700668 break;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100669 case MPLS_LABEL:
670 builder.matchMplsLabel(MplsLabel.mplsLabel((int) match.get(MatchField.MPLS_LABEL)
671 .getValue()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800672 break;
Saurav Dasffc5bbc2015-08-18 23:30:19 -0700673 case MPLS_BOS:
674 builder.matchMplsBos(match.get(MatchField.MPLS_BOS).getValue());
675 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800676 case SCTP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700677 builder.matchSctpSrc(TpPort.tpPort(match.get(MatchField.SCTP_SRC).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800678 break;
679 case SCTP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700680 builder.matchSctpDst(TpPort.tpPort(match.get(MatchField.SCTP_DST).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800681 break;
682 case ICMPV4_TYPE:
683 byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
684 builder.matchIcmpType(icmpType);
685 break;
686 case ICMPV4_CODE:
687 byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode();
688 builder.matchIcmpCode(icmpCode);
689 break;
690 case IPV6_SRC:
691 if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
692 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
693 ip6Prefix = Ip6Prefix.valueOf(
694 maskedIp.getValue().getBytes(),
695 maskedIp.getMask().asCidrMaskLength());
696 } else {
697 ip6Prefix = Ip6Prefix.valueOf(
698 match.get(MatchField.IPV6_SRC).getBytes(),
699 Ip6Prefix.MAX_MASK_LENGTH);
700 }
701 builder.matchIPv6Src(ip6Prefix);
702 break;
703 case IPV6_DST:
704 if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
705 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
706 ip6Prefix = Ip6Prefix.valueOf(
707 maskedIp.getValue().getBytes(),
708 maskedIp.getMask().asCidrMaskLength());
709 } else {
710 ip6Prefix = Ip6Prefix.valueOf(
711 match.get(MatchField.IPV6_DST).getBytes(),
712 Ip6Prefix.MAX_MASK_LENGTH);
713 }
714 builder.matchIPv6Dst(ip6Prefix);
715 break;
716 case IPV6_FLABEL:
717 int flowLabel =
718 match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue();
719 builder.matchIPv6FlowLabel(flowLabel);
720 break;
721 case ICMPV6_TYPE:
722 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
723 builder.matchIcmpv6Type(icmpv6type);
724 break;
725 case ICMPV6_CODE:
726 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
727 builder.matchIcmpv6Code(icmpv6code);
728 break;
729 case IPV6_ND_TARGET:
730 ip6Address =
731 Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes());
732 builder.matchIPv6NDTargetAddress(ip6Address);
733 break;
734 case IPV6_ND_SLL:
735 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong());
736 builder.matchIPv6NDSourceLinkLayerAddress(mac);
737 break;
738 case IPV6_ND_TLL:
739 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong());
740 builder.matchIPv6NDTargetLinkLayerAddress(mac);
741 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800742 case IPV6_EXTHDR:
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800743 builder.matchIPv6ExthdrFlags((short) match.get(MatchField.IPV6_EXTHDR)
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700744 .getValue());
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800745 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700746 case OCH_SIGID:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700747 CircuitSignalID sigId = match.get(MatchField.OCH_SIGID);
748 builder.add(matchLambda(Lambda.ochSignal(
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700749 lookupGridType(sigId.getGridType()), lookupChannelSpacing(sigId.getChannelSpacing()),
Marc De Leenheer0b8b2ef2015-08-03 15:39:00 -0700750 sigId.getChannelNumber(), sigId.getSpectralWidth())
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700751 ));
Marc De Leenheer49087752014-10-23 13:54:09 -0700752 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800753 case OCH_SIGTYPE:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700754 U8 sigType = match.get(MatchField.OCH_SIGTYPE);
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700755 builder.add(matchOchSignalType(lookupOchSignalType((byte) sigType.getValue())));
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800756 break;
Yafit Hadar73514612015-11-04 10:14:21 +0200757 case EXP_OCH_SIG_ID:
758 try {
759 CircuitSignalID expSigId = match.get(MatchField.EXP_OCH_SIG_ID);
760 builder.add(matchLambda(Lambda.ochSignal(
761 lookupGridType(expSigId.getGridType()), lookupChannelSpacing(expSigId.getChannelSpacing()),
762 expSigId.getChannelNumber(), expSigId.getSpectralWidth())));
763 } catch (NoMappingFoundException e) {
764 log.warn(e.getMessage());
765 break;
766 }
767 break;
768 case EXP_OCH_SIGTYPE:
769 try {
770 U8 expOchSigType = match.get(MatchField.EXP_OCH_SIGTYPE);
771 builder.add(matchOchSignalType(lookupOchSignalType((byte) expOchSigType.getValue())));
772 } catch (NoMappingFoundException e) {
773 log.warn(e.getMessage());
774 break;
775 }
776 break;
777 case EXP_ODU_SIG_ID:
778 OduSignalId oduSignalId = OduSignalId.oduSignalId(match.get(MatchField.EXP_ODU_SIG_ID).getTpn(),
779 match.get(MatchField.EXP_ODU_SIG_ID).getTslen(),
780 match.get(MatchField.EXP_ODU_SIG_ID).getTsmap());
781 builder.add(matchOduSignalId(oduSignalId));
782 break;
783 case EXP_ODU_SIGTYPE:
784 try {
785 U8 oduSigType = match.get(MatchField.EXP_ODU_SIGTYPE);
786 builder.add(matchOduSignalType(lookupOduSignalType((byte) oduSigType.getValue())));
787 } catch (NoMappingFoundException e) {
788 log.warn(e.getMessage());
789 break;
790 }
791 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700792 case TUNNEL_ID:
793 long tunnelId = match.get(MatchField.TUNNEL_ID).getValue();
794 builder.matchTunnelId(tunnelId);
795 break;
BitOhenryb40129a2015-11-30 12:41:18 +0800796 case ARP_OP:
797 int arpOp = match.get(MatchField.ARP_OP).getOpcode();
798 builder.matchArpOp(arpOp);
799 break;
BitOhenrya331b182015-11-23 08:39:37 +0800800 case ARP_SHA:
801 mac = MacAddress.valueOf(match.get(MatchField.ARP_SHA).getLong());
802 builder.matchArpSha(mac);
803 break;
BitOhenry296b4542015-11-24 08:41:58 +0800804 case ARP_SPA:
805 ip = Ip4Address.valueOf(match.get(MatchField.ARP_SPA).getInt());
806 builder.matchArpSpa(ip);
807 break;
BitOhenry76430852015-11-20 19:04:49 +0800808 case ARP_THA:
809 mac = MacAddress.valueOf(match.get(MatchField.ARP_THA).getLong());
810 builder.matchArpTha(mac);
811 break;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800812 case ARP_TPA:
813 ip = Ip4Address.valueOf(match.get(MatchField.ARP_TPA).getInt());
814 builder.matchArpTpa(ip);
815 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700816 case MPLS_TC:
alshabib6b5cfec2014-09-18 17:42:18 -0700817 default:
818 log.warn("Match type {} not yet implemented.", field.id);
alshabib6b5cfec2014-09-18 17:42:18 -0700819 }
820 }
821 return builder.build();
822 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700823
824 private DriverHandler getDriver(Dpid dpid) {
825 DeviceId deviceId = DeviceId.deviceId(Dpid.uri(dpid));
826 Driver driver = driverService.getDriver(deviceId);
827 DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, deviceId));
828 return handler;
829 }
alshabib6b5cfec2014-09-18 17:42:18 -0700830}