blob: 46055648446ee7a7c15efed50d1a3c5e8f2eed90 [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;
Sho SHIMIZU9553bb82015-06-30 16:02:45 -070040import org.onosproject.net.flow.instructions.Instructions;
Brian O'Connorabafb502014-12-02 22:26:20 -080041import org.onosproject.openflow.controller.Dpid;
Brian O'Connor72cb19a2015-01-16 16:14:41 -080042import org.projectfloodlight.openflow.protocol.OFFlowMod;
alshabib6b5cfec2014-09-18 17:42:18 -070043import org.projectfloodlight.openflow.protocol.OFFlowRemoved;
44import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry;
45import org.projectfloodlight.openflow.protocol.action.OFAction;
Marc De Leenheer49087752014-10-23 13:54:09 -070046import org.projectfloodlight.openflow.protocol.action.OFActionCircuit;
47import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter;
sangho8995ac52015-02-04 11:29:03 -080048import org.projectfloodlight.openflow.protocol.action.OFActionGroup;
alshabib6b5cfec2014-09-18 17:42:18 -070049import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
sangho3f97a17d2015-01-29 22:56:29 -080050import org.projectfloodlight.openflow.protocol.action.OFActionPopMpls;
alshabib6b5cfec2014-09-18 17:42:18 -070051import org.projectfloodlight.openflow.protocol.action.OFActionSetDlDst;
52import org.projectfloodlight.openflow.protocol.action.OFActionSetDlSrc;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080053import org.projectfloodlight.openflow.protocol.action.OFActionSetField;
alshabib6b5cfec2014-09-18 17:42:18 -070054import org.projectfloodlight.openflow.protocol.action.OFActionSetNwDst;
55import org.projectfloodlight.openflow.protocol.action.OFActionSetNwSrc;
56import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanPcp;
57import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanVid;
alshabib19fdc122014-10-03 11:38:19 -070058import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
Jonathan Hartcf783202014-11-24 18:55:42 -080059import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions;
alshabibbdcbb102015-04-22 14:16:38 -070060import org.projectfloodlight.openflow.protocol.instruction.OFInstructionGotoTable;
alshabib346b5b32015-03-06 00:42:16 -080061import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteActions;
Saurav Das86af8f12015-05-25 23:55:33 -070062import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteMetadata;
alshabib6b5cfec2014-09-18 17:42:18 -070063import org.projectfloodlight.openflow.protocol.match.Match;
64import org.projectfloodlight.openflow.protocol.match.MatchField;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080065import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
Marc De Leenheer49087752014-10-23 13:54:09 -070066import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigidBasic;
alshabib346b5b32015-03-06 00:42:16 -080067import org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070068import org.projectfloodlight.openflow.types.CircuitSignalID;
sanghoc0b3c342015-03-12 17:12:10 -070069import org.projectfloodlight.openflow.types.EthType;
alshabib6b5cfec2014-09-18 17:42:18 -070070import org.projectfloodlight.openflow.types.IPv4Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080071import org.projectfloodlight.openflow.types.IPv6Address;
Jonathan Hart0e12fad2014-10-17 14:54:58 -070072import org.projectfloodlight.openflow.types.Masked;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080073import org.projectfloodlight.openflow.types.OFVlanVidMatch;
sangho3f97a17d2015-01-29 22:56:29 -080074import org.projectfloodlight.openflow.types.U32;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070075import org.projectfloodlight.openflow.types.U8;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080076import org.projectfloodlight.openflow.types.VlanPcp;
alshabib6b5cfec2014-09-18 17:42:18 -070077import org.slf4j.Logger;
78
Jonathan Hart6cd2f352015-01-13 17:44:45 -080079import java.util.List;
80
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070081import static org.onosproject.net.flow.criteria.Criteria.matchLambda;
82import static org.onosproject.net.flow.criteria.Criteria.matchOchSignalType;
Sho SHIMIZUc17042d2015-05-28 12:07:23 -070083import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupChannelSpacing;
84import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupGridType;
85import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupOchSignalType;
Jonathan Hart6cd2f352015-01-13 17:44:45 -080086import static org.slf4j.LoggerFactory.getLogger;
alshabib19fdc122014-10-03 11:38:19 -070087
alshabib1c319ff2014-10-04 20:29:09 -070088public class FlowEntryBuilder {
alshabib6b5cfec2014-09-18 17:42:18 -070089 private final Logger log = getLogger(getClass());
90
91 private final OFFlowStatsEntry stat;
92 private final OFFlowRemoved removed;
Brian O'Connor72cb19a2015-01-16 16:14:41 -080093 private final OFFlowMod flowMod;
alshabib6b5cfec2014-09-18 17:42:18 -070094
95 private final Match match;
alshabib346b5b32015-03-06 00:42:16 -080096
Jonathan Hart67fc0972015-03-19 15:21:20 -070097 // All actions are contained in an OFInstruction. For OF1.0
98 // the instruction type is apply instruction (immediate set in ONOS speak)
alshabib346b5b32015-03-06 00:42:16 -080099 private final List<OFInstruction> instructions;
alshabib6b5cfec2014-09-18 17:42:18 -0700100
101 private final Dpid dpid;
102
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800103 public enum FlowType { STAT, REMOVED, MOD }
104
105 private final FlowType type;
alshabib6b5cfec2014-09-18 17:42:18 -0700106
alshabibbdcbb102015-04-22 14:16:38 -0700107 public FlowEntryBuilder(Dpid dpid, OFFlowStatsEntry entry) {
Saurav Dasfa2fa932015-03-03 11:29:48 -0800108 this.stat = entry;
109 this.match = entry.getMatch();
alshabib346b5b32015-03-06 00:42:16 -0800110 this.instructions = getInstructions(entry);
Saurav Dasfa2fa932015-03-03 11:29:48 -0800111 this.dpid = dpid;
112 this.removed = null;
113 this.flowMod = null;
114 this.type = FlowType.STAT;
Saurav Dasfa2fa932015-03-03 11:29:48 -0800115 }
116
alshabibbdcbb102015-04-22 14:16:38 -0700117 public FlowEntryBuilder(Dpid dpid, OFFlowRemoved removed) {
alshabib6b5cfec2014-09-18 17:42:18 -0700118 this.match = removed.getMatch();
119 this.removed = removed;
120
121 this.dpid = dpid;
alshabib346b5b32015-03-06 00:42:16 -0800122 this.instructions = null;
alshabib6b5cfec2014-09-18 17:42:18 -0700123 this.stat = null;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800124 this.flowMod = null;
125 this.type = FlowType.REMOVED;
alshabib6b5cfec2014-09-18 17:42:18 -0700126
127 }
128
alshabibbdcbb102015-04-22 14:16:38 -0700129 public FlowEntryBuilder(Dpid dpid, OFFlowMod fm) {
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800130 this.match = fm.getMatch();
131 this.dpid = dpid;
alshabib346b5b32015-03-06 00:42:16 -0800132 this.instructions = getInstructions(fm);
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800133 this.type = FlowType.MOD;
134 this.flowMod = fm;
135 this.stat = null;
136 this.removed = null;
137 }
alshabib1c319ff2014-10-04 20:29:09 -0700138
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800139 public FlowEntry build(FlowEntryState... state) {
140 FlowRule rule;
141 switch (this.type) {
142 case STAT:
alshabibbdcbb102015-04-22 14:16:38 -0700143 rule = DefaultFlowRule.builder()
144 .forDevice(DeviceId.deviceId(Dpid.uri(dpid)))
145 .withSelector(buildSelector())
146 .withTreatment(buildTreatment())
147 .withPriority(stat.getPriority())
148 .makeTemporary(stat.getIdleTimeout())
149 .withCookie(stat.getCookie().getValue())
150 .forTable(stat.getTableId().getValue())
151 .build();
152
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800153 return new DefaultFlowEntry(rule, FlowEntryState.ADDED,
154 stat.getDurationSec(), stat.getPacketCount().getValue(),
155 stat.getByteCount().getValue());
156 case REMOVED:
alshabibbdcbb102015-04-22 14:16:38 -0700157 rule = DefaultFlowRule.builder()
158 .forDevice(DeviceId.deviceId(Dpid.uri(dpid)))
159 .withSelector(buildSelector())
160 .withPriority(removed.getPriority())
161 .makeTemporary(removed.getIdleTimeout())
162 .withCookie(removed.getCookie().getValue())
163 .forTable(removed.getTableId().getValue())
164 .build();
165
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800166 return new DefaultFlowEntry(rule, FlowEntryState.REMOVED, removed.getDurationSec(),
167 removed.getPacketCount().getValue(), removed.getByteCount().getValue());
168 case MOD:
169 FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED;
alshabibbdcbb102015-04-22 14:16:38 -0700170 rule = DefaultFlowRule.builder()
171 .forDevice(DeviceId.deviceId(Dpid.uri(dpid)))
172 .withSelector(buildSelector())
173 .withTreatment(buildTreatment())
174 .withPriority(flowMod.getPriority())
175 .makeTemporary(flowMod.getIdleTimeout())
176 .withCookie(flowMod.getCookie().getValue())
177 .forTable(flowMod.getTableId().getValue())
178 .build();
179
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800180 return new DefaultFlowEntry(rule, flowState, 0, 0, 0);
181 default:
182 log.error("Unknown flow type : {}", this.type);
183 return null;
alshabib6b5cfec2014-09-18 17:42:18 -0700184 }
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800185
alshabib6b5cfec2014-09-18 17:42:18 -0700186 }
187
alshabib346b5b32015-03-06 00:42:16 -0800188 private List<OFInstruction> getInstructions(OFFlowMod entry) {
alshabib19fdc122014-10-03 11:38:19 -0700189 switch (entry.getVersion()) {
190 case OF_10:
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700191 return Lists.newArrayList(OFFactoryVer13.INSTANCE.instructions()
192 .applyActions(
193 entry.getActions()));
alshabib19fdc122014-10-03 11:38:19 -0700194 case OF_11:
195 case OF_12:
196 case OF_13:
alshabib346b5b32015-03-06 00:42:16 -0800197 return entry.getInstructions();
198 default:
199 log.warn("Unknown OF version {}", entry.getVersion());
200 }
201 return Lists.newLinkedList();
202 }
203
204 private List<OFInstruction> getInstructions(OFFlowStatsEntry entry) {
205 switch (entry.getVersion()) {
206 case OF_10:
207 return Lists.newArrayList(
208 OFFactoryVer13.INSTANCE.instructions().applyActions(entry.getActions()));
209 case OF_11:
210 case OF_12:
211 case OF_13:
212 return entry.getInstructions();
alshabib19fdc122014-10-03 11:38:19 -0700213 default:
214 log.warn("Unknown OF version {}", entry.getVersion());
215 }
216 return Lists.newLinkedList();
217 }
alshabib6b5cfec2014-09-18 17:42:18 -0700218
219 private TrafficTreatment buildTreatment() {
tom9a693fd2014-10-03 11:32:19 -0700220 TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700221 // If this is a drop rule
alshabib346b5b32015-03-06 00:42:16 -0800222 if (instructions.size() == 0) {
alshabib010c31d2014-09-26 10:01:12 -0700223 builder.drop();
alshabib6b5cfec2014-09-18 17:42:18 -0700224 return builder.build();
225 }
alshabib346b5b32015-03-06 00:42:16 -0800226 for (OFInstruction in : instructions) {
227 switch (in.getType()) {
228 case GOTO_TABLE:
alshabibbdcbb102015-04-22 14:16:38 -0700229 builder.transition(((int) ((OFInstructionGotoTable) in)
230 .getTableId().getValue()));
alshabib346b5b32015-03-06 00:42:16 -0800231 break;
232 case WRITE_METADATA:
Saurav Das86af8f12015-05-25 23:55:33 -0700233 OFInstructionWriteMetadata m = (OFInstructionWriteMetadata) in;
234 builder.writeMetadata(m.getMetadata().getValue(),
235 m.getMetadataMask().getValue());
alshabib346b5b32015-03-06 00:42:16 -0800236 break;
237 case WRITE_ACTIONS:
238 builder.deferred();
239 buildActions(((OFInstructionWriteActions) in).getActions(),
240 builder);
241 break;
242 case APPLY_ACTIONS:
243 builder.immediate();
244 buildActions(((OFInstructionApplyActions) in).getActions(),
245 builder);
246 break;
247 case CLEAR_ACTIONS:
248 builder.wipeDeferred();
249 break;
250 case EXPERIMENTER:
251 break;
252 case METER:
253 break;
254 default:
255 log.warn("Unknown instructions type {}", in.getType());
alshabib6b5cfec2014-09-18 17:42:18 -0700256 }
257 }
258
259 return builder.build();
260 }
261
alshabib346b5b32015-03-06 00:42:16 -0800262 private TrafficTreatment.Builder buildActions(List<OFAction> actions,
263 TrafficTreatment.Builder builder) {
264 for (OFAction act : actions) {
265 switch (act.getType()) {
266 case OUTPUT:
267 OFActionOutput out = (OFActionOutput) act;
268 builder.setOutput(
269 PortNumber.portNumber(out.getPort().getPortNumber()));
270 break;
271 case SET_VLAN_VID:
272 OFActionSetVlanVid vlan = (OFActionSetVlanVid) act;
273 builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan()));
274 break;
275 case SET_VLAN_PCP:
276 OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act;
277 builder.setVlanPcp(pcp.getVlanPcp().getValue());
278 break;
279 case SET_DL_DST:
280 OFActionSetDlDst dldst = (OFActionSetDlDst) act;
281 builder.setEthDst(
282 MacAddress.valueOf(dldst.getDlAddr().getLong()));
283 break;
284 case SET_DL_SRC:
285 OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act;
286 builder.setEthSrc(
287 MacAddress.valueOf(dlsrc.getDlAddr().getLong()));
288
289 break;
290 case SET_NW_DST:
291 OFActionSetNwDst nwdst = (OFActionSetNwDst) act;
292 IPv4Address di = nwdst.getNwAddr();
293 builder.setIpDst(Ip4Address.valueOf(di.getInt()));
294 break;
295 case SET_NW_SRC:
296 OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act;
297 IPv4Address si = nwsrc.getNwAddr();
298 builder.setIpSrc(Ip4Address.valueOf(si.getInt()));
299 break;
300 case EXPERIMENTER:
301 OFActionExperimenter exp = (OFActionExperimenter) act;
302 if (exp.getExperimenter() == 0x80005A06 ||
303 exp.getExperimenter() == 0x748771) {
304 OFActionCircuit ct = (OFActionCircuit) exp;
Sho SHIMIZU9553bb82015-06-30 16:02:45 -0700305 short lambda = ((OFOxmOchSigidBasic) ct.getField()).getValue().getChannelNumber();
306 builder.add(Instructions.modL0Lambda(Lambda.indexedLambda(lambda)));
alshabib346b5b32015-03-06 00:42:16 -0800307 } else {
308 log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter());
309 }
310 break;
311 case SET_FIELD:
312 OFActionSetField setField = (OFActionSetField) act;
313 handleSetField(builder, setField.getField());
314 break;
315 case POP_MPLS:
316 OFActionPopMpls popMpls = (OFActionPopMpls) act;
317 builder.popMpls((short) popMpls.getEthertype().getValue());
318 break;
319 case PUSH_MPLS:
320 builder.pushMpls();
321 break;
322 case COPY_TTL_IN:
323 builder.copyTtlIn();
324 break;
325 case COPY_TTL_OUT:
326 builder.copyTtlOut();
327 break;
328 case DEC_MPLS_TTL:
329 builder.decMplsTtl();
330 break;
331 case DEC_NW_TTL:
332 builder.decNwTtl();
333 break;
334 case GROUP:
335 OFActionGroup group = (OFActionGroup) act;
336 builder.group(new DefaultGroupId(group.getGroup().getGroupNumber()));
337 break;
Jonathan Hart67fc0972015-03-19 15:21:20 -0700338 case STRIP_VLAN:
alshabib346b5b32015-03-06 00:42:16 -0800339 case POP_VLAN:
340 builder.popVlan();
341 break;
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700342 case PUSH_VLAN:
343 builder.pushVlan();
344 break;
alshabib346b5b32015-03-06 00:42:16 -0800345 case SET_TP_DST:
346 case SET_TP_SRC:
347 case POP_PBB:
348 case PUSH_PBB:
alshabib346b5b32015-03-06 00:42:16 -0800349 case SET_MPLS_LABEL:
350 case SET_MPLS_TC:
351 case SET_MPLS_TTL:
352 case SET_NW_ECN:
353 case SET_NW_TOS:
354 case SET_NW_TTL:
355 case SET_QUEUE:
356
357 case ENQUEUE:
358 default:
359 log.warn("Action type {} not yet implemented.", act.getType());
360 }
361 }
362 return builder;
363 }
364
365
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800366 private void handleSetField(TrafficTreatment.Builder builder, OFOxm<?> oxm) {
367 switch (oxm.getMatchField().id) {
368 case VLAN_PCP:
369 @SuppressWarnings("unchecked")
370 OFOxm<VlanPcp> vlanpcp = (OFOxm<VlanPcp>) oxm;
371 builder.setVlanPcp(vlanpcp.getValue().getValue());
372 break;
373 case VLAN_VID:
374 @SuppressWarnings("unchecked")
375 OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm;
376 builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan()));
377 break;
378 case ETH_DST:
379 @SuppressWarnings("unchecked")
380 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethdst =
381 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
382 builder.setEthDst(MacAddress.valueOf(ethdst.getValue().getLong()));
383 break;
384 case ETH_SRC:
385 @SuppressWarnings("unchecked")
386 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethsrc =
387 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
388 builder.setEthSrc(MacAddress.valueOf(ethsrc.getValue().getLong()));
389 break;
390 case IPV4_DST:
391 @SuppressWarnings("unchecked")
392 OFOxm<IPv4Address> ip4dst = (OFOxm<IPv4Address>) oxm;
393 builder.setIpDst(Ip4Address.valueOf(ip4dst.getValue().getInt()));
394 break;
395 case IPV4_SRC:
396 @SuppressWarnings("unchecked")
397 OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm;
398 builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt()));
399 break;
sangho3f97a17d2015-01-29 22:56:29 -0800400 case MPLS_LABEL:
401 @SuppressWarnings("unchecked")
402 OFOxm<U32> labelId = (OFOxm<U32>) oxm;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100403 builder.setMpls(MplsLabel.mplsLabel((int) labelId.getValue().getValue()));
sangho3f97a17d2015-01-29 22:56:29 -0800404 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800405 case ARP_OP:
406 case ARP_SHA:
407 case ARP_SPA:
408 case ARP_THA:
409 case ARP_TPA:
410 case BSN_EGR_PORT_GROUP_ID:
411 case BSN_GLOBAL_VRF_ALLOWED:
412 case BSN_IN_PORTS_128:
413 case BSN_L3_DST_CLASS_ID:
414 case BSN_L3_INTERFACE_CLASS_ID:
415 case BSN_L3_SRC_CLASS_ID:
416 case BSN_LAG_ID:
417 case BSN_TCP_FLAGS:
418 case BSN_UDF0:
419 case BSN_UDF1:
420 case BSN_UDF2:
421 case BSN_UDF3:
422 case BSN_UDF4:
423 case BSN_UDF5:
424 case BSN_UDF6:
425 case BSN_UDF7:
426 case BSN_VLAN_XLATE_PORT_GROUP_ID:
427 case BSN_VRF:
428 case ETH_TYPE:
429 case ICMPV4_CODE:
430 case ICMPV4_TYPE:
431 case ICMPV6_CODE:
432 case ICMPV6_TYPE:
433 case IN_PHY_PORT:
434 case IN_PORT:
435 case IPV6_DST:
436 case IPV6_FLABEL:
437 case IPV6_ND_SLL:
438 case IPV6_ND_TARGET:
439 case IPV6_ND_TLL:
440 case IPV6_SRC:
441 case IP_DSCP:
442 case IP_ECN:
443 case IP_PROTO:
444 case METADATA:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800445 case MPLS_TC:
446 case OCH_SIGID:
447 case OCH_SIGID_BASIC:
448 case OCH_SIGTYPE:
449 case OCH_SIGTYPE_BASIC:
450 case SCTP_DST:
451 case SCTP_SRC:
452 case TCP_DST:
453 case TCP_SRC:
454 case TUNNEL_ID:
455 case UDP_DST:
456 case UDP_SRC:
457 default:
458 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
459 break;
460 }
461 }
462
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700463 // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES
alshabib6b5cfec2014-09-18 17:42:18 -0700464 private TrafficSelector buildSelector() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800465 MacAddress mac;
466 Ip4Prefix ip4Prefix;
467 Ip6Address ip6Address;
468 Ip6Prefix ip6Prefix;
469
tom9a693fd2014-10-03 11:32:19 -0700470 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700471 for (MatchField<?> field : match.getMatchFields()) {
472 switch (field.id) {
473 case IN_PORT:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800474 builder.matchInPort(PortNumber
alshabib010c31d2014-09-26 10:01:12 -0700475 .portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700476 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800477 case IN_PHY_PORT:
478 builder.matchInPhyPort(PortNumber
479 .portNumber(match.get(MatchField.IN_PHY_PORT).getPortNumber()));
480 break;
481 case METADATA:
482 long metadata =
483 match.get(MatchField.METADATA).getValue().getValue();
484 builder.matchMetadata(metadata);
485 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700486 case ETH_DST:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800487 mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
488 builder.matchEthDst(mac);
489 break;
490 case ETH_SRC:
491 mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
492 builder.matchEthSrc(mac);
alshabib6b5cfec2014-09-18 17:42:18 -0700493 break;
494 case ETH_TYPE:
495 int ethType = match.get(MatchField.ETH_TYPE).getValue();
sanghoc0b3c342015-03-12 17:12:10 -0700496 if (ethType == EthType.VLAN_FRAME.getValue()) {
497 builder.matchVlanId(VlanId.ANY);
498 } else {
499 builder.matchEthType((short) ethType);
500 }
alshabib6b5cfec2014-09-18 17:42:18 -0700501 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700502 case VLAN_VID:
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800503 VlanId vlanId = null;
504 if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
505 Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
506 if (masked.getValue().equals(OFVlanVidMatch.PRESENT)
507 && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
508 vlanId = VlanId.ANY;
509 }
510 } else {
511 vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
512 }
513 if (vlanId != null) {
514 builder.matchVlanId(vlanId);
515 }
alshabib6b5cfec2014-09-18 17:42:18 -0700516 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800517 case VLAN_PCP:
518 byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
519 builder.matchVlanPcp(vlanPcp);
520 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800521 case IP_DSCP:
522 byte ipDscp = match.get(MatchField.IP_DSCP).getDscpValue();
523 builder.matchIPDscp(ipDscp);
524 break;
525 case IP_ECN:
526 byte ipEcn = match.get(MatchField.IP_ECN).getEcnValue();
527 builder.matchIPEcn(ipEcn);
528 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800529 case IP_PROTO:
530 short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
531 builder.matchIPProtocol((byte) proto);
532 break;
533 case IPV4_SRC:
534 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
535 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800536 ip4Prefix = Ip4Prefix.valueOf(
537 maskedIp.getValue().getInt(),
538 maskedIp.getMask().asCidrMaskLength());
539 } else {
540 ip4Prefix = Ip4Prefix.valueOf(
541 match.get(MatchField.IPV4_SRC).getInt(),
542 Ip4Prefix.MAX_MASK_LENGTH);
543 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800544 builder.matchIPSrc(ip4Prefix);
545 break;
546 case IPV4_DST:
547 if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
548 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800549 ip4Prefix = Ip4Prefix.valueOf(
550 maskedIp.getValue().getInt(),
551 maskedIp.getMask().asCidrMaskLength());
552 } else {
553 ip4Prefix = Ip4Prefix.valueOf(
554 match.get(MatchField.IPV4_DST).getInt(),
555 Ip4Prefix.MAX_MASK_LENGTH);
556 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800557 builder.matchIPDst(ip4Prefix);
Jonathan Hart34bc6142014-10-17 11:00:43 -0700558 break;
559 case TCP_SRC:
560 builder.matchTcpSrc((short) match.get(MatchField.TCP_SRC).getPort());
561 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800562 case TCP_DST:
563 builder.matchTcpDst((short) match.get(MatchField.TCP_DST).getPort());
564 break;
565 case UDP_SRC:
566 builder.matchUdpSrc((short) match.get(MatchField.UDP_SRC).getPort());
567 break;
568 case UDP_DST:
569 builder.matchUdpDst((short) match.get(MatchField.UDP_DST).getPort());
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700570 break;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100571 case MPLS_LABEL:
572 builder.matchMplsLabel(MplsLabel.mplsLabel((int) match.get(MatchField.MPLS_LABEL)
573 .getValue()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800574 break;
575 case SCTP_SRC:
576 builder.matchSctpSrc((short) match.get(MatchField.SCTP_SRC).getPort());
577 break;
578 case SCTP_DST:
579 builder.matchSctpDst((short) match.get(MatchField.SCTP_DST).getPort());
580 break;
581 case ICMPV4_TYPE:
582 byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
583 builder.matchIcmpType(icmpType);
584 break;
585 case ICMPV4_CODE:
586 byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode();
587 builder.matchIcmpCode(icmpCode);
588 break;
589 case IPV6_SRC:
590 if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
591 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
592 ip6Prefix = Ip6Prefix.valueOf(
593 maskedIp.getValue().getBytes(),
594 maskedIp.getMask().asCidrMaskLength());
595 } else {
596 ip6Prefix = Ip6Prefix.valueOf(
597 match.get(MatchField.IPV6_SRC).getBytes(),
598 Ip6Prefix.MAX_MASK_LENGTH);
599 }
600 builder.matchIPv6Src(ip6Prefix);
601 break;
602 case IPV6_DST:
603 if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
604 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
605 ip6Prefix = Ip6Prefix.valueOf(
606 maskedIp.getValue().getBytes(),
607 maskedIp.getMask().asCidrMaskLength());
608 } else {
609 ip6Prefix = Ip6Prefix.valueOf(
610 match.get(MatchField.IPV6_DST).getBytes(),
611 Ip6Prefix.MAX_MASK_LENGTH);
612 }
613 builder.matchIPv6Dst(ip6Prefix);
614 break;
615 case IPV6_FLABEL:
616 int flowLabel =
617 match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue();
618 builder.matchIPv6FlowLabel(flowLabel);
619 break;
620 case ICMPV6_TYPE:
621 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
622 builder.matchIcmpv6Type(icmpv6type);
623 break;
624 case ICMPV6_CODE:
625 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
626 builder.matchIcmpv6Code(icmpv6code);
627 break;
628 case IPV6_ND_TARGET:
629 ip6Address =
630 Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes());
631 builder.matchIPv6NDTargetAddress(ip6Address);
632 break;
633 case IPV6_ND_SLL:
634 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong());
635 builder.matchIPv6NDSourceLinkLayerAddress(mac);
636 break;
637 case IPV6_ND_TLL:
638 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong());
639 builder.matchIPv6NDTargetLinkLayerAddress(mac);
640 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800641 case IPV6_EXTHDR:
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800642 builder.matchIPv6ExthdrFlags((short) match.get(MatchField.IPV6_EXTHDR)
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800643 .getValue());
644 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700645 case OCH_SIGID:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700646 CircuitSignalID sigId = match.get(MatchField.OCH_SIGID);
647 builder.add(matchLambda(Lambda.ochSignal(
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700648 lookupGridType(sigId.getGridType()), lookupChannelSpacing(sigId.getChannelSpacing()),
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700649 sigId.getChannelNumber(), sigId.getChannelSpacing())
650 ));
Marc De Leenheer49087752014-10-23 13:54:09 -0700651 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800652 case OCH_SIGTYPE:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700653 U8 sigType = match.get(MatchField.OCH_SIGTYPE);
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700654 builder.add(matchOchSignalType(lookupOchSignalType((byte) sigType.getValue())));
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800655 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700656 case ARP_OP:
657 case ARP_SHA:
658 case ARP_SPA:
659 case ARP_THA:
660 case ARP_TPA:
alshabib6b5cfec2014-09-18 17:42:18 -0700661 case MPLS_TC:
alshabib6b5cfec2014-09-18 17:42:18 -0700662 case TUNNEL_ID:
alshabib6b5cfec2014-09-18 17:42:18 -0700663 default:
664 log.warn("Match type {} not yet implemented.", field.id);
alshabib6b5cfec2014-09-18 17:42:18 -0700665 }
666 }
667 return builder.build();
668 }
alshabib6b5cfec2014-09-18 17:42:18 -0700669}