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