blob: 71327e59479f456df493be74f8493c660ea1de3f [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;
47import org.onosproject.net.flow.criteria.UdpPortCriterion;
48import org.onosproject.net.flow.criteria.VlanIdCriterion;
49import org.onosproject.net.flow.criteria.VlanPcpCriterion;
Brian O'Connorabafb502014-12-02 22:26:20 -080050import org.onosproject.net.flow.criteria.Criterion;
alshabibeec3a062014-09-17 18:01:26 -070051import org.projectfloodlight.openflow.protocol.OFFactory;
alshabib193525b2014-10-08 18:58:03 -070052import org.projectfloodlight.openflow.protocol.OFFlowAdd;
53import org.projectfloodlight.openflow.protocol.OFFlowDelete;
alshabibeec3a062014-09-17 18:01:26 -070054import org.projectfloodlight.openflow.protocol.OFFlowMod;
alshabibeec3a062014-09-17 18:01:26 -070055import org.projectfloodlight.openflow.protocol.match.Match;
56import org.projectfloodlight.openflow.protocol.match.MatchField;
Marc De Leenheer49087752014-10-23 13:54:09 -070057import org.projectfloodlight.openflow.types.CircuitSignalID;
alshabibeec3a062014-09-17 18:01:26 -070058import org.projectfloodlight.openflow.types.EthType;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080059import org.projectfloodlight.openflow.types.ICMPv4Code;
60import org.projectfloodlight.openflow.types.ICMPv4Type;
alshabibeec3a062014-09-17 18:01:26 -070061import org.projectfloodlight.openflow.types.IPv4Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080062import org.projectfloodlight.openflow.types.IPv6Address;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080063import org.projectfloodlight.openflow.types.IPv6FlowLabel;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080064import org.projectfloodlight.openflow.types.IpDscp;
65import org.projectfloodlight.openflow.types.IpEcn;
alshabibeec3a062014-09-17 18:01:26 -070066import org.projectfloodlight.openflow.types.IpProtocol;
67import org.projectfloodlight.openflow.types.MacAddress;
68import org.projectfloodlight.openflow.types.Masked;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080069import org.projectfloodlight.openflow.types.OFMetadata;
alshabibeec3a062014-09-17 18:01:26 -070070import org.projectfloodlight.openflow.types.OFPort;
71import org.projectfloodlight.openflow.types.OFVlanVidMatch;
Jonathan Hart34bc6142014-10-17 11:00:43 -070072import org.projectfloodlight.openflow.types.TransportPort;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -080073import org.projectfloodlight.openflow.types.U16;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -080074import org.projectfloodlight.openflow.types.U32;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -080075import org.projectfloodlight.openflow.types.U8;
alshabibeec3a062014-09-17 18:01:26 -070076import org.projectfloodlight.openflow.types.VlanPcp;
77import org.projectfloodlight.openflow.types.VlanVid;
78import org.slf4j.Logger;
79
Brian O'Connor427a1762014-11-19 18:40:32 -080080import java.util.Optional;
81
Jonathan Hart6cd2f352015-01-13 17:44:45 -080082import static org.slf4j.LoggerFactory.getLogger;
83
Jonathan Hart86e59352014-10-22 10:42:16 -070084/**
85 * Builder for OpenFlow flow mods based on FlowRules.
86 */
87public abstract class FlowModBuilder {
alshabibeec3a062014-09-17 18:01:26 -070088
89 private final Logger log = getLogger(getClass());
90
91 private final OFFactory factory;
Jonathan Hart86e59352014-10-22 10:42:16 -070092 private final FlowRule flowRule;
alshabibeec3a062014-09-17 18:01:26 -070093 private final TrafficSelector selector;
Brian O'Connor427a1762014-11-19 18:40:32 -080094 protected final Long xid;
alshabibeec3a062014-09-17 18:01:26 -070095
Jonathan Hart86e59352014-10-22 10:42:16 -070096 /**
97 * Creates a new flow mod builder.
98 *
99 * @param flowRule the flow rule to transform into a flow mod
100 * @param factory the OpenFlow factory to use to build the flow mod
Pavlin Radoslavov119fd5c2014-11-25 19:08:19 -0800101 * @param xid the transaction ID
Jonathan Hart86e59352014-10-22 10:42:16 -0700102 * @return the new flow mod builder
103 */
Brian O'Connor427a1762014-11-19 18:40:32 -0800104 public static FlowModBuilder builder(FlowRule flowRule,
alshabib9af70072015-02-09 14:34:16 -0800105 OFFactory factory,
106 Optional<Long> xid) {
Jonathan Hart86e59352014-10-22 10:42:16 -0700107 switch (factory.getVersion()) {
108 case OF_10:
Brian O'Connor427a1762014-11-19 18:40:32 -0800109 return new FlowModBuilderVer10(flowRule, factory, xid);
Jonathan Hart86e59352014-10-22 10:42:16 -0700110 case OF_13:
Brian O'Connor427a1762014-11-19 18:40:32 -0800111 return new FlowModBuilderVer13(flowRule, factory, xid);
Jonathan Hart86e59352014-10-22 10:42:16 -0700112 default:
113 throw new UnsupportedOperationException(
114 "No flow mod builder for protocol version " + factory.getVersion());
115 }
116 }
alshabibeec3a062014-09-17 18:01:26 -0700117
Jonathan Hart86e59352014-10-22 10:42:16 -0700118 /**
119 * Constructs a flow mod builder.
120 *
121 * @param flowRule the flow rule to transform into a flow mod
122 * @param factory the OpenFlow factory to use to build the flow mod
Pavlin Radoslavov119fd5c2014-11-25 19:08:19 -0800123 * @param xid the transaction ID
Jonathan Hart86e59352014-10-22 10:42:16 -0700124 */
Brian O'Connor427a1762014-11-19 18:40:32 -0800125 protected FlowModBuilder(FlowRule flowRule, OFFactory factory, Optional<Long> xid) {
alshabibeec3a062014-09-17 18:01:26 -0700126 this.factory = factory;
Jonathan Hart86e59352014-10-22 10:42:16 -0700127 this.flowRule = flowRule;
alshabibeec3a062014-09-17 18:01:26 -0700128 this.selector = flowRule.selector();
Sho SHIMIZUc14b2a22015-05-05 18:15:13 -0700129 this.xid = xid.orElse(0L);
Brian O'Connor427a1762014-11-19 18:40:32 -0800130
alshabibeec3a062014-09-17 18:01:26 -0700131 }
132
Jonathan Hart86e59352014-10-22 10:42:16 -0700133 /**
134 * Builds an ADD flow mod.
135 *
136 * @return the flow mod
137 */
138 public abstract OFFlowAdd buildFlowAdd();
alshabibeec3a062014-09-17 18:01:26 -0700139
Jonathan Hart86e59352014-10-22 10:42:16 -0700140 /**
141 * Builds a MODIFY flow mod.
142 *
143 * @return the flow mod
144 */
145 public abstract OFFlowMod buildFlowMod();
alshabibeec3a062014-09-17 18:01:26 -0700146
Jonathan Hart86e59352014-10-22 10:42:16 -0700147 /**
148 * Builds a DELETE flow mod.
149 *
150 * @return the flow mod
151 */
152 public abstract OFFlowDelete buildFlowDel();
alshabibeec3a062014-09-17 18:01:26 -0700153
Jonathan Hart86e59352014-10-22 10:42:16 -0700154 /**
155 * Builds the match for the flow mod.
156 *
157 * @return the match
158 */
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800159 // CHECKSTYLE IGNORE MethodLength FOR NEXT 300 LINES
Jonathan Hart86e59352014-10-22 10:42:16 -0700160 protected Match buildMatch() {
alshabibeec3a062014-09-17 18:01:26 -0700161 Match.Builder mBuilder = factory.buildMatch();
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800162 Ip6Address ip6Address;
Pavlin Radoslavov23e398d2014-11-05 15:17:57 -0800163 Ip4Prefix ip4Prefix;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800164 Ip6Prefix ip6Prefix;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800165 EthCriterion ethCriterion;
166 IPCriterion ipCriterion;
167 TcpPortCriterion tcpPortCriterion;
168 UdpPortCriterion udpPortCriterion;
169 SctpPortCriterion sctpPortCriterion;
170 IPv6NDLinkLayerAddressCriterion llAddressCriterion;
171
alshabibeec3a062014-09-17 18:01:26 -0700172 for (Criterion c : selector.criteria()) {
173 switch (c.type()) {
174 case IN_PORT:
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800175 PortCriterion inPort = (PortCriterion) c;
176 mBuilder.setExact(MatchField.IN_PORT,
177 OFPort.of((int) inPort.port().toLong()));
178 break;
179 case IN_PHY_PORT:
180 PortCriterion inPhyPort = (PortCriterion) c;
181 mBuilder.setExact(MatchField.IN_PORT,
182 OFPort.of((int) inPhyPort.port().toLong()));
183 break;
184 case METADATA:
185 MetadataCriterion metadata = (MetadataCriterion) c;
186 mBuilder.setExact(MatchField.METADATA,
187 OFMetadata.ofRaw(metadata.metadata()));
alshabibeec3a062014-09-17 18:01:26 -0700188 break;
alshabibeec3a062014-09-17 18:01:26 -0700189 case ETH_DST:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800190 ethCriterion = (EthCriterion) c;
191 mBuilder.setExact(MatchField.ETH_DST,
192 MacAddress.of(ethCriterion.mac().toLong()));
193 break;
194 case ETH_SRC:
195 ethCriterion = (EthCriterion) c;
196 mBuilder.setExact(MatchField.ETH_SRC,
197 MacAddress.of(ethCriterion.mac().toLong()));
alshabibeec3a062014-09-17 18:01:26 -0700198 break;
199 case ETH_TYPE:
200 EthTypeCriterion ethType = (EthTypeCriterion) c;
201 mBuilder.setExact(MatchField.ETH_TYPE, EthType.of(ethType.ethType()));
202 break;
alshabibeec3a062014-09-17 18:01:26 -0700203 case VLAN_VID:
204 VlanIdCriterion vid = (VlanIdCriterion) c;
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800205
206 if (vid.vlanId().equals(VlanId.ANY)) {
207 mBuilder.setMasked(MatchField.VLAN_VID, OFVlanVidMatch.PRESENT,
208 OFVlanVidMatch.PRESENT);
209 } else {
210 mBuilder.setExact(MatchField.VLAN_VID,
alshabib346b5b32015-03-06 00:42:16 -0800211 OFVlanVidMatch.ofVlanVid(VlanVid.ofVlan(vid.vlanId().toShort())));
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800212 }
alshabibeec3a062014-09-17 18:01:26 -0700213 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800214 case VLAN_PCP:
215 VlanPcpCriterion vpcp = (VlanPcpCriterion) c;
216 mBuilder.setExact(MatchField.VLAN_PCP, VlanPcp.of(vpcp.priority()));
217 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800218 case IP_DSCP:
219 IPDscpCriterion ipDscpCriterion = (IPDscpCriterion) c;
220 mBuilder.setExact(MatchField.IP_DSCP,
221 IpDscp.of(ipDscpCriterion.ipDscp()));
222 break;
223 case IP_ECN:
224 IPEcnCriterion ipEcnCriterion = (IPEcnCriterion) c;
225 mBuilder.setExact(MatchField.IP_ECN,
226 IpEcn.of(ipEcnCriterion.ipEcn()));
227 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800228 case IP_PROTO:
229 IPProtocolCriterion p = (IPProtocolCriterion) c;
230 mBuilder.setExact(MatchField.IP_PROTO, IpProtocol.of(p.protocol()));
231 break;
232 case IPV4_SRC:
233 ipCriterion = (IPCriterion) c;
234 ip4Prefix = ipCriterion.ip().getIp4Prefix();
235 if (ip4Prefix.prefixLength() != Ip4Prefix.MAX_MASK_LENGTH) {
236 Ip4Address maskAddr =
237 Ip4Address.makeMaskPrefix(ip4Prefix.prefixLength());
238 Masked<IPv4Address> maskedIp =
239 Masked.of(IPv4Address.of(ip4Prefix.address().toInt()),
240 IPv4Address.of(maskAddr.toInt()));
241 mBuilder.setMasked(MatchField.IPV4_SRC, maskedIp);
242 } else {
243 mBuilder.setExact(MatchField.IPV4_SRC,
244 IPv4Address.of(ip4Prefix.address().toInt()));
245 }
246 break;
247 case IPV4_DST:
248 ipCriterion = (IPCriterion) c;
249 ip4Prefix = ipCriterion.ip().getIp4Prefix();
250 if (ip4Prefix.prefixLength() != Ip4Prefix.MAX_MASK_LENGTH) {
251 Ip4Address maskAddr =
252 Ip4Address.makeMaskPrefix(ip4Prefix.prefixLength());
253 Masked<IPv4Address> maskedIp =
254 Masked.of(IPv4Address.of(ip4Prefix.address().toInt()),
255 IPv4Address.of(maskAddr.toInt()));
256 mBuilder.setMasked(MatchField.IPV4_DST, maskedIp);
257 } else {
258 mBuilder.setExact(MatchField.IPV4_DST,
259 IPv4Address.of(ip4Prefix.address().toInt()));
260 }
Jonathan Hart34bc6142014-10-17 11:00:43 -0700261 break;
262 case TCP_SRC:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800263 tcpPortCriterion = (TcpPortCriterion) c;
264 mBuilder.setExact(MatchField.TCP_SRC,
265 TransportPort.of(tcpPortCriterion.tcpPort()));
266 break;
267 case TCP_DST:
268 tcpPortCriterion = (TcpPortCriterion) c;
269 mBuilder.setExact(MatchField.TCP_DST,
270 TransportPort.of(tcpPortCriterion.tcpPort()));
271 break;
272 case UDP_SRC:
273 udpPortCriterion = (UdpPortCriterion) c;
274 mBuilder.setExact(MatchField.UDP_SRC,
275 TransportPort.of(udpPortCriterion.udpPort()));
276 break;
277 case UDP_DST:
278 udpPortCriterion = (UdpPortCriterion) c;
279 mBuilder.setExact(MatchField.UDP_DST,
280 TransportPort.of(udpPortCriterion.udpPort()));
281 break;
282 case SCTP_SRC:
283 sctpPortCriterion = (SctpPortCriterion) c;
284 mBuilder.setExact(MatchField.SCTP_SRC,
285 TransportPort.of(sctpPortCriterion.sctpPort()));
286 break;
287 case SCTP_DST:
288 sctpPortCriterion = (SctpPortCriterion) c;
289 mBuilder.setExact(MatchField.SCTP_DST,
290 TransportPort.of(sctpPortCriterion.sctpPort()));
291 break;
292 case ICMPV4_TYPE:
293 IcmpTypeCriterion icmpType = (IcmpTypeCriterion) c;
294 mBuilder.setExact(MatchField.ICMPV4_TYPE,
295 ICMPv4Type.of(icmpType.icmpType()));
296 break;
297 case ICMPV4_CODE:
298 IcmpCodeCriterion icmpCode = (IcmpCodeCriterion) c;
299 mBuilder.setExact(MatchField.ICMPV4_CODE,
300 ICMPv4Code.of(icmpCode.icmpCode()));
301 break;
302 case IPV6_SRC:
303 ipCriterion = (IPCriterion) c;
304 ip6Prefix = ipCriterion.ip().getIp6Prefix();
305 if (ip6Prefix.prefixLength() != Ip6Prefix.MAX_MASK_LENGTH) {
306 Ip6Address maskAddr =
307 Ip6Address.makeMaskPrefix(ip6Prefix.prefixLength());
308 Masked<IPv6Address> maskedIp =
309 Masked.of(IPv6Address.of(ip6Prefix.address().toString()),
310 IPv6Address.of(maskAddr.toString()));
311 mBuilder.setMasked(MatchField.IPV6_SRC, maskedIp);
312 } else {
313 mBuilder.setExact(MatchField.IPV6_SRC,
314 IPv6Address.of(ip6Prefix.address().toString()));
315 }
316 break;
317 case IPV6_DST:
318 ipCriterion = (IPCriterion) c;
319 ip6Prefix = ipCriterion.ip().getIp6Prefix();
320 if (ip6Prefix.prefixLength() != Ip6Prefix.MAX_MASK_LENGTH) {
321 Ip6Address maskAddr =
322 Ip6Address.makeMaskPrefix(ip6Prefix.prefixLength());
323 Masked<IPv6Address> maskedIp =
324 Masked.of(IPv6Address.of(ip6Prefix.address().toString()),
325 IPv6Address.of(maskAddr.toString()));
326 mBuilder.setMasked(MatchField.IPV6_DST, maskedIp);
327 } else {
328 mBuilder.setExact(MatchField.IPV6_DST,
329 IPv6Address.of(ip6Prefix.address().toString()));
330 }
331 break;
332 case IPV6_FLABEL:
333 IPv6FlowLabelCriterion flowLabelCriterion =
334 (IPv6FlowLabelCriterion) c;
335 mBuilder.setExact(MatchField.IPV6_FLABEL,
336 IPv6FlowLabel.of(flowLabelCriterion.flowLabel()));
337 break;
338 case ICMPV6_TYPE:
339 Icmpv6TypeCriterion icmpv6Type = (Icmpv6TypeCriterion) c;
340 mBuilder.setExact(MatchField.ICMPV6_TYPE,
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800341 U8.of(icmpv6Type.icmpv6Type()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800342 break;
343 case ICMPV6_CODE:
344 Icmpv6CodeCriterion icmpv6Code = (Icmpv6CodeCriterion) c;
345 mBuilder.setExact(MatchField.ICMPV6_CODE,
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800346 U8.of(icmpv6Code.icmpv6Code()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800347 break;
348 case IPV6_ND_TARGET:
349 IPv6NDTargetAddressCriterion targetAddressCriterion =
350 (IPv6NDTargetAddressCriterion) c;
351 ip6Address = targetAddressCriterion.targetAddress();
352 mBuilder.setExact(MatchField.IPV6_ND_TARGET,
353 IPv6Address.of(ip6Address.toOctets()));
354 break;
355 case IPV6_ND_SLL:
356 llAddressCriterion =
357 (IPv6NDLinkLayerAddressCriterion) c;
358 mBuilder.setExact(MatchField.IPV6_ND_SLL,
359 MacAddress.of(llAddressCriterion.mac().toLong()));
360 break;
361 case IPV6_ND_TLL:
362 llAddressCriterion =
363 (IPv6NDLinkLayerAddressCriterion) c;
364 mBuilder.setExact(MatchField.IPV6_ND_TLL,
365 MacAddress.of(llAddressCriterion.mac().toLong()));
Jonathan Hart34bc6142014-10-17 11:00:43 -0700366 break;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800367 case MPLS_LABEL:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700368 MplsCriterion mp = (MplsCriterion) c;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100369 mBuilder.setExact(MatchField.MPLS_LABEL, U32.of(mp.label().toInt()));
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800370 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800371 case IPV6_EXTHDR:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700372 IPv6ExthdrFlagsCriterion exthdrFlagsCriterion =
373 (IPv6ExthdrFlagsCriterion) c;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800374 mBuilder.setExact(MatchField.IPV6_EXTHDR,
375 U16.of(exthdrFlagsCriterion.exthdrFlags()));
376 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700377 case OCH_SIGID:
Sho SHIMIZUc15ce512015-05-26 16:54:08 -0700378 try {
379 OchSignalCriterion ochSignalCriterion = (OchSignalCriterion) c;
380 OchSignal signal = ochSignalCriterion.lambda();
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700381 byte gridType = OpenFlowValueMapper.lookupGridType(signal.gridType());
382 byte channelSpacing = OpenFlowValueMapper.lookupChannelSpacing(signal.channelSpacing());
Sho SHIMIZUc15ce512015-05-26 16:54:08 -0700383 mBuilder.setExact(MatchField.OCH_SIGID,
384 new CircuitSignalID(gridType, channelSpacing,
385 (short) signal.spacingMultiplier(), (short) signal.slotGranularity()));
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700386 } catch (NoMappingFoundException e) {
Sho SHIMIZUc15ce512015-05-26 16:54:08 -0700387 log.warn(e.getMessage());
388 }
Marc De Leenheer49087752014-10-23 13:54:09 -0700389 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800390 case OCH_SIGTYPE:
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700391 OchSignalTypeCriterion sc = (OchSignalTypeCriterion) c;
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700392 byte signalType = OpenFlowValueMapper.lookupOchSignalType(sc.signalType());
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700393 mBuilder.setExact(MatchField.OCH_SIGTYPE, U8.of(signalType));
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800394 break;
alshabibeec3a062014-09-17 18:01:26 -0700395 case ARP_OP:
396 case ARP_SHA:
397 case ARP_SPA:
398 case ARP_THA:
399 case ARP_TPA:
alshabibeec3a062014-09-17 18:01:26 -0700400 case MPLS_BOS:
alshabibeec3a062014-09-17 18:01:26 -0700401 case MPLS_TC:
402 case PBB_ISID:
alshabibeec3a062014-09-17 18:01:26 -0700403 case TUNNEL_ID:
alshabibeec3a062014-09-17 18:01:26 -0700404 default:
405 log.warn("Match type {} not yet implemented.", c.type());
406 }
407 }
408 return mBuilder.build();
409 }
410
Jonathan Hart86e59352014-10-22 10:42:16 -0700411 /**
412 * Returns the flow rule for this builder.
413 *
414 * @return the flow rule
415 */
416 protected FlowRule flowRule() {
417 return flowRule;
418 }
alshabib219ebaa2014-09-22 15:41:24 -0700419
Jonathan Hart86e59352014-10-22 10:42:16 -0700420 /**
421 * Returns the factory used for building OpenFlow constructs.
422 *
423 * @return the factory
424 */
425 protected OFFactory factory() {
426 return factory;
427 }
alshabib219ebaa2014-09-22 15:41:24 -0700428
alshabibeec3a062014-09-17 18:01:26 -0700429}