Dusan Pajin
Committed by Gerrit Code Review

Added matching vlan and push, pop and rewrite VLAN ID treatement in Intent add …

…command. Added MPLS intent support for vlan operations

Change-Id: Ia70f13209adecaebde93a6fe7bd07b8e5a21074d
...@@ -24,6 +24,7 @@ import java.util.List; ...@@ -24,6 +24,7 @@ import java.util.List;
24 import org.apache.karaf.shell.commands.Option; 24 import org.apache.karaf.shell.commands.Option;
25 import org.onlab.packet.Ip6Address; 25 import org.onlab.packet.Ip6Address;
26 import org.onlab.packet.IpAddress; 26 import org.onlab.packet.IpAddress;
27 +import org.onlab.packet.VlanId;
27 import org.onlab.util.Bandwidth; 28 import org.onlab.util.Bandwidth;
28 import org.onosproject.cli.AbstractShellCommand; 29 import org.onosproject.cli.AbstractShellCommand;
29 import org.onosproject.core.ApplicationId; 30 import org.onosproject.core.ApplicationId;
...@@ -61,6 +62,10 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { ...@@ -61,6 +62,10 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
61 required = false, multiValued = false) 62 required = false, multiValued = false)
62 private String ethTypeString = null; 63 private String ethTypeString = null;
63 64
65 + @Option(name = "-v", aliases = "--vlan", description = "VLAN ID",
66 + required = false, multiValued = false)
67 + private String vlanString = null;
68 +
64 @Option(name = "--ipProto", description = "IP Protocol", 69 @Option(name = "--ipProto", description = "IP Protocol",
65 required = false, multiValued = false) 70 required = false, multiValued = false)
66 private String ipProtoString = null; 71 private String ipProtoString = null;
...@@ -143,6 +148,17 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { ...@@ -143,6 +148,17 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
143 required = false, multiValued = false) 148 required = false, multiValued = false)
144 private String setIpDstString = null; 149 private String setIpDstString = null;
145 150
151 + @Option(name = "--setVlan", description = "Rewrite VLAN ID",
152 + required = false, multiValued = false)
153 + private String setVlan = null;
154 +
155 + @Option(name = "--popVlan", description = "Pop VLAN Tag",
156 + required = false, multiValued = false)
157 + private boolean popVlan = false;
158 +
159 + @Option(name = "--pushVlan", description = "Push VLAN ID",
160 + required = false, multiValued = false)
161 + private String pushVlan = null;
146 162
147 // Priorities 163 // Priorities
148 @Option(name = "-p", aliases = "--priority", description = "Priority", 164 @Option(name = "-p", aliases = "--priority", description = "Priority",
...@@ -202,6 +218,9 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { ...@@ -202,6 +218,9 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
202 if (ethType != null) { 218 if (ethType != null) {
203 selectorBuilder.matchEthType(ethType); 219 selectorBuilder.matchEthType(ethType);
204 } 220 }
221 + if (!isNullOrEmpty(vlanString)) {
222 + selectorBuilder.matchVlanId(VlanId.vlanId(Short.parseShort(vlanString)));
223 + }
205 if (!isNullOrEmpty(srcMacString)) { 224 if (!isNullOrEmpty(srcMacString)) {
206 selectorBuilder.matchEthSrc(MacAddress.valueOf(srcMacString)); 225 selectorBuilder.matchEthSrc(MacAddress.valueOf(srcMacString));
207 } 226 }
...@@ -289,6 +308,19 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { ...@@ -289,6 +308,19 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
289 treatmentBuilder.setIpSrc(IpAddress.valueOf(setIpDstString)); 308 treatmentBuilder.setIpSrc(IpAddress.valueOf(setIpDstString));
290 emptyTreatment = false; 309 emptyTreatment = false;
291 } 310 }
311 + if (!isNullOrEmpty(setVlan)) {
312 + treatmentBuilder.setVlanId(VlanId.vlanId(Short.parseShort(setVlan)));
313 + emptyTreatment = false;
314 + }
315 + if (popVlan) {
316 + treatmentBuilder.popVlan();
317 + emptyTreatment = false;
318 + }
319 + if (!isNullOrEmpty(pushVlan)) {
320 + treatmentBuilder.pushVlan();
321 + treatmentBuilder.setVlanId(VlanId.vlanId(Short.parseShort(pushVlan)));
322 + emptyTreatment = false;
323 + }
292 324
293 if (emptyTreatment) { 325 if (emptyTreatment) {
294 return DefaultTrafficTreatment.emptyTreatment(); 326 return DefaultTrafficTreatment.emptyTreatment();
......
...@@ -16,12 +16,14 @@ ...@@ -16,12 +16,14 @@
16 package org.onosproject.net.intent.impl.compiler; 16 package org.onosproject.net.intent.impl.compiler;
17 17
18 import com.google.common.collect.Sets; 18 import com.google.common.collect.Sets;
19 +
19 import org.apache.felix.scr.annotations.Activate; 20 import org.apache.felix.scr.annotations.Activate;
20 import org.apache.felix.scr.annotations.Component; 21 import org.apache.felix.scr.annotations.Component;
21 import org.apache.felix.scr.annotations.Deactivate; 22 import org.apache.felix.scr.annotations.Deactivate;
22 import org.apache.felix.scr.annotations.Reference; 23 import org.apache.felix.scr.annotations.Reference;
23 import org.apache.felix.scr.annotations.ReferenceCardinality; 24 import org.apache.felix.scr.annotations.ReferenceCardinality;
24 import org.onlab.packet.Ethernet; 25 import org.onlab.packet.Ethernet;
26 +import org.onlab.packet.VlanId;
25 import org.onosproject.core.ApplicationId; 27 import org.onosproject.core.ApplicationId;
26 import org.onosproject.core.CoreService; 28 import org.onosproject.core.CoreService;
27 import org.onosproject.net.ConnectPoint; 29 import org.onosproject.net.ConnectPoint;
...@@ -36,6 +38,8 @@ import org.onosproject.net.flow.TrafficSelector; ...@@ -36,6 +38,8 @@ import org.onosproject.net.flow.TrafficSelector;
36 import org.onosproject.net.flow.TrafficTreatment; 38 import org.onosproject.net.flow.TrafficTreatment;
37 import org.onosproject.net.flow.criteria.Criterion; 39 import org.onosproject.net.flow.criteria.Criterion;
38 import org.onosproject.net.flow.criteria.EthTypeCriterion; 40 import org.onosproject.net.flow.criteria.EthTypeCriterion;
41 +import org.onosproject.net.flow.instructions.Instruction;
42 +import org.onosproject.net.flow.instructions.L2ModificationInstruction;
39 import org.onosproject.net.intent.FlowRuleIntent; 43 import org.onosproject.net.intent.FlowRuleIntent;
40 import org.onosproject.net.intent.Intent; 44 import org.onosproject.net.intent.Intent;
41 import org.onosproject.net.intent.IntentCompiler; 45 import org.onosproject.net.intent.IntentCompiler;
...@@ -235,6 +239,21 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> { ...@@ -235,6 +239,21 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> {
235 TrafficTreatment.Builder treat = DefaultTrafficTreatment.builder(intent 239 TrafficTreatment.Builder treat = DefaultTrafficTreatment.builder(intent
236 .treatment()); 240 .treatment());
237 241
242 + // check if the treatement is popVlan or setVlan (rewrite),
243 + // than selector needs to match any VlanId
244 + for (Instruction instruct : intent.treatment().allInstructions()) {
245 + if (instruct instanceof L2ModificationInstruction) {
246 + L2ModificationInstruction l2Mod = (L2ModificationInstruction) instruct;
247 + if (l2Mod.subtype() == L2ModificationInstruction.L2SubType.VLAN_PUSH) {
248 + break;
249 + }
250 + if (l2Mod.subtype() == L2ModificationInstruction.L2SubType.VLAN_POP ||
251 + l2Mod.subtype() == L2ModificationInstruction.L2SubType.VLAN_ID) {
252 + selector.matchVlanId(VlanId.ANY);
253 + }
254 + }
255 + }
256 +
238 if (intent.egressLabel().isPresent()) { 257 if (intent.egressLabel().isPresent()) {
239 treat.setMpls(intent.egressLabel().get()); 258 treat.setMpls(intent.egressLabel().get());
240 } else { 259 } else {
......