blob: b63dfe7de10b8eb143850308903e9b83facbe011 [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;
Gamze Abaka2bc10ae2019-02-27 12:07:43 +000085import org.projectfloodlight.openflow.protocol.instruction.OFInstructionMeter;
Cem Türker3baff672017-10-12 15:09:01 +030086import org.projectfloodlight.openflow.protocol.instruction.OFInstructionStatTrigger;
alshabib346b5b32015-03-06 00:42:16 -080087import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteActions;
Saurav Das86af8f12015-05-25 23:55:33 -070088import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteMetadata;
alshabib6b5cfec2014-09-18 17:42:18 -070089import org.projectfloodlight.openflow.protocol.match.Match;
90import org.projectfloodlight.openflow.protocol.match.MatchField;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080091import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
Yafit Hadar4cc65f72016-02-10 11:23:06 +020092import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigid;
Cem Türker3baff672017-10-12 15:09:01 +030093import org.projectfloodlight.openflow.protocol.oxs.OFOxs;
alshabib346b5b32015-03-06 00:42:16 -080094import org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070095import org.projectfloodlight.openflow.types.CircuitSignalID;
alshabib6b5cfec2014-09-18 17:42:18 -070096import org.projectfloodlight.openflow.types.IPv4Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080097import org.projectfloodlight.openflow.types.IPv6Address;
Thiago Santos4a69ef82018-08-21 21:18:05 -070098import org.projectfloodlight.openflow.types.IpDscp;
Jonathan Hart0e12fad2014-10-17 14:54:58 -070099import org.projectfloodlight.openflow.types.Masked;
Pier Ventre23f78672016-11-15 08:46:34 -0800100import org.projectfloodlight.openflow.types.OFBooleanValue;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800101import org.projectfloodlight.openflow.types.OFVlanVidMatch;
Jonathan Harte4e74f02016-03-03 12:57:40 -0800102import org.projectfloodlight.openflow.types.OduSignalID;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700103import org.projectfloodlight.openflow.types.TransportPort;
sangho3f97a17d2015-01-29 22:56:29 -0800104import org.projectfloodlight.openflow.types.U32;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700105import org.projectfloodlight.openflow.types.U64;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700106import org.projectfloodlight.openflow.types.U8;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800107import org.projectfloodlight.openflow.types.VlanPcp;
alshabib6b5cfec2014-09-18 17:42:18 -0700108import org.slf4j.Logger;
Jian Lia0d9a172016-04-01 16:58:06 -0700109import org.slf4j.LoggerFactory;
alshabib6b5cfec2014-09-18 17:42:18 -0700110
Jonathan Hart8cf212a2015-10-29 17:42:03 -0700111import java.util.List;
Cem Türker3baff672017-10-12 15:09:01 +0300112import java.util.Map;
113import java.util.Set;
Jonathan Hart8cf212a2015-10-29 17:42:03 -0700114
Thiago Santos877914d2016-07-20 18:29:29 -0300115import static java.util.concurrent.TimeUnit.NANOSECONDS;
116import static java.util.concurrent.TimeUnit.SECONDS;
Cem Türker3baff672017-10-12 15:09:01 +0300117import static org.onosproject.net.flow.StatTriggerField.*;
118import static org.onosproject.net.flow.StatTriggerField.IDLE_TIME;
119import static org.onosproject.net.flow.StatTriggerFlag.ONLY_FIRST;
120import static org.onosproject.net.flow.StatTriggerFlag.PERIODIC;
alshabib44852fb2016-04-15 15:56:51 -0700121import static org.onosproject.net.flow.criteria.Criteria.*;
Yafit Hadar73514612015-11-04 10:14:21 +0200122import static org.onosproject.net.flow.instructions.Instructions.modL0Lambda;
123import static org.onosproject.net.flow.instructions.Instructions.modL1OduSignalId;
alshabib44852fb2016-04-15 15:56:51 -0700124import static org.onosproject.provider.of.flow.util.OpenFlowValueMapper.*;
alshabib19fdc122014-10-03 11:38:19 -0700125
alshabib1c319ff2014-10-04 20:29:09 -0700126public class FlowEntryBuilder {
Jian Lia0d9a172016-04-01 16:58:06 -0700127 private static final Logger log = LoggerFactory.getLogger(FlowEntryBuilder.class);
alshabib6b5cfec2014-09-18 17:42:18 -0700128
129 private final OFFlowStatsEntry stat;
130 private final OFFlowRemoved removed;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800131 private final OFFlowMod flowMod;
Cem Türker3baff672017-10-12 15:09:01 +0300132 private final OFFlowLightweightStatsEntry lightWeightStat;
alshabib6b5cfec2014-09-18 17:42:18 -0700133
134 private final Match match;
alshabib346b5b32015-03-06 00:42:16 -0800135
Jonathan Hart67fc0972015-03-19 15:21:20 -0700136 // All actions are contained in an OFInstruction. For OF1.0
137 // the instruction type is apply instruction (immediate set in ONOS speak)
alshabib346b5b32015-03-06 00:42:16 -0800138 private final List<OFInstruction> instructions;
alshabib6b5cfec2014-09-18 17:42:18 -0700139
Jonathan Harte4e74f02016-03-03 12:57:40 -0800140 private final DeviceId deviceId;
alshabib6b5cfec2014-09-18 17:42:18 -0700141
Cem Türker3baff672017-10-12 15:09:01 +0300142 public enum FlowType { STAT, LIGHTWEIGHT_STAT, REMOVED, MOD }
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800143
144 private final FlowType type;
alshabib6b5cfec2014-09-18 17:42:18 -0700145
Rodrigo Duarte Sousae37d1292017-08-29 17:01:24 -0300146 private DriverHandler driverHandler;
Jonathan Hart3c259162015-10-21 21:31:19 -0700147
Sangsik Yoonb1b823f2016-05-16 18:55:39 +0900148 // NewAdaptiveFlowStatsCollector for AdaptiveFlowSampling mode,
149 // null is not AFM mode, namely SimpleStatsCollector mode
150 private NewAdaptiveFlowStatsCollector afsc;
151
Rodrigo Duarte Sousae37d1292017-08-29 17:01:24 -0300152 public FlowEntryBuilder(DeviceId deviceId, OFFlowStatsEntry entry, DriverHandler driverHandler) {
Saurav Dasfa2fa932015-03-03 11:29:48 -0800153 this.stat = entry;
154 this.match = entry.getMatch();
alshabib346b5b32015-03-06 00:42:16 -0800155 this.instructions = getInstructions(entry);
Jonathan Harte4e74f02016-03-03 12:57:40 -0800156 this.deviceId = deviceId;
Saurav Dasfa2fa932015-03-03 11:29:48 -0800157 this.removed = null;
158 this.flowMod = null;
159 this.type = FlowType.STAT;
Rodrigo Duarte Sousae37d1292017-08-29 17:01:24 -0300160 this.driverHandler = driverHandler;
Sangsik Yoonb1b823f2016-05-16 18:55:39 +0900161 this.afsc = null;
Cem Türker3baff672017-10-12 15:09:01 +0300162 this.lightWeightStat = null;
163 }
164
165 public FlowEntryBuilder(DeviceId deviceId, OFFlowLightweightStatsEntry lightWeightStat,
166 DriverService driverService) {
167 this.stat = null;
168 this.match = lightWeightStat.getMatch();
169 this.instructions = null;
170 this.deviceId = deviceId;
171 this.removed = null;
172 this.flowMod = null;
173 this.type = FlowType.LIGHTWEIGHT_STAT;
Rodrigo Duarte Sousae37d1292017-08-29 17:01:24 -0300174 this.driverHandler = getDriver(deviceId, driverService);
Cem Türker3baff672017-10-12 15:09:01 +0300175 this.afsc = null;
176 this.lightWeightStat = lightWeightStat;
Saurav Dasfa2fa932015-03-03 11:29:48 -0800177 }
178
Rodrigo Duarte Sousae37d1292017-08-29 17:01:24 -0300179 public FlowEntryBuilder(DeviceId deviceId, OFFlowRemoved removed, DriverHandler driverHandler) {
alshabib6b5cfec2014-09-18 17:42:18 -0700180 this.match = removed.getMatch();
181 this.removed = removed;
Jonathan Harte4e74f02016-03-03 12:57:40 -0800182 this.deviceId = deviceId;
alshabib346b5b32015-03-06 00:42:16 -0800183 this.instructions = null;
alshabib6b5cfec2014-09-18 17:42:18 -0700184 this.stat = null;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800185 this.flowMod = null;
186 this.type = FlowType.REMOVED;
Rodrigo Duarte Sousae37d1292017-08-29 17:01:24 -0300187 this.driverHandler = driverHandler;
Sangsik Yoonb1b823f2016-05-16 18:55:39 +0900188 this.afsc = null;
Cem Türker3baff672017-10-12 15:09:01 +0300189 this.lightWeightStat = null;
alshabib6b5cfec2014-09-18 17:42:18 -0700190 }
191
Rodrigo Duarte Sousae37d1292017-08-29 17:01:24 -0300192 public FlowEntryBuilder(DeviceId deviceId, OFFlowMod fm, DriverHandler driverHandler) {
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800193 this.match = fm.getMatch();
Jonathan Harte4e74f02016-03-03 12:57:40 -0800194 this.deviceId = deviceId;
alshabib346b5b32015-03-06 00:42:16 -0800195 this.instructions = getInstructions(fm);
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800196 this.type = FlowType.MOD;
197 this.flowMod = fm;
198 this.stat = null;
199 this.removed = null;
Rodrigo Duarte Sousae37d1292017-08-29 17:01:24 -0300200 this.driverHandler = driverHandler;
Sangsik Yoonb1b823f2016-05-16 18:55:39 +0900201 this.afsc = null;
Cem Türker3baff672017-10-12 15:09:01 +0300202 this.lightWeightStat = null;
Sangsik Yoonb1b823f2016-05-16 18:55:39 +0900203 }
204
Rodrigo Duarte Sousae37d1292017-08-29 17:01:24 -0300205 public FlowEntryBuilder(DeviceId deviceId, OFFlowStatsEntry entry, DriverService driverService) {
206 this(deviceId, entry, getDriver(deviceId, driverService));
207 }
208
209 public FlowEntryBuilder(DeviceId deviceId, OFFlowRemoved removed, DriverService driverService) {
210 this(deviceId, removed, getDriver(deviceId, driverService));
211 }
212
213 public FlowEntryBuilder(DeviceId deviceId, OFFlowMod fm, DriverService driverService) {
214 this(deviceId, fm, getDriver(deviceId, driverService));
215 }
216
Sangsik Yoonb1b823f2016-05-16 18:55:39 +0900217 public FlowEntryBuilder withSetAfsc(NewAdaptiveFlowStatsCollector afsc) {
218 this.afsc = afsc;
219 return this;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800220 }
alshabib1c319ff2014-10-04 20:29:09 -0700221
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800222 public FlowEntry build(FlowEntryState... state) {
Brian O'Connor21564612015-12-05 19:24:59 -0800223 try {
224 switch (this.type) {
225 case STAT:
Cem Türker3baff672017-10-12 15:09:01 +0300226 return createFlowEntryFromStat();
227 case LIGHTWEIGHT_STAT:
228 return createFlowEntryFromLightweightStat();
Brian O'Connor21564612015-12-05 19:24:59 -0800229 case REMOVED:
Cem Türker3baff672017-10-12 15:09:01 +0300230 return createFlowEntryForFlowRemoved();
Brian O'Connor21564612015-12-05 19:24:59 -0800231 case MOD:
Cem Türker3baff672017-10-12 15:09:01 +0300232 return createFlowEntryForFlowMod(state);
Brian O'Connor21564612015-12-05 19:24:59 -0800233 default:
234 log.error("Unknown flow type : {}", this.type);
235 return null;
236 }
237 } catch (UnsupportedOperationException e) {
238 log.warn("Error building flow entry", e);
239 return null;
alshabib6b5cfec2014-09-18 17:42:18 -0700240 }
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800241
alshabib6b5cfec2014-09-18 17:42:18 -0700242 }
243
Cem Türker3baff672017-10-12 15:09:01 +0300244 private FlowEntry createFlowEntryFromStat() {
245
246 FlowRule.Builder builder = DefaultFlowRule.builder()
247 .forDevice(deviceId)
248 .withSelector(buildSelector())
249 .withTreatment(buildTreatment())
250 .withPriority(stat.getPriority())
251 .withIdleTimeout(stat.getIdleTimeout())
252 .withCookie(stat.getCookie().getValue());
253 if (stat.getVersion() != OFVersion.OF_10) {
254 builder.forTable(stat.getTableId().getValue());
255 }
256 if (stat.getVersion().getWireVersion() < OFVersion.OF_15.getWireVersion()) {
257 if (afsc != null) {
258 FlowEntry.FlowLiveType liveType = afsc.calFlowLiveType(stat.getDurationSec());
259 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
260 SECONDS.toNanos(stat.getDurationSec())
261 + stat.getDurationNsec(), NANOSECONDS,
262 liveType,
263 stat.getPacketCount().getValue(),
264 stat.getByteCount().getValue());
265 } else {
266 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
267 stat.getDurationSec(),
268 stat.getPacketCount().getValue(),
269 stat.getByteCount().getValue());
270 }
271 }
272 FlowStatParser statParser = new FlowStatParser(stat.getStats());
273 if (afsc != null && statParser.isDurationReceived()) {
274 FlowEntry.FlowLiveType liveType = afsc.calFlowLiveType(statParser.getDuration());
275 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
276 SECONDS.toNanos(statParser.getDuration())
277 + SECONDS.toNanos(statParser.getDuration()), NANOSECONDS,
278 liveType,
279 statParser.getPacketCount(),
280 statParser.getByteCount());
281 } else {
282 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
283 statParser.getDuration(),
284 statParser.getPacketCount(),
285 statParser.getByteCount());
286 }
287
288 }
289
Yuta HIGUCHIe7e71a82018-05-18 16:36:43 -0700290 private FlowEntry createFlowEntryForFlowMod(FlowEntryState...state) {
Cem Türker3baff672017-10-12 15:09:01 +0300291 FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED;
292 FlowRule.Builder builder = DefaultFlowRule.builder()
293 .forDevice(deviceId)
294 .withSelector(buildSelector())
295 .withTreatment(buildTreatment())
296 .withPriority(flowMod.getPriority())
297 .withIdleTimeout(flowMod.getIdleTimeout())
298 .withCookie(flowMod.getCookie().getValue());
299 if (flowMod.getVersion() != OFVersion.OF_10) {
300 builder.forTable(flowMod.getTableId().getValue());
301 }
302
303 if (afsc != null) {
304 FlowEntry.FlowLiveType liveType = FlowEntry.FlowLiveType.IMMEDIATE;
305 return new DefaultFlowEntry(builder.build(), flowState, 0, liveType, 0, 0);
306 } else {
307 return new DefaultFlowEntry(builder.build(), flowState, 0, 0, 0);
308 }
309 }
310
311 private FlowEntry createFlowEntryForFlowRemoved() {
312 FlowRule.Builder builder = DefaultFlowRule.builder()
313 .forDevice(deviceId)
314 .withSelector(buildSelector())
315 .withPriority(removed.getPriority())
316 .withIdleTimeout(removed.getIdleTimeout())
317 .withCookie(removed.getCookie().getValue())
318 .withReason(FlowRule.FlowRemoveReason.parseShort((short) removed.getReason().ordinal()));
319
320 if (removed.getVersion() != OFVersion.OF_10) {
321 builder.forTable(removed.getTableId().getValue());
322 }
323 if (removed.getVersion().getWireVersion() < OFVersion.OF_15.getWireVersion()) {
324 if (afsc != null) {
325 FlowEntry.FlowLiveType liveType = afsc.calFlowLiveType(removed.getDurationSec());
326 return new DefaultFlowEntry(builder.build(), FlowEntryState.REMOVED,
327 SECONDS.toNanos(removed.getDurationSec())
328 + removed.getDurationNsec(), NANOSECONDS,
329 liveType,
330 removed.getPacketCount().getValue(),
331 removed.getByteCount().getValue());
332 } else {
333 return new DefaultFlowEntry(builder.build(), FlowEntryState.REMOVED,
334 removed.getDurationSec(),
335 removed.getPacketCount().getValue(),
336 removed.getByteCount().getValue());
337 }
338 }
339 FlowStatParser statParser = new FlowStatParser(removed.getStats());
340 if (afsc != null && statParser.isDurationReceived()) {
341 FlowEntry.FlowLiveType liveType = afsc.calFlowLiveType(statParser.getDuration());
342 return new DefaultFlowEntry(builder.build(), FlowEntryState.REMOVED,
343 SECONDS.toNanos(statParser.getDuration())
344 + SECONDS.toNanos(statParser.getDuration()), NANOSECONDS,
345 liveType,
346 statParser.getPacketCount(),
347 statParser.getByteCount());
348 } else {
349 return new DefaultFlowEntry(builder.build(), FlowEntryState.REMOVED,
350 statParser.getDuration(),
351 statParser.getPacketCount(),
352 statParser.getByteCount());
353 }
354 }
355
356 private FlowEntry createFlowEntryFromLightweightStat() {
357 FlowRule.Builder builder = DefaultFlowRule.builder()
358 .forDevice(deviceId)
359 .withSelector(buildSelector())
360 .withPriority(lightWeightStat.getPriority())
361 .withIdleTimeout(0)
362 .withCookie(0);
363 FlowStatParser flowLightweightStatParser = new FlowStatParser(lightWeightStat.getStats());
364 builder.forTable(lightWeightStat.getTableId().getValue());
365 if (afsc != null && flowLightweightStatParser.isDurationReceived()) {
366 FlowEntry.FlowLiveType liveType = afsc.calFlowLiveType(flowLightweightStatParser.getDuration());
367 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
368 SECONDS.toNanos(flowLightweightStatParser.getDuration())
369 + flowLightweightStatParser.getDuration(), NANOSECONDS,
370 liveType,
371 flowLightweightStatParser.getPacketCount(),
372 flowLightweightStatParser.getByteCount());
373 } else {
374 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
375 flowLightweightStatParser.getDuration(),
376 flowLightweightStatParser.getPacketCount(),
377 flowLightweightStatParser.getByteCount());
378 }
379 }
380
alshabib346b5b32015-03-06 00:42:16 -0800381 private List<OFInstruction> getInstructions(OFFlowMod entry) {
alshabib19fdc122014-10-03 11:38:19 -0700382 switch (entry.getVersion()) {
383 case OF_10:
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700384 return Lists.newArrayList(OFFactoryVer13.INSTANCE.instructions()
385 .applyActions(
386 entry.getActions()));
alshabib19fdc122014-10-03 11:38:19 -0700387 case OF_11:
388 case OF_12:
389 case OF_13:
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -0700390 case OF_14:
391 case OF_15:
alshabib346b5b32015-03-06 00:42:16 -0800392 return entry.getInstructions();
393 default:
394 log.warn("Unknown OF version {}", entry.getVersion());
395 }
396 return Lists.newLinkedList();
397 }
398
399 private List<OFInstruction> getInstructions(OFFlowStatsEntry entry) {
400 switch (entry.getVersion()) {
401 case OF_10:
402 return Lists.newArrayList(
403 OFFactoryVer13.INSTANCE.instructions().applyActions(entry.getActions()));
404 case OF_11:
405 case OF_12:
406 case OF_13:
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -0700407 case OF_14:
408 case OF_15:
alshabib346b5b32015-03-06 00:42:16 -0800409 return entry.getInstructions();
alshabib19fdc122014-10-03 11:38:19 -0700410 default:
411 log.warn("Unknown OF version {}", entry.getVersion());
412 }
413 return Lists.newLinkedList();
414 }
alshabib6b5cfec2014-09-18 17:42:18 -0700415
416 private TrafficTreatment buildTreatment() {
tom9a693fd2014-10-03 11:32:19 -0700417 TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
alshabib346b5b32015-03-06 00:42:16 -0800418 for (OFInstruction in : instructions) {
419 switch (in.getType()) {
420 case GOTO_TABLE:
alshabibbdcbb102015-04-22 14:16:38 -0700421 builder.transition(((int) ((OFInstructionGotoTable) in)
422 .getTableId().getValue()));
alshabib346b5b32015-03-06 00:42:16 -0800423 break;
424 case WRITE_METADATA:
Saurav Das86af8f12015-05-25 23:55:33 -0700425 OFInstructionWriteMetadata m = (OFInstructionWriteMetadata) in;
426 builder.writeMetadata(m.getMetadata().getValue(),
427 m.getMetadataMask().getValue());
alshabib346b5b32015-03-06 00:42:16 -0800428 break;
429 case WRITE_ACTIONS:
430 builder.deferred();
431 buildActions(((OFInstructionWriteActions) in).getActions(),
432 builder);
433 break;
434 case APPLY_ACTIONS:
435 builder.immediate();
436 buildActions(((OFInstructionApplyActions) in).getActions(),
437 builder);
438 break;
439 case CLEAR_ACTIONS:
440 builder.wipeDeferred();
441 break;
Cem Türker3baff672017-10-12 15:09:01 +0300442 case STAT_TRIGGER:
443 OFInstructionStatTrigger statTrigger = (OFInstructionStatTrigger) in;
444 buildStatTrigger(statTrigger.getThresholds(), statTrigger.getFlags(), builder);
445 break;
alshabib346b5b32015-03-06 00:42:16 -0800446 case EXPERIMENTER:
447 break;
448 case METER:
Gamze Abaka2bc10ae2019-02-27 12:07:43 +0000449 builder.meter(MeterId.meterId(((OFInstructionMeter) in).getMeterId()));
alshabib346b5b32015-03-06 00:42:16 -0800450 break;
451 default:
452 log.warn("Unknown instructions type {}", in.getType());
alshabib6b5cfec2014-09-18 17:42:18 -0700453 }
454 }
455
456 return builder.build();
457 }
458
Cem Türker3baff672017-10-12 15:09:01 +0300459 private TrafficTreatment.Builder buildStatTrigger(OFOxsList oxsList,
460 Set<OFStatTriggerFlags> flagsSet,
461 TrafficTreatment.Builder builder) {
462 Map<StatTriggerField, Long> statTriggerMap = Maps.newEnumMap(StatTriggerField.class);
463 for (OFOxs<?> ofOxs : oxsList) {
464 switch (ofOxs.getStatField().id) {
465 case DURATION:
466 U64 durationType = (U64) ofOxs.getValue();
467 statTriggerMap.put(DURATION, durationType.getValue());
468 break;
469 case FLOW_COUNT:
470 U32 flowCount = (U32) ofOxs.getValue();
471 statTriggerMap.put(FLOW_COUNT, flowCount.getValue());
472 break;
473 case PACKET_COUNT:
474 U64 packetCount = (U64) ofOxs.getValue();
475 statTriggerMap.put(PACKET_COUNT, packetCount.getValue());
476 break;
477 case BYTE_COUNT:
478 U64 byteCount = (U64) ofOxs.getValue();
479 statTriggerMap.put(BYTE_COUNT, byteCount.getValue());
480 break;
481 case IDLE_TIME:
482 U64 idleTime = (U64) ofOxs.getValue();
483 statTriggerMap.put(IDLE_TIME, idleTime.getValue());
484 break;
485 default:
486 log.warn("getStatField not supported {}", ofOxs.getStatField().id);
487 break;
488 }
489 }
490 StatTriggerFlag flag = null;
491 for (OFStatTriggerFlags flags : flagsSet) {
492 switch (flags) {
493 case PERIODIC:
494 flag = PERIODIC;
495 break;
496 case ONLY_FIRST:
497 flag = ONLY_FIRST;
498 break;
499 default:
500 log.warn("flag not supported {}", flags);
501 break;
502 }
503 }
504 if (!statTriggerMap.isEmpty() && flag != null) {
505 builder.add(Instructions.statTrigger(statTriggerMap, flag));
506 }
507 return builder;
508 }
509
Jian Lia0d9a172016-04-01 16:58:06 -0700510 /**
511 * Configures traffic treatment builder with a given collection of actions.
512 *
513 * @param actions a set of OpenFlow actions
514 * @param builder traffic treatment builder
515 * @param driverHandler driver handler
516 * @param deviceId device identifier
517 * @return configured traffic treatment builder
518 */
519 public static TrafficTreatment.Builder configureTreatmentBuilder(List<OFAction> actions,
520 TrafficTreatment.Builder builder,
521 DriverHandler driverHandler,
522 DeviceId deviceId) {
523 ExtensionTreatmentInterpreter interpreter;
Charles Chan14967c22015-12-07 11:11:50 -0800524 if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
Jian Lia0d9a172016-04-01 16:58:06 -0700525 interpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class);
Charles Chan14967c22015-12-07 11:11:50 -0800526 } else {
Jian Lia0d9a172016-04-01 16:58:06 -0700527 interpreter = null;
Charles Chan14967c22015-12-07 11:11:50 -0800528 }
529
alshabib346b5b32015-03-06 00:42:16 -0800530 for (OFAction act : actions) {
531 switch (act.getType()) {
532 case OUTPUT:
533 OFActionOutput out = (OFActionOutput) act;
534 builder.setOutput(
535 PortNumber.portNumber(out.getPort().getPortNumber()));
536 break;
537 case SET_VLAN_VID:
538 OFActionSetVlanVid vlan = (OFActionSetVlanVid) act;
539 builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan()));
540 break;
541 case SET_VLAN_PCP:
542 OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act;
543 builder.setVlanPcp(pcp.getVlanPcp().getValue());
544 break;
545 case SET_DL_DST:
546 OFActionSetDlDst dldst = (OFActionSetDlDst) act;
547 builder.setEthDst(
548 MacAddress.valueOf(dldst.getDlAddr().getLong()));
549 break;
550 case SET_DL_SRC:
551 OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act;
552 builder.setEthSrc(
553 MacAddress.valueOf(dlsrc.getDlAddr().getLong()));
alshabib346b5b32015-03-06 00:42:16 -0800554 break;
555 case SET_NW_DST:
556 OFActionSetNwDst nwdst = (OFActionSetNwDst) act;
557 IPv4Address di = nwdst.getNwAddr();
558 builder.setIpDst(Ip4Address.valueOf(di.getInt()));
559 break;
560 case SET_NW_SRC:
561 OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act;
562 IPv4Address si = nwsrc.getNwAddr();
563 builder.setIpSrc(Ip4Address.valueOf(si.getInt()));
564 break;
565 case EXPERIMENTER:
566 OFActionExperimenter exp = (OFActionExperimenter) act;
567 if (exp.getExperimenter() == 0x80005A06 ||
568 exp.getExperimenter() == 0x748771) {
569 OFActionCircuit ct = (OFActionCircuit) exp;
Yafit Hadar4cc65f72016-02-10 11:23:06 +0200570 CircuitSignalID circuitSignalID = ((OFOxmOchSigid) ct.getField()).getValue();
571 builder.add(Instructions.modL0Lambda(Lambda.ochSignal(
572 lookupGridType(circuitSignalID.getGridType()),
573 lookupChannelSpacing(circuitSignalID.getChannelSpacing()),
574 circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth())));
Jian Lia0d9a172016-04-01 16:58:06 -0700575 } else if (interpreter != null) {
576 builder.extension(interpreter.mapAction(exp), deviceId);
alshabib346b5b32015-03-06 00:42:16 -0800577 } else {
578 log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter());
579 }
580 break;
581 case SET_FIELD:
582 OFActionSetField setField = (OFActionSetField) act;
Jian Lia0d9a172016-04-01 16:58:06 -0700583 handleSetField(builder, setField, driverHandler, deviceId);
alshabib346b5b32015-03-06 00:42:16 -0800584 break;
585 case POP_MPLS:
586 OFActionPopMpls popMpls = (OFActionPopMpls) act;
Ray Milkey84d5a292016-02-22 14:04:01 -0800587 builder.popMpls(new EthType(popMpls.getEthertype().getValue()));
alshabib346b5b32015-03-06 00:42:16 -0800588 break;
589 case PUSH_MPLS:
590 builder.pushMpls();
591 break;
592 case COPY_TTL_IN:
593 builder.copyTtlIn();
594 break;
595 case COPY_TTL_OUT:
596 builder.copyTtlOut();
597 break;
598 case DEC_MPLS_TTL:
599 builder.decMplsTtl();
600 break;
601 case DEC_NW_TTL:
602 builder.decNwTtl();
603 break;
604 case GROUP:
605 OFActionGroup group = (OFActionGroup) act;
Yi Tsengfa394de2017-02-01 11:26:40 -0800606 builder.group(new GroupId(group.getGroup().getGroupNumber()));
alshabib346b5b32015-03-06 00:42:16 -0800607 break;
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200608 case SET_QUEUE:
609 OFActionSetQueue setQueue = (OFActionSetQueue) act;
610 builder.setQueue(setQueue.getQueueId());
611 break;
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200612 case ENQUEUE:
613 OFActionEnqueue enqueue = (OFActionEnqueue) act;
Jian Liffef5002016-04-04 23:27:37 -0700614 builder.setQueue(enqueue.getQueueId(),
615 PortNumber.portNumber(enqueue.getPort().getPortNumber()));
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200616 break;
Jonathan Hart67fc0972015-03-19 15:21:20 -0700617 case STRIP_VLAN:
alshabib346b5b32015-03-06 00:42:16 -0800618 case POP_VLAN:
619 builder.popVlan();
620 break;
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700621 case PUSH_VLAN:
Konstantinos Kanonakis9215ff22016-11-04 13:28:11 -0500622 OFActionPushVlan pushVlan = (OFActionPushVlan) act;
623 builder.pushVlan(new EthType((short) pushVlan.getEthertype().getValue()));
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700624 break;
cansu.toprak409289d2017-10-27 10:04:05 +0300625 case METER:
626 OFActionMeter actionMeter = (OFActionMeter) act;
627 builder.meter(MeterId.meterId(actionMeter.getMeterId()));
628 break;
alshabib346b5b32015-03-06 00:42:16 -0800629 case SET_TP_DST:
630 case SET_TP_SRC:
631 case POP_PBB:
632 case PUSH_PBB:
alshabib346b5b32015-03-06 00:42:16 -0800633 case SET_MPLS_LABEL:
634 case SET_MPLS_TC:
635 case SET_MPLS_TTL:
636 case SET_NW_ECN:
637 case SET_NW_TOS:
638 case SET_NW_TTL:
alshabib346b5b32015-03-06 00:42:16 -0800639
alshabib346b5b32015-03-06 00:42:16 -0800640 default:
641 log.warn("Action type {} not yet implemented.", act.getType());
642 }
643 }
644 return builder;
645 }
646
Jian Lia0d9a172016-04-01 16:58:06 -0700647 private TrafficTreatment.Builder buildActions(List<OFAction> actions,
648 TrafficTreatment.Builder builder) {
Jian Lia0d9a172016-04-01 16:58:06 -0700649 return configureTreatmentBuilder(actions, builder, driverHandler, deviceId);
650 }
651
Charles Chancad338a2016-09-16 18:03:11 -0700652 // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES
Jian Lia0d9a172016-04-01 16:58:06 -0700653 private static void handleSetField(TrafficTreatment.Builder builder,
654 OFActionSetField action,
655 DriverHandler driverHandler,
656 DeviceId deviceId) {
Charles Chan14967c22015-12-07 11:11:50 -0800657 ExtensionTreatmentInterpreter treatmentInterpreter;
658 if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
659 treatmentInterpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class);
660 } else {
661 treatmentInterpreter = null;
662 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700663 OFOxm<?> oxm = action.getField();
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800664 switch (oxm.getMatchField().id) {
665 case VLAN_PCP:
666 @SuppressWarnings("unchecked")
667 OFOxm<VlanPcp> vlanpcp = (OFOxm<VlanPcp>) oxm;
668 builder.setVlanPcp(vlanpcp.getValue().getValue());
669 break;
670 case VLAN_VID:
Charles Chan4211baa2016-04-20 17:10:40 -0700671 if (treatmentInterpreter != null) {
672 try {
673 builder.extension(treatmentInterpreter.mapAction(action), deviceId);
674 break;
675 } catch (UnsupportedOperationException e) {
676 log.debug("Unsupported action extension; defaulting to native OF");
677 }
Charles Chan14967c22015-12-07 11:11:50 -0800678 }
alshabib44852fb2016-04-15 15:56:51 -0700679 @SuppressWarnings("unchecked")
680 OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm;
681 builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan()));
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800682 break;
683 case ETH_DST:
684 @SuppressWarnings("unchecked")
685 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethdst =
686 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
687 builder.setEthDst(MacAddress.valueOf(ethdst.getValue().getLong()));
688 break;
689 case ETH_SRC:
690 @SuppressWarnings("unchecked")
691 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethsrc =
692 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
693 builder.setEthSrc(MacAddress.valueOf(ethsrc.getValue().getLong()));
694 break;
695 case IPV4_DST:
696 @SuppressWarnings("unchecked")
697 OFOxm<IPv4Address> ip4dst = (OFOxm<IPv4Address>) oxm;
698 builder.setIpDst(Ip4Address.valueOf(ip4dst.getValue().getInt()));
699 break;
700 case IPV4_SRC:
701 @SuppressWarnings("unchecked")
702 OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm;
703 builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt()));
704 break;
sangho3f97a17d2015-01-29 22:56:29 -0800705 case MPLS_LABEL:
706 @SuppressWarnings("unchecked")
707 OFOxm<U32> labelId = (OFOxm<U32>) oxm;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100708 builder.setMpls(MplsLabel.mplsLabel((int) labelId.getValue().getValue()));
sangho3f97a17d2015-01-29 22:56:29 -0800709 break;
Saurav Das73a7dd42015-08-19 22:20:31 -0700710 case MPLS_BOS:
711 @SuppressWarnings("unchecked")
Pier Ventre23f78672016-11-15 08:46:34 -0800712 OFOxm<OFBooleanValue> mplsBos = (OFOxm<OFBooleanValue>) oxm;
713 builder.setMplsBos(mplsBos.getValue().getValue());
Saurav Das73a7dd42015-08-19 22:20:31 -0700714 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700715 case TUNNEL_ID:
716 @SuppressWarnings("unchecked")
717 OFOxm<U64> tunnelId = (OFOxm<U64>) oxm;
718 builder.setTunnelId(tunnelId.getValue().getValue());
719 break;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700720 case TCP_DST:
721 @SuppressWarnings("unchecked")
722 OFOxm<TransportPort> tcpdst = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700723 builder.setTcpDst(TpPort.tpPort(tcpdst.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700724 break;
725 case TCP_SRC:
726 @SuppressWarnings("unchecked")
727 OFOxm<TransportPort> tcpsrc = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700728 builder.setTcpSrc(TpPort.tpPort(tcpsrc.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700729 break;
730 case UDP_DST:
731 @SuppressWarnings("unchecked")
732 OFOxm<TransportPort> udpdst = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700733 builder.setUdpDst(TpPort.tpPort(udpdst.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700734 break;
735 case UDP_SRC:
736 @SuppressWarnings("unchecked")
737 OFOxm<TransportPort> udpsrc = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700738 builder.setUdpSrc(TpPort.tpPort(udpsrc.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700739 break;
Jonathan Hart3c259162015-10-21 21:31:19 -0700740 case TUNNEL_IPV4_DST:
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530741 case NSP:
742 case NSI:
743 case NSH_C1:
744 case NSH_C2:
745 case NSH_C3:
746 case NSH_C4:
747 case NSH_MDTYPE:
748 case NSH_NP:
749 case ENCAP_ETH_SRC:
750 case ENCAP_ETH_DST:
751 case ENCAP_ETH_TYPE:
752 case TUN_GPE_NP:
Jian Liffef5002016-04-04 23:27:37 -0700753 if (treatmentInterpreter != null) {
754 try {
755 builder.extension(treatmentInterpreter.mapAction(action), deviceId);
756 } catch (UnsupportedOperationException e) {
alshabib44852fb2016-04-15 15:56:51 -0700757 log.debug(e.getMessage());
Jian Liffef5002016-04-04 23:27:37 -0700758 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700759 }
760 break;
Yafit Hadar73514612015-11-04 10:14:21 +0200761 case EXP_ODU_SIG_ID:
762 @SuppressWarnings("unchecked")
763 OFOxm<OduSignalID> oduID = (OFOxm<OduSignalID>) oxm;
764 OduSignalID oduSignalID = oduID.getValue();
765 OduSignalId oduSignalId = OduSignalId.oduSignalId(oduSignalID.getTpn(),
766 oduSignalID.getTslen(),
767 oduSignalID.getTsmap());
768 builder.add(modL1OduSignalId(oduSignalId));
769 break;
770 case EXP_OCH_SIG_ID:
771 try {
772 @SuppressWarnings("unchecked")
773 OFOxm<CircuitSignalID> ochId = (OFOxm<CircuitSignalID>) oxm;
774 CircuitSignalID circuitSignalID = ochId.getValue();
775 builder.add(modL0Lambda(Lambda.ochSignal(
776 lookupGridType(circuitSignalID.getGridType()),
777 lookupChannelSpacing(circuitSignalID.getChannelSpacing()),
778 circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth())));
779 } catch (NoMappingFoundException e) {
780 log.warn(e.getMessage());
781 break;
782 }
783 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800784 case ARP_OP:
lishuai67574ce2016-05-12 16:39:59 +0800785 @SuppressWarnings("unchecked")
786 OFOxm<org.projectfloodlight.openflow.types.ArpOpcode> arpop =
787 (OFOxm<org.projectfloodlight.openflow.types.ArpOpcode>) oxm;
788 builder.setArpOp((short) arpop.getValue().getOpcode());
789 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800790 case ARP_SHA:
lishuai67574ce2016-05-12 16:39:59 +0800791 @SuppressWarnings("unchecked")
792 OFOxm<org.projectfloodlight.openflow.types.MacAddress> arpsha =
793 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
794 builder.setArpSha(MacAddress.valueOf(arpsha.getValue().getLong()));
795 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800796 case ARP_SPA:
lishuai67574ce2016-05-12 16:39:59 +0800797 @SuppressWarnings("unchecked")
798 OFOxm<IPv4Address> arpspa = (OFOxm<IPv4Address>) oxm;
799 builder.setArpSpa(Ip4Address.valueOf(arpspa.getValue().getInt()));
800 break;
Charles Chancad338a2016-09-16 18:03:11 -0700801 case OFDPA_MPLS_TYPE:
Pier Ventre6f630052016-10-18 09:58:41 -0700802 case OFDPA_OVID:
Pier Ventre9cf536b2016-10-21 13:30:18 -0700803 case OFDPA_MPLS_L2_PORT:
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -0700804 case OFDPA_ALLOW_VLAN_TRANSLATION:
Pier Ventredb252cc2016-10-21 21:54:26 -0700805 case OFDPA_QOS_INDEX:
Charles Chancad338a2016-09-16 18:03:11 -0700806 if (treatmentInterpreter != null) {
807 try {
808 builder.extension(treatmentInterpreter.mapAction(action), deviceId);
809 break;
810 } catch (UnsupportedOperationException e) {
811 log.warn("Unsupported action extension");
812 }
813 }
814 break;
Thiago Santos4a69ef82018-08-21 21:18:05 -0700815 case IP_DSCP:
816 @SuppressWarnings("unchecked")
817 OFOxm<IpDscp> ipDscp = (OFOxm<IpDscp>) oxm;
818 builder.setIpDscp(ipDscp.getValue().getDscpValue());
819 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800820 case ARP_THA:
821 case ARP_TPA:
822 case BSN_EGR_PORT_GROUP_ID:
823 case BSN_GLOBAL_VRF_ALLOWED:
824 case BSN_IN_PORTS_128:
825 case BSN_L3_DST_CLASS_ID:
826 case BSN_L3_INTERFACE_CLASS_ID:
827 case BSN_L3_SRC_CLASS_ID:
828 case BSN_LAG_ID:
829 case BSN_TCP_FLAGS:
830 case BSN_UDF0:
831 case BSN_UDF1:
832 case BSN_UDF2:
833 case BSN_UDF3:
834 case BSN_UDF4:
835 case BSN_UDF5:
836 case BSN_UDF6:
837 case BSN_UDF7:
838 case BSN_VLAN_XLATE_PORT_GROUP_ID:
839 case BSN_VRF:
840 case ETH_TYPE:
841 case ICMPV4_CODE:
842 case ICMPV4_TYPE:
843 case ICMPV6_CODE:
844 case ICMPV6_TYPE:
845 case IN_PHY_PORT:
846 case IN_PORT:
847 case IPV6_DST:
848 case IPV6_FLABEL:
849 case IPV6_ND_SLL:
850 case IPV6_ND_TARGET:
851 case IPV6_ND_TLL:
852 case IPV6_SRC:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800853 case IP_ECN:
854 case IP_PROTO:
855 case METADATA:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800856 case MPLS_TC:
857 case OCH_SIGID:
858 case OCH_SIGID_BASIC:
859 case OCH_SIGTYPE:
860 case OCH_SIGTYPE_BASIC:
861 case SCTP_DST:
862 case SCTP_SRC:
Yafit Hadar73514612015-11-04 10:14:21 +0200863 case EXP_ODU_SIGTYPE:
864 case EXP_OCH_SIGTYPE:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800865 default:
866 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
867 break;
868 }
869 }
870
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700871 // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES
alshabib6b5cfec2014-09-18 17:42:18 -0700872 private TrafficSelector buildSelector() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800873 MacAddress mac;
874 Ip4Prefix ip4Prefix;
875 Ip6Address ip6Address;
876 Ip6Prefix ip6Prefix;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800877 Ip4Address ip;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800878
Charles Chan14967c22015-12-07 11:11:50 -0800879 ExtensionSelectorInterpreter selectorInterpreter;
880 if (driverHandler.hasBehaviour(ExtensionSelectorInterpreter.class)) {
881 selectorInterpreter = driverHandler.behaviour(ExtensionSelectorInterpreter.class);
882 } else {
883 selectorInterpreter = null;
884 }
885
tom9a693fd2014-10-03 11:32:19 -0700886 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700887 for (MatchField<?> field : match.getMatchFields()) {
888 switch (field.id) {
889 case IN_PORT:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800890 builder.matchInPort(PortNumber
alshabib010c31d2014-09-26 10:01:12 -0700891 .portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700892 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800893 case IN_PHY_PORT:
894 builder.matchInPhyPort(PortNumber
895 .portNumber(match.get(MatchField.IN_PHY_PORT).getPortNumber()));
896 break;
897 case METADATA:
898 long metadata =
899 match.get(MatchField.METADATA).getValue().getValue();
900 builder.matchMetadata(metadata);
901 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700902 case ETH_DST:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800903 if (match.isPartiallyMasked(MatchField.ETH_DST)) {
904 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
905 match.getMasked(MatchField.ETH_DST);
906 builder.matchEthDstMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
907 MacAddress.valueOf(maskedMac.getMask().getLong()));
908 } else {
909 mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
910 builder.matchEthDst(mac);
911 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800912 break;
913 case ETH_SRC:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800914 if (match.isPartiallyMasked(MatchField.ETH_SRC)) {
915 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
916 match.getMasked(MatchField.ETH_SRC);
917 builder.matchEthSrcMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
918 MacAddress.valueOf(maskedMac.getMask().getLong()));
919 } else {
920 mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
921 builder.matchEthSrc(mac);
922 }
alshabib6b5cfec2014-09-18 17:42:18 -0700923 break;
924 case ETH_TYPE:
925 int ethType = match.get(MatchField.ETH_TYPE).getValue();
Jonathan Hart8cf212a2015-10-29 17:42:03 -0700926 builder.matchEthType((short) ethType);
alshabib6b5cfec2014-09-18 17:42:18 -0700927 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700928 case VLAN_VID:
Charles Chan14967c22015-12-07 11:11:50 -0800929 if (selectorInterpreter != null &&
930 selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -0700931 if (isOF13OrLater(match)) {
Charles Chan14967c22015-12-07 11:11:50 -0800932 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.VLAN_VID);
933 builder.extension(selectorInterpreter.mapOxm(oxm),
Jonathan Harte4e74f02016-03-03 12:57:40 -0800934 deviceId);
Charles Chan14967c22015-12-07 11:11:50 -0800935 } else {
936 break;
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800937 }
938 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800939 VlanId vlanId = null;
940 if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
941 Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
942 if (masked.getValue().equals(OFVlanVidMatch.PRESENT)
943 && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
944 vlanId = VlanId.ANY;
945 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700946 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800947 if (!match.get(MatchField.VLAN_VID).isPresentBitSet()) {
948 vlanId = VlanId.NONE;
949 } else {
950 vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
951 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700952 }
Charles Chan14967c22015-12-07 11:11:50 -0800953 if (vlanId != null) {
954 builder.matchVlanId(vlanId);
955 }
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800956 }
alshabib6b5cfec2014-09-18 17:42:18 -0700957 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800958 case VLAN_PCP:
959 byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
960 builder.matchVlanPcp(vlanPcp);
961 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800962 case IP_DSCP:
963 byte ipDscp = match.get(MatchField.IP_DSCP).getDscpValue();
964 builder.matchIPDscp(ipDscp);
965 break;
966 case IP_ECN:
967 byte ipEcn = match.get(MatchField.IP_ECN).getEcnValue();
968 builder.matchIPEcn(ipEcn);
969 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800970 case IP_PROTO:
971 short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
972 builder.matchIPProtocol((byte) proto);
973 break;
974 case IPV4_SRC:
975 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
976 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800977 ip4Prefix = Ip4Prefix.valueOf(
978 maskedIp.getValue().getInt(),
979 maskedIp.getMask().asCidrMaskLength());
980 } else {
981 ip4Prefix = Ip4Prefix.valueOf(
982 match.get(MatchField.IPV4_SRC).getInt(),
983 Ip4Prefix.MAX_MASK_LENGTH);
984 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800985 builder.matchIPSrc(ip4Prefix);
986 break;
987 case IPV4_DST:
988 if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
989 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800990 ip4Prefix = Ip4Prefix.valueOf(
991 maskedIp.getValue().getInt(),
992 maskedIp.getMask().asCidrMaskLength());
993 } else {
994 ip4Prefix = Ip4Prefix.valueOf(
995 match.get(MatchField.IPV4_DST).getInt(),
996 Ip4Prefix.MAX_MASK_LENGTH);
997 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800998 builder.matchIPDst(ip4Prefix);
Jonathan Hart34bc6142014-10-17 11:00:43 -0700999 break;
1000 case TCP_SRC:
Andreas Gilbert75b882f72017-02-03 09:58:07 +01001001 if (match.isPartiallyMasked(MatchField.TCP_SRC)) {
1002 Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort =
1003 match.getMasked(MatchField.TCP_SRC);
1004 builder.matchTcpSrcMasked(TpPort.tpPort(maskedPort.getValue().getPort()),
1005 TpPort.tpPort(maskedPort.getMask().getPort()));
1006 } else {
1007 builder.matchTcpSrc(TpPort.tpPort(match.get(MatchField.TCP_SRC).getPort()));
1008 }
Jonathan Hart34bc6142014-10-17 11:00:43 -07001009 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001010 case TCP_DST:
Andreas Gilbert75b882f72017-02-03 09:58:07 +01001011 if (match.isPartiallyMasked(MatchField.TCP_DST)) {
1012 Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort =
1013 match.getMasked(MatchField.TCP_DST);
1014 builder.matchTcpDstMasked(TpPort.tpPort(maskedPort.getValue().getPort()),
1015 TpPort.tpPort(maskedPort.getMask().getPort()));
1016 } else {
1017 builder.matchTcpDst(TpPort.tpPort(match.get(MatchField.TCP_DST).getPort()));
1018 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001019 break;
1020 case UDP_SRC:
Andreas Gilbert75b882f72017-02-03 09:58:07 +01001021 if (match.isPartiallyMasked(MatchField.UDP_SRC)) {
1022 Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort =
1023 match.getMasked(MatchField.UDP_SRC);
1024 builder.matchUdpSrcMasked(TpPort.tpPort(maskedPort.getValue().getPort()),
1025 TpPort.tpPort(maskedPort.getMask().getPort()));
1026 } else {
1027 builder.matchUdpSrc(TpPort.tpPort(match.get(MatchField.UDP_SRC).getPort()));
1028 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001029 break;
1030 case UDP_DST:
Andreas Gilbert75b882f72017-02-03 09:58:07 +01001031 if (match.isPartiallyMasked(MatchField.UDP_DST)) {
1032 Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort =
1033 match.getMasked(MatchField.UDP_DST);
1034 builder.matchUdpDstMasked(TpPort.tpPort(maskedPort.getValue().getPort()),
1035 TpPort.tpPort(maskedPort.getMask().getPort()));
1036 } else {
1037 builder.matchUdpDst(TpPort.tpPort(match.get(MatchField.UDP_DST).getPort()));
1038 }
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -07001039 break;
Michele Santuari4b6019e2014-12-19 11:31:45 +01001040 case MPLS_LABEL:
1041 builder.matchMplsLabel(MplsLabel.mplsLabel((int) match.get(MatchField.MPLS_LABEL)
1042 .getValue()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001043 break;
Saurav Dasffc5bbc2015-08-18 23:30:19 -07001044 case MPLS_BOS:
1045 builder.matchMplsBos(match.get(MatchField.MPLS_BOS).getValue());
1046 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001047 case SCTP_SRC:
Andreas Gilbert75b882f72017-02-03 09:58:07 +01001048 if (match.isPartiallyMasked(MatchField.SCTP_SRC)) {
1049 Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort =
1050 match.getMasked(MatchField.SCTP_SRC);
1051 builder.matchSctpSrcMasked(TpPort.tpPort(maskedPort.getValue().getPort()),
1052 TpPort.tpPort(maskedPort.getMask().getPort()));
1053 } else {
1054 builder.matchSctpSrc(TpPort.tpPort(match.get(MatchField.SCTP_SRC).getPort()));
1055 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001056 break;
1057 case SCTP_DST:
Andreas Gilbert75b882f72017-02-03 09:58:07 +01001058 if (match.isPartiallyMasked(MatchField.SCTP_DST)) {
1059 Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort =
1060 match.getMasked(MatchField.SCTP_DST);
1061 builder.matchSctpDstMasked(TpPort.tpPort(maskedPort.getValue().getPort()),
1062 TpPort.tpPort(maskedPort.getMask().getPort()));
1063 } else {
1064 builder.matchSctpDst(TpPort.tpPort(match.get(MatchField.SCTP_DST).getPort()));
1065 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001066 break;
1067 case ICMPV4_TYPE:
1068 byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
1069 builder.matchIcmpType(icmpType);
1070 break;
1071 case ICMPV4_CODE:
1072 byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode();
1073 builder.matchIcmpCode(icmpCode);
1074 break;
1075 case IPV6_SRC:
1076 if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
1077 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
1078 ip6Prefix = Ip6Prefix.valueOf(
1079 maskedIp.getValue().getBytes(),
1080 maskedIp.getMask().asCidrMaskLength());
1081 } else {
1082 ip6Prefix = Ip6Prefix.valueOf(
1083 match.get(MatchField.IPV6_SRC).getBytes(),
1084 Ip6Prefix.MAX_MASK_LENGTH);
1085 }
1086 builder.matchIPv6Src(ip6Prefix);
1087 break;
1088 case IPV6_DST:
1089 if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
1090 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
1091 ip6Prefix = Ip6Prefix.valueOf(
1092 maskedIp.getValue().getBytes(),
1093 maskedIp.getMask().asCidrMaskLength());
1094 } else {
1095 ip6Prefix = Ip6Prefix.valueOf(
1096 match.get(MatchField.IPV6_DST).getBytes(),
1097 Ip6Prefix.MAX_MASK_LENGTH);
1098 }
1099 builder.matchIPv6Dst(ip6Prefix);
1100 break;
1101 case IPV6_FLABEL:
1102 int flowLabel =
1103 match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue();
1104 builder.matchIPv6FlowLabel(flowLabel);
1105 break;
1106 case ICMPV6_TYPE:
1107 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
1108 builder.matchIcmpv6Type(icmpv6type);
1109 break;
1110 case ICMPV6_CODE:
1111 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
1112 builder.matchIcmpv6Code(icmpv6code);
1113 break;
1114 case IPV6_ND_TARGET:
1115 ip6Address =
1116 Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes());
1117 builder.matchIPv6NDTargetAddress(ip6Address);
1118 break;
1119 case IPV6_ND_SLL:
1120 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong());
1121 builder.matchIPv6NDSourceLinkLayerAddress(mac);
1122 break;
1123 case IPV6_ND_TLL:
1124 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong());
1125 builder.matchIPv6NDTargetLinkLayerAddress(mac);
1126 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001127 case IPV6_EXTHDR:
Charles M.C. Chan2184de12015-04-26 02:24:53 +08001128 builder.matchIPv6ExthdrFlags((short) match.get(MatchField.IPV6_EXTHDR)
Hyunsun Moona08c5d02015-07-14 17:53:00 -07001129 .getValue());
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001130 break;
Marc De Leenheer49087752014-10-23 13:54:09 -07001131 case OCH_SIGID:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -07001132 CircuitSignalID sigId = match.get(MatchField.OCH_SIGID);
1133 builder.add(matchLambda(Lambda.ochSignal(
Sho SHIMIZUc17042d2015-05-28 12:07:23 -07001134 lookupGridType(sigId.getGridType()), lookupChannelSpacing(sigId.getChannelSpacing()),
Marc De Leenheer0b8b2ef2015-08-03 15:39:00 -07001135 sigId.getChannelNumber(), sigId.getSpectralWidth())
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -07001136 ));
Marc De Leenheer49087752014-10-23 13:54:09 -07001137 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -08001138 case OCH_SIGTYPE:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -07001139 U8 sigType = match.get(MatchField.OCH_SIGTYPE);
Sho SHIMIZUc17042d2015-05-28 12:07:23 -07001140 builder.add(matchOchSignalType(lookupOchSignalType((byte) sigType.getValue())));
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -08001141 break;
Yafit Hadar73514612015-11-04 10:14:21 +02001142 case EXP_OCH_SIG_ID:
1143 try {
1144 CircuitSignalID expSigId = match.get(MatchField.EXP_OCH_SIG_ID);
1145 builder.add(matchLambda(Lambda.ochSignal(
1146 lookupGridType(expSigId.getGridType()), lookupChannelSpacing(expSigId.getChannelSpacing()),
1147 expSigId.getChannelNumber(), expSigId.getSpectralWidth())));
1148 } catch (NoMappingFoundException e) {
1149 log.warn(e.getMessage());
1150 break;
1151 }
1152 break;
1153 case EXP_OCH_SIGTYPE:
1154 try {
1155 U8 expOchSigType = match.get(MatchField.EXP_OCH_SIGTYPE);
1156 builder.add(matchOchSignalType(lookupOchSignalType((byte) expOchSigType.getValue())));
1157 } catch (NoMappingFoundException e) {
1158 log.warn(e.getMessage());
1159 break;
1160 }
1161 break;
1162 case EXP_ODU_SIG_ID:
1163 OduSignalId oduSignalId = OduSignalId.oduSignalId(match.get(MatchField.EXP_ODU_SIG_ID).getTpn(),
1164 match.get(MatchField.EXP_ODU_SIG_ID).getTslen(),
1165 match.get(MatchField.EXP_ODU_SIG_ID).getTsmap());
1166 builder.add(matchOduSignalId(oduSignalId));
Frank Wang5733c382017-03-28 10:15:18 +08001167 break;
Yafit Hadar73514612015-11-04 10:14:21 +02001168 case EXP_ODU_SIGTYPE:
1169 try {
1170 U8 oduSigType = match.get(MatchField.EXP_ODU_SIGTYPE);
1171 builder.add(matchOduSignalType(lookupOduSignalType((byte) oduSigType.getValue())));
1172 } catch (NoMappingFoundException e) {
1173 log.warn(e.getMessage());
1174 break;
1175 }
1176 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -07001177 case TUNNEL_ID:
1178 long tunnelId = match.get(MatchField.TUNNEL_ID).getValue();
1179 builder.matchTunnelId(tunnelId);
1180 break;
BitOhenryb40129a2015-11-30 12:41:18 +08001181 case ARP_OP:
1182 int arpOp = match.get(MatchField.ARP_OP).getOpcode();
1183 builder.matchArpOp(arpOp);
1184 break;
BitOhenrya331b182015-11-23 08:39:37 +08001185 case ARP_SHA:
1186 mac = MacAddress.valueOf(match.get(MatchField.ARP_SHA).getLong());
1187 builder.matchArpSha(mac);
1188 break;
BitOhenry296b4542015-11-24 08:41:58 +08001189 case ARP_SPA:
1190 ip = Ip4Address.valueOf(match.get(MatchField.ARP_SPA).getInt());
1191 builder.matchArpSpa(ip);
1192 break;
BitOhenry76430852015-11-20 19:04:49 +08001193 case ARP_THA:
1194 mac = MacAddress.valueOf(match.get(MatchField.ARP_THA).getLong());
1195 builder.matchArpTha(mac);
1196 break;
BitOhenryc1e5fcc2015-11-23 20:47:53 +08001197 case ARP_TPA:
1198 ip = Ip4Address.valueOf(match.get(MatchField.ARP_TPA).getInt());
1199 builder.matchArpTpa(ip);
1200 break;
Phaneendra Manda8db7d092016-06-04 00:17:24 +05301201 case NSP:
1202 if (selectorInterpreter != null) {
1203 try {
1204 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.NSP);
1205 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
1206 } catch (UnsupportedOperationException e) {
1207 log.debug(e.getMessage());
1208 }
1209 }
1210 break;
1211 case NSI:
1212 if (selectorInterpreter != null) {
1213 try {
1214 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.NSI);
1215 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
1216 } catch (UnsupportedOperationException e) {
1217 log.debug(e.getMessage());
1218 }
1219 }
1220 break;
1221 case ENCAP_ETH_TYPE:
1222 if (selectorInterpreter != null) {
1223 try {
1224 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.ENCAP_ETH_TYPE);
1225 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
1226 } catch (UnsupportedOperationException e) {
1227 log.debug(e.getMessage());
1228 }
1229 }
1230 break;
Frank Wang5733c382017-03-28 10:15:18 +08001231 case CONNTRACK_STATE:
1232 if (selectorInterpreter != null &&
1233 selectorInterpreter.supported(ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_STATE.type())) {
1234 try {
1235 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.CONNTRACK_STATE);
1236 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
1237 } catch (UnsupportedOperationException e) {
1238 log.debug(e.getMessage());
1239 }
1240 }
1241 break;
1242 case CONNTRACK_ZONE:
1243 if (selectorInterpreter != null &&
1244 selectorInterpreter.supported(ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_ZONE.type())) {
1245 try {
1246 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.CONNTRACK_ZONE);
1247 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
1248 } catch (UnsupportedOperationException e) {
1249 log.debug(e.getMessage());
1250 }
1251 }
1252 break;
1253 case CONNTRACK_MARK:
1254 if (selectorInterpreter != null &&
1255 selectorInterpreter.supported(ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_MARK.type())) {
1256 try {
1257 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.CONNTRACK_MARK);
1258 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
1259 } catch (UnsupportedOperationException e) {
1260 log.debug(e.getMessage());
1261 }
1262 }
1263 break;
Pier Ventre6f630052016-10-18 09:58:41 -07001264 case OFDPA_OVID:
1265 if (selectorInterpreter != null &&
1266 selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_OVID.type())) {
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -07001267 if (isOF13OrLater(match)) {
Pier Ventre6f630052016-10-18 09:58:41 -07001268 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.OFDPA_OVID);
1269 builder.extension(selectorInterpreter.mapOxm(oxm),
1270 deviceId);
1271 } else {
1272 break;
1273 }
1274 }
1275 break;
Pier Ventre9cf536b2016-10-21 13:30:18 -07001276 case OFDPA_MPLS_L2_PORT:
1277 if (selectorInterpreter != null &&
1278 selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_MPLS_L2_PORT.type())) {
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -07001279 if (isOF13OrLater(match)) {
Pier Ventre9cf536b2016-10-21 13:30:18 -07001280 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.OFDPA_MPLS_L2_PORT);
1281 builder.extension(selectorInterpreter.mapOxm(oxm),
1282 deviceId);
1283 } else {
1284 break;
1285 }
1286 }
1287 break;
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -07001288 case OFDPA_ALLOW_VLAN_TRANSLATION:
1289 if (selectorInterpreter != null &&
1290 selectorInterpreter.supported(
1291 ExtensionSelectorTypes.OFDPA_MATCH_ALLOW_VLAN_TRANSLATION.type())) {
1292 if (isOF13OrLater(match)) {
1293 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.OFDPA_ALLOW_VLAN_TRANSLATION);
1294 builder.extension(selectorInterpreter.mapOxm(oxm),
1295 deviceId);
1296 } else {
1297 break;
1298 }
1299 }
1300 break;
1301 case OFDPA_ACTSET_OUTPUT:
1302 if (selectorInterpreter != null &&
1303 selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_ACTSET_OUTPUT.type())) {
1304 if (isOF13OrLater(match)) {
1305 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.OFDPA_ACTSET_OUTPUT);
1306 builder.extension(selectorInterpreter.mapOxm(oxm),
1307 deviceId);
1308 } else {
1309 break;
1310 }
1311 }
1312 break;
alshabib6b5cfec2014-09-18 17:42:18 -07001313 case MPLS_TC:
alshabib6b5cfec2014-09-18 17:42:18 -07001314 default:
1315 log.warn("Match type {} not yet implemented.", field.id);
alshabib6b5cfec2014-09-18 17:42:18 -07001316 }
1317 }
1318 return builder.build();
1319 }
Jonathan Hart3c259162015-10-21 21:31:19 -07001320
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -07001321 /**
1322 * @param obj OpenFlow object to test
1323 * @return true if OFObject is OF_13 or later
1324 */
1325 private static boolean isOF13OrLater(OFObject obj) {
1326 return obj.getVersion().wireVersion >= OFVersion.OF_13.wireVersion;
1327 }
1328
Claudine Chiu20cbd452017-08-30 19:23:11 -04001329 /**
1330 * Retrieves the driver handler for the specified device.
1331 *
1332 * @param deviceId device identifier
Rodrigo Duarte Sousae37d1292017-08-29 17:01:24 -03001333 * @param driverService service handle for the driver service
Claudine Chiu20cbd452017-08-30 19:23:11 -04001334 * @return driver handler
1335 */
Rodrigo Duarte Sousae37d1292017-08-29 17:01:24 -03001336 protected static DriverHandler getDriver(DeviceId deviceId, DriverService driverService) {
Claudine Chiu20cbd452017-08-30 19:23:11 -04001337 Driver driver = driverService.getDriver(deviceId);
1338 DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, deviceId));
Jonathan Hart3c259162015-10-21 21:31:19 -07001339 return handler;
1340 }
alshabib6b5cfec2014-09-18 17:42:18 -07001341}