blob: 8f2b5f4d8d9398f66186efe2eccef7e2ac44eef7 [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;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080019import org.onlab.packet.Ip4Address;
20import org.onlab.packet.Ip4Prefix;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080021import org.onlab.packet.Ip6Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080022import org.onlab.packet.Ip6Prefix;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080023import org.onlab.packet.MacAddress;
24import org.onlab.packet.VlanId;
sangho8995ac52015-02-04 11:29:03 -080025import org.onosproject.core.DefaultGroupId;
Brian O'Connorabafb502014-12-02 22:26:20 -080026import org.onosproject.net.DeviceId;
27import org.onosproject.net.PortNumber;
28import org.onosproject.net.flow.DefaultFlowEntry;
29import org.onosproject.net.flow.DefaultFlowRule;
30import org.onosproject.net.flow.DefaultTrafficSelector;
31import org.onosproject.net.flow.DefaultTrafficTreatment;
32import org.onosproject.net.flow.FlowEntry;
33import org.onosproject.net.flow.FlowEntry.FlowEntryState;
34import org.onosproject.net.flow.FlowRule;
35import org.onosproject.net.flow.TrafficSelector;
36import org.onosproject.net.flow.TrafficTreatment;
37import org.onosproject.openflow.controller.Dpid;
Brian O'Connor72cb19a2015-01-16 16:14:41 -080038import org.projectfloodlight.openflow.protocol.OFFlowMod;
alshabib6b5cfec2014-09-18 17:42:18 -070039import org.projectfloodlight.openflow.protocol.OFFlowRemoved;
40import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry;
alshabib19fdc122014-10-03 11:38:19 -070041import org.projectfloodlight.openflow.protocol.OFInstructionType;
alshabib6b5cfec2014-09-18 17:42:18 -070042import org.projectfloodlight.openflow.protocol.action.OFAction;
Marc De Leenheer49087752014-10-23 13:54:09 -070043import org.projectfloodlight.openflow.protocol.action.OFActionCircuit;
44import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter;
sangho8995ac52015-02-04 11:29:03 -080045import org.projectfloodlight.openflow.protocol.action.OFActionGroup;
alshabib6b5cfec2014-09-18 17:42:18 -070046import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
sangho3f97a17d2015-01-29 22:56:29 -080047import org.projectfloodlight.openflow.protocol.action.OFActionPopMpls;
alshabib6b5cfec2014-09-18 17:42:18 -070048import org.projectfloodlight.openflow.protocol.action.OFActionSetDlDst;
49import org.projectfloodlight.openflow.protocol.action.OFActionSetDlSrc;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080050import org.projectfloodlight.openflow.protocol.action.OFActionSetField;
alshabib6b5cfec2014-09-18 17:42:18 -070051import org.projectfloodlight.openflow.protocol.action.OFActionSetNwDst;
52import org.projectfloodlight.openflow.protocol.action.OFActionSetNwSrc;
53import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanPcp;
54import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanVid;
alshabib19fdc122014-10-03 11:38:19 -070055import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
Jonathan Hartcf783202014-11-24 18:55:42 -080056import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions;
alshabib6b5cfec2014-09-18 17:42:18 -070057import org.projectfloodlight.openflow.protocol.match.Match;
58import org.projectfloodlight.openflow.protocol.match.MatchField;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080059import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
Marc De Leenheer49087752014-10-23 13:54:09 -070060import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigidBasic;
alshabib6b5cfec2014-09-18 17:42:18 -070061import org.projectfloodlight.openflow.types.IPv4Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080062import org.projectfloodlight.openflow.types.IPv6Address;
Jonathan Hart0e12fad2014-10-17 14:54:58 -070063import org.projectfloodlight.openflow.types.Masked;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080064import org.projectfloodlight.openflow.types.OFVlanVidMatch;
sangho3f97a17d2015-01-29 22:56:29 -080065import org.projectfloodlight.openflow.types.U32;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080066import org.projectfloodlight.openflow.types.VlanPcp;
alshabib6b5cfec2014-09-18 17:42:18 -070067import org.slf4j.Logger;
68
Jonathan Hart6cd2f352015-01-13 17:44:45 -080069import java.util.List;
70
71import static org.slf4j.LoggerFactory.getLogger;
alshabib19fdc122014-10-03 11:38:19 -070072
alshabib1c319ff2014-10-04 20:29:09 -070073public class FlowEntryBuilder {
alshabib6b5cfec2014-09-18 17:42:18 -070074 private final Logger log = getLogger(getClass());
75
76 private final OFFlowStatsEntry stat;
77 private final OFFlowRemoved removed;
Brian O'Connor72cb19a2015-01-16 16:14:41 -080078 private final OFFlowMod flowMod;
alshabib6b5cfec2014-09-18 17:42:18 -070079
80 private final Match match;
81 private final List<OFAction> actions;
82
83 private final Dpid dpid;
84
Brian O'Connor72cb19a2015-01-16 16:14:41 -080085 public enum FlowType { STAT, REMOVED, MOD }
86
87 private final FlowType type;
alshabib6b5cfec2014-09-18 17:42:18 -070088
89
alshabib1c319ff2014-10-04 20:29:09 -070090 public FlowEntryBuilder(Dpid dpid, OFFlowStatsEntry entry) {
alshabib6b5cfec2014-09-18 17:42:18 -070091 this.stat = entry;
92 this.match = entry.getMatch();
alshabib19fdc122014-10-03 11:38:19 -070093 this.actions = getActions(entry);
alshabib6b5cfec2014-09-18 17:42:18 -070094 this.dpid = dpid;
alshabib219ebaa2014-09-22 15:41:24 -070095 this.removed = null;
Brian O'Connor72cb19a2015-01-16 16:14:41 -080096 this.flowMod = null;
97 this.type = FlowType.STAT;
alshabib6b5cfec2014-09-18 17:42:18 -070098 }
99
alshabib1c319ff2014-10-04 20:29:09 -0700100 public FlowEntryBuilder(Dpid dpid, OFFlowRemoved removed) {
alshabib6b5cfec2014-09-18 17:42:18 -0700101 this.match = removed.getMatch();
102 this.removed = removed;
103
104 this.dpid = dpid;
105 this.actions = null;
106 this.stat = null;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800107 this.flowMod = null;
108 this.type = FlowType.REMOVED;
alshabib6b5cfec2014-09-18 17:42:18 -0700109
110 }
111
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800112 public FlowEntryBuilder(Dpid dpid, OFFlowMod fm) {
113 this.match = fm.getMatch();
114 this.dpid = dpid;
115 this.actions = fm.getActions();
116 this.type = FlowType.MOD;
117 this.flowMod = fm;
118 this.stat = null;
119 this.removed = null;
120 }
alshabib1c319ff2014-10-04 20:29:09 -0700121
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800122 public FlowEntry build(FlowEntryState... state) {
123 FlowRule rule;
124 switch (this.type) {
125 case STAT:
126 rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)),
127 buildSelector(), buildTreatment(), stat.getPriority(),
128 stat.getCookie().getValue(), stat.getIdleTimeout(), false);
129 return new DefaultFlowEntry(rule, FlowEntryState.ADDED,
130 stat.getDurationSec(), stat.getPacketCount().getValue(),
131 stat.getByteCount().getValue());
132 case REMOVED:
133 rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)),
134 buildSelector(), null, removed.getPriority(),
135 removed.getCookie().getValue(), removed.getIdleTimeout(), false);
136 return new DefaultFlowEntry(rule, FlowEntryState.REMOVED, removed.getDurationSec(),
137 removed.getPacketCount().getValue(), removed.getByteCount().getValue());
138 case MOD:
139 FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED;
140 rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)),
141 buildSelector(), buildTreatment(), flowMod.getPriority(),
142 flowMod.getCookie().getValue(), flowMod.getIdleTimeout(), false);
143 return new DefaultFlowEntry(rule, flowState, 0, 0, 0);
144 default:
145 log.error("Unknown flow type : {}", this.type);
146 return null;
alshabib6b5cfec2014-09-18 17:42:18 -0700147 }
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800148
alshabib6b5cfec2014-09-18 17:42:18 -0700149 }
150
alshabib19fdc122014-10-03 11:38:19 -0700151 private List<OFAction> getActions(OFFlowStatsEntry entry) {
152 switch (entry.getVersion()) {
153 case OF_10:
154 return entry.getActions();
155 case OF_11:
156 case OF_12:
157 case OF_13:
158 List<OFInstruction> ins = entry.getInstructions();
159 for (OFInstruction in : ins) {
Jonathan Hartcf783202014-11-24 18:55:42 -0800160 if (in.getType().equals(OFInstructionType.APPLY_ACTIONS)) {
161 OFInstructionApplyActions apply = (OFInstructionApplyActions) in;
alshabib19fdc122014-10-03 11:38:19 -0700162 return apply.getActions();
163 }
164 }
165 return Lists.newLinkedList();
166 default:
167 log.warn("Unknown OF version {}", entry.getVersion());
168 }
169 return Lists.newLinkedList();
170 }
alshabib6b5cfec2014-09-18 17:42:18 -0700171
172 private TrafficTreatment buildTreatment() {
tom9a693fd2014-10-03 11:32:19 -0700173 TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700174 // If this is a drop rule
175 if (actions.size() == 0) {
alshabib010c31d2014-09-26 10:01:12 -0700176 builder.drop();
alshabib6b5cfec2014-09-18 17:42:18 -0700177 return builder.build();
178 }
179 for (OFAction act : actions) {
180 switch (act.getType()) {
181 case OUTPUT:
182 OFActionOutput out = (OFActionOutput) act;
alshabib010c31d2014-09-26 10:01:12 -0700183 builder.setOutput(
184 PortNumber.portNumber(out.getPort().getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700185 break;
186 case SET_VLAN_VID:
alshabib010c31d2014-09-26 10:01:12 -0700187 OFActionSetVlanVid vlan = (OFActionSetVlanVid) act;
188 builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan()));
189 break;
190 case SET_VLAN_PCP:
alshabib6b5cfec2014-09-18 17:42:18 -0700191 OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800192 builder.setVlanPcp(pcp.getVlanPcp().getValue());
alshabib6b5cfec2014-09-18 17:42:18 -0700193 break;
194 case SET_DL_DST:
195 OFActionSetDlDst dldst = (OFActionSetDlDst) act;
alshabib010c31d2014-09-26 10:01:12 -0700196 builder.setEthDst(
197 MacAddress.valueOf(dldst.getDlAddr().getLong()));
alshabib6b5cfec2014-09-18 17:42:18 -0700198 break;
199 case SET_DL_SRC:
200 OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act;
alshabib010c31d2014-09-26 10:01:12 -0700201 builder.setEthSrc(
202 MacAddress.valueOf(dlsrc.getDlAddr().getLong()));
alshabib6b5cfec2014-09-18 17:42:18 -0700203
204 break;
205 case SET_NW_DST:
206 OFActionSetNwDst nwdst = (OFActionSetNwDst) act;
207 IPv4Address di = nwdst.getNwAddr();
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800208 builder.setIpDst(Ip4Address.valueOf(di.getInt()));
alshabib6b5cfec2014-09-18 17:42:18 -0700209 break;
210 case SET_NW_SRC:
211 OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act;
212 IPv4Address si = nwsrc.getNwAddr();
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800213 builder.setIpSrc(Ip4Address.valueOf(si.getInt()));
alshabib6b5cfec2014-09-18 17:42:18 -0700214 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700215 case EXPERIMENTER:
216 OFActionExperimenter exp = (OFActionExperimenter) act;
Praseed Balakrishnandb8a9d22014-12-03 11:47:55 -0800217 if (exp.getExperimenter() == 0x80005A06 ||
218 exp.getExperimenter() == 0x748771) {
Marc De Leenheer49087752014-10-23 13:54:09 -0700219 OFActionCircuit ct = (OFActionCircuit) exp;
220 builder.setLambda(((OFOxmOchSigidBasic) ct.getField()).getValue().getChannelNumber());
221 } else {
222 log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter());
223 }
224 break;
Jonathan Hart1f8e0d72014-11-25 11:13:00 -0800225 case SET_FIELD:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800226 OFActionSetField setField = (OFActionSetField) act;
227 handleSetField(builder, setField.getField());
Jonathan Hart1f8e0d72014-11-25 11:13:00 -0800228 break;
sangho3f97a17d2015-01-29 22:56:29 -0800229 case POP_MPLS:
230 OFActionPopMpls popMpls = (OFActionPopMpls) act;
231 builder.popMpls((short) popMpls.getEthertype().getValue());
232 break;
233 case PUSH_MPLS:
sangho3f97a17d2015-01-29 22:56:29 -0800234 builder.pushMpls();
235 break;
236 case COPY_TTL_IN:
sangho3f97a17d2015-01-29 22:56:29 -0800237 builder.copyTtlIn();
238 break;
239 case COPY_TTL_OUT:
sangho3f97a17d2015-01-29 22:56:29 -0800240 builder.copyTtlOut();
241 break;
242 case DEC_MPLS_TTL:
sangho3f97a17d2015-01-29 22:56:29 -0800243 builder.decMplsTtl();
244 break;
245 case DEC_NW_TTL:
sangho3f97a17d2015-01-29 22:56:29 -0800246 builder.decNwTtl();
247 break;
sangho8995ac52015-02-04 11:29:03 -0800248 case GROUP:
249 OFActionGroup group = (OFActionGroup) act;
250 builder.group(new DefaultGroupId(group.getGroup().getGroupNumber()));
251 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700252 case SET_TP_DST:
253 case SET_TP_SRC:
alshabib6b5cfec2014-09-18 17:42:18 -0700254 case POP_PBB:
255 case POP_VLAN:
alshabib6b5cfec2014-09-18 17:42:18 -0700256 case PUSH_PBB:
257 case PUSH_VLAN:
alshabib6b5cfec2014-09-18 17:42:18 -0700258 case SET_MPLS_LABEL:
259 case SET_MPLS_TC:
260 case SET_MPLS_TTL:
261 case SET_NW_ECN:
262 case SET_NW_TOS:
263 case SET_NW_TTL:
264 case SET_QUEUE:
265 case STRIP_VLAN:
alshabib6b5cfec2014-09-18 17:42:18 -0700266 case ENQUEUE:
alshabib6b5cfec2014-09-18 17:42:18 -0700267 default:
268 log.warn("Action type {} not yet implemented.", act.getType());
269 }
270 }
271
272 return builder.build();
273 }
274
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800275 private void handleSetField(TrafficTreatment.Builder builder, OFOxm<?> oxm) {
276 switch (oxm.getMatchField().id) {
277 case VLAN_PCP:
278 @SuppressWarnings("unchecked")
279 OFOxm<VlanPcp> vlanpcp = (OFOxm<VlanPcp>) oxm;
280 builder.setVlanPcp(vlanpcp.getValue().getValue());
281 break;
282 case VLAN_VID:
283 @SuppressWarnings("unchecked")
284 OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm;
285 builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan()));
286 break;
287 case ETH_DST:
288 @SuppressWarnings("unchecked")
289 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethdst =
290 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
291 builder.setEthDst(MacAddress.valueOf(ethdst.getValue().getLong()));
292 break;
293 case ETH_SRC:
294 @SuppressWarnings("unchecked")
295 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethsrc =
296 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
297 builder.setEthSrc(MacAddress.valueOf(ethsrc.getValue().getLong()));
298 break;
299 case IPV4_DST:
300 @SuppressWarnings("unchecked")
301 OFOxm<IPv4Address> ip4dst = (OFOxm<IPv4Address>) oxm;
302 builder.setIpDst(Ip4Address.valueOf(ip4dst.getValue().getInt()));
303 break;
304 case IPV4_SRC:
305 @SuppressWarnings("unchecked")
306 OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm;
307 builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt()));
308 break;
sangho3f97a17d2015-01-29 22:56:29 -0800309 case MPLS_LABEL:
310 @SuppressWarnings("unchecked")
311 OFOxm<U32> labelId = (OFOxm<U32>) oxm;
312 builder.setMpls((int) labelId.getValue().getValue());
313 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800314 case ARP_OP:
315 case ARP_SHA:
316 case ARP_SPA:
317 case ARP_THA:
318 case ARP_TPA:
319 case BSN_EGR_PORT_GROUP_ID:
320 case BSN_GLOBAL_VRF_ALLOWED:
321 case BSN_IN_PORTS_128:
322 case BSN_L3_DST_CLASS_ID:
323 case BSN_L3_INTERFACE_CLASS_ID:
324 case BSN_L3_SRC_CLASS_ID:
325 case BSN_LAG_ID:
326 case BSN_TCP_FLAGS:
327 case BSN_UDF0:
328 case BSN_UDF1:
329 case BSN_UDF2:
330 case BSN_UDF3:
331 case BSN_UDF4:
332 case BSN_UDF5:
333 case BSN_UDF6:
334 case BSN_UDF7:
335 case BSN_VLAN_XLATE_PORT_GROUP_ID:
336 case BSN_VRF:
337 case ETH_TYPE:
338 case ICMPV4_CODE:
339 case ICMPV4_TYPE:
340 case ICMPV6_CODE:
341 case ICMPV6_TYPE:
342 case IN_PHY_PORT:
343 case IN_PORT:
344 case IPV6_DST:
345 case IPV6_FLABEL:
346 case IPV6_ND_SLL:
347 case IPV6_ND_TARGET:
348 case IPV6_ND_TLL:
349 case IPV6_SRC:
350 case IP_DSCP:
351 case IP_ECN:
352 case IP_PROTO:
353 case METADATA:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800354 case MPLS_TC:
355 case OCH_SIGID:
356 case OCH_SIGID_BASIC:
357 case OCH_SIGTYPE:
358 case OCH_SIGTYPE_BASIC:
359 case SCTP_DST:
360 case SCTP_SRC:
361 case TCP_DST:
362 case TCP_SRC:
363 case TUNNEL_ID:
364 case UDP_DST:
365 case UDP_SRC:
366 default:
367 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
368 break;
369 }
370 }
371
alshabib6b5cfec2014-09-18 17:42:18 -0700372 private TrafficSelector buildSelector() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800373 MacAddress mac;
374 Ip4Prefix ip4Prefix;
375 Ip6Address ip6Address;
376 Ip6Prefix ip6Prefix;
377
tom9a693fd2014-10-03 11:32:19 -0700378 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700379 for (MatchField<?> field : match.getMatchFields()) {
380 switch (field.id) {
381 case IN_PORT:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800382 builder.matchInPort(PortNumber
alshabib010c31d2014-09-26 10:01:12 -0700383 .portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700384 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800385 case IN_PHY_PORT:
386 builder.matchInPhyPort(PortNumber
387 .portNumber(match.get(MatchField.IN_PHY_PORT).getPortNumber()));
388 break;
389 case METADATA:
390 long metadata =
391 match.get(MatchField.METADATA).getValue().getValue();
392 builder.matchMetadata(metadata);
393 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700394 case ETH_DST:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800395 mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
396 builder.matchEthDst(mac);
397 break;
398 case ETH_SRC:
399 mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
400 builder.matchEthSrc(mac);
alshabib6b5cfec2014-09-18 17:42:18 -0700401 break;
402 case ETH_TYPE:
403 int ethType = match.get(MatchField.ETH_TYPE).getValue();
alshabib010c31d2014-09-26 10:01:12 -0700404 builder.matchEthType((short) ethType);
alshabib6b5cfec2014-09-18 17:42:18 -0700405 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700406 case VLAN_VID:
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800407 VlanId vlanId = null;
408 if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
409 Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
410 if (masked.getValue().equals(OFVlanVidMatch.PRESENT)
411 && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
412 vlanId = VlanId.ANY;
413 }
414 } else {
415 vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
416 }
417 if (vlanId != null) {
418 builder.matchVlanId(vlanId);
419 }
alshabib6b5cfec2014-09-18 17:42:18 -0700420 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800421 case VLAN_PCP:
422 byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
423 builder.matchVlanPcp(vlanPcp);
424 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800425 case IP_DSCP:
426 byte ipDscp = match.get(MatchField.IP_DSCP).getDscpValue();
427 builder.matchIPDscp(ipDscp);
428 break;
429 case IP_ECN:
430 byte ipEcn = match.get(MatchField.IP_ECN).getEcnValue();
431 builder.matchIPEcn(ipEcn);
432 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800433 case IP_PROTO:
434 short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
435 builder.matchIPProtocol((byte) proto);
436 break;
437 case IPV4_SRC:
438 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
439 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800440 ip4Prefix = Ip4Prefix.valueOf(
441 maskedIp.getValue().getInt(),
442 maskedIp.getMask().asCidrMaskLength());
443 } else {
444 ip4Prefix = Ip4Prefix.valueOf(
445 match.get(MatchField.IPV4_SRC).getInt(),
446 Ip4Prefix.MAX_MASK_LENGTH);
447 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800448 builder.matchIPSrc(ip4Prefix);
449 break;
450 case IPV4_DST:
451 if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
452 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800453 ip4Prefix = Ip4Prefix.valueOf(
454 maskedIp.getValue().getInt(),
455 maskedIp.getMask().asCidrMaskLength());
456 } else {
457 ip4Prefix = Ip4Prefix.valueOf(
458 match.get(MatchField.IPV4_DST).getInt(),
459 Ip4Prefix.MAX_MASK_LENGTH);
460 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800461 builder.matchIPDst(ip4Prefix);
Jonathan Hart34bc6142014-10-17 11:00:43 -0700462 break;
463 case TCP_SRC:
464 builder.matchTcpSrc((short) match.get(MatchField.TCP_SRC).getPort());
465 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800466 case TCP_DST:
467 builder.matchTcpDst((short) match.get(MatchField.TCP_DST).getPort());
468 break;
469 case UDP_SRC:
470 builder.matchUdpSrc((short) match.get(MatchField.UDP_SRC).getPort());
471 break;
472 case UDP_DST:
473 builder.matchUdpDst((short) match.get(MatchField.UDP_DST).getPort());
474 break;
475 case SCTP_SRC:
476 builder.matchSctpSrc((short) match.get(MatchField.SCTP_SRC).getPort());
477 break;
478 case SCTP_DST:
479 builder.matchSctpDst((short) match.get(MatchField.SCTP_DST).getPort());
480 break;
481 case ICMPV4_TYPE:
482 byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
483 builder.matchIcmpType(icmpType);
484 break;
485 case ICMPV4_CODE:
486 byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode();
487 builder.matchIcmpCode(icmpCode);
488 break;
489 case IPV6_SRC:
490 if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
491 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
492 ip6Prefix = Ip6Prefix.valueOf(
493 maskedIp.getValue().getBytes(),
494 maskedIp.getMask().asCidrMaskLength());
495 } else {
496 ip6Prefix = Ip6Prefix.valueOf(
497 match.get(MatchField.IPV6_SRC).getBytes(),
498 Ip6Prefix.MAX_MASK_LENGTH);
499 }
500 builder.matchIPv6Src(ip6Prefix);
501 break;
502 case IPV6_DST:
503 if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
504 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
505 ip6Prefix = Ip6Prefix.valueOf(
506 maskedIp.getValue().getBytes(),
507 maskedIp.getMask().asCidrMaskLength());
508 } else {
509 ip6Prefix = Ip6Prefix.valueOf(
510 match.get(MatchField.IPV6_DST).getBytes(),
511 Ip6Prefix.MAX_MASK_LENGTH);
512 }
513 builder.matchIPv6Dst(ip6Prefix);
514 break;
515 case IPV6_FLABEL:
516 int flowLabel =
517 match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue();
518 builder.matchIPv6FlowLabel(flowLabel);
519 break;
520 case ICMPV6_TYPE:
521 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
522 builder.matchIcmpv6Type(icmpv6type);
523 break;
524 case ICMPV6_CODE:
525 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
526 builder.matchIcmpv6Code(icmpv6code);
527 break;
528 case IPV6_ND_TARGET:
529 ip6Address =
530 Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes());
531 builder.matchIPv6NDTargetAddress(ip6Address);
532 break;
533 case IPV6_ND_SLL:
534 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong());
535 builder.matchIPv6NDSourceLinkLayerAddress(mac);
536 break;
537 case IPV6_ND_TLL:
538 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong());
539 builder.matchIPv6NDTargetLinkLayerAddress(mac);
540 break;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800541 case MPLS_LABEL:
542 builder.matchMplsLabel((int) match.get(MatchField.MPLS_LABEL)
543 .getValue());
544 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800545 case IPV6_EXTHDR:
546 builder.matchIPv6ExthdrFlags((int) match.get(MatchField.IPV6_EXTHDR)
547 .getValue());
548 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700549 case OCH_SIGID:
550 builder.matchLambda(match.get(MatchField.OCH_SIGID).getChannelNumber());
551 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800552 case OCH_SIGTYPE:
553 builder.matchOpticalSignalType(match.get(MatchField
554 .OCH_SIGTYPE).getValue());
555 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700556 case ARP_OP:
557 case ARP_SHA:
558 case ARP_SPA:
559 case ARP_THA:
560 case ARP_TPA:
alshabib6b5cfec2014-09-18 17:42:18 -0700561 case MPLS_TC:
alshabib6b5cfec2014-09-18 17:42:18 -0700562 case TUNNEL_ID:
alshabib6b5cfec2014-09-18 17:42:18 -0700563 default:
564 log.warn("Match type {} not yet implemented.", field.id);
alshabib6b5cfec2014-09-18 17:42:18 -0700565 }
566 }
567 return builder.build();
568 }
alshabib6b5cfec2014-09-18 17:42:18 -0700569}