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 | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 17 | |
| 18 | import static org.slf4j.LoggerFactory.getLogger; |
| 19 | |
| 20 | import java.util.List; |
| 21 | |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame^] | 22 | import org.onlab.packet.Ip4Address; |
| 23 | import org.onlab.packet.Ip4Prefix; |
| 24 | import org.onlab.packet.MacAddress; |
| 25 | import org.onlab.packet.VlanId; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 26 | import org.onosproject.net.DeviceId; |
| 27 | import org.onosproject.net.PortNumber; |
| 28 | import org.onosproject.net.flow.DefaultFlowEntry; |
| 29 | import org.onosproject.net.flow.DefaultFlowRule; |
| 30 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 31 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 32 | import org.onosproject.net.flow.FlowEntry; |
| 33 | import org.onosproject.net.flow.FlowEntry.FlowEntryState; |
| 34 | import org.onosproject.net.flow.FlowRule; |
| 35 | import org.onosproject.net.flow.TrafficSelector; |
| 36 | import org.onosproject.net.flow.TrafficTreatment; |
| 37 | import org.onosproject.openflow.controller.Dpid; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 38 | import org.projectfloodlight.openflow.protocol.OFFlowRemoved; |
| 39 | import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry; |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 40 | import org.projectfloodlight.openflow.protocol.OFInstructionType; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 41 | import org.projectfloodlight.openflow.protocol.action.OFAction; |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 42 | import org.projectfloodlight.openflow.protocol.action.OFActionCircuit; |
| 43 | import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 44 | import org.projectfloodlight.openflow.protocol.action.OFActionOutput; |
| 45 | import org.projectfloodlight.openflow.protocol.action.OFActionSetDlDst; |
| 46 | import org.projectfloodlight.openflow.protocol.action.OFActionSetDlSrc; |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame^] | 47 | import org.projectfloodlight.openflow.protocol.action.OFActionSetField; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 48 | import org.projectfloodlight.openflow.protocol.action.OFActionSetNwDst; |
| 49 | import org.projectfloodlight.openflow.protocol.action.OFActionSetNwSrc; |
| 50 | import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanPcp; |
| 51 | import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanVid; |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 52 | import org.projectfloodlight.openflow.protocol.instruction.OFInstruction; |
Jonathan Hart | cf78320 | 2014-11-24 18:55:42 -0800 | [diff] [blame] | 53 | import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 54 | import org.projectfloodlight.openflow.protocol.match.Match; |
| 55 | import org.projectfloodlight.openflow.protocol.match.MatchField; |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame^] | 56 | import org.projectfloodlight.openflow.protocol.oxm.OFOxm; |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 57 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigidBasic; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 58 | import org.projectfloodlight.openflow.types.IPv4Address; |
Jonathan Hart | 0e12fad | 2014-10-17 14:54:58 -0700 | [diff] [blame] | 59 | import org.projectfloodlight.openflow.types.Masked; |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame^] | 60 | import org.projectfloodlight.openflow.types.OFVlanVidMatch; |
| 61 | import org.projectfloodlight.openflow.types.VlanPcp; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 62 | import org.slf4j.Logger; |
| 63 | |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 64 | import com.google.common.collect.Lists; |
| 65 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 66 | public class FlowEntryBuilder { |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 67 | private final Logger log = getLogger(getClass()); |
| 68 | |
| 69 | private final OFFlowStatsEntry stat; |
| 70 | private final OFFlowRemoved removed; |
| 71 | |
| 72 | private final Match match; |
| 73 | private final List<OFAction> actions; |
| 74 | |
| 75 | private final Dpid dpid; |
| 76 | |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 77 | private final boolean addedRule; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 78 | |
| 79 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 80 | public FlowEntryBuilder(Dpid dpid, OFFlowStatsEntry entry) { |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 81 | this.stat = entry; |
| 82 | this.match = entry.getMatch(); |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 83 | this.actions = getActions(entry); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 84 | this.dpid = dpid; |
alshabib | 219ebaa | 2014-09-22 15:41:24 -0700 | [diff] [blame] | 85 | this.removed = null; |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 86 | this.addedRule = true; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 87 | } |
| 88 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 89 | public FlowEntryBuilder(Dpid dpid, OFFlowRemoved removed) { |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 90 | this.match = removed.getMatch(); |
| 91 | this.removed = removed; |
| 92 | |
| 93 | this.dpid = dpid; |
| 94 | this.actions = null; |
| 95 | this.stat = null; |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 96 | this.addedRule = false; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 97 | |
| 98 | } |
| 99 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 100 | public FlowEntry build() { |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 101 | if (addedRule) { |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 102 | FlowRule rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)), |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 103 | buildSelector(), buildTreatment(), stat.getPriority(), |
Jonathan Hart | bc4a793 | 2014-10-21 11:46:00 -0700 | [diff] [blame] | 104 | stat.getCookie().getValue(), stat.getIdleTimeout(), false); |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 105 | return new DefaultFlowEntry(rule, FlowEntryState.ADDED, |
| 106 | stat.getDurationSec(), stat.getPacketCount().getValue(), |
| 107 | stat.getByteCount().getValue()); |
| 108 | |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 109 | } else { |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 110 | FlowRule rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)), |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 111 | buildSelector(), null, removed.getPriority(), |
Jonathan Hart | bc4a793 | 2014-10-21 11:46:00 -0700 | [diff] [blame] | 112 | removed.getCookie().getValue(), removed.getIdleTimeout(), false); |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 113 | return new DefaultFlowEntry(rule, FlowEntryState.REMOVED, removed.getDurationSec(), |
| 114 | removed.getPacketCount().getValue(), removed.getByteCount().getValue()); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 115 | } |
| 116 | } |
| 117 | |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 118 | private List<OFAction> getActions(OFFlowStatsEntry entry) { |
| 119 | switch (entry.getVersion()) { |
| 120 | case OF_10: |
| 121 | return entry.getActions(); |
| 122 | case OF_11: |
| 123 | case OF_12: |
| 124 | case OF_13: |
| 125 | List<OFInstruction> ins = entry.getInstructions(); |
| 126 | for (OFInstruction in : ins) { |
Jonathan Hart | cf78320 | 2014-11-24 18:55:42 -0800 | [diff] [blame] | 127 | if (in.getType().equals(OFInstructionType.APPLY_ACTIONS)) { |
| 128 | OFInstructionApplyActions apply = (OFInstructionApplyActions) in; |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 129 | return apply.getActions(); |
| 130 | } |
| 131 | } |
| 132 | return Lists.newLinkedList(); |
| 133 | default: |
| 134 | log.warn("Unknown OF version {}", entry.getVersion()); |
| 135 | } |
| 136 | return Lists.newLinkedList(); |
| 137 | } |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 138 | |
| 139 | private TrafficTreatment buildTreatment() { |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 140 | TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder(); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 141 | // If this is a drop rule |
| 142 | if (actions.size() == 0) { |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 143 | builder.drop(); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 144 | return builder.build(); |
| 145 | } |
| 146 | for (OFAction act : actions) { |
| 147 | switch (act.getType()) { |
| 148 | case OUTPUT: |
| 149 | OFActionOutput out = (OFActionOutput) act; |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 150 | builder.setOutput( |
| 151 | PortNumber.portNumber(out.getPort().getPortNumber())); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 152 | break; |
| 153 | case SET_VLAN_VID: |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 154 | OFActionSetVlanVid vlan = (OFActionSetVlanVid) act; |
| 155 | builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan())); |
| 156 | break; |
| 157 | case SET_VLAN_PCP: |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 158 | OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act; |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame^] | 159 | builder.setVlanPcp(pcp.getVlanPcp().getValue()); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 160 | break; |
| 161 | case SET_DL_DST: |
| 162 | OFActionSetDlDst dldst = (OFActionSetDlDst) act; |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 163 | builder.setEthDst( |
| 164 | MacAddress.valueOf(dldst.getDlAddr().getLong())); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 165 | break; |
| 166 | case SET_DL_SRC: |
| 167 | OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act; |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 168 | builder.setEthSrc( |
| 169 | MacAddress.valueOf(dlsrc.getDlAddr().getLong())); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 170 | |
| 171 | break; |
| 172 | case SET_NW_DST: |
| 173 | OFActionSetNwDst nwdst = (OFActionSetNwDst) act; |
| 174 | IPv4Address di = nwdst.getNwAddr(); |
Pavlin Radoslavov | ff894a2 | 2014-11-05 16:09:35 -0800 | [diff] [blame] | 175 | builder.setIpDst(Ip4Address.valueOf(di.getInt())); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 176 | break; |
| 177 | case SET_NW_SRC: |
| 178 | OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act; |
| 179 | IPv4Address si = nwsrc.getNwAddr(); |
Pavlin Radoslavov | ff894a2 | 2014-11-05 16:09:35 -0800 | [diff] [blame] | 180 | builder.setIpSrc(Ip4Address.valueOf(si.getInt())); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 181 | break; |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 182 | case EXPERIMENTER: |
| 183 | OFActionExperimenter exp = (OFActionExperimenter) act; |
Praseed Balakrishnan | db8a9d2 | 2014-12-03 11:47:55 -0800 | [diff] [blame] | 184 | if (exp.getExperimenter() == 0x80005A06 || |
| 185 | exp.getExperimenter() == 0x748771) { |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 186 | OFActionCircuit ct = (OFActionCircuit) exp; |
| 187 | builder.setLambda(((OFOxmOchSigidBasic) ct.getField()).getValue().getChannelNumber()); |
| 188 | } else { |
| 189 | log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter()); |
| 190 | } |
| 191 | break; |
Jonathan Hart | 1f8e0d7 | 2014-11-25 11:13:00 -0800 | [diff] [blame] | 192 | case SET_FIELD: |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame^] | 193 | OFActionSetField setField = (OFActionSetField) act; |
| 194 | handleSetField(builder, setField.getField()); |
Jonathan Hart | 1f8e0d7 | 2014-11-25 11:13:00 -0800 | [diff] [blame] | 195 | break; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 196 | case SET_TP_DST: |
| 197 | case SET_TP_SRC: |
| 198 | case POP_MPLS: |
| 199 | case POP_PBB: |
| 200 | case POP_VLAN: |
| 201 | case PUSH_MPLS: |
| 202 | case PUSH_PBB: |
| 203 | case PUSH_VLAN: |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 204 | case SET_MPLS_LABEL: |
| 205 | case SET_MPLS_TC: |
| 206 | case SET_MPLS_TTL: |
| 207 | case SET_NW_ECN: |
| 208 | case SET_NW_TOS: |
| 209 | case SET_NW_TTL: |
| 210 | case SET_QUEUE: |
| 211 | case STRIP_VLAN: |
| 212 | case COPY_TTL_IN: |
| 213 | case COPY_TTL_OUT: |
| 214 | case DEC_MPLS_TTL: |
| 215 | case DEC_NW_TTL: |
| 216 | case ENQUEUE: |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 217 | |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 218 | case GROUP: |
| 219 | default: |
| 220 | log.warn("Action type {} not yet implemented.", act.getType()); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | return builder.build(); |
| 225 | } |
| 226 | |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame^] | 227 | private void handleSetField(TrafficTreatment.Builder builder, OFOxm<?> oxm) { |
| 228 | switch (oxm.getMatchField().id) { |
| 229 | case VLAN_PCP: |
| 230 | @SuppressWarnings("unchecked") |
| 231 | OFOxm<VlanPcp> vlanpcp = (OFOxm<VlanPcp>) oxm; |
| 232 | builder.setVlanPcp(vlanpcp.getValue().getValue()); |
| 233 | break; |
| 234 | case VLAN_VID: |
| 235 | @SuppressWarnings("unchecked") |
| 236 | OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm; |
| 237 | builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan())); |
| 238 | break; |
| 239 | case ETH_DST: |
| 240 | @SuppressWarnings("unchecked") |
| 241 | OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethdst = |
| 242 | (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm; |
| 243 | builder.setEthDst(MacAddress.valueOf(ethdst.getValue().getLong())); |
| 244 | break; |
| 245 | case ETH_SRC: |
| 246 | @SuppressWarnings("unchecked") |
| 247 | OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethsrc = |
| 248 | (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm; |
| 249 | builder.setEthSrc(MacAddress.valueOf(ethsrc.getValue().getLong())); |
| 250 | break; |
| 251 | case IPV4_DST: |
| 252 | @SuppressWarnings("unchecked") |
| 253 | OFOxm<IPv4Address> ip4dst = (OFOxm<IPv4Address>) oxm; |
| 254 | builder.setIpDst(Ip4Address.valueOf(ip4dst.getValue().getInt())); |
| 255 | break; |
| 256 | case IPV4_SRC: |
| 257 | @SuppressWarnings("unchecked") |
| 258 | OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm; |
| 259 | builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt())); |
| 260 | break; |
| 261 | case ARP_OP: |
| 262 | case ARP_SHA: |
| 263 | case ARP_SPA: |
| 264 | case ARP_THA: |
| 265 | case ARP_TPA: |
| 266 | case BSN_EGR_PORT_GROUP_ID: |
| 267 | case BSN_GLOBAL_VRF_ALLOWED: |
| 268 | case BSN_IN_PORTS_128: |
| 269 | case BSN_L3_DST_CLASS_ID: |
| 270 | case BSN_L3_INTERFACE_CLASS_ID: |
| 271 | case BSN_L3_SRC_CLASS_ID: |
| 272 | case BSN_LAG_ID: |
| 273 | case BSN_TCP_FLAGS: |
| 274 | case BSN_UDF0: |
| 275 | case BSN_UDF1: |
| 276 | case BSN_UDF2: |
| 277 | case BSN_UDF3: |
| 278 | case BSN_UDF4: |
| 279 | case BSN_UDF5: |
| 280 | case BSN_UDF6: |
| 281 | case BSN_UDF7: |
| 282 | case BSN_VLAN_XLATE_PORT_GROUP_ID: |
| 283 | case BSN_VRF: |
| 284 | case ETH_TYPE: |
| 285 | case ICMPV4_CODE: |
| 286 | case ICMPV4_TYPE: |
| 287 | case ICMPV6_CODE: |
| 288 | case ICMPV6_TYPE: |
| 289 | case IN_PHY_PORT: |
| 290 | case IN_PORT: |
| 291 | case IPV6_DST: |
| 292 | case IPV6_FLABEL: |
| 293 | case IPV6_ND_SLL: |
| 294 | case IPV6_ND_TARGET: |
| 295 | case IPV6_ND_TLL: |
| 296 | case IPV6_SRC: |
| 297 | case IP_DSCP: |
| 298 | case IP_ECN: |
| 299 | case IP_PROTO: |
| 300 | case METADATA: |
| 301 | case MPLS_LABEL: |
| 302 | case MPLS_TC: |
| 303 | case OCH_SIGID: |
| 304 | case OCH_SIGID_BASIC: |
| 305 | case OCH_SIGTYPE: |
| 306 | case OCH_SIGTYPE_BASIC: |
| 307 | case SCTP_DST: |
| 308 | case SCTP_SRC: |
| 309 | case TCP_DST: |
| 310 | case TCP_SRC: |
| 311 | case TUNNEL_ID: |
| 312 | case UDP_DST: |
| 313 | case UDP_SRC: |
| 314 | default: |
| 315 | log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id); |
| 316 | break; |
| 317 | } |
| 318 | } |
| 319 | |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 320 | private TrafficSelector buildSelector() { |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 321 | TrafficSelector.Builder builder = DefaultTrafficSelector.builder(); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 322 | for (MatchField<?> field : match.getMatchFields()) { |
| 323 | switch (field.id) { |
| 324 | case IN_PORT: |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 325 | builder.matchInport(PortNumber |
| 326 | .portNumber(match.get(MatchField.IN_PORT).getPortNumber())); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 327 | break; |
| 328 | case ETH_SRC: |
| 329 | MacAddress sMac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong()); |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 330 | builder.matchEthSrc(sMac); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 331 | break; |
| 332 | case ETH_DST: |
| 333 | MacAddress dMac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong()); |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 334 | builder.matchEthDst(dMac); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 335 | break; |
| 336 | case ETH_TYPE: |
| 337 | int ethType = match.get(MatchField.ETH_TYPE).getValue(); |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 338 | builder.matchEthType((short) ethType); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 339 | break; |
| 340 | case IPV4_DST: |
Pavlin Radoslavov | ff894a2 | 2014-11-05 16:09:35 -0800 | [diff] [blame] | 341 | Ip4Prefix dip; |
Jonathan Hart | 0e12fad | 2014-10-17 14:54:58 -0700 | [diff] [blame] | 342 | if (match.isPartiallyMasked(MatchField.IPV4_DST)) { |
| 343 | Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST); |
| 344 | |
Pavlin Radoslavov | ff894a2 | 2014-11-05 16:09:35 -0800 | [diff] [blame] | 345 | dip = Ip4Prefix.valueOf( |
Jonathan Hart | 0e12fad | 2014-10-17 14:54:58 -0700 | [diff] [blame] | 346 | maskedIp.getValue().getInt(), |
| 347 | maskedIp.getMask().asCidrMaskLength()); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 348 | } else { |
Pavlin Radoslavov | ff894a2 | 2014-11-05 16:09:35 -0800 | [diff] [blame] | 349 | dip = Ip4Prefix.valueOf( |
Jonathan Hart | 0e12fad | 2014-10-17 14:54:58 -0700 | [diff] [blame] | 350 | match.get(MatchField.IPV4_DST).getInt(), |
Pavlin Radoslavov | ff894a2 | 2014-11-05 16:09:35 -0800 | [diff] [blame] | 351 | Ip4Prefix.MAX_MASK_LENGTH); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 352 | } |
Jonathan Hart | 0e12fad | 2014-10-17 14:54:58 -0700 | [diff] [blame] | 353 | |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 354 | builder.matchIPDst(dip); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 355 | break; |
| 356 | case IPV4_SRC: |
Pavlin Radoslavov | ff894a2 | 2014-11-05 16:09:35 -0800 | [diff] [blame] | 357 | Ip4Prefix sip; |
Jonathan Hart | 0e12fad | 2014-10-17 14:54:58 -0700 | [diff] [blame] | 358 | if (match.isPartiallyMasked(MatchField.IPV4_SRC)) { |
| 359 | Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC); |
| 360 | |
Pavlin Radoslavov | ff894a2 | 2014-11-05 16:09:35 -0800 | [diff] [blame] | 361 | sip = Ip4Prefix.valueOf( |
Jonathan Hart | 0e12fad | 2014-10-17 14:54:58 -0700 | [diff] [blame] | 362 | maskedIp.getValue().getInt(), |
| 363 | maskedIp.getMask().asCidrMaskLength()); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 364 | } else { |
Pavlin Radoslavov | ff894a2 | 2014-11-05 16:09:35 -0800 | [diff] [blame] | 365 | sip = Ip4Prefix.valueOf( |
Jonathan Hart | 0e12fad | 2014-10-17 14:54:58 -0700 | [diff] [blame] | 366 | match.get(MatchField.IPV4_SRC).getInt(), |
Pavlin Radoslavov | ff894a2 | 2014-11-05 16:09:35 -0800 | [diff] [blame] | 367 | Ip4Prefix.MAX_MASK_LENGTH); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 368 | } |
Jonathan Hart | 0e12fad | 2014-10-17 14:54:58 -0700 | [diff] [blame] | 369 | |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 370 | builder.matchIPSrc(sip); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 371 | break; |
| 372 | case IP_PROTO: |
| 373 | short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber(); |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 374 | builder.matchIPProtocol((byte) proto); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 375 | break; |
| 376 | case VLAN_PCP: |
| 377 | byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue(); |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 378 | builder.matchVlanPcp(vlanPcp); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 379 | break; |
| 380 | case VLAN_VID: |
| 381 | VlanId vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan()); |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 382 | builder.matchVlanId(vlanId); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 383 | break; |
Jonathan Hart | 34bc614 | 2014-10-17 11:00:43 -0700 | [diff] [blame] | 384 | case TCP_DST: |
| 385 | builder.matchTcpDst((short) match.get(MatchField.TCP_DST).getPort()); |
| 386 | break; |
| 387 | case TCP_SRC: |
| 388 | builder.matchTcpSrc((short) match.get(MatchField.TCP_SRC).getPort()); |
| 389 | break; |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 390 | case MPLS_LABEL: |
| 391 | builder.matchMplsLabel((int) match.get(MatchField.MPLS_LABEL) |
| 392 | .getValue()); |
| 393 | break; |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 394 | case OCH_SIGID: |
| 395 | builder.matchLambda(match.get(MatchField.OCH_SIGID).getChannelNumber()); |
| 396 | break; |
Praseed Balakrishnan | 2dd5abd | 2014-11-03 14:56:28 -0800 | [diff] [blame] | 397 | case OCH_SIGTYPE: |
| 398 | builder.matchOpticalSignalType(match.get(MatchField |
| 399 | .OCH_SIGTYPE).getValue()); |
| 400 | break; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 401 | case ARP_OP: |
| 402 | case ARP_SHA: |
| 403 | case ARP_SPA: |
| 404 | case ARP_THA: |
| 405 | case ARP_TPA: |
| 406 | case ICMPV4_CODE: |
| 407 | case ICMPV4_TYPE: |
| 408 | case ICMPV6_CODE: |
| 409 | case ICMPV6_TYPE: |
| 410 | case IN_PHY_PORT: |
| 411 | case IPV6_DST: |
| 412 | case IPV6_FLABEL: |
| 413 | case IPV6_ND_SLL: |
| 414 | case IPV6_ND_TARGET: |
| 415 | case IPV6_ND_TLL: |
| 416 | case IPV6_SRC: |
| 417 | case IP_DSCP: |
| 418 | case IP_ECN: |
| 419 | case METADATA: |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 420 | case MPLS_TC: |
| 421 | case SCTP_DST: |
| 422 | case SCTP_SRC: |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 423 | case TUNNEL_ID: |
| 424 | case UDP_DST: |
| 425 | case UDP_SRC: |
| 426 | default: |
| 427 | log.warn("Match type {} not yet implemented.", field.id); |
| 428 | |
| 429 | |
| 430 | } |
| 431 | } |
| 432 | return builder.build(); |
| 433 | } |
| 434 | |
| 435 | } |