blob: e443aacff6eaa86afa3e869a016918a92b63abec [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 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;
alshabibeec3a062014-09-17 18:01:26 -070017
Jonathan Hart6cd2f352015-01-13 17:44:45 -080018import org.onlab.packet.Ip4Address;
19import org.onlab.packet.Ip4Prefix;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080020import org.onlab.packet.Ip6Address;
21import org.onlab.packet.Ip6Prefix;
Jonathan Hart6cd2f352015-01-13 17:44:45 -080022import org.onlab.packet.VlanId;
Sho SHIMIZUc15ce512015-05-26 16:54:08 -070023import org.onosproject.net.OchSignal;
Brian O'Connorabafb502014-12-02 22:26:20 -080024import org.onosproject.net.flow.FlowRule;
25import org.onosproject.net.flow.TrafficSelector;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070026import org.onosproject.net.flow.criteria.EthCriterion;
27import org.onosproject.net.flow.criteria.EthTypeCriterion;
28import org.onosproject.net.flow.criteria.IPCriterion;
29import org.onosproject.net.flow.criteria.IPDscpCriterion;
30import org.onosproject.net.flow.criteria.IPEcnCriterion;
31import org.onosproject.net.flow.criteria.IPProtocolCriterion;
32import org.onosproject.net.flow.criteria.IPv6ExthdrFlagsCriterion;
33import org.onosproject.net.flow.criteria.IPv6FlowLabelCriterion;
34import org.onosproject.net.flow.criteria.IPv6NDLinkLayerAddressCriterion;
35import org.onosproject.net.flow.criteria.IPv6NDTargetAddressCriterion;
36import org.onosproject.net.flow.criteria.IcmpCodeCriterion;
37import org.onosproject.net.flow.criteria.IcmpTypeCriterion;
38import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion;
39import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070040import org.onosproject.net.flow.criteria.MetadataCriterion;
41import org.onosproject.net.flow.criteria.MplsCriterion;
Sho SHIMIZUc15ce512015-05-26 16:54:08 -070042import org.onosproject.net.flow.criteria.OchSignalCriterion;
Marc De Leenheerd24420f2015-05-27 09:40:59 -070043import org.onosproject.net.flow.criteria.OchSignalTypeCriterion;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070044import org.onosproject.net.flow.criteria.PortCriterion;
45import org.onosproject.net.flow.criteria.SctpPortCriterion;
46import org.onosproject.net.flow.criteria.TcpPortCriterion;
Hyunsun Moona08c5d02015-07-14 17:53:00 -070047import org.onosproject.net.flow.criteria.TunnelIdCriterion;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070048import org.onosproject.net.flow.criteria.UdpPortCriterion;
49import org.onosproject.net.flow.criteria.VlanIdCriterion;
50import org.onosproject.net.flow.criteria.VlanPcpCriterion;
Brian O'Connorabafb502014-12-02 22:26:20 -080051import org.onosproject.net.flow.criteria.Criterion;
alshabibeec3a062014-09-17 18:01:26 -070052import org.projectfloodlight.openflow.protocol.OFFactory;
alshabib193525b2014-10-08 18:58:03 -070053import org.projectfloodlight.openflow.protocol.OFFlowAdd;
54import org.projectfloodlight.openflow.protocol.OFFlowDelete;
alshabibeec3a062014-09-17 18:01:26 -070055import org.projectfloodlight.openflow.protocol.OFFlowMod;
alshabibeec3a062014-09-17 18:01:26 -070056import org.projectfloodlight.openflow.protocol.match.Match;
57import org.projectfloodlight.openflow.protocol.match.MatchField;
Marc De Leenheer49087752014-10-23 13:54:09 -070058import org.projectfloodlight.openflow.types.CircuitSignalID;
alshabibeec3a062014-09-17 18:01:26 -070059import org.projectfloodlight.openflow.types.EthType;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080060import org.projectfloodlight.openflow.types.ICMPv4Code;
61import org.projectfloodlight.openflow.types.ICMPv4Type;
alshabibeec3a062014-09-17 18:01:26 -070062import org.projectfloodlight.openflow.types.IPv4Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080063import org.projectfloodlight.openflow.types.IPv6Address;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080064import org.projectfloodlight.openflow.types.IPv6FlowLabel;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080065import org.projectfloodlight.openflow.types.IpDscp;
66import org.projectfloodlight.openflow.types.IpEcn;
alshabibeec3a062014-09-17 18:01:26 -070067import org.projectfloodlight.openflow.types.IpProtocol;
68import org.projectfloodlight.openflow.types.MacAddress;
69import org.projectfloodlight.openflow.types.Masked;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080070import org.projectfloodlight.openflow.types.OFMetadata;
alshabibeec3a062014-09-17 18:01:26 -070071import org.projectfloodlight.openflow.types.OFPort;
72import org.projectfloodlight.openflow.types.OFVlanVidMatch;
Jonathan Hart34bc6142014-10-17 11:00:43 -070073import org.projectfloodlight.openflow.types.TransportPort;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -080074import org.projectfloodlight.openflow.types.U16;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -080075import org.projectfloodlight.openflow.types.U32;
Hyunsun Moona08c5d02015-07-14 17:53:00 -070076import org.projectfloodlight.openflow.types.U64;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -080077import org.projectfloodlight.openflow.types.U8;
alshabibeec3a062014-09-17 18:01:26 -070078import org.projectfloodlight.openflow.types.VlanPcp;
79import org.projectfloodlight.openflow.types.VlanVid;
80import org.slf4j.Logger;
81
Brian O'Connor427a1762014-11-19 18:40:32 -080082import java.util.Optional;
83
Jonathan Hart6cd2f352015-01-13 17:44:45 -080084import static org.slf4j.LoggerFactory.getLogger;
85
Jonathan Hart86e59352014-10-22 10:42:16 -070086/**
87 * Builder for OpenFlow flow mods based on FlowRules.
88 */
89public abstract class FlowModBuilder {
alshabibeec3a062014-09-17 18:01:26 -070090
91 private final Logger log = getLogger(getClass());
92
93 private final OFFactory factory;
Jonathan Hart86e59352014-10-22 10:42:16 -070094 private final FlowRule flowRule;
alshabibeec3a062014-09-17 18:01:26 -070095 private final TrafficSelector selector;
Brian O'Connor427a1762014-11-19 18:40:32 -080096 protected final Long xid;
alshabibeec3a062014-09-17 18:01:26 -070097
Jonathan Hart86e59352014-10-22 10:42:16 -070098 /**
99 * Creates a new flow mod builder.
100 *
101 * @param flowRule the flow rule to transform into a flow mod
102 * @param factory the OpenFlow factory to use to build the flow mod
Pavlin Radoslavov119fd5c2014-11-25 19:08:19 -0800103 * @param xid the transaction ID
Jonathan Hart86e59352014-10-22 10:42:16 -0700104 * @return the new flow mod builder
105 */
Brian O'Connor427a1762014-11-19 18:40:32 -0800106 public static FlowModBuilder builder(FlowRule flowRule,
alshabib9af70072015-02-09 14:34:16 -0800107 OFFactory factory,
108 Optional<Long> xid) {
Jonathan Hart86e59352014-10-22 10:42:16 -0700109 switch (factory.getVersion()) {
110 case OF_10:
Brian O'Connor427a1762014-11-19 18:40:32 -0800111 return new FlowModBuilderVer10(flowRule, factory, xid);
Jonathan Hart86e59352014-10-22 10:42:16 -0700112 case OF_13:
Brian O'Connor427a1762014-11-19 18:40:32 -0800113 return new FlowModBuilderVer13(flowRule, factory, xid);
Jonathan Hart86e59352014-10-22 10:42:16 -0700114 default:
115 throw new UnsupportedOperationException(
116 "No flow mod builder for protocol version " + factory.getVersion());
117 }
118 }
alshabibeec3a062014-09-17 18:01:26 -0700119
Jonathan Hart86e59352014-10-22 10:42:16 -0700120 /**
121 * Constructs a flow mod builder.
122 *
123 * @param flowRule the flow rule to transform into a flow mod
124 * @param factory the OpenFlow factory to use to build the flow mod
Pavlin Radoslavov119fd5c2014-11-25 19:08:19 -0800125 * @param xid the transaction ID
Jonathan Hart86e59352014-10-22 10:42:16 -0700126 */
Brian O'Connor427a1762014-11-19 18:40:32 -0800127 protected FlowModBuilder(FlowRule flowRule, OFFactory factory, Optional<Long> xid) {
alshabibeec3a062014-09-17 18:01:26 -0700128 this.factory = factory;
Jonathan Hart86e59352014-10-22 10:42:16 -0700129 this.flowRule = flowRule;
alshabibeec3a062014-09-17 18:01:26 -0700130 this.selector = flowRule.selector();
Sho SHIMIZUc14b2a22015-05-05 18:15:13 -0700131 this.xid = xid.orElse(0L);
Brian O'Connor427a1762014-11-19 18:40:32 -0800132
alshabibeec3a062014-09-17 18:01:26 -0700133 }
134
Jonathan Hart86e59352014-10-22 10:42:16 -0700135 /**
136 * Builds an ADD flow mod.
137 *
138 * @return the flow mod
139 */
140 public abstract OFFlowAdd buildFlowAdd();
alshabibeec3a062014-09-17 18:01:26 -0700141
Jonathan Hart86e59352014-10-22 10:42:16 -0700142 /**
143 * Builds a MODIFY flow mod.
144 *
145 * @return the flow mod
146 */
147 public abstract OFFlowMod buildFlowMod();
alshabibeec3a062014-09-17 18:01:26 -0700148
Jonathan Hart86e59352014-10-22 10:42:16 -0700149 /**
150 * Builds a DELETE flow mod.
151 *
152 * @return the flow mod
153 */
154 public abstract OFFlowDelete buildFlowDel();
alshabibeec3a062014-09-17 18:01:26 -0700155
Jonathan Hart86e59352014-10-22 10:42:16 -0700156 /**
157 * Builds the match for the flow mod.
158 *
159 * @return the match
160 */
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800161 // CHECKSTYLE IGNORE MethodLength FOR NEXT 300 LINES
Jonathan Hart86e59352014-10-22 10:42:16 -0700162 protected Match buildMatch() {
alshabibeec3a062014-09-17 18:01:26 -0700163 Match.Builder mBuilder = factory.buildMatch();
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800164 Ip6Address ip6Address;
Pavlin Radoslavov23e398d2014-11-05 15:17:57 -0800165 Ip4Prefix ip4Prefix;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800166 Ip6Prefix ip6Prefix;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800167 EthCriterion ethCriterion;
168 IPCriterion ipCriterion;
169 TcpPortCriterion tcpPortCriterion;
170 UdpPortCriterion udpPortCriterion;
171 SctpPortCriterion sctpPortCriterion;
172 IPv6NDLinkLayerAddressCriterion llAddressCriterion;
173
alshabibeec3a062014-09-17 18:01:26 -0700174 for (Criterion c : selector.criteria()) {
175 switch (c.type()) {
176 case IN_PORT:
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800177 PortCriterion inPort = (PortCriterion) c;
178 mBuilder.setExact(MatchField.IN_PORT,
179 OFPort.of((int) inPort.port().toLong()));
180 break;
181 case IN_PHY_PORT:
182 PortCriterion inPhyPort = (PortCriterion) c;
183 mBuilder.setExact(MatchField.IN_PORT,
184 OFPort.of((int) inPhyPort.port().toLong()));
185 break;
186 case METADATA:
187 MetadataCriterion metadata = (MetadataCriterion) c;
188 mBuilder.setExact(MatchField.METADATA,
189 OFMetadata.ofRaw(metadata.metadata()));
alshabibeec3a062014-09-17 18:01:26 -0700190 break;
alshabibeec3a062014-09-17 18:01:26 -0700191 case ETH_DST:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800192 ethCriterion = (EthCriterion) c;
193 mBuilder.setExact(MatchField.ETH_DST,
194 MacAddress.of(ethCriterion.mac().toLong()));
195 break;
196 case ETH_SRC:
197 ethCriterion = (EthCriterion) c;
198 mBuilder.setExact(MatchField.ETH_SRC,
199 MacAddress.of(ethCriterion.mac().toLong()));
alshabibeec3a062014-09-17 18:01:26 -0700200 break;
201 case ETH_TYPE:
202 EthTypeCriterion ethType = (EthTypeCriterion) c;
alshabibcaf1ca22015-06-25 15:18:16 -0700203 mBuilder.setExact(MatchField.ETH_TYPE, EthType.of(ethType.ethType().toShort()));
alshabibeec3a062014-09-17 18:01:26 -0700204 break;
alshabibeec3a062014-09-17 18:01:26 -0700205 case VLAN_VID:
206 VlanIdCriterion vid = (VlanIdCriterion) c;
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800207
208 if (vid.vlanId().equals(VlanId.ANY)) {
209 mBuilder.setMasked(MatchField.VLAN_VID, OFVlanVidMatch.PRESENT,
210 OFVlanVidMatch.PRESENT);
Jonathan Hart1468fee2015-07-16 18:50:34 -0700211 } else if (vid.vlanId().equals(VlanId.NONE)) {
212 mBuilder.setExact(MatchField.VLAN_VID, OFVlanVidMatch.NONE);
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800213 } else {
214 mBuilder.setExact(MatchField.VLAN_VID,
alshabib346b5b32015-03-06 00:42:16 -0800215 OFVlanVidMatch.ofVlanVid(VlanVid.ofVlan(vid.vlanId().toShort())));
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800216 }
alshabibeec3a062014-09-17 18:01:26 -0700217 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800218 case VLAN_PCP:
219 VlanPcpCriterion vpcp = (VlanPcpCriterion) c;
220 mBuilder.setExact(MatchField.VLAN_PCP, VlanPcp.of(vpcp.priority()));
221 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800222 case IP_DSCP:
223 IPDscpCriterion ipDscpCriterion = (IPDscpCriterion) c;
224 mBuilder.setExact(MatchField.IP_DSCP,
225 IpDscp.of(ipDscpCriterion.ipDscp()));
226 break;
227 case IP_ECN:
228 IPEcnCriterion ipEcnCriterion = (IPEcnCriterion) c;
229 mBuilder.setExact(MatchField.IP_ECN,
230 IpEcn.of(ipEcnCriterion.ipEcn()));
231 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800232 case IP_PROTO:
233 IPProtocolCriterion p = (IPProtocolCriterion) c;
234 mBuilder.setExact(MatchField.IP_PROTO, IpProtocol.of(p.protocol()));
235 break;
236 case IPV4_SRC:
237 ipCriterion = (IPCriterion) c;
238 ip4Prefix = ipCriterion.ip().getIp4Prefix();
239 if (ip4Prefix.prefixLength() != Ip4Prefix.MAX_MASK_LENGTH) {
240 Ip4Address maskAddr =
241 Ip4Address.makeMaskPrefix(ip4Prefix.prefixLength());
242 Masked<IPv4Address> maskedIp =
243 Masked.of(IPv4Address.of(ip4Prefix.address().toInt()),
244 IPv4Address.of(maskAddr.toInt()));
245 mBuilder.setMasked(MatchField.IPV4_SRC, maskedIp);
246 } else {
247 mBuilder.setExact(MatchField.IPV4_SRC,
248 IPv4Address.of(ip4Prefix.address().toInt()));
249 }
250 break;
251 case IPV4_DST:
252 ipCriterion = (IPCriterion) c;
253 ip4Prefix = ipCriterion.ip().getIp4Prefix();
254 if (ip4Prefix.prefixLength() != Ip4Prefix.MAX_MASK_LENGTH) {
255 Ip4Address maskAddr =
256 Ip4Address.makeMaskPrefix(ip4Prefix.prefixLength());
257 Masked<IPv4Address> maskedIp =
258 Masked.of(IPv4Address.of(ip4Prefix.address().toInt()),
259 IPv4Address.of(maskAddr.toInt()));
260 mBuilder.setMasked(MatchField.IPV4_DST, maskedIp);
261 } else {
262 mBuilder.setExact(MatchField.IPV4_DST,
263 IPv4Address.of(ip4Prefix.address().toInt()));
264 }
Jonathan Hart34bc6142014-10-17 11:00:43 -0700265 break;
266 case TCP_SRC:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800267 tcpPortCriterion = (TcpPortCriterion) c;
268 mBuilder.setExact(MatchField.TCP_SRC,
269 TransportPort.of(tcpPortCriterion.tcpPort()));
270 break;
271 case TCP_DST:
272 tcpPortCriterion = (TcpPortCriterion) c;
273 mBuilder.setExact(MatchField.TCP_DST,
274 TransportPort.of(tcpPortCriterion.tcpPort()));
275 break;
276 case UDP_SRC:
277 udpPortCriterion = (UdpPortCriterion) c;
278 mBuilder.setExact(MatchField.UDP_SRC,
279 TransportPort.of(udpPortCriterion.udpPort()));
280 break;
281 case UDP_DST:
282 udpPortCriterion = (UdpPortCriterion) c;
283 mBuilder.setExact(MatchField.UDP_DST,
284 TransportPort.of(udpPortCriterion.udpPort()));
285 break;
286 case SCTP_SRC:
287 sctpPortCriterion = (SctpPortCriterion) c;
288 mBuilder.setExact(MatchField.SCTP_SRC,
289 TransportPort.of(sctpPortCriterion.sctpPort()));
290 break;
291 case SCTP_DST:
292 sctpPortCriterion = (SctpPortCriterion) c;
293 mBuilder.setExact(MatchField.SCTP_DST,
294 TransportPort.of(sctpPortCriterion.sctpPort()));
295 break;
296 case ICMPV4_TYPE:
297 IcmpTypeCriterion icmpType = (IcmpTypeCriterion) c;
298 mBuilder.setExact(MatchField.ICMPV4_TYPE,
299 ICMPv4Type.of(icmpType.icmpType()));
300 break;
301 case ICMPV4_CODE:
302 IcmpCodeCriterion icmpCode = (IcmpCodeCriterion) c;
303 mBuilder.setExact(MatchField.ICMPV4_CODE,
304 ICMPv4Code.of(icmpCode.icmpCode()));
305 break;
306 case IPV6_SRC:
307 ipCriterion = (IPCriterion) c;
308 ip6Prefix = ipCriterion.ip().getIp6Prefix();
309 if (ip6Prefix.prefixLength() != Ip6Prefix.MAX_MASK_LENGTH) {
310 Ip6Address maskAddr =
311 Ip6Address.makeMaskPrefix(ip6Prefix.prefixLength());
312 Masked<IPv6Address> maskedIp =
313 Masked.of(IPv6Address.of(ip6Prefix.address().toString()),
314 IPv6Address.of(maskAddr.toString()));
315 mBuilder.setMasked(MatchField.IPV6_SRC, maskedIp);
316 } else {
317 mBuilder.setExact(MatchField.IPV6_SRC,
318 IPv6Address.of(ip6Prefix.address().toString()));
319 }
320 break;
321 case IPV6_DST:
322 ipCriterion = (IPCriterion) c;
323 ip6Prefix = ipCriterion.ip().getIp6Prefix();
324 if (ip6Prefix.prefixLength() != Ip6Prefix.MAX_MASK_LENGTH) {
325 Ip6Address maskAddr =
326 Ip6Address.makeMaskPrefix(ip6Prefix.prefixLength());
327 Masked<IPv6Address> maskedIp =
328 Masked.of(IPv6Address.of(ip6Prefix.address().toString()),
329 IPv6Address.of(maskAddr.toString()));
330 mBuilder.setMasked(MatchField.IPV6_DST, maskedIp);
331 } else {
332 mBuilder.setExact(MatchField.IPV6_DST,
333 IPv6Address.of(ip6Prefix.address().toString()));
334 }
335 break;
336 case IPV6_FLABEL:
337 IPv6FlowLabelCriterion flowLabelCriterion =
338 (IPv6FlowLabelCriterion) c;
339 mBuilder.setExact(MatchField.IPV6_FLABEL,
340 IPv6FlowLabel.of(flowLabelCriterion.flowLabel()));
341 break;
342 case ICMPV6_TYPE:
343 Icmpv6TypeCriterion icmpv6Type = (Icmpv6TypeCriterion) c;
344 mBuilder.setExact(MatchField.ICMPV6_TYPE,
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800345 U8.of(icmpv6Type.icmpv6Type()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800346 break;
347 case ICMPV6_CODE:
348 Icmpv6CodeCriterion icmpv6Code = (Icmpv6CodeCriterion) c;
349 mBuilder.setExact(MatchField.ICMPV6_CODE,
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800350 U8.of(icmpv6Code.icmpv6Code()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800351 break;
352 case IPV6_ND_TARGET:
353 IPv6NDTargetAddressCriterion targetAddressCriterion =
354 (IPv6NDTargetAddressCriterion) c;
355 ip6Address = targetAddressCriterion.targetAddress();
356 mBuilder.setExact(MatchField.IPV6_ND_TARGET,
357 IPv6Address.of(ip6Address.toOctets()));
358 break;
359 case IPV6_ND_SLL:
360 llAddressCriterion =
361 (IPv6NDLinkLayerAddressCriterion) c;
362 mBuilder.setExact(MatchField.IPV6_ND_SLL,
363 MacAddress.of(llAddressCriterion.mac().toLong()));
364 break;
365 case IPV6_ND_TLL:
366 llAddressCriterion =
367 (IPv6NDLinkLayerAddressCriterion) c;
368 mBuilder.setExact(MatchField.IPV6_ND_TLL,
369 MacAddress.of(llAddressCriterion.mac().toLong()));
Jonathan Hart34bc6142014-10-17 11:00:43 -0700370 break;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800371 case MPLS_LABEL:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700372 MplsCriterion mp = (MplsCriterion) c;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100373 mBuilder.setExact(MatchField.MPLS_LABEL, U32.of(mp.label().toInt()));
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800374 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800375 case IPV6_EXTHDR:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700376 IPv6ExthdrFlagsCriterion exthdrFlagsCriterion =
377 (IPv6ExthdrFlagsCriterion) c;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800378 mBuilder.setExact(MatchField.IPV6_EXTHDR,
379 U16.of(exthdrFlagsCriterion.exthdrFlags()));
380 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700381 case OCH_SIGID:
Sho SHIMIZUc15ce512015-05-26 16:54:08 -0700382 try {
383 OchSignalCriterion ochSignalCriterion = (OchSignalCriterion) c;
384 OchSignal signal = ochSignalCriterion.lambda();
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700385 byte gridType = OpenFlowValueMapper.lookupGridType(signal.gridType());
386 byte channelSpacing = OpenFlowValueMapper.lookupChannelSpacing(signal.channelSpacing());
Sho SHIMIZUc15ce512015-05-26 16:54:08 -0700387 mBuilder.setExact(MatchField.OCH_SIGID,
388 new CircuitSignalID(gridType, channelSpacing,
389 (short) signal.spacingMultiplier(), (short) signal.slotGranularity()));
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700390 } catch (NoMappingFoundException e) {
Sho SHIMIZUc15ce512015-05-26 16:54:08 -0700391 log.warn(e.getMessage());
392 }
Marc De Leenheer49087752014-10-23 13:54:09 -0700393 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800394 case OCH_SIGTYPE:
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700395 OchSignalTypeCriterion sc = (OchSignalTypeCriterion) c;
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700396 byte signalType = OpenFlowValueMapper.lookupOchSignalType(sc.signalType());
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700397 mBuilder.setExact(MatchField.OCH_SIGTYPE, U8.of(signalType));
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800398 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700399 case TUNNEL_ID:
400 TunnelIdCriterion tunnelId = (TunnelIdCriterion) c;
401 mBuilder.setExact(MatchField.TUNNEL_ID,
402 U64.of(tunnelId.tunnelId()));
403 break;
alshabibeec3a062014-09-17 18:01:26 -0700404 case ARP_OP:
405 case ARP_SHA:
406 case ARP_SPA:
407 case ARP_THA:
408 case ARP_TPA:
alshabibeec3a062014-09-17 18:01:26 -0700409 case MPLS_BOS:
alshabibeec3a062014-09-17 18:01:26 -0700410 case MPLS_TC:
411 case PBB_ISID:
alshabibeec3a062014-09-17 18:01:26 -0700412 default:
413 log.warn("Match type {} not yet implemented.", c.type());
414 }
415 }
416 return mBuilder.build();
417 }
418
Jonathan Hart86e59352014-10-22 10:42:16 -0700419 /**
420 * Returns the flow rule for this builder.
421 *
422 * @return the flow rule
423 */
424 protected FlowRule flowRule() {
425 return flowRule;
426 }
alshabib219ebaa2014-09-22 15:41:24 -0700427
Jonathan Hart86e59352014-10-22 10:42:16 -0700428 /**
429 * Returns the factory used for building OpenFlow constructs.
430 *
431 * @return the factory
432 */
433 protected OFFactory factory() {
434 return factory;
435 }
alshabib219ebaa2014-09-22 15:41:24 -0700436
alshabibeec3a062014-09-17 18:01:26 -0700437}