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