Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 95caba3 | 2016-04-04 10:42:05 -0700 | [diff] [blame] | 2 | * Copyright 2016 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 | */ |
Thomas Vachuska | 95caba3 | 2016-04-04 10:42:05 -0700 | [diff] [blame] | 16 | package org.onosproject.provider.of.flow.util; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 17 | |
Jonathan Hart | 8cf212a | 2015-10-29 17:42:03 -0700 | [diff] [blame] | 18 | import com.google.common.collect.Lists; |
Ray Milkey | 84d5a29 | 2016-02-22 14:04:01 -0800 | [diff] [blame] | 19 | import org.onlab.packet.EthType; |
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; |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 26 | import org.onlab.packet.TpPort; |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 27 | import org.onlab.packet.VlanId; |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 28 | import org.onosproject.core.DefaultGroupId; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 29 | import org.onosproject.net.DeviceId; |
Sho SHIMIZU | 4f828ee | 2015-05-28 09:38:21 -0700 | [diff] [blame] | 30 | import org.onosproject.net.Lambda; |
Yafit Hadar | 7351461 | 2015-11-04 10:14:21 +0200 | [diff] [blame] | 31 | import org.onosproject.net.OduSignalId; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 32 | import org.onosproject.net.PortNumber; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 33 | import org.onosproject.net.driver.DefaultDriverData; |
| 34 | import org.onosproject.net.driver.DefaultDriverHandler; |
| 35 | import org.onosproject.net.driver.Driver; |
| 36 | import org.onosproject.net.driver.DriverHandler; |
| 37 | import org.onosproject.net.driver.DriverService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 38 | import org.onosproject.net.flow.DefaultFlowEntry; |
| 39 | import org.onosproject.net.flow.DefaultFlowRule; |
| 40 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 41 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 42 | import org.onosproject.net.flow.FlowEntry; |
| 43 | import org.onosproject.net.flow.FlowEntry.FlowEntryState; |
| 44 | import org.onosproject.net.flow.FlowRule; |
| 45 | import org.onosproject.net.flow.TrafficSelector; |
| 46 | import org.onosproject.net.flow.TrafficTreatment; |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 47 | import org.onosproject.net.flow.criteria.ExtensionSelectorType.ExtensionSelectorTypes; |
| 48 | import org.onosproject.net.flow.instructions.ExtensionTreatmentType.ExtensionTreatmentTypes; |
Sho SHIMIZU | 9553bb8 | 2015-06-30 16:02:45 -0700 | [diff] [blame] | 49 | import org.onosproject.net.flow.instructions.Instructions; |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 50 | import org.onosproject.openflow.controller.ExtensionSelectorInterpreter; |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 51 | import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter; |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 52 | import org.projectfloodlight.openflow.protocol.OFFlowMod; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 53 | import org.projectfloodlight.openflow.protocol.OFFlowRemoved; |
| 54 | import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry; |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 55 | import org.projectfloodlight.openflow.protocol.OFMatchV3; |
Brian O'Connor | 2156461 | 2015-12-05 19:24:59 -0800 | [diff] [blame] | 56 | import org.projectfloodlight.openflow.protocol.OFVersion; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 57 | import org.projectfloodlight.openflow.protocol.action.OFAction; |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 58 | import org.projectfloodlight.openflow.protocol.action.OFActionCircuit; |
Steffen Gebert | ba2d3b7 | 2015-10-22 11:14:31 +0200 | [diff] [blame] | 59 | import org.projectfloodlight.openflow.protocol.action.OFActionEnqueue; |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 60 | import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter; |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 61 | import org.projectfloodlight.openflow.protocol.action.OFActionGroup; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 62 | import org.projectfloodlight.openflow.protocol.action.OFActionOutput; |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 63 | import org.projectfloodlight.openflow.protocol.action.OFActionPopMpls; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 64 | import org.projectfloodlight.openflow.protocol.action.OFActionSetDlDst; |
| 65 | import org.projectfloodlight.openflow.protocol.action.OFActionSetDlSrc; |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 66 | import org.projectfloodlight.openflow.protocol.action.OFActionSetField; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 67 | import org.projectfloodlight.openflow.protocol.action.OFActionSetNwDst; |
| 68 | import org.projectfloodlight.openflow.protocol.action.OFActionSetNwSrc; |
Jonathan Hart | 8cf212a | 2015-10-29 17:42:03 -0700 | [diff] [blame] | 69 | import org.projectfloodlight.openflow.protocol.action.OFActionSetQueue; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 70 | import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanPcp; |
| 71 | import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanVid; |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 72 | import org.projectfloodlight.openflow.protocol.instruction.OFInstruction; |
Jonathan Hart | cf78320 | 2014-11-24 18:55:42 -0800 | [diff] [blame] | 73 | import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions; |
alshabib | bdcbb10 | 2015-04-22 14:16:38 -0700 | [diff] [blame] | 74 | import org.projectfloodlight.openflow.protocol.instruction.OFInstructionGotoTable; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 75 | import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteActions; |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 76 | import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteMetadata; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 77 | import org.projectfloodlight.openflow.protocol.match.Match; |
| 78 | import org.projectfloodlight.openflow.protocol.match.MatchField; |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 79 | import org.projectfloodlight.openflow.protocol.oxm.OFOxm; |
Yafit Hadar | 4cc65f7 | 2016-02-10 11:23:06 +0200 | [diff] [blame] | 80 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigid; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 81 | import org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13; |
Sho SHIMIZU | 4f828ee | 2015-05-28 09:38:21 -0700 | [diff] [blame] | 82 | import org.projectfloodlight.openflow.types.CircuitSignalID; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 83 | import org.projectfloodlight.openflow.types.IPv4Address; |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 84 | import org.projectfloodlight.openflow.types.IPv6Address; |
Jonathan Hart | 0e12fad | 2014-10-17 14:54:58 -0700 | [diff] [blame] | 85 | import org.projectfloodlight.openflow.types.Masked; |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 86 | import org.projectfloodlight.openflow.types.OFVlanVidMatch; |
Jonathan Hart | e4e74f0 | 2016-03-03 12:57:40 -0800 | [diff] [blame] | 87 | import org.projectfloodlight.openflow.types.OduSignalID; |
Hyunsun Moon | c8bd97c | 2015-07-18 22:47:33 -0700 | [diff] [blame] | 88 | import org.projectfloodlight.openflow.types.TransportPort; |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 89 | import org.projectfloodlight.openflow.types.U32; |
Hyunsun Moon | a08c5d0 | 2015-07-14 17:53:00 -0700 | [diff] [blame] | 90 | import org.projectfloodlight.openflow.types.U64; |
Sho SHIMIZU | 4f828ee | 2015-05-28 09:38:21 -0700 | [diff] [blame] | 91 | import org.projectfloodlight.openflow.types.U8; |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 92 | import org.projectfloodlight.openflow.types.VlanPcp; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 93 | import org.slf4j.Logger; |
Jian Li | a0d9a17 | 2016-04-01 16:58:06 -0700 | [diff] [blame] | 94 | import org.slf4j.LoggerFactory; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 95 | |
Jonathan Hart | 8cf212a | 2015-10-29 17:42:03 -0700 | [diff] [blame] | 96 | import java.util.List; |
| 97 | |
| 98 | import static org.onosproject.net.flow.criteria.Criteria.matchLambda; |
| 99 | import static org.onosproject.net.flow.criteria.Criteria.matchOchSignalType; |
Yafit Hadar | 7351461 | 2015-11-04 10:14:21 +0200 | [diff] [blame] | 100 | import static org.onosproject.net.flow.criteria.Criteria.matchOduSignalId; |
Jonathan Hart | e4e74f0 | 2016-03-03 12:57:40 -0800 | [diff] [blame] | 101 | import static org.onosproject.net.flow.criteria.Criteria.matchOduSignalType; |
Yafit Hadar | 7351461 | 2015-11-04 10:14:21 +0200 | [diff] [blame] | 102 | import static org.onosproject.net.flow.instructions.Instructions.modL0Lambda; |
| 103 | import static org.onosproject.net.flow.instructions.Instructions.modL1OduSignalId; |
Thomas Vachuska | 95caba3 | 2016-04-04 10:42:05 -0700 | [diff] [blame] | 104 | import static org.onosproject.provider.of.flow.util.OpenFlowValueMapper.lookupChannelSpacing; |
| 105 | import static org.onosproject.provider.of.flow.util.OpenFlowValueMapper.lookupGridType; |
| 106 | import static org.onosproject.provider.of.flow.util.OpenFlowValueMapper.lookupOchSignalType; |
| 107 | import static org.onosproject.provider.of.flow.util.OpenFlowValueMapper.lookupOduSignalType; |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 108 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 109 | public class FlowEntryBuilder { |
Jian Li | a0d9a17 | 2016-04-01 16:58:06 -0700 | [diff] [blame] | 110 | private static final Logger log = LoggerFactory.getLogger(FlowEntryBuilder.class); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 111 | |
| 112 | private final OFFlowStatsEntry stat; |
| 113 | private final OFFlowRemoved removed; |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 114 | private final OFFlowMod flowMod; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 115 | |
| 116 | private final Match match; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 117 | |
Jonathan Hart | 67fc097 | 2015-03-19 15:21:20 -0700 | [diff] [blame] | 118 | // All actions are contained in an OFInstruction. For OF1.0 |
| 119 | // the instruction type is apply instruction (immediate set in ONOS speak) |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 120 | private final List<OFInstruction> instructions; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 121 | |
Jonathan Hart | e4e74f0 | 2016-03-03 12:57:40 -0800 | [diff] [blame] | 122 | private final DeviceId deviceId; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 123 | |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 124 | public enum FlowType { STAT, REMOVED, MOD } |
| 125 | |
| 126 | private final FlowType type; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 127 | |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 128 | private final DriverService driverService; |
| 129 | |
Jonathan Hart | e4e74f0 | 2016-03-03 12:57:40 -0800 | [diff] [blame] | 130 | public FlowEntryBuilder(DeviceId deviceId, OFFlowStatsEntry entry, DriverService driverService) { |
Saurav Das | fa2fa93 | 2015-03-03 11:29:48 -0800 | [diff] [blame] | 131 | this.stat = entry; |
| 132 | this.match = entry.getMatch(); |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 133 | this.instructions = getInstructions(entry); |
Jonathan Hart | e4e74f0 | 2016-03-03 12:57:40 -0800 | [diff] [blame] | 134 | this.deviceId = deviceId; |
Saurav Das | fa2fa93 | 2015-03-03 11:29:48 -0800 | [diff] [blame] | 135 | this.removed = null; |
| 136 | this.flowMod = null; |
| 137 | this.type = FlowType.STAT; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 138 | this.driverService = driverService; |
Saurav Das | fa2fa93 | 2015-03-03 11:29:48 -0800 | [diff] [blame] | 139 | } |
| 140 | |
Jonathan Hart | e4e74f0 | 2016-03-03 12:57:40 -0800 | [diff] [blame] | 141 | public FlowEntryBuilder(DeviceId deviceId, OFFlowRemoved removed, DriverService driverService) { |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 142 | this.match = removed.getMatch(); |
| 143 | this.removed = removed; |
Jonathan Hart | e4e74f0 | 2016-03-03 12:57:40 -0800 | [diff] [blame] | 144 | this.deviceId = deviceId; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 145 | this.instructions = null; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 146 | this.stat = null; |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 147 | this.flowMod = null; |
| 148 | this.type = FlowType.REMOVED; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 149 | this.driverService = driverService; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Jonathan Hart | e4e74f0 | 2016-03-03 12:57:40 -0800 | [diff] [blame] | 152 | public FlowEntryBuilder(DeviceId deviceId, OFFlowMod fm, DriverService driverService) { |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 153 | this.match = fm.getMatch(); |
Jonathan Hart | e4e74f0 | 2016-03-03 12:57:40 -0800 | [diff] [blame] | 154 | this.deviceId = deviceId; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 155 | this.instructions = getInstructions(fm); |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 156 | this.type = FlowType.MOD; |
| 157 | this.flowMod = fm; |
| 158 | this.stat = null; |
| 159 | this.removed = null; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 160 | this.driverService = driverService; |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 161 | } |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 162 | |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 163 | public FlowEntry build(FlowEntryState... state) { |
Brian O'Connor | 2156461 | 2015-12-05 19:24:59 -0800 | [diff] [blame] | 164 | FlowRule.Builder builder; |
| 165 | try { |
| 166 | switch (this.type) { |
| 167 | case STAT: |
| 168 | builder = DefaultFlowRule.builder() |
Jonathan Hart | e4e74f0 | 2016-03-03 12:57:40 -0800 | [diff] [blame] | 169 | .forDevice(deviceId) |
Brian O'Connor | 2156461 | 2015-12-05 19:24:59 -0800 | [diff] [blame] | 170 | .withSelector(buildSelector()) |
| 171 | .withTreatment(buildTreatment()) |
| 172 | .withPriority(stat.getPriority()) |
| 173 | .makeTemporary(stat.getIdleTimeout()) |
Jonathan Hart | d1ce4b0 | 2016-01-11 13:28:36 -0800 | [diff] [blame] | 174 | .withCookie(stat.getCookie().getValue()); |
| 175 | if (stat.getVersion() != OFVersion.OF_10) { |
| 176 | builder.forTable(stat.getTableId().getValue()); |
| 177 | } |
alshabib | bdcbb10 | 2015-04-22 14:16:38 -0700 | [diff] [blame] | 178 | |
Brian O'Connor | 2156461 | 2015-12-05 19:24:59 -0800 | [diff] [blame] | 179 | return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED, |
| 180 | stat.getDurationSec(), |
| 181 | stat.getPacketCount().getValue(), |
| 182 | stat.getByteCount().getValue()); |
| 183 | case REMOVED: |
| 184 | builder = DefaultFlowRule.builder() |
Jonathan Hart | e4e74f0 | 2016-03-03 12:57:40 -0800 | [diff] [blame] | 185 | .forDevice(deviceId) |
Brian O'Connor | 2156461 | 2015-12-05 19:24:59 -0800 | [diff] [blame] | 186 | .withSelector(buildSelector()) |
| 187 | .withPriority(removed.getPriority()) |
| 188 | .makeTemporary(removed.getIdleTimeout()) |
| 189 | .withCookie(removed.getCookie().getValue()); |
| 190 | if (removed.getVersion() != OFVersion.OF_10) { |
| 191 | builder.forTable(removed.getTableId().getValue()); |
| 192 | } |
alshabib | bdcbb10 | 2015-04-22 14:16:38 -0700 | [diff] [blame] | 193 | |
Brian O'Connor | 2156461 | 2015-12-05 19:24:59 -0800 | [diff] [blame] | 194 | return new DefaultFlowEntry(builder.build(), FlowEntryState.REMOVED, |
| 195 | removed.getDurationSec(), |
| 196 | removed.getPacketCount().getValue(), |
| 197 | removed.getByteCount().getValue()); |
| 198 | case MOD: |
| 199 | FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED; |
| 200 | builder = DefaultFlowRule.builder() |
Jonathan Hart | e4e74f0 | 2016-03-03 12:57:40 -0800 | [diff] [blame] | 201 | .forDevice(deviceId) |
Brian O'Connor | 2156461 | 2015-12-05 19:24:59 -0800 | [diff] [blame] | 202 | .withSelector(buildSelector()) |
| 203 | .withTreatment(buildTreatment()) |
| 204 | .withPriority(flowMod.getPriority()) |
| 205 | .makeTemporary(flowMod.getIdleTimeout()) |
| 206 | .withCookie(flowMod.getCookie().getValue()); |
| 207 | if (flowMod.getVersion() != OFVersion.OF_10) { |
| 208 | builder.forTable(flowMod.getTableId().getValue()); |
| 209 | } |
alshabib | bdcbb10 | 2015-04-22 14:16:38 -0700 | [diff] [blame] | 210 | |
Brian O'Connor | 2156461 | 2015-12-05 19:24:59 -0800 | [diff] [blame] | 211 | return new DefaultFlowEntry(builder.build(), flowState, 0, 0, 0); |
| 212 | default: |
| 213 | log.error("Unknown flow type : {}", this.type); |
| 214 | return null; |
| 215 | } |
| 216 | } catch (UnsupportedOperationException e) { |
| 217 | log.warn("Error building flow entry", e); |
| 218 | return null; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 219 | } |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 220 | |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 221 | } |
| 222 | |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 223 | private List<OFInstruction> getInstructions(OFFlowMod entry) { |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 224 | switch (entry.getVersion()) { |
| 225 | case OF_10: |
Jonathan Hart | 8ef6d3b | 2015-03-08 21:21:27 -0700 | [diff] [blame] | 226 | return Lists.newArrayList(OFFactoryVer13.INSTANCE.instructions() |
| 227 | .applyActions( |
| 228 | entry.getActions())); |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 229 | case OF_11: |
| 230 | case OF_12: |
| 231 | case OF_13: |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 232 | return entry.getInstructions(); |
| 233 | default: |
| 234 | log.warn("Unknown OF version {}", entry.getVersion()); |
| 235 | } |
| 236 | return Lists.newLinkedList(); |
| 237 | } |
| 238 | |
| 239 | private List<OFInstruction> getInstructions(OFFlowStatsEntry entry) { |
| 240 | switch (entry.getVersion()) { |
| 241 | case OF_10: |
| 242 | return Lists.newArrayList( |
| 243 | OFFactoryVer13.INSTANCE.instructions().applyActions(entry.getActions())); |
| 244 | case OF_11: |
| 245 | case OF_12: |
| 246 | case OF_13: |
| 247 | return entry.getInstructions(); |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 248 | default: |
| 249 | log.warn("Unknown OF version {}", entry.getVersion()); |
| 250 | } |
| 251 | return Lists.newLinkedList(); |
| 252 | } |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 253 | |
| 254 | private TrafficTreatment buildTreatment() { |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 255 | TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder(); |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 256 | for (OFInstruction in : instructions) { |
| 257 | switch (in.getType()) { |
| 258 | case GOTO_TABLE: |
alshabib | bdcbb10 | 2015-04-22 14:16:38 -0700 | [diff] [blame] | 259 | builder.transition(((int) ((OFInstructionGotoTable) in) |
| 260 | .getTableId().getValue())); |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 261 | break; |
| 262 | case WRITE_METADATA: |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 263 | OFInstructionWriteMetadata m = (OFInstructionWriteMetadata) in; |
| 264 | builder.writeMetadata(m.getMetadata().getValue(), |
| 265 | m.getMetadataMask().getValue()); |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 266 | break; |
| 267 | case WRITE_ACTIONS: |
| 268 | builder.deferred(); |
| 269 | buildActions(((OFInstructionWriteActions) in).getActions(), |
| 270 | builder); |
| 271 | break; |
| 272 | case APPLY_ACTIONS: |
| 273 | builder.immediate(); |
| 274 | buildActions(((OFInstructionApplyActions) in).getActions(), |
| 275 | builder); |
| 276 | break; |
| 277 | case CLEAR_ACTIONS: |
| 278 | builder.wipeDeferred(); |
| 279 | break; |
| 280 | case EXPERIMENTER: |
| 281 | break; |
| 282 | case METER: |
| 283 | break; |
| 284 | default: |
| 285 | log.warn("Unknown instructions type {}", in.getType()); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 286 | } |
| 287 | } |
| 288 | |
| 289 | return builder.build(); |
| 290 | } |
| 291 | |
Jian Li | a0d9a17 | 2016-04-01 16:58:06 -0700 | [diff] [blame] | 292 | /** |
| 293 | * Configures traffic treatment builder with a given collection of actions. |
| 294 | * |
| 295 | * @param actions a set of OpenFlow actions |
| 296 | * @param builder traffic treatment builder |
| 297 | * @param driverHandler driver handler |
| 298 | * @param deviceId device identifier |
| 299 | * @return configured traffic treatment builder |
| 300 | */ |
| 301 | public static TrafficTreatment.Builder configureTreatmentBuilder(List<OFAction> actions, |
| 302 | TrafficTreatment.Builder builder, |
| 303 | DriverHandler driverHandler, |
| 304 | DeviceId deviceId) { |
| 305 | ExtensionTreatmentInterpreter interpreter; |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 306 | if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) { |
Jian Li | a0d9a17 | 2016-04-01 16:58:06 -0700 | [diff] [blame] | 307 | interpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class); |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 308 | } else { |
Jian Li | a0d9a17 | 2016-04-01 16:58:06 -0700 | [diff] [blame] | 309 | interpreter = null; |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 310 | } |
| 311 | |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 312 | for (OFAction act : actions) { |
| 313 | switch (act.getType()) { |
| 314 | case OUTPUT: |
| 315 | OFActionOutput out = (OFActionOutput) act; |
| 316 | builder.setOutput( |
| 317 | PortNumber.portNumber(out.getPort().getPortNumber())); |
| 318 | break; |
| 319 | case SET_VLAN_VID: |
| 320 | OFActionSetVlanVid vlan = (OFActionSetVlanVid) act; |
| 321 | builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan())); |
| 322 | break; |
| 323 | case SET_VLAN_PCP: |
| 324 | OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act; |
| 325 | builder.setVlanPcp(pcp.getVlanPcp().getValue()); |
| 326 | break; |
| 327 | case SET_DL_DST: |
| 328 | OFActionSetDlDst dldst = (OFActionSetDlDst) act; |
| 329 | builder.setEthDst( |
| 330 | MacAddress.valueOf(dldst.getDlAddr().getLong())); |
| 331 | break; |
| 332 | case SET_DL_SRC: |
| 333 | OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act; |
| 334 | builder.setEthSrc( |
| 335 | MacAddress.valueOf(dlsrc.getDlAddr().getLong())); |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 336 | break; |
| 337 | case SET_NW_DST: |
| 338 | OFActionSetNwDst nwdst = (OFActionSetNwDst) act; |
| 339 | IPv4Address di = nwdst.getNwAddr(); |
| 340 | builder.setIpDst(Ip4Address.valueOf(di.getInt())); |
| 341 | break; |
| 342 | case SET_NW_SRC: |
| 343 | OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act; |
| 344 | IPv4Address si = nwsrc.getNwAddr(); |
| 345 | builder.setIpSrc(Ip4Address.valueOf(si.getInt())); |
| 346 | break; |
| 347 | case EXPERIMENTER: |
| 348 | OFActionExperimenter exp = (OFActionExperimenter) act; |
| 349 | if (exp.getExperimenter() == 0x80005A06 || |
| 350 | exp.getExperimenter() == 0x748771) { |
| 351 | OFActionCircuit ct = (OFActionCircuit) exp; |
Yafit Hadar | 4cc65f7 | 2016-02-10 11:23:06 +0200 | [diff] [blame] | 352 | CircuitSignalID circuitSignalID = ((OFOxmOchSigid) ct.getField()).getValue(); |
| 353 | builder.add(Instructions.modL0Lambda(Lambda.ochSignal( |
| 354 | lookupGridType(circuitSignalID.getGridType()), |
| 355 | lookupChannelSpacing(circuitSignalID.getChannelSpacing()), |
| 356 | circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth()))); |
Jian Li | a0d9a17 | 2016-04-01 16:58:06 -0700 | [diff] [blame] | 357 | } else if (interpreter != null) { |
| 358 | builder.extension(interpreter.mapAction(exp), deviceId); |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 359 | } else { |
| 360 | log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter()); |
| 361 | } |
| 362 | break; |
| 363 | case SET_FIELD: |
| 364 | OFActionSetField setField = (OFActionSetField) act; |
Jian Li | a0d9a17 | 2016-04-01 16:58:06 -0700 | [diff] [blame] | 365 | handleSetField(builder, setField, driverHandler, deviceId); |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 366 | break; |
| 367 | case POP_MPLS: |
| 368 | OFActionPopMpls popMpls = (OFActionPopMpls) act; |
Ray Milkey | 84d5a29 | 2016-02-22 14:04:01 -0800 | [diff] [blame] | 369 | builder.popMpls(new EthType(popMpls.getEthertype().getValue())); |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 370 | break; |
| 371 | case PUSH_MPLS: |
| 372 | builder.pushMpls(); |
| 373 | break; |
| 374 | case COPY_TTL_IN: |
| 375 | builder.copyTtlIn(); |
| 376 | break; |
| 377 | case COPY_TTL_OUT: |
| 378 | builder.copyTtlOut(); |
| 379 | break; |
| 380 | case DEC_MPLS_TTL: |
| 381 | builder.decMplsTtl(); |
| 382 | break; |
| 383 | case DEC_NW_TTL: |
| 384 | builder.decNwTtl(); |
| 385 | break; |
| 386 | case GROUP: |
| 387 | OFActionGroup group = (OFActionGroup) act; |
| 388 | builder.group(new DefaultGroupId(group.getGroup().getGroupNumber())); |
| 389 | break; |
Steffen Gebert | bbfdaaa | 2015-09-29 11:01:46 +0200 | [diff] [blame] | 390 | case SET_QUEUE: |
| 391 | OFActionSetQueue setQueue = (OFActionSetQueue) act; |
| 392 | builder.setQueue(setQueue.getQueueId()); |
| 393 | break; |
Steffen Gebert | ba2d3b7 | 2015-10-22 11:14:31 +0200 | [diff] [blame] | 394 | case ENQUEUE: |
| 395 | OFActionEnqueue enqueue = (OFActionEnqueue) act; |
| 396 | builder.setQueue(enqueue.getQueueId(), PortNumber.portNumber(enqueue.getPort().getPortNumber())); |
| 397 | break; |
Jonathan Hart | 67fc097 | 2015-03-19 15:21:20 -0700 | [diff] [blame] | 398 | case STRIP_VLAN: |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 399 | case POP_VLAN: |
| 400 | builder.popVlan(); |
| 401 | break; |
Jonathan Hart | 8ef6d3b | 2015-03-08 21:21:27 -0700 | [diff] [blame] | 402 | case PUSH_VLAN: |
| 403 | builder.pushVlan(); |
| 404 | break; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 405 | case SET_TP_DST: |
| 406 | case SET_TP_SRC: |
| 407 | case POP_PBB: |
| 408 | case PUSH_PBB: |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 409 | case SET_MPLS_LABEL: |
| 410 | case SET_MPLS_TC: |
| 411 | case SET_MPLS_TTL: |
| 412 | case SET_NW_ECN: |
| 413 | case SET_NW_TOS: |
| 414 | case SET_NW_TTL: |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 415 | |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 416 | default: |
| 417 | log.warn("Action type {} not yet implemented.", act.getType()); |
| 418 | } |
| 419 | } |
| 420 | return builder; |
| 421 | } |
| 422 | |
Jian Li | a0d9a17 | 2016-04-01 16:58:06 -0700 | [diff] [blame] | 423 | private TrafficTreatment.Builder buildActions(List<OFAction> actions, |
| 424 | TrafficTreatment.Builder builder) { |
Jonathan Hart | e4e74f0 | 2016-03-03 12:57:40 -0800 | [diff] [blame] | 425 | DriverHandler driverHandler = getDriver(deviceId); |
Jian Li | a0d9a17 | 2016-04-01 16:58:06 -0700 | [diff] [blame] | 426 | |
| 427 | return configureTreatmentBuilder(actions, builder, driverHandler, deviceId); |
| 428 | } |
| 429 | |
| 430 | |
| 431 | private static void handleSetField(TrafficTreatment.Builder builder, |
| 432 | OFActionSetField action, |
| 433 | DriverHandler driverHandler, |
| 434 | DeviceId deviceId) { |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 435 | ExtensionTreatmentInterpreter treatmentInterpreter; |
| 436 | if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) { |
| 437 | treatmentInterpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class); |
| 438 | } else { |
| 439 | treatmentInterpreter = null; |
| 440 | } |
| 441 | |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 442 | OFOxm<?> oxm = action.getField(); |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 443 | switch (oxm.getMatchField().id) { |
| 444 | case VLAN_PCP: |
| 445 | @SuppressWarnings("unchecked") |
| 446 | OFOxm<VlanPcp> vlanpcp = (OFOxm<VlanPcp>) oxm; |
| 447 | builder.setVlanPcp(vlanpcp.getValue().getValue()); |
| 448 | break; |
| 449 | case VLAN_VID: |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 450 | if (treatmentInterpreter != null && |
| 451 | treatmentInterpreter.supported(ExtensionTreatmentTypes.OFDPA_SET_VLAN_ID.type())) { |
| 452 | builder.extension(treatmentInterpreter.mapAction(action), |
Jonathan Hart | e4e74f0 | 2016-03-03 12:57:40 -0800 | [diff] [blame] | 453 | deviceId); |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 454 | } else { |
| 455 | @SuppressWarnings("unchecked") |
| 456 | OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm; |
| 457 | builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan())); |
| 458 | } |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 459 | break; |
| 460 | case ETH_DST: |
| 461 | @SuppressWarnings("unchecked") |
| 462 | OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethdst = |
| 463 | (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm; |
| 464 | builder.setEthDst(MacAddress.valueOf(ethdst.getValue().getLong())); |
| 465 | break; |
| 466 | case ETH_SRC: |
| 467 | @SuppressWarnings("unchecked") |
| 468 | OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethsrc = |
| 469 | (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm; |
| 470 | builder.setEthSrc(MacAddress.valueOf(ethsrc.getValue().getLong())); |
| 471 | break; |
| 472 | case IPV4_DST: |
| 473 | @SuppressWarnings("unchecked") |
| 474 | OFOxm<IPv4Address> ip4dst = (OFOxm<IPv4Address>) oxm; |
| 475 | builder.setIpDst(Ip4Address.valueOf(ip4dst.getValue().getInt())); |
| 476 | break; |
| 477 | case IPV4_SRC: |
| 478 | @SuppressWarnings("unchecked") |
| 479 | OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm; |
| 480 | builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt())); |
| 481 | break; |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 482 | case MPLS_LABEL: |
| 483 | @SuppressWarnings("unchecked") |
| 484 | OFOxm<U32> labelId = (OFOxm<U32>) oxm; |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 485 | builder.setMpls(MplsLabel.mplsLabel((int) labelId.getValue().getValue())); |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 486 | break; |
Saurav Das | 73a7dd4 | 2015-08-19 22:20:31 -0700 | [diff] [blame] | 487 | case MPLS_BOS: |
| 488 | @SuppressWarnings("unchecked") |
| 489 | OFOxm<U8> mplsBos = (OFOxm<U8>) oxm; |
| 490 | builder.setMplsBos(mplsBos.getValue() == U8.ZERO ? false : true); |
| 491 | break; |
Hyunsun Moon | a08c5d0 | 2015-07-14 17:53:00 -0700 | [diff] [blame] | 492 | case TUNNEL_ID: |
| 493 | @SuppressWarnings("unchecked") |
| 494 | OFOxm<U64> tunnelId = (OFOxm<U64>) oxm; |
| 495 | builder.setTunnelId(tunnelId.getValue().getValue()); |
| 496 | break; |
Hyunsun Moon | c8bd97c | 2015-07-18 22:47:33 -0700 | [diff] [blame] | 497 | case TCP_DST: |
| 498 | @SuppressWarnings("unchecked") |
| 499 | OFOxm<TransportPort> tcpdst = (OFOxm<TransportPort>) oxm; |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 500 | builder.setTcpDst(TpPort.tpPort(tcpdst.getValue().getPort())); |
Hyunsun Moon | c8bd97c | 2015-07-18 22:47:33 -0700 | [diff] [blame] | 501 | break; |
| 502 | case TCP_SRC: |
| 503 | @SuppressWarnings("unchecked") |
| 504 | OFOxm<TransportPort> tcpsrc = (OFOxm<TransportPort>) oxm; |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 505 | builder.setTcpSrc(TpPort.tpPort(tcpsrc.getValue().getPort())); |
Hyunsun Moon | c8bd97c | 2015-07-18 22:47:33 -0700 | [diff] [blame] | 506 | break; |
| 507 | case UDP_DST: |
| 508 | @SuppressWarnings("unchecked") |
| 509 | OFOxm<TransportPort> udpdst = (OFOxm<TransportPort>) oxm; |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 510 | builder.setUdpDst(TpPort.tpPort(udpdst.getValue().getPort())); |
Hyunsun Moon | c8bd97c | 2015-07-18 22:47:33 -0700 | [diff] [blame] | 511 | break; |
| 512 | case UDP_SRC: |
| 513 | @SuppressWarnings("unchecked") |
| 514 | OFOxm<TransportPort> udpsrc = (OFOxm<TransportPort>) oxm; |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 515 | builder.setUdpSrc(TpPort.tpPort(udpsrc.getValue().getPort())); |
Hyunsun Moon | c8bd97c | 2015-07-18 22:47:33 -0700 | [diff] [blame] | 516 | break; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 517 | case TUNNEL_IPV4_DST: |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 518 | if (treatmentInterpreter != null && |
| 519 | treatmentInterpreter.supported(ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) { |
Jonathan Hart | e4e74f0 | 2016-03-03 12:57:40 -0800 | [diff] [blame] | 520 | builder.extension(treatmentInterpreter.mapAction(action), deviceId); |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 521 | } |
| 522 | break; |
Yafit Hadar | 7351461 | 2015-11-04 10:14:21 +0200 | [diff] [blame] | 523 | case EXP_ODU_SIG_ID: |
| 524 | @SuppressWarnings("unchecked") |
| 525 | OFOxm<OduSignalID> oduID = (OFOxm<OduSignalID>) oxm; |
| 526 | OduSignalID oduSignalID = oduID.getValue(); |
| 527 | OduSignalId oduSignalId = OduSignalId.oduSignalId(oduSignalID.getTpn(), |
| 528 | oduSignalID.getTslen(), |
| 529 | oduSignalID.getTsmap()); |
| 530 | builder.add(modL1OduSignalId(oduSignalId)); |
| 531 | break; |
| 532 | case EXP_OCH_SIG_ID: |
| 533 | try { |
| 534 | @SuppressWarnings("unchecked") |
| 535 | OFOxm<CircuitSignalID> ochId = (OFOxm<CircuitSignalID>) oxm; |
| 536 | CircuitSignalID circuitSignalID = ochId.getValue(); |
| 537 | builder.add(modL0Lambda(Lambda.ochSignal( |
| 538 | lookupGridType(circuitSignalID.getGridType()), |
| 539 | lookupChannelSpacing(circuitSignalID.getChannelSpacing()), |
| 540 | circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth()))); |
| 541 | } catch (NoMappingFoundException e) { |
| 542 | log.warn(e.getMessage()); |
| 543 | break; |
| 544 | } |
| 545 | break; |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 546 | case ARP_OP: |
| 547 | case ARP_SHA: |
| 548 | case ARP_SPA: |
| 549 | case ARP_THA: |
| 550 | case ARP_TPA: |
| 551 | case BSN_EGR_PORT_GROUP_ID: |
| 552 | case BSN_GLOBAL_VRF_ALLOWED: |
| 553 | case BSN_IN_PORTS_128: |
| 554 | case BSN_L3_DST_CLASS_ID: |
| 555 | case BSN_L3_INTERFACE_CLASS_ID: |
| 556 | case BSN_L3_SRC_CLASS_ID: |
| 557 | case BSN_LAG_ID: |
| 558 | case BSN_TCP_FLAGS: |
| 559 | case BSN_UDF0: |
| 560 | case BSN_UDF1: |
| 561 | case BSN_UDF2: |
| 562 | case BSN_UDF3: |
| 563 | case BSN_UDF4: |
| 564 | case BSN_UDF5: |
| 565 | case BSN_UDF6: |
| 566 | case BSN_UDF7: |
| 567 | case BSN_VLAN_XLATE_PORT_GROUP_ID: |
| 568 | case BSN_VRF: |
| 569 | case ETH_TYPE: |
| 570 | case ICMPV4_CODE: |
| 571 | case ICMPV4_TYPE: |
| 572 | case ICMPV6_CODE: |
| 573 | case ICMPV6_TYPE: |
| 574 | case IN_PHY_PORT: |
| 575 | case IN_PORT: |
| 576 | case IPV6_DST: |
| 577 | case IPV6_FLABEL: |
| 578 | case IPV6_ND_SLL: |
| 579 | case IPV6_ND_TARGET: |
| 580 | case IPV6_ND_TLL: |
| 581 | case IPV6_SRC: |
| 582 | case IP_DSCP: |
| 583 | case IP_ECN: |
| 584 | case IP_PROTO: |
| 585 | case METADATA: |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 586 | case MPLS_TC: |
| 587 | case OCH_SIGID: |
| 588 | case OCH_SIGID_BASIC: |
| 589 | case OCH_SIGTYPE: |
| 590 | case OCH_SIGTYPE_BASIC: |
| 591 | case SCTP_DST: |
| 592 | case SCTP_SRC: |
Yafit Hadar | 7351461 | 2015-11-04 10:14:21 +0200 | [diff] [blame] | 593 | case EXP_ODU_SIGTYPE: |
| 594 | case EXP_OCH_SIGTYPE: |
Jonathan Hart | d0ef752 | 2014-12-11 11:51:18 -0800 | [diff] [blame] | 595 | default: |
| 596 | log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id); |
| 597 | break; |
| 598 | } |
| 599 | } |
| 600 | |
Sho SHIMIZU | 6f1b09e | 2015-05-05 11:26:22 -0700 | [diff] [blame] | 601 | // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 602 | private TrafficSelector buildSelector() { |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 603 | MacAddress mac; |
| 604 | Ip4Prefix ip4Prefix; |
| 605 | Ip6Address ip6Address; |
| 606 | Ip6Prefix ip6Prefix; |
BitOhenry | c1e5fcc | 2015-11-23 20:47:53 +0800 | [diff] [blame] | 607 | Ip4Address ip; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 608 | |
Jonathan Hart | e4e74f0 | 2016-03-03 12:57:40 -0800 | [diff] [blame] | 609 | DriverHandler driverHandler = getDriver(deviceId); |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 610 | ExtensionSelectorInterpreter selectorInterpreter; |
| 611 | if (driverHandler.hasBehaviour(ExtensionSelectorInterpreter.class)) { |
| 612 | selectorInterpreter = driverHandler.behaviour(ExtensionSelectorInterpreter.class); |
| 613 | } else { |
| 614 | selectorInterpreter = null; |
| 615 | } |
| 616 | |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 617 | TrafficSelector.Builder builder = DefaultTrafficSelector.builder(); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 618 | for (MatchField<?> field : match.getMatchFields()) { |
| 619 | switch (field.id) { |
| 620 | case IN_PORT: |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 621 | builder.matchInPort(PortNumber |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 622 | .portNumber(match.get(MatchField.IN_PORT).getPortNumber())); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 623 | break; |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 624 | case IN_PHY_PORT: |
| 625 | builder.matchInPhyPort(PortNumber |
| 626 | .portNumber(match.get(MatchField.IN_PHY_PORT).getPortNumber())); |
| 627 | break; |
| 628 | case METADATA: |
| 629 | long metadata = |
| 630 | match.get(MatchField.METADATA).getValue().getValue(); |
| 631 | builder.matchMetadata(metadata); |
| 632 | break; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 633 | case ETH_DST: |
Saurav Das | 9d6c86b | 2016-02-19 09:01:07 -0800 | [diff] [blame] | 634 | if (match.isPartiallyMasked(MatchField.ETH_DST)) { |
| 635 | Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac = |
| 636 | match.getMasked(MatchField.ETH_DST); |
| 637 | builder.matchEthDstMasked(MacAddress.valueOf(maskedMac.getValue().getLong()), |
| 638 | MacAddress.valueOf(maskedMac.getMask().getLong())); |
| 639 | } else { |
| 640 | mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong()); |
| 641 | builder.matchEthDst(mac); |
| 642 | } |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 643 | break; |
| 644 | case ETH_SRC: |
Saurav Das | 9d6c86b | 2016-02-19 09:01:07 -0800 | [diff] [blame] | 645 | if (match.isPartiallyMasked(MatchField.ETH_SRC)) { |
| 646 | Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac = |
| 647 | match.getMasked(MatchField.ETH_SRC); |
| 648 | builder.matchEthSrcMasked(MacAddress.valueOf(maskedMac.getValue().getLong()), |
| 649 | MacAddress.valueOf(maskedMac.getMask().getLong())); |
| 650 | } else { |
| 651 | mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong()); |
| 652 | builder.matchEthSrc(mac); |
| 653 | } |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 654 | break; |
| 655 | case ETH_TYPE: |
| 656 | int ethType = match.get(MatchField.ETH_TYPE).getValue(); |
Jonathan Hart | 8cf212a | 2015-10-29 17:42:03 -0700 | [diff] [blame] | 657 | builder.matchEthType((short) ethType); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 658 | break; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 659 | case VLAN_VID: |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 660 | if (selectorInterpreter != null && |
| 661 | selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) { |
| 662 | if (match.getVersion().equals(OFVersion.OF_13)) { |
| 663 | OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.VLAN_VID); |
| 664 | builder.extension(selectorInterpreter.mapOxm(oxm), |
Jonathan Hart | e4e74f0 | 2016-03-03 12:57:40 -0800 | [diff] [blame] | 665 | deviceId); |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 666 | } else { |
| 667 | break; |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 668 | } |
| 669 | } else { |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 670 | VlanId vlanId = null; |
| 671 | if (match.isPartiallyMasked(MatchField.VLAN_VID)) { |
| 672 | Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID); |
| 673 | if (masked.getValue().equals(OFVlanVidMatch.PRESENT) |
| 674 | && masked.getMask().equals(OFVlanVidMatch.PRESENT)) { |
| 675 | vlanId = VlanId.ANY; |
| 676 | } |
Jonathan Hart | 1468fee | 2015-07-16 18:50:34 -0700 | [diff] [blame] | 677 | } else { |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 678 | if (!match.get(MatchField.VLAN_VID).isPresentBitSet()) { |
| 679 | vlanId = VlanId.NONE; |
| 680 | } else { |
| 681 | vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan()); |
| 682 | } |
Jonathan Hart | 1468fee | 2015-07-16 18:50:34 -0700 | [diff] [blame] | 683 | } |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 684 | if (vlanId != null) { |
| 685 | builder.matchVlanId(vlanId); |
| 686 | } |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 687 | } |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 688 | break; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 689 | case VLAN_PCP: |
| 690 | byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue(); |
| 691 | builder.matchVlanPcp(vlanPcp); |
| 692 | break; |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 693 | case IP_DSCP: |
| 694 | byte ipDscp = match.get(MatchField.IP_DSCP).getDscpValue(); |
| 695 | builder.matchIPDscp(ipDscp); |
| 696 | break; |
| 697 | case IP_ECN: |
| 698 | byte ipEcn = match.get(MatchField.IP_ECN).getEcnValue(); |
| 699 | builder.matchIPEcn(ipEcn); |
| 700 | break; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 701 | case IP_PROTO: |
| 702 | short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber(); |
| 703 | builder.matchIPProtocol((byte) proto); |
| 704 | break; |
| 705 | case IPV4_SRC: |
| 706 | if (match.isPartiallyMasked(MatchField.IPV4_SRC)) { |
| 707 | Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 708 | ip4Prefix = Ip4Prefix.valueOf( |
| 709 | maskedIp.getValue().getInt(), |
| 710 | maskedIp.getMask().asCidrMaskLength()); |
| 711 | } else { |
| 712 | ip4Prefix = Ip4Prefix.valueOf( |
| 713 | match.get(MatchField.IPV4_SRC).getInt(), |
| 714 | Ip4Prefix.MAX_MASK_LENGTH); |
| 715 | } |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 716 | builder.matchIPSrc(ip4Prefix); |
| 717 | break; |
| 718 | case IPV4_DST: |
| 719 | if (match.isPartiallyMasked(MatchField.IPV4_DST)) { |
| 720 | Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 721 | ip4Prefix = Ip4Prefix.valueOf( |
| 722 | maskedIp.getValue().getInt(), |
| 723 | maskedIp.getMask().asCidrMaskLength()); |
| 724 | } else { |
| 725 | ip4Prefix = Ip4Prefix.valueOf( |
| 726 | match.get(MatchField.IPV4_DST).getInt(), |
| 727 | Ip4Prefix.MAX_MASK_LENGTH); |
| 728 | } |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 729 | builder.matchIPDst(ip4Prefix); |
Jonathan Hart | 34bc614 | 2014-10-17 11:00:43 -0700 | [diff] [blame] | 730 | break; |
| 731 | case TCP_SRC: |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 732 | builder.matchTcpSrc(TpPort.tpPort(match.get(MatchField.TCP_SRC).getPort())); |
Jonathan Hart | 34bc614 | 2014-10-17 11:00:43 -0700 | [diff] [blame] | 733 | break; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 734 | case TCP_DST: |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 735 | builder.matchTcpDst(TpPort.tpPort(match.get(MatchField.TCP_DST).getPort())); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 736 | break; |
| 737 | case UDP_SRC: |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 738 | builder.matchUdpSrc(TpPort.tpPort(match.get(MatchField.UDP_SRC).getPort())); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 739 | break; |
| 740 | case UDP_DST: |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 741 | builder.matchUdpDst(TpPort.tpPort(match.get(MatchField.UDP_DST).getPort())); |
Sho SHIMIZU | 6f1b09e | 2015-05-05 11:26:22 -0700 | [diff] [blame] | 742 | break; |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 743 | case MPLS_LABEL: |
| 744 | builder.matchMplsLabel(MplsLabel.mplsLabel((int) match.get(MatchField.MPLS_LABEL) |
| 745 | .getValue())); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 746 | break; |
Saurav Das | ffc5bbc | 2015-08-18 23:30:19 -0700 | [diff] [blame] | 747 | case MPLS_BOS: |
| 748 | builder.matchMplsBos(match.get(MatchField.MPLS_BOS).getValue()); |
| 749 | break; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 750 | case SCTP_SRC: |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 751 | builder.matchSctpSrc(TpPort.tpPort(match.get(MatchField.SCTP_SRC).getPort())); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 752 | break; |
| 753 | case SCTP_DST: |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 754 | builder.matchSctpDst(TpPort.tpPort(match.get(MatchField.SCTP_DST).getPort())); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 755 | break; |
| 756 | case ICMPV4_TYPE: |
| 757 | byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType(); |
| 758 | builder.matchIcmpType(icmpType); |
| 759 | break; |
| 760 | case ICMPV4_CODE: |
| 761 | byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode(); |
| 762 | builder.matchIcmpCode(icmpCode); |
| 763 | break; |
| 764 | case IPV6_SRC: |
| 765 | if (match.isPartiallyMasked(MatchField.IPV6_SRC)) { |
| 766 | Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC); |
| 767 | ip6Prefix = Ip6Prefix.valueOf( |
| 768 | maskedIp.getValue().getBytes(), |
| 769 | maskedIp.getMask().asCidrMaskLength()); |
| 770 | } else { |
| 771 | ip6Prefix = Ip6Prefix.valueOf( |
| 772 | match.get(MatchField.IPV6_SRC).getBytes(), |
| 773 | Ip6Prefix.MAX_MASK_LENGTH); |
| 774 | } |
| 775 | builder.matchIPv6Src(ip6Prefix); |
| 776 | break; |
| 777 | case IPV6_DST: |
| 778 | if (match.isPartiallyMasked(MatchField.IPV6_DST)) { |
| 779 | Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST); |
| 780 | ip6Prefix = Ip6Prefix.valueOf( |
| 781 | maskedIp.getValue().getBytes(), |
| 782 | maskedIp.getMask().asCidrMaskLength()); |
| 783 | } else { |
| 784 | ip6Prefix = Ip6Prefix.valueOf( |
| 785 | match.get(MatchField.IPV6_DST).getBytes(), |
| 786 | Ip6Prefix.MAX_MASK_LENGTH); |
| 787 | } |
| 788 | builder.matchIPv6Dst(ip6Prefix); |
| 789 | break; |
| 790 | case IPV6_FLABEL: |
| 791 | int flowLabel = |
| 792 | match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue(); |
| 793 | builder.matchIPv6FlowLabel(flowLabel); |
| 794 | break; |
| 795 | case ICMPV6_TYPE: |
| 796 | byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue(); |
| 797 | builder.matchIcmpv6Type(icmpv6type); |
| 798 | break; |
| 799 | case ICMPV6_CODE: |
| 800 | byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue(); |
| 801 | builder.matchIcmpv6Code(icmpv6code); |
| 802 | break; |
| 803 | case IPV6_ND_TARGET: |
| 804 | ip6Address = |
| 805 | Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes()); |
| 806 | builder.matchIPv6NDTargetAddress(ip6Address); |
| 807 | break; |
| 808 | case IPV6_ND_SLL: |
| 809 | mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong()); |
| 810 | builder.matchIPv6NDSourceLinkLayerAddress(mac); |
| 811 | break; |
| 812 | case IPV6_ND_TLL: |
| 813 | mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong()); |
| 814 | builder.matchIPv6NDTargetLinkLayerAddress(mac); |
| 815 | break; |
Pavlin Radoslavov | 5e4f754 | 2015-02-06 18:18:21 -0800 | [diff] [blame] | 816 | case IPV6_EXTHDR: |
Charles M.C. Chan | 2184de1 | 2015-04-26 02:24:53 +0800 | [diff] [blame] | 817 | builder.matchIPv6ExthdrFlags((short) match.get(MatchField.IPV6_EXTHDR) |
Hyunsun Moon | a08c5d0 | 2015-07-14 17:53:00 -0700 | [diff] [blame] | 818 | .getValue()); |
Pavlin Radoslavov | 5e4f754 | 2015-02-06 18:18:21 -0800 | [diff] [blame] | 819 | break; |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 820 | case OCH_SIGID: |
Sho SHIMIZU | 4f828ee | 2015-05-28 09:38:21 -0700 | [diff] [blame] | 821 | CircuitSignalID sigId = match.get(MatchField.OCH_SIGID); |
| 822 | builder.add(matchLambda(Lambda.ochSignal( |
Sho SHIMIZU | c17042d | 2015-05-28 12:07:23 -0700 | [diff] [blame] | 823 | lookupGridType(sigId.getGridType()), lookupChannelSpacing(sigId.getChannelSpacing()), |
Marc De Leenheer | 0b8b2ef | 2015-08-03 15:39:00 -0700 | [diff] [blame] | 824 | sigId.getChannelNumber(), sigId.getSpectralWidth()) |
Sho SHIMIZU | 4f828ee | 2015-05-28 09:38:21 -0700 | [diff] [blame] | 825 | )); |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 826 | break; |
Praseed Balakrishnan | 2dd5abd | 2014-11-03 14:56:28 -0800 | [diff] [blame] | 827 | case OCH_SIGTYPE: |
Sho SHIMIZU | 4f828ee | 2015-05-28 09:38:21 -0700 | [diff] [blame] | 828 | U8 sigType = match.get(MatchField.OCH_SIGTYPE); |
Sho SHIMIZU | c17042d | 2015-05-28 12:07:23 -0700 | [diff] [blame] | 829 | builder.add(matchOchSignalType(lookupOchSignalType((byte) sigType.getValue()))); |
Praseed Balakrishnan | 2dd5abd | 2014-11-03 14:56:28 -0800 | [diff] [blame] | 830 | break; |
Yafit Hadar | 7351461 | 2015-11-04 10:14:21 +0200 | [diff] [blame] | 831 | case EXP_OCH_SIG_ID: |
| 832 | try { |
| 833 | CircuitSignalID expSigId = match.get(MatchField.EXP_OCH_SIG_ID); |
| 834 | builder.add(matchLambda(Lambda.ochSignal( |
| 835 | lookupGridType(expSigId.getGridType()), lookupChannelSpacing(expSigId.getChannelSpacing()), |
| 836 | expSigId.getChannelNumber(), expSigId.getSpectralWidth()))); |
| 837 | } catch (NoMappingFoundException e) { |
| 838 | log.warn(e.getMessage()); |
| 839 | break; |
| 840 | } |
| 841 | break; |
| 842 | case EXP_OCH_SIGTYPE: |
| 843 | try { |
| 844 | U8 expOchSigType = match.get(MatchField.EXP_OCH_SIGTYPE); |
| 845 | builder.add(matchOchSignalType(lookupOchSignalType((byte) expOchSigType.getValue()))); |
| 846 | } catch (NoMappingFoundException e) { |
| 847 | log.warn(e.getMessage()); |
| 848 | break; |
| 849 | } |
| 850 | break; |
| 851 | case EXP_ODU_SIG_ID: |
| 852 | OduSignalId oduSignalId = OduSignalId.oduSignalId(match.get(MatchField.EXP_ODU_SIG_ID).getTpn(), |
| 853 | match.get(MatchField.EXP_ODU_SIG_ID).getTslen(), |
| 854 | match.get(MatchField.EXP_ODU_SIG_ID).getTsmap()); |
| 855 | builder.add(matchOduSignalId(oduSignalId)); |
| 856 | break; |
| 857 | case EXP_ODU_SIGTYPE: |
| 858 | try { |
| 859 | U8 oduSigType = match.get(MatchField.EXP_ODU_SIGTYPE); |
| 860 | builder.add(matchOduSignalType(lookupOduSignalType((byte) oduSigType.getValue()))); |
| 861 | } catch (NoMappingFoundException e) { |
| 862 | log.warn(e.getMessage()); |
| 863 | break; |
| 864 | } |
| 865 | break; |
Hyunsun Moon | a08c5d0 | 2015-07-14 17:53:00 -0700 | [diff] [blame] | 866 | case TUNNEL_ID: |
| 867 | long tunnelId = match.get(MatchField.TUNNEL_ID).getValue(); |
| 868 | builder.matchTunnelId(tunnelId); |
| 869 | break; |
BitOhenry | b40129a | 2015-11-30 12:41:18 +0800 | [diff] [blame] | 870 | case ARP_OP: |
| 871 | int arpOp = match.get(MatchField.ARP_OP).getOpcode(); |
| 872 | builder.matchArpOp(arpOp); |
| 873 | break; |
BitOhenry | a331b18 | 2015-11-23 08:39:37 +0800 | [diff] [blame] | 874 | case ARP_SHA: |
| 875 | mac = MacAddress.valueOf(match.get(MatchField.ARP_SHA).getLong()); |
| 876 | builder.matchArpSha(mac); |
| 877 | break; |
BitOhenry | 296b454 | 2015-11-24 08:41:58 +0800 | [diff] [blame] | 878 | case ARP_SPA: |
| 879 | ip = Ip4Address.valueOf(match.get(MatchField.ARP_SPA).getInt()); |
| 880 | builder.matchArpSpa(ip); |
| 881 | break; |
BitOhenry | 7643085 | 2015-11-20 19:04:49 +0800 | [diff] [blame] | 882 | case ARP_THA: |
| 883 | mac = MacAddress.valueOf(match.get(MatchField.ARP_THA).getLong()); |
| 884 | builder.matchArpTha(mac); |
| 885 | break; |
BitOhenry | c1e5fcc | 2015-11-23 20:47:53 +0800 | [diff] [blame] | 886 | case ARP_TPA: |
| 887 | ip = Ip4Address.valueOf(match.get(MatchField.ARP_TPA).getInt()); |
| 888 | builder.matchArpTpa(ip); |
| 889 | break; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 890 | case MPLS_TC: |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 891 | default: |
| 892 | log.warn("Match type {} not yet implemented.", field.id); |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 893 | } |
| 894 | } |
| 895 | return builder.build(); |
| 896 | } |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 897 | |
Jonathan Hart | e4e74f0 | 2016-03-03 12:57:40 -0800 | [diff] [blame] | 898 | private DriverHandler getDriver(DeviceId deviceId) { |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 899 | Driver driver = driverService.getDriver(deviceId); |
| 900 | DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, deviceId)); |
| 901 | return handler; |
| 902 | } |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 903 | } |