blob: b2978d9781be03c8674e357d3808ca1f1ba26381 [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
Saurav Dasffc5bbc2015-08-18 23:30:19 -070018import static org.slf4j.LoggerFactory.getLogger;
19
20import java.util.Optional;
21
Jonathan Hart6cd2f352015-01-13 17:44:45 -080022import org.onlab.packet.Ip4Address;
23import org.onlab.packet.Ip4Prefix;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080024import org.onlab.packet.Ip6Address;
25import org.onlab.packet.Ip6Prefix;
Jonathan Hart6cd2f352015-01-13 17:44:45 -080026import org.onlab.packet.VlanId;
Sho SHIMIZUc15ce512015-05-26 16:54:08 -070027import org.onosproject.net.OchSignal;
Brian O'Connorabafb502014-12-02 22:26:20 -080028import org.onosproject.net.flow.FlowRule;
29import org.onosproject.net.flow.TrafficSelector;
Saurav Dasffc5bbc2015-08-18 23:30:19 -070030import org.onosproject.net.flow.criteria.Criterion;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070031import org.onosproject.net.flow.criteria.EthCriterion;
32import org.onosproject.net.flow.criteria.EthTypeCriterion;
33import org.onosproject.net.flow.criteria.IPCriterion;
34import org.onosproject.net.flow.criteria.IPDscpCriterion;
35import org.onosproject.net.flow.criteria.IPEcnCriterion;
36import org.onosproject.net.flow.criteria.IPProtocolCriterion;
37import org.onosproject.net.flow.criteria.IPv6ExthdrFlagsCriterion;
38import org.onosproject.net.flow.criteria.IPv6FlowLabelCriterion;
39import org.onosproject.net.flow.criteria.IPv6NDLinkLayerAddressCriterion;
40import org.onosproject.net.flow.criteria.IPv6NDTargetAddressCriterion;
41import org.onosproject.net.flow.criteria.IcmpCodeCriterion;
42import org.onosproject.net.flow.criteria.IcmpTypeCriterion;
43import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion;
44import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070045import org.onosproject.net.flow.criteria.MetadataCriterion;
Saurav Dasffc5bbc2015-08-18 23:30:19 -070046import org.onosproject.net.flow.criteria.MplsBosCriterion;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070047import org.onosproject.net.flow.criteria.MplsCriterion;
Sho SHIMIZUc15ce512015-05-26 16:54:08 -070048import org.onosproject.net.flow.criteria.OchSignalCriterion;
Marc De Leenheerd24420f2015-05-27 09:40:59 -070049import org.onosproject.net.flow.criteria.OchSignalTypeCriterion;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070050import org.onosproject.net.flow.criteria.PortCriterion;
51import org.onosproject.net.flow.criteria.SctpPortCriterion;
52import org.onosproject.net.flow.criteria.TcpPortCriterion;
Hyunsun Moona08c5d02015-07-14 17:53:00 -070053import org.onosproject.net.flow.criteria.TunnelIdCriterion;
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070054import org.onosproject.net.flow.criteria.UdpPortCriterion;
55import org.onosproject.net.flow.criteria.VlanIdCriterion;
56import org.onosproject.net.flow.criteria.VlanPcpCriterion;
alshabibeec3a062014-09-17 18:01:26 -070057import org.projectfloodlight.openflow.protocol.OFFactory;
alshabib193525b2014-10-08 18:58:03 -070058import org.projectfloodlight.openflow.protocol.OFFlowAdd;
59import org.projectfloodlight.openflow.protocol.OFFlowDelete;
alshabibeec3a062014-09-17 18:01:26 -070060import org.projectfloodlight.openflow.protocol.OFFlowMod;
alshabibeec3a062014-09-17 18:01:26 -070061import org.projectfloodlight.openflow.protocol.match.Match;
62import org.projectfloodlight.openflow.protocol.match.MatchField;
Marc De Leenheer49087752014-10-23 13:54:09 -070063import org.projectfloodlight.openflow.types.CircuitSignalID;
alshabibeec3a062014-09-17 18:01:26 -070064import org.projectfloodlight.openflow.types.EthType;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080065import org.projectfloodlight.openflow.types.ICMPv4Code;
66import org.projectfloodlight.openflow.types.ICMPv4Type;
alshabibeec3a062014-09-17 18:01:26 -070067import org.projectfloodlight.openflow.types.IPv4Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080068import org.projectfloodlight.openflow.types.IPv6Address;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080069import org.projectfloodlight.openflow.types.IPv6FlowLabel;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080070import org.projectfloodlight.openflow.types.IpDscp;
71import org.projectfloodlight.openflow.types.IpEcn;
alshabibeec3a062014-09-17 18:01:26 -070072import org.projectfloodlight.openflow.types.IpProtocol;
73import org.projectfloodlight.openflow.types.MacAddress;
74import org.projectfloodlight.openflow.types.Masked;
Saurav Dasffc5bbc2015-08-18 23:30:19 -070075import org.projectfloodlight.openflow.types.OFBooleanValue;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080076import org.projectfloodlight.openflow.types.OFMetadata;
alshabibeec3a062014-09-17 18:01:26 -070077import org.projectfloodlight.openflow.types.OFPort;
78import org.projectfloodlight.openflow.types.OFVlanVidMatch;
Jonathan Hart34bc6142014-10-17 11:00:43 -070079import org.projectfloodlight.openflow.types.TransportPort;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -080080import org.projectfloodlight.openflow.types.U16;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -080081import org.projectfloodlight.openflow.types.U32;
Hyunsun Moona08c5d02015-07-14 17:53:00 -070082import org.projectfloodlight.openflow.types.U64;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -080083import org.projectfloodlight.openflow.types.U8;
alshabibeec3a062014-09-17 18:01:26 -070084import org.projectfloodlight.openflow.types.VlanPcp;
85import org.projectfloodlight.openflow.types.VlanVid;
86import org.slf4j.Logger;
87
Jonathan Hart86e59352014-10-22 10:42:16 -070088/**
89 * Builder for OpenFlow flow mods based on FlowRules.
90 */
91public abstract class FlowModBuilder {
alshabibeec3a062014-09-17 18:01:26 -070092
93 private final Logger log = getLogger(getClass());
94
95 private final OFFactory factory;
Jonathan Hart86e59352014-10-22 10:42:16 -070096 private final FlowRule flowRule;
alshabibeec3a062014-09-17 18:01:26 -070097 private final TrafficSelector selector;
Brian O'Connor427a1762014-11-19 18:40:32 -080098 protected final Long xid;
alshabibeec3a062014-09-17 18:01:26 -070099
Jonathan Hart86e59352014-10-22 10:42:16 -0700100 /**
101 * Creates a new flow mod builder.
102 *
103 * @param flowRule the flow rule to transform into a flow mod
104 * @param factory the OpenFlow factory to use to build the flow mod
Pavlin Radoslavov119fd5c2014-11-25 19:08:19 -0800105 * @param xid the transaction ID
Jonathan Hart86e59352014-10-22 10:42:16 -0700106 * @return the new flow mod builder
107 */
Brian O'Connor427a1762014-11-19 18:40:32 -0800108 public static FlowModBuilder builder(FlowRule flowRule,
alshabib9af70072015-02-09 14:34:16 -0800109 OFFactory factory,
110 Optional<Long> xid) {
Jonathan Hart86e59352014-10-22 10:42:16 -0700111 switch (factory.getVersion()) {
112 case OF_10:
Brian O'Connor427a1762014-11-19 18:40:32 -0800113 return new FlowModBuilderVer10(flowRule, factory, xid);
Jonathan Hart86e59352014-10-22 10:42:16 -0700114 case OF_13:
Brian O'Connor427a1762014-11-19 18:40:32 -0800115 return new FlowModBuilderVer13(flowRule, factory, xid);
Jonathan Hart86e59352014-10-22 10:42:16 -0700116 default:
117 throw new UnsupportedOperationException(
118 "No flow mod builder for protocol version " + factory.getVersion());
119 }
120 }
alshabibeec3a062014-09-17 18:01:26 -0700121
Jonathan Hart86e59352014-10-22 10:42:16 -0700122 /**
123 * Constructs a flow mod builder.
124 *
125 * @param flowRule the flow rule to transform into a flow mod
126 * @param factory the OpenFlow factory to use to build the flow mod
Pavlin Radoslavov119fd5c2014-11-25 19:08:19 -0800127 * @param xid the transaction ID
Jonathan Hart86e59352014-10-22 10:42:16 -0700128 */
Brian O'Connor427a1762014-11-19 18:40:32 -0800129 protected FlowModBuilder(FlowRule flowRule, OFFactory factory, Optional<Long> xid) {
alshabibeec3a062014-09-17 18:01:26 -0700130 this.factory = factory;
Jonathan Hart86e59352014-10-22 10:42:16 -0700131 this.flowRule = flowRule;
alshabibeec3a062014-09-17 18:01:26 -0700132 this.selector = flowRule.selector();
Sho SHIMIZUc14b2a22015-05-05 18:15:13 -0700133 this.xid = xid.orElse(0L);
Brian O'Connor427a1762014-11-19 18:40:32 -0800134
alshabibeec3a062014-09-17 18:01:26 -0700135 }
136
Jonathan Hart86e59352014-10-22 10:42:16 -0700137 /**
138 * Builds an ADD flow mod.
139 *
140 * @return the flow mod
141 */
142 public abstract OFFlowAdd buildFlowAdd();
alshabibeec3a062014-09-17 18:01:26 -0700143
Jonathan Hart86e59352014-10-22 10:42:16 -0700144 /**
145 * Builds a MODIFY flow mod.
146 *
147 * @return the flow mod
148 */
149 public abstract OFFlowMod buildFlowMod();
alshabibeec3a062014-09-17 18:01:26 -0700150
Jonathan Hart86e59352014-10-22 10:42:16 -0700151 /**
152 * Builds a DELETE flow mod.
153 *
154 * @return the flow mod
155 */
156 public abstract OFFlowDelete buildFlowDel();
alshabibeec3a062014-09-17 18:01:26 -0700157
Jonathan Hart86e59352014-10-22 10:42:16 -0700158 /**
159 * Builds the match for the flow mod.
160 *
161 * @return the match
162 */
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800163 // CHECKSTYLE IGNORE MethodLength FOR NEXT 300 LINES
Jonathan Hart86e59352014-10-22 10:42:16 -0700164 protected Match buildMatch() {
alshabibeec3a062014-09-17 18:01:26 -0700165 Match.Builder mBuilder = factory.buildMatch();
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800166 Ip6Address ip6Address;
Pavlin Radoslavov23e398d2014-11-05 15:17:57 -0800167 Ip4Prefix ip4Prefix;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800168 Ip6Prefix ip6Prefix;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800169 EthCriterion ethCriterion;
170 IPCriterion ipCriterion;
171 TcpPortCriterion tcpPortCriterion;
172 UdpPortCriterion udpPortCriterion;
173 SctpPortCriterion sctpPortCriterion;
174 IPv6NDLinkLayerAddressCriterion llAddressCriterion;
175
alshabibeec3a062014-09-17 18:01:26 -0700176 for (Criterion c : selector.criteria()) {
177 switch (c.type()) {
178 case IN_PORT:
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800179 PortCriterion inPort = (PortCriterion) c;
180 mBuilder.setExact(MatchField.IN_PORT,
181 OFPort.of((int) inPort.port().toLong()));
182 break;
183 case IN_PHY_PORT:
184 PortCriterion inPhyPort = (PortCriterion) c;
185 mBuilder.setExact(MatchField.IN_PORT,
186 OFPort.of((int) inPhyPort.port().toLong()));
187 break;
188 case METADATA:
189 MetadataCriterion metadata = (MetadataCriterion) c;
190 mBuilder.setExact(MatchField.METADATA,
191 OFMetadata.ofRaw(metadata.metadata()));
alshabibeec3a062014-09-17 18:01:26 -0700192 break;
alshabibeec3a062014-09-17 18:01:26 -0700193 case ETH_DST:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800194 ethCriterion = (EthCriterion) c;
195 mBuilder.setExact(MatchField.ETH_DST,
196 MacAddress.of(ethCriterion.mac().toLong()));
197 break;
198 case ETH_SRC:
199 ethCriterion = (EthCriterion) c;
200 mBuilder.setExact(MatchField.ETH_SRC,
201 MacAddress.of(ethCriterion.mac().toLong()));
alshabibeec3a062014-09-17 18:01:26 -0700202 break;
203 case ETH_TYPE:
204 EthTypeCriterion ethType = (EthTypeCriterion) c;
alshabibcaf1ca22015-06-25 15:18:16 -0700205 mBuilder.setExact(MatchField.ETH_TYPE, EthType.of(ethType.ethType().toShort()));
alshabibeec3a062014-09-17 18:01:26 -0700206 break;
alshabibeec3a062014-09-17 18:01:26 -0700207 case VLAN_VID:
208 VlanIdCriterion vid = (VlanIdCriterion) c;
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800209
210 if (vid.vlanId().equals(VlanId.ANY)) {
211 mBuilder.setMasked(MatchField.VLAN_VID, OFVlanVidMatch.PRESENT,
212 OFVlanVidMatch.PRESENT);
Jonathan Hart1468fee2015-07-16 18:50:34 -0700213 } else if (vid.vlanId().equals(VlanId.NONE)) {
214 mBuilder.setExact(MatchField.VLAN_VID, OFVlanVidMatch.NONE);
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800215 } else {
216 mBuilder.setExact(MatchField.VLAN_VID,
alshabib346b5b32015-03-06 00:42:16 -0800217 OFVlanVidMatch.ofVlanVid(VlanVid.ofVlan(vid.vlanId().toShort())));
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800218 }
alshabibeec3a062014-09-17 18:01:26 -0700219 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800220 case VLAN_PCP:
221 VlanPcpCriterion vpcp = (VlanPcpCriterion) c;
222 mBuilder.setExact(MatchField.VLAN_PCP, VlanPcp.of(vpcp.priority()));
223 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800224 case IP_DSCP:
225 IPDscpCriterion ipDscpCriterion = (IPDscpCriterion) c;
226 mBuilder.setExact(MatchField.IP_DSCP,
227 IpDscp.of(ipDscpCriterion.ipDscp()));
228 break;
229 case IP_ECN:
230 IPEcnCriterion ipEcnCriterion = (IPEcnCriterion) c;
231 mBuilder.setExact(MatchField.IP_ECN,
232 IpEcn.of(ipEcnCriterion.ipEcn()));
233 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800234 case IP_PROTO:
235 IPProtocolCriterion p = (IPProtocolCriterion) c;
236 mBuilder.setExact(MatchField.IP_PROTO, IpProtocol.of(p.protocol()));
237 break;
238 case IPV4_SRC:
239 ipCriterion = (IPCriterion) c;
240 ip4Prefix = ipCriterion.ip().getIp4Prefix();
241 if (ip4Prefix.prefixLength() != Ip4Prefix.MAX_MASK_LENGTH) {
242 Ip4Address maskAddr =
243 Ip4Address.makeMaskPrefix(ip4Prefix.prefixLength());
244 Masked<IPv4Address> maskedIp =
245 Masked.of(IPv4Address.of(ip4Prefix.address().toInt()),
246 IPv4Address.of(maskAddr.toInt()));
247 mBuilder.setMasked(MatchField.IPV4_SRC, maskedIp);
248 } else {
249 mBuilder.setExact(MatchField.IPV4_SRC,
250 IPv4Address.of(ip4Prefix.address().toInt()));
251 }
252 break;
253 case IPV4_DST:
254 ipCriterion = (IPCriterion) c;
255 ip4Prefix = ipCriterion.ip().getIp4Prefix();
256 if (ip4Prefix.prefixLength() != Ip4Prefix.MAX_MASK_LENGTH) {
257 Ip4Address maskAddr =
258 Ip4Address.makeMaskPrefix(ip4Prefix.prefixLength());
259 Masked<IPv4Address> maskedIp =
260 Masked.of(IPv4Address.of(ip4Prefix.address().toInt()),
261 IPv4Address.of(maskAddr.toInt()));
262 mBuilder.setMasked(MatchField.IPV4_DST, maskedIp);
263 } else {
264 mBuilder.setExact(MatchField.IPV4_DST,
265 IPv4Address.of(ip4Prefix.address().toInt()));
266 }
Jonathan Hart34bc6142014-10-17 11:00:43 -0700267 break;
268 case TCP_SRC:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800269 tcpPortCriterion = (TcpPortCriterion) c;
270 mBuilder.setExact(MatchField.TCP_SRC,
271 TransportPort.of(tcpPortCriterion.tcpPort()));
272 break;
273 case TCP_DST:
274 tcpPortCriterion = (TcpPortCriterion) c;
275 mBuilder.setExact(MatchField.TCP_DST,
276 TransportPort.of(tcpPortCriterion.tcpPort()));
277 break;
278 case UDP_SRC:
279 udpPortCriterion = (UdpPortCriterion) c;
280 mBuilder.setExact(MatchField.UDP_SRC,
281 TransportPort.of(udpPortCriterion.udpPort()));
282 break;
283 case UDP_DST:
284 udpPortCriterion = (UdpPortCriterion) c;
285 mBuilder.setExact(MatchField.UDP_DST,
286 TransportPort.of(udpPortCriterion.udpPort()));
287 break;
288 case SCTP_SRC:
289 sctpPortCriterion = (SctpPortCriterion) c;
290 mBuilder.setExact(MatchField.SCTP_SRC,
291 TransportPort.of(sctpPortCriterion.sctpPort()));
292 break;
293 case SCTP_DST:
294 sctpPortCriterion = (SctpPortCriterion) c;
295 mBuilder.setExact(MatchField.SCTP_DST,
296 TransportPort.of(sctpPortCriterion.sctpPort()));
297 break;
298 case ICMPV4_TYPE:
299 IcmpTypeCriterion icmpType = (IcmpTypeCriterion) c;
300 mBuilder.setExact(MatchField.ICMPV4_TYPE,
301 ICMPv4Type.of(icmpType.icmpType()));
302 break;
303 case ICMPV4_CODE:
304 IcmpCodeCriterion icmpCode = (IcmpCodeCriterion) c;
305 mBuilder.setExact(MatchField.ICMPV4_CODE,
306 ICMPv4Code.of(icmpCode.icmpCode()));
307 break;
308 case IPV6_SRC:
309 ipCriterion = (IPCriterion) c;
310 ip6Prefix = ipCriterion.ip().getIp6Prefix();
311 if (ip6Prefix.prefixLength() != Ip6Prefix.MAX_MASK_LENGTH) {
312 Ip6Address maskAddr =
313 Ip6Address.makeMaskPrefix(ip6Prefix.prefixLength());
314 Masked<IPv6Address> maskedIp =
315 Masked.of(IPv6Address.of(ip6Prefix.address().toString()),
316 IPv6Address.of(maskAddr.toString()));
317 mBuilder.setMasked(MatchField.IPV6_SRC, maskedIp);
318 } else {
319 mBuilder.setExact(MatchField.IPV6_SRC,
320 IPv6Address.of(ip6Prefix.address().toString()));
321 }
322 break;
323 case IPV6_DST:
324 ipCriterion = (IPCriterion) c;
325 ip6Prefix = ipCriterion.ip().getIp6Prefix();
326 if (ip6Prefix.prefixLength() != Ip6Prefix.MAX_MASK_LENGTH) {
327 Ip6Address maskAddr =
328 Ip6Address.makeMaskPrefix(ip6Prefix.prefixLength());
329 Masked<IPv6Address> maskedIp =
330 Masked.of(IPv6Address.of(ip6Prefix.address().toString()),
331 IPv6Address.of(maskAddr.toString()));
332 mBuilder.setMasked(MatchField.IPV6_DST, maskedIp);
333 } else {
334 mBuilder.setExact(MatchField.IPV6_DST,
335 IPv6Address.of(ip6Prefix.address().toString()));
336 }
337 break;
338 case IPV6_FLABEL:
339 IPv6FlowLabelCriterion flowLabelCriterion =
340 (IPv6FlowLabelCriterion) c;
341 mBuilder.setExact(MatchField.IPV6_FLABEL,
342 IPv6FlowLabel.of(flowLabelCriterion.flowLabel()));
343 break;
344 case ICMPV6_TYPE:
345 Icmpv6TypeCriterion icmpv6Type = (Icmpv6TypeCriterion) c;
346 mBuilder.setExact(MatchField.ICMPV6_TYPE,
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800347 U8.of(icmpv6Type.icmpv6Type()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800348 break;
349 case ICMPV6_CODE:
350 Icmpv6CodeCriterion icmpv6Code = (Icmpv6CodeCriterion) c;
351 mBuilder.setExact(MatchField.ICMPV6_CODE,
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800352 U8.of(icmpv6Code.icmpv6Code()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800353 break;
354 case IPV6_ND_TARGET:
355 IPv6NDTargetAddressCriterion targetAddressCriterion =
356 (IPv6NDTargetAddressCriterion) c;
357 ip6Address = targetAddressCriterion.targetAddress();
358 mBuilder.setExact(MatchField.IPV6_ND_TARGET,
359 IPv6Address.of(ip6Address.toOctets()));
360 break;
361 case IPV6_ND_SLL:
362 llAddressCriterion =
363 (IPv6NDLinkLayerAddressCriterion) c;
364 mBuilder.setExact(MatchField.IPV6_ND_SLL,
365 MacAddress.of(llAddressCriterion.mac().toLong()));
366 break;
367 case IPV6_ND_TLL:
368 llAddressCriterion =
369 (IPv6NDLinkLayerAddressCriterion) c;
370 mBuilder.setExact(MatchField.IPV6_ND_TLL,
371 MacAddress.of(llAddressCriterion.mac().toLong()));
Jonathan Hart34bc6142014-10-17 11:00:43 -0700372 break;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800373 case MPLS_LABEL:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700374 MplsCriterion mp = (MplsCriterion) c;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100375 mBuilder.setExact(MatchField.MPLS_LABEL, U32.of(mp.label().toInt()));
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800376 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800377 case IPV6_EXTHDR:
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700378 IPv6ExthdrFlagsCriterion exthdrFlagsCriterion =
379 (IPv6ExthdrFlagsCriterion) c;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800380 mBuilder.setExact(MatchField.IPV6_EXTHDR,
381 U16.of(exthdrFlagsCriterion.exthdrFlags()));
382 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700383 case OCH_SIGID:
Sho SHIMIZUc15ce512015-05-26 16:54:08 -0700384 try {
385 OchSignalCriterion ochSignalCriterion = (OchSignalCriterion) c;
386 OchSignal signal = ochSignalCriterion.lambda();
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700387 byte gridType = OpenFlowValueMapper.lookupGridType(signal.gridType());
388 byte channelSpacing = OpenFlowValueMapper.lookupChannelSpacing(signal.channelSpacing());
Sho SHIMIZUc15ce512015-05-26 16:54:08 -0700389 mBuilder.setExact(MatchField.OCH_SIGID,
390 new CircuitSignalID(gridType, channelSpacing,
391 (short) signal.spacingMultiplier(), (short) signal.slotGranularity()));
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700392 } catch (NoMappingFoundException e) {
Sho SHIMIZUc15ce512015-05-26 16:54:08 -0700393 log.warn(e.getMessage());
394 }
Marc De Leenheer49087752014-10-23 13:54:09 -0700395 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800396 case OCH_SIGTYPE:
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700397 OchSignalTypeCriterion sc = (OchSignalTypeCriterion) c;
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700398 byte signalType = OpenFlowValueMapper.lookupOchSignalType(sc.signalType());
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700399 mBuilder.setExact(MatchField.OCH_SIGTYPE, U8.of(signalType));
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800400 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700401 case TUNNEL_ID:
402 TunnelIdCriterion tunnelId = (TunnelIdCriterion) c;
403 mBuilder.setExact(MatchField.TUNNEL_ID,
404 U64.of(tunnelId.tunnelId()));
405 break;
Saurav Dasffc5bbc2015-08-18 23:30:19 -0700406 case MPLS_BOS:
407 MplsBosCriterion mplsBos = (MplsBosCriterion) c;
408 mBuilder.setExact(MatchField.MPLS_BOS,
409 mplsBos.mplsBos() ? OFBooleanValue.TRUE
410 : OFBooleanValue.FALSE);
411 break;
alshabibeec3a062014-09-17 18:01:26 -0700412 case ARP_OP:
413 case ARP_SHA:
414 case ARP_SPA:
415 case ARP_THA:
416 case ARP_TPA:
alshabibeec3a062014-09-17 18:01:26 -0700417 case MPLS_TC:
418 case PBB_ISID:
alshabibeec3a062014-09-17 18:01:26 -0700419 default:
420 log.warn("Match type {} not yet implemented.", c.type());
421 }
422 }
423 return mBuilder.build();
424 }
425
Jonathan Hart86e59352014-10-22 10:42:16 -0700426 /**
427 * Returns the flow rule for this builder.
428 *
429 * @return the flow rule
430 */
431 protected FlowRule flowRule() {
432 return flowRule;
433 }
alshabib219ebaa2014-09-22 15:41:24 -0700434
Jonathan Hart86e59352014-10-22 10:42:16 -0700435 /**
436 * Returns the factory used for building OpenFlow constructs.
437 *
438 * @return the factory
439 */
440 protected OFFactory factory() {
441 return factory;
442 }
alshabib219ebaa2014-09-22 15:41:24 -0700443
alshabibeec3a062014-09-17 18:01:26 -0700444}