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