Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 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; |
Sho SHIMIZU | c15ce51 | 2015-05-26 16:54:08 -0700 | [diff] [blame] | 23 | import org.onosproject.net.OchSignal; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 24 | import org.onosproject.net.driver.DriverService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 25 | import org.onosproject.net.flow.FlowRule; |
| 26 | import org.onosproject.net.flow.TrafficSelector; |
Saurav Das | ffc5bbc | 2015-08-18 23:30:19 -0700 | [diff] [blame] | 27 | import org.onosproject.net.flow.criteria.Criterion; |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 28 | import org.onosproject.net.flow.criteria.EthCriterion; |
| 29 | import org.onosproject.net.flow.criteria.EthTypeCriterion; |
| 30 | import org.onosproject.net.flow.criteria.IPCriterion; |
| 31 | import org.onosproject.net.flow.criteria.IPDscpCriterion; |
| 32 | import org.onosproject.net.flow.criteria.IPEcnCriterion; |
| 33 | import org.onosproject.net.flow.criteria.IPProtocolCriterion; |
| 34 | import org.onosproject.net.flow.criteria.IPv6ExthdrFlagsCriterion; |
| 35 | import org.onosproject.net.flow.criteria.IPv6FlowLabelCriterion; |
| 36 | import org.onosproject.net.flow.criteria.IPv6NDLinkLayerAddressCriterion; |
| 37 | import org.onosproject.net.flow.criteria.IPv6NDTargetAddressCriterion; |
| 38 | import org.onosproject.net.flow.criteria.IcmpCodeCriterion; |
| 39 | import org.onosproject.net.flow.criteria.IcmpTypeCriterion; |
| 40 | import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion; |
| 41 | import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion; |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 42 | import org.onosproject.net.flow.criteria.MetadataCriterion; |
Saurav Das | ffc5bbc | 2015-08-18 23:30:19 -0700 | [diff] [blame] | 43 | import org.onosproject.net.flow.criteria.MplsBosCriterion; |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 44 | import org.onosproject.net.flow.criteria.MplsCriterion; |
Sho SHIMIZU | c15ce51 | 2015-05-26 16:54:08 -0700 | [diff] [blame] | 45 | import org.onosproject.net.flow.criteria.OchSignalCriterion; |
Marc De Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 46 | import org.onosproject.net.flow.criteria.OchSignalTypeCriterion; |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 47 | import org.onosproject.net.flow.criteria.PortCriterion; |
| 48 | import org.onosproject.net.flow.criteria.SctpPortCriterion; |
| 49 | import org.onosproject.net.flow.criteria.TcpPortCriterion; |
Hyunsun Moon | a08c5d0 | 2015-07-14 17:53:00 -0700 | [diff] [blame] | 50 | import org.onosproject.net.flow.criteria.TunnelIdCriterion; |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 51 | import org.onosproject.net.flow.criteria.UdpPortCriterion; |
| 52 | import org.onosproject.net.flow.criteria.VlanIdCriterion; |
| 53 | import org.onosproject.net.flow.criteria.VlanPcpCriterion; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 54 | import org.projectfloodlight.openflow.protocol.OFFactory; |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 55 | import org.projectfloodlight.openflow.protocol.OFFlowAdd; |
| 56 | import org.projectfloodlight.openflow.protocol.OFFlowDelete; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 57 | import org.projectfloodlight.openflow.protocol.OFFlowMod; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 58 | import org.projectfloodlight.openflow.protocol.match.Match; |
| 59 | import org.projectfloodlight.openflow.protocol.match.MatchField; |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 60 | import org.projectfloodlight.openflow.types.CircuitSignalID; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 61 | import org.projectfloodlight.openflow.types.EthType; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 62 | import org.projectfloodlight.openflow.types.ICMPv4Code; |
| 63 | import org.projectfloodlight.openflow.types.ICMPv4Type; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 64 | import org.projectfloodlight.openflow.types.IPv4Address; |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 65 | import org.projectfloodlight.openflow.types.IPv6Address; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 66 | import org.projectfloodlight.openflow.types.IPv6FlowLabel; |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 67 | import org.projectfloodlight.openflow.types.IpDscp; |
| 68 | import org.projectfloodlight.openflow.types.IpEcn; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 69 | import org.projectfloodlight.openflow.types.IpProtocol; |
| 70 | import org.projectfloodlight.openflow.types.MacAddress; |
| 71 | import org.projectfloodlight.openflow.types.Masked; |
Saurav Das | ffc5bbc | 2015-08-18 23:30:19 -0700 | [diff] [blame] | 72 | import org.projectfloodlight.openflow.types.OFBooleanValue; |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 73 | import org.projectfloodlight.openflow.types.OFMetadata; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 74 | import org.projectfloodlight.openflow.types.OFPort; |
| 75 | import org.projectfloodlight.openflow.types.OFVlanVidMatch; |
Jonathan Hart | 34bc614 | 2014-10-17 11:00:43 -0700 | [diff] [blame] | 76 | import org.projectfloodlight.openflow.types.TransportPort; |
Pavlin Radoslavov | 5e4f754 | 2015-02-06 18:18:21 -0800 | [diff] [blame] | 77 | import org.projectfloodlight.openflow.types.U16; |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 78 | import org.projectfloodlight.openflow.types.U32; |
Hyunsun Moon | a08c5d0 | 2015-07-14 17:53:00 -0700 | [diff] [blame] | 79 | import org.projectfloodlight.openflow.types.U64; |
Praseed Balakrishnan | 2dd5abd | 2014-11-03 14:56:28 -0800 | [diff] [blame] | 80 | import org.projectfloodlight.openflow.types.U8; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 81 | import org.projectfloodlight.openflow.types.VlanPcp; |
| 82 | import org.projectfloodlight.openflow.types.VlanVid; |
| 83 | import org.slf4j.Logger; |
| 84 | |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 85 | import java.util.Optional; |
| 86 | |
| 87 | import static org.slf4j.LoggerFactory.getLogger; |
| 88 | |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 89 | /** |
| 90 | * Builder for OpenFlow flow mods based on FlowRules. |
| 91 | */ |
| 92 | public abstract class FlowModBuilder { |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 93 | |
| 94 | private final Logger log = getLogger(getClass()); |
| 95 | |
| 96 | private final OFFactory factory; |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 97 | private final FlowRule flowRule; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 98 | private final TrafficSelector selector; |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 99 | protected final Long xid; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 100 | protected final Optional<DriverService> driverService; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 101 | |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 102 | /** |
| 103 | * Creates a new flow mod builder. |
| 104 | * |
| 105 | * @param flowRule the flow rule to transform into a flow mod |
| 106 | * @param factory the OpenFlow factory to use to build the flow mod |
Pavlin Radoslavov | 119fd5c | 2014-11-25 19:08:19 -0800 | [diff] [blame] | 107 | * @param xid the transaction ID |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 108 | * @return the new flow mod builder |
| 109 | */ |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 110 | public static FlowModBuilder builder(FlowRule flowRule, |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 111 | OFFactory factory, |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 112 | Optional<Long> xid, |
| 113 | Optional<DriverService> driverService) { |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 114 | switch (factory.getVersion()) { |
| 115 | case OF_10: |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 116 | return new FlowModBuilderVer10(flowRule, factory, xid, driverService); |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 117 | case OF_13: |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 118 | return new FlowModBuilderVer13(flowRule, factory, xid, driverService); |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 119 | default: |
| 120 | throw new UnsupportedOperationException( |
| 121 | "No flow mod builder for protocol version " + factory.getVersion()); |
| 122 | } |
| 123 | } |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 124 | |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 125 | /** |
| 126 | * Constructs a flow mod builder. |
| 127 | * |
| 128 | * @param flowRule the flow rule to transform into a flow mod |
| 129 | * @param factory the OpenFlow factory to use to build the flow mod |
Pavlin Radoslavov | 119fd5c | 2014-11-25 19:08:19 -0800 | [diff] [blame] | 130 | * @param xid the transaction ID |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 131 | */ |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 132 | protected FlowModBuilder(FlowRule flowRule, OFFactory factory, Optional<Long> xid, |
| 133 | Optional<DriverService> driverService) { |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 134 | this.factory = factory; |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 135 | this.flowRule = flowRule; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 136 | this.selector = flowRule.selector(); |
Sho SHIMIZU | c14b2a2 | 2015-05-05 18:15:13 -0700 | [diff] [blame] | 137 | this.xid = xid.orElse(0L); |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 138 | this.driverService = driverService; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 141 | /** |
| 142 | * Builds an ADD flow mod. |
| 143 | * |
| 144 | * @return the flow mod |
| 145 | */ |
| 146 | public abstract OFFlowAdd buildFlowAdd(); |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 147 | |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 148 | /** |
| 149 | * Builds a MODIFY flow mod. |
| 150 | * |
| 151 | * @return the flow mod |
| 152 | */ |
| 153 | public abstract OFFlowMod buildFlowMod(); |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 154 | |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 155 | /** |
| 156 | * Builds a DELETE flow mod. |
| 157 | * |
| 158 | * @return the flow mod |
| 159 | */ |
| 160 | public abstract OFFlowDelete buildFlowDel(); |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 161 | |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 162 | /** |
| 163 | * Builds the match for the flow mod. |
| 164 | * |
| 165 | * @return the match |
| 166 | */ |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 167 | // CHECKSTYLE IGNORE MethodLength FOR NEXT 300 LINES |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 168 | protected Match buildMatch() { |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 169 | Match.Builder mBuilder = factory.buildMatch(); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 170 | Ip6Address ip6Address; |
Pavlin Radoslavov | 23e398d | 2014-11-05 15:17:57 -0800 | [diff] [blame] | 171 | Ip4Prefix ip4Prefix; |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 172 | Ip6Prefix ip6Prefix; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 173 | EthCriterion ethCriterion; |
| 174 | IPCriterion ipCriterion; |
| 175 | TcpPortCriterion tcpPortCriterion; |
| 176 | UdpPortCriterion udpPortCriterion; |
| 177 | SctpPortCriterion sctpPortCriterion; |
| 178 | IPv6NDLinkLayerAddressCriterion llAddressCriterion; |
| 179 | |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 180 | for (Criterion c : selector.criteria()) { |
| 181 | switch (c.type()) { |
| 182 | case IN_PORT: |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 183 | PortCriterion inPort = (PortCriterion) c; |
| 184 | mBuilder.setExact(MatchField.IN_PORT, |
| 185 | OFPort.of((int) inPort.port().toLong())); |
| 186 | break; |
| 187 | case IN_PHY_PORT: |
| 188 | PortCriterion inPhyPort = (PortCriterion) c; |
| 189 | mBuilder.setExact(MatchField.IN_PORT, |
| 190 | OFPort.of((int) inPhyPort.port().toLong())); |
| 191 | break; |
| 192 | case METADATA: |
| 193 | MetadataCriterion metadata = (MetadataCriterion) c; |
| 194 | mBuilder.setExact(MatchField.METADATA, |
| 195 | OFMetadata.ofRaw(metadata.metadata())); |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 196 | break; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 197 | case ETH_DST: |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 198 | ethCriterion = (EthCriterion) c; |
| 199 | mBuilder.setExact(MatchField.ETH_DST, |
| 200 | MacAddress.of(ethCriterion.mac().toLong())); |
| 201 | break; |
| 202 | case ETH_SRC: |
| 203 | ethCriterion = (EthCriterion) c; |
| 204 | mBuilder.setExact(MatchField.ETH_SRC, |
| 205 | MacAddress.of(ethCriterion.mac().toLong())); |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 206 | break; |
| 207 | case ETH_TYPE: |
| 208 | EthTypeCriterion ethType = (EthTypeCriterion) c; |
alshabib | caf1ca2 | 2015-06-25 15:18:16 -0700 | [diff] [blame] | 209 | mBuilder.setExact(MatchField.ETH_TYPE, EthType.of(ethType.ethType().toShort())); |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 210 | break; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 211 | case VLAN_VID: |
| 212 | VlanIdCriterion vid = (VlanIdCriterion) c; |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 213 | |
| 214 | if (vid.vlanId().equals(VlanId.ANY)) { |
| 215 | mBuilder.setMasked(MatchField.VLAN_VID, OFVlanVidMatch.PRESENT, |
| 216 | OFVlanVidMatch.PRESENT); |
Jonathan Hart | 1468fee | 2015-07-16 18:50:34 -0700 | [diff] [blame] | 217 | } else if (vid.vlanId().equals(VlanId.NONE)) { |
| 218 | mBuilder.setExact(MatchField.VLAN_VID, OFVlanVidMatch.NONE); |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 219 | } else { |
| 220 | mBuilder.setExact(MatchField.VLAN_VID, |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 221 | OFVlanVidMatch.ofVlanVid(VlanVid.ofVlan(vid.vlanId().toShort()))); |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 222 | } |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 223 | break; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 224 | case VLAN_PCP: |
| 225 | VlanPcpCriterion vpcp = (VlanPcpCriterion) c; |
| 226 | mBuilder.setExact(MatchField.VLAN_PCP, VlanPcp.of(vpcp.priority())); |
| 227 | break; |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 228 | case IP_DSCP: |
| 229 | IPDscpCriterion ipDscpCriterion = (IPDscpCriterion) c; |
| 230 | mBuilder.setExact(MatchField.IP_DSCP, |
| 231 | IpDscp.of(ipDscpCriterion.ipDscp())); |
| 232 | break; |
| 233 | case IP_ECN: |
| 234 | IPEcnCriterion ipEcnCriterion = (IPEcnCriterion) c; |
| 235 | mBuilder.setExact(MatchField.IP_ECN, |
| 236 | IpEcn.of(ipEcnCriterion.ipEcn())); |
| 237 | break; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 238 | case IP_PROTO: |
| 239 | IPProtocolCriterion p = (IPProtocolCriterion) c; |
| 240 | mBuilder.setExact(MatchField.IP_PROTO, IpProtocol.of(p.protocol())); |
| 241 | break; |
| 242 | case IPV4_SRC: |
| 243 | ipCriterion = (IPCriterion) c; |
| 244 | ip4Prefix = ipCriterion.ip().getIp4Prefix(); |
| 245 | if (ip4Prefix.prefixLength() != Ip4Prefix.MAX_MASK_LENGTH) { |
| 246 | Ip4Address maskAddr = |
| 247 | Ip4Address.makeMaskPrefix(ip4Prefix.prefixLength()); |
| 248 | Masked<IPv4Address> maskedIp = |
| 249 | Masked.of(IPv4Address.of(ip4Prefix.address().toInt()), |
| 250 | IPv4Address.of(maskAddr.toInt())); |
| 251 | mBuilder.setMasked(MatchField.IPV4_SRC, maskedIp); |
| 252 | } else { |
| 253 | mBuilder.setExact(MatchField.IPV4_SRC, |
| 254 | IPv4Address.of(ip4Prefix.address().toInt())); |
| 255 | } |
| 256 | break; |
| 257 | case IPV4_DST: |
| 258 | ipCriterion = (IPCriterion) c; |
| 259 | ip4Prefix = ipCriterion.ip().getIp4Prefix(); |
| 260 | if (ip4Prefix.prefixLength() != Ip4Prefix.MAX_MASK_LENGTH) { |
| 261 | Ip4Address maskAddr = |
| 262 | Ip4Address.makeMaskPrefix(ip4Prefix.prefixLength()); |
| 263 | Masked<IPv4Address> maskedIp = |
| 264 | Masked.of(IPv4Address.of(ip4Prefix.address().toInt()), |
| 265 | IPv4Address.of(maskAddr.toInt())); |
| 266 | mBuilder.setMasked(MatchField.IPV4_DST, maskedIp); |
| 267 | } else { |
| 268 | mBuilder.setExact(MatchField.IPV4_DST, |
| 269 | IPv4Address.of(ip4Prefix.address().toInt())); |
| 270 | } |
Jonathan Hart | 34bc614 | 2014-10-17 11:00:43 -0700 | [diff] [blame] | 271 | break; |
| 272 | case TCP_SRC: |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 273 | tcpPortCriterion = (TcpPortCriterion) c; |
| 274 | mBuilder.setExact(MatchField.TCP_SRC, |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 275 | TransportPort.of(tcpPortCriterion.tcpPort().toInt())); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 276 | break; |
| 277 | case TCP_DST: |
| 278 | tcpPortCriterion = (TcpPortCriterion) c; |
| 279 | mBuilder.setExact(MatchField.TCP_DST, |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 280 | TransportPort.of(tcpPortCriterion.tcpPort().toInt())); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 281 | break; |
| 282 | case UDP_SRC: |
| 283 | udpPortCriterion = (UdpPortCriterion) c; |
| 284 | mBuilder.setExact(MatchField.UDP_SRC, |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 285 | TransportPort.of(udpPortCriterion.udpPort().toInt())); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 286 | break; |
| 287 | case UDP_DST: |
| 288 | udpPortCriterion = (UdpPortCriterion) c; |
| 289 | mBuilder.setExact(MatchField.UDP_DST, |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 290 | TransportPort.of(udpPortCriterion.udpPort().toInt())); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 291 | break; |
| 292 | case SCTP_SRC: |
| 293 | sctpPortCriterion = (SctpPortCriterion) c; |
| 294 | mBuilder.setExact(MatchField.SCTP_SRC, |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 295 | TransportPort.of(sctpPortCriterion.sctpPort().toInt())); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 296 | break; |
| 297 | case SCTP_DST: |
| 298 | sctpPortCriterion = (SctpPortCriterion) c; |
| 299 | mBuilder.setExact(MatchField.SCTP_DST, |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 300 | TransportPort.of(sctpPortCriterion.sctpPort().toInt())); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 301 | break; |
| 302 | case ICMPV4_TYPE: |
| 303 | IcmpTypeCriterion icmpType = (IcmpTypeCriterion) c; |
| 304 | mBuilder.setExact(MatchField.ICMPV4_TYPE, |
| 305 | ICMPv4Type.of(icmpType.icmpType())); |
| 306 | break; |
| 307 | case ICMPV4_CODE: |
| 308 | IcmpCodeCriterion icmpCode = (IcmpCodeCriterion) c; |
| 309 | mBuilder.setExact(MatchField.ICMPV4_CODE, |
| 310 | ICMPv4Code.of(icmpCode.icmpCode())); |
| 311 | break; |
| 312 | case IPV6_SRC: |
| 313 | ipCriterion = (IPCriterion) c; |
| 314 | ip6Prefix = ipCriterion.ip().getIp6Prefix(); |
| 315 | if (ip6Prefix.prefixLength() != Ip6Prefix.MAX_MASK_LENGTH) { |
| 316 | Ip6Address maskAddr = |
| 317 | Ip6Address.makeMaskPrefix(ip6Prefix.prefixLength()); |
| 318 | Masked<IPv6Address> maskedIp = |
| 319 | Masked.of(IPv6Address.of(ip6Prefix.address().toString()), |
| 320 | IPv6Address.of(maskAddr.toString())); |
| 321 | mBuilder.setMasked(MatchField.IPV6_SRC, maskedIp); |
| 322 | } else { |
| 323 | mBuilder.setExact(MatchField.IPV6_SRC, |
| 324 | IPv6Address.of(ip6Prefix.address().toString())); |
| 325 | } |
| 326 | break; |
| 327 | case IPV6_DST: |
| 328 | ipCriterion = (IPCriterion) c; |
| 329 | ip6Prefix = ipCriterion.ip().getIp6Prefix(); |
| 330 | if (ip6Prefix.prefixLength() != Ip6Prefix.MAX_MASK_LENGTH) { |
| 331 | Ip6Address maskAddr = |
| 332 | Ip6Address.makeMaskPrefix(ip6Prefix.prefixLength()); |
| 333 | Masked<IPv6Address> maskedIp = |
| 334 | Masked.of(IPv6Address.of(ip6Prefix.address().toString()), |
| 335 | IPv6Address.of(maskAddr.toString())); |
| 336 | mBuilder.setMasked(MatchField.IPV6_DST, maskedIp); |
| 337 | } else { |
| 338 | mBuilder.setExact(MatchField.IPV6_DST, |
| 339 | IPv6Address.of(ip6Prefix.address().toString())); |
| 340 | } |
| 341 | break; |
| 342 | case IPV6_FLABEL: |
| 343 | IPv6FlowLabelCriterion flowLabelCriterion = |
| 344 | (IPv6FlowLabelCriterion) c; |
| 345 | mBuilder.setExact(MatchField.IPV6_FLABEL, |
| 346 | IPv6FlowLabel.of(flowLabelCriterion.flowLabel())); |
| 347 | break; |
| 348 | case ICMPV6_TYPE: |
| 349 | Icmpv6TypeCriterion icmpv6Type = (Icmpv6TypeCriterion) c; |
| 350 | mBuilder.setExact(MatchField.ICMPV6_TYPE, |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 351 | U8.of(icmpv6Type.icmpv6Type())); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 352 | break; |
| 353 | case ICMPV6_CODE: |
| 354 | Icmpv6CodeCriterion icmpv6Code = (Icmpv6CodeCriterion) c; |
| 355 | mBuilder.setExact(MatchField.ICMPV6_CODE, |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 356 | U8.of(icmpv6Code.icmpv6Code())); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 357 | break; |
| 358 | case IPV6_ND_TARGET: |
| 359 | IPv6NDTargetAddressCriterion targetAddressCriterion = |
| 360 | (IPv6NDTargetAddressCriterion) c; |
| 361 | ip6Address = targetAddressCriterion.targetAddress(); |
| 362 | mBuilder.setExact(MatchField.IPV6_ND_TARGET, |
| 363 | IPv6Address.of(ip6Address.toOctets())); |
| 364 | break; |
| 365 | case IPV6_ND_SLL: |
| 366 | llAddressCriterion = |
| 367 | (IPv6NDLinkLayerAddressCriterion) c; |
| 368 | mBuilder.setExact(MatchField.IPV6_ND_SLL, |
| 369 | MacAddress.of(llAddressCriterion.mac().toLong())); |
| 370 | break; |
| 371 | case IPV6_ND_TLL: |
| 372 | llAddressCriterion = |
| 373 | (IPv6NDLinkLayerAddressCriterion) c; |
| 374 | mBuilder.setExact(MatchField.IPV6_ND_TLL, |
| 375 | MacAddress.of(llAddressCriterion.mac().toLong())); |
Jonathan Hart | 34bc614 | 2014-10-17 11:00:43 -0700 | [diff] [blame] | 376 | break; |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 377 | case MPLS_LABEL: |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 378 | MplsCriterion mp = (MplsCriterion) c; |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 379 | mBuilder.setExact(MatchField.MPLS_LABEL, U32.of(mp.label().toInt())); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 380 | break; |
Pavlin Radoslavov | 5e4f754 | 2015-02-06 18:18:21 -0800 | [diff] [blame] | 381 | case IPV6_EXTHDR: |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 382 | IPv6ExthdrFlagsCriterion exthdrFlagsCriterion = |
| 383 | (IPv6ExthdrFlagsCriterion) c; |
Pavlin Radoslavov | 5e4f754 | 2015-02-06 18:18:21 -0800 | [diff] [blame] | 384 | mBuilder.setExact(MatchField.IPV6_EXTHDR, |
| 385 | U16.of(exthdrFlagsCriterion.exthdrFlags())); |
| 386 | break; |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 387 | case OCH_SIGID: |
Sho SHIMIZU | c15ce51 | 2015-05-26 16:54:08 -0700 | [diff] [blame] | 388 | try { |
| 389 | OchSignalCriterion ochSignalCriterion = (OchSignalCriterion) c; |
| 390 | OchSignal signal = ochSignalCriterion.lambda(); |
Sho SHIMIZU | c17042d | 2015-05-28 12:07:23 -0700 | [diff] [blame] | 391 | byte gridType = OpenFlowValueMapper.lookupGridType(signal.gridType()); |
| 392 | byte channelSpacing = OpenFlowValueMapper.lookupChannelSpacing(signal.channelSpacing()); |
Sho SHIMIZU | c15ce51 | 2015-05-26 16:54:08 -0700 | [diff] [blame] | 393 | mBuilder.setExact(MatchField.OCH_SIGID, |
| 394 | new CircuitSignalID(gridType, channelSpacing, |
| 395 | (short) signal.spacingMultiplier(), (short) signal.slotGranularity())); |
Sho SHIMIZU | c17042d | 2015-05-28 12:07:23 -0700 | [diff] [blame] | 396 | } catch (NoMappingFoundException e) { |
Sho SHIMIZU | c15ce51 | 2015-05-26 16:54:08 -0700 | [diff] [blame] | 397 | log.warn(e.getMessage()); |
| 398 | } |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 399 | break; |
Praseed Balakrishnan | 2dd5abd | 2014-11-03 14:56:28 -0800 | [diff] [blame] | 400 | case OCH_SIGTYPE: |
Marc De Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 401 | OchSignalTypeCriterion sc = (OchSignalTypeCriterion) c; |
Sho SHIMIZU | c17042d | 2015-05-28 12:07:23 -0700 | [diff] [blame] | 402 | byte signalType = OpenFlowValueMapper.lookupOchSignalType(sc.signalType()); |
Marc De Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 403 | mBuilder.setExact(MatchField.OCH_SIGTYPE, U8.of(signalType)); |
Praseed Balakrishnan | 2dd5abd | 2014-11-03 14:56:28 -0800 | [diff] [blame] | 404 | break; |
Hyunsun Moon | a08c5d0 | 2015-07-14 17:53:00 -0700 | [diff] [blame] | 405 | case TUNNEL_ID: |
| 406 | TunnelIdCriterion tunnelId = (TunnelIdCriterion) c; |
| 407 | mBuilder.setExact(MatchField.TUNNEL_ID, |
| 408 | U64.of(tunnelId.tunnelId())); |
| 409 | break; |
Saurav Das | ffc5bbc | 2015-08-18 23:30:19 -0700 | [diff] [blame] | 410 | case MPLS_BOS: |
| 411 | MplsBosCriterion mplsBos = (MplsBosCriterion) c; |
| 412 | mBuilder.setExact(MatchField.MPLS_BOS, |
| 413 | mplsBos.mplsBos() ? OFBooleanValue.TRUE |
| 414 | : OFBooleanValue.FALSE); |
| 415 | break; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 416 | case ARP_OP: |
| 417 | case ARP_SHA: |
| 418 | case ARP_SPA: |
| 419 | case ARP_THA: |
| 420 | case ARP_TPA: |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 421 | case MPLS_TC: |
| 422 | case PBB_ISID: |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 423 | default: |
| 424 | log.warn("Match type {} not yet implemented.", c.type()); |
| 425 | } |
| 426 | } |
| 427 | return mBuilder.build(); |
| 428 | } |
| 429 | |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 430 | /** |
| 431 | * Returns the flow rule for this builder. |
| 432 | * |
| 433 | * @return the flow rule |
| 434 | */ |
| 435 | protected FlowRule flowRule() { |
| 436 | return flowRule; |
| 437 | } |
alshabib | 219ebaa | 2014-09-22 15:41:24 -0700 | [diff] [blame] | 438 | |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 439 | /** |
| 440 | * Returns the factory used for building OpenFlow constructs. |
| 441 | * |
| 442 | * @return the factory |
| 443 | */ |
| 444 | protected OFFactory factory() { |
| 445 | return factory; |
| 446 | } |
alshabib | 219ebaa | 2014-09-22 15:41:24 -0700 | [diff] [blame] | 447 | |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 448 | } |