blob: 0b9b0cd2ac250ea12f3f25d1267678674317a93f [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 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;
Michele Santuari4b6019e2014-12-19 11:31:45 +010019
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;
29import org.onosproject.net.PortNumber;
30import org.onosproject.net.flow.DefaultFlowEntry;
31import org.onosproject.net.flow.DefaultFlowRule;
32import org.onosproject.net.flow.DefaultTrafficSelector;
33import org.onosproject.net.flow.DefaultTrafficTreatment;
34import org.onosproject.net.flow.FlowEntry;
35import org.onosproject.net.flow.FlowEntry.FlowEntryState;
36import org.onosproject.net.flow.FlowRule;
37import org.onosproject.net.flow.TrafficSelector;
38import org.onosproject.net.flow.TrafficTreatment;
39import org.onosproject.openflow.controller.Dpid;
Brian O'Connor72cb19a2015-01-16 16:14:41 -080040import org.projectfloodlight.openflow.protocol.OFFlowMod;
alshabib6b5cfec2014-09-18 17:42:18 -070041import org.projectfloodlight.openflow.protocol.OFFlowRemoved;
42import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry;
alshabib19fdc122014-10-03 11:38:19 -070043import org.projectfloodlight.openflow.protocol.OFInstructionType;
alshabib6b5cfec2014-09-18 17:42:18 -070044import org.projectfloodlight.openflow.protocol.action.OFAction;
Marc De Leenheer49087752014-10-23 13:54:09 -070045import org.projectfloodlight.openflow.protocol.action.OFActionCircuit;
46import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter;
sangho8995ac52015-02-04 11:29:03 -080047import org.projectfloodlight.openflow.protocol.action.OFActionGroup;
alshabib6b5cfec2014-09-18 17:42:18 -070048import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
sangho3f97a17d2015-01-29 22:56:29 -080049import org.projectfloodlight.openflow.protocol.action.OFActionPopMpls;
alshabib6b5cfec2014-09-18 17:42:18 -070050import org.projectfloodlight.openflow.protocol.action.OFActionSetDlDst;
51import org.projectfloodlight.openflow.protocol.action.OFActionSetDlSrc;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080052import org.projectfloodlight.openflow.protocol.action.OFActionSetField;
alshabib6b5cfec2014-09-18 17:42:18 -070053import org.projectfloodlight.openflow.protocol.action.OFActionSetNwDst;
54import org.projectfloodlight.openflow.protocol.action.OFActionSetNwSrc;
55import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanPcp;
56import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanVid;
alshabib19fdc122014-10-03 11:38:19 -070057import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
Jonathan Hartcf783202014-11-24 18:55:42 -080058import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions;
alshabib6b5cfec2014-09-18 17:42:18 -070059import org.projectfloodlight.openflow.protocol.match.Match;
60import org.projectfloodlight.openflow.protocol.match.MatchField;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080061import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
Marc De Leenheer49087752014-10-23 13:54:09 -070062import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigidBasic;
alshabib6b5cfec2014-09-18 17:42:18 -070063import org.projectfloodlight.openflow.types.IPv4Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080064import org.projectfloodlight.openflow.types.IPv6Address;
Jonathan Hart0e12fad2014-10-17 14:54:58 -070065import org.projectfloodlight.openflow.types.Masked;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080066import org.projectfloodlight.openflow.types.OFVlanVidMatch;
sangho3f97a17d2015-01-29 22:56:29 -080067import org.projectfloodlight.openflow.types.U32;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080068import org.projectfloodlight.openflow.types.VlanPcp;
alshabib6b5cfec2014-09-18 17:42:18 -070069import org.slf4j.Logger;
70
Jonathan Hart6cd2f352015-01-13 17:44:45 -080071import java.util.List;
72
73import static org.slf4j.LoggerFactory.getLogger;
alshabib19fdc122014-10-03 11:38:19 -070074
alshabib1c319ff2014-10-04 20:29:09 -070075public class FlowEntryBuilder {
alshabib6b5cfec2014-09-18 17:42:18 -070076 private final Logger log = getLogger(getClass());
77
78 private final OFFlowStatsEntry stat;
79 private final OFFlowRemoved removed;
Brian O'Connor72cb19a2015-01-16 16:14:41 -080080 private final OFFlowMod flowMod;
alshabib6b5cfec2014-09-18 17:42:18 -070081
82 private final Match match;
83 private final List<OFAction> actions;
84
85 private final Dpid dpid;
86
Brian O'Connor72cb19a2015-01-16 16:14:41 -080087 public enum FlowType { STAT, REMOVED, MOD }
88
89 private final FlowType type;
alshabib6b5cfec2014-09-18 17:42:18 -070090
91
alshabib1c319ff2014-10-04 20:29:09 -070092 public FlowEntryBuilder(Dpid dpid, OFFlowStatsEntry entry) {
alshabib6b5cfec2014-09-18 17:42:18 -070093 this.stat = entry;
94 this.match = entry.getMatch();
alshabib19fdc122014-10-03 11:38:19 -070095 this.actions = getActions(entry);
alshabib6b5cfec2014-09-18 17:42:18 -070096 this.dpid = dpid;
alshabib219ebaa2014-09-22 15:41:24 -070097 this.removed = null;
Brian O'Connor72cb19a2015-01-16 16:14:41 -080098 this.flowMod = null;
99 this.type = FlowType.STAT;
alshabib6b5cfec2014-09-18 17:42:18 -0700100 }
101
alshabib1c319ff2014-10-04 20:29:09 -0700102 public FlowEntryBuilder(Dpid dpid, OFFlowRemoved removed) {
alshabib6b5cfec2014-09-18 17:42:18 -0700103 this.match = removed.getMatch();
104 this.removed = removed;
105
106 this.dpid = dpid;
107 this.actions = null;
108 this.stat = null;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800109 this.flowMod = null;
110 this.type = FlowType.REMOVED;
alshabib6b5cfec2014-09-18 17:42:18 -0700111
112 }
113
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800114 public FlowEntryBuilder(Dpid dpid, OFFlowMod fm) {
115 this.match = fm.getMatch();
116 this.dpid = dpid;
117 this.actions = fm.getActions();
118 this.type = FlowType.MOD;
119 this.flowMod = fm;
120 this.stat = null;
121 this.removed = null;
122 }
alshabib1c319ff2014-10-04 20:29:09 -0700123
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800124 public FlowEntry build(FlowEntryState... state) {
125 FlowRule rule;
126 switch (this.type) {
127 case STAT:
128 rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)),
129 buildSelector(), buildTreatment(), stat.getPriority(),
130 stat.getCookie().getValue(), stat.getIdleTimeout(), false);
131 return new DefaultFlowEntry(rule, FlowEntryState.ADDED,
132 stat.getDurationSec(), stat.getPacketCount().getValue(),
133 stat.getByteCount().getValue());
134 case REMOVED:
135 rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)),
136 buildSelector(), null, removed.getPriority(),
137 removed.getCookie().getValue(), removed.getIdleTimeout(), false);
138 return new DefaultFlowEntry(rule, FlowEntryState.REMOVED, removed.getDurationSec(),
139 removed.getPacketCount().getValue(), removed.getByteCount().getValue());
140 case MOD:
141 FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED;
142 rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)),
143 buildSelector(), buildTreatment(), flowMod.getPriority(),
144 flowMod.getCookie().getValue(), flowMod.getIdleTimeout(), false);
145 return new DefaultFlowEntry(rule, flowState, 0, 0, 0);
146 default:
147 log.error("Unknown flow type : {}", this.type);
148 return null;
alshabib6b5cfec2014-09-18 17:42:18 -0700149 }
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800150
alshabib6b5cfec2014-09-18 17:42:18 -0700151 }
152
alshabib19fdc122014-10-03 11:38:19 -0700153 private List<OFAction> getActions(OFFlowStatsEntry entry) {
154 switch (entry.getVersion()) {
155 case OF_10:
156 return entry.getActions();
157 case OF_11:
158 case OF_12:
159 case OF_13:
160 List<OFInstruction> ins = entry.getInstructions();
161 for (OFInstruction in : ins) {
Jonathan Hartcf783202014-11-24 18:55:42 -0800162 if (in.getType().equals(OFInstructionType.APPLY_ACTIONS)) {
163 OFInstructionApplyActions apply = (OFInstructionApplyActions) in;
alshabib19fdc122014-10-03 11:38:19 -0700164 return apply.getActions();
165 }
166 }
167 return Lists.newLinkedList();
168 default:
169 log.warn("Unknown OF version {}", entry.getVersion());
170 }
171 return Lists.newLinkedList();
172 }
alshabib6b5cfec2014-09-18 17:42:18 -0700173
174 private TrafficTreatment buildTreatment() {
tom9a693fd2014-10-03 11:32:19 -0700175 TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700176 // If this is a drop rule
177 if (actions.size() == 0) {
alshabib010c31d2014-09-26 10:01:12 -0700178 builder.drop();
alshabib6b5cfec2014-09-18 17:42:18 -0700179 return builder.build();
180 }
181 for (OFAction act : actions) {
182 switch (act.getType()) {
183 case OUTPUT:
184 OFActionOutput out = (OFActionOutput) act;
alshabib010c31d2014-09-26 10:01:12 -0700185 builder.setOutput(
186 PortNumber.portNumber(out.getPort().getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700187 break;
188 case SET_VLAN_VID:
alshabib010c31d2014-09-26 10:01:12 -0700189 OFActionSetVlanVid vlan = (OFActionSetVlanVid) act;
190 builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan()));
191 break;
192 case SET_VLAN_PCP:
alshabib6b5cfec2014-09-18 17:42:18 -0700193 OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800194 builder.setVlanPcp(pcp.getVlanPcp().getValue());
alshabib6b5cfec2014-09-18 17:42:18 -0700195 break;
196 case SET_DL_DST:
197 OFActionSetDlDst dldst = (OFActionSetDlDst) act;
alshabib010c31d2014-09-26 10:01:12 -0700198 builder.setEthDst(
199 MacAddress.valueOf(dldst.getDlAddr().getLong()));
alshabib6b5cfec2014-09-18 17:42:18 -0700200 break;
201 case SET_DL_SRC:
202 OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act;
alshabib010c31d2014-09-26 10:01:12 -0700203 builder.setEthSrc(
204 MacAddress.valueOf(dlsrc.getDlAddr().getLong()));
alshabib6b5cfec2014-09-18 17:42:18 -0700205
206 break;
207 case SET_NW_DST:
208 OFActionSetNwDst nwdst = (OFActionSetNwDst) act;
209 IPv4Address di = nwdst.getNwAddr();
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800210 builder.setIpDst(Ip4Address.valueOf(di.getInt()));
alshabib6b5cfec2014-09-18 17:42:18 -0700211 break;
212 case SET_NW_SRC:
213 OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act;
214 IPv4Address si = nwsrc.getNwAddr();
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800215 builder.setIpSrc(Ip4Address.valueOf(si.getInt()));
alshabib6b5cfec2014-09-18 17:42:18 -0700216 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700217 case EXPERIMENTER:
218 OFActionExperimenter exp = (OFActionExperimenter) act;
Praseed Balakrishnandb8a9d22014-12-03 11:47:55 -0800219 if (exp.getExperimenter() == 0x80005A06 ||
220 exp.getExperimenter() == 0x748771) {
Marc De Leenheer49087752014-10-23 13:54:09 -0700221 OFActionCircuit ct = (OFActionCircuit) exp;
222 builder.setLambda(((OFOxmOchSigidBasic) ct.getField()).getValue().getChannelNumber());
223 } else {
224 log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter());
225 }
226 break;
Jonathan Hart1f8e0d72014-11-25 11:13:00 -0800227 case SET_FIELD:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800228 OFActionSetField setField = (OFActionSetField) act;
229 handleSetField(builder, setField.getField());
Jonathan Hart1f8e0d72014-11-25 11:13:00 -0800230 break;
sangho3f97a17d2015-01-29 22:56:29 -0800231 case POP_MPLS:
232 OFActionPopMpls popMpls = (OFActionPopMpls) act;
233 builder.popMpls((short) popMpls.getEthertype().getValue());
234 break;
235 case PUSH_MPLS:
sangho3f97a17d2015-01-29 22:56:29 -0800236 builder.pushMpls();
237 break;
238 case COPY_TTL_IN:
sangho3f97a17d2015-01-29 22:56:29 -0800239 builder.copyTtlIn();
240 break;
241 case COPY_TTL_OUT:
sangho3f97a17d2015-01-29 22:56:29 -0800242 builder.copyTtlOut();
243 break;
244 case DEC_MPLS_TTL:
sangho3f97a17d2015-01-29 22:56:29 -0800245 builder.decMplsTtl();
246 break;
247 case DEC_NW_TTL:
sangho3f97a17d2015-01-29 22:56:29 -0800248 builder.decNwTtl();
249 break;
sangho8995ac52015-02-04 11:29:03 -0800250 case GROUP:
251 OFActionGroup group = (OFActionGroup) act;
252 builder.group(new DefaultGroupId(group.getGroup().getGroupNumber()));
253 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700254 case SET_TP_DST:
255 case SET_TP_SRC:
alshabib6b5cfec2014-09-18 17:42:18 -0700256 case POP_PBB:
257 case POP_VLAN:
alshabib6b5cfec2014-09-18 17:42:18 -0700258 case PUSH_PBB:
259 case PUSH_VLAN:
alshabib6b5cfec2014-09-18 17:42:18 -0700260 case SET_MPLS_LABEL:
261 case SET_MPLS_TC:
262 case SET_MPLS_TTL:
263 case SET_NW_ECN:
264 case SET_NW_TOS:
265 case SET_NW_TTL:
266 case SET_QUEUE:
267 case STRIP_VLAN:
alshabib6b5cfec2014-09-18 17:42:18 -0700268 case ENQUEUE:
alshabib6b5cfec2014-09-18 17:42:18 -0700269 default:
270 log.warn("Action type {} not yet implemented.", act.getType());
271 }
272 }
273
274 return builder.build();
275 }
276
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800277 private void handleSetField(TrafficTreatment.Builder builder, OFOxm<?> oxm) {
278 switch (oxm.getMatchField().id) {
279 case VLAN_PCP:
280 @SuppressWarnings("unchecked")
281 OFOxm<VlanPcp> vlanpcp = (OFOxm<VlanPcp>) oxm;
282 builder.setVlanPcp(vlanpcp.getValue().getValue());
283 break;
284 case VLAN_VID:
285 @SuppressWarnings("unchecked")
286 OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm;
287 builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan()));
288 break;
289 case ETH_DST:
290 @SuppressWarnings("unchecked")
291 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethdst =
292 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
293 builder.setEthDst(MacAddress.valueOf(ethdst.getValue().getLong()));
294 break;
295 case ETH_SRC:
296 @SuppressWarnings("unchecked")
297 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethsrc =
298 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
299 builder.setEthSrc(MacAddress.valueOf(ethsrc.getValue().getLong()));
300 break;
301 case IPV4_DST:
302 @SuppressWarnings("unchecked")
303 OFOxm<IPv4Address> ip4dst = (OFOxm<IPv4Address>) oxm;
304 builder.setIpDst(Ip4Address.valueOf(ip4dst.getValue().getInt()));
305 break;
306 case IPV4_SRC:
307 @SuppressWarnings("unchecked")
308 OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm;
309 builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt()));
310 break;
sangho3f97a17d2015-01-29 22:56:29 -0800311 case MPLS_LABEL:
312 @SuppressWarnings("unchecked")
313 OFOxm<U32> labelId = (OFOxm<U32>) oxm;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100314 builder.setMpls(MplsLabel.mplsLabel((int) labelId.getValue().getValue()));
sangho3f97a17d2015-01-29 22:56:29 -0800315 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800316 case ARP_OP:
317 case ARP_SHA:
318 case ARP_SPA:
319 case ARP_THA:
320 case ARP_TPA:
321 case BSN_EGR_PORT_GROUP_ID:
322 case BSN_GLOBAL_VRF_ALLOWED:
323 case BSN_IN_PORTS_128:
324 case BSN_L3_DST_CLASS_ID:
325 case BSN_L3_INTERFACE_CLASS_ID:
326 case BSN_L3_SRC_CLASS_ID:
327 case BSN_LAG_ID:
328 case BSN_TCP_FLAGS:
329 case BSN_UDF0:
330 case BSN_UDF1:
331 case BSN_UDF2:
332 case BSN_UDF3:
333 case BSN_UDF4:
334 case BSN_UDF5:
335 case BSN_UDF6:
336 case BSN_UDF7:
337 case BSN_VLAN_XLATE_PORT_GROUP_ID:
338 case BSN_VRF:
339 case ETH_TYPE:
340 case ICMPV4_CODE:
341 case ICMPV4_TYPE:
342 case ICMPV6_CODE:
343 case ICMPV6_TYPE:
344 case IN_PHY_PORT:
345 case IN_PORT:
346 case IPV6_DST:
347 case IPV6_FLABEL:
348 case IPV6_ND_SLL:
349 case IPV6_ND_TARGET:
350 case IPV6_ND_TLL:
351 case IPV6_SRC:
352 case IP_DSCP:
353 case IP_ECN:
354 case IP_PROTO:
355 case METADATA:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800356 case MPLS_TC:
357 case OCH_SIGID:
358 case OCH_SIGID_BASIC:
359 case OCH_SIGTYPE:
360 case OCH_SIGTYPE_BASIC:
361 case SCTP_DST:
362 case SCTP_SRC:
363 case TCP_DST:
364 case TCP_SRC:
365 case TUNNEL_ID:
366 case UDP_DST:
367 case UDP_SRC:
368 default:
369 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
370 break;
371 }
372 }
373
alshabib6b5cfec2014-09-18 17:42:18 -0700374 private TrafficSelector buildSelector() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800375 MacAddress mac;
376 Ip4Prefix ip4Prefix;
377 Ip6Address ip6Address;
378 Ip6Prefix ip6Prefix;
379
tom9a693fd2014-10-03 11:32:19 -0700380 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700381 for (MatchField<?> field : match.getMatchFields()) {
382 switch (field.id) {
383 case IN_PORT:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800384 builder.matchInPort(PortNumber
alshabib010c31d2014-09-26 10:01:12 -0700385 .portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700386 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800387 case IN_PHY_PORT:
388 builder.matchInPhyPort(PortNumber
389 .portNumber(match.get(MatchField.IN_PHY_PORT).getPortNumber()));
390 break;
391 case METADATA:
392 long metadata =
393 match.get(MatchField.METADATA).getValue().getValue();
394 builder.matchMetadata(metadata);
395 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700396 case ETH_DST:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800397 mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
398 builder.matchEthDst(mac);
399 break;
400 case ETH_SRC:
401 mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
402 builder.matchEthSrc(mac);
alshabib6b5cfec2014-09-18 17:42:18 -0700403 break;
404 case ETH_TYPE:
405 int ethType = match.get(MatchField.ETH_TYPE).getValue();
alshabib010c31d2014-09-26 10:01:12 -0700406 builder.matchEthType((short) ethType);
alshabib6b5cfec2014-09-18 17:42:18 -0700407 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700408 case VLAN_VID:
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800409 VlanId vlanId = null;
410 if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
411 Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
412 if (masked.getValue().equals(OFVlanVidMatch.PRESENT)
413 && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
414 vlanId = VlanId.ANY;
415 }
416 } else {
417 vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
418 }
419 if (vlanId != null) {
420 builder.matchVlanId(vlanId);
421 }
alshabib6b5cfec2014-09-18 17:42:18 -0700422 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800423 case VLAN_PCP:
424 byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
425 builder.matchVlanPcp(vlanPcp);
426 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800427 case IP_DSCP:
428 byte ipDscp = match.get(MatchField.IP_DSCP).getDscpValue();
429 builder.matchIPDscp(ipDscp);
430 break;
431 case IP_ECN:
432 byte ipEcn = match.get(MatchField.IP_ECN).getEcnValue();
433 builder.matchIPEcn(ipEcn);
434 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800435 case IP_PROTO:
436 short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
437 builder.matchIPProtocol((byte) proto);
438 break;
439 case IPV4_SRC:
440 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
441 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800442 ip4Prefix = Ip4Prefix.valueOf(
443 maskedIp.getValue().getInt(),
444 maskedIp.getMask().asCidrMaskLength());
445 } else {
446 ip4Prefix = Ip4Prefix.valueOf(
447 match.get(MatchField.IPV4_SRC).getInt(),
448 Ip4Prefix.MAX_MASK_LENGTH);
449 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800450 builder.matchIPSrc(ip4Prefix);
451 break;
452 case IPV4_DST:
453 if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
454 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800455 ip4Prefix = Ip4Prefix.valueOf(
456 maskedIp.getValue().getInt(),
457 maskedIp.getMask().asCidrMaskLength());
458 } else {
459 ip4Prefix = Ip4Prefix.valueOf(
460 match.get(MatchField.IPV4_DST).getInt(),
461 Ip4Prefix.MAX_MASK_LENGTH);
462 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800463 builder.matchIPDst(ip4Prefix);
Jonathan Hart34bc6142014-10-17 11:00:43 -0700464 break;
465 case TCP_SRC:
466 builder.matchTcpSrc((short) match.get(MatchField.TCP_SRC).getPort());
467 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800468 case TCP_DST:
469 builder.matchTcpDst((short) match.get(MatchField.TCP_DST).getPort());
470 break;
471 case UDP_SRC:
472 builder.matchUdpSrc((short) match.get(MatchField.UDP_SRC).getPort());
473 break;
474 case UDP_DST:
475 builder.matchUdpDst((short) match.get(MatchField.UDP_DST).getPort());
Michele Santuari4b6019e2014-12-19 11:31:45 +0100476 case MPLS_LABEL:
477 builder.matchMplsLabel(MplsLabel.mplsLabel((int) match.get(MatchField.MPLS_LABEL)
478 .getValue()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800479 break;
480 case SCTP_SRC:
481 builder.matchSctpSrc((short) match.get(MatchField.SCTP_SRC).getPort());
482 break;
483 case SCTP_DST:
484 builder.matchSctpDst((short) match.get(MatchField.SCTP_DST).getPort());
485 break;
486 case ICMPV4_TYPE:
487 byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
488 builder.matchIcmpType(icmpType);
489 break;
490 case ICMPV4_CODE:
491 byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode();
492 builder.matchIcmpCode(icmpCode);
493 break;
494 case IPV6_SRC:
495 if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
496 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
497 ip6Prefix = Ip6Prefix.valueOf(
498 maskedIp.getValue().getBytes(),
499 maskedIp.getMask().asCidrMaskLength());
500 } else {
501 ip6Prefix = Ip6Prefix.valueOf(
502 match.get(MatchField.IPV6_SRC).getBytes(),
503 Ip6Prefix.MAX_MASK_LENGTH);
504 }
505 builder.matchIPv6Src(ip6Prefix);
506 break;
507 case IPV6_DST:
508 if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
509 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
510 ip6Prefix = Ip6Prefix.valueOf(
511 maskedIp.getValue().getBytes(),
512 maskedIp.getMask().asCidrMaskLength());
513 } else {
514 ip6Prefix = Ip6Prefix.valueOf(
515 match.get(MatchField.IPV6_DST).getBytes(),
516 Ip6Prefix.MAX_MASK_LENGTH);
517 }
518 builder.matchIPv6Dst(ip6Prefix);
519 break;
520 case IPV6_FLABEL:
521 int flowLabel =
522 match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue();
523 builder.matchIPv6FlowLabel(flowLabel);
524 break;
525 case ICMPV6_TYPE:
526 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
527 builder.matchIcmpv6Type(icmpv6type);
528 break;
529 case ICMPV6_CODE:
530 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
531 builder.matchIcmpv6Code(icmpv6code);
532 break;
533 case IPV6_ND_TARGET:
534 ip6Address =
535 Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes());
536 builder.matchIPv6NDTargetAddress(ip6Address);
537 break;
538 case IPV6_ND_SLL:
539 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong());
540 builder.matchIPv6NDSourceLinkLayerAddress(mac);
541 break;
542 case IPV6_ND_TLL:
543 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong());
544 builder.matchIPv6NDTargetLinkLayerAddress(mac);
545 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800546 case IPV6_EXTHDR:
547 builder.matchIPv6ExthdrFlags((int) match.get(MatchField.IPV6_EXTHDR)
548 .getValue());
549 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700550 case OCH_SIGID:
551 builder.matchLambda(match.get(MatchField.OCH_SIGID).getChannelNumber());
552 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800553 case OCH_SIGTYPE:
554 builder.matchOpticalSignalType(match.get(MatchField
555 .OCH_SIGTYPE).getValue());
556 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700557 case ARP_OP:
558 case ARP_SHA:
559 case ARP_SPA:
560 case ARP_THA:
561 case ARP_TPA:
alshabib6b5cfec2014-09-18 17:42:18 -0700562 case MPLS_TC:
alshabib6b5cfec2014-09-18 17:42:18 -0700563 case TUNNEL_ID:
alshabib6b5cfec2014-09-18 17:42:18 -0700564 default:
565 log.warn("Match type {} not yet implemented.", field.id);
alshabib6b5cfec2014-09-18 17:42:18 -0700566 }
567 }
568 return builder.build();
569 }
alshabib6b5cfec2014-09-18 17:42:18 -0700570}