blob: 0dd6b892a9f748ef9fd98007b1b836fb66e0d965 [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;
BitOhenryc1e5fcc2015-11-23 20:47:53 +080028import org.onosproject.net.flow.criteria.ArpPaCriterion;
Saurav Dasffc5bbc2015-08-18 23:30:19 -070029import org.onosproject.net.flow.criteria.Criterion;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070030import org.onosproject.net.flow.criteria.EthCriterion;
31import org.onosproject.net.flow.criteria.EthTypeCriterion;
32import org.onosproject.net.flow.criteria.IPCriterion;
33import org.onosproject.net.flow.criteria.IPDscpCriterion;
34import org.onosproject.net.flow.criteria.IPEcnCriterion;
35import org.onosproject.net.flow.criteria.IPProtocolCriterion;
36import org.onosproject.net.flow.criteria.IPv6ExthdrFlagsCriterion;
37import org.onosproject.net.flow.criteria.IPv6FlowLabelCriterion;
38import org.onosproject.net.flow.criteria.IPv6NDLinkLayerAddressCriterion;
39import org.onosproject.net.flow.criteria.IPv6NDTargetAddressCriterion;
40import org.onosproject.net.flow.criteria.IcmpCodeCriterion;
41import org.onosproject.net.flow.criteria.IcmpTypeCriterion;
42import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion;
43import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070044import org.onosproject.net.flow.criteria.MetadataCriterion;
Saurav Dasffc5bbc2015-08-18 23:30:19 -070045import org.onosproject.net.flow.criteria.MplsBosCriterion;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070046import org.onosproject.net.flow.criteria.MplsCriterion;
Sho SHIMIZUc15ce512015-05-26 16:54:08 -070047import org.onosproject.net.flow.criteria.OchSignalCriterion;
Marc De Leenheerd24420f2015-05-27 09:40:59 -070048import org.onosproject.net.flow.criteria.OchSignalTypeCriterion;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070049import org.onosproject.net.flow.criteria.PortCriterion;
50import org.onosproject.net.flow.criteria.SctpPortCriterion;
51import org.onosproject.net.flow.criteria.TcpPortCriterion;
Hyunsun Moona08c5d02015-07-14 17:53:00 -070052import org.onosproject.net.flow.criteria.TunnelIdCriterion;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070053import org.onosproject.net.flow.criteria.UdpPortCriterion;
54import org.onosproject.net.flow.criteria.VlanIdCriterion;
55import org.onosproject.net.flow.criteria.VlanPcpCriterion;
alshabibeec3a062014-09-17 18:01:26 -070056import org.projectfloodlight.openflow.protocol.OFFactory;
alshabib193525b2014-10-08 18:58:03 -070057import org.projectfloodlight.openflow.protocol.OFFlowAdd;
58import org.projectfloodlight.openflow.protocol.OFFlowDelete;
alshabibeec3a062014-09-17 18:01:26 -070059import org.projectfloodlight.openflow.protocol.OFFlowMod;
alshabibeec3a062014-09-17 18:01:26 -070060import org.projectfloodlight.openflow.protocol.match.Match;
61import org.projectfloodlight.openflow.protocol.match.MatchField;
Marc De Leenheer49087752014-10-23 13:54:09 -070062import org.projectfloodlight.openflow.types.CircuitSignalID;
alshabibeec3a062014-09-17 18:01:26 -070063import org.projectfloodlight.openflow.types.EthType;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080064import org.projectfloodlight.openflow.types.ICMPv4Code;
65import org.projectfloodlight.openflow.types.ICMPv4Type;
alshabibeec3a062014-09-17 18:01:26 -070066import org.projectfloodlight.openflow.types.IPv4Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080067import org.projectfloodlight.openflow.types.IPv6Address;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080068import org.projectfloodlight.openflow.types.IPv6FlowLabel;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080069import org.projectfloodlight.openflow.types.IpDscp;
70import org.projectfloodlight.openflow.types.IpEcn;
alshabibeec3a062014-09-17 18:01:26 -070071import org.projectfloodlight.openflow.types.IpProtocol;
72import org.projectfloodlight.openflow.types.MacAddress;
73import org.projectfloodlight.openflow.types.Masked;
Saurav Dasffc5bbc2015-08-18 23:30:19 -070074import org.projectfloodlight.openflow.types.OFBooleanValue;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080075import org.projectfloodlight.openflow.types.OFMetadata;
alshabibeec3a062014-09-17 18:01:26 -070076import org.projectfloodlight.openflow.types.OFPort;
77import org.projectfloodlight.openflow.types.OFVlanVidMatch;
Jonathan Hart34bc6142014-10-17 11:00:43 -070078import org.projectfloodlight.openflow.types.TransportPort;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -080079import org.projectfloodlight.openflow.types.U16;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -080080import org.projectfloodlight.openflow.types.U32;
Hyunsun Moona08c5d02015-07-14 17:53:00 -070081import org.projectfloodlight.openflow.types.U64;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -080082import org.projectfloodlight.openflow.types.U8;
alshabibeec3a062014-09-17 18:01:26 -070083import org.projectfloodlight.openflow.types.VlanPcp;
84import org.projectfloodlight.openflow.types.VlanVid;
85import org.slf4j.Logger;
86
Jonathan Hart3c259162015-10-21 21:31:19 -070087import java.util.Optional;
88
89import static org.slf4j.LoggerFactory.getLogger;
90
Jonathan Hart86e59352014-10-22 10:42:16 -070091/**
92 * Builder for OpenFlow flow mods based on FlowRules.
93 */
94public abstract class FlowModBuilder {
alshabibeec3a062014-09-17 18:01:26 -070095
96 private final Logger log = getLogger(getClass());
97
98 private final OFFactory factory;
Jonathan Hart86e59352014-10-22 10:42:16 -070099 private final FlowRule flowRule;
alshabibeec3a062014-09-17 18:01:26 -0700100 private final TrafficSelector selector;
Brian O'Connor427a1762014-11-19 18:40:32 -0800101 protected final Long xid;
Jonathan Hart3c259162015-10-21 21:31:19 -0700102 protected final Optional<DriverService> driverService;
alshabibeec3a062014-09-17 18:01:26 -0700103
Jonathan Hart86e59352014-10-22 10:42:16 -0700104 /**
105 * Creates a new flow mod builder.
106 *
107 * @param flowRule the flow rule to transform into a flow mod
108 * @param factory the OpenFlow factory to use to build the flow mod
Pavlin Radoslavov119fd5c2014-11-25 19:08:19 -0800109 * @param xid the transaction ID
Charles Chan30ba4002015-11-05 14:45:16 -0800110 * @param driverService the device driver service
Jonathan Hart86e59352014-10-22 10:42:16 -0700111 * @return the new flow mod builder
112 */
Brian O'Connor427a1762014-11-19 18:40:32 -0800113 public static FlowModBuilder builder(FlowRule flowRule,
alshabib9af70072015-02-09 14:34:16 -0800114 OFFactory factory,
Jonathan Hart3c259162015-10-21 21:31:19 -0700115 Optional<Long> xid,
116 Optional<DriverService> driverService) {
Jonathan Hart86e59352014-10-22 10:42:16 -0700117 switch (factory.getVersion()) {
118 case OF_10:
Jonathan Hart3c259162015-10-21 21:31:19 -0700119 return new FlowModBuilderVer10(flowRule, factory, xid, driverService);
Jonathan Hart86e59352014-10-22 10:42:16 -0700120 case OF_13:
Jonathan Hart3c259162015-10-21 21:31:19 -0700121 return new FlowModBuilderVer13(flowRule, factory, xid, driverService);
Jonathan Hart86e59352014-10-22 10:42:16 -0700122 default:
123 throw new UnsupportedOperationException(
124 "No flow mod builder for protocol version " + factory.getVersion());
125 }
126 }
alshabibeec3a062014-09-17 18:01:26 -0700127
Jonathan Hart86e59352014-10-22 10:42:16 -0700128 /**
129 * Constructs a flow mod builder.
130 *
131 * @param flowRule the flow rule to transform into a flow mod
132 * @param factory the OpenFlow factory to use to build the flow mod
Charles Chan30ba4002015-11-05 14:45:16 -0800133 * @param driverService the device driver service
Pavlin Radoslavov119fd5c2014-11-25 19:08:19 -0800134 * @param xid the transaction ID
Jonathan Hart86e59352014-10-22 10:42:16 -0700135 */
Jonathan Hart3c259162015-10-21 21:31:19 -0700136 protected FlowModBuilder(FlowRule flowRule, OFFactory factory, Optional<Long> xid,
137 Optional<DriverService> driverService) {
alshabibeec3a062014-09-17 18:01:26 -0700138 this.factory = factory;
Jonathan Hart86e59352014-10-22 10:42:16 -0700139 this.flowRule = flowRule;
alshabibeec3a062014-09-17 18:01:26 -0700140 this.selector = flowRule.selector();
Sho SHIMIZUc14b2a22015-05-05 18:15:13 -0700141 this.xid = xid.orElse(0L);
Jonathan Hart3c259162015-10-21 21:31:19 -0700142 this.driverService = driverService;
alshabibeec3a062014-09-17 18:01:26 -0700143 }
144
Jonathan Hart86e59352014-10-22 10:42:16 -0700145 /**
146 * Builds an ADD flow mod.
147 *
148 * @return the flow mod
149 */
150 public abstract OFFlowAdd buildFlowAdd();
alshabibeec3a062014-09-17 18:01:26 -0700151
Jonathan Hart86e59352014-10-22 10:42:16 -0700152 /**
153 * Builds a MODIFY flow mod.
154 *
155 * @return the flow mod
156 */
157 public abstract OFFlowMod buildFlowMod();
alshabibeec3a062014-09-17 18:01:26 -0700158
Jonathan Hart86e59352014-10-22 10:42:16 -0700159 /**
160 * Builds a DELETE flow mod.
161 *
162 * @return the flow mod
163 */
164 public abstract OFFlowDelete buildFlowDel();
alshabibeec3a062014-09-17 18:01:26 -0700165
Jonathan Hart86e59352014-10-22 10:42:16 -0700166 /**
167 * Builds the match for the flow mod.
168 *
169 * @return the match
170 */
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800171 // CHECKSTYLE IGNORE MethodLength FOR NEXT 300 LINES
Jonathan Hart86e59352014-10-22 10:42:16 -0700172 protected Match buildMatch() {
alshabibeec3a062014-09-17 18:01:26 -0700173 Match.Builder mBuilder = factory.buildMatch();
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800174 Ip6Address ip6Address;
Pavlin Radoslavov23e398d2014-11-05 15:17:57 -0800175 Ip4Prefix ip4Prefix;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800176 Ip6Prefix ip6Prefix;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800177 EthCriterion ethCriterion;
178 IPCriterion ipCriterion;
179 TcpPortCriterion tcpPortCriterion;
180 UdpPortCriterion udpPortCriterion;
181 SctpPortCriterion sctpPortCriterion;
182 IPv6NDLinkLayerAddressCriterion llAddressCriterion;
BitOhenry76430852015-11-20 19:04:49 +0800183 ArpHaCriterion arpHaCriterion;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800184 ArpPaCriterion arpPaCriterion;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800185
alshabibeec3a062014-09-17 18:01:26 -0700186 for (Criterion c : selector.criteria()) {
187 switch (c.type()) {
188 case IN_PORT:
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800189 PortCriterion inPort = (PortCriterion) c;
190 mBuilder.setExact(MatchField.IN_PORT,
191 OFPort.of((int) inPort.port().toLong()));
192 break;
193 case IN_PHY_PORT:
194 PortCriterion inPhyPort = (PortCriterion) c;
195 mBuilder.setExact(MatchField.IN_PORT,
196 OFPort.of((int) inPhyPort.port().toLong()));
197 break;
198 case METADATA:
199 MetadataCriterion metadata = (MetadataCriterion) c;
200 mBuilder.setExact(MatchField.METADATA,
201 OFMetadata.ofRaw(metadata.metadata()));
alshabibeec3a062014-09-17 18:01:26 -0700202 break;
alshabibeec3a062014-09-17 18:01:26 -0700203 case ETH_DST:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800204 ethCriterion = (EthCriterion) c;
205 mBuilder.setExact(MatchField.ETH_DST,
206 MacAddress.of(ethCriterion.mac().toLong()));
207 break;
208 case ETH_SRC:
209 ethCriterion = (EthCriterion) c;
210 mBuilder.setExact(MatchField.ETH_SRC,
211 MacAddress.of(ethCriterion.mac().toLong()));
alshabibeec3a062014-09-17 18:01:26 -0700212 break;
213 case ETH_TYPE:
214 EthTypeCriterion ethType = (EthTypeCriterion) c;
alshabibcaf1ca22015-06-25 15:18:16 -0700215 mBuilder.setExact(MatchField.ETH_TYPE, EthType.of(ethType.ethType().toShort()));
alshabibeec3a062014-09-17 18:01:26 -0700216 break;
alshabibeec3a062014-09-17 18:01:26 -0700217 case VLAN_VID:
218 VlanIdCriterion vid = (VlanIdCriterion) c;
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800219
220 if (vid.vlanId().equals(VlanId.ANY)) {
221 mBuilder.setMasked(MatchField.VLAN_VID, OFVlanVidMatch.PRESENT,
222 OFVlanVidMatch.PRESENT);
Jonathan Hart1468fee2015-07-16 18:50:34 -0700223 } else if (vid.vlanId().equals(VlanId.NONE)) {
224 mBuilder.setExact(MatchField.VLAN_VID, OFVlanVidMatch.NONE);
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800225 } else {
226 mBuilder.setExact(MatchField.VLAN_VID,
alshabib346b5b32015-03-06 00:42:16 -0800227 OFVlanVidMatch.ofVlanVid(VlanVid.ofVlan(vid.vlanId().toShort())));
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800228 }
alshabibeec3a062014-09-17 18:01:26 -0700229 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800230 case VLAN_PCP:
231 VlanPcpCriterion vpcp = (VlanPcpCriterion) c;
232 mBuilder.setExact(MatchField.VLAN_PCP, VlanPcp.of(vpcp.priority()));
233 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800234 case IP_DSCP:
235 IPDscpCriterion ipDscpCriterion = (IPDscpCriterion) c;
236 mBuilder.setExact(MatchField.IP_DSCP,
237 IpDscp.of(ipDscpCriterion.ipDscp()));
238 break;
239 case IP_ECN:
240 IPEcnCriterion ipEcnCriterion = (IPEcnCriterion) c;
241 mBuilder.setExact(MatchField.IP_ECN,
242 IpEcn.of(ipEcnCriterion.ipEcn()));
243 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800244 case IP_PROTO:
245 IPProtocolCriterion p = (IPProtocolCriterion) c;
246 mBuilder.setExact(MatchField.IP_PROTO, IpProtocol.of(p.protocol()));
247 break;
248 case IPV4_SRC:
249 ipCriterion = (IPCriterion) c;
250 ip4Prefix = ipCriterion.ip().getIp4Prefix();
251 if (ip4Prefix.prefixLength() != Ip4Prefix.MAX_MASK_LENGTH) {
252 Ip4Address maskAddr =
253 Ip4Address.makeMaskPrefix(ip4Prefix.prefixLength());
254 Masked<IPv4Address> maskedIp =
255 Masked.of(IPv4Address.of(ip4Prefix.address().toInt()),
256 IPv4Address.of(maskAddr.toInt()));
257 mBuilder.setMasked(MatchField.IPV4_SRC, maskedIp);
258 } else {
259 mBuilder.setExact(MatchField.IPV4_SRC,
260 IPv4Address.of(ip4Prefix.address().toInt()));
261 }
262 break;
263 case IPV4_DST:
264 ipCriterion = (IPCriterion) c;
265 ip4Prefix = ipCriterion.ip().getIp4Prefix();
266 if (ip4Prefix.prefixLength() != Ip4Prefix.MAX_MASK_LENGTH) {
267 Ip4Address maskAddr =
268 Ip4Address.makeMaskPrefix(ip4Prefix.prefixLength());
269 Masked<IPv4Address> maskedIp =
270 Masked.of(IPv4Address.of(ip4Prefix.address().toInt()),
271 IPv4Address.of(maskAddr.toInt()));
272 mBuilder.setMasked(MatchField.IPV4_DST, maskedIp);
273 } else {
274 mBuilder.setExact(MatchField.IPV4_DST,
275 IPv4Address.of(ip4Prefix.address().toInt()));
276 }
Jonathan Hart34bc6142014-10-17 11:00:43 -0700277 break;
278 case TCP_SRC:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800279 tcpPortCriterion = (TcpPortCriterion) c;
280 mBuilder.setExact(MatchField.TCP_SRC,
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700281 TransportPort.of(tcpPortCriterion.tcpPort().toInt()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800282 break;
283 case TCP_DST:
284 tcpPortCriterion = (TcpPortCriterion) c;
285 mBuilder.setExact(MatchField.TCP_DST,
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700286 TransportPort.of(tcpPortCriterion.tcpPort().toInt()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800287 break;
288 case UDP_SRC:
289 udpPortCriterion = (UdpPortCriterion) c;
290 mBuilder.setExact(MatchField.UDP_SRC,
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700291 TransportPort.of(udpPortCriterion.udpPort().toInt()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800292 break;
293 case UDP_DST:
294 udpPortCriterion = (UdpPortCriterion) c;
295 mBuilder.setExact(MatchField.UDP_DST,
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700296 TransportPort.of(udpPortCriterion.udpPort().toInt()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800297 break;
298 case SCTP_SRC:
299 sctpPortCriterion = (SctpPortCriterion) c;
300 mBuilder.setExact(MatchField.SCTP_SRC,
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700301 TransportPort.of(sctpPortCriterion.sctpPort().toInt()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800302 break;
303 case SCTP_DST:
304 sctpPortCriterion = (SctpPortCriterion) c;
305 mBuilder.setExact(MatchField.SCTP_DST,
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700306 TransportPort.of(sctpPortCriterion.sctpPort().toInt()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800307 break;
308 case ICMPV4_TYPE:
309 IcmpTypeCriterion icmpType = (IcmpTypeCriterion) c;
310 mBuilder.setExact(MatchField.ICMPV4_TYPE,
311 ICMPv4Type.of(icmpType.icmpType()));
312 break;
313 case ICMPV4_CODE:
314 IcmpCodeCriterion icmpCode = (IcmpCodeCriterion) c;
315 mBuilder.setExact(MatchField.ICMPV4_CODE,
316 ICMPv4Code.of(icmpCode.icmpCode()));
317 break;
318 case IPV6_SRC:
319 ipCriterion = (IPCriterion) c;
320 ip6Prefix = ipCriterion.ip().getIp6Prefix();
321 if (ip6Prefix.prefixLength() != Ip6Prefix.MAX_MASK_LENGTH) {
322 Ip6Address maskAddr =
323 Ip6Address.makeMaskPrefix(ip6Prefix.prefixLength());
324 Masked<IPv6Address> maskedIp =
325 Masked.of(IPv6Address.of(ip6Prefix.address().toString()),
326 IPv6Address.of(maskAddr.toString()));
327 mBuilder.setMasked(MatchField.IPV6_SRC, maskedIp);
328 } else {
329 mBuilder.setExact(MatchField.IPV6_SRC,
330 IPv6Address.of(ip6Prefix.address().toString()));
331 }
332 break;
333 case IPV6_DST:
334 ipCriterion = (IPCriterion) c;
335 ip6Prefix = ipCriterion.ip().getIp6Prefix();
336 if (ip6Prefix.prefixLength() != Ip6Prefix.MAX_MASK_LENGTH) {
337 Ip6Address maskAddr =
338 Ip6Address.makeMaskPrefix(ip6Prefix.prefixLength());
339 Masked<IPv6Address> maskedIp =
340 Masked.of(IPv6Address.of(ip6Prefix.address().toString()),
341 IPv6Address.of(maskAddr.toString()));
342 mBuilder.setMasked(MatchField.IPV6_DST, maskedIp);
343 } else {
344 mBuilder.setExact(MatchField.IPV6_DST,
345 IPv6Address.of(ip6Prefix.address().toString()));
346 }
347 break;
348 case IPV6_FLABEL:
349 IPv6FlowLabelCriterion flowLabelCriterion =
350 (IPv6FlowLabelCriterion) c;
351 mBuilder.setExact(MatchField.IPV6_FLABEL,
352 IPv6FlowLabel.of(flowLabelCriterion.flowLabel()));
353 break;
354 case ICMPV6_TYPE:
355 Icmpv6TypeCriterion icmpv6Type = (Icmpv6TypeCriterion) c;
356 mBuilder.setExact(MatchField.ICMPV6_TYPE,
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800357 U8.of(icmpv6Type.icmpv6Type()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800358 break;
359 case ICMPV6_CODE:
360 Icmpv6CodeCriterion icmpv6Code = (Icmpv6CodeCriterion) c;
361 mBuilder.setExact(MatchField.ICMPV6_CODE,
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800362 U8.of(icmpv6Code.icmpv6Code()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800363 break;
364 case IPV6_ND_TARGET:
365 IPv6NDTargetAddressCriterion targetAddressCriterion =
366 (IPv6NDTargetAddressCriterion) c;
367 ip6Address = targetAddressCriterion.targetAddress();
368 mBuilder.setExact(MatchField.IPV6_ND_TARGET,
369 IPv6Address.of(ip6Address.toOctets()));
370 break;
371 case IPV6_ND_SLL:
372 llAddressCriterion =
373 (IPv6NDLinkLayerAddressCriterion) c;
374 mBuilder.setExact(MatchField.IPV6_ND_SLL,
375 MacAddress.of(llAddressCriterion.mac().toLong()));
376 break;
377 case IPV6_ND_TLL:
378 llAddressCriterion =
379 (IPv6NDLinkLayerAddressCriterion) c;
380 mBuilder.setExact(MatchField.IPV6_ND_TLL,
381 MacAddress.of(llAddressCriterion.mac().toLong()));
Jonathan Hart34bc6142014-10-17 11:00:43 -0700382 break;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800383 case MPLS_LABEL:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700384 MplsCriterion mp = (MplsCriterion) c;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100385 mBuilder.setExact(MatchField.MPLS_LABEL, U32.of(mp.label().toInt()));
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800386 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800387 case IPV6_EXTHDR:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700388 IPv6ExthdrFlagsCriterion exthdrFlagsCriterion =
389 (IPv6ExthdrFlagsCriterion) c;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800390 mBuilder.setExact(MatchField.IPV6_EXTHDR,
391 U16.of(exthdrFlagsCriterion.exthdrFlags()));
392 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700393 case OCH_SIGID:
Sho SHIMIZUc15ce512015-05-26 16:54:08 -0700394 try {
395 OchSignalCriterion ochSignalCriterion = (OchSignalCriterion) c;
396 OchSignal signal = ochSignalCriterion.lambda();
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700397 byte gridType = OpenFlowValueMapper.lookupGridType(signal.gridType());
398 byte channelSpacing = OpenFlowValueMapper.lookupChannelSpacing(signal.channelSpacing());
Sho SHIMIZUc15ce512015-05-26 16:54:08 -0700399 mBuilder.setExact(MatchField.OCH_SIGID,
400 new CircuitSignalID(gridType, channelSpacing,
401 (short) signal.spacingMultiplier(), (short) signal.slotGranularity()));
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700402 } catch (NoMappingFoundException e) {
Sho SHIMIZUc15ce512015-05-26 16:54:08 -0700403 log.warn(e.getMessage());
404 }
Marc De Leenheer49087752014-10-23 13:54:09 -0700405 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800406 case OCH_SIGTYPE:
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700407 OchSignalTypeCriterion sc = (OchSignalTypeCriterion) c;
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700408 byte signalType = OpenFlowValueMapper.lookupOchSignalType(sc.signalType());
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700409 mBuilder.setExact(MatchField.OCH_SIGTYPE, U8.of(signalType));
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800410 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700411 case TUNNEL_ID:
412 TunnelIdCriterion tunnelId = (TunnelIdCriterion) c;
413 mBuilder.setExact(MatchField.TUNNEL_ID,
414 U64.of(tunnelId.tunnelId()));
415 break;
Saurav Dasffc5bbc2015-08-18 23:30:19 -0700416 case MPLS_BOS:
417 MplsBosCriterion mplsBos = (MplsBosCriterion) c;
418 mBuilder.setExact(MatchField.MPLS_BOS,
419 mplsBos.mplsBos() ? OFBooleanValue.TRUE
420 : OFBooleanValue.FALSE);
421 break;
BitOhenrya331b182015-11-23 08:39:37 +0800422 case ARP_SHA:
423 arpHaCriterion = (ArpHaCriterion) c;
424 mBuilder.setExact(MatchField.ARP_SHA,
425 MacAddress.of(arpHaCriterion.mac().toLong()));
426 break;
BitOhenry296b4542015-11-24 08:41:58 +0800427 case ARP_SPA:
428 arpPaCriterion = (ArpPaCriterion) c;
429 mBuilder.setExact(MatchField.ARP_SPA,
430 IPv4Address.of(arpPaCriterion.ip().toInt()));
431 break;
BitOhenry76430852015-11-20 19:04:49 +0800432 case ARP_THA:
433 arpHaCriterion = (ArpHaCriterion) c;
434 mBuilder.setExact(MatchField.ARP_THA,
435 MacAddress.of(arpHaCriterion.mac().toLong()));
436 break;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800437 case ARP_TPA:
438 arpPaCriterion = (ArpPaCriterion) c;
439 mBuilder.setExact(MatchField.ARP_TPA,
440 IPv4Address.of(arpPaCriterion.ip().toInt()));
441 break;
alshabibeec3a062014-09-17 18:01:26 -0700442 case ARP_OP:
alshabibeec3a062014-09-17 18:01:26 -0700443 case MPLS_TC:
444 case PBB_ISID:
alshabibeec3a062014-09-17 18:01:26 -0700445 default:
446 log.warn("Match type {} not yet implemented.", c.type());
447 }
448 }
449 return mBuilder.build();
450 }
451
Jonathan Hart86e59352014-10-22 10:42:16 -0700452 /**
453 * Returns the flow rule for this builder.
454 *
455 * @return the flow rule
456 */
457 protected FlowRule flowRule() {
458 return flowRule;
459 }
alshabib219ebaa2014-09-22 15:41:24 -0700460
Jonathan Hart86e59352014-10-22 10:42:16 -0700461 /**
462 * Returns the factory used for building OpenFlow constructs.
463 *
464 * @return the factory
465 */
466 protected OFFactory factory() {
467 return factory;
468 }
alshabib219ebaa2014-09-22 15:41:24 -0700469
alshabibeec3a062014-09-17 18:01:26 -0700470}