blob: 04ff8979d312011691e421ff464585e6568193c4 [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;
alshabib6b5cfec2014-09-18 17:42:18 -070038import org.projectfloodlight.openflow.protocol.OFFlowRemoved;
39import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry;
alshabib19fdc122014-10-03 11:38:19 -070040import org.projectfloodlight.openflow.protocol.OFInstructionType;
alshabib6b5cfec2014-09-18 17:42:18 -070041import org.projectfloodlight.openflow.protocol.action.OFAction;
Marc De Leenheer49087752014-10-23 13:54:09 -070042import org.projectfloodlight.openflow.protocol.action.OFActionCircuit;
43import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter;
sangho8995ac52015-02-04 11:29:03 -080044import org.projectfloodlight.openflow.protocol.action.OFActionGroup;
alshabib6b5cfec2014-09-18 17:42:18 -070045import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
sangho3f97a17d2015-01-29 22:56:29 -080046import org.projectfloodlight.openflow.protocol.action.OFActionPopMpls;
alshabib6b5cfec2014-09-18 17:42:18 -070047import org.projectfloodlight.openflow.protocol.action.OFActionSetDlDst;
48import org.projectfloodlight.openflow.protocol.action.OFActionSetDlSrc;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080049import org.projectfloodlight.openflow.protocol.action.OFActionSetField;
alshabib6b5cfec2014-09-18 17:42:18 -070050import org.projectfloodlight.openflow.protocol.action.OFActionSetNwDst;
51import org.projectfloodlight.openflow.protocol.action.OFActionSetNwSrc;
52import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanPcp;
53import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanVid;
alshabib19fdc122014-10-03 11:38:19 -070054import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
Jonathan Hartcf783202014-11-24 18:55:42 -080055import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions;
alshabib6b5cfec2014-09-18 17:42:18 -070056import org.projectfloodlight.openflow.protocol.match.Match;
57import org.projectfloodlight.openflow.protocol.match.MatchField;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080058import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
Marc De Leenheer49087752014-10-23 13:54:09 -070059import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigidBasic;
alshabib6b5cfec2014-09-18 17:42:18 -070060import org.projectfloodlight.openflow.types.IPv4Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080061import org.projectfloodlight.openflow.types.IPv6Address;
Jonathan Hart0e12fad2014-10-17 14:54:58 -070062import org.projectfloodlight.openflow.types.Masked;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080063import org.projectfloodlight.openflow.types.OFVlanVidMatch;
sangho3f97a17d2015-01-29 22:56:29 -080064import org.projectfloodlight.openflow.types.U32;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080065import org.projectfloodlight.openflow.types.VlanPcp;
alshabib6b5cfec2014-09-18 17:42:18 -070066import org.slf4j.Logger;
67
Jonathan Hart6cd2f352015-01-13 17:44:45 -080068import java.util.List;
69
70import static org.slf4j.LoggerFactory.getLogger;
alshabib19fdc122014-10-03 11:38:19 -070071
alshabib1c319ff2014-10-04 20:29:09 -070072public class FlowEntryBuilder {
alshabib6b5cfec2014-09-18 17:42:18 -070073 private final Logger log = getLogger(getClass());
74
75 private final OFFlowStatsEntry stat;
76 private final OFFlowRemoved removed;
77
78 private final Match match;
79 private final List<OFAction> actions;
80
81 private final Dpid dpid;
82
alshabib19fdc122014-10-03 11:38:19 -070083 private final boolean addedRule;
alshabib6b5cfec2014-09-18 17:42:18 -070084
85
alshabib1c319ff2014-10-04 20:29:09 -070086 public FlowEntryBuilder(Dpid dpid, OFFlowStatsEntry entry) {
alshabib6b5cfec2014-09-18 17:42:18 -070087 this.stat = entry;
88 this.match = entry.getMatch();
alshabib19fdc122014-10-03 11:38:19 -070089 this.actions = getActions(entry);
alshabib6b5cfec2014-09-18 17:42:18 -070090 this.dpid = dpid;
alshabib219ebaa2014-09-22 15:41:24 -070091 this.removed = null;
alshabib19fdc122014-10-03 11:38:19 -070092 this.addedRule = true;
alshabib6b5cfec2014-09-18 17:42:18 -070093 }
94
alshabib1c319ff2014-10-04 20:29:09 -070095 public FlowEntryBuilder(Dpid dpid, OFFlowRemoved removed) {
alshabib6b5cfec2014-09-18 17:42:18 -070096 this.match = removed.getMatch();
97 this.removed = removed;
98
99 this.dpid = dpid;
100 this.actions = null;
101 this.stat = null;
alshabib19fdc122014-10-03 11:38:19 -0700102 this.addedRule = false;
alshabib6b5cfec2014-09-18 17:42:18 -0700103
104 }
105
alshabib1c319ff2014-10-04 20:29:09 -0700106 public FlowEntry build() {
alshabib19fdc122014-10-03 11:38:19 -0700107 if (addedRule) {
alshabib1c319ff2014-10-04 20:29:09 -0700108 FlowRule rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)),
alshabib6b5cfec2014-09-18 17:42:18 -0700109 buildSelector(), buildTreatment(), stat.getPriority(),
Jonathan Hartbc4a7932014-10-21 11:46:00 -0700110 stat.getCookie().getValue(), stat.getIdleTimeout(), false);
alshabib1c319ff2014-10-04 20:29:09 -0700111 return new DefaultFlowEntry(rule, FlowEntryState.ADDED,
112 stat.getDurationSec(), stat.getPacketCount().getValue(),
113 stat.getByteCount().getValue());
114
alshabib6b5cfec2014-09-18 17:42:18 -0700115 } else {
alshabib1c319ff2014-10-04 20:29:09 -0700116 FlowRule rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)),
alshabib6b5cfec2014-09-18 17:42:18 -0700117 buildSelector(), null, removed.getPriority(),
Jonathan Hartbc4a7932014-10-21 11:46:00 -0700118 removed.getCookie().getValue(), removed.getIdleTimeout(), false);
alshabib1c319ff2014-10-04 20:29:09 -0700119 return new DefaultFlowEntry(rule, FlowEntryState.REMOVED, removed.getDurationSec(),
120 removed.getPacketCount().getValue(), removed.getByteCount().getValue());
alshabib6b5cfec2014-09-18 17:42:18 -0700121 }
122 }
123
alshabib19fdc122014-10-03 11:38:19 -0700124 private List<OFAction> getActions(OFFlowStatsEntry entry) {
125 switch (entry.getVersion()) {
126 case OF_10:
127 return entry.getActions();
128 case OF_11:
129 case OF_12:
130 case OF_13:
131 List<OFInstruction> ins = entry.getInstructions();
132 for (OFInstruction in : ins) {
Jonathan Hartcf783202014-11-24 18:55:42 -0800133 if (in.getType().equals(OFInstructionType.APPLY_ACTIONS)) {
134 OFInstructionApplyActions apply = (OFInstructionApplyActions) in;
alshabib19fdc122014-10-03 11:38:19 -0700135 return apply.getActions();
136 }
137 }
138 return Lists.newLinkedList();
139 default:
140 log.warn("Unknown OF version {}", entry.getVersion());
141 }
142 return Lists.newLinkedList();
143 }
alshabib6b5cfec2014-09-18 17:42:18 -0700144
145 private TrafficTreatment buildTreatment() {
tom9a693fd2014-10-03 11:32:19 -0700146 TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700147 // If this is a drop rule
148 if (actions.size() == 0) {
alshabib010c31d2014-09-26 10:01:12 -0700149 builder.drop();
alshabib6b5cfec2014-09-18 17:42:18 -0700150 return builder.build();
151 }
152 for (OFAction act : actions) {
153 switch (act.getType()) {
154 case OUTPUT:
155 OFActionOutput out = (OFActionOutput) act;
alshabib010c31d2014-09-26 10:01:12 -0700156 builder.setOutput(
157 PortNumber.portNumber(out.getPort().getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700158 break;
159 case SET_VLAN_VID:
alshabib010c31d2014-09-26 10:01:12 -0700160 OFActionSetVlanVid vlan = (OFActionSetVlanVid) act;
161 builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan()));
162 break;
163 case SET_VLAN_PCP:
alshabib6b5cfec2014-09-18 17:42:18 -0700164 OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800165 builder.setVlanPcp(pcp.getVlanPcp().getValue());
alshabib6b5cfec2014-09-18 17:42:18 -0700166 break;
167 case SET_DL_DST:
168 OFActionSetDlDst dldst = (OFActionSetDlDst) act;
alshabib010c31d2014-09-26 10:01:12 -0700169 builder.setEthDst(
170 MacAddress.valueOf(dldst.getDlAddr().getLong()));
alshabib6b5cfec2014-09-18 17:42:18 -0700171 break;
172 case SET_DL_SRC:
173 OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act;
alshabib010c31d2014-09-26 10:01:12 -0700174 builder.setEthSrc(
175 MacAddress.valueOf(dlsrc.getDlAddr().getLong()));
alshabib6b5cfec2014-09-18 17:42:18 -0700176
177 break;
178 case SET_NW_DST:
179 OFActionSetNwDst nwdst = (OFActionSetNwDst) act;
180 IPv4Address di = nwdst.getNwAddr();
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800181 builder.setIpDst(Ip4Address.valueOf(di.getInt()));
alshabib6b5cfec2014-09-18 17:42:18 -0700182 break;
183 case SET_NW_SRC:
184 OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act;
185 IPv4Address si = nwsrc.getNwAddr();
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800186 builder.setIpSrc(Ip4Address.valueOf(si.getInt()));
alshabib6b5cfec2014-09-18 17:42:18 -0700187 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700188 case EXPERIMENTER:
189 OFActionExperimenter exp = (OFActionExperimenter) act;
Praseed Balakrishnandb8a9d22014-12-03 11:47:55 -0800190 if (exp.getExperimenter() == 0x80005A06 ||
191 exp.getExperimenter() == 0x748771) {
Marc De Leenheer49087752014-10-23 13:54:09 -0700192 OFActionCircuit ct = (OFActionCircuit) exp;
193 builder.setLambda(((OFOxmOchSigidBasic) ct.getField()).getValue().getChannelNumber());
194 } else {
195 log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter());
196 }
197 break;
Jonathan Hart1f8e0d72014-11-25 11:13:00 -0800198 case SET_FIELD:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800199 OFActionSetField setField = (OFActionSetField) act;
200 handleSetField(builder, setField.getField());
Jonathan Hart1f8e0d72014-11-25 11:13:00 -0800201 break;
sangho3f97a17d2015-01-29 22:56:29 -0800202 case POP_MPLS:
203 OFActionPopMpls popMpls = (OFActionPopMpls) act;
204 builder.popMpls((short) popMpls.getEthertype().getValue());
205 break;
206 case PUSH_MPLS:
sangho3f97a17d2015-01-29 22:56:29 -0800207 builder.pushMpls();
208 break;
209 case COPY_TTL_IN:
sangho3f97a17d2015-01-29 22:56:29 -0800210 builder.copyTtlIn();
211 break;
212 case COPY_TTL_OUT:
sangho3f97a17d2015-01-29 22:56:29 -0800213 builder.copyTtlOut();
214 break;
215 case DEC_MPLS_TTL:
sangho3f97a17d2015-01-29 22:56:29 -0800216 builder.decMplsTtl();
217 break;
218 case DEC_NW_TTL:
sangho3f97a17d2015-01-29 22:56:29 -0800219 builder.decNwTtl();
220 break;
sangho8995ac52015-02-04 11:29:03 -0800221 case GROUP:
222 OFActionGroup group = (OFActionGroup) act;
223 builder.group(new DefaultGroupId(group.getGroup().getGroupNumber()));
224 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700225 case SET_TP_DST:
226 case SET_TP_SRC:
alshabib6b5cfec2014-09-18 17:42:18 -0700227 case POP_PBB:
228 case POP_VLAN:
alshabib6b5cfec2014-09-18 17:42:18 -0700229 case PUSH_PBB:
230 case PUSH_VLAN:
alshabib6b5cfec2014-09-18 17:42:18 -0700231 case SET_MPLS_LABEL:
232 case SET_MPLS_TC:
233 case SET_MPLS_TTL:
234 case SET_NW_ECN:
235 case SET_NW_TOS:
236 case SET_NW_TTL:
237 case SET_QUEUE:
238 case STRIP_VLAN:
alshabib6b5cfec2014-09-18 17:42:18 -0700239 case ENQUEUE:
alshabib6b5cfec2014-09-18 17:42:18 -0700240 default:
241 log.warn("Action type {} not yet implemented.", act.getType());
242 }
243 }
244
245 return builder.build();
246 }
247
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800248 private void handleSetField(TrafficTreatment.Builder builder, OFOxm<?> oxm) {
249 switch (oxm.getMatchField().id) {
250 case VLAN_PCP:
251 @SuppressWarnings("unchecked")
252 OFOxm<VlanPcp> vlanpcp = (OFOxm<VlanPcp>) oxm;
253 builder.setVlanPcp(vlanpcp.getValue().getValue());
254 break;
255 case VLAN_VID:
256 @SuppressWarnings("unchecked")
257 OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm;
258 builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan()));
259 break;
260 case ETH_DST:
261 @SuppressWarnings("unchecked")
262 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethdst =
263 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
264 builder.setEthDst(MacAddress.valueOf(ethdst.getValue().getLong()));
265 break;
266 case ETH_SRC:
267 @SuppressWarnings("unchecked")
268 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethsrc =
269 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
270 builder.setEthSrc(MacAddress.valueOf(ethsrc.getValue().getLong()));
271 break;
272 case IPV4_DST:
273 @SuppressWarnings("unchecked")
274 OFOxm<IPv4Address> ip4dst = (OFOxm<IPv4Address>) oxm;
275 builder.setIpDst(Ip4Address.valueOf(ip4dst.getValue().getInt()));
276 break;
277 case IPV4_SRC:
278 @SuppressWarnings("unchecked")
279 OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm;
280 builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt()));
281 break;
sangho3f97a17d2015-01-29 22:56:29 -0800282 case MPLS_LABEL:
283 @SuppressWarnings("unchecked")
284 OFOxm<U32> labelId = (OFOxm<U32>) oxm;
285 builder.setMpls((int) labelId.getValue().getValue());
286 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800287 case ARP_OP:
288 case ARP_SHA:
289 case ARP_SPA:
290 case ARP_THA:
291 case ARP_TPA:
292 case BSN_EGR_PORT_GROUP_ID:
293 case BSN_GLOBAL_VRF_ALLOWED:
294 case BSN_IN_PORTS_128:
295 case BSN_L3_DST_CLASS_ID:
296 case BSN_L3_INTERFACE_CLASS_ID:
297 case BSN_L3_SRC_CLASS_ID:
298 case BSN_LAG_ID:
299 case BSN_TCP_FLAGS:
300 case BSN_UDF0:
301 case BSN_UDF1:
302 case BSN_UDF2:
303 case BSN_UDF3:
304 case BSN_UDF4:
305 case BSN_UDF5:
306 case BSN_UDF6:
307 case BSN_UDF7:
308 case BSN_VLAN_XLATE_PORT_GROUP_ID:
309 case BSN_VRF:
310 case ETH_TYPE:
311 case ICMPV4_CODE:
312 case ICMPV4_TYPE:
313 case ICMPV6_CODE:
314 case ICMPV6_TYPE:
315 case IN_PHY_PORT:
316 case IN_PORT:
317 case IPV6_DST:
318 case IPV6_FLABEL:
319 case IPV6_ND_SLL:
320 case IPV6_ND_TARGET:
321 case IPV6_ND_TLL:
322 case IPV6_SRC:
323 case IP_DSCP:
324 case IP_ECN:
325 case IP_PROTO:
326 case METADATA:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800327 case MPLS_TC:
328 case OCH_SIGID:
329 case OCH_SIGID_BASIC:
330 case OCH_SIGTYPE:
331 case OCH_SIGTYPE_BASIC:
332 case SCTP_DST:
333 case SCTP_SRC:
334 case TCP_DST:
335 case TCP_SRC:
336 case TUNNEL_ID:
337 case UDP_DST:
338 case UDP_SRC:
339 default:
340 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
341 break;
342 }
343 }
344
alshabib6b5cfec2014-09-18 17:42:18 -0700345 private TrafficSelector buildSelector() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800346 MacAddress mac;
347 Ip4Prefix ip4Prefix;
348 Ip6Address ip6Address;
349 Ip6Prefix ip6Prefix;
350
tom9a693fd2014-10-03 11:32:19 -0700351 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700352 for (MatchField<?> field : match.getMatchFields()) {
353 switch (field.id) {
354 case IN_PORT:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800355 builder.matchInPort(PortNumber
alshabib010c31d2014-09-26 10:01:12 -0700356 .portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700357 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800358 case IN_PHY_PORT:
359 builder.matchInPhyPort(PortNumber
360 .portNumber(match.get(MatchField.IN_PHY_PORT).getPortNumber()));
361 break;
362 case METADATA:
363 long metadata =
364 match.get(MatchField.METADATA).getValue().getValue();
365 builder.matchMetadata(metadata);
366 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700367 case ETH_DST:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800368 mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
369 builder.matchEthDst(mac);
370 break;
371 case ETH_SRC:
372 mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
373 builder.matchEthSrc(mac);
alshabib6b5cfec2014-09-18 17:42:18 -0700374 break;
375 case ETH_TYPE:
376 int ethType = match.get(MatchField.ETH_TYPE).getValue();
alshabib010c31d2014-09-26 10:01:12 -0700377 builder.matchEthType((short) ethType);
alshabib6b5cfec2014-09-18 17:42:18 -0700378 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700379 case VLAN_VID:
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800380 VlanId vlanId = null;
381 if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
382 Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
383 if (masked.getValue().equals(OFVlanVidMatch.PRESENT)
384 && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
385 vlanId = VlanId.ANY;
386 }
387 } else {
388 vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
389 }
390 if (vlanId != null) {
391 builder.matchVlanId(vlanId);
392 }
alshabib6b5cfec2014-09-18 17:42:18 -0700393 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800394 case VLAN_PCP:
395 byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
396 builder.matchVlanPcp(vlanPcp);
397 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800398 case IP_DSCP:
399 byte ipDscp = match.get(MatchField.IP_DSCP).getDscpValue();
400 builder.matchIPDscp(ipDscp);
401 break;
402 case IP_ECN:
403 byte ipEcn = match.get(MatchField.IP_ECN).getEcnValue();
404 builder.matchIPEcn(ipEcn);
405 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800406 case IP_PROTO:
407 short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
408 builder.matchIPProtocol((byte) proto);
409 break;
410 case IPV4_SRC:
411 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
412 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800413 ip4Prefix = Ip4Prefix.valueOf(
414 maskedIp.getValue().getInt(),
415 maskedIp.getMask().asCidrMaskLength());
416 } else {
417 ip4Prefix = Ip4Prefix.valueOf(
418 match.get(MatchField.IPV4_SRC).getInt(),
419 Ip4Prefix.MAX_MASK_LENGTH);
420 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800421 builder.matchIPSrc(ip4Prefix);
422 break;
423 case IPV4_DST:
424 if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
425 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800426 ip4Prefix = Ip4Prefix.valueOf(
427 maskedIp.getValue().getInt(),
428 maskedIp.getMask().asCidrMaskLength());
429 } else {
430 ip4Prefix = Ip4Prefix.valueOf(
431 match.get(MatchField.IPV4_DST).getInt(),
432 Ip4Prefix.MAX_MASK_LENGTH);
433 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800434 builder.matchIPDst(ip4Prefix);
Jonathan Hart34bc6142014-10-17 11:00:43 -0700435 break;
436 case TCP_SRC:
437 builder.matchTcpSrc((short) match.get(MatchField.TCP_SRC).getPort());
438 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800439 case TCP_DST:
440 builder.matchTcpDst((short) match.get(MatchField.TCP_DST).getPort());
441 break;
442 case UDP_SRC:
443 builder.matchUdpSrc((short) match.get(MatchField.UDP_SRC).getPort());
444 break;
445 case UDP_DST:
446 builder.matchUdpDst((short) match.get(MatchField.UDP_DST).getPort());
447 break;
448 case SCTP_SRC:
449 builder.matchSctpSrc((short) match.get(MatchField.SCTP_SRC).getPort());
450 break;
451 case SCTP_DST:
452 builder.matchSctpDst((short) match.get(MatchField.SCTP_DST).getPort());
453 break;
454 case ICMPV4_TYPE:
455 byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
456 builder.matchIcmpType(icmpType);
457 break;
458 case ICMPV4_CODE:
459 byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode();
460 builder.matchIcmpCode(icmpCode);
461 break;
462 case IPV6_SRC:
463 if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
464 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
465 ip6Prefix = Ip6Prefix.valueOf(
466 maskedIp.getValue().getBytes(),
467 maskedIp.getMask().asCidrMaskLength());
468 } else {
469 ip6Prefix = Ip6Prefix.valueOf(
470 match.get(MatchField.IPV6_SRC).getBytes(),
471 Ip6Prefix.MAX_MASK_LENGTH);
472 }
473 builder.matchIPv6Src(ip6Prefix);
474 break;
475 case IPV6_DST:
476 if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
477 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
478 ip6Prefix = Ip6Prefix.valueOf(
479 maskedIp.getValue().getBytes(),
480 maskedIp.getMask().asCidrMaskLength());
481 } else {
482 ip6Prefix = Ip6Prefix.valueOf(
483 match.get(MatchField.IPV6_DST).getBytes(),
484 Ip6Prefix.MAX_MASK_LENGTH);
485 }
486 builder.matchIPv6Dst(ip6Prefix);
487 break;
488 case IPV6_FLABEL:
489 int flowLabel =
490 match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue();
491 builder.matchIPv6FlowLabel(flowLabel);
492 break;
493 case ICMPV6_TYPE:
494 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
495 builder.matchIcmpv6Type(icmpv6type);
496 break;
497 case ICMPV6_CODE:
498 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
499 builder.matchIcmpv6Code(icmpv6code);
500 break;
501 case IPV6_ND_TARGET:
502 ip6Address =
503 Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes());
504 builder.matchIPv6NDTargetAddress(ip6Address);
505 break;
506 case IPV6_ND_SLL:
507 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong());
508 builder.matchIPv6NDSourceLinkLayerAddress(mac);
509 break;
510 case IPV6_ND_TLL:
511 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong());
512 builder.matchIPv6NDTargetLinkLayerAddress(mac);
513 break;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800514 case MPLS_LABEL:
515 builder.matchMplsLabel((int) match.get(MatchField.MPLS_LABEL)
516 .getValue());
517 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800518 case IPV6_EXTHDR:
519 builder.matchIPv6ExthdrFlags((int) match.get(MatchField.IPV6_EXTHDR)
520 .getValue());
521 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700522 case OCH_SIGID:
523 builder.matchLambda(match.get(MatchField.OCH_SIGID).getChannelNumber());
524 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800525 case OCH_SIGTYPE:
526 builder.matchOpticalSignalType(match.get(MatchField
527 .OCH_SIGTYPE).getValue());
528 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700529 case ARP_OP:
530 case ARP_SHA:
531 case ARP_SPA:
532 case ARP_THA:
533 case ARP_TPA:
alshabib6b5cfec2014-09-18 17:42:18 -0700534 case MPLS_TC:
alshabib6b5cfec2014-09-18 17:42:18 -0700535 case TUNNEL_ID:
alshabib6b5cfec2014-09-18 17:42:18 -0700536 default:
537 log.warn("Match type {} not yet implemented.", field.id);
alshabib6b5cfec2014-09-18 17:42:18 -0700538 }
539 }
540 return builder.build();
541 }
alshabib6b5cfec2014-09-18 17:42:18 -0700542}