blob: b8844084ec19794c276dc0e1b0716013547e3616 [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 Open Networking Laboratory
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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.provider.of.flow.impl;
alshabib6b5cfec2014-09-18 17:42:18 -070017
Jonathan Hart8cf212a2015-10-29 17:42:03 -070018import com.google.common.collect.Lists;
Ray Milkey84d5a292016-02-22 14:04:01 -080019
20import 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;
sangho8995ac52015-02-04 11:29:03 -080029import org.onosproject.core.DefaultGroupId;
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;
46import org.onosproject.net.flow.TrafficSelector;
47import org.onosproject.net.flow.TrafficTreatment;
Charles Chan14967c22015-12-07 11:11:50 -080048import org.onosproject.net.flow.criteria.ExtensionSelectorType.ExtensionSelectorTypes;
49import org.onosproject.net.flow.instructions.ExtensionTreatmentType.ExtensionTreatmentTypes;
Sho SHIMIZU9553bb82015-06-30 16:02:45 -070050import org.onosproject.net.flow.instructions.Instructions;
Brian O'Connorabafb502014-12-02 22:26:20 -080051import org.onosproject.openflow.controller.Dpid;
Charles Chan14967c22015-12-07 11:11:50 -080052import org.onosproject.openflow.controller.ExtensionSelectorInterpreter;
alshabib880b6442015-11-23 22:13:04 -080053import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter;
Brian O'Connor72cb19a2015-01-16 16:14:41 -080054import org.projectfloodlight.openflow.protocol.OFFlowMod;
alshabib6b5cfec2014-09-18 17:42:18 -070055import org.projectfloodlight.openflow.protocol.OFFlowRemoved;
56import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry;
Charles Chan14967c22015-12-07 11:11:50 -080057import org.projectfloodlight.openflow.protocol.OFMatchV3;
Brian O'Connor21564612015-12-05 19:24:59 -080058import org.projectfloodlight.openflow.protocol.OFVersion;
alshabib6b5cfec2014-09-18 17:42:18 -070059import org.projectfloodlight.openflow.protocol.action.OFAction;
Marc De Leenheer49087752014-10-23 13:54:09 -070060import org.projectfloodlight.openflow.protocol.action.OFActionCircuit;
Steffen Gebertba2d3b72015-10-22 11:14:31 +020061import org.projectfloodlight.openflow.protocol.action.OFActionEnqueue;
Marc De Leenheer49087752014-10-23 13:54:09 -070062import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter;
sangho8995ac52015-02-04 11:29:03 -080063import org.projectfloodlight.openflow.protocol.action.OFActionGroup;
alshabib6b5cfec2014-09-18 17:42:18 -070064import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
sangho3f97a17d2015-01-29 22:56:29 -080065import org.projectfloodlight.openflow.protocol.action.OFActionPopMpls;
alshabib6b5cfec2014-09-18 17:42:18 -070066import org.projectfloodlight.openflow.protocol.action.OFActionSetDlDst;
67import org.projectfloodlight.openflow.protocol.action.OFActionSetDlSrc;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080068import org.projectfloodlight.openflow.protocol.action.OFActionSetField;
alshabib6b5cfec2014-09-18 17:42:18 -070069import org.projectfloodlight.openflow.protocol.action.OFActionSetNwDst;
70import org.projectfloodlight.openflow.protocol.action.OFActionSetNwSrc;
Jonathan Hart8cf212a2015-10-29 17:42:03 -070071import org.projectfloodlight.openflow.protocol.action.OFActionSetQueue;
alshabib6b5cfec2014-09-18 17:42:18 -070072import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanPcp;
73import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanVid;
alshabib19fdc122014-10-03 11:38:19 -070074import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
Jonathan Hartcf783202014-11-24 18:55:42 -080075import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions;
alshabibbdcbb102015-04-22 14:16:38 -070076import org.projectfloodlight.openflow.protocol.instruction.OFInstructionGotoTable;
alshabib346b5b32015-03-06 00:42:16 -080077import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteActions;
Saurav Das86af8f12015-05-25 23:55:33 -070078import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteMetadata;
alshabib6b5cfec2014-09-18 17:42:18 -070079import org.projectfloodlight.openflow.protocol.match.Match;
80import org.projectfloodlight.openflow.protocol.match.MatchField;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080081import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
Yafit Hadar4cc65f72016-02-10 11:23:06 +020082import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigid;
alshabib346b5b32015-03-06 00:42:16 -080083import org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070084import org.projectfloodlight.openflow.types.CircuitSignalID;
alshabib6b5cfec2014-09-18 17:42:18 -070085import org.projectfloodlight.openflow.types.IPv4Address;
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080086import org.projectfloodlight.openflow.types.IPv6Address;
Jonathan Hart0e12fad2014-10-17 14:54:58 -070087import org.projectfloodlight.openflow.types.Masked;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080088import org.projectfloodlight.openflow.types.OFVlanVidMatch;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -070089import org.projectfloodlight.openflow.types.TransportPort;
sangho3f97a17d2015-01-29 22:56:29 -080090import org.projectfloodlight.openflow.types.U32;
Hyunsun Moona08c5d02015-07-14 17:53:00 -070091import org.projectfloodlight.openflow.types.U64;
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -070092import org.projectfloodlight.openflow.types.U8;
Jonathan Hartd0ef7522014-12-11 11:51:18 -080093import org.projectfloodlight.openflow.types.VlanPcp;
Yafit Hadar73514612015-11-04 10:14:21 +020094import org.projectfloodlight.openflow.types.OduSignalID;
alshabib6b5cfec2014-09-18 17:42:18 -070095import org.slf4j.Logger;
96
Jonathan Hart8cf212a2015-10-29 17:42:03 -070097import java.util.List;
98
99import static org.onosproject.net.flow.criteria.Criteria.matchLambda;
100import static org.onosproject.net.flow.criteria.Criteria.matchOchSignalType;
Yafit Hadar73514612015-11-04 10:14:21 +0200101import static org.onosproject.net.flow.criteria.Criteria.matchOduSignalType;
102import static org.onosproject.net.flow.criteria.Criteria.matchOduSignalId;
103import static org.onosproject.net.flow.instructions.Instructions.modL0Lambda;
104import static org.onosproject.net.flow.instructions.Instructions.modL1OduSignalId;
Jonathan Hart8cf212a2015-10-29 17:42:03 -0700105import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupChannelSpacing;
106import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupGridType;
107import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupOchSignalType;
Yafit Hadar73514612015-11-04 10:14:21 +0200108import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupOduSignalType;
Jonathan Hart8cf212a2015-10-29 17:42:03 -0700109import static org.slf4j.LoggerFactory.getLogger;
alshabib19fdc122014-10-03 11:38:19 -0700110
alshabib1c319ff2014-10-04 20:29:09 -0700111public class FlowEntryBuilder {
alshabib6b5cfec2014-09-18 17:42:18 -0700112 private final Logger log = getLogger(getClass());
113
114 private final OFFlowStatsEntry stat;
115 private final OFFlowRemoved removed;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800116 private final OFFlowMod flowMod;
alshabib6b5cfec2014-09-18 17:42:18 -0700117
118 private final Match match;
alshabib346b5b32015-03-06 00:42:16 -0800119
Jonathan Hart67fc0972015-03-19 15:21:20 -0700120 // All actions are contained in an OFInstruction. For OF1.0
121 // the instruction type is apply instruction (immediate set in ONOS speak)
alshabib346b5b32015-03-06 00:42:16 -0800122 private final List<OFInstruction> instructions;
alshabib6b5cfec2014-09-18 17:42:18 -0700123
124 private final Dpid dpid;
125
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800126 public enum FlowType { STAT, REMOVED, MOD }
127
128 private final FlowType type;
alshabib6b5cfec2014-09-18 17:42:18 -0700129
Jonathan Hart3c259162015-10-21 21:31:19 -0700130 private final DriverService driverService;
131
132 public FlowEntryBuilder(Dpid dpid, OFFlowStatsEntry entry, DriverService driverService) {
Saurav Dasfa2fa932015-03-03 11:29:48 -0800133 this.stat = entry;
134 this.match = entry.getMatch();
alshabib346b5b32015-03-06 00:42:16 -0800135 this.instructions = getInstructions(entry);
Saurav Dasfa2fa932015-03-03 11:29:48 -0800136 this.dpid = dpid;
137 this.removed = null;
138 this.flowMod = null;
139 this.type = FlowType.STAT;
Jonathan Hart3c259162015-10-21 21:31:19 -0700140 this.driverService = driverService;
Saurav Dasfa2fa932015-03-03 11:29:48 -0800141 }
142
Jonathan Hart3c259162015-10-21 21:31:19 -0700143 public FlowEntryBuilder(Dpid dpid, OFFlowRemoved removed, DriverService driverService) {
alshabib6b5cfec2014-09-18 17:42:18 -0700144 this.match = removed.getMatch();
145 this.removed = removed;
alshabib6b5cfec2014-09-18 17:42:18 -0700146 this.dpid = dpid;
alshabib346b5b32015-03-06 00:42:16 -0800147 this.instructions = null;
alshabib6b5cfec2014-09-18 17:42:18 -0700148 this.stat = null;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800149 this.flowMod = null;
150 this.type = FlowType.REMOVED;
Jonathan Hart3c259162015-10-21 21:31:19 -0700151 this.driverService = driverService;
alshabib6b5cfec2014-09-18 17:42:18 -0700152 }
153
Jonathan Hart3c259162015-10-21 21:31:19 -0700154 public FlowEntryBuilder(Dpid dpid, OFFlowMod fm, DriverService driverService) {
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800155 this.match = fm.getMatch();
156 this.dpid = dpid;
alshabib346b5b32015-03-06 00:42:16 -0800157 this.instructions = getInstructions(fm);
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800158 this.type = FlowType.MOD;
159 this.flowMod = fm;
160 this.stat = null;
161 this.removed = null;
Jonathan Hart3c259162015-10-21 21:31:19 -0700162 this.driverService = driverService;
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800163 }
alshabib1c319ff2014-10-04 20:29:09 -0700164
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800165 public FlowEntry build(FlowEntryState... state) {
Brian O'Connor21564612015-12-05 19:24:59 -0800166 FlowRule.Builder builder;
167 try {
168 switch (this.type) {
169 case STAT:
170 builder = DefaultFlowRule.builder()
171 .forDevice(DeviceId.deviceId(Dpid.uri(dpid)))
172 .withSelector(buildSelector())
173 .withTreatment(buildTreatment())
174 .withPriority(stat.getPriority())
175 .makeTemporary(stat.getIdleTimeout())
Jonathan Hartd1ce4b02016-01-11 13:28:36 -0800176 .withCookie(stat.getCookie().getValue());
177 if (stat.getVersion() != OFVersion.OF_10) {
178 builder.forTable(stat.getTableId().getValue());
179 }
alshabibbdcbb102015-04-22 14:16:38 -0700180
Brian O'Connor21564612015-12-05 19:24:59 -0800181 return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
182 stat.getDurationSec(),
183 stat.getPacketCount().getValue(),
184 stat.getByteCount().getValue());
185 case REMOVED:
186 builder = DefaultFlowRule.builder()
187 .forDevice(DeviceId.deviceId(Dpid.uri(dpid)))
188 .withSelector(buildSelector())
189 .withPriority(removed.getPriority())
190 .makeTemporary(removed.getIdleTimeout())
191 .withCookie(removed.getCookie().getValue());
192 if (removed.getVersion() != OFVersion.OF_10) {
193 builder.forTable(removed.getTableId().getValue());
194 }
alshabibbdcbb102015-04-22 14:16:38 -0700195
Brian O'Connor21564612015-12-05 19:24:59 -0800196 return new DefaultFlowEntry(builder.build(), FlowEntryState.REMOVED,
197 removed.getDurationSec(),
198 removed.getPacketCount().getValue(),
199 removed.getByteCount().getValue());
200 case MOD:
201 FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED;
202 builder = DefaultFlowRule.builder()
203 .forDevice(DeviceId.deviceId(Dpid.uri(dpid)))
204 .withSelector(buildSelector())
205 .withTreatment(buildTreatment())
206 .withPriority(flowMod.getPriority())
207 .makeTemporary(flowMod.getIdleTimeout())
208 .withCookie(flowMod.getCookie().getValue());
209 if (flowMod.getVersion() != OFVersion.OF_10) {
210 builder.forTable(flowMod.getTableId().getValue());
211 }
alshabibbdcbb102015-04-22 14:16:38 -0700212
Brian O'Connor21564612015-12-05 19:24:59 -0800213 return new DefaultFlowEntry(builder.build(), flowState, 0, 0, 0);
214 default:
215 log.error("Unknown flow type : {}", this.type);
216 return null;
217 }
218 } catch (UnsupportedOperationException e) {
219 log.warn("Error building flow entry", e);
220 return null;
alshabib6b5cfec2014-09-18 17:42:18 -0700221 }
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800222
alshabib6b5cfec2014-09-18 17:42:18 -0700223 }
224
alshabib346b5b32015-03-06 00:42:16 -0800225 private List<OFInstruction> getInstructions(OFFlowMod entry) {
alshabib19fdc122014-10-03 11:38:19 -0700226 switch (entry.getVersion()) {
227 case OF_10:
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700228 return Lists.newArrayList(OFFactoryVer13.INSTANCE.instructions()
229 .applyActions(
230 entry.getActions()));
alshabib19fdc122014-10-03 11:38:19 -0700231 case OF_11:
232 case OF_12:
233 case OF_13:
alshabib346b5b32015-03-06 00:42:16 -0800234 return entry.getInstructions();
235 default:
236 log.warn("Unknown OF version {}", entry.getVersion());
237 }
238 return Lists.newLinkedList();
239 }
240
241 private List<OFInstruction> getInstructions(OFFlowStatsEntry entry) {
242 switch (entry.getVersion()) {
243 case OF_10:
244 return Lists.newArrayList(
245 OFFactoryVer13.INSTANCE.instructions().applyActions(entry.getActions()));
246 case OF_11:
247 case OF_12:
248 case OF_13:
249 return entry.getInstructions();
alshabib19fdc122014-10-03 11:38:19 -0700250 default:
251 log.warn("Unknown OF version {}", entry.getVersion());
252 }
253 return Lists.newLinkedList();
254 }
alshabib6b5cfec2014-09-18 17:42:18 -0700255
256 private TrafficTreatment buildTreatment() {
tom9a693fd2014-10-03 11:32:19 -0700257 TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
alshabib346b5b32015-03-06 00:42:16 -0800258 for (OFInstruction in : instructions) {
259 switch (in.getType()) {
260 case GOTO_TABLE:
alshabibbdcbb102015-04-22 14:16:38 -0700261 builder.transition(((int) ((OFInstructionGotoTable) in)
262 .getTableId().getValue()));
alshabib346b5b32015-03-06 00:42:16 -0800263 break;
264 case WRITE_METADATA:
Saurav Das86af8f12015-05-25 23:55:33 -0700265 OFInstructionWriteMetadata m = (OFInstructionWriteMetadata) in;
266 builder.writeMetadata(m.getMetadata().getValue(),
267 m.getMetadataMask().getValue());
alshabib346b5b32015-03-06 00:42:16 -0800268 break;
269 case WRITE_ACTIONS:
270 builder.deferred();
271 buildActions(((OFInstructionWriteActions) in).getActions(),
272 builder);
273 break;
274 case APPLY_ACTIONS:
275 builder.immediate();
276 buildActions(((OFInstructionApplyActions) in).getActions(),
277 builder);
278 break;
279 case CLEAR_ACTIONS:
280 builder.wipeDeferred();
281 break;
282 case EXPERIMENTER:
283 break;
284 case METER:
285 break;
286 default:
287 log.warn("Unknown instructions type {}", in.getType());
alshabib6b5cfec2014-09-18 17:42:18 -0700288 }
289 }
290
291 return builder.build();
292 }
293
alshabib346b5b32015-03-06 00:42:16 -0800294 private TrafficTreatment.Builder buildActions(List<OFAction> actions,
295 TrafficTreatment.Builder builder) {
Charles Chan14967c22015-12-07 11:11:50 -0800296 DriverHandler driverHandler = getDriver(dpid);
297 ExtensionTreatmentInterpreter treatmentInterpreter;
298 if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
299 treatmentInterpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class);
300 } else {
301 treatmentInterpreter = null;
302 }
303
alshabib346b5b32015-03-06 00:42:16 -0800304 for (OFAction act : actions) {
305 switch (act.getType()) {
306 case OUTPUT:
307 OFActionOutput out = (OFActionOutput) act;
308 builder.setOutput(
309 PortNumber.portNumber(out.getPort().getPortNumber()));
310 break;
311 case SET_VLAN_VID:
312 OFActionSetVlanVid vlan = (OFActionSetVlanVid) act;
313 builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan()));
314 break;
315 case SET_VLAN_PCP:
316 OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act;
317 builder.setVlanPcp(pcp.getVlanPcp().getValue());
318 break;
319 case SET_DL_DST:
320 OFActionSetDlDst dldst = (OFActionSetDlDst) act;
321 builder.setEthDst(
322 MacAddress.valueOf(dldst.getDlAddr().getLong()));
323 break;
324 case SET_DL_SRC:
325 OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act;
326 builder.setEthSrc(
327 MacAddress.valueOf(dlsrc.getDlAddr().getLong()));
alshabib346b5b32015-03-06 00:42:16 -0800328 break;
329 case SET_NW_DST:
330 OFActionSetNwDst nwdst = (OFActionSetNwDst) act;
331 IPv4Address di = nwdst.getNwAddr();
332 builder.setIpDst(Ip4Address.valueOf(di.getInt()));
333 break;
334 case SET_NW_SRC:
335 OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act;
336 IPv4Address si = nwsrc.getNwAddr();
337 builder.setIpSrc(Ip4Address.valueOf(si.getInt()));
338 break;
339 case EXPERIMENTER:
340 OFActionExperimenter exp = (OFActionExperimenter) act;
341 if (exp.getExperimenter() == 0x80005A06 ||
342 exp.getExperimenter() == 0x748771) {
343 OFActionCircuit ct = (OFActionCircuit) exp;
Yafit Hadar4cc65f72016-02-10 11:23:06 +0200344 CircuitSignalID circuitSignalID = ((OFOxmOchSigid) ct.getField()).getValue();
345 builder.add(Instructions.modL0Lambda(Lambda.ochSignal(
346 lookupGridType(circuitSignalID.getGridType()),
347 lookupChannelSpacing(circuitSignalID.getChannelSpacing()),
348 circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth())));
samueljcc4f4d25a2015-12-07 10:52:28 +0800349 } else if (exp.getExperimenter() == 0x2320) {
Charles Chan14967c22015-12-07 11:11:50 -0800350 if (treatmentInterpreter != null) {
351 builder.extension(treatmentInterpreter.mapAction(exp),
samueljcc4f4d25a2015-12-07 10:52:28 +0800352 DeviceId.deviceId(Dpid.uri(dpid)));
353 }
alshabib346b5b32015-03-06 00:42:16 -0800354 } else {
355 log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter());
356 }
357 break;
358 case SET_FIELD:
359 OFActionSetField setField = (OFActionSetField) act;
Jonathan Hart3c259162015-10-21 21:31:19 -0700360 handleSetField(builder, setField);
alshabib346b5b32015-03-06 00:42:16 -0800361 break;
362 case POP_MPLS:
363 OFActionPopMpls popMpls = (OFActionPopMpls) act;
Ray Milkey84d5a292016-02-22 14:04:01 -0800364 builder.popMpls(new EthType(popMpls.getEthertype().getValue()));
alshabib346b5b32015-03-06 00:42:16 -0800365 break;
366 case PUSH_MPLS:
367 builder.pushMpls();
368 break;
369 case COPY_TTL_IN:
370 builder.copyTtlIn();
371 break;
372 case COPY_TTL_OUT:
373 builder.copyTtlOut();
374 break;
375 case DEC_MPLS_TTL:
376 builder.decMplsTtl();
377 break;
378 case DEC_NW_TTL:
379 builder.decNwTtl();
380 break;
381 case GROUP:
382 OFActionGroup group = (OFActionGroup) act;
383 builder.group(new DefaultGroupId(group.getGroup().getGroupNumber()));
384 break;
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200385 case SET_QUEUE:
386 OFActionSetQueue setQueue = (OFActionSetQueue) act;
387 builder.setQueue(setQueue.getQueueId());
388 break;
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200389 case ENQUEUE:
390 OFActionEnqueue enqueue = (OFActionEnqueue) act;
391 builder.setQueue(enqueue.getQueueId(), PortNumber.portNumber(enqueue.getPort().getPortNumber()));
392 break;
Jonathan Hart67fc0972015-03-19 15:21:20 -0700393 case STRIP_VLAN:
alshabib346b5b32015-03-06 00:42:16 -0800394 case POP_VLAN:
395 builder.popVlan();
396 break;
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -0700397 case PUSH_VLAN:
398 builder.pushVlan();
399 break;
alshabib346b5b32015-03-06 00:42:16 -0800400 case SET_TP_DST:
401 case SET_TP_SRC:
402 case POP_PBB:
403 case PUSH_PBB:
alshabib346b5b32015-03-06 00:42:16 -0800404 case SET_MPLS_LABEL:
405 case SET_MPLS_TC:
406 case SET_MPLS_TTL:
407 case SET_NW_ECN:
408 case SET_NW_TOS:
409 case SET_NW_TTL:
alshabib346b5b32015-03-06 00:42:16 -0800410
alshabib346b5b32015-03-06 00:42:16 -0800411 default:
412 log.warn("Action type {} not yet implemented.", act.getType());
413 }
414 }
415 return builder;
416 }
417
418
Jonathan Hart3c259162015-10-21 21:31:19 -0700419 private void handleSetField(TrafficTreatment.Builder builder, OFActionSetField action) {
Charles Chan14967c22015-12-07 11:11:50 -0800420 DriverHandler driverHandler = getDriver(dpid);
421 ExtensionTreatmentInterpreter treatmentInterpreter;
422 if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
423 treatmentInterpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class);
424 } else {
425 treatmentInterpreter = null;
426 }
427
Jonathan Hart3c259162015-10-21 21:31:19 -0700428 OFOxm<?> oxm = action.getField();
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800429 switch (oxm.getMatchField().id) {
430 case VLAN_PCP:
431 @SuppressWarnings("unchecked")
432 OFOxm<VlanPcp> vlanpcp = (OFOxm<VlanPcp>) oxm;
433 builder.setVlanPcp(vlanpcp.getValue().getValue());
434 break;
435 case VLAN_VID:
Charles Chan14967c22015-12-07 11:11:50 -0800436 if (treatmentInterpreter != null &&
437 treatmentInterpreter.supported(ExtensionTreatmentTypes.OFDPA_SET_VLAN_ID.type())) {
438 builder.extension(treatmentInterpreter.mapAction(action),
439 DeviceId.deviceId(Dpid.uri(dpid)));
440 } else {
441 @SuppressWarnings("unchecked")
442 OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm;
443 builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan()));
444 }
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800445 break;
446 case ETH_DST:
447 @SuppressWarnings("unchecked")
448 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethdst =
449 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
450 builder.setEthDst(MacAddress.valueOf(ethdst.getValue().getLong()));
451 break;
452 case ETH_SRC:
453 @SuppressWarnings("unchecked")
454 OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethsrc =
455 (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
456 builder.setEthSrc(MacAddress.valueOf(ethsrc.getValue().getLong()));
457 break;
458 case IPV4_DST:
459 @SuppressWarnings("unchecked")
460 OFOxm<IPv4Address> ip4dst = (OFOxm<IPv4Address>) oxm;
461 builder.setIpDst(Ip4Address.valueOf(ip4dst.getValue().getInt()));
462 break;
463 case IPV4_SRC:
464 @SuppressWarnings("unchecked")
465 OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm;
466 builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt()));
467 break;
sangho3f97a17d2015-01-29 22:56:29 -0800468 case MPLS_LABEL:
469 @SuppressWarnings("unchecked")
470 OFOxm<U32> labelId = (OFOxm<U32>) oxm;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100471 builder.setMpls(MplsLabel.mplsLabel((int) labelId.getValue().getValue()));
sangho3f97a17d2015-01-29 22:56:29 -0800472 break;
Saurav Das73a7dd42015-08-19 22:20:31 -0700473 case MPLS_BOS:
474 @SuppressWarnings("unchecked")
475 OFOxm<U8> mplsBos = (OFOxm<U8>) oxm;
476 builder.setMplsBos(mplsBos.getValue() == U8.ZERO ? false : true);
477 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700478 case TUNNEL_ID:
479 @SuppressWarnings("unchecked")
480 OFOxm<U64> tunnelId = (OFOxm<U64>) oxm;
481 builder.setTunnelId(tunnelId.getValue().getValue());
482 break;
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700483 case TCP_DST:
484 @SuppressWarnings("unchecked")
485 OFOxm<TransportPort> tcpdst = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700486 builder.setTcpDst(TpPort.tpPort(tcpdst.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700487 break;
488 case TCP_SRC:
489 @SuppressWarnings("unchecked")
490 OFOxm<TransportPort> tcpsrc = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700491 builder.setTcpSrc(TpPort.tpPort(tcpsrc.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700492 break;
493 case UDP_DST:
494 @SuppressWarnings("unchecked")
495 OFOxm<TransportPort> udpdst = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700496 builder.setUdpDst(TpPort.tpPort(udpdst.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700497 break;
498 case UDP_SRC:
499 @SuppressWarnings("unchecked")
500 OFOxm<TransportPort> udpsrc = (OFOxm<TransportPort>) oxm;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700501 builder.setUdpSrc(TpPort.tpPort(udpsrc.getValue().getPort()));
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700502 break;
Jonathan Hart3c259162015-10-21 21:31:19 -0700503 case TUNNEL_IPV4_DST:
Charles Chan14967c22015-12-07 11:11:50 -0800504 if (treatmentInterpreter != null &&
505 treatmentInterpreter.supported(ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) {
506 builder.extension(treatmentInterpreter.mapAction(action), DeviceId.deviceId(Dpid.uri(dpid)));
Jonathan Hart3c259162015-10-21 21:31:19 -0700507 }
508 break;
Yafit Hadar73514612015-11-04 10:14:21 +0200509 case EXP_ODU_SIG_ID:
510 @SuppressWarnings("unchecked")
511 OFOxm<OduSignalID> oduID = (OFOxm<OduSignalID>) oxm;
512 OduSignalID oduSignalID = oduID.getValue();
513 OduSignalId oduSignalId = OduSignalId.oduSignalId(oduSignalID.getTpn(),
514 oduSignalID.getTslen(),
515 oduSignalID.getTsmap());
516 builder.add(modL1OduSignalId(oduSignalId));
517 break;
518 case EXP_OCH_SIG_ID:
519 try {
520 @SuppressWarnings("unchecked")
521 OFOxm<CircuitSignalID> ochId = (OFOxm<CircuitSignalID>) oxm;
522 CircuitSignalID circuitSignalID = ochId.getValue();
523 builder.add(modL0Lambda(Lambda.ochSignal(
524 lookupGridType(circuitSignalID.getGridType()),
525 lookupChannelSpacing(circuitSignalID.getChannelSpacing()),
526 circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth())));
527 } catch (NoMappingFoundException e) {
528 log.warn(e.getMessage());
529 break;
530 }
531 break;
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800532 case ARP_OP:
533 case ARP_SHA:
534 case ARP_SPA:
535 case ARP_THA:
536 case ARP_TPA:
537 case BSN_EGR_PORT_GROUP_ID:
538 case BSN_GLOBAL_VRF_ALLOWED:
539 case BSN_IN_PORTS_128:
540 case BSN_L3_DST_CLASS_ID:
541 case BSN_L3_INTERFACE_CLASS_ID:
542 case BSN_L3_SRC_CLASS_ID:
543 case BSN_LAG_ID:
544 case BSN_TCP_FLAGS:
545 case BSN_UDF0:
546 case BSN_UDF1:
547 case BSN_UDF2:
548 case BSN_UDF3:
549 case BSN_UDF4:
550 case BSN_UDF5:
551 case BSN_UDF6:
552 case BSN_UDF7:
553 case BSN_VLAN_XLATE_PORT_GROUP_ID:
554 case BSN_VRF:
555 case ETH_TYPE:
556 case ICMPV4_CODE:
557 case ICMPV4_TYPE:
558 case ICMPV6_CODE:
559 case ICMPV6_TYPE:
560 case IN_PHY_PORT:
561 case IN_PORT:
562 case IPV6_DST:
563 case IPV6_FLABEL:
564 case IPV6_ND_SLL:
565 case IPV6_ND_TARGET:
566 case IPV6_ND_TLL:
567 case IPV6_SRC:
568 case IP_DSCP:
569 case IP_ECN:
570 case IP_PROTO:
571 case METADATA:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800572 case MPLS_TC:
573 case OCH_SIGID:
574 case OCH_SIGID_BASIC:
575 case OCH_SIGTYPE:
576 case OCH_SIGTYPE_BASIC:
577 case SCTP_DST:
578 case SCTP_SRC:
Yafit Hadar73514612015-11-04 10:14:21 +0200579 case EXP_ODU_SIGTYPE:
580 case EXP_OCH_SIGTYPE:
Jonathan Hartd0ef7522014-12-11 11:51:18 -0800581 default:
582 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
583 break;
584 }
585 }
586
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700587 // CHECKSTYLE IGNORE MethodLength FOR NEXT 1 LINES
alshabib6b5cfec2014-09-18 17:42:18 -0700588 private TrafficSelector buildSelector() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800589 MacAddress mac;
590 Ip4Prefix ip4Prefix;
591 Ip6Address ip6Address;
592 Ip6Prefix ip6Prefix;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800593 Ip4Address ip;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800594
Charles Chan14967c22015-12-07 11:11:50 -0800595 DriverHandler driverHandler = getDriver(dpid);
596 ExtensionSelectorInterpreter selectorInterpreter;
597 if (driverHandler.hasBehaviour(ExtensionSelectorInterpreter.class)) {
598 selectorInterpreter = driverHandler.behaviour(ExtensionSelectorInterpreter.class);
599 } else {
600 selectorInterpreter = null;
601 }
602
tom9a693fd2014-10-03 11:32:19 -0700603 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
alshabib6b5cfec2014-09-18 17:42:18 -0700604 for (MatchField<?> field : match.getMatchFields()) {
605 switch (field.id) {
606 case IN_PORT:
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800607 builder.matchInPort(PortNumber
alshabib010c31d2014-09-26 10:01:12 -0700608 .portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
alshabib6b5cfec2014-09-18 17:42:18 -0700609 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800610 case IN_PHY_PORT:
611 builder.matchInPhyPort(PortNumber
612 .portNumber(match.get(MatchField.IN_PHY_PORT).getPortNumber()));
613 break;
614 case METADATA:
615 long metadata =
616 match.get(MatchField.METADATA).getValue().getValue();
617 builder.matchMetadata(metadata);
618 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700619 case ETH_DST:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800620 if (match.isPartiallyMasked(MatchField.ETH_DST)) {
621 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
622 match.getMasked(MatchField.ETH_DST);
623 builder.matchEthDstMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
624 MacAddress.valueOf(maskedMac.getMask().getLong()));
625 } else {
626 mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
627 builder.matchEthDst(mac);
628 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800629 break;
630 case ETH_SRC:
Saurav Das9d6c86b2016-02-19 09:01:07 -0800631 if (match.isPartiallyMasked(MatchField.ETH_SRC)) {
632 Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac =
633 match.getMasked(MatchField.ETH_SRC);
634 builder.matchEthSrcMasked(MacAddress.valueOf(maskedMac.getValue().getLong()),
635 MacAddress.valueOf(maskedMac.getMask().getLong()));
636 } else {
637 mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
638 builder.matchEthSrc(mac);
639 }
alshabib6b5cfec2014-09-18 17:42:18 -0700640 break;
641 case ETH_TYPE:
642 int ethType = match.get(MatchField.ETH_TYPE).getValue();
Jonathan Hart8cf212a2015-10-29 17:42:03 -0700643 builder.matchEthType((short) ethType);
alshabib6b5cfec2014-09-18 17:42:18 -0700644 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700645 case VLAN_VID:
Charles Chan14967c22015-12-07 11:11:50 -0800646 if (selectorInterpreter != null &&
647 selectorInterpreter.supported(ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
648 if (match.getVersion().equals(OFVersion.OF_13)) {
649 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.VLAN_VID);
650 builder.extension(selectorInterpreter.mapOxm(oxm),
651 DeviceId.deviceId(Dpid.uri(dpid)));
652 } else {
653 break;
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800654 }
655 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800656 VlanId vlanId = null;
657 if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
658 Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
659 if (masked.getValue().equals(OFVlanVidMatch.PRESENT)
660 && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
661 vlanId = VlanId.ANY;
662 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700663 } else {
Charles Chan14967c22015-12-07 11:11:50 -0800664 if (!match.get(MatchField.VLAN_VID).isPresentBitSet()) {
665 vlanId = VlanId.NONE;
666 } else {
667 vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
668 }
Jonathan Hart1468fee2015-07-16 18:50:34 -0700669 }
Charles Chan14967c22015-12-07 11:11:50 -0800670 if (vlanId != null) {
671 builder.matchVlanId(vlanId);
672 }
Jonathan Hart6cd2f352015-01-13 17:44:45 -0800673 }
alshabib6b5cfec2014-09-18 17:42:18 -0700674 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800675 case VLAN_PCP:
676 byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
677 builder.matchVlanPcp(vlanPcp);
678 break;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800679 case IP_DSCP:
680 byte ipDscp = match.get(MatchField.IP_DSCP).getDscpValue();
681 builder.matchIPDscp(ipDscp);
682 break;
683 case IP_ECN:
684 byte ipEcn = match.get(MatchField.IP_ECN).getEcnValue();
685 builder.matchIPEcn(ipEcn);
686 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800687 case IP_PROTO:
688 short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
689 builder.matchIPProtocol((byte) proto);
690 break;
691 case IPV4_SRC:
692 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
693 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800694 ip4Prefix = Ip4Prefix.valueOf(
695 maskedIp.getValue().getInt(),
696 maskedIp.getMask().asCidrMaskLength());
697 } else {
698 ip4Prefix = Ip4Prefix.valueOf(
699 match.get(MatchField.IPV4_SRC).getInt(),
700 Ip4Prefix.MAX_MASK_LENGTH);
701 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800702 builder.matchIPSrc(ip4Prefix);
703 break;
704 case IPV4_DST:
705 if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
706 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800707 ip4Prefix = Ip4Prefix.valueOf(
708 maskedIp.getValue().getInt(),
709 maskedIp.getMask().asCidrMaskLength());
710 } else {
711 ip4Prefix = Ip4Prefix.valueOf(
712 match.get(MatchField.IPV4_DST).getInt(),
713 Ip4Prefix.MAX_MASK_LENGTH);
714 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800715 builder.matchIPDst(ip4Prefix);
Jonathan Hart34bc6142014-10-17 11:00:43 -0700716 break;
717 case TCP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700718 builder.matchTcpSrc(TpPort.tpPort(match.get(MatchField.TCP_SRC).getPort()));
Jonathan Hart34bc6142014-10-17 11:00:43 -0700719 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800720 case TCP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700721 builder.matchTcpDst(TpPort.tpPort(match.get(MatchField.TCP_DST).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800722 break;
723 case UDP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700724 builder.matchUdpSrc(TpPort.tpPort(match.get(MatchField.UDP_SRC).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800725 break;
726 case UDP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700727 builder.matchUdpDst(TpPort.tpPort(match.get(MatchField.UDP_DST).getPort()));
Sho SHIMIZU6f1b09e2015-05-05 11:26:22 -0700728 break;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100729 case MPLS_LABEL:
730 builder.matchMplsLabel(MplsLabel.mplsLabel((int) match.get(MatchField.MPLS_LABEL)
731 .getValue()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800732 break;
Saurav Dasffc5bbc2015-08-18 23:30:19 -0700733 case MPLS_BOS:
734 builder.matchMplsBos(match.get(MatchField.MPLS_BOS).getValue());
735 break;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800736 case SCTP_SRC:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700737 builder.matchSctpSrc(TpPort.tpPort(match.get(MatchField.SCTP_SRC).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800738 break;
739 case SCTP_DST:
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700740 builder.matchSctpDst(TpPort.tpPort(match.get(MatchField.SCTP_DST).getPort()));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800741 break;
742 case ICMPV4_TYPE:
743 byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
744 builder.matchIcmpType(icmpType);
745 break;
746 case ICMPV4_CODE:
747 byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode();
748 builder.matchIcmpCode(icmpCode);
749 break;
750 case IPV6_SRC:
751 if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
752 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
753 ip6Prefix = Ip6Prefix.valueOf(
754 maskedIp.getValue().getBytes(),
755 maskedIp.getMask().asCidrMaskLength());
756 } else {
757 ip6Prefix = Ip6Prefix.valueOf(
758 match.get(MatchField.IPV6_SRC).getBytes(),
759 Ip6Prefix.MAX_MASK_LENGTH);
760 }
761 builder.matchIPv6Src(ip6Prefix);
762 break;
763 case IPV6_DST:
764 if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
765 Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
766 ip6Prefix = Ip6Prefix.valueOf(
767 maskedIp.getValue().getBytes(),
768 maskedIp.getMask().asCidrMaskLength());
769 } else {
770 ip6Prefix = Ip6Prefix.valueOf(
771 match.get(MatchField.IPV6_DST).getBytes(),
772 Ip6Prefix.MAX_MASK_LENGTH);
773 }
774 builder.matchIPv6Dst(ip6Prefix);
775 break;
776 case IPV6_FLABEL:
777 int flowLabel =
778 match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue();
779 builder.matchIPv6FlowLabel(flowLabel);
780 break;
781 case ICMPV6_TYPE:
782 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
783 builder.matchIcmpv6Type(icmpv6type);
784 break;
785 case ICMPV6_CODE:
786 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
787 builder.matchIcmpv6Code(icmpv6code);
788 break;
789 case IPV6_ND_TARGET:
790 ip6Address =
791 Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes());
792 builder.matchIPv6NDTargetAddress(ip6Address);
793 break;
794 case IPV6_ND_SLL:
795 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong());
796 builder.matchIPv6NDSourceLinkLayerAddress(mac);
797 break;
798 case IPV6_ND_TLL:
799 mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong());
800 builder.matchIPv6NDTargetLinkLayerAddress(mac);
801 break;
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800802 case IPV6_EXTHDR:
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800803 builder.matchIPv6ExthdrFlags((short) match.get(MatchField.IPV6_EXTHDR)
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700804 .getValue());
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800805 break;
Marc De Leenheer49087752014-10-23 13:54:09 -0700806 case OCH_SIGID:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700807 CircuitSignalID sigId = match.get(MatchField.OCH_SIGID);
808 builder.add(matchLambda(Lambda.ochSignal(
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700809 lookupGridType(sigId.getGridType()), lookupChannelSpacing(sigId.getChannelSpacing()),
Marc De Leenheer0b8b2ef2015-08-03 15:39:00 -0700810 sigId.getChannelNumber(), sigId.getSpectralWidth())
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700811 ));
Marc De Leenheer49087752014-10-23 13:54:09 -0700812 break;
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800813 case OCH_SIGTYPE:
Sho SHIMIZU4f828ee2015-05-28 09:38:21 -0700814 U8 sigType = match.get(MatchField.OCH_SIGTYPE);
Sho SHIMIZUc17042d2015-05-28 12:07:23 -0700815 builder.add(matchOchSignalType(lookupOchSignalType((byte) sigType.getValue())));
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800816 break;
Yafit Hadar73514612015-11-04 10:14:21 +0200817 case EXP_OCH_SIG_ID:
818 try {
819 CircuitSignalID expSigId = match.get(MatchField.EXP_OCH_SIG_ID);
820 builder.add(matchLambda(Lambda.ochSignal(
821 lookupGridType(expSigId.getGridType()), lookupChannelSpacing(expSigId.getChannelSpacing()),
822 expSigId.getChannelNumber(), expSigId.getSpectralWidth())));
823 } catch (NoMappingFoundException e) {
824 log.warn(e.getMessage());
825 break;
826 }
827 break;
828 case EXP_OCH_SIGTYPE:
829 try {
830 U8 expOchSigType = match.get(MatchField.EXP_OCH_SIGTYPE);
831 builder.add(matchOchSignalType(lookupOchSignalType((byte) expOchSigType.getValue())));
832 } catch (NoMappingFoundException e) {
833 log.warn(e.getMessage());
834 break;
835 }
836 break;
837 case EXP_ODU_SIG_ID:
838 OduSignalId oduSignalId = OduSignalId.oduSignalId(match.get(MatchField.EXP_ODU_SIG_ID).getTpn(),
839 match.get(MatchField.EXP_ODU_SIG_ID).getTslen(),
840 match.get(MatchField.EXP_ODU_SIG_ID).getTsmap());
841 builder.add(matchOduSignalId(oduSignalId));
842 break;
843 case EXP_ODU_SIGTYPE:
844 try {
845 U8 oduSigType = match.get(MatchField.EXP_ODU_SIGTYPE);
846 builder.add(matchOduSignalType(lookupOduSignalType((byte) oduSigType.getValue())));
847 } catch (NoMappingFoundException e) {
848 log.warn(e.getMessage());
849 break;
850 }
851 break;
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700852 case TUNNEL_ID:
853 long tunnelId = match.get(MatchField.TUNNEL_ID).getValue();
854 builder.matchTunnelId(tunnelId);
855 break;
BitOhenryb40129a2015-11-30 12:41:18 +0800856 case ARP_OP:
857 int arpOp = match.get(MatchField.ARP_OP).getOpcode();
858 builder.matchArpOp(arpOp);
859 break;
BitOhenrya331b182015-11-23 08:39:37 +0800860 case ARP_SHA:
861 mac = MacAddress.valueOf(match.get(MatchField.ARP_SHA).getLong());
862 builder.matchArpSha(mac);
863 break;
BitOhenry296b4542015-11-24 08:41:58 +0800864 case ARP_SPA:
865 ip = Ip4Address.valueOf(match.get(MatchField.ARP_SPA).getInt());
866 builder.matchArpSpa(ip);
867 break;
BitOhenry76430852015-11-20 19:04:49 +0800868 case ARP_THA:
869 mac = MacAddress.valueOf(match.get(MatchField.ARP_THA).getLong());
870 builder.matchArpTha(mac);
871 break;
BitOhenryc1e5fcc2015-11-23 20:47:53 +0800872 case ARP_TPA:
873 ip = Ip4Address.valueOf(match.get(MatchField.ARP_TPA).getInt());
874 builder.matchArpTpa(ip);
875 break;
alshabib6b5cfec2014-09-18 17:42:18 -0700876 case MPLS_TC:
alshabib6b5cfec2014-09-18 17:42:18 -0700877 default:
878 log.warn("Match type {} not yet implemented.", field.id);
alshabib6b5cfec2014-09-18 17:42:18 -0700879 }
880 }
881 return builder.build();
882 }
Jonathan Hart3c259162015-10-21 21:31:19 -0700883
884 private DriverHandler getDriver(Dpid dpid) {
885 DeviceId deviceId = DeviceId.deviceId(Dpid.uri(dpid));
886 Driver driver = driverService.getDriver(deviceId);
887 DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, deviceId));
888 return handler;
889 }
alshabib6b5cfec2014-09-18 17:42:18 -0700890}