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