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