blob: dba123bd1fa55845f5837d48b6ddd5cee83bdcad [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
Saurav Dasffc5bbc2015-08-18 23:30:19 -070018import static org.onosproject.net.flow.criteria.Criteria.matchLambda;
19import static org.onosproject.net.flow.criteria.Criteria.matchOchSignalType;
20import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupChannelSpacing;
21import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupGridType;
22import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupOchSignalType;
23import static org.slf4j.LoggerFactory.getLogger;
24
25import java.util.List;
Saurav Das86af8f12015-05-25 23:55:33 -070026
Jonathan Hartd0ef7522014-12-11 11:51:18 -080027import org.onlab.packet.Ip4Address;
28import org.onlab.packet.Ip4Prefix;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080029import org.onlab.packet.Ip6Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080030import org.onlab.packet.Ip6Prefix;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080031import org.onlab.packet.MacAddress;
Michele Santuari4b6019e2014-12-19 11:31:45 +010032import org.onlab.packet.MplsLabel;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080033import org.onlab.packet.VlanId;
sangho8995ac52015-02-04 11:29:03 -080034import org.onosproject.core.DefaultGroupId;
Brian O'Connorabafb502014-12-02 22:26:20 -080035import org.onosproject.net.DeviceId;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070036import org.onosproject.net.Lambda;
Brian O'Connorabafb502014-12-02 22:26:20 -080037import org.onosproject.net.PortNumber;
38import org.onosproject.net.flow.DefaultFlowEntry;
39import org.onosproject.net.flow.DefaultFlowRule;
40import org.onosproject.net.flow.DefaultTrafficSelector;
41import org.onosproject.net.flow.DefaultTrafficTreatment;
42import org.onosproject.net.flow.FlowEntry;
43import org.onosproject.net.flow.FlowEntry.FlowEntryState;
44import org.onosproject.net.flow.FlowRule;
45import org.onosproject.net.flow.TrafficSelector;
46import org.onosproject.net.flow.TrafficTreatment;
Sho SHIMIZU9553bb82015-06-30 16:02:45 -070047import org.onosproject.net.flow.instructions.Instructions;
Brian O'Connorabafb502014-12-02 22:26:20 -080048import org.onosproject.openflow.controller.Dpid;
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;
52import org.projectfloodlight.openflow.protocol.action.OFAction;
Marc De Leenheer49087752014-10-23 13:54:09 -070053import org.projectfloodlight.openflow.protocol.action.OFActionCircuit;
54import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter;
sangho8995ac52015-02-04 11:29:03 -080055import org.projectfloodlight.openflow.protocol.action.OFActionGroup;
alshabib6b5cfec2014-09-18 17:42:18 -070056import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
sangho3f97a17d2015-01-29 22:56:29 -080057import org.projectfloodlight.openflow.protocol.action.OFActionPopMpls;
alshabib6b5cfec2014-09-18 17:42:18 -070058import org.projectfloodlight.openflow.protocol.action.OFActionSetDlDst;
59import org.projectfloodlight.openflow.protocol.action.OFActionSetDlSrc;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080060import org.projectfloodlight.openflow.protocol.action.OFActionSetField;
alshabib6b5cfec2014-09-18 17:42:18 -070061import org.projectfloodlight.openflow.protocol.action.OFActionSetNwDst;
62import org.projectfloodlight.openflow.protocol.action.OFActionSetNwSrc;
63import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanPcp;
64import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanVid;
alshabib19fdc122014-10-03 11:38:19 -070065import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
Jonathan Hartcf783202014-11-24 18:55:42 -080066import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions;
alshabibbdcbb102015-04-22 14:16:38 -070067import org.projectfloodlight.openflow.protocol.instruction.OFInstructionGotoTable;
alshabib346b5b32015-03-06 00:42:16 -080068import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteActions;
Saurav Das86af8f12015-05-25 23:55:33 -070069import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteMetadata;
alshabib6b5cfec2014-09-18 17:42:18 -070070import org.projectfloodlight.openflow.protocol.match.Match;
71import org.projectfloodlight.openflow.protocol.match.MatchField;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080072import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
Marc De Leenheer49087752014-10-23 13:54:09 -070073import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigidBasic;
alshabib346b5b32015-03-06 00:42:16 -080074import org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070075import org.projectfloodlight.openflow.types.CircuitSignalID;
sanghoc0b3c342015-03-12 17:12:10 -070076import org.projectfloodlight.openflow.types.EthType;
alshabib6b5cfec2014-09-18 17:42:18 -070077import org.projectfloodlight.openflow.types.IPv4Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080078import org.projectfloodlight.openflow.types.IPv6Address;
Jonathan Hart0e12fad2014-10-17 14:54:58 -070079import org.projectfloodlight.openflow.types.Masked;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080080import org.projectfloodlight.openflow.types.OFVlanVidMatch;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -070081import org.projectfloodlight.openflow.types.TransportPort;
sangho3f97a17d2015-01-29 22:56:29 -080082import org.projectfloodlight.openflow.types.U32;
Hyunsun Moona08c5d02015-07-14 17:53:00 -070083import org.projectfloodlight.openflow.types.U64;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070084import org.projectfloodlight.openflow.types.U8;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080085import org.projectfloodlight.openflow.types.VlanPcp;
alshabib6b5cfec2014-09-18 17:42:18 -070086import org.slf4j.Logger;
87
Saurav Dasffc5bbc2015-08-18 23:30:19 -070088import com.google.common.collect.Lists;
alshabib19fdc122014-10-03 11:38:19 -070089
alshabib1c319ff2014-10-04 20:29:09 -070090public class FlowEntryBuilder {
alshabib6b5cfec2014-09-18 17:42:18 -070091 private final Logger log = getLogger(getClass());
92
93 private final OFFlowStatsEntry stat;
94 private final OFFlowRemoved removed;
Brian O'Connor72cb19a2015-01-16 16:14:41 -080095 private final OFFlowMod flowMod;
alshabib6b5cfec2014-09-18 17:42:18 -070096
97 private final Match match;
alshabib346b5b32015-03-06 00:42:16 -080098
Jonathan Hart67fc0972015-03-19 15:21:20 -070099 // All actions are contained in an OFInstruction. For OF1.0
100 // the instruction type is apply instruction (immediate set in ONOS speak)
alshabib346b5b32015-03-06 00:42:16 -0800101 private final List<OFInstruction> instructions;
alshabib6b5cfec2014-09-18 17:42:18 -0700102
103 private final Dpid dpid;
104
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800105 public enum FlowType { STAT, REMOVED, MOD }
106
107 private final FlowType type;
alshabib6b5cfec2014-09-18 17:42:18 -0700108
alshabibbdcbb102015-04-22 14:16:38 -0700109 public FlowEntryBuilder(Dpid dpid, OFFlowStatsEntry entry) {
Saurav Dasfa2fa932015-03-03 11:29:48 -0800110 this.stat = entry;
111 this.match = entry.getMatch();
alshabib346b5b32015-03-06 00:42:16 -0800112 this.instructions = getInstructions(entry);
Saurav Dasfa2fa932015-03-03 11:29:48 -0800113 this.dpid = dpid;
114 this.removed = null;
115 this.flowMod = null;
116 this.type = FlowType.STAT;
Saurav Dasfa2fa932015-03-03 11:29:48 -0800117 }
118
alshabibbdcbb102015-04-22 14:16:38 -0700119 public FlowEntryBuilder(Dpid dpid, OFFlowRemoved removed) {
alshabib6b5cfec2014-09-18 17:42:18 -0700120 this.match = removed.getMatch();
121 this.removed = removed;
122
123 this.dpid = dpid;
alshabib346b5b32015-03-06 00:42:16 -0800124 this.instructions = null;
alshabib6b5cfec2014-09-18 17:42:18 -0700125 this.stat = null;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800126 this.flowMod = null;
127 this.type = FlowType.REMOVED;
alshabib6b5cfec2014-09-18 17:42:18 -0700128
129 }
130
alshabibbdcbb102015-04-22 14:16:38 -0700131 public FlowEntryBuilder(Dpid dpid, OFFlowMod fm) {
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800132 this.match = fm.getMatch();
133 this.dpid = dpid;
alshabib346b5b32015-03-06 00:42:16 -0800134 this.instructions = getInstructions(fm);
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800135 this.type = FlowType.MOD;
136 this.flowMod = fm;
137 this.stat = null;
138 this.removed = null;
139 }
alshabib1c319ff2014-10-04 20:29:09 -0700140
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800141 public FlowEntry build(FlowEntryState... state) {
142 FlowRule rule;
143 switch (this.type) {
144 case STAT:
alshabibbdcbb102015-04-22 14:16:38 -0700145 rule = DefaultFlowRule.builder()
146 .forDevice(DeviceId.deviceId(Dpid.uri(dpid)))
147 .withSelector(buildSelector())
148 .withTreatment(buildTreatment())
149 .withPriority(stat.getPriority())
150 .makeTemporary(stat.getIdleTimeout())
151 .withCookie(stat.getCookie().getValue())
152 .forTable(stat.getTableId().getValue())
153 .build();
154
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800155 return new DefaultFlowEntry(rule, FlowEntryState.ADDED,
156 stat.getDurationSec(), stat.getPacketCount().getValue(),
157 stat.getByteCount().getValue());
158 case REMOVED:
alshabibbdcbb102015-04-22 14:16:38 -0700159 rule = DefaultFlowRule.builder()
160 .forDevice(DeviceId.deviceId(Dpid.uri(dpid)))
161 .withSelector(buildSelector())
162 .withPriority(removed.getPriority())
163 .makeTemporary(removed.getIdleTimeout())
164 .withCookie(removed.getCookie().getValue())
165 .forTable(removed.getTableId().getValue())
166 .build();
167
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800168 return new DefaultFlowEntry(rule, FlowEntryState.REMOVED, removed.getDurationSec(),
169 removed.getPacketCount().getValue(), removed.getByteCount().getValue());
170 case MOD:
171 FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED;
alshabibbdcbb102015-04-22 14:16:38 -0700172 rule = DefaultFlowRule.builder()
173 .forDevice(DeviceId.deviceId(Dpid.uri(dpid)))
174 .withSelector(buildSelector())
175 .withTreatment(buildTreatment())
176 .withPriority(flowMod.getPriority())
177 .makeTemporary(flowMod.getIdleTimeout())
178 .withCookie(flowMod.getCookie().getValue())
179 .forTable(flowMod.getTableId().getValue())
180 .build();
181
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800182 return new DefaultFlowEntry(rule, flowState, 0, 0, 0);
183 default:
184 log.error("Unknown flow type : {}", this.type);
185 return null;
alshabib6b5cfec2014-09-18 17:42:18 -0700186 }
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800187
alshabib6b5cfec2014-09-18 17:42:18 -0700188 }
189
alshabib346b5b32015-03-06 00:42:16 -0800190 private List<OFInstruction> getInstructions(OFFlowMod entry) {
alshabib19fdc122014-10-03 11:38:19 -0700191 switch (entry.getVersion()) {
192 case OF_10:
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700193 return Lists.newArrayList(OFFactoryVer13.INSTANCE.instructions()
194 .applyActions(
195 entry.getActions()));
alshabib19fdc122014-10-03 11:38:19 -0700196 case OF_11:
197 case OF_12:
198 case OF_13:
alshabib346b5b32015-03-06 00:42:16 -0800199 return entry.getInstructions();
200 default:
201 log.warn("Unknown OF version {}", entry.getVersion());
202 }
203 return Lists.newLinkedList();
204 }
205
206 private List<OFInstruction> getInstructions(OFFlowStatsEntry entry) {
207 switch (entry.getVersion()) {
208 case OF_10:
209 return Lists.newArrayList(
210 OFFactoryVer13.INSTANCE.instructions().applyActions(entry.getActions()));
211 case OF_11:
212 case OF_12:
213 case OF_13:
214 return entry.getInstructions();
alshabib19fdc122014-10-03 11:38:19 -0700215 default:
216 log.warn("Unknown OF version {}", entry.getVersion());
217 }
218 return Lists.newLinkedList();
219 }
alshabib6b5cfec2014-09-18 17:42:18 -0700220
221 private TrafficTreatment buildTreatment() {
tom9a693fd2014-10-03 11:32:19 -0700222 TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700223 // If this is a drop rule
alshabib346b5b32015-03-06 00:42:16 -0800224 if (instructions.size() == 0) {
alshabib010c31d2014-09-26 10:01:12 -0700225 builder.drop();
alshabib6b5cfec2014-09-18 17:42:18 -0700226 return builder.build();
227 }
alshabib346b5b32015-03-06 00:42:16 -0800228 for (OFInstruction in : instructions) {
229 switch (in.getType()) {
230 case GOTO_TABLE:
alshabibbdcbb102015-04-22 14:16:38 -0700231 builder.transition(((int) ((OFInstructionGotoTable) in)
232 .getTableId().getValue()));
alshabib346b5b32015-03-06 00:42:16 -0800233 break;
234 case WRITE_METADATA:
Saurav Das86af8f12015-05-25 23:55:33 -0700235 OFInstructionWriteMetadata m = (OFInstructionWriteMetadata) in;
236 builder.writeMetadata(m.getMetadata().getValue(),
237 m.getMetadataMask().getValue());
alshabib346b5b32015-03-06 00:42:16 -0800238 break;
239 case WRITE_ACTIONS:
240 builder.deferred();
241 buildActions(((OFInstructionWriteActions) in).getActions(),
242 builder);
243 break;
244 case APPLY_ACTIONS:
245 builder.immediate();
246 buildActions(((OFInstructionApplyActions) in).getActions(),
247 builder);
248 break;
249 case CLEAR_ACTIONS:
250 builder.wipeDeferred();
251 break;
252 case EXPERIMENTER:
253 break;
254 case METER:
255 break;
256 default:
257 log.warn("Unknown instructions type {}", in.getType());
alshabib6b5cfec2014-09-18 17:42:18 -0700258 }
259 }
260
261 return builder.build();
262 }
263
alshabib346b5b32015-03-06 00:42:16 -0800264 private TrafficTreatment.Builder buildActions(List<OFAction> actions,
265 TrafficTreatment.Builder builder) {
266 for (OFAction act : actions) {
267 switch (act.getType()) {
268 case OUTPUT:
269 OFActionOutput out = (OFActionOutput) act;
270 builder.setOutput(
271 PortNumber.portNumber(out.getPort().getPortNumber()));
272 break;
273 case SET_VLAN_VID:
274 OFActionSetVlanVid vlan = (OFActionSetVlanVid) act;
275 builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan()));
276 break;
277 case SET_VLAN_PCP:
278 OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act;
279 builder.setVlanPcp(pcp.getVlanPcp().getValue());
280 break;
281 case SET_DL_DST:
282 OFActionSetDlDst dldst = (OFActionSetDlDst) act;
283 builder.setEthDst(
284 MacAddress.valueOf(dldst.getDlAddr().getLong()));
285 break;
286 case SET_DL_SRC:
287 OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act;
288 builder.setEthSrc(
289 MacAddress.valueOf(dlsrc.getDlAddr().getLong()));
290
291 break;
292 case SET_NW_DST:
293 OFActionSetNwDst nwdst = (OFActionSetNwDst) act;
294 IPv4Address di = nwdst.getNwAddr();
295 builder.setIpDst(Ip4Address.valueOf(di.getInt()));
296 break;
297 case SET_NW_SRC:
298 OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act;
299 IPv4Address si = nwsrc.getNwAddr();
300 builder.setIpSrc(Ip4Address.valueOf(si.getInt()));
301 break;
302 case EXPERIMENTER:
303 OFActionExperimenter exp = (OFActionExperimenter) act;
304 if (exp.getExperimenter() == 0x80005A06 ||
305 exp.getExperimenter() == 0x748771) {
306 OFActionCircuit ct = (OFActionCircuit) exp;
Sho SHIMIZU9553bb82015-06-30 16:02:45 -0700307 short lambda = ((OFOxmOchSigidBasic) ct.getField()).getValue().getChannelNumber();
308 builder.add(Instructions.modL0Lambda(Lambda.indexedLambda(lambda)));
alshabib346b5b32015-03-06 00:42:16 -0800309 } else {
310 log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter());
311 }
312 break;
313 case SET_FIELD:
314 OFActionSetField setField = (OFActionSetField) act;
315 handleSetField(builder, setField.getField());
316 break;
317 case POP_MPLS:
318 OFActionPopMpls popMpls = (OFActionPopMpls) act;
319 builder.popMpls((short) popMpls.getEthertype().getValue());
320 break;
321 case PUSH_MPLS:
322 builder.pushMpls();
323 break;
324 case COPY_TTL_IN:
325 builder.copyTtlIn();
326 break;
327 case COPY_TTL_OUT:
328 builder.copyTtlOut();
329 break;
330 case DEC_MPLS_TTL:
331 builder.decMplsTtl();
332 break;
333 case DEC_NW_TTL:
334 builder.decNwTtl();
335 break;
336 case GROUP:
337 OFActionGroup group = (OFActionGroup) act;
338 builder.group(new DefaultGroupId(group.getGroup().getGroupNumber()));
339 break;
Jonathan Hart67fc0972015-03-19 15:21:20 -0700340 case STRIP_VLAN:
alshabib346b5b32015-03-06 00:42:16 -0800341 case POP_VLAN:
342 builder.popVlan();
343 break;
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700344 case PUSH_VLAN:
345 builder.pushVlan();
346 break;
alshabib346b5b32015-03-06 00:42:16 -0800347 case SET_TP_DST:
348 case SET_TP_SRC:
349 case POP_PBB:
350 case PUSH_PBB:
alshabib346b5b32015-03-06 00:42:16 -0800351 case SET_MPLS_LABEL:
352 case SET_MPLS_TC:
353 case SET_MPLS_TTL:
354 case SET_NW_ECN:
355 case SET_NW_TOS:
356 case SET_NW_TTL:
357 case SET_QUEUE:
358
359 case ENQUEUE:
360 default:
361 log.warn("Action type {} not yet implemented.", act.getType());
362 }
363 }
364 return builder;
365 }
366
367
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800368 private void handleSetField(TrafficTreatment.Builder builder, OFOxm<?> oxm) {
369 switch (oxm.getMatchField().id) {
370 case VLAN_PCP:
371 @SuppressWarnings("unchecked")
372 OFOxm<VlanPcp> vlanpcp = (OFOxm<VlanPcp>) oxm;
373 builder.setVlanPcp(vlanpcp.getValue().getValue());
374 break;
375 case VLAN_VID:
376 @SuppressWarnings("unchecked")
377 OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm;
378 builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan()));
379 break;
380 case ETH_DST:
381 @SuppressWarnings("unchecked")
382 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethdst =
383 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
384 builder.setEthDst(MacAddress.valueOf(ethdst.getValue().getLong()));
385 break;
386 case ETH_SRC:
387 @SuppressWarnings("unchecked")
388 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethsrc =
389 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
390 builder.setEthSrc(MacAddress.valueOf(ethsrc.getValue().getLong()));
391 break;
392 case IPV4_DST:
393 @SuppressWarnings("unchecked")
394 OFOxm<IPv4Address> ip4dst = (OFOxm<IPv4Address>) oxm;
395 builder.setIpDst(Ip4Address.valueOf(ip4dst.getValue().getInt()));
396 break;
397 case IPV4_SRC:
398 @SuppressWarnings("unchecked")
399 OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm;
400 builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt()));
401 break;
sangho3f97a17d2015-01-29 22:56:29 -0800402 case MPLS_LABEL:
403 @SuppressWarnings("unchecked")
404 OFOxm<U32> labelId = (OFOxm<U32>) oxm;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100405 builder.setMpls(MplsLabel.mplsLabel((int) labelId.getValue().getValue()));
sangho3f97a17d2015-01-29 22:56:29 -0800406 break;
Saurav Das73a7dd42015-08-19 22:20:31 -0700407 case MPLS_BOS:
408 @SuppressWarnings("unchecked")
409 OFOxm<U8> mplsBos = (OFOxm<U8>) oxm;
410 builder.setMplsBos(mplsBos.getValue() == U8.ZERO ? false : true);
411 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700412 case TUNNEL_ID:
413 @SuppressWarnings("unchecked")
414 OFOxm<U64> tunnelId = (OFOxm<U64>) oxm;
415 builder.setTunnelId(tunnelId.getValue().getValue());
416 break;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700417 case TCP_DST:
418 @SuppressWarnings("unchecked")
419 OFOxm<TransportPort> tcpdst = (OFOxm<TransportPort>) oxm;
420 builder.setTcpDst((short) tcpdst.getValue().getPort());
421 break;
422 case TCP_SRC:
423 @SuppressWarnings("unchecked")
424 OFOxm<TransportPort> tcpsrc = (OFOxm<TransportPort>) oxm;
425 builder.setTcpSrc((short) tcpsrc.getValue().getPort());
426 break;
427 case UDP_DST:
428 @SuppressWarnings("unchecked")
429 OFOxm<TransportPort> udpdst = (OFOxm<TransportPort>) oxm;
430 builder.setUdpDst((short) udpdst.getValue().getPort());
431 break;
432 case UDP_SRC:
433 @SuppressWarnings("unchecked")
434 OFOxm<TransportPort> udpsrc = (OFOxm<TransportPort>) oxm;
435 builder.setUdpSrc((short) udpsrc.getValue().getPort());
436 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800437 case ARP_OP:
438 case ARP_SHA:
439 case ARP_SPA:
440 case ARP_THA:
441 case ARP_TPA:
442 case BSN_EGR_PORT_GROUP_ID:
443 case BSN_GLOBAL_VRF_ALLOWED:
444 case BSN_IN_PORTS_128:
445 case BSN_L3_DST_CLASS_ID:
446 case BSN_L3_INTERFACE_CLASS_ID:
447 case BSN_L3_SRC_CLASS_ID:
448 case BSN_LAG_ID:
449 case BSN_TCP_FLAGS:
450 case BSN_UDF0:
451 case BSN_UDF1:
452 case BSN_UDF2:
453 case BSN_UDF3:
454 case BSN_UDF4:
455 case BSN_UDF5:
456 case BSN_UDF6:
457 case BSN_UDF7:
458 case BSN_VLAN_XLATE_PORT_GROUP_ID:
459 case BSN_VRF:
460 case ETH_TYPE:
461 case ICMPV4_CODE:
462 case ICMPV4_TYPE:
463 case ICMPV6_CODE:
464 case ICMPV6_TYPE:
465 case IN_PHY_PORT:
466 case IN_PORT:
467 case IPV6_DST:
468 case IPV6_FLABEL:
469 case IPV6_ND_SLL:
470 case IPV6_ND_TARGET:
471 case IPV6_ND_TLL:
472 case IPV6_SRC:
473 case IP_DSCP:
474 case IP_ECN:
475 case IP_PROTO:
476 case METADATA:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800477 case MPLS_TC:
478 case OCH_SIGID:
479 case OCH_SIGID_BASIC:
480 case OCH_SIGTYPE:
481 case OCH_SIGTYPE_BASIC:
482 case SCTP_DST:
483 case SCTP_SRC:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800484 default:
485 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
486 break;
487 }
488 }
489
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700490 // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES
alshabib6b5cfec2014-09-18 17:42:18 -0700491 private TrafficSelector buildSelector() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800492 MacAddress mac;
493 Ip4Prefix ip4Prefix;
494 Ip6Address ip6Address;
495 Ip6Prefix ip6Prefix;
496
tom9a693fd2014-10-03 11:32:19 -0700497 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700498 for (MatchField<?> field : match.getMatchFields()) {
499 switch (field.id) {
500 case IN_PORT:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800501 builder.matchInPort(PortNumber
alshabib010c31d2014-09-26 10:01:12 -0700502 .portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700503 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800504 case IN_PHY_PORT:
505 builder.matchInPhyPort(PortNumber
506 .portNumber(match.get(MatchField.IN_PHY_PORT).getPortNumber()));
507 break;
508 case METADATA:
509 long metadata =
510 match.get(MatchField.METADATA).getValue().getValue();
511 builder.matchMetadata(metadata);
512 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700513 case ETH_DST:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800514 mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
515 builder.matchEthDst(mac);
516 break;
517 case ETH_SRC:
518 mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
519 builder.matchEthSrc(mac);
alshabib6b5cfec2014-09-18 17:42:18 -0700520 break;
521 case ETH_TYPE:
522 int ethType = match.get(MatchField.ETH_TYPE).getValue();
sanghoc0b3c342015-03-12 17:12:10 -0700523 if (ethType == EthType.VLAN_FRAME.getValue()) {
524 builder.matchVlanId(VlanId.ANY);
525 } else {
526 builder.matchEthType((short) ethType);
527 }
alshabib6b5cfec2014-09-18 17:42:18 -0700528 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700529 case VLAN_VID:
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800530 VlanId vlanId = null;
531 if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
532 Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
533 if (masked.getValue().equals(OFVlanVidMatch.PRESENT)
534 && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
535 vlanId = VlanId.ANY;
536 }
537 } else {
Jonathan Hart1468fee2015-07-16 18:50:34 -0700538 if (!match.get(MatchField.VLAN_VID).isPresentBitSet()) {
539 vlanId = VlanId.NONE;
540 } else {
541 vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
542 }
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800543 }
544 if (vlanId != null) {
545 builder.matchVlanId(vlanId);
546 }
alshabib6b5cfec2014-09-18 17:42:18 -0700547 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800548 case VLAN_PCP:
549 byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
550 builder.matchVlanPcp(vlanPcp);
551 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800552 case IP_DSCP:
553 byte ipDscp = match.get(MatchField.IP_DSCP).getDscpValue();
554 builder.matchIPDscp(ipDscp);
555 break;
556 case IP_ECN:
557 byte ipEcn = match.get(MatchField.IP_ECN).getEcnValue();
558 builder.matchIPEcn(ipEcn);
559 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800560 case IP_PROTO:
561 short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
562 builder.matchIPProtocol((byte) proto);
563 break;
564 case IPV4_SRC:
565 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
566 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800567 ip4Prefix = Ip4Prefix.valueOf(
568 maskedIp.getValue().getInt(),
569 maskedIp.getMask().asCidrMaskLength());
570 } else {
571 ip4Prefix = Ip4Prefix.valueOf(
572 match.get(MatchField.IPV4_SRC).getInt(),
573 Ip4Prefix.MAX_MASK_LENGTH);
574 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800575 builder.matchIPSrc(ip4Prefix);
576 break;
577 case IPV4_DST:
578 if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
579 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800580 ip4Prefix = Ip4Prefix.valueOf(
581 maskedIp.getValue().getInt(),
582 maskedIp.getMask().asCidrMaskLength());
583 } else {
584 ip4Prefix = Ip4Prefix.valueOf(
585 match.get(MatchField.IPV4_DST).getInt(),
586 Ip4Prefix.MAX_MASK_LENGTH);
587 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800588 builder.matchIPDst(ip4Prefix);
Jonathan Hart34bc6142014-10-17 11:00:43 -0700589 break;
590 case TCP_SRC:
591 builder.matchTcpSrc((short) match.get(MatchField.TCP_SRC).getPort());
592 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800593 case TCP_DST:
594 builder.matchTcpDst((short) match.get(MatchField.TCP_DST).getPort());
595 break;
596 case UDP_SRC:
597 builder.matchUdpSrc((short) match.get(MatchField.UDP_SRC).getPort());
598 break;
599 case UDP_DST:
600 builder.matchUdpDst((short) match.get(MatchField.UDP_DST).getPort());
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700601 break;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100602 case MPLS_LABEL:
603 builder.matchMplsLabel(MplsLabel.mplsLabel((int) match.get(MatchField.MPLS_LABEL)
604 .getValue()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800605 break;
Saurav Dasffc5bbc2015-08-18 23:30:19 -0700606 case MPLS_BOS:
607 builder.matchMplsBos(match.get(MatchField.MPLS_BOS).getValue());
608 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800609 case SCTP_SRC:
610 builder.matchSctpSrc((short) match.get(MatchField.SCTP_SRC).getPort());
611 break;
612 case SCTP_DST:
613 builder.matchSctpDst((short) match.get(MatchField.SCTP_DST).getPort());
614 break;
615 case ICMPV4_TYPE:
616 byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
617 builder.matchIcmpType(icmpType);
618 break;
619 case ICMPV4_CODE:
620 byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode();
621 builder.matchIcmpCode(icmpCode);
622 break;
623 case IPV6_SRC:
624 if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
625 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
626 ip6Prefix = Ip6Prefix.valueOf(
627 maskedIp.getValue().getBytes(),
628 maskedIp.getMask().asCidrMaskLength());
629 } else {
630 ip6Prefix = Ip6Prefix.valueOf(
631 match.get(MatchField.IPV6_SRC).getBytes(),
632 Ip6Prefix.MAX_MASK_LENGTH);
633 }
634 builder.matchIPv6Src(ip6Prefix);
635 break;
636 case IPV6_DST:
637 if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
638 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
639 ip6Prefix = Ip6Prefix.valueOf(
640 maskedIp.getValue().getBytes(),
641 maskedIp.getMask().asCidrMaskLength());
642 } else {
643 ip6Prefix = Ip6Prefix.valueOf(
644 match.get(MatchField.IPV6_DST).getBytes(),
645 Ip6Prefix.MAX_MASK_LENGTH);
646 }
647 builder.matchIPv6Dst(ip6Prefix);
648 break;
649 case IPV6_FLABEL:
650 int flowLabel =
651 match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue();
652 builder.matchIPv6FlowLabel(flowLabel);
653 break;
654 case ICMPV6_TYPE:
655 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
656 builder.matchIcmpv6Type(icmpv6type);
657 break;
658 case ICMPV6_CODE:
659 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
660 builder.matchIcmpv6Code(icmpv6code);
661 break;
662 case IPV6_ND_TARGET:
663 ip6Address =
664 Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes());
665 builder.matchIPv6NDTargetAddress(ip6Address);
666 break;
667 case IPV6_ND_SLL:
668 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong());
669 builder.matchIPv6NDSourceLinkLayerAddress(mac);
670 break;
671 case IPV6_ND_TLL:
672 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong());
673 builder.matchIPv6NDTargetLinkLayerAddress(mac);
674 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800675 case IPV6_EXTHDR:
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800676 builder.matchIPv6ExthdrFlags((short) match.get(MatchField.IPV6_EXTHDR)
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700677 .getValue());
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800678 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700679 case OCH_SIGID:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700680 CircuitSignalID sigId = match.get(MatchField.OCH_SIGID);
681 builder.add(matchLambda(Lambda.ochSignal(
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700682 lookupGridType(sigId.getGridType()), lookupChannelSpacing(sigId.getChannelSpacing()),
Marc De Leenheer0b8b2ef2015-08-03 15:39:00 -0700683 sigId.getChannelNumber(), sigId.getSpectralWidth())
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700684 ));
Marc De Leenheer49087752014-10-23 13:54:09 -0700685 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800686 case OCH_SIGTYPE:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700687 U8 sigType = match.get(MatchField.OCH_SIGTYPE);
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700688 builder.add(matchOchSignalType(lookupOchSignalType((byte) sigType.getValue())));
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800689 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700690 case TUNNEL_ID:
691 long tunnelId = match.get(MatchField.TUNNEL_ID).getValue();
692 builder.matchTunnelId(tunnelId);
693 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700694 case ARP_OP:
695 case ARP_SHA:
696 case ARP_SPA:
697 case ARP_THA:
698 case ARP_TPA:
alshabib6b5cfec2014-09-18 17:42:18 -0700699 case MPLS_TC:
alshabib6b5cfec2014-09-18 17:42:18 -0700700 default:
701 log.warn("Match type {} not yet implemented.", field.id);
alshabib6b5cfec2014-09-18 17:42:18 -0700702 }
703 }
704 return builder.build();
705 }
alshabib6b5cfec2014-09-18 17:42:18 -0700706}