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 | |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 18 | import com.google.common.collect.Lists; |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 19 | import org.onlab.packet.Ip4Address; |
| 20 | import org.onlab.packet.Ip4Prefix; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 21 | import org.onlab.packet.Ip6Address; |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 22 | import org.onlab.packet.Ip6Prefix; |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 23 | import org.onlab.packet.MacAddress; |
| 24 | import org.onlab.packet.VlanId; |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 25 | import org.onosproject.core.DefaultGroupId; |
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; |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame^] | 38 | import org.projectfloodlight.openflow.protocol.OFFlowMod; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 39 | import org.projectfloodlight.openflow.protocol.OFFlowRemoved; |
| 40 | import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry; |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 41 | import org.projectfloodlight.openflow.protocol.OFInstructionType; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 42 | import org.projectfloodlight.openflow.protocol.action.OFAction; |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 43 | import org.projectfloodlight.openflow.protocol.action.OFActionCircuit; |
| 44 | import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter; |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 45 | import org.projectfloodlight.openflow.protocol.action.OFActionGroup; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 46 | import org.projectfloodlight.openflow.protocol.action.OFActionOutput; |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 47 | import org.projectfloodlight.openflow.protocol.action.OFActionPopMpls; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 48 | import org.projectfloodlight.openflow.protocol.action.OFActionSetDlDst; |
| 49 | import org.projectfloodlight.openflow.protocol.action.OFActionSetDlSrc; |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 50 | import org.projectfloodlight.openflow.protocol.action.OFActionSetField; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 51 | import org.projectfloodlight.openflow.protocol.action.OFActionSetNwDst; |
| 52 | import org.projectfloodlight.openflow.protocol.action.OFActionSetNwSrc; |
| 53 | import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanPcp; |
| 54 | import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanVid; |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 55 | import org.projectfloodlight.openflow.protocol.instruction.OFInstruction; |
Jonathan Hart | cf78320 | 2014-11-24 18:55:42 -0800 | [diff] [blame] | 56 | import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 57 | import org.projectfloodlight.openflow.protocol.match.Match; |
| 58 | import org.projectfloodlight.openflow.protocol.match.MatchField; |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 59 | import org.projectfloodlight.openflow.protocol.oxm.OFOxm; |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 60 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigidBasic; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -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; |
Jonathan Hart | 0e12fad | 2014-10-17 14:54:58 -0700 | [diff] [blame] | 63 | import org.projectfloodlight.openflow.types.Masked; |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 64 | import org.projectfloodlight.openflow.types.OFVlanVidMatch; |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 65 | import org.projectfloodlight.openflow.types.U32; |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 66 | import org.projectfloodlight.openflow.types.VlanPcp; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 67 | import org.slf4j.Logger; |
| 68 | |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 69 | import java.util.List; |
| 70 | |
| 71 | import static org.slf4j.LoggerFactory.getLogger; |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 72 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 73 | public class FlowEntryBuilder { |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 74 | private final Logger log = getLogger(getClass()); |
| 75 | |
| 76 | private final OFFlowStatsEntry stat; |
| 77 | private final OFFlowRemoved removed; |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame^] | 78 | private final OFFlowMod flowMod; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 79 | |
| 80 | private final Match match; |
| 81 | private final List<OFAction> actions; |
| 82 | |
| 83 | private final Dpid dpid; |
| 84 | |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame^] | 85 | public enum FlowType { STAT, REMOVED, MOD } |
| 86 | |
| 87 | private final FlowType type; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 88 | |
| 89 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 90 | public FlowEntryBuilder(Dpid dpid, OFFlowStatsEntry entry) { |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 91 | this.stat = entry; |
| 92 | this.match = entry.getMatch(); |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 93 | this.actions = getActions(entry); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 94 | this.dpid = dpid; |
alshabib | 219ebaa | 2014-09-22 15:41:24 -0700 | [diff] [blame] | 95 | this.removed = null; |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame^] | 96 | this.flowMod = null; |
| 97 | this.type = FlowType.STAT; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 98 | } |
| 99 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 100 | public FlowEntryBuilder(Dpid dpid, OFFlowRemoved removed) { |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 101 | this.match = removed.getMatch(); |
| 102 | this.removed = removed; |
| 103 | |
| 104 | this.dpid = dpid; |
| 105 | this.actions = null; |
| 106 | this.stat = null; |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame^] | 107 | this.flowMod = null; |
| 108 | this.type = FlowType.REMOVED; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 109 | |
| 110 | } |
| 111 | |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame^] | 112 | public FlowEntryBuilder(Dpid dpid, OFFlowMod fm) { |
| 113 | this.match = fm.getMatch(); |
| 114 | this.dpid = dpid; |
| 115 | this.actions = fm.getActions(); |
| 116 | this.type = FlowType.MOD; |
| 117 | this.flowMod = fm; |
| 118 | this.stat = null; |
| 119 | this.removed = null; |
| 120 | } |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 121 | |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame^] | 122 | public FlowEntry build(FlowEntryState... state) { |
| 123 | FlowRule rule; |
| 124 | switch (this.type) { |
| 125 | case STAT: |
| 126 | rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)), |
| 127 | buildSelector(), buildTreatment(), stat.getPriority(), |
| 128 | stat.getCookie().getValue(), stat.getIdleTimeout(), false); |
| 129 | return new DefaultFlowEntry(rule, FlowEntryState.ADDED, |
| 130 | stat.getDurationSec(), stat.getPacketCount().getValue(), |
| 131 | stat.getByteCount().getValue()); |
| 132 | case REMOVED: |
| 133 | rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)), |
| 134 | buildSelector(), null, removed.getPriority(), |
| 135 | removed.getCookie().getValue(), removed.getIdleTimeout(), false); |
| 136 | return new DefaultFlowEntry(rule, FlowEntryState.REMOVED, removed.getDurationSec(), |
| 137 | removed.getPacketCount().getValue(), removed.getByteCount().getValue()); |
| 138 | case MOD: |
| 139 | FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED; |
| 140 | rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)), |
| 141 | buildSelector(), buildTreatment(), flowMod.getPriority(), |
| 142 | flowMod.getCookie().getValue(), flowMod.getIdleTimeout(), false); |
| 143 | return new DefaultFlowEntry(rule, flowState, 0, 0, 0); |
| 144 | default: |
| 145 | log.error("Unknown flow type : {}", this.type); |
| 146 | return null; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 147 | } |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame^] | 148 | |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 149 | } |
| 150 | |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 151 | private List<OFAction> getActions(OFFlowStatsEntry entry) { |
| 152 | switch (entry.getVersion()) { |
| 153 | case OF_10: |
| 154 | return entry.getActions(); |
| 155 | case OF_11: |
| 156 | case OF_12: |
| 157 | case OF_13: |
| 158 | List<OFInstruction> ins = entry.getInstructions(); |
| 159 | for (OFInstruction in : ins) { |
Jonathan Hart | cf78320 | 2014-11-24 18:55:42 -0800 | [diff] [blame] | 160 | if (in.getType().equals(OFInstructionType.APPLY_ACTIONS)) { |
| 161 | OFInstructionApplyActions apply = (OFInstructionApplyActions) in; |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 162 | return apply.getActions(); |
| 163 | } |
| 164 | } |
| 165 | return Lists.newLinkedList(); |
| 166 | default: |
| 167 | log.warn("Unknown OF version {}", entry.getVersion()); |
| 168 | } |
| 169 | return Lists.newLinkedList(); |
| 170 | } |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 171 | |
| 172 | private TrafficTreatment buildTreatment() { |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 173 | TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder(); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 174 | // If this is a drop rule |
| 175 | if (actions.size() == 0) { |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 176 | builder.drop(); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 177 | return builder.build(); |
| 178 | } |
| 179 | for (OFAction act : actions) { |
| 180 | switch (act.getType()) { |
| 181 | case OUTPUT: |
| 182 | OFActionOutput out = (OFActionOutput) act; |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 183 | builder.setOutput( |
| 184 | PortNumber.portNumber(out.getPort().getPortNumber())); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 185 | break; |
| 186 | case SET_VLAN_VID: |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 187 | OFActionSetVlanVid vlan = (OFActionSetVlanVid) act; |
| 188 | builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan())); |
| 189 | break; |
| 190 | case SET_VLAN_PCP: |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 191 | OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act; |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 192 | builder.setVlanPcp(pcp.getVlanPcp().getValue()); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 193 | break; |
| 194 | case SET_DL_DST: |
| 195 | OFActionSetDlDst dldst = (OFActionSetDlDst) act; |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 196 | builder.setEthDst( |
| 197 | MacAddress.valueOf(dldst.getDlAddr().getLong())); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 198 | break; |
| 199 | case SET_DL_SRC: |
| 200 | OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act; |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 201 | builder.setEthSrc( |
| 202 | MacAddress.valueOf(dlsrc.getDlAddr().getLong())); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 203 | |
| 204 | break; |
| 205 | case SET_NW_DST: |
| 206 | OFActionSetNwDst nwdst = (OFActionSetNwDst) act; |
| 207 | IPv4Address di = nwdst.getNwAddr(); |
Pavlin Radoslavov | ff894a2 | 2014-11-05 16:09:35 -0800 | [diff] [blame] | 208 | builder.setIpDst(Ip4Address.valueOf(di.getInt())); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 209 | break; |
| 210 | case SET_NW_SRC: |
| 211 | OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act; |
| 212 | IPv4Address si = nwsrc.getNwAddr(); |
Pavlin Radoslavov | ff894a2 | 2014-11-05 16:09:35 -0800 | [diff] [blame] | 213 | builder.setIpSrc(Ip4Address.valueOf(si.getInt())); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 214 | break; |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 215 | case EXPERIMENTER: |
| 216 | OFActionExperimenter exp = (OFActionExperimenter) act; |
Praseed Balakrishnan | db8a9d2 | 2014-12-03 11:47:55 -0800 | [diff] [blame] | 217 | if (exp.getExperimenter() == 0x80005A06 || |
| 218 | exp.getExperimenter() == 0x748771) { |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 219 | OFActionCircuit ct = (OFActionCircuit) exp; |
| 220 | builder.setLambda(((OFOxmOchSigidBasic) ct.getField()).getValue().getChannelNumber()); |
| 221 | } else { |
| 222 | log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter()); |
| 223 | } |
| 224 | break; |
Jonathan Hart | 1f8e0d7 | 2014-11-25 11:13:00 -0800 | [diff] [blame] | 225 | case SET_FIELD: |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 226 | OFActionSetField setField = (OFActionSetField) act; |
| 227 | handleSetField(builder, setField.getField()); |
Jonathan Hart | 1f8e0d7 | 2014-11-25 11:13:00 -0800 | [diff] [blame] | 228 | break; |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 229 | case POP_MPLS: |
| 230 | OFActionPopMpls popMpls = (OFActionPopMpls) act; |
| 231 | builder.popMpls((short) popMpls.getEthertype().getValue()); |
| 232 | break; |
| 233 | case PUSH_MPLS: |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 234 | builder.pushMpls(); |
| 235 | break; |
| 236 | case COPY_TTL_IN: |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 237 | builder.copyTtlIn(); |
| 238 | break; |
| 239 | case COPY_TTL_OUT: |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 240 | builder.copyTtlOut(); |
| 241 | break; |
| 242 | case DEC_MPLS_TTL: |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 243 | builder.decMplsTtl(); |
| 244 | break; |
| 245 | case DEC_NW_TTL: |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 246 | builder.decNwTtl(); |
| 247 | break; |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 248 | case GROUP: |
| 249 | OFActionGroup group = (OFActionGroup) act; |
| 250 | builder.group(new DefaultGroupId(group.getGroup().getGroupNumber())); |
| 251 | break; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 252 | case SET_TP_DST: |
| 253 | case SET_TP_SRC: |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 254 | case POP_PBB: |
| 255 | case POP_VLAN: |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 256 | case PUSH_PBB: |
| 257 | case PUSH_VLAN: |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 258 | case SET_MPLS_LABEL: |
| 259 | case SET_MPLS_TC: |
| 260 | case SET_MPLS_TTL: |
| 261 | case SET_NW_ECN: |
| 262 | case SET_NW_TOS: |
| 263 | case SET_NW_TTL: |
| 264 | case SET_QUEUE: |
| 265 | case STRIP_VLAN: |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 266 | case ENQUEUE: |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 267 | default: |
| 268 | log.warn("Action type {} not yet implemented.", act.getType()); |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | return builder.build(); |
| 273 | } |
| 274 | |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 275 | private void handleSetField(TrafficTreatment.Builder builder, OFOxm<?> oxm) { |
| 276 | switch (oxm.getMatchField().id) { |
| 277 | case VLAN_PCP: |
| 278 | @SuppressWarnings("unchecked") |
| 279 | OFOxm<VlanPcp> vlanpcp = (OFOxm<VlanPcp>) oxm; |
| 280 | builder.setVlanPcp(vlanpcp.getValue().getValue()); |
| 281 | break; |
| 282 | case VLAN_VID: |
| 283 | @SuppressWarnings("unchecked") |
| 284 | OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm; |
| 285 | builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan())); |
| 286 | break; |
| 287 | case ETH_DST: |
| 288 | @SuppressWarnings("unchecked") |
| 289 | OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethdst = |
| 290 | (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm; |
| 291 | builder.setEthDst(MacAddress.valueOf(ethdst.getValue().getLong())); |
| 292 | break; |
| 293 | case ETH_SRC: |
| 294 | @SuppressWarnings("unchecked") |
| 295 | OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethsrc = |
| 296 | (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm; |
| 297 | builder.setEthSrc(MacAddress.valueOf(ethsrc.getValue().getLong())); |
| 298 | break; |
| 299 | case IPV4_DST: |
| 300 | @SuppressWarnings("unchecked") |
| 301 | OFOxm<IPv4Address> ip4dst = (OFOxm<IPv4Address>) oxm; |
| 302 | builder.setIpDst(Ip4Address.valueOf(ip4dst.getValue().getInt())); |
| 303 | break; |
| 304 | case IPV4_SRC: |
| 305 | @SuppressWarnings("unchecked") |
| 306 | OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm; |
| 307 | builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt())); |
| 308 | break; |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 309 | case MPLS_LABEL: |
| 310 | @SuppressWarnings("unchecked") |
| 311 | OFOxm<U32> labelId = (OFOxm<U32>) oxm; |
| 312 | builder.setMpls((int) labelId.getValue().getValue()); |
| 313 | break; |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 314 | case ARP_OP: |
| 315 | case ARP_SHA: |
| 316 | case ARP_SPA: |
| 317 | case ARP_THA: |
| 318 | case ARP_TPA: |
| 319 | case BSN_EGR_PORT_GROUP_ID: |
| 320 | case BSN_GLOBAL_VRF_ALLOWED: |
| 321 | case BSN_IN_PORTS_128: |
| 322 | case BSN_L3_DST_CLASS_ID: |
| 323 | case BSN_L3_INTERFACE_CLASS_ID: |
| 324 | case BSN_L3_SRC_CLASS_ID: |
| 325 | case BSN_LAG_ID: |
| 326 | case BSN_TCP_FLAGS: |
| 327 | case BSN_UDF0: |
| 328 | case BSN_UDF1: |
| 329 | case BSN_UDF2: |
| 330 | case BSN_UDF3: |
| 331 | case BSN_UDF4: |
| 332 | case BSN_UDF5: |
| 333 | case BSN_UDF6: |
| 334 | case BSN_UDF7: |
| 335 | case BSN_VLAN_XLATE_PORT_GROUP_ID: |
| 336 | case BSN_VRF: |
| 337 | case ETH_TYPE: |
| 338 | case ICMPV4_CODE: |
| 339 | case ICMPV4_TYPE: |
| 340 | case ICMPV6_CODE: |
| 341 | case ICMPV6_TYPE: |
| 342 | case IN_PHY_PORT: |
| 343 | case IN_PORT: |
| 344 | case IPV6_DST: |
| 345 | case IPV6_FLABEL: |
| 346 | case IPV6_ND_SLL: |
| 347 | case IPV6_ND_TARGET: |
| 348 | case IPV6_ND_TLL: |
| 349 | case IPV6_SRC: |
| 350 | case IP_DSCP: |
| 351 | case IP_ECN: |
| 352 | case IP_PROTO: |
| 353 | case METADATA: |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 354 | case MPLS_TC: |
| 355 | case OCH_SIGID: |
| 356 | case OCH_SIGID_BASIC: |
| 357 | case OCH_SIGTYPE: |
| 358 | case OCH_SIGTYPE_BASIC: |
| 359 | case SCTP_DST: |
| 360 | case SCTP_SRC: |
| 361 | case TCP_DST: |
| 362 | case TCP_SRC: |
| 363 | case TUNNEL_ID: |
| 364 | case UDP_DST: |
| 365 | case UDP_SRC: |
| 366 | default: |
| 367 | log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id); |
| 368 | break; |
| 369 | } |
| 370 | } |
| 371 | |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 372 | private TrafficSelector buildSelector() { |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 373 | MacAddress mac; |
| 374 | Ip4Prefix ip4Prefix; |
| 375 | Ip6Address ip6Address; |
| 376 | Ip6Prefix ip6Prefix; |
| 377 | |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 378 | TrafficSelector.Builder builder = DefaultTrafficSelector.builder(); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 379 | for (MatchField<?> field : match.getMatchFields()) { |
| 380 | switch (field.id) { |
| 381 | case IN_PORT: |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 382 | builder.matchInPort(PortNumber |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 383 | .portNumber(match.get(MatchField.IN_PORT).getPortNumber())); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 384 | break; |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 385 | case IN_PHY_PORT: |
| 386 | builder.matchInPhyPort(PortNumber |
| 387 | .portNumber(match.get(MatchField.IN_PHY_PORT).getPortNumber())); |
| 388 | break; |
| 389 | case METADATA: |
| 390 | long metadata = |
| 391 | match.get(MatchField.METADATA).getValue().getValue(); |
| 392 | builder.matchMetadata(metadata); |
| 393 | break; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 394 | case ETH_DST: |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 395 | mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong()); |
| 396 | builder.matchEthDst(mac); |
| 397 | break; |
| 398 | case ETH_SRC: |
| 399 | mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong()); |
| 400 | builder.matchEthSrc(mac); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 401 | break; |
| 402 | case ETH_TYPE: |
| 403 | int ethType = match.get(MatchField.ETH_TYPE).getValue(); |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 404 | builder.matchEthType((short) ethType); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 405 | break; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 406 | case VLAN_VID: |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 407 | VlanId vlanId = null; |
| 408 | if (match.isPartiallyMasked(MatchField.VLAN_VID)) { |
| 409 | Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID); |
| 410 | if (masked.getValue().equals(OFVlanVidMatch.PRESENT) |
| 411 | && masked.getMask().equals(OFVlanVidMatch.PRESENT)) { |
| 412 | vlanId = VlanId.ANY; |
| 413 | } |
| 414 | } else { |
| 415 | vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan()); |
| 416 | } |
| 417 | if (vlanId != null) { |
| 418 | builder.matchVlanId(vlanId); |
| 419 | } |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 420 | break; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 421 | case VLAN_PCP: |
| 422 | byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue(); |
| 423 | builder.matchVlanPcp(vlanPcp); |
| 424 | break; |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 425 | case IP_DSCP: |
| 426 | byte ipDscp = match.get(MatchField.IP_DSCP).getDscpValue(); |
| 427 | builder.matchIPDscp(ipDscp); |
| 428 | break; |
| 429 | case IP_ECN: |
| 430 | byte ipEcn = match.get(MatchField.IP_ECN).getEcnValue(); |
| 431 | builder.matchIPEcn(ipEcn); |
| 432 | break; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 433 | case IP_PROTO: |
| 434 | short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber(); |
| 435 | builder.matchIPProtocol((byte) proto); |
| 436 | break; |
| 437 | case IPV4_SRC: |
| 438 | if (match.isPartiallyMasked(MatchField.IPV4_SRC)) { |
| 439 | Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 440 | ip4Prefix = Ip4Prefix.valueOf( |
| 441 | maskedIp.getValue().getInt(), |
| 442 | maskedIp.getMask().asCidrMaskLength()); |
| 443 | } else { |
| 444 | ip4Prefix = Ip4Prefix.valueOf( |
| 445 | match.get(MatchField.IPV4_SRC).getInt(), |
| 446 | Ip4Prefix.MAX_MASK_LENGTH); |
| 447 | } |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 448 | builder.matchIPSrc(ip4Prefix); |
| 449 | break; |
| 450 | case IPV4_DST: |
| 451 | if (match.isPartiallyMasked(MatchField.IPV4_DST)) { |
| 452 | Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 453 | ip4Prefix = Ip4Prefix.valueOf( |
| 454 | maskedIp.getValue().getInt(), |
| 455 | maskedIp.getMask().asCidrMaskLength()); |
| 456 | } else { |
| 457 | ip4Prefix = Ip4Prefix.valueOf( |
| 458 | match.get(MatchField.IPV4_DST).getInt(), |
| 459 | Ip4Prefix.MAX_MASK_LENGTH); |
| 460 | } |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 461 | builder.matchIPDst(ip4Prefix); |
Jonathan Hart | 34bc614 | 2014-10-17 11:00:43 -0700 | [diff] [blame] | 462 | break; |
| 463 | case TCP_SRC: |
| 464 | builder.matchTcpSrc((short) match.get(MatchField.TCP_SRC).getPort()); |
| 465 | break; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 466 | case TCP_DST: |
| 467 | builder.matchTcpDst((short) match.get(MatchField.TCP_DST).getPort()); |
| 468 | break; |
| 469 | case UDP_SRC: |
| 470 | builder.matchUdpSrc((short) match.get(MatchField.UDP_SRC).getPort()); |
| 471 | break; |
| 472 | case UDP_DST: |
| 473 | builder.matchUdpDst((short) match.get(MatchField.UDP_DST).getPort()); |
| 474 | break; |
| 475 | case SCTP_SRC: |
| 476 | builder.matchSctpSrc((short) match.get(MatchField.SCTP_SRC).getPort()); |
| 477 | break; |
| 478 | case SCTP_DST: |
| 479 | builder.matchSctpDst((short) match.get(MatchField.SCTP_DST).getPort()); |
| 480 | break; |
| 481 | case ICMPV4_TYPE: |
| 482 | byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType(); |
| 483 | builder.matchIcmpType(icmpType); |
| 484 | break; |
| 485 | case ICMPV4_CODE: |
| 486 | byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode(); |
| 487 | builder.matchIcmpCode(icmpCode); |
| 488 | break; |
| 489 | case IPV6_SRC: |
| 490 | if (match.isPartiallyMasked(MatchField.IPV6_SRC)) { |
| 491 | Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC); |
| 492 | ip6Prefix = Ip6Prefix.valueOf( |
| 493 | maskedIp.getValue().getBytes(), |
| 494 | maskedIp.getMask().asCidrMaskLength()); |
| 495 | } else { |
| 496 | ip6Prefix = Ip6Prefix.valueOf( |
| 497 | match.get(MatchField.IPV6_SRC).getBytes(), |
| 498 | Ip6Prefix.MAX_MASK_LENGTH); |
| 499 | } |
| 500 | builder.matchIPv6Src(ip6Prefix); |
| 501 | break; |
| 502 | case IPV6_DST: |
| 503 | if (match.isPartiallyMasked(MatchField.IPV6_DST)) { |
| 504 | Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST); |
| 505 | ip6Prefix = Ip6Prefix.valueOf( |
| 506 | maskedIp.getValue().getBytes(), |
| 507 | maskedIp.getMask().asCidrMaskLength()); |
| 508 | } else { |
| 509 | ip6Prefix = Ip6Prefix.valueOf( |
| 510 | match.get(MatchField.IPV6_DST).getBytes(), |
| 511 | Ip6Prefix.MAX_MASK_LENGTH); |
| 512 | } |
| 513 | builder.matchIPv6Dst(ip6Prefix); |
| 514 | break; |
| 515 | case IPV6_FLABEL: |
| 516 | int flowLabel = |
| 517 | match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue(); |
| 518 | builder.matchIPv6FlowLabel(flowLabel); |
| 519 | break; |
| 520 | case ICMPV6_TYPE: |
| 521 | byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue(); |
| 522 | builder.matchIcmpv6Type(icmpv6type); |
| 523 | break; |
| 524 | case ICMPV6_CODE: |
| 525 | byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue(); |
| 526 | builder.matchIcmpv6Code(icmpv6code); |
| 527 | break; |
| 528 | case IPV6_ND_TARGET: |
| 529 | ip6Address = |
| 530 | Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes()); |
| 531 | builder.matchIPv6NDTargetAddress(ip6Address); |
| 532 | break; |
| 533 | case IPV6_ND_SLL: |
| 534 | mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong()); |
| 535 | builder.matchIPv6NDSourceLinkLayerAddress(mac); |
| 536 | break; |
| 537 | case IPV6_ND_TLL: |
| 538 | mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong()); |
| 539 | builder.matchIPv6NDTargetLinkLayerAddress(mac); |
| 540 | break; |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 541 | case MPLS_LABEL: |
| 542 | builder.matchMplsLabel((int) match.get(MatchField.MPLS_LABEL) |
| 543 | .getValue()); |
| 544 | break; |
Pavlin Radoslavov | 5e4f754 | 2015-02-06 18:18:21 -0800 | [diff] [blame] | 545 | case IPV6_EXTHDR: |
| 546 | builder.matchIPv6ExthdrFlags((int) match.get(MatchField.IPV6_EXTHDR) |
| 547 | .getValue()); |
| 548 | break; |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 549 | case OCH_SIGID: |
| 550 | builder.matchLambda(match.get(MatchField.OCH_SIGID).getChannelNumber()); |
| 551 | break; |
Praseed Balakrishnan | 2dd5abd | 2014-11-03 14:56:28 -0800 | [diff] [blame] | 552 | case OCH_SIGTYPE: |
| 553 | builder.matchOpticalSignalType(match.get(MatchField |
| 554 | .OCH_SIGTYPE).getValue()); |
| 555 | break; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 556 | case ARP_OP: |
| 557 | case ARP_SHA: |
| 558 | case ARP_SPA: |
| 559 | case ARP_THA: |
| 560 | case ARP_TPA: |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 561 | case MPLS_TC: |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 562 | case TUNNEL_ID: |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 563 | default: |
| 564 | log.warn("Match type {} not yet implemented.", field.id); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 565 | } |
| 566 | } |
| 567 | return builder.build(); |
| 568 | } |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 569 | } |