blob: b1fa717905074a67aeaaf591bb2dc666dd110648 [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)));
alshabib346b5b32015-03-06 00:42:16 -0800332 } else {
333 log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter());
334 }
335 break;
336 case SET_FIELD:
337 OFActionSetField setField = (OFActionSetField) act;
Jonathan Hart3c259162015-10-21 21:31:19 -0700338 handleSetField(builder, setField);
alshabib346b5b32015-03-06 00:42:16 -0800339 break;
340 case POP_MPLS:
341 OFActionPopMpls popMpls = (OFActionPopMpls) act;
342 builder.popMpls((short) popMpls.getEthertype().getValue());
343 break;
344 case PUSH_MPLS:
345 builder.pushMpls();
346 break;
347 case COPY_TTL_IN:
348 builder.copyTtlIn();
349 break;
350 case COPY_TTL_OUT:
351 builder.copyTtlOut();
352 break;
353 case DEC_MPLS_TTL:
354 builder.decMplsTtl();
355 break;
356 case DEC_NW_TTL:
357 builder.decNwTtl();
358 break;
359 case GROUP:
360 OFActionGroup group = (OFActionGroup) act;
361 builder.group(new DefaultGroupId(group.getGroup().getGroupNumber()));
362 break;
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200363 case SET_QUEUE:
364 OFActionSetQueue setQueue = (OFActionSetQueue) act;
365 builder.setQueue(setQueue.getQueueId());
366 break;
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200367 case ENQUEUE:
368 OFActionEnqueue enqueue = (OFActionEnqueue) act;
369 builder.setQueue(enqueue.getQueueId(), PortNumber.portNumber(enqueue.getPort().getPortNumber()));
370 break;
Jonathan Hart67fc0972015-03-19 15:21:20 -0700371 case STRIP_VLAN:
alshabib346b5b32015-03-06 00:42:16 -0800372 case POP_VLAN:
373 builder.popVlan();
374 break;
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700375 case PUSH_VLAN:
376 builder.pushVlan();
377 break;
alshabib346b5b32015-03-06 00:42:16 -0800378 case SET_TP_DST:
379 case SET_TP_SRC:
380 case POP_PBB:
381 case PUSH_PBB:
alshabib346b5b32015-03-06 00:42:16 -0800382 case SET_MPLS_LABEL:
383 case SET_MPLS_TC:
384 case SET_MPLS_TTL:
385 case SET_NW_ECN:
386 case SET_NW_TOS:
387 case SET_NW_TTL:
alshabib346b5b32015-03-06 00:42:16 -0800388
alshabib346b5b32015-03-06 00:42:16 -0800389 default:
390 log.warn("Action type {} not yet implemented.", act.getType());
391 }
392 }
393 return builder;
394 }
395
396
Jonathan Hart3c259162015-10-21 21:31:19 -0700397 private void handleSetField(TrafficTreatment.Builder builder, OFActionSetField action) {
398 OFOxm<?> oxm = action.getField();
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800399 switch (oxm.getMatchField().id) {
400 case VLAN_PCP:
401 @SuppressWarnings("unchecked")
402 OFOxm<VlanPcp> vlanpcp = (OFOxm<VlanPcp>) oxm;
403 builder.setVlanPcp(vlanpcp.getValue().getValue());
404 break;
405 case VLAN_VID:
406 @SuppressWarnings("unchecked")
407 OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm;
408 builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan()));
409 break;
410 case ETH_DST:
411 @SuppressWarnings("unchecked")
412 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethdst =
413 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
414 builder.setEthDst(MacAddress.valueOf(ethdst.getValue().getLong()));
415 break;
416 case ETH_SRC:
417 @SuppressWarnings("unchecked")
418 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethsrc =
419 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
420 builder.setEthSrc(MacAddress.valueOf(ethsrc.getValue().getLong()));
421 break;
422 case IPV4_DST:
423 @SuppressWarnings("unchecked")
424 OFOxm<IPv4Address> ip4dst = (OFOxm<IPv4Address>) oxm;
425 builder.setIpDst(Ip4Address.valueOf(ip4dst.getValue().getInt()));
426 break;
427 case IPV4_SRC:
428 @SuppressWarnings("unchecked")
429 OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm;
430 builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt()));
431 break;
sangho3f97a17d2015-01-29 22:56:29 -0800432 case MPLS_LABEL:
433 @SuppressWarnings("unchecked")
434 OFOxm<U32> labelId = (OFOxm<U32>) oxm;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100435 builder.setMpls(MplsLabel.mplsLabel((int) labelId.getValue().getValue()));
sangho3f97a17d2015-01-29 22:56:29 -0800436 break;
Saurav Das73a7dd42015-08-19 22:20:31 -0700437 case MPLS_BOS:
438 @SuppressWarnings("unchecked")
439 OFOxm<U8> mplsBos = (OFOxm<U8>) oxm;
440 builder.setMplsBos(mplsBos.getValue() == U8.ZERO ? false : true);
441 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700442 case TUNNEL_ID:
443 @SuppressWarnings("unchecked")
444 OFOxm<U64> tunnelId = (OFOxm<U64>) oxm;
445 builder.setTunnelId(tunnelId.getValue().getValue());
446 break;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700447 case TCP_DST:
448 @SuppressWarnings("unchecked")
449 OFOxm<TransportPort> tcpdst = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700450 builder.setTcpDst(TpPort.tpPort(tcpdst.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700451 break;
452 case TCP_SRC:
453 @SuppressWarnings("unchecked")
454 OFOxm<TransportPort> tcpsrc = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700455 builder.setTcpSrc(TpPort.tpPort(tcpsrc.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700456 break;
457 case UDP_DST:
458 @SuppressWarnings("unchecked")
459 OFOxm<TransportPort> udpdst = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700460 builder.setUdpDst(TpPort.tpPort(udpdst.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700461 break;
462 case UDP_SRC:
463 @SuppressWarnings("unchecked")
464 OFOxm<TransportPort> udpsrc = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700465 builder.setUdpSrc(TpPort.tpPort(udpsrc.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700466 break;
Jonathan Hart3c259162015-10-21 21:31:19 -0700467 case TUNNEL_IPV4_DST:
468 DriverHandler driver = getDriver(dpid);
alshabib880b6442015-11-23 22:13:04 -0800469 ExtensionTreatmentInterpreter interpreter = driver.behaviour(ExtensionTreatmentInterpreter.class);
Jonathan Hart3c259162015-10-21 21:31:19 -0700470 if (interpreter != null) {
471 builder.extension(interpreter.mapAction(action), DeviceId.deviceId(Dpid.uri(dpid)));
472 }
473 break;
Yafit Hadar73514612015-11-04 10:14:21 +0200474 case EXP_ODU_SIG_ID:
475 @SuppressWarnings("unchecked")
476 OFOxm<OduSignalID> oduID = (OFOxm<OduSignalID>) oxm;
477 OduSignalID oduSignalID = oduID.getValue();
478 OduSignalId oduSignalId = OduSignalId.oduSignalId(oduSignalID.getTpn(),
479 oduSignalID.getTslen(),
480 oduSignalID.getTsmap());
481 builder.add(modL1OduSignalId(oduSignalId));
482 break;
483 case EXP_OCH_SIG_ID:
484 try {
485 @SuppressWarnings("unchecked")
486 OFOxm<CircuitSignalID> ochId = (OFOxm<CircuitSignalID>) oxm;
487 CircuitSignalID circuitSignalID = ochId.getValue();
488 builder.add(modL0Lambda(Lambda.ochSignal(
489 lookupGridType(circuitSignalID.getGridType()),
490 lookupChannelSpacing(circuitSignalID.getChannelSpacing()),
491 circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth())));
492 } catch (NoMappingFoundException e) {
493 log.warn(e.getMessage());
494 break;
495 }
496 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800497 case ARP_OP:
498 case ARP_SHA:
499 case ARP_SPA:
500 case ARP_THA:
501 case ARP_TPA:
502 case BSN_EGR_PORT_GROUP_ID:
503 case BSN_GLOBAL_VRF_ALLOWED:
504 case BSN_IN_PORTS_128:
505 case BSN_L3_DST_CLASS_ID:
506 case BSN_L3_INTERFACE_CLASS_ID:
507 case BSN_L3_SRC_CLASS_ID:
508 case BSN_LAG_ID:
509 case BSN_TCP_FLAGS:
510 case BSN_UDF0:
511 case BSN_UDF1:
512 case BSN_UDF2:
513 case BSN_UDF3:
514 case BSN_UDF4:
515 case BSN_UDF5:
516 case BSN_UDF6:
517 case BSN_UDF7:
518 case BSN_VLAN_XLATE_PORT_GROUP_ID:
519 case BSN_VRF:
520 case ETH_TYPE:
521 case ICMPV4_CODE:
522 case ICMPV4_TYPE:
523 case ICMPV6_CODE:
524 case ICMPV6_TYPE:
525 case IN_PHY_PORT:
526 case IN_PORT:
527 case IPV6_DST:
528 case IPV6_FLABEL:
529 case IPV6_ND_SLL:
530 case IPV6_ND_TARGET:
531 case IPV6_ND_TLL:
532 case IPV6_SRC:
533 case IP_DSCP:
534 case IP_ECN:
535 case IP_PROTO:
536 case METADATA:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800537 case MPLS_TC:
538 case OCH_SIGID:
539 case OCH_SIGID_BASIC:
540 case OCH_SIGTYPE:
541 case OCH_SIGTYPE_BASIC:
542 case SCTP_DST:
543 case SCTP_SRC:
Yafit Hadar73514612015-11-04 10:14:21 +0200544 case EXP_ODU_SIGTYPE:
545 case EXP_OCH_SIGTYPE:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800546 default:
547 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
548 break;
549 }
550 }
551
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700552 // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES
alshabib6b5cfec2014-09-18 17:42:18 -0700553 private TrafficSelector buildSelector() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800554 MacAddress mac;
555 Ip4Prefix ip4Prefix;
556 Ip6Address ip6Address;
557 Ip6Prefix ip6Prefix;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800558 Ip4Address ip;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800559
tom9a693fd2014-10-03 11:32:19 -0700560 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700561 for (MatchField<?> field : match.getMatchFields()) {
562 switch (field.id) {
563 case IN_PORT:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800564 builder.matchInPort(PortNumber
alshabib010c31d2014-09-26 10:01:12 -0700565 .portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700566 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800567 case IN_PHY_PORT:
568 builder.matchInPhyPort(PortNumber
569 .portNumber(match.get(MatchField.IN_PHY_PORT).getPortNumber()));
570 break;
571 case METADATA:
572 long metadata =
573 match.get(MatchField.METADATA).getValue().getValue();
574 builder.matchMetadata(metadata);
575 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700576 case ETH_DST:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800577 mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
578 builder.matchEthDst(mac);
579 break;
580 case ETH_SRC:
581 mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
582 builder.matchEthSrc(mac);
alshabib6b5cfec2014-09-18 17:42:18 -0700583 break;
584 case ETH_TYPE:
585 int ethType = match.get(MatchField.ETH_TYPE).getValue();
Jonathan Hart8cf212a2015-10-29 17:42:03 -0700586 builder.matchEthType((short) ethType);
alshabib6b5cfec2014-09-18 17:42:18 -0700587 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700588 case VLAN_VID:
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800589 VlanId vlanId = null;
590 if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
591 Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
592 if (masked.getValue().equals(OFVlanVidMatch.PRESENT)
593 && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
594 vlanId = VlanId.ANY;
595 }
596 } else {
Jonathan Hart1468fee2015-07-16 18:50:34 -0700597 if (!match.get(MatchField.VLAN_VID).isPresentBitSet()) {
598 vlanId = VlanId.NONE;
599 } else {
600 vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
601 }
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800602 }
603 if (vlanId != null) {
604 builder.matchVlanId(vlanId);
605 }
alshabib6b5cfec2014-09-18 17:42:18 -0700606 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800607 case VLAN_PCP:
608 byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
609 builder.matchVlanPcp(vlanPcp);
610 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800611 case IP_DSCP:
612 byte ipDscp = match.get(MatchField.IP_DSCP).getDscpValue();
613 builder.matchIPDscp(ipDscp);
614 break;
615 case IP_ECN:
616 byte ipEcn = match.get(MatchField.IP_ECN).getEcnValue();
617 builder.matchIPEcn(ipEcn);
618 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800619 case IP_PROTO:
620 short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
621 builder.matchIPProtocol((byte) proto);
622 break;
623 case IPV4_SRC:
624 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
625 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800626 ip4Prefix = Ip4Prefix.valueOf(
627 maskedIp.getValue().getInt(),
628 maskedIp.getMask().asCidrMaskLength());
629 } else {
630 ip4Prefix = Ip4Prefix.valueOf(
631 match.get(MatchField.IPV4_SRC).getInt(),
632 Ip4Prefix.MAX_MASK_LENGTH);
633 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800634 builder.matchIPSrc(ip4Prefix);
635 break;
636 case IPV4_DST:
637 if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
638 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800639 ip4Prefix = Ip4Prefix.valueOf(
640 maskedIp.getValue().getInt(),
641 maskedIp.getMask().asCidrMaskLength());
642 } else {
643 ip4Prefix = Ip4Prefix.valueOf(
644 match.get(MatchField.IPV4_DST).getInt(),
645 Ip4Prefix.MAX_MASK_LENGTH);
646 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800647 builder.matchIPDst(ip4Prefix);
Jonathan Hart34bc6142014-10-17 11:00:43 -0700648 break;
649 case TCP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700650 builder.matchTcpSrc(TpPort.tpPort(match.get(MatchField.TCP_SRC).getPort()));
Jonathan Hart34bc6142014-10-17 11:00:43 -0700651 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800652 case TCP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700653 builder.matchTcpDst(TpPort.tpPort(match.get(MatchField.TCP_DST).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800654 break;
655 case UDP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700656 builder.matchUdpSrc(TpPort.tpPort(match.get(MatchField.UDP_SRC).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800657 break;
658 case UDP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700659 builder.matchUdpDst(TpPort.tpPort(match.get(MatchField.UDP_DST).getPort()));
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700660 break;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100661 case MPLS_LABEL:
662 builder.matchMplsLabel(MplsLabel.mplsLabel((int) match.get(MatchField.MPLS_LABEL)
663 .getValue()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800664 break;
Saurav Dasffc5bbc2015-08-18 23:30:19 -0700665 case MPLS_BOS:
666 builder.matchMplsBos(match.get(MatchField.MPLS_BOS).getValue());
667 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800668 case SCTP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700669 builder.matchSctpSrc(TpPort.tpPort(match.get(MatchField.SCTP_SRC).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800670 break;
671 case SCTP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700672 builder.matchSctpDst(TpPort.tpPort(match.get(MatchField.SCTP_DST).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800673 break;
674 case ICMPV4_TYPE:
675 byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
676 builder.matchIcmpType(icmpType);
677 break;
678 case ICMPV4_CODE:
679 byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode();
680 builder.matchIcmpCode(icmpCode);
681 break;
682 case IPV6_SRC:
683 if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
684 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
685 ip6Prefix = Ip6Prefix.valueOf(
686 maskedIp.getValue().getBytes(),
687 maskedIp.getMask().asCidrMaskLength());
688 } else {
689 ip6Prefix = Ip6Prefix.valueOf(
690 match.get(MatchField.IPV6_SRC).getBytes(),
691 Ip6Prefix.MAX_MASK_LENGTH);
692 }
693 builder.matchIPv6Src(ip6Prefix);
694 break;
695 case IPV6_DST:
696 if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
697 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
698 ip6Prefix = Ip6Prefix.valueOf(
699 maskedIp.getValue().getBytes(),
700 maskedIp.getMask().asCidrMaskLength());
701 } else {
702 ip6Prefix = Ip6Prefix.valueOf(
703 match.get(MatchField.IPV6_DST).getBytes(),
704 Ip6Prefix.MAX_MASK_LENGTH);
705 }
706 builder.matchIPv6Dst(ip6Prefix);
707 break;
708 case IPV6_FLABEL:
709 int flowLabel =
710 match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue();
711 builder.matchIPv6FlowLabel(flowLabel);
712 break;
713 case ICMPV6_TYPE:
714 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
715 builder.matchIcmpv6Type(icmpv6type);
716 break;
717 case ICMPV6_CODE:
718 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
719 builder.matchIcmpv6Code(icmpv6code);
720 break;
721 case IPV6_ND_TARGET:
722 ip6Address =
723 Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes());
724 builder.matchIPv6NDTargetAddress(ip6Address);
725 break;
726 case IPV6_ND_SLL:
727 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong());
728 builder.matchIPv6NDSourceLinkLayerAddress(mac);
729 break;
730 case IPV6_ND_TLL:
731 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong());
732 builder.matchIPv6NDTargetLinkLayerAddress(mac);
733 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800734 case IPV6_EXTHDR:
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800735 builder.matchIPv6ExthdrFlags((short) match.get(MatchField.IPV6_EXTHDR)
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700736 .getValue());
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800737 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700738 case OCH_SIGID:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700739 CircuitSignalID sigId = match.get(MatchField.OCH_SIGID);
740 builder.add(matchLambda(Lambda.ochSignal(
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700741 lookupGridType(sigId.getGridType()), lookupChannelSpacing(sigId.getChannelSpacing()),
Marc De Leenheer0b8b2ef2015-08-03 15:39:00 -0700742 sigId.getChannelNumber(), sigId.getSpectralWidth())
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700743 ));
Marc De Leenheer49087752014-10-23 13:54:09 -0700744 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800745 case OCH_SIGTYPE:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700746 U8 sigType = match.get(MatchField.OCH_SIGTYPE);
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700747 builder.add(matchOchSignalType(lookupOchSignalType((byte) sigType.getValue())));
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800748 break;
Yafit Hadar73514612015-11-04 10:14:21 +0200749 case EXP_OCH_SIG_ID:
750 try {
751 CircuitSignalID expSigId = match.get(MatchField.EXP_OCH_SIG_ID);
752 builder.add(matchLambda(Lambda.ochSignal(
753 lookupGridType(expSigId.getGridType()), lookupChannelSpacing(expSigId.getChannelSpacing()),
754 expSigId.getChannelNumber(), expSigId.getSpectralWidth())));
755 } catch (NoMappingFoundException e) {
756 log.warn(e.getMessage());
757 break;
758 }
759 break;
760 case EXP_OCH_SIGTYPE:
761 try {
762 U8 expOchSigType = match.get(MatchField.EXP_OCH_SIGTYPE);
763 builder.add(matchOchSignalType(lookupOchSignalType((byte) expOchSigType.getValue())));
764 } catch (NoMappingFoundException e) {
765 log.warn(e.getMessage());
766 break;
767 }
768 break;
769 case EXP_ODU_SIG_ID:
770 OduSignalId oduSignalId = OduSignalId.oduSignalId(match.get(MatchField.EXP_ODU_SIG_ID).getTpn(),
771 match.get(MatchField.EXP_ODU_SIG_ID).getTslen(),
772 match.get(MatchField.EXP_ODU_SIG_ID).getTsmap());
773 builder.add(matchOduSignalId(oduSignalId));
774 break;
775 case EXP_ODU_SIGTYPE:
776 try {
777 U8 oduSigType = match.get(MatchField.EXP_ODU_SIGTYPE);
778 builder.add(matchOduSignalType(lookupOduSignalType((byte) oduSigType.getValue())));
779 } catch (NoMappingFoundException e) {
780 log.warn(e.getMessage());
781 break;
782 }
783 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700784 case TUNNEL_ID:
785 long tunnelId = match.get(MatchField.TUNNEL_ID).getValue();
786 builder.matchTunnelId(tunnelId);
787 break;
BitOhenryb40129a2015-11-30 12:41:18 +0800788 case ARP_OP:
789 int arpOp = match.get(MatchField.ARP_OP).getOpcode();
790 builder.matchArpOp(arpOp);
791 break;
BitOhenrya331b182015-11-23 08:39:37 +0800792 case ARP_SHA:
793 mac = MacAddress.valueOf(match.get(MatchField.ARP_SHA).getLong());
794 builder.matchArpSha(mac);
795 break;
BitOhenry296b4542015-11-24 08:41:58 +0800796 case ARP_SPA:
797 ip = Ip4Address.valueOf(match.get(MatchField.ARP_SPA).getInt());
798 builder.matchArpSpa(ip);
799 break;
BitOhenry76430852015-11-20 19:04:49 +0800800 case ARP_THA:
801 mac = MacAddress.valueOf(match.get(MatchField.ARP_THA).getLong());
802 builder.matchArpTha(mac);
803 break;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800804 case ARP_TPA:
805 ip = Ip4Address.valueOf(match.get(MatchField.ARP_TPA).getInt());
806 builder.matchArpTpa(ip);
807 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700808 case MPLS_TC:
alshabib6b5cfec2014-09-18 17:42:18 -0700809 default:
810 log.warn("Match type {} not yet implemented.", field.id);
alshabib6b5cfec2014-09-18 17:42:18 -0700811 }
812 }
813 return builder.build();
814 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700815
816 private DriverHandler getDriver(Dpid dpid) {
817 DeviceId deviceId = DeviceId.deviceId(Dpid.uri(dpid));
818 Driver driver = driverService.getDriver(deviceId);
819 DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, deviceId));
820 return handler;
821 }
alshabib6b5cfec2014-09-18 17:42:18 -0700822}