blob: 2a8d2010b44d174f027d45327eb7fe4d12fc90c5 [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;
Jonathan Hart3c259162015-10-21 21:31:19 -070024import org.onosproject.net.driver.DriverService;
Brian O'Connorabafb502014-12-02 22:26:20 -080025import org.onosproject.net.flow.FlowRule;
26import org.onosproject.net.flow.TrafficSelector;
BitOhenry76430852015-11-20 19:04:49 +080027import org.onosproject.net.flow.criteria.ArpHaCriterion;
BitOhenryb40129a2015-11-30 12:41:18 +080028import org.onosproject.net.flow.criteria.ArpOpCriterion;
BitOhenryc1e5fcc2015-11-23 20:47:53 +080029import org.onosproject.net.flow.criteria.ArpPaCriterion;
Saurav Dasffc5bbc2015-08-18 23:30:19 -070030import org.onosproject.net.flow.criteria.Criterion;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070031import org.onosproject.net.flow.criteria.EthCriterion;
32import org.onosproject.net.flow.criteria.EthTypeCriterion;
33import org.onosproject.net.flow.criteria.IPCriterion;
34import org.onosproject.net.flow.criteria.IPDscpCriterion;
35import org.onosproject.net.flow.criteria.IPEcnCriterion;
36import org.onosproject.net.flow.criteria.IPProtocolCriterion;
37import org.onosproject.net.flow.criteria.IPv6ExthdrFlagsCriterion;
38import org.onosproject.net.flow.criteria.IPv6FlowLabelCriterion;
39import org.onosproject.net.flow.criteria.IPv6NDLinkLayerAddressCriterion;
40import org.onosproject.net.flow.criteria.IPv6NDTargetAddressCriterion;
41import org.onosproject.net.flow.criteria.IcmpCodeCriterion;
42import org.onosproject.net.flow.criteria.IcmpTypeCriterion;
43import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion;
44import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070045import org.onosproject.net.flow.criteria.MetadataCriterion;
Saurav Dasffc5bbc2015-08-18 23:30:19 -070046import org.onosproject.net.flow.criteria.MplsBosCriterion;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070047import org.onosproject.net.flow.criteria.MplsCriterion;
Sho SHIMIZUc15ce512015-05-26 16:54:08 -070048import org.onosproject.net.flow.criteria.OchSignalCriterion;
Marc De Leenheerd24420f2015-05-27 09:40:59 -070049import org.onosproject.net.flow.criteria.OchSignalTypeCriterion;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070050import org.onosproject.net.flow.criteria.PortCriterion;
51import org.onosproject.net.flow.criteria.SctpPortCriterion;
52import org.onosproject.net.flow.criteria.TcpPortCriterion;
Hyunsun Moona08c5d02015-07-14 17:53:00 -070053import org.onosproject.net.flow.criteria.TunnelIdCriterion;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070054import org.onosproject.net.flow.criteria.UdpPortCriterion;
55import org.onosproject.net.flow.criteria.VlanIdCriterion;
56import org.onosproject.net.flow.criteria.VlanPcpCriterion;
alshabibeec3a062014-09-17 18:01:26 -070057import org.projectfloodlight.openflow.protocol.OFFactory;
alshabib193525b2014-10-08 18:58:03 -070058import org.projectfloodlight.openflow.protocol.OFFlowAdd;
59import org.projectfloodlight.openflow.protocol.OFFlowDelete;
alshabibeec3a062014-09-17 18:01:26 -070060import org.projectfloodlight.openflow.protocol.OFFlowMod;
alshabibeec3a062014-09-17 18:01:26 -070061import org.projectfloodlight.openflow.protocol.match.Match;
62import org.projectfloodlight.openflow.protocol.match.MatchField;
BitOhenryb40129a2015-11-30 12:41:18 +080063import org.projectfloodlight.openflow.types.ArpOpcode;
Marc De Leenheer49087752014-10-23 13:54:09 -070064import org.projectfloodlight.openflow.types.CircuitSignalID;
alshabibeec3a062014-09-17 18:01:26 -070065import org.projectfloodlight.openflow.types.EthType;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080066import org.projectfloodlight.openflow.types.ICMPv4Code;
67import org.projectfloodlight.openflow.types.ICMPv4Type;
alshabibeec3a062014-09-17 18:01:26 -070068import org.projectfloodlight.openflow.types.IPv4Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080069import org.projectfloodlight.openflow.types.IPv6Address;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080070import org.projectfloodlight.openflow.types.IPv6FlowLabel;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080071import org.projectfloodlight.openflow.types.IpDscp;
72import org.projectfloodlight.openflow.types.IpEcn;
alshabibeec3a062014-09-17 18:01:26 -070073import org.projectfloodlight.openflow.types.IpProtocol;
74import org.projectfloodlight.openflow.types.MacAddress;
75import org.projectfloodlight.openflow.types.Masked;
Saurav Dasffc5bbc2015-08-18 23:30:19 -070076import org.projectfloodlight.openflow.types.OFBooleanValue;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080077import org.projectfloodlight.openflow.types.OFMetadata;
alshabibeec3a062014-09-17 18:01:26 -070078import org.projectfloodlight.openflow.types.OFPort;
79import org.projectfloodlight.openflow.types.OFVlanVidMatch;
Jonathan Hart34bc6142014-10-17 11:00:43 -070080import org.projectfloodlight.openflow.types.TransportPort;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -080081import org.projectfloodlight.openflow.types.U16;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -080082import org.projectfloodlight.openflow.types.U32;
Hyunsun Moona08c5d02015-07-14 17:53:00 -070083import org.projectfloodlight.openflow.types.U64;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -080084import org.projectfloodlight.openflow.types.U8;
alshabibeec3a062014-09-17 18:01:26 -070085import org.projectfloodlight.openflow.types.VlanPcp;
86import org.projectfloodlight.openflow.types.VlanVid;
87import org.slf4j.Logger;
88
Jonathan Hart3c259162015-10-21 21:31:19 -070089import java.util.Optional;
90
91import static org.slf4j.LoggerFactory.getLogger;
92
Jonathan Hart86e59352014-10-22 10:42:16 -070093/**
94 * Builder for OpenFlow flow mods based on FlowRules.
95 */
96public abstract class FlowModBuilder {
alshabibeec3a062014-09-17 18:01:26 -070097
98 private final Logger log = getLogger(getClass());
99
100 private final OFFactory factory;
Jonathan Hart86e59352014-10-22 10:42:16 -0700101 private final FlowRule flowRule;
alshabibeec3a062014-09-17 18:01:26 -0700102 private final TrafficSelector selector;
Brian O'Connor427a1762014-11-19 18:40:32 -0800103 protected final Long xid;
Jonathan Hart3c259162015-10-21 21:31:19 -0700104 protected final Optional<DriverService> driverService;
alshabibeec3a062014-09-17 18:01:26 -0700105
Jonathan Hart86e59352014-10-22 10:42:16 -0700106 /**
107 * Creates a new flow mod builder.
108 *
109 * @param flowRule the flow rule to transform into a flow mod
110 * @param factory the OpenFlow factory to use to build the flow mod
Pavlin Radoslavov119fd5c2014-11-25 19:08:19 -0800111 * @param xid the transaction ID
Charles Chan30ba4002015-11-05 14:45:16 -0800112 * @param driverService the device driver service
Jonathan Hart86e59352014-10-22 10:42:16 -0700113 * @return the new flow mod builder
114 */
Brian O'Connor427a1762014-11-19 18:40:32 -0800115 public static FlowModBuilder builder(FlowRule flowRule,
alshabib9af70072015-02-09 14:34:16 -0800116 OFFactory factory,
Jonathan Hart3c259162015-10-21 21:31:19 -0700117 Optional<Long> xid,
118 Optional<DriverService> driverService) {
Jonathan Hart86e59352014-10-22 10:42:16 -0700119 switch (factory.getVersion()) {
120 case OF_10:
Jonathan Hart3c259162015-10-21 21:31:19 -0700121 return new FlowModBuilderVer10(flowRule, factory, xid, driverService);
Jonathan Hart86e59352014-10-22 10:42:16 -0700122 case OF_13:
Jonathan Hart3c259162015-10-21 21:31:19 -0700123 return new FlowModBuilderVer13(flowRule, factory, xid, driverService);
Jonathan Hart86e59352014-10-22 10:42:16 -0700124 default:
125 throw new UnsupportedOperationException(
126 "No flow mod builder for protocol version " + factory.getVersion());
127 }
128 }
alshabibeec3a062014-09-17 18:01:26 -0700129
Jonathan Hart86e59352014-10-22 10:42:16 -0700130 /**
131 * Constructs a flow mod builder.
132 *
133 * @param flowRule the flow rule to transform into a flow mod
134 * @param factory the OpenFlow factory to use to build the flow mod
Charles Chan30ba4002015-11-05 14:45:16 -0800135 * @param driverService the device driver service
Pavlin Radoslavov119fd5c2014-11-25 19:08:19 -0800136 * @param xid the transaction ID
Jonathan Hart86e59352014-10-22 10:42:16 -0700137 */
Jonathan Hart3c259162015-10-21 21:31:19 -0700138 protected FlowModBuilder(FlowRule flowRule, OFFactory factory, Optional<Long> xid,
139 Optional<DriverService> driverService) {
alshabibeec3a062014-09-17 18:01:26 -0700140 this.factory = factory;
Jonathan Hart86e59352014-10-22 10:42:16 -0700141 this.flowRule = flowRule;
alshabibeec3a062014-09-17 18:01:26 -0700142 this.selector = flowRule.selector();
Sho SHIMIZUc14b2a22015-05-05 18:15:13 -0700143 this.xid = xid.orElse(0L);
Jonathan Hart3c259162015-10-21 21:31:19 -0700144 this.driverService = driverService;
alshabibeec3a062014-09-17 18:01:26 -0700145 }
146
Jonathan Hart86e59352014-10-22 10:42:16 -0700147 /**
148 * Builds an ADD flow mod.
149 *
150 * @return the flow mod
151 */
152 public abstract OFFlowAdd buildFlowAdd();
alshabibeec3a062014-09-17 18:01:26 -0700153
Jonathan Hart86e59352014-10-22 10:42:16 -0700154 /**
155 * Builds a MODIFY flow mod.
156 *
157 * @return the flow mod
158 */
159 public abstract OFFlowMod buildFlowMod();
alshabibeec3a062014-09-17 18:01:26 -0700160
Jonathan Hart86e59352014-10-22 10:42:16 -0700161 /**
162 * Builds a DELETE flow mod.
163 *
164 * @return the flow mod
165 */
166 public abstract OFFlowDelete buildFlowDel();
alshabibeec3a062014-09-17 18:01:26 -0700167
Jonathan Hart86e59352014-10-22 10:42:16 -0700168 /**
169 * Builds the match for the flow mod.
170 *
171 * @return the match
172 */
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800173 // CHECKSTYLE IGNORE MethodLength FOR NEXT 300 LINES
Jonathan Hart86e59352014-10-22 10:42:16 -0700174 protected Match buildMatch() {
alshabibeec3a062014-09-17 18:01:26 -0700175 Match.Builder mBuilder = factory.buildMatch();
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800176 Ip6Address ip6Address;
Pavlin Radoslavov23e398d2014-11-05 15:17:57 -0800177 Ip4Prefix ip4Prefix;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800178 Ip6Prefix ip6Prefix;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800179 EthCriterion ethCriterion;
180 IPCriterion ipCriterion;
181 TcpPortCriterion tcpPortCriterion;
182 UdpPortCriterion udpPortCriterion;
183 SctpPortCriterion sctpPortCriterion;
184 IPv6NDLinkLayerAddressCriterion llAddressCriterion;
BitOhenry76430852015-11-20 19:04:49 +0800185 ArpHaCriterion arpHaCriterion;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800186 ArpPaCriterion arpPaCriterion;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800187
alshabibeec3a062014-09-17 18:01:26 -0700188 for (Criterion c : selector.criteria()) {
189 switch (c.type()) {
190 case IN_PORT:
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800191 PortCriterion inPort = (PortCriterion) c;
192 mBuilder.setExact(MatchField.IN_PORT,
193 OFPort.of((int) inPort.port().toLong()));
194 break;
195 case IN_PHY_PORT:
196 PortCriterion inPhyPort = (PortCriterion) c;
197 mBuilder.setExact(MatchField.IN_PORT,
198 OFPort.of((int) inPhyPort.port().toLong()));
199 break;
200 case METADATA:
201 MetadataCriterion metadata = (MetadataCriterion) c;
202 mBuilder.setExact(MatchField.METADATA,
203 OFMetadata.ofRaw(metadata.metadata()));
alshabibeec3a062014-09-17 18:01:26 -0700204 break;
alshabibeec3a062014-09-17 18:01:26 -0700205 case ETH_DST:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800206 ethCriterion = (EthCriterion) c;
207 mBuilder.setExact(MatchField.ETH_DST,
208 MacAddress.of(ethCriterion.mac().toLong()));
209 break;
210 case ETH_SRC:
211 ethCriterion = (EthCriterion) c;
212 mBuilder.setExact(MatchField.ETH_SRC,
213 MacAddress.of(ethCriterion.mac().toLong()));
alshabibeec3a062014-09-17 18:01:26 -0700214 break;
215 case ETH_TYPE:
216 EthTypeCriterion ethType = (EthTypeCriterion) c;
alshabibcaf1ca22015-06-25 15:18:16 -0700217 mBuilder.setExact(MatchField.ETH_TYPE, EthType.of(ethType.ethType().toShort()));
alshabibeec3a062014-09-17 18:01:26 -0700218 break;
alshabibeec3a062014-09-17 18:01:26 -0700219 case VLAN_VID:
220 VlanIdCriterion vid = (VlanIdCriterion) c;
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800221
222 if (vid.vlanId().equals(VlanId.ANY)) {
223 mBuilder.setMasked(MatchField.VLAN_VID, OFVlanVidMatch.PRESENT,
224 OFVlanVidMatch.PRESENT);
Jonathan Hart1468fee2015-07-16 18:50:34 -0700225 } else if (vid.vlanId().equals(VlanId.NONE)) {
226 mBuilder.setExact(MatchField.VLAN_VID, OFVlanVidMatch.NONE);
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800227 } else {
228 mBuilder.setExact(MatchField.VLAN_VID,
alshabib346b5b32015-03-06 00:42:16 -0800229 OFVlanVidMatch.ofVlanVid(VlanVid.ofVlan(vid.vlanId().toShort())));
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800230 }
alshabibeec3a062014-09-17 18:01:26 -0700231 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800232 case VLAN_PCP:
233 VlanPcpCriterion vpcp = (VlanPcpCriterion) c;
234 mBuilder.setExact(MatchField.VLAN_PCP, VlanPcp.of(vpcp.priority()));
235 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800236 case IP_DSCP:
237 IPDscpCriterion ipDscpCriterion = (IPDscpCriterion) c;
238 mBuilder.setExact(MatchField.IP_DSCP,
239 IpDscp.of(ipDscpCriterion.ipDscp()));
240 break;
241 case IP_ECN:
242 IPEcnCriterion ipEcnCriterion = (IPEcnCriterion) c;
243 mBuilder.setExact(MatchField.IP_ECN,
244 IpEcn.of(ipEcnCriterion.ipEcn()));
245 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800246 case IP_PROTO:
247 IPProtocolCriterion p = (IPProtocolCriterion) c;
248 mBuilder.setExact(MatchField.IP_PROTO, IpProtocol.of(p.protocol()));
249 break;
250 case IPV4_SRC:
251 ipCriterion = (IPCriterion) c;
252 ip4Prefix = ipCriterion.ip().getIp4Prefix();
253 if (ip4Prefix.prefixLength() != Ip4Prefix.MAX_MASK_LENGTH) {
254 Ip4Address maskAddr =
255 Ip4Address.makeMaskPrefix(ip4Prefix.prefixLength());
256 Masked<IPv4Address> maskedIp =
257 Masked.of(IPv4Address.of(ip4Prefix.address().toInt()),
258 IPv4Address.of(maskAddr.toInt()));
259 mBuilder.setMasked(MatchField.IPV4_SRC, maskedIp);
260 } else {
261 mBuilder.setExact(MatchField.IPV4_SRC,
262 IPv4Address.of(ip4Prefix.address().toInt()));
263 }
264 break;
265 case IPV4_DST:
266 ipCriterion = (IPCriterion) c;
267 ip4Prefix = ipCriterion.ip().getIp4Prefix();
268 if (ip4Prefix.prefixLength() != Ip4Prefix.MAX_MASK_LENGTH) {
269 Ip4Address maskAddr =
270 Ip4Address.makeMaskPrefix(ip4Prefix.prefixLength());
271 Masked<IPv4Address> maskedIp =
272 Masked.of(IPv4Address.of(ip4Prefix.address().toInt()),
273 IPv4Address.of(maskAddr.toInt()));
274 mBuilder.setMasked(MatchField.IPV4_DST, maskedIp);
275 } else {
276 mBuilder.setExact(MatchField.IPV4_DST,
277 IPv4Address.of(ip4Prefix.address().toInt()));
278 }
Jonathan Hart34bc6142014-10-17 11:00:43 -0700279 break;
280 case TCP_SRC:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800281 tcpPortCriterion = (TcpPortCriterion) c;
282 mBuilder.setExact(MatchField.TCP_SRC,
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700283 TransportPort.of(tcpPortCriterion.tcpPort().toInt()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800284 break;
285 case TCP_DST:
286 tcpPortCriterion = (TcpPortCriterion) c;
287 mBuilder.setExact(MatchField.TCP_DST,
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700288 TransportPort.of(tcpPortCriterion.tcpPort().toInt()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800289 break;
290 case UDP_SRC:
291 udpPortCriterion = (UdpPortCriterion) c;
292 mBuilder.setExact(MatchField.UDP_SRC,
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700293 TransportPort.of(udpPortCriterion.udpPort().toInt()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800294 break;
295 case UDP_DST:
296 udpPortCriterion = (UdpPortCriterion) c;
297 mBuilder.setExact(MatchField.UDP_DST,
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700298 TransportPort.of(udpPortCriterion.udpPort().toInt()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800299 break;
300 case SCTP_SRC:
301 sctpPortCriterion = (SctpPortCriterion) c;
302 mBuilder.setExact(MatchField.SCTP_SRC,
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700303 TransportPort.of(sctpPortCriterion.sctpPort().toInt()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800304 break;
305 case SCTP_DST:
306 sctpPortCriterion = (SctpPortCriterion) c;
307 mBuilder.setExact(MatchField.SCTP_DST,
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700308 TransportPort.of(sctpPortCriterion.sctpPort().toInt()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800309 break;
310 case ICMPV4_TYPE:
311 IcmpTypeCriterion icmpType = (IcmpTypeCriterion) c;
312 mBuilder.setExact(MatchField.ICMPV4_TYPE,
313 ICMPv4Type.of(icmpType.icmpType()));
314 break;
315 case ICMPV4_CODE:
316 IcmpCodeCriterion icmpCode = (IcmpCodeCriterion) c;
317 mBuilder.setExact(MatchField.ICMPV4_CODE,
318 ICMPv4Code.of(icmpCode.icmpCode()));
319 break;
320 case IPV6_SRC:
321 ipCriterion = (IPCriterion) c;
322 ip6Prefix = ipCriterion.ip().getIp6Prefix();
323 if (ip6Prefix.prefixLength() != Ip6Prefix.MAX_MASK_LENGTH) {
324 Ip6Address maskAddr =
325 Ip6Address.makeMaskPrefix(ip6Prefix.prefixLength());
326 Masked<IPv6Address> maskedIp =
327 Masked.of(IPv6Address.of(ip6Prefix.address().toString()),
328 IPv6Address.of(maskAddr.toString()));
329 mBuilder.setMasked(MatchField.IPV6_SRC, maskedIp);
330 } else {
331 mBuilder.setExact(MatchField.IPV6_SRC,
332 IPv6Address.of(ip6Prefix.address().toString()));
333 }
334 break;
335 case IPV6_DST:
336 ipCriterion = (IPCriterion) c;
337 ip6Prefix = ipCriterion.ip().getIp6Prefix();
338 if (ip6Prefix.prefixLength() != Ip6Prefix.MAX_MASK_LENGTH) {
339 Ip6Address maskAddr =
340 Ip6Address.makeMaskPrefix(ip6Prefix.prefixLength());
341 Masked<IPv6Address> maskedIp =
342 Masked.of(IPv6Address.of(ip6Prefix.address().toString()),
343 IPv6Address.of(maskAddr.toString()));
344 mBuilder.setMasked(MatchField.IPV6_DST, maskedIp);
345 } else {
346 mBuilder.setExact(MatchField.IPV6_DST,
347 IPv6Address.of(ip6Prefix.address().toString()));
348 }
349 break;
350 case IPV6_FLABEL:
351 IPv6FlowLabelCriterion flowLabelCriterion =
352 (IPv6FlowLabelCriterion) c;
353 mBuilder.setExact(MatchField.IPV6_FLABEL,
354 IPv6FlowLabel.of(flowLabelCriterion.flowLabel()));
355 break;
356 case ICMPV6_TYPE:
357 Icmpv6TypeCriterion icmpv6Type = (Icmpv6TypeCriterion) c;
358 mBuilder.setExact(MatchField.ICMPV6_TYPE,
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800359 U8.of(icmpv6Type.icmpv6Type()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800360 break;
361 case ICMPV6_CODE:
362 Icmpv6CodeCriterion icmpv6Code = (Icmpv6CodeCriterion) c;
363 mBuilder.setExact(MatchField.ICMPV6_CODE,
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800364 U8.of(icmpv6Code.icmpv6Code()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800365 break;
366 case IPV6_ND_TARGET:
367 IPv6NDTargetAddressCriterion targetAddressCriterion =
368 (IPv6NDTargetAddressCriterion) c;
369 ip6Address = targetAddressCriterion.targetAddress();
370 mBuilder.setExact(MatchField.IPV6_ND_TARGET,
371 IPv6Address.of(ip6Address.toOctets()));
372 break;
373 case IPV6_ND_SLL:
374 llAddressCriterion =
375 (IPv6NDLinkLayerAddressCriterion) c;
376 mBuilder.setExact(MatchField.IPV6_ND_SLL,
377 MacAddress.of(llAddressCriterion.mac().toLong()));
378 break;
379 case IPV6_ND_TLL:
380 llAddressCriterion =
381 (IPv6NDLinkLayerAddressCriterion) c;
382 mBuilder.setExact(MatchField.IPV6_ND_TLL,
383 MacAddress.of(llAddressCriterion.mac().toLong()));
Jonathan Hart34bc6142014-10-17 11:00:43 -0700384 break;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800385 case MPLS_LABEL:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700386 MplsCriterion mp = (MplsCriterion) c;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100387 mBuilder.setExact(MatchField.MPLS_LABEL, U32.of(mp.label().toInt()));
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800388 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800389 case IPV6_EXTHDR:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700390 IPv6ExthdrFlagsCriterion exthdrFlagsCriterion =
391 (IPv6ExthdrFlagsCriterion) c;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800392 mBuilder.setExact(MatchField.IPV6_EXTHDR,
393 U16.of(exthdrFlagsCriterion.exthdrFlags()));
394 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700395 case OCH_SIGID:
Sho SHIMIZUc15ce512015-05-26 16:54:08 -0700396 try {
397 OchSignalCriterion ochSignalCriterion = (OchSignalCriterion) c;
398 OchSignal signal = ochSignalCriterion.lambda();
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700399 byte gridType = OpenFlowValueMapper.lookupGridType(signal.gridType());
400 byte channelSpacing = OpenFlowValueMapper.lookupChannelSpacing(signal.channelSpacing());
Sho SHIMIZUc15ce512015-05-26 16:54:08 -0700401 mBuilder.setExact(MatchField.OCH_SIGID,
402 new CircuitSignalID(gridType, channelSpacing,
403 (short) signal.spacingMultiplier(), (short) signal.slotGranularity()));
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700404 } catch (NoMappingFoundException e) {
Sho SHIMIZUc15ce512015-05-26 16:54:08 -0700405 log.warn(e.getMessage());
406 }
Marc De Leenheer49087752014-10-23 13:54:09 -0700407 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800408 case OCH_SIGTYPE:
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700409 OchSignalTypeCriterion sc = (OchSignalTypeCriterion) c;
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700410 byte signalType = OpenFlowValueMapper.lookupOchSignalType(sc.signalType());
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700411 mBuilder.setExact(MatchField.OCH_SIGTYPE, U8.of(signalType));
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800412 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700413 case TUNNEL_ID:
414 TunnelIdCriterion tunnelId = (TunnelIdCriterion) c;
415 mBuilder.setExact(MatchField.TUNNEL_ID,
416 U64.of(tunnelId.tunnelId()));
417 break;
Saurav Dasffc5bbc2015-08-18 23:30:19 -0700418 case MPLS_BOS:
419 MplsBosCriterion mplsBos = (MplsBosCriterion) c;
420 mBuilder.setExact(MatchField.MPLS_BOS,
421 mplsBos.mplsBos() ? OFBooleanValue.TRUE
422 : OFBooleanValue.FALSE);
423 break;
BitOhenryb40129a2015-11-30 12:41:18 +0800424 case ARP_OP:
425 ArpOpCriterion arpOp = (ArpOpCriterion) c;
426 mBuilder.setExact(MatchField.ARP_OP,
427 ArpOpcode.of(arpOp.arpOp()));
428 break;
BitOhenrya331b182015-11-23 08:39:37 +0800429 case ARP_SHA:
430 arpHaCriterion = (ArpHaCriterion) c;
431 mBuilder.setExact(MatchField.ARP_SHA,
432 MacAddress.of(arpHaCriterion.mac().toLong()));
433 break;
BitOhenry296b4542015-11-24 08:41:58 +0800434 case ARP_SPA:
435 arpPaCriterion = (ArpPaCriterion) c;
436 mBuilder.setExact(MatchField.ARP_SPA,
437 IPv4Address.of(arpPaCriterion.ip().toInt()));
438 break;
BitOhenry76430852015-11-20 19:04:49 +0800439 case ARP_THA:
440 arpHaCriterion = (ArpHaCriterion) c;
441 mBuilder.setExact(MatchField.ARP_THA,
442 MacAddress.of(arpHaCriterion.mac().toLong()));
443 break;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800444 case ARP_TPA:
445 arpPaCriterion = (ArpPaCriterion) c;
446 mBuilder.setExact(MatchField.ARP_TPA,
447 IPv4Address.of(arpPaCriterion.ip().toInt()));
448 break;
alshabibeec3a062014-09-17 18:01:26 -0700449 case MPLS_TC:
450 case PBB_ISID:
alshabibeec3a062014-09-17 18:01:26 -0700451 default:
452 log.warn("Match type {} not yet implemented.", c.type());
453 }
454 }
455 return mBuilder.build();
456 }
457
Jonathan Hart86e59352014-10-22 10:42:16 -0700458 /**
459 * Returns the flow rule for this builder.
460 *
461 * @return the flow rule
462 */
463 protected FlowRule flowRule() {
464 return flowRule;
465 }
alshabib219ebaa2014-09-22 15:41:24 -0700466
Jonathan Hart86e59352014-10-22 10:42:16 -0700467 /**
468 * Returns the factory used for building OpenFlow constructs.
469 *
470 * @return the factory
471 */
472 protected OFFactory factory() {
473 return factory;
474 }
alshabib219ebaa2014-09-22 15:41:24 -0700475
alshabibeec3a062014-09-17 18:01:26 -0700476}