blob: 3ea2efa0b050da4c3badb182180f5ded232dcf61 [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
18import static org.slf4j.LoggerFactory.getLogger;
19
20import java.util.List;
21
Jonathan Hartd0ef7522014-12-11 11:51:18 -080022import org.onlab.packet.Ip4Address;
23import org.onlab.packet.Ip4Prefix;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080024import org.onlab.packet.Ip6Prefix;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080025import org.onlab.packet.MacAddress;
26import org.onlab.packet.VlanId;
Brian O'Connorabafb502014-12-02 22:26:20 -080027import org.onosproject.net.DeviceId;
28import org.onosproject.net.PortNumber;
29import org.onosproject.net.flow.DefaultFlowEntry;
30import org.onosproject.net.flow.DefaultFlowRule;
31import org.onosproject.net.flow.DefaultTrafficSelector;
32import org.onosproject.net.flow.DefaultTrafficTreatment;
33import org.onosproject.net.flow.FlowEntry;
34import org.onosproject.net.flow.FlowEntry.FlowEntryState;
35import org.onosproject.net.flow.FlowRule;
36import org.onosproject.net.flow.TrafficSelector;
37import org.onosproject.net.flow.TrafficTreatment;
38import org.onosproject.openflow.controller.Dpid;
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;
alshabib6b5cfec2014-09-18 17:42:18 -070045import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
46import org.projectfloodlight.openflow.protocol.action.OFActionSetDlDst;
47import org.projectfloodlight.openflow.protocol.action.OFActionSetDlSrc;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080048import org.projectfloodlight.openflow.protocol.action.OFActionSetField;
alshabib6b5cfec2014-09-18 17:42:18 -070049import org.projectfloodlight.openflow.protocol.action.OFActionSetNwDst;
50import org.projectfloodlight.openflow.protocol.action.OFActionSetNwSrc;
51import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanPcp;
52import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanVid;
alshabib19fdc122014-10-03 11:38:19 -070053import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
Jonathan Hartcf783202014-11-24 18:55:42 -080054import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions;
alshabib6b5cfec2014-09-18 17:42:18 -070055import org.projectfloodlight.openflow.protocol.match.Match;
56import org.projectfloodlight.openflow.protocol.match.MatchField;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080057import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
Marc De Leenheer49087752014-10-23 13:54:09 -070058import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigidBasic;
alshabib6b5cfec2014-09-18 17:42:18 -070059import org.projectfloodlight.openflow.types.IPv4Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080060import org.projectfloodlight.openflow.types.IPv6Address;
Jonathan Hart0e12fad2014-10-17 14:54:58 -070061import org.projectfloodlight.openflow.types.Masked;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080062import org.projectfloodlight.openflow.types.OFVlanVidMatch;
63import org.projectfloodlight.openflow.types.VlanPcp;
alshabib6b5cfec2014-09-18 17:42:18 -070064import org.slf4j.Logger;
65
alshabib19fdc122014-10-03 11:38:19 -070066import com.google.common.collect.Lists;
67
alshabib1c319ff2014-10-04 20:29:09 -070068public class FlowEntryBuilder {
alshabib6b5cfec2014-09-18 17:42:18 -070069 private final Logger log = getLogger(getClass());
70
71 private final OFFlowStatsEntry stat;
72 private final OFFlowRemoved removed;
73
74 private final Match match;
75 private final List<OFAction> actions;
76
77 private final Dpid dpid;
78
alshabib19fdc122014-10-03 11:38:19 -070079 private final boolean addedRule;
alshabib6b5cfec2014-09-18 17:42:18 -070080
81
alshabib1c319ff2014-10-04 20:29:09 -070082 public FlowEntryBuilder(Dpid dpid, OFFlowStatsEntry entry) {
alshabib6b5cfec2014-09-18 17:42:18 -070083 this.stat = entry;
84 this.match = entry.getMatch();
alshabib19fdc122014-10-03 11:38:19 -070085 this.actions = getActions(entry);
alshabib6b5cfec2014-09-18 17:42:18 -070086 this.dpid = dpid;
alshabib219ebaa2014-09-22 15:41:24 -070087 this.removed = null;
alshabib19fdc122014-10-03 11:38:19 -070088 this.addedRule = true;
alshabib6b5cfec2014-09-18 17:42:18 -070089 }
90
alshabib1c319ff2014-10-04 20:29:09 -070091 public FlowEntryBuilder(Dpid dpid, OFFlowRemoved removed) {
alshabib6b5cfec2014-09-18 17:42:18 -070092 this.match = removed.getMatch();
93 this.removed = removed;
94
95 this.dpid = dpid;
96 this.actions = null;
97 this.stat = null;
alshabib19fdc122014-10-03 11:38:19 -070098 this.addedRule = false;
alshabib6b5cfec2014-09-18 17:42:18 -070099
100 }
101
alshabib1c319ff2014-10-04 20:29:09 -0700102 public FlowEntry build() {
alshabib19fdc122014-10-03 11:38:19 -0700103 if (addedRule) {
alshabib1c319ff2014-10-04 20:29:09 -0700104 FlowRule rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)),
alshabib6b5cfec2014-09-18 17:42:18 -0700105 buildSelector(), buildTreatment(), stat.getPriority(),
Jonathan Hartbc4a7932014-10-21 11:46:00 -0700106 stat.getCookie().getValue(), stat.getIdleTimeout(), false);
alshabib1c319ff2014-10-04 20:29:09 -0700107 return new DefaultFlowEntry(rule, FlowEntryState.ADDED,
108 stat.getDurationSec(), stat.getPacketCount().getValue(),
109 stat.getByteCount().getValue());
110
alshabib6b5cfec2014-09-18 17:42:18 -0700111 } else {
alshabib1c319ff2014-10-04 20:29:09 -0700112 FlowRule rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)),
alshabib6b5cfec2014-09-18 17:42:18 -0700113 buildSelector(), null, removed.getPriority(),
Jonathan Hartbc4a7932014-10-21 11:46:00 -0700114 removed.getCookie().getValue(), removed.getIdleTimeout(), false);
alshabib1c319ff2014-10-04 20:29:09 -0700115 return new DefaultFlowEntry(rule, FlowEntryState.REMOVED, removed.getDurationSec(),
116 removed.getPacketCount().getValue(), removed.getByteCount().getValue());
alshabib6b5cfec2014-09-18 17:42:18 -0700117 }
118 }
119
alshabib19fdc122014-10-03 11:38:19 -0700120 private List<OFAction> getActions(OFFlowStatsEntry entry) {
121 switch (entry.getVersion()) {
122 case OF_10:
123 return entry.getActions();
124 case OF_11:
125 case OF_12:
126 case OF_13:
127 List<OFInstruction> ins = entry.getInstructions();
128 for (OFInstruction in : ins) {
Jonathan Hartcf783202014-11-24 18:55:42 -0800129 if (in.getType().equals(OFInstructionType.APPLY_ACTIONS)) {
130 OFInstructionApplyActions apply = (OFInstructionApplyActions) in;
alshabib19fdc122014-10-03 11:38:19 -0700131 return apply.getActions();
132 }
133 }
134 return Lists.newLinkedList();
135 default:
136 log.warn("Unknown OF version {}", entry.getVersion());
137 }
138 return Lists.newLinkedList();
139 }
alshabib6b5cfec2014-09-18 17:42:18 -0700140
141 private TrafficTreatment buildTreatment() {
tom9a693fd2014-10-03 11:32:19 -0700142 TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700143 // If this is a drop rule
144 if (actions.size() == 0) {
alshabib010c31d2014-09-26 10:01:12 -0700145 builder.drop();
alshabib6b5cfec2014-09-18 17:42:18 -0700146 return builder.build();
147 }
148 for (OFAction act : actions) {
149 switch (act.getType()) {
150 case OUTPUT:
151 OFActionOutput out = (OFActionOutput) act;
alshabib010c31d2014-09-26 10:01:12 -0700152 builder.setOutput(
153 PortNumber.portNumber(out.getPort().getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700154 break;
155 case SET_VLAN_VID:
alshabib010c31d2014-09-26 10:01:12 -0700156 OFActionSetVlanVid vlan = (OFActionSetVlanVid) act;
157 builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan()));
158 break;
159 case SET_VLAN_PCP:
alshabib6b5cfec2014-09-18 17:42:18 -0700160 OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800161 builder.setVlanPcp(pcp.getVlanPcp().getValue());
alshabib6b5cfec2014-09-18 17:42:18 -0700162 break;
163 case SET_DL_DST:
164 OFActionSetDlDst dldst = (OFActionSetDlDst) act;
alshabib010c31d2014-09-26 10:01:12 -0700165 builder.setEthDst(
166 MacAddress.valueOf(dldst.getDlAddr().getLong()));
alshabib6b5cfec2014-09-18 17:42:18 -0700167 break;
168 case SET_DL_SRC:
169 OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act;
alshabib010c31d2014-09-26 10:01:12 -0700170 builder.setEthSrc(
171 MacAddress.valueOf(dlsrc.getDlAddr().getLong()));
alshabib6b5cfec2014-09-18 17:42:18 -0700172
173 break;
174 case SET_NW_DST:
175 OFActionSetNwDst nwdst = (OFActionSetNwDst) act;
176 IPv4Address di = nwdst.getNwAddr();
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800177 builder.setIpDst(Ip4Address.valueOf(di.getInt()));
alshabib6b5cfec2014-09-18 17:42:18 -0700178 break;
179 case SET_NW_SRC:
180 OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act;
181 IPv4Address si = nwsrc.getNwAddr();
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800182 builder.setIpSrc(Ip4Address.valueOf(si.getInt()));
alshabib6b5cfec2014-09-18 17:42:18 -0700183 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700184 case EXPERIMENTER:
185 OFActionExperimenter exp = (OFActionExperimenter) act;
Praseed Balakrishnandb8a9d22014-12-03 11:47:55 -0800186 if (exp.getExperimenter() == 0x80005A06 ||
187 exp.getExperimenter() == 0x748771) {
Marc De Leenheer49087752014-10-23 13:54:09 -0700188 OFActionCircuit ct = (OFActionCircuit) exp;
189 builder.setLambda(((OFOxmOchSigidBasic) ct.getField()).getValue().getChannelNumber());
190 } else {
191 log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter());
192 }
193 break;
Jonathan Hart1f8e0d72014-11-25 11:13:00 -0800194 case SET_FIELD:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800195 OFActionSetField setField = (OFActionSetField) act;
196 handleSetField(builder, setField.getField());
Jonathan Hart1f8e0d72014-11-25 11:13:00 -0800197 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700198 case SET_TP_DST:
199 case SET_TP_SRC:
200 case POP_MPLS:
201 case POP_PBB:
202 case POP_VLAN:
203 case PUSH_MPLS:
204 case PUSH_PBB:
205 case PUSH_VLAN:
alshabib6b5cfec2014-09-18 17:42:18 -0700206 case SET_MPLS_LABEL:
207 case SET_MPLS_TC:
208 case SET_MPLS_TTL:
209 case SET_NW_ECN:
210 case SET_NW_TOS:
211 case SET_NW_TTL:
212 case SET_QUEUE:
213 case STRIP_VLAN:
214 case COPY_TTL_IN:
215 case COPY_TTL_OUT:
216 case DEC_MPLS_TTL:
217 case DEC_NW_TTL:
218 case ENQUEUE:
Marc De Leenheer49087752014-10-23 13:54:09 -0700219
alshabib6b5cfec2014-09-18 17:42:18 -0700220 case GROUP:
221 default:
222 log.warn("Action type {} not yet implemented.", act.getType());
223 }
224 }
225
226 return builder.build();
227 }
228
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800229 private void handleSetField(TrafficTreatment.Builder builder, OFOxm<?> oxm) {
230 switch (oxm.getMatchField().id) {
231 case VLAN_PCP:
232 @SuppressWarnings("unchecked")
233 OFOxm<VlanPcp> vlanpcp = (OFOxm<VlanPcp>) oxm;
234 builder.setVlanPcp(vlanpcp.getValue().getValue());
235 break;
236 case VLAN_VID:
237 @SuppressWarnings("unchecked")
238 OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm;
239 builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan()));
240 break;
241 case ETH_DST:
242 @SuppressWarnings("unchecked")
243 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethdst =
244 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
245 builder.setEthDst(MacAddress.valueOf(ethdst.getValue().getLong()));
246 break;
247 case ETH_SRC:
248 @SuppressWarnings("unchecked")
249 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethsrc =
250 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
251 builder.setEthSrc(MacAddress.valueOf(ethsrc.getValue().getLong()));
252 break;
253 case IPV4_DST:
254 @SuppressWarnings("unchecked")
255 OFOxm<IPv4Address> ip4dst = (OFOxm<IPv4Address>) oxm;
256 builder.setIpDst(Ip4Address.valueOf(ip4dst.getValue().getInt()));
257 break;
258 case IPV4_SRC:
259 @SuppressWarnings("unchecked")
260 OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm;
261 builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt()));
262 break;
263 case ARP_OP:
264 case ARP_SHA:
265 case ARP_SPA:
266 case ARP_THA:
267 case ARP_TPA:
268 case BSN_EGR_PORT_GROUP_ID:
269 case BSN_GLOBAL_VRF_ALLOWED:
270 case BSN_IN_PORTS_128:
271 case BSN_L3_DST_CLASS_ID:
272 case BSN_L3_INTERFACE_CLASS_ID:
273 case BSN_L3_SRC_CLASS_ID:
274 case BSN_LAG_ID:
275 case BSN_TCP_FLAGS:
276 case BSN_UDF0:
277 case BSN_UDF1:
278 case BSN_UDF2:
279 case BSN_UDF3:
280 case BSN_UDF4:
281 case BSN_UDF5:
282 case BSN_UDF6:
283 case BSN_UDF7:
284 case BSN_VLAN_XLATE_PORT_GROUP_ID:
285 case BSN_VRF:
286 case ETH_TYPE:
287 case ICMPV4_CODE:
288 case ICMPV4_TYPE:
289 case ICMPV6_CODE:
290 case ICMPV6_TYPE:
291 case IN_PHY_PORT:
292 case IN_PORT:
293 case IPV6_DST:
294 case IPV6_FLABEL:
295 case IPV6_ND_SLL:
296 case IPV6_ND_TARGET:
297 case IPV6_ND_TLL:
298 case IPV6_SRC:
299 case IP_DSCP:
300 case IP_ECN:
301 case IP_PROTO:
302 case METADATA:
303 case MPLS_LABEL:
304 case MPLS_TC:
305 case OCH_SIGID:
306 case OCH_SIGID_BASIC:
307 case OCH_SIGTYPE:
308 case OCH_SIGTYPE_BASIC:
309 case SCTP_DST:
310 case SCTP_SRC:
311 case TCP_DST:
312 case TCP_SRC:
313 case TUNNEL_ID:
314 case UDP_DST:
315 case UDP_SRC:
316 default:
317 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
318 break;
319 }
320 }
321
alshabib6b5cfec2014-09-18 17:42:18 -0700322 private TrafficSelector buildSelector() {
tom9a693fd2014-10-03 11:32:19 -0700323 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700324 for (MatchField<?> field : match.getMatchFields()) {
325 switch (field.id) {
326 case IN_PORT:
alshabib010c31d2014-09-26 10:01:12 -0700327 builder.matchInport(PortNumber
328 .portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700329 break;
330 case ETH_SRC:
331 MacAddress sMac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
alshabib010c31d2014-09-26 10:01:12 -0700332 builder.matchEthSrc(sMac);
alshabib6b5cfec2014-09-18 17:42:18 -0700333 break;
334 case ETH_DST:
335 MacAddress dMac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
alshabib010c31d2014-09-26 10:01:12 -0700336 builder.matchEthDst(dMac);
alshabib6b5cfec2014-09-18 17:42:18 -0700337 break;
338 case ETH_TYPE:
339 int ethType = match.get(MatchField.ETH_TYPE).getValue();
alshabib010c31d2014-09-26 10:01:12 -0700340 builder.matchEthType((short) ethType);
alshabib6b5cfec2014-09-18 17:42:18 -0700341 break;
342 case IPV4_DST:
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800343 Ip4Prefix dip;
Jonathan Hart0e12fad2014-10-17 14:54:58 -0700344 if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
345 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
346
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800347 dip = Ip4Prefix.valueOf(
Jonathan Hart0e12fad2014-10-17 14:54:58 -0700348 maskedIp.getValue().getInt(),
349 maskedIp.getMask().asCidrMaskLength());
alshabib6b5cfec2014-09-18 17:42:18 -0700350 } else {
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800351 dip = Ip4Prefix.valueOf(
Jonathan Hart0e12fad2014-10-17 14:54:58 -0700352 match.get(MatchField.IPV4_DST).getInt(),
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800353 Ip4Prefix.MAX_MASK_LENGTH);
alshabib6b5cfec2014-09-18 17:42:18 -0700354 }
Jonathan Hart0e12fad2014-10-17 14:54:58 -0700355
alshabib010c31d2014-09-26 10:01:12 -0700356 builder.matchIPDst(dip);
alshabib6b5cfec2014-09-18 17:42:18 -0700357 break;
358 case IPV4_SRC:
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800359 Ip4Prefix sip;
Jonathan Hart0e12fad2014-10-17 14:54:58 -0700360 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
361 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
362
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800363 sip = Ip4Prefix.valueOf(
Jonathan Hart0e12fad2014-10-17 14:54:58 -0700364 maskedIp.getValue().getInt(),
365 maskedIp.getMask().asCidrMaskLength());
alshabib6b5cfec2014-09-18 17:42:18 -0700366 } else {
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800367 sip = Ip4Prefix.valueOf(
Jonathan Hart0e12fad2014-10-17 14:54:58 -0700368 match.get(MatchField.IPV4_SRC).getInt(),
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800369 Ip4Prefix.MAX_MASK_LENGTH);
alshabib6b5cfec2014-09-18 17:42:18 -0700370 }
Jonathan Hart0e12fad2014-10-17 14:54:58 -0700371
alshabib010c31d2014-09-26 10:01:12 -0700372 builder.matchIPSrc(sip);
alshabib6b5cfec2014-09-18 17:42:18 -0700373 break;
374 case IP_PROTO:
375 short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
alshabib010c31d2014-09-26 10:01:12 -0700376 builder.matchIPProtocol((byte) proto);
alshabib6b5cfec2014-09-18 17:42:18 -0700377 break;
378 case VLAN_PCP:
379 byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
alshabib010c31d2014-09-26 10:01:12 -0700380 builder.matchVlanPcp(vlanPcp);
alshabib6b5cfec2014-09-18 17:42:18 -0700381 break;
382 case VLAN_VID:
383 VlanId vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
alshabib010c31d2014-09-26 10:01:12 -0700384 builder.matchVlanId(vlanId);
alshabib6b5cfec2014-09-18 17:42:18 -0700385 break;
Jonathan Hart34bc6142014-10-17 11:00:43 -0700386 case TCP_DST:
387 builder.matchTcpDst((short) match.get(MatchField.TCP_DST).getPort());
388 break;
389 case TCP_SRC:
390 builder.matchTcpSrc((short) match.get(MatchField.TCP_SRC).getPort());
391 break;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800392 case MPLS_LABEL:
393 builder.matchMplsLabel((int) match.get(MatchField.MPLS_LABEL)
394 .getValue());
395 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700396 case OCH_SIGID:
397 builder.matchLambda(match.get(MatchField.OCH_SIGID).getChannelNumber());
398 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800399 case OCH_SIGTYPE:
400 builder.matchOpticalSignalType(match.get(MatchField
401 .OCH_SIGTYPE).getValue());
402 break;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800403 case IPV6_DST:
404 Ip6Prefix dipv6;
405 if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
406 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
407 dipv6 = Ip6Prefix.valueOf(
408 maskedIp.getValue().getBytes(),
409 maskedIp.getMask().asCidrMaskLength());
410 } else {
411 dipv6 = Ip6Prefix.valueOf(
412 match.get(MatchField.IPV6_DST).getBytes(),
413 Ip6Prefix.MAX_MASK_LENGTH);
414 }
415 builder.matchIPv6Dst(dipv6);
416 break;
417 case IPV6_SRC:
418 Ip6Prefix sipv6;
419 if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
420 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
421 sipv6 = Ip6Prefix.valueOf(
422 maskedIp.getValue().getBytes(),
423 maskedIp.getMask().asCidrMaskLength());
424 } else {
425 sipv6 = Ip6Prefix.valueOf(
426 match.get(MatchField.IPV6_SRC).getBytes(),
427 Ip6Prefix.MAX_MASK_LENGTH);
428 }
429 builder.matchIPv6Src(sipv6);
430 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700431 case ARP_OP:
432 case ARP_SHA:
433 case ARP_SPA:
434 case ARP_THA:
435 case ARP_TPA:
436 case ICMPV4_CODE:
437 case ICMPV4_TYPE:
438 case ICMPV6_CODE:
439 case ICMPV6_TYPE:
440 case IN_PHY_PORT:
alshabib6b5cfec2014-09-18 17:42:18 -0700441 case IPV6_FLABEL:
442 case IPV6_ND_SLL:
443 case IPV6_ND_TARGET:
444 case IPV6_ND_TLL:
alshabib6b5cfec2014-09-18 17:42:18 -0700445 case IP_DSCP:
446 case IP_ECN:
447 case METADATA:
alshabib6b5cfec2014-09-18 17:42:18 -0700448 case MPLS_TC:
449 case SCTP_DST:
450 case SCTP_SRC:
alshabib6b5cfec2014-09-18 17:42:18 -0700451 case TUNNEL_ID:
452 case UDP_DST:
453 case UDP_SRC:
454 default:
455 log.warn("Match type {} not yet implemented.", field.id);
alshabib6b5cfec2014-09-18 17:42:18 -0700456 }
457 }
458 return builder.build();
459 }
460
461}