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