blob: cb9568b399d45eb925d9796ea84faa3a58b200cd [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
Rodrigo Duarte Sousae37d1292017-08-29 17:01:24 -0300144 private DriverHandler driverHandler;
Jonathan Hart3c259162015-10-21 21:31:19 -0700145
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
Rodrigo Duarte Sousae37d1292017-08-29 17:01:24 -0300150 public FlowEntryBuilder(DeviceId deviceId, OFFlowStatsEntry entry, DriverHandler driverHandler) {
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;
Rodrigo Duarte Sousae37d1292017-08-29 17:01:24 -0300158 this.driverHandler = driverHandler;
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;
Rodrigo Duarte Sousae37d1292017-08-29 17:01:24 -0300172 this.driverHandler = getDriver(deviceId, driverService);
Cem Türker3baff672017-10-12 15:09:01 +0300173 this.afsc = null;
174 this.lightWeightStat = lightWeightStat;
Saurav Dasfa2fa932015-03-03 11:29:48 -0800175 }
176
Rodrigo Duarte Sousae37d1292017-08-29 17:01:24 -0300177 public FlowEntryBuilder(DeviceId deviceId, OFFlowRemoved removed, DriverHandler driverHandler) {
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;
Rodrigo Duarte Sousae37d1292017-08-29 17:01:24 -0300185 this.driverHandler = driverHandler;
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
Rodrigo Duarte Sousae37d1292017-08-29 17:01:24 -0300190 public FlowEntryBuilder(DeviceId deviceId, OFFlowMod fm, DriverHandler driverHandler) {
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;
Rodrigo Duarte Sousae37d1292017-08-29 17:01:24 -0300198 this.driverHandler = driverHandler;
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
Rodrigo Duarte Sousae37d1292017-08-29 17:01:24 -0300203 public FlowEntryBuilder(DeviceId deviceId, OFFlowStatsEntry entry, DriverService driverService) {
204 this(deviceId, entry, getDriver(deviceId, driverService));
205 }
206
207 public FlowEntryBuilder(DeviceId deviceId, OFFlowRemoved removed, DriverService driverService) {
208 this(deviceId, removed, getDriver(deviceId, driverService));
209 }
210
211 public FlowEntryBuilder(DeviceId deviceId, OFFlowMod fm, DriverService driverService) {
212 this(deviceId, fm, getDriver(deviceId, driverService));
213 }
214
Sangsik Yoonb1b823f2016-05-16 18:55:39 +0900215 public FlowEntryBuilder withSetAfsc(NewAdaptiveFlowStatsCollector afsc) {
216 this.afsc = afsc;
217 return this;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800218 }
alshabib1c319ff2014-10-04 20:29:09 -0700219
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800220 public FlowEntry build(FlowEntryState... state) {
Brian O'Connor21564612015-12-05 19:24:59 -0800221 try {
222 switch (this.type) {
223 case STAT:
Cem Türker3baff672017-10-12 15:09:01 +0300224 return createFlowEntryFromStat();
225 case LIGHTWEIGHT_STAT:
226 return createFlowEntryFromLightweightStat();
Brian O'Connor21564612015-12-05 19:24:59 -0800227 case REMOVED:
Cem Türker3baff672017-10-12 15:09:01 +0300228 return createFlowEntryForFlowRemoved();
Brian O'Connor21564612015-12-05 19:24:59 -0800229 case MOD:
Cem Türker3baff672017-10-12 15:09:01 +0300230 return createFlowEntryForFlowMod(state);
Brian O'Connor21564612015-12-05 19:24:59 -0800231 default:
232 log.error("Unknown flow type : {}", this.type);
233 return null;
234 }
235 } catch (UnsupportedOperationException e) {
236 log.warn("Error building flow entry", e);
237 return null;
alshabib6b5cfec2014-09-18 17:42:18 -0700238 }
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800239
alshabib6b5cfec2014-09-18 17:42:18 -0700240 }
241
Cem Türker3baff672017-10-12 15:09:01 +0300242 private FlowEntry createFlowEntryFromStat() {
243
244 FlowRule.Builder builder = DefaultFlowRule.builder()
245 .forDevice(deviceId)
246 .withSelector(buildSelector())
247 .withTreatment(buildTreatment())
248 .withPriority(stat.getPriority())
249 .withIdleTimeout(stat.getIdleTimeout())
250 .withCookie(stat.getCookie().getValue());
251 if (stat.getVersion() != OFVersion.OF_10) {
252 builder.forTable(stat.getTableId().getValue());
253 }
254 if (stat.getVersion().getWireVersion() < OFVersion.OF_15.getWireVersion()) {
255 if (afsc != null) {
256 FlowEntry.FlowLiveType liveType = afsc.calFlowLiveType(stat.getDurationSec());
257 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
258 SECONDS.toNanos(stat.getDurationSec())
259 + stat.getDurationNsec(), NANOSECONDS,
260 liveType,
261 stat.getPacketCount().getValue(),
262 stat.getByteCount().getValue());
263 } else {
264 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
265 stat.getDurationSec(),
266 stat.getPacketCount().getValue(),
267 stat.getByteCount().getValue());
268 }
269 }
270 FlowStatParser statParser = new FlowStatParser(stat.getStats());
271 if (afsc != null && statParser.isDurationReceived()) {
272 FlowEntry.FlowLiveType liveType = afsc.calFlowLiveType(statParser.getDuration());
273 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
274 SECONDS.toNanos(statParser.getDuration())
275 + SECONDS.toNanos(statParser.getDuration()), NANOSECONDS,
276 liveType,
277 statParser.getPacketCount(),
278 statParser.getByteCount());
279 } else {
280 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
281 statParser.getDuration(),
282 statParser.getPacketCount(),
283 statParser.getByteCount());
284 }
285
286 }
287
288 private FlowEntry createFlowEntryForFlowMod(FlowEntryState ...state) {
289 FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED;
290 FlowRule.Builder builder = DefaultFlowRule.builder()
291 .forDevice(deviceId)
292 .withSelector(buildSelector())
293 .withTreatment(buildTreatment())
294 .withPriority(flowMod.getPriority())
295 .withIdleTimeout(flowMod.getIdleTimeout())
296 .withCookie(flowMod.getCookie().getValue());
297 if (flowMod.getVersion() != OFVersion.OF_10) {
298 builder.forTable(flowMod.getTableId().getValue());
299 }
300
301 if (afsc != null) {
302 FlowEntry.FlowLiveType liveType = FlowEntry.FlowLiveType.IMMEDIATE;
303 return new DefaultFlowEntry(builder.build(), flowState, 0, liveType, 0, 0);
304 } else {
305 return new DefaultFlowEntry(builder.build(), flowState, 0, 0, 0);
306 }
307 }
308
309 private FlowEntry createFlowEntryForFlowRemoved() {
310 FlowRule.Builder builder = DefaultFlowRule.builder()
311 .forDevice(deviceId)
312 .withSelector(buildSelector())
313 .withPriority(removed.getPriority())
314 .withIdleTimeout(removed.getIdleTimeout())
315 .withCookie(removed.getCookie().getValue())
316 .withReason(FlowRule.FlowRemoveReason.parseShort((short) removed.getReason().ordinal()));
317
318 if (removed.getVersion() != OFVersion.OF_10) {
319 builder.forTable(removed.getTableId().getValue());
320 }
321 if (removed.getVersion().getWireVersion() < OFVersion.OF_15.getWireVersion()) {
322 if (afsc != null) {
323 FlowEntry.FlowLiveType liveType = afsc.calFlowLiveType(removed.getDurationSec());
324 return new DefaultFlowEntry(builder.build(), FlowEntryState.REMOVED,
325 SECONDS.toNanos(removed.getDurationSec())
326 + removed.getDurationNsec(), NANOSECONDS,
327 liveType,
328 removed.getPacketCount().getValue(),
329 removed.getByteCount().getValue());
330 } else {
331 return new DefaultFlowEntry(builder.build(), FlowEntryState.REMOVED,
332 removed.getDurationSec(),
333 removed.getPacketCount().getValue(),
334 removed.getByteCount().getValue());
335 }
336 }
337 FlowStatParser statParser = new FlowStatParser(removed.getStats());
338 if (afsc != null && statParser.isDurationReceived()) {
339 FlowEntry.FlowLiveType liveType = afsc.calFlowLiveType(statParser.getDuration());
340 return new DefaultFlowEntry(builder.build(), FlowEntryState.REMOVED,
341 SECONDS.toNanos(statParser.getDuration())
342 + SECONDS.toNanos(statParser.getDuration()), NANOSECONDS,
343 liveType,
344 statParser.getPacketCount(),
345 statParser.getByteCount());
346 } else {
347 return new DefaultFlowEntry(builder.build(), FlowEntryState.REMOVED,
348 statParser.getDuration(),
349 statParser.getPacketCount(),
350 statParser.getByteCount());
351 }
352 }
353
354 private FlowEntry createFlowEntryFromLightweightStat() {
355 FlowRule.Builder builder = DefaultFlowRule.builder()
356 .forDevice(deviceId)
357 .withSelector(buildSelector())
358 .withPriority(lightWeightStat.getPriority())
359 .withIdleTimeout(0)
360 .withCookie(0);
361 FlowStatParser flowLightweightStatParser = new FlowStatParser(lightWeightStat.getStats());
362 builder.forTable(lightWeightStat.getTableId().getValue());
363 if (afsc != null && flowLightweightStatParser.isDurationReceived()) {
364 FlowEntry.FlowLiveType liveType = afsc.calFlowLiveType(flowLightweightStatParser.getDuration());
365 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
366 SECONDS.toNanos(flowLightweightStatParser.getDuration())
367 + flowLightweightStatParser.getDuration(), NANOSECONDS,
368 liveType,
369 flowLightweightStatParser.getPacketCount(),
370 flowLightweightStatParser.getByteCount());
371 } else {
372 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
373 flowLightweightStatParser.getDuration(),
374 flowLightweightStatParser.getPacketCount(),
375 flowLightweightStatParser.getByteCount());
376 }
377 }
378
alshabib346b5b32015-03-06 00:42:16 -0800379 private List<OFInstruction> getInstructions(OFFlowMod entry) {
alshabib19fdc122014-10-03 11:38:19 -0700380 switch (entry.getVersion()) {
381 case OF_10:
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700382 return Lists.newArrayList(OFFactoryVer13.INSTANCE.instructions()
383 .applyActions(
384 entry.getActions()));
alshabib19fdc122014-10-03 11:38:19 -0700385 case OF_11:
386 case OF_12:
387 case OF_13:
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -0700388 case OF_14:
389 case OF_15:
alshabib346b5b32015-03-06 00:42:16 -0800390 return entry.getInstructions();
391 default:
392 log.warn("Unknown OF version {}", entry.getVersion());
393 }
394 return Lists.newLinkedList();
395 }
396
397 private List<OFInstruction> getInstructions(OFFlowStatsEntry entry) {
398 switch (entry.getVersion()) {
399 case OF_10:
400 return Lists.newArrayList(
401 OFFactoryVer13.INSTANCE.instructions().applyActions(entry.getActions()));
402 case OF_11:
403 case OF_12:
404 case OF_13:
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -0700405 case OF_14:
406 case OF_15:
alshabib346b5b32015-03-06 00:42:16 -0800407 return entry.getInstructions();
alshabib19fdc122014-10-03 11:38:19 -0700408 default:
409 log.warn("Unknown OF version {}", entry.getVersion());
410 }
411 return Lists.newLinkedList();
412 }
alshabib6b5cfec2014-09-18 17:42:18 -0700413
414 private TrafficTreatment buildTreatment() {
tom9a693fd2014-10-03 11:32:19 -0700415 TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
alshabib346b5b32015-03-06 00:42:16 -0800416 for (OFInstruction in : instructions) {
417 switch (in.getType()) {
418 case GOTO_TABLE:
alshabibbdcbb102015-04-22 14:16:38 -0700419 builder.transition(((int) ((OFInstructionGotoTable) in)
420 .getTableId().getValue()));
alshabib346b5b32015-03-06 00:42:16 -0800421 break;
422 case WRITE_METADATA:
Saurav Das86af8f12015-05-25 23:55:33 -0700423 OFInstructionWriteMetadata m = (OFInstructionWriteMetadata) in;
424 builder.writeMetadata(m.getMetadata().getValue(),
425 m.getMetadataMask().getValue());
alshabib346b5b32015-03-06 00:42:16 -0800426 break;
427 case WRITE_ACTIONS:
428 builder.deferred();
429 buildActions(((OFInstructionWriteActions) in).getActions(),
430 builder);
431 break;
432 case APPLY_ACTIONS:
433 builder.immediate();
434 buildActions(((OFInstructionApplyActions) in).getActions(),
435 builder);
436 break;
437 case CLEAR_ACTIONS:
438 builder.wipeDeferred();
439 break;
Cem Türker3baff672017-10-12 15:09:01 +0300440 case STAT_TRIGGER:
441 OFInstructionStatTrigger statTrigger = (OFInstructionStatTrigger) in;
442 buildStatTrigger(statTrigger.getThresholds(), statTrigger.getFlags(), builder);
443 break;
alshabib346b5b32015-03-06 00:42:16 -0800444 case EXPERIMENTER:
445 break;
446 case METER:
447 break;
448 default:
449 log.warn("Unknown instructions type {}", in.getType());
alshabib6b5cfec2014-09-18 17:42:18 -0700450 }
451 }
452
453 return builder.build();
454 }
455
Cem Türker3baff672017-10-12 15:09:01 +0300456 private TrafficTreatment.Builder buildStatTrigger(OFOxsList oxsList,
457 Set<OFStatTriggerFlags> flagsSet,
458 TrafficTreatment.Builder builder) {
459 Map<StatTriggerField, Long> statTriggerMap = Maps.newEnumMap(StatTriggerField.class);
460 for (OFOxs<?> ofOxs : oxsList) {
461 switch (ofOxs.getStatField().id) {
462 case DURATION:
463 U64 durationType = (U64) ofOxs.getValue();
464 statTriggerMap.put(DURATION, durationType.getValue());
465 break;
466 case FLOW_COUNT:
467 U32 flowCount = (U32) ofOxs.getValue();
468 statTriggerMap.put(FLOW_COUNT, flowCount.getValue());
469 break;
470 case PACKET_COUNT:
471 U64 packetCount = (U64) ofOxs.getValue();
472 statTriggerMap.put(PACKET_COUNT, packetCount.getValue());
473 break;
474 case BYTE_COUNT:
475 U64 byteCount = (U64) ofOxs.getValue();
476 statTriggerMap.put(BYTE_COUNT, byteCount.getValue());
477 break;
478 case IDLE_TIME:
479 U64 idleTime = (U64) ofOxs.getValue();
480 statTriggerMap.put(IDLE_TIME, idleTime.getValue());
481 break;
482 default:
483 log.warn("getStatField not supported {}", ofOxs.getStatField().id);
484 break;
485 }
486 }
487 StatTriggerFlag flag = null;
488 for (OFStatTriggerFlags flags : flagsSet) {
489 switch (flags) {
490 case PERIODIC:
491 flag = PERIODIC;
492 break;
493 case ONLY_FIRST:
494 flag = ONLY_FIRST;
495 break;
496 default:
497 log.warn("flag not supported {}", flags);
498 break;
499 }
500 }
501 if (!statTriggerMap.isEmpty() && flag != null) {
502 builder.add(Instructions.statTrigger(statTriggerMap, flag));
503 }
504 return builder;
505 }
506
Jian Lia0d9a172016-04-01 16:58:06 -0700507 /**
508 * Configures traffic treatment builder with a given collection of actions.
509 *
510 * @param actions a set of OpenFlow actions
511 * @param builder traffic treatment builder
512 * @param driverHandler driver handler
513 * @param deviceId device identifier
514 * @return configured traffic treatment builder
515 */
516 public static TrafficTreatment.Builder configureTreatmentBuilder(List<OFAction> actions,
517 TrafficTreatment.Builder builder,
518 DriverHandler driverHandler,
519 DeviceId deviceId) {
520 ExtensionTreatmentInterpreter interpreter;
Charles Chan14967c22015-12-07 11:11:50 -0800521 if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
Jian Lia0d9a172016-04-01 16:58:06 -0700522 interpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class);
Charles Chan14967c22015-12-07 11:11:50 -0800523 } else {
Jian Lia0d9a172016-04-01 16:58:06 -0700524 interpreter = null;
Charles Chan14967c22015-12-07 11:11:50 -0800525 }
526
alshabib346b5b32015-03-06 00:42:16 -0800527 for (OFAction act : actions) {
528 switch (act.getType()) {
529 case OUTPUT:
530 OFActionOutput out = (OFActionOutput) act;
531 builder.setOutput(
532 PortNumber.portNumber(out.getPort().getPortNumber()));
533 break;
534 case SET_VLAN_VID:
535 OFActionSetVlanVid vlan = (OFActionSetVlanVid) act;
536 builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan()));
537 break;
538 case SET_VLAN_PCP:
539 OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act;
540 builder.setVlanPcp(pcp.getVlanPcp().getValue());
541 break;
542 case SET_DL_DST:
543 OFActionSetDlDst dldst = (OFActionSetDlDst) act;
544 builder.setEthDst(
545 MacAddress.valueOf(dldst.getDlAddr().getLong()));
546 break;
547 case SET_DL_SRC:
548 OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act;
549 builder.setEthSrc(
550 MacAddress.valueOf(dlsrc.getDlAddr().getLong()));
alshabib346b5b32015-03-06 00:42:16 -0800551 break;
552 case SET_NW_DST:
553 OFActionSetNwDst nwdst = (OFActionSetNwDst) act;
554 IPv4Address di = nwdst.getNwAddr();
555 builder.setIpDst(Ip4Address.valueOf(di.getInt()));
556 break;
557 case SET_NW_SRC:
558 OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act;
559 IPv4Address si = nwsrc.getNwAddr();
560 builder.setIpSrc(Ip4Address.valueOf(si.getInt()));
561 break;
562 case EXPERIMENTER:
563 OFActionExperimenter exp = (OFActionExperimenter) act;
564 if (exp.getExperimenter() == 0x80005A06 ||
565 exp.getExperimenter() == 0x748771) {
566 OFActionCircuit ct = (OFActionCircuit) exp;
Yafit Hadar4cc65f72016-02-10 11:23:06 +0200567 CircuitSignalID circuitSignalID = ((OFOxmOchSigid) ct.getField()).getValue();
568 builder.add(Instructions.modL0Lambda(Lambda.ochSignal(
569 lookupGridType(circuitSignalID.getGridType()),
570 lookupChannelSpacing(circuitSignalID.getChannelSpacing()),
571 circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth())));
Jian Lia0d9a172016-04-01 16:58:06 -0700572 } else if (interpreter != null) {
573 builder.extension(interpreter.mapAction(exp), deviceId);
alshabib346b5b32015-03-06 00:42:16 -0800574 } else {
575 log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter());
576 }
577 break;
578 case SET_FIELD:
579 OFActionSetField setField = (OFActionSetField) act;
Jian Lia0d9a172016-04-01 16:58:06 -0700580 handleSetField(builder, setField, driverHandler, deviceId);
alshabib346b5b32015-03-06 00:42:16 -0800581 break;
582 case POP_MPLS:
583 OFActionPopMpls popMpls = (OFActionPopMpls) act;
Ray Milkey84d5a292016-02-22 14:04:01 -0800584 builder.popMpls(new EthType(popMpls.getEthertype().getValue()));
alshabib346b5b32015-03-06 00:42:16 -0800585 break;
586 case PUSH_MPLS:
587 builder.pushMpls();
588 break;
589 case COPY_TTL_IN:
590 builder.copyTtlIn();
591 break;
592 case COPY_TTL_OUT:
593 builder.copyTtlOut();
594 break;
595 case DEC_MPLS_TTL:
596 builder.decMplsTtl();
597 break;
598 case DEC_NW_TTL:
599 builder.decNwTtl();
600 break;
601 case GROUP:
602 OFActionGroup group = (OFActionGroup) act;
Yi Tsengfa394de2017-02-01 11:26:40 -0800603 builder.group(new GroupId(group.getGroup().getGroupNumber()));
alshabib346b5b32015-03-06 00:42:16 -0800604 break;
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200605 case SET_QUEUE:
606 OFActionSetQueue setQueue = (OFActionSetQueue) act;
607 builder.setQueue(setQueue.getQueueId());
608 break;
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200609 case ENQUEUE:
610 OFActionEnqueue enqueue = (OFActionEnqueue) act;
Jian Liffef5002016-04-04 23:27:37 -0700611 builder.setQueue(enqueue.getQueueId(),
612 PortNumber.portNumber(enqueue.getPort().getPortNumber()));
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200613 break;
Jonathan Hart67fc0972015-03-19 15:21:20 -0700614 case STRIP_VLAN:
alshabib346b5b32015-03-06 00:42:16 -0800615 case POP_VLAN:
616 builder.popVlan();
617 break;
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700618 case PUSH_VLAN:
Konstantinos Kanonakis9215ff22016-11-04 13:28:11 -0500619 OFActionPushVlan pushVlan = (OFActionPushVlan) act;
620 builder.pushVlan(new EthType((short) pushVlan.getEthertype().getValue()));
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700621 break;
cansu.toprak409289d2017-10-27 10:04:05 +0300622 case METER:
623 OFActionMeter actionMeter = (OFActionMeter) act;
624 builder.meter(MeterId.meterId(actionMeter.getMeterId()));
625 break;
alshabib346b5b32015-03-06 00:42:16 -0800626 case SET_TP_DST:
627 case SET_TP_SRC:
628 case POP_PBB:
629 case PUSH_PBB:
alshabib346b5b32015-03-06 00:42:16 -0800630 case SET_MPLS_LABEL:
631 case SET_MPLS_TC:
632 case SET_MPLS_TTL:
633 case SET_NW_ECN:
634 case SET_NW_TOS:
635 case SET_NW_TTL:
alshabib346b5b32015-03-06 00:42:16 -0800636
alshabib346b5b32015-03-06 00:42:16 -0800637 default:
638 log.warn("Action type {} not yet implemented.", act.getType());
639 }
640 }
641 return builder;
642 }
643
Jian Lia0d9a172016-04-01 16:58:06 -0700644 private TrafficTreatment.Builder buildActions(List<OFAction> actions,
645 TrafficTreatment.Builder builder) {
Jian Lia0d9a172016-04-01 16:58:06 -0700646 return configureTreatmentBuilder(actions, builder, driverHandler, deviceId);
647 }
648
Charles Chancad338a2016-09-16 18:03:11 -0700649 // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES
Jian Lia0d9a172016-04-01 16:58:06 -0700650 private static void handleSetField(TrafficTreatment.Builder builder,
651 OFActionSetField action,
652 DriverHandler driverHandler,
653 DeviceId deviceId) {
Charles Chan14967c22015-12-07 11:11:50 -0800654 ExtensionTreatmentInterpreter treatmentInterpreter;
655 if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
656 treatmentInterpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class);
657 } else {
658 treatmentInterpreter = null;
659 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700660 OFOxm<?> oxm = action.getField();
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800661 switch (oxm.getMatchField().id) {
662 case VLAN_PCP:
663 @SuppressWarnings("unchecked")
664 OFOxm<VlanPcp> vlanpcp = (OFOxm<VlanPcp>) oxm;
665 builder.setVlanPcp(vlanpcp.getValue().getValue());
666 break;
667 case VLAN_VID:
Charles Chan4211baa2016-04-20 17:10:40 -0700668 if (treatmentInterpreter != null) {
669 try {
670 builder.extension(treatmentInterpreter.mapAction(action), deviceId);
671 break;
672 } catch (UnsupportedOperationException e) {
673 log.debug("Unsupported action extension; defaulting to native OF");
674 }
Charles Chan14967c22015-12-07 11:11:50 -0800675 }
alshabib44852fb2016-04-15 15:56:51 -0700676 @SuppressWarnings("unchecked")
677 OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm;
678 builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan()));
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800679 break;
680 case ETH_DST:
681 @SuppressWarnings("unchecked")
682 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethdst =
683 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
684 builder.setEthDst(MacAddress.valueOf(ethdst.getValue().getLong()));
685 break;
686 case ETH_SRC:
687 @SuppressWarnings("unchecked")
688 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethsrc =
689 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
690 builder.setEthSrc(MacAddress.valueOf(ethsrc.getValue().getLong()));
691 break;
692 case IPV4_DST:
693 @SuppressWarnings("unchecked")
694 OFOxm<IPv4Address> ip4dst = (OFOxm<IPv4Address>) oxm;
695 builder.setIpDst(Ip4Address.valueOf(ip4dst.getValue().getInt()));
696 break;
697 case IPV4_SRC:
698 @SuppressWarnings("unchecked")
699 OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm;
700 builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt()));
701 break;
sangho3f97a17d2015-01-29 22:56:29 -0800702 case MPLS_LABEL:
703 @SuppressWarnings("unchecked")
704 OFOxm<U32> labelId = (OFOxm<U32>) oxm;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100705 builder.setMpls(MplsLabel.mplsLabel((int) labelId.getValue().getValue()));
sangho3f97a17d2015-01-29 22:56:29 -0800706 break;
Saurav Das73a7dd42015-08-19 22:20:31 -0700707 case MPLS_BOS:
708 @SuppressWarnings("unchecked")
Pier Ventre23f78672016-11-15 08:46:34 -0800709 OFOxm<OFBooleanValue> mplsBos = (OFOxm<OFBooleanValue>) oxm;
710 builder.setMplsBos(mplsBos.getValue().getValue());
Saurav Das73a7dd42015-08-19 22:20:31 -0700711 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700712 case TUNNEL_ID:
713 @SuppressWarnings("unchecked")
714 OFOxm<U64> tunnelId = (OFOxm<U64>) oxm;
715 builder.setTunnelId(tunnelId.getValue().getValue());
716 break;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700717 case TCP_DST:
718 @SuppressWarnings("unchecked")
719 OFOxm<TransportPort> tcpdst = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700720 builder.setTcpDst(TpPort.tpPort(tcpdst.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700721 break;
722 case TCP_SRC:
723 @SuppressWarnings("unchecked")
724 OFOxm<TransportPort> tcpsrc = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700725 builder.setTcpSrc(TpPort.tpPort(tcpsrc.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700726 break;
727 case UDP_DST:
728 @SuppressWarnings("unchecked")
729 OFOxm<TransportPort> udpdst = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700730 builder.setUdpDst(TpPort.tpPort(udpdst.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700731 break;
732 case UDP_SRC:
733 @SuppressWarnings("unchecked")
734 OFOxm<TransportPort> udpsrc = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700735 builder.setUdpSrc(TpPort.tpPort(udpsrc.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700736 break;
Jonathan Hart3c259162015-10-21 21:31:19 -0700737 case TUNNEL_IPV4_DST:
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530738 case NSP:
739 case NSI:
740 case NSH_C1:
741 case NSH_C2:
742 case NSH_C3:
743 case NSH_C4:
744 case NSH_MDTYPE:
745 case NSH_NP:
746 case ENCAP_ETH_SRC:
747 case ENCAP_ETH_DST:
748 case ENCAP_ETH_TYPE:
749 case TUN_GPE_NP:
Jian Liffef5002016-04-04 23:27:37 -0700750 if (treatmentInterpreter != null) {
751 try {
752 builder.extension(treatmentInterpreter.mapAction(action), deviceId);
753 } catch (UnsupportedOperationException e) {
alshabib44852fb2016-04-15 15:56:51 -0700754 log.debug(e.getMessage());
Jian Liffef5002016-04-04 23:27:37 -0700755 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700756 }
757 break;
Yafit Hadar73514612015-11-04 10:14:21 +0200758 case EXP_ODU_SIG_ID:
759 @SuppressWarnings("unchecked")
760 OFOxm<OduSignalID> oduID = (OFOxm<OduSignalID>) oxm;
761 OduSignalID oduSignalID = oduID.getValue();
762 OduSignalId oduSignalId = OduSignalId.oduSignalId(oduSignalID.getTpn(),
763 oduSignalID.getTslen(),
764 oduSignalID.getTsmap());
765 builder.add(modL1OduSignalId(oduSignalId));
766 break;
767 case EXP_OCH_SIG_ID:
768 try {
769 @SuppressWarnings("unchecked")
770 OFOxm<CircuitSignalID> ochId = (OFOxm<CircuitSignalID>) oxm;
771 CircuitSignalID circuitSignalID = ochId.getValue();
772 builder.add(modL0Lambda(Lambda.ochSignal(
773 lookupGridType(circuitSignalID.getGridType()),
774 lookupChannelSpacing(circuitSignalID.getChannelSpacing()),
775 circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth())));
776 } catch (NoMappingFoundException e) {
777 log.warn(e.getMessage());
778 break;
779 }
780 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800781 case ARP_OP:
lishuai67574ce2016-05-12 16:39:59 +0800782 @SuppressWarnings("unchecked")
783 OFOxm<org.projectfloodlight.openflow.types.ArpOpcode> arpop =
784 (OFOxm<org.projectfloodlight.openflow.types.ArpOpcode>) oxm;
785 builder.setArpOp((short) arpop.getValue().getOpcode());
786 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800787 case ARP_SHA:
lishuai67574ce2016-05-12 16:39:59 +0800788 @SuppressWarnings("unchecked")
789 OFOxm<org.projectfloodlight.openflow.types.MacAddress> arpsha =
790 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
791 builder.setArpSha(MacAddress.valueOf(arpsha.getValue().getLong()));
792 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800793 case ARP_SPA:
lishuai67574ce2016-05-12 16:39:59 +0800794 @SuppressWarnings("unchecked")
795 OFOxm<IPv4Address> arpspa = (OFOxm<IPv4Address>) oxm;
796 builder.setArpSpa(Ip4Address.valueOf(arpspa.getValue().getInt()));
797 break;
Charles Chancad338a2016-09-16 18:03:11 -0700798 case OFDPA_MPLS_TYPE:
Pier Ventre6f630052016-10-18 09:58:41 -0700799 case OFDPA_OVID:
Pier Ventre9cf536b2016-10-21 13:30:18 -0700800 case OFDPA_MPLS_L2_PORT:
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -0700801 case OFDPA_ALLOW_VLAN_TRANSLATION:
Pier Ventredb252cc2016-10-21 21:54:26 -0700802 case OFDPA_QOS_INDEX:
Charles Chancad338a2016-09-16 18:03:11 -0700803 if (treatmentInterpreter != null) {
804 try {
805 builder.extension(treatmentInterpreter.mapAction(action), deviceId);
806 break;
807 } catch (UnsupportedOperationException e) {
808 log.warn("Unsupported action extension");
809 }
810 }
811 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800812 case ARP_THA:
813 case ARP_TPA:
814 case BSN_EGR_PORT_GROUP_ID:
815 case BSN_GLOBAL_VRF_ALLOWED:
816 case BSN_IN_PORTS_128:
817 case BSN_L3_DST_CLASS_ID:
818 case BSN_L3_INTERFACE_CLASS_ID:
819 case BSN_L3_SRC_CLASS_ID:
820 case BSN_LAG_ID:
821 case BSN_TCP_FLAGS:
822 case BSN_UDF0:
823 case BSN_UDF1:
824 case BSN_UDF2:
825 case BSN_UDF3:
826 case BSN_UDF4:
827 case BSN_UDF5:
828 case BSN_UDF6:
829 case BSN_UDF7:
830 case BSN_VLAN_XLATE_PORT_GROUP_ID:
831 case BSN_VRF:
832 case ETH_TYPE:
833 case ICMPV4_CODE:
834 case ICMPV4_TYPE:
835 case ICMPV6_CODE:
836 case ICMPV6_TYPE:
837 case IN_PHY_PORT:
838 case IN_PORT:
839 case IPV6_DST:
840 case IPV6_FLABEL:
841 case IPV6_ND_SLL:
842 case IPV6_ND_TARGET:
843 case IPV6_ND_TLL:
844 case IPV6_SRC:
845 case IP_DSCP:
846 case IP_ECN:
847 case IP_PROTO:
848 case METADATA:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800849 case MPLS_TC:
850 case OCH_SIGID:
851 case OCH_SIGID_BASIC:
852 case OCH_SIGTYPE:
853 case OCH_SIGTYPE_BASIC:
854 case SCTP_DST:
855 case SCTP_SRC:
Yafit Hadar73514612015-11-04 10:14:21 +0200856 case EXP_ODU_SIGTYPE:
857 case EXP_OCH_SIGTYPE:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800858 default:
859 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
860 break;
861 }
862 }
863
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700864 // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES
alshabib6b5cfec2014-09-18 17:42:18 -0700865 private TrafficSelector buildSelector() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800866 MacAddress mac;
867 Ip4Prefix ip4Prefix;
868 Ip6Address ip6Address;
869 Ip6Prefix ip6Prefix;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800870 Ip4Address ip;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800871
Charles Chan14967c22015-12-07 11:11:50 -0800872 ExtensionSelectorInterpreter selectorInterpreter;
873 if (driverHandler.hasBehaviour(ExtensionSelectorInterpreter.class)) {
874 selectorInterpreter = driverHandler.behaviour(ExtensionSelectorInterpreter.class);
875 } else {
876 selectorInterpreter = null;
877 }
878
tom9a693fd2014-10-03 11:32:19 -0700879 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700880 for (MatchField<?> field : match.getMatchFields()) {
881 switch (field.id) {
882 case IN_PORT:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800883 builder.matchInPort(PortNumber
alshabib010c31d2014-09-26 10:01:12 -0700884 .portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700885 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800886 case IN_PHY_PORT:
887 builder.matchInPhyPort(PortNumber
888 .portNumber(match.get(MatchField.IN_PHY_PORT).getPortNumber()));
889 break;
890 case METADATA:
891 long metadata =
892 match.get(MatchField.METADATA).getValue().getValue();
893 builder.matchMetadata(metadata);
894 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700895 case ETH_DST:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800896 if (match.isPartiallyMasked(MatchField.ETH_DST)) {
897 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
898 match.getMasked(MatchField.ETH_DST);
899 builder.matchEthDstMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
900 MacAddress.valueOf(maskedMac.getMask().getLong()));
901 } else {
902 mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
903 builder.matchEthDst(mac);
904 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800905 break;
906 case ETH_SRC:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800907 if (match.isPartiallyMasked(MatchField.ETH_SRC)) {
908 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
909 match.getMasked(MatchField.ETH_SRC);
910 builder.matchEthSrcMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
911 MacAddress.valueOf(maskedMac.getMask().getLong()));
912 } else {
913 mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
914 builder.matchEthSrc(mac);
915 }
alshabib6b5cfec2014-09-18 17:42:18 -0700916 break;
917 case ETH_TYPE:
918 int ethType = match.get(MatchField.ETH_TYPE).getValue();
Jonathan Hart8cf212a2015-10-29 17:42:03 -0700919 builder.matchEthType((short) ethType);
alshabib6b5cfec2014-09-18 17:42:18 -0700920 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700921 case VLAN_VID:
Charles Chan14967c22015-12-07 11:11:50 -0800922 if (selectorInterpreter != null &&
923 selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -0700924 if (isOF13OrLater(match)) {
Charles Chan14967c22015-12-07 11:11:50 -0800925 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.VLAN_VID);
926 builder.extension(selectorInterpreter.mapOxm(oxm),
Jonathan Harte4e74f02016-03-03 12:57:40 -0800927 deviceId);
Charles Chan14967c22015-12-07 11:11:50 -0800928 } else {
929 break;
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800930 }
931 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800932 VlanId vlanId = null;
933 if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
934 Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
935 if (masked.getValue().equals(OFVlanVidMatch.PRESENT)
936 && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
937 vlanId = VlanId.ANY;
938 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700939 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800940 if (!match.get(MatchField.VLAN_VID).isPresentBitSet()) {
941 vlanId = VlanId.NONE;
942 } else {
943 vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
944 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700945 }
Charles Chan14967c22015-12-07 11:11:50 -0800946 if (vlanId != null) {
947 builder.matchVlanId(vlanId);
948 }
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800949 }
alshabib6b5cfec2014-09-18 17:42:18 -0700950 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800951 case VLAN_PCP:
952 byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
953 builder.matchVlanPcp(vlanPcp);
954 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800955 case IP_DSCP:
956 byte ipDscp = match.get(MatchField.IP_DSCP).getDscpValue();
957 builder.matchIPDscp(ipDscp);
958 break;
959 case IP_ECN:
960 byte ipEcn = match.get(MatchField.IP_ECN).getEcnValue();
961 builder.matchIPEcn(ipEcn);
962 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800963 case IP_PROTO:
964 short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
965 builder.matchIPProtocol((byte) proto);
966 break;
967 case IPV4_SRC:
968 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
969 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800970 ip4Prefix = Ip4Prefix.valueOf(
971 maskedIp.getValue().getInt(),
972 maskedIp.getMask().asCidrMaskLength());
973 } else {
974 ip4Prefix = Ip4Prefix.valueOf(
975 match.get(MatchField.IPV4_SRC).getInt(),
976 Ip4Prefix.MAX_MASK_LENGTH);
977 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800978 builder.matchIPSrc(ip4Prefix);
979 break;
980 case IPV4_DST:
981 if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
982 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800983 ip4Prefix = Ip4Prefix.valueOf(
984 maskedIp.getValue().getInt(),
985 maskedIp.getMask().asCidrMaskLength());
986 } else {
987 ip4Prefix = Ip4Prefix.valueOf(
988 match.get(MatchField.IPV4_DST).getInt(),
989 Ip4Prefix.MAX_MASK_LENGTH);
990 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800991 builder.matchIPDst(ip4Prefix);
Jonathan Hart34bc6142014-10-17 11:00:43 -0700992 break;
993 case TCP_SRC:
Andreas Gilbert75b882f72017-02-03 09:58:07 +0100994 if (match.isPartiallyMasked(MatchField.TCP_SRC)) {
995 Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort =
996 match.getMasked(MatchField.TCP_SRC);
997 builder.matchTcpSrcMasked(TpPort.tpPort(maskedPort.getValue().getPort()),
998 TpPort.tpPort(maskedPort.getMask().getPort()));
999 } else {
1000 builder.matchTcpSrc(TpPort.tpPort(match.get(MatchField.TCP_SRC).getPort()));
1001 }
Jonathan Hart34bc6142014-10-17 11:00:43 -07001002 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001003 case TCP_DST:
Andreas Gilbert75b882f72017-02-03 09:58:07 +01001004 if (match.isPartiallyMasked(MatchField.TCP_DST)) {
1005 Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort =
1006 match.getMasked(MatchField.TCP_DST);
1007 builder.matchTcpDstMasked(TpPort.tpPort(maskedPort.getValue().getPort()),
1008 TpPort.tpPort(maskedPort.getMask().getPort()));
1009 } else {
1010 builder.matchTcpDst(TpPort.tpPort(match.get(MatchField.TCP_DST).getPort()));
1011 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001012 break;
1013 case UDP_SRC:
Andreas Gilbert75b882f72017-02-03 09:58:07 +01001014 if (match.isPartiallyMasked(MatchField.UDP_SRC)) {
1015 Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort =
1016 match.getMasked(MatchField.UDP_SRC);
1017 builder.matchUdpSrcMasked(TpPort.tpPort(maskedPort.getValue().getPort()),
1018 TpPort.tpPort(maskedPort.getMask().getPort()));
1019 } else {
1020 builder.matchUdpSrc(TpPort.tpPort(match.get(MatchField.UDP_SRC).getPort()));
1021 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001022 break;
1023 case UDP_DST:
Andreas Gilbert75b882f72017-02-03 09:58:07 +01001024 if (match.isPartiallyMasked(MatchField.UDP_DST)) {
1025 Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort =
1026 match.getMasked(MatchField.UDP_DST);
1027 builder.matchUdpDstMasked(TpPort.tpPort(maskedPort.getValue().getPort()),
1028 TpPort.tpPort(maskedPort.getMask().getPort()));
1029 } else {
1030 builder.matchUdpDst(TpPort.tpPort(match.get(MatchField.UDP_DST).getPort()));
1031 }
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -07001032 break;
Michele Santuari4b6019e2014-12-19 11:31:45 +01001033 case MPLS_LABEL:
1034 builder.matchMplsLabel(MplsLabel.mplsLabel((int) match.get(MatchField.MPLS_LABEL)
1035 .getValue()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001036 break;
Saurav Dasffc5bbc2015-08-18 23:30:19 -07001037 case MPLS_BOS:
1038 builder.matchMplsBos(match.get(MatchField.MPLS_BOS).getValue());
1039 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001040 case SCTP_SRC:
Andreas Gilbert75b882f72017-02-03 09:58:07 +01001041 if (match.isPartiallyMasked(MatchField.SCTP_SRC)) {
1042 Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort =
1043 match.getMasked(MatchField.SCTP_SRC);
1044 builder.matchSctpSrcMasked(TpPort.tpPort(maskedPort.getValue().getPort()),
1045 TpPort.tpPort(maskedPort.getMask().getPort()));
1046 } else {
1047 builder.matchSctpSrc(TpPort.tpPort(match.get(MatchField.SCTP_SRC).getPort()));
1048 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001049 break;
1050 case SCTP_DST:
Andreas Gilbert75b882f72017-02-03 09:58:07 +01001051 if (match.isPartiallyMasked(MatchField.SCTP_DST)) {
1052 Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort =
1053 match.getMasked(MatchField.SCTP_DST);
1054 builder.matchSctpDstMasked(TpPort.tpPort(maskedPort.getValue().getPort()),
1055 TpPort.tpPort(maskedPort.getMask().getPort()));
1056 } else {
1057 builder.matchSctpDst(TpPort.tpPort(match.get(MatchField.SCTP_DST).getPort()));
1058 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001059 break;
1060 case ICMPV4_TYPE:
1061 byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
1062 builder.matchIcmpType(icmpType);
1063 break;
1064 case ICMPV4_CODE:
1065 byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode();
1066 builder.matchIcmpCode(icmpCode);
1067 break;
1068 case IPV6_SRC:
1069 if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
1070 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
1071 ip6Prefix = Ip6Prefix.valueOf(
1072 maskedIp.getValue().getBytes(),
1073 maskedIp.getMask().asCidrMaskLength());
1074 } else {
1075 ip6Prefix = Ip6Prefix.valueOf(
1076 match.get(MatchField.IPV6_SRC).getBytes(),
1077 Ip6Prefix.MAX_MASK_LENGTH);
1078 }
1079 builder.matchIPv6Src(ip6Prefix);
1080 break;
1081 case IPV6_DST:
1082 if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
1083 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
1084 ip6Prefix = Ip6Prefix.valueOf(
1085 maskedIp.getValue().getBytes(),
1086 maskedIp.getMask().asCidrMaskLength());
1087 } else {
1088 ip6Prefix = Ip6Prefix.valueOf(
1089 match.get(MatchField.IPV6_DST).getBytes(),
1090 Ip6Prefix.MAX_MASK_LENGTH);
1091 }
1092 builder.matchIPv6Dst(ip6Prefix);
1093 break;
1094 case IPV6_FLABEL:
1095 int flowLabel =
1096 match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue();
1097 builder.matchIPv6FlowLabel(flowLabel);
1098 break;
1099 case ICMPV6_TYPE:
1100 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
1101 builder.matchIcmpv6Type(icmpv6type);
1102 break;
1103 case ICMPV6_CODE:
1104 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
1105 builder.matchIcmpv6Code(icmpv6code);
1106 break;
1107 case IPV6_ND_TARGET:
1108 ip6Address =
1109 Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes());
1110 builder.matchIPv6NDTargetAddress(ip6Address);
1111 break;
1112 case IPV6_ND_SLL:
1113 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong());
1114 builder.matchIPv6NDSourceLinkLayerAddress(mac);
1115 break;
1116 case IPV6_ND_TLL:
1117 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong());
1118 builder.matchIPv6NDTargetLinkLayerAddress(mac);
1119 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001120 case IPV6_EXTHDR:
Charles M.C. Chan2184de12015-04-26 02:24:53 +08001121 builder.matchIPv6ExthdrFlags((short) match.get(MatchField.IPV6_EXTHDR)
Hyunsun Moona08c5d02015-07-14 17:53:00 -07001122 .getValue());
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001123 break;
Marc De Leenheer49087752014-10-23 13:54:09 -07001124 case OCH_SIGID:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -07001125 CircuitSignalID sigId = match.get(MatchField.OCH_SIGID);
1126 builder.add(matchLambda(Lambda.ochSignal(
Sho SHIMIZUc17042d2015-05-28 12:07:23 -07001127 lookupGridType(sigId.getGridType()), lookupChannelSpacing(sigId.getChannelSpacing()),
Marc De Leenheer0b8b2ef2015-08-03 15:39:00 -07001128 sigId.getChannelNumber(), sigId.getSpectralWidth())
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -07001129 ));
Marc De Leenheer49087752014-10-23 13:54:09 -07001130 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -08001131 case OCH_SIGTYPE:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -07001132 U8 sigType = match.get(MatchField.OCH_SIGTYPE);
Sho SHIMIZUc17042d2015-05-28 12:07:23 -07001133 builder.add(matchOchSignalType(lookupOchSignalType((byte) sigType.getValue())));
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -08001134 break;
Yafit Hadar73514612015-11-04 10:14:21 +02001135 case EXP_OCH_SIG_ID:
1136 try {
1137 CircuitSignalID expSigId = match.get(MatchField.EXP_OCH_SIG_ID);
1138 builder.add(matchLambda(Lambda.ochSignal(
1139 lookupGridType(expSigId.getGridType()), lookupChannelSpacing(expSigId.getChannelSpacing()),
1140 expSigId.getChannelNumber(), expSigId.getSpectralWidth())));
1141 } catch (NoMappingFoundException e) {
1142 log.warn(e.getMessage());
1143 break;
1144 }
1145 break;
1146 case EXP_OCH_SIGTYPE:
1147 try {
1148 U8 expOchSigType = match.get(MatchField.EXP_OCH_SIGTYPE);
1149 builder.add(matchOchSignalType(lookupOchSignalType((byte) expOchSigType.getValue())));
1150 } catch (NoMappingFoundException e) {
1151 log.warn(e.getMessage());
1152 break;
1153 }
1154 break;
1155 case EXP_ODU_SIG_ID:
1156 OduSignalId oduSignalId = OduSignalId.oduSignalId(match.get(MatchField.EXP_ODU_SIG_ID).getTpn(),
1157 match.get(MatchField.EXP_ODU_SIG_ID).getTslen(),
1158 match.get(MatchField.EXP_ODU_SIG_ID).getTsmap());
1159 builder.add(matchOduSignalId(oduSignalId));
Frank Wang5733c382017-03-28 10:15:18 +08001160 break;
Yafit Hadar73514612015-11-04 10:14:21 +02001161 case EXP_ODU_SIGTYPE:
1162 try {
1163 U8 oduSigType = match.get(MatchField.EXP_ODU_SIGTYPE);
1164 builder.add(matchOduSignalType(lookupOduSignalType((byte) oduSigType.getValue())));
1165 } catch (NoMappingFoundException e) {
1166 log.warn(e.getMessage());
1167 break;
1168 }
1169 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -07001170 case TUNNEL_ID:
1171 long tunnelId = match.get(MatchField.TUNNEL_ID).getValue();
1172 builder.matchTunnelId(tunnelId);
1173 break;
BitOhenryb40129a2015-11-30 12:41:18 +08001174 case ARP_OP:
1175 int arpOp = match.get(MatchField.ARP_OP).getOpcode();
1176 builder.matchArpOp(arpOp);
1177 break;
BitOhenrya331b182015-11-23 08:39:37 +08001178 case ARP_SHA:
1179 mac = MacAddress.valueOf(match.get(MatchField.ARP_SHA).getLong());
1180 builder.matchArpSha(mac);
1181 break;
BitOhenry296b4542015-11-24 08:41:58 +08001182 case ARP_SPA:
1183 ip = Ip4Address.valueOf(match.get(MatchField.ARP_SPA).getInt());
1184 builder.matchArpSpa(ip);
1185 break;
BitOhenry76430852015-11-20 19:04:49 +08001186 case ARP_THA:
1187 mac = MacAddress.valueOf(match.get(MatchField.ARP_THA).getLong());
1188 builder.matchArpTha(mac);
1189 break;
BitOhenryc1e5fcc2015-11-23 20:47:53 +08001190 case ARP_TPA:
1191 ip = Ip4Address.valueOf(match.get(MatchField.ARP_TPA).getInt());
1192 builder.matchArpTpa(ip);
1193 break;
Phaneendra Manda8db7d092016-06-04 00:17:24 +05301194 case NSP:
1195 if (selectorInterpreter != null) {
1196 try {
1197 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.NSP);
1198 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
1199 } catch (UnsupportedOperationException e) {
1200 log.debug(e.getMessage());
1201 }
1202 }
1203 break;
1204 case NSI:
1205 if (selectorInterpreter != null) {
1206 try {
1207 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.NSI);
1208 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
1209 } catch (UnsupportedOperationException e) {
1210 log.debug(e.getMessage());
1211 }
1212 }
1213 break;
1214 case ENCAP_ETH_TYPE:
1215 if (selectorInterpreter != null) {
1216 try {
1217 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.ENCAP_ETH_TYPE);
1218 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
1219 } catch (UnsupportedOperationException e) {
1220 log.debug(e.getMessage());
1221 }
1222 }
1223 break;
Frank Wang5733c382017-03-28 10:15:18 +08001224 case CONNTRACK_STATE:
1225 if (selectorInterpreter != null &&
1226 selectorInterpreter.supported(ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_STATE.type())) {
1227 try {
1228 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.CONNTRACK_STATE);
1229 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
1230 } catch (UnsupportedOperationException e) {
1231 log.debug(e.getMessage());
1232 }
1233 }
1234 break;
1235 case CONNTRACK_ZONE:
1236 if (selectorInterpreter != null &&
1237 selectorInterpreter.supported(ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_ZONE.type())) {
1238 try {
1239 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.CONNTRACK_ZONE);
1240 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
1241 } catch (UnsupportedOperationException e) {
1242 log.debug(e.getMessage());
1243 }
1244 }
1245 break;
1246 case CONNTRACK_MARK:
1247 if (selectorInterpreter != null &&
1248 selectorInterpreter.supported(ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_MARK.type())) {
1249 try {
1250 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.CONNTRACK_MARK);
1251 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
1252 } catch (UnsupportedOperationException e) {
1253 log.debug(e.getMessage());
1254 }
1255 }
1256 break;
Pier Ventre6f630052016-10-18 09:58:41 -07001257 case OFDPA_OVID:
1258 if (selectorInterpreter != null &&
1259 selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_OVID.type())) {
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -07001260 if (isOF13OrLater(match)) {
Pier Ventre6f630052016-10-18 09:58:41 -07001261 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.OFDPA_OVID);
1262 builder.extension(selectorInterpreter.mapOxm(oxm),
1263 deviceId);
1264 } else {
1265 break;
1266 }
1267 }
1268 break;
Pier Ventre9cf536b2016-10-21 13:30:18 -07001269 case OFDPA_MPLS_L2_PORT:
1270 if (selectorInterpreter != null &&
1271 selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_MPLS_L2_PORT.type())) {
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -07001272 if (isOF13OrLater(match)) {
Pier Ventre9cf536b2016-10-21 13:30:18 -07001273 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.OFDPA_MPLS_L2_PORT);
1274 builder.extension(selectorInterpreter.mapOxm(oxm),
1275 deviceId);
1276 } else {
1277 break;
1278 }
1279 }
1280 break;
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -07001281 case OFDPA_ALLOW_VLAN_TRANSLATION:
1282 if (selectorInterpreter != null &&
1283 selectorInterpreter.supported(
1284 ExtensionSelectorTypes.OFDPA_MATCH_ALLOW_VLAN_TRANSLATION.type())) {
1285 if (isOF13OrLater(match)) {
1286 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.OFDPA_ALLOW_VLAN_TRANSLATION);
1287 builder.extension(selectorInterpreter.mapOxm(oxm),
1288 deviceId);
1289 } else {
1290 break;
1291 }
1292 }
1293 break;
1294 case OFDPA_ACTSET_OUTPUT:
1295 if (selectorInterpreter != null &&
1296 selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_ACTSET_OUTPUT.type())) {
1297 if (isOF13OrLater(match)) {
1298 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.OFDPA_ACTSET_OUTPUT);
1299 builder.extension(selectorInterpreter.mapOxm(oxm),
1300 deviceId);
1301 } else {
1302 break;
1303 }
1304 }
1305 break;
alshabib6b5cfec2014-09-18 17:42:18 -07001306 case MPLS_TC:
alshabib6b5cfec2014-09-18 17:42:18 -07001307 default:
1308 log.warn("Match type {} not yet implemented.", field.id);
alshabib6b5cfec2014-09-18 17:42:18 -07001309 }
1310 }
1311 return builder.build();
1312 }
Jonathan Hart3c259162015-10-21 21:31:19 -07001313
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -07001314 /**
1315 * @param obj OpenFlow object to test
1316 * @return true if OFObject is OF_13 or later
1317 */
1318 private static boolean isOF13OrLater(OFObject obj) {
1319 return obj.getVersion().wireVersion >= OFVersion.OF_13.wireVersion;
1320 }
1321
Claudine Chiu20cbd452017-08-30 19:23:11 -04001322 /**
1323 * Retrieves the driver handler for the specified device.
1324 *
1325 * @param deviceId device identifier
Rodrigo Duarte Sousae37d1292017-08-29 17:01:24 -03001326 * @param driverService service handle for the driver service
Claudine Chiu20cbd452017-08-30 19:23:11 -04001327 * @return driver handler
1328 */
Rodrigo Duarte Sousae37d1292017-08-29 17:01:24 -03001329 protected static DriverHandler getDriver(DeviceId deviceId, DriverService driverService) {
Claudine Chiu20cbd452017-08-30 19:23:11 -04001330 Driver driver = driverService.getDriver(deviceId);
1331 DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, deviceId));
Jonathan Hart3c259162015-10-21 21:31:19 -07001332 return handler;
1333 }
alshabib6b5cfec2014-09-18 17:42:18 -07001334}