blob: 5b0e1efcdb04a69ccae31dfaf0ce235b4563ab65 [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;
Brian O'Connorabafb502014-12-02 22:26:20 -080025import org.onosproject.net.DeviceId;
26import org.onosproject.net.PortNumber;
27import org.onosproject.net.flow.DefaultFlowEntry;
28import org.onosproject.net.flow.DefaultFlowRule;
29import org.onosproject.net.flow.DefaultTrafficSelector;
30import org.onosproject.net.flow.DefaultTrafficTreatment;
31import org.onosproject.net.flow.FlowEntry;
32import org.onosproject.net.flow.FlowEntry.FlowEntryState;
33import org.onosproject.net.flow.FlowRule;
34import org.onosproject.net.flow.TrafficSelector;
35import org.onosproject.net.flow.TrafficTreatment;
36import org.onosproject.openflow.controller.Dpid;
alshabib6b5cfec2014-09-18 17:42:18 -070037import org.projectfloodlight.openflow.protocol.OFFlowRemoved;
38import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry;
alshabib19fdc122014-10-03 11:38:19 -070039import org.projectfloodlight.openflow.protocol.OFInstructionType;
alshabib6b5cfec2014-09-18 17:42:18 -070040import org.projectfloodlight.openflow.protocol.action.OFAction;
Marc De Leenheer49087752014-10-23 13:54:09 -070041import org.projectfloodlight.openflow.protocol.action.OFActionCircuit;
sangho3f97a17d2015-01-29 22:56:29 -080042import org.projectfloodlight.openflow.protocol.action.OFActionCopyTtlIn;
43import org.projectfloodlight.openflow.protocol.action.OFActionCopyTtlOut;
44import org.projectfloodlight.openflow.protocol.action.OFActionDecMplsTtl;
45import org.projectfloodlight.openflow.protocol.action.OFActionDecNwTtl;
Marc De Leenheer49087752014-10-23 13:54:09 -070046import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter;
alshabib6b5cfec2014-09-18 17:42:18 -070047import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
sangho3f97a17d2015-01-29 22:56:29 -080048import org.projectfloodlight.openflow.protocol.action.OFActionPopMpls;
49import org.projectfloodlight.openflow.protocol.action.OFActionPushMpls;
alshabib6b5cfec2014-09-18 17:42:18 -070050import org.projectfloodlight.openflow.protocol.action.OFActionSetDlDst;
51import org.projectfloodlight.openflow.protocol.action.OFActionSetDlSrc;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080052import org.projectfloodlight.openflow.protocol.action.OFActionSetField;
alshabib6b5cfec2014-09-18 17:42:18 -070053import org.projectfloodlight.openflow.protocol.action.OFActionSetNwDst;
54import org.projectfloodlight.openflow.protocol.action.OFActionSetNwSrc;
55import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanPcp;
56import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanVid;
alshabib19fdc122014-10-03 11:38:19 -070057import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
Jonathan Hartcf783202014-11-24 18:55:42 -080058import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions;
alshabib6b5cfec2014-09-18 17:42:18 -070059import org.projectfloodlight.openflow.protocol.match.Match;
60import org.projectfloodlight.openflow.protocol.match.MatchField;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080061import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
Marc De Leenheer49087752014-10-23 13:54:09 -070062import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigidBasic;
alshabib6b5cfec2014-09-18 17:42:18 -070063import org.projectfloodlight.openflow.types.IPv4Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080064import org.projectfloodlight.openflow.types.IPv6Address;
Jonathan Hart0e12fad2014-10-17 14:54:58 -070065import org.projectfloodlight.openflow.types.Masked;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080066import org.projectfloodlight.openflow.types.OFVlanVidMatch;
sangho3f97a17d2015-01-29 22:56:29 -080067import org.projectfloodlight.openflow.types.U32;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080068import org.projectfloodlight.openflow.types.VlanPcp;
alshabib6b5cfec2014-09-18 17:42:18 -070069import org.slf4j.Logger;
70
Jonathan Hart6cd2f352015-01-13 17:44:45 -080071import java.util.List;
72
73import static org.slf4j.LoggerFactory.getLogger;
alshabib19fdc122014-10-03 11:38:19 -070074
alshabib1c319ff2014-10-04 20:29:09 -070075public class FlowEntryBuilder {
alshabib6b5cfec2014-09-18 17:42:18 -070076 private final Logger log = getLogger(getClass());
77
78 private final OFFlowStatsEntry stat;
79 private final OFFlowRemoved removed;
80
81 private final Match match;
82 private final List<OFAction> actions;
83
84 private final Dpid dpid;
85
alshabib19fdc122014-10-03 11:38:19 -070086 private final boolean addedRule;
alshabib6b5cfec2014-09-18 17:42:18 -070087
88
alshabib1c319ff2014-10-04 20:29:09 -070089 public FlowEntryBuilder(Dpid dpid, OFFlowStatsEntry entry) {
alshabib6b5cfec2014-09-18 17:42:18 -070090 this.stat = entry;
91 this.match = entry.getMatch();
alshabib19fdc122014-10-03 11:38:19 -070092 this.actions = getActions(entry);
alshabib6b5cfec2014-09-18 17:42:18 -070093 this.dpid = dpid;
alshabib219ebaa2014-09-22 15:41:24 -070094 this.removed = null;
alshabib19fdc122014-10-03 11:38:19 -070095 this.addedRule = true;
alshabib6b5cfec2014-09-18 17:42:18 -070096 }
97
alshabib1c319ff2014-10-04 20:29:09 -070098 public FlowEntryBuilder(Dpid dpid, OFFlowRemoved removed) {
alshabib6b5cfec2014-09-18 17:42:18 -070099 this.match = removed.getMatch();
100 this.removed = removed;
101
102 this.dpid = dpid;
103 this.actions = null;
104 this.stat = null;
alshabib19fdc122014-10-03 11:38:19 -0700105 this.addedRule = false;
alshabib6b5cfec2014-09-18 17:42:18 -0700106
107 }
108
alshabib1c319ff2014-10-04 20:29:09 -0700109 public FlowEntry build() {
alshabib19fdc122014-10-03 11:38:19 -0700110 if (addedRule) {
alshabib1c319ff2014-10-04 20:29:09 -0700111 FlowRule rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)),
alshabib6b5cfec2014-09-18 17:42:18 -0700112 buildSelector(), buildTreatment(), stat.getPriority(),
Jonathan Hartbc4a7932014-10-21 11:46:00 -0700113 stat.getCookie().getValue(), stat.getIdleTimeout(), false);
alshabib1c319ff2014-10-04 20:29:09 -0700114 return new DefaultFlowEntry(rule, FlowEntryState.ADDED,
115 stat.getDurationSec(), stat.getPacketCount().getValue(),
116 stat.getByteCount().getValue());
117
alshabib6b5cfec2014-09-18 17:42:18 -0700118 } else {
alshabib1c319ff2014-10-04 20:29:09 -0700119 FlowRule rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)),
alshabib6b5cfec2014-09-18 17:42:18 -0700120 buildSelector(), null, removed.getPriority(),
Jonathan Hartbc4a7932014-10-21 11:46:00 -0700121 removed.getCookie().getValue(), removed.getIdleTimeout(), false);
alshabib1c319ff2014-10-04 20:29:09 -0700122 return new DefaultFlowEntry(rule, FlowEntryState.REMOVED, removed.getDurationSec(),
123 removed.getPacketCount().getValue(), removed.getByteCount().getValue());
alshabib6b5cfec2014-09-18 17:42:18 -0700124 }
125 }
126
alshabib19fdc122014-10-03 11:38:19 -0700127 private List<OFAction> getActions(OFFlowStatsEntry entry) {
128 switch (entry.getVersion()) {
129 case OF_10:
130 return entry.getActions();
131 case OF_11:
132 case OF_12:
133 case OF_13:
134 List<OFInstruction> ins = entry.getInstructions();
135 for (OFInstruction in : ins) {
Jonathan Hartcf783202014-11-24 18:55:42 -0800136 if (in.getType().equals(OFInstructionType.APPLY_ACTIONS)) {
137 OFInstructionApplyActions apply = (OFInstructionApplyActions) in;
alshabib19fdc122014-10-03 11:38:19 -0700138 return apply.getActions();
139 }
140 }
141 return Lists.newLinkedList();
142 default:
143 log.warn("Unknown OF version {}", entry.getVersion());
144 }
145 return Lists.newLinkedList();
146 }
alshabib6b5cfec2014-09-18 17:42:18 -0700147
148 private TrafficTreatment buildTreatment() {
tom9a693fd2014-10-03 11:32:19 -0700149 TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700150 // If this is a drop rule
151 if (actions.size() == 0) {
alshabib010c31d2014-09-26 10:01:12 -0700152 builder.drop();
alshabib6b5cfec2014-09-18 17:42:18 -0700153 return builder.build();
154 }
155 for (OFAction act : actions) {
156 switch (act.getType()) {
157 case OUTPUT:
158 OFActionOutput out = (OFActionOutput) act;
alshabib010c31d2014-09-26 10:01:12 -0700159 builder.setOutput(
160 PortNumber.portNumber(out.getPort().getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700161 break;
162 case SET_VLAN_VID:
alshabib010c31d2014-09-26 10:01:12 -0700163 OFActionSetVlanVid vlan = (OFActionSetVlanVid) act;
164 builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan()));
165 break;
166 case SET_VLAN_PCP:
alshabib6b5cfec2014-09-18 17:42:18 -0700167 OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800168 builder.setVlanPcp(pcp.getVlanPcp().getValue());
alshabib6b5cfec2014-09-18 17:42:18 -0700169 break;
170 case SET_DL_DST:
171 OFActionSetDlDst dldst = (OFActionSetDlDst) act;
alshabib010c31d2014-09-26 10:01:12 -0700172 builder.setEthDst(
173 MacAddress.valueOf(dldst.getDlAddr().getLong()));
alshabib6b5cfec2014-09-18 17:42:18 -0700174 break;
175 case SET_DL_SRC:
176 OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act;
alshabib010c31d2014-09-26 10:01:12 -0700177 builder.setEthSrc(
178 MacAddress.valueOf(dlsrc.getDlAddr().getLong()));
alshabib6b5cfec2014-09-18 17:42:18 -0700179
180 break;
181 case SET_NW_DST:
182 OFActionSetNwDst nwdst = (OFActionSetNwDst) act;
183 IPv4Address di = nwdst.getNwAddr();
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800184 builder.setIpDst(Ip4Address.valueOf(di.getInt()));
alshabib6b5cfec2014-09-18 17:42:18 -0700185 break;
186 case SET_NW_SRC:
187 OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act;
188 IPv4Address si = nwsrc.getNwAddr();
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800189 builder.setIpSrc(Ip4Address.valueOf(si.getInt()));
alshabib6b5cfec2014-09-18 17:42:18 -0700190 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700191 case EXPERIMENTER:
192 OFActionExperimenter exp = (OFActionExperimenter) act;
Praseed Balakrishnandb8a9d22014-12-03 11:47:55 -0800193 if (exp.getExperimenter() == 0x80005A06 ||
194 exp.getExperimenter() == 0x748771) {
Marc De Leenheer49087752014-10-23 13:54:09 -0700195 OFActionCircuit ct = (OFActionCircuit) exp;
196 builder.setLambda(((OFOxmOchSigidBasic) ct.getField()).getValue().getChannelNumber());
197 } else {
198 log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter());
199 }
200 break;
Jonathan Hart1f8e0d72014-11-25 11:13:00 -0800201 case SET_FIELD:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800202 OFActionSetField setField = (OFActionSetField) act;
203 handleSetField(builder, setField.getField());
Jonathan Hart1f8e0d72014-11-25 11:13:00 -0800204 break;
sangho3f97a17d2015-01-29 22:56:29 -0800205 case POP_MPLS:
206 OFActionPopMpls popMpls = (OFActionPopMpls) act;
207 builder.popMpls((short) popMpls.getEthertype().getValue());
208 break;
209 case PUSH_MPLS:
210 OFActionPushMpls pushMpls = (OFActionPushMpls) act;
211 builder.pushMpls();
212 break;
213 case COPY_TTL_IN:
214 OFActionCopyTtlIn copyTtlIn = (OFActionCopyTtlIn) act;
215 builder.copyTtlIn();
216 break;
217 case COPY_TTL_OUT:
218 OFActionCopyTtlOut copyTtlOut = (OFActionCopyTtlOut) act;
219 builder.copyTtlOut();
220 break;
221 case DEC_MPLS_TTL:
222 OFActionDecMplsTtl decMplsTtl = (OFActionDecMplsTtl) act;
223 builder.decMplsTtl();
224 break;
225 case DEC_NW_TTL:
226 OFActionDecNwTtl decNwTtl = (OFActionDecNwTtl) act;
227 builder.decNwTtl();
228 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700229 case SET_TP_DST:
230 case SET_TP_SRC:
alshabib6b5cfec2014-09-18 17:42:18 -0700231 case POP_PBB:
232 case POP_VLAN:
alshabib6b5cfec2014-09-18 17:42:18 -0700233 case PUSH_PBB:
234 case PUSH_VLAN:
alshabib6b5cfec2014-09-18 17:42:18 -0700235 case SET_MPLS_LABEL:
236 case SET_MPLS_TC:
237 case SET_MPLS_TTL:
238 case SET_NW_ECN:
239 case SET_NW_TOS:
240 case SET_NW_TTL:
241 case SET_QUEUE:
242 case STRIP_VLAN:
alshabib6b5cfec2014-09-18 17:42:18 -0700243 case ENQUEUE:
Marc De Leenheer49087752014-10-23 13:54:09 -0700244
alshabib6b5cfec2014-09-18 17:42:18 -0700245 case GROUP:
246 default:
247 log.warn("Action type {} not yet implemented.", act.getType());
248 }
249 }
250
251 return builder.build();
252 }
253
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800254 private void handleSetField(TrafficTreatment.Builder builder, OFOxm<?> oxm) {
255 switch (oxm.getMatchField().id) {
256 case VLAN_PCP:
257 @SuppressWarnings("unchecked")
258 OFOxm<VlanPcp> vlanpcp = (OFOxm<VlanPcp>) oxm;
259 builder.setVlanPcp(vlanpcp.getValue().getValue());
260 break;
261 case VLAN_VID:
262 @SuppressWarnings("unchecked")
263 OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm;
264 builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan()));
265 break;
266 case ETH_DST:
267 @SuppressWarnings("unchecked")
268 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethdst =
269 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
270 builder.setEthDst(MacAddress.valueOf(ethdst.getValue().getLong()));
271 break;
272 case ETH_SRC:
273 @SuppressWarnings("unchecked")
274 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethsrc =
275 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
276 builder.setEthSrc(MacAddress.valueOf(ethsrc.getValue().getLong()));
277 break;
278 case IPV4_DST:
279 @SuppressWarnings("unchecked")
280 OFOxm<IPv4Address> ip4dst = (OFOxm<IPv4Address>) oxm;
281 builder.setIpDst(Ip4Address.valueOf(ip4dst.getValue().getInt()));
282 break;
283 case IPV4_SRC:
284 @SuppressWarnings("unchecked")
285 OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm;
286 builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt()));
287 break;
sangho3f97a17d2015-01-29 22:56:29 -0800288 case MPLS_LABEL:
289 @SuppressWarnings("unchecked")
290 OFOxm<U32> labelId = (OFOxm<U32>) oxm;
291 builder.setMpls((int) labelId.getValue().getValue());
292 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800293 case ARP_OP:
294 case ARP_SHA:
295 case ARP_SPA:
296 case ARP_THA:
297 case ARP_TPA:
298 case BSN_EGR_PORT_GROUP_ID:
299 case BSN_GLOBAL_VRF_ALLOWED:
300 case BSN_IN_PORTS_128:
301 case BSN_L3_DST_CLASS_ID:
302 case BSN_L3_INTERFACE_CLASS_ID:
303 case BSN_L3_SRC_CLASS_ID:
304 case BSN_LAG_ID:
305 case BSN_TCP_FLAGS:
306 case BSN_UDF0:
307 case BSN_UDF1:
308 case BSN_UDF2:
309 case BSN_UDF3:
310 case BSN_UDF4:
311 case BSN_UDF5:
312 case BSN_UDF6:
313 case BSN_UDF7:
314 case BSN_VLAN_XLATE_PORT_GROUP_ID:
315 case BSN_VRF:
316 case ETH_TYPE:
317 case ICMPV4_CODE:
318 case ICMPV4_TYPE:
319 case ICMPV6_CODE:
320 case ICMPV6_TYPE:
321 case IN_PHY_PORT:
322 case IN_PORT:
323 case IPV6_DST:
324 case IPV6_FLABEL:
325 case IPV6_ND_SLL:
326 case IPV6_ND_TARGET:
327 case IPV6_ND_TLL:
328 case IPV6_SRC:
329 case IP_DSCP:
330 case IP_ECN:
331 case IP_PROTO:
332 case METADATA:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800333 case MPLS_TC:
334 case OCH_SIGID:
335 case OCH_SIGID_BASIC:
336 case OCH_SIGTYPE:
337 case OCH_SIGTYPE_BASIC:
338 case SCTP_DST:
339 case SCTP_SRC:
340 case TCP_DST:
341 case TCP_SRC:
342 case TUNNEL_ID:
343 case UDP_DST:
344 case UDP_SRC:
345 default:
346 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
347 break;
348 }
349 }
350
alshabib6b5cfec2014-09-18 17:42:18 -0700351 private TrafficSelector buildSelector() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800352 MacAddress mac;
353 Ip4Prefix ip4Prefix;
354 Ip6Address ip6Address;
355 Ip6Prefix ip6Prefix;
356
tom9a693fd2014-10-03 11:32:19 -0700357 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700358 for (MatchField<?> field : match.getMatchFields()) {
359 switch (field.id) {
360 case IN_PORT:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800361 builder.matchInPort(PortNumber
alshabib010c31d2014-09-26 10:01:12 -0700362 .portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700363 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700364 case ETH_DST:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800365 mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
366 builder.matchEthDst(mac);
367 break;
368 case ETH_SRC:
369 mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
370 builder.matchEthSrc(mac);
alshabib6b5cfec2014-09-18 17:42:18 -0700371 break;
372 case ETH_TYPE:
373 int ethType = match.get(MatchField.ETH_TYPE).getValue();
alshabib010c31d2014-09-26 10:01:12 -0700374 builder.matchEthType((short) ethType);
alshabib6b5cfec2014-09-18 17:42:18 -0700375 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700376 case VLAN_VID:
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800377 VlanId vlanId = null;
378 if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
379 Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
380 if (masked.getValue().equals(OFVlanVidMatch.PRESENT)
381 && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
382 vlanId = VlanId.ANY;
383 }
384 } else {
385 vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
386 }
387 if (vlanId != null) {
388 builder.matchVlanId(vlanId);
389 }
alshabib6b5cfec2014-09-18 17:42:18 -0700390 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800391 case VLAN_PCP:
392 byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
393 builder.matchVlanPcp(vlanPcp);
394 break;
395 case IP_PROTO:
396 short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
397 builder.matchIPProtocol((byte) proto);
398 break;
399 case IPV4_SRC:
400 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
401 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
402
403 ip4Prefix = Ip4Prefix.valueOf(
404 maskedIp.getValue().getInt(),
405 maskedIp.getMask().asCidrMaskLength());
406 } else {
407 ip4Prefix = Ip4Prefix.valueOf(
408 match.get(MatchField.IPV4_SRC).getInt(),
409 Ip4Prefix.MAX_MASK_LENGTH);
410 }
411
412 builder.matchIPSrc(ip4Prefix);
413 break;
414 case IPV4_DST:
415 if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
416 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
417
418 ip4Prefix = Ip4Prefix.valueOf(
419 maskedIp.getValue().getInt(),
420 maskedIp.getMask().asCidrMaskLength());
421 } else {
422 ip4Prefix = Ip4Prefix.valueOf(
423 match.get(MatchField.IPV4_DST).getInt(),
424 Ip4Prefix.MAX_MASK_LENGTH);
425 }
426
427 builder.matchIPDst(ip4Prefix);
Jonathan Hart34bc6142014-10-17 11:00:43 -0700428 break;
429 case TCP_SRC:
430 builder.matchTcpSrc((short) match.get(MatchField.TCP_SRC).getPort());
431 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800432 case TCP_DST:
433 builder.matchTcpDst((short) match.get(MatchField.TCP_DST).getPort());
434 break;
435 case UDP_SRC:
436 builder.matchUdpSrc((short) match.get(MatchField.UDP_SRC).getPort());
437 break;
438 case UDP_DST:
439 builder.matchUdpDst((short) match.get(MatchField.UDP_DST).getPort());
440 break;
441 case SCTP_SRC:
442 builder.matchSctpSrc((short) match.get(MatchField.SCTP_SRC).getPort());
443 break;
444 case SCTP_DST:
445 builder.matchSctpDst((short) match.get(MatchField.SCTP_DST).getPort());
446 break;
447 case ICMPV4_TYPE:
448 byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
449 builder.matchIcmpType(icmpType);
450 break;
451 case ICMPV4_CODE:
452 byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode();
453 builder.matchIcmpCode(icmpCode);
454 break;
455 case IPV6_SRC:
456 if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
457 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
458 ip6Prefix = Ip6Prefix.valueOf(
459 maskedIp.getValue().getBytes(),
460 maskedIp.getMask().asCidrMaskLength());
461 } else {
462 ip6Prefix = Ip6Prefix.valueOf(
463 match.get(MatchField.IPV6_SRC).getBytes(),
464 Ip6Prefix.MAX_MASK_LENGTH);
465 }
466 builder.matchIPv6Src(ip6Prefix);
467 break;
468 case IPV6_DST:
469 if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
470 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
471 ip6Prefix = Ip6Prefix.valueOf(
472 maskedIp.getValue().getBytes(),
473 maskedIp.getMask().asCidrMaskLength());
474 } else {
475 ip6Prefix = Ip6Prefix.valueOf(
476 match.get(MatchField.IPV6_DST).getBytes(),
477 Ip6Prefix.MAX_MASK_LENGTH);
478 }
479 builder.matchIPv6Dst(ip6Prefix);
480 break;
481 case IPV6_FLABEL:
482 int flowLabel =
483 match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue();
484 builder.matchIPv6FlowLabel(flowLabel);
485 break;
486 case ICMPV6_TYPE:
487 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
488 builder.matchIcmpv6Type(icmpv6type);
489 break;
490 case ICMPV6_CODE:
491 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
492 builder.matchIcmpv6Code(icmpv6code);
493 break;
494 case IPV6_ND_TARGET:
495 ip6Address =
496 Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes());
497 builder.matchIPv6NDTargetAddress(ip6Address);
498 break;
499 case IPV6_ND_SLL:
500 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong());
501 builder.matchIPv6NDSourceLinkLayerAddress(mac);
502 break;
503 case IPV6_ND_TLL:
504 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong());
505 builder.matchIPv6NDTargetLinkLayerAddress(mac);
506 break;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800507 case MPLS_LABEL:
508 builder.matchMplsLabel((int) match.get(MatchField.MPLS_LABEL)
509 .getValue());
510 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700511 case OCH_SIGID:
512 builder.matchLambda(match.get(MatchField.OCH_SIGID).getChannelNumber());
513 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800514 case OCH_SIGTYPE:
515 builder.matchOpticalSignalType(match.get(MatchField
516 .OCH_SIGTYPE).getValue());
517 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700518 case ARP_OP:
519 case ARP_SHA:
520 case ARP_SPA:
521 case ARP_THA:
522 case ARP_TPA:
alshabib6b5cfec2014-09-18 17:42:18 -0700523 case IN_PHY_PORT:
alshabib6b5cfec2014-09-18 17:42:18 -0700524 case IP_DSCP:
525 case IP_ECN:
526 case METADATA:
alshabib6b5cfec2014-09-18 17:42:18 -0700527 case MPLS_TC:
alshabib6b5cfec2014-09-18 17:42:18 -0700528 case TUNNEL_ID:
alshabib6b5cfec2014-09-18 17:42:18 -0700529 default:
530 log.warn("Match type {} not yet implemented.", field.id);
alshabib6b5cfec2014-09-18 17:42:18 -0700531 }
532 }
533 return builder.build();
534 }
535
536}