blob: d9d02ff531ec93daa0f87070907e73c423b4643b [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);
211 } else {
212 mBuilder.setExact(MatchField.VLAN_VID,
alshabib346b5b32015-03-06 00:42:16 -0800213 OFVlanVidMatch.ofVlanVid(VlanVid.ofVlan(vid.vlanId().toShort())));
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800214 }
alshabibeec3a062014-09-17 18:01:26 -0700215 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800216 case VLAN_PCP:
217 VlanPcpCriterion vpcp = (VlanPcpCriterion) c;
218 mBuilder.setExact(MatchField.VLAN_PCP, VlanPcp.of(vpcp.priority()));
219 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800220 case IP_DSCP:
221 IPDscpCriterion ipDscpCriterion = (IPDscpCriterion) c;
222 mBuilder.setExact(MatchField.IP_DSCP,
223 IpDscp.of(ipDscpCriterion.ipDscp()));
224 break;
225 case IP_ECN:
226 IPEcnCriterion ipEcnCriterion = (IPEcnCriterion) c;
227 mBuilder.setExact(MatchField.IP_ECN,
228 IpEcn.of(ipEcnCriterion.ipEcn()));
229 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800230 case IP_PROTO:
231 IPProtocolCriterion p = (IPProtocolCriterion) c;
232 mBuilder.setExact(MatchField.IP_PROTO, IpProtocol.of(p.protocol()));
233 break;
234 case IPV4_SRC:
235 ipCriterion = (IPCriterion) c;
236 ip4Prefix = ipCriterion.ip().getIp4Prefix();
237 if (ip4Prefix.prefixLength() != Ip4Prefix.MAX_MASK_LENGTH) {
238 Ip4Address maskAddr =
239 Ip4Address.makeMaskPrefix(ip4Prefix.prefixLength());
240 Masked<IPv4Address> maskedIp =
241 Masked.of(IPv4Address.of(ip4Prefix.address().toInt()),
242 IPv4Address.of(maskAddr.toInt()));
243 mBuilder.setMasked(MatchField.IPV4_SRC, maskedIp);
244 } else {
245 mBuilder.setExact(MatchField.IPV4_SRC,
246 IPv4Address.of(ip4Prefix.address().toInt()));
247 }
248 break;
249 case IPV4_DST:
250 ipCriterion = (IPCriterion) c;
251 ip4Prefix = ipCriterion.ip().getIp4Prefix();
252 if (ip4Prefix.prefixLength() != Ip4Prefix.MAX_MASK_LENGTH) {
253 Ip4Address maskAddr =
254 Ip4Address.makeMaskPrefix(ip4Prefix.prefixLength());
255 Masked<IPv4Address> maskedIp =
256 Masked.of(IPv4Address.of(ip4Prefix.address().toInt()),
257 IPv4Address.of(maskAddr.toInt()));
258 mBuilder.setMasked(MatchField.IPV4_DST, maskedIp);
259 } else {
260 mBuilder.setExact(MatchField.IPV4_DST,
261 IPv4Address.of(ip4Prefix.address().toInt()));
262 }
Jonathan Hart34bc6142014-10-17 11:00:43 -0700263 break;
264 case TCP_SRC:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800265 tcpPortCriterion = (TcpPortCriterion) c;
266 mBuilder.setExact(MatchField.TCP_SRC,
267 TransportPort.of(tcpPortCriterion.tcpPort()));
268 break;
269 case TCP_DST:
270 tcpPortCriterion = (TcpPortCriterion) c;
271 mBuilder.setExact(MatchField.TCP_DST,
272 TransportPort.of(tcpPortCriterion.tcpPort()));
273 break;
274 case UDP_SRC:
275 udpPortCriterion = (UdpPortCriterion) c;
276 mBuilder.setExact(MatchField.UDP_SRC,
277 TransportPort.of(udpPortCriterion.udpPort()));
278 break;
279 case UDP_DST:
280 udpPortCriterion = (UdpPortCriterion) c;
281 mBuilder.setExact(MatchField.UDP_DST,
282 TransportPort.of(udpPortCriterion.udpPort()));
283 break;
284 case SCTP_SRC:
285 sctpPortCriterion = (SctpPortCriterion) c;
286 mBuilder.setExact(MatchField.SCTP_SRC,
287 TransportPort.of(sctpPortCriterion.sctpPort()));
288 break;
289 case SCTP_DST:
290 sctpPortCriterion = (SctpPortCriterion) c;
291 mBuilder.setExact(MatchField.SCTP_DST,
292 TransportPort.of(sctpPortCriterion.sctpPort()));
293 break;
294 case ICMPV4_TYPE:
295 IcmpTypeCriterion icmpType = (IcmpTypeCriterion) c;
296 mBuilder.setExact(MatchField.ICMPV4_TYPE,
297 ICMPv4Type.of(icmpType.icmpType()));
298 break;
299 case ICMPV4_CODE:
300 IcmpCodeCriterion icmpCode = (IcmpCodeCriterion) c;
301 mBuilder.setExact(MatchField.ICMPV4_CODE,
302 ICMPv4Code.of(icmpCode.icmpCode()));
303 break;
304 case IPV6_SRC:
305 ipCriterion = (IPCriterion) c;
306 ip6Prefix = ipCriterion.ip().getIp6Prefix();
307 if (ip6Prefix.prefixLength() != Ip6Prefix.MAX_MASK_LENGTH) {
308 Ip6Address maskAddr =
309 Ip6Address.makeMaskPrefix(ip6Prefix.prefixLength());
310 Masked<IPv6Address> maskedIp =
311 Masked.of(IPv6Address.of(ip6Prefix.address().toString()),
312 IPv6Address.of(maskAddr.toString()));
313 mBuilder.setMasked(MatchField.IPV6_SRC, maskedIp);
314 } else {
315 mBuilder.setExact(MatchField.IPV6_SRC,
316 IPv6Address.of(ip6Prefix.address().toString()));
317 }
318 break;
319 case IPV6_DST:
320 ipCriterion = (IPCriterion) c;
321 ip6Prefix = ipCriterion.ip().getIp6Prefix();
322 if (ip6Prefix.prefixLength() != Ip6Prefix.MAX_MASK_LENGTH) {
323 Ip6Address maskAddr =
324 Ip6Address.makeMaskPrefix(ip6Prefix.prefixLength());
325 Masked<IPv6Address> maskedIp =
326 Masked.of(IPv6Address.of(ip6Prefix.address().toString()),
327 IPv6Address.of(maskAddr.toString()));
328 mBuilder.setMasked(MatchField.IPV6_DST, maskedIp);
329 } else {
330 mBuilder.setExact(MatchField.IPV6_DST,
331 IPv6Address.of(ip6Prefix.address().toString()));
332 }
333 break;
334 case IPV6_FLABEL:
335 IPv6FlowLabelCriterion flowLabelCriterion =
336 (IPv6FlowLabelCriterion) c;
337 mBuilder.setExact(MatchField.IPV6_FLABEL,
338 IPv6FlowLabel.of(flowLabelCriterion.flowLabel()));
339 break;
340 case ICMPV6_TYPE:
341 Icmpv6TypeCriterion icmpv6Type = (Icmpv6TypeCriterion) c;
342 mBuilder.setExact(MatchField.ICMPV6_TYPE,
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800343 U8.of(icmpv6Type.icmpv6Type()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800344 break;
345 case ICMPV6_CODE:
346 Icmpv6CodeCriterion icmpv6Code = (Icmpv6CodeCriterion) c;
347 mBuilder.setExact(MatchField.ICMPV6_CODE,
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800348 U8.of(icmpv6Code.icmpv6Code()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800349 break;
350 case IPV6_ND_TARGET:
351 IPv6NDTargetAddressCriterion targetAddressCriterion =
352 (IPv6NDTargetAddressCriterion) c;
353 ip6Address = targetAddressCriterion.targetAddress();
354 mBuilder.setExact(MatchField.IPV6_ND_TARGET,
355 IPv6Address.of(ip6Address.toOctets()));
356 break;
357 case IPV6_ND_SLL:
358 llAddressCriterion =
359 (IPv6NDLinkLayerAddressCriterion) c;
360 mBuilder.setExact(MatchField.IPV6_ND_SLL,
361 MacAddress.of(llAddressCriterion.mac().toLong()));
362 break;
363 case IPV6_ND_TLL:
364 llAddressCriterion =
365 (IPv6NDLinkLayerAddressCriterion) c;
366 mBuilder.setExact(MatchField.IPV6_ND_TLL,
367 MacAddress.of(llAddressCriterion.mac().toLong()));
Jonathan Hart34bc6142014-10-17 11:00:43 -0700368 break;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800369 case MPLS_LABEL:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700370 MplsCriterion mp = (MplsCriterion) c;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100371 mBuilder.setExact(MatchField.MPLS_LABEL, U32.of(mp.label().toInt()));
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800372 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800373 case IPV6_EXTHDR:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700374 IPv6ExthdrFlagsCriterion exthdrFlagsCriterion =
375 (IPv6ExthdrFlagsCriterion) c;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800376 mBuilder.setExact(MatchField.IPV6_EXTHDR,
377 U16.of(exthdrFlagsCriterion.exthdrFlags()));
378 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700379 case OCH_SIGID:
Sho SHIMIZUc15ce512015-05-26 16:54:08 -0700380 try {
381 OchSignalCriterion ochSignalCriterion = (OchSignalCriterion) c;
382 OchSignal signal = ochSignalCriterion.lambda();
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700383 byte gridType = OpenFlowValueMapper.lookupGridType(signal.gridType());
384 byte channelSpacing = OpenFlowValueMapper.lookupChannelSpacing(signal.channelSpacing());
Sho SHIMIZUc15ce512015-05-26 16:54:08 -0700385 mBuilder.setExact(MatchField.OCH_SIGID,
386 new CircuitSignalID(gridType, channelSpacing,
387 (short) signal.spacingMultiplier(), (short) signal.slotGranularity()));
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700388 } catch (NoMappingFoundException e) {
Sho SHIMIZUc15ce512015-05-26 16:54:08 -0700389 log.warn(e.getMessage());
390 }
Marc De Leenheer49087752014-10-23 13:54:09 -0700391 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800392 case OCH_SIGTYPE:
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700393 OchSignalTypeCriterion sc = (OchSignalTypeCriterion) c;
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700394 byte signalType = OpenFlowValueMapper.lookupOchSignalType(sc.signalType());
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700395 mBuilder.setExact(MatchField.OCH_SIGTYPE, U8.of(signalType));
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800396 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700397 case TUNNEL_ID:
398 TunnelIdCriterion tunnelId = (TunnelIdCriterion) c;
399 mBuilder.setExact(MatchField.TUNNEL_ID,
400 U64.of(tunnelId.tunnelId()));
401 break;
alshabibeec3a062014-09-17 18:01:26 -0700402 case ARP_OP:
403 case ARP_SHA:
404 case ARP_SPA:
405 case ARP_THA:
406 case ARP_TPA:
alshabibeec3a062014-09-17 18:01:26 -0700407 case MPLS_BOS:
alshabibeec3a062014-09-17 18:01:26 -0700408 case MPLS_TC:
409 case PBB_ISID:
alshabibeec3a062014-09-17 18:01:26 -0700410 default:
411 log.warn("Match type {} not yet implemented.", c.type());
412 }
413 }
414 return mBuilder.build();
415 }
416
Jonathan Hart86e59352014-10-22 10:42:16 -0700417 /**
418 * Returns the flow rule for this builder.
419 *
420 * @return the flow rule
421 */
422 protected FlowRule flowRule() {
423 return flowRule;
424 }
alshabib219ebaa2014-09-22 15:41:24 -0700425
Jonathan Hart86e59352014-10-22 10:42:16 -0700426 /**
427 * Returns the factory used for building OpenFlow constructs.
428 *
429 * @return the factory
430 */
431 protected OFFactory factory() {
432 return factory;
433 }
alshabib219ebaa2014-09-22 15:41:24 -0700434
alshabibeec3a062014-09-17 18:01:26 -0700435}