blob: a71d440c651478e2f3dd354b92ead6dac26258b9 [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:
Pier Ventredb252cc2016-10-21 21:54:26 -0700801 case OFDPA_QOS_INDEX:
Charles Chancad338a2016-09-16 18:03:11 -0700802 if (treatmentInterpreter != null) {
803 try {
804 builder.extension(treatmentInterpreter.mapAction(action), deviceId);
805 break;
806 } catch (UnsupportedOperationException e) {
807 log.warn("Unsupported action extension");
808 }
809 }
810 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800811 case ARP_THA:
812 case ARP_TPA:
813 case BSN_EGR_PORT_GROUP_ID:
814 case BSN_GLOBAL_VRF_ALLOWED:
815 case BSN_IN_PORTS_128:
816 case BSN_L3_DST_CLASS_ID:
817 case BSN_L3_INTERFACE_CLASS_ID:
818 case BSN_L3_SRC_CLASS_ID:
819 case BSN_LAG_ID:
820 case BSN_TCP_FLAGS:
821 case BSN_UDF0:
822 case BSN_UDF1:
823 case BSN_UDF2:
824 case BSN_UDF3:
825 case BSN_UDF4:
826 case BSN_UDF5:
827 case BSN_UDF6:
828 case BSN_UDF7:
829 case BSN_VLAN_XLATE_PORT_GROUP_ID:
830 case BSN_VRF:
831 case ETH_TYPE:
832 case ICMPV4_CODE:
833 case ICMPV4_TYPE:
834 case ICMPV6_CODE:
835 case ICMPV6_TYPE:
836 case IN_PHY_PORT:
837 case IN_PORT:
838 case IPV6_DST:
839 case IPV6_FLABEL:
840 case IPV6_ND_SLL:
841 case IPV6_ND_TARGET:
842 case IPV6_ND_TLL:
843 case IPV6_SRC:
844 case IP_DSCP:
845 case IP_ECN:
846 case IP_PROTO:
847 case METADATA:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800848 case MPLS_TC:
849 case OCH_SIGID:
850 case OCH_SIGID_BASIC:
851 case OCH_SIGTYPE:
852 case OCH_SIGTYPE_BASIC:
853 case SCTP_DST:
854 case SCTP_SRC:
Yafit Hadar73514612015-11-04 10:14:21 +0200855 case EXP_ODU_SIGTYPE:
856 case EXP_OCH_SIGTYPE:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800857 default:
858 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
859 break;
860 }
861 }
862
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700863 // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES
alshabib6b5cfec2014-09-18 17:42:18 -0700864 private TrafficSelector buildSelector() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800865 MacAddress mac;
866 Ip4Prefix ip4Prefix;
867 Ip6Address ip6Address;
868 Ip6Prefix ip6Prefix;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800869 Ip4Address ip;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800870
Charles Chan14967c22015-12-07 11:11:50 -0800871 ExtensionSelectorInterpreter selectorInterpreter;
872 if (driverHandler.hasBehaviour(ExtensionSelectorInterpreter.class)) {
873 selectorInterpreter = driverHandler.behaviour(ExtensionSelectorInterpreter.class);
874 } else {
875 selectorInterpreter = null;
876 }
877
tom9a693fd2014-10-03 11:32:19 -0700878 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700879 for (MatchField<?> field : match.getMatchFields()) {
880 switch (field.id) {
881 case IN_PORT:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800882 builder.matchInPort(PortNumber
alshabib010c31d2014-09-26 10:01:12 -0700883 .portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700884 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800885 case IN_PHY_PORT:
886 builder.matchInPhyPort(PortNumber
887 .portNumber(match.get(MatchField.IN_PHY_PORT).getPortNumber()));
888 break;
889 case METADATA:
890 long metadata =
891 match.get(MatchField.METADATA).getValue().getValue();
892 builder.matchMetadata(metadata);
893 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700894 case ETH_DST:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800895 if (match.isPartiallyMasked(MatchField.ETH_DST)) {
896 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
897 match.getMasked(MatchField.ETH_DST);
898 builder.matchEthDstMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
899 MacAddress.valueOf(maskedMac.getMask().getLong()));
900 } else {
901 mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
902 builder.matchEthDst(mac);
903 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800904 break;
905 case ETH_SRC:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800906 if (match.isPartiallyMasked(MatchField.ETH_SRC)) {
907 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
908 match.getMasked(MatchField.ETH_SRC);
909 builder.matchEthSrcMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
910 MacAddress.valueOf(maskedMac.getMask().getLong()));
911 } else {
912 mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
913 builder.matchEthSrc(mac);
914 }
alshabib6b5cfec2014-09-18 17:42:18 -0700915 break;
916 case ETH_TYPE:
917 int ethType = match.get(MatchField.ETH_TYPE).getValue();
Jonathan Hart8cf212a2015-10-29 17:42:03 -0700918 builder.matchEthType((short) ethType);
alshabib6b5cfec2014-09-18 17:42:18 -0700919 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700920 case VLAN_VID:
Charles Chan14967c22015-12-07 11:11:50 -0800921 if (selectorInterpreter != null &&
922 selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -0700923 if (isOF13OrLater(match)) {
Charles Chan14967c22015-12-07 11:11:50 -0800924 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.VLAN_VID);
925 builder.extension(selectorInterpreter.mapOxm(oxm),
Jonathan Harte4e74f02016-03-03 12:57:40 -0800926 deviceId);
Charles Chan14967c22015-12-07 11:11:50 -0800927 } else {
928 break;
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800929 }
930 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800931 VlanId vlanId = null;
932 if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
933 Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
934 if (masked.getValue().equals(OFVlanVidMatch.PRESENT)
935 && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
936 vlanId = VlanId.ANY;
937 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700938 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800939 if (!match.get(MatchField.VLAN_VID).isPresentBitSet()) {
940 vlanId = VlanId.NONE;
941 } else {
942 vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
943 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700944 }
Charles Chan14967c22015-12-07 11:11:50 -0800945 if (vlanId != null) {
946 builder.matchVlanId(vlanId);
947 }
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800948 }
alshabib6b5cfec2014-09-18 17:42:18 -0700949 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800950 case VLAN_PCP:
951 byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
952 builder.matchVlanPcp(vlanPcp);
953 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800954 case IP_DSCP:
955 byte ipDscp = match.get(MatchField.IP_DSCP).getDscpValue();
956 builder.matchIPDscp(ipDscp);
957 break;
958 case IP_ECN:
959 byte ipEcn = match.get(MatchField.IP_ECN).getEcnValue();
960 builder.matchIPEcn(ipEcn);
961 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800962 case IP_PROTO:
963 short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
964 builder.matchIPProtocol((byte) proto);
965 break;
966 case IPV4_SRC:
967 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
968 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800969 ip4Prefix = Ip4Prefix.valueOf(
970 maskedIp.getValue().getInt(),
971 maskedIp.getMask().asCidrMaskLength());
972 } else {
973 ip4Prefix = Ip4Prefix.valueOf(
974 match.get(MatchField.IPV4_SRC).getInt(),
975 Ip4Prefix.MAX_MASK_LENGTH);
976 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800977 builder.matchIPSrc(ip4Prefix);
978 break;
979 case IPV4_DST:
980 if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
981 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800982 ip4Prefix = Ip4Prefix.valueOf(
983 maskedIp.getValue().getInt(),
984 maskedIp.getMask().asCidrMaskLength());
985 } else {
986 ip4Prefix = Ip4Prefix.valueOf(
987 match.get(MatchField.IPV4_DST).getInt(),
988 Ip4Prefix.MAX_MASK_LENGTH);
989 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800990 builder.matchIPDst(ip4Prefix);
Jonathan Hart34bc6142014-10-17 11:00:43 -0700991 break;
992 case TCP_SRC:
Andreas Gilbert75b882f72017-02-03 09:58:07 +0100993 if (match.isPartiallyMasked(MatchField.TCP_SRC)) {
994 Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort =
995 match.getMasked(MatchField.TCP_SRC);
996 builder.matchTcpSrcMasked(TpPort.tpPort(maskedPort.getValue().getPort()),
997 TpPort.tpPort(maskedPort.getMask().getPort()));
998 } else {
999 builder.matchTcpSrc(TpPort.tpPort(match.get(MatchField.TCP_SRC).getPort()));
1000 }
Jonathan Hart34bc6142014-10-17 11:00:43 -07001001 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001002 case TCP_DST:
Andreas Gilbert75b882f72017-02-03 09:58:07 +01001003 if (match.isPartiallyMasked(MatchField.TCP_DST)) {
1004 Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort =
1005 match.getMasked(MatchField.TCP_DST);
1006 builder.matchTcpDstMasked(TpPort.tpPort(maskedPort.getValue().getPort()),
1007 TpPort.tpPort(maskedPort.getMask().getPort()));
1008 } else {
1009 builder.matchTcpDst(TpPort.tpPort(match.get(MatchField.TCP_DST).getPort()));
1010 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001011 break;
1012 case UDP_SRC:
Andreas Gilbert75b882f72017-02-03 09:58:07 +01001013 if (match.isPartiallyMasked(MatchField.UDP_SRC)) {
1014 Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort =
1015 match.getMasked(MatchField.UDP_SRC);
1016 builder.matchUdpSrcMasked(TpPort.tpPort(maskedPort.getValue().getPort()),
1017 TpPort.tpPort(maskedPort.getMask().getPort()));
1018 } else {
1019 builder.matchUdpSrc(TpPort.tpPort(match.get(MatchField.UDP_SRC).getPort()));
1020 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001021 break;
1022 case UDP_DST:
Andreas Gilbert75b882f72017-02-03 09:58:07 +01001023 if (match.isPartiallyMasked(MatchField.UDP_DST)) {
1024 Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort =
1025 match.getMasked(MatchField.UDP_DST);
1026 builder.matchUdpDstMasked(TpPort.tpPort(maskedPort.getValue().getPort()),
1027 TpPort.tpPort(maskedPort.getMask().getPort()));
1028 } else {
1029 builder.matchUdpDst(TpPort.tpPort(match.get(MatchField.UDP_DST).getPort()));
1030 }
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -07001031 break;
Michele Santuari4b6019e2014-12-19 11:31:45 +01001032 case MPLS_LABEL:
1033 builder.matchMplsLabel(MplsLabel.mplsLabel((int) match.get(MatchField.MPLS_LABEL)
1034 .getValue()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001035 break;
Saurav Dasffc5bbc2015-08-18 23:30:19 -07001036 case MPLS_BOS:
1037 builder.matchMplsBos(match.get(MatchField.MPLS_BOS).getValue());
1038 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001039 case SCTP_SRC:
Andreas Gilbert75b882f72017-02-03 09:58:07 +01001040 if (match.isPartiallyMasked(MatchField.SCTP_SRC)) {
1041 Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort =
1042 match.getMasked(MatchField.SCTP_SRC);
1043 builder.matchSctpSrcMasked(TpPort.tpPort(maskedPort.getValue().getPort()),
1044 TpPort.tpPort(maskedPort.getMask().getPort()));
1045 } else {
1046 builder.matchSctpSrc(TpPort.tpPort(match.get(MatchField.SCTP_SRC).getPort()));
1047 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001048 break;
1049 case SCTP_DST:
Andreas Gilbert75b882f72017-02-03 09:58:07 +01001050 if (match.isPartiallyMasked(MatchField.SCTP_DST)) {
1051 Masked<org.projectfloodlight.openflow.types.TransportPort> maskedPort =
1052 match.getMasked(MatchField.SCTP_DST);
1053 builder.matchSctpDstMasked(TpPort.tpPort(maskedPort.getValue().getPort()),
1054 TpPort.tpPort(maskedPort.getMask().getPort()));
1055 } else {
1056 builder.matchSctpDst(TpPort.tpPort(match.get(MatchField.SCTP_DST).getPort()));
1057 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001058 break;
1059 case ICMPV4_TYPE:
1060 byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
1061 builder.matchIcmpType(icmpType);
1062 break;
1063 case ICMPV4_CODE:
1064 byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode();
1065 builder.matchIcmpCode(icmpCode);
1066 break;
1067 case IPV6_SRC:
1068 if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
1069 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
1070 ip6Prefix = Ip6Prefix.valueOf(
1071 maskedIp.getValue().getBytes(),
1072 maskedIp.getMask().asCidrMaskLength());
1073 } else {
1074 ip6Prefix = Ip6Prefix.valueOf(
1075 match.get(MatchField.IPV6_SRC).getBytes(),
1076 Ip6Prefix.MAX_MASK_LENGTH);
1077 }
1078 builder.matchIPv6Src(ip6Prefix);
1079 break;
1080 case IPV6_DST:
1081 if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
1082 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
1083 ip6Prefix = Ip6Prefix.valueOf(
1084 maskedIp.getValue().getBytes(),
1085 maskedIp.getMask().asCidrMaskLength());
1086 } else {
1087 ip6Prefix = Ip6Prefix.valueOf(
1088 match.get(MatchField.IPV6_DST).getBytes(),
1089 Ip6Prefix.MAX_MASK_LENGTH);
1090 }
1091 builder.matchIPv6Dst(ip6Prefix);
1092 break;
1093 case IPV6_FLABEL:
1094 int flowLabel =
1095 match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue();
1096 builder.matchIPv6FlowLabel(flowLabel);
1097 break;
1098 case ICMPV6_TYPE:
1099 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
1100 builder.matchIcmpv6Type(icmpv6type);
1101 break;
1102 case ICMPV6_CODE:
1103 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
1104 builder.matchIcmpv6Code(icmpv6code);
1105 break;
1106 case IPV6_ND_TARGET:
1107 ip6Address =
1108 Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes());
1109 builder.matchIPv6NDTargetAddress(ip6Address);
1110 break;
1111 case IPV6_ND_SLL:
1112 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong());
1113 builder.matchIPv6NDSourceLinkLayerAddress(mac);
1114 break;
1115 case IPV6_ND_TLL:
1116 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong());
1117 builder.matchIPv6NDTargetLinkLayerAddress(mac);
1118 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001119 case IPV6_EXTHDR:
Charles M.C. Chan2184de12015-04-26 02:24:53 +08001120 builder.matchIPv6ExthdrFlags((short) match.get(MatchField.IPV6_EXTHDR)
Hyunsun Moona08c5d02015-07-14 17:53:00 -07001121 .getValue());
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001122 break;
Marc De Leenheer49087752014-10-23 13:54:09 -07001123 case OCH_SIGID:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -07001124 CircuitSignalID sigId = match.get(MatchField.OCH_SIGID);
1125 builder.add(matchLambda(Lambda.ochSignal(
Sho SHIMIZUc17042d2015-05-28 12:07:23 -07001126 lookupGridType(sigId.getGridType()), lookupChannelSpacing(sigId.getChannelSpacing()),
Marc De Leenheer0b8b2ef2015-08-03 15:39:00 -07001127 sigId.getChannelNumber(), sigId.getSpectralWidth())
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -07001128 ));
Marc De Leenheer49087752014-10-23 13:54:09 -07001129 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -08001130 case OCH_SIGTYPE:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -07001131 U8 sigType = match.get(MatchField.OCH_SIGTYPE);
Sho SHIMIZUc17042d2015-05-28 12:07:23 -07001132 builder.add(matchOchSignalType(lookupOchSignalType((byte) sigType.getValue())));
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -08001133 break;
Yafit Hadar73514612015-11-04 10:14:21 +02001134 case EXP_OCH_SIG_ID:
1135 try {
1136 CircuitSignalID expSigId = match.get(MatchField.EXP_OCH_SIG_ID);
1137 builder.add(matchLambda(Lambda.ochSignal(
1138 lookupGridType(expSigId.getGridType()), lookupChannelSpacing(expSigId.getChannelSpacing()),
1139 expSigId.getChannelNumber(), expSigId.getSpectralWidth())));
1140 } catch (NoMappingFoundException e) {
1141 log.warn(e.getMessage());
1142 break;
1143 }
1144 break;
1145 case EXP_OCH_SIGTYPE:
1146 try {
1147 U8 expOchSigType = match.get(MatchField.EXP_OCH_SIGTYPE);
1148 builder.add(matchOchSignalType(lookupOchSignalType((byte) expOchSigType.getValue())));
1149 } catch (NoMappingFoundException e) {
1150 log.warn(e.getMessage());
1151 break;
1152 }
1153 break;
1154 case EXP_ODU_SIG_ID:
1155 OduSignalId oduSignalId = OduSignalId.oduSignalId(match.get(MatchField.EXP_ODU_SIG_ID).getTpn(),
1156 match.get(MatchField.EXP_ODU_SIG_ID).getTslen(),
1157 match.get(MatchField.EXP_ODU_SIG_ID).getTsmap());
1158 builder.add(matchOduSignalId(oduSignalId));
Frank Wang5733c382017-03-28 10:15:18 +08001159 break;
Yafit Hadar73514612015-11-04 10:14:21 +02001160 case EXP_ODU_SIGTYPE:
1161 try {
1162 U8 oduSigType = match.get(MatchField.EXP_ODU_SIGTYPE);
1163 builder.add(matchOduSignalType(lookupOduSignalType((byte) oduSigType.getValue())));
1164 } catch (NoMappingFoundException e) {
1165 log.warn(e.getMessage());
1166 break;
1167 }
1168 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -07001169 case TUNNEL_ID:
1170 long tunnelId = match.get(MatchField.TUNNEL_ID).getValue();
1171 builder.matchTunnelId(tunnelId);
1172 break;
BitOhenryb40129a2015-11-30 12:41:18 +08001173 case ARP_OP:
1174 int arpOp = match.get(MatchField.ARP_OP).getOpcode();
1175 builder.matchArpOp(arpOp);
1176 break;
BitOhenrya331b182015-11-23 08:39:37 +08001177 case ARP_SHA:
1178 mac = MacAddress.valueOf(match.get(MatchField.ARP_SHA).getLong());
1179 builder.matchArpSha(mac);
1180 break;
BitOhenry296b4542015-11-24 08:41:58 +08001181 case ARP_SPA:
1182 ip = Ip4Address.valueOf(match.get(MatchField.ARP_SPA).getInt());
1183 builder.matchArpSpa(ip);
1184 break;
BitOhenry76430852015-11-20 19:04:49 +08001185 case ARP_THA:
1186 mac = MacAddress.valueOf(match.get(MatchField.ARP_THA).getLong());
1187 builder.matchArpTha(mac);
1188 break;
BitOhenryc1e5fcc2015-11-23 20:47:53 +08001189 case ARP_TPA:
1190 ip = Ip4Address.valueOf(match.get(MatchField.ARP_TPA).getInt());
1191 builder.matchArpTpa(ip);
1192 break;
Phaneendra Manda8db7d092016-06-04 00:17:24 +05301193 case NSP:
1194 if (selectorInterpreter != null) {
1195 try {
1196 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.NSP);
1197 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
1198 } catch (UnsupportedOperationException e) {
1199 log.debug(e.getMessage());
1200 }
1201 }
1202 break;
1203 case NSI:
1204 if (selectorInterpreter != null) {
1205 try {
1206 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.NSI);
1207 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
1208 } catch (UnsupportedOperationException e) {
1209 log.debug(e.getMessage());
1210 }
1211 }
1212 break;
1213 case ENCAP_ETH_TYPE:
1214 if (selectorInterpreter != null) {
1215 try {
1216 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.ENCAP_ETH_TYPE);
1217 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
1218 } catch (UnsupportedOperationException e) {
1219 log.debug(e.getMessage());
1220 }
1221 }
1222 break;
Frank Wang5733c382017-03-28 10:15:18 +08001223 case CONNTRACK_STATE:
1224 if (selectorInterpreter != null &&
1225 selectorInterpreter.supported(ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_STATE.type())) {
1226 try {
1227 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.CONNTRACK_STATE);
1228 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
1229 } catch (UnsupportedOperationException e) {
1230 log.debug(e.getMessage());
1231 }
1232 }
1233 break;
1234 case CONNTRACK_ZONE:
1235 if (selectorInterpreter != null &&
1236 selectorInterpreter.supported(ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_ZONE.type())) {
1237 try {
1238 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.CONNTRACK_ZONE);
1239 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
1240 } catch (UnsupportedOperationException e) {
1241 log.debug(e.getMessage());
1242 }
1243 }
1244 break;
1245 case CONNTRACK_MARK:
1246 if (selectorInterpreter != null &&
1247 selectorInterpreter.supported(ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_MARK.type())) {
1248 try {
1249 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.CONNTRACK_MARK);
1250 builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
1251 } catch (UnsupportedOperationException e) {
1252 log.debug(e.getMessage());
1253 }
1254 }
1255 break;
Pier Ventre6f630052016-10-18 09:58:41 -07001256 case OFDPA_OVID:
1257 if (selectorInterpreter != null &&
1258 selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_OVID.type())) {
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -07001259 if (isOF13OrLater(match)) {
Pier Ventre6f630052016-10-18 09:58:41 -07001260 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.OFDPA_OVID);
1261 builder.extension(selectorInterpreter.mapOxm(oxm),
1262 deviceId);
1263 } else {
1264 break;
1265 }
1266 }
1267 break;
Pier Ventre9cf536b2016-10-21 13:30:18 -07001268 case OFDPA_MPLS_L2_PORT:
1269 if (selectorInterpreter != null &&
1270 selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_MPLS_L2_PORT.type())) {
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -07001271 if (isOF13OrLater(match)) {
Pier Ventre9cf536b2016-10-21 13:30:18 -07001272 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.OFDPA_MPLS_L2_PORT);
1273 builder.extension(selectorInterpreter.mapOxm(oxm),
1274 deviceId);
1275 } else {
1276 break;
1277 }
1278 }
1279 break;
alshabib6b5cfec2014-09-18 17:42:18 -07001280 case MPLS_TC:
alshabib6b5cfec2014-09-18 17:42:18 -07001281 default:
1282 log.warn("Match type {} not yet implemented.", field.id);
alshabib6b5cfec2014-09-18 17:42:18 -07001283 }
1284 }
1285 return builder.build();
1286 }
Jonathan Hart3c259162015-10-21 21:31:19 -07001287
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -07001288 /**
1289 * @param obj OpenFlow object to test
1290 * @return true if OFObject is OF_13 or later
1291 */
1292 private static boolean isOF13OrLater(OFObject obj) {
1293 return obj.getVersion().wireVersion >= OFVersion.OF_13.wireVersion;
1294 }
1295
Claudine Chiu20cbd452017-08-30 19:23:11 -04001296 /**
1297 * Retrieves the driver handler for the specified device.
1298 *
1299 * @param deviceId device identifier
Rodrigo Duarte Sousae37d1292017-08-29 17:01:24 -03001300 * @param driverService service handle for the driver service
Claudine Chiu20cbd452017-08-30 19:23:11 -04001301 * @return driver handler
1302 */
Rodrigo Duarte Sousae37d1292017-08-29 17:01:24 -03001303 protected static DriverHandler getDriver(DeviceId deviceId, DriverService driverService) {
Claudine Chiu20cbd452017-08-30 19:23:11 -04001304 Driver driver = driverService.getDriver(deviceId);
1305 DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, deviceId));
Jonathan Hart3c259162015-10-21 21:31:19 -07001306 return handler;
1307 }
alshabib6b5cfec2014-09-18 17:42:18 -07001308}