blob: 676046236b0e34ef36812dc0de7a61960f8b6760 [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;
Hyunsun Moona08c5d02015-07-14 17:53:00 -070075import org.projectfloodlight.openflow.types.U64;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070076import org.projectfloodlight.openflow.types.U8;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080077import org.projectfloodlight.openflow.types.VlanPcp;
alshabib6b5cfec2014-09-18 17:42:18 -070078import org.slf4j.Logger;
79
Jonathan Hart6cd2f352015-01-13 17:44:45 -080080import java.util.List;
81
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070082import static org.onosproject.net.flow.criteria.Criteria.matchLambda;
83import static org.onosproject.net.flow.criteria.Criteria.matchOchSignalType;
Sho SHIMIZUc17042d2015-05-28 12:07:23 -070084import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupChannelSpacing;
85import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupGridType;
86import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupOchSignalType;
Jonathan Hart6cd2f352015-01-13 17:44:45 -080087import static org.slf4j.LoggerFactory.getLogger;
alshabib19fdc122014-10-03 11:38:19 -070088
alshabib1c319ff2014-10-04 20:29:09 -070089public class FlowEntryBuilder {
alshabib6b5cfec2014-09-18 17:42:18 -070090 private final Logger log = getLogger(getClass());
91
92 private final OFFlowStatsEntry stat;
93 private final OFFlowRemoved removed;
Brian O'Connor72cb19a2015-01-16 16:14:41 -080094 private final OFFlowMod flowMod;
alshabib6b5cfec2014-09-18 17:42:18 -070095
96 private final Match match;
alshabib346b5b32015-03-06 00:42:16 -080097
Jonathan Hart67fc0972015-03-19 15:21:20 -070098 // All actions are contained in an OFInstruction. For OF1.0
99 // the instruction type is apply instruction (immediate set in ONOS speak)
alshabib346b5b32015-03-06 00:42:16 -0800100 private final List<OFInstruction> instructions;
alshabib6b5cfec2014-09-18 17:42:18 -0700101
102 private final Dpid dpid;
103
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800104 public enum FlowType { STAT, REMOVED, MOD }
105
106 private final FlowType type;
alshabib6b5cfec2014-09-18 17:42:18 -0700107
alshabibbdcbb102015-04-22 14:16:38 -0700108 public FlowEntryBuilder(Dpid dpid, OFFlowStatsEntry entry) {
Saurav Dasfa2fa932015-03-03 11:29:48 -0800109 this.stat = entry;
110 this.match = entry.getMatch();
alshabib346b5b32015-03-06 00:42:16 -0800111 this.instructions = getInstructions(entry);
Saurav Dasfa2fa932015-03-03 11:29:48 -0800112 this.dpid = dpid;
113 this.removed = null;
114 this.flowMod = null;
115 this.type = FlowType.STAT;
Saurav Dasfa2fa932015-03-03 11:29:48 -0800116 }
117
alshabibbdcbb102015-04-22 14:16:38 -0700118 public FlowEntryBuilder(Dpid dpid, OFFlowRemoved removed) {
alshabib6b5cfec2014-09-18 17:42:18 -0700119 this.match = removed.getMatch();
120 this.removed = removed;
121
122 this.dpid = dpid;
alshabib346b5b32015-03-06 00:42:16 -0800123 this.instructions = null;
alshabib6b5cfec2014-09-18 17:42:18 -0700124 this.stat = null;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800125 this.flowMod = null;
126 this.type = FlowType.REMOVED;
alshabib6b5cfec2014-09-18 17:42:18 -0700127
128 }
129
alshabibbdcbb102015-04-22 14:16:38 -0700130 public FlowEntryBuilder(Dpid dpid, OFFlowMod fm) {
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800131 this.match = fm.getMatch();
132 this.dpid = dpid;
alshabib346b5b32015-03-06 00:42:16 -0800133 this.instructions = getInstructions(fm);
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800134 this.type = FlowType.MOD;
135 this.flowMod = fm;
136 this.stat = null;
137 this.removed = null;
138 }
alshabib1c319ff2014-10-04 20:29:09 -0700139
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800140 public FlowEntry build(FlowEntryState... state) {
141 FlowRule rule;
142 switch (this.type) {
143 case STAT:
alshabibbdcbb102015-04-22 14:16:38 -0700144 rule = DefaultFlowRule.builder()
145 .forDevice(DeviceId.deviceId(Dpid.uri(dpid)))
146 .withSelector(buildSelector())
147 .withTreatment(buildTreatment())
148 .withPriority(stat.getPriority())
149 .makeTemporary(stat.getIdleTimeout())
150 .withCookie(stat.getCookie().getValue())
151 .forTable(stat.getTableId().getValue())
152 .build();
153
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800154 return new DefaultFlowEntry(rule, FlowEntryState.ADDED,
155 stat.getDurationSec(), stat.getPacketCount().getValue(),
156 stat.getByteCount().getValue());
157 case REMOVED:
alshabibbdcbb102015-04-22 14:16:38 -0700158 rule = DefaultFlowRule.builder()
159 .forDevice(DeviceId.deviceId(Dpid.uri(dpid)))
160 .withSelector(buildSelector())
161 .withPriority(removed.getPriority())
162 .makeTemporary(removed.getIdleTimeout())
163 .withCookie(removed.getCookie().getValue())
164 .forTable(removed.getTableId().getValue())
165 .build();
166
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800167 return new DefaultFlowEntry(rule, FlowEntryState.REMOVED, removed.getDurationSec(),
168 removed.getPacketCount().getValue(), removed.getByteCount().getValue());
169 case MOD:
170 FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED;
alshabibbdcbb102015-04-22 14:16:38 -0700171 rule = DefaultFlowRule.builder()
172 .forDevice(DeviceId.deviceId(Dpid.uri(dpid)))
173 .withSelector(buildSelector())
174 .withTreatment(buildTreatment())
175 .withPriority(flowMod.getPriority())
176 .makeTemporary(flowMod.getIdleTimeout())
177 .withCookie(flowMod.getCookie().getValue())
178 .forTable(flowMod.getTableId().getValue())
179 .build();
180
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800181 return new DefaultFlowEntry(rule, flowState, 0, 0, 0);
182 default:
183 log.error("Unknown flow type : {}", this.type);
184 return null;
alshabib6b5cfec2014-09-18 17:42:18 -0700185 }
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800186
alshabib6b5cfec2014-09-18 17:42:18 -0700187 }
188
alshabib346b5b32015-03-06 00:42:16 -0800189 private List<OFInstruction> getInstructions(OFFlowMod entry) {
alshabib19fdc122014-10-03 11:38:19 -0700190 switch (entry.getVersion()) {
191 case OF_10:
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700192 return Lists.newArrayList(OFFactoryVer13.INSTANCE.instructions()
193 .applyActions(
194 entry.getActions()));
alshabib19fdc122014-10-03 11:38:19 -0700195 case OF_11:
196 case OF_12:
197 case OF_13:
alshabib346b5b32015-03-06 00:42:16 -0800198 return entry.getInstructions();
199 default:
200 log.warn("Unknown OF version {}", entry.getVersion());
201 }
202 return Lists.newLinkedList();
203 }
204
205 private List<OFInstruction> getInstructions(OFFlowStatsEntry entry) {
206 switch (entry.getVersion()) {
207 case OF_10:
208 return Lists.newArrayList(
209 OFFactoryVer13.INSTANCE.instructions().applyActions(entry.getActions()));
210 case OF_11:
211 case OF_12:
212 case OF_13:
213 return entry.getInstructions();
alshabib19fdc122014-10-03 11:38:19 -0700214 default:
215 log.warn("Unknown OF version {}", entry.getVersion());
216 }
217 return Lists.newLinkedList();
218 }
alshabib6b5cfec2014-09-18 17:42:18 -0700219
220 private TrafficTreatment buildTreatment() {
tom9a693fd2014-10-03 11:32:19 -0700221 TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700222 // If this is a drop rule
alshabib346b5b32015-03-06 00:42:16 -0800223 if (instructions.size() == 0) {
alshabib010c31d2014-09-26 10:01:12 -0700224 builder.drop();
alshabib6b5cfec2014-09-18 17:42:18 -0700225 return builder.build();
226 }
alshabib346b5b32015-03-06 00:42:16 -0800227 for (OFInstruction in : instructions) {
228 switch (in.getType()) {
229 case GOTO_TABLE:
alshabibbdcbb102015-04-22 14:16:38 -0700230 builder.transition(((int) ((OFInstructionGotoTable) in)
231 .getTableId().getValue()));
alshabib346b5b32015-03-06 00:42:16 -0800232 break;
233 case WRITE_METADATA:
Saurav Das86af8f12015-05-25 23:55:33 -0700234 OFInstructionWriteMetadata m = (OFInstructionWriteMetadata) in;
235 builder.writeMetadata(m.getMetadata().getValue(),
236 m.getMetadataMask().getValue());
alshabib346b5b32015-03-06 00:42:16 -0800237 break;
238 case WRITE_ACTIONS:
239 builder.deferred();
240 buildActions(((OFInstructionWriteActions) in).getActions(),
241 builder);
242 break;
243 case APPLY_ACTIONS:
244 builder.immediate();
245 buildActions(((OFInstructionApplyActions) in).getActions(),
246 builder);
247 break;
248 case CLEAR_ACTIONS:
249 builder.wipeDeferred();
250 break;
251 case EXPERIMENTER:
252 break;
253 case METER:
254 break;
255 default:
256 log.warn("Unknown instructions type {}", in.getType());
alshabib6b5cfec2014-09-18 17:42:18 -0700257 }
258 }
259
260 return builder.build();
261 }
262
alshabib346b5b32015-03-06 00:42:16 -0800263 private TrafficTreatment.Builder buildActions(List<OFAction> actions,
264 TrafficTreatment.Builder builder) {
265 for (OFAction act : actions) {
266 switch (act.getType()) {
267 case OUTPUT:
268 OFActionOutput out = (OFActionOutput) act;
269 builder.setOutput(
270 PortNumber.portNumber(out.getPort().getPortNumber()));
271 break;
272 case SET_VLAN_VID:
273 OFActionSetVlanVid vlan = (OFActionSetVlanVid) act;
274 builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan()));
275 break;
276 case SET_VLAN_PCP:
277 OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act;
278 builder.setVlanPcp(pcp.getVlanPcp().getValue());
279 break;
280 case SET_DL_DST:
281 OFActionSetDlDst dldst = (OFActionSetDlDst) act;
282 builder.setEthDst(
283 MacAddress.valueOf(dldst.getDlAddr().getLong()));
284 break;
285 case SET_DL_SRC:
286 OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act;
287 builder.setEthSrc(
288 MacAddress.valueOf(dlsrc.getDlAddr().getLong()));
289
290 break;
291 case SET_NW_DST:
292 OFActionSetNwDst nwdst = (OFActionSetNwDst) act;
293 IPv4Address di = nwdst.getNwAddr();
294 builder.setIpDst(Ip4Address.valueOf(di.getInt()));
295 break;
296 case SET_NW_SRC:
297 OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act;
298 IPv4Address si = nwsrc.getNwAddr();
299 builder.setIpSrc(Ip4Address.valueOf(si.getInt()));
300 break;
301 case EXPERIMENTER:
302 OFActionExperimenter exp = (OFActionExperimenter) act;
303 if (exp.getExperimenter() == 0x80005A06 ||
304 exp.getExperimenter() == 0x748771) {
305 OFActionCircuit ct = (OFActionCircuit) exp;
Sho SHIMIZU9553bb82015-06-30 16:02:45 -0700306 short lambda = ((OFOxmOchSigidBasic) ct.getField()).getValue().getChannelNumber();
307 builder.add(Instructions.modL0Lambda(Lambda.indexedLambda(lambda)));
alshabib346b5b32015-03-06 00:42:16 -0800308 } else {
309 log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter());
310 }
311 break;
312 case SET_FIELD:
313 OFActionSetField setField = (OFActionSetField) act;
314 handleSetField(builder, setField.getField());
315 break;
316 case POP_MPLS:
317 OFActionPopMpls popMpls = (OFActionPopMpls) act;
318 builder.popMpls((short) popMpls.getEthertype().getValue());
319 break;
320 case PUSH_MPLS:
321 builder.pushMpls();
322 break;
323 case COPY_TTL_IN:
324 builder.copyTtlIn();
325 break;
326 case COPY_TTL_OUT:
327 builder.copyTtlOut();
328 break;
329 case DEC_MPLS_TTL:
330 builder.decMplsTtl();
331 break;
332 case DEC_NW_TTL:
333 builder.decNwTtl();
334 break;
335 case GROUP:
336 OFActionGroup group = (OFActionGroup) act;
337 builder.group(new DefaultGroupId(group.getGroup().getGroupNumber()));
338 break;
Jonathan Hart67fc0972015-03-19 15:21:20 -0700339 case STRIP_VLAN:
alshabib346b5b32015-03-06 00:42:16 -0800340 case POP_VLAN:
341 builder.popVlan();
342 break;
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700343 case PUSH_VLAN:
344 builder.pushVlan();
345 break;
alshabib346b5b32015-03-06 00:42:16 -0800346 case SET_TP_DST:
347 case SET_TP_SRC:
348 case POP_PBB:
349 case PUSH_PBB:
alshabib346b5b32015-03-06 00:42:16 -0800350 case SET_MPLS_LABEL:
351 case SET_MPLS_TC:
352 case SET_MPLS_TTL:
353 case SET_NW_ECN:
354 case SET_NW_TOS:
355 case SET_NW_TTL:
356 case SET_QUEUE:
357
358 case ENQUEUE:
359 default:
360 log.warn("Action type {} not yet implemented.", act.getType());
361 }
362 }
363 return builder;
364 }
365
366
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800367 private void handleSetField(TrafficTreatment.Builder builder, OFOxm<?> oxm) {
368 switch (oxm.getMatchField().id) {
369 case VLAN_PCP:
370 @SuppressWarnings("unchecked")
371 OFOxm<VlanPcp> vlanpcp = (OFOxm<VlanPcp>) oxm;
372 builder.setVlanPcp(vlanpcp.getValue().getValue());
373 break;
374 case VLAN_VID:
375 @SuppressWarnings("unchecked")
376 OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm;
377 builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan()));
378 break;
379 case ETH_DST:
380 @SuppressWarnings("unchecked")
381 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethdst =
382 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
383 builder.setEthDst(MacAddress.valueOf(ethdst.getValue().getLong()));
384 break;
385 case ETH_SRC:
386 @SuppressWarnings("unchecked")
387 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethsrc =
388 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
389 builder.setEthSrc(MacAddress.valueOf(ethsrc.getValue().getLong()));
390 break;
391 case IPV4_DST:
392 @SuppressWarnings("unchecked")
393 OFOxm<IPv4Address> ip4dst = (OFOxm<IPv4Address>) oxm;
394 builder.setIpDst(Ip4Address.valueOf(ip4dst.getValue().getInt()));
395 break;
396 case IPV4_SRC:
397 @SuppressWarnings("unchecked")
398 OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm;
399 builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt()));
400 break;
sangho3f97a17d2015-01-29 22:56:29 -0800401 case MPLS_LABEL:
402 @SuppressWarnings("unchecked")
403 OFOxm<U32> labelId = (OFOxm<U32>) oxm;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100404 builder.setMpls(MplsLabel.mplsLabel((int) labelId.getValue().getValue()));
sangho3f97a17d2015-01-29 22:56:29 -0800405 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700406 case TUNNEL_ID:
407 @SuppressWarnings("unchecked")
408 OFOxm<U64> tunnelId = (OFOxm<U64>) oxm;
409 builder.setTunnelId(tunnelId.getValue().getValue());
410 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800411 case ARP_OP:
412 case ARP_SHA:
413 case ARP_SPA:
414 case ARP_THA:
415 case ARP_TPA:
416 case BSN_EGR_PORT_GROUP_ID:
417 case BSN_GLOBAL_VRF_ALLOWED:
418 case BSN_IN_PORTS_128:
419 case BSN_L3_DST_CLASS_ID:
420 case BSN_L3_INTERFACE_CLASS_ID:
421 case BSN_L3_SRC_CLASS_ID:
422 case BSN_LAG_ID:
423 case BSN_TCP_FLAGS:
424 case BSN_UDF0:
425 case BSN_UDF1:
426 case BSN_UDF2:
427 case BSN_UDF3:
428 case BSN_UDF4:
429 case BSN_UDF5:
430 case BSN_UDF6:
431 case BSN_UDF7:
432 case BSN_VLAN_XLATE_PORT_GROUP_ID:
433 case BSN_VRF:
434 case ETH_TYPE:
435 case ICMPV4_CODE:
436 case ICMPV4_TYPE:
437 case ICMPV6_CODE:
438 case ICMPV6_TYPE:
439 case IN_PHY_PORT:
440 case IN_PORT:
441 case IPV6_DST:
442 case IPV6_FLABEL:
443 case IPV6_ND_SLL:
444 case IPV6_ND_TARGET:
445 case IPV6_ND_TLL:
446 case IPV6_SRC:
447 case IP_DSCP:
448 case IP_ECN:
449 case IP_PROTO:
450 case METADATA:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800451 case MPLS_TC:
452 case OCH_SIGID:
453 case OCH_SIGID_BASIC:
454 case OCH_SIGTYPE:
455 case OCH_SIGTYPE_BASIC:
456 case SCTP_DST:
457 case SCTP_SRC:
458 case TCP_DST:
459 case TCP_SRC:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800460 case UDP_DST:
461 case UDP_SRC:
462 default:
463 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
464 break;
465 }
466 }
467
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700468 // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES
alshabib6b5cfec2014-09-18 17:42:18 -0700469 private TrafficSelector buildSelector() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800470 MacAddress mac;
471 Ip4Prefix ip4Prefix;
472 Ip6Address ip6Address;
473 Ip6Prefix ip6Prefix;
474
tom9a693fd2014-10-03 11:32:19 -0700475 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700476 for (MatchField<?> field : match.getMatchFields()) {
477 switch (field.id) {
478 case IN_PORT:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800479 builder.matchInPort(PortNumber
alshabib010c31d2014-09-26 10:01:12 -0700480 .portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700481 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800482 case IN_PHY_PORT:
483 builder.matchInPhyPort(PortNumber
484 .portNumber(match.get(MatchField.IN_PHY_PORT).getPortNumber()));
485 break;
486 case METADATA:
487 long metadata =
488 match.get(MatchField.METADATA).getValue().getValue();
489 builder.matchMetadata(metadata);
490 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700491 case ETH_DST:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800492 mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
493 builder.matchEthDst(mac);
494 break;
495 case ETH_SRC:
496 mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
497 builder.matchEthSrc(mac);
alshabib6b5cfec2014-09-18 17:42:18 -0700498 break;
499 case ETH_TYPE:
500 int ethType = match.get(MatchField.ETH_TYPE).getValue();
sanghoc0b3c342015-03-12 17:12:10 -0700501 if (ethType == EthType.VLAN_FRAME.getValue()) {
502 builder.matchVlanId(VlanId.ANY);
503 } else {
504 builder.matchEthType((short) ethType);
505 }
alshabib6b5cfec2014-09-18 17:42:18 -0700506 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700507 case VLAN_VID:
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800508 VlanId vlanId = null;
509 if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
510 Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
511 if (masked.getValue().equals(OFVlanVidMatch.PRESENT)
512 && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
513 vlanId = VlanId.ANY;
514 }
515 } else {
516 vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
517 }
518 if (vlanId != null) {
519 builder.matchVlanId(vlanId);
520 }
alshabib6b5cfec2014-09-18 17:42:18 -0700521 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800522 case VLAN_PCP:
523 byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
524 builder.matchVlanPcp(vlanPcp);
525 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800526 case IP_DSCP:
527 byte ipDscp = match.get(MatchField.IP_DSCP).getDscpValue();
528 builder.matchIPDscp(ipDscp);
529 break;
530 case IP_ECN:
531 byte ipEcn = match.get(MatchField.IP_ECN).getEcnValue();
532 builder.matchIPEcn(ipEcn);
533 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800534 case IP_PROTO:
535 short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
536 builder.matchIPProtocol((byte) proto);
537 break;
538 case IPV4_SRC:
539 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
540 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800541 ip4Prefix = Ip4Prefix.valueOf(
542 maskedIp.getValue().getInt(),
543 maskedIp.getMask().asCidrMaskLength());
544 } else {
545 ip4Prefix = Ip4Prefix.valueOf(
546 match.get(MatchField.IPV4_SRC).getInt(),
547 Ip4Prefix.MAX_MASK_LENGTH);
548 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800549 builder.matchIPSrc(ip4Prefix);
550 break;
551 case IPV4_DST:
552 if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
553 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800554 ip4Prefix = Ip4Prefix.valueOf(
555 maskedIp.getValue().getInt(),
556 maskedIp.getMask().asCidrMaskLength());
557 } else {
558 ip4Prefix = Ip4Prefix.valueOf(
559 match.get(MatchField.IPV4_DST).getInt(),
560 Ip4Prefix.MAX_MASK_LENGTH);
561 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800562 builder.matchIPDst(ip4Prefix);
Jonathan Hart34bc6142014-10-17 11:00:43 -0700563 break;
564 case TCP_SRC:
565 builder.matchTcpSrc((short) match.get(MatchField.TCP_SRC).getPort());
566 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800567 case TCP_DST:
568 builder.matchTcpDst((short) match.get(MatchField.TCP_DST).getPort());
569 break;
570 case UDP_SRC:
571 builder.matchUdpSrc((short) match.get(MatchField.UDP_SRC).getPort());
572 break;
573 case UDP_DST:
574 builder.matchUdpDst((short) match.get(MatchField.UDP_DST).getPort());
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700575 break;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100576 case MPLS_LABEL:
577 builder.matchMplsLabel(MplsLabel.mplsLabel((int) match.get(MatchField.MPLS_LABEL)
578 .getValue()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800579 break;
580 case SCTP_SRC:
581 builder.matchSctpSrc((short) match.get(MatchField.SCTP_SRC).getPort());
582 break;
583 case SCTP_DST:
584 builder.matchSctpDst((short) match.get(MatchField.SCTP_DST).getPort());
585 break;
586 case ICMPV4_TYPE:
587 byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
588 builder.matchIcmpType(icmpType);
589 break;
590 case ICMPV4_CODE:
591 byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode();
592 builder.matchIcmpCode(icmpCode);
593 break;
594 case IPV6_SRC:
595 if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
596 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
597 ip6Prefix = Ip6Prefix.valueOf(
598 maskedIp.getValue().getBytes(),
599 maskedIp.getMask().asCidrMaskLength());
600 } else {
601 ip6Prefix = Ip6Prefix.valueOf(
602 match.get(MatchField.IPV6_SRC).getBytes(),
603 Ip6Prefix.MAX_MASK_LENGTH);
604 }
605 builder.matchIPv6Src(ip6Prefix);
606 break;
607 case IPV6_DST:
608 if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
609 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
610 ip6Prefix = Ip6Prefix.valueOf(
611 maskedIp.getValue().getBytes(),
612 maskedIp.getMask().asCidrMaskLength());
613 } else {
614 ip6Prefix = Ip6Prefix.valueOf(
615 match.get(MatchField.IPV6_DST).getBytes(),
616 Ip6Prefix.MAX_MASK_LENGTH);
617 }
618 builder.matchIPv6Dst(ip6Prefix);
619 break;
620 case IPV6_FLABEL:
621 int flowLabel =
622 match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue();
623 builder.matchIPv6FlowLabel(flowLabel);
624 break;
625 case ICMPV6_TYPE:
626 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
627 builder.matchIcmpv6Type(icmpv6type);
628 break;
629 case ICMPV6_CODE:
630 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
631 builder.matchIcmpv6Code(icmpv6code);
632 break;
633 case IPV6_ND_TARGET:
634 ip6Address =
635 Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes());
636 builder.matchIPv6NDTargetAddress(ip6Address);
637 break;
638 case IPV6_ND_SLL:
639 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong());
640 builder.matchIPv6NDSourceLinkLayerAddress(mac);
641 break;
642 case IPV6_ND_TLL:
643 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong());
644 builder.matchIPv6NDTargetLinkLayerAddress(mac);
645 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800646 case IPV6_EXTHDR:
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800647 builder.matchIPv6ExthdrFlags((short) match.get(MatchField.IPV6_EXTHDR)
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700648 .getValue());
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800649 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700650 case OCH_SIGID:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700651 CircuitSignalID sigId = match.get(MatchField.OCH_SIGID);
652 builder.add(matchLambda(Lambda.ochSignal(
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700653 lookupGridType(sigId.getGridType()), lookupChannelSpacing(sigId.getChannelSpacing()),
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700654 sigId.getChannelNumber(), sigId.getChannelSpacing())
655 ));
Marc De Leenheer49087752014-10-23 13:54:09 -0700656 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800657 case OCH_SIGTYPE:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700658 U8 sigType = match.get(MatchField.OCH_SIGTYPE);
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700659 builder.add(matchOchSignalType(lookupOchSignalType((byte) sigType.getValue())));
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800660 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700661 case TUNNEL_ID:
662 long tunnelId = match.get(MatchField.TUNNEL_ID).getValue();
663 builder.matchTunnelId(tunnelId);
664 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700665 case ARP_OP:
666 case ARP_SHA:
667 case ARP_SPA:
668 case ARP_THA:
669 case ARP_TPA:
alshabib6b5cfec2014-09-18 17:42:18 -0700670 case MPLS_TC:
alshabib6b5cfec2014-09-18 17:42:18 -0700671 default:
672 log.warn("Match type {} not yet implemented.", field.id);
alshabib6b5cfec2014-09-18 17:42:18 -0700673 }
674 }
675 return builder.build();
676 }
alshabib6b5cfec2014-09-18 17:42:18 -0700677}