Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 4 | * 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 Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 8 | * 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 Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.provider.of.flow.impl; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 17 | |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 18 | import org.onlab.packet.Ip4Address; |
| 19 | import org.onlab.packet.Ip4Prefix; |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 20 | import org.onlab.packet.Ip6Address; |
| 21 | import org.onlab.packet.Ip6Prefix; |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 22 | import org.onlab.packet.VlanId; |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 23 | import org.onosproject.net.DeviceId; |
Sho SHIMIZU | c15ce51 | 2015-05-26 16:54:08 -0700 | [diff] [blame] | 24 | import org.onosproject.net.OchSignal; |
Jonathan Hart | 42feabd | 2016-02-03 17:56:21 -0800 | [diff] [blame] | 25 | import org.onosproject.net.OduSignalId; |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 26 | import org.onosproject.net.driver.DefaultDriverData; |
| 27 | import org.onosproject.net.driver.DefaultDriverHandler; |
| 28 | import org.onosproject.net.driver.Driver; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 29 | import org.onosproject.net.driver.DriverService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 30 | import org.onosproject.net.flow.FlowRule; |
| 31 | import org.onosproject.net.flow.TrafficSelector; |
BitOhenry | 7643085 | 2015-11-20 19:04:49 +0800 | [diff] [blame] | 32 | import org.onosproject.net.flow.criteria.ArpHaCriterion; |
BitOhenry | b40129a | 2015-11-30 12:41:18 +0800 | [diff] [blame] | 33 | import org.onosproject.net.flow.criteria.ArpOpCriterion; |
BitOhenry | c1e5fcc | 2015-11-23 20:47:53 +0800 | [diff] [blame] | 34 | import org.onosproject.net.flow.criteria.ArpPaCriterion; |
Saurav Das | ffc5bbc | 2015-08-18 23:30:19 -0700 | [diff] [blame] | 35 | import org.onosproject.net.flow.criteria.Criterion; |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 36 | import org.onosproject.net.flow.criteria.EthCriterion; |
| 37 | import org.onosproject.net.flow.criteria.EthTypeCriterion; |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 38 | import org.onosproject.net.flow.criteria.ExtensionCriterion; |
| 39 | import org.onosproject.net.flow.criteria.ExtensionSelector; |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 40 | import org.onosproject.net.flow.criteria.IPCriterion; |
| 41 | import org.onosproject.net.flow.criteria.IPDscpCriterion; |
| 42 | import org.onosproject.net.flow.criteria.IPEcnCriterion; |
| 43 | import org.onosproject.net.flow.criteria.IPProtocolCriterion; |
| 44 | import org.onosproject.net.flow.criteria.IPv6ExthdrFlagsCriterion; |
| 45 | import org.onosproject.net.flow.criteria.IPv6FlowLabelCriterion; |
| 46 | import org.onosproject.net.flow.criteria.IPv6NDLinkLayerAddressCriterion; |
| 47 | import org.onosproject.net.flow.criteria.IPv6NDTargetAddressCriterion; |
| 48 | import org.onosproject.net.flow.criteria.IcmpCodeCriterion; |
| 49 | import org.onosproject.net.flow.criteria.IcmpTypeCriterion; |
| 50 | import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion; |
| 51 | import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion; |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 52 | import org.onosproject.net.flow.criteria.MetadataCriterion; |
Saurav Das | ffc5bbc | 2015-08-18 23:30:19 -0700 | [diff] [blame] | 53 | import org.onosproject.net.flow.criteria.MplsBosCriterion; |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 54 | import org.onosproject.net.flow.criteria.MplsCriterion; |
Sho SHIMIZU | c15ce51 | 2015-05-26 16:54:08 -0700 | [diff] [blame] | 55 | import org.onosproject.net.flow.criteria.OchSignalCriterion; |
Marc De Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 56 | import org.onosproject.net.flow.criteria.OchSignalTypeCriterion; |
Yafit Hadar | 7351461 | 2015-11-04 10:14:21 +0200 | [diff] [blame] | 57 | import org.onosproject.net.flow.criteria.OduSignalIdCriterion; |
| 58 | import org.onosproject.net.flow.criteria.OduSignalTypeCriterion; |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 59 | import org.onosproject.net.flow.criteria.PortCriterion; |
| 60 | import org.onosproject.net.flow.criteria.SctpPortCriterion; |
| 61 | import org.onosproject.net.flow.criteria.TcpPortCriterion; |
Hyunsun Moon | a08c5d0 | 2015-07-14 17:53:00 -0700 | [diff] [blame] | 62 | import org.onosproject.net.flow.criteria.TunnelIdCriterion; |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 63 | import org.onosproject.net.flow.criteria.UdpPortCriterion; |
| 64 | import org.onosproject.net.flow.criteria.VlanIdCriterion; |
| 65 | import org.onosproject.net.flow.criteria.VlanPcpCriterion; |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 66 | import org.onosproject.openflow.controller.ExtensionSelectorInterpreter; |
Thomas Vachuska | 95caba3 | 2016-04-04 10:42:05 -0700 | [diff] [blame] | 67 | import org.onosproject.provider.of.flow.util.NoMappingFoundException; |
| 68 | import org.onosproject.provider.of.flow.util.OpenFlowValueMapper; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 69 | import org.projectfloodlight.openflow.protocol.OFFactory; |
| 70 | import org.projectfloodlight.openflow.protocol.OFFlowMod; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 71 | import org.projectfloodlight.openflow.protocol.match.Match; |
| 72 | import org.projectfloodlight.openflow.protocol.match.MatchField; |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 73 | import org.projectfloodlight.openflow.protocol.oxm.OFOxm; |
BitOhenry | b40129a | 2015-11-30 12:41:18 +0800 | [diff] [blame] | 74 | import org.projectfloodlight.openflow.types.ArpOpcode; |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 75 | import org.projectfloodlight.openflow.types.CircuitSignalID; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 76 | import org.projectfloodlight.openflow.types.EthType; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 77 | import org.projectfloodlight.openflow.types.ICMPv4Code; |
| 78 | import org.projectfloodlight.openflow.types.ICMPv4Type; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 79 | import org.projectfloodlight.openflow.types.IPv4Address; |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 80 | import org.projectfloodlight.openflow.types.IPv6Address; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 81 | import org.projectfloodlight.openflow.types.IPv6FlowLabel; |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 82 | import org.projectfloodlight.openflow.types.IpDscp; |
| 83 | import org.projectfloodlight.openflow.types.IpEcn; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 84 | import org.projectfloodlight.openflow.types.IpProtocol; |
| 85 | import org.projectfloodlight.openflow.types.MacAddress; |
| 86 | import org.projectfloodlight.openflow.types.Masked; |
Saurav Das | ffc5bbc | 2015-08-18 23:30:19 -0700 | [diff] [blame] | 87 | import org.projectfloodlight.openflow.types.OFBooleanValue; |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 88 | import org.projectfloodlight.openflow.types.OFMetadata; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 89 | import org.projectfloodlight.openflow.types.OFPort; |
| 90 | import org.projectfloodlight.openflow.types.OFVlanVidMatch; |
Jonathan Hart | 42feabd | 2016-02-03 17:56:21 -0800 | [diff] [blame] | 91 | import org.projectfloodlight.openflow.types.OduSignalID; |
Jonathan Hart | 34bc614 | 2014-10-17 11:00:43 -0700 | [diff] [blame] | 92 | import org.projectfloodlight.openflow.types.TransportPort; |
Pavlin Radoslavov | 5e4f754 | 2015-02-06 18:18:21 -0800 | [diff] [blame] | 93 | import org.projectfloodlight.openflow.types.U16; |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 94 | import org.projectfloodlight.openflow.types.U32; |
Hyunsun Moon | a08c5d0 | 2015-07-14 17:53:00 -0700 | [diff] [blame] | 95 | import org.projectfloodlight.openflow.types.U64; |
Praseed Balakrishnan | 2dd5abd | 2014-11-03 14:56:28 -0800 | [diff] [blame] | 96 | import org.projectfloodlight.openflow.types.U8; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 97 | import org.projectfloodlight.openflow.types.VlanPcp; |
| 98 | import org.projectfloodlight.openflow.types.VlanVid; |
| 99 | import org.slf4j.Logger; |
| 100 | |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 101 | import java.util.Optional; |
| 102 | |
| 103 | import static org.slf4j.LoggerFactory.getLogger; |
| 104 | |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 105 | /** |
| 106 | * Builder for OpenFlow flow mods based on FlowRules. |
| 107 | */ |
| 108 | public abstract class FlowModBuilder { |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 109 | |
| 110 | private final Logger log = getLogger(getClass()); |
| 111 | |
| 112 | private final OFFactory factory; |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 113 | private final FlowRule flowRule; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 114 | private final TrafficSelector selector; |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 115 | protected final Long xid; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 116 | protected final Optional<DriverService> driverService; |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 117 | protected final DeviceId deviceId; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 118 | |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 119 | /** |
| 120 | * Creates a new flow mod builder. |
| 121 | * |
| 122 | * @param flowRule the flow rule to transform into a flow mod |
| 123 | * @param factory the OpenFlow factory to use to build the flow mod |
Pavlin Radoslavov | 119fd5c | 2014-11-25 19:08:19 -0800 | [diff] [blame] | 124 | * @param xid the transaction ID |
Charles Chan | 30ba400 | 2015-11-05 14:45:16 -0800 | [diff] [blame] | 125 | * @param driverService the device driver service |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 126 | * @return the new flow mod builder |
| 127 | */ |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 128 | public static FlowModBuilder builder(FlowRule flowRule, |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 129 | OFFactory factory, |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 130 | Optional<Long> xid, |
| 131 | Optional<DriverService> driverService) { |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 132 | switch (factory.getVersion()) { |
| 133 | case OF_10: |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 134 | return new FlowModBuilderVer10(flowRule, factory, xid, driverService); |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 135 | case OF_13: |
Yuta HIGUCHI | 2341e60 | 2017-03-08 20:10:08 -0800 | [diff] [blame] | 136 | case OF_14: |
Yuta HIGUCHI | 6512f3e | 2017-05-18 17:21:24 -0700 | [diff] [blame^] | 137 | case OF_15: |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 138 | return new FlowModBuilderVer13(flowRule, factory, xid, driverService); |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 139 | default: |
| 140 | throw new UnsupportedOperationException( |
| 141 | "No flow mod builder for protocol version " + factory.getVersion()); |
| 142 | } |
| 143 | } |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 144 | |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 145 | /** |
| 146 | * Constructs a flow mod builder. |
| 147 | * |
| 148 | * @param flowRule the flow rule to transform into a flow mod |
| 149 | * @param factory the OpenFlow factory to use to build the flow mod |
Charles Chan | 30ba400 | 2015-11-05 14:45:16 -0800 | [diff] [blame] | 150 | * @param driverService the device driver service |
Pavlin Radoslavov | 119fd5c | 2014-11-25 19:08:19 -0800 | [diff] [blame] | 151 | * @param xid the transaction ID |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 152 | */ |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 153 | protected FlowModBuilder(FlowRule flowRule, OFFactory factory, Optional<Long> xid, |
| 154 | Optional<DriverService> driverService) { |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 155 | this.factory = factory; |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 156 | this.flowRule = flowRule; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 157 | this.selector = flowRule.selector(); |
Sho SHIMIZU | c14b2a2 | 2015-05-05 18:15:13 -0700 | [diff] [blame] | 158 | this.xid = xid.orElse(0L); |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 159 | this.driverService = driverService; |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 160 | this.deviceId = flowRule.deviceId(); |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 163 | /** |
| 164 | * Builds an ADD flow mod. |
| 165 | * |
| 166 | * @return the flow mod |
| 167 | */ |
Jonathan Hart | 42feabd | 2016-02-03 17:56:21 -0800 | [diff] [blame] | 168 | public abstract OFFlowMod buildFlowAdd(); |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 169 | |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 170 | /** |
| 171 | * Builds a MODIFY flow mod. |
| 172 | * |
| 173 | * @return the flow mod |
| 174 | */ |
| 175 | public abstract OFFlowMod buildFlowMod(); |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 176 | |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 177 | /** |
| 178 | * Builds a DELETE flow mod. |
| 179 | * |
| 180 | * @return the flow mod |
| 181 | */ |
Jonathan Hart | 42feabd | 2016-02-03 17:56:21 -0800 | [diff] [blame] | 182 | public abstract OFFlowMod buildFlowDel(); |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 183 | |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 184 | /** |
| 185 | * Builds the match for the flow mod. |
| 186 | * |
| 187 | * @return the match |
| 188 | */ |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 189 | // CHECKSTYLE IGNORE MethodLength FOR NEXT 300 LINES |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 190 | protected Match buildMatch() { |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 191 | Match.Builder mBuilder = factory.buildMatch(); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 192 | Ip6Address ip6Address; |
Pavlin Radoslavov | 23e398d | 2014-11-05 15:17:57 -0800 | [diff] [blame] | 193 | Ip4Prefix ip4Prefix; |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 194 | Ip6Prefix ip6Prefix; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 195 | EthCriterion ethCriterion; |
| 196 | IPCriterion ipCriterion; |
| 197 | TcpPortCriterion tcpPortCriterion; |
| 198 | UdpPortCriterion udpPortCriterion; |
| 199 | SctpPortCriterion sctpPortCriterion; |
| 200 | IPv6NDLinkLayerAddressCriterion llAddressCriterion; |
BitOhenry | 7643085 | 2015-11-20 19:04:49 +0800 | [diff] [blame] | 201 | ArpHaCriterion arpHaCriterion; |
BitOhenry | c1e5fcc | 2015-11-23 20:47:53 +0800 | [diff] [blame] | 202 | ArpPaCriterion arpPaCriterion; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 203 | |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 204 | for (Criterion c : selector.criteria()) { |
| 205 | switch (c.type()) { |
| 206 | case IN_PORT: |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 207 | PortCriterion inPort = (PortCriterion) c; |
| 208 | mBuilder.setExact(MatchField.IN_PORT, |
| 209 | OFPort.of((int) inPort.port().toLong())); |
| 210 | break; |
| 211 | case IN_PHY_PORT: |
| 212 | PortCriterion inPhyPort = (PortCriterion) c; |
| 213 | mBuilder.setExact(MatchField.IN_PORT, |
| 214 | OFPort.of((int) inPhyPort.port().toLong())); |
| 215 | break; |
| 216 | case METADATA: |
| 217 | MetadataCriterion metadata = (MetadataCriterion) c; |
| 218 | mBuilder.setExact(MatchField.METADATA, |
| 219 | OFMetadata.ofRaw(metadata.metadata())); |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 220 | break; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 221 | case ETH_DST: |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 222 | ethCriterion = (EthCriterion) c; |
| 223 | mBuilder.setExact(MatchField.ETH_DST, |
| 224 | MacAddress.of(ethCriterion.mac().toLong())); |
| 225 | break; |
Saurav Das | 9d6c86b | 2016-02-19 09:01:07 -0800 | [diff] [blame] | 226 | case ETH_DST_MASKED: |
| 227 | ethCriterion = (EthCriterion) c; |
| 228 | mBuilder.setMasked(MatchField.ETH_DST, |
| 229 | MacAddress.of(ethCriterion.mac().toLong()), |
| 230 | MacAddress.of(ethCriterion.mask().toLong())); |
| 231 | break; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 232 | case ETH_SRC: |
| 233 | ethCriterion = (EthCriterion) c; |
| 234 | mBuilder.setExact(MatchField.ETH_SRC, |
| 235 | MacAddress.of(ethCriterion.mac().toLong())); |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 236 | break; |
Saurav Das | 9d6c86b | 2016-02-19 09:01:07 -0800 | [diff] [blame] | 237 | case ETH_SRC_MASKED: |
| 238 | ethCriterion = (EthCriterion) c; |
| 239 | mBuilder.setMasked(MatchField.ETH_SRC, |
| 240 | MacAddress.of(ethCriterion.mac().toLong()), |
| 241 | MacAddress.of(ethCriterion.mask().toLong())); |
| 242 | break; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 243 | case ETH_TYPE: |
| 244 | EthTypeCriterion ethType = (EthTypeCriterion) c; |
alshabib | caf1ca2 | 2015-06-25 15:18:16 -0700 | [diff] [blame] | 245 | mBuilder.setExact(MatchField.ETH_TYPE, EthType.of(ethType.ethType().toShort())); |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 246 | break; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 247 | case VLAN_VID: |
| 248 | VlanIdCriterion vid = (VlanIdCriterion) c; |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 249 | |
| 250 | if (vid.vlanId().equals(VlanId.ANY)) { |
| 251 | mBuilder.setMasked(MatchField.VLAN_VID, OFVlanVidMatch.PRESENT, |
| 252 | OFVlanVidMatch.PRESENT); |
Jonathan Hart | 1468fee | 2015-07-16 18:50:34 -0700 | [diff] [blame] | 253 | } else if (vid.vlanId().equals(VlanId.NONE)) { |
| 254 | mBuilder.setExact(MatchField.VLAN_VID, OFVlanVidMatch.NONE); |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 255 | } else { |
| 256 | mBuilder.setExact(MatchField.VLAN_VID, |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 257 | OFVlanVidMatch.ofVlanVid(VlanVid.ofVlan(vid.vlanId().toShort()))); |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 258 | } |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 259 | break; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 260 | case VLAN_PCP: |
| 261 | VlanPcpCriterion vpcp = (VlanPcpCriterion) c; |
| 262 | mBuilder.setExact(MatchField.VLAN_PCP, VlanPcp.of(vpcp.priority())); |
| 263 | break; |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 264 | case IP_DSCP: |
| 265 | IPDscpCriterion ipDscpCriterion = (IPDscpCriterion) c; |
| 266 | mBuilder.setExact(MatchField.IP_DSCP, |
| 267 | IpDscp.of(ipDscpCriterion.ipDscp())); |
| 268 | break; |
| 269 | case IP_ECN: |
| 270 | IPEcnCriterion ipEcnCriterion = (IPEcnCriterion) c; |
| 271 | mBuilder.setExact(MatchField.IP_ECN, |
| 272 | IpEcn.of(ipEcnCriterion.ipEcn())); |
| 273 | break; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 274 | case IP_PROTO: |
| 275 | IPProtocolCriterion p = (IPProtocolCriterion) c; |
| 276 | mBuilder.setExact(MatchField.IP_PROTO, IpProtocol.of(p.protocol())); |
| 277 | break; |
| 278 | case IPV4_SRC: |
| 279 | ipCriterion = (IPCriterion) c; |
| 280 | ip4Prefix = ipCriterion.ip().getIp4Prefix(); |
| 281 | if (ip4Prefix.prefixLength() != Ip4Prefix.MAX_MASK_LENGTH) { |
| 282 | Ip4Address maskAddr = |
| 283 | Ip4Address.makeMaskPrefix(ip4Prefix.prefixLength()); |
| 284 | Masked<IPv4Address> maskedIp = |
| 285 | Masked.of(IPv4Address.of(ip4Prefix.address().toInt()), |
| 286 | IPv4Address.of(maskAddr.toInt())); |
| 287 | mBuilder.setMasked(MatchField.IPV4_SRC, maskedIp); |
| 288 | } else { |
| 289 | mBuilder.setExact(MatchField.IPV4_SRC, |
| 290 | IPv4Address.of(ip4Prefix.address().toInt())); |
| 291 | } |
| 292 | break; |
| 293 | case IPV4_DST: |
| 294 | ipCriterion = (IPCriterion) c; |
| 295 | ip4Prefix = ipCriterion.ip().getIp4Prefix(); |
| 296 | if (ip4Prefix.prefixLength() != Ip4Prefix.MAX_MASK_LENGTH) { |
| 297 | Ip4Address maskAddr = |
| 298 | Ip4Address.makeMaskPrefix(ip4Prefix.prefixLength()); |
| 299 | Masked<IPv4Address> maskedIp = |
| 300 | Masked.of(IPv4Address.of(ip4Prefix.address().toInt()), |
| 301 | IPv4Address.of(maskAddr.toInt())); |
| 302 | mBuilder.setMasked(MatchField.IPV4_DST, maskedIp); |
| 303 | } else { |
| 304 | mBuilder.setExact(MatchField.IPV4_DST, |
| 305 | IPv4Address.of(ip4Prefix.address().toInt())); |
| 306 | } |
Jonathan Hart | 34bc614 | 2014-10-17 11:00:43 -0700 | [diff] [blame] | 307 | break; |
| 308 | case TCP_SRC: |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 309 | tcpPortCriterion = (TcpPortCriterion) c; |
| 310 | mBuilder.setExact(MatchField.TCP_SRC, |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 311 | TransportPort.of(tcpPortCriterion.tcpPort().toInt())); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 312 | break; |
Andreas Gilbert | 75b882f7 | 2017-02-03 09:58:07 +0100 | [diff] [blame] | 313 | case TCP_SRC_MASKED: |
| 314 | tcpPortCriterion = (TcpPortCriterion) c; |
| 315 | mBuilder.setMasked(MatchField.TCP_SRC, |
| 316 | TransportPort.of(tcpPortCriterion.tcpPort().toInt()), |
| 317 | TransportPort.of(tcpPortCriterion.mask().toInt())); |
| 318 | break; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 319 | case TCP_DST: |
| 320 | tcpPortCriterion = (TcpPortCriterion) c; |
| 321 | mBuilder.setExact(MatchField.TCP_DST, |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 322 | TransportPort.of(tcpPortCriterion.tcpPort().toInt())); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 323 | break; |
Andreas Gilbert | 75b882f7 | 2017-02-03 09:58:07 +0100 | [diff] [blame] | 324 | case TCP_DST_MASKED: |
| 325 | tcpPortCriterion = (TcpPortCriterion) c; |
| 326 | mBuilder.setMasked(MatchField.TCP_DST, |
| 327 | TransportPort.of(tcpPortCriterion.tcpPort().toInt()), |
| 328 | TransportPort.of(tcpPortCriterion.mask().toInt())); |
| 329 | break; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 330 | case UDP_SRC: |
| 331 | udpPortCriterion = (UdpPortCriterion) c; |
| 332 | mBuilder.setExact(MatchField.UDP_SRC, |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 333 | TransportPort.of(udpPortCriterion.udpPort().toInt())); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 334 | break; |
Andreas Gilbert | 75b882f7 | 2017-02-03 09:58:07 +0100 | [diff] [blame] | 335 | case UDP_SRC_MASKED: |
| 336 | udpPortCriterion = (UdpPortCriterion) c; |
| 337 | mBuilder.setMasked(MatchField.UDP_SRC, |
| 338 | TransportPort.of(udpPortCriterion.udpPort().toInt()), |
| 339 | TransportPort.of(udpPortCriterion.mask().toInt())); |
| 340 | break; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 341 | case UDP_DST: |
| 342 | udpPortCriterion = (UdpPortCriterion) c; |
| 343 | mBuilder.setExact(MatchField.UDP_DST, |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 344 | TransportPort.of(udpPortCriterion.udpPort().toInt())); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 345 | break; |
Andreas Gilbert | 75b882f7 | 2017-02-03 09:58:07 +0100 | [diff] [blame] | 346 | case UDP_DST_MASKED: |
| 347 | udpPortCriterion = (UdpPortCriterion) c; |
| 348 | mBuilder.setMasked(MatchField.UDP_DST, |
| 349 | TransportPort.of(udpPortCriterion.udpPort().toInt()), |
| 350 | TransportPort.of(udpPortCriterion.mask().toInt())); |
| 351 | break; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 352 | case SCTP_SRC: |
| 353 | sctpPortCriterion = (SctpPortCriterion) c; |
| 354 | mBuilder.setExact(MatchField.SCTP_SRC, |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 355 | TransportPort.of(sctpPortCriterion.sctpPort().toInt())); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 356 | break; |
Andreas Gilbert | 75b882f7 | 2017-02-03 09:58:07 +0100 | [diff] [blame] | 357 | case SCTP_SRC_MASKED: |
| 358 | sctpPortCriterion = (SctpPortCriterion) c; |
| 359 | mBuilder.setMasked(MatchField.SCTP_SRC, |
| 360 | TransportPort.of(sctpPortCriterion.sctpPort().toInt()), |
| 361 | TransportPort.of(sctpPortCriterion.mask().toInt())); |
| 362 | break; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 363 | case SCTP_DST: |
| 364 | sctpPortCriterion = (SctpPortCriterion) c; |
| 365 | mBuilder.setExact(MatchField.SCTP_DST, |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 366 | TransportPort.of(sctpPortCriterion.sctpPort().toInt())); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 367 | break; |
Andreas Gilbert | 75b882f7 | 2017-02-03 09:58:07 +0100 | [diff] [blame] | 368 | case SCTP_DST_MASKED: |
| 369 | sctpPortCriterion = (SctpPortCriterion) c; |
| 370 | mBuilder.setMasked(MatchField.SCTP_DST, |
| 371 | TransportPort.of(sctpPortCriterion.sctpPort().toInt()), |
| 372 | TransportPort.of(sctpPortCriterion.mask().toInt())); |
| 373 | break; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 374 | case ICMPV4_TYPE: |
| 375 | IcmpTypeCriterion icmpType = (IcmpTypeCriterion) c; |
| 376 | mBuilder.setExact(MatchField.ICMPV4_TYPE, |
| 377 | ICMPv4Type.of(icmpType.icmpType())); |
| 378 | break; |
| 379 | case ICMPV4_CODE: |
| 380 | IcmpCodeCriterion icmpCode = (IcmpCodeCriterion) c; |
| 381 | mBuilder.setExact(MatchField.ICMPV4_CODE, |
| 382 | ICMPv4Code.of(icmpCode.icmpCode())); |
| 383 | break; |
| 384 | case IPV6_SRC: |
| 385 | ipCriterion = (IPCriterion) c; |
| 386 | ip6Prefix = ipCriterion.ip().getIp6Prefix(); |
| 387 | if (ip6Prefix.prefixLength() != Ip6Prefix.MAX_MASK_LENGTH) { |
| 388 | Ip6Address maskAddr = |
| 389 | Ip6Address.makeMaskPrefix(ip6Prefix.prefixLength()); |
| 390 | Masked<IPv6Address> maskedIp = |
| 391 | Masked.of(IPv6Address.of(ip6Prefix.address().toString()), |
| 392 | IPv6Address.of(maskAddr.toString())); |
| 393 | mBuilder.setMasked(MatchField.IPV6_SRC, maskedIp); |
| 394 | } else { |
| 395 | mBuilder.setExact(MatchField.IPV6_SRC, |
| 396 | IPv6Address.of(ip6Prefix.address().toString())); |
| 397 | } |
| 398 | break; |
| 399 | case IPV6_DST: |
| 400 | ipCriterion = (IPCriterion) c; |
| 401 | ip6Prefix = ipCriterion.ip().getIp6Prefix(); |
| 402 | if (ip6Prefix.prefixLength() != Ip6Prefix.MAX_MASK_LENGTH) { |
| 403 | Ip6Address maskAddr = |
| 404 | Ip6Address.makeMaskPrefix(ip6Prefix.prefixLength()); |
| 405 | Masked<IPv6Address> maskedIp = |
| 406 | Masked.of(IPv6Address.of(ip6Prefix.address().toString()), |
| 407 | IPv6Address.of(maskAddr.toString())); |
| 408 | mBuilder.setMasked(MatchField.IPV6_DST, maskedIp); |
| 409 | } else { |
| 410 | mBuilder.setExact(MatchField.IPV6_DST, |
| 411 | IPv6Address.of(ip6Prefix.address().toString())); |
| 412 | } |
| 413 | break; |
| 414 | case IPV6_FLABEL: |
| 415 | IPv6FlowLabelCriterion flowLabelCriterion = |
| 416 | (IPv6FlowLabelCriterion) c; |
| 417 | mBuilder.setExact(MatchField.IPV6_FLABEL, |
| 418 | IPv6FlowLabel.of(flowLabelCriterion.flowLabel())); |
| 419 | break; |
| 420 | case ICMPV6_TYPE: |
| 421 | Icmpv6TypeCriterion icmpv6Type = (Icmpv6TypeCriterion) c; |
| 422 | mBuilder.setExact(MatchField.ICMPV6_TYPE, |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 423 | U8.of(icmpv6Type.icmpv6Type())); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 424 | break; |
| 425 | case ICMPV6_CODE: |
| 426 | Icmpv6CodeCriterion icmpv6Code = (Icmpv6CodeCriterion) c; |
| 427 | mBuilder.setExact(MatchField.ICMPV6_CODE, |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 428 | U8.of(icmpv6Code.icmpv6Code())); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 429 | break; |
| 430 | case IPV6_ND_TARGET: |
| 431 | IPv6NDTargetAddressCriterion targetAddressCriterion = |
| 432 | (IPv6NDTargetAddressCriterion) c; |
| 433 | ip6Address = targetAddressCriterion.targetAddress(); |
| 434 | mBuilder.setExact(MatchField.IPV6_ND_TARGET, |
| 435 | IPv6Address.of(ip6Address.toOctets())); |
| 436 | break; |
| 437 | case IPV6_ND_SLL: |
| 438 | llAddressCriterion = |
| 439 | (IPv6NDLinkLayerAddressCriterion) c; |
| 440 | mBuilder.setExact(MatchField.IPV6_ND_SLL, |
| 441 | MacAddress.of(llAddressCriterion.mac().toLong())); |
| 442 | break; |
| 443 | case IPV6_ND_TLL: |
| 444 | llAddressCriterion = |
| 445 | (IPv6NDLinkLayerAddressCriterion) c; |
| 446 | mBuilder.setExact(MatchField.IPV6_ND_TLL, |
| 447 | MacAddress.of(llAddressCriterion.mac().toLong())); |
Jonathan Hart | 34bc614 | 2014-10-17 11:00:43 -0700 | [diff] [blame] | 448 | break; |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 449 | case MPLS_LABEL: |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 450 | MplsCriterion mp = (MplsCriterion) c; |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 451 | mBuilder.setExact(MatchField.MPLS_LABEL, U32.of(mp.label().toInt())); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 452 | break; |
Pavlin Radoslavov | 5e4f754 | 2015-02-06 18:18:21 -0800 | [diff] [blame] | 453 | case IPV6_EXTHDR: |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 454 | IPv6ExthdrFlagsCriterion exthdrFlagsCriterion = |
| 455 | (IPv6ExthdrFlagsCriterion) c; |
Pavlin Radoslavov | 5e4f754 | 2015-02-06 18:18:21 -0800 | [diff] [blame] | 456 | mBuilder.setExact(MatchField.IPV6_EXTHDR, |
| 457 | U16.of(exthdrFlagsCriterion.exthdrFlags())); |
| 458 | break; |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 459 | case OCH_SIGID: |
Sho SHIMIZU | c15ce51 | 2015-05-26 16:54:08 -0700 | [diff] [blame] | 460 | try { |
| 461 | OchSignalCriterion ochSignalCriterion = (OchSignalCriterion) c; |
| 462 | OchSignal signal = ochSignalCriterion.lambda(); |
Sho SHIMIZU | c17042d | 2015-05-28 12:07:23 -0700 | [diff] [blame] | 463 | byte gridType = OpenFlowValueMapper.lookupGridType(signal.gridType()); |
| 464 | byte channelSpacing = OpenFlowValueMapper.lookupChannelSpacing(signal.channelSpacing()); |
Yafit Hadar | 7351461 | 2015-11-04 10:14:21 +0200 | [diff] [blame] | 465 | mBuilder.setExact(MatchField.EXP_OCH_SIG_ID, |
Sho SHIMIZU | c15ce51 | 2015-05-26 16:54:08 -0700 | [diff] [blame] | 466 | new CircuitSignalID(gridType, channelSpacing, |
| 467 | (short) signal.spacingMultiplier(), (short) signal.slotGranularity())); |
Sho SHIMIZU | c17042d | 2015-05-28 12:07:23 -0700 | [diff] [blame] | 468 | } catch (NoMappingFoundException e) { |
Sho SHIMIZU | c15ce51 | 2015-05-26 16:54:08 -0700 | [diff] [blame] | 469 | log.warn(e.getMessage()); |
| 470 | } |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 471 | break; |
Praseed Balakrishnan | 2dd5abd | 2014-11-03 14:56:28 -0800 | [diff] [blame] | 472 | case OCH_SIGTYPE: |
Yafit Hadar | 7351461 | 2015-11-04 10:14:21 +0200 | [diff] [blame] | 473 | try { |
| 474 | OchSignalTypeCriterion sc = (OchSignalTypeCriterion) c; |
| 475 | byte signalType = OpenFlowValueMapper.lookupOchSignalType(sc.signalType()); |
| 476 | mBuilder.setExact(MatchField.EXP_OCH_SIGTYPE, U8.of(signalType)); |
| 477 | } catch (NoMappingFoundException e) { |
| 478 | log.warn(e.getMessage()); |
| 479 | } |
| 480 | break; |
| 481 | case ODU_SIGID: |
| 482 | OduSignalIdCriterion oduSignalIdCriterion = (OduSignalIdCriterion) c; |
| 483 | OduSignalId oduSignalId = oduSignalIdCriterion.oduSignalId(); |
| 484 | mBuilder.setExact(MatchField.EXP_ODU_SIG_ID, |
| 485 | new OduSignalID((short) oduSignalId.tributaryPortNumber(), |
| 486 | (short) oduSignalId.tributarySlotLength(), |
| 487 | oduSignalId.tributarySlotBitmap())); |
| 488 | break; |
| 489 | case ODU_SIGTYPE: |
| 490 | try { |
| 491 | OduSignalTypeCriterion oduSignalTypeCriterion = (OduSignalTypeCriterion) c; |
| 492 | byte oduSigType = OpenFlowValueMapper.lookupOduSignalType(oduSignalTypeCriterion.signalType()); |
| 493 | mBuilder.setExact(MatchField.EXP_ODU_SIGTYPE, U8.of(oduSigType)); |
| 494 | } catch (NoMappingFoundException e) { |
| 495 | log.warn(e.getMessage()); |
| 496 | } |
Praseed Balakrishnan | 2dd5abd | 2014-11-03 14:56:28 -0800 | [diff] [blame] | 497 | break; |
Hyunsun Moon | a08c5d0 | 2015-07-14 17:53:00 -0700 | [diff] [blame] | 498 | case TUNNEL_ID: |
| 499 | TunnelIdCriterion tunnelId = (TunnelIdCriterion) c; |
| 500 | mBuilder.setExact(MatchField.TUNNEL_ID, |
| 501 | U64.of(tunnelId.tunnelId())); |
| 502 | break; |
Saurav Das | ffc5bbc | 2015-08-18 23:30:19 -0700 | [diff] [blame] | 503 | case MPLS_BOS: |
| 504 | MplsBosCriterion mplsBos = (MplsBosCriterion) c; |
| 505 | mBuilder.setExact(MatchField.MPLS_BOS, |
| 506 | mplsBos.mplsBos() ? OFBooleanValue.TRUE |
| 507 | : OFBooleanValue.FALSE); |
| 508 | break; |
BitOhenry | b40129a | 2015-11-30 12:41:18 +0800 | [diff] [blame] | 509 | case ARP_OP: |
| 510 | ArpOpCriterion arpOp = (ArpOpCriterion) c; |
| 511 | mBuilder.setExact(MatchField.ARP_OP, |
| 512 | ArpOpcode.of(arpOp.arpOp())); |
| 513 | break; |
BitOhenry | a331b18 | 2015-11-23 08:39:37 +0800 | [diff] [blame] | 514 | case ARP_SHA: |
| 515 | arpHaCriterion = (ArpHaCriterion) c; |
| 516 | mBuilder.setExact(MatchField.ARP_SHA, |
| 517 | MacAddress.of(arpHaCriterion.mac().toLong())); |
| 518 | break; |
BitOhenry | 296b454 | 2015-11-24 08:41:58 +0800 | [diff] [blame] | 519 | case ARP_SPA: |
| 520 | arpPaCriterion = (ArpPaCriterion) c; |
| 521 | mBuilder.setExact(MatchField.ARP_SPA, |
| 522 | IPv4Address.of(arpPaCriterion.ip().toInt())); |
| 523 | break; |
BitOhenry | 7643085 | 2015-11-20 19:04:49 +0800 | [diff] [blame] | 524 | case ARP_THA: |
| 525 | arpHaCriterion = (ArpHaCriterion) c; |
| 526 | mBuilder.setExact(MatchField.ARP_THA, |
| 527 | MacAddress.of(arpHaCriterion.mac().toLong())); |
| 528 | break; |
BitOhenry | c1e5fcc | 2015-11-23 20:47:53 +0800 | [diff] [blame] | 529 | case ARP_TPA: |
| 530 | arpPaCriterion = (ArpPaCriterion) c; |
| 531 | mBuilder.setExact(MatchField.ARP_TPA, |
| 532 | IPv4Address.of(arpPaCriterion.ip().toInt())); |
| 533 | break; |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 534 | case EXTENSION: |
| 535 | ExtensionCriterion extensionCriterion = (ExtensionCriterion) c; |
| 536 | OFOxm oxm = buildExtensionOxm(extensionCriterion.extensionSelector()); |
| 537 | if (oxm == null) { |
| 538 | log.warn("Unable to build extension selector"); |
| 539 | break; |
| 540 | } |
| 541 | |
| 542 | if (oxm.isMasked()) { |
| 543 | mBuilder.setMasked(oxm.getMatchField(), oxm.getValue(), oxm.getMask()); |
| 544 | } else { |
| 545 | mBuilder.setExact(oxm.getMatchField(), oxm.getValue()); |
| 546 | } |
| 547 | |
| 548 | break; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 549 | case MPLS_TC: |
| 550 | case PBB_ISID: |
Jian Li | f1ecf99 | 2015-12-02 17:48:54 -0800 | [diff] [blame] | 551 | // TODO: need to implement PBB-ISID case when OpenFlowJ is ready |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 552 | default: |
| 553 | log.warn("Match type {} not yet implemented.", c.type()); |
| 554 | } |
| 555 | } |
| 556 | return mBuilder.build(); |
| 557 | } |
| 558 | |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 559 | /** |
| 560 | * Returns the flow rule for this builder. |
| 561 | * |
| 562 | * @return the flow rule |
| 563 | */ |
| 564 | protected FlowRule flowRule() { |
| 565 | return flowRule; |
| 566 | } |
alshabib | 219ebaa | 2014-09-22 15:41:24 -0700 | [diff] [blame] | 567 | |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 568 | /** |
| 569 | * Returns the factory used for building OpenFlow constructs. |
| 570 | * |
| 571 | * @return the factory |
| 572 | */ |
| 573 | protected OFFactory factory() { |
| 574 | return factory; |
| 575 | } |
alshabib | 219ebaa | 2014-09-22 15:41:24 -0700 | [diff] [blame] | 576 | |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 577 | private OFOxm buildExtensionOxm(ExtensionSelector extension) { |
| 578 | if (!driverService.isPresent()) { |
| 579 | log.error("No driver service present"); |
| 580 | return null; |
| 581 | } |
| 582 | Driver driver = driverService.get().getDriver(deviceId); |
| 583 | if (driver.hasBehaviour(ExtensionSelectorInterpreter.class)) { |
| 584 | DefaultDriverHandler handler = |
| 585 | new DefaultDriverHandler(new DefaultDriverData(driver, deviceId)); |
| 586 | ExtensionSelectorInterpreter interpreter = handler.behaviour(ExtensionSelectorInterpreter.class); |
| 587 | |
| 588 | return interpreter.mapSelector(factory(), extension); |
| 589 | } |
| 590 | |
| 591 | return null; |
| 592 | } |
| 593 | |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 594 | } |