blob: dee94555dd3c8ffde178567aa9efd5859933c24d [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;
cansu.toprak409289d2017-10-27 10:04:05 +030052import org.onosproject.net.meter.MeterId;
Charles Chan14967c22015-12-07 11:11:50 -080053import org.onosproject.openflow.controller.ExtensionSelectorInterpreter;
alshabib880b6442015-11-23 22:13:04 -080054import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter;
Sangsik Yoonb1b823f2016-05-16 18:55:39 +090055import org.onosproject.provider.of.flow.impl.NewAdaptiveFlowStatsCollector;
Cem Türker3baff672017-10-12 15:09:01 +030056import org.projectfloodlight.openflow.protocol.OFFlowLightweightStatsEntry;
Brian O'Connor72cb19a2015-01-16 16:14:41 -080057import org.projectfloodlight.openflow.protocol.OFFlowMod;
alshabib6b5cfec2014-09-18 17:42:18 -070058import org.projectfloodlight.openflow.protocol.OFFlowRemoved;
59import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry;
Charles Chan14967c22015-12-07 11:11:50 -080060import org.projectfloodlight.openflow.protocol.OFMatchV3;
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -070061import org.projectfloodlight.openflow.protocol.OFObject;
Cem Türker3baff672017-10-12 15:09:01 +030062import org.projectfloodlight.openflow.protocol.OFOxsList;
63import org.projectfloodlight.openflow.protocol.OFStatTriggerFlags;
Brian O'Connor21564612015-12-05 19:24:59 -080064import org.projectfloodlight.openflow.protocol.OFVersion;
alshabib6b5cfec2014-09-18 17:42:18 -070065import org.projectfloodlight.openflow.protocol.action.OFAction;
Marc De Leenheer49087752014-10-23 13:54:09 -070066import org.projectfloodlight.openflow.protocol.action.OFActionCircuit;
Steffen Gebertba2d3b72015-10-22 11:14:31 +020067import org.projectfloodlight.openflow.protocol.action.OFActionEnqueue;
Marc De Leenheer49087752014-10-23 13:54:09 -070068import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter;
sangho8995ac52015-02-04 11:29:03 -080069import org.projectfloodlight.openflow.protocol.action.OFActionGroup;
cansu.toprak409289d2017-10-27 10:04:05 +030070import org.projectfloodlight.openflow.protocol.action.OFActionMeter;
alshabib6b5cfec2014-09-18 17:42:18 -070071import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
sangho3f97a17d2015-01-29 22:56:29 -080072import org.projectfloodlight.openflow.protocol.action.OFActionPopMpls;
Konstantinos Kanonakis9215ff22016-11-04 13:28:11 -050073import org.projectfloodlight.openflow.protocol.action.OFActionPushVlan;
alshabib6b5cfec2014-09-18 17:42:18 -070074import org.projectfloodlight.openflow.protocol.action.OFActionSetDlDst;
75import org.projectfloodlight.openflow.protocol.action.OFActionSetDlSrc;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080076import org.projectfloodlight.openflow.protocol.action.OFActionSetField;
alshabib6b5cfec2014-09-18 17:42:18 -070077import org.projectfloodlight.openflow.protocol.action.OFActionSetNwDst;
78import org.projectfloodlight.openflow.protocol.action.OFActionSetNwSrc;
Jonathan Hart8cf212a2015-10-29 17:42:03 -070079import org.projectfloodlight.openflow.protocol.action.OFActionSetQueue;
alshabib6b5cfec2014-09-18 17:42:18 -070080import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanPcp;
81import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanVid;
alshabib19fdc122014-10-03 11:38:19 -070082import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
Jonathan Hartcf783202014-11-24 18:55:42 -080083import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions;
alshabibbdcbb102015-04-22 14:16:38 -070084import org.projectfloodlight.openflow.protocol.instruction.OFInstructionGotoTable;
Cem Türker3baff672017-10-12 15:09:01 +030085import org.projectfloodlight.openflow.protocol.instruction.OFInstructionStatTrigger;
alshabib346b5b32015-03-06 00:42:16 -080086import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteActions;
Saurav Das86af8f12015-05-25 23:55:33 -070087import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteMetadata;
alshabib6b5cfec2014-09-18 17:42:18 -070088import org.projectfloodlight.openflow.protocol.match.Match;
89import org.projectfloodlight.openflow.protocol.match.MatchField;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080090import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
Yafit Hadar4cc65f72016-02-10 11:23:06 +020091import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigid;
Cem Türker3baff672017-10-12 15:09:01 +030092import org.projectfloodlight.openflow.protocol.oxs.OFOxs;
alshabib346b5b32015-03-06 00:42:16 -080093import org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070094import org.projectfloodlight.openflow.types.CircuitSignalID;
alshabib6b5cfec2014-09-18 17:42:18 -070095import org.projectfloodlight.openflow.types.IPv4Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080096import org.projectfloodlight.openflow.types.IPv6Address;
Jonathan Hart0e12fad2014-10-17 14:54:58 -070097import org.projectfloodlight.openflow.types.Masked;
Pier Ventre23f78672016-11-15 08:46:34 -080098import org.projectfloodlight.openflow.types.OFBooleanValue;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080099import org.projectfloodlight.openflow.types.OFVlanVidMatch;
Jonathan Harte4e74f02016-03-03 12:57:40 -0800100import org.projectfloodlight.openflow.types.OduSignalID;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700101import org.projectfloodlight.openflow.types.TransportPort;
sangho3f97a17d2015-01-29 22:56:29 -0800102import org.projectfloodlight.openflow.types.U32;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700103import org.projectfloodlight.openflow.types.U64;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700104import org.projectfloodlight.openflow.types.U8;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800105import org.projectfloodlight.openflow.types.VlanPcp;
alshabib6b5cfec2014-09-18 17:42:18 -0700106import org.slf4j.Logger;
Jian Lia0d9a172016-04-01 16:58:06 -0700107import org.slf4j.LoggerFactory;
alshabib6b5cfec2014-09-18 17:42:18 -0700108
Jonathan Hart8cf212a2015-10-29 17:42:03 -0700109import java.util.List;
Cem Türker3baff672017-10-12 15:09:01 +0300110import java.util.Map;
111import java.util.Set;
Jonathan Hart8cf212a2015-10-29 17:42:03 -0700112
Thiago Santos877914d2016-07-20 18:29:29 -0300113import static java.util.concurrent.TimeUnit.NANOSECONDS;
114import static java.util.concurrent.TimeUnit.SECONDS;
Cem Türker3baff672017-10-12 15:09:01 +0300115import static org.onosproject.net.flow.StatTriggerField.*;
116import static org.onosproject.net.flow.StatTriggerField.IDLE_TIME;
117import static org.onosproject.net.flow.StatTriggerFlag.ONLY_FIRST;
118import static org.onosproject.net.flow.StatTriggerFlag.PERIODIC;
alshabib44852fb2016-04-15 15:56:51 -0700119import static org.onosproject.net.flow.criteria.Criteria.*;
Yafit Hadar73514612015-11-04 10:14:21 +0200120import static org.onosproject.net.flow.instructions.Instructions.modL0Lambda;
121import static org.onosproject.net.flow.instructions.Instructions.modL1OduSignalId;
alshabib44852fb2016-04-15 15:56:51 -0700122import static org.onosproject.provider.of.flow.util.OpenFlowValueMapper.*;
alshabib19fdc122014-10-03 11:38:19 -0700123
alshabib1c319ff2014-10-04 20:29:09 -0700124public class FlowEntryBuilder {
Jian Lia0d9a172016-04-01 16:58:06 -0700125 private static final Logger log = LoggerFactory.getLogger(FlowEntryBuilder.class);
alshabib6b5cfec2014-09-18 17:42:18 -0700126
127 private final OFFlowStatsEntry stat;
128 private final OFFlowRemoved removed;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800129 private final OFFlowMod flowMod;
Cem Türker3baff672017-10-12 15:09:01 +0300130 private final OFFlowLightweightStatsEntry lightWeightStat;
alshabib6b5cfec2014-09-18 17:42:18 -0700131
132 private final Match match;
alshabib346b5b32015-03-06 00:42:16 -0800133
Jonathan Hart67fc0972015-03-19 15:21:20 -0700134 // All actions are contained in an OFInstruction. For OF1.0
135 // the instruction type is apply instruction (immediate set in ONOS speak)
alshabib346b5b32015-03-06 00:42:16 -0800136 private final List<OFInstruction> instructions;
alshabib6b5cfec2014-09-18 17:42:18 -0700137
Jonathan Harte4e74f02016-03-03 12:57:40 -0800138 private final DeviceId deviceId;
alshabib6b5cfec2014-09-18 17:42:18 -0700139
Cem Türker3baff672017-10-12 15:09:01 +0300140 public enum FlowType { STAT, LIGHTWEIGHT_STAT, REMOVED, MOD }
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800141
142 private final FlowType type;
alshabib6b5cfec2014-09-18 17:42:18 -0700143
Jonathan Hart3c259162015-10-21 21:31:19 -0700144 private final DriverService driverService;
145
Sangsik Yoonb1b823f2016-05-16 18:55:39 +0900146 // NewAdaptiveFlowStatsCollector for AdaptiveFlowSampling mode,
147 // null is not AFM mode, namely SimpleStatsCollector mode
148 private NewAdaptiveFlowStatsCollector afsc;
149
Jonathan Harte4e74f02016-03-03 12:57:40 -0800150 public FlowEntryBuilder(DeviceId deviceId, OFFlowStatsEntry entry, DriverService driverService) {
Saurav Dasfa2fa932015-03-03 11:29:48 -0800151 this.stat = entry;
152 this.match = entry.getMatch();
alshabib346b5b32015-03-06 00:42:16 -0800153 this.instructions = getInstructions(entry);
Jonathan Harte4e74f02016-03-03 12:57:40 -0800154 this.deviceId = deviceId;
Saurav Dasfa2fa932015-03-03 11:29:48 -0800155 this.removed = null;
156 this.flowMod = null;
157 this.type = FlowType.STAT;
Jonathan Hart3c259162015-10-21 21:31:19 -0700158 this.driverService = driverService;
Sangsik Yoonb1b823f2016-05-16 18:55:39 +0900159 this.afsc = null;
Cem Türker3baff672017-10-12 15:09:01 +0300160 this.lightWeightStat = null;
161 }
162
163 public FlowEntryBuilder(DeviceId deviceId, OFFlowLightweightStatsEntry lightWeightStat,
164 DriverService driverService) {
165 this.stat = null;
166 this.match = lightWeightStat.getMatch();
167 this.instructions = null;
168 this.deviceId = deviceId;
169 this.removed = null;
170 this.flowMod = null;
171 this.type = FlowType.LIGHTWEIGHT_STAT;
172 this.driverService = driverService;
173 this.afsc = null;
174 this.lightWeightStat = lightWeightStat;
Saurav Dasfa2fa932015-03-03 11:29:48 -0800175 }
176
Jonathan Harte4e74f02016-03-03 12:57:40 -0800177 public FlowEntryBuilder(DeviceId deviceId, OFFlowRemoved removed, DriverService driverService) {
alshabib6b5cfec2014-09-18 17:42:18 -0700178 this.match = removed.getMatch();
179 this.removed = removed;
Jonathan Harte4e74f02016-03-03 12:57:40 -0800180 this.deviceId = deviceId;
alshabib346b5b32015-03-06 00:42:16 -0800181 this.instructions = null;
alshabib6b5cfec2014-09-18 17:42:18 -0700182 this.stat = null;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800183 this.flowMod = null;
184 this.type = FlowType.REMOVED;
Jonathan Hart3c259162015-10-21 21:31:19 -0700185 this.driverService = driverService;
Sangsik Yoonb1b823f2016-05-16 18:55:39 +0900186 this.afsc = null;
Cem Türker3baff672017-10-12 15:09:01 +0300187 this.lightWeightStat = null;
alshabib6b5cfec2014-09-18 17:42:18 -0700188 }
189
Jonathan Harte4e74f02016-03-03 12:57:40 -0800190 public FlowEntryBuilder(DeviceId deviceId, OFFlowMod fm, DriverService driverService) {
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800191 this.match = fm.getMatch();
Jonathan Harte4e74f02016-03-03 12:57:40 -0800192 this.deviceId = deviceId;
alshabib346b5b32015-03-06 00:42:16 -0800193 this.instructions = getInstructions(fm);
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800194 this.type = FlowType.MOD;
195 this.flowMod = fm;
196 this.stat = null;
197 this.removed = null;
Jonathan Hart3c259162015-10-21 21:31:19 -0700198 this.driverService = driverService;
Sangsik Yoonb1b823f2016-05-16 18:55:39 +0900199 this.afsc = null;
Cem Türker3baff672017-10-12 15:09:01 +0300200 this.lightWeightStat = null;
Sangsik Yoonb1b823f2016-05-16 18:55:39 +0900201 }
202
203 public FlowEntryBuilder withSetAfsc(NewAdaptiveFlowStatsCollector afsc) {
204 this.afsc = afsc;
205 return this;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800206 }
alshabib1c319ff2014-10-04 20:29:09 -0700207
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800208 public FlowEntry build(FlowEntryState... state) {
Brian O'Connor21564612015-12-05 19:24:59 -0800209 try {
210 switch (this.type) {
211 case STAT:
Cem Türker3baff672017-10-12 15:09:01 +0300212 return createFlowEntryFromStat();
213 case LIGHTWEIGHT_STAT:
214 return createFlowEntryFromLightweightStat();
Brian O'Connor21564612015-12-05 19:24:59 -0800215 case REMOVED:
Cem Türker3baff672017-10-12 15:09:01 +0300216 return createFlowEntryForFlowRemoved();
Brian O'Connor21564612015-12-05 19:24:59 -0800217 case MOD:
Cem Türker3baff672017-10-12 15:09:01 +0300218 return createFlowEntryForFlowMod(state);
Brian O'Connor21564612015-12-05 19:24:59 -0800219 default:
220 log.error("Unknown flow type : {}", this.type);
221 return null;
222 }
223 } catch (UnsupportedOperationException e) {
224 log.warn("Error building flow entry", e);
225 return null;
alshabib6b5cfec2014-09-18 17:42:18 -0700226 }
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800227
alshabib6b5cfec2014-09-18 17:42:18 -0700228 }
229
Cem Türker3baff672017-10-12 15:09:01 +0300230 private FlowEntry createFlowEntryFromStat() {
231
232 FlowRule.Builder builder = DefaultFlowRule.builder()
233 .forDevice(deviceId)
234 .withSelector(buildSelector())
235 .withTreatment(buildTreatment())
236 .withPriority(stat.getPriority())
237 .withIdleTimeout(stat.getIdleTimeout())
238 .withCookie(stat.getCookie().getValue());
239 if (stat.getVersion() != OFVersion.OF_10) {
240 builder.forTable(stat.getTableId().getValue());
241 }
242 if (stat.getVersion().getWireVersion() < OFVersion.OF_15.getWireVersion()) {
243 if (afsc != null) {
244 FlowEntry.FlowLiveType liveType = afsc.calFlowLiveType(stat.getDurationSec());
245 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
246 SECONDS.toNanos(stat.getDurationSec())
247 + stat.getDurationNsec(), NANOSECONDS,
248 liveType,
249 stat.getPacketCount().getValue(),
250 stat.getByteCount().getValue());
251 } else {
252 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
253 stat.getDurationSec(),
254 stat.getPacketCount().getValue(),
255 stat.getByteCount().getValue());
256 }
257 }
258 FlowStatParser statParser = new FlowStatParser(stat.getStats());
259 if (afsc != null && statParser.isDurationReceived()) {
260 FlowEntry.FlowLiveType liveType = afsc.calFlowLiveType(statParser.getDuration());
261 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
262 SECONDS.toNanos(statParser.getDuration())
263 + SECONDS.toNanos(statParser.getDuration()), NANOSECONDS,
264 liveType,
265 statParser.getPacketCount(),
266 statParser.getByteCount());
267 } else {
268 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
269 statParser.getDuration(),
270 statParser.getPacketCount(),
271 statParser.getByteCount());
272 }
273
274 }
275
276 private FlowEntry createFlowEntryForFlowMod(FlowEntryState ...state) {
277 FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED;
278 FlowRule.Builder builder = DefaultFlowRule.builder()
279 .forDevice(deviceId)
280 .withSelector(buildSelector())
281 .withTreatment(buildTreatment())
282 .withPriority(flowMod.getPriority())
283 .withIdleTimeout(flowMod.getIdleTimeout())
284 .withCookie(flowMod.getCookie().getValue());
285 if (flowMod.getVersion() != OFVersion.OF_10) {
286 builder.forTable(flowMod.getTableId().getValue());
287 }
288
289 if (afsc != null) {
290 FlowEntry.FlowLiveType liveType = FlowEntry.FlowLiveType.IMMEDIATE;
291 return new DefaultFlowEntry(builder.build(), flowState, 0, liveType, 0, 0);
292 } else {
293 return new DefaultFlowEntry(builder.build(), flowState, 0, 0, 0);
294 }
295 }
296
297 private FlowEntry createFlowEntryForFlowRemoved() {
298 FlowRule.Builder builder = DefaultFlowRule.builder()
299 .forDevice(deviceId)
300 .withSelector(buildSelector())
301 .withPriority(removed.getPriority())
302 .withIdleTimeout(removed.getIdleTimeout())
303 .withCookie(removed.getCookie().getValue())
304 .withReason(FlowRule.FlowRemoveReason.parseShort((short) removed.getReason().ordinal()));
305
306 if (removed.getVersion() != OFVersion.OF_10) {
307 builder.forTable(removed.getTableId().getValue());
308 }
309 if (removed.getVersion().getWireVersion() < OFVersion.OF_15.getWireVersion()) {
310 if (afsc != null) {
311 FlowEntry.FlowLiveType liveType = afsc.calFlowLiveType(removed.getDurationSec());
312 return new DefaultFlowEntry(builder.build(), FlowEntryState.REMOVED,
313 SECONDS.toNanos(removed.getDurationSec())
314 + removed.getDurationNsec(), NANOSECONDS,
315 liveType,
316 removed.getPacketCount().getValue(),
317 removed.getByteCount().getValue());
318 } else {
319 return new DefaultFlowEntry(builder.build(), FlowEntryState.REMOVED,
320 removed.getDurationSec(),
321 removed.getPacketCount().getValue(),
322 removed.getByteCount().getValue());
323 }
324 }
325 FlowStatParser statParser = new FlowStatParser(removed.getStats());
326 if (afsc != null && statParser.isDurationReceived()) {
327 FlowEntry.FlowLiveType liveType = afsc.calFlowLiveType(statParser.getDuration());
328 return new DefaultFlowEntry(builder.build(), FlowEntryState.REMOVED,
329 SECONDS.toNanos(statParser.getDuration())
330 + SECONDS.toNanos(statParser.getDuration()), NANOSECONDS,
331 liveType,
332 statParser.getPacketCount(),
333 statParser.getByteCount());
334 } else {
335 return new DefaultFlowEntry(builder.build(), FlowEntryState.REMOVED,
336 statParser.getDuration(),
337 statParser.getPacketCount(),
338 statParser.getByteCount());
339 }
340 }
341
342 private FlowEntry createFlowEntryFromLightweightStat() {
343 FlowRule.Builder builder = DefaultFlowRule.builder()
344 .forDevice(deviceId)
345 .withSelector(buildSelector())
346 .withPriority(lightWeightStat.getPriority())
347 .withIdleTimeout(0)
348 .withCookie(0);
349 FlowStatParser flowLightweightStatParser = new FlowStatParser(lightWeightStat.getStats());
350 builder.forTable(lightWeightStat.getTableId().getValue());
351 if (afsc != null && flowLightweightStatParser.isDurationReceived()) {
352 FlowEntry.FlowLiveType liveType = afsc.calFlowLiveType(flowLightweightStatParser.getDuration());
353 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
354 SECONDS.toNanos(flowLightweightStatParser.getDuration())
355 + flowLightweightStatParser.getDuration(), NANOSECONDS,
356 liveType,
357 flowLightweightStatParser.getPacketCount(),
358 flowLightweightStatParser.getByteCount());
359 } else {
360 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
361 flowLightweightStatParser.getDuration(),
362 flowLightweightStatParser.getPacketCount(),
363 flowLightweightStatParser.getByteCount());
364 }
365 }
366
alshabib346b5b32015-03-06 00:42:16 -0800367 private List<OFInstruction> getInstructions(OFFlowMod entry) {
alshabib19fdc122014-10-03 11:38:19 -0700368 switch (entry.getVersion()) {
369 case OF_10:
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700370 return Lists.newArrayList(OFFactoryVer13.INSTANCE.instructions()
371 .applyActions(
372 entry.getActions()));
alshabib19fdc122014-10-03 11:38:19 -0700373 case OF_11:
374 case OF_12:
375 case OF_13:
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -0700376 case OF_14:
377 case OF_15:
alshabib346b5b32015-03-06 00:42:16 -0800378 return entry.getInstructions();
379 default:
380 log.warn("Unknown OF version {}", entry.getVersion());
381 }
382 return Lists.newLinkedList();
383 }
384
385 private List<OFInstruction> getInstructions(OFFlowStatsEntry entry) {
386 switch (entry.getVersion()) {
387 case OF_10:
388 return Lists.newArrayList(
389 OFFactoryVer13.INSTANCE.instructions().applyActions(entry.getActions()));
390 case OF_11:
391 case OF_12:
392 case OF_13:
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -0700393 case OF_14:
394 case OF_15:
alshabib346b5b32015-03-06 00:42:16 -0800395 return entry.getInstructions();
alshabib19fdc122014-10-03 11:38:19 -0700396 default:
397 log.warn("Unknown OF version {}", entry.getVersion());
398 }
399 return Lists.newLinkedList();
400 }
alshabib6b5cfec2014-09-18 17:42:18 -0700401
402 private TrafficTreatment buildTreatment() {
tom9a693fd2014-10-03 11:32:19 -0700403 TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
alshabib346b5b32015-03-06 00:42:16 -0800404 for (OFInstruction in : instructions) {
405 switch (in.getType()) {
406 case GOTO_TABLE:
alshabibbdcbb102015-04-22 14:16:38 -0700407 builder.transition(((int) ((OFInstructionGotoTable) in)
408 .getTableId().getValue()));
alshabib346b5b32015-03-06 00:42:16 -0800409 break;
410 case WRITE_METADATA:
Saurav Das86af8f12015-05-25 23:55:33 -0700411 OFInstructionWriteMetadata m = (OFInstructionWriteMetadata) in;
412 builder.writeMetadata(m.getMetadata().getValue(),
413 m.getMetadataMask().getValue());
alshabib346b5b32015-03-06 00:42:16 -0800414 break;
415 case WRITE_ACTIONS:
416 builder.deferred();
417 buildActions(((OFInstructionWriteActions) in).getActions(),
418 builder);
419 break;
420 case APPLY_ACTIONS:
421 builder.immediate();
422 buildActions(((OFInstructionApplyActions) in).getActions(),
423 builder);
424 break;
425 case CLEAR_ACTIONS:
426 builder.wipeDeferred();
427 break;
Cem Türker3baff672017-10-12 15:09:01 +0300428 case STAT_TRIGGER:
429 OFInstructionStatTrigger statTrigger = (OFInstructionStatTrigger) in;
430 buildStatTrigger(statTrigger.getThresholds(), statTrigger.getFlags(), builder);
431 break;
alshabib346b5b32015-03-06 00:42:16 -0800432 case EXPERIMENTER:
433 break;
434 case METER:
435 break;
436 default:
437 log.warn("Unknown instructions type {}", in.getType());
alshabib6b5cfec2014-09-18 17:42:18 -0700438 }
439 }
440
441 return builder.build();
442 }
443
Cem Türker3baff672017-10-12 15:09:01 +0300444 private TrafficTreatment.Builder buildStatTrigger(OFOxsList oxsList,
445 Set<OFStatTriggerFlags> flagsSet,
446 TrafficTreatment.Builder builder) {
447 Map<StatTriggerField, Long> statTriggerMap = Maps.newEnumMap(StatTriggerField.class);
448 for (OFOxs<?> ofOxs : oxsList) {
449 switch (ofOxs.getStatField().id) {
450 case DURATION:
451 U64 durationType = (U64) ofOxs.getValue();
452 statTriggerMap.put(DURATION, durationType.getValue());
453 break;
454 case FLOW_COUNT:
455 U32 flowCount = (U32) ofOxs.getValue();
456 statTriggerMap.put(FLOW_COUNT, flowCount.getValue());
457 break;
458 case PACKET_COUNT:
459 U64 packetCount = (U64) ofOxs.getValue();
460 statTriggerMap.put(PACKET_COUNT, packetCount.getValue());
461 break;
462 case BYTE_COUNT:
463 U64 byteCount = (U64) ofOxs.getValue();
464 statTriggerMap.put(BYTE_COUNT, byteCount.getValue());
465 break;
466 case IDLE_TIME:
467 U64 idleTime = (U64) ofOxs.getValue();
468 statTriggerMap.put(IDLE_TIME, idleTime.getValue());
469 break;
470 default:
471 log.warn("getStatField not supported {}", ofOxs.getStatField().id);
472 break;
473 }
474 }
475 StatTriggerFlag flag = null;
476 for (OFStatTriggerFlags flags : flagsSet) {
477 switch (flags) {
478 case PERIODIC:
479 flag = PERIODIC;
480 break;
481 case ONLY_FIRST:
482 flag = ONLY_FIRST;
483 break;
484 default:
485 log.warn("flag not supported {}", flags);
486 break;
487 }
488 }
489 if (!statTriggerMap.isEmpty() && flag != null) {
490 builder.add(Instructions.statTrigger(statTriggerMap, flag));
491 }
492 return builder;
493 }
494
Jian Lia0d9a172016-04-01 16:58:06 -0700495 /**
496 * Configures traffic treatment builder with a given collection of actions.
497 *
498 * @param actions a set of OpenFlow actions
499 * @param builder traffic treatment builder
500 * @param driverHandler driver handler
501 * @param deviceId device identifier
502 * @return configured traffic treatment builder
503 */
504 public static TrafficTreatment.Builder configureTreatmentBuilder(List<OFAction> actions,
505 TrafficTreatment.Builder builder,
506 DriverHandler driverHandler,
507 DeviceId deviceId) {
508 ExtensionTreatmentInterpreter interpreter;
Charles Chan14967c22015-12-07 11:11:50 -0800509 if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
Jian Lia0d9a172016-04-01 16:58:06 -0700510 interpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class);
Charles Chan14967c22015-12-07 11:11:50 -0800511 } else {
Jian Lia0d9a172016-04-01 16:58:06 -0700512 interpreter = null;
Charles Chan14967c22015-12-07 11:11:50 -0800513 }
514
alshabib346b5b32015-03-06 00:42:16 -0800515 for (OFAction act : actions) {
516 switch (act.getType()) {
517 case OUTPUT:
518 OFActionOutput out = (OFActionOutput) act;
519 builder.setOutput(
520 PortNumber.portNumber(out.getPort().getPortNumber()));
521 break;
522 case SET_VLAN_VID:
523 OFActionSetVlanVid vlan = (OFActionSetVlanVid) act;
524 builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan()));
525 break;
526 case SET_VLAN_PCP:
527 OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act;
528 builder.setVlanPcp(pcp.getVlanPcp().getValue());
529 break;
530 case SET_DL_DST:
531 OFActionSetDlDst dldst = (OFActionSetDlDst) act;
532 builder.setEthDst(
533 MacAddress.valueOf(dldst.getDlAddr().getLong()));
534 break;
535 case SET_DL_SRC:
536 OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act;
537 builder.setEthSrc(
538 MacAddress.valueOf(dlsrc.getDlAddr().getLong()));
alshabib346b5b32015-03-06 00:42:16 -0800539 break;
540 case SET_NW_DST:
541 OFActionSetNwDst nwdst = (OFActionSetNwDst) act;
542 IPv4Address di = nwdst.getNwAddr();
543 builder.setIpDst(Ip4Address.valueOf(di.getInt()));
544 break;
545 case SET_NW_SRC:
546 OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act;
547 IPv4Address si = nwsrc.getNwAddr();
548 builder.setIpSrc(Ip4Address.valueOf(si.getInt()));
549 break;
550 case EXPERIMENTER:
551 OFActionExperimenter exp = (OFActionExperimenter) act;
552 if (exp.getExperimenter() == 0x80005A06 ||
553 exp.getExperimenter() == 0x748771) {
554 OFActionCircuit ct = (OFActionCircuit) exp;
Yafit Hadar4cc65f72016-02-10 11:23:06 +0200555 CircuitSignalID circuitSignalID = ((OFOxmOchSigid) ct.getField()).getValue();
556 builder.add(Instructions.modL0Lambda(Lambda.ochSignal(
557 lookupGridType(circuitSignalID.getGridType()),
558 lookupChannelSpacing(circuitSignalID.getChannelSpacing()),
559 circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth())));
Jian Lia0d9a172016-04-01 16:58:06 -0700560 } else if (interpreter != null) {
561 builder.extension(interpreter.mapAction(exp), deviceId);
alshabib346b5b32015-03-06 00:42:16 -0800562 } else {
563 log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter());
564 }
565 break;
566 case SET_FIELD:
567 OFActionSetField setField = (OFActionSetField) act;
Jian Lia0d9a172016-04-01 16:58:06 -0700568 handleSetField(builder, setField, driverHandler, deviceId);
alshabib346b5b32015-03-06 00:42:16 -0800569 break;
570 case POP_MPLS:
571 OFActionPopMpls popMpls = (OFActionPopMpls) act;
Ray Milkey84d5a292016-02-22 14:04:01 -0800572 builder.popMpls(new EthType(popMpls.getEthertype().getValue()));
alshabib346b5b32015-03-06 00:42:16 -0800573 break;
574 case PUSH_MPLS:
575 builder.pushMpls();
576 break;
577 case COPY_TTL_IN:
578 builder.copyTtlIn();
579 break;
580 case COPY_TTL_OUT:
581 builder.copyTtlOut();
582 break;
583 case DEC_MPLS_TTL:
584 builder.decMplsTtl();
585 break;
586 case DEC_NW_TTL:
587 builder.decNwTtl();
588 break;
589 case GROUP:
590 OFActionGroup group = (OFActionGroup) act;
Yi Tsengfa394de2017-02-01 11:26:40 -0800591 builder.group(new GroupId(group.getGroup().getGroupNumber()));
alshabib346b5b32015-03-06 00:42:16 -0800592 break;
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200593 case SET_QUEUE:
594 OFActionSetQueue setQueue = (OFActionSetQueue) act;
595 builder.setQueue(setQueue.getQueueId());
596 break;
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200597 case ENQUEUE:
598 OFActionEnqueue enqueue = (OFActionEnqueue) act;
Jian Liffef5002016-04-04 23:27:37 -0700599 builder.setQueue(enqueue.getQueueId(),
600 PortNumber.portNumber(enqueue.getPort().getPortNumber()));
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200601 break;
Jonathan Hart67fc0972015-03-19 15:21:20 -0700602 case STRIP_VLAN:
alshabib346b5b32015-03-06 00:42:16 -0800603 case POP_VLAN:
604 builder.popVlan();
605 break;
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700606 case PUSH_VLAN:
Konstantinos Kanonakis9215ff22016-11-04 13:28:11 -0500607 OFActionPushVlan pushVlan = (OFActionPushVlan) act;
608 builder.pushVlan(new EthType((short) pushVlan.getEthertype().getValue()));
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700609 break;
cansu.toprak409289d2017-10-27 10:04:05 +0300610 case METER:
611 OFActionMeter actionMeter = (OFActionMeter) act;
612 builder.meter(MeterId.meterId(actionMeter.getMeterId()));
613 break;
alshabib346b5b32015-03-06 00:42:16 -0800614 case SET_TP_DST:
615 case SET_TP_SRC:
616 case POP_PBB:
617 case PUSH_PBB:
alshabib346b5b32015-03-06 00:42:16 -0800618 case SET_MPLS_LABEL:
619 case SET_MPLS_TC:
620 case SET_MPLS_TTL:
621 case SET_NW_ECN:
622 case SET_NW_TOS:
623 case SET_NW_TTL:
alshabib346b5b32015-03-06 00:42:16 -0800624
alshabib346b5b32015-03-06 00:42:16 -0800625 default:
626 log.warn("Action type {} not yet implemented.", act.getType());
627 }
628 }
629 return builder;
630 }
631
Jian Lia0d9a172016-04-01 16:58:06 -0700632 private TrafficTreatment.Builder buildActions(List<OFAction> actions,
633 TrafficTreatment.Builder builder) {
Jonathan Harte4e74f02016-03-03 12:57:40 -0800634 DriverHandler driverHandler = getDriver(deviceId);
Jian Lia0d9a172016-04-01 16:58:06 -0700635
636 return configureTreatmentBuilder(actions, builder, driverHandler, deviceId);
637 }
638
Charles Chancad338a2016-09-16 18:03:11 -0700639 // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES
Jian Lia0d9a172016-04-01 16:58:06 -0700640 private static void handleSetField(TrafficTreatment.Builder builder,
641 OFActionSetField action,
642 DriverHandler driverHandler,
643 DeviceId deviceId) {
Charles Chan14967c22015-12-07 11:11:50 -0800644 ExtensionTreatmentInterpreter treatmentInterpreter;
645 if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
646 treatmentInterpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class);
647 } else {
648 treatmentInterpreter = null;
649 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700650 OFOxm<?> oxm = action.getField();
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800651 switch (oxm.getMatchField().id) {
652 case VLAN_PCP:
653 @SuppressWarnings("unchecked")
654 OFOxm<VlanPcp> vlanpcp = (OFOxm<VlanPcp>) oxm;
655 builder.setVlanPcp(vlanpcp.getValue().getValue());
656 break;
657 case VLAN_VID:
Charles Chan4211baa2016-04-20 17:10:40 -0700658 if (treatmentInterpreter != null) {
659 try {
660 builder.extension(treatmentInterpreter.mapAction(action), deviceId);
661 break;
662 } catch (UnsupportedOperationException e) {
663 log.debug("Unsupported action extension; defaulting to native OF");
664 }
Charles Chan14967c22015-12-07 11:11:50 -0800665 }
alshabib44852fb2016-04-15 15:56:51 -0700666 @SuppressWarnings("unchecked")
667 OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm;
668 builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan()));
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800669 break;
670 case ETH_DST:
671 @SuppressWarnings("unchecked")
672 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethdst =
673 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
674 builder.setEthDst(MacAddress.valueOf(ethdst.getValue().getLong()));
675 break;
676 case ETH_SRC:
677 @SuppressWarnings("unchecked")
678 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethsrc =
679 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
680 builder.setEthSrc(MacAddress.valueOf(ethsrc.getValue().getLong()));
681 break;
682 case IPV4_DST:
683 @SuppressWarnings("unchecked")
684 OFOxm<IPv4Address> ip4dst = (OFOxm<IPv4Address>) oxm;
685 builder.setIpDst(Ip4Address.valueOf(ip4dst.getValue().getInt()));
686 break;
687 case IPV4_SRC:
688 @SuppressWarnings("unchecked")
689 OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm;
690 builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt()));
691 break;
sangho3f97a17d2015-01-29 22:56:29 -0800692 case MPLS_LABEL:
693 @SuppressWarnings("unchecked")
694 OFOxm<U32> labelId = (OFOxm<U32>) oxm;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100695 builder.setMpls(MplsLabel.mplsLabel((int) labelId.getValue().getValue()));
sangho3f97a17d2015-01-29 22:56:29 -0800696 break;
Saurav Das73a7dd42015-08-19 22:20:31 -0700697 case MPLS_BOS:
698 @SuppressWarnings("unchecked")
Pier Ventre23f78672016-11-15 08:46:34 -0800699 OFOxm<OFBooleanValue> mplsBos = (OFOxm<OFBooleanValue>) oxm;
700 builder.setMplsBos(mplsBos.getValue().getValue());
Saurav Das73a7dd42015-08-19 22:20:31 -0700701 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700702 case TUNNEL_ID:
703 @SuppressWarnings("unchecked")
704 OFOxm<U64> tunnelId = (OFOxm<U64>) oxm;
705 builder.setTunnelId(tunnelId.getValue().getValue());
706 break;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700707 case TCP_DST:
708 @SuppressWarnings("unchecked")
709 OFOxm<TransportPort> tcpdst = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700710 builder.setTcpDst(TpPort.tpPort(tcpdst.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700711 break;
712 case TCP_SRC:
713 @SuppressWarnings("unchecked")
714 OFOxm<TransportPort> tcpsrc = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700715 builder.setTcpSrc(TpPort.tpPort(tcpsrc.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700716 break;
717 case UDP_DST:
718 @SuppressWarnings("unchecked")
719 OFOxm<TransportPort> udpdst = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700720 builder.setUdpDst(TpPort.tpPort(udpdst.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700721 break;
722 case UDP_SRC:
723 @SuppressWarnings("unchecked")
724 OFOxm<TransportPort> udpsrc = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700725 builder.setUdpSrc(TpPort.tpPort(udpsrc.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700726 break;
Jonathan Hart3c259162015-10-21 21:31:19 -0700727 case TUNNEL_IPV4_DST:
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530728 case NSP:
729 case NSI:
730 case NSH_C1:
731 case NSH_C2:
732 case NSH_C3:
733 case NSH_C4:
734 case NSH_MDTYPE:
735 case NSH_NP:
736 case ENCAP_ETH_SRC:
737 case ENCAP_ETH_DST:
738 case ENCAP_ETH_TYPE:
739 case TUN_GPE_NP:
Jian Liffef5002016-04-04 23:27:37 -0700740 if (treatmentInterpreter != null) {
741 try {
742 builder.extension(treatmentInterpreter.mapAction(action), deviceId);
743 } catch (UnsupportedOperationException e) {
alshabib44852fb2016-04-15 15:56:51 -0700744 log.debug(e.getMessage());
Jian Liffef5002016-04-04 23:27:37 -0700745 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700746 }
747 break;
Yafit Hadar73514612015-11-04 10:14:21 +0200748 case EXP_ODU_SIG_ID:
749 @SuppressWarnings("unchecked")
750 OFOxm<OduSignalID> oduID = (OFOxm<OduSignalID>) oxm;
751 OduSignalID oduSignalID = oduID.getValue();
752 OduSignalId oduSignalId = OduSignalId.oduSignalId(oduSignalID.getTpn(),
753 oduSignalID.getTslen(),
754 oduSignalID.getTsmap());
755 builder.add(modL1OduSignalId(oduSignalId));
756 break;
757 case EXP_OCH_SIG_ID:
758 try {
759 @SuppressWarnings("unchecked")
760 OFOxm<CircuitSignalID> ochId = (OFOxm<CircuitSignalID>) oxm;
761 CircuitSignalID circuitSignalID = ochId.getValue();
762 builder.add(modL0Lambda(Lambda.ochSignal(
763 lookupGridType(circuitSignalID.getGridType()),
764 lookupChannelSpacing(circuitSignalID.getChannelSpacing()),
765 circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth())));
766 } catch (NoMappingFoundException e) {
767 log.warn(e.getMessage());
768 break;
769 }
770 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800771 case ARP_OP:
lishuai67574ce2016-05-12 16:39:59 +0800772 @SuppressWarnings("unchecked")
773 OFOxm<org.projectfloodlight.openflow.types.ArpOpcode> arpop =
774 (OFOxm<org.projectfloodlight.openflow.types.ArpOpcode>) oxm;
775 builder.setArpOp((short) arpop.getValue().getOpcode());
776 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800777 case ARP_SHA:
lishuai67574ce2016-05-12 16:39:59 +0800778 @SuppressWarnings("unchecked")
779 OFOxm<org.projectfloodlight.openflow.types.MacAddress> arpsha =
780 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
781 builder.setArpSha(MacAddress.valueOf(arpsha.getValue().getLong()));
782 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800783 case ARP_SPA:
lishuai67574ce2016-05-12 16:39:59 +0800784 @SuppressWarnings("unchecked")
785 OFOxm<IPv4Address> arpspa = (OFOxm<IPv4Address>) oxm;
786 builder.setArpSpa(Ip4Address.valueOf(arpspa.getValue().getInt()));
787 break;
Charles Chancad338a2016-09-16 18:03:11 -0700788 case OFDPA_MPLS_TYPE:
Pier Ventre6f630052016-10-18 09:58:41 -0700789 case OFDPA_OVID:
Pier Ventre9cf536b2016-10-21 13:30:18 -0700790 case OFDPA_MPLS_L2_PORT:
Pier Ventredb252cc2016-10-21 21:54:26 -0700791 case OFDPA_QOS_INDEX:
Charles Chancad338a2016-09-16 18:03:11 -0700792 if (treatmentInterpreter != null) {
793 try {
794 builder.extension(treatmentInterpreter.mapAction(action), deviceId);
795 break;
796 } catch (UnsupportedOperationException e) {
797 log.warn("Unsupported action extension");
798 }
799 }
800 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800801 case ARP_THA:
802 case ARP_TPA:
803 case BSN_EGR_PORT_GROUP_ID:
804 case BSN_GLOBAL_VRF_ALLOWED:
805 case BSN_IN_PORTS_128:
806 case BSN_L3_DST_CLASS_ID:
807 case BSN_L3_INTERFACE_CLASS_ID:
808 case BSN_L3_SRC_CLASS_ID:
809 case BSN_LAG_ID:
810 case BSN_TCP_FLAGS:
811 case BSN_UDF0:
812 case BSN_UDF1:
813 case BSN_UDF2:
814 case BSN_UDF3:
815 case BSN_UDF4:
816 case BSN_UDF5:
817 case BSN_UDF6:
818 case BSN_UDF7:
819 case BSN_VLAN_XLATE_PORT_GROUP_ID:
820 case BSN_VRF:
821 case ETH_TYPE:
822 case ICMPV4_CODE:
823 case ICMPV4_TYPE:
824 case ICMPV6_CODE:
825 case ICMPV6_TYPE:
826 case IN_PHY_PORT:
827 case IN_PORT:
828 case IPV6_DST:
829 case IPV6_FLABEL:
830 case IPV6_ND_SLL:
831 case IPV6_ND_TARGET:
832 case IPV6_ND_TLL:
833 case IPV6_SRC:
834 case IP_DSCP:
835 case IP_ECN:
836 case IP_PROTO:
837 case METADATA:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800838 case MPLS_TC:
839 case OCH_SIGID:
840 case OCH_SIGID_BASIC:
841 case OCH_SIGTYPE:
842 case OCH_SIGTYPE_BASIC:
843 case SCTP_DST:
844 case SCTP_SRC:
Yafit Hadar73514612015-11-04 10:14:21 +0200845 case EXP_ODU_SIGTYPE:
846 case EXP_OCH_SIGTYPE:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800847 default:
848 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
849 break;
850 }
851 }
852
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700853 // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES
alshabib6b5cfec2014-09-18 17:42:18 -0700854 private TrafficSelector buildSelector() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800855 MacAddress mac;
856 Ip4Prefix ip4Prefix;
857 Ip6Address ip6Address;
858 Ip6Prefix ip6Prefix;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800859 Ip4Address ip;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800860
Jonathan Harte4e74f02016-03-03 12:57:40 -0800861 DriverHandler driverHandler = getDriver(deviceId);
Charles Chan14967c22015-12-07 11:11:50 -0800862 ExtensionSelectorInterpreter selectorInterpreter;
863 if (driverHandler.hasBehaviour(ExtensionSelectorInterpreter.class)) {
864 selectorInterpreter = driverHandler.behaviour(ExtensionSelectorInterpreter.class);
865 } else {
866 selectorInterpreter = null;
867 }
868
tom9a693fd2014-10-03 11:32:19 -0700869 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700870 for (MatchField<?> field : match.getMatchFields()) {
871 switch (field.id) {
872 case IN_PORT:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800873 builder.matchInPort(PortNumber
alshabib010c31d2014-09-26 10:01:12 -0700874 .portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700875 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800876 case IN_PHY_PORT:
877 builder.matchInPhyPort(PortNumber
878 .portNumber(match.get(MatchField.IN_PHY_PORT).getPortNumber()));
879 break;
880 case METADATA:
881 long metadata =
882 match.get(MatchField.METADATA).getValue().getValue();
883 builder.matchMetadata(metadata);
884 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700885 case ETH_DST:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800886 if (match.isPartiallyMasked(MatchField.ETH_DST)) {
887 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
888 match.getMasked(MatchField.ETH_DST);
889 builder.matchEthDstMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
890 MacAddress.valueOf(maskedMac.getMask().getLong()));
891 } else {
892 mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
893 builder.matchEthDst(mac);
894 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800895 break;
896 case ETH_SRC:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800897 if (match.isPartiallyMasked(MatchField.ETH_SRC)) {
898 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
899 match.getMasked(MatchField.ETH_SRC);
900 builder.matchEthSrcMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
901 MacAddress.valueOf(maskedMac.getMask().getLong()));
902 } else {
903 mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
904 builder.matchEthSrc(mac);
905 }
alshabib6b5cfec2014-09-18 17:42:18 -0700906 break;
907 case ETH_TYPE:
908 int ethType = match.get(MatchField.ETH_TYPE).getValue();
Jonathan Hart8cf212a2015-10-29 17:42:03 -0700909 builder.matchEthType((short) ethType);
alshabib6b5cfec2014-09-18 17:42:18 -0700910 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700911 case VLAN_VID:
Charles Chan14967c22015-12-07 11:11:50 -0800912 if (selectorInterpreter != null &&
913 selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -0700914 if (isOF13OrLater(match)) {
Charles Chan14967c22015-12-07 11:11:50 -0800915 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.VLAN_VID);
916 builder.extension(selectorInterpreter.mapOxm(oxm),
Jonathan Harte4e74f02016-03-03 12:57:40 -0800917 deviceId);
Charles Chan14967c22015-12-07 11:11:50 -0800918 } else {
919 break;
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800920 }
921 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800922 VlanId vlanId = null;
923 if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
924 Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
925 if (masked.getValue().equals(OFVlanVidMatch.PRESENT)
926 && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
927 vlanId = VlanId.ANY;
928 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700929 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800930 if (!match.get(MatchField.VLAN_VID).isPresentBitSet()) {
931 vlanId = VlanId.NONE;
932 } else {
933 vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
934 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700935 }
Charles Chan14967c22015-12-07 11:11:50 -0800936 if (vlanId != null) {
937 builder.matchVlanId(vlanId);
938 }
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800939 }
alshabib6b5cfec2014-09-18 17:42:18 -0700940 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800941 case VLAN_PCP:
942 byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
943 builder.matchVlanPcp(vlanPcp);
944 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800945 case IP_DSCP:
946 byte ipDscp = match.get(MatchField.IP_DSCP).getDscpValue();
947 builder.matchIPDscp(ipDscp);
948 break;
949 case IP_ECN:
950 byte ipEcn = match.get(MatchField.IP_ECN).getEcnValue();
951 builder.matchIPEcn(ipEcn);
952 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800953 case IP_PROTO:
954 short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
955 builder.matchIPProtocol((byte) proto);
956 break;
957 case IPV4_SRC:
958 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
959 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800960 ip4Prefix = Ip4Prefix.valueOf(
961 maskedIp.getValue().getInt(),
962 maskedIp.getMask().asCidrMaskLength());
963 } else {
964 ip4Prefix = Ip4Prefix.valueOf(
965 match.get(MatchField.IPV4_SRC).getInt(),
966 Ip4Prefix.MAX_MASK_LENGTH);
967 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800968 builder.matchIPSrc(ip4Prefix);
969 break;
970 case IPV4_DST:
971 if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
972 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800973 ip4Prefix = Ip4Prefix.valueOf(
974 maskedIp.getValue().getInt(),
975 maskedIp.getMask().asCidrMaskLength());
976 } else {
977 ip4Prefix = Ip4Prefix.valueOf(
978 match.get(MatchField.IPV4_DST).getInt(),
979 Ip4Prefix.MAX_MASK_LENGTH);
980 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800981 builder.matchIPDst(ip4Prefix);
Jonathan Hart34bc6142014-10-17 11:00:43 -0700982 break;
983 case TCP_SRC:
Andreas Gilbert75b882f72017-02-03 09:58:07 +0100984 if (match.isPartiallyMasked(MatchField.TCP_SRC)) {
985 Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort =
986 match.getMasked(MatchField.TCP_SRC);
987 builder.matchTcpSrcMasked(TpPort.tpPort(maskedPort.getValue().getPort()),
988 TpPort.tpPort(maskedPort.getMask().getPort()));
989 } else {
990 builder.matchTcpSrc(TpPort.tpPort(match.get(MatchField.TCP_SRC).getPort()));
991 }
Jonathan Hart34bc6142014-10-17 11:00:43 -0700992 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800993 case TCP_DST:
Andreas Gilbert75b882f72017-02-03 09:58:07 +0100994 if (match.isPartiallyMasked(MatchField.TCP_DST)) {
995 Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort =
996 match.getMasked(MatchField.TCP_DST);
997 builder.matchTcpDstMasked(TpPort.tpPort(maskedPort.getValue().getPort()),
998 TpPort.tpPort(maskedPort.getMask().getPort()));
999 } else {
1000 builder.matchTcpDst(TpPort.tpPort(match.get(MatchField.TCP_DST).getPort()));
1001 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001002 break;
1003 case UDP_SRC:
Andreas Gilbert75b882f72017-02-03 09:58:07 +01001004 if (match.isPartiallyMasked(MatchField.UDP_SRC)) {
1005 Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort =
1006 match.getMasked(MatchField.UDP_SRC);
1007 builder.matchUdpSrcMasked(TpPort.tpPort(maskedPort.getValue().getPort()),
1008 TpPort.tpPort(maskedPort.getMask().getPort()));
1009 } else {
1010 builder.matchUdpSrc(TpPort.tpPort(match.get(MatchField.UDP_SRC).getPort()));
1011 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001012 break;
1013 case UDP_DST:
Andreas Gilbert75b882f72017-02-03 09:58:07 +01001014 if (match.isPartiallyMasked(MatchField.UDP_DST)) {
1015 Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort =
1016 match.getMasked(MatchField.UDP_DST);
1017 builder.matchUdpDstMasked(TpPort.tpPort(maskedPort.getValue().getPort()),
1018 TpPort.tpPort(maskedPort.getMask().getPort()));
1019 } else {
1020 builder.matchUdpDst(TpPort.tpPort(match.get(MatchField.UDP_DST).getPort()));
1021 }
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -07001022 break;
Michele Santuari4b6019e2014-12-19 11:31:45 +01001023 case MPLS_LABEL:
1024 builder.matchMplsLabel(MplsLabel.mplsLabel((int) match.get(MatchField.MPLS_LABEL)
1025 .getValue()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001026 break;
Saurav Dasffc5bbc2015-08-18 23:30:19 -07001027 case MPLS_BOS:
1028 builder.matchMplsBos(match.get(MatchField.MPLS_BOS).getValue());
1029 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001030 case SCTP_SRC:
Andreas Gilbert75b882f72017-02-03 09:58:07 +01001031 if (match.isPartiallyMasked(MatchField.SCTP_SRC)) {
1032 Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort =
1033 match.getMasked(MatchField.SCTP_SRC);
1034 builder.matchSctpSrcMasked(TpPort.tpPort(maskedPort.getValue().getPort()),
1035 TpPort.tpPort(maskedPort.getMask().getPort()));
1036 } else {
1037 builder.matchSctpSrc(TpPort.tpPort(match.get(MatchField.SCTP_SRC).getPort()));
1038 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001039 break;
1040 case SCTP_DST:
Andreas Gilbert75b882f72017-02-03 09:58:07 +01001041 if (match.isPartiallyMasked(MatchField.SCTP_DST)) {
1042 Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort =
1043 match.getMasked(MatchField.SCTP_DST);
1044 builder.matchSctpDstMasked(TpPort.tpPort(maskedPort.getValue().getPort()),
1045 TpPort.tpPort(maskedPort.getMask().getPort()));
1046 } else {
1047 builder.matchSctpDst(TpPort.tpPort(match.get(MatchField.SCTP_DST).getPort()));
1048 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001049 break;
1050 case ICMPV4_TYPE:
1051 byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
1052 builder.matchIcmpType(icmpType);
1053 break;
1054 case ICMPV4_CODE:
1055 byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode();
1056 builder.matchIcmpCode(icmpCode);
1057 break;
1058 case IPV6_SRC:
1059 if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
1060 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
1061 ip6Prefix = Ip6Prefix.valueOf(
1062 maskedIp.getValue().getBytes(),
1063 maskedIp.getMask().asCidrMaskLength());
1064 } else {
1065 ip6Prefix = Ip6Prefix.valueOf(
1066 match.get(MatchField.IPV6_SRC).getBytes(),
1067 Ip6Prefix.MAX_MASK_LENGTH);
1068 }
1069 builder.matchIPv6Src(ip6Prefix);
1070 break;
1071 case IPV6_DST:
1072 if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
1073 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
1074 ip6Prefix = Ip6Prefix.valueOf(
1075 maskedIp.getValue().getBytes(),
1076 maskedIp.getMask().asCidrMaskLength());
1077 } else {
1078 ip6Prefix = Ip6Prefix.valueOf(
1079 match.get(MatchField.IPV6_DST).getBytes(),
1080 Ip6Prefix.MAX_MASK_LENGTH);
1081 }
1082 builder.matchIPv6Dst(ip6Prefix);
1083 break;
1084 case IPV6_FLABEL:
1085 int flowLabel =
1086 match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue();
1087 builder.matchIPv6FlowLabel(flowLabel);
1088 break;
1089 case ICMPV6_TYPE:
1090 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
1091 builder.matchIcmpv6Type(icmpv6type);
1092 break;
1093 case ICMPV6_CODE:
1094 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
1095 builder.matchIcmpv6Code(icmpv6code);
1096 break;
1097 case IPV6_ND_TARGET:
1098 ip6Address =
1099 Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes());
1100 builder.matchIPv6NDTargetAddress(ip6Address);
1101 break;
1102 case IPV6_ND_SLL:
1103 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong());
1104 builder.matchIPv6NDSourceLinkLayerAddress(mac);
1105 break;
1106 case IPV6_ND_TLL:
1107 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong());
1108 builder.matchIPv6NDTargetLinkLayerAddress(mac);
1109 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001110 case IPV6_EXTHDR:
Charles M.C. Chan2184de12015-04-26 02:24:53 +08001111 builder.matchIPv6ExthdrFlags((short) match.get(MatchField.IPV6_EXTHDR)
Hyunsun Moona08c5d02015-07-14 17:53:00 -07001112 .getValue());
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001113 break;
Marc De Leenheer49087752014-10-23 13:54:09 -07001114 case OCH_SIGID:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -07001115 CircuitSignalID sigId = match.get(MatchField.OCH_SIGID);
1116 builder.add(matchLambda(Lambda.ochSignal(
Sho SHIMIZUc17042d2015-05-28 12:07:23 -07001117 lookupGridType(sigId.getGridType()), lookupChannelSpacing(sigId.getChannelSpacing()),
Marc De Leenheer0b8b2ef2015-08-03 15:39:00 -07001118 sigId.getChannelNumber(), sigId.getSpectralWidth())
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -07001119 ));
Marc De Leenheer49087752014-10-23 13:54:09 -07001120 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -08001121 case OCH_SIGTYPE:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -07001122 U8 sigType = match.get(MatchField.OCH_SIGTYPE);
Sho SHIMIZUc17042d2015-05-28 12:07:23 -07001123 builder.add(matchOchSignalType(lookupOchSignalType((byte) sigType.getValue())));
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -08001124 break;
Yafit Hadar73514612015-11-04 10:14:21 +02001125 case EXP_OCH_SIG_ID:
1126 try {
1127 CircuitSignalID expSigId = match.get(MatchField.EXP_OCH_SIG_ID);
1128 builder.add(matchLambda(Lambda.ochSignal(
1129 lookupGridType(expSigId.getGridType()), lookupChannelSpacing(expSigId.getChannelSpacing()),
1130 expSigId.getChannelNumber(), expSigId.getSpectralWidth())));
1131 } catch (NoMappingFoundException e) {
1132 log.warn(e.getMessage());
1133 break;
1134 }
1135 break;
1136 case EXP_OCH_SIGTYPE:
1137 try {
1138 U8 expOchSigType = match.get(MatchField.EXP_OCH_SIGTYPE);
1139 builder.add(matchOchSignalType(lookupOchSignalType((byte) expOchSigType.getValue())));
1140 } catch (NoMappingFoundException e) {
1141 log.warn(e.getMessage());
1142 break;
1143 }
1144 break;
1145 case EXP_ODU_SIG_ID:
1146 OduSignalId oduSignalId = OduSignalId.oduSignalId(match.get(MatchField.EXP_ODU_SIG_ID).getTpn(),
1147 match.get(MatchField.EXP_ODU_SIG_ID).getTslen(),
1148 match.get(MatchField.EXP_ODU_SIG_ID).getTsmap());
1149 builder.add(matchOduSignalId(oduSignalId));
Frank Wang5733c382017-03-28 10:15:18 +08001150 break;
Yafit Hadar73514612015-11-04 10:14:21 +02001151 case EXP_ODU_SIGTYPE:
1152 try {
1153 U8 oduSigType = match.get(MatchField.EXP_ODU_SIGTYPE);
1154 builder.add(matchOduSignalType(lookupOduSignalType((byte) oduSigType.getValue())));
1155 } catch (NoMappingFoundException e) {
1156 log.warn(e.getMessage());
1157 break;
1158 }
1159 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -07001160 case TUNNEL_ID:
1161 long tunnelId = match.get(MatchField.TUNNEL_ID).getValue();
1162 builder.matchTunnelId(tunnelId);
1163 break;
BitOhenryb40129a2015-11-30 12:41:18 +08001164 case ARP_OP:
1165 int arpOp = match.get(MatchField.ARP_OP).getOpcode();
1166 builder.matchArpOp(arpOp);
1167 break;
BitOhenrya331b182015-11-23 08:39:37 +08001168 case ARP_SHA:
1169 mac = MacAddress.valueOf(match.get(MatchField.ARP_SHA).getLong());
1170 builder.matchArpSha(mac);
1171 break;
BitOhenry296b4542015-11-24 08:41:58 +08001172 case ARP_SPA:
1173 ip = Ip4Address.valueOf(match.get(MatchField.ARP_SPA).getInt());
1174 builder.matchArpSpa(ip);
1175 break;
BitOhenry76430852015-11-20 19:04:49 +08001176 case ARP_THA:
1177 mac = MacAddress.valueOf(match.get(MatchField.ARP_THA).getLong());
1178 builder.matchArpTha(mac);
1179 break;
BitOhenryc1e5fcc2015-11-23 20:47:53 +08001180 case ARP_TPA:
1181 ip = Ip4Address.valueOf(match.get(MatchField.ARP_TPA).getInt());
1182 builder.matchArpTpa(ip);
1183 break;
Phaneendra Manda8db7d092016-06-04 00:17:24 +05301184 case NSP:
1185 if (selectorInterpreter != null) {
1186 try {
1187 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.NSP);
1188 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
1189 } catch (UnsupportedOperationException e) {
1190 log.debug(e.getMessage());
1191 }
1192 }
1193 break;
1194 case NSI:
1195 if (selectorInterpreter != null) {
1196 try {
1197 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.NSI);
1198 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
1199 } catch (UnsupportedOperationException e) {
1200 log.debug(e.getMessage());
1201 }
1202 }
1203 break;
1204 case ENCAP_ETH_TYPE:
1205 if (selectorInterpreter != null) {
1206 try {
1207 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.ENCAP_ETH_TYPE);
1208 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
1209 } catch (UnsupportedOperationException e) {
1210 log.debug(e.getMessage());
1211 }
1212 }
1213 break;
Frank Wang5733c382017-03-28 10:15:18 +08001214 case CONNTRACK_STATE:
1215 if (selectorInterpreter != null &&
1216 selectorInterpreter.supported(ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_STATE.type())) {
1217 try {
1218 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.CONNTRACK_STATE);
1219 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
1220 } catch (UnsupportedOperationException e) {
1221 log.debug(e.getMessage());
1222 }
1223 }
1224 break;
1225 case CONNTRACK_ZONE:
1226 if (selectorInterpreter != null &&
1227 selectorInterpreter.supported(ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_ZONE.type())) {
1228 try {
1229 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.CONNTRACK_ZONE);
1230 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
1231 } catch (UnsupportedOperationException e) {
1232 log.debug(e.getMessage());
1233 }
1234 }
1235 break;
1236 case CONNTRACK_MARK:
1237 if (selectorInterpreter != null &&
1238 selectorInterpreter.supported(ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_MARK.type())) {
1239 try {
1240 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.CONNTRACK_MARK);
1241 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
1242 } catch (UnsupportedOperationException e) {
1243 log.debug(e.getMessage());
1244 }
1245 }
1246 break;
Pier Ventre6f630052016-10-18 09:58:41 -07001247 case OFDPA_OVID:
1248 if (selectorInterpreter != null &&
1249 selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_OVID.type())) {
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -07001250 if (isOF13OrLater(match)) {
Pier Ventre6f630052016-10-18 09:58:41 -07001251 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.OFDPA_OVID);
1252 builder.extension(selectorInterpreter.mapOxm(oxm),
1253 deviceId);
1254 } else {
1255 break;
1256 }
1257 }
1258 break;
Pier Ventre9cf536b2016-10-21 13:30:18 -07001259 case OFDPA_MPLS_L2_PORT:
1260 if (selectorInterpreter != null &&
1261 selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_MPLS_L2_PORT.type())) {
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -07001262 if (isOF13OrLater(match)) {
Pier Ventre9cf536b2016-10-21 13:30:18 -07001263 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.OFDPA_MPLS_L2_PORT);
1264 builder.extension(selectorInterpreter.mapOxm(oxm),
1265 deviceId);
1266 } else {
1267 break;
1268 }
1269 }
1270 break;
alshabib6b5cfec2014-09-18 17:42:18 -07001271 case MPLS_TC:
alshabib6b5cfec2014-09-18 17:42:18 -07001272 default:
1273 log.warn("Match type {} not yet implemented.", field.id);
alshabib6b5cfec2014-09-18 17:42:18 -07001274 }
1275 }
1276 return builder.build();
1277 }
Jonathan Hart3c259162015-10-21 21:31:19 -07001278
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -07001279 /**
1280 * @param obj OpenFlow object to test
1281 * @return true if OFObject is OF_13 or later
1282 */
1283 private static boolean isOF13OrLater(OFObject obj) {
1284 return obj.getVersion().wireVersion >= OFVersion.OF_13.wireVersion;
1285 }
1286
Claudine Chiu20cbd452017-08-30 19:23:11 -04001287 /**
1288 * Retrieves the driver handler for the specified device.
1289 *
1290 * @param deviceId device identifier
1291 * @return driver handler
1292 */
1293 protected DriverHandler getDriver(DeviceId deviceId) {
1294 Driver driver = driverService.getDriver(deviceId);
1295 DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, deviceId));
Jonathan Hart3c259162015-10-21 21:31:19 -07001296 return handler;
1297 }
alshabib6b5cfec2014-09-18 17:42:18 -07001298}