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