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