blob: 5c445a894ec3406293338502b6ee621325a28b1b [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;
alshabib6b5cfec2014-09-18 17:42:18 -0700358 case ETH_DST:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800359 mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
360 builder.matchEthDst(mac);
361 break;
362 case ETH_SRC:
363 mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
364 builder.matchEthSrc(mac);
alshabib6b5cfec2014-09-18 17:42:18 -0700365 break;
366 case ETH_TYPE:
367 int ethType = match.get(MatchField.ETH_TYPE).getValue();
alshabib010c31d2014-09-26 10:01:12 -0700368 builder.matchEthType((short) ethType);
alshabib6b5cfec2014-09-18 17:42:18 -0700369 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700370 case VLAN_VID:
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800371 VlanId vlanId = null;
372 if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
373 Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
374 if (masked.getValue().equals(OFVlanVidMatch.PRESENT)
375 && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
376 vlanId = VlanId.ANY;
377 }
378 } else {
379 vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
380 }
381 if (vlanId != null) {
382 builder.matchVlanId(vlanId);
383 }
alshabib6b5cfec2014-09-18 17:42:18 -0700384 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800385 case VLAN_PCP:
386 byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
387 builder.matchVlanPcp(vlanPcp);
388 break;
389 case IP_PROTO:
390 short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
391 builder.matchIPProtocol((byte) proto);
392 break;
393 case IPV4_SRC:
394 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
395 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
396
397 ip4Prefix = Ip4Prefix.valueOf(
398 maskedIp.getValue().getInt(),
399 maskedIp.getMask().asCidrMaskLength());
400 } else {
401 ip4Prefix = Ip4Prefix.valueOf(
402 match.get(MatchField.IPV4_SRC).getInt(),
403 Ip4Prefix.MAX_MASK_LENGTH);
404 }
405
406 builder.matchIPSrc(ip4Prefix);
407 break;
408 case IPV4_DST:
409 if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
410 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
411
412 ip4Prefix = Ip4Prefix.valueOf(
413 maskedIp.getValue().getInt(),
414 maskedIp.getMask().asCidrMaskLength());
415 } else {
416 ip4Prefix = Ip4Prefix.valueOf(
417 match.get(MatchField.IPV4_DST).getInt(),
418 Ip4Prefix.MAX_MASK_LENGTH);
419 }
420
421 builder.matchIPDst(ip4Prefix);
Jonathan Hart34bc6142014-10-17 11:00:43 -0700422 break;
423 case TCP_SRC:
424 builder.matchTcpSrc((short) match.get(MatchField.TCP_SRC).getPort());
425 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800426 case TCP_DST:
427 builder.matchTcpDst((short) match.get(MatchField.TCP_DST).getPort());
428 break;
429 case UDP_SRC:
430 builder.matchUdpSrc((short) match.get(MatchField.UDP_SRC).getPort());
431 break;
432 case UDP_DST:
433 builder.matchUdpDst((short) match.get(MatchField.UDP_DST).getPort());
434 break;
435 case SCTP_SRC:
436 builder.matchSctpSrc((short) match.get(MatchField.SCTP_SRC).getPort());
437 break;
438 case SCTP_DST:
439 builder.matchSctpDst((short) match.get(MatchField.SCTP_DST).getPort());
440 break;
441 case ICMPV4_TYPE:
442 byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
443 builder.matchIcmpType(icmpType);
444 break;
445 case ICMPV4_CODE:
446 byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode();
447 builder.matchIcmpCode(icmpCode);
448 break;
449 case IPV6_SRC:
450 if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
451 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
452 ip6Prefix = Ip6Prefix.valueOf(
453 maskedIp.getValue().getBytes(),
454 maskedIp.getMask().asCidrMaskLength());
455 } else {
456 ip6Prefix = Ip6Prefix.valueOf(
457 match.get(MatchField.IPV6_SRC).getBytes(),
458 Ip6Prefix.MAX_MASK_LENGTH);
459 }
460 builder.matchIPv6Src(ip6Prefix);
461 break;
462 case IPV6_DST:
463 if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
464 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
465 ip6Prefix = Ip6Prefix.valueOf(
466 maskedIp.getValue().getBytes(),
467 maskedIp.getMask().asCidrMaskLength());
468 } else {
469 ip6Prefix = Ip6Prefix.valueOf(
470 match.get(MatchField.IPV6_DST).getBytes(),
471 Ip6Prefix.MAX_MASK_LENGTH);
472 }
473 builder.matchIPv6Dst(ip6Prefix);
474 break;
475 case IPV6_FLABEL:
476 int flowLabel =
477 match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue();
478 builder.matchIPv6FlowLabel(flowLabel);
479 break;
480 case ICMPV6_TYPE:
481 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
482 builder.matchIcmpv6Type(icmpv6type);
483 break;
484 case ICMPV6_CODE:
485 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
486 builder.matchIcmpv6Code(icmpv6code);
487 break;
488 case IPV6_ND_TARGET:
489 ip6Address =
490 Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes());
491 builder.matchIPv6NDTargetAddress(ip6Address);
492 break;
493 case IPV6_ND_SLL:
494 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong());
495 builder.matchIPv6NDSourceLinkLayerAddress(mac);
496 break;
497 case IPV6_ND_TLL:
498 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong());
499 builder.matchIPv6NDTargetLinkLayerAddress(mac);
500 break;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800501 case MPLS_LABEL:
502 builder.matchMplsLabel((int) match.get(MatchField.MPLS_LABEL)
503 .getValue());
504 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700505 case OCH_SIGID:
506 builder.matchLambda(match.get(MatchField.OCH_SIGID).getChannelNumber());
507 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800508 case OCH_SIGTYPE:
509 builder.matchOpticalSignalType(match.get(MatchField
510 .OCH_SIGTYPE).getValue());
511 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700512 case ARP_OP:
513 case ARP_SHA:
514 case ARP_SPA:
515 case ARP_THA:
516 case ARP_TPA:
alshabib6b5cfec2014-09-18 17:42:18 -0700517 case IN_PHY_PORT:
alshabib6b5cfec2014-09-18 17:42:18 -0700518 case IP_DSCP:
519 case IP_ECN:
520 case METADATA:
alshabib6b5cfec2014-09-18 17:42:18 -0700521 case MPLS_TC:
alshabib6b5cfec2014-09-18 17:42:18 -0700522 case TUNNEL_ID:
alshabib6b5cfec2014-09-18 17:42:18 -0700523 default:
524 log.warn("Match type {} not yet implemented.", field.id);
alshabib6b5cfec2014-09-18 17:42:18 -0700525 }
526 }
527 return builder.build();
528 }
529
530}