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