blob: a78cadb8b70082bca97b5f18a212598f5bf921af [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;
41import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter;
alshabib6b5cfec2014-09-18 17:42:18 -070042import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
43import org.projectfloodlight.openflow.protocol.action.OFActionSetDlDst;
44import org.projectfloodlight.openflow.protocol.action.OFActionSetDlSrc;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080045import org.projectfloodlight.openflow.protocol.action.OFActionSetField;
alshabib6b5cfec2014-09-18 17:42:18 -070046import org.projectfloodlight.openflow.protocol.action.OFActionSetNwDst;
47import org.projectfloodlight.openflow.protocol.action.OFActionSetNwSrc;
48import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanPcp;
49import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanVid;
alshabib19fdc122014-10-03 11:38:19 -070050import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
Jonathan Hartcf783202014-11-24 18:55:42 -080051import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions;
alshabib6b5cfec2014-09-18 17:42:18 -070052import org.projectfloodlight.openflow.protocol.match.Match;
53import org.projectfloodlight.openflow.protocol.match.MatchField;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080054import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
Marc De Leenheer49087752014-10-23 13:54:09 -070055import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigidBasic;
alshabib6b5cfec2014-09-18 17:42:18 -070056import org.projectfloodlight.openflow.types.IPv4Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080057import org.projectfloodlight.openflow.types.IPv6Address;
Jonathan Hart0e12fad2014-10-17 14:54:58 -070058import org.projectfloodlight.openflow.types.Masked;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080059import org.projectfloodlight.openflow.types.OFVlanVidMatch;
60import org.projectfloodlight.openflow.types.VlanPcp;
alshabib6b5cfec2014-09-18 17:42:18 -070061import org.slf4j.Logger;
62
Jonathan Hart6cd2f352015-01-13 17:44:45 -080063import java.util.List;
64
65import static org.slf4j.LoggerFactory.getLogger;
alshabib19fdc122014-10-03 11:38:19 -070066
alshabib1c319ff2014-10-04 20:29:09 -070067public class FlowEntryBuilder {
alshabib6b5cfec2014-09-18 17:42:18 -070068 private final Logger log = getLogger(getClass());
69
70 private final OFFlowStatsEntry stat;
71 private final OFFlowRemoved removed;
72
73 private final Match match;
74 private final List<OFAction> actions;
75
76 private final Dpid dpid;
77
alshabib19fdc122014-10-03 11:38:19 -070078 private final boolean addedRule;
alshabib6b5cfec2014-09-18 17:42:18 -070079
80
alshabib1c319ff2014-10-04 20:29:09 -070081 public FlowEntryBuilder(Dpid dpid, OFFlowStatsEntry entry) {
alshabib6b5cfec2014-09-18 17:42:18 -070082 this.stat = entry;
83 this.match = entry.getMatch();
alshabib19fdc122014-10-03 11:38:19 -070084 this.actions = getActions(entry);
alshabib6b5cfec2014-09-18 17:42:18 -070085 this.dpid = dpid;
alshabib219ebaa2014-09-22 15:41:24 -070086 this.removed = null;
alshabib19fdc122014-10-03 11:38:19 -070087 this.addedRule = true;
alshabib6b5cfec2014-09-18 17:42:18 -070088 }
89
alshabib1c319ff2014-10-04 20:29:09 -070090 public FlowEntryBuilder(Dpid dpid, OFFlowRemoved removed) {
alshabib6b5cfec2014-09-18 17:42:18 -070091 this.match = removed.getMatch();
92 this.removed = removed;
93
94 this.dpid = dpid;
95 this.actions = null;
96 this.stat = null;
alshabib19fdc122014-10-03 11:38:19 -070097 this.addedRule = false;
alshabib6b5cfec2014-09-18 17:42:18 -070098
99 }
100
alshabib1c319ff2014-10-04 20:29:09 -0700101 public FlowEntry build() {
alshabib19fdc122014-10-03 11:38:19 -0700102 if (addedRule) {
alshabib1c319ff2014-10-04 20:29:09 -0700103 FlowRule rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)),
alshabib6b5cfec2014-09-18 17:42:18 -0700104 buildSelector(), buildTreatment(), stat.getPriority(),
Jonathan Hartbc4a7932014-10-21 11:46:00 -0700105 stat.getCookie().getValue(), stat.getIdleTimeout(), false);
alshabib1c319ff2014-10-04 20:29:09 -0700106 return new DefaultFlowEntry(rule, FlowEntryState.ADDED,
107 stat.getDurationSec(), stat.getPacketCount().getValue(),
108 stat.getByteCount().getValue());
109
alshabib6b5cfec2014-09-18 17:42:18 -0700110 } else {
alshabib1c319ff2014-10-04 20:29:09 -0700111 FlowRule rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)),
alshabib6b5cfec2014-09-18 17:42:18 -0700112 buildSelector(), null, removed.getPriority(),
Jonathan Hartbc4a7932014-10-21 11:46:00 -0700113 removed.getCookie().getValue(), removed.getIdleTimeout(), false);
alshabib1c319ff2014-10-04 20:29:09 -0700114 return new DefaultFlowEntry(rule, FlowEntryState.REMOVED, removed.getDurationSec(),
115 removed.getPacketCount().getValue(), removed.getByteCount().getValue());
alshabib6b5cfec2014-09-18 17:42:18 -0700116 }
117 }
118
alshabib19fdc122014-10-03 11:38:19 -0700119 private List<OFAction> getActions(OFFlowStatsEntry entry) {
120 switch (entry.getVersion()) {
121 case OF_10:
122 return entry.getActions();
123 case OF_11:
124 case OF_12:
125 case OF_13:
126 List<OFInstruction> ins = entry.getInstructions();
127 for (OFInstruction in : ins) {
Jonathan Hartcf783202014-11-24 18:55:42 -0800128 if (in.getType().equals(OFInstructionType.APPLY_ACTIONS)) {
129 OFInstructionApplyActions apply = (OFInstructionApplyActions) in;
alshabib19fdc122014-10-03 11:38:19 -0700130 return apply.getActions();
131 }
132 }
133 return Lists.newLinkedList();
134 default:
135 log.warn("Unknown OF version {}", entry.getVersion());
136 }
137 return Lists.newLinkedList();
138 }
alshabib6b5cfec2014-09-18 17:42:18 -0700139
140 private TrafficTreatment buildTreatment() {
tom9a693fd2014-10-03 11:32:19 -0700141 TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700142 // If this is a drop rule
143 if (actions.size() == 0) {
alshabib010c31d2014-09-26 10:01:12 -0700144 builder.drop();
alshabib6b5cfec2014-09-18 17:42:18 -0700145 return builder.build();
146 }
147 for (OFAction act : actions) {
148 switch (act.getType()) {
149 case OUTPUT:
150 OFActionOutput out = (OFActionOutput) act;
alshabib010c31d2014-09-26 10:01:12 -0700151 builder.setOutput(
152 PortNumber.portNumber(out.getPort().getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700153 break;
154 case SET_VLAN_VID:
alshabib010c31d2014-09-26 10:01:12 -0700155 OFActionSetVlanVid vlan = (OFActionSetVlanVid) act;
156 builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan()));
157 break;
158 case SET_VLAN_PCP:
alshabib6b5cfec2014-09-18 17:42:18 -0700159 OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800160 builder.setVlanPcp(pcp.getVlanPcp().getValue());
alshabib6b5cfec2014-09-18 17:42:18 -0700161 break;
162 case SET_DL_DST:
163 OFActionSetDlDst dldst = (OFActionSetDlDst) act;
alshabib010c31d2014-09-26 10:01:12 -0700164 builder.setEthDst(
165 MacAddress.valueOf(dldst.getDlAddr().getLong()));
alshabib6b5cfec2014-09-18 17:42:18 -0700166 break;
167 case SET_DL_SRC:
168 OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act;
alshabib010c31d2014-09-26 10:01:12 -0700169 builder.setEthSrc(
170 MacAddress.valueOf(dlsrc.getDlAddr().getLong()));
alshabib6b5cfec2014-09-18 17:42:18 -0700171
172 break;
173 case SET_NW_DST:
174 OFActionSetNwDst nwdst = (OFActionSetNwDst) act;
175 IPv4Address di = nwdst.getNwAddr();
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800176 builder.setIpDst(Ip4Address.valueOf(di.getInt()));
alshabib6b5cfec2014-09-18 17:42:18 -0700177 break;
178 case SET_NW_SRC:
179 OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act;
180 IPv4Address si = nwsrc.getNwAddr();
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800181 builder.setIpSrc(Ip4Address.valueOf(si.getInt()));
alshabib6b5cfec2014-09-18 17:42:18 -0700182 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700183 case EXPERIMENTER:
184 OFActionExperimenter exp = (OFActionExperimenter) act;
Praseed Balakrishnandb8a9d22014-12-03 11:47:55 -0800185 if (exp.getExperimenter() == 0x80005A06 ||
186 exp.getExperimenter() == 0x748771) {
Marc De Leenheer49087752014-10-23 13:54:09 -0700187 OFActionCircuit ct = (OFActionCircuit) exp;
188 builder.setLambda(((OFOxmOchSigidBasic) ct.getField()).getValue().getChannelNumber());
189 } else {
190 log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter());
191 }
192 break;
Jonathan Hart1f8e0d72014-11-25 11:13:00 -0800193 case SET_FIELD:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800194 OFActionSetField setField = (OFActionSetField) act;
195 handleSetField(builder, setField.getField());
Jonathan Hart1f8e0d72014-11-25 11:13:00 -0800196 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700197 case SET_TP_DST:
198 case SET_TP_SRC:
199 case POP_MPLS:
200 case POP_PBB:
201 case POP_VLAN:
202 case PUSH_MPLS:
203 case PUSH_PBB:
204 case PUSH_VLAN:
alshabib6b5cfec2014-09-18 17:42:18 -0700205 case SET_MPLS_LABEL:
206 case SET_MPLS_TC:
207 case SET_MPLS_TTL:
208 case SET_NW_ECN:
209 case SET_NW_TOS:
210 case SET_NW_TTL:
211 case SET_QUEUE:
212 case STRIP_VLAN:
213 case COPY_TTL_IN:
214 case COPY_TTL_OUT:
215 case DEC_MPLS_TTL:
216 case DEC_NW_TTL:
217 case ENQUEUE:
Marc De Leenheer49087752014-10-23 13:54:09 -0700218
alshabib6b5cfec2014-09-18 17:42:18 -0700219 case GROUP:
220 default:
221 log.warn("Action type {} not yet implemented.", act.getType());
222 }
223 }
224
225 return builder.build();
226 }
227
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800228 private void handleSetField(TrafficTreatment.Builder builder, OFOxm<?> oxm) {
229 switch (oxm.getMatchField().id) {
230 case VLAN_PCP:
231 @SuppressWarnings("unchecked")
232 OFOxm<VlanPcp> vlanpcp = (OFOxm<VlanPcp>) oxm;
233 builder.setVlanPcp(vlanpcp.getValue().getValue());
234 break;
235 case VLAN_VID:
236 @SuppressWarnings("unchecked")
237 OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm;
238 builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan()));
239 break;
240 case ETH_DST:
241 @SuppressWarnings("unchecked")
242 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethdst =
243 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
244 builder.setEthDst(MacAddress.valueOf(ethdst.getValue().getLong()));
245 break;
246 case ETH_SRC:
247 @SuppressWarnings("unchecked")
248 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethsrc =
249 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
250 builder.setEthSrc(MacAddress.valueOf(ethsrc.getValue().getLong()));
251 break;
252 case IPV4_DST:
253 @SuppressWarnings("unchecked")
254 OFOxm<IPv4Address> ip4dst = (OFOxm<IPv4Address>) oxm;
255 builder.setIpDst(Ip4Address.valueOf(ip4dst.getValue().getInt()));
256 break;
257 case IPV4_SRC:
258 @SuppressWarnings("unchecked")
259 OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm;
260 builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt()));
261 break;
262 case ARP_OP:
263 case ARP_SHA:
264 case ARP_SPA:
265 case ARP_THA:
266 case ARP_TPA:
267 case BSN_EGR_PORT_GROUP_ID:
268 case BSN_GLOBAL_VRF_ALLOWED:
269 case BSN_IN_PORTS_128:
270 case BSN_L3_DST_CLASS_ID:
271 case BSN_L3_INTERFACE_CLASS_ID:
272 case BSN_L3_SRC_CLASS_ID:
273 case BSN_LAG_ID:
274 case BSN_TCP_FLAGS:
275 case BSN_UDF0:
276 case BSN_UDF1:
277 case BSN_UDF2:
278 case BSN_UDF3:
279 case BSN_UDF4:
280 case BSN_UDF5:
281 case BSN_UDF6:
282 case BSN_UDF7:
283 case BSN_VLAN_XLATE_PORT_GROUP_ID:
284 case BSN_VRF:
285 case ETH_TYPE:
286 case ICMPV4_CODE:
287 case ICMPV4_TYPE:
288 case ICMPV6_CODE:
289 case ICMPV6_TYPE:
290 case IN_PHY_PORT:
291 case IN_PORT:
292 case IPV6_DST:
293 case IPV6_FLABEL:
294 case IPV6_ND_SLL:
295 case IPV6_ND_TARGET:
296 case IPV6_ND_TLL:
297 case IPV6_SRC:
298 case IP_DSCP:
299 case IP_ECN:
300 case IP_PROTO:
301 case METADATA:
302 case MPLS_LABEL:
303 case MPLS_TC:
304 case OCH_SIGID:
305 case OCH_SIGID_BASIC:
306 case OCH_SIGTYPE:
307 case OCH_SIGTYPE_BASIC:
308 case SCTP_DST:
309 case SCTP_SRC:
310 case TCP_DST:
311 case TCP_SRC:
312 case TUNNEL_ID:
313 case UDP_DST:
314 case UDP_SRC:
315 default:
316 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
317 break;
318 }
319 }
320
alshabib6b5cfec2014-09-18 17:42:18 -0700321 private TrafficSelector buildSelector() {
tom9a693fd2014-10-03 11:32:19 -0700322 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700323 for (MatchField<?> field : match.getMatchFields()) {
324 switch (field.id) {
325 case IN_PORT:
alshabib010c31d2014-09-26 10:01:12 -0700326 builder.matchInport(PortNumber
327 .portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700328 break;
329 case ETH_SRC:
330 MacAddress sMac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
alshabib010c31d2014-09-26 10:01:12 -0700331 builder.matchEthSrc(sMac);
alshabib6b5cfec2014-09-18 17:42:18 -0700332 break;
333 case ETH_DST:
334 MacAddress dMac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
alshabib010c31d2014-09-26 10:01:12 -0700335 builder.matchEthDst(dMac);
alshabib6b5cfec2014-09-18 17:42:18 -0700336 break;
337 case ETH_TYPE:
338 int ethType = match.get(MatchField.ETH_TYPE).getValue();
alshabib010c31d2014-09-26 10:01:12 -0700339 builder.matchEthType((short) ethType);
alshabib6b5cfec2014-09-18 17:42:18 -0700340 break;
341 case IPV4_DST:
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800342 Ip4Prefix dip;
Jonathan Hart0e12fad2014-10-17 14:54:58 -0700343 if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
344 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
345
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800346 dip = Ip4Prefix.valueOf(
Jonathan Hart0e12fad2014-10-17 14:54:58 -0700347 maskedIp.getValue().getInt(),
348 maskedIp.getMask().asCidrMaskLength());
alshabib6b5cfec2014-09-18 17:42:18 -0700349 } else {
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800350 dip = Ip4Prefix.valueOf(
Jonathan Hart0e12fad2014-10-17 14:54:58 -0700351 match.get(MatchField.IPV4_DST).getInt(),
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800352 Ip4Prefix.MAX_MASK_LENGTH);
alshabib6b5cfec2014-09-18 17:42:18 -0700353 }
Jonathan Hart0e12fad2014-10-17 14:54:58 -0700354
alshabib010c31d2014-09-26 10:01:12 -0700355 builder.matchIPDst(dip);
alshabib6b5cfec2014-09-18 17:42:18 -0700356 break;
357 case IPV4_SRC:
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800358 Ip4Prefix sip;
Jonathan Hart0e12fad2014-10-17 14:54:58 -0700359 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
360 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
361
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800362 sip = Ip4Prefix.valueOf(
Jonathan Hart0e12fad2014-10-17 14:54:58 -0700363 maskedIp.getValue().getInt(),
364 maskedIp.getMask().asCidrMaskLength());
alshabib6b5cfec2014-09-18 17:42:18 -0700365 } else {
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800366 sip = Ip4Prefix.valueOf(
Jonathan Hart0e12fad2014-10-17 14:54:58 -0700367 match.get(MatchField.IPV4_SRC).getInt(),
Pavlin Radoslavovff894a22014-11-05 16:09:35 -0800368 Ip4Prefix.MAX_MASK_LENGTH);
alshabib6b5cfec2014-09-18 17:42:18 -0700369 }
Jonathan Hart0e12fad2014-10-17 14:54:58 -0700370
alshabib010c31d2014-09-26 10:01:12 -0700371 builder.matchIPSrc(sip);
alshabib6b5cfec2014-09-18 17:42:18 -0700372 break;
373 case IP_PROTO:
374 short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
alshabib010c31d2014-09-26 10:01:12 -0700375 builder.matchIPProtocol((byte) proto);
alshabib6b5cfec2014-09-18 17:42:18 -0700376 break;
377 case VLAN_PCP:
378 byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
alshabib010c31d2014-09-26 10:01:12 -0700379 builder.matchVlanPcp(vlanPcp);
alshabib6b5cfec2014-09-18 17:42:18 -0700380 break;
381 case VLAN_VID:
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800382 VlanId vlanId = null;
383 if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
384 Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
385 if (masked.getValue().equals(OFVlanVidMatch.PRESENT)
386 && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
387 vlanId = VlanId.ANY;
388 }
389 } else {
390 vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
391 }
392 if (vlanId != null) {
393 builder.matchVlanId(vlanId);
394 }
alshabib6b5cfec2014-09-18 17:42:18 -0700395 break;
Jonathan Hart34bc6142014-10-17 11:00:43 -0700396 case TCP_DST:
397 builder.matchTcpDst((short) match.get(MatchField.TCP_DST).getPort());
398 break;
399 case TCP_SRC:
400 builder.matchTcpSrc((short) match.get(MatchField.TCP_SRC).getPort());
401 break;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800402 case MPLS_LABEL:
403 builder.matchMplsLabel((int) match.get(MatchField.MPLS_LABEL)
404 .getValue());
405 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700406 case OCH_SIGID:
407 builder.matchLambda(match.get(MatchField.OCH_SIGID).getChannelNumber());
408 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800409 case OCH_SIGTYPE:
410 builder.matchOpticalSignalType(match.get(MatchField
411 .OCH_SIGTYPE).getValue());
412 break;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800413 case IPV6_DST:
414 Ip6Prefix dipv6;
415 if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
416 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
417 dipv6 = Ip6Prefix.valueOf(
418 maskedIp.getValue().getBytes(),
419 maskedIp.getMask().asCidrMaskLength());
420 } else {
421 dipv6 = Ip6Prefix.valueOf(
422 match.get(MatchField.IPV6_DST).getBytes(),
423 Ip6Prefix.MAX_MASK_LENGTH);
424 }
425 builder.matchIPv6Dst(dipv6);
426 break;
427 case IPV6_SRC:
428 Ip6Prefix sipv6;
429 if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
430 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
431 sipv6 = Ip6Prefix.valueOf(
432 maskedIp.getValue().getBytes(),
433 maskedIp.getMask().asCidrMaskLength());
434 } else {
435 sipv6 = Ip6Prefix.valueOf(
436 match.get(MatchField.IPV6_SRC).getBytes(),
437 Ip6Prefix.MAX_MASK_LENGTH);
438 }
439 builder.matchIPv6Src(sipv6);
440 break;
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800441 case ICMPV6_TYPE:
442 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
443 builder.matchIcmpv6Type(icmpv6type);
444 break;
445 case ICMPV6_CODE:
446 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
447 builder.matchIcmpv6Code(icmpv6code);
448 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700449 case ARP_OP:
450 case ARP_SHA:
451 case ARP_SPA:
452 case ARP_THA:
453 case ARP_TPA:
454 case ICMPV4_CODE:
455 case ICMPV4_TYPE:
alshabib6b5cfec2014-09-18 17:42:18 -0700456 case IN_PHY_PORT:
alshabib6b5cfec2014-09-18 17:42:18 -0700457 case IPV6_FLABEL:
458 case IPV6_ND_SLL:
459 case IPV6_ND_TARGET:
460 case IPV6_ND_TLL:
alshabib6b5cfec2014-09-18 17:42:18 -0700461 case IP_DSCP:
462 case IP_ECN:
463 case METADATA:
alshabib6b5cfec2014-09-18 17:42:18 -0700464 case MPLS_TC:
465 case SCTP_DST:
466 case SCTP_SRC:
alshabib6b5cfec2014-09-18 17:42:18 -0700467 case TUNNEL_ID:
468 case UDP_DST:
469 case UDP_SRC:
470 default:
471 log.warn("Match type {} not yet implemented.", field.id);
alshabib6b5cfec2014-09-18 17:42:18 -0700472 }
473 }
474 return builder.build();
475 }
476
477}