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