blob: 1dfb35da1c19de501c8aa20972887151b03fac3b [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 Hart6cd2f352015-01-13 17:44:45 -080018import com.google.common.collect.Lists;
Saurav Das86af8f12015-05-25 23:55:33 -070019
Jonathan Hartd0ef7522014-12-11 11:51:18 -080020import org.onlab.packet.Ip4Address;
21import org.onlab.packet.Ip4Prefix;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080022import org.onlab.packet.Ip6Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080023import org.onlab.packet.Ip6Prefix;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080024import org.onlab.packet.MacAddress;
Michele Santuari4b6019e2014-12-19 11:31:45 +010025import org.onlab.packet.MplsLabel;
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;
Brian O'Connorabafb502014-12-02 22:26:20 -080030import org.onosproject.net.PortNumber;
31import org.onosproject.net.flow.DefaultFlowEntry;
32import org.onosproject.net.flow.DefaultFlowRule;
33import org.onosproject.net.flow.DefaultTrafficSelector;
34import org.onosproject.net.flow.DefaultTrafficTreatment;
35import org.onosproject.net.flow.FlowEntry;
36import org.onosproject.net.flow.FlowEntry.FlowEntryState;
37import org.onosproject.net.flow.FlowRule;
38import org.onosproject.net.flow.TrafficSelector;
39import org.onosproject.net.flow.TrafficTreatment;
40import org.onosproject.openflow.controller.Dpid;
Brian O'Connor72cb19a2015-01-16 16:14:41 -080041import org.projectfloodlight.openflow.protocol.OFFlowMod;
alshabib6b5cfec2014-09-18 17:42:18 -070042import org.projectfloodlight.openflow.protocol.OFFlowRemoved;
43import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry;
44import org.projectfloodlight.openflow.protocol.action.OFAction;
Marc De Leenheer49087752014-10-23 13:54:09 -070045import org.projectfloodlight.openflow.protocol.action.OFActionCircuit;
46import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter;
sangho8995ac52015-02-04 11:29:03 -080047import org.projectfloodlight.openflow.protocol.action.OFActionGroup;
alshabib6b5cfec2014-09-18 17:42:18 -070048import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
sangho3f97a17d2015-01-29 22:56:29 -080049import org.projectfloodlight.openflow.protocol.action.OFActionPopMpls;
alshabib6b5cfec2014-09-18 17:42:18 -070050import org.projectfloodlight.openflow.protocol.action.OFActionSetDlDst;
51import org.projectfloodlight.openflow.protocol.action.OFActionSetDlSrc;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080052import org.projectfloodlight.openflow.protocol.action.OFActionSetField;
alshabib6b5cfec2014-09-18 17:42:18 -070053import org.projectfloodlight.openflow.protocol.action.OFActionSetNwDst;
54import org.projectfloodlight.openflow.protocol.action.OFActionSetNwSrc;
55import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanPcp;
56import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanVid;
alshabib19fdc122014-10-03 11:38:19 -070057import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
Jonathan Hartcf783202014-11-24 18:55:42 -080058import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions;
alshabibbdcbb102015-04-22 14:16:38 -070059import org.projectfloodlight.openflow.protocol.instruction.OFInstructionGotoTable;
alshabib346b5b32015-03-06 00:42:16 -080060import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteActions;
Saurav Das86af8f12015-05-25 23:55:33 -070061import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteMetadata;
alshabib6b5cfec2014-09-18 17:42:18 -070062import org.projectfloodlight.openflow.protocol.match.Match;
63import org.projectfloodlight.openflow.protocol.match.MatchField;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080064import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
Marc De Leenheer49087752014-10-23 13:54:09 -070065import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigidBasic;
alshabib346b5b32015-03-06 00:42:16 -080066import org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070067import org.projectfloodlight.openflow.types.CircuitSignalID;
sanghoc0b3c342015-03-12 17:12:10 -070068import org.projectfloodlight.openflow.types.EthType;
alshabib6b5cfec2014-09-18 17:42:18 -070069import org.projectfloodlight.openflow.types.IPv4Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080070import org.projectfloodlight.openflow.types.IPv6Address;
Jonathan Hart0e12fad2014-10-17 14:54:58 -070071import org.projectfloodlight.openflow.types.Masked;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080072import org.projectfloodlight.openflow.types.OFVlanVidMatch;
sangho3f97a17d2015-01-29 22:56:29 -080073import org.projectfloodlight.openflow.types.U32;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070074import org.projectfloodlight.openflow.types.U8;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080075import org.projectfloodlight.openflow.types.VlanPcp;
alshabib6b5cfec2014-09-18 17:42:18 -070076import org.slf4j.Logger;
77
Jonathan Hart6cd2f352015-01-13 17:44:45 -080078import java.util.List;
79
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070080import static org.onosproject.net.flow.criteria.Criteria.matchLambda;
81import static org.onosproject.net.flow.criteria.Criteria.matchOchSignalType;
Sho SHIMIZUc17042d2015-05-28 12:07:23 -070082import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupChannelSpacing;
83import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupGridType;
84import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupOchSignalType;
Jonathan Hart6cd2f352015-01-13 17:44:45 -080085import static org.slf4j.LoggerFactory.getLogger;
alshabib19fdc122014-10-03 11:38:19 -070086
alshabib1c319ff2014-10-04 20:29:09 -070087public class FlowEntryBuilder {
alshabib6b5cfec2014-09-18 17:42:18 -070088 private final Logger log = getLogger(getClass());
89
90 private final OFFlowStatsEntry stat;
91 private final OFFlowRemoved removed;
Brian O'Connor72cb19a2015-01-16 16:14:41 -080092 private final OFFlowMod flowMod;
alshabib6b5cfec2014-09-18 17:42:18 -070093
94 private final Match match;
alshabib346b5b32015-03-06 00:42:16 -080095
Jonathan Hart67fc0972015-03-19 15:21:20 -070096 // All actions are contained in an OFInstruction. For OF1.0
97 // the instruction type is apply instruction (immediate set in ONOS speak)
alshabib346b5b32015-03-06 00:42:16 -080098 private final List<OFInstruction> instructions;
alshabib6b5cfec2014-09-18 17:42:18 -070099
100 private final Dpid dpid;
101
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800102 public enum FlowType { STAT, REMOVED, MOD }
103
104 private final FlowType type;
alshabib6b5cfec2014-09-18 17:42:18 -0700105
alshabibbdcbb102015-04-22 14:16:38 -0700106 public FlowEntryBuilder(Dpid dpid, OFFlowStatsEntry entry) {
Saurav Dasfa2fa932015-03-03 11:29:48 -0800107 this.stat = entry;
108 this.match = entry.getMatch();
alshabib346b5b32015-03-06 00:42:16 -0800109 this.instructions = getInstructions(entry);
Saurav Dasfa2fa932015-03-03 11:29:48 -0800110 this.dpid = dpid;
111 this.removed = null;
112 this.flowMod = null;
113 this.type = FlowType.STAT;
Saurav Dasfa2fa932015-03-03 11:29:48 -0800114 }
115
alshabibbdcbb102015-04-22 14:16:38 -0700116 public FlowEntryBuilder(Dpid dpid, OFFlowRemoved removed) {
alshabib6b5cfec2014-09-18 17:42:18 -0700117 this.match = removed.getMatch();
118 this.removed = removed;
119
120 this.dpid = dpid;
alshabib346b5b32015-03-06 00:42:16 -0800121 this.instructions = null;
alshabib6b5cfec2014-09-18 17:42:18 -0700122 this.stat = null;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800123 this.flowMod = null;
124 this.type = FlowType.REMOVED;
alshabib6b5cfec2014-09-18 17:42:18 -0700125
126 }
127
alshabibbdcbb102015-04-22 14:16:38 -0700128 public FlowEntryBuilder(Dpid dpid, OFFlowMod fm) {
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800129 this.match = fm.getMatch();
130 this.dpid = dpid;
alshabib346b5b32015-03-06 00:42:16 -0800131 this.instructions = getInstructions(fm);
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800132 this.type = FlowType.MOD;
133 this.flowMod = fm;
134 this.stat = null;
135 this.removed = null;
136 }
alshabib1c319ff2014-10-04 20:29:09 -0700137
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800138 public FlowEntry build(FlowEntryState... state) {
139 FlowRule rule;
140 switch (this.type) {
141 case STAT:
alshabibbdcbb102015-04-22 14:16:38 -0700142 rule = DefaultFlowRule.builder()
143 .forDevice(DeviceId.deviceId(Dpid.uri(dpid)))
144 .withSelector(buildSelector())
145 .withTreatment(buildTreatment())
146 .withPriority(stat.getPriority())
147 .makeTemporary(stat.getIdleTimeout())
148 .withCookie(stat.getCookie().getValue())
149 .forTable(stat.getTableId().getValue())
150 .build();
151
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800152 return new DefaultFlowEntry(rule, FlowEntryState.ADDED,
153 stat.getDurationSec(), stat.getPacketCount().getValue(),
154 stat.getByteCount().getValue());
155 case REMOVED:
alshabibbdcbb102015-04-22 14:16:38 -0700156 rule = DefaultFlowRule.builder()
157 .forDevice(DeviceId.deviceId(Dpid.uri(dpid)))
158 .withSelector(buildSelector())
159 .withPriority(removed.getPriority())
160 .makeTemporary(removed.getIdleTimeout())
161 .withCookie(removed.getCookie().getValue())
162 .forTable(removed.getTableId().getValue())
163 .build();
164
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800165 return new DefaultFlowEntry(rule, FlowEntryState.REMOVED, removed.getDurationSec(),
166 removed.getPacketCount().getValue(), removed.getByteCount().getValue());
167 case MOD:
168 FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED;
alshabibbdcbb102015-04-22 14:16:38 -0700169 rule = DefaultFlowRule.builder()
170 .forDevice(DeviceId.deviceId(Dpid.uri(dpid)))
171 .withSelector(buildSelector())
172 .withTreatment(buildTreatment())
173 .withPriority(flowMod.getPriority())
174 .makeTemporary(flowMod.getIdleTimeout())
175 .withCookie(flowMod.getCookie().getValue())
176 .forTable(flowMod.getTableId().getValue())
177 .build();
178
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800179 return new DefaultFlowEntry(rule, flowState, 0, 0, 0);
180 default:
181 log.error("Unknown flow type : {}", this.type);
182 return null;
alshabib6b5cfec2014-09-18 17:42:18 -0700183 }
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800184
alshabib6b5cfec2014-09-18 17:42:18 -0700185 }
186
alshabib346b5b32015-03-06 00:42:16 -0800187 private List<OFInstruction> getInstructions(OFFlowMod entry) {
alshabib19fdc122014-10-03 11:38:19 -0700188 switch (entry.getVersion()) {
189 case OF_10:
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700190 return Lists.newArrayList(OFFactoryVer13.INSTANCE.instructions()
191 .applyActions(
192 entry.getActions()));
alshabib19fdc122014-10-03 11:38:19 -0700193 case OF_11:
194 case OF_12:
195 case OF_13:
alshabib346b5b32015-03-06 00:42:16 -0800196 return entry.getInstructions();
197 default:
198 log.warn("Unknown OF version {}", entry.getVersion());
199 }
200 return Lists.newLinkedList();
201 }
202
203 private List<OFInstruction> getInstructions(OFFlowStatsEntry entry) {
204 switch (entry.getVersion()) {
205 case OF_10:
206 return Lists.newArrayList(
207 OFFactoryVer13.INSTANCE.instructions().applyActions(entry.getActions()));
208 case OF_11:
209 case OF_12:
210 case OF_13:
211 return entry.getInstructions();
alshabib19fdc122014-10-03 11:38:19 -0700212 default:
213 log.warn("Unknown OF version {}", entry.getVersion());
214 }
215 return Lists.newLinkedList();
216 }
alshabib6b5cfec2014-09-18 17:42:18 -0700217
218 private TrafficTreatment buildTreatment() {
tom9a693fd2014-10-03 11:32:19 -0700219 TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700220 // If this is a drop rule
alshabib346b5b32015-03-06 00:42:16 -0800221 if (instructions.size() == 0) {
alshabib010c31d2014-09-26 10:01:12 -0700222 builder.drop();
alshabib6b5cfec2014-09-18 17:42:18 -0700223 return builder.build();
224 }
alshabib346b5b32015-03-06 00:42:16 -0800225 for (OFInstruction in : instructions) {
226 switch (in.getType()) {
227 case GOTO_TABLE:
alshabibbdcbb102015-04-22 14:16:38 -0700228 builder.transition(((int) ((OFInstructionGotoTable) in)
229 .getTableId().getValue()));
alshabib346b5b32015-03-06 00:42:16 -0800230 break;
231 case WRITE_METADATA:
Saurav Das86af8f12015-05-25 23:55:33 -0700232 OFInstructionWriteMetadata m = (OFInstructionWriteMetadata) in;
233 builder.writeMetadata(m.getMetadata().getValue(),
234 m.getMetadataMask().getValue());
alshabib346b5b32015-03-06 00:42:16 -0800235 break;
236 case WRITE_ACTIONS:
237 builder.deferred();
238 buildActions(((OFInstructionWriteActions) in).getActions(),
239 builder);
240 break;
241 case APPLY_ACTIONS:
242 builder.immediate();
243 buildActions(((OFInstructionApplyActions) in).getActions(),
244 builder);
245 break;
246 case CLEAR_ACTIONS:
247 builder.wipeDeferred();
248 break;
249 case EXPERIMENTER:
250 break;
251 case METER:
252 break;
253 default:
254 log.warn("Unknown instructions type {}", in.getType());
alshabib6b5cfec2014-09-18 17:42:18 -0700255 }
256 }
257
258 return builder.build();
259 }
260
alshabib346b5b32015-03-06 00:42:16 -0800261 private TrafficTreatment.Builder buildActions(List<OFAction> actions,
262 TrafficTreatment.Builder builder) {
263 for (OFAction act : actions) {
264 switch (act.getType()) {
265 case OUTPUT:
266 OFActionOutput out = (OFActionOutput) act;
267 builder.setOutput(
268 PortNumber.portNumber(out.getPort().getPortNumber()));
269 break;
270 case SET_VLAN_VID:
271 OFActionSetVlanVid vlan = (OFActionSetVlanVid) act;
272 builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan()));
273 break;
274 case SET_VLAN_PCP:
275 OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act;
276 builder.setVlanPcp(pcp.getVlanPcp().getValue());
277 break;
278 case SET_DL_DST:
279 OFActionSetDlDst dldst = (OFActionSetDlDst) act;
280 builder.setEthDst(
281 MacAddress.valueOf(dldst.getDlAddr().getLong()));
282 break;
283 case SET_DL_SRC:
284 OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act;
285 builder.setEthSrc(
286 MacAddress.valueOf(dlsrc.getDlAddr().getLong()));
287
288 break;
289 case SET_NW_DST:
290 OFActionSetNwDst nwdst = (OFActionSetNwDst) act;
291 IPv4Address di = nwdst.getNwAddr();
292 builder.setIpDst(Ip4Address.valueOf(di.getInt()));
293 break;
294 case SET_NW_SRC:
295 OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act;
296 IPv4Address si = nwsrc.getNwAddr();
297 builder.setIpSrc(Ip4Address.valueOf(si.getInt()));
298 break;
299 case EXPERIMENTER:
300 OFActionExperimenter exp = (OFActionExperimenter) act;
301 if (exp.getExperimenter() == 0x80005A06 ||
302 exp.getExperimenter() == 0x748771) {
303 OFActionCircuit ct = (OFActionCircuit) exp;
304 builder.setLambda(((OFOxmOchSigidBasic) ct.getField()).getValue().getChannelNumber());
305 } else {
306 log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter());
307 }
308 break;
309 case SET_FIELD:
310 OFActionSetField setField = (OFActionSetField) act;
311 handleSetField(builder, setField.getField());
312 break;
313 case POP_MPLS:
314 OFActionPopMpls popMpls = (OFActionPopMpls) act;
315 builder.popMpls((short) popMpls.getEthertype().getValue());
316 break;
317 case PUSH_MPLS:
318 builder.pushMpls();
319 break;
320 case COPY_TTL_IN:
321 builder.copyTtlIn();
322 break;
323 case COPY_TTL_OUT:
324 builder.copyTtlOut();
325 break;
326 case DEC_MPLS_TTL:
327 builder.decMplsTtl();
328 break;
329 case DEC_NW_TTL:
330 builder.decNwTtl();
331 break;
332 case GROUP:
333 OFActionGroup group = (OFActionGroup) act;
334 builder.group(new DefaultGroupId(group.getGroup().getGroupNumber()));
335 break;
Jonathan Hart67fc0972015-03-19 15:21:20 -0700336 case STRIP_VLAN:
alshabib346b5b32015-03-06 00:42:16 -0800337 case POP_VLAN:
338 builder.popVlan();
339 break;
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700340 case PUSH_VLAN:
341 builder.pushVlan();
342 break;
alshabib346b5b32015-03-06 00:42:16 -0800343 case SET_TP_DST:
344 case SET_TP_SRC:
345 case POP_PBB:
346 case PUSH_PBB:
alshabib346b5b32015-03-06 00:42:16 -0800347 case SET_MPLS_LABEL:
348 case SET_MPLS_TC:
349 case SET_MPLS_TTL:
350 case SET_NW_ECN:
351 case SET_NW_TOS:
352 case SET_NW_TTL:
353 case SET_QUEUE:
354
355 case ENQUEUE:
356 default:
357 log.warn("Action type {} not yet implemented.", act.getType());
358 }
359 }
360 return builder;
361 }
362
363
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800364 private void handleSetField(TrafficTreatment.Builder builder, OFOxm<?> oxm) {
365 switch (oxm.getMatchField().id) {
366 case VLAN_PCP:
367 @SuppressWarnings("unchecked")
368 OFOxm<VlanPcp> vlanpcp = (OFOxm<VlanPcp>) oxm;
369 builder.setVlanPcp(vlanpcp.getValue().getValue());
370 break;
371 case VLAN_VID:
372 @SuppressWarnings("unchecked")
373 OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm;
374 builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan()));
375 break;
376 case ETH_DST:
377 @SuppressWarnings("unchecked")
378 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethdst =
379 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
380 builder.setEthDst(MacAddress.valueOf(ethdst.getValue().getLong()));
381 break;
382 case ETH_SRC:
383 @SuppressWarnings("unchecked")
384 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethsrc =
385 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
386 builder.setEthSrc(MacAddress.valueOf(ethsrc.getValue().getLong()));
387 break;
388 case IPV4_DST:
389 @SuppressWarnings("unchecked")
390 OFOxm<IPv4Address> ip4dst = (OFOxm<IPv4Address>) oxm;
391 builder.setIpDst(Ip4Address.valueOf(ip4dst.getValue().getInt()));
392 break;
393 case IPV4_SRC:
394 @SuppressWarnings("unchecked")
395 OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm;
396 builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt()));
397 break;
sangho3f97a17d2015-01-29 22:56:29 -0800398 case MPLS_LABEL:
399 @SuppressWarnings("unchecked")
400 OFOxm<U32> labelId = (OFOxm<U32>) oxm;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100401 builder.setMpls(MplsLabel.mplsLabel((int) labelId.getValue().getValue()));
sangho3f97a17d2015-01-29 22:56:29 -0800402 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800403 case ARP_OP:
404 case ARP_SHA:
405 case ARP_SPA:
406 case ARP_THA:
407 case ARP_TPA:
408 case BSN_EGR_PORT_GROUP_ID:
409 case BSN_GLOBAL_VRF_ALLOWED:
410 case BSN_IN_PORTS_128:
411 case BSN_L3_DST_CLASS_ID:
412 case BSN_L3_INTERFACE_CLASS_ID:
413 case BSN_L3_SRC_CLASS_ID:
414 case BSN_LAG_ID:
415 case BSN_TCP_FLAGS:
416 case BSN_UDF0:
417 case BSN_UDF1:
418 case BSN_UDF2:
419 case BSN_UDF3:
420 case BSN_UDF4:
421 case BSN_UDF5:
422 case BSN_UDF6:
423 case BSN_UDF7:
424 case BSN_VLAN_XLATE_PORT_GROUP_ID:
425 case BSN_VRF:
426 case ETH_TYPE:
427 case ICMPV4_CODE:
428 case ICMPV4_TYPE:
429 case ICMPV6_CODE:
430 case ICMPV6_TYPE:
431 case IN_PHY_PORT:
432 case IN_PORT:
433 case IPV6_DST:
434 case IPV6_FLABEL:
435 case IPV6_ND_SLL:
436 case IPV6_ND_TARGET:
437 case IPV6_ND_TLL:
438 case IPV6_SRC:
439 case IP_DSCP:
440 case IP_ECN:
441 case IP_PROTO:
442 case METADATA:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800443 case MPLS_TC:
444 case OCH_SIGID:
445 case OCH_SIGID_BASIC:
446 case OCH_SIGTYPE:
447 case OCH_SIGTYPE_BASIC:
448 case SCTP_DST:
449 case SCTP_SRC:
450 case TCP_DST:
451 case TCP_SRC:
452 case TUNNEL_ID:
453 case UDP_DST:
454 case UDP_SRC:
455 default:
456 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
457 break;
458 }
459 }
460
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700461 // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES
alshabib6b5cfec2014-09-18 17:42:18 -0700462 private TrafficSelector buildSelector() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800463 MacAddress mac;
464 Ip4Prefix ip4Prefix;
465 Ip6Address ip6Address;
466 Ip6Prefix ip6Prefix;
467
tom9a693fd2014-10-03 11:32:19 -0700468 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700469 for (MatchField<?> field : match.getMatchFields()) {
470 switch (field.id) {
471 case IN_PORT:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800472 builder.matchInPort(PortNumber
alshabib010c31d2014-09-26 10:01:12 -0700473 .portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700474 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800475 case IN_PHY_PORT:
476 builder.matchInPhyPort(PortNumber
477 .portNumber(match.get(MatchField.IN_PHY_PORT).getPortNumber()));
478 break;
479 case METADATA:
480 long metadata =
481 match.get(MatchField.METADATA).getValue().getValue();
482 builder.matchMetadata(metadata);
483 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700484 case ETH_DST:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800485 mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
486 builder.matchEthDst(mac);
487 break;
488 case ETH_SRC:
489 mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
490 builder.matchEthSrc(mac);
alshabib6b5cfec2014-09-18 17:42:18 -0700491 break;
492 case ETH_TYPE:
493 int ethType = match.get(MatchField.ETH_TYPE).getValue();
sanghoc0b3c342015-03-12 17:12:10 -0700494 if (ethType == EthType.VLAN_FRAME.getValue()) {
495 builder.matchVlanId(VlanId.ANY);
496 } else {
497 builder.matchEthType((short) ethType);
498 }
alshabib6b5cfec2014-09-18 17:42:18 -0700499 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700500 case VLAN_VID:
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800501 VlanId vlanId = null;
502 if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
503 Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
504 if (masked.getValue().equals(OFVlanVidMatch.PRESENT)
505 && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
506 vlanId = VlanId.ANY;
507 }
508 } else {
509 vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
510 }
511 if (vlanId != null) {
512 builder.matchVlanId(vlanId);
513 }
alshabib6b5cfec2014-09-18 17:42:18 -0700514 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800515 case VLAN_PCP:
516 byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
517 builder.matchVlanPcp(vlanPcp);
518 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800519 case IP_DSCP:
520 byte ipDscp = match.get(MatchField.IP_DSCP).getDscpValue();
521 builder.matchIPDscp(ipDscp);
522 break;
523 case IP_ECN:
524 byte ipEcn = match.get(MatchField.IP_ECN).getEcnValue();
525 builder.matchIPEcn(ipEcn);
526 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800527 case IP_PROTO:
528 short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
529 builder.matchIPProtocol((byte) proto);
530 break;
531 case IPV4_SRC:
532 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
533 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800534 ip4Prefix = Ip4Prefix.valueOf(
535 maskedIp.getValue().getInt(),
536 maskedIp.getMask().asCidrMaskLength());
537 } else {
538 ip4Prefix = Ip4Prefix.valueOf(
539 match.get(MatchField.IPV4_SRC).getInt(),
540 Ip4Prefix.MAX_MASK_LENGTH);
541 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800542 builder.matchIPSrc(ip4Prefix);
543 break;
544 case IPV4_DST:
545 if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
546 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800547 ip4Prefix = Ip4Prefix.valueOf(
548 maskedIp.getValue().getInt(),
549 maskedIp.getMask().asCidrMaskLength());
550 } else {
551 ip4Prefix = Ip4Prefix.valueOf(
552 match.get(MatchField.IPV4_DST).getInt(),
553 Ip4Prefix.MAX_MASK_LENGTH);
554 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800555 builder.matchIPDst(ip4Prefix);
Jonathan Hart34bc6142014-10-17 11:00:43 -0700556 break;
557 case TCP_SRC:
558 builder.matchTcpSrc((short) match.get(MatchField.TCP_SRC).getPort());
559 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800560 case TCP_DST:
561 builder.matchTcpDst((short) match.get(MatchField.TCP_DST).getPort());
562 break;
563 case UDP_SRC:
564 builder.matchUdpSrc((short) match.get(MatchField.UDP_SRC).getPort());
565 break;
566 case UDP_DST:
567 builder.matchUdpDst((short) match.get(MatchField.UDP_DST).getPort());
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700568 break;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100569 case MPLS_LABEL:
570 builder.matchMplsLabel(MplsLabel.mplsLabel((int) match.get(MatchField.MPLS_LABEL)
571 .getValue()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800572 break;
573 case SCTP_SRC:
574 builder.matchSctpSrc((short) match.get(MatchField.SCTP_SRC).getPort());
575 break;
576 case SCTP_DST:
577 builder.matchSctpDst((short) match.get(MatchField.SCTP_DST).getPort());
578 break;
579 case ICMPV4_TYPE:
580 byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
581 builder.matchIcmpType(icmpType);
582 break;
583 case ICMPV4_CODE:
584 byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode();
585 builder.matchIcmpCode(icmpCode);
586 break;
587 case IPV6_SRC:
588 if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
589 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
590 ip6Prefix = Ip6Prefix.valueOf(
591 maskedIp.getValue().getBytes(),
592 maskedIp.getMask().asCidrMaskLength());
593 } else {
594 ip6Prefix = Ip6Prefix.valueOf(
595 match.get(MatchField.IPV6_SRC).getBytes(),
596 Ip6Prefix.MAX_MASK_LENGTH);
597 }
598 builder.matchIPv6Src(ip6Prefix);
599 break;
600 case IPV6_DST:
601 if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
602 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
603 ip6Prefix = Ip6Prefix.valueOf(
604 maskedIp.getValue().getBytes(),
605 maskedIp.getMask().asCidrMaskLength());
606 } else {
607 ip6Prefix = Ip6Prefix.valueOf(
608 match.get(MatchField.IPV6_DST).getBytes(),
609 Ip6Prefix.MAX_MASK_LENGTH);
610 }
611 builder.matchIPv6Dst(ip6Prefix);
612 break;
613 case IPV6_FLABEL:
614 int flowLabel =
615 match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue();
616 builder.matchIPv6FlowLabel(flowLabel);
617 break;
618 case ICMPV6_TYPE:
619 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
620 builder.matchIcmpv6Type(icmpv6type);
621 break;
622 case ICMPV6_CODE:
623 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
624 builder.matchIcmpv6Code(icmpv6code);
625 break;
626 case IPV6_ND_TARGET:
627 ip6Address =
628 Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes());
629 builder.matchIPv6NDTargetAddress(ip6Address);
630 break;
631 case IPV6_ND_SLL:
632 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong());
633 builder.matchIPv6NDSourceLinkLayerAddress(mac);
634 break;
635 case IPV6_ND_TLL:
636 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong());
637 builder.matchIPv6NDTargetLinkLayerAddress(mac);
638 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800639 case IPV6_EXTHDR:
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800640 builder.matchIPv6ExthdrFlags((short) match.get(MatchField.IPV6_EXTHDR)
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800641 .getValue());
642 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700643 case OCH_SIGID:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700644 CircuitSignalID sigId = match.get(MatchField.OCH_SIGID);
645 builder.add(matchLambda(Lambda.ochSignal(
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700646 lookupGridType(sigId.getGridType()), lookupChannelSpacing(sigId.getChannelSpacing()),
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700647 sigId.getChannelNumber(), sigId.getChannelSpacing())
648 ));
Marc De Leenheer49087752014-10-23 13:54:09 -0700649 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800650 case OCH_SIGTYPE:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700651 U8 sigType = match.get(MatchField.OCH_SIGTYPE);
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700652 builder.add(matchOchSignalType(lookupOchSignalType((byte) sigType.getValue())));
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800653 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700654 case ARP_OP:
655 case ARP_SHA:
656 case ARP_SPA:
657 case ARP_THA:
658 case ARP_TPA:
alshabib6b5cfec2014-09-18 17:42:18 -0700659 case MPLS_TC:
alshabib6b5cfec2014-09-18 17:42:18 -0700660 case TUNNEL_ID:
alshabib6b5cfec2014-09-18 17:42:18 -0700661 default:
662 log.warn("Match type {} not yet implemented.", field.id);
alshabib6b5cfec2014-09-18 17:42:18 -0700663 }
664 }
665 return builder.build();
666 }
alshabib6b5cfec2014-09-18 17:42:18 -0700667}