blob: 3c1e6432d86058f6606e25c06bb735eb21b28871 [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;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080021import org.onlab.packet.Ip6Prefix;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080022import org.onlab.packet.MacAddress;
23import org.onlab.packet.VlanId;
Brian O'Connorabafb502014-12-02 22:26:20 -080024import org.onosproject.net.DeviceId;
25import org.onosproject.net.PortNumber;
26import org.onosproject.net.flow.DefaultFlowEntry;
27import org.onosproject.net.flow.DefaultFlowRule;
28import org.onosproject.net.flow.DefaultTrafficSelector;
29import org.onosproject.net.flow.DefaultTrafficTreatment;
30import org.onosproject.net.flow.FlowEntry;
31import org.onosproject.net.flow.FlowEntry.FlowEntryState;
32import org.onosproject.net.flow.FlowRule;
33import org.onosproject.net.flow.TrafficSelector;
34import org.onosproject.net.flow.TrafficTreatment;
35import org.onosproject.openflow.controller.Dpid;
alshabib6b5cfec2014-09-18 17:42:18 -070036import org.projectfloodlight.openflow.protocol.OFFlowRemoved;
37import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry;
alshabib19fdc122014-10-03 11:38:19 -070038import org.projectfloodlight.openflow.protocol.OFInstructionType;
alshabib6b5cfec2014-09-18 17:42:18 -070039import org.projectfloodlight.openflow.protocol.action.OFAction;
Marc De Leenheer49087752014-10-23 13:54:09 -070040import org.projectfloodlight.openflow.protocol.action.OFActionCircuit;
sangho3f97a17d2015-01-29 22:56:29 -080041import org.projectfloodlight.openflow.protocol.action.OFActionCopyTtlIn;
42import org.projectfloodlight.openflow.protocol.action.OFActionCopyTtlOut;
43import org.projectfloodlight.openflow.protocol.action.OFActionDecMplsTtl;
44import org.projectfloodlight.openflow.protocol.action.OFActionDecNwTtl;
Marc De Leenheer49087752014-10-23 13:54:09 -070045import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter;
alshabib6b5cfec2014-09-18 17:42:18 -070046import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
sangho3f97a17d2015-01-29 22:56:29 -080047import org.projectfloodlight.openflow.protocol.action.OFActionPopMpls;
48import org.projectfloodlight.openflow.protocol.action.OFActionPushMpls;
alshabib6b5cfec2014-09-18 17:42:18 -070049import org.projectfloodlight.openflow.protocol.action.OFActionSetDlDst;
50import org.projectfloodlight.openflow.protocol.action.OFActionSetDlSrc;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080051import org.projectfloodlight.openflow.protocol.action.OFActionSetField;
alshabib6b5cfec2014-09-18 17:42:18 -070052import org.projectfloodlight.openflow.protocol.action.OFActionSetNwDst;
53import org.projectfloodlight.openflow.protocol.action.OFActionSetNwSrc;
54import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanPcp;
55import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanVid;
alshabib19fdc122014-10-03 11:38:19 -070056import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
Jonathan Hartcf783202014-11-24 18:55:42 -080057import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions;
alshabib6b5cfec2014-09-18 17:42:18 -070058import org.projectfloodlight.openflow.protocol.match.Match;
59import org.projectfloodlight.openflow.protocol.match.MatchField;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080060import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
Marc De Leenheer49087752014-10-23 13:54:09 -070061import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigidBasic;
alshabib6b5cfec2014-09-18 17:42:18 -070062import org.projectfloodlight.openflow.types.IPv4Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080063import org.projectfloodlight.openflow.types.IPv6Address;
Jonathan Hart0e12fad2014-10-17 14:54:58 -070064import org.projectfloodlight.openflow.types.Masked;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080065import org.projectfloodlight.openflow.types.OFVlanVidMatch;
sangho3f97a17d2015-01-29 22:56:29 -080066import org.projectfloodlight.openflow.types.U32;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080067import org.projectfloodlight.openflow.types.VlanPcp;
alshabib6b5cfec2014-09-18 17:42:18 -070068import org.slf4j.Logger;
69
Jonathan Hart6cd2f352015-01-13 17:44:45 -080070import java.util.List;
71
72import static org.slf4j.LoggerFactory.getLogger;
alshabib19fdc122014-10-03 11:38:19 -070073
alshabib1c319ff2014-10-04 20:29:09 -070074public class FlowEntryBuilder {
alshabib6b5cfec2014-09-18 17:42:18 -070075 private final Logger log = getLogger(getClass());
76
77 private final OFFlowStatsEntry stat;
78 private final OFFlowRemoved removed;
79
80 private final Match match;
81 private final List<OFAction> actions;
82
83 private final Dpid dpid;
84
alshabib19fdc122014-10-03 11:38:19 -070085 private final boolean addedRule;
alshabib6b5cfec2014-09-18 17:42:18 -070086
87
alshabib1c319ff2014-10-04 20:29:09 -070088 public FlowEntryBuilder(Dpid dpid, OFFlowStatsEntry entry) {
alshabib6b5cfec2014-09-18 17:42:18 -070089 this.stat = entry;
90 this.match = entry.getMatch();
alshabib19fdc122014-10-03 11:38:19 -070091 this.actions = getActions(entry);
alshabib6b5cfec2014-09-18 17:42:18 -070092 this.dpid = dpid;
alshabib219ebaa2014-09-22 15:41:24 -070093 this.removed = null;
alshabib19fdc122014-10-03 11:38:19 -070094 this.addedRule = true;
alshabib6b5cfec2014-09-18 17:42:18 -070095 }
96
alshabib1c319ff2014-10-04 20:29:09 -070097 public FlowEntryBuilder(Dpid dpid, OFFlowRemoved removed) {
alshabib6b5cfec2014-09-18 17:42:18 -070098 this.match = removed.getMatch();
99 this.removed = removed;
100
101 this.dpid = dpid;
102 this.actions = null;
103 this.stat = null;
alshabib19fdc122014-10-03 11:38:19 -0700104 this.addedRule = false;
alshabib6b5cfec2014-09-18 17:42:18 -0700105
106 }
107
alshabib1c319ff2014-10-04 20:29:09 -0700108 public FlowEntry build() {
alshabib19fdc122014-10-03 11:38:19 -0700109 if (addedRule) {
alshabib1c319ff2014-10-04 20:29:09 -0700110 FlowRule rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)),
alshabib6b5cfec2014-09-18 17:42:18 -0700111 buildSelector(), buildTreatment(), stat.getPriority(),
Jonathan Hartbc4a7932014-10-21 11:46:00 -0700112 stat.getCookie().getValue(), stat.getIdleTimeout(), false);
alshabib1c319ff2014-10-04 20:29:09 -0700113 return new DefaultFlowEntry(rule, FlowEntryState.ADDED,
114 stat.getDurationSec(), stat.getPacketCount().getValue(),
115 stat.getByteCount().getValue());
116
alshabib6b5cfec2014-09-18 17:42:18 -0700117 } else {
alshabib1c319ff2014-10-04 20:29:09 -0700118 FlowRule rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)),
alshabib6b5cfec2014-09-18 17:42:18 -0700119 buildSelector(), null, removed.getPriority(),
Jonathan Hartbc4a7932014-10-21 11:46:00 -0700120 removed.getCookie().getValue(), removed.getIdleTimeout(), false);
alshabib1c319ff2014-10-04 20:29:09 -0700121 return new DefaultFlowEntry(rule, FlowEntryState.REMOVED, removed.getDurationSec(),
122 removed.getPacketCount().getValue(), removed.getByteCount().getValue());
alshabib6b5cfec2014-09-18 17:42:18 -0700123 }
124 }
125
alshabib19fdc122014-10-03 11:38:19 -0700126 private List<OFAction> getActions(OFFlowStatsEntry entry) {
127 switch (entry.getVersion()) {
128 case OF_10:
129 return entry.getActions();
130 case OF_11:
131 case OF_12:
132 case OF_13:
133 List<OFInstruction> ins = entry.getInstructions();
134 for (OFInstruction in : ins) {
Jonathan Hartcf783202014-11-24 18:55:42 -0800135 if (in.getType().equals(OFInstructionType.APPLY_ACTIONS)) {
136 OFInstructionApplyActions apply = (OFInstructionApplyActions) in;
alshabib19fdc122014-10-03 11:38:19 -0700137 return apply.getActions();
138 }
139 }
140 return Lists.newLinkedList();
141 default:
142 log.warn("Unknown OF version {}", entry.getVersion());
143 }
144 return Lists.newLinkedList();
145 }
alshabib6b5cfec2014-09-18 17:42:18 -0700146
147 private TrafficTreatment buildTreatment() {
tom9a693fd2014-10-03 11:32:19 -0700148 TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700149 // If this is a drop rule
150 if (actions.size() == 0) {
alshabib010c31d2014-09-26 10:01:12 -0700151 builder.drop();
alshabib6b5cfec2014-09-18 17:42:18 -0700152 return builder.build();
153 }
154 for (OFAction act : actions) {
155 switch (act.getType()) {
156 case OUTPUT:
157 OFActionOutput out = (OFActionOutput) act;
alshabib010c31d2014-09-26 10:01:12 -0700158 builder.setOutput(
159 PortNumber.portNumber(out.getPort().getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700160 break;
161 case SET_VLAN_VID:
alshabib010c31d2014-09-26 10:01:12 -0700162 OFActionSetVlanVid vlan = (OFActionSetVlanVid) act;
163 builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan()));
164 break;
165 case SET_VLAN_PCP:
alshabib6b5cfec2014-09-18 17:42:18 -0700166 OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800167 builder.setVlanPcp(pcp.getVlanPcp().getValue());
alshabib6b5cfec2014-09-18 17:42:18 -0700168 break;
169 case SET_DL_DST:
170 OFActionSetDlDst dldst = (OFActionSetDlDst) act;
alshabib010c31d2014-09-26 10:01:12 -0700171 builder.setEthDst(
172 MacAddress.valueOf(dldst.getDlAddr().getLong()));
alshabib6b5cfec2014-09-18 17:42:18 -0700173 break;
174 case SET_DL_SRC:
175 OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act;
alshabib010c31d2014-09-26 10:01:12 -0700176 builder.setEthSrc(
177 MacAddress.valueOf(dlsrc.getDlAddr().getLong()));
alshabib6b5cfec2014-09-18 17:42:18 -0700178
179 break;
180 case SET_NW_DST:
181 OFActionSetNwDst nwdst = (OFActionSetNwDst) act;
182 IPv4Address di = nwdst.getNwAddr();
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800183 builder.setIpDst(Ip4Address.valueOf(di.getInt()));
alshabib6b5cfec2014-09-18 17:42:18 -0700184 break;
185 case SET_NW_SRC:
186 OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act;
187 IPv4Address si = nwsrc.getNwAddr();
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800188 builder.setIpSrc(Ip4Address.valueOf(si.getInt()));
alshabib6b5cfec2014-09-18 17:42:18 -0700189 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700190 case EXPERIMENTER:
191 OFActionExperimenter exp = (OFActionExperimenter) act;
Praseed Balakrishnandb8a9d22014-12-03 11:47:55 -0800192 if (exp.getExperimenter() == 0x80005A06 ||
193 exp.getExperimenter() == 0x748771) {
Marc De Leenheer49087752014-10-23 13:54:09 -0700194 OFActionCircuit ct = (OFActionCircuit) exp;
195 builder.setLambda(((OFOxmOchSigidBasic) ct.getField()).getValue().getChannelNumber());
196 } else {
197 log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter());
198 }
199 break;
Jonathan Hart1f8e0d72014-11-25 11:13:00 -0800200 case SET_FIELD:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800201 OFActionSetField setField = (OFActionSetField) act;
202 handleSetField(builder, setField.getField());
Jonathan Hart1f8e0d72014-11-25 11:13:00 -0800203 break;
sangho3f97a17d2015-01-29 22:56:29 -0800204 case POP_MPLS:
205 OFActionPopMpls popMpls = (OFActionPopMpls) act;
206 builder.popMpls((short) popMpls.getEthertype().getValue());
207 break;
208 case PUSH_MPLS:
209 OFActionPushMpls pushMpls = (OFActionPushMpls) act;
210 builder.pushMpls();
211 break;
212 case COPY_TTL_IN:
213 OFActionCopyTtlIn copyTtlIn = (OFActionCopyTtlIn) act;
214 builder.copyTtlIn();
215 break;
216 case COPY_TTL_OUT:
217 OFActionCopyTtlOut copyTtlOut = (OFActionCopyTtlOut) act;
218 builder.copyTtlOut();
219 break;
220 case DEC_MPLS_TTL:
221 OFActionDecMplsTtl decMplsTtl = (OFActionDecMplsTtl) act;
222 builder.decMplsTtl();
223 break;
224 case DEC_NW_TTL:
225 OFActionDecNwTtl decNwTtl = (OFActionDecNwTtl) act;
226 builder.decNwTtl();
227 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700228 case SET_TP_DST:
229 case SET_TP_SRC:
alshabib6b5cfec2014-09-18 17:42:18 -0700230 case POP_PBB:
231 case POP_VLAN:
alshabib6b5cfec2014-09-18 17:42:18 -0700232 case PUSH_PBB:
233 case PUSH_VLAN:
alshabib6b5cfec2014-09-18 17:42:18 -0700234 case SET_MPLS_LABEL:
235 case SET_MPLS_TC:
236 case SET_MPLS_TTL:
237 case SET_NW_ECN:
238 case SET_NW_TOS:
239 case SET_NW_TTL:
240 case SET_QUEUE:
241 case STRIP_VLAN:
alshabib6b5cfec2014-09-18 17:42:18 -0700242 case ENQUEUE:
Marc De Leenheer49087752014-10-23 13:54:09 -0700243
alshabib6b5cfec2014-09-18 17:42:18 -0700244 case GROUP:
245 default:
246 log.warn("Action type {} not yet implemented.", act.getType());
247 }
248 }
249
250 return builder.build();
251 }
252
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800253 private void handleSetField(TrafficTreatment.Builder builder, OFOxm<?> oxm) {
254 switch (oxm.getMatchField().id) {
255 case VLAN_PCP:
256 @SuppressWarnings("unchecked")
257 OFOxm<VlanPcp> vlanpcp = (OFOxm<VlanPcp>) oxm;
258 builder.setVlanPcp(vlanpcp.getValue().getValue());
259 break;
260 case VLAN_VID:
261 @SuppressWarnings("unchecked")
262 OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm;
263 builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan()));
264 break;
265 case ETH_DST:
266 @SuppressWarnings("unchecked")
267 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethdst =
268 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
269 builder.setEthDst(MacAddress.valueOf(ethdst.getValue().getLong()));
270 break;
271 case ETH_SRC:
272 @SuppressWarnings("unchecked")
273 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethsrc =
274 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
275 builder.setEthSrc(MacAddress.valueOf(ethsrc.getValue().getLong()));
276 break;
277 case IPV4_DST:
278 @SuppressWarnings("unchecked")
279 OFOxm<IPv4Address> ip4dst = (OFOxm<IPv4Address>) oxm;
280 builder.setIpDst(Ip4Address.valueOf(ip4dst.getValue().getInt()));
281 break;
282 case IPV4_SRC:
283 @SuppressWarnings("unchecked")
284 OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm;
285 builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt()));
286 break;
sangho3f97a17d2015-01-29 22:56:29 -0800287 case MPLS_LABEL:
288 @SuppressWarnings("unchecked")
289 OFOxm<U32> labelId = (OFOxm<U32>) oxm;
290 builder.setMpls((int) labelId.getValue().getValue());
291 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800292 case ARP_OP:
293 case ARP_SHA:
294 case ARP_SPA:
295 case ARP_THA:
296 case ARP_TPA:
297 case BSN_EGR_PORT_GROUP_ID:
298 case BSN_GLOBAL_VRF_ALLOWED:
299 case BSN_IN_PORTS_128:
300 case BSN_L3_DST_CLASS_ID:
301 case BSN_L3_INTERFACE_CLASS_ID:
302 case BSN_L3_SRC_CLASS_ID:
303 case BSN_LAG_ID:
304 case BSN_TCP_FLAGS:
305 case BSN_UDF0:
306 case BSN_UDF1:
307 case BSN_UDF2:
308 case BSN_UDF3:
309 case BSN_UDF4:
310 case BSN_UDF5:
311 case BSN_UDF6:
312 case BSN_UDF7:
313 case BSN_VLAN_XLATE_PORT_GROUP_ID:
314 case BSN_VRF:
315 case ETH_TYPE:
316 case ICMPV4_CODE:
317 case ICMPV4_TYPE:
318 case ICMPV6_CODE:
319 case ICMPV6_TYPE:
320 case IN_PHY_PORT:
321 case IN_PORT:
322 case IPV6_DST:
323 case IPV6_FLABEL:
324 case IPV6_ND_SLL:
325 case IPV6_ND_TARGET:
326 case IPV6_ND_TLL:
327 case IPV6_SRC:
328 case IP_DSCP:
329 case IP_ECN:
330 case IP_PROTO:
331 case METADATA:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800332 case MPLS_TC:
333 case OCH_SIGID:
334 case OCH_SIGID_BASIC:
335 case OCH_SIGTYPE:
336 case OCH_SIGTYPE_BASIC:
337 case SCTP_DST:
338 case SCTP_SRC:
339 case TCP_DST:
340 case TCP_SRC:
341 case TUNNEL_ID:
342 case UDP_DST:
343 case UDP_SRC:
344 default:
345 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
346 break;
347 }
348 }
349
alshabib6b5cfec2014-09-18 17:42:18 -0700350 private TrafficSelector buildSelector() {
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:
alshabib010c31d2014-09-26 10:01:12 -0700355 builder.matchInport(PortNumber
356 .portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700357 break;
358 case ETH_SRC:
359 MacAddress sMac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
alshabib010c31d2014-09-26 10:01:12 -0700360 builder.matchEthSrc(sMac);
alshabib6b5cfec2014-09-18 17:42:18 -0700361 break;
362 case ETH_DST:
363 MacAddress dMac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
alshabib010c31d2014-09-26 10:01:12 -0700364 builder.matchEthDst(dMac);
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;
370 case IPV4_DST:
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800371 Ip4Prefix dip;
Jonathan Hart0e12fad2014-10-17 14:54:58 -0700372 if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
373 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
374
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800375 dip = Ip4Prefix.valueOf(
Jonathan Hart0e12fad2014-10-17 14:54:58 -0700376 maskedIp.getValue().getInt(),
377 maskedIp.getMask().asCidrMaskLength());
alshabib6b5cfec2014-09-18 17:42:18 -0700378 } else {
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800379 dip = Ip4Prefix.valueOf(
Jonathan Hart0e12fad2014-10-17 14:54:58 -0700380 match.get(MatchField.IPV4_DST).getInt(),
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800381 Ip4Prefix.MAX_MASK_LENGTH);
alshabib6b5cfec2014-09-18 17:42:18 -0700382 }
Jonathan Hart0e12fad2014-10-17 14:54:58 -0700383
alshabib010c31d2014-09-26 10:01:12 -0700384 builder.matchIPDst(dip);
alshabib6b5cfec2014-09-18 17:42:18 -0700385 break;
386 case IPV4_SRC:
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800387 Ip4Prefix sip;
Jonathan Hart0e12fad2014-10-17 14:54:58 -0700388 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
389 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
390
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800391 sip = Ip4Prefix.valueOf(
Jonathan Hart0e12fad2014-10-17 14:54:58 -0700392 maskedIp.getValue().getInt(),
393 maskedIp.getMask().asCidrMaskLength());
alshabib6b5cfec2014-09-18 17:42:18 -0700394 } else {
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800395 sip = Ip4Prefix.valueOf(
Jonathan Hart0e12fad2014-10-17 14:54:58 -0700396 match.get(MatchField.IPV4_SRC).getInt(),
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800397 Ip4Prefix.MAX_MASK_LENGTH);
alshabib6b5cfec2014-09-18 17:42:18 -0700398 }
Jonathan Hart0e12fad2014-10-17 14:54:58 -0700399
alshabib010c31d2014-09-26 10:01:12 -0700400 builder.matchIPSrc(sip);
alshabib6b5cfec2014-09-18 17:42:18 -0700401 break;
402 case IP_PROTO:
403 short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
alshabib010c31d2014-09-26 10:01:12 -0700404 builder.matchIPProtocol((byte) proto);
alshabib6b5cfec2014-09-18 17:42:18 -0700405 break;
406 case VLAN_PCP:
407 byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
alshabib010c31d2014-09-26 10:01:12 -0700408 builder.matchVlanPcp(vlanPcp);
alshabib6b5cfec2014-09-18 17:42:18 -0700409 break;
410 case VLAN_VID:
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800411 VlanId vlanId = null;
412 if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
413 Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
414 if (masked.getValue().equals(OFVlanVidMatch.PRESENT)
415 && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
416 vlanId = VlanId.ANY;
417 }
418 } else {
419 vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
420 }
421 if (vlanId != null) {
422 builder.matchVlanId(vlanId);
423 }
alshabib6b5cfec2014-09-18 17:42:18 -0700424 break;
Jonathan Hart34bc6142014-10-17 11:00:43 -0700425 case TCP_DST:
426 builder.matchTcpDst((short) match.get(MatchField.TCP_DST).getPort());
427 break;
428 case TCP_SRC:
429 builder.matchTcpSrc((short) match.get(MatchField.TCP_SRC).getPort());
430 break;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800431 case MPLS_LABEL:
432 builder.matchMplsLabel((int) match.get(MatchField.MPLS_LABEL)
433 .getValue());
434 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700435 case OCH_SIGID:
436 builder.matchLambda(match.get(MatchField.OCH_SIGID).getChannelNumber());
437 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800438 case OCH_SIGTYPE:
439 builder.matchOpticalSignalType(match.get(MatchField
440 .OCH_SIGTYPE).getValue());
441 break;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800442 case IPV6_DST:
443 Ip6Prefix dipv6;
444 if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
445 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
446 dipv6 = Ip6Prefix.valueOf(
447 maskedIp.getValue().getBytes(),
448 maskedIp.getMask().asCidrMaskLength());
449 } else {
450 dipv6 = Ip6Prefix.valueOf(
451 match.get(MatchField.IPV6_DST).getBytes(),
452 Ip6Prefix.MAX_MASK_LENGTH);
453 }
454 builder.matchIPv6Dst(dipv6);
455 break;
456 case IPV6_SRC:
457 Ip6Prefix sipv6;
458 if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
459 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
460 sipv6 = Ip6Prefix.valueOf(
461 maskedIp.getValue().getBytes(),
462 maskedIp.getMask().asCidrMaskLength());
463 } else {
464 sipv6 = Ip6Prefix.valueOf(
465 match.get(MatchField.IPV6_SRC).getBytes(),
466 Ip6Prefix.MAX_MASK_LENGTH);
467 }
468 builder.matchIPv6Src(sipv6);
469 break;
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800470 case ICMPV6_TYPE:
471 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
472 builder.matchIcmpv6Type(icmpv6type);
473 break;
474 case ICMPV6_CODE:
475 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
476 builder.matchIcmpv6Code(icmpv6code);
477 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700478 case ARP_OP:
479 case ARP_SHA:
480 case ARP_SPA:
481 case ARP_THA:
482 case ARP_TPA:
483 case ICMPV4_CODE:
484 case ICMPV4_TYPE:
alshabib6b5cfec2014-09-18 17:42:18 -0700485 case IN_PHY_PORT:
alshabib6b5cfec2014-09-18 17:42:18 -0700486 case IPV6_FLABEL:
487 case IPV6_ND_SLL:
488 case IPV6_ND_TARGET:
489 case IPV6_ND_TLL:
alshabib6b5cfec2014-09-18 17:42:18 -0700490 case IP_DSCP:
491 case IP_ECN:
492 case METADATA:
alshabib6b5cfec2014-09-18 17:42:18 -0700493 case MPLS_TC:
494 case SCTP_DST:
495 case SCTP_SRC:
alshabib6b5cfec2014-09-18 17:42:18 -0700496 case TUNNEL_ID:
497 case UDP_DST:
498 case UDP_SRC:
499 default:
500 log.warn("Match type {} not yet implemented.", field.id);
alshabib6b5cfec2014-09-18 17:42:18 -0700501 }
502 }
503 return builder.build();
504 }
505
506}