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;
import org.apache.karaf.shell.commands.Option;
import org.onlab.packet.Ip6Address;
import org.onlab.packet.IpAddress;
import org.onlab.packet.VlanId;
import org.onlab.util.Bandwidth;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.core.ApplicationId;
......@@ -61,6 +62,10 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
required = false, multiValued = false)
private String ethTypeString = null;
@Option(name = "-v", aliases = "--vlan", description = "VLAN ID",
required = false, multiValued = false)
private String vlanString = null;
@Option(name = "--ipProto", description = "IP Protocol",
required = false, multiValued = false)
private String ipProtoString = null;
......@@ -143,6 +148,17 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
required = false, multiValued = false)
private String setIpDstString = null;
@Option(name = "--setVlan", description = "Rewrite VLAN ID",
required = false, multiValued = false)
private String setVlan = null;
@Option(name = "--popVlan", description = "Pop VLAN Tag",
required = false, multiValued = false)
private boolean popVlan = false;
@Option(name = "--pushVlan", description = "Push VLAN ID",
required = false, multiValued = false)
private String pushVlan = null;
// Priorities
@Option(name = "-p", aliases = "--priority", description = "Priority",
......@@ -202,6 +218,9 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
if (ethType != null) {
selectorBuilder.matchEthType(ethType);
}
if (!isNullOrEmpty(vlanString)) {
selectorBuilder.matchVlanId(VlanId.vlanId(Short.parseShort(vlanString)));
}
if (!isNullOrEmpty(srcMacString)) {
selectorBuilder.matchEthSrc(MacAddress.valueOf(srcMacString));
}
......@@ -289,6 +308,19 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
treatmentBuilder.setIpSrc(IpAddress.valueOf(setIpDstString));
emptyTreatment = false;
}
if (!isNullOrEmpty(setVlan)) {
treatmentBuilder.setVlanId(VlanId.vlanId(Short.parseShort(setVlan)));
emptyTreatment = false;
}
if (popVlan) {
treatmentBuilder.popVlan();
emptyTreatment = false;
}
if (!isNullOrEmpty(pushVlan)) {
treatmentBuilder.pushVlan();
treatmentBuilder.setVlanId(VlanId.vlanId(Short.parseShort(pushVlan)));
emptyTreatment = false;
}
if (emptyTreatment) {
return DefaultTrafficTreatment.emptyTreatment();
......
......@@ -16,12 +16,14 @@
package org.onosproject.net.intent.impl.compiler;
import com.google.common.collect.Sets;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.packet.Ethernet;
import org.onlab.packet.VlanId;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.net.ConnectPoint;
......@@ -36,6 +38,8 @@ import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.flow.criteria.Criterion;
import org.onosproject.net.flow.criteria.EthTypeCriterion;
import org.onosproject.net.flow.instructions.Instruction;
import org.onosproject.net.flow.instructions.L2ModificationInstruction;
import org.onosproject.net.intent.FlowRuleIntent;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentCompiler;
......@@ -235,6 +239,21 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> {
TrafficTreatment.Builder treat = DefaultTrafficTreatment.builder(intent
.treatment());
// check if the treatement is popVlan or setVlan (rewrite),
// than selector needs to match any VlanId
for (Instruction instruct : intent.treatment().allInstructions()) {
if (instruct instanceof L2ModificationInstruction) {
L2ModificationInstruction l2Mod = (L2ModificationInstruction) instruct;
if (l2Mod.subtype() == L2ModificationInstruction.L2SubType.VLAN_PUSH) {
break;
}
if (l2Mod.subtype() == L2ModificationInstruction.L2SubType.VLAN_POP ||
l2Mod.subtype() == L2ModificationInstruction.L2SubType.VLAN_ID) {
selector.matchVlanId(VlanId.ANY);
}
}
}
if (intent.egressLabel().isPresent()) {
treat.setMpls(intent.egressLabel().get());
} else {
......