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 | */ |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 16 | package org.onlab.onos.provider.of.flow.impl; |
| 17 | |
| 18 | import static org.slf4j.LoggerFactory.getLogger; |
| 19 | |
| 20 | import java.util.List; |
| 21 | |
| 22 | import org.onlab.onos.net.DeviceId; |
| 23 | import org.onlab.onos.net.PortNumber; |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 24 | import org.onlab.onos.net.flow.DefaultFlowEntry; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 25 | import org.onlab.onos.net.flow.DefaultFlowRule; |
| 26 | import org.onlab.onos.net.flow.DefaultTrafficSelector; |
| 27 | import org.onlab.onos.net.flow.DefaultTrafficTreatment; |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 28 | import org.onlab.onos.net.flow.FlowEntry; |
| 29 | import org.onlab.onos.net.flow.FlowEntry.FlowEntryState; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 30 | import org.onlab.onos.net.flow.FlowRule; |
| 31 | import org.onlab.onos.net.flow.TrafficSelector; |
| 32 | import org.onlab.onos.net.flow.TrafficTreatment; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 33 | import org.onlab.onos.openflow.controller.Dpid; |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 34 | import org.onlab.packet.IpPrefix; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 35 | import org.onlab.packet.MacAddress; |
| 36 | import org.onlab.packet.VlanId; |
| 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; |
| 42 | import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 43 | import org.projectfloodlight.openflow.protocol.action.OFActionOutput; |
| 44 | import org.projectfloodlight.openflow.protocol.action.OFActionSetDlDst; |
| 45 | import org.projectfloodlight.openflow.protocol.action.OFActionSetDlSrc; |
| 46 | import org.projectfloodlight.openflow.protocol.action.OFActionSetNwDst; |
| 47 | import org.projectfloodlight.openflow.protocol.action.OFActionSetNwSrc; |
| 48 | import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanPcp; |
| 49 | import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanVid; |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 50 | import org.projectfloodlight.openflow.protocol.instruction.OFInstruction; |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 51 | import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteActions; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 52 | import org.projectfloodlight.openflow.protocol.match.Match; |
| 53 | import org.projectfloodlight.openflow.protocol.match.MatchField; |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 54 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigidBasic; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 55 | import org.projectfloodlight.openflow.types.IPv4Address; |
Jonathan Hart | 0e12fad | 2014-10-17 14:54:58 -0700 | [diff] [blame] | 56 | import org.projectfloodlight.openflow.types.Masked; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 57 | import org.slf4j.Logger; |
| 58 | |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 59 | import com.google.common.collect.Lists; |
| 60 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 61 | public class FlowEntryBuilder { |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 62 | private final Logger log = getLogger(getClass()); |
| 63 | |
| 64 | private final OFFlowStatsEntry stat; |
| 65 | private final OFFlowRemoved removed; |
| 66 | |
| 67 | private final Match match; |
| 68 | private final List<OFAction> actions; |
| 69 | |
| 70 | private final Dpid dpid; |
| 71 | |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 72 | private final boolean addedRule; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 73 | |
| 74 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 75 | public FlowEntryBuilder(Dpid dpid, OFFlowStatsEntry entry) { |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 76 | this.stat = entry; |
| 77 | this.match = entry.getMatch(); |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 78 | this.actions = getActions(entry); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 79 | this.dpid = dpid; |
alshabib | 219ebaa | 2014-09-22 15:41:24 -0700 | [diff] [blame] | 80 | this.removed = null; |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 81 | this.addedRule = true; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 82 | } |
| 83 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 84 | public FlowEntryBuilder(Dpid dpid, OFFlowRemoved removed) { |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 85 | this.match = removed.getMatch(); |
| 86 | this.removed = removed; |
| 87 | |
| 88 | this.dpid = dpid; |
| 89 | this.actions = null; |
| 90 | this.stat = null; |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 91 | this.addedRule = false; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 92 | |
| 93 | } |
| 94 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 95 | public FlowEntry build() { |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 96 | if (addedRule) { |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 97 | FlowRule rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)), |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 98 | buildSelector(), buildTreatment(), stat.getPriority(), |
Jonathan Hart | bc4a793 | 2014-10-21 11:46:00 -0700 | [diff] [blame] | 99 | stat.getCookie().getValue(), stat.getIdleTimeout(), false); |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 100 | return new DefaultFlowEntry(rule, FlowEntryState.ADDED, |
| 101 | stat.getDurationSec(), stat.getPacketCount().getValue(), |
| 102 | stat.getByteCount().getValue()); |
| 103 | |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 104 | } else { |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 105 | FlowRule rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)), |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 106 | buildSelector(), null, removed.getPriority(), |
Jonathan Hart | bc4a793 | 2014-10-21 11:46:00 -0700 | [diff] [blame] | 107 | removed.getCookie().getValue(), removed.getIdleTimeout(), false); |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 108 | return new DefaultFlowEntry(rule, FlowEntryState.REMOVED, removed.getDurationSec(), |
| 109 | removed.getPacketCount().getValue(), removed.getByteCount().getValue()); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 110 | } |
| 111 | } |
| 112 | |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 113 | private List<OFAction> getActions(OFFlowStatsEntry entry) { |
| 114 | switch (entry.getVersion()) { |
| 115 | case OF_10: |
| 116 | return entry.getActions(); |
| 117 | case OF_11: |
| 118 | case OF_12: |
| 119 | case OF_13: |
| 120 | List<OFInstruction> ins = entry.getInstructions(); |
| 121 | for (OFInstruction in : ins) { |
Jonathan Hart | 86e5935 | 2014-10-22 10:42:16 -0700 | [diff] [blame] | 122 | if (in.getType().equals(OFInstructionType.WRITE_ACTIONS)) { |
| 123 | OFInstructionWriteActions apply = (OFInstructionWriteActions) in; |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 124 | return apply.getActions(); |
| 125 | } |
| 126 | } |
| 127 | return Lists.newLinkedList(); |
| 128 | default: |
| 129 | log.warn("Unknown OF version {}", entry.getVersion()); |
| 130 | } |
| 131 | return Lists.newLinkedList(); |
| 132 | } |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 133 | |
| 134 | private TrafficTreatment buildTreatment() { |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 135 | TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder(); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 136 | // If this is a drop rule |
| 137 | if (actions.size() == 0) { |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 138 | builder.drop(); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 139 | return builder.build(); |
| 140 | } |
| 141 | for (OFAction act : actions) { |
| 142 | switch (act.getType()) { |
| 143 | case OUTPUT: |
| 144 | OFActionOutput out = (OFActionOutput) act; |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 145 | builder.setOutput( |
| 146 | PortNumber.portNumber(out.getPort().getPortNumber())); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 147 | break; |
| 148 | case SET_VLAN_VID: |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 149 | OFActionSetVlanVid vlan = (OFActionSetVlanVid) act; |
| 150 | builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan())); |
| 151 | break; |
| 152 | case SET_VLAN_PCP: |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 153 | OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act; |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 154 | builder.setVlanId(VlanId.vlanId(pcp.getVlanPcp().getValue())); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 155 | break; |
| 156 | case SET_DL_DST: |
| 157 | OFActionSetDlDst dldst = (OFActionSetDlDst) act; |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 158 | builder.setEthDst( |
| 159 | MacAddress.valueOf(dldst.getDlAddr().getLong())); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 160 | break; |
| 161 | case SET_DL_SRC: |
| 162 | OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act; |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 163 | builder.setEthSrc( |
| 164 | MacAddress.valueOf(dlsrc.getDlAddr().getLong())); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 165 | |
| 166 | break; |
| 167 | case SET_NW_DST: |
| 168 | OFActionSetNwDst nwdst = (OFActionSetNwDst) act; |
| 169 | IPv4Address di = nwdst.getNwAddr(); |
| 170 | if (di.isCidrMask()) { |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 171 | builder.setIpDst(IpPrefix.valueOf(di.getInt(), |
| 172 | di.asCidrMaskLength())); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 173 | } else { |
Pavlin Radoslavov | 52307e6 | 2014-10-29 15:07:37 -0700 | [diff] [blame] | 174 | builder.setIpDst(IpPrefix.valueOf(di.getInt(), |
| 175 | IpPrefix.MAX_INET_MASK_LENGTH)); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 176 | } |
| 177 | break; |
| 178 | case SET_NW_SRC: |
| 179 | OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act; |
| 180 | IPv4Address si = nwsrc.getNwAddr(); |
| 181 | if (si.isCidrMask()) { |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 182 | builder.setIpSrc(IpPrefix.valueOf(si.getInt(), |
| 183 | si.asCidrMaskLength())); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 184 | } else { |
Pavlin Radoslavov | 52307e6 | 2014-10-29 15:07:37 -0700 | [diff] [blame] | 185 | builder.setIpSrc(IpPrefix.valueOf(si.getInt(), |
| 186 | IpPrefix.MAX_INET_MASK_LENGTH)); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 187 | } |
| 188 | break; |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 189 | case EXPERIMENTER: |
| 190 | OFActionExperimenter exp = (OFActionExperimenter) act; |
| 191 | if (exp.getExperimenter() == 0x80005A06) { |
| 192 | OFActionCircuit ct = (OFActionCircuit) exp; |
| 193 | builder.setLambda(((OFOxmOchSigidBasic) ct.getField()).getValue().getChannelNumber()); |
| 194 | } else { |
| 195 | log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter()); |
| 196 | } |
| 197 | break; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 198 | case SET_TP_DST: |
| 199 | case SET_TP_SRC: |
| 200 | case POP_MPLS: |
| 201 | case POP_PBB: |
| 202 | case POP_VLAN: |
| 203 | case PUSH_MPLS: |
| 204 | case PUSH_PBB: |
| 205 | case PUSH_VLAN: |
| 206 | case SET_FIELD: |
| 207 | case SET_MPLS_LABEL: |
| 208 | case SET_MPLS_TC: |
| 209 | case SET_MPLS_TTL: |
| 210 | case SET_NW_ECN: |
| 211 | case SET_NW_TOS: |
| 212 | case SET_NW_TTL: |
| 213 | case SET_QUEUE: |
| 214 | case STRIP_VLAN: |
| 215 | case COPY_TTL_IN: |
| 216 | case COPY_TTL_OUT: |
| 217 | case DEC_MPLS_TTL: |
| 218 | case DEC_NW_TTL: |
| 219 | case ENQUEUE: |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 220 | |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 221 | case GROUP: |
| 222 | default: |
| 223 | log.warn("Action type {} not yet implemented.", act.getType()); |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | return builder.build(); |
| 228 | } |
| 229 | |
| 230 | private TrafficSelector buildSelector() { |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 231 | TrafficSelector.Builder builder = DefaultTrafficSelector.builder(); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 232 | for (MatchField<?> field : match.getMatchFields()) { |
| 233 | switch (field.id) { |
| 234 | case IN_PORT: |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 235 | builder.matchInport(PortNumber |
| 236 | .portNumber(match.get(MatchField.IN_PORT).getPortNumber())); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 237 | break; |
| 238 | case ETH_SRC: |
| 239 | MacAddress sMac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong()); |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 240 | builder.matchEthSrc(sMac); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 241 | break; |
| 242 | case ETH_DST: |
| 243 | MacAddress dMac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong()); |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 244 | builder.matchEthDst(dMac); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 245 | break; |
| 246 | case ETH_TYPE: |
| 247 | int ethType = match.get(MatchField.ETH_TYPE).getValue(); |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 248 | builder.matchEthType((short) ethType); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 249 | break; |
| 250 | case IPV4_DST: |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 251 | IpPrefix dip; |
Jonathan Hart | 0e12fad | 2014-10-17 14:54:58 -0700 | [diff] [blame] | 252 | if (match.isPartiallyMasked(MatchField.IPV4_DST)) { |
| 253 | Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST); |
| 254 | |
| 255 | dip = IpPrefix.valueOf( |
| 256 | maskedIp.getValue().getInt(), |
| 257 | maskedIp.getMask().asCidrMaskLength()); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 258 | } else { |
Jonathan Hart | 0e12fad | 2014-10-17 14:54:58 -0700 | [diff] [blame] | 259 | dip = IpPrefix.valueOf( |
| 260 | match.get(MatchField.IPV4_DST).getInt(), |
Pavlin Radoslavov | 52307e6 | 2014-10-29 15:07:37 -0700 | [diff] [blame] | 261 | IpPrefix.MAX_INET_MASK_LENGTH); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 262 | } |
Jonathan Hart | 0e12fad | 2014-10-17 14:54:58 -0700 | [diff] [blame] | 263 | |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 264 | builder.matchIPDst(dip); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 265 | break; |
| 266 | case IPV4_SRC: |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 267 | IpPrefix sip; |
Jonathan Hart | 0e12fad | 2014-10-17 14:54:58 -0700 | [diff] [blame] | 268 | if (match.isPartiallyMasked(MatchField.IPV4_SRC)) { |
| 269 | Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC); |
| 270 | |
| 271 | sip = IpPrefix.valueOf( |
| 272 | maskedIp.getValue().getInt(), |
| 273 | maskedIp.getMask().asCidrMaskLength()); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 274 | } else { |
Jonathan Hart | 0e12fad | 2014-10-17 14:54:58 -0700 | [diff] [blame] | 275 | sip = IpPrefix.valueOf( |
| 276 | match.get(MatchField.IPV4_SRC).getInt(), |
Pavlin Radoslavov | 52307e6 | 2014-10-29 15:07:37 -0700 | [diff] [blame] | 277 | IpPrefix.MAX_INET_MASK_LENGTH); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 278 | } |
Jonathan Hart | 0e12fad | 2014-10-17 14:54:58 -0700 | [diff] [blame] | 279 | |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 280 | builder.matchIPSrc(sip); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 281 | break; |
| 282 | case IP_PROTO: |
| 283 | short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber(); |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 284 | builder.matchIPProtocol((byte) proto); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 285 | break; |
| 286 | case VLAN_PCP: |
| 287 | byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue(); |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 288 | builder.matchVlanPcp(vlanPcp); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 289 | break; |
| 290 | case VLAN_VID: |
| 291 | VlanId vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan()); |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 292 | builder.matchVlanId(vlanId); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 293 | break; |
Jonathan Hart | 34bc614 | 2014-10-17 11:00:43 -0700 | [diff] [blame] | 294 | case TCP_DST: |
| 295 | builder.matchTcpDst((short) match.get(MatchField.TCP_DST).getPort()); |
| 296 | break; |
| 297 | case TCP_SRC: |
| 298 | builder.matchTcpSrc((short) match.get(MatchField.TCP_SRC).getPort()); |
| 299 | break; |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 300 | case OCH_SIGID: |
| 301 | builder.matchLambda(match.get(MatchField.OCH_SIGID).getChannelNumber()); |
| 302 | break; |
| 303 | case OCH_SIGTYPE_BASIC: |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 304 | case ARP_OP: |
| 305 | case ARP_SHA: |
| 306 | case ARP_SPA: |
| 307 | case ARP_THA: |
| 308 | case ARP_TPA: |
| 309 | case ICMPV4_CODE: |
| 310 | case ICMPV4_TYPE: |
| 311 | case ICMPV6_CODE: |
| 312 | case ICMPV6_TYPE: |
| 313 | case IN_PHY_PORT: |
| 314 | case IPV6_DST: |
| 315 | case IPV6_FLABEL: |
| 316 | case IPV6_ND_SLL: |
| 317 | case IPV6_ND_TARGET: |
| 318 | case IPV6_ND_TLL: |
| 319 | case IPV6_SRC: |
| 320 | case IP_DSCP: |
| 321 | case IP_ECN: |
| 322 | case METADATA: |
| 323 | case MPLS_LABEL: |
| 324 | case MPLS_TC: |
| 325 | case SCTP_DST: |
| 326 | case SCTP_SRC: |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 327 | case TUNNEL_ID: |
| 328 | case UDP_DST: |
| 329 | case UDP_SRC: |
| 330 | default: |
| 331 | log.warn("Match type {} not yet implemented.", field.id); |
| 332 | |
| 333 | |
| 334 | } |
| 335 | } |
| 336 | return builder.build(); |
| 337 | } |
| 338 | |
| 339 | } |