blob: c16c34f344fb393238c96a8a4649395a7f979fd1 [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Thomas Vachuska781d18b2014-10-27 10:31:25 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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 Vachuska781d18b2014-10-27 10:31:25 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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 Vachuska781d18b2014-10-27 10:31:25 -070015 */
Thomas Vachuska95caba32016-04-04 10:42:05 -070016package org.onosproject.provider.of.flow.util;
alshabib6b5cfec2014-09-18 17:42:18 -070017
Jonathan Hart8cf212a2015-10-29 17:42:03 -070018import com.google.common.collect.Lists;
Cem Türker3baff672017-10-12 15:09:01 +030019import com.google.common.collect.Maps;
Ray Milkey84d5a292016-02-22 14:04:01 -080020import org.onlab.packet.EthType;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080021import org.onlab.packet.Ip4Address;
22import org.onlab.packet.Ip4Prefix;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080023import org.onlab.packet.Ip6Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080024import org.onlab.packet.Ip6Prefix;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080025import org.onlab.packet.MacAddress;
Michele Santuari4b6019e2014-12-19 11:31:45 +010026import org.onlab.packet.MplsLabel;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -070027import org.onlab.packet.TpPort;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080028import org.onlab.packet.VlanId;
Yi Tsengfa394de2017-02-01 11:26:40 -080029import org.onosproject.core.GroupId;
Brian O'Connorabafb502014-12-02 22:26:20 -080030import org.onosproject.net.DeviceId;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070031import org.onosproject.net.Lambda;
Yafit Hadar73514612015-11-04 10:14:21 +020032import org.onosproject.net.OduSignalId;
Brian O'Connorabafb502014-12-02 22:26:20 -080033import org.onosproject.net.PortNumber;
Jonathan Hart3c259162015-10-21 21:31:19 -070034import org.onosproject.net.driver.DefaultDriverData;
35import org.onosproject.net.driver.DefaultDriverHandler;
36import org.onosproject.net.driver.Driver;
37import org.onosproject.net.driver.DriverHandler;
38import org.onosproject.net.driver.DriverService;
Brian O'Connorabafb502014-12-02 22:26:20 -080039import org.onosproject.net.flow.DefaultFlowEntry;
40import org.onosproject.net.flow.DefaultFlowRule;
41import org.onosproject.net.flow.DefaultTrafficSelector;
42import org.onosproject.net.flow.DefaultTrafficTreatment;
43import org.onosproject.net.flow.FlowEntry;
44import org.onosproject.net.flow.FlowEntry.FlowEntryState;
45import org.onosproject.net.flow.FlowRule;
Cem Türker3baff672017-10-12 15:09:01 +030046import org.onosproject.net.flow.StatTriggerField;
47import org.onosproject.net.flow.StatTriggerFlag;
Brian O'Connorabafb502014-12-02 22:26:20 -080048import org.onosproject.net.flow.TrafficSelector;
49import org.onosproject.net.flow.TrafficTreatment;
Charles Chan14967c22015-12-07 11:11:50 -080050import org.onosproject.net.flow.criteria.ExtensionSelectorType.ExtensionSelectorTypes;
Sho SHIMIZU9553bb82015-06-30 16:02:45 -070051import org.onosproject.net.flow.instructions.Instructions;
Charles Chan14967c22015-12-07 11:11:50 -080052import org.onosproject.openflow.controller.ExtensionSelectorInterpreter;
alshabib880b6442015-11-23 22:13:04 -080053import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter;
Sangsik Yoonb1b823f2016-05-16 18:55:39 +090054import org.onosproject.provider.of.flow.impl.NewAdaptiveFlowStatsCollector;
Cem Türker3baff672017-10-12 15:09:01 +030055import org.projectfloodlight.openflow.protocol.OFFlowLightweightStatsEntry;
Brian O'Connor72cb19a2015-01-16 16:14:41 -080056import org.projectfloodlight.openflow.protocol.OFFlowMod;
alshabib6b5cfec2014-09-18 17:42:18 -070057import org.projectfloodlight.openflow.protocol.OFFlowRemoved;
58import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry;
Charles Chan14967c22015-12-07 11:11:50 -080059import org.projectfloodlight.openflow.protocol.OFMatchV3;
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -070060import org.projectfloodlight.openflow.protocol.OFObject;
Cem Türker3baff672017-10-12 15:09:01 +030061import org.projectfloodlight.openflow.protocol.OFOxsList;
62import org.projectfloodlight.openflow.protocol.OFStatTriggerFlags;
Brian O'Connor21564612015-12-05 19:24:59 -080063import org.projectfloodlight.openflow.protocol.OFVersion;
alshabib6b5cfec2014-09-18 17:42:18 -070064import org.projectfloodlight.openflow.protocol.action.OFAction;
Marc De Leenheer49087752014-10-23 13:54:09 -070065import org.projectfloodlight.openflow.protocol.action.OFActionCircuit;
Steffen Gebertba2d3b72015-10-22 11:14:31 +020066import org.projectfloodlight.openflow.protocol.action.OFActionEnqueue;
Marc De Leenheer49087752014-10-23 13:54:09 -070067import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter;
sangho8995ac52015-02-04 11:29:03 -080068import org.projectfloodlight.openflow.protocol.action.OFActionGroup;
alshabib6b5cfec2014-09-18 17:42:18 -070069import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
sangho3f97a17d2015-01-29 22:56:29 -080070import org.projectfloodlight.openflow.protocol.action.OFActionPopMpls;
Konstantinos Kanonakis9215ff22016-11-04 13:28:11 -050071import org.projectfloodlight.openflow.protocol.action.OFActionPushVlan;
alshabib6b5cfec2014-09-18 17:42:18 -070072import org.projectfloodlight.openflow.protocol.action.OFActionSetDlDst;
73import org.projectfloodlight.openflow.protocol.action.OFActionSetDlSrc;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080074import org.projectfloodlight.openflow.protocol.action.OFActionSetField;
alshabib6b5cfec2014-09-18 17:42:18 -070075import org.projectfloodlight.openflow.protocol.action.OFActionSetNwDst;
76import org.projectfloodlight.openflow.protocol.action.OFActionSetNwSrc;
Jonathan Hart8cf212a2015-10-29 17:42:03 -070077import org.projectfloodlight.openflow.protocol.action.OFActionSetQueue;
alshabib6b5cfec2014-09-18 17:42:18 -070078import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanPcp;
79import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanVid;
alshabib19fdc122014-10-03 11:38:19 -070080import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
Jonathan Hartcf783202014-11-24 18:55:42 -080081import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions;
alshabibbdcbb102015-04-22 14:16:38 -070082import org.projectfloodlight.openflow.protocol.instruction.OFInstructionGotoTable;
Cem Türker3baff672017-10-12 15:09:01 +030083import org.projectfloodlight.openflow.protocol.instruction.OFInstructionStatTrigger;
alshabib346b5b32015-03-06 00:42:16 -080084import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteActions;
Saurav Das86af8f12015-05-25 23:55:33 -070085import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteMetadata;
alshabib6b5cfec2014-09-18 17:42:18 -070086import org.projectfloodlight.openflow.protocol.match.Match;
87import org.projectfloodlight.openflow.protocol.match.MatchField;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080088import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
Yafit Hadar4cc65f72016-02-10 11:23:06 +020089import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigid;
Cem Türker3baff672017-10-12 15:09:01 +030090import org.projectfloodlight.openflow.protocol.oxs.OFOxs;
alshabib346b5b32015-03-06 00:42:16 -080091import org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070092import org.projectfloodlight.openflow.types.CircuitSignalID;
alshabib6b5cfec2014-09-18 17:42:18 -070093import org.projectfloodlight.openflow.types.IPv4Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080094import org.projectfloodlight.openflow.types.IPv6Address;
Jonathan Hart0e12fad2014-10-17 14:54:58 -070095import org.projectfloodlight.openflow.types.Masked;
Pier Ventre23f78672016-11-15 08:46:34 -080096import org.projectfloodlight.openflow.types.OFBooleanValue;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080097import org.projectfloodlight.openflow.types.OFVlanVidMatch;
Jonathan Harte4e74f02016-03-03 12:57:40 -080098import org.projectfloodlight.openflow.types.OduSignalID;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -070099import org.projectfloodlight.openflow.types.TransportPort;
sangho3f97a17d2015-01-29 22:56:29 -0800100import org.projectfloodlight.openflow.types.U32;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700101import org.projectfloodlight.openflow.types.U64;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700102import org.projectfloodlight.openflow.types.U8;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800103import org.projectfloodlight.openflow.types.VlanPcp;
alshabib6b5cfec2014-09-18 17:42:18 -0700104import org.slf4j.Logger;
Jian Lia0d9a172016-04-01 16:58:06 -0700105import org.slf4j.LoggerFactory;
alshabib6b5cfec2014-09-18 17:42:18 -0700106
Jonathan Hart8cf212a2015-10-29 17:42:03 -0700107import java.util.List;
Cem Türker3baff672017-10-12 15:09:01 +0300108import java.util.Map;
109import java.util.Set;
Jonathan Hart8cf212a2015-10-29 17:42:03 -0700110
Thiago Santos877914d2016-07-20 18:29:29 -0300111import static java.util.concurrent.TimeUnit.NANOSECONDS;
112import static java.util.concurrent.TimeUnit.SECONDS;
Cem Türker3baff672017-10-12 15:09:01 +0300113import static org.onosproject.net.flow.StatTriggerField.*;
114import static org.onosproject.net.flow.StatTriggerField.IDLE_TIME;
115import static org.onosproject.net.flow.StatTriggerFlag.ONLY_FIRST;
116import static org.onosproject.net.flow.StatTriggerFlag.PERIODIC;
alshabib44852fb2016-04-15 15:56:51 -0700117import static org.onosproject.net.flow.criteria.Criteria.*;
Yafit Hadar73514612015-11-04 10:14:21 +0200118import static org.onosproject.net.flow.instructions.Instructions.modL0Lambda;
119import static org.onosproject.net.flow.instructions.Instructions.modL1OduSignalId;
alshabib44852fb2016-04-15 15:56:51 -0700120import static org.onosproject.provider.of.flow.util.OpenFlowValueMapper.*;
alshabib19fdc122014-10-03 11:38:19 -0700121
alshabib1c319ff2014-10-04 20:29:09 -0700122public class FlowEntryBuilder {
Jian Lia0d9a172016-04-01 16:58:06 -0700123 private static final Logger log = LoggerFactory.getLogger(FlowEntryBuilder.class);
alshabib6b5cfec2014-09-18 17:42:18 -0700124
125 private final OFFlowStatsEntry stat;
126 private final OFFlowRemoved removed;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800127 private final OFFlowMod flowMod;
Cem Türker3baff672017-10-12 15:09:01 +0300128 private final OFFlowLightweightStatsEntry lightWeightStat;
alshabib6b5cfec2014-09-18 17:42:18 -0700129
130 private final Match match;
alshabib346b5b32015-03-06 00:42:16 -0800131
Jonathan Hart67fc0972015-03-19 15:21:20 -0700132 // All actions are contained in an OFInstruction. For OF1.0
133 // the instruction type is apply instruction (immediate set in ONOS speak)
alshabib346b5b32015-03-06 00:42:16 -0800134 private final List<OFInstruction> instructions;
alshabib6b5cfec2014-09-18 17:42:18 -0700135
Jonathan Harte4e74f02016-03-03 12:57:40 -0800136 private final DeviceId deviceId;
alshabib6b5cfec2014-09-18 17:42:18 -0700137
Cem Türker3baff672017-10-12 15:09:01 +0300138 public enum FlowType { STAT, LIGHTWEIGHT_STAT, REMOVED, MOD }
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800139
140 private final FlowType type;
alshabib6b5cfec2014-09-18 17:42:18 -0700141
Jonathan Hart3c259162015-10-21 21:31:19 -0700142 private final DriverService driverService;
143
Sangsik Yoonb1b823f2016-05-16 18:55:39 +0900144 // NewAdaptiveFlowStatsCollector for AdaptiveFlowSampling mode,
145 // null is not AFM mode, namely SimpleStatsCollector mode
146 private NewAdaptiveFlowStatsCollector afsc;
147
Jonathan Harte4e74f02016-03-03 12:57:40 -0800148 public FlowEntryBuilder(DeviceId deviceId, OFFlowStatsEntry entry, DriverService driverService) {
Saurav Dasfa2fa932015-03-03 11:29:48 -0800149 this.stat = entry;
150 this.match = entry.getMatch();
alshabib346b5b32015-03-06 00:42:16 -0800151 this.instructions = getInstructions(entry);
Jonathan Harte4e74f02016-03-03 12:57:40 -0800152 this.deviceId = deviceId;
Saurav Dasfa2fa932015-03-03 11:29:48 -0800153 this.removed = null;
154 this.flowMod = null;
155 this.type = FlowType.STAT;
Jonathan Hart3c259162015-10-21 21:31:19 -0700156 this.driverService = driverService;
Sangsik Yoonb1b823f2016-05-16 18:55:39 +0900157 this.afsc = null;
Cem Türker3baff672017-10-12 15:09:01 +0300158 this.lightWeightStat = null;
159 }
160
161 public FlowEntryBuilder(DeviceId deviceId, OFFlowLightweightStatsEntry lightWeightStat,
162 DriverService driverService) {
163 this.stat = null;
164 this.match = lightWeightStat.getMatch();
165 this.instructions = null;
166 this.deviceId = deviceId;
167 this.removed = null;
168 this.flowMod = null;
169 this.type = FlowType.LIGHTWEIGHT_STAT;
170 this.driverService = driverService;
171 this.afsc = null;
172 this.lightWeightStat = lightWeightStat;
Saurav Dasfa2fa932015-03-03 11:29:48 -0800173 }
174
Jonathan Harte4e74f02016-03-03 12:57:40 -0800175 public FlowEntryBuilder(DeviceId deviceId, OFFlowRemoved removed, DriverService driverService) {
alshabib6b5cfec2014-09-18 17:42:18 -0700176 this.match = removed.getMatch();
177 this.removed = removed;
Jonathan Harte4e74f02016-03-03 12:57:40 -0800178 this.deviceId = deviceId;
alshabib346b5b32015-03-06 00:42:16 -0800179 this.instructions = null;
alshabib6b5cfec2014-09-18 17:42:18 -0700180 this.stat = null;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800181 this.flowMod = null;
182 this.type = FlowType.REMOVED;
Jonathan Hart3c259162015-10-21 21:31:19 -0700183 this.driverService = driverService;
Sangsik Yoonb1b823f2016-05-16 18:55:39 +0900184 this.afsc = null;
Cem Türker3baff672017-10-12 15:09:01 +0300185 this.lightWeightStat = null;
alshabib6b5cfec2014-09-18 17:42:18 -0700186 }
187
Jonathan Harte4e74f02016-03-03 12:57:40 -0800188 public FlowEntryBuilder(DeviceId deviceId, OFFlowMod fm, DriverService driverService) {
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800189 this.match = fm.getMatch();
Jonathan Harte4e74f02016-03-03 12:57:40 -0800190 this.deviceId = deviceId;
alshabib346b5b32015-03-06 00:42:16 -0800191 this.instructions = getInstructions(fm);
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800192 this.type = FlowType.MOD;
193 this.flowMod = fm;
194 this.stat = null;
195 this.removed = null;
Jonathan Hart3c259162015-10-21 21:31:19 -0700196 this.driverService = driverService;
Sangsik Yoonb1b823f2016-05-16 18:55:39 +0900197 this.afsc = null;
Cem Türker3baff672017-10-12 15:09:01 +0300198 this.lightWeightStat = null;
Sangsik Yoonb1b823f2016-05-16 18:55:39 +0900199 }
200
201 public FlowEntryBuilder withSetAfsc(NewAdaptiveFlowStatsCollector afsc) {
202 this.afsc = afsc;
203 return this;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800204 }
alshabib1c319ff2014-10-04 20:29:09 -0700205
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800206 public FlowEntry build(FlowEntryState... state) {
Brian O'Connor21564612015-12-05 19:24:59 -0800207 try {
208 switch (this.type) {
209 case STAT:
Cem Türker3baff672017-10-12 15:09:01 +0300210 return createFlowEntryFromStat();
211 case LIGHTWEIGHT_STAT:
212 return createFlowEntryFromLightweightStat();
Brian O'Connor21564612015-12-05 19:24:59 -0800213 case REMOVED:
Cem Türker3baff672017-10-12 15:09:01 +0300214 return createFlowEntryForFlowRemoved();
Brian O'Connor21564612015-12-05 19:24:59 -0800215 case MOD:
Cem Türker3baff672017-10-12 15:09:01 +0300216 return createFlowEntryForFlowMod(state);
Brian O'Connor21564612015-12-05 19:24:59 -0800217 default:
218 log.error("Unknown flow type : {}", this.type);
219 return null;
220 }
221 } catch (UnsupportedOperationException e) {
222 log.warn("Error building flow entry", e);
223 return null;
alshabib6b5cfec2014-09-18 17:42:18 -0700224 }
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800225
alshabib6b5cfec2014-09-18 17:42:18 -0700226 }
227
Cem Türker3baff672017-10-12 15:09:01 +0300228 private FlowEntry createFlowEntryFromStat() {
229
230 FlowRule.Builder builder = DefaultFlowRule.builder()
231 .forDevice(deviceId)
232 .withSelector(buildSelector())
233 .withTreatment(buildTreatment())
234 .withPriority(stat.getPriority())
235 .withIdleTimeout(stat.getIdleTimeout())
236 .withCookie(stat.getCookie().getValue());
237 if (stat.getVersion() != OFVersion.OF_10) {
238 builder.forTable(stat.getTableId().getValue());
239 }
240 if (stat.getVersion().getWireVersion() < OFVersion.OF_15.getWireVersion()) {
241 if (afsc != null) {
242 FlowEntry.FlowLiveType liveType = afsc.calFlowLiveType(stat.getDurationSec());
243 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
244 SECONDS.toNanos(stat.getDurationSec())
245 + stat.getDurationNsec(), NANOSECONDS,
246 liveType,
247 stat.getPacketCount().getValue(),
248 stat.getByteCount().getValue());
249 } else {
250 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
251 stat.getDurationSec(),
252 stat.getPacketCount().getValue(),
253 stat.getByteCount().getValue());
254 }
255 }
256 FlowStatParser statParser = new FlowStatParser(stat.getStats());
257 if (afsc != null && statParser.isDurationReceived()) {
258 FlowEntry.FlowLiveType liveType = afsc.calFlowLiveType(statParser.getDuration());
259 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
260 SECONDS.toNanos(statParser.getDuration())
261 + SECONDS.toNanos(statParser.getDuration()), NANOSECONDS,
262 liveType,
263 statParser.getPacketCount(),
264 statParser.getByteCount());
265 } else {
266 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
267 statParser.getDuration(),
268 statParser.getPacketCount(),
269 statParser.getByteCount());
270 }
271
272 }
273
274 private FlowEntry createFlowEntryForFlowMod(FlowEntryState ...state) {
275 FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED;
276 FlowRule.Builder builder = DefaultFlowRule.builder()
277 .forDevice(deviceId)
278 .withSelector(buildSelector())
279 .withTreatment(buildTreatment())
280 .withPriority(flowMod.getPriority())
281 .withIdleTimeout(flowMod.getIdleTimeout())
282 .withCookie(flowMod.getCookie().getValue());
283 if (flowMod.getVersion() != OFVersion.OF_10) {
284 builder.forTable(flowMod.getTableId().getValue());
285 }
286
287 if (afsc != null) {
288 FlowEntry.FlowLiveType liveType = FlowEntry.FlowLiveType.IMMEDIATE;
289 return new DefaultFlowEntry(builder.build(), flowState, 0, liveType, 0, 0);
290 } else {
291 return new DefaultFlowEntry(builder.build(), flowState, 0, 0, 0);
292 }
293 }
294
295 private FlowEntry createFlowEntryForFlowRemoved() {
296 FlowRule.Builder builder = DefaultFlowRule.builder()
297 .forDevice(deviceId)
298 .withSelector(buildSelector())
299 .withPriority(removed.getPriority())
300 .withIdleTimeout(removed.getIdleTimeout())
301 .withCookie(removed.getCookie().getValue())
302 .withReason(FlowRule.FlowRemoveReason.parseShort((short) removed.getReason().ordinal()));
303
304 if (removed.getVersion() != OFVersion.OF_10) {
305 builder.forTable(removed.getTableId().getValue());
306 }
307 if (removed.getVersion().getWireVersion() < OFVersion.OF_15.getWireVersion()) {
308 if (afsc != null) {
309 FlowEntry.FlowLiveType liveType = afsc.calFlowLiveType(removed.getDurationSec());
310 return new DefaultFlowEntry(builder.build(), FlowEntryState.REMOVED,
311 SECONDS.toNanos(removed.getDurationSec())
312 + removed.getDurationNsec(), NANOSECONDS,
313 liveType,
314 removed.getPacketCount().getValue(),
315 removed.getByteCount().getValue());
316 } else {
317 return new DefaultFlowEntry(builder.build(), FlowEntryState.REMOVED,
318 removed.getDurationSec(),
319 removed.getPacketCount().getValue(),
320 removed.getByteCount().getValue());
321 }
322 }
323 FlowStatParser statParser = new FlowStatParser(removed.getStats());
324 if (afsc != null && statParser.isDurationReceived()) {
325 FlowEntry.FlowLiveType liveType = afsc.calFlowLiveType(statParser.getDuration());
326 return new DefaultFlowEntry(builder.build(), FlowEntryState.REMOVED,
327 SECONDS.toNanos(statParser.getDuration())
328 + SECONDS.toNanos(statParser.getDuration()), NANOSECONDS,
329 liveType,
330 statParser.getPacketCount(),
331 statParser.getByteCount());
332 } else {
333 return new DefaultFlowEntry(builder.build(), FlowEntryState.REMOVED,
334 statParser.getDuration(),
335 statParser.getPacketCount(),
336 statParser.getByteCount());
337 }
338 }
339
340 private FlowEntry createFlowEntryFromLightweightStat() {
341 FlowRule.Builder builder = DefaultFlowRule.builder()
342 .forDevice(deviceId)
343 .withSelector(buildSelector())
344 .withPriority(lightWeightStat.getPriority())
345 .withIdleTimeout(0)
346 .withCookie(0);
347 FlowStatParser flowLightweightStatParser = new FlowStatParser(lightWeightStat.getStats());
348 builder.forTable(lightWeightStat.getTableId().getValue());
349 if (afsc != null && flowLightweightStatParser.isDurationReceived()) {
350 FlowEntry.FlowLiveType liveType = afsc.calFlowLiveType(flowLightweightStatParser.getDuration());
351 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
352 SECONDS.toNanos(flowLightweightStatParser.getDuration())
353 + flowLightweightStatParser.getDuration(), NANOSECONDS,
354 liveType,
355 flowLightweightStatParser.getPacketCount(),
356 flowLightweightStatParser.getByteCount());
357 } else {
358 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
359 flowLightweightStatParser.getDuration(),
360 flowLightweightStatParser.getPacketCount(),
361 flowLightweightStatParser.getByteCount());
362 }
363 }
364
alshabib346b5b32015-03-06 00:42:16 -0800365 private List<OFInstruction> getInstructions(OFFlowMod entry) {
alshabib19fdc122014-10-03 11:38:19 -0700366 switch (entry.getVersion()) {
367 case OF_10:
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700368 return Lists.newArrayList(OFFactoryVer13.INSTANCE.instructions()
369 .applyActions(
370 entry.getActions()));
alshabib19fdc122014-10-03 11:38:19 -0700371 case OF_11:
372 case OF_12:
373 case OF_13:
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -0700374 case OF_14:
375 case OF_15:
alshabib346b5b32015-03-06 00:42:16 -0800376 return entry.getInstructions();
377 default:
378 log.warn("Unknown OF version {}", entry.getVersion());
379 }
380 return Lists.newLinkedList();
381 }
382
383 private List<OFInstruction> getInstructions(OFFlowStatsEntry entry) {
384 switch (entry.getVersion()) {
385 case OF_10:
386 return Lists.newArrayList(
387 OFFactoryVer13.INSTANCE.instructions().applyActions(entry.getActions()));
388 case OF_11:
389 case OF_12:
390 case OF_13:
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -0700391 case OF_14:
392 case OF_15:
alshabib346b5b32015-03-06 00:42:16 -0800393 return entry.getInstructions();
alshabib19fdc122014-10-03 11:38:19 -0700394 default:
395 log.warn("Unknown OF version {}", entry.getVersion());
396 }
397 return Lists.newLinkedList();
398 }
alshabib6b5cfec2014-09-18 17:42:18 -0700399
400 private TrafficTreatment buildTreatment() {
tom9a693fd2014-10-03 11:32:19 -0700401 TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
alshabib346b5b32015-03-06 00:42:16 -0800402 for (OFInstruction in : instructions) {
403 switch (in.getType()) {
404 case GOTO_TABLE:
alshabibbdcbb102015-04-22 14:16:38 -0700405 builder.transition(((int) ((OFInstructionGotoTable) in)
406 .getTableId().getValue()));
alshabib346b5b32015-03-06 00:42:16 -0800407 break;
408 case WRITE_METADATA:
Saurav Das86af8f12015-05-25 23:55:33 -0700409 OFInstructionWriteMetadata m = (OFInstructionWriteMetadata) in;
410 builder.writeMetadata(m.getMetadata().getValue(),
411 m.getMetadataMask().getValue());
alshabib346b5b32015-03-06 00:42:16 -0800412 break;
413 case WRITE_ACTIONS:
414 builder.deferred();
415 buildActions(((OFInstructionWriteActions) in).getActions(),
416 builder);
417 break;
418 case APPLY_ACTIONS:
419 builder.immediate();
420 buildActions(((OFInstructionApplyActions) in).getActions(),
421 builder);
422 break;
423 case CLEAR_ACTIONS:
424 builder.wipeDeferred();
425 break;
Cem Türker3baff672017-10-12 15:09:01 +0300426 case STAT_TRIGGER:
427 OFInstructionStatTrigger statTrigger = (OFInstructionStatTrigger) in;
428 buildStatTrigger(statTrigger.getThresholds(), statTrigger.getFlags(), builder);
429 break;
alshabib346b5b32015-03-06 00:42:16 -0800430 case EXPERIMENTER:
431 break;
432 case METER:
433 break;
434 default:
435 log.warn("Unknown instructions type {}", in.getType());
alshabib6b5cfec2014-09-18 17:42:18 -0700436 }
437 }
438
439 return builder.build();
440 }
441
Cem Türker3baff672017-10-12 15:09:01 +0300442 private TrafficTreatment.Builder buildStatTrigger(OFOxsList oxsList,
443 Set<OFStatTriggerFlags> flagsSet,
444 TrafficTreatment.Builder builder) {
445 Map<StatTriggerField, Long> statTriggerMap = Maps.newEnumMap(StatTriggerField.class);
446 for (OFOxs<?> ofOxs : oxsList) {
447 switch (ofOxs.getStatField().id) {
448 case DURATION:
449 U64 durationType = (U64) ofOxs.getValue();
450 statTriggerMap.put(DURATION, durationType.getValue());
451 break;
452 case FLOW_COUNT:
453 U32 flowCount = (U32) ofOxs.getValue();
454 statTriggerMap.put(FLOW_COUNT, flowCount.getValue());
455 break;
456 case PACKET_COUNT:
457 U64 packetCount = (U64) ofOxs.getValue();
458 statTriggerMap.put(PACKET_COUNT, packetCount.getValue());
459 break;
460 case BYTE_COUNT:
461 U64 byteCount = (U64) ofOxs.getValue();
462 statTriggerMap.put(BYTE_COUNT, byteCount.getValue());
463 break;
464 case IDLE_TIME:
465 U64 idleTime = (U64) ofOxs.getValue();
466 statTriggerMap.put(IDLE_TIME, idleTime.getValue());
467 break;
468 default:
469 log.warn("getStatField not supported {}", ofOxs.getStatField().id);
470 break;
471 }
472 }
473 StatTriggerFlag flag = null;
474 for (OFStatTriggerFlags flags : flagsSet) {
475 switch (flags) {
476 case PERIODIC:
477 flag = PERIODIC;
478 break;
479 case ONLY_FIRST:
480 flag = ONLY_FIRST;
481 break;
482 default:
483 log.warn("flag not supported {}", flags);
484 break;
485 }
486 }
487 if (!statTriggerMap.isEmpty() && flag != null) {
488 builder.add(Instructions.statTrigger(statTriggerMap, flag));
489 }
490 return builder;
491 }
492
Jian Lia0d9a172016-04-01 16:58:06 -0700493 /**
494 * Configures traffic treatment builder with a given collection of actions.
495 *
496 * @param actions a set of OpenFlow actions
497 * @param builder traffic treatment builder
498 * @param driverHandler driver handler
499 * @param deviceId device identifier
500 * @return configured traffic treatment builder
501 */
502 public static TrafficTreatment.Builder configureTreatmentBuilder(List<OFAction> actions,
503 TrafficTreatment.Builder builder,
504 DriverHandler driverHandler,
505 DeviceId deviceId) {
506 ExtensionTreatmentInterpreter interpreter;
Charles Chan14967c22015-12-07 11:11:50 -0800507 if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
Jian Lia0d9a172016-04-01 16:58:06 -0700508 interpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class);
Charles Chan14967c22015-12-07 11:11:50 -0800509 } else {
Jian Lia0d9a172016-04-01 16:58:06 -0700510 interpreter = null;
Charles Chan14967c22015-12-07 11:11:50 -0800511 }
512
alshabib346b5b32015-03-06 00:42:16 -0800513 for (OFAction act : actions) {
514 switch (act.getType()) {
515 case OUTPUT:
516 OFActionOutput out = (OFActionOutput) act;
517 builder.setOutput(
518 PortNumber.portNumber(out.getPort().getPortNumber()));
519 break;
520 case SET_VLAN_VID:
521 OFActionSetVlanVid vlan = (OFActionSetVlanVid) act;
522 builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan()));
523 break;
524 case SET_VLAN_PCP:
525 OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act;
526 builder.setVlanPcp(pcp.getVlanPcp().getValue());
527 break;
528 case SET_DL_DST:
529 OFActionSetDlDst dldst = (OFActionSetDlDst) act;
530 builder.setEthDst(
531 MacAddress.valueOf(dldst.getDlAddr().getLong()));
532 break;
533 case SET_DL_SRC:
534 OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act;
535 builder.setEthSrc(
536 MacAddress.valueOf(dlsrc.getDlAddr().getLong()));
alshabib346b5b32015-03-06 00:42:16 -0800537 break;
538 case SET_NW_DST:
539 OFActionSetNwDst nwdst = (OFActionSetNwDst) act;
540 IPv4Address di = nwdst.getNwAddr();
541 builder.setIpDst(Ip4Address.valueOf(di.getInt()));
542 break;
543 case SET_NW_SRC:
544 OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act;
545 IPv4Address si = nwsrc.getNwAddr();
546 builder.setIpSrc(Ip4Address.valueOf(si.getInt()));
547 break;
548 case EXPERIMENTER:
549 OFActionExperimenter exp = (OFActionExperimenter) act;
550 if (exp.getExperimenter() == 0x80005A06 ||
551 exp.getExperimenter() == 0x748771) {
552 OFActionCircuit ct = (OFActionCircuit) exp;
Yafit Hadar4cc65f72016-02-10 11:23:06 +0200553 CircuitSignalID circuitSignalID = ((OFOxmOchSigid) ct.getField()).getValue();
554 builder.add(Instructions.modL0Lambda(Lambda.ochSignal(
555 lookupGridType(circuitSignalID.getGridType()),
556 lookupChannelSpacing(circuitSignalID.getChannelSpacing()),
557 circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth())));
Jian Lia0d9a172016-04-01 16:58:06 -0700558 } else if (interpreter != null) {
559 builder.extension(interpreter.mapAction(exp), deviceId);
alshabib346b5b32015-03-06 00:42:16 -0800560 } else {
561 log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter());
562 }
563 break;
564 case SET_FIELD:
565 OFActionSetField setField = (OFActionSetField) act;
Jian Lia0d9a172016-04-01 16:58:06 -0700566 handleSetField(builder, setField, driverHandler, deviceId);
alshabib346b5b32015-03-06 00:42:16 -0800567 break;
568 case POP_MPLS:
569 OFActionPopMpls popMpls = (OFActionPopMpls) act;
Ray Milkey84d5a292016-02-22 14:04:01 -0800570 builder.popMpls(new EthType(popMpls.getEthertype().getValue()));
alshabib346b5b32015-03-06 00:42:16 -0800571 break;
572 case PUSH_MPLS:
573 builder.pushMpls();
574 break;
575 case COPY_TTL_IN:
576 builder.copyTtlIn();
577 break;
578 case COPY_TTL_OUT:
579 builder.copyTtlOut();
580 break;
581 case DEC_MPLS_TTL:
582 builder.decMplsTtl();
583 break;
584 case DEC_NW_TTL:
585 builder.decNwTtl();
586 break;
587 case GROUP:
588 OFActionGroup group = (OFActionGroup) act;
Yi Tsengfa394de2017-02-01 11:26:40 -0800589 builder.group(new GroupId(group.getGroup().getGroupNumber()));
alshabib346b5b32015-03-06 00:42:16 -0800590 break;
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200591 case SET_QUEUE:
592 OFActionSetQueue setQueue = (OFActionSetQueue) act;
593 builder.setQueue(setQueue.getQueueId());
594 break;
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200595 case ENQUEUE:
596 OFActionEnqueue enqueue = (OFActionEnqueue) act;
Jian Liffef5002016-04-04 23:27:37 -0700597 builder.setQueue(enqueue.getQueueId(),
598 PortNumber.portNumber(enqueue.getPort().getPortNumber()));
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200599 break;
Jonathan Hart67fc0972015-03-19 15:21:20 -0700600 case STRIP_VLAN:
alshabib346b5b32015-03-06 00:42:16 -0800601 case POP_VLAN:
602 builder.popVlan();
603 break;
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700604 case PUSH_VLAN:
Konstantinos Kanonakis9215ff22016-11-04 13:28:11 -0500605 OFActionPushVlan pushVlan = (OFActionPushVlan) act;
606 builder.pushVlan(new EthType((short) pushVlan.getEthertype().getValue()));
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700607 break;
alshabib346b5b32015-03-06 00:42:16 -0800608 case SET_TP_DST:
609 case SET_TP_SRC:
610 case POP_PBB:
611 case PUSH_PBB:
alshabib346b5b32015-03-06 00:42:16 -0800612 case SET_MPLS_LABEL:
613 case SET_MPLS_TC:
614 case SET_MPLS_TTL:
615 case SET_NW_ECN:
616 case SET_NW_TOS:
617 case SET_NW_TTL:
alshabib346b5b32015-03-06 00:42:16 -0800618
alshabib346b5b32015-03-06 00:42:16 -0800619 default:
620 log.warn("Action type {} not yet implemented.", act.getType());
621 }
622 }
623 return builder;
624 }
625
Jian Lia0d9a172016-04-01 16:58:06 -0700626 private TrafficTreatment.Builder buildActions(List<OFAction> actions,
627 TrafficTreatment.Builder builder) {
Jonathan Harte4e74f02016-03-03 12:57:40 -0800628 DriverHandler driverHandler = getDriver(deviceId);
Jian Lia0d9a172016-04-01 16:58:06 -0700629
630 return configureTreatmentBuilder(actions, builder, driverHandler, deviceId);
631 }
632
Charles Chancad338a2016-09-16 18:03:11 -0700633 // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES
Jian Lia0d9a172016-04-01 16:58:06 -0700634 private static void handleSetField(TrafficTreatment.Builder builder,
635 OFActionSetField action,
636 DriverHandler driverHandler,
637 DeviceId deviceId) {
Charles Chan14967c22015-12-07 11:11:50 -0800638 ExtensionTreatmentInterpreter treatmentInterpreter;
639 if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
640 treatmentInterpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class);
641 } else {
642 treatmentInterpreter = null;
643 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700644 OFOxm<?> oxm = action.getField();
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800645 switch (oxm.getMatchField().id) {
646 case VLAN_PCP:
647 @SuppressWarnings("unchecked")
648 OFOxm<VlanPcp> vlanpcp = (OFOxm<VlanPcp>) oxm;
649 builder.setVlanPcp(vlanpcp.getValue().getValue());
650 break;
651 case VLAN_VID:
Charles Chan4211baa2016-04-20 17:10:40 -0700652 if (treatmentInterpreter != null) {
653 try {
654 builder.extension(treatmentInterpreter.mapAction(action), deviceId);
655 break;
656 } catch (UnsupportedOperationException e) {
657 log.debug("Unsupported action extension; defaulting to native OF");
658 }
Charles Chan14967c22015-12-07 11:11:50 -0800659 }
alshabib44852fb2016-04-15 15:56:51 -0700660 @SuppressWarnings("unchecked")
661 OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm;
662 builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan()));
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800663 break;
664 case ETH_DST:
665 @SuppressWarnings("unchecked")
666 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethdst =
667 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
668 builder.setEthDst(MacAddress.valueOf(ethdst.getValue().getLong()));
669 break;
670 case ETH_SRC:
671 @SuppressWarnings("unchecked")
672 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethsrc =
673 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
674 builder.setEthSrc(MacAddress.valueOf(ethsrc.getValue().getLong()));
675 break;
676 case IPV4_DST:
677 @SuppressWarnings("unchecked")
678 OFOxm<IPv4Address> ip4dst = (OFOxm<IPv4Address>) oxm;
679 builder.setIpDst(Ip4Address.valueOf(ip4dst.getValue().getInt()));
680 break;
681 case IPV4_SRC:
682 @SuppressWarnings("unchecked")
683 OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm;
684 builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt()));
685 break;
sangho3f97a17d2015-01-29 22:56:29 -0800686 case MPLS_LABEL:
687 @SuppressWarnings("unchecked")
688 OFOxm<U32> labelId = (OFOxm<U32>) oxm;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100689 builder.setMpls(MplsLabel.mplsLabel((int) labelId.getValue().getValue()));
sangho3f97a17d2015-01-29 22:56:29 -0800690 break;
Saurav Das73a7dd42015-08-19 22:20:31 -0700691 case MPLS_BOS:
692 @SuppressWarnings("unchecked")
Pier Ventre23f78672016-11-15 08:46:34 -0800693 OFOxm<OFBooleanValue> mplsBos = (OFOxm<OFBooleanValue>) oxm;
694 builder.setMplsBos(mplsBos.getValue().getValue());
Saurav Das73a7dd42015-08-19 22:20:31 -0700695 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700696 case TUNNEL_ID:
697 @SuppressWarnings("unchecked")
698 OFOxm<U64> tunnelId = (OFOxm<U64>) oxm;
699 builder.setTunnelId(tunnelId.getValue().getValue());
700 break;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700701 case TCP_DST:
702 @SuppressWarnings("unchecked")
703 OFOxm<TransportPort> tcpdst = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700704 builder.setTcpDst(TpPort.tpPort(tcpdst.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700705 break;
706 case TCP_SRC:
707 @SuppressWarnings("unchecked")
708 OFOxm<TransportPort> tcpsrc = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700709 builder.setTcpSrc(TpPort.tpPort(tcpsrc.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700710 break;
711 case UDP_DST:
712 @SuppressWarnings("unchecked")
713 OFOxm<TransportPort> udpdst = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700714 builder.setUdpDst(TpPort.tpPort(udpdst.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700715 break;
716 case UDP_SRC:
717 @SuppressWarnings("unchecked")
718 OFOxm<TransportPort> udpsrc = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700719 builder.setUdpSrc(TpPort.tpPort(udpsrc.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700720 break;
Jonathan Hart3c259162015-10-21 21:31:19 -0700721 case TUNNEL_IPV4_DST:
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530722 case NSP:
723 case NSI:
724 case NSH_C1:
725 case NSH_C2:
726 case NSH_C3:
727 case NSH_C4:
728 case NSH_MDTYPE:
729 case NSH_NP:
730 case ENCAP_ETH_SRC:
731 case ENCAP_ETH_DST:
732 case ENCAP_ETH_TYPE:
733 case TUN_GPE_NP:
Jian Liffef5002016-04-04 23:27:37 -0700734 if (treatmentInterpreter != null) {
735 try {
736 builder.extension(treatmentInterpreter.mapAction(action), deviceId);
737 } catch (UnsupportedOperationException e) {
alshabib44852fb2016-04-15 15:56:51 -0700738 log.debug(e.getMessage());
Jian Liffef5002016-04-04 23:27:37 -0700739 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700740 }
741 break;
Yafit Hadar73514612015-11-04 10:14:21 +0200742 case EXP_ODU_SIG_ID:
743 @SuppressWarnings("unchecked")
744 OFOxm<OduSignalID> oduID = (OFOxm<OduSignalID>) oxm;
745 OduSignalID oduSignalID = oduID.getValue();
746 OduSignalId oduSignalId = OduSignalId.oduSignalId(oduSignalID.getTpn(),
747 oduSignalID.getTslen(),
748 oduSignalID.getTsmap());
749 builder.add(modL1OduSignalId(oduSignalId));
750 break;
751 case EXP_OCH_SIG_ID:
752 try {
753 @SuppressWarnings("unchecked")
754 OFOxm<CircuitSignalID> ochId = (OFOxm<CircuitSignalID>) oxm;
755 CircuitSignalID circuitSignalID = ochId.getValue();
756 builder.add(modL0Lambda(Lambda.ochSignal(
757 lookupGridType(circuitSignalID.getGridType()),
758 lookupChannelSpacing(circuitSignalID.getChannelSpacing()),
759 circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth())));
760 } catch (NoMappingFoundException e) {
761 log.warn(e.getMessage());
762 break;
763 }
764 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800765 case ARP_OP:
lishuai67574ce2016-05-12 16:39:59 +0800766 @SuppressWarnings("unchecked")
767 OFOxm<org.projectfloodlight.openflow.types.ArpOpcode> arpop =
768 (OFOxm<org.projectfloodlight.openflow.types.ArpOpcode>) oxm;
769 builder.setArpOp((short) arpop.getValue().getOpcode());
770 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800771 case ARP_SHA:
lishuai67574ce2016-05-12 16:39:59 +0800772 @SuppressWarnings("unchecked")
773 OFOxm<org.projectfloodlight.openflow.types.MacAddress> arpsha =
774 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
775 builder.setArpSha(MacAddress.valueOf(arpsha.getValue().getLong()));
776 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800777 case ARP_SPA:
lishuai67574ce2016-05-12 16:39:59 +0800778 @SuppressWarnings("unchecked")
779 OFOxm<IPv4Address> arpspa = (OFOxm<IPv4Address>) oxm;
780 builder.setArpSpa(Ip4Address.valueOf(arpspa.getValue().getInt()));
781 break;
Charles Chancad338a2016-09-16 18:03:11 -0700782 case OFDPA_MPLS_TYPE:
Pier Ventre6f630052016-10-18 09:58:41 -0700783 case OFDPA_OVID:
Pier Ventre9cf536b2016-10-21 13:30:18 -0700784 case OFDPA_MPLS_L2_PORT:
Pier Ventredb252cc2016-10-21 21:54:26 -0700785 case OFDPA_QOS_INDEX:
Charles Chancad338a2016-09-16 18:03:11 -0700786 if (treatmentInterpreter != null) {
787 try {
788 builder.extension(treatmentInterpreter.mapAction(action), deviceId);
789 break;
790 } catch (UnsupportedOperationException e) {
791 log.warn("Unsupported action extension");
792 }
793 }
794 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800795 case ARP_THA:
796 case ARP_TPA:
797 case BSN_EGR_PORT_GROUP_ID:
798 case BSN_GLOBAL_VRF_ALLOWED:
799 case BSN_IN_PORTS_128:
800 case BSN_L3_DST_CLASS_ID:
801 case BSN_L3_INTERFACE_CLASS_ID:
802 case BSN_L3_SRC_CLASS_ID:
803 case BSN_LAG_ID:
804 case BSN_TCP_FLAGS:
805 case BSN_UDF0:
806 case BSN_UDF1:
807 case BSN_UDF2:
808 case BSN_UDF3:
809 case BSN_UDF4:
810 case BSN_UDF5:
811 case BSN_UDF6:
812 case BSN_UDF7:
813 case BSN_VLAN_XLATE_PORT_GROUP_ID:
814 case BSN_VRF:
815 case ETH_TYPE:
816 case ICMPV4_CODE:
817 case ICMPV4_TYPE:
818 case ICMPV6_CODE:
819 case ICMPV6_TYPE:
820 case IN_PHY_PORT:
821 case IN_PORT:
822 case IPV6_DST:
823 case IPV6_FLABEL:
824 case IPV6_ND_SLL:
825 case IPV6_ND_TARGET:
826 case IPV6_ND_TLL:
827 case IPV6_SRC:
828 case IP_DSCP:
829 case IP_ECN:
830 case IP_PROTO:
831 case METADATA:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800832 case MPLS_TC:
833 case OCH_SIGID:
834 case OCH_SIGID_BASIC:
835 case OCH_SIGTYPE:
836 case OCH_SIGTYPE_BASIC:
837 case SCTP_DST:
838 case SCTP_SRC:
Yafit Hadar73514612015-11-04 10:14:21 +0200839 case EXP_ODU_SIGTYPE:
840 case EXP_OCH_SIGTYPE:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800841 default:
842 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
843 break;
844 }
845 }
846
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700847 // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES
alshabib6b5cfec2014-09-18 17:42:18 -0700848 private TrafficSelector buildSelector() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800849 MacAddress mac;
850 Ip4Prefix ip4Prefix;
851 Ip6Address ip6Address;
852 Ip6Prefix ip6Prefix;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800853 Ip4Address ip;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800854
Jonathan Harte4e74f02016-03-03 12:57:40 -0800855 DriverHandler driverHandler = getDriver(deviceId);
Charles Chan14967c22015-12-07 11:11:50 -0800856 ExtensionSelectorInterpreter selectorInterpreter;
857 if (driverHandler.hasBehaviour(ExtensionSelectorInterpreter.class)) {
858 selectorInterpreter = driverHandler.behaviour(ExtensionSelectorInterpreter.class);
859 } else {
860 selectorInterpreter = null;
861 }
862
tom9a693fd2014-10-03 11:32:19 -0700863 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700864 for (MatchField<?> field : match.getMatchFields()) {
865 switch (field.id) {
866 case IN_PORT:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800867 builder.matchInPort(PortNumber
alshabib010c31d2014-09-26 10:01:12 -0700868 .portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700869 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800870 case IN_PHY_PORT:
871 builder.matchInPhyPort(PortNumber
872 .portNumber(match.get(MatchField.IN_PHY_PORT).getPortNumber()));
873 break;
874 case METADATA:
875 long metadata =
876 match.get(MatchField.METADATA).getValue().getValue();
877 builder.matchMetadata(metadata);
878 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700879 case ETH_DST:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800880 if (match.isPartiallyMasked(MatchField.ETH_DST)) {
881 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
882 match.getMasked(MatchField.ETH_DST);
883 builder.matchEthDstMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
884 MacAddress.valueOf(maskedMac.getMask().getLong()));
885 } else {
886 mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
887 builder.matchEthDst(mac);
888 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800889 break;
890 case ETH_SRC:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800891 if (match.isPartiallyMasked(MatchField.ETH_SRC)) {
892 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
893 match.getMasked(MatchField.ETH_SRC);
894 builder.matchEthSrcMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
895 MacAddress.valueOf(maskedMac.getMask().getLong()));
896 } else {
897 mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
898 builder.matchEthSrc(mac);
899 }
alshabib6b5cfec2014-09-18 17:42:18 -0700900 break;
901 case ETH_TYPE:
902 int ethType = match.get(MatchField.ETH_TYPE).getValue();
Jonathan Hart8cf212a2015-10-29 17:42:03 -0700903 builder.matchEthType((short) ethType);
alshabib6b5cfec2014-09-18 17:42:18 -0700904 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700905 case VLAN_VID:
Charles Chan14967c22015-12-07 11:11:50 -0800906 if (selectorInterpreter != null &&
907 selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -0700908 if (isOF13OrLater(match)) {
Charles Chan14967c22015-12-07 11:11:50 -0800909 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.VLAN_VID);
910 builder.extension(selectorInterpreter.mapOxm(oxm),
Jonathan Harte4e74f02016-03-03 12:57:40 -0800911 deviceId);
Charles Chan14967c22015-12-07 11:11:50 -0800912 } else {
913 break;
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800914 }
915 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800916 VlanId vlanId = null;
917 if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
918 Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
919 if (masked.getValue().equals(OFVlanVidMatch.PRESENT)
920 && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
921 vlanId = VlanId.ANY;
922 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700923 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800924 if (!match.get(MatchField.VLAN_VID).isPresentBitSet()) {
925 vlanId = VlanId.NONE;
926 } else {
927 vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
928 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700929 }
Charles Chan14967c22015-12-07 11:11:50 -0800930 if (vlanId != null) {
931 builder.matchVlanId(vlanId);
932 }
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800933 }
alshabib6b5cfec2014-09-18 17:42:18 -0700934 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800935 case VLAN_PCP:
936 byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
937 builder.matchVlanPcp(vlanPcp);
938 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800939 case IP_DSCP:
940 byte ipDscp = match.get(MatchField.IP_DSCP).getDscpValue();
941 builder.matchIPDscp(ipDscp);
942 break;
943 case IP_ECN:
944 byte ipEcn = match.get(MatchField.IP_ECN).getEcnValue();
945 builder.matchIPEcn(ipEcn);
946 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800947 case IP_PROTO:
948 short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
949 builder.matchIPProtocol((byte) proto);
950 break;
951 case IPV4_SRC:
952 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
953 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800954 ip4Prefix = Ip4Prefix.valueOf(
955 maskedIp.getValue().getInt(),
956 maskedIp.getMask().asCidrMaskLength());
957 } else {
958 ip4Prefix = Ip4Prefix.valueOf(
959 match.get(MatchField.IPV4_SRC).getInt(),
960 Ip4Prefix.MAX_MASK_LENGTH);
961 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800962 builder.matchIPSrc(ip4Prefix);
963 break;
964 case IPV4_DST:
965 if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
966 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800967 ip4Prefix = Ip4Prefix.valueOf(
968 maskedIp.getValue().getInt(),
969 maskedIp.getMask().asCidrMaskLength());
970 } else {
971 ip4Prefix = Ip4Prefix.valueOf(
972 match.get(MatchField.IPV4_DST).getInt(),
973 Ip4Prefix.MAX_MASK_LENGTH);
974 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800975 builder.matchIPDst(ip4Prefix);
Jonathan Hart34bc6142014-10-17 11:00:43 -0700976 break;
977 case TCP_SRC:
Andreas Gilbert75b882f72017-02-03 09:58:07 +0100978 if (match.isPartiallyMasked(MatchField.TCP_SRC)) {
979 Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort =
980 match.getMasked(MatchField.TCP_SRC);
981 builder.matchTcpSrcMasked(TpPort.tpPort(maskedPort.getValue().getPort()),
982 TpPort.tpPort(maskedPort.getMask().getPort()));
983 } else {
984 builder.matchTcpSrc(TpPort.tpPort(match.get(MatchField.TCP_SRC).getPort()));
985 }
Jonathan Hart34bc6142014-10-17 11:00:43 -0700986 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800987 case TCP_DST:
Andreas Gilbert75b882f72017-02-03 09:58:07 +0100988 if (match.isPartiallyMasked(MatchField.TCP_DST)) {
989 Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort =
990 match.getMasked(MatchField.TCP_DST);
991 builder.matchTcpDstMasked(TpPort.tpPort(maskedPort.getValue().getPort()),
992 TpPort.tpPort(maskedPort.getMask().getPort()));
993 } else {
994 builder.matchTcpDst(TpPort.tpPort(match.get(MatchField.TCP_DST).getPort()));
995 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800996 break;
997 case UDP_SRC:
Andreas Gilbert75b882f72017-02-03 09:58:07 +0100998 if (match.isPartiallyMasked(MatchField.UDP_SRC)) {
999 Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort =
1000 match.getMasked(MatchField.UDP_SRC);
1001 builder.matchUdpSrcMasked(TpPort.tpPort(maskedPort.getValue().getPort()),
1002 TpPort.tpPort(maskedPort.getMask().getPort()));
1003 } else {
1004 builder.matchUdpSrc(TpPort.tpPort(match.get(MatchField.UDP_SRC).getPort()));
1005 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001006 break;
1007 case UDP_DST:
Andreas Gilbert75b882f72017-02-03 09:58:07 +01001008 if (match.isPartiallyMasked(MatchField.UDP_DST)) {
1009 Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort =
1010 match.getMasked(MatchField.UDP_DST);
1011 builder.matchUdpDstMasked(TpPort.tpPort(maskedPort.getValue().getPort()),
1012 TpPort.tpPort(maskedPort.getMask().getPort()));
1013 } else {
1014 builder.matchUdpDst(TpPort.tpPort(match.get(MatchField.UDP_DST).getPort()));
1015 }
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -07001016 break;
Michele Santuari4b6019e2014-12-19 11:31:45 +01001017 case MPLS_LABEL:
1018 builder.matchMplsLabel(MplsLabel.mplsLabel((int) match.get(MatchField.MPLS_LABEL)
1019 .getValue()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001020 break;
Saurav Dasffc5bbc2015-08-18 23:30:19 -07001021 case MPLS_BOS:
1022 builder.matchMplsBos(match.get(MatchField.MPLS_BOS).getValue());
1023 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001024 case SCTP_SRC:
Andreas Gilbert75b882f72017-02-03 09:58:07 +01001025 if (match.isPartiallyMasked(MatchField.SCTP_SRC)) {
1026 Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort =
1027 match.getMasked(MatchField.SCTP_SRC);
1028 builder.matchSctpSrcMasked(TpPort.tpPort(maskedPort.getValue().getPort()),
1029 TpPort.tpPort(maskedPort.getMask().getPort()));
1030 } else {
1031 builder.matchSctpSrc(TpPort.tpPort(match.get(MatchField.SCTP_SRC).getPort()));
1032 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001033 break;
1034 case SCTP_DST:
Andreas Gilbert75b882f72017-02-03 09:58:07 +01001035 if (match.isPartiallyMasked(MatchField.SCTP_DST)) {
1036 Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort =
1037 match.getMasked(MatchField.SCTP_DST);
1038 builder.matchSctpDstMasked(TpPort.tpPort(maskedPort.getValue().getPort()),
1039 TpPort.tpPort(maskedPort.getMask().getPort()));
1040 } else {
1041 builder.matchSctpDst(TpPort.tpPort(match.get(MatchField.SCTP_DST).getPort()));
1042 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001043 break;
1044 case ICMPV4_TYPE:
1045 byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
1046 builder.matchIcmpType(icmpType);
1047 break;
1048 case ICMPV4_CODE:
1049 byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode();
1050 builder.matchIcmpCode(icmpCode);
1051 break;
1052 case IPV6_SRC:
1053 if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
1054 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
1055 ip6Prefix = Ip6Prefix.valueOf(
1056 maskedIp.getValue().getBytes(),
1057 maskedIp.getMask().asCidrMaskLength());
1058 } else {
1059 ip6Prefix = Ip6Prefix.valueOf(
1060 match.get(MatchField.IPV6_SRC).getBytes(),
1061 Ip6Prefix.MAX_MASK_LENGTH);
1062 }
1063 builder.matchIPv6Src(ip6Prefix);
1064 break;
1065 case IPV6_DST:
1066 if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
1067 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
1068 ip6Prefix = Ip6Prefix.valueOf(
1069 maskedIp.getValue().getBytes(),
1070 maskedIp.getMask().asCidrMaskLength());
1071 } else {
1072 ip6Prefix = Ip6Prefix.valueOf(
1073 match.get(MatchField.IPV6_DST).getBytes(),
1074 Ip6Prefix.MAX_MASK_LENGTH);
1075 }
1076 builder.matchIPv6Dst(ip6Prefix);
1077 break;
1078 case IPV6_FLABEL:
1079 int flowLabel =
1080 match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue();
1081 builder.matchIPv6FlowLabel(flowLabel);
1082 break;
1083 case ICMPV6_TYPE:
1084 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
1085 builder.matchIcmpv6Type(icmpv6type);
1086 break;
1087 case ICMPV6_CODE:
1088 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
1089 builder.matchIcmpv6Code(icmpv6code);
1090 break;
1091 case IPV6_ND_TARGET:
1092 ip6Address =
1093 Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes());
1094 builder.matchIPv6NDTargetAddress(ip6Address);
1095 break;
1096 case IPV6_ND_SLL:
1097 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong());
1098 builder.matchIPv6NDSourceLinkLayerAddress(mac);
1099 break;
1100 case IPV6_ND_TLL:
1101 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong());
1102 builder.matchIPv6NDTargetLinkLayerAddress(mac);
1103 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001104 case IPV6_EXTHDR:
Charles M.C. Chan2184de12015-04-26 02:24:53 +08001105 builder.matchIPv6ExthdrFlags((short) match.get(MatchField.IPV6_EXTHDR)
Hyunsun Moona08c5d02015-07-14 17:53:00 -07001106 .getValue());
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001107 break;
Marc De Leenheer49087752014-10-23 13:54:09 -07001108 case OCH_SIGID:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -07001109 CircuitSignalID sigId = match.get(MatchField.OCH_SIGID);
1110 builder.add(matchLambda(Lambda.ochSignal(
Sho SHIMIZUc17042d2015-05-28 12:07:23 -07001111 lookupGridType(sigId.getGridType()), lookupChannelSpacing(sigId.getChannelSpacing()),
Marc De Leenheer0b8b2ef2015-08-03 15:39:00 -07001112 sigId.getChannelNumber(), sigId.getSpectralWidth())
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -07001113 ));
Marc De Leenheer49087752014-10-23 13:54:09 -07001114 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -08001115 case OCH_SIGTYPE:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -07001116 U8 sigType = match.get(MatchField.OCH_SIGTYPE);
Sho SHIMIZUc17042d2015-05-28 12:07:23 -07001117 builder.add(matchOchSignalType(lookupOchSignalType((byte) sigType.getValue())));
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -08001118 break;
Yafit Hadar73514612015-11-04 10:14:21 +02001119 case EXP_OCH_SIG_ID:
1120 try {
1121 CircuitSignalID expSigId = match.get(MatchField.EXP_OCH_SIG_ID);
1122 builder.add(matchLambda(Lambda.ochSignal(
1123 lookupGridType(expSigId.getGridType()), lookupChannelSpacing(expSigId.getChannelSpacing()),
1124 expSigId.getChannelNumber(), expSigId.getSpectralWidth())));
1125 } catch (NoMappingFoundException e) {
1126 log.warn(e.getMessage());
1127 break;
1128 }
1129 break;
1130 case EXP_OCH_SIGTYPE:
1131 try {
1132 U8 expOchSigType = match.get(MatchField.EXP_OCH_SIGTYPE);
1133 builder.add(matchOchSignalType(lookupOchSignalType((byte) expOchSigType.getValue())));
1134 } catch (NoMappingFoundException e) {
1135 log.warn(e.getMessage());
1136 break;
1137 }
1138 break;
1139 case EXP_ODU_SIG_ID:
1140 OduSignalId oduSignalId = OduSignalId.oduSignalId(match.get(MatchField.EXP_ODU_SIG_ID).getTpn(),
1141 match.get(MatchField.EXP_ODU_SIG_ID).getTslen(),
1142 match.get(MatchField.EXP_ODU_SIG_ID).getTsmap());
1143 builder.add(matchOduSignalId(oduSignalId));
Frank Wang5733c382017-03-28 10:15:18 +08001144 break;
Yafit Hadar73514612015-11-04 10:14:21 +02001145 case EXP_ODU_SIGTYPE:
1146 try {
1147 U8 oduSigType = match.get(MatchField.EXP_ODU_SIGTYPE);
1148 builder.add(matchOduSignalType(lookupOduSignalType((byte) oduSigType.getValue())));
1149 } catch (NoMappingFoundException e) {
1150 log.warn(e.getMessage());
1151 break;
1152 }
1153 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -07001154 case TUNNEL_ID:
1155 long tunnelId = match.get(MatchField.TUNNEL_ID).getValue();
1156 builder.matchTunnelId(tunnelId);
1157 break;
BitOhenryb40129a2015-11-30 12:41:18 +08001158 case ARP_OP:
1159 int arpOp = match.get(MatchField.ARP_OP).getOpcode();
1160 builder.matchArpOp(arpOp);
1161 break;
BitOhenrya331b182015-11-23 08:39:37 +08001162 case ARP_SHA:
1163 mac = MacAddress.valueOf(match.get(MatchField.ARP_SHA).getLong());
1164 builder.matchArpSha(mac);
1165 break;
BitOhenry296b4542015-11-24 08:41:58 +08001166 case ARP_SPA:
1167 ip = Ip4Address.valueOf(match.get(MatchField.ARP_SPA).getInt());
1168 builder.matchArpSpa(ip);
1169 break;
BitOhenry76430852015-11-20 19:04:49 +08001170 case ARP_THA:
1171 mac = MacAddress.valueOf(match.get(MatchField.ARP_THA).getLong());
1172 builder.matchArpTha(mac);
1173 break;
BitOhenryc1e5fcc2015-11-23 20:47:53 +08001174 case ARP_TPA:
1175 ip = Ip4Address.valueOf(match.get(MatchField.ARP_TPA).getInt());
1176 builder.matchArpTpa(ip);
1177 break;
Phaneendra Manda8db7d092016-06-04 00:17:24 +05301178 case NSP:
1179 if (selectorInterpreter != null) {
1180 try {
1181 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.NSP);
1182 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
1183 } catch (UnsupportedOperationException e) {
1184 log.debug(e.getMessage());
1185 }
1186 }
1187 break;
1188 case NSI:
1189 if (selectorInterpreter != null) {
1190 try {
1191 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.NSI);
1192 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
1193 } catch (UnsupportedOperationException e) {
1194 log.debug(e.getMessage());
1195 }
1196 }
1197 break;
1198 case ENCAP_ETH_TYPE:
1199 if (selectorInterpreter != null) {
1200 try {
1201 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.ENCAP_ETH_TYPE);
1202 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
1203 } catch (UnsupportedOperationException e) {
1204 log.debug(e.getMessage());
1205 }
1206 }
1207 break;
Frank Wang5733c382017-03-28 10:15:18 +08001208 case CONNTRACK_STATE:
1209 if (selectorInterpreter != null &&
1210 selectorInterpreter.supported(ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_STATE.type())) {
1211 try {
1212 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.CONNTRACK_STATE);
1213 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
1214 } catch (UnsupportedOperationException e) {
1215 log.debug(e.getMessage());
1216 }
1217 }
1218 break;
1219 case CONNTRACK_ZONE:
1220 if (selectorInterpreter != null &&
1221 selectorInterpreter.supported(ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_ZONE.type())) {
1222 try {
1223 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.CONNTRACK_ZONE);
1224 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
1225 } catch (UnsupportedOperationException e) {
1226 log.debug(e.getMessage());
1227 }
1228 }
1229 break;
1230 case CONNTRACK_MARK:
1231 if (selectorInterpreter != null &&
1232 selectorInterpreter.supported(ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_MARK.type())) {
1233 try {
1234 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.CONNTRACK_MARK);
1235 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
1236 } catch (UnsupportedOperationException e) {
1237 log.debug(e.getMessage());
1238 }
1239 }
1240 break;
Pier Ventre6f630052016-10-18 09:58:41 -07001241 case OFDPA_OVID:
1242 if (selectorInterpreter != null &&
1243 selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_OVID.type())) {
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -07001244 if (isOF13OrLater(match)) {
Pier Ventre6f630052016-10-18 09:58:41 -07001245 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.OFDPA_OVID);
1246 builder.extension(selectorInterpreter.mapOxm(oxm),
1247 deviceId);
1248 } else {
1249 break;
1250 }
1251 }
1252 break;
Pier Ventre9cf536b2016-10-21 13:30:18 -07001253 case OFDPA_MPLS_L2_PORT:
1254 if (selectorInterpreter != null &&
1255 selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_MPLS_L2_PORT.type())) {
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -07001256 if (isOF13OrLater(match)) {
Pier Ventre9cf536b2016-10-21 13:30:18 -07001257 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.OFDPA_MPLS_L2_PORT);
1258 builder.extension(selectorInterpreter.mapOxm(oxm),
1259 deviceId);
1260 } else {
1261 break;
1262 }
1263 }
1264 break;
alshabib6b5cfec2014-09-18 17:42:18 -07001265 case MPLS_TC:
alshabib6b5cfec2014-09-18 17:42:18 -07001266 default:
1267 log.warn("Match type {} not yet implemented.", field.id);
alshabib6b5cfec2014-09-18 17:42:18 -07001268 }
1269 }
1270 return builder.build();
1271 }
Jonathan Hart3c259162015-10-21 21:31:19 -07001272
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -07001273 /**
1274 * @param obj OpenFlow object to test
1275 * @return true if OFObject is OF_13 or later
1276 */
1277 private static boolean isOF13OrLater(OFObject obj) {
1278 return obj.getVersion().wireVersion >= OFVersion.OF_13.wireVersion;
1279 }
1280
Claudine Chiu20cbd452017-08-30 19:23:11 -04001281 /**
1282 * Retrieves the driver handler for the specified device.
1283 *
1284 * @param deviceId device identifier
1285 * @return driver handler
1286 */
1287 protected DriverHandler getDriver(DeviceId deviceId) {
1288 Driver driver = driverService.getDriver(deviceId);
1289 DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, deviceId));
Jonathan Hart3c259162015-10-21 21:31:19 -07001290 return handler;
1291 }
alshabib6b5cfec2014-09-18 17:42:18 -07001292}