blob: c5de72a80348f3733570f7e3cf61a8733fe08437 [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;
Saurav Dasffc5bbc2015-08-18 23:30:19 -070028import org.onosproject.net.flow.criteria.Criterion;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070029import org.onosproject.net.flow.criteria.EthCriterion;
30import org.onosproject.net.flow.criteria.EthTypeCriterion;
31import org.onosproject.net.flow.criteria.IPCriterion;
32import org.onosproject.net.flow.criteria.IPDscpCriterion;
33import org.onosproject.net.flow.criteria.IPEcnCriterion;
34import org.onosproject.net.flow.criteria.IPProtocolCriterion;
35import org.onosproject.net.flow.criteria.IPv6ExthdrFlagsCriterion;
36import org.onosproject.net.flow.criteria.IPv6FlowLabelCriterion;
37import org.onosproject.net.flow.criteria.IPv6NDLinkLayerAddressCriterion;
38import org.onosproject.net.flow.criteria.IPv6NDTargetAddressCriterion;
39import org.onosproject.net.flow.criteria.IcmpCodeCriterion;
40import org.onosproject.net.flow.criteria.IcmpTypeCriterion;
41import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion;
42import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070043import org.onosproject.net.flow.criteria.MetadataCriterion;
Saurav Dasffc5bbc2015-08-18 23:30:19 -070044import org.onosproject.net.flow.criteria.MplsBosCriterion;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070045import org.onosproject.net.flow.criteria.MplsCriterion;
Sho SHIMIZUc15ce512015-05-26 16:54:08 -070046import org.onosproject.net.flow.criteria.OchSignalCriterion;
Marc De Leenheerd24420f2015-05-27 09:40:59 -070047import org.onosproject.net.flow.criteria.OchSignalTypeCriterion;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070048import org.onosproject.net.flow.criteria.PortCriterion;
49import org.onosproject.net.flow.criteria.SctpPortCriterion;
50import org.onosproject.net.flow.criteria.TcpPortCriterion;
Hyunsun Moona08c5d02015-07-14 17:53:00 -070051import org.onosproject.net.flow.criteria.TunnelIdCriterion;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070052import org.onosproject.net.flow.criteria.UdpPortCriterion;
53import org.onosproject.net.flow.criteria.VlanIdCriterion;
54import org.onosproject.net.flow.criteria.VlanPcpCriterion;
alshabibeec3a062014-09-17 18:01:26 -070055import org.projectfloodlight.openflow.protocol.OFFactory;
alshabib193525b2014-10-08 18:58:03 -070056import org.projectfloodlight.openflow.protocol.OFFlowAdd;
57import org.projectfloodlight.openflow.protocol.OFFlowDelete;
alshabibeec3a062014-09-17 18:01:26 -070058import org.projectfloodlight.openflow.protocol.OFFlowMod;
alshabibeec3a062014-09-17 18:01:26 -070059import org.projectfloodlight.openflow.protocol.match.Match;
60import org.projectfloodlight.openflow.protocol.match.MatchField;
Marc De Leenheer49087752014-10-23 13:54:09 -070061import org.projectfloodlight.openflow.types.CircuitSignalID;
alshabibeec3a062014-09-17 18:01:26 -070062import org.projectfloodlight.openflow.types.EthType;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080063import org.projectfloodlight.openflow.types.ICMPv4Code;
64import org.projectfloodlight.openflow.types.ICMPv4Type;
alshabibeec3a062014-09-17 18:01:26 -070065import org.projectfloodlight.openflow.types.IPv4Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080066import org.projectfloodlight.openflow.types.IPv6Address;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080067import org.projectfloodlight.openflow.types.IPv6FlowLabel;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080068import org.projectfloodlight.openflow.types.IpDscp;
69import org.projectfloodlight.openflow.types.IpEcn;
alshabibeec3a062014-09-17 18:01:26 -070070import org.projectfloodlight.openflow.types.IpProtocol;
71import org.projectfloodlight.openflow.types.MacAddress;
72import org.projectfloodlight.openflow.types.Masked;
Saurav Dasffc5bbc2015-08-18 23:30:19 -070073import org.projectfloodlight.openflow.types.OFBooleanValue;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080074import org.projectfloodlight.openflow.types.OFMetadata;
alshabibeec3a062014-09-17 18:01:26 -070075import org.projectfloodlight.openflow.types.OFPort;
76import org.projectfloodlight.openflow.types.OFVlanVidMatch;
Jonathan Hart34bc6142014-10-17 11:00:43 -070077import org.projectfloodlight.openflow.types.TransportPort;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -080078import org.projectfloodlight.openflow.types.U16;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -080079import org.projectfloodlight.openflow.types.U32;
Hyunsun Moona08c5d02015-07-14 17:53:00 -070080import org.projectfloodlight.openflow.types.U64;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -080081import org.projectfloodlight.openflow.types.U8;
alshabibeec3a062014-09-17 18:01:26 -070082import org.projectfloodlight.openflow.types.VlanPcp;
83import org.projectfloodlight.openflow.types.VlanVid;
84import org.slf4j.Logger;
85
Jonathan Hart3c259162015-10-21 21:31:19 -070086import java.util.Optional;
87
88import static org.slf4j.LoggerFactory.getLogger;
89
Jonathan Hart86e59352014-10-22 10:42:16 -070090/**
91 * Builder for OpenFlow flow mods based on FlowRules.
92 */
93public abstract class FlowModBuilder {
alshabibeec3a062014-09-17 18:01:26 -070094
95 private final Logger log = getLogger(getClass());
96
97 private final OFFactory factory;
Jonathan Hart86e59352014-10-22 10:42:16 -070098 private final FlowRule flowRule;
alshabibeec3a062014-09-17 18:01:26 -070099 private final TrafficSelector selector;
Brian O'Connor427a1762014-11-19 18:40:32 -0800100 protected final Long xid;
Jonathan Hart3c259162015-10-21 21:31:19 -0700101 protected final Optional<DriverService> driverService;
alshabibeec3a062014-09-17 18:01:26 -0700102
Jonathan Hart86e59352014-10-22 10:42:16 -0700103 /**
104 * Creates a new flow mod builder.
105 *
106 * @param flowRule the flow rule to transform into a flow mod
107 * @param factory the OpenFlow factory to use to build the flow mod
Pavlin Radoslavov119fd5c2014-11-25 19:08:19 -0800108 * @param xid the transaction ID
Charles Chan30ba4002015-11-05 14:45:16 -0800109 * @param driverService the device driver service
Jonathan Hart86e59352014-10-22 10:42:16 -0700110 * @return the new flow mod builder
111 */
Brian O'Connor427a1762014-11-19 18:40:32 -0800112 public static FlowModBuilder builder(FlowRule flowRule,
alshabib9af70072015-02-09 14:34:16 -0800113 OFFactory factory,
Jonathan Hart3c259162015-10-21 21:31:19 -0700114 Optional<Long> xid,
115 Optional<DriverService> driverService) {
Jonathan Hart86e59352014-10-22 10:42:16 -0700116 switch (factory.getVersion()) {
117 case OF_10:
Jonathan Hart3c259162015-10-21 21:31:19 -0700118 return new FlowModBuilderVer10(flowRule, factory, xid, driverService);
Jonathan Hart86e59352014-10-22 10:42:16 -0700119 case OF_13:
Jonathan Hart3c259162015-10-21 21:31:19 -0700120 return new FlowModBuilderVer13(flowRule, factory, xid, driverService);
Jonathan Hart86e59352014-10-22 10:42:16 -0700121 default:
122 throw new UnsupportedOperationException(
123 "No flow mod builder for protocol version " + factory.getVersion());
124 }
125 }
alshabibeec3a062014-09-17 18:01:26 -0700126
Jonathan Hart86e59352014-10-22 10:42:16 -0700127 /**
128 * Constructs a flow mod builder.
129 *
130 * @param flowRule the flow rule to transform into a flow mod
131 * @param factory the OpenFlow factory to use to build the flow mod
Charles Chan30ba4002015-11-05 14:45:16 -0800132 * @param driverService the device driver service
Pavlin Radoslavov119fd5c2014-11-25 19:08:19 -0800133 * @param xid the transaction ID
Jonathan Hart86e59352014-10-22 10:42:16 -0700134 */
Jonathan Hart3c259162015-10-21 21:31:19 -0700135 protected FlowModBuilder(FlowRule flowRule, OFFactory factory, Optional<Long> xid,
136 Optional<DriverService> driverService) {
alshabibeec3a062014-09-17 18:01:26 -0700137 this.factory = factory;
Jonathan Hart86e59352014-10-22 10:42:16 -0700138 this.flowRule = flowRule;
alshabibeec3a062014-09-17 18:01:26 -0700139 this.selector = flowRule.selector();
Sho SHIMIZUc14b2a22015-05-05 18:15:13 -0700140 this.xid = xid.orElse(0L);
Jonathan Hart3c259162015-10-21 21:31:19 -0700141 this.driverService = driverService;
alshabibeec3a062014-09-17 18:01:26 -0700142 }
143
Jonathan Hart86e59352014-10-22 10:42:16 -0700144 /**
145 * Builds an ADD flow mod.
146 *
147 * @return the flow mod
148 */
149 public abstract OFFlowAdd buildFlowAdd();
alshabibeec3a062014-09-17 18:01:26 -0700150
Jonathan Hart86e59352014-10-22 10:42:16 -0700151 /**
152 * Builds a MODIFY flow mod.
153 *
154 * @return the flow mod
155 */
156 public abstract OFFlowMod buildFlowMod();
alshabibeec3a062014-09-17 18:01:26 -0700157
Jonathan Hart86e59352014-10-22 10:42:16 -0700158 /**
159 * Builds a DELETE flow mod.
160 *
161 * @return the flow mod
162 */
163 public abstract OFFlowDelete buildFlowDel();
alshabibeec3a062014-09-17 18:01:26 -0700164
Jonathan Hart86e59352014-10-22 10:42:16 -0700165 /**
166 * Builds the match for the flow mod.
167 *
168 * @return the match
169 */
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800170 // CHECKSTYLE IGNORE MethodLength FOR NEXT 300 LINES
Jonathan Hart86e59352014-10-22 10:42:16 -0700171 protected Match buildMatch() {
alshabibeec3a062014-09-17 18:01:26 -0700172 Match.Builder mBuilder = factory.buildMatch();
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800173 Ip6Address ip6Address;
Pavlin Radoslavov23e398d2014-11-05 15:17:57 -0800174 Ip4Prefix ip4Prefix;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800175 Ip6Prefix ip6Prefix;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800176 EthCriterion ethCriterion;
177 IPCriterion ipCriterion;
178 TcpPortCriterion tcpPortCriterion;
179 UdpPortCriterion udpPortCriterion;
180 SctpPortCriterion sctpPortCriterion;
181 IPv6NDLinkLayerAddressCriterion llAddressCriterion;
BitOhenry76430852015-11-20 19:04:49 +0800182 ArpHaCriterion arpHaCriterion;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800183
alshabibeec3a062014-09-17 18:01:26 -0700184 for (Criterion c : selector.criteria()) {
185 switch (c.type()) {
186 case IN_PORT:
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800187 PortCriterion inPort = (PortCriterion) c;
188 mBuilder.setExact(MatchField.IN_PORT,
189 OFPort.of((int) inPort.port().toLong()));
190 break;
191 case IN_PHY_PORT:
192 PortCriterion inPhyPort = (PortCriterion) c;
193 mBuilder.setExact(MatchField.IN_PORT,
194 OFPort.of((int) inPhyPort.port().toLong()));
195 break;
196 case METADATA:
197 MetadataCriterion metadata = (MetadataCriterion) c;
198 mBuilder.setExact(MatchField.METADATA,
199 OFMetadata.ofRaw(metadata.metadata()));
alshabibeec3a062014-09-17 18:01:26 -0700200 break;
alshabibeec3a062014-09-17 18:01:26 -0700201 case ETH_DST:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800202 ethCriterion = (EthCriterion) c;
203 mBuilder.setExact(MatchField.ETH_DST,
204 MacAddress.of(ethCriterion.mac().toLong()));
205 break;
206 case ETH_SRC:
207 ethCriterion = (EthCriterion) c;
208 mBuilder.setExact(MatchField.ETH_SRC,
209 MacAddress.of(ethCriterion.mac().toLong()));
alshabibeec3a062014-09-17 18:01:26 -0700210 break;
211 case ETH_TYPE:
212 EthTypeCriterion ethType = (EthTypeCriterion) c;
alshabibcaf1ca22015-06-25 15:18:16 -0700213 mBuilder.setExact(MatchField.ETH_TYPE, EthType.of(ethType.ethType().toShort()));
alshabibeec3a062014-09-17 18:01:26 -0700214 break;
alshabibeec3a062014-09-17 18:01:26 -0700215 case VLAN_VID:
216 VlanIdCriterion vid = (VlanIdCriterion) c;
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800217
218 if (vid.vlanId().equals(VlanId.ANY)) {
219 mBuilder.setMasked(MatchField.VLAN_VID, OFVlanVidMatch.PRESENT,
220 OFVlanVidMatch.PRESENT);
Jonathan Hart1468fee2015-07-16 18:50:34 -0700221 } else if (vid.vlanId().equals(VlanId.NONE)) {
222 mBuilder.setExact(MatchField.VLAN_VID, OFVlanVidMatch.NONE);
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800223 } else {
224 mBuilder.setExact(MatchField.VLAN_VID,
alshabib346b5b32015-03-06 00:42:16 -0800225 OFVlanVidMatch.ofVlanVid(VlanVid.ofVlan(vid.vlanId().toShort())));
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800226 }
alshabibeec3a062014-09-17 18:01:26 -0700227 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800228 case VLAN_PCP:
229 VlanPcpCriterion vpcp = (VlanPcpCriterion) c;
230 mBuilder.setExact(MatchField.VLAN_PCP, VlanPcp.of(vpcp.priority()));
231 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800232 case IP_DSCP:
233 IPDscpCriterion ipDscpCriterion = (IPDscpCriterion) c;
234 mBuilder.setExact(MatchField.IP_DSCP,
235 IpDscp.of(ipDscpCriterion.ipDscp()));
236 break;
237 case IP_ECN:
238 IPEcnCriterion ipEcnCriterion = (IPEcnCriterion) c;
239 mBuilder.setExact(MatchField.IP_ECN,
240 IpEcn.of(ipEcnCriterion.ipEcn()));
241 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800242 case IP_PROTO:
243 IPProtocolCriterion p = (IPProtocolCriterion) c;
244 mBuilder.setExact(MatchField.IP_PROTO, IpProtocol.of(p.protocol()));
245 break;
246 case IPV4_SRC:
247 ipCriterion = (IPCriterion) c;
248 ip4Prefix = ipCriterion.ip().getIp4Prefix();
249 if (ip4Prefix.prefixLength() != Ip4Prefix.MAX_MASK_LENGTH) {
250 Ip4Address maskAddr =
251 Ip4Address.makeMaskPrefix(ip4Prefix.prefixLength());
252 Masked<IPv4Address> maskedIp =
253 Masked.of(IPv4Address.of(ip4Prefix.address().toInt()),
254 IPv4Address.of(maskAddr.toInt()));
255 mBuilder.setMasked(MatchField.IPV4_SRC, maskedIp);
256 } else {
257 mBuilder.setExact(MatchField.IPV4_SRC,
258 IPv4Address.of(ip4Prefix.address().toInt()));
259 }
260 break;
261 case IPV4_DST:
262 ipCriterion = (IPCriterion) c;
263 ip4Prefix = ipCriterion.ip().getIp4Prefix();
264 if (ip4Prefix.prefixLength() != Ip4Prefix.MAX_MASK_LENGTH) {
265 Ip4Address maskAddr =
266 Ip4Address.makeMaskPrefix(ip4Prefix.prefixLength());
267 Masked<IPv4Address> maskedIp =
268 Masked.of(IPv4Address.of(ip4Prefix.address().toInt()),
269 IPv4Address.of(maskAddr.toInt()));
270 mBuilder.setMasked(MatchField.IPV4_DST, maskedIp);
271 } else {
272 mBuilder.setExact(MatchField.IPV4_DST,
273 IPv4Address.of(ip4Prefix.address().toInt()));
274 }
Jonathan Hart34bc6142014-10-17 11:00:43 -0700275 break;
276 case TCP_SRC:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800277 tcpPortCriterion = (TcpPortCriterion) c;
278 mBuilder.setExact(MatchField.TCP_SRC,
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700279 TransportPort.of(tcpPortCriterion.tcpPort().toInt()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800280 break;
281 case TCP_DST:
282 tcpPortCriterion = (TcpPortCriterion) c;
283 mBuilder.setExact(MatchField.TCP_DST,
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700284 TransportPort.of(tcpPortCriterion.tcpPort().toInt()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800285 break;
286 case UDP_SRC:
287 udpPortCriterion = (UdpPortCriterion) c;
288 mBuilder.setExact(MatchField.UDP_SRC,
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700289 TransportPort.of(udpPortCriterion.udpPort().toInt()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800290 break;
291 case UDP_DST:
292 udpPortCriterion = (UdpPortCriterion) c;
293 mBuilder.setExact(MatchField.UDP_DST,
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700294 TransportPort.of(udpPortCriterion.udpPort().toInt()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800295 break;
296 case SCTP_SRC:
297 sctpPortCriterion = (SctpPortCriterion) c;
298 mBuilder.setExact(MatchField.SCTP_SRC,
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700299 TransportPort.of(sctpPortCriterion.sctpPort().toInt()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800300 break;
301 case SCTP_DST:
302 sctpPortCriterion = (SctpPortCriterion) c;
303 mBuilder.setExact(MatchField.SCTP_DST,
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700304 TransportPort.of(sctpPortCriterion.sctpPort().toInt()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800305 break;
306 case ICMPV4_TYPE:
307 IcmpTypeCriterion icmpType = (IcmpTypeCriterion) c;
308 mBuilder.setExact(MatchField.ICMPV4_TYPE,
309 ICMPv4Type.of(icmpType.icmpType()));
310 break;
311 case ICMPV4_CODE:
312 IcmpCodeCriterion icmpCode = (IcmpCodeCriterion) c;
313 mBuilder.setExact(MatchField.ICMPV4_CODE,
314 ICMPv4Code.of(icmpCode.icmpCode()));
315 break;
316 case IPV6_SRC:
317 ipCriterion = (IPCriterion) c;
318 ip6Prefix = ipCriterion.ip().getIp6Prefix();
319 if (ip6Prefix.prefixLength() != Ip6Prefix.MAX_MASK_LENGTH) {
320 Ip6Address maskAddr =
321 Ip6Address.makeMaskPrefix(ip6Prefix.prefixLength());
322 Masked<IPv6Address> maskedIp =
323 Masked.of(IPv6Address.of(ip6Prefix.address().toString()),
324 IPv6Address.of(maskAddr.toString()));
325 mBuilder.setMasked(MatchField.IPV6_SRC, maskedIp);
326 } else {
327 mBuilder.setExact(MatchField.IPV6_SRC,
328 IPv6Address.of(ip6Prefix.address().toString()));
329 }
330 break;
331 case IPV6_DST:
332 ipCriterion = (IPCriterion) c;
333 ip6Prefix = ipCriterion.ip().getIp6Prefix();
334 if (ip6Prefix.prefixLength() != Ip6Prefix.MAX_MASK_LENGTH) {
335 Ip6Address maskAddr =
336 Ip6Address.makeMaskPrefix(ip6Prefix.prefixLength());
337 Masked<IPv6Address> maskedIp =
338 Masked.of(IPv6Address.of(ip6Prefix.address().toString()),
339 IPv6Address.of(maskAddr.toString()));
340 mBuilder.setMasked(MatchField.IPV6_DST, maskedIp);
341 } else {
342 mBuilder.setExact(MatchField.IPV6_DST,
343 IPv6Address.of(ip6Prefix.address().toString()));
344 }
345 break;
346 case IPV6_FLABEL:
347 IPv6FlowLabelCriterion flowLabelCriterion =
348 (IPv6FlowLabelCriterion) c;
349 mBuilder.setExact(MatchField.IPV6_FLABEL,
350 IPv6FlowLabel.of(flowLabelCriterion.flowLabel()));
351 break;
352 case ICMPV6_TYPE:
353 Icmpv6TypeCriterion icmpv6Type = (Icmpv6TypeCriterion) c;
354 mBuilder.setExact(MatchField.ICMPV6_TYPE,
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800355 U8.of(icmpv6Type.icmpv6Type()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800356 break;
357 case ICMPV6_CODE:
358 Icmpv6CodeCriterion icmpv6Code = (Icmpv6CodeCriterion) c;
359 mBuilder.setExact(MatchField.ICMPV6_CODE,
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800360 U8.of(icmpv6Code.icmpv6Code()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800361 break;
362 case IPV6_ND_TARGET:
363 IPv6NDTargetAddressCriterion targetAddressCriterion =
364 (IPv6NDTargetAddressCriterion) c;
365 ip6Address = targetAddressCriterion.targetAddress();
366 mBuilder.setExact(MatchField.IPV6_ND_TARGET,
367 IPv6Address.of(ip6Address.toOctets()));
368 break;
369 case IPV6_ND_SLL:
370 llAddressCriterion =
371 (IPv6NDLinkLayerAddressCriterion) c;
372 mBuilder.setExact(MatchField.IPV6_ND_SLL,
373 MacAddress.of(llAddressCriterion.mac().toLong()));
374 break;
375 case IPV6_ND_TLL:
376 llAddressCriterion =
377 (IPv6NDLinkLayerAddressCriterion) c;
378 mBuilder.setExact(MatchField.IPV6_ND_TLL,
379 MacAddress.of(llAddressCriterion.mac().toLong()));
Jonathan Hart34bc6142014-10-17 11:00:43 -0700380 break;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800381 case MPLS_LABEL:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700382 MplsCriterion mp = (MplsCriterion) c;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100383 mBuilder.setExact(MatchField.MPLS_LABEL, U32.of(mp.label().toInt()));
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800384 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800385 case IPV6_EXTHDR:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700386 IPv6ExthdrFlagsCriterion exthdrFlagsCriterion =
387 (IPv6ExthdrFlagsCriterion) c;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800388 mBuilder.setExact(MatchField.IPV6_EXTHDR,
389 U16.of(exthdrFlagsCriterion.exthdrFlags()));
390 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700391 case OCH_SIGID:
Sho SHIMIZUc15ce512015-05-26 16:54:08 -0700392 try {
393 OchSignalCriterion ochSignalCriterion = (OchSignalCriterion) c;
394 OchSignal signal = ochSignalCriterion.lambda();
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700395 byte gridType = OpenFlowValueMapper.lookupGridType(signal.gridType());
396 byte channelSpacing = OpenFlowValueMapper.lookupChannelSpacing(signal.channelSpacing());
Sho SHIMIZUc15ce512015-05-26 16:54:08 -0700397 mBuilder.setExact(MatchField.OCH_SIGID,
398 new CircuitSignalID(gridType, channelSpacing,
399 (short) signal.spacingMultiplier(), (short) signal.slotGranularity()));
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700400 } catch (NoMappingFoundException e) {
Sho SHIMIZUc15ce512015-05-26 16:54:08 -0700401 log.warn(e.getMessage());
402 }
Marc De Leenheer49087752014-10-23 13:54:09 -0700403 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800404 case OCH_SIGTYPE:
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700405 OchSignalTypeCriterion sc = (OchSignalTypeCriterion) c;
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700406 byte signalType = OpenFlowValueMapper.lookupOchSignalType(sc.signalType());
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700407 mBuilder.setExact(MatchField.OCH_SIGTYPE, U8.of(signalType));
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800408 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700409 case TUNNEL_ID:
410 TunnelIdCriterion tunnelId = (TunnelIdCriterion) c;
411 mBuilder.setExact(MatchField.TUNNEL_ID,
412 U64.of(tunnelId.tunnelId()));
413 break;
Saurav Dasffc5bbc2015-08-18 23:30:19 -0700414 case MPLS_BOS:
415 MplsBosCriterion mplsBos = (MplsBosCriterion) c;
416 mBuilder.setExact(MatchField.MPLS_BOS,
417 mplsBos.mplsBos() ? OFBooleanValue.TRUE
418 : OFBooleanValue.FALSE);
419 break;
BitOhenrya331b182015-11-23 08:39:37 +0800420 case ARP_SHA:
421 arpHaCriterion = (ArpHaCriterion) c;
422 mBuilder.setExact(MatchField.ARP_SHA,
423 MacAddress.of(arpHaCriterion.mac().toLong()));
424 break;
BitOhenry76430852015-11-20 19:04:49 +0800425 case ARP_THA:
426 arpHaCriterion = (ArpHaCriterion) c;
427 mBuilder.setExact(MatchField.ARP_THA,
428 MacAddress.of(arpHaCriterion.mac().toLong()));
429 break;
alshabibeec3a062014-09-17 18:01:26 -0700430 case ARP_OP:
alshabibeec3a062014-09-17 18:01:26 -0700431 case ARP_SPA:
alshabibeec3a062014-09-17 18:01:26 -0700432 case ARP_TPA:
alshabibeec3a062014-09-17 18:01:26 -0700433 case MPLS_TC:
434 case PBB_ISID:
alshabibeec3a062014-09-17 18:01:26 -0700435 default:
436 log.warn("Match type {} not yet implemented.", c.type());
437 }
438 }
439 return mBuilder.build();
440 }
441
Jonathan Hart86e59352014-10-22 10:42:16 -0700442 /**
443 * Returns the flow rule for this builder.
444 *
445 * @return the flow rule
446 */
447 protected FlowRule flowRule() {
448 return flowRule;
449 }
alshabib219ebaa2014-09-22 15:41:24 -0700450
Jonathan Hart86e59352014-10-22 10:42:16 -0700451 /**
452 * Returns the factory used for building OpenFlow constructs.
453 *
454 * @return the factory
455 */
456 protected OFFactory factory() {
457 return factory;
458 }
alshabib219ebaa2014-09-22 15:41:24 -0700459
alshabibeec3a062014-09-17 18:01:26 -0700460}