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